diff options
author | Josh Blum <josh@joshknows.com> | 2010-11-29 12:26:57 -0500 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-11-29 12:26:57 -0500 |
commit | d96252d6dcf24a8dec9a2f171bd8f305702d8432 (patch) | |
tree | 33715f0f7b0cb5fdef933a0aa8f646c344e61674 /host | |
parent | 3e268baedbb93fd51888d991e53abf6f658c4c97 (diff) | |
parent | 9a2e26e5004d3f740c9690ad8b0b85debcb51c7a (diff) | |
download | uhd-d96252d6dcf24a8dec9a2f171bd8f305702d8432.tar.gz uhd-d96252d6dcf24a8dec9a2f171bd8f305702d8432.tar.bz2 uhd-d96252d6dcf24a8dec9a2f171bd8f305702d8432.zip |
Merge branch 'dboard_iface_gpio'
Diffstat (limited to 'host')
-rw-r--r-- | host/include/uhd/usrp/dboard_iface.hpp | 76 | ||||
-rw-r--r-- | host/lib/usrp/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/lib/usrp/dboard/db_basic_and_lf.cpp | 2 | ||||
-rw-r--r-- | host/lib/usrp/dboard_iface.cpp | 78 | ||||
-rw-r--r-- | host/lib/usrp/dboard_manager.cpp | 2 | ||||
-rw-r--r-- | host/lib/usrp/usrp1/dboard_iface.cpp | 16 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/dboard_iface.cpp | 16 | ||||
-rw-r--r-- | host/lib/usrp/usrp_e100/dboard_iface.cpp | 16 |
8 files changed, 172 insertions, 35 deletions
diff --git a/host/include/uhd/usrp/dboard_iface.hpp b/host/include/uhd/usrp/dboard_iface.hpp index c430ecd3f..b04756c47 100644 --- a/host/include/uhd/usrp/dboard_iface.hpp +++ b/host/include/uhd/usrp/dboard_iface.hpp @@ -19,6 +19,7 @@ #define INCLUDED_UHD_USRP_DBOARD_IFACE_HPP #include <uhd/config.hpp> +#include <uhd/utils/pimpl.hpp> #include <uhd/types/serial.hpp> #include <boost/shared_ptr.hpp> #include <boost/cstdint.hpp> @@ -114,38 +115,83 @@ public: /*! * Set a daughterboard output pin control source. - * By default, the outputs are all GPIO controlled. * * \param unit which unit rx or tx * \param value 16-bits, 0=GPIO controlled, 1=ATR controlled + * \param mask 16-bits, 0=do not change, 1=change value */ - virtual void set_pin_ctrl(unit_t unit, boost::uint16_t value) = 0; + virtual void set_pin_ctrl( + unit_t unit, boost::uint16_t value, boost::uint16_t mask = 0xffff + ); + + /*! + * Read back the pin control setting. + * + * \param unit which unit rx or tx + * \return the 16-bit settings value + */ + virtual boost::uint16_t get_pin_ctrl(unit_t unit); /*! * Set a daughterboard ATR register. * * \param unit which unit rx or tx - * \param reg which ATR register to set + * \param reg which ATR register * \param value 16-bits, 0=ATR output low, 1=ATR output high + * \param mask 16-bits, 0=do not change, 1=change value */ - virtual void set_atr_reg(unit_t unit, atr_reg_t reg, boost::uint16_t value) = 0; + virtual void set_atr_reg( + unit_t unit, atr_reg_t reg, boost::uint16_t value, boost::uint16_t mask = 0xffff + ); /*! - * Set daughterboard GPIO data direction register. - * By default, the GPIO pins are all inputs. + * Read back an ATR register setting. + * + * \param unit which unit rx or tx + * \param reg which ATR register + * \return the 16-bit settings value + */ + virtual boost::uint16_t get_atr_reg(unit_t unit, atr_reg_t reg); + + /*! + * Set daughterboard GPIO data direction setting. * * \param unit which unit rx or tx * \param value 16-bits, 0=GPIO input, 1=GPIO output + * \param mask 16-bits, 0=do not change, 1=change value */ - virtual void set_gpio_ddr(unit_t unit, boost::uint16_t value) = 0; + virtual void set_gpio_ddr( + unit_t unit, boost::uint16_t value, boost::uint16_t mask = 0xffff + ); /*! - * Read daughterboard GPIO pin values. + * Read back the GPIO data direction setting. + * + * \param unit which unit rx or tx + * \return the 16-bit settings value + */ + virtual boost::uint16_t get_gpio_ddr(unit_t unit); + + /*! + * Set daughterboard GPIO pin output setting. * * \param unit which unit rx or tx * \param value 16-bits, 0=GPIO output low, 1=GPIO output high + * \param mask 16-bits, 0=do not change, 1=change value */ - virtual void write_gpio(unit_t unit, boost::uint16_t value) = 0; + virtual void set_gpio_out( + unit_t unit, boost::uint16_t value, boost::uint16_t mask = 0xffff + ); + + /*! + * Read back the GPIO pin output setting. + * + * \param unit which unit rx or tx + * \return the 16-bit settings value + */ + virtual boost::uint16_t get_gpio_out(unit_t unit); + + UHD_DEPRECATED void write_gpio(unit_t unit, boost::uint16_t value){set_gpio_out(unit, value);} /*! * Setup the GPIO debug mux. @@ -251,6 +297,18 @@ public: * \return the codec rate in Hz */ virtual double get_codec_rate(unit_t unit) = 0; + +private: + UHD_PIMPL_DECL(impl) _impl; + + virtual void _set_pin_ctrl(unit_t unit, boost::uint16_t value) = 0; + virtual void _set_atr_reg(unit_t unit, atr_reg_t reg, boost::uint16_t value) = 0; + virtual void _set_gpio_ddr(unit_t unit, boost::uint16_t value) = 0; + virtual void _set_gpio_out(unit_t unit, boost::uint16_t value) = 0; + +protected: + dboard_iface(void); + }; }} //namespace diff --git a/host/lib/usrp/CMakeLists.txt b/host/lib/usrp/CMakeLists.txt index 073b3c80b..bd26d29a1 100644 --- a/host/lib/usrp/CMakeLists.txt +++ b/host/lib/usrp/CMakeLists.txt @@ -21,6 +21,7 @@ LIBUHD_APPEND_SOURCES( ${CMAKE_SOURCE_DIR}/lib/usrp/dboard_base.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/dboard_eeprom.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/dboard_id.cpp + ${CMAKE_SOURCE_DIR}/lib/usrp/dboard_iface.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/dboard_manager.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/dsp_utils.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/mboard_eeprom.cpp diff --git a/host/lib/usrp/dboard/db_basic_and_lf.cpp b/host/lib/usrp/dboard/db_basic_and_lf.cpp index 73f894374..f771595b6 100644 --- a/host/lib/usrp/dboard/db_basic_and_lf.cpp +++ b/host/lib/usrp/dboard/db_basic_and_lf.cpp @@ -110,7 +110,7 @@ basic_rx::basic_rx(ctor_args_t args, double max_freq) : rx_dboard_base(args){ //set GPIOs to output 0x0000 to decrease noise pickup this->get_iface()->set_pin_ctrl(dboard_iface::UNIT_RX, 0x0000); this->get_iface()->set_gpio_ddr(dboard_iface::UNIT_RX, 0xFFFF); - this->get_iface()->write_gpio(dboard_iface::UNIT_RX, 0x0000); + this->get_iface()->set_gpio_out(dboard_iface::UNIT_RX, 0x0000); } basic_rx::~basic_rx(void){ diff --git a/host/lib/usrp/dboard_iface.cpp b/host/lib/usrp/dboard_iface.cpp new file mode 100644 index 000000000..5cc5ea470 --- /dev/null +++ b/host/lib/usrp/dboard_iface.cpp @@ -0,0 +1,78 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#include <uhd/usrp/dboard_iface.hpp> +#include <uhd/types/dict.hpp> + +using namespace uhd::usrp; + +struct dboard_iface::impl{ + uhd::dict<unit_t, boost::uint16_t> pin_ctrl_shadow; + uhd::dict<unit_t, uhd::dict<atr_reg_t, boost::uint16_t> > atr_reg_shadow; + uhd::dict<unit_t, boost::uint16_t> gpio_ddr_shadow; + uhd::dict<unit_t, boost::uint16_t> gpio_out_shadow; +}; + +dboard_iface::dboard_iface(void){ + _impl = UHD_PIMPL_MAKE(impl, ()); +} + +template <typename T> +static T shadow_it(T &shadow, const T &value, const T &mask){ + shadow = (shadow & ~mask) | (value & mask); + return shadow; +} + +void dboard_iface::set_pin_ctrl( + unit_t unit, boost::uint16_t value, boost::uint16_t mask +){ + _set_pin_ctrl(unit, shadow_it(_impl->pin_ctrl_shadow[unit], value, mask)); +} + +boost::uint16_t dboard_iface::get_pin_ctrl(unit_t unit){ + return _impl->pin_ctrl_shadow[unit]; +} + +void dboard_iface::set_atr_reg( + unit_t unit, atr_reg_t reg, boost::uint16_t value, boost::uint16_t mask +){ + _set_atr_reg(unit, reg, shadow_it(_impl->atr_reg_shadow[unit][reg], value, mask)); +} + +boost::uint16_t dboard_iface::get_atr_reg(unit_t unit, atr_reg_t reg){ + return _impl->atr_reg_shadow[unit][reg]; +} + +void dboard_iface::set_gpio_ddr( + unit_t unit, boost::uint16_t value, boost::uint16_t mask +){ + _set_gpio_ddr(unit, shadow_it(_impl->gpio_ddr_shadow[unit], value, mask)); +} + +boost::uint16_t dboard_iface::get_gpio_ddr(unit_t unit){ + return _impl->gpio_ddr_shadow[unit]; +} + +void dboard_iface::set_gpio_out( + unit_t unit, boost::uint16_t value, boost::uint16_t mask +){ + _set_gpio_out(unit, shadow_it(_impl->gpio_out_shadow[unit], value, mask)); +} + +boost::uint16_t dboard_iface::get_gpio_out(unit_t unit){ + return _impl->gpio_out_shadow[unit]; +} diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp index 5a98bb8eb..72bfd89e8 100644 --- a/host/lib/usrp/dboard_manager.cpp +++ b/host/lib/usrp/dboard_manager.cpp @@ -327,7 +327,7 @@ void dboard_manager_impl::set_nice_dboard_if(void){ //set nice settings on each unit BOOST_FOREACH(dboard_iface::unit_t unit, units){ _iface->set_gpio_ddr(unit, 0x0000); //all inputs - _iface->write_gpio(unit, 0x0000); //all low + _iface->set_gpio_out(unit, 0x0000); //all low _iface->set_pin_ctrl(unit, 0x0000); //all gpio _iface->set_clock_enabled(unit, false); //clock off } diff --git a/host/lib/usrp/usrp1/dboard_iface.cpp b/host/lib/usrp/usrp1/dboard_iface.cpp index 1ac15a46a..70ce3da76 100644 --- a/host/lib/usrp/usrp1/dboard_iface.cpp +++ b/host/lib/usrp/usrp1/dboard_iface.cpp @@ -75,10 +75,10 @@ public: void write_aux_dac(unit_t, aux_dac_t, float); float read_aux_adc(unit_t, aux_adc_t); - void set_pin_ctrl(unit_t, boost::uint16_t); - void set_atr_reg(unit_t, atr_reg_t, boost::uint16_t); - void set_gpio_ddr(unit_t, boost::uint16_t); - void write_gpio(unit_t, boost::uint16_t); + void _set_pin_ctrl(unit_t, boost::uint16_t); + void _set_atr_reg(unit_t, atr_reg_t, boost::uint16_t); + void _set_gpio_ddr(unit_t, boost::uint16_t); + void _set_gpio_out(unit_t, boost::uint16_t); void set_gpio_debug(unit_t, int); boost::uint16_t read_gpio(unit_t); @@ -184,7 +184,7 @@ double usrp1_dboard_iface::get_codec_rate(unit_t){ /*********************************************************************** * GPIO **********************************************************************/ -void usrp1_dboard_iface::set_pin_ctrl(unit_t unit, boost::uint16_t value) +void usrp1_dboard_iface::_set_pin_ctrl(unit_t unit, boost::uint16_t value) { switch(unit) { case UNIT_RX: @@ -202,7 +202,7 @@ void usrp1_dboard_iface::set_pin_ctrl(unit_t unit, boost::uint16_t value) } } -void usrp1_dboard_iface::set_gpio_ddr(unit_t unit, boost::uint16_t value) +void usrp1_dboard_iface::_set_gpio_ddr(unit_t unit, boost::uint16_t value) { switch(unit) { case UNIT_RX: @@ -220,7 +220,7 @@ void usrp1_dboard_iface::set_gpio_ddr(unit_t unit, boost::uint16_t value) } } -void usrp1_dboard_iface::write_gpio(unit_t unit, boost::uint16_t value) +void usrp1_dboard_iface::_set_gpio_out(unit_t unit, boost::uint16_t value) { switch(unit) { case UNIT_RX: @@ -263,7 +263,7 @@ boost::uint16_t usrp1_dboard_iface::read_gpio(unit_t unit) UHD_ASSERT_THROW(false); } -void usrp1_dboard_iface::set_atr_reg(unit_t unit, +void usrp1_dboard_iface::_set_atr_reg(unit_t unit, atr_reg_t atr, boost::uint16_t value) { // Ignore unsupported states diff --git a/host/lib/usrp/usrp2/dboard_iface.cpp b/host/lib/usrp/usrp2/dboard_iface.cpp index ab5f62355..54c1c735c 100644 --- a/host/lib/usrp/usrp2/dboard_iface.cpp +++ b/host/lib/usrp/usrp2/dboard_iface.cpp @@ -47,10 +47,10 @@ public: void write_aux_dac(unit_t, aux_dac_t, float); float read_aux_adc(unit_t, aux_adc_t); - void set_pin_ctrl(unit_t, boost::uint16_t); - void set_atr_reg(unit_t, atr_reg_t, boost::uint16_t); - void set_gpio_ddr(unit_t, boost::uint16_t); - void write_gpio(unit_t, boost::uint16_t); + void _set_pin_ctrl(unit_t, boost::uint16_t); + void _set_atr_reg(unit_t, atr_reg_t, boost::uint16_t); + void _set_gpio_ddr(unit_t, boost::uint16_t); + void _set_gpio_out(unit_t, boost::uint16_t); void set_gpio_debug(unit_t, int); boost::uint16_t read_gpio(unit_t); @@ -170,7 +170,7 @@ static const uhd::dict<dboard_iface::unit_t, int> unit_to_shift = map_list_of (dboard_iface::UNIT_TX, 16) ; -void usrp2_dboard_iface::set_pin_ctrl(unit_t unit, boost::uint16_t value){ +void usrp2_dboard_iface::_set_pin_ctrl(unit_t unit, boost::uint16_t value){ //calculate the new selection mux setting boost::uint32_t new_sels = 0x0; for(size_t i = 0; i < 16; i++){ @@ -185,14 +185,14 @@ void usrp2_dboard_iface::set_pin_ctrl(unit_t unit, boost::uint16_t value){ } } -void usrp2_dboard_iface::set_gpio_ddr(unit_t unit, boost::uint16_t value){ +void usrp2_dboard_iface::_set_gpio_ddr(unit_t unit, boost::uint16_t value){ _ddr_shadow = \ (_ddr_shadow & ~(0xffff << unit_to_shift[unit])) | (boost::uint32_t(value) << unit_to_shift[unit]); _iface->poke32(_iface->regs.gpio_ddr, _ddr_shadow); } -void usrp2_dboard_iface::write_gpio(unit_t unit, boost::uint16_t value){ +void usrp2_dboard_iface::_set_gpio_out(unit_t unit, boost::uint16_t value){ _gpio_shadow = \ (_gpio_shadow & ~(0xffff << unit_to_shift[unit])) | (boost::uint32_t(value) << unit_to_shift[unit]); @@ -203,7 +203,7 @@ boost::uint16_t usrp2_dboard_iface::read_gpio(unit_t unit){ return boost::uint16_t(_iface->peek32(_iface->regs.gpio_io) >> unit_to_shift[unit]); } -void usrp2_dboard_iface::set_atr_reg(unit_t unit, atr_reg_t atr, boost::uint16_t value){ +void usrp2_dboard_iface::_set_atr_reg(unit_t unit, atr_reg_t atr, boost::uint16_t value){ //define mapping of unit to atr regs to register address static const uhd::dict< unit_t, uhd::dict<atr_reg_t, boost::uint32_t> diff --git a/host/lib/usrp/usrp_e100/dboard_iface.cpp b/host/lib/usrp/usrp_e100/dboard_iface.cpp index aa96171d6..a5032f86f 100644 --- a/host/lib/usrp/usrp_e100/dboard_iface.cpp +++ b/host/lib/usrp/usrp_e100/dboard_iface.cpp @@ -63,10 +63,10 @@ public: void write_aux_dac(unit_t, aux_dac_t, float); float read_aux_adc(unit_t, aux_adc_t); - void set_pin_ctrl(unit_t, boost::uint16_t); - void set_atr_reg(unit_t, atr_reg_t, boost::uint16_t); - void set_gpio_ddr(unit_t, boost::uint16_t); - void write_gpio(unit_t, boost::uint16_t); + void _set_pin_ctrl(unit_t, boost::uint16_t); + void _set_atr_reg(unit_t, atr_reg_t, boost::uint16_t); + void _set_gpio_ddr(unit_t, boost::uint16_t); + void _set_gpio_out(unit_t, boost::uint16_t); void set_gpio_debug(unit_t, int); boost::uint16_t read_gpio(unit_t); @@ -148,7 +148,7 @@ double usrp_e100_dboard_iface::get_codec_rate(unit_t){ /*********************************************************************** * GPIO **********************************************************************/ -void usrp_e100_dboard_iface::set_pin_ctrl(unit_t unit, boost::uint16_t value){ +void usrp_e100_dboard_iface::_set_pin_ctrl(unit_t unit, boost::uint16_t value){ UHD_ASSERT_THROW(GPIO_SEL_ATR == 1); //make this assumption switch(unit){ case UNIT_RX: _iface->poke16(UE_REG_GPIO_RX_SEL, value); return; @@ -156,14 +156,14 @@ void usrp_e100_dboard_iface::set_pin_ctrl(unit_t unit, boost::uint16_t value){ } } -void usrp_e100_dboard_iface::set_gpio_ddr(unit_t unit, boost::uint16_t value){ +void usrp_e100_dboard_iface::_set_gpio_ddr(unit_t unit, boost::uint16_t value){ switch(unit){ case UNIT_RX: _iface->poke16(UE_REG_GPIO_RX_DDR, value); return; case UNIT_TX: _iface->poke16(UE_REG_GPIO_TX_DDR, value); return; } } -void usrp_e100_dboard_iface::write_gpio(unit_t unit, boost::uint16_t value){ +void usrp_e100_dboard_iface::_set_gpio_out(unit_t unit, boost::uint16_t value){ switch(unit){ case UNIT_RX: _iface->poke16(UE_REG_GPIO_RX_IO, value); return; case UNIT_TX: _iface->poke16(UE_REG_GPIO_TX_IO, value); return; @@ -178,7 +178,7 @@ boost::uint16_t usrp_e100_dboard_iface::read_gpio(unit_t unit){ } } -void usrp_e100_dboard_iface::set_atr_reg(unit_t unit, atr_reg_t atr, boost::uint16_t value){ +void usrp_e100_dboard_iface::_set_atr_reg(unit_t unit, atr_reg_t atr, boost::uint16_t value){ //define mapping of unit to atr regs to register address static const uhd::dict< unit_t, uhd::dict<atr_reg_t, boost::uint32_t> |