diff options
author | Philip Balister <philip@opensdr.com> | 2010-04-13 16:38:42 +0000 |
---|---|---|
committer | Philip Balister <philip@opensdr.com> | 2010-04-13 16:38:42 +0000 |
commit | f1838b9284a124fcfb5996eaf1647a69b4473278 (patch) | |
tree | 15e69f3641f8919fae201ec002a2edfc61f6cb42 /host/lib/usrp/usrp2/dboard_interface.cpp | |
parent | b59c54e334dfc1c6ab7da81c62038444f93efe61 (diff) | |
parent | 41a515f3f97ae77b7c1b4371fdef7c085dce8c1c (diff) | |
download | uhd-f1838b9284a124fcfb5996eaf1647a69b4473278.tar.gz uhd-f1838b9284a124fcfb5996eaf1647a69b4473278.tar.bz2 uhd-f1838b9284a124fcfb5996eaf1647a69b4473278.zip |
Merge branch 'usrp_e' of git@ettus.sourcerepo.com:ettus/uhd into usrp_e
Diffstat (limited to 'host/lib/usrp/usrp2/dboard_interface.cpp')
-rw-r--r-- | host/lib/usrp/usrp2/dboard_interface.cpp | 79 |
1 files changed, 39 insertions, 40 deletions
diff --git a/host/lib/usrp/usrp2/dboard_interface.cpp b/host/lib/usrp/usrp2/dboard_interface.cpp index dcd6453a8..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, 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); } /*********************************************************************** |