diff options
| author | Josh Blum <josh@joshknows.com> | 2010-01-29 16:07:14 -0800 | 
|---|---|---|
| committer | Josh Blum <josh@joshknows.com> | 2010-01-29 16:07:14 -0800 | 
| commit | 027cfcb163451d76c1fb711e0ae1fadf064dc996 (patch) | |
| tree | 0eddf7bb2049627f2873be46bc0331307fc4d303 /include/usrp_uhd/utils.hpp | |
| parent | 30a8d2ecc36ce8ad6c01032e514ac66a277f06d0 (diff) | |
| download | uhd-027cfcb163451d76c1fb711e0ae1fadf064dc996.tar.gz uhd-027cfcb163451d76c1fb711e0ae1fadf064dc996.tar.bz2 uhd-027cfcb163451d76c1fb711e0ae1fadf064dc996.zip | |
added utility convenience tune function (wip)
Diffstat (limited to 'include/usrp_uhd/utils.hpp')
| -rw-r--r-- | include/usrp_uhd/utils.hpp | 53 | 
1 files changed, 52 insertions, 1 deletions
| 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;      } | 
