diff options
author | Josh Blum <josh@joshknows.com> | 2010-03-29 00:45:26 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-03-29 00:45:26 -0700 |
commit | 86fffe7f9ed78a682879dd56c26628256f89e6ae (patch) | |
tree | dbad6c804cadc80baf69fd53fe86ee251d2a28f6 /host/lib | |
parent | 3b02823640f3d7724c4d517114698285e914d735 (diff) | |
download | uhd-86fffe7f9ed78a682879dd56c26628256f89e6ae.tar.gz uhd-86fffe7f9ed78a682879dd56c26628256f89e6ae.tar.bz2 uhd-86fffe7f9ed78a682879dd56c26628256f89e6ae.zip |
Added tune helper to utils.
Takes a subdevice and dxc properties object and tunes them.
Made use of tune helper in simple device.
Moved gain handler into utils header dir.
Diffstat (limited to 'host/lib')
-rw-r--r-- | host/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/lib/gain_handler.cpp | 2 | ||||
-rw-r--r-- | host/lib/simple_device.cpp | 74 | ||||
-rw-r--r-- | host/lib/tune_helper.cpp | 125 | ||||
-rw-r--r-- | host/lib/usrp/dboard_manager.cpp | 2 |
5 files changed, 131 insertions, 73 deletions
diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index 1eceb53ea..55034c780 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -23,6 +23,7 @@ SET(libuhd_sources gain_handler.cpp load_modules.cpp simple_device.cpp + tune_helper.cpp types.cpp wax.cpp transport/if_addrs.cpp diff --git a/host/lib/gain_handler.cpp b/host/lib/gain_handler.cpp index a6ae06c50..daf629f0b 100644 --- a/host/lib/gain_handler.cpp +++ b/host/lib/gain_handler.cpp @@ -15,7 +15,7 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // -#include <uhd/gain_handler.hpp> +#include <uhd/utils/gain_handler.hpp> #include <uhd/utils/assert.hpp> #include <uhd/types/ranges.hpp> #include <uhd/props.hpp> diff --git a/host/lib/simple_device.cpp b/host/lib/simple_device.cpp index 95bc8fecc..d507762a9 100644 --- a/host/lib/simple_device.cpp +++ b/host/lib/simple_device.cpp @@ -16,8 +16,8 @@ // #include <uhd/simple_device.hpp> +#include <uhd/utils/tune_helper.hpp> #include <uhd/utils/assert.hpp> -#include <uhd/utils/algorithm.hpp> #include <uhd/props.hpp> #include <boost/algorithm/string.hpp> #include <boost/foreach.hpp> @@ -27,64 +27,6 @@ using namespace uhd; /*********************************************************************** - * Tune Helper Function - **********************************************************************/ -static tune_result_t tune( - double target_freq, - double lo_offset, - wax::obj subdev, - wax::obj dxc, - bool is_tx -){ - wax::obj subdev_freq_proxy = subdev[SUBDEV_PROP_FREQ]; - bool subdev_quadrature = subdev[SUBDEV_PROP_QUADRATURE].as<bool>(); - bool subdev_spectrum_inverted = subdev[SUBDEV_PROP_SPECTRUM_INVERTED].as<bool>(); - wax::obj dxc_freq_proxy = dxc[std::string("freq")]; - double dxc_sample_rate = dxc[std::string("rate")].as<double>(); - - // Ask the d'board to tune as closely as it can to target_freq+lo_offset - double target_inter_freq = target_freq + lo_offset; - subdev_freq_proxy = target_inter_freq; - double actual_inter_freq = subdev_freq_proxy.as<double>(); - - // 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); - delta_freq *= delta_sign; - delta_freq = fmod(delta_freq, dxc_sample_rate); - bool inverted = delta_freq > dxc_sample_rate/2.0; - double target_dxc_freq = inverted? (delta_freq - dxc_sample_rate) : (-delta_freq); - target_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){ - target_dxc_freq *= -1.0; - inverted = not inverted; - } - // down conversion versus up conversion, fight! - // your mother is ugly and your going down... - target_dxc_freq *= (is_tx)? -1.0 : +1.0; - - dxc_freq_proxy = target_dxc_freq; - double actual_dxc_freq = dxc_freq_proxy.as<double>(); - - //return some kind of tune result tuple/struct - tune_result_t tune_result; - tune_result.target_inter_freq = target_inter_freq; - tune_result.actual_inter_freq = actual_inter_freq; - tune_result.target_dxc_freq = target_dxc_freq; - tune_result.actual_dxc_freq = actual_dxc_freq; - tune_result.spectrum_inverted = inverted; - return tune_result; -} - -/*********************************************************************** * Helper Functions **********************************************************************/ static std::string trim(const std::string &in){ @@ -190,12 +132,7 @@ public: } tune_result_t set_rx_freq(double target_freq){ - double lo_offset = 0.0; - //if the local oscillator will be in the passband, use an offset - if (_rx_subdev[SUBDEV_PROP_LO_INTERFERES].as<bool>()){ - lo_offset = get_rx_rate()*2.0; - } - return tune(target_freq, lo_offset, _rx_subdev, _rx_ddc, false/* not tx */); + return tune_rx_subdev_and_ddc(_rx_subdev, _rx_ddc, target_freq); } freq_range_t get_rx_freq_range(void){ @@ -246,12 +183,7 @@ public: } tune_result_t set_tx_freq(double target_freq){ - double lo_offset = 0.0; - //if the local oscillator will be in the passband, use an offset - if (_tx_subdev[SUBDEV_PROP_LO_INTERFERES].as<bool>()){ - lo_offset = get_tx_rate()*2.0; - } - return tune(target_freq, lo_offset, _tx_subdev, _tx_duc, true/* is tx */); + return tune_tx_subdev_and_duc(_tx_subdev, _tx_duc, target_freq); } freq_range_t get_tx_freq_range(void){ diff --git a/host/lib/tune_helper.cpp b/host/lib/tune_helper.cpp new file mode 100644 index 000000000..eeda0b6be --- /dev/null +++ b/host/lib/tune_helper.cpp @@ -0,0 +1,125 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#include <uhd/utils/tune_helper.hpp> +#include <uhd/utils/algorithm.hpp> +#include <uhd/props.hpp> +#include <cmath> + +using namespace uhd; + +/*********************************************************************** + * Tune Helper Function + **********************************************************************/ +static tune_result_t tune_xx_subdev_and_dxc( + bool is_tx, + wax::obj subdev, wax::obj dxc, + double target_freq, double lo_offset +){ + wax::obj subdev_freq_proxy = subdev[SUBDEV_PROP_FREQ]; + bool subdev_quadrature = subdev[SUBDEV_PROP_QUADRATURE].as<bool>(); + bool subdev_spectrum_inverted = subdev[SUBDEV_PROP_SPECTRUM_INVERTED].as<bool>(); + wax::obj dxc_freq_proxy = dxc[std::string("freq")]; + double dxc_sample_rate = dxc[std::string("rate")].as<double>(); + + // Ask the d'board to tune as closely as it can to target_freq+lo_offset + double target_inter_freq = target_freq + lo_offset; + subdev_freq_proxy = target_inter_freq; + double actual_inter_freq = subdev_freq_proxy.as<double>(); + + // 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); + delta_freq *= delta_sign; + delta_freq = std::fmod(delta_freq, dxc_sample_rate); + bool inverted = delta_freq > dxc_sample_rate/2.0; + double target_dxc_freq = inverted? (delta_freq - dxc_sample_rate) : (-delta_freq); + target_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){ + target_dxc_freq *= -1.0; + inverted = not inverted; + } + // down conversion versus up conversion, fight! + // your mother is ugly and your going down... + target_dxc_freq *= (is_tx)? -1.0 : +1.0; + + dxc_freq_proxy = target_dxc_freq; + double actual_dxc_freq = dxc_freq_proxy.as<double>(); + + //return some kind of tune result tuple/struct + tune_result_t tune_result; + tune_result.target_inter_freq = target_inter_freq; + tune_result.actual_inter_freq = actual_inter_freq; + tune_result.target_dxc_freq = target_dxc_freq; + tune_result.actual_dxc_freq = actual_dxc_freq; + tune_result.spectrum_inverted = inverted; + return tune_result; +} + +/*********************************************************************** + * RX Tune + **********************************************************************/ +tune_result_t uhd::tune_rx_subdev_and_ddc( + wax::obj subdev, wax::obj ddc, + double target_freq, double lo_offset +){ + bool is_tx = false; + return tune_xx_subdev_and_dxc(is_tx, subdev, ddc, target_freq, lo_offset); +} + +tune_result_t uhd::tune_rx_subdev_and_ddc( + wax::obj subdev, wax::obj ddc, + double target_freq +){ + double lo_offset = 0.0; + //if the local oscillator will be in the passband, use an offset + if (subdev[SUBDEV_PROP_LO_INTERFERES].as<bool>()){ + lo_offset = 2.0*ddc[std::string("rate")].as<double>()/ddc[std::string("decim")].as<size_t>(); + } + return tune_rx_subdev_and_ddc(subdev, ddc, target_freq, lo_offset); +} + +/*********************************************************************** + * TX Tune + **********************************************************************/ +tune_result_t uhd::tune_tx_subdev_and_duc( + wax::obj subdev, wax::obj duc, + double target_freq, double lo_offset +){ + bool is_tx = true; + return tune_xx_subdev_and_dxc(is_tx, subdev, duc, target_freq, lo_offset); +} + +tune_result_t uhd::tune_tx_subdev_and_duc( + wax::obj subdev, wax::obj duc, + double target_freq +){ + double lo_offset = 0.0; + //if the local oscillator will be in the passband, use an offset + if (subdev[SUBDEV_PROP_LO_INTERFERES].as<bool>()){ + lo_offset = 2.0*duc[std::string("rate")].as<double>()/duc[std::string("interp")].as<size_t>(); + } + return tune_tx_subdev_and_duc(subdev, duc, target_freq, lo_offset); +} diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp index bc9bfbf14..f86545696 100644 --- a/host/lib/usrp/dboard_manager.cpp +++ b/host/lib/usrp/dboard_manager.cpp @@ -16,7 +16,7 @@ // #include <uhd/usrp/dboard_manager.hpp> -#include <uhd/gain_handler.hpp> +#include <uhd/utils/gain_handler.hpp> #include <uhd/utils/static.hpp> #include <uhd/utils/assert.hpp> #include <uhd/types/dict.hpp> |