diff options
-rw-r--r-- | include/usrp_uhd/usrp/dboard/Makefile.am | 4 | ||||
-rw-r--r-- | include/usrp_uhd/usrp/dboard/base.hpp | 80 | ||||
-rw-r--r-- | include/usrp_uhd/usrp/dboard/manager.hpp | 47 | ||||
-rw-r--r-- | lib/usrp/dboard/Makefile.am | 4 | ||||
-rw-r--r-- | lib/usrp/dboard/base.cpp | 67 | ||||
-rw-r--r-- | lib/usrp/dboard/manager.cpp | 100 |
6 files changed, 300 insertions, 2 deletions
diff --git a/include/usrp_uhd/usrp/dboard/Makefile.am b/include/usrp_uhd/usrp/dboard/Makefile.am index 19777b11a..d8c240351 100644 --- a/include/usrp_uhd/usrp/dboard/Makefile.am +++ b/include/usrp_uhd/usrp/dboard/Makefile.am @@ -8,4 +8,6 @@ SUBDIRS = this_includedir = $(includedir)/usrp_uhd/usrp/dboard this_include_HEADERS = \ - interface.hpp + base.hpp \ + interface.hpp \ + manager.hpp diff --git a/include/usrp_uhd/usrp/dboard/base.hpp b/include/usrp_uhd/usrp/dboard/base.hpp new file mode 100644 index 000000000..23ae4a4fe --- /dev/null +++ b/include/usrp_uhd/usrp/dboard/base.hpp @@ -0,0 +1,80 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#ifndef INCLUDED_USRP_UHD_USRP_DBOARD_BASE_H +#define INCLUDED_USRP_UHD_USRP_DBOARD_BASE_H + +#include <usrp_uhd/wax.hpp> +#include <boost/utility.hpp> +#include <boost/shared_ptr.hpp> +#include <usrp_uhd/usrp/dboard/interface.hpp> + +namespace usrp_uhd{ namespace usrp{ namespace dboard{ + +/*! + * A daughter board base class for all dboards. + * Sub classes for xcvr boards should inherit this. + */ +class xcvr_base : boost::noncopyable{ +public: + typedef boost::shared_ptr<xcvr_base> sptr; + + //structors + xcvr_base(size_t subdev_index, interface::sptr dboard_interface); + ~xcvr_base(void); + + //interface + virtual void rx_get(const wax::type &key, wax::type &val) = 0; + virtual void rx_set(const wax::type &key, const wax::type &val) = 0; + virtual void tx_get(const wax::type &key, wax::type &val) = 0; + virtual void tx_set(const wax::type &key, const wax::type &val) = 0; + +protected: + size_t get_subdev_index(void); + interface::sptr get_interface(void); + +private: + size_t _subdev_index; + interface::sptr _dboard_interface; +}; + +/*! + * A rx daughter board only implements rx methods. + * Sub classes for rx-only boards should inherit this. + */ +class rx_base : public xcvr_base{ +public: + /*! + * Create a new rx dboard object, override in subclasses. + */ + rx_base(size_t subdev_index, interface::sptr sptr_interface); + + virtual ~rx_base(void); + + //override here so the derived classes cannot + void tx_get(const wax::type &key, wax::type &val); + void tx_set(const wax::type &key, const wax::type &val); +}; + +/*! + * A tx daughter board only implements tx methods. + * Sub classes for rx-only boards should inherit this. + */ +class tx_base : public xcvr_base{ +public: + /*! + * Create a new rx dboard object, override in subclasses. + */ + tx_base(size_t subdev_index, interface::sptr sptr_interface); + + virtual ~tx_base(void); + + //override here so the derived classes cannot + void rx_get(const wax::type &key, wax::type &val); + void rx_set(const wax::type &key, const wax::type &val); +}; + +}}} //namespace + +#endif /* INCLUDED_USRP_UHD_USRP_DBOARD_BASE_H */ diff --git a/include/usrp_uhd/usrp/dboard/manager.hpp b/include/usrp_uhd/usrp/dboard/manager.hpp new file mode 100644 index 000000000..565411371 --- /dev/null +++ b/include/usrp_uhd/usrp/dboard/manager.hpp @@ -0,0 +1,47 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#ifndef INCLUDED_USRP_UHD_USRP_DBOARD_MANAGER_H +#define INCLUDED_USRP_UHD_USRP_DBOARD_MANAGER_H + +#include <vector> +#include <usrp_uhd/wax.hpp> +#include <boost/utility.hpp> +#include <boost/shared_ptr.hpp> +#include <usrp_uhd/usrp/dboard/base.hpp> + +namespace usrp_uhd{ namespace usrp{ namespace dboard{ + +/*! + * A daughter board subdev manager class. + * Create subdev instances for each subdev on a dboard. + * Provide wax::obj access to the subdevs inside. + */ +class manager : boost::noncopyable{ +public: + typedef boost::shared_ptr<manager> sptr; + //structors + manager( + uint16_t rx_dboard_id, + uint16_t tx_dboard_id, + interface::sptr dboard_interface + ); + ~manager(void); + + //interface + size_t get_num_rx_subdevs(void); + size_t get_num_tx_subdevs(void); + wax::obj::sptr get_rx_subdev(size_t subdev_index); + wax::obj::sptr get_tx_subdev(size_t subdev_index); + +private: + //list of rx and tx dboards in this manager + //each dboard here is actually a subdevice + std::vector<xcvr_base::sptr> _rx_dboards; + std::vector<xcvr_base::sptr> _tx_dboards; +}; + +}}} //namespace + +#endif /* INCLUDED_USRP_UHD_USRP_DBOARD_MANAGER_H */ diff --git a/lib/usrp/dboard/Makefile.am b/lib/usrp/dboard/Makefile.am index 8d77dcc42..7bbf4e4f8 100644 --- a/lib/usrp/dboard/Makefile.am +++ b/lib/usrp/dboard/Makefile.am @@ -11,7 +11,9 @@ AM_CPPFLAGS = $(GENERAL_CPPFLAGS) noinst_LTLIBRARIES = lib.la lib_la_SOURCES = \ - interface.cpp + base.cpp \ + interface.cpp \ + manager.cpp lib_la_LIBADD = $(GENERAL_LDDFLAGS) diff --git a/lib/usrp/dboard/base.cpp b/lib/usrp/dboard/base.cpp new file mode 100644 index 000000000..3166cdedc --- /dev/null +++ b/lib/usrp/dboard/base.cpp @@ -0,0 +1,67 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#include <usrp_uhd/usrp/dboard/base.hpp> + +using namespace usrp_uhd::usrp::dboard; + +/*********************************************************************** + * xcvr dboard base class + **********************************************************************/ +xcvr_base::xcvr_base(size_t subdev_index, interface::sptr dboard_interface) + : _subdev_index(subdev_index), _dboard_interface(dboard_interface){ + /* NOP */ +} + +xcvr_base::~xcvr_base(void){ + /* NOP */ +} + +size_t xcvr_base::get_subdev_index(void){ + return _subdev_index; +} + +interface::sptr xcvr_base::get_interface(void){ + return _dboard_interface; +} + +/*********************************************************************** + * rx dboard base class + **********************************************************************/ +rx_base::rx_base(size_t subdev_index, interface::sptr dboard_interface) +: xcvr_base(subdev_index, dboard_interface){ + /* NOP */ +} + +rx_base::~rx_base(void){ + /* NOP */ +} + +void rx_base::tx_get(const wax::type &key, wax::type &val){ + throw std::runtime_error("cannot call tx_get on a rx dboard"); +} + +void rx_base::tx_set(const wax::type &key, const wax::type &val){ + throw std::runtime_error("cannot call tx_set on a rx dboard"); +} + +/*********************************************************************** + * tx dboard base class + **********************************************************************/ +tx_base::tx_base(size_t subdev_index, interface::sptr dboard_interface) +: xcvr_base(subdev_index, dboard_interface){ + /* NOP */ +} + +tx_base::~tx_base(void){ + /* NOP */ +} + +void tx_base::rx_get(const wax::type &key, wax::type &val){ + throw std::runtime_error("cannot call rx_get on a tx dboard"); +} + +void tx_base::rx_set(const wax::type &key, const wax::type &val){ + throw std::runtime_error("cannot call rx_set on a tx dboard"); +} diff --git a/lib/usrp/dboard/manager.cpp b/lib/usrp/dboard/manager.cpp new file mode 100644 index 000000000..1ed563777 --- /dev/null +++ b/lib/usrp/dboard/manager.cpp @@ -0,0 +1,100 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#include <usrp_uhd/usrp/dboard/manager.hpp> + +using namespace usrp_uhd::usrp::dboard; + +/*********************************************************************** + * internal helper classes + **********************************************************************/ +/*! + * A special wax proxy object that forwards calls to a subdev. + * A sptr to an instance will be used in the properties structure. + */ +class subdev_proxy : boost::noncopyable, public wax::obj{ +public: + typedef boost::shared_ptr<subdev_proxy> sptr; + enum type_t{RX_TYPE, TX_TYPE}; + + //structors + subdev_proxy(xcvr_base::sptr dboard, type_t type) + : _dboard(dboard), _type(type){ + /* NOP */ + } + + ~subdev_proxy(void){ + /* NOP */ + } + +private: + xcvr_base::sptr _dboard; + type_t _type; + + //forward the get calls to the rx or tx + void get(const wax::type &key, wax::type &val){ + switch(_type){ + case RX_TYPE: return _dboard->rx_get(key, val); + case TX_TYPE: return _dboard->tx_get(key, val); + } + } + + //forward the set calls to the rx or tx + void set(const wax::type &key, const wax::type &val){ + switch(_type){ + case RX_TYPE: return _dboard->rx_set(key, val); + case TX_TYPE: return _dboard->tx_set(key, val); + } + } +}; + +/*********************************************************************** + * dboard manager methods + **********************************************************************/ +//include dboard derived classes: +//TODO #inlude "basic.hpp" + +#define MAKE_DBOARD_ID_WORD(rx_id, tx_id) \ + ((uint32_t(rx_id) << 16) | (uint32_t(tx_id) << 0)) + +manager::manager( + uint16_t rx_dboard_id, + uint16_t tx_dboard_id, + interface::sptr dboard_interface +){ + //TODO build some boards based on ids + //xcvrs will be added to both vectors + switch(MAKE_DBOARD_ID_WORD(rx_dboard_id, tx_dboard_id)){ + default: + //_rx_dboards.push_back(xcvr_base::sptr(new basic_rx(0, dboard_interface))); + //_rx_dboards.push_back(xcvr_base::sptr(new basic_rx(1, dboard_interface))); + //_rx_dboards.push_back(xcvr_base::sptr(new basic_rx(2, dboard_interface))); + //_tx_dboards.push_back(xcvr_base::sptr(new basic_tx(0, dboard_interface))); + break; + } +} + +manager::~manager(void){ + /* NOP */ +} + +size_t manager::get_num_rx_subdevs(void){ + return _rx_dboards.size(); +} + +size_t manager::get_num_tx_subdevs(void){ + return _tx_dboards.size(); +} + +wax::obj::sptr manager::get_rx_subdev(size_t subdev_index){ + return wax::obj::sptr(new subdev_proxy( + _rx_dboards.at(subdev_index), subdev_proxy::RX_TYPE) + ); +} + +wax::obj::sptr manager::get_tx_subdev(size_t subdev_index){ + return wax::obj::sptr(new subdev_proxy( + _tx_dboards.at(subdev_index), subdev_proxy::TX_TYPE) + ); +} |