diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index 49a89fc9..6d08f276 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -764,17 +764,20 @@ int ADDCALL hackrf_set_freq(hackrf_device* device, const uint64_t freq_hz) typedef struct { - float freq_mhz; + uint32_t freq_hz; + uint32_t divider; } set_fracrate_params_t; -int ADDCALL hackrf_set_fracrate(hackrf_device* device, const float freq_mhz) +int ADDCALL hackrf_set_fracrate_manual(hackrf_device* device, + const uint32_t freq_hz, uint32_t divider) { set_fracrate_params_t set_fracrate_params; uint8_t length; int result; - - set_fracrate_params.freq_mhz = TO_LE(freq_mhz); + + set_fracrate_params.freq_hz = TO_LE(freq_hz); + set_fracrate_params.divider = TO_LE(divider); length = sizeof(set_fracrate_params_t); result = libusb_control_transfer( @@ -796,6 +799,41 @@ int ADDCALL hackrf_set_fracrate(hackrf_device* device, const float freq_mhz) } } +int ADDCALL hackrf_set_fracrate(hackrf_device* device, const double freq) +{ + const int MAX_N = 32; + uint32_t freq_hz, divider; + double freq_frac = 1.0 + freq - (int)freq; + uint64_t v, a, m; + int i, e; + + v = *((uint64_t*)&freq); + e = (v >> 52) - 1023; + + m = ((1ULL << 52) - 1); + + v = *((uint64_t*)&freq_frac); + v &= m; + + m &= ~((1 << (e+4)) - 1); + + a = 0; + + for (i=1; i