aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/simple_device.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib/simple_device.cpp')
-rw-r--r--host/lib/simple_device.cpp140
1 files changed, 25 insertions, 115 deletions
diff --git a/host/lib/simple_device.cpp b/host/lib/simple_device.cpp
index ba1966e0d..25beb45a9 100644
--- a/host/lib/simple_device.cpp
+++ b/host/lib/simple_device.cpp
@@ -16,11 +16,9 @@
//
#include <uhd/simple_device.hpp>
-#include <uhd/device.hpp>
-#include <uhd/utils.hpp>
+#include <uhd/utils/tune_helper.hpp>
+#include <uhd/utils/assert.hpp>
#include <uhd/props.hpp>
-#include <uhd/types.hpp>
-#include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>
#include <boost/format.hpp>
#include <stdexcept>
@@ -28,89 +26,8 @@
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){
- return boost::algorithm::trim_copy(in);
-}
-
-device_addr_t args_to_device_addr(const std::string &args){
- device_addr_t addr;
-
- //split the args at the semi-colons
- std::vector<std::string> pairs;
- boost::split(pairs, args, boost::is_any_of(";"));
- BOOST_FOREACH(std::string pair, pairs){
- if (trim(pair) == "") continue;
-
- //split the key value pairs at the equals
- std::vector<std::string> key_val;
- boost::split(key_val, pair, boost::is_any_of("="));
- if (key_val.size() != 2) throw std::runtime_error("invalid args string: "+args);
- addr[trim(key_val[0])] = trim(key_val[1]);
- }
-
- return addr;
-}
-
static std::vector<double> get_xx_rates(wax::obj decerps, wax::obj rate){
std::vector<double> rates;
BOOST_FOREACH(size_t decerp, decerps.as<std::vector<size_t> >()){
@@ -154,42 +71,42 @@ public:
}
/*******************************************************************
- * Streaming
+ * Timing
******************************************************************/
- void set_streaming(bool enb){
- _rx_ddc[std::string("enabled")] = enb;
+ void set_time_now(const time_spec_t &time_spec){
+ _mboard[MBOARD_PROP_TIME_NOW] = time_spec;
}
- bool get_streaming(void){
- return _rx_ddc[std::string("enabled")].as<bool>();
+ void set_time_next_pps(const time_spec_t &time_spec){
+ _mboard[MBOARD_PROP_TIME_NEXT_PPS] = time_spec;
+ }
+
+ /*******************************************************************
+ * Streaming
+ ******************************************************************/
+ void issue_stream_cmd(const stream_cmd_t &stream_cmd){
+ _rx_ddc[std::string("stream_cmd")] = stream_cmd;
}
/*******************************************************************
* RX methods
******************************************************************/
void set_rx_rate(double rate){
- double samp_rate = _rx_ddc[std::string("rate")].as<double>();
+ double samp_rate = _rx_ddc[std::string("if_rate")].as<double>();
assert_has(get_rx_rates(), rate, "simple device rx rate");
_rx_ddc[std::string("decim")] = size_t(samp_rate/rate);
}
double get_rx_rate(void){
- double samp_rate = _rx_ddc[std::string("rate")].as<double>();
- size_t decim = _rx_ddc[std::string("decim")].as<size_t>();
- return samp_rate/decim;
+ return _rx_ddc[std::string("bb_rate")].as<double>();
}
std::vector<double> get_rx_rates(void){
- return get_xx_rates(_rx_ddc[std::string("decims")], _rx_ddc[std::string("rate")]);
+ return get_xx_rates(_rx_ddc[std::string("decims")], _rx_ddc[std::string("if_rate")]);
}
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){
@@ -201,7 +118,7 @@ public:
}
float get_rx_gain(void){
- return _rx_subdev[SUBDEV_PROP_GAIN].as<gain_t>();
+ return _rx_subdev[SUBDEV_PROP_GAIN].as<float>();
}
gain_range_t get_rx_gain_range(void){
@@ -224,28 +141,21 @@ public:
* TX methods
******************************************************************/
void set_tx_rate(double rate){
- double samp_rate = _tx_duc[std::string("rate")].as<double>();
+ double samp_rate = _tx_duc[std::string("if_rate")].as<double>();
assert_has(get_tx_rates(), rate, "simple device tx rate");
_tx_duc[std::string("interp")] = size_t(samp_rate/rate);
}
double get_tx_rate(void){
- double samp_rate = _tx_duc[std::string("rate")].as<double>();
- size_t interp = _tx_duc[std::string("interp")].as<size_t>();
- return samp_rate/interp;
+ return _tx_duc[std::string("bb_rate")].as<double>();
}
std::vector<double> get_tx_rates(void){
- return get_xx_rates(_tx_duc[std::string("interps")], _tx_duc[std::string("rate")]);
+ return get_xx_rates(_tx_duc[std::string("interps")], _tx_duc[std::string("if_rate")]);
}
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){
@@ -257,7 +167,7 @@ public:
}
float get_tx_gain(void){
- return _tx_subdev[SUBDEV_PROP_GAIN].as<gain_t>();
+ return _tx_subdev[SUBDEV_PROP_GAIN].as<float>();
}
gain_range_t get_tx_gain_range(void){
@@ -289,5 +199,5 @@ private:
* The Make Function
**********************************************************************/
simple_device::sptr simple_device::make(const std::string &args){
- return sptr(new simple_device_impl(args_to_device_addr(args)));
+ return sptr(new simple_device_impl(device_addr_t::from_args_str(args)));
}