summaryrefslogtreecommitdiffstats
path: root/lib/usrp/dboard/manager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/usrp/dboard/manager.cpp')
-rw-r--r--lib/usrp/dboard/manager.cpp98
1 files changed, 46 insertions, 52 deletions
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){