diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/usrp_uhd/device.hpp | 6 | ||||
-rw-r--r-- | include/usrp_uhd/utils.hpp | 53 |
2 files changed, 55 insertions, 4 deletions
diff --git a/include/usrp_uhd/device.hpp b/include/usrp_uhd/device.hpp index 3ef4a79cf..73f28e2cd 100644 --- a/include/usrp_uhd/device.hpp +++ b/include/usrp_uhd/device.hpp @@ -11,8 +11,8 @@ #include <boost/utility.hpp> #include <boost/shared_ptr.hpp> #include <boost/function.hpp> -#include <vector> #include <boost/asio/buffer.hpp> +#include <vector> namespace usrp_uhd{ @@ -26,9 +26,9 @@ public: typedef boost::shared_ptr<device> sptr; //argument types for send and recv raw methods - //the send args is convertable to a boost asio buffer + //the send args is a vector of the boost asio buffers //the recv args is a callback that takes a boost asio buffer - typedef boost::asio::const_buffer send_args_t; + typedef std::vector<boost::asio::const_buffer> send_args_t; typedef boost::function<bool(const boost::asio::const_buffer &)> recv_args_t; //structors diff --git a/include/usrp_uhd/utils.hpp b/include/usrp_uhd/utils.hpp index c1b2bad5c..ef2362453 100644 --- a/include/usrp_uhd/utils.hpp +++ b/include/usrp_uhd/utils.hpp @@ -2,6 +2,7 @@ // Copyright 2010 Ettus Research LLC // +#include <usrp_uhd/wax.hpp> #include <boost/foreach.hpp> #include <boost/format.hpp> #include <boost/function.hpp> @@ -25,6 +26,56 @@ std::vector<Key> get_map_keys(const std::map<Key, T> &m){ return v; } +template<typename T> T signum(T n){ + if (n < 0) return -1; + if (n > 0) return 1; + return 0; +} + +inline void tune( + freq_t target_freq, + freq_t lo_offset, + wax::proxy subdev_freq_proxy, + bool subdev_quadrature, + bool subdev_spectrum_inverted, + bool subdev_is_tx, + wax::proxy dsp_freq_proxy, + freq_t dsp_sample_rate +){ + // Ask the d'board to tune as closely as it can to target_freq+lo_offset + subdev_freq_proxy = target_freq + lo_offset; + freq_t inter_freq = wax::cast<freq_t>(subdev_freq_proxy); + + // Calculate the DDC setting that will downconvert the baseband from the + // daughterboard to our target frequency. + freq_t delta_freq = target_freq - inter_freq; + int delta_sign = signum(delta_freq); + delta_freq *= delta_sign; + delta_freq = fmod(delta_freq, dsp_sample_rate); + bool inverted = delta_freq > dsp_sample_rate/2.0; + freq_t dxc_freq = inverted? (delta_freq - dsp_sample_rate) : (-delta_freq); + dxc_freq *= delta_sign; + + // If the spectrum is inverted, and the daughterboard doesn't do + // quadrature downconversion, we can fix the inversion by flipping the + // sign of the dxc_freq... (This only happens using the basic_rx board) + if (subdev_spectrum_inverted){ + inverted = not inverted; + } + if (inverted and not subdev_quadrature){ + dxc_freq = -dxc_freq; + inverted = not inverted; + } + if (subdev_is_tx){ + dxc_freq = -dxc_freq; // down conversion versus up conversion + } + + dsp_freq_proxy = dxc_freq; + //freq_t actual_dxc_freq = wax::cast<freq_t>(dsp_freq_proxy); + + //return some kind of tune result tuple/struct +} + } //namespace usrp_uhd /*! @@ -57,7 +108,7 @@ namespace std{ return last != std::find(first, last, elem); } - template <class T> + template<class T> T sum(const T &a, const T &b){ return a + b; } |