From efc0b22f7ea9b808512cb59a5a52202adf84b6e1 Mon Sep 17 00:00:00 2001 From: Trung Tran Date: Fri, 12 Jan 2018 05:31:47 -0800 Subject: mg: add clip function on setting individual gain. Reviewed-by: Martin Braun --- .../dboard/magnesium/magnesium_radio_ctrl_impl.cpp | 27 +++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.cpp') 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 eb4894e19..2d61ef1ff 100644 --- a/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.cpp +++ b/host/lib/usrp/dboard/magnesium/magnesium_radio_ctrl_impl.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -420,12 +421,18 @@ double magnesium_radio_ctrl_impl::_set_tx_gain( std::lock_guard l(_set_lock); UHD_LOG_TRACE(unique_id(), "_set_tx_gain(name=" << name << ", gain=" << gain << ", chan=" << chan << ")"); + UHD_LOG_TRACE(unique_id(), + "_set_tx_gain(name=" << name << ", gain=" << gain << ", chan=" << chan << ")"); + double clip_gain = 0; if (name == MAGNESIUM_GAIN1){ - _ad9371_att[TX_DIRECTION] = gain; + clip_gain = uhd::clip(gain, AD9371_MIN_TX_GAIN, AD9371_MAX_TX_GAIN); + _ad9371_att[TX_DIRECTION] = clip_gain; }else if (name == MAGNESIUM_GAIN2){ - _dsa_att[TX_DIRECTION] = gain; + clip_gain = uhd::clip(gain, DSA_MIN_GAIN, DSA_MAX_GAIN); + _dsa_att[TX_DIRECTION] = clip_gain; }else if (name == MAGNESIUM_AMP){ - _amp_bypass[TX_DIRECTION] = gain == 0.0; + clip_gain = gain > 0.0 ? AMP_MAX_GAIN: AMP_MIN_GAIN; + _amp_bypass[TX_DIRECTION] = clip_gain == 0.0; }else { throw uhd::value_error("Could not find gain element " + name); } @@ -437,7 +444,7 @@ double magnesium_radio_ctrl_impl::_set_tx_gain( chan, TX_DIRECTION ); - return gain; // not really any coreced here for individual gain + return clip_gain; // not really any coreced here (only clip) for individual gain } double magnesium_radio_ctrl_impl::_get_tx_gain( @@ -481,12 +488,16 @@ double magnesium_radio_ctrl_impl::_set_rx_gain( std::lock_guard l(_set_lock); UHD_LOG_TRACE(unique_id(), "_set_rx_gain(name=" << name << ", gain=" << gain << ", chan=" << chan << ")"); + double clip_gain = 0; if (name == MAGNESIUM_GAIN1){ - _ad9371_att[RX_DIRECTION] = gain; + clip_gain = uhd::clip(gain, AD9371_MIN_RX_GAIN, AD9371_MAX_RX_GAIN); + _ad9371_att[RX_DIRECTION] = clip_gain; }else if (name == MAGNESIUM_GAIN2){ - _dsa_att[RX_DIRECTION] = gain; + clip_gain = uhd::clip(gain, DSA_MIN_GAIN, DSA_MAX_GAIN); + _dsa_att[RX_DIRECTION] = clip_gain; }else if (name == MAGNESIUM_AMP){ - _amp_bypass[RX_DIRECTION] = gain == 0.0; + clip_gain = gain > 0.0 ? AMP_MAX_GAIN: AMP_MIN_GAIN; + _amp_bypass[RX_DIRECTION] = clip_gain == 0.0; }else { throw uhd::value_error("Could not find gain element " + name); } @@ -498,7 +509,7 @@ double magnesium_radio_ctrl_impl::_set_rx_gain( chan, RX_DIRECTION ); - return gain; // not really any coreced here for individual gain + return clip_gain; // not really any coreced here (only clip) for individual gain } double magnesium_radio_ctrl_impl::_get_rx_gain( -- cgit v1.2.3