summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-02-21 11:01:05 -0800
committerJosh Blum <josh@joshknows.com>2011-02-21 11:01:05 -0800
commit436387677320e371bb9a2efa6b0c2ec97027bc05 (patch)
tree79707ad4bc9699b11aeff2b0a040f27d1ee5c5b9
parent607f5df7013810e94bbe049e457858ec68f8dd0e (diff)
downloaduhd-436387677320e371bb9a2efa6b0c2ec97027bc05.tar.gz
uhd-436387677320e371bb9a2efa6b0c2ec97027bc05.tar.bz2
uhd-436387677320e371bb9a2efa6b0c2ec97027bc05.zip
uhd: moved indexed device addr routines into api
implement in usrp2, also combine non specified args into addr when initializing the mboard so we can use a single addr
-rw-r--r--host/include/uhd/types/device_addr.hpp10
-rw-r--r--host/lib/types/device_addr.cpp51
-rw-r--r--host/lib/usrp/usrp2/mboard_impl.cpp13
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.cpp67
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.hpp1
5 files changed, 73 insertions, 69 deletions
diff --git a/host/include/uhd/types/device_addr.hpp b/host/include/uhd/types/device_addr.hpp
index eb3394230..2c0841146 100644
--- a/host/include/uhd/types/device_addr.hpp
+++ b/host/include/uhd/types/device_addr.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-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
@@ -84,9 +84,15 @@ namespace uhd{
}
};
- //handy typedef for a vector of device addresses
+ //! A typedef for a vector of device addresses
typedef std::vector<device_addr_t> device_addrs_t;
+ //! Separate an indexed device address into a vector of device addresses
+ UHD_API device_addrs_t separate_device_addr(const device_addr_t &dev_addr);
+
+ //! Combine a vector of device addresses into an indexed device address
+ UHD_API device_addr_t combine_device_addrs(const device_addrs_t &dev_addrs);
+
} //namespace uhd
#endif /* INCLUDED_UHD_TYPES_DEVICE_ADDR_HPP */
diff --git a/host/lib/types/device_addr.cpp b/host/lib/types/device_addr.cpp
index 14afaa24b..7f2031272 100644
--- a/host/lib/types/device_addr.cpp
+++ b/host/lib/types/device_addr.cpp
@@ -16,10 +16,11 @@
//
#include <uhd/types/device_addr.hpp>
-#include <boost/algorithm/string.hpp> //for trim
+#include <boost/algorithm/string.hpp>
#include <boost/tokenizer.hpp>
#include <boost/foreach.hpp>
#include <boost/format.hpp>
+#include <boost/regex.hpp>
#include <stdexcept>
#include <sstream>
@@ -71,3 +72,51 @@ std::string device_addr_t::to_string(void) const{
}
return args_str;
}
+
+#include <uhd/utils/warning.hpp>
+
+device_addrs_t uhd::separate_device_addr(const device_addr_t &dev_addr){
+ //------------ support old deprecated way and print warning --------
+ if (dev_addr.has_key("addr") and not dev_addr["addr"].empty()){
+ std::vector<std::string> addrs; boost::split(addrs, dev_addr["addr"], boost::is_any_of(" "));
+ if (addrs.size() > 1){
+ device_addr_t fixed_dev_addr = dev_addr;
+ fixed_dev_addr.pop("addr");
+ for (size_t i = 0; i < addrs.size(); i++){
+ fixed_dev_addr[str(boost::format("addr%d") % i)] = addrs[i];
+ }
+ uhd::warning::post(
+ "addr = <space separated list of ip addresses> is deprecated.\n"
+ "To address a multi-device, use multiple <key><index> = <val>.\n"
+ "See the USRP-NXXX application notes. Two device example:\n"
+ " addr0 = 192.168.10.2\n"
+ " addr1 = 192.168.10.3\n"
+ );
+ return separate_device_addr(fixed_dev_addr);
+ }
+ }
+ //------------------------------------------------------------------
+ device_addrs_t dev_addrs;
+ BOOST_FOREACH(const std::string &key, dev_addr.keys()){
+ boost::cmatch matches;
+ if (not boost::regex_match(key.c_str(), matches, boost::regex("^(\\D+)(\\d*)$"))){
+ throw std::runtime_error("unknown key format: " + key);
+ }
+ std::string key_part(matches[1].first, matches[1].second);
+ std::string num_part(matches[2].first, matches[2].second);
+ size_t num = (num_part.empty())? 0 : boost::lexical_cast<size_t>(num_part);
+ dev_addrs.resize(std::max(num+1, dev_addrs.size()));
+ dev_addrs[num][key_part] = dev_addr[key];
+ }
+ return dev_addrs;
+}
+
+device_addr_t uhd::combine_device_addrs(const device_addrs_t &dev_addrs){
+ device_addr_t dev_addr;
+ for (size_t i = 0; i < dev_addrs.size(); i++){
+ BOOST_FOREACH(const std::string &key, dev_addrs[i].keys()){
+ dev_addr[str(boost::format("%s%d") % key % i)] = dev_addrs[i][key];
+ }
+ }
+ return dev_addr;
+}
diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp
index e8e3ecd31..c7a91c69b 100644
--- a/host/lib/usrp/usrp2/mboard_impl.cpp
+++ b/host/lib/usrp/usrp2/mboard_impl.cpp
@@ -56,8 +56,7 @@ static void init_xport(zero_copy_if::sptr xport){
* Structors
**********************************************************************/
usrp2_mboard_impl::usrp2_mboard_impl(
- const device_addr_t &device_addr, //global args passed into make
- const device_addr_t &device_args, //separated mboard specific args
+ const device_addr_t &device_addr,
size_t index, usrp2_impl &device
):
_index(index), _device(device),
@@ -108,7 +107,7 @@ usrp2_mboard_impl::usrp2_mboard_impl(
dsp_init();
//setting the cycles per update (disabled by default)
- const double ups_per_sec = device_args.cast<double>("ups_per_sec", 0.0);
+ const double ups_per_sec = device_addr.cast<double>("ups_per_sec", 0.0);
if (ups_per_sec > 0.0){
const size_t cycles_per_up = size_t(_clock_ctrl->get_master_clock_rate()/ups_per_sec);
_iface->poke32(_iface->regs.tx_ctrl_cycles_per_up, U2_FLAG_TX_CTRL_UP_ENB | cycles_per_up);
@@ -116,18 +115,18 @@ usrp2_mboard_impl::usrp2_mboard_impl(
//setting the packets per update (enabled by default)
size_t send_frame_size = device.dsp_xports[0]->get_send_frame_size();
- const double ups_per_fifo = device_args.cast<double>("ups_per_fifo", 8.0);
+ const double ups_per_fifo = device_addr.cast<double>("ups_per_fifo", 8.0);
if (ups_per_fifo > 0.0){
const size_t packets_per_up = size_t(usrp2_impl::sram_bytes/ups_per_fifo/send_frame_size);
_iface->poke32(_iface->regs.tx_ctrl_packets_per_up, U2_FLAG_TX_CTRL_UP_ENB | packets_per_up);
}
//initialize the clock configuration
- if (device_args.has_key("mimo_mode")){
- if (device_args["mimo_mode"] == "master"){
+ if (device_addr.has_key("mimo_mode")){
+ if (device_addr["mimo_mode"] == "master"){
_mimo_clocking_mode_is_master = true;
}
- else if (device_args["mimo_mode"] == "slave"){
+ else if (device_addr["mimo_mode"] == "slave"){
_mimo_clocking_mode_is_master = false;
}
else throw std::runtime_error(
diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp
index 4ff56eb5b..6230ec41c 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.cpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.cpp
@@ -23,12 +23,10 @@
#include <uhd/utils/static.hpp>
#include <uhd/utils/warning.hpp>
#include <uhd/utils/byteswap.hpp>
-#include <boost/algorithm/string.hpp> //for split
#include <boost/assign/list_of.hpp>
#include <boost/format.hpp>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
-#include <boost/regex.hpp>
#include <boost/bind.hpp>
#include <boost/asio/ip/address_v4.hpp>
#include <iostream>
@@ -40,63 +38,11 @@ using namespace uhd::transport;
namespace asio = boost::asio;
/***********************************************************************
- * Helper Functions
- **********************************************************************/
-
-//! separate indexed device addresses into a vector of device addresses
-device_addrs_t sep_indexed_dev_addrs(const device_addr_t &dev_addr){
- //------------ support old deprecated way and print warning --------
- if (dev_addr.has_key("addr") and not dev_addr["addr"].empty()){
- std::vector<std::string> addrs; boost::split(addrs, dev_addr["addr"], boost::is_any_of(" "));
- if (addrs.size() > 1){
- device_addr_t fixed_dev_addr = dev_addr;
- fixed_dev_addr.pop("addr");
- for (size_t i = 0; i < addrs.size(); i++){
- fixed_dev_addr[str(boost::format("addr%d") % i)] = addrs[i];
- }
- uhd::warning::post(
- "addr = <space separated list of ip addresses> is deprecated.\n"
- "To address a multi-device, use multiple <key><index> = <val>.\n"
- "See the USRP-NXXX application notes. Two device example:\n"
- " addr0 = 192.168.10.2\n"
- " addr1 = 192.168.10.3\n"
- );
- return sep_indexed_dev_addrs(fixed_dev_addr);
- }
- }
- //------------------------------------------------------------------
- device_addrs_t dev_addrs;
- BOOST_FOREACH(const std::string &key, dev_addr.keys()){
- boost::cmatch matches;
- if (not boost::regex_match(key.c_str(), matches, boost::regex("^(\\D+)(\\d*)$"))){
- throw std::runtime_error("unknown key format: " + key);
- }
- std::string key_part(matches[1].first, matches[1].second);
- std::string num_part(matches[2].first, matches[2].second);
- size_t num = (num_part.empty())? 0 : boost::lexical_cast<size_t>(num_part);
- dev_addrs.resize(std::max(num+1, dev_addrs.size()));
- dev_addrs[num][key_part] = dev_addr[key];
- }
- return dev_addrs;
-}
-
-//! combine a vector in device addresses into an indexed device address
-device_addr_t combine_dev_addr_vector(const device_addrs_t &dev_addrs){
- device_addr_t dev_addr;
- for (size_t i = 0; i < dev_addrs.size(); i++){
- BOOST_FOREACH(const std::string &key, dev_addrs[i].keys()){
- dev_addr[str(boost::format("%s%d") % key % i)] = dev_addrs[i][key];
- }
- }
- return dev_addr;
-}
-
-/***********************************************************************
* Discovery over the udp transport
**********************************************************************/
static device_addrs_t usrp2_find(const device_addr_t &hint_){
//handle the multi-device discovery
- device_addrs_t hints = sep_indexed_dev_addrs(hint_);
+ device_addrs_t hints = separate_device_addr(hint_);
if (hints.size() > 1){
device_addrs_t found_devices;
BOOST_FOREACH(const device_addr_t &hint_i, hints){
@@ -106,7 +52,7 @@ static device_addrs_t usrp2_find(const device_addr_t &hint_){
) % hint_i.to_string()));
found_devices.push_back(found_devices_i[0]);
}
- return device_addrs_t(1, combine_dev_addr_vector(found_devices));
+ return device_addrs_t(1, combine_device_addrs(found_devices));
}
//initialize the hint for a single device case
@@ -207,7 +153,7 @@ UHD_STATIC_BLOCK(register_usrp2_device){
* Structors
**********************************************************************/
usrp2_impl::usrp2_impl(const device_addr_t &device_addr){
- device_addrs_t device_args = sep_indexed_dev_addrs(device_addr);
+ device_addrs_t device_args = separate_device_addr(device_addr);
//setup rx otw type
_rx_otw_type.width = 16;
@@ -223,8 +169,13 @@ usrp2_impl::usrp2_impl(const device_addr_t &device_addr){
//create a new mboard handler for each control transport
for(size_t i = 0; i < device_args.size(); i++){
+ device_addr_t dev_addr_i = device_args[i];
+ BOOST_FOREACH(const std::string &key, device_addr.keys()){
+ if (dev_addr_i.has_key(key)) continue;
+ dev_addr_i[key] = device_addr[key];
+ }
_mboards.push_back(usrp2_mboard_impl::sptr(
- new usrp2_mboard_impl(device_addr, device_args[i], i, *this)
+ new usrp2_mboard_impl(dev_addr_i, i, *this)
));
//use an empty name when there is only one mboard
std::string name = (device_args.size() > 1)? boost::lexical_cast<std::string>(i) : "";
diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp
index df55e6a99..dbddd2ec0 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.hpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.hpp
@@ -89,7 +89,6 @@ public:
//structors
usrp2_mboard_impl(
const uhd::device_addr_t &device_addr,
- const uhd::device_addr_t &device_args,
size_t index, usrp2_impl &device
);
~usrp2_mboard_impl(void);