aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/usrp1
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib/usrp/usrp1')
-rw-r--r--host/lib/usrp/usrp1/dboard_iface.cpp26
-rw-r--r--host/lib/usrp/usrp1/io_impl.cpp375
-rw-r--r--host/lib/usrp/usrp1/soft_time_ctrl.cpp7
-rw-r--r--host/lib/usrp/usrp1/soft_time_ctrl.hpp2
-rw-r--r--host/lib/usrp/usrp1/usrp1_calc_mux.hpp4
-rw-r--r--host/lib/usrp/usrp1/usrp1_impl.cpp126
-rw-r--r--host/lib/usrp/usrp1/usrp1_impl.hpp40
7 files changed, 390 insertions, 190 deletions
diff --git a/host/lib/usrp/usrp1/dboard_iface.cpp b/host/lib/usrp/usrp1/dboard_iface.cpp
index 449ec64fe..34bbe1893 100644
--- a/host/lib/usrp/usrp1/dboard_iface.cpp
+++ b/host/lib/usrp/usrp1/dboard_iface.cpp
@@ -39,7 +39,7 @@ public:
usrp1_dboard_iface(usrp1_iface::sptr iface,
usrp1_codec_ctrl::sptr codec,
usrp1_impl::dboard_slot_t dboard_slot,
- const double master_clock_rate,
+ const double &master_clock_rate,
const dboard_id_t &rx_dboard_id
):
_dboard_slot(dboard_slot),
@@ -49,10 +49,8 @@ public:
_iface = iface;
_codec = codec;
- //init the clock rate shadows
- this->set_clock_rate(UNIT_RX, this->get_clock_rates(UNIT_RX).front());
- this->set_clock_rate(UNIT_TX, this->get_clock_rates(UNIT_TX).front());
-
+ _dbsrx_classic_div = 1;
+
//yes this is evil but it's necessary for TVRX to work on USRP1
if(_rx_dboard_id == tvrx_id) _codec->bypass_adc_buffers(false);
//else _codec->bypass_adc_buffers(false); //don't think this is necessary
@@ -103,9 +101,9 @@ public:
private:
usrp1_iface::sptr _iface;
usrp1_codec_ctrl::sptr _codec;
- uhd::dict<unit_t, double> _clock_rates;
+ unsigned _dbsrx_classic_div;
const usrp1_impl::dboard_slot_t _dboard_slot;
- const double _master_clock_rate;
+ const double &_master_clock_rate;
const dboard_id_t _rx_dboard_id;
};
@@ -115,7 +113,7 @@ private:
dboard_iface::sptr usrp1_impl::make_dboard_iface(usrp1_iface::sptr iface,
usrp1_codec_ctrl::sptr codec,
usrp1_impl::dboard_slot_t dboard_slot,
- const double master_clock_rate,
+ const double &master_clock_rate,
const dboard_id_t &rx_dboard_id
){
return dboard_iface::sptr(new usrp1_dboard_iface(
@@ -137,17 +135,16 @@ static const dboard_id_t dbsrx_classic_id(0x0002);
void usrp1_dboard_iface::set_clock_rate(unit_t unit, double rate)
{
assert_has(this->get_clock_rates(unit), rate, "dboard clock rate");
- _clock_rates[unit] = rate;
if (unit == UNIT_RX && _rx_dboard_id == dbsrx_classic_id){
- size_t divider = size_t(_master_clock_rate/rate);
+ _dbsrx_classic_div = size_t(_master_clock_rate/rate);
switch(_dboard_slot){
case usrp1_impl::DBOARD_SLOT_A:
- _iface->poke32(FR_RX_A_REFCLK, (divider & 0x7f) | 0x80);
+ _iface->poke32(FR_RX_A_REFCLK, (_dbsrx_classic_div & 0x7f) | 0x80);
break;
case usrp1_impl::DBOARD_SLOT_B:
- _iface->poke32(FR_RX_B_REFCLK, (divider & 0x7f) | 0x80);
+ _iface->poke32(FR_RX_B_REFCLK, (_dbsrx_classic_div & 0x7f) | 0x80);
break;
}
}
@@ -168,7 +165,10 @@ std::vector<double> usrp1_dboard_iface::get_clock_rates(unit_t unit)
double usrp1_dboard_iface::get_clock_rate(unit_t unit)
{
- return _clock_rates[unit];
+ if (unit == UNIT_RX && _rx_dboard_id == dbsrx_classic_id){
+ return _master_clock_rate/_dbsrx_classic_div;
+ }
+ return _master_clock_rate;
}
void usrp1_dboard_iface::set_clock_enabled(unit_t, bool)
diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp
index de325ea5d..937706fdd 100644
--- a/host/lib/usrp/usrp1/io_impl.cpp
+++ b/host/lib/usrp/usrp1/io_impl.cpp
@@ -22,6 +22,7 @@
#include "../../transport/super_send_packet_handler.hpp"
#include "usrp1_calc_mux.hpp"
#include "fpga_regs_standard.h"
+#include "fpga_regs_common.h"
#include "usrp_commands.h"
#include "usrp1_impl.hpp"
#include <uhd/utils/msg.hpp>
@@ -33,6 +34,7 @@
#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>
#include <boost/format.hpp>
+#include <boost/make_shared.hpp>
using namespace uhd;
using namespace uhd::usrp;
@@ -109,6 +111,7 @@ static void usrp1_bs_vrt_unpacker(
){
if_packet_info.packet_type = vrt::if_packet_info_t::PACKET_TYPE_DATA;
if_packet_info.num_payload_words32 = if_packet_info.num_packet_words32;
+ if_packet_info.num_payload_bytes = if_packet_info.num_packet_words32*sizeof(boost::uint32_t);
if_packet_info.num_header_words32 = 0;
if_packet_info.packet_count = 0;
if_packet_info.sob = false;
@@ -138,10 +141,6 @@ struct usrp1_impl::io_impl{
zero_copy_if::sptr data_transport;
- //state management for the vrt packet handler code
- sph::recv_packet_handler recv_handler;
- sph::send_packet_handler send_handler;
-
//wrapper around the actual send buffer interface
//all of this to ensure only aligned lengths are committed
//NOTE: you must commit before getting a new buffer
@@ -219,13 +218,6 @@ void usrp1_impl::io_impl::flush_send_buff(void){
* Initialize internals within this file
**********************************************************************/
void usrp1_impl::io_init(void){
- _rx_otw_type.width = 16;
- _rx_otw_type.shift = 0;
- _rx_otw_type.byteorder = otw_type_t::BO_LITTLE_ENDIAN;
-
- _tx_otw_type.width = 16;
- _tx_otw_type.shift = 0;
- _tx_otw_type.byteorder = otw_type_t::BO_LITTLE_ENDIAN;
_io_impl = UHD_PIMPL_MAKE(io_impl, (_data_transport));
@@ -234,18 +226,6 @@ void usrp1_impl::io_init(void){
&usrp1_impl::vandal_conquest_loop, this
));
- //init some handler stuff
- _io_impl->recv_handler.set_tick_rate(_master_clock_rate);
- _io_impl->recv_handler.set_vrt_unpacker(&usrp1_bs_vrt_unpacker);
- _io_impl->recv_handler.set_xport_chan_get_buff(0, boost::bind(
- &uhd::transport::zero_copy_if::get_recv_buff, _io_impl->data_transport, _1
- ));
- _io_impl->send_handler.set_tick_rate(_master_clock_rate);
- _io_impl->send_handler.set_vrt_packer(&usrp1_bs_vrt_packer);
- _io_impl->send_handler.set_xport_chan_get_buff(0, boost::bind(
- &usrp1_impl::io_impl::get_send_buff, _io_impl.get(), _1
- ));
-
//init as disabled, then call the real function (uses restore)
this->enable_rx(false);
this->enable_tx(false);
@@ -325,17 +305,109 @@ void usrp1_impl::vandal_conquest_loop(void){
}
/***********************************************************************
+ * RX streamer wrapper that talks to soft time control
+ **********************************************************************/
+class usrp1_recv_packet_streamer : public sph::recv_packet_handler, public rx_streamer{
+public:
+ usrp1_recv_packet_streamer(const size_t max_num_samps, soft_time_ctrl::sptr stc){
+ _max_num_samps = max_num_samps;
+ _stc = stc;
+ }
+
+ size_t get_num_channels(void) const{
+ return this->size();
+ }
+
+ size_t get_max_num_samps(void) const{
+ return _max_num_samps;
+ }
+
+ size_t recv(
+ const rx_streamer::buffs_type &buffs,
+ const size_t nsamps_per_buff,
+ uhd::rx_metadata_t &metadata,
+ const double timeout,
+ const bool one_packet
+ ){
+ //interleave a "soft" inline message into the receive stream:
+ if (_stc->get_inline_queue().pop_with_haste(metadata)) return 0;
+
+ size_t num_samps_recvd = sph::recv_packet_handler::recv(
+ buffs, nsamps_per_buff, metadata, timeout, one_packet
+ );
+
+ return _stc->recv_post(metadata, num_samps_recvd);
+ }
+
+private:
+ size_t _max_num_samps;
+ soft_time_ctrl::sptr _stc;
+};
+
+/***********************************************************************
+ * TX streamer wrapper that talks to soft time control
+ **********************************************************************/
+class usrp1_send_packet_streamer : public sph::send_packet_handler, public tx_streamer{
+public:
+ usrp1_send_packet_streamer(const size_t max_num_samps, soft_time_ctrl::sptr stc, boost::function<void(bool)> tx_enb_fcn){
+ _max_num_samps = max_num_samps;
+ this->set_max_samples_per_packet(_max_num_samps);
+ _stc = stc;
+ _tx_enb_fcn = tx_enb_fcn;
+ }
+
+ size_t get_num_channels(void) const{
+ return this->size();
+ }
+
+ size_t get_max_num_samps(void) const{
+ return _max_num_samps;
+ }
+
+ size_t send(
+ const tx_streamer::buffs_type &buffs,
+ const size_t nsamps_per_buff,
+ const uhd::tx_metadata_t &metadata,
+ const double timeout_
+ ){
+ double timeout = timeout_; //rw copy
+ _stc->send_pre(metadata, timeout);
+
+ _tx_enb_fcn(true); //always enable (it will do the right thing)
+ size_t num_samps_sent = sph::send_packet_handler::send(
+ buffs, nsamps_per_buff, metadata, timeout
+ );
+
+ //handle eob flag (commit the buffer, //disable the DACs)
+ //check num samps sent to avoid flush on incomplete/timeout
+ if (metadata.end_of_burst and num_samps_sent == nsamps_per_buff){
+ async_metadata_t metadata;
+ metadata.channel = 0;
+ metadata.has_time_spec = true;
+ metadata.time_spec = _stc->get_time();
+ metadata.event_code = async_metadata_t::EVENT_CODE_BURST_ACK;
+ _stc->get_async_queue().push_with_pop_on_full(metadata);
+ _tx_enb_fcn(false);
+ }
+
+ return num_samps_sent;
+ }
+
+private:
+ size_t _max_num_samps;
+ soft_time_ctrl::sptr _stc;
+ boost::function<void(bool)> _tx_enb_fcn;
+};
+
+/***********************************************************************
* Properties callback methods below
**********************************************************************/
void usrp1_impl::update_rx_subdev_spec(const uhd::usrp::subdev_spec_t &spec){
- boost::mutex::scoped_lock lock = _io_impl->recv_handler.get_scoped_lock();
//sanity checking
validate_subdev_spec(_tree, spec, "rx");
_rx_subdev_spec = spec; //shadow
- //_io_impl->recv_handler.resize(spec.size()); //always 1
- _io_impl->recv_handler.set_converter(_rx_otw_type, spec.size());
//set the mux and set the number of rx channels
std::vector<mapping_pair_t> mapping;
@@ -351,14 +423,11 @@ void usrp1_impl::update_rx_subdev_spec(const uhd::usrp::subdev_spec_t &spec){
}
void usrp1_impl::update_tx_subdev_spec(const uhd::usrp::subdev_spec_t &spec){
- boost::mutex::scoped_lock lock = _io_impl->send_handler.get_scoped_lock();
//sanity checking
validate_subdev_spec(_tree, spec, "tx");
_tx_subdev_spec = spec; //shadow
- //_io_impl->send_handler.resize(spec.size()); //always 1
- _io_impl->send_handler.set_converter(_tx_otw_type, spec.size());
//set the mux and set the number of tx channels
std::vector<mapping_pair_t> mapping;
@@ -371,41 +440,94 @@ void usrp1_impl::update_tx_subdev_spec(const uhd::usrp::subdev_spec_t &spec){
bool s = this->disable_tx();
_iface->poke32(FR_TX_MUX, calc_tx_mux(mapping));
this->restore_tx(s);
+}
- //if the spec changes size, so does the max samples per packet...
- _io_impl->send_handler.set_max_samples_per_packet(get_max_send_samps_per_packet());
+void usrp1_impl::update_tick_rate(const double rate){
+ //updating this variable should:
+ //update dboard iface -> it has a reference
+ //update dsp freq bounds -> publisher
+ _master_clock_rate = rate;
}
-double usrp1_impl::update_rx_samp_rate(const double samp_rate){
- boost::mutex::scoped_lock lock = _io_impl->recv_handler.get_scoped_lock();
+uhd::meta_range_t usrp1_impl::get_rx_dsp_host_rates(void){
+ meta_range_t range;
+ const size_t div = this->has_rx_halfband()? 2 : 1;
+ for (int rate = 256; rate >= 4; rate -= div){
+ range.push_back(range_t(_master_clock_rate/rate));
+ }
+ return range;
+}
- const size_t rate = uhd::clip<size_t>(
- boost::math::iround(_master_clock_rate / samp_rate), size_t(std::ceil(_master_clock_rate / 8e6)), 256
- );
+uhd::meta_range_t usrp1_impl::get_tx_dsp_host_rates(void){
+ meta_range_t range;
+ const size_t div = this->has_tx_halfband()? 2 : 1;
+ for (int rate = 256; rate >= 8; rate -= div){
+ range.push_back(range_t(_master_clock_rate/rate));
+ }
+ return range;
+}
- bool s = this->disable_rx();
- _iface->poke32(FR_DECIM_RATE, rate/2 - 1);
- this->restore_rx(s);
+double usrp1_impl::update_rx_samp_rate(size_t dspno, const double samp_rate){
+
+ const size_t div = this->has_rx_halfband()? 2 : 1;
+ const size_t rate = boost::math::iround(_master_clock_rate/this->get_rx_dsp_host_rates().clip(samp_rate, true));
+
+ if (rate < 8 and this->has_rx_halfband()) UHD_MSG(warning) <<
+ "USRP1 cannot achieve decimations below 8 when the half-band filter is present.\n"
+ "The usrp1_fpga_4rx.rbf file is a special FPGA image without RX half-band filters.\n"
+ "To load this image, set the device address key/value pair: fpga=usrp1_fpga_4rx.rbf\n"
+ << std::endl;
+
+ if (dspno == 0){ //only care if dsp0 is set since its homogeneous
+ bool s = this->disable_rx();
+ _iface->poke32(FR_RX_SAMPLE_RATE_DIV, div - 1);
+ _iface->poke32(FR_DECIM_RATE, rate/div - 1);
+ this->restore_rx(s);
+
+ //update the streamer if created
+ boost::shared_ptr<usrp1_recv_packet_streamer> my_streamer =
+ boost::dynamic_pointer_cast<usrp1_recv_packet_streamer>(_rx_streamer.lock());
+ if (my_streamer.get() != NULL){
+ my_streamer->set_samp_rate(_master_clock_rate / rate);
+ }
+ }
- _io_impl->recv_handler.set_samp_rate(_master_clock_rate / rate);
return _master_clock_rate / rate;
}
-double usrp1_impl::update_tx_samp_rate(const double samp_rate){
- boost::mutex::scoped_lock lock = _io_impl->send_handler.get_scoped_lock();
+double usrp1_impl::update_tx_samp_rate(size_t dspno, const double samp_rate){
- const size_t rate = uhd::clip<size_t>(
- boost::math::iround(_master_clock_rate / samp_rate), size_t(std::ceil(_master_clock_rate / 8e6)), 256
- );
+ const size_t div = this->has_tx_halfband()? 2 : 1;
+ const size_t rate = boost::math::iround(_master_clock_rate/this->get_tx_dsp_host_rates().clip(samp_rate, true));
- bool s = this->disable_tx();
- _iface->poke32(FR_INTERP_RATE, rate/2 - 1);
- this->restore_tx(s);
+ if (dspno == 0){ //only care if dsp0 is set since its homogeneous
+ bool s = this->disable_tx();
+ _iface->poke32(FR_TX_SAMPLE_RATE_DIV, div - 1);
+ _iface->poke32(FR_INTERP_RATE, rate/div - 1);
+ this->restore_tx(s);
+
+ //update the streamer if created
+ boost::shared_ptr<usrp1_send_packet_streamer> my_streamer =
+ boost::dynamic_pointer_cast<usrp1_send_packet_streamer>(_tx_streamer.lock());
+ if (my_streamer.get() != NULL){
+ my_streamer->set_samp_rate(_master_clock_rate / rate);
+ }
+ }
- _io_impl->send_handler.set_samp_rate(_master_clock_rate / rate);
return _master_clock_rate / rate;
}
+void usrp1_impl::update_rates(void){
+ const fs_path mb_path = "/mboards/0";
+ this->update_tick_rate(_master_clock_rate);
+ BOOST_FOREACH(const std::string &name, _tree->list(mb_path / "rx_dsps")){
+ _tree->access<double>(mb_path / "rx_dsps" / name / "rate" / "value").update();
+ }
+ BOOST_FOREACH(const std::string &name, _tree->list(mb_path / "tx_dsps")){
+ _tree->access<double>(mb_path / "tx_dsps" / name / "rate" / "value").update();
+ }
+}
+
double usrp1_impl::update_rx_dsp_freq(const size_t dspno, const double freq_){
//correct for outside of rate (wrap around)
@@ -443,67 +565,120 @@ bool usrp1_impl::recv_async_msg(
}
/***********************************************************************
- * Data send + helper functions
+ * Receive streamer
**********************************************************************/
-size_t usrp1_impl::get_max_send_samps_per_packet(void) const {
- return (_data_transport->get_send_frame_size() - alignment_padding)
- / _tx_otw_type.get_sample_size()
- / _tx_subdev_spec.size()
- ;
-}
+rx_streamer::sptr usrp1_impl::get_rx_stream(const uhd::stream_args_t &args_){
+ stream_args_t args = args_;
+
+ //setup defaults for unspecified values
+ args.otw_format = args.otw_format.empty()? "sc16" : args.otw_format;
+ args.channels.clear(); //NOTE: we have no choice about the channel mapping
+ for (size_t ch = 0; ch < _rx_subdev_spec.size(); ch++){
+ args.channels.push_back(ch);
+ }
-size_t usrp1_impl::send(
- const send_buffs_type &buffs, size_t nsamps_per_buff,
- const tx_metadata_t &metadata, const io_type_t &io_type,
- send_mode_t send_mode, double timeout
-){
- if (_soft_time_ctrl->send_pre(metadata, timeout)) return 0;
+ if (args.otw_format == "sc16"){
+ _iface->poke32(FR_RX_FORMAT, 0
+ | (0 << bmFR_RX_FORMAT_SHIFT_SHIFT)
+ | (16 << bmFR_RX_FORMAT_WIDTH_SHIFT)
+ | bmFR_RX_FORMAT_WANT_Q
+ );
+ }
+ else if (args.otw_format == "sc8"){
+ _iface->poke32(FR_RX_FORMAT, 0
+ | (8 << bmFR_RX_FORMAT_SHIFT_SHIFT)
+ | (8 << bmFR_RX_FORMAT_WIDTH_SHIFT)
+ | bmFR_RX_FORMAT_WANT_Q
+ );
+ }
+ else{
+ throw uhd::value_error("USRP1 RX cannot handle requested wire format: " + args.otw_format);
+ }
- this->tx_stream_on_off(true); //always enable (it will do the right thing)
- size_t num_samps_sent = _io_impl->send_handler.send(
- buffs, nsamps_per_buff,
- metadata, io_type,
- send_mode, timeout
- );
+ //calculate packet size
+ const size_t bpp = _data_transport->get_recv_frame_size()/args.channels.size();
+ const size_t spp = bpp/convert::get_bytes_per_item(args.otw_format);
- //handle eob flag (commit the buffer, /*disable the DACs*/)
- //check num samps sent to avoid flush on incomplete/timeout
- if (metadata.end_of_burst and num_samps_sent == nsamps_per_buff){
- async_metadata_t metadata;
- metadata.channel = 0;
- metadata.has_time_spec = true;
- metadata.time_spec = _soft_time_ctrl->get_time();
- metadata.event_code = async_metadata_t::EVENT_CODE_BURST_ACK;
- _soft_time_ctrl->get_async_queue().push_with_pop_on_full(metadata);
- this->tx_stream_on_off(false);
- }
+ //make the new streamer given the samples per packet
+ boost::shared_ptr<usrp1_recv_packet_streamer> my_streamer =
+ boost::make_shared<usrp1_recv_packet_streamer>(spp, _soft_time_ctrl);
+
+ //special scale factor change for sc8
+ if (args.otw_format == "sc8")
+ my_streamer->set_scale_factor(1.0/127);
+
+ //init some streamer stuff
+ my_streamer->set_tick_rate(_master_clock_rate);
+ my_streamer->set_vrt_unpacker(&usrp1_bs_vrt_unpacker);
+ my_streamer->set_xport_chan_get_buff(0, boost::bind(
+ &uhd::transport::zero_copy_if::get_recv_buff, _io_impl->data_transport, _1
+ ));
+
+ //set the converter
+ uhd::convert::id_type id;
+ id.input_format = args.otw_format + "_item16_usrp1";
+ id.num_inputs = 1;
+ id.output_format = args.cpu_format;
+ id.num_outputs = args.channels.size();
+ my_streamer->set_converter(id);
- return num_samps_sent;
+ //save as weak ptr for update access
+ _rx_streamer = my_streamer;
+
+ //sets all tick and samp rates on this streamer
+ this->update_rates();
+
+ return my_streamer;
}
/***********************************************************************
- * Data recv + helper functions
+ * Transmit streamer
**********************************************************************/
-size_t usrp1_impl::get_max_recv_samps_per_packet(void) const {
- return _data_transport->get_recv_frame_size()
- / _rx_otw_type.get_sample_size()
- / _rx_subdev_spec.size()
- ;
-}
+tx_streamer::sptr usrp1_impl::get_tx_stream(const uhd::stream_args_t &args_){
+ stream_args_t args = args_;
+
+ //setup defaults for unspecified values
+ args.otw_format = args.otw_format.empty()? "sc16" : args.otw_format;
+ args.channels.clear(); //NOTE: we have no choice about the channel mapping
+ for (size_t ch = 0; ch < _tx_subdev_spec.size(); ch++){
+ args.channels.push_back(ch);
+ }
-size_t usrp1_impl::recv(
- const recv_buffs_type &buffs, size_t nsamps_per_buff,
- rx_metadata_t &metadata, const io_type_t &io_type,
- recv_mode_t recv_mode, double timeout
-){
- //interleave a "soft" inline message into the receive stream:
- if (_soft_time_ctrl->get_inline_queue().pop_with_haste(metadata)) return 0;
+ if (args.otw_format != "sc16"){
+ throw uhd::value_error("USRP1 TX cannot handle requested wire format: " + args.otw_format);
+ }
- size_t num_samps_recvd = _io_impl->recv_handler.recv(
- buffs, nsamps_per_buff,
- metadata, io_type,
- recv_mode, timeout
- );
+ _iface->poke32(FR_TX_FORMAT, bmFR_TX_FORMAT_16_IQ);
+
+ //calculate packet size
+ const size_t bpp = _data_transport->get_send_frame_size()/args.channels.size();
+ const size_t spp = bpp/convert::get_bytes_per_item(args.otw_format);
+
+ //make the new streamer given the samples per packet
+ boost::function<void(bool)> tx_fcn = boost::bind(&usrp1_impl::tx_stream_on_off, this, _1);
+ boost::shared_ptr<usrp1_send_packet_streamer> my_streamer =
+ boost::make_shared<usrp1_send_packet_streamer>(spp, _soft_time_ctrl, tx_fcn);
+
+ //init some streamer stuff
+ my_streamer->set_tick_rate(_master_clock_rate);
+ my_streamer->set_vrt_packer(&usrp1_bs_vrt_packer);
+ my_streamer->set_xport_chan_get_buff(0, boost::bind(
+ &usrp1_impl::io_impl::get_send_buff, _io_impl.get(), _1
+ ));
+
+ //set the converter
+ uhd::convert::id_type id;
+ id.input_format = args.cpu_format;
+ id.num_inputs = args.channels.size();
+ id.output_format = args.otw_format + "_item16_usrp1";
+ id.num_outputs = 1;
+ my_streamer->set_converter(id);
+
+ //save as weak ptr for update access
+ _tx_streamer = my_streamer;
+
+ //sets all tick and samp rates on this streamer
+ this->update_rates();
- return _soft_time_ctrl->recv_post(metadata, num_samps_recvd);
+ return my_streamer;
}
diff --git a/host/lib/usrp/usrp1/soft_time_ctrl.cpp b/host/lib/usrp/usrp1/soft_time_ctrl.cpp
index 78481c3ff..b8af8af06 100644
--- a/host/lib/usrp/usrp1/soft_time_ctrl.cpp
+++ b/host/lib/usrp/usrp1/soft_time_ctrl.cpp
@@ -131,8 +131,8 @@ public:
/*******************************************************************
* Transmit control
******************************************************************/
- bool send_pre(const tx_metadata_t &md, double &timeout){
- if (not md.has_time_spec) return false;
+ void send_pre(const tx_metadata_t &md, double &timeout){
+ if (not md.has_time_spec) return;
boost::mutex::scoped_lock lock(_update_mutex);
@@ -146,12 +146,11 @@ public:
metadata.time_spec = this->time_now();
metadata.event_code = async_metadata_t::EVENT_CODE_TIME_ERROR;
_async_msg_queue.push_with_pop_on_full(metadata);
- return true;
+ return;
}
timeout -= (time_at - time_now()).get_real_secs();
sleep_until_time(lock, time_at);
- return false;
}
/*******************************************************************
diff --git a/host/lib/usrp/usrp1/soft_time_ctrl.hpp b/host/lib/usrp/usrp1/soft_time_ctrl.hpp
index e91aaf6a2..b92b51252 100644
--- a/host/lib/usrp/usrp1/soft_time_ctrl.hpp
+++ b/host/lib/usrp/usrp1/soft_time_ctrl.hpp
@@ -57,7 +57,7 @@ public:
virtual size_t recv_post(rx_metadata_t &md, const size_t nsamps) = 0;
//! Call before the internal send function
- virtual bool send_pre(const tx_metadata_t &md, double &timeout) = 0;
+ virtual void send_pre(const tx_metadata_t &md, double &timeout) = 0;
//! Issue a stream command to receive
virtual void issue_stream_cmd(const stream_cmd_t &cmd) = 0;
diff --git a/host/lib/usrp/usrp1/usrp1_calc_mux.hpp b/host/lib/usrp/usrp1/usrp1_calc_mux.hpp
index 31c190db0..d86a7a809 100644
--- a/host/lib/usrp/usrp1/usrp1_calc_mux.hpp
+++ b/host/lib/usrp/usrp1/usrp1_calc_mux.hpp
@@ -37,7 +37,7 @@ typedef std::pair<std::string, std::string> mapping_pair_t;
* to account for the reversal in the type conversion routines.
**********************************************************************/
static int calc_rx_mux_pair(int adc_for_i, int adc_for_q){
- return (adc_for_i << 2) | (adc_for_q << 0); //shift reversal here
+ return (adc_for_i << 0) | (adc_for_q << 2);
}
/*!
@@ -98,7 +98,7 @@ static boost::uint32_t calc_rx_mux(const std::vector<mapping_pair_t> &mapping){
* to account for the reversal in the type conversion routines.
**********************************************************************/
static int calc_tx_mux_pair(int chn_for_i, int chn_for_q){
- return (chn_for_i << 4) | (chn_for_q << 0); //shift reversal here
+ return (chn_for_i << 0) | (chn_for_q << 4);
}
/*!
diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp
index fe4541d38..4be5a3a2b 100644
--- a/host/lib/usrp/usrp1/usrp1_impl.cpp
+++ b/host/lib/usrp/usrp1/usrp1_impl.cpp
@@ -33,6 +33,7 @@
#include <boost/filesystem.hpp>
#include <boost/thread/thread.hpp>
#include <boost/lexical_cast.hpp>
+#include <boost/math/special_functions/round.hpp>
#include <cstdio>
using namespace uhd;
@@ -187,21 +188,6 @@ usrp1_impl::usrp1_impl(const device_addr_t &device_addr){
// Normal mode with no loopback or Rx counting
_iface->poke32(FR_MODE, 0x00000000);
_iface->poke32(FR_DEBUG_EN, 0x00000000);
- _iface->poke32(FR_RX_SAMPLE_RATE_DIV, 0x00000001); //divide by 2
- _iface->poke32(FR_TX_SAMPLE_RATE_DIV, 0x00000001); //divide by 2
- _iface->poke32(FR_DC_OFFSET_CL_EN, 0x0000000f);
-
- // Reset offset correction registers
- _iface->poke32(FR_ADC_OFFSET_0, 0x00000000);
- _iface->poke32(FR_ADC_OFFSET_1, 0x00000000);
- _iface->poke32(FR_ADC_OFFSET_2, 0x00000000);
- _iface->poke32(FR_ADC_OFFSET_3, 0x00000000);
-
- // Set default for RX format to 16-bit I&Q and no half-band filter bypass
- _iface->poke32(FR_RX_FORMAT, 0x00000300);
-
- // Set default for TX format to 16-bit I&Q
- _iface->poke32(FR_TX_FORMAT, 0x00000000);
UHD_LOG
<< "USRP1 Capabilities" << std::endl
@@ -233,14 +219,25 @@ usrp1_impl::usrp1_impl(const device_addr_t &device_addr){
// create clock control objects
////////////////////////////////////////////////////////////////////
_master_clock_rate = 64e6;
- try{
- if (not mb_eeprom["mcr"].empty())
+ if (device_addr.has_key("mcr")){
+ try{
+ _master_clock_rate = boost::lexical_cast<double>(device_addr["mcr"]);
+ }
+ catch(const std::exception &e){
+ UHD_MSG(error) << "Error parsing FPGA clock rate from device address: " << e.what() << std::endl;
+ }
+ }
+ else if (not mb_eeprom["mcr"].empty()){
+ try{
_master_clock_rate = boost::lexical_cast<double>(mb_eeprom["mcr"]);
- }catch(const std::exception &e){
- UHD_MSG(error) << "Error parsing FPGA clock rate from EEPROM: " << e.what() << std::endl;
+ }
+ catch(const std::exception &e){
+ UHD_MSG(error) << "Error parsing FPGA clock rate from EEPROM: " << e.what() << std::endl;
+ }
}
UHD_MSG(status) << boost::format("Using FPGA clock rate of %fMHz...") % (_master_clock_rate/1e6) << std::endl;
- _tree->create<double>(mb_path / "tick_rate").set(_master_clock_rate);
+ _tree->create<double>(mb_path / "tick_rate")
+ .subscribe(boost::bind(&usrp1_impl::update_tick_rate, this, _1));
////////////////////////////////////////////////////////////////////
// create codec control objects
@@ -274,18 +271,31 @@ usrp1_impl::usrp1_impl(const device_addr_t &device_addr){
_tree->create<subdev_spec_t>(mb_path / "tx_subdev_spec")
.subscribe(boost::bind(&usrp1_impl::update_tx_subdev_spec, this, _1));
+ BOOST_FOREACH(const std::string &db, _dbc.keys()){
+ const fs_path rx_fe_path = mb_path / "rx_frontends" / db;
+ _tree->create<std::complex<double> >(rx_fe_path / "dc_offset" / "value")
+ .coerce(boost::bind(&usrp1_impl::set_rx_dc_offset, this, db, _1))
+ .set(std::complex<double>(0.0, 0.0));
+ _tree->create<bool>(rx_fe_path / "dc_offset" / "enable")
+ .subscribe(boost::bind(&usrp1_impl::set_enb_rx_dc_offset, this, db, _1))
+ .set(true);
+ }
+
////////////////////////////////////////////////////////////////////
// create rx dsp control objects
////////////////////////////////////////////////////////////////////
_tree->create<int>(mb_path / "rx_dsps"); //dummy in case we have none
for (size_t dspno = 0; dspno < get_num_ddcs(); dspno++){
fs_path rx_dsp_path = mb_path / str(boost::format("rx_dsps/%u") % dspno);
+ _tree->create<meta_range_t>(rx_dsp_path / "rate/range")
+ .publish(boost::bind(&usrp1_impl::get_rx_dsp_host_rates, this));
_tree->create<double>(rx_dsp_path / "rate/value")
- .coerce(boost::bind(&usrp1_impl::update_rx_samp_rate, this, _1));
+ .set(1e6) //some default rate
+ .coerce(boost::bind(&usrp1_impl::update_rx_samp_rate, this, dspno, _1));
_tree->create<double>(rx_dsp_path / "freq/value")
.coerce(boost::bind(&usrp1_impl::update_rx_dsp_freq, this, dspno, _1));
_tree->create<meta_range_t>(rx_dsp_path / "freq/range")
- .set(meta_range_t(-_master_clock_rate/2, +_master_clock_rate/2));
+ .publish(boost::bind(&usrp1_impl::get_rx_dsp_freq_range, this));
_tree->create<stream_cmd_t>(rx_dsp_path / "stream_cmd");
if (dspno == 0){
//only subscribe the callback for dspno 0 since it will stream all dsps
@@ -300,12 +310,15 @@ usrp1_impl::usrp1_impl(const device_addr_t &device_addr){
_tree->create<int>(mb_path / "tx_dsps"); //dummy in case we have none
for (size_t dspno = 0; dspno < get_num_ducs(); dspno++){
fs_path tx_dsp_path = mb_path / str(boost::format("tx_dsps/%u") % dspno);
+ _tree->create<meta_range_t>(tx_dsp_path / "rate/range")
+ .publish(boost::bind(&usrp1_impl::get_tx_dsp_host_rates, this));
_tree->create<double>(tx_dsp_path / "rate/value")
- .coerce(boost::bind(&usrp1_impl::update_tx_samp_rate, this, _1));
+ .set(1e6) //some default rate
+ .coerce(boost::bind(&usrp1_impl::update_tx_samp_rate, this, dspno, _1));
_tree->create<double>(tx_dsp_path / "freq/value")
.coerce(boost::bind(&usrp1_impl::update_tx_dsp_freq, this, dspno, _1));
- _tree->create<meta_range_t>(tx_dsp_path / "freq/range") //magic scalar comes from codec control:
- .set(meta_range_t(-_master_clock_rate*0.6875, +_master_clock_rate*0.6875));
+ _tree->create<meta_range_t>(tx_dsp_path / "freq/range")
+ .publish(boost::bind(&usrp1_impl::get_tx_dsp_freq_range, this));
}
////////////////////////////////////////////////////////////////////
@@ -350,29 +363,16 @@ usrp1_impl::usrp1_impl(const device_addr_t &device_addr){
);
_tree->create<dboard_iface::sptr>(mb_path / "dboards" / db/ "iface").set(_dbc[db].dboard_iface);
_dbc[db].dboard_manager = dboard_manager::make(
- rx_db_eeprom.id,
- ((gdb_eeprom.id == dboard_id_t::none())? tx_db_eeprom : gdb_eeprom).id,
- _dbc[db].dboard_iface
+ rx_db_eeprom.id, tx_db_eeprom.id, gdb_eeprom.id,
+ _dbc[db].dboard_iface, _tree->subtree(mb_path / "dboards" / db)
);
- BOOST_FOREACH(const std::string &name, _dbc[db].dboard_manager->get_rx_subdev_names()){
- dboard_manager::populate_prop_tree_from_subdev(
- _tree->subtree(mb_path / "dboards" / db/ "rx_frontends" / name),
- _dbc[db].dboard_manager->get_rx_subdev(name)
- );
- }
- BOOST_FOREACH(const std::string &name, _dbc[db].dboard_manager->get_tx_subdev_names()){
- dboard_manager::populate_prop_tree_from_subdev(
- _tree->subtree(mb_path / "dboards" / db/ "tx_frontends" / name),
- _dbc[db].dboard_manager->get_tx_subdev(name)
- );
- }
//init the subdev specs if we have a dboard (wont leave this loop empty)
if (rx_db_eeprom.id != dboard_id_t::none() or _rx_subdev_spec.empty()){
- _rx_subdev_spec = subdev_spec_t(db + ":" + _dbc[db].dboard_manager->get_rx_subdev_names()[0]);
+ _rx_subdev_spec = subdev_spec_t(db + ":" + _tree->list(mb_path / "dboards" / db / "rx_frontends").at(0));
}
if (tx_db_eeprom.id != dboard_id_t::none() or _tx_subdev_spec.empty()){
- _tx_subdev_spec = subdev_spec_t(db + ":" + _dbc[db].dboard_manager->get_tx_subdev_names()[0]);
+ _tx_subdev_spec = subdev_spec_t(db + ":" + _tree->list(mb_path / "dboards" / db / "tx_frontends").at(0));
}
}
@@ -382,14 +382,7 @@ usrp1_impl::usrp1_impl(const device_addr_t &device_addr){
////////////////////////////////////////////////////////////////////
// do some post-init tasks
////////////////////////////////////////////////////////////////////
- //and now that the tick rate is set, init the host rates to something
- BOOST_FOREACH(const std::string &name, _tree->list(mb_path / "rx_dsps")){
- _tree->access<double>(mb_path / "rx_dsps" / name / "rate" / "value").set(1e6);
- }
- BOOST_FOREACH(const std::string &name, _tree->list(mb_path / "tx_dsps")){
- _tree->access<double>(mb_path / "tx_dsps" / name / "rate" / "value").set(1e6);
- }
-
+ this->update_rates();
if (_tree->list(mb_path / "rx_dsps").size() > 0)
_tree->access<subdev_spec_t>(mb_path / "rx_subdev_spec").set(_rx_subdev_spec);
if (_tree->list(mb_path / "tx_dsps").size() > 0)
@@ -456,3 +449,36 @@ double usrp1_impl::update_rx_codec_gain(const std::string &db, const double gain
_dbc[db].codec->set_rx_pga_gain(gain, 'B');
return _dbc[db].codec->get_rx_pga_gain('A');
}
+
+uhd::meta_range_t usrp1_impl::get_rx_dsp_freq_range(void){
+ return meta_range_t(-_master_clock_rate/2, +_master_clock_rate/2);
+}
+
+uhd::meta_range_t usrp1_impl::get_tx_dsp_freq_range(void){
+ //magic scalar comes from codec control:
+ return meta_range_t(-_master_clock_rate*0.6875, +_master_clock_rate*0.6875);
+}
+
+void usrp1_impl::set_enb_rx_dc_offset(const std::string &db, const bool enb){
+ const size_t shift = (db == "A")? 0 : 2;
+ _rx_dc_offset_shadow &= ~(0x3 << shift); //clear bits
+ _rx_dc_offset_shadow &= ((enb)? 0x3 : 0x0) << shift;
+ _iface->poke32(FR_DC_OFFSET_CL_EN, _rx_dc_offset_shadow & 0xf);
+}
+
+std::complex<double> usrp1_impl::set_rx_dc_offset(const std::string &db, const std::complex<double> &offset){
+ const boost::int32_t i_off = boost::math::iround(offset.real() * (1ul << 31));
+ const boost::int32_t q_off = boost::math::iround(offset.imag() * (1ul << 31));
+
+ if (db == "A"){
+ _iface->poke32(FR_ADC_OFFSET_0, i_off);
+ _iface->poke32(FR_ADC_OFFSET_1, q_off);
+ }
+
+ if (db == "B"){
+ _iface->poke32(FR_ADC_OFFSET_2, i_off);
+ _iface->poke32(FR_ADC_OFFSET_3, q_off);
+ }
+
+ return std::complex<double>(double(i_off) * (1ul << 31), double(q_off) * (1ul << 31));
+}
diff --git a/host/lib/usrp/usrp1/usrp1_impl.hpp b/host/lib/usrp/usrp1/usrp1_impl.hpp
index 68ce31a54..99bb01c76 100644
--- a/host/lib/usrp/usrp1/usrp1_impl.hpp
+++ b/host/lib/usrp/usrp1/usrp1_impl.hpp
@@ -31,6 +31,7 @@
#include <uhd/usrp/dboard_eeprom.hpp>
#include <uhd/usrp/dboard_manager.hpp>
#include <uhd/transport/usb_zero_copy.hpp>
+#include <complex>
#ifndef INCLUDED_USRP1_IMPL_HPP
#define INCLUDED_USRP1_IMPL_HPP
@@ -55,21 +56,8 @@ public:
~usrp1_impl(void);
//the io interface
- size_t send(const send_buffs_type &,
- size_t,
- const uhd::tx_metadata_t &,
- const uhd::io_type_t &,
- send_mode_t, double);
-
- size_t recv(const recv_buffs_type &,
- size_t, uhd::rx_metadata_t &,
- const uhd::io_type_t &,
- recv_mode_t, double);
-
- size_t get_max_send_samps_per_packet(void) const;
-
- size_t get_max_recv_samps_per_packet(void) const;
-
+ uhd::rx_streamer::sptr get_rx_stream(const uhd::stream_args_t &args);
+ uhd::tx_streamer::sptr get_tx_stream(const uhd::stream_args_t &args);
bool recv_async_msg(uhd::async_metadata_t &, double);
private:
@@ -94,21 +82,34 @@ private:
double _master_clock_rate; //clock rate shadow
+ //weak pointers to streamers for update purposes
+ boost::weak_ptr<uhd::rx_streamer> _rx_streamer;
+ boost::weak_ptr<uhd::tx_streamer> _tx_streamer;
+
void set_mb_eeprom(const uhd::usrp::mboard_eeprom_t &);
void set_db_eeprom(const std::string &, const std::string &, const uhd::usrp::dboard_eeprom_t &);
double update_rx_codec_gain(const std::string &, const double); //sets A and B at once
void update_rx_subdev_spec(const uhd::usrp::subdev_spec_t &);
void update_tx_subdev_spec(const uhd::usrp::subdev_spec_t &);
- double update_rx_samp_rate(const double);
- double update_tx_samp_rate(const double);
+ double update_rx_samp_rate(size_t dspno, const double);
+ double update_tx_samp_rate(size_t dspno, const double);
+ void update_rates(void);
double update_rx_dsp_freq(const size_t, const double);
double update_tx_dsp_freq(const size_t, const double);
+ void update_tick_rate(const double rate);
+ uhd::meta_range_t get_rx_dsp_freq_range(void);
+ uhd::meta_range_t get_tx_dsp_freq_range(void);
+ uhd::meta_range_t get_rx_dsp_host_rates(void);
+ uhd::meta_range_t get_tx_dsp_host_rates(void);
+ size_t _rx_dc_offset_shadow;
+ void set_enb_rx_dc_offset(const std::string &db, const bool);
+ std::complex<double> set_rx_dc_offset(const std::string &db, const std::complex<double> &);
static uhd::usrp::dboard_iface::sptr make_dboard_iface(
usrp1_iface::sptr,
usrp1_codec_ctrl::sptr,
dboard_slot_t,
- const double,
+ const double &,
const uhd::usrp::dboard_id_t &
);
@@ -119,8 +120,7 @@ private:
void tx_stream_on_off(bool);
void handle_overrun(size_t);
- //otw types
- uhd::otw_type_t _rx_otw_type, _tx_otw_type;
+ //channel mapping shadows
uhd::usrp::subdev_spec_t _rx_subdev_spec, _tx_subdev_spec;
//capabilities