summaryrefslogtreecommitdiffstats
path: root/host/lib/simple_device.cpp
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-03-29 00:45:26 -0700
committerJosh Blum <josh@joshknows.com>2010-03-29 00:45:26 -0700
commit86fffe7f9ed78a682879dd56c26628256f89e6ae (patch)
treedbad6c804cadc80baf69fd53fe86ee251d2a28f6 /host/lib/simple_device.cpp
parent3b02823640f3d7724c4d517114698285e914d735 (diff)
downloaduhd-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/simple_device.cpp')
-rw-r--r--host/lib/simple_device.cpp74
1 files changed, 3 insertions, 71 deletions
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){