From f73a3688069b69327f6837871e0b524125c67038 Mon Sep 17 00:00:00 2001 From: Jason Abele Date: Fri, 11 Jun 2010 18:22:01 -0700 Subject: Fixed USRP2 aux_dac numbering convention --- host/lib/usrp/dboard/db_rfx.cpp | 2 +- host/lib/usrp/usrp2/dboard_iface.cpp | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) (limited to 'host/lib/usrp') diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp index 17fc00d24..2585dfa8d 100644 --- a/host/lib/usrp/dboard/db_rfx.cpp +++ b/host/lib/usrp/dboard/db_rfx.cpp @@ -257,7 +257,7 @@ void rfx_xcvr::set_rx_gain(float gain, const std::string &name){ _rx_gains[name] = gain; //write the new voltage to the aux dac - this->get_iface()->write_aux_dac(dboard_iface::UNIT_RX, 1, dac_volts); + this->get_iface()->write_aux_dac(dboard_iface::UNIT_RX, 0, dac_volts); } else UHD_THROW_INVALID_CODE_PATH(); } diff --git a/host/lib/usrp/usrp2/dboard_iface.cpp b/host/lib/usrp/usrp2/dboard_iface.cpp index 9f7c7f9e6..244f502a4 100644 --- a/host/lib/usrp/usrp2/dboard_iface.cpp +++ b/host/lib/usrp/usrp2/dboard_iface.cpp @@ -25,7 +25,7 @@ #include //htonl and ntohl #include #include "ad7922_regs.hpp" //aux adc -#include "ad5624_regs.hpp" //aux dac +#include "ad5623_regs.hpp" //aux dac using namespace uhd; using namespace uhd::usrp; @@ -72,7 +72,7 @@ private: boost::uint32_t _ddr_shadow; boost::uint32_t _gpio_shadow; - uhd::dict _dac_regs; + uhd::dict _dac_regs; void _write_aux_dac(unit_t); }; @@ -99,12 +99,12 @@ usrp2_dboard_iface::usrp2_dboard_iface( _gpio_shadow = 0; //reset the aux dacs - _dac_regs[UNIT_RX] = ad5624_regs_t(); - _dac_regs[UNIT_TX] = ad5624_regs_t(); + _dac_regs[UNIT_RX] = ad5623_regs_t(); + _dac_regs[UNIT_TX] = ad5623_regs_t(); BOOST_FOREACH(unit_t unit, _dac_regs.keys()){ _dac_regs[unit].data = 1; - _dac_regs[unit].addr = ad5624_regs_t::ADDR_ALL; - _dac_regs[unit].cmd = ad5624_regs_t::CMD_RESET; + _dac_regs[unit].addr = ad5623_regs_t::ADDR_ALL; + _dac_regs[unit].cmd = ad5623_regs_t::CMD_RESET; this->_write_aux_dac(unit); } } @@ -242,12 +242,14 @@ void usrp2_dboard_iface::_write_aux_dac(unit_t unit){ void usrp2_dboard_iface::write_aux_dac(unit_t unit, int which, float value){ _dac_regs[unit].data = boost::math::iround(4095*value/3.3); - _dac_regs[unit].cmd = ad5624_regs_t::CMD_WR_UP_DAC_CHAN_N; + _dac_regs[unit].cmd = ad5623_regs_t::CMD_WR_UP_DAC_CHAN_N; + //standardize on USRP1 interface, A=0, B=1, C=2, D=3 + //FIXME josh reccommends the use of a nested dictionary switch(which){ - case 0: _dac_regs[unit].addr = ad5624_regs_t::ADDR_DAC_A; break; - case 1: _dac_regs[unit].addr = ad5624_regs_t::ADDR_DAC_B; break; - case 2: _dac_regs[unit].addr = ad5624_regs_t::ADDR_DAC_C; break; - case 3: _dac_regs[unit].addr = ad5624_regs_t::ADDR_DAC_D; break; + case 0: _dac_regs[unit].addr = unit == dboard_iface::UNIT_RX ? ad5623_regs_t::ADDR_DAC_B : ad5623_regs_t::ADDR_DAC_A; break; + case 1: _dac_regs[unit].addr = unit == dboard_iface::UNIT_RX ? ad5623_regs_t::ADDR_DAC_A : ad5623_regs_t::ADDR_DAC_B; break; + case 2: _dac_regs[unit].addr = unit == dboard_iface::UNIT_RX ? ad5623_regs_t::ADDR_DAC_A : ad5623_regs_t::ADDR_DAC_B; break; + case 3: _dac_regs[unit].addr = unit == dboard_iface::UNIT_RX ? ad5623_regs_t::ADDR_DAC_B : ad5623_regs_t::ADDR_DAC_A; break; default: throw std::runtime_error("not a possible aux dac, must be 0, 1, 2, or 3"); } this->_write_aux_dac(unit); -- cgit v1.2.3 From 0c6fbdfe3738e2d15b369fbd28d51ee0115628f9 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 14 Jun 2010 10:44:50 -0700 Subject: work on algorithms and documentation --- host/include/uhd/utils/algorithm.hpp | 72 ++++++++++++++++++++++++++++++++---- host/lib/device.cpp | 8 +--- host/lib/usrp/tune_helper.cpp | 2 +- 3 files changed, 68 insertions(+), 14 deletions(-) (limited to 'host/lib/usrp') diff --git a/host/include/uhd/utils/algorithm.hpp b/host/include/uhd/utils/algorithm.hpp index 146b56c63..08977a69f 100644 --- a/host/include/uhd/utils/algorithm.hpp +++ b/host/include/uhd/utils/algorithm.hpp @@ -19,31 +19,89 @@ #define INCLUDED_UHD_UTILS_ALGORITHM_HPP #include -#include +#include +#include +#include -/*! - * Useful templated functions and classes that I like to pretend are part of stl +/*! \file algorithm.hpp + * Useful templated functions and classes that I like to pretend are part of stl. + * Many of the range wrapper functions come with recent versions of boost (1.43). */ namespace std{ + /*! + * A wrapper around std::copy that takes ranges instead of iterators. + * + * Copy the elements of the source range into the destination range. + * The destination range should be at least as large as the source range. + * + * \param src the range of elements to copy from + * \param dst the range of elements to be filled + */ template inline void copy(const RangeSrc &src, RangeDst &dst){ std::copy(boost::begin(src), boost::end(src), boost::begin(dst)); } + /*! + * A wrapper around std::sort that takes a range instead of an iterator. + * + * The elements are sorted into ascending order using the less-than operator. + * + * \param range the range of elements to be sorted + */ + template inline void sort(Range &range){ + return std::sort(boost::begin(range), boost::end(range)); + } + + /*! + * A wrapper around std::sort that takes a range instead of an iterator. + * + * The elements are sorted into ascending order using the less-than operator. + * This wrapper sorts the elements non-destructively into a new range. + * Based on the builtin python function sorted(...) + * + * \param range the range of elements to be sorted + * \return a new range with the elements sorted + */ + template inline Range sorted(const Range &range){ + Range srange(range); std::sort(srange); return srange; + } + + /*! + * Is the value found within the elements in this range? + * + * Uses std::find to search the iterable for an element. + * + * \param range the elements to search through + * \param value the match to look for in the range + * \return true when the value is found in the range + */ template inline bool has(const Range &range, const T &value){ return boost::end(range) != std::find(boost::begin(range), boost::end(range), value); } - template inline T signum(T n){ + /*! + * A templated signum implementation. + * \param n the comparable to process + * \return -1 when n negative, +1 when n positive, otherwise 0 + */ + template inline int signum(T n){ if (n < 0) return -1; - if (n > 0) return 1; + if (n > 0) return +1; return 0; } - template inline T clip(T val, T minVal, T maxVal){ - return std::min(std::max(val, minVal), maxVal); + /*! + * A templated clip implementation. + * \param val the value to clip between an upper and lower limit + * \param bound1 the upper or lower bound + * \param bound2 the upper or lower bound + * \return the value clipped at the bounds + */ + template inline T clip(T val, T bound1, T bound2){ + return std::min(std::max(val, std::min(bound1, bound2)), std::max(bound1, bound2)); } }//namespace std diff --git a/host/lib/device.cpp b/host/lib/device.cpp index f139ecb20..431595c4f 100644 --- a/host/lib/device.cpp +++ b/host/lib/device.cpp @@ -19,13 +19,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include using namespace uhd; @@ -41,13 +41,9 @@ using namespace uhd; static size_t hash_device_addr( const device_addr_t &dev_addr ){ - //sort the keys of the device address - std::vector keys = dev_addr.keys(); - std::sort(keys.begin(), keys.end()); - //combine the hashes of sorted keys/value pairs size_t hash = 0; - BOOST_FOREACH(const std::string &key, keys){ + BOOST_FOREACH(const std::string &key, std::sorted(dev_addr.keys())){ boost::hash_combine(hash, key); boost::hash_combine(hash, dev_addr[key]); } diff --git a/host/lib/usrp/tune_helper.cpp b/host/lib/usrp/tune_helper.cpp index a7d695b4e..082c39f6d 100644 --- a/host/lib/usrp/tune_helper.cpp +++ b/host/lib/usrp/tune_helper.cpp @@ -46,7 +46,7 @@ static tune_result_t tune_xx_subdev_and_dxc( // Calculate the DDC setting that will downconvert the baseband from the // daughterboard to our target frequency. double delta_freq = target_freq - actual_inter_freq; - double delta_sign = std::signum(delta_freq); + int delta_sign = std::signum(delta_freq); delta_freq *= delta_sign; delta_freq = std::fmod(delta_freq, dxc_sample_rate); bool inverted = delta_freq > dxc_sample_rate/2.0; -- cgit v1.2.3 From 73ea268536e83b8961bea4a0f825ac68f3da2f2b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 14 Jun 2010 18:47:22 -0700 Subject: usrp2: dboard iface: switched to nested dictionary for dac regs --- host/lib/usrp/usrp2/dboard_iface.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'host/lib/usrp') diff --git a/host/lib/usrp/usrp2/dboard_iface.cpp b/host/lib/usrp/usrp2/dboard_iface.cpp index 244f502a4..114f83f41 100644 --- a/host/lib/usrp/usrp2/dboard_iface.cpp +++ b/host/lib/usrp/usrp2/dboard_iface.cpp @@ -244,14 +244,23 @@ void usrp2_dboard_iface::write_aux_dac(unit_t unit, int which, float value){ _dac_regs[unit].data = boost::math::iround(4095*value/3.3); _dac_regs[unit].cmd = ad5623_regs_t::CMD_WR_UP_DAC_CHAN_N; //standardize on USRP1 interface, A=0, B=1, C=2, D=3 - //FIXME josh reccommends the use of a nested dictionary - switch(which){ - case 0: _dac_regs[unit].addr = unit == dboard_iface::UNIT_RX ? ad5623_regs_t::ADDR_DAC_B : ad5623_regs_t::ADDR_DAC_A; break; - case 1: _dac_regs[unit].addr = unit == dboard_iface::UNIT_RX ? ad5623_regs_t::ADDR_DAC_A : ad5623_regs_t::ADDR_DAC_B; break; - case 2: _dac_regs[unit].addr = unit == dboard_iface::UNIT_RX ? ad5623_regs_t::ADDR_DAC_A : ad5623_regs_t::ADDR_DAC_B; break; - case 3: _dac_regs[unit].addr = unit == dboard_iface::UNIT_RX ? ad5623_regs_t::ADDR_DAC_B : ad5623_regs_t::ADDR_DAC_A; break; - default: throw std::runtime_error("not a possible aux dac, must be 0, 1, 2, or 3"); - } + static const uhd::dict< + unit_t, uhd::dict + > unit_to_which_to_addr = map_list_of + (UNIT_RX, map_list_of + (0, ad5623_regs_t::ADDR_DAC_B) + (1, ad5623_regs_t::ADDR_DAC_A) + (2, ad5623_regs_t::ADDR_DAC_A) + (3, ad5623_regs_t::ADDR_DAC_B) + ) + (UNIT_TX, map_list_of + (0, ad5623_regs_t::ADDR_DAC_A) + (1, ad5623_regs_t::ADDR_DAC_B) + (2, ad5623_regs_t::ADDR_DAC_B) + (3, ad5623_regs_t::ADDR_DAC_A) + ) + ; + _dac_regs[unit].addr = unit_to_which_to_addr[unit][which]; this->_write_aux_dac(unit); } -- cgit v1.2.3