diff options
author | mattprost <matt.prost@ni.com> | 2021-12-16 13:48:26 -0600 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2022-04-07 13:28:02 -0700 |
commit | b8acf58798018f5fb4d84d470badadce5dd3a08d (patch) | |
tree | 137db7eeff0d3bbc202b228fd4bee4f143b1b467 /host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp | |
parent | a8ad4917d331258e163e1786c0325a4b7e7d2e3e (diff) | |
download | uhd-b8acf58798018f5fb4d84d470badadce5dd3a08d.tar.gz uhd-b8acf58798018f5fb4d84d470badadce5dd3a08d.tar.bz2 uhd-b8acf58798018f5fb4d84d470badadce5dd3a08d.zip |
n310: Add Filter API to n310
Add the Filter API to n3xx specifically for the AD937x device. The TX
filter is limited to 32 taps, and the RX filter is limited to 48 taps.
This feature requires MPM version 4.2 or later on the device.
Co-authored-by: bpadalino <bpadalino@gmail.com>
Signed-off-by: mattprost <matt.prost@ni.com>
Diffstat (limited to 'host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp')
-rw-r--r-- | host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp b/host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp index 8e2463721..249833ddf 100644 --- a/host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp +++ b/host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp @@ -1175,6 +1175,145 @@ sensor_value_t magnesium_radio_control_impl::get_tx_sensor( } /************************************************************************** + * Filter API + *************************************************************************/ +std::vector<std::string> magnesium_radio_control_impl::get_rx_filter_names( + const size_t chan) const +{ + UHD_ASSERT_THROW(chan < TOTAL_RADIO_PORTS); + if (chan % 2 == 0) { + return {"RX1_FIR", "RX1RX2_FIR"}; + } else { + return {"RX2_FIR", "RX1RX2_FIR"}; + } +} + +uhd::filter_info_base::sptr magnesium_radio_control_impl::get_rx_filter( + const std::string& name, const size_t) +{ + if (_mpm_compat_num[0] < 4 || (_mpm_compat_num[0] == 4 && _mpm_compat_num[1] < 2)) { + RFNOC_LOG_WARNING("Getting rx filter not supported. Please upgrade MPM to a " + "minimum version of 4.2."); + return std::make_shared<uhd::digital_filter_fir<int16_t>>( + uhd::filter_info_base::filter_type::DIGITAL_FIR_I16, + false, + 0, + 1.0, + 1, + 1, + 32767, + AD9371_RX_MAX_FIR_TAPS, + std::vector<int16_t>(AD9371_RX_MAX_FIR_TAPS, 0)); + } + + const auto rv = _ad9371->get_fir(name); + const auto coeffs = rv.second; + // TODO: Put gain in the digital_filter_fir + return std::make_shared<uhd::digital_filter_fir<int16_t>>( + uhd::filter_info_base::filter_type::DIGITAL_FIR_I16, + false, + 0, + 1.0, + 1, + 1, + 32767, + AD9371_RX_MAX_FIR_TAPS, + coeffs); +} + +void magnesium_radio_control_impl::set_rx_filter( + const std::string& name, uhd::filter_info_base::sptr filter, const size_t) +{ + std::lock_guard<std::recursive_mutex> l(_set_lock); + + if (_mpm_compat_num[0] < 4 || (_mpm_compat_num[0] == 4 && _mpm_compat_num[1] < 2)) { + RFNOC_LOG_WARNING("Setting rx filter not supported. Please upgrade MPM to a " + "minimum version of 4.2."); + return; + } + + auto fir = std::dynamic_pointer_cast<uhd::digital_filter_fir<int16_t>>(filter); + if (fir == nullptr) { + throw uhd::runtime_error("Invalid Filter Type for RX Filter"); + } + if (fir->get_taps().size() != AD9371_RX_MAX_FIR_TAPS) { + throw uhd::runtime_error("AD937x RX Filter Taps must be " + + std::to_string(AD9371_RX_MAX_FIR_TAPS) + + " taps long!"); + } + // TODO: Use gain in the digital_filter_fir + _ad9371->set_fir(name, 6, fir->get_taps()); +} + +std::vector<std::string> magnesium_radio_control_impl::get_tx_filter_names( + const size_t chan) const +{ + UHD_ASSERT_THROW(chan < TOTAL_RADIO_PORTS); + if (chan % 2 == 0) { + return {"TX1_FIR", "TX1TX2_FIR"}; + } else { + return {"TX2_FIR", "TX1TX2_FIR"}; + } +} + +uhd::filter_info_base::sptr magnesium_radio_control_impl::get_tx_filter( + const std::string& name, const size_t) +{ + if (_mpm_compat_num[0] < 4 || (_mpm_compat_num[0] == 4 && _mpm_compat_num[1] < 2)) { + RFNOC_LOG_WARNING("Getting tx filter not supported. Please upgrade MPM to a " + "minimum version of 4.2."); + return std::make_shared<uhd::digital_filter_fir<int16_t>>( + uhd::filter_info_base::filter_type::DIGITAL_FIR_I16, + false, + 0, + 1.0, + 1, + 1, + 32767, + AD9371_TX_MAX_FIR_TAPS, + std::vector<int16_t>(AD9371_TX_MAX_FIR_TAPS, 0)); + } + + const auto rv = _ad9371->get_fir(name); + const auto taps = rv.second; + // TODO: Use gain in the digital_filter_fir + return std::make_shared<uhd::digital_filter_fir<int16_t>>( + uhd::filter_info_base::filter_type::DIGITAL_FIR_I16, + false, + 0, + 1.0, + 1, + 1, + 32767, + AD9371_TX_MAX_FIR_TAPS, + taps); +} + +void magnesium_radio_control_impl::set_tx_filter( + const std::string& name, uhd::filter_info_base::sptr filter, const size_t) +{ + std::lock_guard<std::recursive_mutex> l(_set_lock); + + if (_mpm_compat_num[0] < 4 || (_mpm_compat_num[0] == 4 && _mpm_compat_num[1] < 2)) { + RFNOC_LOG_WARNING("Setting tx filter not supported. Please upgrade MPM to a " + "minimum version of 4.2."); + return; + } + + auto fir = std::dynamic_pointer_cast<uhd::digital_filter_fir<int16_t>>(filter); + if (fir == nullptr) { + throw uhd::runtime_error("Invalid Filter Type for TX Filter"); + } + if (fir->get_taps().size() != AD9371_TX_MAX_FIR_TAPS) { + throw uhd::runtime_error("AD937x TX Filter Taps must be " + + std::to_string(AD9371_TX_MAX_FIR_TAPS) + + " taps long!"); + } + // TODO: Use gain in the digital_filter_fir + _ad9371->set_fir(name, 6, fir->get_taps()); +} + +/************************************************************************** * Radio Identification API Calls *************************************************************************/ size_t magnesium_radio_control_impl::get_chan_from_dboard_fe( |