summaryrefslogtreecommitdiffstats
path: root/host/lib/usrp
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-08-11 12:27:18 -0700
committerJosh Blum <josh@joshknows.com>2010-08-11 12:27:18 -0700
commit54048fd9b227633c724edd975347c81152ab37b2 (patch)
treef922ac5f19fa26249360b3c6614ceb45d482b391 /host/lib/usrp
parent9503c5101007ba1261b8d23ee6a17305bbaa6f2a (diff)
downloaduhd-54048fd9b227633c724edd975347c81152ab37b2.tar.gz
uhd-54048fd9b227633c724edd975347c81152ab37b2.tar.bz2
uhd-54048fd9b227633c724edd975347c81152ab37b2.zip
usrp: added subdev spec verification functions
Diffstat (limited to 'host/lib/usrp')
-rw-r--r--host/lib/usrp/misc_utils.cpp60
-rw-r--r--host/lib/usrp/misc_utils.hpp19
-rw-r--r--host/lib/usrp/usrp2/mboard_impl.cpp15
3 files changed, 82 insertions, 12 deletions
diff --git a/host/lib/usrp/misc_utils.cpp b/host/lib/usrp/misc_utils.cpp
index 0aa03a6cc..da22d79f1 100644
--- a/host/lib/usrp/misc_utils.cpp
+++ b/host/lib/usrp/misc_utils.cpp
@@ -16,8 +16,12 @@
//
#include "misc_utils.hpp"
+#include <uhd/utils/assert.hpp>
#include <uhd/utils/gain_group.hpp>
+#include <uhd/usrp/dboard_id.hpp>
#include <uhd/usrp/subdev_props.hpp>
+#include <uhd/usrp/mboard_props.hpp>
+#include <uhd/usrp/dboard_props.hpp>
#include <uhd/usrp/codec_props.hpp>
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
@@ -112,3 +116,59 @@ gain_group::sptr usrp::make_gain_group(wax::obj subdev, wax::obj codec){
}
return gg;
}
+
+/***********************************************************************
+ * verify subdev specs
+ **********************************************************************/
+static void verify_xx_subdev_spec(
+ mboard_prop_t dboard_names_prop,
+ mboard_prop_t dboard_prop,
+ subdev_spec_t &subdev_spec,
+ wax::obj mboard,
+ std::string xx_type
+){
+ //the subdevice specification is empty: handle automatic
+ if (subdev_spec.empty()){
+ BOOST_FOREACH(const std::string &db_name, mboard[dboard_names_prop].as<prop_names_t>()){
+ wax::obj dboard = mboard[named_prop_t(dboard_prop, db_name)];
+
+ //if the dboard slot is populated, take the first subdevice
+ if (dboard[DBOARD_PROP_DBOARD_ID].as<dboard_id_t>() != dboard_id_t::none()){
+ std::string sd_name = dboard[DBOARD_PROP_SUBDEV_NAMES].as<prop_names_t>().at(0);
+ subdev_spec.push_back(subdev_spec_pair_t(db_name, sd_name));
+ break;
+ }
+ }
+
+ //didnt find any populated dboards: add the first subdevice
+ if (subdev_spec.empty()){
+ std::string db_name = mboard[dboard_names_prop].as<prop_names_t>().at(0);
+ wax::obj dboard = mboard[named_prop_t(dboard_prop, db_name)];
+ std::string sd_name = dboard[DBOARD_PROP_SUBDEV_NAMES].as<prop_names_t>().at(0);
+ subdev_spec.push_back(subdev_spec_pair_t(db_name, sd_name));
+ }
+ }
+
+ //sanity check that the dboard/subdevice names exist for this mboard
+ BOOST_FOREACH(const subdev_spec_pair_t &pair, subdev_spec){
+ uhd::assert_has(mboard[dboard_names_prop].as<prop_names_t>(), pair.db_name, xx_type + " dboard name");
+ wax::obj dboard = mboard[named_prop_t(dboard_prop, pair.db_name)];
+ uhd::assert_has(dboard[DBOARD_PROP_SUBDEV_NAMES].as<prop_names_t>(), pair.sd_name, xx_type + " subdev name");
+ }
+}
+
+void usrp::verify_rx_subdev_spec(subdev_spec_t &subdev_spec, wax::obj mboard){
+ return verify_xx_subdev_spec(
+ MBOARD_PROP_RX_DBOARD_NAMES,
+ MBOARD_PROP_RX_DBOARD,
+ subdev_spec, mboard, "rx"
+ );
+}
+
+void usrp::verify_tx_subdev_spec(subdev_spec_t &subdev_spec, wax::obj mboard){
+ return verify_xx_subdev_spec(
+ MBOARD_PROP_TX_DBOARD_NAMES,
+ MBOARD_PROP_TX_DBOARD,
+ subdev_spec, mboard, "tx"
+ );
+}
diff --git a/host/lib/usrp/misc_utils.hpp b/host/lib/usrp/misc_utils.hpp
index 7fe3c899d..e5d3bd849 100644
--- a/host/lib/usrp/misc_utils.hpp
+++ b/host/lib/usrp/misc_utils.hpp
@@ -20,6 +20,7 @@
#include <uhd/config.hpp>
#include <uhd/wax.hpp>
+#include <uhd/usrp/subdev_spec.hpp>
#include <uhd/utils/gain_group.hpp>
namespace uhd{ namespace usrp{
@@ -29,6 +30,24 @@ namespace uhd{ namespace usrp{
*/
gain_group::sptr make_gain_group(wax::obj subdev, wax::obj codec);
+ /*!
+ * Verify the rx subdevice specification.
+ * If the subdev spec if empty, automatically fill it.
+ * \param subdev_spec the subdev spec to verify/fill
+ * \param mboard the motherboard properties object
+ * \throw exception when the subdev spec is invalid
+ */
+ void verify_rx_subdev_spec(subdev_spec_t &subdev_spec, wax::obj mboard);
+
+ /*!
+ * Verify the tx subdevice specification.
+ * If the subdev spec if empty, automatically fill it.
+ * \param subdev_spec the subdev spec to verify/fill
+ * \param mboard the motherboard properties object
+ * \throw exception when the subdev spec is invalid
+ */
+ void verify_tx_subdev_spec(subdev_spec_t &subdev_spec, wax::obj mboard);
+
}} //namespace
#endif /* INCLUDED_LIBUHD_USRP_MISC_UTILS_HPP */
diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp
index 610aade14..fe3ec6785 100644
--- a/host/lib/usrp/usrp2/mboard_impl.cpp
+++ b/host/lib/usrp/usrp2/mboard_impl.cpp
@@ -17,6 +17,7 @@
#include "usrp2_impl.hpp"
#include "usrp2_regs.hpp"
+#include "../misc_utils.hpp"
#include "../dsp_utils.hpp"
#include <uhd/usrp/mboard_props.hpp>
#include <uhd/utils/assert.hpp>
@@ -324,14 +325,9 @@ void usrp2_mboard_impl::set(const wax::obj &key, const wax::obj &val){
case MBOARD_PROP_RX_SUBDEV_SPEC:
_rx_subdev_spec = val.as<subdev_spec_t>();
- //handle automatic
- if (_rx_subdev_spec.empty()) _rx_subdev_spec.push_back(
- subdev_spec_pair_t("", _dboard_manager->get_rx_subdev_names().front())
- );
+ verify_rx_subdev_spec(_rx_subdev_spec, this->get_link());
//sanity check
UHD_ASSERT_THROW(_rx_subdev_spec.size() == 1);
- uhd::assert_has((*this)[MBOARD_PROP_RX_DBOARD_NAMES].as<prop_names_t>(), _rx_subdev_spec.front().db_name, "rx dboard names");
- uhd::assert_has(_dboard_manager->get_rx_subdev_names(), _rx_subdev_spec.front().sd_name, "rx subdev names");
//set the mux
_iface->poke32(U2_REG_DSP_RX_MUX, dsp_type1::calc_rx_mux_word(
_dboard_manager->get_rx_subdev(_rx_subdev_spec.front().sd_name)[SUBDEV_PROP_CONNECTION].as<subdev_conn_t>()
@@ -340,14 +336,9 @@ void usrp2_mboard_impl::set(const wax::obj &key, const wax::obj &val){
case MBOARD_PROP_TX_SUBDEV_SPEC:
_tx_subdev_spec = val.as<subdev_spec_t>();
- //handle automatic
- if (_tx_subdev_spec.empty()) _tx_subdev_spec.push_back(
- subdev_spec_pair_t("", _dboard_manager->get_tx_subdev_names().front())
- );
+ verify_tx_subdev_spec(_tx_subdev_spec, this->get_link());
//sanity check
UHD_ASSERT_THROW(_tx_subdev_spec.size() == 1);
- uhd::assert_has((*this)[MBOARD_PROP_TX_DBOARD_NAMES].as<prop_names_t>(), _tx_subdev_spec.front().db_name, "tx dboard names");
- uhd::assert_has(_dboard_manager->get_tx_subdev_names(), _tx_subdev_spec.front().sd_name, "tx subdev names");
//set the mux
_iface->poke32(U2_REG_DSP_TX_MUX, dsp_type1::calc_tx_mux_word(
_dboard_manager->get_tx_subdev(_tx_subdev_spec.front().sd_name)[SUBDEV_PROP_CONNECTION].as<subdev_conn_t>()