diff --git a/firmware/hackrf_usb/CMakeLists.txt b/firmware/hackrf_usb/CMakeLists.txt index 10ee4ffb..8db83f7f 100644 --- a/firmware/hackrf_usb/CMakeLists.txt +++ b/firmware/hackrf_usb/CMakeLists.txt @@ -42,6 +42,7 @@ set(SRC_M4 usb_api_register.c usb_api_spiflash.c usb_api_transceiver.c + usb_api_scan.c "${PATH_HACKRF_FIRMWARE_COMMON}/usb_queue.c" "${PATH_HACKRF_FIRMWARE_COMMON}/fault_handler.c" "${PATH_HACKRF_FIRMWARE_COMMON}/cpld_jtag.c" diff --git a/firmware/hackrf_usb/hackrf_usb.c b/firmware/hackrf_usb/hackrf_usb.c index 394875c4..c5dea94c 100644 --- a/firmware/hackrf_usb/hackrf_usb.c +++ b/firmware/hackrf_usb/hackrf_usb.c @@ -42,6 +42,7 @@ #include "usb_api_cpld.h" #include "usb_api_register.h" #include "usb_api_spiflash.h" +#include "usb_api_scan.h" #include "usb_api_transceiver.h" #include "sgpio_isr.h" @@ -142,6 +143,7 @@ static const usb_request_handler_fn vendor_request_handler[] = { #endif usb_vendor_request_set_freq_explicit, usb_vendor_request_read_wcid, // USB_WCID_VENDOR_REQ + usb_vendor_request_init_scan, }; static const uint32_t vendor_request_handler_count = @@ -241,13 +243,8 @@ int main(void) { rf_path_init(&rf_path); unsigned int phase = 0; - unsigned int blocks_queued = 0; - const uint64_t scan_freq_min = 100000000; - const uint64_t scan_freq_max = 6000000000; - const uint64_t scan_freq_step = 20000000; - uint64_t scan_freq = scan_freq_min; - set_freq(scan_freq); + while(true) { // Check whether we need to initiate a CPLD update if (start_cpld_update) @@ -286,11 +283,7 @@ int main(void) { } if (blocks_queued > 2) { - scan_freq += scan_freq_step; - if (scan_freq > scan_freq_max) { - scan_freq = scan_freq_min; - } - set_freq(scan_freq); + scan_callback(); blocks_queued = 0; } } diff --git a/firmware/hackrf_usb/usb_api_scan.c b/firmware/hackrf_usb/usb_api_scan.c new file mode 100644 index 00000000..376a17f7 --- /dev/null +++ b/firmware/hackrf_usb/usb_api_scan.c @@ -0,0 +1,53 @@ +/* + * Copyright 2016 Mike Walters, Dominic Spill + * + * This file is part of HackRF. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#include "usb_api_scan.h" +#include "usb_queue.h" +#include +//#include +#include "tuning.h" + +volatile bool scan_mode = false; +static uint64_t scan_freq; +static uint64_t scan_freq_min; +static uint64_t scan_freq_max; +static uint64_t scan_freq_step; + +usb_request_status_t usb_vendor_request_init_scan( + usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) +{ + if (stage == USB_TRANSFER_STAGE_SETUP) { + // DGS set scan frequencies here + scan_freq = scan_freq_min; + set_freq(scan_freq); + scan_mode = true; + usb_transfer_schedule_ack(endpoint->in); + } + return USB_REQUEST_STATUS_OK; +} + +void scan_callback(void) { + scan_freq += scan_freq_step; + if (scan_freq > scan_freq_max) { + scan_freq = scan_freq_min; + } + set_freq(scan_freq); +} diff --git a/firmware/hackrf_usb/usb_api_scan.h b/firmware/hackrf_usb/usb_api_scan.h new file mode 100644 index 00000000..3aca5372 --- /dev/null +++ b/firmware/hackrf_usb/usb_api_scan.h @@ -0,0 +1,36 @@ +/* + * Copyright 2016 Mike Walters, Dominic Spill + * + * This file is part of HackRF. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __USB_API_SCAN_H__ +#define __USB_API_SCAN_H__ + +#include +#include +#include + +extern volatile bool scan_mode; + +usb_request_status_t usb_vendor_request_init_scan( + usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage); + +void scan_callback(void); + +#endif /* __USB_API_SPCAN_H__ */