diff options
Diffstat (limited to 'host/lib/usrp/dboard_manager.cpp')
-rw-r--r-- | host/lib/usrp/dboard_manager.cpp | 75 |
1 files changed, 44 insertions, 31 deletions
diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp index 390c1d3c9..8161727e5 100644 --- a/host/lib/usrp/dboard_manager.cpp +++ b/host/lib/usrp/dboard_manager.cpp @@ -15,6 +15,7 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // +#include "dboard_ctor_args.hpp" #include <uhd/usrp/dboard_manager.hpp> #include <uhd/usrp/subdev_props.hpp> #include <uhd/utils/gain_handler.hpp> @@ -26,6 +27,7 @@ #include <boost/bind.hpp> #include <boost/foreach.hpp> #include <boost/assign/list_of.hpp> +#include <iostream> using namespace uhd; using namespace uhd::usrp; @@ -49,15 +51,18 @@ void dboard_manager::register_dboard( //std::cout << "registering: " << name << std::endl; if (get_id_to_args_map().has_key(dboard_id)){ throw std::runtime_error(str(boost::format( - "The dboard id 0x%04x is already registered to %s." - ) % dboard_id % dboard_id::to_string(dboard_id))); + "The dboard id %s is already registered to %s." + ) % dboard_id.to_string() % dboard_id.to_pp_string())); } get_id_to_args_map()[dboard_id] = args_t(dboard_ctor, name, subdev_names); } -std::string dboard_id::to_string(const dboard_id_t &id){ - std::string name = (get_id_to_args_map().has_key(id))? get_id_to_args_map()[id].get<1>() : "unknown"; - return str(boost::format("%s (0x%04x)") % name % id); +std::string dboard_id_t::to_pp_string(void) const{ + std::string name = "unknown"; + if (get_id_to_args_map().has_key(*this)){ + name = get_id_to_args_map()[*this].get<1>(); + } + return str(boost::format("%s (%s)") % name % this->to_string()); } /*********************************************************************** @@ -162,26 +167,27 @@ dboard_manager::sptr dboard_manager::make( * implementation class methods **********************************************************************/ static args_t get_dboard_args( - dboard_id_t dboard_id, - std::string const& xx_type + dboard_iface::unit_t unit, + dboard_id_t dboard_id ){ - //special case, its rx and the none id (0xffff) - if (xx_type == "rx" and dboard_id == dboard_id::NONE){ - return get_dboard_args(0x0001, xx_type); - } - - //special case, its tx and the none id (0xffff) - if (xx_type == "tx" and dboard_id == dboard_id::NONE){ - return get_dboard_args(0x0000, xx_type); + //special case, the none id was provided, use the following ids + if (dboard_id == dboard_id_t::none()){ + std::cerr << boost::format( + "Warning: unregistered dboard id: %s" + " -> defaulting to a basic board" + ) % dboard_id.to_pp_string() << std::endl; + UHD_ASSERT_THROW(get_id_to_args_map().has_key(0x0001)); + UHD_ASSERT_THROW(get_id_to_args_map().has_key(0x0000)); + switch(unit){ + case dboard_iface::UNIT_RX: return get_dboard_args(unit, 0x0001); + case dboard_iface::UNIT_TX: return get_dboard_args(unit, 0x0000); + default: UHD_ASSERT_THROW(false); + } } //verify that there is a registered constructor for this id if (not get_id_to_args_map().has_key(dboard_id)){ - /*throw std::runtime_error(str( - boost::format("Unregistered %s dboard id: %s") - % xx_type % dboard_id::to_string(dboard_id) - ));*/ - return get_dboard_args(dboard_id::NONE, xx_type); + return get_dboard_args(unit, dboard_id_t::none()); } //return the dboard args for this id @@ -196,21 +202,26 @@ dboard_manager_impl::dboard_manager_impl( _iface = iface; dboard_ctor_t rx_dboard_ctor; std::string rx_name; prop_names_t rx_subdevs; - boost::tie(rx_dboard_ctor, rx_name, rx_subdevs) = get_dboard_args(rx_dboard_id, "rx"); + boost::tie(rx_dboard_ctor, rx_name, rx_subdevs) = get_dboard_args(dboard_iface::UNIT_RX, rx_dboard_id); dboard_ctor_t tx_dboard_ctor; std::string tx_name; prop_names_t tx_subdevs; - boost::tie(tx_dboard_ctor, tx_name, tx_subdevs) = get_dboard_args(tx_dboard_id, "tx"); + boost::tie(tx_dboard_ctor, tx_name, tx_subdevs) = get_dboard_args(dboard_iface::UNIT_TX, tx_dboard_id); //initialize the gpio pins before creating subdevs set_nice_dboard_if(); + //dboard constructor args + dboard_base::ctor_args_impl db_ctor_args; + db_ctor_args.db_iface = iface; + //make xcvr subdevs (make one subdev for both rx and tx dboards) if (rx_dboard_ctor == tx_dboard_ctor){ UHD_ASSERT_THROW(rx_subdevs == tx_subdevs); BOOST_FOREACH(const std::string &subdev, rx_subdevs){ - dboard_base::sptr xcvr_dboard = rx_dboard_ctor( - dboard_base::ctor_args_t(subdev, iface, rx_dboard_id, tx_dboard_id) - ); + db_ctor_args.sd_name = subdev; + db_ctor_args.rx_id = rx_dboard_id; + db_ctor_args.tx_id = tx_dboard_id; + dboard_base::sptr xcvr_dboard = rx_dboard_ctor(&db_ctor_args); //create a rx proxy for this xcvr board _rx_dboards[subdev] = subdev_proxy::sptr( new subdev_proxy(xcvr_dboard, subdev_proxy::RX_TYPE) @@ -226,9 +237,10 @@ dboard_manager_impl::dboard_manager_impl( else{ //make the rx subdevs BOOST_FOREACH(const std::string &subdev, rx_subdevs){ - dboard_base::sptr rx_dboard = rx_dboard_ctor( - dboard_base::ctor_args_t(subdev, iface, rx_dboard_id, dboard_id::NONE) - ); + db_ctor_args.sd_name = subdev; + db_ctor_args.rx_id = rx_dboard_id; + db_ctor_args.tx_id = dboard_id_t::none(); + dboard_base::sptr rx_dboard = rx_dboard_ctor(&db_ctor_args); //create a rx proxy for this rx board _rx_dboards[subdev] = subdev_proxy::sptr( new subdev_proxy(rx_dboard, subdev_proxy::RX_TYPE) @@ -236,9 +248,10 @@ dboard_manager_impl::dboard_manager_impl( } //make the tx subdevs BOOST_FOREACH(const std::string &subdev, tx_subdevs){ - dboard_base::sptr tx_dboard = tx_dboard_ctor( - dboard_base::ctor_args_t(subdev, iface, dboard_id::NONE, tx_dboard_id) - ); + db_ctor_args.sd_name = subdev; + db_ctor_args.rx_id = dboard_id_t::none(); + db_ctor_args.tx_id = tx_dboard_id; + dboard_base::sptr tx_dboard = tx_dboard_ctor(&db_ctor_args); //create a tx proxy for this tx board _tx_dboards[subdev] = subdev_proxy::sptr( new subdev_proxy(tx_dboard, subdev_proxy::TX_TYPE) |