aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2020-10-07 10:46:49 +0200
committermichael-west <michael.west@ettus.com>2020-10-07 11:29:31 -0700
commit11108c9b1e3d86fa75288402e70f943971159216 (patch)
treee43eb9fbcea545e51ef1817c8bb82cd8403cefc6
parentdocs: Fix doxygen warnings (diff)
downloaduhd-11108c9b1e3d86fa75288402e70f943971159216.tar.xz
uhd-11108c9b1e3d86fa75288402e70f943971159216.zip
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.
-rw-r--r--host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.cpp b/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.cpp
index 405d5955e..892fa94bd 100644
--- a/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.cpp
+++ b/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.cpp
@@ -337,8 +337,15 @@ double magnesium_radio_ctrl_impl::set_tx_gain(const double gain, const size_t ch
{
std::lock_guard<std::mutex> l(_set_lock);
UHD_LOG_TRACE(unique_id(), "set_tx_gain(gain=" << gain << ", chan=" << chan << ")");
+ // First, clip to valid range
+ const double clipped_gain = uhd::clip(gain, ALL_TX_MIN_GAIN, ALL_TX_MAX_GAIN);
+ if (clipped_gain != gain) {
+ UHD_LOG_WARNING(unique_id(),
+ "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_ctrl_impl::set_tx_gain(coerced_gain, chan);
return coerced_gain;
}
@@ -392,8 +399,15 @@ double magnesium_radio_ctrl_impl::set_rx_gain(const double gain, const size_t ch
{
std::lock_guard<std::mutex> l(_set_lock);
UHD_LOG_TRACE(unique_id(), "set_rx_gain(gain=" << gain << ", chan=" << chan << ")");
+ // First, clip to valid range
+ const double clipped_gain = uhd::clip(gain, ALL_RX_MIN_GAIN, ALL_RX_MAX_GAIN);
+ if (clipped_gain != gain) {
+ UHD_LOG_WARNING(unique_id(),
+ "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_ctrl_impl::set_rx_gain(coerced_gain, chan);
return coerced_gain;
}