diff options
author | Martin Braun <martin.braun@ettus.com> | 2018-09-20 10:16:27 -0700 |
---|---|---|
committer | Brent Stapleton <bstapleton@g.hmc.edu> | 2018-10-17 13:49:48 -0700 |
commit | 20855e30f90b004b0746b7456d797e783115f17c (patch) | |
tree | 724713dff5cb25a6f818436535aa054e17d514f2 /host/lib | |
parent | e0d4f92d0543fcc6fbd63241c833feca7aa91c9d (diff) | |
download | uhd-20855e30f90b004b0746b7456d797e783115f17c.tar.gz uhd-20855e30f90b004b0746b7456d797e783115f17c.tar.bz2 uhd-20855e30f90b004b0746b7456d797e783115f17c.zip |
lib: ad9361: De-boostify AD9361 driver
No functional or API changes.
Diffstat (limited to 'host/lib')
-rw-r--r-- | host/lib/usrp/common/ad9361_driver/ad9361_device.cpp | 120 | ||||
-rw-r--r-- | host/lib/usrp/common/ad9361_driver/ad9361_device.h | 181 |
2 files changed, 195 insertions, 106 deletions
diff --git a/host/lib/usrp/common/ad9361_driver/ad9361_device.cpp b/host/lib/usrp/common/ad9361_driver/ad9361_device.cpp index 9273edb02..812de28dc 100644 --- a/host/lib/usrp/common/ad9361_driver/ad9361_device.cpp +++ b/host/lib/usrp/common/ad9361_driver/ad9361_device.cpp @@ -1512,7 +1512,7 @@ double ad9361_device_t::_setup_rates(const double rate) **********************************************************************/ void ad9361_device_t::initialize() { - boost::lock_guard<boost::recursive_mutex> lock(_mutex); + std::lock_guard<std::recursive_mutex> lock(_mutex); /* Initialize shadow registers. */ _regs.vcodivs = 0x00; @@ -1784,7 +1784,7 @@ void ad9361_device_t::set_io_iface(ad9361_io::sptr io_iface) * This is the only clock setting function that is exposed to the outside. */ double ad9361_device_t::set_clock_rate(const double req_rate) { - boost::lock_guard<boost::recursive_mutex> lock(_mutex); + std::lock_guard<std::recursive_mutex> lock(_mutex); if (req_rate > 61.44e6) { throw uhd::runtime_error("[ad9361_device_t] Requested master clock rate outside range"); @@ -1933,7 +1933,7 @@ double ad9361_device_t::set_clock_rate(const double req_rate) */ void ad9361_device_t::set_active_chains(bool tx1, bool tx2, bool rx1, bool rx2) { - boost::lock_guard<boost::recursive_mutex> lock(_mutex); + std::lock_guard<std::recursive_mutex> lock(_mutex); /* Clear out the current active chain settings. */ _regs.txfilt = _regs.txfilt & 0x3F; @@ -2035,7 +2035,7 @@ void ad9361_device_t::set_timing_mode(const ad9361_device_t::timing_mode_t timin * After tuning, it runs any appropriate calibrations. */ double ad9361_device_t::tune(direction_t direction, const double value) { - boost::lock_guard<boost::recursive_mutex> lock(_mutex); + std::lock_guard<std::recursive_mutex> lock(_mutex); double last_cal_freq; if (direction == RX) { @@ -2108,7 +2108,7 @@ double ad9361_device_t::tune(direction_t direction, const double value) /* Get the current RX or TX frequency. */ double ad9361_device_t::get_freq(direction_t direction) { - boost::lock_guard<boost::recursive_mutex> lock(_mutex); + std::lock_guard<std::recursive_mutex> lock(_mutex); if (direction == RX) return _rx_freq; @@ -2123,7 +2123,7 @@ double ad9361_device_t::get_freq(direction_t direction) * the TX chains are done in terms of attenuation. */ double ad9361_device_t::set_gain(direction_t direction, chain_t chain, const double value) { - boost::lock_guard<boost::recursive_mutex> lock(_mutex); + std::lock_guard<std::recursive_mutex> lock(_mutex); if (direction == RX) { @@ -2174,7 +2174,7 @@ double ad9361_device_t::set_gain(direction_t direction, chain_t chain, const dou void ad9361_device_t::output_test_tone() // On RF side! { - boost::lock_guard<boost::recursive_mutex> lock(_mutex); + std::lock_guard<std::recursive_mutex> lock(_mutex); /* Output a 480 kHz tone at 800 MHz */ _io_iface->poke8(0x3F4, 0x0B); _io_iface->poke8(0x3FC, 0xFF); @@ -2184,13 +2184,13 @@ void ad9361_device_t::output_test_tone() // On RF side! void ad9361_device_t::digital_test_tone(bool enb) // Digital output { - boost::lock_guard<boost::recursive_mutex> lock(_mutex); + std::lock_guard<std::recursive_mutex> lock(_mutex); _io_iface->poke8(0x3F4, 0x02 | (enb ? 0x01 : 0x00)); } void ad9361_device_t::data_port_loopback(const bool loopback_enabled) { - boost::lock_guard<boost::recursive_mutex> lock(_mutex); + std::lock_guard<std::recursive_mutex> lock(_mutex); _io_iface->poke8(0x3F5, (loopback_enabled ? 0x01 : 0x00)); } @@ -2396,56 +2396,68 @@ void ad9361_device_t::set_agc_mode(chain_t chain, gain_mode_t gain_mode) std::vector<std::string> ad9361_device_t::get_filter_names(direction_t direction) { - std::vector<std::string> ret; - if(direction == RX) { - for(std::map<std::string, filter_query_helper>::iterator it = _rx_filters.begin(); it != _rx_filters.end(); ++it) { - ret.push_back(it->first); - } - } else if (direction == TX) - { - for(std::map<std::string, filter_query_helper>::iterator it = _tx_filters.begin(); it != _tx_filters.end(); ++it) { - ret.push_back(it->first); - } - } - return ret; -} + auto& filters = (direction == RX) + ? _rx_filters + : _tx_filters + ; -filter_info_base::sptr ad9361_device_t::get_filter(direction_t direction, chain_t chain, const std::string &name) -{ - if(direction == RX) { - if (not _rx_filters[name].get) - { - throw uhd::runtime_error("ad9361_device_t::get_filter this filter can not be read."); - } - return _rx_filters[name].get(direction, chain); - } else if (direction == TX) { - if (not _tx_filters[name].get) - { - throw uhd::runtime_error("ad9361_device_t::get_filter this filter can not be read."); - } - return _tx_filters[name].get(direction, chain); + std::vector<std::string> ret; + ret.reserve(filters.size()); + for (auto& filter : filters) { + ret.push_back(filter.first); } - throw uhd::runtime_error("ad9361_device_t::get_filter wrong direction parameter."); + return ret; } -void ad9361_device_t::set_filter(direction_t direction, chain_t chain, const std::string &name, filter_info_base::sptr filter) -{ - - if(direction == RX) { - if(not _rx_filters[name].set) - { - throw uhd::runtime_error("ad9361_device_t::set_filter this filter can not be written."); - } - _rx_filters[name].set(direction, chain, filter); - } else if (direction == TX) { - if(not _tx_filters[name].set) - { - throw uhd::runtime_error("ad9361_device_t::set_filter this filter can not be written."); - } - _tx_filters[name].set(direction, chain, filter); - } - +filter_info_base::sptr ad9361_device_t::get_filter( + direction_t direction, + chain_t chain, + const std::string &name +) { + auto& filters = (direction == RX) + ? _rx_filters + : _tx_filters + ; + + if (!filters.count(name)) { + throw uhd::runtime_error( + "ad9361_device_t::get_filter this filter does not exist: " + name + ); + } + // Check entry 0 in the tuple (the getter) exists before calling it + if (!std::get<0>(filters[name])) { + throw uhd::runtime_error( + "ad9361_device_t::get_filter this filter can not be read: " + name + ); + } + return std::get<0>(filters[name])(chain); +} + +void ad9361_device_t::set_filter( + direction_t direction, + chain_t chain, + const std::string &name, + filter_info_base::sptr filter +) { + auto& filters = (direction == RX) + ? _rx_filters + : _tx_filters + ; + + if (!filters.count(name)) { + throw uhd::runtime_error( + "ad9361_device_t::set_filter this filter does not exist: " + name + ); + } + // Check entry 1 in the tuple (the setter) exists before calling it + if (!std::get<1>(filters[name])) { + throw uhd::runtime_error( + "ad9361_device_t::set_filter this filter can not be written: " + + name + ); + } + std::get<1>(filters[name])(chain, filter); } double ad9361_device_t::set_bw_filter(direction_t direction, const double rf_bw) diff --git a/host/lib/usrp/common/ad9361_driver/ad9361_device.h b/host/lib/usrp/common/ad9361_driver/ad9361_device.h index a42469035..2a81118ce 100644 --- a/host/lib/usrp/common/ad9361_driver/ad9361_device.h +++ b/host/lib/usrp/common/ad9361_driver/ad9361_device.h @@ -9,16 +9,15 @@ #define INCLUDED_AD9361_DEVICE_H #include <ad9361_client.h> -#include <boost/noncopyable.hpp> -#include <boost/thread/recursive_mutex.hpp> #include <uhd/types/filters.hpp> #include <uhd/types/sensors.hpp> +#include <boost/noncopyable.hpp> #include <complex> #include <vector> #include <map> -#include "boost/assign.hpp" -#include "boost/bind.hpp" -#include "boost/function.hpp" +#include <tuple> +#include <functional> +#include <mutex> namespace uhd { namespace usrp { @@ -38,37 +37,122 @@ public: _tfir_factor(0), _rfir_factor(0), _rx1_agc_mode(GAIN_MODE_MANUAL), _rx2_agc_mode(GAIN_MODE_MANUAL), _rx1_agc_enable(false), _rx2_agc_enable(false), - _use_dc_offset_tracking(false), _use_iq_balance_tracking(false) + _use_dc_offset_tracking(false), _use_iq_balance_tracking(false), + _rx_filters{ + {"LPF_TIA", std::make_tuple( + [this](const chain_t){ + return this->_get_filter_lp_tia_sec(RX); + }, + [this](const chain_t, filter_info_base::sptr filter_info){ + this->_set_filter_lp_tia_sec(RX, filter_info); + } + ) + }, + {"LPF_BB", std::make_tuple( + [this](const chain_t){ + return this->_get_filter_lp_bb(RX); + }, + [this](const chain_t, filter_info_base::sptr filter_info){ + this->_set_filter_lp_bb(RX, filter_info); + } + ) + }, + {"HB_3", std::make_tuple( + [this](const chain_t){ + return this->_get_filter_hb_3(RX); + }, + nullptr + ) + }, + {"DEC_3", std::make_tuple( + [this](const chain_t){ + return this->_get_filter_dec_int_3(RX); + }, + nullptr + ) + }, + {"HB_2", std::make_tuple( + [this](const chain_t){ + return this->_get_filter_hb_2(RX); + }, + nullptr + ) + }, + {"HB_1", std::make_tuple( + [this](const chain_t){ + return this->_get_filter_hb_1(RX); + }, + nullptr + ) + }, + {"FIR_1", std::make_tuple( + [this](const chain_t channel){ + return this->_get_filter_fir(RX, channel); + }, + [this](const chain_t channel, filter_info_base::sptr filter_info){ + this->_set_filter_fir(RX, channel, filter_info); + } + ) + } + }, + _tx_filters{ + {"LPF_SECONDARY", std::make_tuple( + [this](const chain_t){ + return this->_get_filter_lp_tia_sec(TX); + }, + [this](const chain_t, filter_info_base::sptr filter_info){ + this->_set_filter_lp_tia_sec(TX, filter_info); + } + ) + }, + {"LPF_BB", std::make_tuple( + [this](const chain_t){ + return this->_get_filter_lp_bb(TX); + }, + [this](const chain_t, filter_info_base::sptr filter_info){ + this->_set_filter_lp_bb(TX, filter_info); + } + ) + }, + {"HB_3", std::make_tuple( + [this](const chain_t){ + return this->_get_filter_hb_3(TX); + }, + nullptr + ) + }, + {"INT_3", std::make_tuple( + [this](const chain_t){ + return this->_get_filter_dec_int_3(TX); + }, + nullptr + ) + }, + {"HB_2", std::make_tuple( + [this](const chain_t){ + return this->_get_filter_hb_2(TX); + }, + nullptr + ) + }, + {"HB_1", std::make_tuple( + [this](const chain_t){ + return this->_get_filter_hb_1(TX); + }, + nullptr + ) + }, + {"FIR_1", std::make_tuple( + [this](const chain_t channel){ + return this->_get_filter_fir(TX, channel); + }, + [this](const chain_t channel, filter_info_base::sptr filter_info){ + this->_set_filter_fir(TX, channel, filter_info); + } + ) + }, + } { - - /* - * This Boost.Assign to_container() workaround is necessary because STL containers - * apparently confuse newer versions of MSVC. - * - * Source: http://www.boost.org/doc/libs/1_55_0/libs/assign/doc/#portability - */ - - _rx_filters = (boost::assign::map_list_of("LPF_TIA", filter_query_helper(boost::bind(&ad9361_device_t::_get_filter_lp_tia_sec, this, _1), - boost::bind(&ad9361_device_t::_set_filter_lp_tia_sec, this, _1, _3))) - ("LPF_BB", filter_query_helper(boost::bind(&ad9361_device_t::_get_filter_lp_bb, this, _1), - boost::bind(&ad9361_device_t::_set_filter_lp_bb, this, _1, _3))) - ("HB_3", filter_query_helper(boost::bind(&ad9361_device_t::_get_filter_hb_3, this, _1), 0)) - ("DEC_3", filter_query_helper(boost::bind(&ad9361_device_t::_get_filter_dec_int_3, this, _1), 0)) - ("HB_2", filter_query_helper(boost::bind(&ad9361_device_t::_get_filter_hb_2, this, _1), 0)) - ("HB_1", filter_query_helper(boost::bind(&ad9361_device_t::_get_filter_hb_1, this, _1), 0)) - ("FIR_1", filter_query_helper(boost::bind(&ad9361_device_t::_get_filter_fir, this, _1, _2), - boost::bind(&ad9361_device_t::_set_filter_fir, this, _1, _2, _3)))).to_container(_rx_filters); - - _tx_filters = (boost::assign::map_list_of("LPF_SECONDARY", filter_query_helper(boost::bind(&ad9361_device_t::_get_filter_lp_tia_sec, this, _1), - boost::bind(&ad9361_device_t::_set_filter_lp_tia_sec, this, _1, _3))) - ("LPF_BB", filter_query_helper(boost::bind(&ad9361_device_t::_get_filter_lp_bb, this, _1), - boost::bind(&ad9361_device_t::_set_filter_lp_bb, this, _1, _3))) - ("HB_3", filter_query_helper(boost::bind(&ad9361_device_t::_get_filter_hb_3, this, _1), 0)) - ("INT_3", filter_query_helper(boost::bind(&ad9361_device_t::_get_filter_dec_int_3, this, _1), 0)) - ("HB_2", filter_query_helper(boost::bind(&ad9361_device_t::_get_filter_hb_2, this, _1), 0)) - ("HB_1", filter_query_helper(boost::bind(&ad9361_device_t::_get_filter_hb_1, this, _1), 0)) - ("FIR_1", filter_query_helper(boost::bind(&ad9361_device_t::_get_filter_fir, this, _1, _2), - boost::bind(&ad9361_device_t::_set_filter_fir, this, _1, _2, _3)))).to_container(_tx_filters); } /* Initialize the AD9361 codec. */ @@ -233,22 +317,6 @@ private: //Members uint8_t bbftune_mode; }; - struct filter_query_helper - { - filter_query_helper( - boost::function<filter_info_base::sptr (direction_t, chain_t)> p_get, - boost::function<void (direction_t, chain_t, filter_info_base::sptr)> p_set - ) : get(p_get), set(p_set) { } - - filter_query_helper(){ } - - boost::function<filter_info_base::sptr (direction_t, chain_t)> get; - boost::function<void (direction_t, chain_t, filter_info_base::sptr)> set; - }; - - std::map<std::string, filter_query_helper> _rx_filters; - std::map<std::string, filter_query_helper> _tx_filters; - //Interfaces ad9361_params::sptr _client_params; ad9361_io::sptr _io_iface; @@ -276,9 +344,18 @@ private: //Members //Register soft-copies chip_regs_t _regs; //Synchronization - boost::recursive_mutex _mutex; + std::recursive_mutex _mutex; bool _use_dc_offset_tracking; bool _use_iq_balance_tracking; + + // Filter API + using filter_tuple = std::tuple< + std::function<filter_info_base::sptr(const chain_t)>, // getter + std::function<void(chain_t, filter_info_base::sptr)> // setter + >; + std::map<std::string, filter_tuple> _rx_filters; + std::map<std::string, filter_tuple> _tx_filters; + }; }} //namespace |