From fc5ec03353566c08463dcdd5155832e37fbb6a0a Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Tue, 31 Dec 2013 20:12:47 -0800 Subject: [PATCH] Adjust tuning API to use a single 64-bit integer for frequency in Hz, since the Cortex-M4F has good support for uint64_t. --- firmware/common/tuning.c | 12 +++++++----- firmware/common/tuning.h | 2 +- firmware/hackrf_usb/usb_api_transceiver.c | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/firmware/common/tuning.c b/firmware/common/tuning.c index bab3b7f1..aefeafc4 100644 --- a/firmware/common/tuning.c +++ b/firmware/common/tuning.c @@ -40,13 +40,13 @@ static uint32_t max2837_freq_nominal_hz=2560000000; -uint32_t freq_mhz_cache=100, freq_hz_cache=0; +uint64_t freq_cache = 100000000; /* * Set freq/tuning between 5MHz to 6800 MHz (less than 16bits really used) * hz between 0 to 999999 Hz (not checked) * return false on error or true if success. */ -bool set_freq(uint32_t freq_mhz, uint32_t freq_hz) +bool set_freq(const uint64_t freq) { bool success; uint32_t RFFC5071_freq_mhz; @@ -54,6 +54,9 @@ bool set_freq(uint32_t freq_mhz, uint32_t freq_hz) uint32_t real_RFFC5071_freq_hz; uint32_t tmp_hz; + const uint32_t freq_mhz = freq / 1000000; + const uint32_t freq_hz = freq % 1000000; + success = true; const max2837_mode_t prior_max2837_mode = max2837_mode(); @@ -107,8 +110,7 @@ bool set_freq(uint32_t freq_mhz, uint32_t freq_hz) success = false; } max2837_set_mode(prior_max2837_mode); - freq_mhz_cache = freq_mhz; - freq_hz_cache = freq_hz; + freq_cache = freq; return success; } @@ -116,7 +118,7 @@ bool set_freq_if(const uint32_t freq_if_hz) { bool success = false; if( (freq_if_hz >= MIN_BYPASS_FREQ_MHZ) && (freq_if_hz <= MAX_BYPASS_FREQ_MHZ) ) { max2837_freq_nominal_hz = freq_if_hz; - success = set_freq(freq_mhz_cache, freq_hz_cache); + success = set_freq(freq_cache); } return success; } diff --git a/firmware/common/tuning.h b/firmware/common/tuning.h index 0c1a99d9..16887c9e 100644 --- a/firmware/common/tuning.h +++ b/firmware/common/tuning.h @@ -26,7 +26,7 @@ #include #include -bool set_freq(uint32_t freq_mhz, uint32_t freq_hz); +bool set_freq(const uint64_t freq); bool set_freq_if(const uint32_t freq_if_hz); #endif/*__TUNING_H__*/ diff --git a/firmware/hackrf_usb/usb_api_transceiver.c b/firmware/hackrf_usb/usb_api_transceiver.c index 6566c9e2..1dd071c5 100644 --- a/firmware/hackrf_usb/usb_api_transceiver.c +++ b/firmware/hackrf_usb/usb_api_transceiver.c @@ -75,7 +75,8 @@ usb_request_status_t usb_vendor_request_set_freq( return USB_REQUEST_STATUS_OK; } else if (stage == USB_TRANSFER_STAGE_DATA) { - if( set_freq(set_freq_params.freq_mhz, set_freq_params.freq_hz) ) + const uint64_t freq = set_freq_params.freq_mhz * 1000000 + set_freq_params.freq_hz; + if( set_freq(freq) ) { usb_transfer_schedule_ack(endpoint->in); return USB_REQUEST_STATUS_OK;