diff options
Diffstat (limited to 'host/lib/usrp/dboard/magnesium/magnesium_gain_table.cpp')
-rw-r--r-- | host/lib/usrp/dboard/magnesium/magnesium_gain_table.cpp | 120 |
1 files changed, 81 insertions, 39 deletions
diff --git a/host/lib/usrp/dboard/magnesium/magnesium_gain_table.cpp b/host/lib/usrp/dboard/magnesium/magnesium_gain_table.cpp index 8681dc1d5..145501202 100644 --- a/host/lib/usrp/dboard/magnesium/magnesium_gain_table.cpp +++ b/host/lib/usrp/dboard/magnesium/magnesium_gain_table.cpp @@ -11,22 +11,54 @@ #include <map> using namespace uhd; +using namespace uhd::rfnoc; using namespace magnesium; namespace { + typedef magnesium_radio_ctrl_impl::rx_band rx_band; + typedef magnesium_radio_ctrl_impl::tx_band tx_band; + + const size_t TX_LOWBAND = 0; + const size_t TX_HIGHBAND = 1; + const size_t RX_LOWBAND = 0; + const size_t RX_MIDBAND = 1; + const size_t RX_HIGHBAND = 2; + + size_t map_tx_band(const tx_band band) + { + if (band == tx_band::LOWBAND) { + return TX_LOWBAND; + } + return TX_HIGHBAND; + } + + size_t map_rx_band(const rx_band band) + { + if (band == rx_band::LOWBAND) { + return RX_LOWBAND; + } + if (band == rx_band::BAND0 or + band == rx_band::BAND1 or + band == rx_band::BAND2 or + band == rx_band::BAND3) { + return RX_MIDBAND; + } + return RX_HIGHBAND; + } + //! Maps gain index -> gain_tuple_t // // Note: This is an int, for easier lookups. We're basically hardcoding the // knowledge that the gain map has a 1 dB granularity. using gain_tuple_map_t = std::map<int, gain_tuple_t>; - //! Maps max frequency -> gain_tuple_map_t - using gain_tables_t = std::map<double, gain_tuple_map_t>; + //! Maps band -> gain_tuple_map_t + using gain_tables_t = std::map<size_t, gain_tuple_map_t>; /*! RX gain tables */ const gain_tables_t rx_gain_tables = { - {MAGNESIUM_LOWBAND_FREQ, { + {RX_LOWBAND, { // Gain, DSA att, Myk att, bypass {0, {30, 30, true}}, {1, {30, 29, true}}, @@ -105,7 +137,7 @@ namespace { {74, {0, 6, false}}, {75, {0, 5, false}} }}, - {MAGNESIUM_RX_BAND4_MIN_FREQ, { + {RX_MIDBAND, { // Valid for bands 0, 1, 2, 3 {0, {30, 30, true}}, {1, {30, 29, true}}, {2, {30, 28, true}}, @@ -183,7 +215,7 @@ namespace { {74, {6, 0, false}}, {75, {5, 0, false}} }}, - {MAGNESIUM_MAX_FREQ, { + {RX_HIGHBAND, { // Valid for bands 4, 5, 6 {0, {30, 30, true}}, {1, {30, 29, true}}, {2, {30, 28, true}}, @@ -265,7 +297,7 @@ namespace { }; /* rx_gain_tables */ const gain_tables_t tx_gain_tables = { - {MAGNESIUM_LOWBAND_FREQ, { + {TX_LOWBAND, { // Gain, DSA att, Myk att, bypass {0, {30, 20, true}}, {1, {29, 20, true}}, @@ -334,7 +366,7 @@ namespace { {64, {0, 1, false}}, {65, {0, 0, false}} }}, - {6e9, { + {TX_HIGHBAND, { // Valid for bands 1, 2, 3, 4 {0, {30, 20, true}}, {1, {29, 20, true}}, {2, {28, 20, true}}, @@ -404,41 +436,51 @@ namespace { {65, {0, 0, false}} }} }; /* tx_gain_tables */ + + gain_tuple_t fine_tune_ad9371_att( + const gain_tuple_t gain_tuple, + const double gain_index + ) { + // Here, we hardcode the half-dB steps. We soak up all half-dB + // steps by twiddling the AD9371 attenuation, but we need to make + // sure we don't make it negative. + if (gain_index - int(gain_index) >= .5) { + gain_tuple_t gt2 = gain_tuple; + gt2.ad9371_att = std::max(0.0, gain_tuple.ad9371_att - .5); + } + return gain_tuple; + } + } /* namespace ANON */ -gain_tuple_t magnesium::get_gain_tuple( + +gain_tuple_t magnesium::get_rx_gain_tuple( const double gain_index, - const double freq, - const uhd::direction_t dir + const magnesium_radio_ctrl_impl::rx_band band ) { - UHD_ASSERT_THROW(dir == RX_DIRECTION or dir == TX_DIRECTION); - if (dir == RX_DIRECTION) { - UHD_ASSERT_THROW( - gain_index <= ALL_RX_MAX_GAIN and gain_index >= ALL_RX_MIN_GAIN - ); - } else { - UHD_ASSERT_THROW( - gain_index <= ALL_TX_MAX_GAIN and gain_index >= ALL_TX_MIN_GAIN - ); - } - auto &gain_table = (dir == RX_DIRECTION) ? - rx_gain_tables : - tx_gain_tables; + UHD_ASSERT_THROW( + gain_index <= ALL_RX_MAX_GAIN and gain_index >= ALL_RX_MIN_GAIN + ); + auto &gain_table = rx_gain_tables.at(map_rx_band(band)); + const int gain_index_truncd = int(gain_index); + return fine_tune_ad9371_att( + gain_table.at(gain_index_truncd), + gain_index + ); +} - for (const auto &gain_map : gain_table) { - // First, find appropriate gain map for this frequency - if (gain_map.first >= freq) { - int gain_index_truncd = int(gain_index); - // Here, we hardcode the half-dB steps. We soak up all half-dB - // steps by twiddling the AD9371 attenuation, but we need to make - // sure we don't make it negative. - gain_tuple_t gain_tuple = gain_map.second.at(gain_index_truncd); - if (gain_index - double(gain_index_truncd) >= .5) { - gain_tuple.ad9371_att = - std::max(0.0, gain_tuple.ad9371_att - .5); - } - return gain_tuple; - } - } - UHD_THROW_INVALID_CODE_PATH(); +gain_tuple_t magnesium::get_tx_gain_tuple( + const double gain_index, + const magnesium_radio_ctrl_impl::tx_band band +) { + UHD_ASSERT_THROW( + gain_index <= ALL_TX_MAX_GAIN and gain_index >= ALL_TX_MIN_GAIN + ); + auto &gain_table = tx_gain_tables.at(map_tx_band(band)); + const int gain_index_truncd = int(gain_index); + return fine_tune_ad9371_att( + gain_table.at(gain_index_truncd), + gain_index + ); } + |