summaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/usrp2
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib/usrp/usrp2')
-rw-r--r--host/lib/usrp/usrp2/dboard_impl.cpp8
-rw-r--r--host/lib/usrp/usrp2/dboard_interface.cpp79
-rw-r--r--host/lib/usrp/usrp2/dsp_impl.cpp246
-rw-r--r--host/lib/usrp/usrp2/fw_common.h4
-rw-r--r--host/lib/usrp/usrp2/io_impl.cpp15
-rw-r--r--host/lib/usrp/usrp2/mboard_impl.cpp96
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.cpp37
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.hpp18
-rw-r--r--host/lib/usrp/usrp2/usrp2_regs.hpp26
9 files changed, 263 insertions, 266 deletions
diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp
index 30883cd50..d1515f2d5 100644
--- a/host/lib/usrp/usrp2/dboard_impl.cpp
+++ b/host/lib/usrp/usrp2/dboard_impl.cpp
@@ -49,11 +49,11 @@ void usrp2_impl::dboard_init(void){
);
//load dboards
- _rx_dboards[""] = wax_obj_proxy::make(
+ _rx_dboard_proxy = wax_obj_proxy::make(
boost::bind(&usrp2_impl::rx_dboard_get, this, _1, _2),
boost::bind(&usrp2_impl::rx_dboard_set, this, _1, _2)
);
- _tx_dboards[""] = wax_obj_proxy::make(
+ _tx_dboard_proxy = wax_obj_proxy::make(
boost::bind(&usrp2_impl::tx_dboard_get, this, _1, _2),
boost::bind(&usrp2_impl::tx_dboard_set, this, _1, _2)
);
@@ -81,7 +81,7 @@ void usrp2_impl::update_rx_mux_config(void){
rx_mux = (((rx_mux >> 0) & 0x3) << 2) | (((rx_mux >> 2) & 0x3) << 0);
}
- this->poke(FR_DSP_RX_MUX, rx_mux);
+ this->poke32(FR_DSP_RX_MUX, rx_mux);
}
void usrp2_impl::update_tx_mux_config(void){
@@ -94,7 +94,7 @@ void usrp2_impl::update_tx_mux_config(void){
tx_mux = (((tx_mux >> 0) & 0x1) << 1) | (((tx_mux >> 1) & 0x1) << 0);
}
- this->poke(FR_DSP_TX_MUX, tx_mux);
+ this->poke32(FR_DSP_TX_MUX, tx_mux);
}
/***********************************************************************
diff --git a/host/lib/usrp/usrp2/dboard_interface.cpp b/host/lib/usrp/usrp2/dboard_interface.cpp
index 2e79381c5..6dd756420 100644
--- a/host/lib/usrp/usrp2/dboard_interface.cpp
+++ b/host/lib/usrp/usrp2/dboard_interface.cpp
@@ -48,17 +48,7 @@ private:
);
usrp2_impl *_impl;
-
- //shadows
boost::uint32_t _ddr_shadow;
- uhd::dict<atr_reg_t, boost::uint32_t> _atr_reg_shadows;
-
- //utilities
- static int bank_to_shift(gpio_bank_t bank){
- static const uhd::dict<gpio_bank_t, int> _bank_to_shift = \
- boost::assign::map_list_of(GPIO_BANK_RX, 0)(GPIO_BANK_TX, 16);
- return _bank_to_shift[bank];
- }
};
/***********************************************************************
@@ -74,6 +64,14 @@ dboard_interface::sptr make_usrp2_dboard_interface(usrp2_impl *impl){
usrp2_dboard_interface::usrp2_dboard_interface(usrp2_impl *impl){
_impl = impl;
_ddr_shadow = 0;
+
+ //set the selection mux to use atr
+ boost::uint32_t new_sels = 0x0;
+ for(size_t i = 0; i < 16; i++){
+ new_sels |= FRF_GPIO_SEL_ATR << (i*2);
+ }
+ _impl->poke32(FR_GPIO_TX_SEL, new_sels);
+ _impl->poke32(FR_GPIO_RX_SEL, new_sels);
}
usrp2_dboard_interface::~usrp2_dboard_interface(void){
@@ -94,43 +92,44 @@ double usrp2_dboard_interface::get_tx_clock_rate(void){
/***********************************************************************
* GPIO
**********************************************************************/
+static int bank_to_shift(dboard_interface::gpio_bank_t bank){
+ switch(bank){
+ case dboard_interface::GPIO_BANK_RX: return 0;
+ case dboard_interface::GPIO_BANK_TX: return 16;
+ }
+ throw std::runtime_error("unknown gpio bank type");
+}
+
void usrp2_dboard_interface::set_gpio_ddr(gpio_bank_t bank, boost::uint16_t value){
- //calculate the new 32 bit ddr value
- int shift = bank_to_shift(bank);
- boost::uint32_t new_ddr_val =
- (_ddr_shadow & ~(boost::uint32_t(0xffff) << shift)) //zero out new bits
- | (boost::uint32_t(value) << shift); //or'ed in the new bits
-
- //poke in the value and shadow
- _impl->poke(FR_GPIO_DDR, new_ddr_val);
- _ddr_shadow = new_ddr_val;
+ _ddr_shadow = \
+ (_ddr_shadow & ~(0xffff << bank_to_shift(bank))) |
+ (boost::uint32_t(value) << bank_to_shift(bank));
+ _impl->poke32(FR_GPIO_DDR, _ddr_shadow);
}
boost::uint16_t usrp2_dboard_interface::read_gpio(gpio_bank_t bank){
- boost::uint32_t data = _impl->peek(FR_GPIO_IO);
- return boost::uint16_t(data >> bank_to_shift(bank));
+ return boost::uint16_t(_impl->peek32(FR_GPIO_IO) >> bank_to_shift(bank));
}
-void usrp2_dboard_interface::set_atr_reg(gpio_bank_t bank, atr_reg_t reg, boost::uint16_t value){
- //map the atr reg to an offset in register space
- static const uhd::dict<atr_reg_t, int> reg_to_addr = boost::assign::map_list_of
- (ATR_REG_IDLE, FR_ATR_IDLE) (ATR_REG_TX_ONLY, FR_ATR_TX)
- (ATR_REG_RX_ONLY, FR_ATR_RX) (ATR_REG_FULL_DUPLEX, FR_ATR_FULL)
+void usrp2_dboard_interface::set_atr_reg(gpio_bank_t bank, atr_reg_t atr, boost::uint16_t value){
+ //define mapping of bank to atr regs to register address
+ static const uhd::dict<
+ gpio_bank_t, uhd::dict<atr_reg_t, boost::uint32_t>
+ > bank_to_atr_to_addr = boost::assign::map_list_of
+ (GPIO_BANK_RX, boost::assign::map_list_of
+ (ATR_REG_IDLE, FR_ATR_IDLE_RXSIDE)
+ (ATR_REG_TX_ONLY, FR_ATR_INTX_RXSIDE)
+ (ATR_REG_RX_ONLY, FR_ATR_INRX_RXSIDE)
+ (ATR_REG_FULL_DUPLEX, FR_ATR_FULL_RXSIDE)
+ )
+ (GPIO_BANK_TX, boost::assign::map_list_of
+ (ATR_REG_IDLE, FR_ATR_IDLE_TXSIDE)
+ (ATR_REG_TX_ONLY, FR_ATR_INTX_TXSIDE)
+ (ATR_REG_RX_ONLY, FR_ATR_INRX_TXSIDE)
+ (ATR_REG_FULL_DUPLEX, FR_ATR_FULL_TXSIDE)
+ )
;
- ASSERT_THROW(reg_to_addr.has_key(reg));
-
- //ensure a value exists in the shadow
- if (not _atr_reg_shadows.has_key(reg)) _atr_reg_shadows[reg] = 0;
-
- //calculate the new 32 bit atr value
- int shift = bank_to_shift(bank);
- boost::uint32_t new_atr_val =
- (_atr_reg_shadows[reg] & ~(boost::uint32_t(0xffff) << shift)) //zero out new bits
- | (boost::uint32_t(value) << shift); //or'ed in the new bits
-
- //poke in the value and shadow
- _impl->poke(reg_to_addr[reg], new_atr_val);
- _atr_reg_shadows[reg] = new_atr_val;
+ _impl->poke16(bank_to_atr_to_addr[bank][atr], value);
}
/***********************************************************************
diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp
index d70248682..92b55d029 100644
--- a/host/lib/usrp/usrp2/dsp_impl.cpp
+++ b/host/lib/usrp/usrp2/dsp_impl.cpp
@@ -54,9 +54,19 @@ static boost::uint32_t calculate_iq_scale_word(boost::int16_t i, boost::int16_t
return (boost::uint16_t(i) << 16) | (boost::uint16_t(q) << 0);
}
+template <class rate_t> static rate_t
+pick_closest_rate(double exact_rate, const std::vector<rate_t> &rates){
+ rate_t closest_match = rates.at(0);
+ BOOST_FOREACH(rate_t possible_rate, rates){
+ if(std::abs(exact_rate - possible_rate) < std::abs(exact_rate - closest_match))
+ closest_match = possible_rate;
+ }
+ return closest_match;
+}
+
void usrp2_impl::init_ddc_config(void){
//create the ddc in the rx dsp dict
- _rx_dsps["ddc0"] = wax_obj_proxy::make(
+ _rx_dsp_proxy = wax_obj_proxy::make(
boost::bind(&usrp2_impl::ddc_get, this, _1, _2),
boost::bind(&usrp2_impl::ddc_set, this, _1, _2)
);
@@ -67,124 +77,71 @@ void usrp2_impl::init_ddc_config(void){
update_ddc_config();
//initial command that kills streaming (in case if was left on)
- stream_cmd_t stream_cmd_off;
- stream_cmd_off.stream_now = true;
- stream_cmd_off.continuous = false;
- stream_cmd_off.num_samps = 0;
- issue_ddc_stream_cmd(stream_cmd_off);
+ issue_ddc_stream_cmd(stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS);
}
void usrp2_impl::update_ddc_config(void){
//set the decimation
- this->poke(FR_DSP_RX_DECIM_RATE, _ddc_decim);
+ this->poke32(FR_DSP_RX_DECIM_RATE, _ddc_decim);
//set the scaling
static const boost::int16_t default_rx_scale_iq = 1024;
- this->poke(FR_DSP_RX_SCALE_IQ,
+ this->poke32(FR_DSP_RX_SCALE_IQ,
calculate_iq_scale_word(default_rx_scale_iq, default_rx_scale_iq)
);
}
-void usrp2_impl::issue_ddc_stream_cmd(const stream_cmd_t &stream_cmd){
- //setup the out data
- usrp2_ctrl_data_t out_data;
- out_data.id = htonl(USRP2_CTRL_ID_SEND_STREAM_COMMAND_FOR_ME_BRO);
- out_data.data.stream_cmd.now = (stream_cmd.stream_now)? 1 : 0;
- out_data.data.stream_cmd.continuous = (stream_cmd.continuous)? 1 : 0;
- out_data.data.stream_cmd.secs = htonl(stream_cmd.time_spec.secs);
- out_data.data.stream_cmd.ticks = htonl(stream_cmd.time_spec.ticks);
- out_data.data.stream_cmd.num_samps = htonl(stream_cmd.num_samps);
-
- //send and recv
- usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data);
- ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_GOT_THAT_STREAM_COMMAND_DUDE);
-}
-
/***********************************************************************
* DDC Properties
**********************************************************************/
void usrp2_impl::ddc_get(const wax::obj &key, wax::obj &val){
- //handle the case where the key is an expected dsp property
- if (key.type() == typeid(dsp_prop_t)){
- switch(key.as<dsp_prop_t>()){
- case DSP_PROP_NAME:
- val = std::string("usrp2 ddc0");
- return;
-
- case DSP_PROP_OTHERS:{
- prop_names_t others = boost::assign::list_of
- ("if_rate")
- ("bb_rate")
- ("decim")
- ("decims")
- ("freq")
- ("stream_cmd")
- ;
- val = others;
- }
- return;
- }
- }
-
- //handle string-based properties specific to this dsp
- std::string key_name = key.as<std::string>();
- if (key_name == "if_rate"){
- val = get_master_clock_freq();
+ switch(key.as<dsp_prop_t>()){
+ case DSP_PROP_NAME:
+ val = std::string("usrp2 ddc0");
return;
- }
- else if (key_name == "bb_rate"){
- val = get_master_clock_freq()/_ddc_decim;
+
+ case DSP_PROP_OTHERS:
+ val = prop_names_t(); //empty
return;
- }
- else if (key_name == "decim"){
- val = _ddc_decim;
+
+ case DSP_PROP_FREQ_SHIFT:
+ val = _ddc_freq;
return;
- }
- else if (key_name == "decims"){
- val = _allowed_decim_and_interp_rates;
+
+ case DSP_PROP_CODEC_RATE:
+ val = get_master_clock_freq();
return;
- }
- else if (key_name == "freq"){
- val = _ddc_freq;
+
+ case DSP_PROP_HOST_RATE:
+ val = get_master_clock_freq()/_ddc_decim;
return;
}
-
- throw std::invalid_argument(str(
- boost::format("error getting: unknown key with name %s") % key_name
- ));
}
void usrp2_impl::ddc_set(const wax::obj &key, const wax::obj &val){
- //handle string-based properties specific to this dsp
- std::string key_name = key.as<std::string>();
- if (key_name == "decim"){
- size_t new_decim = val.as<size_t>();
- assert_has(
- _allowed_decim_and_interp_rates,
- new_decim, "usrp2 decimation"
- );
- _ddc_decim = new_decim; //shadow
- update_ddc_config();
- return;
- }
- else if (key_name == "freq"){
- double new_freq = val.as<double>();
- ASSERT_THROW(new_freq <= get_master_clock_freq()/2.0);
- ASSERT_THROW(new_freq >= -get_master_clock_freq()/2.0);
- _ddc_freq = new_freq; //shadow
- this->poke(FR_DSP_RX_FREQ,
- calculate_freq_word_and_update_actual_freq(_ddc_freq, get_master_clock_freq())
- );
+ switch(key.as<dsp_prop_t>()){
+
+ case DSP_PROP_FREQ_SHIFT:{
+ double new_freq = val.as<double>();
+ ASSERT_THROW(new_freq <= get_master_clock_freq()/2.0);
+ ASSERT_THROW(new_freq >= -get_master_clock_freq()/2.0);
+ _ddc_freq = new_freq; //shadow
+ this->poke32(FR_DSP_RX_FREQ,
+ calculate_freq_word_and_update_actual_freq(_ddc_freq, get_master_clock_freq())
+ );
+ }
return;
- }
- else if (key_name == "stream_cmd"){
- issue_ddc_stream_cmd(val.as<stream_cmd_t>());
+
+ case DSP_PROP_HOST_RATE:{
+ double extact_rate = get_master_clock_freq()/val.as<double>();
+ _ddc_decim = pick_closest_rate(extact_rate, _allowed_decim_and_interp_rates);
+ update_ddc_config();
+ }
return;
- }
- throw std::invalid_argument(str(
- boost::format("error setting: unknown key with name %s") % key_name
- ));
+ default:
+ throw std::runtime_error("Error: trying to set read-only property on usrp2 ddc0");
+ }
}
/***********************************************************************
@@ -192,7 +149,7 @@ void usrp2_impl::ddc_set(const wax::obj &key, const wax::obj &val){
**********************************************************************/
void usrp2_impl::init_duc_config(void){
//create the duc in the tx dsp dict
- _tx_dsps["duc0"] = wax_obj_proxy::make(
+ _tx_dsp_proxy = wax_obj_proxy::make(
boost::bind(&usrp2_impl::duc_get, this, _1, _2),
boost::bind(&usrp2_impl::duc_set, this, _1, _2)
);
@@ -213,90 +170,61 @@ void usrp2_impl::update_duc_config(void){
boost::int16_t scale = rint((4096*std::pow(2, ceil(log2(interp_cubed))))/(1.65*interp_cubed));
//set the interpolation
- this->poke(FR_DSP_TX_INTERP_RATE, _ddc_decim);
+ this->poke32(FR_DSP_TX_INTERP_RATE, _ddc_decim);
//set the scaling
- this->poke(FR_DSP_TX_SCALE_IQ, calculate_iq_scale_word(scale, scale));
+ this->poke32(FR_DSP_TX_SCALE_IQ, calculate_iq_scale_word(scale, scale));
}
/***********************************************************************
* DUC Properties
**********************************************************************/
void usrp2_impl::duc_get(const wax::obj &key, wax::obj &val){
- //handle the case where the key is an expected dsp property
- if (key.type() == typeid(dsp_prop_t)){
- switch(key.as<dsp_prop_t>()){
- case DSP_PROP_NAME:
- val = std::string("usrp2 duc0");
- return;
-
- case DSP_PROP_OTHERS:{
- prop_names_t others = boost::assign::list_of
- ("if_rate")
- ("bb_rate")
- ("interp")
- ("interps")
- ("freq")
- ;
- val = others;
- }
- return;
- }
- }
-
- //handle string-based properties specific to this dsp
- std::string key_name = key.as<std::string>();
- if (key_name == "if_rate"){
- val = get_master_clock_freq();
+ switch(key.as<dsp_prop_t>()){
+ case DSP_PROP_NAME:
+ val = std::string("usrp2 duc0");
return;
- }
- else if (key_name == "bb_rate"){
- val = get_master_clock_freq()/_duc_interp;
+
+ case DSP_PROP_OTHERS:
+ val = prop_names_t(); //empty
return;
- }
- else if (key_name == "interp"){
- val = _duc_interp;
+
+ case DSP_PROP_FREQ_SHIFT:
+ val = _duc_freq;
return;
- }
- else if (key_name == "interps"){
- val = _allowed_decim_and_interp_rates;
+
+ case DSP_PROP_CODEC_RATE:
+ val = get_master_clock_freq();
return;
- }
- else if (key_name == "freq"){
- val = _duc_freq;
+
+ case DSP_PROP_HOST_RATE:
+ val = get_master_clock_freq()/_duc_interp;
return;
}
-
- throw std::invalid_argument(str(
- boost::format("error getting: unknown key with name %s") % key_name
- ));
}
void usrp2_impl::duc_set(const wax::obj &key, const wax::obj &val){
- //handle string-based properties specific to this dsp
- std::string key_name = key.as<std::string>();
- if (key_name == "interp"){
- size_t new_interp = val.as<size_t>();
- assert_has(
- _allowed_decim_and_interp_rates,
- new_interp, "usrp2 interpolation"
- );
- _duc_interp = new_interp; //shadow
- update_duc_config();
+ switch(key.as<dsp_prop_t>()){
+
+ case DSP_PROP_FREQ_SHIFT:{
+ double new_freq = val.as<double>();
+ ASSERT_THROW(new_freq <= get_master_clock_freq()/2.0);
+ ASSERT_THROW(new_freq >= -get_master_clock_freq()/2.0);
+ _duc_freq = new_freq; //shadow
+ this->poke32(FR_DSP_TX_FREQ,
+ calculate_freq_word_and_update_actual_freq(_duc_freq, get_master_clock_freq())
+ );
+ }
return;
- }
- else if (key_name == "freq"){
- double new_freq = val.as<double>();
- ASSERT_THROW(new_freq <= get_master_clock_freq()/2.0);
- ASSERT_THROW(new_freq >= -get_master_clock_freq()/2.0);
- _duc_freq = new_freq; //shadow
- this->poke(FR_DSP_TX_FREQ,
- calculate_freq_word_and_update_actual_freq(_duc_freq, get_master_clock_freq())
- );
+
+ case DSP_PROP_HOST_RATE:{
+ double extact_rate = get_master_clock_freq()/val.as<double>();
+ _duc_interp = pick_closest_rate(extact_rate, _allowed_decim_and_interp_rates);
+ update_duc_config();
+ }
return;
- }
- throw std::invalid_argument(str(
- boost::format("error setting: unknown key with name %s") % key_name
- ));
+ default:
+ throw std::runtime_error("Error: trying to set read-only property on usrp2 duc0");
+ }
}
diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h
index c168614ee..019f3b931 100644
--- a/host/lib/usrp/usrp2/fw_common.h
+++ b/host/lib/usrp/usrp2/fw_common.h
@@ -129,7 +129,8 @@ typedef struct{
struct {
_SINS_ uint8_t now; //stream now?
_SINS_ uint8_t continuous; //auto-reload commmands?
- _SINS_ uint8_t _pad[2];
+ _SINS_ uint8_t chain;
+ _SINS_ uint8_t _pad[1];
_SINS_ uint32_t secs;
_SINS_ uint32_t ticks;
_SINS_ uint32_t num_samps;
@@ -137,6 +138,7 @@ typedef struct{
struct {
_SINS_ uint32_t addr;
_SINS_ uint32_t data;
+ _SINS_ uint8_t num_bytes; //1, 2, 4
} poke_args;
} data;
} usrp2_ctrl_data_t;
diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp
index c87884ebb..a58e32619 100644
--- a/host/lib/usrp/usrp2/io_impl.cpp
+++ b/host/lib/usrp/usrp2/io_impl.cpp
@@ -171,15 +171,21 @@ void usrp2_impl::recv_raw(rx_metadata_t &metadata){
**********************************************************************/
size_t usrp2_impl::send(
const asio::const_buffer &buff,
- const tx_metadata_t &metadata,
+ const tx_metadata_t &metadata_,
const io_type_t &io_type
){
+ tx_metadata_t metadata = metadata_; //rw copy to change later
+
boost::uint32_t tx_mem[_mtu/sizeof(boost::uint32_t)];
size_t num_samps = std::min(
asio::buffer_size(buff)/io_type.size,
size_t(_max_tx_samples_per_packet)
);
+ //kill the end of burst flag if this is a fragment
+ if (asio::buffer_size(buff)/io_type.size < num_samps)
+ metadata.end_of_burst = false;
+
size_t num_header_words32, num_packet_words32;
size_t packet_count = _tx_stream_id_to_packet_seq[metadata.stream_id]++;
@@ -222,12 +228,12 @@ size_t usrp2_impl::recv(
){
//perform a receive if no rx data is waiting to be copied
if (asio::buffer_size(_rx_copy_buff) == 0){
+ _fragment_offset_in_samps = 0;
recv_raw(metadata);
}
//otherwise flag the metadata to show that is is a fragment
else{
metadata = rx_metadata_t();
- metadata.is_fragment = true;
}
//extract the number of samples available to copy
@@ -240,6 +246,11 @@ size_t usrp2_impl::recv(
);
const boost::uint32_t *items = asio::buffer_cast<const boost::uint32_t*>(_rx_copy_buff);
+ //setup the fragment flags and offset
+ metadata.more_fragments = asio::buffer_size(buff)/io_type.size < num_samps;
+ metadata.fragment_offset = _fragment_offset_in_samps;
+ _fragment_offset_in_samps += num_samps; //set for next time
+
//copy the samples from the recv buffer
switch(io_type.tid){
case io_type_t::COMPLEX_FLOAT32:
diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp
index 7594c85fa..94ab88a6b 100644
--- a/host/lib/usrp/usrp2/mboard_impl.cpp
+++ b/host/lib/usrp/usrp2/mboard_impl.cpp
@@ -29,7 +29,7 @@ using namespace uhd::usrp;
* Helper Methods
**********************************************************************/
void usrp2_impl::mboard_init(void){
- _mboards[""] = wax_obj_proxy::make(
+ _mboard_proxy = wax_obj_proxy::make(
boost::bind(&usrp2_impl::mboard_get, this, _1, _2),
boost::bind(&usrp2_impl::mboard_set, this, _1, _2)
);
@@ -67,19 +67,56 @@ void usrp2_impl::update_clock_config(void){
}
//set the pps flags
- this->poke(FR_TIME64_FLAGS, pps_flags);
+ this->poke32(FR_TIME64_FLAGS, pps_flags);
//TODO clock source ref 10mhz (spi ad9510)
}
void usrp2_impl::set_time_spec(const time_spec_t &time_spec, bool now){
//set ticks and seconds
- this->poke(FR_TIME64_SECS, time_spec.secs);
- this->poke(FR_TIME64_TICKS, time_spec.ticks);
+ this->poke32(FR_TIME64_SECS, time_spec.secs);
+ this->poke32(FR_TIME64_TICKS, time_spec.ticks);
//set the register to latch it all in
boost::uint32_t imm_flags = (now)? FRF_TIME64_LATCH_NOW : FRF_TIME64_LATCH_NEXT_PPS;
- this->poke(FR_TIME64_IMM, imm_flags);
+ this->poke32(FR_TIME64_IMM, imm_flags);
+}
+
+void usrp2_impl::issue_ddc_stream_cmd(const stream_cmd_t &stream_cmd){
+ //setup the out data
+ usrp2_ctrl_data_t out_data;
+ out_data.id = htonl(USRP2_CTRL_ID_SEND_STREAM_COMMAND_FOR_ME_BRO);
+ out_data.data.stream_cmd.now = (stream_cmd.stream_now)? 1 : 0;
+ out_data.data.stream_cmd.secs = htonl(stream_cmd.time_spec.secs);
+ out_data.data.stream_cmd.ticks = htonl(stream_cmd.time_spec.ticks);
+
+ //set these to defaults, then change in the switch statement
+ out_data.data.stream_cmd.continuous = 0;
+ out_data.data.stream_cmd.chain = 0;
+ out_data.data.stream_cmd.num_samps = htonl(stream_cmd.num_samps);
+
+ //setup chain, num samps, and continuous below
+ switch(stream_cmd.stream_mode){
+ case stream_cmd_t::STREAM_MODE_START_CONTINUOUS:
+ out_data.data.stream_cmd.continuous = 1;
+ break;
+
+ case stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS:
+ out_data.data.stream_cmd.num_samps = htonl(0);
+ break;
+
+ case stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE:
+ //all set by defaults above
+ break;
+
+ case stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_MORE:
+ out_data.data.stream_cmd.chain = 1;
+ break;
+ }
+
+ //send and recv
+ usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data);
+ ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_GOT_THAT_STREAM_COMMAND_DUDE);
}
/***********************************************************************
@@ -136,21 +173,21 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){
return;
case MBOARD_PROP_RX_DBOARD:
- ASSERT_THROW(_rx_dboards.has_key(name));
- val = _rx_dboards[name]->get_link();
+ ASSERT_THROW(name == "");
+ val = _rx_dboard_proxy->get_link();
return;
case MBOARD_PROP_RX_DBOARD_NAMES:
- val = prop_names_t(_rx_dboards.get_keys());
+ val = prop_names_t(1, "");
return;
case MBOARD_PROP_TX_DBOARD:
- ASSERT_THROW(_tx_dboards.has_key(name));
- val = _tx_dboards[name]->get_link();
+ ASSERT_THROW(name == "");
+ val = _tx_dboard_proxy->get_link();
return;
case MBOARD_PROP_TX_DBOARD_NAMES:
- val = prop_names_t(_tx_dboards.get_keys());
+ val = prop_names_t(1, "");
return;
case MBOARD_PROP_CLOCK_RATE:
@@ -158,29 +195,28 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){
return;
case MBOARD_PROP_RX_DSP:
- ASSERT_THROW(_rx_dsps.has_key(name));
- val = _rx_dsps[name]->get_link();
+ ASSERT_THROW(name == "");
+ val = _rx_dsp_proxy->get_link();
return;
case MBOARD_PROP_RX_DSP_NAMES:
- val = prop_names_t(_rx_dsps.get_keys());
+ val = prop_names_t(1, "");
return;
case MBOARD_PROP_TX_DSP:
- ASSERT_THROW(_tx_dsps.has_key(name));
- val = _tx_dsps[name]->get_link();
+ ASSERT_THROW(name == "");
+ val = _tx_dsp_proxy->get_link();
return;
case MBOARD_PROP_TX_DSP_NAMES:
- val = prop_names_t(_tx_dsps.get_keys());
+ val = prop_names_t(1, "");
return;
case MBOARD_PROP_CLOCK_CONFIG:
val = _clock_config;
return;
- case MBOARD_PROP_TIME_NOW:
- case MBOARD_PROP_TIME_NEXT_PPS:
+ default:
throw std::runtime_error("Error: trying to get write-only property on usrp2 mboard");
}
@@ -226,27 +262,19 @@ void usrp2_impl::mboard_set(const wax::obj &key, const wax::obj &val){
update_clock_config();
return;
- case MBOARD_PROP_TIME_NOW:{
+ case MBOARD_PROP_TIME_NOW:
set_time_spec(val.as<time_spec_t>(), true);
return;
- }
- case MBOARD_PROP_TIME_NEXT_PPS:{
+ case MBOARD_PROP_TIME_NEXT_PPS:
set_time_spec(val.as<time_spec_t>(), false);
return;
- }
- case MBOARD_PROP_NAME:
- case MBOARD_PROP_OTHERS:
- case MBOARD_PROP_CLOCK_RATE:
- case MBOARD_PROP_RX_DSP:
- case MBOARD_PROP_RX_DSP_NAMES:
- case MBOARD_PROP_TX_DSP:
- case MBOARD_PROP_TX_DSP_NAMES:
- case MBOARD_PROP_RX_DBOARD:
- case MBOARD_PROP_RX_DBOARD_NAMES:
- case MBOARD_PROP_TX_DBOARD:
- case MBOARD_PROP_TX_DBOARD_NAMES:
+ case MBOARD_PROP_STREAM_CMD:
+ issue_ddc_stream_cmd(val.as<stream_cmd_t>());
+ return;
+
+ default:
throw std::runtime_error("Error: trying to set read-only property on usrp2 mboard");
}
diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp
index b3a22e175..a7be2da8c 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.cpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.cpp
@@ -174,28 +174,47 @@ double usrp2_impl::get_master_clock_freq(void){
return 100e6;
}
-void usrp2_impl::poke(boost::uint32_t addr, boost::uint32_t data){
+template <class T> void impl_poke(usrp2_impl *impl, boost::uint32_t addr, T data){
//setup the out data
usrp2_ctrl_data_t out_data;
out_data.id = htonl(USRP2_CTRL_ID_POKE_THIS_REGISTER_FOR_ME_BRO);
out_data.data.poke_args.addr = htonl(addr);
- out_data.data.poke_args.data = htonl(data);
+ out_data.data.poke_args.data = htonl(boost::uint32_t(data));
+ out_data.data.poke_args.num_bytes = sizeof(T);
//send and recv
- usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data);
+ usrp2_ctrl_data_t in_data = impl->ctrl_send_and_recv(out_data);
ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_OMG_POKED_REGISTER_SO_BAD_DUDE);
}
-boost::uint32_t usrp2_impl::peek(boost::uint32_t addr){
+template <class T> T impl_peek(usrp2_impl *impl, boost::uint32_t addr){
//setup the out data
usrp2_ctrl_data_t out_data;
out_data.id = htonl(USRP2_CTRL_ID_PEEK_AT_THIS_REGISTER_FOR_ME_BRO);
out_data.data.poke_args.addr = htonl(addr);
+ out_data.data.poke_args.num_bytes = sizeof(T);
//send and recv
- usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data);
+ usrp2_ctrl_data_t in_data = impl->ctrl_send_and_recv(out_data);
ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE);
- return ntohl(out_data.data.poke_args.data);
+ return T(ntohl(out_data.data.poke_args.data));
+}
+
+
+void usrp2_impl::poke32(boost::uint32_t addr, boost::uint32_t data){
+ return impl_poke<boost::uint32_t>(this, addr, data);
+}
+
+boost::uint32_t usrp2_impl::peek32(boost::uint32_t addr){
+ return impl_peek<boost::uint32_t>(this, addr);
+}
+
+void usrp2_impl::poke16(boost::uint32_t addr, boost::uint16_t data){
+ return impl_poke<boost::uint16_t>(this, addr, data);
+}
+
+boost::uint16_t usrp2_impl::peek16(boost::uint32_t addr){
+ return impl_peek<boost::uint16_t>(this, addr);
}
/***********************************************************************
@@ -236,12 +255,12 @@ void usrp2_impl::get(const wax::obj &key_, wax::obj &val){
return;
case DEVICE_PROP_MBOARD:
- ASSERT_THROW(_mboards.has_key(name));
- val = _mboards[name]->get_link();
+ ASSERT_THROW(name == "");
+ val = _mboard_proxy->get_link();
return;
case DEVICE_PROP_MBOARD_NAMES:
- val = prop_names_t(_mboards.get_keys());
+ val = prop_names_t(1, "");
return;
case DEVICE_PROP_MAX_RX_SAMPLES:
diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp
index 55be420cd..baa6530b8 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.hpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.hpp
@@ -103,8 +103,11 @@ public:
usrp2_ctrl_data_t ctrl_send_and_recv(const usrp2_ctrl_data_t &);
//peek and poke registers
- void poke(boost::uint32_t addr, boost::uint32_t data);
- boost::uint32_t peek(boost::uint32_t addr);
+ void poke32(boost::uint32_t addr, boost::uint32_t data);
+ boost::uint32_t peek32(boost::uint32_t addr);
+
+ void poke16(boost::uint32_t addr, boost::uint16_t data);
+ boost::uint16_t peek16(boost::uint32_t addr);
//misc access methods
double get_master_clock_freq(void);
@@ -135,6 +138,7 @@ private:
;
uhd::transport::smart_buffer::sptr _rx_smart_buff;
boost::asio::const_buffer _rx_copy_buff;
+ size_t _fragment_offset_in_samps;
void io_init(void);
//udp transports for control and data
@@ -159,18 +163,18 @@ private:
void mboard_init(void);
void mboard_get(const wax::obj &, wax::obj &);
void mboard_set(const wax::obj &, const wax::obj &);
- uhd::dict<std::string, wax_obj_proxy::sptr> _mboards;
+ wax_obj_proxy::sptr _mboard_proxy;
//properties interface for rx dboard
void rx_dboard_get(const wax::obj &, wax::obj &);
void rx_dboard_set(const wax::obj &, const wax::obj &);
- uhd::dict<std::string, wax_obj_proxy::sptr> _rx_dboards;
+ wax_obj_proxy::sptr _rx_dboard_proxy;
uhd::prop_names_t _rx_subdevs_in_use;
//properties interface for tx dboard
void tx_dboard_get(const wax::obj &, wax::obj &);
void tx_dboard_set(const wax::obj &, const wax::obj &);
- uhd::dict<std::string, wax_obj_proxy::sptr> _tx_dboards;
+ wax_obj_proxy::sptr _tx_dboard_proxy;
uhd::prop_names_t _tx_subdevs_in_use;
void update_rx_mux_config(void);
void update_tx_mux_config(void);
@@ -192,12 +196,12 @@ private:
//properties interface for ddc
void ddc_get(const wax::obj &, wax::obj &);
void ddc_set(const wax::obj &, const wax::obj &);
- uhd::dict<std::string, wax_obj_proxy::sptr> _rx_dsps;
+ wax_obj_proxy::sptr _rx_dsp_proxy;
//properties interface for duc
void duc_get(const wax::obj &, wax::obj &);
void duc_set(const wax::obj &, const wax::obj &);
- uhd::dict<std::string, wax_obj_proxy::sptr> _tx_dsps;
+ wax_obj_proxy::sptr _tx_dsp_proxy;
};
diff --git a/host/lib/usrp/usrp2/usrp2_regs.hpp b/host/lib/usrp/usrp2/usrp2_regs.hpp
index 10545d712..77d9f4ad9 100644
--- a/host/lib/usrp/usrp2/usrp2_regs.hpp
+++ b/host/lib/usrp/usrp2/usrp2_regs.hpp
@@ -175,11 +175,12 @@
//
// These go to the daughterboard i/o pins
//
-#define _FR_GPIO_ADDR(off) (0xC800 + (off) * sizeof(boost::uint32_t))
-#define FR_GPIO_IO _FR_GPIO_ADDR(0) // tx data in high 16, rx in low 16
-#define FR_GPIO_DDR _FR_GPIO_ADDR(1) // 32 bits, 1 means output. tx in high 16, rx in low 16
-#define FR_GPIO_TX_SEL _FR_GPIO_ADDR(2) // 16 2-bit fields select which source goes to TX DB
-#define FR_GPIO_RX_SEL _FR_GPIO_ADDR(3) // 16 2-bit fields select which source goes to RX DB
+#define FR_GPIO_BASE 0xC800
+
+#define FR_GPIO_IO FR_GPIO_BASE + 0 // 32 bits, gpio io pins (tx high 16 bits, rx low 16 bits)
+#define FR_GPIO_DDR FR_GPIO_BASE + 4 // 32 bits, gpio ddr, 1 means output (tx high 16 bits, rx low 16 bits)
+#define FR_GPIO_TX_SEL FR_GPIO_BASE + 8 // 16 2-bit fields select which source goes to TX DB
+#define FR_GPIO_RX_SEL FR_GPIO_BASE + 12 // 16 2-bit fields select which source goes to RX DB
// each 2-bit sel field is layed out this way
#define FRF_GPIO_SEL_SW 0 // if pin is an output, set by software in the io reg
@@ -190,10 +191,15 @@
///////////////////////////////////////////////////
// ATR Controller, Slave 11
////////////////////////////////////////////////
-#define _FR_ATR_ADDR(off) (0xE400 + (off) * sizeof(boost::uint32_t))
-#define FR_ATR_IDLE _FR_ATR_ADDR(0) // tx data in high 16, rx in low 16
-#define FR_ATR_TX _FR_ATR_ADDR(1)
-#define FR_ATR_RX _FR_ATR_ADDR(2)
-#define FR_ATR_FULL _FR_ATR_ADDR(3)
+#define FR_ATR_BASE 0xE400
+
+#define FR_ATR_IDLE_TXSIDE FR_ATR_BASE + 0
+#define FR_ATR_IDLE_RXSIDE FR_ATR_BASE + 2
+#define FR_ATR_INTX_TXSIDE FR_ATR_BASE + 4
+#define FR_ATR_INTX_RXSIDE FR_ATR_BASE + 6
+#define FR_ATR_INRX_TXSIDE FR_ATR_BASE + 8
+#define FR_ATR_INRX_RXSIDE FR_ATR_BASE + 10
+#define FR_ATR_FULL_TXSIDE FR_ATR_BASE + 12
+#define FR_ATR_FULL_RXSIDE FR_ATR_BASE + 14
#endif /* INCLUDED_USRP2_REGS_HPP */