From 54048fd9b227633c724edd975347c81152ab37b2 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 11 Aug 2010 12:27:18 -0700 Subject: usrp: added subdev spec verification functions --- host/lib/usrp/misc_utils.cpp | 60 +++++++++++++++++++++++++++++++++++++ host/lib/usrp/misc_utils.hpp | 19 ++++++++++++ host/lib/usrp/usrp2/mboard_impl.cpp | 15 ++-------- 3 files changed, 82 insertions(+), 12 deletions(-) (limited to 'host') 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 #include +#include #include +#include +#include #include #include #include @@ -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()){ + 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::none()){ + std::string sd_name = dboard[DBOARD_PROP_SUBDEV_NAMES].as().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().at(0); + wax::obj dboard = mboard[named_prop_t(dboard_prop, db_name)]; + std::string sd_name = dboard[DBOARD_PROP_SUBDEV_NAMES].as().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(), 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(), 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 #include +#include #include 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 #include @@ -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(); - //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(), _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() @@ -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(); - //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(), _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() -- cgit v1.2.3 From 805d4a0cff00fb4e0071bb300436bb7eefb8fb16 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 12 Aug 2010 10:08:17 -0700 Subject: uhd: made split string utility function --- host/include/uhd/utils/algorithm.hpp | 21 +++++++++++++++++++++ host/lib/types.cpp | 19 ++++++------------- host/lib/usrp/subdev_spec.cpp | 9 +++------ host/lib/usrp/usrp2/usrp2_impl.cpp | 12 +++--------- host/lib/utils/paths.cpp | 10 ++-------- host/lib/utils/warning.cpp | 8 ++------ host/utils/uhd_usrp_probe.cpp | 4 ++-- 7 files changed, 39 insertions(+), 44 deletions(-) (limited to 'host') diff --git a/host/include/uhd/utils/algorithm.hpp b/host/include/uhd/utils/algorithm.hpp index 1b5eacfa9..53c571e4e 100644 --- a/host/include/uhd/utils/algorithm.hpp +++ b/host/include/uhd/utils/algorithm.hpp @@ -22,6 +22,9 @@ #include #include #include +#include +#include +#include /*! \file algorithm.hpp * Useful templated functions and classes that I like to pretend are part of stl. @@ -29,6 +32,24 @@ */ namespace std{ + /*! + * Split a string at the separation characters. + * \param string the string to split + * \param sep the separator characters + * \return a range of strings + */ + inline std::vector split_string( + const std::string &string, const std::string &sep = "\t " + ){ + std::vector strings; + if (not string.empty()) boost::split( + // do not split an empty string: + // let me tell you about the time when boost::split segfaulted... + strings, string, boost::is_any_of(sep) + ); + return strings; + } + /*! * A wrapper around std::copy that takes ranges instead of iterators. * diff --git a/host/lib/types.cpp b/host/lib/types.cpp index 5c0fb1f42..f957cd83f 100644 --- a/host/lib/types.cpp +++ b/host/lib/types.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -181,15 +180,10 @@ static std::string trim(const std::string &in){ } device_addr_t::device_addr_t(const std::string &args){ - //split the args at the semi-colons - std::vector pairs; - boost::split(pairs, args, boost::is_any_of(arg_delim)); - BOOST_FOREACH(const std::string &pair, pairs){ + BOOST_FOREACH(const std::string &pair, std::split_string(args, arg_delim)){ if (trim(pair) == "") continue; - //split the key value pairs at the equals - std::vector key_val; - boost::split(key_val, pair, boost::is_any_of(pair_delim)); + std::vector key_val = std::split_string(pair, pair_delim); if (key_val.size() != 2) throw std::runtime_error("invalid args string: "+args); (*this)[trim(key_val.front())] = trim(key_val.back()); } @@ -238,13 +232,12 @@ mac_addr_t mac_addr_t::from_string(const std::string &mac_addr_str){ throw std::runtime_error("expected exactly 5 or 17 characters"); //split the mac addr hex string at the colons - std::vector hex_strs; - boost::split(hex_strs, mac_addr_str, boost::is_any_of(":")); - for (size_t i = 0; i < hex_strs.size(); i++){ + size_t i = 0; + BOOST_FOREACH(const std::string &hex_str, std::split_string(mac_addr_str, ":")){ int hex_num; - std::istringstream iss(hex_strs[i]); + std::istringstream iss(hex_str); iss >> std::hex >> hex_num; - bytes[i] = boost::uint8_t(hex_num); + bytes[i++] = boost::uint8_t(hex_num); } } diff --git a/host/lib/usrp/subdev_spec.cpp b/host/lib/usrp/subdev_spec.cpp index 0f00e2f74..765eecb3d 100644 --- a/host/lib/usrp/subdev_spec.cpp +++ b/host/lib/usrp/subdev_spec.cpp @@ -16,7 +16,7 @@ // #include -#include +#include #include #include #include @@ -35,12 +35,9 @@ subdev_spec_pair_t::subdev_spec_pair_t( } subdev_spec_t::subdev_spec_t(const std::string &markup){ - std::vector pairs; - boost::split(pairs, markup, boost::is_any_of("\t ")); - BOOST_FOREACH(const std::string &pair, pairs){ + BOOST_FOREACH(const std::string &pair, std::split_string(markup)){ if (pair == "") continue; - std::vector db_sd; - boost::split(db_sd, pair, boost::is_any_of(":")); + std::vector db_sd = std::split_string(pair, ":"); switch(db_sd.size()){ case 1: this->push_back(subdev_spec_pair_t("", db_sd.front())); break; case 2: this->push_back(subdev_spec_pair_t(db_sd.front(), db_sd.back())); break; diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 21f411afe..45362c20f 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include @@ -41,12 +41,6 @@ static const size_t DISCOVERY_TIMEOUT_MS = 100; /*********************************************************************** * Helper Functions **********************************************************************/ -std::vector split_addrs(const std::string &addrs_str){ - std::vector addrs; - boost::split(addrs, addrs_str, boost::is_any_of("\t ")); - return addrs; -} - template std::string num2str(T num){ return boost::lexical_cast(num); } @@ -80,7 +74,7 @@ static uhd::device_addrs_t usrp2_find(const device_addr_t &hint){ } //if there are multiple addresses, just return good, dont test - std::vector addrs = split_addrs(hint["addr"]); + std::vector addrs = std::split_string(hint["addr"]); if (addrs.size() > 1){ device_addr_t new_addr; new_addr["type"] = "usrp2"; @@ -155,7 +149,7 @@ static device::sptr usrp2_make(const device_addr_t &device_addr){ std::vector ctrl_transports; std::vector data_transports; - BOOST_FOREACH(const std::string &addr, split_addrs(device_addr["addr"])){ + BOOST_FOREACH(const std::string &addr, std::split_string(device_addr["addr"])){ ctrl_transports.push_back(udp_simple::make_connected( addr, num2str(USRP2_UDP_CTRL_PORT) )); diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp index 4029bd989..9ac20d855 100644 --- a/host/lib/utils/paths.cpp +++ b/host/lib/utils/paths.cpp @@ -17,7 +17,7 @@ #include "constants.hpp" #include -#include +#include #include #include #include @@ -58,15 +58,9 @@ static std::vector get_env_paths(const std::string &var_name){ po::store(po::parse_environment(desc, boost::bind(&name_mapper, var_name, _1)), vm); po::notify(vm); - //split the path at the path separators - std::vector path_strings; - if (not var_value.empty()) boost::split(//dont split empty strings - path_strings, var_value, boost::is_any_of(env_path_sep) - ); - //convert to filesystem path, filter blank paths std::vector paths; - BOOST_FOREACH(std::string &path_string, path_strings){ + BOOST_FOREACH(const std::string &path_string, std::split_string(var_value, env_path_sep)){ if (path_string.empty()) continue; paths.push_back(fs::system_complete(path_string)); } diff --git a/host/lib/utils/warning.cpp b/host/lib/utils/warning.cpp index ae4d4c7aa..8a7d35a23 100644 --- a/host/lib/utils/warning.cpp +++ b/host/lib/utils/warning.cpp @@ -16,7 +16,7 @@ // #include -#include +#include #include #include #include @@ -24,13 +24,9 @@ using namespace uhd; void uhd::print_warning(const std::string &msg){ - //extract the message lines - std::vector lines; - boost::split(lines, msg, boost::is_any_of("\n")); - //print the warning message std::cerr << std::endl << "Warning:" << std::endl; - BOOST_FOREACH(const std::string &line, lines){ + BOOST_FOREACH(const std::string &line, std::split_string(msg, "\n")){ std::cerr << " " << line << std::endl; } } diff --git a/host/utils/uhd_usrp_probe.cpp b/host/utils/uhd_usrp_probe.cpp index 097317516..8947034d7 100644 --- a/host/utils/uhd_usrp_probe.cpp +++ b/host/utils/uhd_usrp_probe.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -26,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -43,7 +43,7 @@ static std::string make_border(const std::string &text){ std::stringstream ss; ss << boost::format(" _____________________________________________________") << std::endl; ss << boost::format(" /") << std::endl; - std::vector lines; boost::split(lines, text, boost::is_any_of("\n")); + std::vector lines = std::split_string(text, "\n"); while (lines.back() == "") lines.pop_back(); //strip trailing newlines if (lines.size()) lines[0] = " " + lines[0]; //indent the title line BOOST_FOREACH(const std::string &line, lines){ -- cgit v1.2.3 From f0960e79489c6702d3bd79c40f9e24f2b9e5b42d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 14 Aug 2010 14:45:59 -0700 Subject: usrp: replaced mboard name with special props for dboard iface --- host/include/uhd/usrp/dboard_iface.hpp | 29 ++++++++++++++++++++++++++--- host/lib/usrp/dboard/db_dbsrx.cpp | 31 ++++++++++++++----------------- host/lib/usrp/usrp2/dboard_iface.cpp | 7 ++++++- 3 files changed, 46 insertions(+), 21 deletions(-) (limited to 'host') diff --git a/host/include/uhd/usrp/dboard_iface.hpp b/host/include/uhd/usrp/dboard_iface.hpp index fc7ea3052..e776ecc42 100644 --- a/host/include/uhd/usrp/dboard_iface.hpp +++ b/host/include/uhd/usrp/dboard_iface.hpp @@ -65,11 +65,34 @@ public: AUX_ADC_B = 'b' }; + //! Special properties that differentiate this daughterboard slot + struct special_props_t{ + /*! + * Soft clock divider: + * When a motherboard cannot provided a divided dboard clock, + * it may provided a "soft" divided clock over an FPGA GPIO. + * The implementation must know the type of clock provided. + */ + bool soft_clock_divider; + + /*! + * Mangle i2c addresses: + * When i2c is shared across multiple daugterboard slots, + * the i2c addresses will be mangled on the secondary slot + * to avoid conflicts between slots in the i2c address space. + * The mangling is daguhterboard specific so the implementation + * needs to know whether it should use mangled addresses or not. + */ + bool mangle_i2c_addrs; + }; + /*! - * Get the motherboard name of the form: usrp1, usrp2... - * \return string representing the motherboard name + * Get special properties information for this dboard slot. + * This call helps the dboard code to handle implementation + * differences between different motherboards and dboard slots. + * \return the special properties struct */ - virtual std::string get_mboard_name(void) = 0; + virtual special_props_t get_special_props(void) = 0; /*! * Write to an aux dac. diff --git a/host/lib/usrp/dboard/db_dbsrx.cpp b/host/lib/usrp/dboard/db_dbsrx.cpp index 03e6b6255..072497dcc 100644 --- a/host/lib/usrp/dboard/db_dbsrx.cpp +++ b/host/lib/usrp/dboard/db_dbsrx.cpp @@ -61,7 +61,7 @@ static const uhd::dict dbsrx_gain_ranges = map_list_o **********************************************************************/ class dbsrx : public rx_dboard_base{ public: - dbsrx(ctor_args_t args, boost::uint8_t max2118_addr); + dbsrx(ctor_args_t args); ~dbsrx(void); void rx_get(const wax::obj &key, wax::obj &val); @@ -73,7 +73,9 @@ private: uhd::dict _gains; max2118_write_regs_t _max2118_write_regs; max2118_read_regs_t _max2118_read_regs; - boost::uint8_t _max2118_addr; //0x67 or 0x65 depending on which side + boost::uint8_t _max2118_addr(void){ + return (this->get_iface()->get_special_props().mangle_i2c_addrs)? 0x65 : 0x67; + }; void set_lo_freq(double target_freq); void set_gain(float gain, const std::string &name); @@ -102,7 +104,7 @@ private: //send the data this->get_iface()->write_i2c( - _max2118_addr, regs_vector + _max2118_addr(), regs_vector ); } } @@ -120,7 +122,7 @@ private: //read from i2c regs_vector = this->get_iface()->read_i2c( - _max2118_addr, num_bytes + _max2118_addr(), num_bytes ); for(boost::uint8_t i=0; i < num_bytes; i++){ @@ -156,10 +158,8 @@ private: /*********************************************************************** * Register the DBSRX dboard **********************************************************************/ -// FIXME 0x67 is the default i2c address on USRP2 -// need to handle which side for USRP1 with different address static dboard_base::sptr make_dbsrx(dboard_base::ctor_args_t args){ - return dboard_base::sptr(new dbsrx(args, 0x67)); + return dboard_base::sptr(new dbsrx(args)); } //dbid for USRP2 version @@ -177,27 +177,27 @@ UHD_STATIC_BLOCK(reg_dbsrx_on_usrp1_dboard){ /*********************************************************************** * Structors **********************************************************************/ -dbsrx::dbsrx(ctor_args_t args, boost::uint8_t max2118_addr) : rx_dboard_base(args){ +dbsrx::dbsrx(ctor_args_t args) : rx_dboard_base(args){ //warn user about incorrect DBID on USRP1, requires R193 populated - if (this->get_iface()->get_mboard_name() == "usrp1" and this->get_rx_id() == 0x000D) + if (this->get_iface()->get_special_props().soft_clock_divider and this->get_rx_id() == 0x000D) uhd::print_warning( str(boost::format( "DBSRX: incorrect dbid\n" - "%s expects dbid 0x0002 and R193\n" + "Expected dbid 0x0002 and R193\n" "found dbid == %d\n" "Please see the daughterboard app notes" - ) % (this->get_iface()->get_mboard_name()) % (this->get_rx_id().to_pp_string())) + ) % this->get_rx_id().to_pp_string()) ); //warn user about incorrect DBID on non-USRP1, requires R194 populated - if (this->get_iface()->get_mboard_name() != "usrp1" and this->get_rx_id() == 0x0002) + if (not this->get_iface()->get_special_props().soft_clock_divider and this->get_rx_id() == 0x0002) uhd::print_warning( str(boost::format( "DBSRX: incorrect dbid\n" - "%s expects dbid 0x000D and R194\n" + "Expected dbid 0x000D and R194\n" "found dbid == %d\n" "Please see the daughterboard app notes" - ) % (this->get_iface()->get_mboard_name()) % (this->get_rx_id().to_pp_string())) + ) % this->get_rx_id().to_pp_string()) ); //enable only the clocks we need @@ -207,9 +207,6 @@ dbsrx::dbsrx(ctor_args_t args, boost::uint8_t max2118_addr) : rx_dboard_base(arg this->get_iface()->set_pin_ctrl(dboard_iface::UNIT_RX, 0x0); // All unused in atr this->get_iface()->set_gpio_ddr(dboard_iface::UNIT_RX, 0x0); // All Inputs - //set the i2c address for the max2118 - _max2118_addr = max2118_addr; - //send initial register settings this->send_reg(0x0, 0x5); diff --git a/host/lib/usrp/usrp2/dboard_iface.cpp b/host/lib/usrp/usrp2/dboard_iface.cpp index 1b9a4bb97..8bded1ea3 100644 --- a/host/lib/usrp/usrp2/dboard_iface.cpp +++ b/host/lib/usrp/usrp2/dboard_iface.cpp @@ -37,7 +37,12 @@ public: usrp2_dboard_iface(usrp2_iface::sptr iface, usrp2_clock_ctrl::sptr clock_ctrl); ~usrp2_dboard_iface(void); - std::string get_mboard_name(void){return "usrp2";} + special_props_t get_special_props(void){ + special_props_t props; + props.soft_clock_divider = false; + props.mangle_i2c_addrs = false; + return props; + } void write_aux_dac(unit_t, aux_dac_t, float); float read_aux_adc(unit_t, aux_adc_t); -- cgit v1.2.3 From 6c3d37caa3a47ca534c5e3a110adad0137d5d06d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 15 Aug 2010 01:41:35 -0700 Subject: usrp: give dboards a name (not a blank string), do automatic selection when not provided --- host/include/uhd/usrp/dboard_manager.hpp | 2 +- host/lib/usrp/misc_utils.cpp | 20 +++++++++++++++----- host/lib/usrp/subdev_spec.cpp | 6 +----- host/lib/usrp/usrp2/mboard_impl.cpp | 10 ++++++---- 4 files changed, 23 insertions(+), 15 deletions(-) (limited to 'host') diff --git a/host/include/uhd/usrp/dboard_manager.hpp b/host/include/uhd/usrp/dboard_manager.hpp index e5831d4cf..c68f069f0 100644 --- a/host/include/uhd/usrp/dboard_manager.hpp +++ b/host/include/uhd/usrp/dboard_manager.hpp @@ -51,7 +51,7 @@ public: const dboard_id_t &dboard_id, dboard_ctor_t dboard_ctor, const std::string &name, - const prop_names_t &subdev_names = prop_names_t(1, "") + const prop_names_t &subdev_names = prop_names_t(1, "0") ); /*! diff --git a/host/lib/usrp/misc_utils.cpp b/host/lib/usrp/misc_utils.cpp index da22d79f1..930314fc2 100644 --- a/host/lib/usrp/misc_utils.cpp +++ b/host/lib/usrp/misc_utils.cpp @@ -127,14 +127,17 @@ static void verify_xx_subdev_spec( wax::obj mboard, std::string xx_type ){ + prop_names_t dboard_names = mboard[dboard_names_prop].as(); + UHD_ASSERT_THROW(dboard_names.size() > 0); //well i hope there is a dboard + //the subdevice specification is empty: handle automatic if (subdev_spec.empty()){ - BOOST_FOREACH(const std::string &db_name, mboard[dboard_names_prop].as()){ + BOOST_FOREACH(const std::string &db_name, dboard_names){ 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::none()){ - std::string sd_name = dboard[DBOARD_PROP_SUBDEV_NAMES].as().at(0); + std::string sd_name = dboard[DBOARD_PROP_SUBDEV_NAMES].as().front(); subdev_spec.push_back(subdev_spec_pair_t(db_name, sd_name)); break; } @@ -142,16 +145,23 @@ static void verify_xx_subdev_spec( //didnt find any populated dboards: add the first subdevice if (subdev_spec.empty()){ - std::string db_name = mboard[dboard_names_prop].as().at(0); + std::string db_name = dboard_names.front(); wax::obj dboard = mboard[named_prop_t(dboard_prop, db_name)]; - std::string sd_name = dboard[DBOARD_PROP_SUBDEV_NAMES].as().at(0); + std::string sd_name = dboard[DBOARD_PROP_SUBDEV_NAMES].as().front(); 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(), pair.db_name, xx_type + " dboard name"); + //empty db name means select dboard automatically + if (pair.db_name.empty()){ + if (dboard_names.size() != 1) throw std::runtime_error( + "A daughterboard name must be provided for multi-slot boards: " + subdev_spec.to_string() + ); + pair.db_name == dboard_names.front(); + } + uhd::assert_has(dboard_names, 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(), pair.sd_name, xx_type + " subdev name"); } diff --git a/host/lib/usrp/subdev_spec.cpp b/host/lib/usrp/subdev_spec.cpp index 765eecb3d..7a3e72867 100644 --- a/host/lib/usrp/subdev_spec.cpp +++ b/host/lib/usrp/subdev_spec.cpp @@ -53,13 +53,9 @@ std::string subdev_spec_t::to_pp_string(void) const{ size_t count = 0; ss << "Subdevice Specification:" << std::endl; BOOST_FOREACH(const subdev_spec_pair_t &pair, *this){ - std::string db_name = pair.db_name; - if (db_name == "") db_name = "0"; - std::string sd_name = pair.sd_name; - if (sd_name == "") sd_name = "0"; ss << boost::format( " Channel %d: Daughterboard %s, Subdevice %s" - ) % (count++) % db_name % sd_name << std::endl; + ) % (count++) % pair.db_name % pair.sd_name << std::endl; } return ss.str(); } diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index fe3ec6785..533b60bae 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -186,6 +186,8 @@ void usrp2_mboard_impl::issue_ddc_stream_cmd(const stream_cmd_t &stream_cmd){ /*********************************************************************** * MBoard Get Properties **********************************************************************/ +static const std::string dboard_name = "0"; + void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ wax::obj key; std::string name; boost::tie(key, name) = extract_named_prop(key_); @@ -222,21 +224,21 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ return; case MBOARD_PROP_RX_DBOARD: - UHD_ASSERT_THROW(name == ""); + UHD_ASSERT_THROW(name == dboard_name); val = _rx_dboard_proxy->get_link(); return; case MBOARD_PROP_RX_DBOARD_NAMES: - val = prop_names_t(1, ""); + val = prop_names_t(1, dboard_name); return; case MBOARD_PROP_TX_DBOARD: - UHD_ASSERT_THROW(name == ""); + UHD_ASSERT_THROW(name == dboard_name); val = _tx_dboard_proxy->get_link(); return; case MBOARD_PROP_TX_DBOARD_NAMES: - val = prop_names_t(1, ""); + val = prop_names_t(1, dboard_name); return; case MBOARD_PROP_RX_DSP: -- cgit v1.2.3 From 98ba0cc067489d417342314a7e7408d2dbbc8250 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 15 Aug 2010 10:51:25 -0700 Subject: uhd: extract named prop returns a named prop (not a tuple) simplifies the code after the property set/get declaration --- host/include/uhd/utils/props.hpp | 33 ++++++++++++++++++-------------- host/lib/usrp/dboard/db_basic_and_lf.cpp | 12 ++++-------- host/lib/usrp/dboard/db_dbsrx.cpp | 29 +++++++--------------------- host/lib/usrp/dboard/db_rfx.cpp | 26 +++++++++++-------------- host/lib/usrp/dboard/db_unknown.cpp | 12 ++++-------- host/lib/usrp/dboard/db_wbx.cpp | 32 ++++++++++++++----------------- host/lib/usrp/dboard/db_xcvr2450.cpp | 32 ++++++++++++++----------------- host/lib/usrp/usrp2/codec_impl.cpp | 8 ++------ host/lib/usrp/usrp2/dboard_impl.cpp | 14 ++++++-------- host/lib/usrp/usrp2/mboard_impl.cpp | 13 ++++++------- host/lib/usrp/usrp2/usrp2_impl.cpp | 5 ++--- host/lib/utils/props.cpp | 9 +++------ 12 files changed, 92 insertions(+), 133 deletions(-) (limited to 'host') diff --git a/host/include/uhd/utils/props.hpp b/host/include/uhd/utils/props.hpp index f376d2612..fbca03019 100644 --- a/host/include/uhd/utils/props.hpp +++ b/host/include/uhd/utils/props.hpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -36,8 +35,25 @@ namespace uhd{ * Allows properties to be sub-sectioned by name. */ struct UHD_API named_prop_t{ - wax::obj key; - std::string name; + const wax::obj key; + const std::string name; + + //! Convert the key to the specified type + template inline T as(void){ + return key.as(); + } + + /*! + * Utility function to convert generic key into a named prop. + * If the key was already a named prop, the prop will be split. + * Otherwise, the key will be the key, and the name will be used. + * \param key a reference to the prop object + * \param name a reference to the name object + * \return a named property struct with key and name + */ + static named_prop_t extract( + const wax::obj &key, const std::string &name = "" + ); /*! * Create a new named prop from key and name. @@ -47,17 +63,6 @@ namespace uhd{ named_prop_t(const wax::obj &key, const std::string &name); }; - /*! - * Utility function to separate a named property into its components. - * \param key a reference to the prop object - * \param name a reference to the name object - * \return a tuple that can be used with boost::tie - */ - UHD_API boost::tuple extract_named_prop( - const wax::obj &key, - const std::string &name = "" - ); - /*! * Throw when getting a not-implemented or write-only property. * Throw-site information will be included with this error. diff --git a/host/lib/usrp/dboard/db_basic_and_lf.cpp b/host/lib/usrp/dboard/db_basic_and_lf.cpp index 9180828d8..f8236d598 100644 --- a/host/lib/usrp/dboard/db_basic_and_lf.cpp +++ b/host/lib/usrp/dboard/db_basic_and_lf.cpp @@ -95,8 +95,7 @@ basic_rx::~basic_rx(void){ } void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -161,8 +160,7 @@ void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){ } void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -194,8 +192,7 @@ basic_tx::~basic_tx(void){ } void basic_tx::tx_get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -252,8 +249,7 @@ void basic_tx::tx_get(const wax::obj &key_, wax::obj &val){ } void basic_tx::tx_set(const wax::obj &key_, const wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ diff --git a/host/lib/usrp/dboard/db_dbsrx.cpp b/host/lib/usrp/dboard/db_dbsrx.cpp index 072497dcc..06cf91d3b 100644 --- a/host/lib/usrp/dboard/db_dbsrx.cpp +++ b/host/lib/usrp/dboard/db_dbsrx.cpp @@ -500,8 +500,7 @@ void dbsrx::set_bandwidth(float bandwidth){ * RX Get and Set **********************************************************************/ void dbsrx::rx_get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -514,13 +513,13 @@ void dbsrx::rx_get(const wax::obj &key_, wax::obj &val){ return; case SUBDEV_PROP_GAIN: - assert_has(_gains.keys(), name, "dbsrx gain name"); - val = _gains[name]; + assert_has(_gains.keys(), key.name, "dbsrx gain name"); + val = _gains[key.name]; return; case SUBDEV_PROP_GAIN_RANGE: - assert_has(dbsrx_gain_ranges.keys(), name, "dbsrx gain name"); - val = dbsrx_gain_ranges[name]; + assert_has(dbsrx_gain_ranges.keys(), key.name, "dbsrx gain name"); + val = dbsrx_gain_ranges[key.name]; return; case SUBDEV_PROP_GAIN_NAMES: @@ -543,19 +542,6 @@ void dbsrx::rx_get(const wax::obj &key_, wax::obj &val){ val = dbsrx_antennas; return; -/* - case SUBDEV_PROP_QUADRATURE: - val = true; - return; - - case SUBDEV_PROP_IQ_SWAPPED: - val = false; - return; - - case SUBDEV_PROP_SPECTRUM_INVERTED: - val = false; - return; -*/ case SUBDEV_PROP_CONNECTION: val = SUBDEV_CONN_COMPLEX_IQ; return; @@ -583,8 +569,7 @@ void dbsrx::rx_get(const wax::obj &key_, wax::obj &val){ } void dbsrx::rx_set(const wax::obj &key_, const wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -594,7 +579,7 @@ void dbsrx::rx_set(const wax::obj &key_, const wax::obj &val){ return; case SUBDEV_PROP_GAIN: - this->set_gain(val.as(), name); + this->set_gain(val.as(), key.name); return; case SUBDEV_PROP_BANDWIDTH: diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp index b6b44199a..c3ab96e59 100644 --- a/host/lib/usrp/dboard/db_rfx.cpp +++ b/host/lib/usrp/dboard/db_rfx.cpp @@ -398,8 +398,7 @@ double rfx_xcvr::set_lo_freq( * RX Get and Set **********************************************************************/ void rfx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -412,13 +411,13 @@ void rfx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){ return; case SUBDEV_PROP_GAIN: - assert_has(_rx_gains.keys(), name, "rfx rx gain name"); - val = _rx_gains[name]; + assert_has(_rx_gains.keys(), key.name, "rfx rx gain name"); + val = _rx_gains[key.name]; return; case SUBDEV_PROP_GAIN_RANGE: - assert_has(_rx_gain_ranges.keys(), name, "rfx rx gain name"); - val = _rx_gain_ranges[name]; + assert_has(_rx_gain_ranges.keys(), key.name, "rfx rx gain name"); + val = _rx_gain_ranges[key.name]; return; case SUBDEV_PROP_GAIN_NAMES: @@ -458,8 +457,7 @@ void rfx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){ } void rfx_xcvr::rx_set(const wax::obj &key_, const wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -469,7 +467,7 @@ void rfx_xcvr::rx_set(const wax::obj &key_, const wax::obj &val){ return; case SUBDEV_PROP_GAIN: - this->set_rx_gain(val.as(), name); + this->set_rx_gain(val.as(), key.name); return; case SUBDEV_PROP_ANTENNA: @@ -484,8 +482,7 @@ void rfx_xcvr::rx_set(const wax::obj &key_, const wax::obj &val){ * TX Get and Set **********************************************************************/ void rfx_xcvr::tx_get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -499,7 +496,7 @@ void rfx_xcvr::tx_get(const wax::obj &key_, wax::obj &val){ case SUBDEV_PROP_GAIN: case SUBDEV_PROP_GAIN_RANGE: - assert_has(rfx_tx_gain_ranges.keys(), name, "rfx tx gain name"); + assert_has(rfx_tx_gain_ranges.keys(), key.name, "rfx tx gain name"); //no controllable tx gains, will not get here return; @@ -540,8 +537,7 @@ void rfx_xcvr::tx_get(const wax::obj &key_, wax::obj &val){ } void rfx_xcvr::tx_set(const wax::obj &key_, const wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -551,7 +547,7 @@ void rfx_xcvr::tx_set(const wax::obj &key_, const wax::obj &val){ return; case SUBDEV_PROP_GAIN: - this->set_tx_gain(val.as(), name); + this->set_tx_gain(val.as(), key.name); return; case SUBDEV_PROP_ANTENNA: diff --git a/host/lib/usrp/dboard/db_unknown.cpp b/host/lib/usrp/dboard/db_unknown.cpp index 9dd9b550b..f6f4f4a61 100644 --- a/host/lib/usrp/dboard/db_unknown.cpp +++ b/host/lib/usrp/dboard/db_unknown.cpp @@ -78,8 +78,7 @@ unknown_rx::~unknown_rx(void){ } void unknown_rx::rx_get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -136,8 +135,7 @@ void unknown_rx::rx_get(const wax::obj &key_, wax::obj &val){ } void unknown_rx::rx_set(const wax::obj &key_, const wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -169,8 +167,7 @@ unknown_tx::~unknown_tx(void){ } void unknown_tx::tx_get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -227,8 +224,7 @@ void unknown_tx::tx_get(const wax::obj &key_, wax::obj &val){ } void unknown_tx::tx_set(const wax::obj &key_, const wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ diff --git a/host/lib/usrp/dboard/db_wbx.cpp b/host/lib/usrp/dboard/db_wbx.cpp index 3038ce30b..ccd897674 100644 --- a/host/lib/usrp/dboard/db_wbx.cpp +++ b/host/lib/usrp/dboard/db_wbx.cpp @@ -467,8 +467,7 @@ double wbx_xcvr::set_lo_freq( * RX Get and Set **********************************************************************/ void wbx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -481,13 +480,13 @@ void wbx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){ return; case SUBDEV_PROP_GAIN: - assert_has(_rx_gains.keys(), name, "wbx rx gain name"); - val = _rx_gains[name]; + assert_has(_rx_gains.keys(), key.name, "wbx rx gain name"); + val = _rx_gains[key.name]; return; case SUBDEV_PROP_GAIN_RANGE: - assert_has(wbx_rx_gain_ranges.keys(), name, "wbx rx gain name"); - val = wbx_rx_gain_ranges[name]; + assert_has(wbx_rx_gain_ranges.keys(), key.name, "wbx rx gain name"); + val = wbx_rx_gain_ranges[key.name]; return; case SUBDEV_PROP_GAIN_NAMES: @@ -527,8 +526,7 @@ void wbx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){ } void wbx_xcvr::rx_set(const wax::obj &key_, const wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -538,7 +536,7 @@ void wbx_xcvr::rx_set(const wax::obj &key_, const wax::obj &val){ return; case SUBDEV_PROP_GAIN: - this->set_rx_gain(val.as(), name); + this->set_rx_gain(val.as(), key.name); return; case SUBDEV_PROP_ANTENNA: @@ -553,8 +551,7 @@ void wbx_xcvr::rx_set(const wax::obj &key_, const wax::obj &val){ * TX Get and Set **********************************************************************/ void wbx_xcvr::tx_get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -567,13 +564,13 @@ void wbx_xcvr::tx_get(const wax::obj &key_, wax::obj &val){ return; case SUBDEV_PROP_GAIN: - assert_has(_tx_gains.keys(), name, "wbx tx gain name"); - val = _tx_gains[name]; + assert_has(_tx_gains.keys(), key.name, "wbx tx gain name"); + val = _tx_gains[key.name]; return; case SUBDEV_PROP_GAIN_RANGE: - assert_has(wbx_tx_gain_ranges.keys(), name, "wbx tx gain name"); - val = wbx_tx_gain_ranges[name]; + assert_has(wbx_tx_gain_ranges.keys(), key.name, "wbx tx gain name"); + val = wbx_tx_gain_ranges[key.name]; return; case SUBDEV_PROP_GAIN_NAMES: @@ -613,8 +610,7 @@ void wbx_xcvr::tx_get(const wax::obj &key_, wax::obj &val){ } void wbx_xcvr::tx_set(const wax::obj &key_, const wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -624,7 +620,7 @@ void wbx_xcvr::tx_set(const wax::obj &key_, const wax::obj &val){ return; case SUBDEV_PROP_GAIN: - this->set_tx_gain(val.as(), name); + this->set_tx_gain(val.as(), key.name); return; case SUBDEV_PROP_ANTENNA: diff --git a/host/lib/usrp/dboard/db_xcvr2450.cpp b/host/lib/usrp/dboard/db_xcvr2450.cpp index 2c94bcd2d..798ff74a3 100644 --- a/host/lib/usrp/dboard/db_xcvr2450.cpp +++ b/host/lib/usrp/dboard/db_xcvr2450.cpp @@ -438,8 +438,7 @@ void xcvr2450::set_rx_gain(float gain, const std::string &name){ * RX Get and Set **********************************************************************/ void xcvr2450::rx_get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -452,13 +451,13 @@ void xcvr2450::rx_get(const wax::obj &key_, wax::obj &val){ return; case SUBDEV_PROP_GAIN: - assert_has(_rx_gains.keys(), name, "xcvr rx gain name"); - val = _rx_gains[name]; + assert_has(_rx_gains.keys(), key.name, "xcvr rx gain name"); + val = _rx_gains[key.name]; return; case SUBDEV_PROP_GAIN_RANGE: - assert_has(xcvr_rx_gain_ranges.keys(), name, "xcvr rx gain name"); - val = xcvr_rx_gain_ranges[name]; + assert_has(xcvr_rx_gain_ranges.keys(), key.name, "xcvr rx gain name"); + val = xcvr_rx_gain_ranges[key.name]; return; case SUBDEV_PROP_GAIN_NAMES: @@ -502,8 +501,7 @@ void xcvr2450::rx_get(const wax::obj &key_, wax::obj &val){ } void xcvr2450::rx_set(const wax::obj &key_, const wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -513,7 +511,7 @@ void xcvr2450::rx_set(const wax::obj &key_, const wax::obj &val){ return; case SUBDEV_PROP_GAIN: - this->set_rx_gain(val.as(), name); + this->set_rx_gain(val.as(), key.name); return; case SUBDEV_PROP_ANTENNA: @@ -528,8 +526,7 @@ void xcvr2450::rx_set(const wax::obj &key_, const wax::obj &val){ * TX Get and Set **********************************************************************/ void xcvr2450::tx_get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -542,13 +539,13 @@ void xcvr2450::tx_get(const wax::obj &key_, wax::obj &val){ return; case SUBDEV_PROP_GAIN: - assert_has(_tx_gains.keys(), name, "xcvr tx gain name"); - val = _tx_gains[name]; + assert_has(_tx_gains.keys(), key.name, "xcvr tx gain name"); + val = _tx_gains[key.name]; return; case SUBDEV_PROP_GAIN_RANGE: - assert_has(xcvr_tx_gain_ranges.keys(), name, "xcvr tx gain name"); - val = xcvr_tx_gain_ranges[name]; + assert_has(xcvr_tx_gain_ranges.keys(), key.name, "xcvr tx gain name"); + val = xcvr_tx_gain_ranges[key.name]; return; case SUBDEV_PROP_GAIN_NAMES: @@ -588,8 +585,7 @@ void xcvr2450::tx_get(const wax::obj &key_, wax::obj &val){ } void xcvr2450::tx_set(const wax::obj &key_, const wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -599,7 +595,7 @@ void xcvr2450::tx_set(const wax::obj &key_, const wax::obj &val){ return; case SUBDEV_PROP_GAIN: - this->set_tx_gain(val.as(), name); + this->set_tx_gain(val.as(), key.name); return; case SUBDEV_PROP_ANTENNA: diff --git a/host/lib/usrp/usrp2/codec_impl.cpp b/host/lib/usrp/usrp2/codec_impl.cpp index b9d51abf5..fc917b102 100644 --- a/host/lib/usrp/usrp2/codec_impl.cpp +++ b/host/lib/usrp/usrp2/codec_impl.cpp @@ -40,9 +40,7 @@ void usrp2_mboard_impl::codec_init(void){ /*********************************************************************** * RX Codec Properties **********************************************************************/ -void usrp2_mboard_impl::rx_codec_get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); +void usrp2_mboard_impl::rx_codec_get(const wax::obj &key, wax::obj &val){ //handle the get request conditioned on the key switch(key.as()){ @@ -69,9 +67,7 @@ void usrp2_mboard_impl::rx_codec_set(const wax::obj &, const wax::obj &){ /*********************************************************************** * TX Codec Properties **********************************************************************/ -void usrp2_mboard_impl::tx_codec_get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); +void usrp2_mboard_impl::tx_codec_get(const wax::obj &key, wax::obj &val){ //handle the get request conditioned on the key switch(key.as()){ diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index 075f22388..bafeb3f15 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -59,8 +59,7 @@ void usrp2_mboard_impl::dboard_init(void){ * RX DBoard Properties **********************************************************************/ void usrp2_mboard_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -69,7 +68,7 @@ void usrp2_mboard_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){ return; case DBOARD_PROP_SUBDEV: - val = _dboard_manager->get_rx_subdev(name); + val = _dboard_manager->get_rx_subdev(key.name); return; case DBOARD_PROP_SUBDEV_NAMES: @@ -90,7 +89,7 @@ void usrp2_mboard_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){ case DBOARD_PROP_GAIN_GROUP: val = make_gain_group( - _dboard_manager->get_rx_subdev(name), _rx_codec_proxy->get_link() + _dboard_manager->get_rx_subdev(key.name), _rx_codec_proxy->get_link() ); return; @@ -114,8 +113,7 @@ void usrp2_mboard_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){ * TX DBoard Properties **********************************************************************/ void usrp2_mboard_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -124,7 +122,7 @@ void usrp2_mboard_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){ return; case DBOARD_PROP_SUBDEV: - val = _dboard_manager->get_tx_subdev(name); + val = _dboard_manager->get_tx_subdev(key.name); return; case DBOARD_PROP_SUBDEV_NAMES: @@ -145,7 +143,7 @@ void usrp2_mboard_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){ case DBOARD_PROP_GAIN_GROUP: val = make_gain_group( - _dboard_manager->get_tx_subdev(name), _tx_codec_proxy->get_link() + _dboard_manager->get_tx_subdev(key.name), _tx_codec_proxy->get_link() ); return; diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 533b60bae..d354a943b 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -189,11 +189,10 @@ void usrp2_mboard_impl::issue_ddc_stream_cmd(const stream_cmd_t &stream_cmd){ static const std::string dboard_name = "0"; void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the other props - if (key.type() == typeid(std::string)){ + if (key_.type() == typeid(std::string)){ if (key.as() == "mac-addr"){ byte_vector_t bytes = _iface->read_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_MAC_ADDR, 6); val = mac_addr_t::from_bytes(bytes).to_string(); @@ -224,7 +223,7 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ return; case MBOARD_PROP_RX_DBOARD: - UHD_ASSERT_THROW(name == dboard_name); + UHD_ASSERT_THROW(key.name == dboard_name); val = _rx_dboard_proxy->get_link(); return; @@ -233,7 +232,7 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ return; case MBOARD_PROP_TX_DBOARD: - UHD_ASSERT_THROW(name == dboard_name); + UHD_ASSERT_THROW(key.name == dboard_name); val = _tx_dboard_proxy->get_link(); return; @@ -242,7 +241,7 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ return; case MBOARD_PROP_RX_DSP: - UHD_ASSERT_THROW(name == ""); + UHD_ASSERT_THROW(key.name == ""); val = _rx_dsp_proxy->get_link(); return; @@ -251,7 +250,7 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ return; case MBOARD_PROP_TX_DSP: - UHD_ASSERT_THROW(name == ""); + UHD_ASSERT_THROW(key.name == ""); val = _tx_dsp_proxy->get_link(); return; diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 45362c20f..568c87a22 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -201,8 +201,7 @@ usrp2_impl::~usrp2_impl(void){ * Device Properties **********************************************************************/ void usrp2_impl::get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -212,7 +211,7 @@ void usrp2_impl::get(const wax::obj &key_, wax::obj &val){ return; case DEVICE_PROP_MBOARD: - val = _mboard_dict[name]->get_link(); + val = _mboard_dict[key.name]->get_link(); return; case DEVICE_PROP_MBOARD_NAMES: diff --git a/host/lib/utils/props.cpp b/host/lib/utils/props.cpp index fac5fe24f..fc9f8e63f 100644 --- a/host/lib/utils/props.cpp +++ b/host/lib/utils/props.cpp @@ -29,15 +29,12 @@ named_prop_t::named_prop_t( /* NOP */ } -typedef boost::tuple named_prop_tuple; - -named_prop_tuple uhd::extract_named_prop( +named_prop_t named_prop_t::extract( const wax::obj &key, const std::string &name ){ if (key.type() == typeid(named_prop_t)){ - named_prop_t np = key.as(); - return named_prop_tuple(np.key, np.name); + return key.as(); } - return named_prop_tuple(key, name); + return named_prop_t(key, name); } -- cgit v1.2.3 From 7b084e3af206afa20ff5a026ebf5d7e49a755def Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 15 Aug 2010 12:18:35 -0700 Subject: uhd: use cmake to convert the pkg data dir to native system format --- host/lib/CMakeLists.txt | 3 +++ host/lib/constants.hpp.in | 3 +-- host/lib/utils/paths.cpp | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'host') diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index 48cfe742e..b117b99ce 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -53,6 +53,9 @@ INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/utils/CMakeLists.txt) ######################################################################## # Append to the list of sources for lib uhd ######################################################################## +FILE(TO_NATIVE_PATH ${CMAKE_INSTALL_PREFIX}/${PKG_DATA_DIR} FULL_PKG_DATA_DIR) +MESSAGE(STATUS "Full package data directory: ${FULL_PKG_DATA_DIR}") + CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/constants.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/constants.hpp diff --git a/host/lib/constants.hpp.in b/host/lib/constants.hpp.in index aa51e558c..2ed4e302f 100644 --- a/host/lib/constants.hpp.in +++ b/host/lib/constants.hpp.in @@ -23,7 +23,6 @@ //these should be pre-processor macros to avoid static initialization issues #define UHD_VERSION_STRING "@CPACK_PACKAGE_VERSION@" -#define UHD_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@" -#define UHD_PKG_DATA_DIR "@PKG_DATA_DIR@" +#define FULL_PKG_DATA_DIR "@FULL_PKG_DATA_DIR@" #endif /* INCLUDED_LIBUHD_CONSTANTS_HPP */ diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp index 9ac20d855..3f29945dd 100644 --- a/host/lib/utils/paths.cpp +++ b/host/lib/utils/paths.cpp @@ -72,13 +72,13 @@ static std::vector get_env_paths(const std::string &var_name){ **********************************************************************/ std::vector get_image_paths(void){ std::vector paths = get_env_paths("UHD_IMAGE_PATH"); - paths.push_back(fs::path(UHD_INSTALL_PREFIX) / UHD_PKG_DATA_DIR / "images"); + paths.push_back(fs::path(FULL_PKG_DATA_DIR) / "images"); return paths; } std::vector get_module_paths(void){ std::vector paths = get_env_paths("UHD_MODULE_PATH"); - paths.push_back(fs::path(UHD_INSTALL_PREFIX) / UHD_PKG_DATA_DIR / "modules"); + paths.push_back(fs::path(FULL_PKG_DATA_DIR) / "modules"); return paths; } -- cgit v1.2.3 From 58519b292b561cbec5eb41c85f85c8c6bd4a06fe Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 15 Aug 2010 21:34:16 -0700 Subject: usrp: moved usrp utils into public include space --- host/include/uhd/usrp/CMakeLists.txt | 2 + host/include/uhd/usrp/dsp_utils.hpp | 99 +++++++++++++++++++ host/include/uhd/usrp/misc_utils.hpp | 54 ++++++++++ host/lib/usrp/CMakeLists.txt | 3 +- host/lib/usrp/dsp_utils.cpp | 124 +++++++++++++++++++++++ host/lib/usrp/dsp_utils.hpp | 187 ----------------------------------- host/lib/usrp/misc_utils.cpp | 2 +- host/lib/usrp/misc_utils.hpp | 54 ---------- host/lib/usrp/usrp2/dboard_impl.cpp | 4 +- host/lib/usrp/usrp2/dsp_impl.cpp | 10 +- host/lib/usrp/usrp2/mboard_impl.cpp | 4 +- 11 files changed, 290 insertions(+), 253 deletions(-) create mode 100644 host/include/uhd/usrp/dsp_utils.hpp create mode 100644 host/include/uhd/usrp/misc_utils.hpp create mode 100644 host/lib/usrp/dsp_utils.cpp delete mode 100644 host/lib/usrp/dsp_utils.hpp delete mode 100644 host/lib/usrp/misc_utils.hpp (limited to 'host') diff --git a/host/include/uhd/usrp/CMakeLists.txt b/host/include/uhd/usrp/CMakeLists.txt index 76ee24e5f..130956f8a 100644 --- a/host/include/uhd/usrp/CMakeLists.txt +++ b/host/include/uhd/usrp/CMakeLists.txt @@ -33,6 +33,8 @@ INSTALL(FILES dboard_manager.hpp ### utilities ### + dsp_utils.hpp + misc_utils.hpp subdev_spec.hpp tune_helper.hpp diff --git a/host/include/uhd/usrp/dsp_utils.hpp b/host/include/uhd/usrp/dsp_utils.hpp new file mode 100644 index 000000000..8ec04dd2f --- /dev/null +++ b/host/include/uhd/usrp/dsp_utils.hpp @@ -0,0 +1,99 @@ +// +// Copyright 2010 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 . +// + +#ifndef INCLUDED_UHD_USRP_DSP_UTILS_HPP +#define INCLUDED_UHD_USRP_DSP_UTILS_HPP + +#include +#include +#include +#include + +namespace uhd{ namespace usrp{ + +namespace dsp_type1{ + + /*! + * Calculate the rx mux word from properties. + * \param subdev_conn the subdev connection type + * \return the 32-bit rx mux control word + */ + UHD_API boost::uint32_t calc_rx_mux_word(subdev_conn_t subdev_conn); + + /*! + * Calculate the tx mux word from properties. + * \param subdev_conn the subdev connection type + * \return the 32-bit tx mux control word + */ + UHD_API boost::uint32_t calc_tx_mux_word(subdev_conn_t subdev_conn); + + /*! + * Calculate the cordic word from the frequency and clock rate. + * The frequency will be set to the actual (possible) frequency. + * + * \param freq the requested frequency in Hz + * \param codec_rate the dsp codec rate in Hz + * \return the 32-bit cordic control word + */ + UHD_API boost::uint32_t calc_cordic_word_and_update( + double &freq, double codec_rate + ); + + /*! + * Calculate the CIC filter word from the rate. + * Check if requested decim/interp rate is: + * multiple of 4, enable two halfband filters + * multiple of 2, enable one halfband filter + * handle remainder in CIC + * + * \param rate the requested rate in Sps + * \return the 32-bit cic filter control word + */ + UHD_API boost::uint32_t calc_cic_filter_word(unsigned rate); + + /*! + * Calculate the IQ scale factor word from I and Q components. + * \param i the I component of the scalar + * \param q the Q component of the scalar + * \return the 32-bit scale factor control word + */ + UHD_API boost::uint32_t calc_iq_scale_word( + boost::int16_t i, boost::int16_t q + ); + + /*! + * Calculate the IQ scale factor word from the rate. + * \param rate the requested rate in Sps + * \return the 32-bit scale factor control word + */ + UHD_API boost::uint32_t calc_iq_scale_word(unsigned rate); + + /*! + * Calculate the stream command word from the stream command struct. + * \param stream_cmd the requested stream command with mode, flags, timestamp + * \param num_samps_continuous number of samples to request in continuous mode + * \return the 32-bit stream command word + */ + UHD_API boost::uint32_t calc_stream_cmd_word( + const stream_cmd_t &stream_cmd, size_t num_samps_continuous + ); + +} //namespace dsp_type1 + +}} //namespace + +#endif /* INCLUDED_UHD_USRP_DSP_UTILS_HPP */ diff --git a/host/include/uhd/usrp/misc_utils.hpp b/host/include/uhd/usrp/misc_utils.hpp new file mode 100644 index 000000000..14db80162 --- /dev/null +++ b/host/include/uhd/usrp/misc_utils.hpp @@ -0,0 +1,54 @@ +// +// Copyright 2010 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 . +// + +#ifndef INCLUDED_UHD_USRP_MISC_UTILS_HPP +#define INCLUDED_UHD_USRP_MISC_UTILS_HPP + +#include +#include +#include +#include + +namespace uhd{ namespace usrp{ + + /*! + * Create a gain group that represents the subdevice and its codec. + */ + UHD_API 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 + */ + UHD_API 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 + */ + UHD_API void verify_tx_subdev_spec(subdev_spec_t &subdev_spec, wax::obj mboard); + +}} //namespace + +#endif /* INCLUDED_UHD_USRP_MISC_UTILS_HPP */ + diff --git a/host/lib/usrp/CMakeLists.txt b/host/lib/usrp/CMakeLists.txt index d951ab412..2b408e479 100644 --- a/host/lib/usrp/CMakeLists.txt +++ b/host/lib/usrp/CMakeLists.txt @@ -22,10 +22,9 @@ LIBUHD_APPEND_SOURCES( ${CMAKE_SOURCE_DIR}/lib/usrp/dboard_eeprom.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/dboard_id.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/dboard_manager.cpp - ${CMAKE_SOURCE_DIR}/lib/usrp/dsp_utils.hpp + ${CMAKE_SOURCE_DIR}/lib/usrp/dsp_utils.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/mimo_usrp.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/misc_utils.cpp - ${CMAKE_SOURCE_DIR}/lib/usrp/misc_utils.hpp ${CMAKE_SOURCE_DIR}/lib/usrp/simple_usrp.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/subdev_spec.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/tune_helper.cpp diff --git a/host/lib/usrp/dsp_utils.cpp b/host/lib/usrp/dsp_utils.cpp new file mode 100644 index 000000000..fe1313af1 --- /dev/null +++ b/host/lib/usrp/dsp_utils.cpp @@ -0,0 +1,124 @@ +// +// Copyright 2010 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 . +// + +#include +#include +#include +#include +#include +#include +#include + +using namespace uhd; +using namespace uhd::usrp; + +template T ceil_log2(T num){ + return std::ceil(std::log(num)/std::log(T(2))); +} + +boost::uint32_t dsp_type1::calc_rx_mux_word(subdev_conn_t subdev_conn){ + switch(subdev_conn){ + case SUBDEV_CONN_COMPLEX_IQ: return (0x1 << 2) | (0x0 << 0); //DDC0Q=ADC1, DDC0I=ADC0 + case SUBDEV_CONN_COMPLEX_QI: return (0x0 << 2) | (0x1 << 0); //DDC0Q=ADC0, DDC0I=ADC1 + case SUBDEV_CONN_REAL_I: return (0x3 << 2) | (0x0 << 0); //DDC0Q=ZERO, DDC0I=ADC0 + case SUBDEV_CONN_REAL_Q: return (0x1 << 2) | (0x3 << 0); //DDC0Q=ADC1, DDC0I=ZERO + default: UHD_THROW_INVALID_CODE_PATH(); + } +} + +boost::uint32_t dsp_type1::calc_tx_mux_word(subdev_conn_t subdev_conn){ + switch(subdev_conn){ + case SUBDEV_CONN_COMPLEX_IQ: return (0x1 << 4) | (0x0 << 0); //DAC1=DUC0Q, DAC0=DUC0I + case SUBDEV_CONN_COMPLEX_QI: return (0x0 << 4) | (0x1 << 0); //DAC1=DUC0I, DAC0=DUC0Q + case SUBDEV_CONN_REAL_I: return (0xf << 4) | (0x0 << 0); //DAC1=ZERO, DAC0=DUC0I + case SUBDEV_CONN_REAL_Q: return (0x0 << 4) | (0xf << 0); //DAC1=DUC0I, DAC0=ZERO + default: UHD_THROW_INVALID_CODE_PATH(); + } +} + +boost::uint32_t dsp_type1::calc_cordic_word_and_update( + double &freq, + double codec_rate +){ + UHD_ASSERT_THROW(std::abs(freq) <= codec_rate/2.0); + static const double scale_factor = std::pow(2.0, 32); + + //calculate the freq register word (signed) + boost::int32_t freq_word = boost::int32_t(boost::math::round((freq / codec_rate) * scale_factor)); + + //update the actual frequency + freq = (double(freq_word) / scale_factor) * codec_rate; + + return boost::uint32_t(freq_word); +} + +boost::uint32_t dsp_type1::calc_cic_filter_word(unsigned rate){ + int hb0 = 0, hb1 = 0; + if (not (rate & 0x1)){ + hb0 = 1; + rate /= 2; + } + if (not (rate & 0x1)){ + hb1 = 1; + rate /= 2; + } + return (hb1 << 9) | (hb0 << 8) | (rate & 0xff); +} + +boost::uint32_t dsp_type1::calc_iq_scale_word( + boost::int16_t i, boost::int16_t q +){ + return (boost::uint32_t(i) << 16) | (boost::uint32_t(q) << 0); +} + +boost::uint32_t dsp_type1::calc_iq_scale_word(unsigned rate){ + // Calculate CIC interpolation (i.e., without halfband interpolators) + unsigned tmp_rate = calc_cic_filter_word(rate) & 0xff; + + // Calculate closest multiplier constant to reverse gain absent scale multipliers + double rate_cubed = std::pow(double(tmp_rate), 3); + boost::int16_t scale = boost::math::iround((4096*std::pow(2, ceil_log2(rate_cubed)))/(1.65*rate_cubed)); + return calc_iq_scale_word(scale, scale); +} + +boost::uint32_t dsp_type1::calc_stream_cmd_word( + const stream_cmd_t &stream_cmd, size_t num_samps_continuous +){ + UHD_ASSERT_THROW(stream_cmd.num_samps <= 0x3fffffff); + + //setup the mode to instruction flags + typedef boost::tuple inst_t; + static const uhd::dict mode_to_inst = boost::assign::map_list_of + //reload, chain, samps + (stream_cmd_t::STREAM_MODE_START_CONTINUOUS, inst_t(true, true, false)) + (stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS, inst_t(false, false, false)) + (stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE, inst_t(false, false, true)) + (stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_MORE, inst_t(false, true, true)) + ; + + //setup the instruction flag values + bool inst_reload, inst_chain, inst_samps; + boost::tie(inst_reload, inst_chain, inst_samps) = mode_to_inst[stream_cmd.stream_mode]; + + //calculate the word from flags and length + boost::uint32_t word = 0; + word |= boost::uint32_t((stream_cmd.stream_now)? 1 : 0) << 31; + word |= boost::uint32_t((inst_chain)? 1 : 0) << 30; + word |= boost::uint32_t((inst_reload)? 1 : 0) << 29; + word |= (inst_samps)? stream_cmd.num_samps : ((inst_chain)? num_samps_continuous : 1); + return word; +} diff --git a/host/lib/usrp/dsp_utils.hpp b/host/lib/usrp/dsp_utils.hpp deleted file mode 100644 index ebed12c41..000000000 --- a/host/lib/usrp/dsp_utils.hpp +++ /dev/null @@ -1,187 +0,0 @@ -// -// Copyright 2010 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 . -// - -#ifndef INCLUDED_LIBUHD_USRP_DSP_UTILS_HPP -#define INCLUDED_LIBUHD_USRP_DSP_UTILS_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace uhd{ namespace usrp{ - -namespace dsp_type1{ - - template T ceil_log2(T num){ - return std::ceil(std::log(num)/std::log(T(2))); - } - - /*! - * Calculate the rx mux word from properties. - * \param subdev_conn the subdev connection type - * \param the 32-bit rx mux control word - */ - static inline boost::uint32_t calc_rx_mux_word( - subdev_conn_t subdev_conn - ){ - switch(subdev_conn){ - case SUBDEV_CONN_COMPLEX_IQ: return (0x1 << 2) | (0x0 << 0); //DDC0Q=ADC1, DDC0I=ADC0 - case SUBDEV_CONN_COMPLEX_QI: return (0x0 << 2) | (0x1 << 0); //DDC0Q=ADC0, DDC0I=ADC1 - case SUBDEV_CONN_REAL_I: return (0x3 << 2) | (0x0 << 0); //DDC0Q=ZERO, DDC0I=ADC0 - case SUBDEV_CONN_REAL_Q: return (0x1 << 2) | (0x3 << 0); //DDC0Q=ADC1, DDC0I=ZERO - default: UHD_THROW_INVALID_CODE_PATH(); - } - } - - /*! - * Calculate the tx mux word from properties. - * \param subdev_conn the subdev connection type - * \param the 32-bit tx mux control word - */ - static inline boost::uint32_t calc_tx_mux_word( - subdev_conn_t subdev_conn - ){ - switch(subdev_conn){ - case SUBDEV_CONN_COMPLEX_IQ: return (0x1 << 4) | (0x0 << 0); //DAC1=DUC0Q, DAC0=DUC0I - case SUBDEV_CONN_COMPLEX_QI: return (0x0 << 4) | (0x1 << 0); //DAC1=DUC0I, DAC0=DUC0Q - case SUBDEV_CONN_REAL_I: return (0xf << 4) | (0x0 << 0); //DAC1=ZERO, DAC0=DUC0I - case SUBDEV_CONN_REAL_Q: return (0x0 << 4) | (0xf << 0); //DAC1=DUC0I, DAC0=ZERO - default: UHD_THROW_INVALID_CODE_PATH(); - } - } - - /*! - * Calculate the cordic word from the frequency and clock rate. - * The frequency will be set to the actual (possible) frequency. - * - * \param freq the requested frequency in Hz - * \param codec_rate the dsp codec rate in Hz - * \param the 32-bit cordic control word - */ - static inline boost::uint32_t calc_cordic_word_and_update( - double &freq, - double codec_rate - ){ - UHD_ASSERT_THROW(std::abs(freq) <= codec_rate/2.0); - static const double scale_factor = std::pow(2.0, 32); - - //calculate the freq register word (signed) - boost::int32_t freq_word = boost::int32_t(boost::math::round((freq / codec_rate) * scale_factor)); - - //update the actual frequency - freq = (double(freq_word) / scale_factor) * codec_rate; - - return boost::uint32_t(freq_word); - } - - /*! - * Calculate the CIC filter word from the rate. - * Check if requested decim/interp rate is: - * multiple of 4, enable two halfband filters - * multiple of 2, enable one halfband filter - * handle remainder in CIC - * - * \param rate the requested rate in Sps - * \return the 32-bit cic filter control word - */ - template - static inline boost::uint32_t calc_cic_filter_word(dsp_rate_type rate){ - int hb0 = 0, hb1 = 0; - if (not (rate & 0x1)){ - hb0 = 1; - rate /= 2; - } - if (not (rate & 0x1)){ - hb1 = 1; - rate /= 2; - } - return (hb1 << 9) | (hb0 << 8) | (rate & 0xff); - } - - /*! - * Calculate the IQ scale factor word from I and Q components. - * \param i the I component of the scalar - * \param q the Q component of the scalar - * \return the 32-bit scale factor control word - */ - static inline boost::uint32_t calc_iq_scale_word( - boost::int16_t i, boost::int16_t q - ){ - return (boost::uint32_t(i) << 16) | (boost::uint32_t(q) << 0); - } - - /*! - * Calculate the IQ scale factor word from the rate. - * \param rate the requested rate in Sps - * \return the 32-bit scale factor control word - */ - template - static inline boost::uint32_t calc_iq_scale_word(dsp_rate_type rate){ - // Calculate CIC interpolation (i.e., without halfband interpolators) - dsp_rate_type tmp_rate = calc_cic_filter_word(rate) & 0xff; - - // Calculate closest multiplier constant to reverse gain absent scale multipliers - double rate_cubed = std::pow(double(tmp_rate), 3); - boost::int16_t scale = boost::math::iround((4096*std::pow(2, ceil_log2(rate_cubed)))/(1.65*rate_cubed)); - return calc_iq_scale_word(scale, scale); - } - - /*! - * Calculate the stream command word from the stream command struct. - * \param stream_cmd the requested stream command with mode, flags, timestamp - * \param num_samps_continuous number of samples to request in continuous mode - * \return the 32-bit stream command word - */ - static inline boost::uint32_t calc_stream_cmd_word( - const stream_cmd_t &stream_cmd, size_t num_samps_continuous - ){ - UHD_ASSERT_THROW(stream_cmd.num_samps <= 0x3fffffff); - - //setup the mode to instruction flags - typedef boost::tuple inst_t; - static const uhd::dict mode_to_inst = boost::assign::map_list_of - //reload, chain, samps - (stream_cmd_t::STREAM_MODE_START_CONTINUOUS, inst_t(true, true, false)) - (stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS, inst_t(false, false, false)) - (stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE, inst_t(false, false, true)) - (stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_MORE, inst_t(false, true, true)) - ; - - //setup the instruction flag values - bool inst_reload, inst_chain, inst_samps; - boost::tie(inst_reload, inst_chain, inst_samps) = mode_to_inst[stream_cmd.stream_mode]; - - //calculate the word from flags and length - boost::uint32_t word = 0; - word |= boost::uint32_t((stream_cmd.stream_now)? 1 : 0) << 31; - word |= boost::uint32_t((inst_chain)? 1 : 0) << 30; - word |= boost::uint32_t((inst_reload)? 1 : 0) << 29; - word |= (inst_samps)? stream_cmd.num_samps : ((inst_chain)? num_samps_continuous : 1); - return word; - } - -} //namespace dsp_type1 - -}} //namespace - -#endif /* INCLUDED_LIBUHD_USRP_DSP_UTILS_HPP */ diff --git a/host/lib/usrp/misc_utils.cpp b/host/lib/usrp/misc_utils.cpp index 930314fc2..41239b144 100644 --- a/host/lib/usrp/misc_utils.cpp +++ b/host/lib/usrp/misc_utils.cpp @@ -15,7 +15,7 @@ // along with this program. If not, see . // -#include "misc_utils.hpp" +#include #include #include #include diff --git a/host/lib/usrp/misc_utils.hpp b/host/lib/usrp/misc_utils.hpp deleted file mode 100644 index e5d3bd849..000000000 --- a/host/lib/usrp/misc_utils.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// -// Copyright 2010 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 . -// - -#ifndef INCLUDED_LIBUHD_USRP_MISC_UTILS_HPP -#define INCLUDED_LIBUHD_USRP_MISC_UTILS_HPP - -#include -#include -#include -#include - -namespace uhd{ namespace usrp{ - - /*! - * Create a gain group that represents the subdevice and its codec. - */ - 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/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index bafeb3f15..99599f11a 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -17,8 +17,8 @@ #include "usrp2_impl.hpp" #include "usrp2_regs.hpp" -#include "../dsp_utils.hpp" -#include "../misc_utils.hpp" +#include +#include #include #include #include diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp index 7d9cdc441..347ec38af 100644 --- a/host/lib/usrp/usrp2/dsp_impl.cpp +++ b/host/lib/usrp/usrp2/dsp_impl.cpp @@ -17,9 +17,10 @@ #include "usrp2_impl.hpp" #include "usrp2_regs.hpp" -#include "../dsp_utils.hpp" +#include #include #include +#include using namespace uhd; using namespace uhd::usrp; @@ -30,10 +31,9 @@ static const size_t default_interp = 16; /*********************************************************************** * DDC Helper Methods **********************************************************************/ -template static rate_t -pick_closest_rate(double exact_rate, const std::vector &rates){ - rate_t closest_match = rates.at(0); - BOOST_FOREACH(rate_t possible_rate, rates){ +static unsigned pick_closest_rate(double exact_rate, const std::vector &rates){ + unsigned closest_match = rates.front(); + BOOST_FOREACH(unsigned possible_rate, rates){ if(std::abs(exact_rate - possible_rate) < std::abs(exact_rate - closest_match)) closest_match = possible_rate; } diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index d354a943b..e3c5d5ed6 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -17,8 +17,8 @@ #include "usrp2_impl.hpp" #include "usrp2_regs.hpp" -#include "../misc_utils.hpp" -#include "../dsp_utils.hpp" +#include +#include #include #include #include -- cgit v1.2.3 From a80a62dfe6ebfe5a814c71880b83b64a6bee0d0a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 15 Aug 2010 22:23:04 -0700 Subject: usrp: use different priority policies for gain group (rx vs tx) --- host/include/uhd/usrp/misc_utils.hpp | 16 +++++++++++++++- host/lib/usrp/misc_utils.cpp | 13 +++++++++---- host/lib/usrp/usrp2/dboard_impl.cpp | 8 ++++++-- 3 files changed, 30 insertions(+), 7 deletions(-) (limited to 'host') diff --git a/host/include/uhd/usrp/misc_utils.hpp b/host/include/uhd/usrp/misc_utils.hpp index 14db80162..2af9f5b40 100644 --- a/host/include/uhd/usrp/misc_utils.hpp +++ b/host/include/uhd/usrp/misc_utils.hpp @@ -25,10 +25,24 @@ namespace uhd{ namespace usrp{ + /*! + * Different policies for gain group prioritization. + */ + enum gain_group_policy_t{ + GAIN_GROUP_POLICY_RX = 'R', + GAIN_GROUP_POLICY_TX = 'T' + }; + /*! * Create a gain group that represents the subdevice and its codec. + * \param subdev the object with subdevice properties + * \param codec the object with codec properties + * \param gain_group_policy the policy to use */ - UHD_API gain_group::sptr make_gain_group(wax::obj subdev, wax::obj codec); + UHD_API gain_group::sptr make_gain_group( + wax::obj subdev, wax::obj codec, + gain_group_policy_t gain_group_policy + ); /*! * Verify the rx subdevice specification. diff --git a/host/lib/usrp/misc_utils.cpp b/host/lib/usrp/misc_utils.cpp index 41239b144..46094ba32 100644 --- a/host/lib/usrp/misc_utils.cpp +++ b/host/lib/usrp/misc_utils.cpp @@ -29,9 +29,6 @@ using namespace uhd; using namespace uhd::usrp; -static const size_t subdev_gain_priority = 1; //higher, closer to the antenna -static const size_t codec_gain_priority = 0; - /*********************************************************************** * codec gain group helper functions: * do this so we dont have to bind a templated function @@ -80,7 +77,15 @@ static void set_subdev_gain(wax::obj subdev, const std::string &name, float gain /*********************************************************************** * gain group factory function for usrp **********************************************************************/ -gain_group::sptr usrp::make_gain_group(wax::obj subdev, wax::obj codec){ +gain_group::sptr usrp::make_gain_group( + wax::obj subdev, wax::obj codec, + gain_group_policy_t gain_group_policy +){ + const size_t subdev_gain_priority = 1; + const size_t codec_gain_priority = (gain_group_policy == GAIN_GROUP_POLICY_RX)? + (subdev_gain_priority - 1): //RX policy, codec gains fill last (lower priority) + (subdev_gain_priority + 1); //TX policy, codec gains fill first (higher priority) + gain_group::sptr gg = gain_group::make(); gain_fcns_t fcns; //add all the subdev gains first (antenna to dsp order) diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index 99599f11a..a462b93c2 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -89,7 +89,9 @@ void usrp2_mboard_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){ case DBOARD_PROP_GAIN_GROUP: val = make_gain_group( - _dboard_manager->get_rx_subdev(key.name), _rx_codec_proxy->get_link() + _dboard_manager->get_rx_subdev(key.name), + _rx_codec_proxy->get_link(), + GAIN_GROUP_POLICY_RX ); return; @@ -143,7 +145,9 @@ void usrp2_mboard_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){ case DBOARD_PROP_GAIN_GROUP: val = make_gain_group( - _dboard_manager->get_tx_subdev(key.name), _tx_codec_proxy->get_link() + _dboard_manager->get_tx_subdev(key.name), + _tx_codec_proxy->get_link(), + GAIN_GROUP_POLICY_TX ); return; -- cgit v1.2.3 From f75869e4f7ffb53ca7f348c3a1b6d6c8fb1499b7 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 15 Aug 2010 23:21:10 -0700 Subject: usrp2: fix missing include --- host/lib/usrp/usrp2/mboard_impl.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'host') diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index e3c5d5ed6..d5785f326 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include -- cgit v1.2.3 From 1bee816db5a925b17577010542fbbc459722f481 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 11 Aug 2010 11:17:11 -0700 Subject: usrp: needed default constructor for MSVC, fixed gain group float warnings --- host/include/uhd/usrp/subdev_spec.hpp | 3 ++- host/test/gain_group_test.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'host') diff --git a/host/include/uhd/usrp/subdev_spec.hpp b/host/include/uhd/usrp/subdev_spec.hpp index 4d8f03b77..56aa0df20 100644 --- a/host/include/uhd/usrp/subdev_spec.hpp +++ b/host/include/uhd/usrp/subdev_spec.hpp @@ -40,7 +40,8 @@ namespace uhd{ namespace usrp{ * \param sd_name the name of a subdevice on that daughterboard */ subdev_spec_pair_t( - const std::string &db_name, const std::string &sd_name + const std::string &db_name = "", + const std::string &sd_name = "" ); }; diff --git a/host/test/gain_group_test.cpp b/host/test/gain_group_test.cpp index 6a6af8eb2..761372e5a 100644 --- a/host/test/gain_group_test.cpp +++ b/host/test/gain_group_test.cpp @@ -52,7 +52,7 @@ class gain_element2{ public: gain_range_t get_range(void){ - return gain_range_t(-20, 10, 0.1); + return gain_range_t(-20, 10, float(0.1)); } float get_value(void){ @@ -94,7 +94,7 @@ static gain_group::sptr get_gain_group(size_t pri1 = 0, size_t pri2 = 0){ /*********************************************************************** * Test cases **********************************************************************/ -static const double tolerance = 0.001; +static const float tolerance = float(0.001); BOOST_AUTO_TEST_CASE(test_gain_group_overall){ gain_group::sptr gg = get_gain_group(); -- cgit v1.2.3 From f29306c54536d0bbe9f76b67f4c3651888bc485e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 12 Aug 2010 03:49:37 +0000 Subject: uhd: avoid segfaults - use CPP macros for paths and dont split empty string --- host/lib/constants.hpp.in | 7 ++++--- host/lib/utils/paths.cpp | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'host') diff --git a/host/lib/constants.hpp.in b/host/lib/constants.hpp.in index 295c8f16c..aa51e558c 100644 --- a/host/lib/constants.hpp.in +++ b/host/lib/constants.hpp.in @@ -21,8 +21,9 @@ #include #include -static const std::string UHD_VERSION_STRING = "@CPACK_PACKAGE_VERSION@"; -static const std::string UHD_INSTALL_PREFIX = "@CMAKE_INSTALL_PREFIX@"; -static const std::string UHD_PKG_DATA_DIR = "@PKG_DATA_DIR@"; +//these should be pre-processor macros to avoid static initialization issues +#define UHD_VERSION_STRING "@CPACK_PACKAGE_VERSION@" +#define UHD_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@" +#define UHD_PKG_DATA_DIR "@PKG_DATA_DIR@" #endif /* INCLUDED_LIBUHD_CONSTANTS_HPP */ diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp index 0805a44fe..4029bd989 100644 --- a/host/lib/utils/paths.cpp +++ b/host/lib/utils/paths.cpp @@ -60,12 +60,14 @@ static std::vector get_env_paths(const std::string &var_name){ //split the path at the path separators std::vector path_strings; - boost::split(path_strings, var_value, boost::is_any_of(env_path_sep)); + if (not var_value.empty()) boost::split(//dont split empty strings + path_strings, var_value, boost::is_any_of(env_path_sep) + ); //convert to filesystem path, filter blank paths std::vector paths; BOOST_FOREACH(std::string &path_string, path_strings){ - if (path_string.size() == 0) continue; + if (path_string.empty()) continue; paths.push_back(fs::system_complete(path_string)); } return paths; @@ -74,17 +76,15 @@ static std::vector get_env_paths(const std::string &var_name){ /*********************************************************************** * Get a list of special purpose paths **********************************************************************/ -static const fs::path pkg_data_path = fs::path(UHD_INSTALL_PREFIX) / UHD_PKG_DATA_DIR; - std::vector get_image_paths(void){ std::vector paths = get_env_paths("UHD_IMAGE_PATH"); - paths.push_back(pkg_data_path / "images"); + paths.push_back(fs::path(UHD_INSTALL_PREFIX) / UHD_PKG_DATA_DIR / "images"); return paths; } std::vector get_module_paths(void){ std::vector paths = get_env_paths("UHD_MODULE_PATH"); - paths.push_back(pkg_data_path / "modules"); + paths.push_back(fs::path(UHD_INSTALL_PREFIX) / UHD_PKG_DATA_DIR / "modules"); return paths; } -- cgit v1.2.3 From 38b6482e254c1b048bb724653d95f5630f92e279 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 12 Aug 2010 00:47:28 -0700 Subject: uhd: created floor_step to handle floating-point errors in gain group --- host/lib/utils/gain_group.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'host') diff --git a/host/lib/utils/gain_group.cpp b/host/lib/utils/gain_group.cpp index c113719c8..078fe56b2 100644 --- a/host/lib/utils/gain_group.cpp +++ b/host/lib/utils/gain_group.cpp @@ -35,6 +35,25 @@ static bool compare_by_step_size( return fcns.at(rhs).get_range().step > fcns.at(lhs).get_range().step; } +/*! + * Get a multiple of step with the following relation: + * result = step*floor(num/step) + * + * Due to small floating-point inaccuracies: + * num = n*step + e, where e is a small inaccuracy. + * When e is negative, floor would yeild (n-1)*step, + * despite that n*step is really the desired result. + * This function is designed to mitigate that issue. + * + * \param num the number to approximate + * \param step the step size to round with + * \param e the small inaccuracy to account for + * \return a multiple of step approximating num + */ +template static T floor_step(T num, T step, T e = T(0.001)){ + return step*int(num/step + e); +} + /*********************************************************************** * gain group implementation **********************************************************************/ @@ -82,9 +101,9 @@ public: float gain_left_to_distribute = gain; BOOST_FOREACH(const gain_fcns_t &fcns, all_fcns){ const gain_range_t range = fcns.get_range(); - gain_bucket.push_back( - max_step*int(std::clip(gain_left_to_distribute, range.min, range.max)/max_step) - ); + gain_bucket.push_back(floor_step(std::clip( + gain_left_to_distribute, range.min, range.max + ), max_step)); gain_left_to_distribute -= gain_bucket.back(); } @@ -106,9 +125,9 @@ public: //fill in the largest step sizes first that are less than the remainder BOOST_FOREACH(size_t i, indexes_step_size_dec){ const gain_range_t range = all_fcns.at(i).get_range(); - float additional_gain = range.step*int( - std::clip(gain_bucket.at(i) + gain_left_to_distribute, range.min, range.max - )/range.step) - gain_bucket.at(i); + float additional_gain = floor_step(std::clip( + gain_bucket.at(i) + gain_left_to_distribute, range.min, range.max + ), range.step) - gain_bucket.at(i); gain_bucket.at(i) += additional_gain; gain_left_to_distribute -= additional_gain; } -- cgit v1.2.3 From f89f7476a1c3452511d54ec6839f574a7a37c0fe Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Tue, 10 Aug 2010 15:26:21 -0700 Subject: Brought in changes to SPI to match up with parallel branch so they share a common protocol. --- host/lib/usrp/usrp2/fw_common.h | 6 +++--- host/lib/usrp/usrp2/usrp2_iface.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'host') diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index a781c1a21..85d41d57f 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -104,12 +104,12 @@ typedef struct{ union{ __stdint(uint32_t) ip_addr; struct { - __stdint(uint8_t) dev; + __stdint(uint32_t) dev; + __stdint(uint32_t) data; __stdint(uint8_t) miso_edge; __stdint(uint8_t) mosi_edge; - __stdint(uint8_t) readback; - __stdint(uint32_t) data; __stdint(uint8_t) num_bits; + __stdint(uint8_t) readback; } spi_args; struct { __stdint(uint8_t) addr; diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 4124221ef..2d450bfc6 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -115,7 +115,7 @@ public: //setup the out data usrp2_ctrl_data_t out_data; out_data.id = htonl(USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO); - out_data.data.spi_args.dev = which_slave; + out_data.data.spi_args.dev = htonl(which_slave); out_data.data.spi_args.miso_edge = spi_edge_to_otw[config.miso_edge]; out_data.data.spi_args.mosi_edge = spi_edge_to_otw[config.mosi_edge]; out_data.data.spi_args.readback = (readback)? 1 : 0; -- cgit v1.2.3 From 230368da5c55c0eb587960db50f68e1b618f271c Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Mon, 16 Aug 2010 18:21:37 -0700 Subject: Rev firmware compatibility number to 6 --- host/lib/usrp/usrp2/fw_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'host') diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index 85d41d57f..cc6c41ba7 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -34,7 +34,7 @@ extern "C" { //fpga and firmware compatibility numbers #define USRP2_FPGA_COMPAT_NUM 1 -#define USRP2_FW_COMPAT_NUM 5 +#define USRP2_FW_COMPAT_NUM 6 //used to differentiate control packets over data port #define USRP2_INVALID_VRT_HEADER 0 -- cgit v1.2.3 From 7d110e73e6b0651f73e8e5b165244f59e66fed87 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 16 Aug 2010 23:28:37 -0700 Subject: uhd: added the concept of installer path (along with local path) for package data --- host/lib/CMakeLists.txt | 10 ++++++++-- host/lib/constants.hpp.in | 6 ++---- host/lib/utils/paths.cpp | 8 ++++++-- 3 files changed, 16 insertions(+), 8 deletions(-) (limited to 'host') diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index b117b99ce..cbb68c725 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -53,8 +53,14 @@ INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/utils/CMakeLists.txt) ######################################################################## # Append to the list of sources for lib uhd ######################################################################## -FILE(TO_NATIVE_PATH ${CMAKE_INSTALL_PREFIX}/${PKG_DATA_DIR} FULL_PKG_DATA_DIR) -MESSAGE(STATUS "Full package data directory: ${FULL_PKG_DATA_DIR}") +FILE(TO_NATIVE_PATH ${CMAKE_INSTALL_PREFIX}/${PKG_DATA_DIR} LOCAL_PKG_DATA_DIR) +MESSAGE(STATUS "Local package data directory: ${LOCAL_PKG_DATA_DIR}") + +IF(UNIX) + #on unix systems, installers will use this directory for the package data + FILE(TO_NATIVE_PATH /usr/${PKG_DATA_DIR} INSTALLER_PKG_DATA_DIR) + MESSAGE(STATUS "Installer package data directory: ${INSTALLER_PKG_DATA_DIR}") +ENDIF(UNIX) CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/constants.hpp.in diff --git a/host/lib/constants.hpp.in b/host/lib/constants.hpp.in index 2ed4e302f..4aedb6d4a 100644 --- a/host/lib/constants.hpp.in +++ b/host/lib/constants.hpp.in @@ -18,11 +18,9 @@ #ifndef INCLUDED_LIBUHD_CONSTANTS_HPP #define INCLUDED_LIBUHD_CONSTANTS_HPP -#include -#include - //these should be pre-processor macros to avoid static initialization issues #define UHD_VERSION_STRING "@CPACK_PACKAGE_VERSION@" -#define FULL_PKG_DATA_DIR "@FULL_PKG_DATA_DIR@" +#define LOCAL_PKG_DATA_DIR "@LOCAL_PKG_DATA_DIR@" +#define INSTALLER_PKG_DATA_DIR "@INSTALLER_PKG_DATA_DIR@" #endif /* INCLUDED_LIBUHD_CONSTANTS_HPP */ diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp index 3f29945dd..6ad12d3cc 100644 --- a/host/lib/utils/paths.cpp +++ b/host/lib/utils/paths.cpp @@ -72,13 +72,17 @@ static std::vector get_env_paths(const std::string &var_name){ **********************************************************************/ std::vector get_image_paths(void){ std::vector paths = get_env_paths("UHD_IMAGE_PATH"); - paths.push_back(fs::path(FULL_PKG_DATA_DIR) / "images"); + paths.push_back(fs::path(LOCAL_PKG_DATA_DIR) / "images"); + if (not std::string(INSTALLER_PKG_DATA_DIR).empty()) + paths.push_back(fs::path(INSTALLER_PKG_DATA_DIR) / "images"); return paths; } std::vector get_module_paths(void){ std::vector paths = get_env_paths("UHD_MODULE_PATH"); - paths.push_back(fs::path(FULL_PKG_DATA_DIR) / "modules"); + paths.push_back(fs::path(LOCAL_PKG_DATA_DIR) / "modules"); + if (not std::string(INSTALLER_PKG_DATA_DIR).empty()) + paths.push_back(fs::path(INSTALLER_PKG_DATA_DIR) / "modules"); return paths; } -- cgit v1.2.3 From 977651fd5710b1201b28b0cc4b6a9b0bd9871166 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 17 Aug 2010 11:05:28 -0700 Subject: uhd: add space to multiline string so quotes in the string cant disturb the multiline quotes --- host/config/Version.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'host') diff --git a/host/config/Version.cmake b/host/config/Version.cmake index a592a4565..9e4b6b306 100644 --- a/host/config/Version.cmake +++ b/host/config/Version.cmake @@ -42,7 +42,7 @@ ELSE(${GIT} STREQUAL "GIT-NOTFOUND") #extract the timestamp from the git log entry EXECUTE_PROCESS( WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - COMMAND ${PYTHON_EXECUTABLE} -c "import re; print re.match('^.*Date:\\s*(\\d*).*$', '''${_git_log}''', re.MULTILINE | re.DOTALL).groups()[0]" + COMMAND ${PYTHON_EXECUTABLE} -c "import re; print re.match('^.*Date:\\s*(\\d*).*$', ''' ${_git_log} ''', re.MULTILINE | re.DOTALL).groups()[0]" OUTPUT_VARIABLE _git_timestamp OUTPUT_STRIP_TRAILING_WHITESPACE ) -- cgit v1.2.3 From 5f27d6edb43f74abd5c8a7bb10b0931b61c6218d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 18 Aug 2010 12:24:15 -0700 Subject: uhd: windows path escape fix --- host/lib/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) (limited to 'host') diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index cbb68c725..81845de21 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -54,11 +54,13 @@ INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/utils/CMakeLists.txt) # Append to the list of sources for lib uhd ######################################################################## FILE(TO_NATIVE_PATH ${CMAKE_INSTALL_PREFIX}/${PKG_DATA_DIR} LOCAL_PKG_DATA_DIR) +STRING(REPLACE "\\" "\\\\" LOCAL_PKG_DATA_DIR ${LOCAL_PKG_DATA_DIR}) MESSAGE(STATUS "Local package data directory: ${LOCAL_PKG_DATA_DIR}") IF(UNIX) #on unix systems, installers will use this directory for the package data FILE(TO_NATIVE_PATH /usr/${PKG_DATA_DIR} INSTALLER_PKG_DATA_DIR) + STRING(REPLACE "\\" "\\\\" INSTALLER_PKG_DATA_DIR ${INSTALLER_PKG_DATA_DIR}) MESSAGE(STATUS "Installer package data directory: ${INSTALLER_PKG_DATA_DIR}") ENDIF(UNIX) -- cgit v1.2.3 From 4aa48966bff52e5fec2980d27c762b82d3ff8f1e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 18 Aug 2010 12:43:59 -0700 Subject: usrp2: template pick rate to avoid compile errors --- host/lib/usrp/usrp2/dsp_impl.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'host') diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp index 347ec38af..6422142ce 100644 --- a/host/lib/usrp/usrp2/dsp_impl.cpp +++ b/host/lib/usrp/usrp2/dsp_impl.cpp @@ -31,9 +31,10 @@ static const size_t default_interp = 16; /*********************************************************************** * DDC Helper Methods **********************************************************************/ -static unsigned pick_closest_rate(double exact_rate, const std::vector &rates){ +template +static rate_type pick_closest_rate(double exact_rate, const std::vector &rates){ unsigned closest_match = rates.front(); - BOOST_FOREACH(unsigned possible_rate, rates){ + BOOST_FOREACH(rate_type possible_rate, rates){ if(std::abs(exact_rate - possible_rate) < std::abs(exact_rate - closest_match)) closest_match = possible_rate; } -- cgit v1.2.3 From 8740197dfed997bb235b73ec649edb803d544326 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 18 Aug 2010 13:42:47 -0700 Subject: uhd: docs on building and installing images --- host/docs/CMakeLists.txt | 1 + host/docs/images.rst | 104 +++++++++++++++++++++++++++++++++++++++++++++++ host/docs/index.rst | 1 + host/docs/usrp2.rst | 36 ---------------- 4 files changed, 106 insertions(+), 36 deletions(-) create mode 100644 host/docs/images.rst (limited to 'host') diff --git a/host/docs/CMakeLists.txt b/host/docs/CMakeLists.txt index d0041f71c..b4383f88d 100644 --- a/host/docs/CMakeLists.txt +++ b/host/docs/CMakeLists.txt @@ -24,6 +24,7 @@ SET(manual_sources coding.rst dboards.rst general.rst + images.rst usrp2.rst ) diff --git a/host/docs/images.rst b/host/docs/images.rst new file mode 100644 index 000000000..ff5c5404e --- /dev/null +++ b/host/docs/images.rst @@ -0,0 +1,104 @@ +======================================================================== +UHD - Firmware and FPGA Image Application Notes +======================================================================== + +.. contents:: Table of Contents + +------------------------------------------------------------------------ +Images Overview +------------------------------------------------------------------------ +Every USRP device must be loaded with special firmware and FPGA images. +The methods of loading images into the device varies among devices: + +* **USRP1:** The host code will automatically load the firmware and FPGA at runtime. +* **USRP2:** The user must manually write the images onto the USRP2 SD card. + +------------------------------------------------------------------------ +Pre-built images +------------------------------------------------------------------------ + +Pre-built images are available for download. +See the UHD wiki for the download link. + +The pre-built images come in platform-specific installer packages +and platform-independent archive files: + +* **Linux:** DEB or RPM installer +* **Windows:** not available yet... +* **Macintosh:** not available yet... +* **Platform-independent:** ZIP or TAR.GZ archive + +^^^^^^^^^^^^^^^^^^ +Linux installers +^^^^^^^^^^^^^^^^^^ +The Linux-based installers will install the images into /usr/share/uhd/images. +On a Linux system, the UHD will always search this path for image files. + +Commands to install a linux rpm or deb package: + +:: + + sudo rpm -i .rpm + + -- OR -- + + sudo dpkg -i .deb + +^^^^^^^^^^^^^^^^^^^^^^ +Archive install +^^^^^^^^^^^^^^^^^^^^^^ +When installing images from an archive, there are two options: + +**Option 1:** + +Unpack the archive into the UHD installation prefix. +The UHD will always search /share/uhd/images for image files. +Where was set by the CMAKE_INSTALL_PREFIX at configure-time. + +**Option 2:** + +Unpack the archive anywhere and set the UHD_IMAGE_PATH environment variable. +The UHD_IMAGE_PATH may contain a list of directories to search for image files, +or paths to specific image files. + +------------------------------------------------------------------------ +Building images +------------------------------------------------------------------------ + +The UHD source repository comes with the source code necessary to build +both firmware and FPGA images for all supported devices. +The build commands for a particular image can be found in /images/Makefile. + +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Xilinx FPGA builds +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Xilinx ISE 12.x and up is required to build the Xilinx FPGA images. +The build requires that you have a unix-like environment with make. +Make sure that xtclsh from the Xilinx ISE bin directory is in your $PATH. + +See /fpga/usrp2/top/* + +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Microblaze firmware builds +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +The Microblaze GCC compiler from the Xilinx EDK is required to build the Microblaze firmware images. +The build requires that you have a unix-like environment with autotools and make. +Make sure that mb-gcc from the Xilinx EDK/microblaze directory is in your $PATH. + +See /firmware/microblaze + +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Altera FPGA builds +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Quartus is required to build the Altera FPGA images. +Pre-built images can also be found in /fpga/usrp1/rbf + +See /fpga/usrp1/toplevel/* + +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +FX2 firmware builds +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +The sdcc compiler is required to build the FX2 firmware images. +The build requires that you have a unix-like environment with autotools and make. + +See /firmware/fx2 diff --git a/host/docs/index.rst b/host/docs/index.rst index b31a3d0ac..6973ede19 100644 --- a/host/docs/index.rst +++ b/host/docs/index.rst @@ -21,6 +21,7 @@ Building the UHD Application Notes ^^^^^^^^^^^^^^^^^^^^^ * `General App Notes <./general.html>`_ +* `Firmware and FPGA Image Notes <./images.html>`_ * `USRP2 App Notes <./usrp2.html>`_ * `Daughterboard App Notes <./dboards.html>`_ diff --git a/host/docs/usrp2.rst b/host/docs/usrp2.rst index bc4ea0e44..3ac326f58 100644 --- a/host/docs/usrp2.rst +++ b/host/docs/usrp2.rst @@ -4,42 +4,6 @@ UHD - USRP2 Application Notes .. contents:: Table of Contents ------------------------------------------------------------------------- -Building firmware and FPGA images ------------------------------------------------------------------------- - -^^^^^^^^^^^^^^^^^^ -FPGA Image -^^^^^^^^^^^^^^^^^^ -Xilinx ISE 10.1 and up is required to build the FPGA image for the USRP2. -The build requires that you have a unix-like environment with make. -Make sure that xtclsh from the Xilinx ISE bin directory is in your $PATH. - -Run the following commands: -:: - - cd /fpga/usrp2/top/u2_rev3 - make -f Makefile.udp bin - -*The image file will be ./build/u2_rev3.bin* - -^^^^^^^^^^^^^^^^^^ -Firmware Image -^^^^^^^^^^^^^^^^^^ -The Microblaze GCC compiler from the Xilinx EDK is required to build the firmware. -The build requires that you have a unix-like environment with autotools and make. -Make sure that mb-gcc from the Xilinx EDK/microblaze directory is in your $PATH. - -Run the following commands: -:: - - cd /firmware/microblaze - ./boostrap - ./configure --host=mb - make - -*The image file will be ./usrp2/usrp2_txrx_uhd.bin* - ------------------------------------------------------------------------ Load the images onto the SD card ------------------------------------------------------------------------ -- cgit v1.2.3