diff options
author | Josh Blum <josh@joshknows.com> | 2010-02-18 17:48:14 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-02-18 17:48:14 -0800 |
commit | 6fdaccea1fba15b754945d9be7da0ed4a3861633 (patch) | |
tree | a5822f02409cc2d69f0566b4ea6e787b0d8ca43d /host/lib/usrp/dboard/manager.cpp | |
parent | b4e5df4080b276ff1bf7cf896bd60630cdaab652 (diff) | |
download | uhd-6fdaccea1fba15b754945d9be7da0ed4a3861633.tar.gz uhd-6fdaccea1fba15b754945d9be7da0ed4a3861633.tar.bz2 uhd-6fdaccea1fba15b754945d9be7da0ed4a3861633.zip |
Added special case for empty dboard slot (none id 0xffff)
Added error handling in the dboard base classes for mishandling the none id.
Added better to string function for the dboard ids.
Added get methods for dboard classes to get their ids.
Diffstat (limited to 'host/lib/usrp/dboard/manager.cpp')
-rw-r--r-- | host/lib/usrp/dboard/manager.cpp | 54 |
1 files changed, 34 insertions, 20 deletions
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( |