summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/usrp/dboard/base.cpp27
-rw-r--r--lib/usrp/dboard/dboards.hpp8
-rw-r--r--lib/usrp/dboard/manager.cpp98
3 files changed, 68 insertions, 65 deletions
diff --git a/lib/usrp/dboard/base.cpp b/lib/usrp/dboard/base.cpp
index 4fbe4df8c..d8a6e66c2 100644
--- a/lib/usrp/dboard/base.cpp
+++ b/lib/usrp/dboard/base.cpp
@@ -7,30 +7,40 @@
using namespace usrp_uhd::usrp::dboard;
/***********************************************************************
- * xcvr dboard base class
+ * base dboard base class
**********************************************************************/
-xcvr_base::xcvr_base(ctor_args_t const& args)
+base::base(ctor_args_t const& args)
: _subdev_index(args.get<0>()), _dboard_interface(args.get<1>()){
/* NOP */
}
-xcvr_base::~xcvr_base(void){
+base::~base(void){
/* NOP */
}
-size_t xcvr_base::get_subdev_index(void){
+size_t base::get_subdev_index(void){
return _subdev_index;
}
-interface::sptr xcvr_base::get_interface(void){
+interface::sptr base::get_interface(void){
return _dboard_interface;
}
/***********************************************************************
+ * xcvr dboard base class
+ **********************************************************************/
+xcvr_base::xcvr_base(ctor_args_t const& args) : base(args){
+ /* NOP */
+}
+
+xcvr_base::~xcvr_base(void){
+ /* NOP */
+}
+
+/***********************************************************************
* rx dboard base class
**********************************************************************/
-rx_base::rx_base(ctor_args_t const& args)
-: xcvr_base(args){
+rx_base::rx_base(ctor_args_t const& args) : base(args){
/* NOP */
}
@@ -49,8 +59,7 @@ void rx_base::tx_set(const wax::type &, const wax::type &){
/***********************************************************************
* tx dboard base class
**********************************************************************/
-tx_base::tx_base(ctor_args_t const& args)
-: xcvr_base(args){
+tx_base::tx_base(ctor_args_t const& args) : base(args){
/* NOP */
}
diff --git a/lib/usrp/dboard/dboards.hpp b/lib/usrp/dboard/dboards.hpp
index b46b5f590..7a93286ae 100644
--- a/lib/usrp/dboard/dboards.hpp
+++ b/lib/usrp/dboard/dboards.hpp
@@ -14,8 +14,8 @@ using namespace usrp_uhd::usrp::dboard;
**********************************************************************/
class basic_rx : public rx_base{
public:
- static xcvr_base::sptr make(ctor_args_t const& args){
- return xcvr_base::sptr(new basic_rx(args));
+ static base::sptr make(ctor_args_t const& args){
+ return base::sptr(new basic_rx(args));
}
basic_rx(ctor_args_t const& args);
~basic_rx(void);
@@ -26,8 +26,8 @@ public:
class basic_tx : public tx_base{
public:
- static xcvr_base::sptr make(ctor_args_t const& args){
- return xcvr_base::sptr(new basic_tx(args));
+ static base::sptr make(ctor_args_t const& args){
+ return base::sptr(new basic_tx(args));
}
basic_tx(ctor_args_t const& args);
~basic_tx(void);
diff --git a/lib/usrp/dboard/manager.cpp b/lib/usrp/dboard/manager.cpp
index 897b6e304..6486fadf2 100644
--- a/lib/usrp/dboard/manager.cpp
+++ b/lib/usrp/dboard/manager.cpp
@@ -3,7 +3,6 @@
//
#include <usrp_uhd/usrp/dboard/manager.hpp>
-#include <boost/tuple/tuple.hpp>
#include <boost/format.hpp>
#include <map>
#include "dboards.hpp"
@@ -27,48 +26,27 @@ static void register_internal_dboards(void){
static bool called = false;
if (called) return; called = true;
//register the known dboards (dboard id, constructor, num subdevs)
- manager::register_tx_subdev(0x0000, &basic_tx::make, 1);
- manager::register_rx_subdev(0x0001, &basic_rx::make, 3);
+ manager::register_subdevs(0x0000, &basic_tx::make, 1);
+ manager::register_subdevs(0x0001, &basic_rx::make, 3);
}
/***********************************************************************
* storage and registering for dboards
**********************************************************************/
-//hold a dboard constructor and the number of subdevs
-typedef boost::tuple<manager::dboard_ctor_t, size_t> dboard_reg_val_t;
+//map a dboard id to a dboard constructor
+static std::map<manager::dboard_id_t, manager::dboard_ctor_t> id_to_ctor_map;
-//map a dboard id to a registered value tuple
-typedef std::map<manager::dboard_id_t, dboard_reg_val_t> dboard_reg_map_t;
+//map a dboard constructor to number of subdevices
+static std::map<manager::dboard_ctor_t, size_t> ctor_to_num_map;
-//static instances of registered dboard ids
-static dboard_reg_map_t dboard_rx_regs, dboard_tx_regs;
-
-/*!
- * Helper function to register a dboard contructor to its id.
- * This should be called by the api calls to register subdevs.
- */
-static void register_xx_subdev(
- manager::dboard_id_t dboard_id,
- manager::dboard_ctor_t dboard_ctor,
- size_t num_subdevs,
- dboard_reg_map_t &dboard_reg_map
+void manager::register_subdevs(
+ dboard_id_t dboard_id,
+ dboard_ctor_t dboard_ctor,
+ size_t num_subdevs
){
register_internal_dboards(); //always call first
- dboard_reg_map.insert(std::pair<manager::dboard_id_t, dboard_reg_val_t>(
- dboard_id, dboard_reg_val_t(dboard_ctor, num_subdevs)
- ));
-}
-
-void manager::register_rx_subdev(
- dboard_id_t dboard_id, dboard_ctor_t dboard_ctor, size_t num_subdevs
-){
- register_xx_subdev(dboard_id, dboard_ctor, num_subdevs, dboard_rx_regs);
-}
-
-void manager::register_tx_subdev(
- dboard_id_t dboard_id, dboard_ctor_t dboard_ctor, size_t num_subdevs
-){
- register_xx_subdev(dboard_id, dboard_ctor, num_subdevs, dboard_tx_regs);
+ id_to_ctor_map[dboard_id] = dboard_ctor;
+ ctor_to_num_map[dboard_ctor] = num_subdevs;
}
/***********************************************************************
@@ -84,7 +62,7 @@ public:
enum type_t{RX_TYPE, TX_TYPE};
//structors
- subdev_proxy(xcvr_base::sptr subdev, type_t type)
+ subdev_proxy(base::sptr subdev, type_t type)
: _subdev(subdev), _type(type){
/* NOP */
}
@@ -94,8 +72,8 @@ public:
}
private:
- xcvr_base::sptr _subdev;
- type_t _type;
+ base::sptr _subdev;
+ type_t _type;
//forward the get calls to the rx or tx
void get(const wax::type &key, wax::type &val){
@@ -117,27 +95,18 @@ private:
/***********************************************************************
* dboard manager methods
**********************************************************************/
-static void create_subdevs(
- dboard_reg_map_t &dboard_reg_map,
+static manager::dboard_ctor_t const& get_dboard_ctor(
manager::dboard_id_t dboard_id,
- interface::sptr dboard_interface,
- std::vector<xcvr_base::sptr> &subdevs,
std::string const& xx_type
){
//verify that there is a registered constructor for this id
- if (dboard_reg_map.count(dboard_id) == 0){
+ if (id_to_ctor_map.count(dboard_id) == 0){
throw std::runtime_error(str(
boost::format("Unknown %s dboard id: 0x%04x") % xx_type % dboard_id
));
}
- //create new subdevices for the dboard ids
- for (size_t i = 0; i < dboard_reg_map[dboard_id].get<1>(); i++){
- subdevs.push_back(
- dboard_reg_map[dboard_id].get<0>()(
- xcvr_base::ctor_args_t(i, dboard_interface)
- )
- );
- }
+ //return the dboard constructor for this id
+ return id_to_ctor_map[dboard_id];
}
manager::manager(
@@ -146,8 +115,33 @@ manager::manager(
interface::sptr dboard_interface
){
register_internal_dboards(); //always call first
- create_subdevs(dboard_rx_regs, rx_dboard_id, dboard_interface, _rx_dboards, "rx");
- create_subdevs(dboard_tx_regs, tx_dboard_id, dboard_interface, _tx_dboards, "tx");
+ const dboard_ctor_t rx_dboard_ctor = get_dboard_ctor(rx_dboard_id, "rx");
+ const dboard_ctor_t tx_dboard_ctor = get_dboard_ctor(tx_dboard_id, "tx");
+ //make xcvr subdevs (make one subdev for both rx and tx dboards)
+ if (rx_dboard_ctor == tx_dboard_ctor){
+ for (size_t i = 0; i < ctor_to_num_map[rx_dboard_ctor]; i++){
+ base::sptr xcvr_dboard = rx_dboard_ctor(
+ base::ctor_args_t(i, dboard_interface)
+ );
+ _rx_dboards.push_back(xcvr_dboard);
+ _tx_dboards.push_back(xcvr_dboard);
+ }
+ }
+ //make tx and rx subdevs (separate subdevs for rx and tx dboards)
+ else{
+ //make the rx subdevs
+ for (size_t i = 0; i < ctor_to_num_map[rx_dboard_ctor]; i++){
+ _rx_dboards.push_back(rx_dboard_ctor(
+ base::ctor_args_t(i, dboard_interface)
+ ));
+ }
+ //make the tx subdevs
+ for (size_t i = 0; i < ctor_to_num_map[tx_dboard_ctor]; i++){
+ _tx_dboards.push_back(tx_dboard_ctor(
+ base::ctor_args_t(i, dboard_interface)
+ ));
+ }
+ }
}
manager::~manager(void){