From df2c949417af9d351fc5b28f67ca4e507059560b Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Tue, 28 Jul 2020 16:06:52 +0200 Subject: [PATCH] Radio: add individual Rx gain and integrate in srsue Fix compilation Fix compilation Add missing variable. Wasn't compiling Radio: revert some changes --- lib/include/srslte/common/interfaces_common.h | 1 + lib/src/radio/radio.cc | 28 ++++++++++++++++--- srsue/src/main.cc | 5 ++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/include/srslte/common/interfaces_common.h b/lib/include/srslte/common/interfaces_common.h index 47b98f961..278629588 100644 --- a/lib/include/srslte/common/interfaces_common.h +++ b/lib/include/srslte/common/interfaces_common.h @@ -47,6 +47,7 @@ typedef struct { float ul_freq; float freq_offset; float rx_gain; + float rx_gain_ch[SRSLTE_MAX_CARRIERS]; float tx_gain; float tx_gain_ch[SRSLTE_MAX_CARRIERS]; float tx_max_power; diff --git a/lib/src/radio/radio.cc b/lib/src/radio/radio.cc index 213fd1e4b..24f7d536e 100644 --- a/lib/src/radio/radio.cc +++ b/lib/src/radio/radio.cc @@ -198,6 +198,26 @@ int radio::init(const rf_args_t& args, phy_interface_radio* phy_) } } + // Set individual gains + for (uint32_t i = 0; i < args.nof_carriers; i++) { + if (args.rx_gain_ch[i] > 0) { + for (uint32_t j = 0; j < nof_antennas; j++) { + uint32_t phys_antenna_idx = i * nof_antennas + j; + + // From channel number deduce RF device index and channel + uint32_t rf_device_idx = phys_antenna_idx / nof_channels_x_dev; + uint32_t rf_channel_idx = phys_antenna_idx % nof_channels_x_dev; + + log_h->info( + "Setting individual rx_gain=%.1f on dev=%d ch=%d\n", args.rx_gain_ch[i], rf_device_idx, rf_channel_idx); + if (srslte_rf_set_rx_gain_ch(&rf_devices[rf_device_idx], rf_channel_idx, args.rx_gain_ch[i]) < 0) { + log_h->error( + "Setting channel rx_gain=%.1f on dev=%d ch=%d\n", args.rx_gain_ch[i], rf_device_idx, rf_channel_idx); + } + } + } + } + // Set resampler buffers to 5 ms if (std::isnormal(fix_srate_hz)) { for (auto& buf : rx_buffer) { @@ -277,9 +297,9 @@ bool radio::start_agc(bool tx_gain_same_rx) bool radio::rx_now(rf_buffer_interface& buffer, rf_timestamp_interface& rxd_time) { std::unique_lock lock(rx_mutex); - bool ret = true; - rf_buffer_t buffer_rx; - uint32_t ratio = SRSLTE_MAX(1, decimators[0].ratio); + bool ret = true; + rf_buffer_t buffer_rx; + uint32_t ratio = SRSLTE_MAX(1, decimators[0].ratio); // If the interpolator have been set, interpolate for (uint32_t ch = 0; ch < nof_channels; ch++) { @@ -379,7 +399,7 @@ bool radio::rx_dev(const uint32_t& device_idx, const rf_buffer_interface& buffer bool radio::tx(rf_buffer_interface& buffer, const rf_timestamp_interface& tx_time) { - bool ret = true; + bool ret = true; std::unique_lock lock(tx_mutex); // If the interpolator have been set, interpolate diff --git a/srsue/src/main.cc b/srsue/src/main.cc index 5d20ab843..8ea17fefd 100644 --- a/srsue/src/main.cc +++ b/srsue/src/main.cc @@ -87,6 +87,11 @@ static int parse_args(all_args_t* args, int argc, char* argv[]) ("rf.tx_gain[2]", bpo::value(&args->rf.tx_gain_ch[2])->default_value(-1), "Front-end transmitter gain CH2") ("rf.tx_gain[3]", bpo::value(&args->rf.tx_gain_ch[3])->default_value(-1), "Front-end transmitter gain CH3") ("rf.tx_gain[4]", bpo::value(&args->rf.tx_gain_ch[4])->default_value(-1), "Front-end transmitter gain CH4") + ("rf.rx_gain[0]", bpo::value(&args->rf.rx_gain_ch[0])->default_value(-1), "Front-end receiver gain CH0") + ("rf.rx_gain[1]", bpo::value(&args->rf.rx_gain_ch[1])->default_value(-1), "Front-end receiver gain CH1") + ("rf.rx_gain[2]", bpo::value(&args->rf.rx_gain_ch[2])->default_value(-1), "Front-end receiver gain CH2") + ("rf.rx_gain[3]", bpo::value(&args->rf.rx_gain_ch[3])->default_value(-1), "Front-end receiver gain CH3") + ("rf.rx_gain[4]", bpo::value(&args->rf.rx_gain_ch[4])->default_value(-1), "Front-end receiver gain CH4") ("rf.nof_carriers", bpo::value(&args->rf.nof_carriers)->default_value(1), "Number of carriers") ("rf.nof_antennas", bpo::value(&args->rf.nof_antennas)->default_value(1), "Number of antennas per carrier")