From 531ea2d0cdc66caff189d9b7b07a336ced891618 Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Thu, 19 Sep 2019 15:31:45 +0200 Subject: [PATCH] Cleaned up unused RF functions. Integrated Soapy Master Clock Rate in set srate. --- lib/src/phy/rf/rf_blade_imp.c | 6 ---- lib/src/phy/rf/rf_blade_imp.h | 2 -- lib/src/phy/rf/rf_dev.h | 5 ---- lib/src/phy/rf/rf_soapy_imp.c | 54 ++++++++++++++++++----------------- lib/src/phy/rf/rf_soapy_imp.h | 12 ++------ lib/src/phy/rf/rf_uhd_imp.h | 12 ++------ lib/src/phy/rf/rf_zmq_imp.c | 6 ---- lib/src/phy/rf/rf_zmq_imp.h | 2 -- 8 files changed, 33 insertions(+), 66 deletions(-) diff --git a/lib/src/phy/rf/rf_blade_imp.c b/lib/src/phy/rf/rf_blade_imp.c index 1137e0301..843f04574 100644 --- a/lib/src/phy/rf/rf_blade_imp.c +++ b/lib/src/phy/rf/rf_blade_imp.c @@ -52,12 +52,6 @@ void rf_blade_register_error_handler(UNUSED void* ptr, srslte_rf_error_handler_t blade_error_handler = new_handler; } -bool rf_blade_rx_wait_lo_locked(UNUSED void* h) -{ - usleep(1000); - return true; -} - const unsigned int num_buffers = 256; const unsigned int ms_buffer_size_rx = 1024; const unsigned int buffer_size_tx = 1024; diff --git a/lib/src/phy/rf/rf_blade_imp.h b/lib/src/phy/rf/rf_blade_imp.h index d869f69f7..deb347448 100644 --- a/lib/src/phy/rf/rf_blade_imp.h +++ b/lib/src/phy/rf/rf_blade_imp.h @@ -47,8 +47,6 @@ SRSLTE_API bool rf_blade_has_rssi(void *h); SRSLTE_API float rf_blade_get_rssi(void *h); -SRSLTE_API bool rf_blade_rx_wait_lo_locked(void *h); - SRSLTE_API double rf_blade_set_rx_srate(void* h, double freq); SRSLTE_API double rf_blade_set_rx_gain(void *h, diff --git a/lib/src/phy/rf/rf_dev.h b/lib/src/phy/rf/rf_dev.h index 200cf35b4..9d3d2de0d 100644 --- a/lib/src/phy/rf/rf_dev.h +++ b/lib/src/phy/rf/rf_dev.h @@ -23,7 +23,6 @@ typedef struct { const char *name; char* (*srslte_rf_devname) (void *h); - bool (*srslte_rf_rx_wait_lo_locked) (void *h); int (*srslte_rf_start_rx_stream)(void *h, bool now); int (*srslte_rf_stop_rx_stream)(void *h); void (*srslte_rf_flush_buffer)(void *h); @@ -64,7 +63,6 @@ typedef struct { static rf_dev_t dev_uhd = {"UHD", rf_uhd_devname, - rf_uhd_rx_wait_lo_locked, rf_uhd_start_rx_stream, rf_uhd_stop_rx_stream, rf_uhd_flush_buffer, @@ -99,7 +97,6 @@ static rf_dev_t dev_uhd = {"UHD", static rf_dev_t dev_blade = {"bladeRF", rf_blade_devname, - rf_blade_rx_wait_lo_locked, rf_blade_start_rx_stream, rf_blade_stop_rx_stream, rf_blade_flush_buffer, @@ -133,7 +130,6 @@ static rf_dev_t dev_blade = {"bladeRF", static rf_dev_t dev_soapy = {"soapy", rf_soapy_devname, - rf_soapy_rx_wait_lo_locked, rf_soapy_start_rx_stream, rf_soapy_stop_rx_stream, rf_soapy_flush_buffer, @@ -169,7 +165,6 @@ static rf_dev_t dev_soapy = {"soapy", static rf_dev_t dev_zmq = {"zmq", rf_zmq_devname, - rf_zmq_rx_wait_lo_locked, rf_zmq_start_rx_stream, rf_zmq_stop_rx_stream, rf_zmq_flush_buffer, diff --git a/lib/src/phy/rf/rf_soapy_imp.c b/lib/src/phy/rf/rf_soapy_imp.c index 10c255c06..37cd4c7e1 100644 --- a/lib/src/phy/rf/rf_soapy_imp.c +++ b/lib/src/phy/rf/rf_soapy_imp.c @@ -53,6 +53,7 @@ typedef struct { bool rx_stream_active; srslte_rf_info_t info; double tx_rate; + double master_clock_rate; size_t rx_mtu, tx_mtu; size_t num_rx_channels; size_t num_tx_channels; @@ -192,10 +193,8 @@ char* rf_soapy_devname(void* h) return handler->devname; } - -bool rf_soapy_rx_wait_lo_locked(void *h) +static bool rf_soapy_rx_wait_lo_locked(rf_soapy_handler_t* handler) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*)h; char *ret = SoapySDRDevice_readChannelSensor(handler->device, SOAPY_SDR_RX, 0, "lo_locked"); if (ret != NULL) { return (strcmp(ret, "true") == 0 ? true : false); @@ -380,8 +379,8 @@ int rf_soapy_open_multi(char* args, void** h, uint32_t num_requested_channels) for (uint32_t i = 0; i < handler->num_rx_channels; ++i) { list = SoapySDRDevice_listChannelSensors(handler->device, SOAPY_SDR_RX, i, &list_length); printf("Available sensors for Rx channel %d: \n", i); - for (int i = 0; i < list_length; i++) { - printf(" - %s\n", list[i]); + for (int j = 0; j < list_length; j++) { + printf(" - %s\n", list[j]); } } @@ -554,28 +553,29 @@ int rf_soapy_close(void *h) return SRSLTE_SUCCESS; } -void rf_soapy_set_master_clock_rate(void *h, double rate) +void soapy_set_master_clock_rate(rf_soapy_handler_t* handler, double rate) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - if (SoapySDRDevice_setMasterClockRate(handler->device, rate) != 0) { - printf("rf_soapy_set_master_clock_rate Rx fail: %s\n", SoapySDRDevice_lastError()); + if (rate != rate) { + if (SoapySDRDevice_setMasterClockRate(handler->device, rate) != 0) { + printf("rf_soapy_set_master_clock_rate Rx fail: %s\n", SoapySDRDevice_lastError()); + } else { + handler->master_clock_rate = rate; + } } printf("Set master clock rate to %.2f MHz\n", SoapySDRDevice_getMasterClockRate(handler->device)/1e6); } - -bool rf_soapy_is_master_clock_dynamic(void *h) -{ - printf("TODO: implement rf_soapy_is_master_clock_dynamic()\n"); - return false; -} - - double rf_soapy_set_rx_srate(void *h, double rate) { rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + if (rate < 10e6) { + soapy_set_master_clock_rate(handler, 4 * rate); + } else { + soapy_set_master_clock_rate(handler, rate); + } + // Restart streaming, as the Lime seems to have problems reconfiguring the sample rate during streaming bool rx_stream_active = handler->rx_stream_active; if (rx_stream_active) { @@ -616,6 +616,12 @@ double rf_soapy_set_tx_srate(void *h, double rate) { rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + if (rate < 10e6) { + soapy_set_master_clock_rate(handler, 4 * rate); + } else { + soapy_set_master_clock_rate(handler, rate); + } + // stop/start streaming during rate reconfiguration bool rx_stream_active = handler->rx_stream_active; if (handler->rx_stream_active) { @@ -778,12 +784,10 @@ int rf_soapy_recv_with_time_multi(void *h, if (ret == SOAPY_SDR_OVERFLOW || (ret > 0 && (flags & SOAPY_SDR_END_ABRUPT) != 0)) { log_overflow(handler); continue; - } else - if (ret == SOAPY_SDR_TIMEOUT) { + } else if (ret == SOAPY_SDR_TIMEOUT) { log_late(handler, true); continue; - } else - if (ret < 0) { + } else if (ret < 0) { // unspecific error printf("SoapySDRDevice_readStream returned %d: %s\n", ret, SoapySDR_errToStr(ret)); handler->num_other_errors++; @@ -791,8 +795,8 @@ int rf_soapy_recv_with_time_multi(void *h, // update rx time only for first segment if (secs != NULL && frac_secs != NULL && n == 0) { - *secs = timeNs / 1e9; - *frac_secs = (timeNs % 1000000000)/1e9; + *secs = floor(timeNs / 1e9); + *frac_secs = (timeNs % 1000000000) / 1e9; //printf("rx_time: secs=%lld, frac_secs=%lf timeNs=%llu\n", *secs, *frac_secs, timeNs); } @@ -917,9 +921,7 @@ int rf_soapy_send_timed_multi(void* h, timeNs += adv; } n += ret; - } - else - if (ret < 0) { + } else if (ret < 0) { // An error has occured switch (ret) { case SOAPY_SDR_TIMEOUT: diff --git a/lib/src/phy/rf/rf_soapy_imp.h b/lib/src/phy/rf/rf_soapy_imp.h index 865883634..155dd3aec 100644 --- a/lib/src/phy/rf/rf_soapy_imp.h +++ b/lib/src/phy/rf/rf_soapy_imp.h @@ -46,17 +46,11 @@ SRSLTE_API void rf_soapy_flush_buffer(void *h); SRSLTE_API bool rf_soapy_has_rssi(void *h); -SRSLTE_API float rf_soapy_get_rssi(void *h); +SRSLTE_API float rf_soapy_get_rssi(void* h); -SRSLTE_API bool rf_soapy_rx_wait_lo_locked(void *h); +SRSLTE_API void rf_soapy_set_master_clock_rate(void* h, double rate); -SRSLTE_API void rf_soapy_set_master_clock_rate(void *h, - double rate); - -SRSLTE_API bool rf_soapy_is_master_clock_dynamic(void *h); - -SRSLTE_API double rf_soapy_set_rx_srate(void *h, - double freq); +SRSLTE_API double rf_soapy_set_rx_srate(void* h, double freq); SRSLTE_API double rf_soapy_set_rx_gain(void *h, double gain); diff --git a/lib/src/phy/rf/rf_uhd_imp.h b/lib/src/phy/rf/rf_uhd_imp.h index 083679527..34aac195d 100644 --- a/lib/src/phy/rf/rf_uhd_imp.h +++ b/lib/src/phy/rf/rf_uhd_imp.h @@ -54,17 +54,9 @@ SRSLTE_API void rf_uhd_flush_buffer(void *h); SRSLTE_API bool rf_uhd_has_rssi(void *h); -SRSLTE_API float rf_uhd_get_rssi(void *h); +SRSLTE_API float rf_uhd_get_rssi(void* h); -SRSLTE_API bool rf_uhd_rx_wait_lo_locked(void *h); - -SRSLTE_API void rf_uhd_set_master_clock_rate(void *h, - double rate); - -SRSLTE_API bool rf_uhd_is_master_clock_dynamic(void *h); - -SRSLTE_API double rf_uhd_set_rx_srate(void *h, - double freq); +SRSLTE_API double rf_uhd_set_rx_srate(void* h, double freq); SRSLTE_API double rf_uhd_set_rx_gain(void *h, double gain); diff --git a/lib/src/phy/rf/rf_zmq_imp.c b/lib/src/phy/rf/rf_zmq_imp.c index 118896d6b..43d7614d8 100644 --- a/lib/src/phy/rf/rf_zmq_imp.c +++ b/lib/src/phy/rf/rf_zmq_imp.c @@ -294,12 +294,6 @@ char* rf_zmq_devname(void* h) return (char*)zmq_devname; } -bool rf_zmq_rx_wait_lo_locked(void* h) -{ - // TODO: Return true if it is client and connected - return true; -} - int rf_zmq_start_rx_stream(void* h, bool now) { return SRSLTE_SUCCESS; diff --git a/lib/src/phy/rf/rf_zmq_imp.h b/lib/src/phy/rf/rf_zmq_imp.h index ebda16ab5..be6ec1608 100644 --- a/lib/src/phy/rf/rf_zmq_imp.h +++ b/lib/src/phy/rf/rf_zmq_imp.h @@ -51,8 +51,6 @@ SRSLTE_API bool rf_zmq_has_rssi(void* h); SRSLTE_API float rf_zmq_get_rssi(void* h); -SRSLTE_API bool rf_zmq_rx_wait_lo_locked(void* h); - SRSLTE_API double rf_zmq_set_rx_srate(void* h, double freq); SRSLTE_API double rf_zmq_set_rx_gain(void* h, double gain);