aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/usrp/dboard/base.cpp36
-rw-r--r--host/lib/usrp/dboard/id.cpp11
-rw-r--r--host/lib/usrp/dboard/manager.cpp54
3 files changed, 69 insertions, 32 deletions
diff --git a/host/lib/usrp/dboard/base.cpp b/host/lib/usrp/dboard/base.cpp
index de8db323a..92a886407 100644
--- a/host/lib/usrp/dboard/base.cpp
+++ b/host/lib/usrp/dboard/base.cpp
@@ -16,6 +16,7 @@
//
#include <uhd/usrp/dboard/base.hpp>
+#include <boost/format.hpp>
#include <stdexcept>
using namespace uhd::usrp::dboard;
@@ -24,7 +25,7 @@ using namespace uhd::usrp::dboard;
* base dboard base class
**********************************************************************/
base::base(ctor_args_t const& args){
- boost::tie(_subdev_name, _dboard_interface) = args;
+ boost::tie(_subdev_name, _dboard_interface, _rx_id, _tx_id) = args;
}
base::~base(void){
@@ -39,11 +40,28 @@ interface::sptr base::get_interface(void){
return _dboard_interface;
}
+dboard_id_t base::get_rx_id(void){
+ return _rx_id;
+}
+
+dboard_id_t base::get_tx_id(void){
+ return _tx_id;
+}
+
/***********************************************************************
* xcvr dboard base class
**********************************************************************/
xcvr_base::xcvr_base(ctor_args_t const& args) : base(args){
- /* NOP */
+ if (get_rx_id() == ID_NONE){
+ throw std::runtime_error(str(boost::format(
+ "cannot create xcvr board when the rx id is \"%s\""
+ ) % id::to_string(ID_NONE)));
+ }
+ if (get_tx_id() == ID_NONE){
+ throw std::runtime_error(str(boost::format(
+ "cannot create xcvr board when the tx id is \"%s\""
+ ) % id::to_string(ID_NONE)));
+ }
}
xcvr_base::~xcvr_base(void){
@@ -54,7 +72,12 @@ xcvr_base::~xcvr_base(void){
* rx dboard base class
**********************************************************************/
rx_base::rx_base(ctor_args_t const& args) : base(args){
- /* NOP */
+ if (get_tx_id() != ID_NONE){
+ throw std::runtime_error(str(boost::format(
+ "cannot create rx board when the tx id is \"%s\""
+ " -> expected a tx id of \"%s\""
+ ) % id::to_string(get_tx_id()) % id::to_string(ID_NONE)));
+ }
}
rx_base::~rx_base(void){
@@ -73,7 +96,12 @@ void rx_base::tx_set(const wax::obj &, const wax::obj &){
* tx dboard base class
**********************************************************************/
tx_base::tx_base(ctor_args_t const& args) : base(args){
- /* NOP */
+ if (get_rx_id() != ID_NONE){
+ throw std::runtime_error(str(boost::format(
+ "cannot create tx board when the rx id is \"%s\""
+ " -> expected a rx id of \"%s\""
+ ) % id::to_string(get_rx_id()) % id::to_string(ID_NONE)));
+ }
}
tx_base::~tx_base(void){
diff --git a/host/lib/usrp/dboard/id.cpp b/host/lib/usrp/dboard/id.cpp
index 80162240e..b62e469de 100644
--- a/host/lib/usrp/dboard/id.cpp
+++ b/host/lib/usrp/dboard/id.cpp
@@ -21,7 +21,7 @@
using namespace uhd::usrp::dboard;
-std::ostream& operator<<(std::ostream &os, const dboard_id_t &id){
+std::string id::to_string(const dboard_id_t &id){
//map the dboard ids to string representations
uhd::dict<dboard_id_t, std::string> id_to_str;
id_to_str[ID_NONE] = "none";
@@ -29,11 +29,6 @@ std::ostream& operator<<(std::ostream &os, const dboard_id_t &id){
id_to_str[ID_BASIC_RX] = "basic rx";
//get the string representation
- if (id_to_str.has_key(id)){
- os << id_to_str[id];
- }
- else{
- os << boost::format("dboard id %u") % unsigned(id);
- }
- return os;
+ std::string name = (id_to_str.has_key(id))? id_to_str[id] : "unknown";
+ return str(boost::format("%s (0x%.4x)") % name % id);
}
diff --git a/host/lib/usrp/dboard/manager.cpp b/host/lib/usrp/dboard/manager.cpp
index 3540cd1bc..337c31ad6 100644
--- a/host/lib/usrp/dboard/manager.cpp
+++ b/host/lib/usrp/dboard/manager.cpp
@@ -16,7 +16,9 @@
//
#include <uhd/usrp/dboard/manager.hpp>
+#include <uhd/utils.hpp>
#include <boost/assign/list_of.hpp>
+#include <boost/tuple/tuple.hpp>
#include <boost/format.hpp>
#include <boost/foreach.hpp>
#include "dboards.hpp"
@@ -42,8 +44,6 @@ static void register_internal_dboards(void){
static bool called = false;
if (called) return; called = true;
//register the known dboards (dboard id, constructor, subdev names)
- manager::register_subdevs(ID_NONE, &basic_tx::make, list_of("")); //for none, make a basic tx
- manager::register_subdevs(ID_NONE, &basic_rx::make, list_of("ab")); //for none, make a basic rx (one subdev)
manager::register_subdevs(ID_BASIC_TX, &basic_tx::make, list_of(""));
manager::register_subdevs(ID_BASIC_RX, &basic_rx::make, list_of("a")("b")("ab"));
}
@@ -51,11 +51,10 @@ static void register_internal_dboards(void){
/***********************************************************************
* storage and registering for dboards
**********************************************************************/
-//map a dboard id to a dboard constructor
-static uhd::dict<dboard_id_t, manager::dboard_ctor_t> id_to_ctor_map;
+typedef boost::tuple<manager::dboard_ctor_t, prop_names_t> args_t;
-//map a dboard constructor to subdevice names
-static uhd::dict<manager::dboard_ctor_t, prop_names_t> ctor_to_names_map;
+//map a dboard id to a dboard constructor
+static uhd::dict<dboard_id_t, args_t> id_to_args_map;
void manager::register_subdevs(
dboard_id_t dboard_id,
@@ -63,8 +62,7 @@ void manager::register_subdevs(
const prop_names_t &subdev_names
){
register_internal_dboards(); //always call first
- id_to_ctor_map[dboard_id] = dboard_ctor;
- ctor_to_names_map[dboard_ctor] = subdev_names;
+ id_to_args_map[dboard_id] = args_t(dboard_ctor, subdev_names);
}
/***********************************************************************
@@ -113,18 +111,29 @@ private:
/***********************************************************************
* dboard manager methods
**********************************************************************/
-static manager::dboard_ctor_t const& get_dboard_ctor(
+static args_t get_dboard_args(
dboard_id_t dboard_id,
std::string const& xx_type
){
+ //special case, its rx and the none id (0xffff)
+ if (xx_type == "rx" and dboard_id == ID_NONE){
+ return args_t(&basic_rx::make, list_of("ab"));
+ }
+
+ //special case, its tx and the none id (0xffff)
+ if (xx_type == "tx" and dboard_id == ID_NONE){
+ return args_t(&basic_tx::make, list_of(""));
+ }
+
//verify that there is a registered constructor for this id
- if (not id_to_ctor_map.has_key(dboard_id)){
+ if (not id_to_args_map.has_key(dboard_id)){
throw std::runtime_error(str(
boost::format("Unknown %s dboard id: 0x%04x") % xx_type % dboard_id
));
}
- //return the dboard constructor for this id
- return id_to_ctor_map[dboard_id];
+
+ //return the dboard args for this id
+ return id_to_args_map[dboard_id];
}
manager::manager(
@@ -133,8 +142,12 @@ manager::manager(
interface::sptr dboard_interface
){
register_internal_dboards(); //always call first
- 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");
+
+ dboard_ctor_t rx_dboard_ctor; prop_names_t rx_subdevs;
+ boost::tie(rx_dboard_ctor, rx_subdevs) = get_dboard_args(rx_dboard_id, "rx");
+
+ dboard_ctor_t tx_dboard_ctor; prop_names_t tx_subdevs;
+ boost::tie(tx_dboard_ctor, tx_subdevs) = get_dboard_args(tx_dboard_id, "tx");
//initialize the gpio pins before creating subdevs
dboard_interface->set_gpio_ddr(interface::GPIO_RX_BANK, 0x0000, 0xffff); //all inputs
@@ -148,9 +161,10 @@ manager::manager(
//make xcvr subdevs (make one subdev for both rx and tx dboards)
if (rx_dboard_ctor == tx_dboard_ctor){
- BOOST_FOREACH(std::string name, ctor_to_names_map[rx_dboard_ctor]){
+ ASSERT_THROW(rx_subdevs == tx_subdevs);
+ BOOST_FOREACH(std::string name, rx_subdevs){
base::sptr xcvr_dboard = rx_dboard_ctor(
- base::ctor_args_t(name, dboard_interface)
+ base::ctor_args_t(name, dboard_interface, rx_dboard_id, tx_dboard_id)
);
//create a rx proxy for this xcvr board
_rx_dboards[name] = subdev_proxy::sptr(
@@ -166,9 +180,9 @@ manager::manager(
//make tx and rx subdevs (separate subdevs for rx and tx dboards)
else{
//make the rx subdevs
- BOOST_FOREACH(std::string name, ctor_to_names_map[rx_dboard_ctor]){
+ BOOST_FOREACH(std::string name, rx_subdevs){
base::sptr rx_dboard = rx_dboard_ctor(
- base::ctor_args_t(name, dboard_interface)
+ base::ctor_args_t(name, dboard_interface, rx_dboard_id, ID_NONE)
);
//create a rx proxy for this rx board
_rx_dboards[name] = subdev_proxy::sptr(
@@ -176,9 +190,9 @@ manager::manager(
);
}
//make the tx subdevs
- BOOST_FOREACH(std::string name, ctor_to_names_map[tx_dboard_ctor]){
+ BOOST_FOREACH(std::string name, tx_subdevs){
base::sptr tx_dboard = tx_dboard_ctor(
- base::ctor_args_t(name, dboard_interface)
+ base::ctor_args_t(name, dboard_interface, ID_NONE, tx_dboard_id)
);
//create a tx proxy for this tx board
_tx_dboards[name] = subdev_proxy::sptr(