aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2020-10-07 10:32:39 +0200
committerAaron Rossetto <aaron.rossetto@ni.com>2020-10-09 12:28:54 -0500
commit88cb85be34a0a164153019845dbc2d8ea48d22fd (patch)
tree3dc54ee1ea78e62c7f732660310d9d2cfe768ef7 /host/lib/usrp
parent70e1f0f0c697d6522e3a87e2de93e34e375decb4 (diff)
downloaduhd-88cb85be34a0a164153019845dbc2d8ea48d22fd.tar.gz
uhd-88cb85be34a0a164153019845dbc2d8ea48d22fd.tar.bz2
uhd-88cb85be34a0a164153019845dbc2d8ea48d22fd.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.
Diffstat (limited to 'host/lib/usrp')
-rw-r--r--host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp16
1 files 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<std::recursive_mutex> 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<std::recursive_mutex> 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;
}