diff options
author | Josh Blum <josh@joshknows.com> | 2011-07-01 15:07:38 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-07-01 15:07:38 -0700 |
commit | 6aa4690af05559d28b5238fa153fd46ff57cf06f (patch) | |
tree | 6c43e2c2571d61a724c12577fbb5efba2aa701e8 /host | |
parent | d6d51025dc83719a01b93213e3be9248a5d93b4f (diff) | |
download | uhd-6aa4690af05559d28b5238fa153fd46ff57cf06f.tar.gz uhd-6aa4690af05559d28b5238fa153fd46ff57cf06f.tar.bz2 uhd-6aa4690af05559d28b5238fa153fd46ff57cf06f.zip |
usrp: added validate_subdev_spec to all io_impls
Diffstat (limited to 'host')
-rw-r--r-- | host/lib/transport/super_send_packet_handler.hpp | 2 | ||||
-rw-r--r-- | host/lib/usrp/b100/io_impl.cpp | 6 | ||||
-rw-r--r-- | host/lib/usrp/common/CMakeLists.txt | 2 | ||||
-rw-r--r-- | host/lib/usrp/common/fx2_ctrl.hpp | 6 | ||||
-rw-r--r-- | host/lib/usrp/common/validate_subdev_spec.cpp | 65 | ||||
-rw-r--r-- | host/lib/usrp/common/validate_subdev_spec.hpp | 39 | ||||
-rw-r--r-- | host/lib/usrp/e100/io_impl.cpp | 10 | ||||
-rw-r--r-- | host/lib/usrp/usrp1/io_impl.cpp | 7 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/io_impl.cpp | 6 |
9 files changed, 124 insertions, 19 deletions
diff --git a/host/lib/transport/super_send_packet_handler.hpp b/host/lib/transport/super_send_packet_handler.hpp index 8ebc264ef..05557250f 100644 --- a/host/lib/transport/super_send_packet_handler.hpp +++ b/host/lib/transport/super_send_packet_handler.hpp @@ -242,7 +242,7 @@ private: /******************************************************************* * Send a single packet: ******************************************************************/ - size_t send_one_packet( + UHD_INLINE size_t send_one_packet( const uhd::device::send_buffs_type &buffs, const size_t nsamps_per_buff, vrt::if_packet_info_t &if_packet_info, diff --git a/host/lib/usrp/b100/io_impl.cpp b/host/lib/usrp/b100/io_impl.cpp index 3c1acedaf..5b38a14ac 100644 --- a/host/lib/usrp/b100/io_impl.cpp +++ b/host/lib/usrp/b100/io_impl.cpp @@ -15,6 +15,7 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // +#include "validate_subdev_spec.hpp" #include "../../transport/super_recv_packet_handler.hpp" #include "../../transport/super_send_packet_handler.hpp" #include "usrp_commands.h" @@ -176,8 +177,7 @@ void b100_impl::update_rx_subdev_spec(const uhd::usrp::subdev_spec_t &spec){ property_tree::path_type root = "/mboards/0/dboards"; //sanity checking - if (spec.size() == 0) throw uhd::value_error("rx subdev spec cant be empty"); - if (spec.size() > _rx_dsps.size()) throw uhd::value_error("rx subdev spec too long"); + validate_subdev_spec(_tree, spec, "rx"); //setup mux for this spec for (size_t i = 0; i < spec.size(); i++){ @@ -204,7 +204,7 @@ void b100_impl::update_tx_subdev_spec(const uhd::usrp::subdev_spec_t &spec){ property_tree::path_type root = "/mboards/0/dboards"; //sanity checking - if (spec.size() != 1) throw uhd::value_error("tx subdev spec has to be size 1"); + validate_subdev_spec(_tree, spec, "tx"); //set the mux for this spec const std::string conn = _tree->access<std::string>(root / spec[0].db_name / "tx_frontends" / spec[0].sd_name / "connection").get(); diff --git a/host/lib/usrp/common/CMakeLists.txt b/host/lib/usrp/common/CMakeLists.txt index 33f2c0ca1..31004d952 100644 --- a/host/lib/usrp/common/CMakeLists.txt +++ b/host/lib/usrp/common/CMakeLists.txt @@ -24,6 +24,6 @@ IF(ENABLE_USB) LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/fx2_ctrl.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/fx2_ctrl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/validate_subdev_spec.cpp ) ENDIF(ENABLE_USB) diff --git a/host/lib/usrp/common/fx2_ctrl.hpp b/host/lib/usrp/common/fx2_ctrl.hpp index eeff6287d..691d64275 100644 --- a/host/lib/usrp/common/fx2_ctrl.hpp +++ b/host/lib/usrp/common/fx2_ctrl.hpp @@ -15,8 +15,8 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // -#ifndef INCLUDED_USRP_CTRL_HPP -#define INCLUDED_USRP_CTRL_HPP +#ifndef INCLUDED_LIBUHD_USRP_COMMON_FX2_CTRL_HPP +#define INCLUDED_LIBUHD_USRP_COMMON_FX2_CTRL_HPP #include <uhd/transport/usb_control.hpp> #include <uhd/types/serial.hpp> //i2c iface @@ -120,4 +120,4 @@ public: }} //namespace uhd::usrp -#endif /* INCLUDED_USRP_CTRL_HPP */ +#endif /* INCLUDED_LIBUHD_USRP_COMMON_FX2_CTRL_HPP */ diff --git a/host/lib/usrp/common/validate_subdev_spec.cpp b/host/lib/usrp/common/validate_subdev_spec.cpp new file mode 100644 index 000000000..811995bdf --- /dev/null +++ b/host/lib/usrp/common/validate_subdev_spec.cpp @@ -0,0 +1,65 @@ +// +// Copyright 2011 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#include "validate_subdev_spec.hpp" +#include <uhd/exception.hpp> +#include <uhd/utils/assert_has.hpp> +#include <boost/foreach.hpp> +#include <boost/format.hpp> + +using namespace uhd; +using namespace uhd::usrp; + +namespace uhd{ namespace usrp{ + + static std::ostream& operator<< (std::ostream &out, const subdev_spec_pair_t &pair){ + out << pair.db_name << ":" << pair.sd_name; + return out; + } + +}} + +void uhd::usrp::validate_subdev_spec( + property_tree::sptr tree, + const subdev_spec_t &spec, + const std::string &type, + const std::string &mb +){ + const size_t num_dsps = tree->list(str(boost::format("/mboards/%s/%s_dsps") % mb % type)).size(); + + //sanity checking on the length + if (spec.size() == 0) throw uhd::value_error(str(boost::format( + "Empty %s subdevice specification is not supported.\n" + ) % type)); + if (spec.size() > num_dsps) throw uhd::value_error(str(boost::format( + "The subdevice specification \"%s\" is too long.\n" + "The user specified %u channels, but there are only %u %s dsps on mboard %s.\n" + ) % spec.to_string() % spec.size() % num_dsps % type % mb)); + + //make a list of all possible specs + subdev_spec_t all_specs; + BOOST_FOREACH(const std::string &db, tree->list(str(boost::format("/mboards/%s/dboards") % mb))){ + BOOST_FOREACH(const std::string &sd, tree->list(str(boost::format("/mboards/%s/dboards/%s/%s_frontends") % mb % db % type))){ + all_specs.push_back(subdev_spec_pair_t(db, sd)); + } + } + + //validate that the spec is possible + BOOST_FOREACH(const subdev_spec_pair_t &pair, spec){ + uhd::assert_has(all_specs, pair, str(boost::format("%s subdevice specification on mboard %s") % type % mb)); + } +} diff --git a/host/lib/usrp/common/validate_subdev_spec.hpp b/host/lib/usrp/common/validate_subdev_spec.hpp new file mode 100644 index 000000000..e73b3e1ee --- /dev/null +++ b/host/lib/usrp/common/validate_subdev_spec.hpp @@ -0,0 +1,39 @@ +// +// Copyright 2011 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#ifndef INCLUDED_LIBUHD_USRP_COMMON_VALIDATE_SUBDEV_SPEC_HPP +#define INCLUDED_LIBUHD_USRP_COMMON_VALIDATE_SUBDEV_SPEC_HPP + +#include <uhd/config.hpp> +#include <uhd/usrp/subdev_spec.hpp> +#include <uhd/utils/assert_has.hpp> +#include <uhd/property_tree.hpp> +#include <string> + +namespace uhd{ namespace usrp{ + + //! Validate a subdev spec against a property tree + void validate_subdev_spec( + property_tree::sptr tree, + const subdev_spec_t &spec, + const std::string &type, //rx or tx + const std::string &mb = "0" + ); + +}} //namespace uhd::usrp + +#endif /* INCLUDED_LIBUHD_USRP_COMMON_VALIDATE_SUBDEV_SPEC_HPP */ diff --git a/host/lib/usrp/e100/io_impl.cpp b/host/lib/usrp/e100/io_impl.cpp index 519d163a0..7af2515a9 100644 --- a/host/lib/usrp/e100/io_impl.cpp +++ b/host/lib/usrp/e100/io_impl.cpp @@ -15,6 +15,7 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // +#include "validate_subdev_spec.hpp" #include "../../transport/super_recv_packet_handler.hpp" #include "../../transport/super_send_packet_handler.hpp" #include <linux/usrp_e.h> //ioctl structures and constants @@ -46,7 +47,9 @@ using namespace uhd::transport; **********************************************************************/ struct e100_impl::io_impl{ io_impl(zero_copy_if::sptr data_transport, const size_t recv_width): - data_transport(data_transport), async_msg_fifo(100/*messages deep*/), false_alarm(0) + false_alarm(0), + data_transport(data_transport), + async_msg_fifo(100/*messages deep*/) { for (size_t i = 0; i < recv_width; i++){ typedef bounded_buffer<managed_recv_buffer::sptr> buffs_queue_type; @@ -261,8 +264,7 @@ void e100_impl::update_rx_subdev_spec(const uhd::usrp::subdev_spec_t &spec){ property_tree::path_type root = "/mboards/0/dboards"; //sanity checking - if (spec.size() == 0) throw uhd::value_error("rx subdev spec cant be empty"); - if (spec.size() > _rx_dsps.size()) throw uhd::value_error("rx subdev spec too long"); + validate_subdev_spec(_tree, spec, "rx"); //setup mux for this spec for (size_t i = 0; i < spec.size(); i++){ @@ -289,7 +291,7 @@ void e100_impl::update_tx_subdev_spec(const uhd::usrp::subdev_spec_t &spec){ property_tree::path_type root = "/mboards/0/dboards"; //sanity checking - if (spec.size() != 1) throw uhd::value_error("tx subdev spec has to be size 1"); + validate_subdev_spec(_tree, spec, "tx"); //set the mux for this spec const std::string conn = _tree->access<std::string>(root / spec[0].db_name / "tx_frontends" / spec[0].sd_name / "connection").get(); diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp index 9de11e0ea..8e75f2025 100644 --- a/host/lib/usrp/usrp1/io_impl.cpp +++ b/host/lib/usrp/usrp1/io_impl.cpp @@ -15,6 +15,7 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // +#include "validate_subdev_spec.hpp" #define SRPH_DONT_CHECK_SEQUENCE #include "../../transport/super_recv_packet_handler.hpp" #include "../../transport/super_send_packet_handler.hpp" @@ -260,8 +261,7 @@ void usrp1_impl::rx_stream_on_off(bool enb){ **********************************************************************/ void usrp1_impl::update_rx_subdev_spec(const uhd::usrp::subdev_spec_t &spec){ //sanity checking - if (spec.size() == 0) throw uhd::value_error("rx subdev spec cant be empty"); - if (spec.size() > get_num_ddcs()) throw uhd::value_error("rx subdev spec too long"); + validate_subdev_spec(_tree, spec, "rx"); _rx_subdev_spec = spec; //shadow _io_impl->recv_handler.resize(spec.size()); @@ -282,8 +282,7 @@ void usrp1_impl::update_rx_subdev_spec(const uhd::usrp::subdev_spec_t &spec){ void usrp1_impl::update_tx_subdev_spec(const uhd::usrp::subdev_spec_t &spec){ //sanity checking - if (spec.size() == 0) throw uhd::value_error("tx subdev spec cant be empty"); - if (spec.size() > get_num_ducs()) throw uhd::value_error("tx subdev spec too long"); + validate_subdev_spec(_tree, spec, "tx"); _tx_subdev_spec = spec; //shadow _io_impl->send_handler.resize(spec.size()); diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp index 0c583f3ca..8809ac709 100644 --- a/host/lib/usrp/usrp2/io_impl.cpp +++ b/host/lib/usrp/usrp2/io_impl.cpp @@ -15,6 +15,7 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // +#include "validate_subdev_spec.hpp" #include "../../transport/super_recv_packet_handler.hpp" #include "../../transport/super_send_packet_handler.hpp" #include "usrp2_impl.hpp" @@ -306,8 +307,7 @@ void usrp2_impl::update_rx_subdev_spec(const std::string &which_mb, const subdev property_tree::path_type root = "/mboards/" + which_mb + "/dboards"; //sanity checking - if (spec.size() == 0) throw uhd::value_error("rx subdev spec cant be empty"); - if (spec.size() > _mbc[which_mb].rx_dsps.size()) throw uhd::value_error("rx subdev spec too long"); + validate_subdev_spec(_tree, spec, "rx", which_mb); //setup mux for this spec for (size_t i = 0; i < spec.size(); i++){ @@ -339,7 +339,7 @@ void usrp2_impl::update_tx_subdev_spec(const std::string &which_mb, const subdev property_tree::path_type root = "/mboards/" + which_mb + "/dboards"; //sanity checking - if (spec.size() != 1) throw uhd::value_error("tx subdev spec has to be size 1"); + validate_subdev_spec(_tree, spec, "tx", which_mb); //set the mux for this spec const std::string conn = _tree->access<std::string>(root / spec[0].db_name / "tx_frontends" / spec[0].sd_name / "connection").get(); |