From 88cb85be34a0a164153019845dbc2d8ea48d22fd Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 7 Oct 2020 10:32:39 +0200 Subject: n310/n300: Allow gain coercion The N310 had a different behaviour from other devices, where setting a gain out of range would cause an assertion error. This is problematic for two reasons: 1) Assertion errors should not be triggered by public APIs (if we throw public APIs, we should give a clear error message), and 2) Setting gain and frequency has a coercing behaviour on all other devices. This changeset clips the gain before calling into the gain table lookup. --- .../usrp/dboard/magnesium/magnesium_radio_control.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp b/host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp index e52551365..ce34a771d 100644 --- a/host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp +++ b/host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp @@ -394,8 +394,14 @@ double magnesium_radio_control_impl::set_tx_gain(const double gain, const size_t { std::lock_guard l(_set_lock); RFNOC_LOG_TRACE("set_tx_gain(gain=" << gain << ", chan=" << chan << ")"); + // First, clip to valid range + const double clipped_gain = get_tx_gain_range(chan).clip(gain); + if (clipped_gain != gain) { + RFNOC_LOG_WARNING("Channel " << chan << ": Coercing TX gain from " << gain + << " dB to " << clipped_gain); + } const double coerced_gain = - _set_all_gain(gain, this->get_tx_frequency(chan), chan, TX_DIRECTION); + _set_all_gain(clipped_gain, this->get_tx_frequency(chan), chan, TX_DIRECTION); radio_control_impl::set_tx_gain(coerced_gain, chan); return coerced_gain; } @@ -449,8 +455,14 @@ double magnesium_radio_control_impl::set_rx_gain(const double gain, const size_t { std::lock_guard l(_set_lock); RFNOC_LOG_TRACE("set_rx_gain(gain=" << gain << ", chan=" << chan << ")"); + // First, clip to valid range + const double clipped_gain = get_rx_gain_range(chan).clip(gain); + if (clipped_gain != gain) { + RFNOC_LOG_WARNING("Channel " << chan << ": Coercing RX gain from " << gain + << " dB to " << clipped_gain); + } const double coerced_gain = - _set_all_gain(gain, this->get_rx_frequency(chan), chan, RX_DIRECTION); + _set_all_gain(clipped_gain, this->get_rx_frequency(chan), chan, RX_DIRECTION); radio_control_impl::set_rx_gain(coerced_gain, chan); return coerced_gain; } -- cgit v1.2.3