diff options
-rw-r--r-- | host/include/uhd/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/include/uhd/utils/CMakeLists.txt | 2 | ||||
-rw-r--r-- | host/include/uhd/utils/gain_handler.hpp (renamed from host/include/uhd/gain_handler.hpp) | 6 | ||||
-rw-r--r-- | host/include/uhd/utils/tune_helper.hpp | 79 | ||||
-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 | ||||
-rw-r--r-- | host/test/gain_handler_test.cpp | 2 |
10 files changed, 216 insertions, 78 deletions
diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt index 0cebea095..b364f78cd 100644 --- a/host/include/uhd/CMakeLists.txt +++ b/host/include/uhd/CMakeLists.txt @@ -24,7 +24,6 @@ ADD_SUBDIRECTORY(utils) INSTALL(FILES config.hpp device.hpp - gain_handler.hpp props.hpp simple_device.hpp wax.hpp diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt index f6ed87701..1b673f44a 100644 --- a/host/include/uhd/utils/CMakeLists.txt +++ b/host/include/uhd/utils/CMakeLists.txt @@ -18,7 +18,9 @@ INSTALL(FILES algorithm.hpp assert.hpp + gain_handler.hpp safe_main.hpp static.hpp + tune_helper.hpp DESTINATION ${INCLUDE_DIR}/uhd/utils ) diff --git a/host/include/uhd/gain_handler.hpp b/host/include/uhd/utils/gain_handler.hpp index 65d6cecf9..f4629e6a7 100644 --- a/host/include/uhd/gain_handler.hpp +++ b/host/include/uhd/utils/gain_handler.hpp @@ -15,8 +15,8 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // -#ifndef INCLUDED_UHD_GAIN_HANDLER_HPP -#define INCLUDED_UHD_GAIN_HANDLER_HPP +#ifndef INCLUDED_UHD_UTILS_GAIN_HANDLER_HPP +#define INCLUDED_UHD_UTILS_GAIN_HANDLER_HPP #include <uhd/config.hpp> #include <uhd/wax.hpp> @@ -86,5 +86,5 @@ public: } //namespace uhd -#endif /* INCLUDED_UHD_GAIN_HANDLER_HPP */ +#endif /* INCLUDED_UHD_UTILS_GAIN_HANDLER_HPP */ diff --git a/host/include/uhd/utils/tune_helper.hpp b/host/include/uhd/utils/tune_helper.hpp new file mode 100644 index 000000000..828575c99 --- /dev/null +++ b/host/include/uhd/utils/tune_helper.hpp @@ -0,0 +1,79 @@ +// +// 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/>. +// + +#ifndef INCLUDED_UHD_UTILS_TUNE_HELPER_HPP +#define INCLUDED_UHD_UTILS_TUNE_HELPER_HPP + +#include <uhd/config.hpp> +#include <uhd/wax.hpp> +#include <uhd/types/tune_result.hpp> + +namespace uhd{ + +/*! + * Tune a rx chain to the desired frequency: + * The IF of the subdevice is set as close as possible to + * the given target frequency + the LO offset (when applicable). + * The ddc cordic is setup to bring the IF down to baseband. + * \param subdev the dboard subdevice object with properties + * \param ddc the ddc properties object (with "rate", "decim", "freq") + * \param target_freq the desired center frequency + * \param lo_offset an offset for the subdevice IF from center + * \return a tune result struct + */ +UHD_API tune_result_t tune_rx_subdev_and_ddc( + wax::obj subdev, wax::obj ddc, + double target_freq, double lo_offset +); + +/*! + * Tune a rx chain to the desired frequency: + * Same as the above, except the LO offset + * is calculated based on the subdevice and BW. + */ +UHD_API tune_result_t tune_rx_subdev_and_ddc( + wax::obj subdev, wax::obj ddc, double target_freq +); + +/*! + * Tune a tx chain to the desired frequency: + * The IF of the subdevice is set as close as possible to + * the given target frequency + the LO offset (when applicable). + * The duc cordic is setup to bring the baseband up to IF. + * \param subdev the dboard subdevice object with properties + * \param duc the duc properties object (with "rate", "interp", "freq") + * \param target_freq the desired center frequency + * \param lo_offset an offset for the subdevice IF from center + * \return a tune result struct + */ +UHD_API tune_result_t tune_tx_subdev_and_duc( + wax::obj subdev, wax::obj duc, + double target_freq, double lo_offset +); + +/*! + * Tune a tx chain to the desired frequency: + * Same as the above, except the LO offset + * is calculated based on the subdevice and BW. + */ +UHD_API tune_result_t tune_tx_subdev_and_duc( + wax::obj subdev, wax::obj duc, double target_freq +); + +} //namespace uhd + +#endif /* INCLUDED_UHD_UTILS_TUNE_HELPER_HPP */ 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> diff --git a/host/test/gain_handler_test.cpp b/host/test/gain_handler_test.cpp index a7c6e1e82..76b065ce2 100644 --- a/host/test/gain_handler_test.cpp +++ b/host/test/gain_handler_test.cpp @@ -16,7 +16,7 @@ // #include <boost/test/unit_test.hpp> -#include <uhd/gain_handler.hpp> +#include <uhd/utils/gain_handler.hpp> #include <uhd/types/ranges.hpp> #include <uhd/types/dict.hpp> #include <uhd/props.hpp> |