Merge pull request #105 from jboone/master

Fix int32/int64 problems in tuning code.
This commit is contained in:
Michael Ossmann
2014-02-20 11:10:15 -07:00
4 changed files with 9 additions and 7 deletions

View File

@ -1,5 +1,6 @@
/*
* Copyright 2012 Michael Ossmann
* Copyright 2014 Jared Boone <jared@sharebrained.com>
*
* This file is part of HackRF.
*
@ -407,12 +408,12 @@ void rffc5071_enable(void) {
#define REF_FREQ 50
/* configure frequency synthesizer in integer mode (lo in MHz) */
uint32_t rffc5071_config_synth_int(uint16_t lo) {
uint64_t rffc5071_config_synth_int(uint16_t lo) {
uint8_t lodiv;
uint16_t fvco;
uint8_t fbkdiv;
uint16_t n;
uint32_t tune_freq_hz;
uint64_t tune_freq_hz;
uint16_t p1nmsb;
uint8_t p1nlsb;
@ -448,7 +449,7 @@ uint32_t rffc5071_config_synth_int(uint16_t lo) {
p1nlsb = (tmp_n >> 5ULL) & 0xff;
//~ tune_freq = REF_FREQ*tmp_n*fbkdiv/lodiv / (1 << 29);
tune_freq_hz = (uint32_t)(REF_FREQ*tmp_n*fbkdiv/lodiv * 1000*1000 / (1 << 29ULL));
tune_freq_hz = REF_FREQ*tmp_n*fbkdiv/lodiv * 1000*1000 / (1 << 29ULL);
LOG("# lo=%d n_lo=%d lodiv=%d fvco=%d fbkdiv=%d n=%d tune_freq_hz=%d\n",
lo, n_lo, lodiv, fvco, fbkdiv, n, tune_freq);
@ -472,7 +473,7 @@ uint32_t rffc5071_config_synth_int(uint16_t lo) {
}
/* !!!!!!!!!!! hz is currently ignored !!!!!!!!!!! */
uint32_t rffc5071_set_frequency(uint16_t mhz) {
uint64_t rffc5071_set_frequency(uint16_t mhz) {
uint32_t tune_freq;
rffc5071_disable();

View File

@ -1,5 +1,6 @@
/*
* Copyright 2012 Michael Ossmann
* Copyright 2014 Jared Boone <jared@sharebrained.com>
*
* This file is part of HackRF.
*
@ -49,7 +50,7 @@ extern void rffc5071_reg_write(uint8_t r, uint16_t v);
extern void rffc5071_regs_commit(void);
/* Set frequency (MHz). */
extern uint32_t rffc5071_set_frequency(uint16_t mhz);
extern uint64_t rffc5071_set_frequency(uint16_t mhz);
/* Set up rx only, tx only, or full duplex. Chip should be disabled
* before _tx, _rx, or _rxtx are called. */

View File

@ -51,7 +51,7 @@ bool set_freq(const uint64_t freq)
bool success;
uint32_t RFFC5071_freq_mhz;
uint32_t MAX2837_freq_hz;
uint32_t real_RFFC5071_freq_hz;
uint64_t real_RFFC5071_freq_hz;
uint32_t tmp_hz;
const uint32_t freq_mhz = freq / 1000000;

View File

@ -75,7 +75,7 @@ usb_request_status_t usb_vendor_request_set_freq(
return USB_REQUEST_STATUS_OK;
} else if (stage == USB_TRANSFER_STAGE_DATA)
{
const uint64_t freq = set_freq_params.freq_mhz * 1000000 + set_freq_params.freq_hz;
const uint64_t freq = set_freq_params.freq_mhz * 1000000ULL + set_freq_params.freq_hz;
if( set_freq(freq) )
{
usb_transfer_schedule_ack(endpoint->in);