From 0da74522a5fded7b2901c4bd49c1d43f43ef376d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 1 Apr 2010 19:01:17 -0700 Subject: windows fix, forgot boost namespace for stdint --- host/lib/usrp/usrp2/dboard_interface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'host/lib/usrp/usrp2/dboard_interface.cpp') diff --git a/host/lib/usrp/usrp2/dboard_interface.cpp b/host/lib/usrp/usrp2/dboard_interface.cpp index dcd6453a8..2e79381c5 100644 --- a/host/lib/usrp/usrp2/dboard_interface.cpp +++ b/host/lib/usrp/usrp2/dboard_interface.cpp @@ -51,7 +51,7 @@ private: //shadows boost::uint32_t _ddr_shadow; - uhd::dict _atr_reg_shadows; + uhd::dict _atr_reg_shadows; //utilities static int bank_to_shift(gpio_bank_t bank){ -- 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/lib/usrp/usrp2/dboard_interface.cpp') 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 97496ace66842f9d7529793b2b202be9abe156c3 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 5 Apr 2010 16:36:51 -0700 Subject: simplified the usage of dboard, dsp, and mboard proxies. removed the dict structure for each, we are just going to have one. --- host/examples/rx_timed_samples.cpp | 4 +++- host/lib/usrp/simple_usrp.cpp | 4 ++-- host/lib/usrp/usrp2/dboard_impl.cpp | 4 ++-- host/lib/usrp/usrp2/dboard_interface.cpp | 8 ++++++++ host/lib/usrp/usrp2/dsp_impl.cpp | 4 ++-- host/lib/usrp/usrp2/mboard_impl.cpp | 26 +++++++++++++------------- host/lib/usrp/usrp2/usrp2_impl.cpp | 6 +++--- host/lib/usrp/usrp2/usrp2_impl.hpp | 10 +++++----- 8 files changed, 38 insertions(+), 28 deletions(-) (limited to 'host/lib/usrp/usrp2/dboard_interface.cpp') diff --git a/host/examples/rx_timed_samples.cpp b/host/examples/rx_timed_samples.cpp index 7b06981b2..e971e9f6a 100644 --- a/host/examples/rx_timed_samples.cpp +++ b/host/examples/rx_timed_samples.cpp @@ -29,6 +29,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::string transport_args; int seconds_in_future; size_t total_num_samps; + double rx_rate; //setup the program options po::options_description desc("Allowed options"); @@ -37,6 +38,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ ("args", po::value(&transport_args)->default_value(""), "simple uhd transport args") ("secs", po::value(&seconds_in_future)->default_value(3), "number of seconds in the future to receive") ("nsamps", po::value(&total_num_samps)->default_value(1000), "total number of samples to receive") + ("rxrate", po::value(&rx_rate)->default_value(100e6/16), "rate of incoming samples") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); @@ -57,9 +59,9 @@ 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 = 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("Actual RX Rate: %f Msps...") % (sdev->get_rx_rate()/1e6) << std::endl; std::cout << boost::format("Setting device timestamp to 0...") << std::endl; sdev->set_time_now(uhd::time_spec_t(0)); diff --git a/host/lib/usrp/simple_usrp.cpp b/host/lib/usrp/simple_usrp.cpp index bd8bac00f..fb3cc8eec 100644 --- a/host/lib/usrp/simple_usrp.cpp +++ b/host/lib/usrp/simple_usrp.cpp @@ -38,8 +38,8 @@ public: simple_usrp_impl(const device_addr_t &addr){ _dev = device::make(addr); _mboard = (*_dev)[DEVICE_PROP_MBOARD]; - _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 + _rx_dsp = _mboard[MBOARD_PROP_RX_DSP]; + _tx_dsp = _mboard[MBOARD_PROP_TX_DSP]; //extract rx subdevice wax::obj rx_dboard = _mboard[MBOARD_PROP_RX_DBOARD]; diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index 39e4baa7b..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) ); diff --git a/host/lib/usrp/usrp2/dboard_interface.cpp b/host/lib/usrp/usrp2/dboard_interface.cpp index 87fc19117..d7c18983a 100644 --- a/host/lib/usrp/usrp2/dboard_interface.cpp +++ b/host/lib/usrp/usrp2/dboard_interface.cpp @@ -62,6 +62,14 @@ dboard_interface::sptr make_usrp2_dboard_interface(usrp2_impl *impl){ **********************************************************************/ usrp2_dboard_interface::usrp2_dboard_interface(usrp2_impl *impl){ _impl = impl; + + //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){ diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp index 559ea38d8..92b55d029 100644 --- a/host/lib/usrp/usrp2/dsp_impl.cpp +++ b/host/lib/usrp/usrp2/dsp_impl.cpp @@ -66,7 +66,7 @@ pick_closest_rate(double exact_rate, const std::vector &rates){ 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) ); @@ -149,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) ); diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 0891f9dc8..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) ); @@ -173,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: @@ -195,21 +195,21 @@ 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: diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index d7a9845cd..a7be2da8c 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -255,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 26f9bb386..baa6530b8 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.hpp +++ b/host/lib/usrp/usrp2/usrp2_impl.hpp @@ -163,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 _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 _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 _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); @@ -196,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 _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 _tx_dsps; + wax_obj_proxy::sptr _tx_dsp_proxy; }; -- cgit v1.2.3 From 8ee3d7200169983e7a20409ed5e8c37907fe66e1 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 5 Apr 2010 19:35:34 -0700 Subject: GPIO tested working on usrp. Write gpio regs in 32 bit chunks. ATR regs rx side is high address. --- host/lib/usrp/dboard/db_basic_and_lf.cpp | 40 +++++++++++--------------------- host/lib/usrp/usrp2/dboard_interface.cpp | 25 ++++++++++++-------- host/lib/usrp/usrp2/usrp2_regs.hpp | 22 ++++++++---------- 3 files changed, 39 insertions(+), 48 deletions(-) (limited to 'host/lib/usrp/usrp2/dboard_interface.cpp') diff --git a/host/lib/usrp/dboard/db_basic_and_lf.cpp b/host/lib/usrp/dboard/db_basic_and_lf.cpp index 930646f76..3c14e473e 100644 --- a/host/lib/usrp/dboard/db_basic_and_lf.cpp +++ b/host/lib/usrp/dboard/db_basic_and_lf.cpp @@ -87,8 +87,6 @@ UHD_STATIC_BLOCK(reg_dboards){ **********************************************************************/ basic_rx::basic_rx(ctor_args_t const& args, double max_freq) : rx_dboard_base(args){ _max_freq = max_freq; - // set the gpios to safe values (all inputs) - get_interface()->set_gpio_ddr(dboard_interface::GPIO_BANK_RX, 0x0000); } basic_rx::~basic_rx(void){ @@ -149,7 +147,13 @@ void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){ return; case SUBDEV_PROP_IQ_SWAPPED: + val = false; + return; + case SUBDEV_PROP_SPECTRUM_INVERTED: + val = false; + return; + case SUBDEV_PROP_USE_LO_OFFSET: val = false; return; @@ -177,17 +181,7 @@ void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){ case SUBDEV_PROP_FREQ: return; // it wont do you much good, but you can set it - case SUBDEV_PROP_NAME: - case SUBDEV_PROP_OTHERS: - case SUBDEV_PROP_GAIN_RANGE: - case SUBDEV_PROP_GAIN_NAMES: - case SUBDEV_PROP_FREQ_RANGE: - case SUBDEV_PROP_ANTENNA_NAMES: - case SUBDEV_PROP_QUADRATURE: - case SUBDEV_PROP_IQ_SWAPPED: - case SUBDEV_PROP_SPECTRUM_INVERTED: - case SUBDEV_PROP_USE_LO_OFFSET: - throw std::runtime_error(str(boost::format( + default: throw std::runtime_error(str(boost::format( "Error: trying to set read-only property on %s subdev" ) % dboard_id::to_string(get_rx_id()))); } @@ -198,8 +192,6 @@ void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){ **********************************************************************/ basic_tx::basic_tx(ctor_args_t const& args, double max_freq) : tx_dboard_base(args){ _max_freq = max_freq; - // set the gpios to safe values (all inputs) - get_interface()->set_gpio_ddr(dboard_interface::GPIO_BANK_TX, 0x0000); } basic_tx::~basic_tx(void){ @@ -257,7 +249,13 @@ void basic_tx::tx_get(const wax::obj &key_, wax::obj &val){ return; case SUBDEV_PROP_IQ_SWAPPED: + val = false; + return; + case SUBDEV_PROP_SPECTRUM_INVERTED: + val = false; + return; + case SUBDEV_PROP_USE_LO_OFFSET: val = false; return; @@ -285,17 +283,7 @@ void basic_tx::tx_set(const wax::obj &key_, const wax::obj &val){ case SUBDEV_PROP_FREQ: return; // it wont do you much good, but you can set it - case SUBDEV_PROP_NAME: - case SUBDEV_PROP_OTHERS: - case SUBDEV_PROP_GAIN_RANGE: - case SUBDEV_PROP_GAIN_NAMES: - case SUBDEV_PROP_FREQ_RANGE: - case SUBDEV_PROP_ANTENNA_NAMES: - case SUBDEV_PROP_QUADRATURE: - case SUBDEV_PROP_IQ_SWAPPED: - case SUBDEV_PROP_SPECTRUM_INVERTED: - case SUBDEV_PROP_USE_LO_OFFSET: - throw std::runtime_error(str(boost::format( + default: 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/usrp2/dboard_interface.cpp b/host/lib/usrp/usrp2/dboard_interface.cpp index d7c18983a..6dd756420 100644 --- a/host/lib/usrp/usrp2/dboard_interface.cpp +++ b/host/lib/usrp/usrp2/dboard_interface.cpp @@ -48,6 +48,7 @@ private: ); usrp2_impl *_impl; + boost::uint32_t _ddr_shadow; }; /*********************************************************************** @@ -62,6 +63,7 @@ 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; @@ -90,20 +92,23 @@ 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){ - 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); + _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){ - 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]); + 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 atr, boost::uint16_t value){ diff --git a/host/lib/usrp/usrp2/usrp2_regs.hpp b/host/lib/usrp/usrp2/usrp2_regs.hpp index 0a2de2c6d..77d9f4ad9 100644 --- a/host/lib/usrp/usrp2/usrp2_regs.hpp +++ b/host/lib/usrp/usrp2/usrp2_regs.hpp @@ -177,10 +177,8 @@ // #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_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 @@ -195,13 +193,13 @@ //////////////////////////////////////////////// #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 +#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 */ -- cgit v1.2.3