From 83bd55d63972804e62f3890a4a90c8288fcbad0c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 3 Apr 2010 19:43:20 -0700 Subject: extended stream cmd with mode enum, and extended fragment flags in metadata --- host/include/uhd/device.hpp | 1 + host/include/uhd/types/metadata.hpp | 60 ++++++++++++++++++++++++++++++++--- host/include/uhd/types/stream_cmd.hpp | 32 ++++++++++++------- 3 files changed, 76 insertions(+), 17 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/device.hpp b/host/include/uhd/device.hpp index 4d4196d98..bf7e0753d 100644 --- a/host/include/uhd/device.hpp +++ b/host/include/uhd/device.hpp @@ -112,6 +112,7 @@ public: * and will flag the metadata to show that this is a fragment. * The next call to receive, after the remainder becomes exahausted, * will perform an over-the-wire receive as usual. + * See the rx metadata fragment flags and offset fields for details. * * This is a blocking call and will not return until the number * of samples returned have been written into the buffer. diff --git a/host/include/uhd/types/metadata.hpp b/host/include/uhd/types/metadata.hpp index 6e93040d9..20f483bed 100644 --- a/host/include/uhd/types/metadata.hpp +++ b/host/include/uhd/types/metadata.hpp @@ -29,11 +29,45 @@ namespace uhd{ * The receive routines will convert IF data headers into metadata. */ struct UHD_API rx_metadata_t{ - boost::uint32_t stream_id; - time_spec_t time_spec; + /*! + * Stream IDs may be used to identify source DSP units. + * --Not currently used in any known device implementation.-- + */ bool has_stream_id; + boost::uint32_t stream_id; + + /*! + * Time specification: + * Set from timestamps on incoming data when provided. + */ bool has_time_spec; - bool is_fragment; + time_spec_t time_spec; + + /*! + * Fragmentation flag and offset: + * Similar to IPv4 fragmentation: http://en.wikipedia.org/wiki/IPv4#Fragmentation_and_reassembly + * More fragments is true when the input buffer has insufficient size to fit + * an entire received packet. More fragments will be false for the last fragment. + * The fragment offset is the sample number at the start of the receive buffer. + * For non-fragmented receives, the fragment offset should always be zero. + */ + bool more_fragments; + size_t fragment_offset; + + /*! + * Burst flags: + * Start of burst will be true for the first packet in the chain. + * End of burst will be true for the last packet in the chain. + * --Not currently used in any known device implementation.-- + */ + //bool start_of_burst; + //bool end_of_burst; + + /*! + * Error conditions (TODO): + * Previous packets dropped? + * Timed-out on receive? + */ //default constructor rx_metadata_t(void); @@ -45,10 +79,26 @@ namespace uhd{ * The send routines will convert the metadata to IF data headers. */ struct UHD_API tx_metadata_t{ - boost::uint32_t stream_id; - time_spec_t time_spec; + /*! + * Stream IDs may be used to identify destination DSP units. + * --Not currently used in any known device implementation.-- + */ bool has_stream_id; + boost::uint32_t stream_id; + + /*! + * Time specification: + * Set has time spec to false to perform a send "now". + * Or, set to true, and fill in time spec for a send "at". + */ bool has_time_spec; + time_spec_t time_spec; + + /*! + * Burst flags: + * Set start of burst to true for the first packet in the chain. + * Set end of burst to true for the last packet in the chain. + */ bool start_of_burst; bool end_of_burst; diff --git a/host/include/uhd/types/stream_cmd.hpp b/host/include/uhd/types/stream_cmd.hpp index 97a6b73ce..ff063af29 100644 --- a/host/include/uhd/types/stream_cmd.hpp +++ b/host/include/uhd/types/stream_cmd.hpp @@ -31,24 +31,32 @@ namespace uhd{ * Granular control over what the device streams to the host can be * achieved through submission of multiple (carefully-crafted) commands. * - * The stream_now parameter controls when the stream begins. + * The mode parameter controls how streaming is issued to the device: + * * "Start continuous" tells the device to stream samples indefinitely. + * * "Stop continuous" tells the device to end continuous streaming. + * * "Num samps and done" tells the device to stream num samps and + * to not expect a future stream command for contiguous samples. + * * "Num samps and more" tells the device to stream num samps and + * to expect a future stream command for contiguous samples. + * + * The stream now parameter controls when the stream begins. * When true, the device will begin streaming ASAP. When false, * the device will begin streaming at a time specified by time_spec. - * - * The continuous parameter controls the number of samples received. - * When true, the device continues streaming indefinitely. When false, - * the device will stream the number of samples specified by num_samps. - * - * Standard usage case: - * To start continuous streaming, set stream_now to true and continuous to true. - * To end continuous streaming, set stream_now to true and continuous to false. */ struct UHD_API stream_cmd_t{ + + enum stream_mode_t { + STREAM_MODE_START_CONTINUOUS = 'a', + STREAM_MODE_STOP_CONTINUOUS = 'o', + STREAM_MODE_NUM_SAMPS_AND_DONE = 'd', + STREAM_MODE_NUM_SAMPS_AND_MORE = 'm' + } stream_mode; + size_t num_samps; + bool stream_now; time_spec_t time_spec; - bool continuous; - size_t num_samps; - stream_cmd_t(void); + + stream_cmd_t(const stream_mode_t &stream_mode); }; } //namespace uhd -- cgit v1.2.3 From 12aa8ad74cf3a343159ddbb452455bf4e7f435b8 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 5 Apr 2010 12:18:17 -0700 Subject: added 16 bit peek and poke, 16 bit register defs for gpios and atrs --- firmware/microblaze/apps/txrx.c | 30 ++++++++++++-- host/include/uhd/types/stream_cmd.hpp | 8 ++-- host/lib/usrp/usrp2/dboard_impl.cpp | 4 +- host/lib/usrp/usrp2/dboard_interface.cpp | 70 +++++++++++++------------------- host/lib/usrp/usrp2/dsp_impl.cpp | 12 +++--- host/lib/usrp/usrp2/fw_common.h | 1 + host/lib/usrp/usrp2/mboard_impl.cpp | 8 ++-- host/lib/usrp/usrp2/usrp2_impl.cpp | 31 +++++++++++--- host/lib/usrp/usrp2/usrp2_impl.hpp | 7 +++- host/lib/usrp/usrp2/usrp2_regs.hpp | 28 ++++++++----- 10 files changed, 120 insertions(+), 79 deletions(-) (limited to 'host/include') diff --git a/firmware/microblaze/apps/txrx.c b/firmware/microblaze/apps/txrx.c index 555dd4dd5..69a04d771 100644 --- a/firmware/microblaze/apps/txrx.c +++ b/firmware/microblaze/apps/txrx.c @@ -415,14 +415,38 @@ void handle_udp_ctrl_packet( if (ctrl_data_in->data.poke_args.addr < 0xC000){ printf("error! tried to poke into 0x%x\n", ctrl_data_in->data.poke_args.addr); } - else{ - *((uint32_t *) ctrl_data_in->data.poke_args.addr) = ctrl_data_in->data.poke_args.data; + else switch(ctrl_data_in->data.poke_args.num_bytes){ + case sizeof(uint32_t): + *((uint32_t *) ctrl_data_in->data.poke_args.addr) = (uint32_t)ctrl_data_in->data.poke_args.data; + break; + + case sizeof(uint16_t): + *((uint16_t *) ctrl_data_in->data.poke_args.addr) = (uint16_t)ctrl_data_in->data.poke_args.data; + break; + + case sizeof(uint8_t): + *((uint8_t *) ctrl_data_in->data.poke_args.addr) = (uint8_t)ctrl_data_in->data.poke_args.data; + break; + } ctrl_data_out.id = USRP2_CTRL_ID_OMG_POKED_REGISTER_SO_BAD_DUDE; break; case USRP2_CTRL_ID_PEEK_AT_THIS_REGISTER_FOR_ME_BRO: - ctrl_data_in->data.poke_args.data = *((uint32_t *) ctrl_data_in->data.poke_args.addr); + switch(ctrl_data_in->data.poke_args.num_bytes){ + case sizeof(uint32_t): + ctrl_data_in->data.poke_args.data = *((uint32_t *) ctrl_data_in->data.poke_args.addr); + break; + + case sizeof(uint16_t): + ctrl_data_in->data.poke_args.data = *((uint16_t *) ctrl_data_in->data.poke_args.addr); + break; + + case sizeof(uint8_t): + ctrl_data_in->data.poke_args.data = *((uint8_t *) ctrl_data_in->data.poke_args.addr); + break; + + } ctrl_data_out.id = USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE; break; diff --git a/host/include/uhd/types/stream_cmd.hpp b/host/include/uhd/types/stream_cmd.hpp index ff063af29..41708e2e2 100644 --- a/host/include/uhd/types/stream_cmd.hpp +++ b/host/include/uhd/types/stream_cmd.hpp @@ -32,11 +32,11 @@ namespace uhd{ * achieved through submission of multiple (carefully-crafted) commands. * * The mode parameter controls how streaming is issued to the device: - * * "Start continuous" tells the device to stream samples indefinitely. - * * "Stop continuous" tells the device to end continuous streaming. - * * "Num samps and done" tells the device to stream num samps and + * - "Start continuous" tells the device to stream samples indefinitely. + * - "Stop continuous" tells the device to end continuous streaming. + * - "Num samps and done" tells the device to stream num samps and * to not expect a future stream command for contiguous samples. - * * "Num samps and more" tells the device to stream num samps and + * - "Num samps and more" tells the device to stream num samps and * to expect a future stream command for contiguous samples. * * The stream now parameter controls when the stream begins. diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index 30883cd50..39e4baa7b 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -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..87fc19117 100644 --- a/host/lib/usrp/usrp2/dboard_interface.cpp +++ b/host/lib/usrp/usrp2/dboard_interface.cpp @@ -48,17 +48,6 @@ private: ); usrp2_impl *_impl; - - //shadows - boost::uint32_t _ddr_shadow; - uhd::dict _atr_reg_shadows; - - //utilities - static int bank_to_shift(gpio_bank_t bank){ - static const uhd::dict _bank_to_shift = \ - boost::assign::map_list_of(GPIO_BANK_RX, 0)(GPIO_BANK_TX, 16); - return _bank_to_shift[bank]; - } }; /*********************************************************************** @@ -73,7 +62,6 @@ dboard_interface::sptr make_usrp2_dboard_interface(usrp2_impl *impl){ **********************************************************************/ usrp2_dboard_interface::usrp2_dboard_interface(usrp2_impl *impl){ _impl = impl; - _ddr_shadow = 0; } usrp2_dboard_interface::~usrp2_dboard_interface(void){ @@ -95,42 +83,40 @@ double usrp2_dboard_interface::get_tx_clock_rate(void){ * GPIO **********************************************************************/ 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; + static const uhd::dict bank_to_addr = boost::assign::map_list_of + (GPIO_BANK_RX, FR_GPIO_RX_DDR) + (GPIO_BANK_TX, FR_GPIO_TX_DDR) + ; + _impl->poke16(bank_to_addr[bank], value); } 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)); + static const uhd::dict bank_to_addr = boost::assign::map_list_of + (GPIO_BANK_RX, FR_GPIO_RX_IO) + (GPIO_BANK_TX, FR_GPIO_TX_IO) + ; + return _impl->peek16(bank_to_addr[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 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 + > 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 647a8bf1c..1fe7b7f25 100644 --- a/host/lib/usrp/usrp2/dsp_impl.cpp +++ b/host/lib/usrp/usrp2/dsp_impl.cpp @@ -72,11 +72,11 @@ void usrp2_impl::init_ddc_config(void){ 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) ); } @@ -190,7 +190,7 @@ void usrp2_impl::ddc_set(const wax::obj &key, const wax::obj &val){ 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, + this->poke32(FR_DSP_RX_FREQ, calculate_freq_word_and_update_actual_freq(_ddc_freq, get_master_clock_freq()) ); return; @@ -231,10 +231,10 @@ 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)); } /*********************************************************************** @@ -308,7 +308,7 @@ void usrp2_impl::duc_set(const wax::obj &key, const wax::obj &val){ 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, + this->poke32(FR_DSP_TX_FREQ, calculate_freq_word_and_update_actual_freq(_duc_freq, get_master_clock_freq()) ); return; diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index 7f35c8abd..019f3b931 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -138,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/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 7594c85fa..ceb2ec98f 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -67,19 +67,19 @@ 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); } /*********************************************************************** diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index b3a22e175..d7a9845cd 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 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 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(this, addr, data); +} + +boost::uint32_t usrp2_impl::peek32(boost::uint32_t addr){ + return impl_peek(this, addr); +} + +void usrp2_impl::poke16(boost::uint32_t addr, boost::uint16_t data){ + return impl_poke(this, addr, data); +} + +boost::uint16_t usrp2_impl::peek16(boost::uint32_t addr){ + return impl_peek(this, addr); } /*********************************************************************** diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp index 7c55d4c3c..26f9bb386 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); diff --git a/host/lib/usrp/usrp2/usrp2_regs.hpp b/host/lib/usrp/usrp2/usrp2_regs.hpp index 10545d712..0a2de2c6d 100644 --- a/host/lib/usrp/usrp2/usrp2_regs.hpp +++ b/host/lib/usrp/usrp2/usrp2_regs.hpp @@ -175,11 +175,14 @@ // // 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_RX_IO FR_GPIO_BASE + 0 // 16 io data pins +#define FR_GPIO_TX_IO FR_GPIO_BASE + 2 // 16 io data pins +#define FR_GPIO_RX_DDR FR_GPIO_BASE + 4 // 16 ddr pins, 1 means output +#define FR_GPIO_TX_DDR FR_GPIO_BASE + 6 // 16 ddr pins, 1 means output +#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 +193,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_RXSIDE FR_ATR_BASE + 0 +#define FR_ATR_IDLE_TXSIDE FR_ATR_BASE + 2 +#define FR_ATR_INTX_RXSIDE FR_ATR_BASE + 4 +#define FR_ATR_INTX_TXSIDE FR_ATR_BASE + 6 +#define FR_ATR_INRX_RXSIDE FR_ATR_BASE + 8 +#define FR_ATR_INRX_TXSIDE FR_ATR_BASE + 10 +#define FR_ATR_FULL_RXSIDE FR_ATR_BASE + 12 +#define FR_ATR_FULL_TXSIDE FR_ATR_BASE + 14 #endif /* INCLUDED_USRP2_REGS_HPP */ -- cgit v1.2.3 From 1cc8c6c964d4368d9e918e4cb357600453a24c94 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 5 Apr 2010 14:37:21 -0700 Subject: paradigm shift for the dsp abstraction --- host/examples/rx_timed_samples.cpp | 2 +- host/include/uhd/usrp/dsp_props.hpp | 23 ++- host/include/uhd/usrp/mboard_props.hpp | 3 +- host/include/uhd/usrp/simple_usrp.hpp | 2 - host/include/uhd/usrp/subdev_props.hpp | 2 +- host/lib/usrp/dboard/db_basic_and_lf.cpp | 8 +- host/lib/usrp/simple_usrp.cpp | 46 ++---- host/lib/usrp/tune_helper.cpp | 13 +- host/lib/usrp/usrp2/dsp_impl.cpp | 250 ++++++++++--------------------- host/lib/usrp/usrp2/mboard_impl.cpp | 62 +++++--- 10 files changed, 168 insertions(+), 243 deletions(-) (limited to 'host/include') diff --git a/host/examples/rx_timed_samples.cpp b/host/examples/rx_timed_samples.cpp index 1292d9b27..7b06981b2 100644 --- a/host/examples/rx_timed_samples.cpp +++ b/host/examples/rx_timed_samples.cpp @@ -57,7 +57,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << boost::format("Using Device: %s") % sdev->get_name() << std::endl; //set properties on the device - double rx_rate = sdev->get_rx_rates()[4]; //pick some rate + double rx_rate = 100e6/16; //FIXME get this from somewhere std::cout << boost::format("Setting RX Rate: %f Msps...") % (rx_rate/1e6) << std::endl; sdev->set_rx_rate(rx_rate); std::cout << boost::format("Setting device timestamp to 0...") << std::endl; diff --git a/host/include/uhd/usrp/dsp_props.hpp b/host/include/uhd/usrp/dsp_props.hpp index 60c0df942..75d8c0a60 100644 --- a/host/include/uhd/usrp/dsp_props.hpp +++ b/host/include/uhd/usrp/dsp_props.hpp @@ -24,15 +24,24 @@ namespace uhd{ namespace usrp{ /*! * Possible device dsp properties: - * A dsp can have a wide range of possible properties. - * A ddc would have a properties "decim", "freq", "taps"... - * Other properties could be gains, complex scalars, enables... - * For this reason the only required properties of a dsp is a name - * and a property to get list of other possible properties. + * A dsp is a black box fpga component found between + * the over-the-wire data and the codec pins. + * + * The host rate can be modified to control resampling. + * Resampling can take the form of decimation, interpolation, + * or more complex fractional resampling techniques. + * As usual, read back the host rate after setting it + * to get the actual rate that was set (implementation dependent). + * + * A dsp can also shift the digital stream in frequency. + * Set the shift property and read it back to get actual shift. */ enum dsp_prop_t{ - DSP_PROP_NAME = 'n', //ro, std::string - DSP_PROP_OTHERS = 'o' //ro, prop_names_t + DSP_PROP_NAME = 'n', //ro, std::string + DSP_PROP_OTHERS = 'o', //ro, prop_names_t + DSP_PROP_FREQ_SHIFT = 'f', //rw, double Hz + DSP_PROP_CODEC_RATE = 'c', //ro, double Sps + DSP_PROP_HOST_RATE = 'h' //rw, double Sps }; }} //namespace diff --git a/host/include/uhd/usrp/mboard_props.hpp b/host/include/uhd/usrp/mboard_props.hpp index cfc1f412e..55c11b822 100644 --- a/host/include/uhd/usrp/mboard_props.hpp +++ b/host/include/uhd/usrp/mboard_props.hpp @@ -42,7 +42,8 @@ namespace uhd{ namespace usrp{ MBOARD_PROP_TX_DBOARD_NAMES = 'V', //ro, prop_names_t MBOARD_PROP_CLOCK_CONFIG = 'C', //rw, clock_config_t MBOARD_PROP_TIME_NOW = 't', //wo, time_spec_t - MBOARD_PROP_TIME_NEXT_PPS = 'T' //wo, time_spec_t + MBOARD_PROP_TIME_NEXT_PPS = 'T', //wo, time_spec_t + MBOARD_PROP_STREAM_CMD = 's' //wo, stream_cmd_t }; }} //namespace diff --git a/host/include/uhd/usrp/simple_usrp.hpp b/host/include/uhd/usrp/simple_usrp.hpp index 2d6ad2a0f..6f74a406b 100644 --- a/host/include/uhd/usrp/simple_usrp.hpp +++ b/host/include/uhd/usrp/simple_usrp.hpp @@ -59,7 +59,6 @@ public: ******************************************************************/ virtual void set_rx_rate(double rate) = 0; virtual double get_rx_rate(void) = 0; - virtual std::vector get_rx_rates(void) = 0; virtual tune_result_t set_rx_freq(double freq) = 0; virtual freq_range_t get_rx_freq_range(void) = 0; @@ -77,7 +76,6 @@ public: ******************************************************************/ virtual void set_tx_rate(double rate) = 0; virtual double get_tx_rate(void) = 0; - virtual std::vector get_tx_rates(void) = 0; virtual tune_result_t set_tx_freq(double freq) = 0; virtual freq_range_t get_tx_freq_range(void) = 0; diff --git a/host/include/uhd/usrp/subdev_props.hpp b/host/include/uhd/usrp/subdev_props.hpp index 92d18340b..d35793c6b 100644 --- a/host/include/uhd/usrp/subdev_props.hpp +++ b/host/include/uhd/usrp/subdev_props.hpp @@ -39,7 +39,7 @@ namespace uhd{ namespace usrp{ SUBDEV_PROP_QUADRATURE = 'q', //ro, bool SUBDEV_PROP_IQ_SWAPPED = 'i', //ro, bool SUBDEV_PROP_SPECTRUM_INVERTED = 's', //ro, bool - SUBDEV_PROP_LO_INTERFERES = 'l' //ro, bool + SUBDEV_PROP_USE_LO_OFFSET = 'l' //ro, bool //SUBDEV_PROP_RSSI, //ro, float //----> not on all boards, use named prop //SUBDEV_PROP_BANDWIDTH //rw, double //----> not on all boards, use named prop }; diff --git a/host/lib/usrp/dboard/db_basic_and_lf.cpp b/host/lib/usrp/dboard/db_basic_and_lf.cpp index be4e646ed..930646f76 100644 --- a/host/lib/usrp/dboard/db_basic_and_lf.cpp +++ b/host/lib/usrp/dboard/db_basic_and_lf.cpp @@ -150,7 +150,7 @@ void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){ case SUBDEV_PROP_IQ_SWAPPED: case SUBDEV_PROP_SPECTRUM_INVERTED: - case SUBDEV_PROP_LO_INTERFERES: + case SUBDEV_PROP_USE_LO_OFFSET: val = false; return; } @@ -186,7 +186,7 @@ void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){ case SUBDEV_PROP_QUADRATURE: case SUBDEV_PROP_IQ_SWAPPED: case SUBDEV_PROP_SPECTRUM_INVERTED: - case SUBDEV_PROP_LO_INTERFERES: + case SUBDEV_PROP_USE_LO_OFFSET: throw std::runtime_error(str(boost::format( "Error: trying to set read-only property on %s subdev" ) % dboard_id::to_string(get_rx_id()))); @@ -258,7 +258,7 @@ void basic_tx::tx_get(const wax::obj &key_, wax::obj &val){ case SUBDEV_PROP_IQ_SWAPPED: case SUBDEV_PROP_SPECTRUM_INVERTED: - case SUBDEV_PROP_LO_INTERFERES: + case SUBDEV_PROP_USE_LO_OFFSET: val = false; return; } @@ -294,7 +294,7 @@ void basic_tx::tx_set(const wax::obj &key_, const wax::obj &val){ case SUBDEV_PROP_QUADRATURE: case SUBDEV_PROP_IQ_SWAPPED: case SUBDEV_PROP_SPECTRUM_INVERTED: - case SUBDEV_PROP_LO_INTERFERES: + case SUBDEV_PROP_USE_LO_OFFSET: throw std::runtime_error(str(boost::format( "Error: trying to set read-only property on %s subdev" ) % dboard_id::to_string(get_tx_id()))); diff --git a/host/lib/usrp/simple_usrp.cpp b/host/lib/usrp/simple_usrp.cpp index a0551a630..bd8bac00f 100644 --- a/host/lib/usrp/simple_usrp.cpp +++ b/host/lib/usrp/simple_usrp.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -29,17 +30,6 @@ using namespace uhd; using namespace uhd::usrp; -/*********************************************************************** - * Helper Functions - **********************************************************************/ -static std::vector get_xx_rates(wax::obj decerps, wax::obj rate){ - std::vector rates; - BOOST_FOREACH(size_t decerp, decerps.as >()){ - rates.push_back(rate.as()/decerp); - } - return rates; -} - /*********************************************************************** * Simple Device Implementation **********************************************************************/ @@ -48,8 +38,8 @@ public: simple_usrp_impl(const device_addr_t &addr){ _dev = device::make(addr); _mboard = (*_dev)[DEVICE_PROP_MBOARD]; - _rx_ddc = _mboard[named_prop_t(MBOARD_PROP_RX_DSP, "ddc0")]; - _tx_duc = _mboard[named_prop_t(MBOARD_PROP_TX_DSP, "duc0")]; + _rx_dsp = _mboard[named_prop_t(MBOARD_PROP_RX_DSP, "ddc0")]; //FIX string crap + _tx_dsp = _mboard[named_prop_t(MBOARD_PROP_TX_DSP, "duc0")]; //FIX string crap //extract rx subdevice wax::obj rx_dboard = _mboard[MBOARD_PROP_RX_DBOARD]; @@ -86,7 +76,7 @@ public: } void issue_stream_cmd(const stream_cmd_t &stream_cmd){ - _rx_ddc[std::string("stream_cmd")] = stream_cmd; + _mboard[MBOARD_PROP_STREAM_CMD] = stream_cmd; } void set_clock_config(const clock_config_t &clock_config){ @@ -101,21 +91,15 @@ public: * RX methods ******************************************************************/ void set_rx_rate(double rate){ - double samp_rate = _rx_ddc[std::string("if_rate")].as(); - assert_has(get_rx_rates(), rate, "simple device rx rate"); - _rx_ddc[std::string("decim")] = size_t(samp_rate/rate); + _rx_dsp[DSP_PROP_HOST_RATE] = rate; } double get_rx_rate(void){ - return _rx_ddc[std::string("bb_rate")].as(); - } - - std::vector get_rx_rates(void){ - return get_xx_rates(_rx_ddc[std::string("decims")], _rx_ddc[std::string("if_rate")]); + return _rx_dsp[DSP_PROP_HOST_RATE].as(); } tune_result_t set_rx_freq(double target_freq){ - return tune_rx_subdev_and_ddc(_rx_subdev, _rx_ddc, target_freq); + return tune_rx_subdev_and_ddc(_rx_subdev, _rx_dsp, target_freq); } freq_range_t get_rx_freq_range(void){ @@ -150,21 +134,15 @@ public: * TX methods ******************************************************************/ void set_tx_rate(double rate){ - double samp_rate = _tx_duc[std::string("if_rate")].as(); - assert_has(get_tx_rates(), rate, "simple device tx rate"); - _tx_duc[std::string("interp")] = size_t(samp_rate/rate); + _tx_dsp[DSP_PROP_HOST_RATE] = rate; } double get_tx_rate(void){ - return _tx_duc[std::string("bb_rate")].as(); - } - - std::vector get_tx_rates(void){ - return get_xx_rates(_tx_duc[std::string("interps")], _tx_duc[std::string("if_rate")]); + return _tx_dsp[DSP_PROP_HOST_RATE].as(); } tune_result_t set_tx_freq(double target_freq){ - return tune_tx_subdev_and_duc(_tx_subdev, _tx_duc, target_freq); + return tune_tx_subdev_and_duc(_tx_subdev, _tx_dsp, target_freq); } freq_range_t get_tx_freq_range(void){ @@ -198,8 +176,8 @@ public: private: device::sptr _dev; wax::obj _mboard; - wax::obj _rx_ddc; - wax::obj _tx_duc; + wax::obj _rx_dsp; + wax::obj _tx_dsp; wax::obj _rx_subdev; wax::obj _tx_subdev; }; diff --git a/host/lib/usrp/tune_helper.cpp b/host/lib/usrp/tune_helper.cpp index 79a6aff7b..2fb15064c 100644 --- a/host/lib/usrp/tune_helper.cpp +++ b/host/lib/usrp/tune_helper.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include using namespace uhd; @@ -34,8 +35,8 @@ static tune_result_t tune_xx_subdev_and_dxc( wax::obj subdev_freq_proxy = subdev[SUBDEV_PROP_FREQ]; bool subdev_quadrature = subdev[SUBDEV_PROP_QUADRATURE].as(); bool subdev_spectrum_inverted = subdev[SUBDEV_PROP_SPECTRUM_INVERTED].as(); - wax::obj dxc_freq_proxy = dxc[std::string("freq")]; - double dxc_sample_rate = dxc[std::string("if_rate")].as(); + wax::obj dxc_freq_proxy = dxc[DSP_PROP_FREQ_SHIFT]; + double dxc_sample_rate = dxc[DSP_PROP_CODEC_RATE].as(); // Ask the d'board to tune as closely as it can to target_freq+lo_offset double target_inter_freq = target_freq + lo_offset; @@ -96,8 +97,8 @@ tune_result_t uhd::usrp::tune_rx_subdev_and_ddc( ){ double lo_offset = 0.0; //if the local oscillator will be in the passband, use an offset - if (subdev[SUBDEV_PROP_LO_INTERFERES].as()){ - lo_offset = 2.0*ddc[std::string("bb_rate")].as(); + if (subdev[SUBDEV_PROP_USE_LO_OFFSET].as()){ + lo_offset = 2.0*ddc[DSP_PROP_HOST_RATE].as(); } return tune_rx_subdev_and_ddc(subdev, ddc, target_freq, lo_offset); } @@ -119,8 +120,8 @@ tune_result_t uhd::usrp::tune_tx_subdev_and_duc( ){ double lo_offset = 0.0; //if the local oscillator will be in the passband, use an offset - if (subdev[SUBDEV_PROP_LO_INTERFERES].as()){ - lo_offset = 2.0*duc[std::string("bb_rate")].as(); + if (subdev[SUBDEV_PROP_USE_LO_OFFSET].as()){ + lo_offset = 2.0*duc[DSP_PROP_HOST_RATE].as(); } return tune_tx_subdev_and_duc(subdev, duc, target_freq, lo_offset); } diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp index 1fe7b7f25..559ea38d8 100644 --- a/host/lib/usrp/usrp2/dsp_impl.cpp +++ b/host/lib/usrp/usrp2/dsp_impl.cpp @@ -54,6 +54,16 @@ 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 static rate_t +pick_closest_rate(double exact_rate, const std::vector &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( @@ -81,128 +91,57 @@ void usrp2_impl::update_ddc_config(void){ ); } -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); -} - /*********************************************************************** * 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()){ - 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(); - if (key_name == "if_rate"){ - val = get_master_clock_freq(); + switch(key.as()){ + 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(); - if (key_name == "decim"){ - size_t new_decim = val.as(); - 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(); - 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()) - ); + switch(key.as()){ + + case DSP_PROP_FREQ_SHIFT:{ + double new_freq = val.as(); + 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()); + + case DSP_PROP_HOST_RATE:{ + double extact_rate = get_master_clock_freq()/val.as(); + _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"); + } } /*********************************************************************** @@ -241,80 +180,51 @@ void usrp2_impl::update_duc_config(void){ * 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()){ - 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(); - if (key_name == "if_rate"){ - val = get_master_clock_freq(); + switch(key.as()){ + 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(); - if (key_name == "interp"){ - size_t new_interp = val.as(); - assert_has( - _allowed_decim_and_interp_rates, - new_interp, "usrp2 interpolation" - ); - _duc_interp = new_interp; //shadow - update_duc_config(); + switch(key.as()){ + + case DSP_PROP_FREQ_SHIFT:{ + double new_freq = val.as(); + 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(); - 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()) - ); + + case DSP_PROP_HOST_RATE:{ + double extact_rate = get_master_clock_freq()/val.as(); + _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/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index ceb2ec98f..0891f9dc8 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -82,6 +82,43 @@ void usrp2_impl::set_time_spec(const time_spec_t &time_spec, bool now){ 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); +} + /*********************************************************************** * MBoard Get Properties **********************************************************************/ @@ -179,8 +216,7 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){ 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(), true); return; - } - case MBOARD_PROP_TIME_NEXT_PPS:{ + case MBOARD_PROP_TIME_NEXT_PPS: set_time_spec(val.as(), 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()); + return; + + default: throw std::runtime_error("Error: trying to set read-only property on usrp2 mboard"); } -- cgit v1.2.3 From 57f1f769e5e5bb07a5385955eee9390d0e1de908 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 5 Apr 2010 17:55:13 -0700 Subject: some doxygen fixes after merge --- host/CMakeLists.txt | 2 +- host/Doxyfile.in | 2 +- host/include/uhd/types/device_addr.hpp | 2 +- host/include/uhd/types/dict.hpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'host/include') diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 44dc74f8c..d2889fe58 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -138,7 +138,7 @@ IF(DOXYGEN_FOUND) COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile COMMENT "Generating documentation with doxygen" ) - ADD_CUSTOM_TARGET(doxygen_docs ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR_DOXYGEN}) + ADD_CUSTOM_TARGET(docs ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR_DOXYGEN}) INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR_DOXYGEN} DESTINATION ${PKG_DOC_DIR}) ENDIF(DOXYGEN_FOUND) diff --git a/host/Doxyfile.in b/host/Doxyfile.in index a5a14ac0b..7395516b5 100644 --- a/host/Doxyfile.in +++ b/host/Doxyfile.in @@ -1223,7 +1223,7 @@ ENABLE_PREPROCESSING = YES # compilation will be performed. Macro expansion can be done in a controlled # way by setting EXPAND_ONLY_PREDEF to YES. -MACRO_EXPANSION = NO +MACRO_EXPANSION = YES # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES # then the macro expansion is limited to the macros specified with the diff --git a/host/include/uhd/types/device_addr.hpp b/host/include/uhd/types/device_addr.hpp index 1162884fb..f5dd9371c 100644 --- a/host/include/uhd/types/device_addr.hpp +++ b/host/include/uhd/types/device_addr.hpp @@ -32,7 +32,7 @@ namespace uhd{ * * To narrow down the discovery process to a particular device, * specify a transport key/value pair specific to your device. - * Ex, to find a usrp2: my_dev_addr["addr"] = + * Ex, to find a usrp2: my_dev_addr["addr"] = [resolvable_hostname_or_ip] * * The device address can also be used to pass arguments into * the transport layer control to set (for example) buffer sizes. diff --git a/host/include/uhd/types/dict.hpp b/host/include/uhd/types/dict.hpp index 7fb712e76..22f702575 100644 --- a/host/include/uhd/types/dict.hpp +++ b/host/include/uhd/types/dict.hpp @@ -62,7 +62,7 @@ namespace uhd{ /*! * Get the number of elements in this dict. - * \param the number of elements + * \return the number of elements */ std::size_t size(void) const{ return _map.size(); -- cgit v1.2.3 From ed5cb33eb402c5d34c330d1b9dcb99658c628a72 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 5 Apr 2010 18:11:32 -0700 Subject: renamed dict get key and value methods --- host/include/uhd/types/dict.hpp | 4 ++-- host/lib/device.cpp | 4 ++-- host/lib/types.cpp | 4 ++-- host/lib/usrp/dboard_manager.cpp | 4 ++-- host/test/addr_test.cpp | 8 ++++---- host/test/gain_handler_test.cpp | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/types/dict.hpp b/host/include/uhd/types/dict.hpp index 22f702575..c8fbc5a9f 100644 --- a/host/include/uhd/types/dict.hpp +++ b/host/include/uhd/types/dict.hpp @@ -73,7 +73,7 @@ namespace uhd{ * Key order depends on insertion precedence. * \return vector of keys */ - std::vector get_keys(void) const{ + const std::vector keys(void) const{ std::vector keys; BOOST_FOREACH(const pair_t &p, _map){ keys.push_back(p.first); @@ -86,7 +86,7 @@ namespace uhd{ * Value order depends on insertion precedence. * \return vector of values */ - std::vector get_vals(void) const{ + const std::vector vals(void) const{ std::vector vals; BOOST_FOREACH(const pair_t &p, _map){ vals.push_back(p.second); diff --git a/host/lib/device.cpp b/host/lib/device.cpp index 27a365d34..0197a6232 100644 --- a/host/lib/device.cpp +++ b/host/lib/device.cpp @@ -42,7 +42,7 @@ static size_t hash_device_addr( const device_addr_t &dev_addr ){ //sort the keys of the device address - std::vector keys = dev_addr.get_keys(); + std::vector keys = dev_addr.keys(); std::sort(keys.begin(), keys.end()); //combine the hashes of sorted keys/value pairs @@ -99,7 +99,7 @@ device::sptr device::make(const device_addr_t &hint, size_t which){ BOOST_FOREACH(device_addr_t dev_addr, fcn.get<0>()(hint)){ //copy keys that were in hint but not in dev_addr //this way, we can pass additional transport arguments - BOOST_FOREACH(const std::string &key, hint.get_keys()){ + BOOST_FOREACH(const std::string &key, hint.keys()){ if (not dev_addr.has_key(key)) dev_addr[key] = hint[key]; } //append the discovered address and its factory function diff --git a/host/lib/types.cpp b/host/lib/types.cpp index d87238161..61a63b710 100644 --- a/host/lib/types.cpp +++ b/host/lib/types.cpp @@ -122,7 +122,7 @@ time_spec_t::time_spec_t(boost::posix_time::ptime time, double tick_rate){ std::string device_addr_t::to_string(void) const{ const device_addr_t &device_addr = *this; std::stringstream ss; - BOOST_FOREACH(std::string key, device_addr.get_keys()){ + BOOST_FOREACH(std::string key, device_addr.keys()){ ss << boost::format("%s: %s") % key % device_addr[key] << std::endl; } return ss.str(); @@ -138,7 +138,7 @@ static std::string trim(const std::string &in){ std::string device_addr_t::to_args_str(void) const{ std::string args_str; const device_addr_t &device_addr = *this; - BOOST_FOREACH(const std::string &key, device_addr.get_keys()){ + BOOST_FOREACH(const std::string &key, device_addr.keys()){ args_str += key + pair_delim + device_addr[key] + arg_delim; } return args_str; diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp index 3a5cf3a35..4cf2e5820 100644 --- a/host/lib/usrp/dboard_manager.cpp +++ b/host/lib/usrp/dboard_manager.cpp @@ -250,11 +250,11 @@ dboard_manager_impl::~dboard_manager_impl(void){ } prop_names_t dboard_manager_impl::get_rx_subdev_names(void){ - return _rx_dboards.get_keys(); + return _rx_dboards.keys(); } prop_names_t dboard_manager_impl::get_tx_subdev_names(void){ - return _tx_dboards.get_keys(); + return _tx_dboards.keys(); } wax::obj dboard_manager_impl::get_rx_subdev(const std::string &subdev_name){ diff --git a/host/test/addr_test.cpp b/host/test/addr_test.cpp index a5d2d4c06..2ec6de14b 100644 --- a/host/test/addr_test.cpp +++ b/host/test/addr_test.cpp @@ -50,16 +50,16 @@ BOOST_AUTO_TEST_CASE(test_device_addr){ BOOST_CHECK_EQUAL(dev_addr.size(), new_dev_addr.size()); //the keys should match - std::vector old_dev_addr_keys = dev_addr.get_keys(); - std::vector new_dev_addr_keys = new_dev_addr.get_keys(); + std::vector old_dev_addr_keys = dev_addr.keys(); + std::vector new_dev_addr_keys = new_dev_addr.keys(); BOOST_CHECK_EQUAL_COLLECTIONS( old_dev_addr_keys.begin(), old_dev_addr_keys.end(), new_dev_addr_keys.begin(), new_dev_addr_keys.end() ); //the vals should match - std::vector old_dev_addr_vals = dev_addr.get_vals(); - std::vector new_dev_addr_vals = new_dev_addr.get_vals(); + std::vector old_dev_addr_vals = dev_addr.vals(); + std::vector new_dev_addr_vals = new_dev_addr.vals(); BOOST_CHECK_EQUAL_COLLECTIONS( old_dev_addr_vals.begin(), old_dev_addr_vals.end(), new_dev_addr_vals.begin(), new_dev_addr_vals.end() diff --git a/host/test/gain_handler_test.cpp b/host/test/gain_handler_test.cpp index 72d26e1c2..bf2ec5db7 100644 --- a/host/test/gain_handler_test.cpp +++ b/host/test/gain_handler_test.cpp @@ -70,7 +70,7 @@ private: return; case PROP_GAIN_NAMES: - val = _gain_values.get_keys(); + val = _gain_values.keys(); return; } } -- cgit v1.2.3 From 8740bc7149717673c4580767142ce2563035d4cb Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 5 Apr 2010 18:32:33 -0700 Subject: handle tx fragment eob flag case --- host/include/uhd/device.hpp | 1 + host/lib/usrp/usrp2/io_impl.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'host/include') diff --git a/host/include/uhd/device.hpp b/host/include/uhd/device.hpp index bf7e0753d..ae75e6dc8 100644 --- a/host/include/uhd/device.hpp +++ b/host/include/uhd/device.hpp @@ -83,6 +83,7 @@ public: * If the buffer has more samples than the maximum supported, * the send method will send the maximum number of samples * as supported by the transport and return the number sent. + * In this case, the end of burst flag will be forced to false. * It is up to the caller to call send again on the un-sent * portions of the buffer, until the buffer is exhausted. * diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp index 5820841d7..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]++; -- cgit v1.2.3