From 8be3b883f5b1a889f4f07611e8954449cc07c2b3 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 16 Mar 2010 13:49:39 -0700 Subject: Added ability to set the subdevices in use for rx and tx dboards. This is used to calculate and set the ddc and duc muxes. Also, minor fix for burning addrs (wrong pointer....) --- firmware/microblaze/apps/txrx.c | 11 ++++- firmware/microblaze/lib/ethernet.c | 4 +- host/include/uhd/props.hpp | 7 ++- host/lib/usrp/dboard/basic.cpp | 2 +- host/lib/usrp/dboard_manager.cpp | 4 +- host/lib/usrp/usrp2/dboard_impl.cpp | 82 ++++++++++++++++++++++++++------ host/lib/usrp/usrp2/dboard_interface.cpp | 39 ++++++++++++++- host/lib/usrp/usrp2/dboard_interface.hpp | 63 ------------------------ host/lib/usrp/usrp2/fw_common.h | 7 +++ host/lib/usrp/usrp2/usrp2_impl.hpp | 12 +++++ 10 files changed, 141 insertions(+), 90 deletions(-) delete mode 100644 host/lib/usrp/usrp2/dboard_interface.hpp diff --git a/firmware/microblaze/apps/txrx.c b/firmware/microblaze/apps/txrx.c index 97376ffbd..8949f1263 100644 --- a/firmware/microblaze/apps/txrx.c +++ b/firmware/microblaze/apps/txrx.c @@ -427,7 +427,6 @@ void handle_udp_ctrl_packet( case USRP2_CTRL_ID_SETUP_THIS_DDC_FOR_ME_BRO: dsp_rx_regs->freq = ctrl_data_in->data.ddc_args.freq_word; dsp_rx_regs->scale_iq = ctrl_data_in->data.ddc_args.scale_iq; - dsp_rx_regs->rx_mux = 0x00 | (0x01 << 2); //TODO fill in from control //setup the interp and half band filters { @@ -471,7 +470,6 @@ void handle_udp_ctrl_packet( case USRP2_CTRL_ID_SETUP_THIS_DUC_FOR_ME_BRO: dsp_tx_regs->freq = ctrl_data_in->data.duc_args.freq_word; dsp_tx_regs->scale_iq = ctrl_data_in->data.duc_args.scale_iq; - dsp_tx_regs->tx_mux = 0x01; //TODO fill in from control //setup the interp and half band filters { @@ -504,6 +502,15 @@ void handle_udp_ctrl_packet( ctrl_data_out.id = USRP2_CTRL_ID_SWEET_I_GOT_THAT_TIME_DUDE; break; + /******************************************************************* + * MUX Config + ******************************************************************/ + case USRP2_CTRL_ID_UPDATE_THOSE_MUX_SETTINGS_BRO: + dsp_rx_regs->rx_mux = ctrl_data_in->data.mux_args.rx_mux; + dsp_tx_regs->tx_mux = ctrl_data_in->data.mux_args.tx_mux; + ctrl_data_out.id = USRP2_CTRL_ID_UPDATED_THE_MUX_SETTINGS_DUDE; + break; + default: ctrl_data_out.id = USRP2_CTRL_ID_HUH_WHAT; diff --git a/firmware/microblaze/lib/ethernet.c b/firmware/microblaze/lib/ethernet.c index 757a36ce4..0e731c68c 100644 --- a/firmware/microblaze/lib/ethernet.c +++ b/firmware/microblaze/lib/ethernet.c @@ -316,7 +316,7 @@ ethernet_mac_addr(void) bool ethernet_set_mac_addr(const eth_mac_addr_t *t) { - bool ok = eeprom_write(I2C_ADDR_MBOARD, MBOARD_MAC_ADDR, &t, sizeof(eth_mac_addr_t)); + bool ok = eeprom_write(I2C_ADDR_MBOARD, MBOARD_MAC_ADDR, t, sizeof(eth_mac_addr_t)); if (ok){ src_mac_addr = *t; src_mac_addr_initialized = true; @@ -356,7 +356,7 @@ const struct ip_addr *get_ip_addr(void) } bool set_ip_addr(const struct ip_addr *t){ - bool ok = eeprom_write(I2C_ADDR_MBOARD, MBOARD_IP_ADDR, &t, sizeof(struct ip_addr)); + bool ok = eeprom_write(I2C_ADDR_MBOARD, MBOARD_IP_ADDR, t, sizeof(struct ip_addr)); if (ok){ src_ip_addr = *t; src_ip_addr_initialized = true; diff --git a/host/include/uhd/props.hpp b/host/include/uhd/props.hpp index 0dddba647..6d4414d3a 100644 --- a/host/include/uhd/props.hpp +++ b/host/include/uhd/props.hpp @@ -122,7 +122,8 @@ namespace uhd{ enum dboard_prop_t{ DBOARD_PROP_NAME, //ro, std::string DBOARD_PROP_SUBDEV, //ro, wax::obj - DBOARD_PROP_SUBDEV_NAMES //ro, prop_names_t + DBOARD_PROP_SUBDEV_NAMES, //ro, prop_names_t + DBOARD_PROP_USED_SUBDEVS //ro, prop_names_t //DBOARD_PROP_CODEC //ro, wax::obj //----> not sure, dont have to deal with yet }; @@ -135,9 +136,7 @@ namespace uhd{ CODEC_PROP_NAME, //ro, std::string CODEC_PROP_OTHERS, //ro, prop_names_t CODEC_PROP_GAIN, //rw, gain_t - CODEC_PROP_GAIN_MAX, //ro, gain_t - CODEC_PROP_GAIN_MIN, //ro, gain_t - CODEC_PROP_GAIN_STEP, //ro, gain_t + CODEC_PROP_GAIN_RANGE, //ro, gain_range_t CODEC_PROP_GAIN_NAMES, //ro, prop_names_t //CODEC_PROP_CLOCK_RATE //ro, freq_t //----> not sure we care to know };*/ diff --git a/host/lib/usrp/dboard/basic.cpp b/host/lib/usrp/dboard/basic.cpp index 095b77ce1..5a82bf145 100644 --- a/host/lib/usrp/dboard/basic.cpp +++ b/host/lib/usrp/dboard/basic.cpp @@ -100,7 +100,7 @@ void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){ //handle the get request conditioned on the key switch(key.as()){ case SUBDEV_PROP_NAME: - val = std::string(str(boost::format("%s:%s") + val = std::string(str(boost::format("%s - %s") % dboard_id::to_string(get_rx_id()) % get_subdev_name() )); diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp index eeabbda99..6ca15e98c 100644 --- a/host/lib/usrp/dboard_manager.cpp +++ b/host/lib/usrp/dboard_manager.cpp @@ -46,7 +46,7 @@ void dboard_manager::register_dboard( //std::cout << "registering: " << name << std::endl; if (get_id_to_args_map().has_key(dboard_id)){ throw std::runtime_error(str(boost::format( - "The dboard id 0x%.4x is already registered to %s." + "The dboard id 0x%04x is already registered to %s." ) % dboard_id % dboard_id::to_string(dboard_id))); } get_id_to_args_map()[dboard_id] = args_t(dboard_ctor, name, subdev_names); @@ -54,7 +54,7 @@ void dboard_manager::register_dboard( std::string dboard_id::to_string(const dboard_id_t &id){ std::string name = (get_id_to_args_map().has_key(id))? get_id_to_args_map()[id].get<1>() : "unknown"; - return str(boost::format("%s (0x%.4x)") % name % id); + return str(boost::format("%s (0x%04x)") % name % id); } /*********************************************************************** diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index 6d957436e..502a7daa0 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -18,7 +18,6 @@ #include #include #include "usrp2_impl.hpp" -#include "dboard_interface.hpp" using namespace uhd; using namespace uhd::usrp; @@ -32,23 +31,16 @@ void usrp2_impl::dboard_init(void){ out_data.id = htonl(USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO); usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data); ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_THESE_ARE_MY_DBOARD_IDS_DUDE); - std::cout << boost::format("rx id 0x%.2x, tx id 0x%.2x") - % ntohs(in_data.data.dboard_ids.rx_id) - % ntohs(in_data.data.dboard_ids.tx_id) << std::endl; - //extract the dboard ids an convert them to enums - dboard_id_t rx_dboard_id = static_cast( - ntohs(in_data.data.dboard_ids.rx_id) - ); - dboard_id_t tx_dboard_id = static_cast( - ntohs(in_data.data.dboard_ids.tx_id) - ); + //extract the dboard ids an convert them + dboard_id_t rx_dboard_id = ntohs(in_data.data.dboard_ids.rx_id); + dboard_id_t tx_dboard_id = ntohs(in_data.data.dboard_ids.tx_id); //create a new dboard interface and manager dboard_interface::sptr _dboard_interface( - new usrp2_dboard_interface(this) + make_usrp2_dboard_interface(this) ); - dboard_manager::sptr _dboard_manager = dboard_manager::make( + _dboard_manager = dboard_manager::make( rx_dboard_id, tx_dboard_id, _dboard_interface ); @@ -61,6 +53,46 @@ void usrp2_impl::dboard_init(void){ boost::bind(&usrp2_impl::tx_dboard_get, this, _1, _2), boost::bind(&usrp2_impl::tx_dboard_set, this, _1, _2) ); + + //init the subdevs in use (use the first subdevice) + _rx_subdevs_in_use = prop_names_t(1, _dboard_manager->get_rx_subdev_names().at(0)); + _tx_subdevs_in_use = prop_names_t(1, _dboard_manager->get_tx_subdev_names().at(0)); + update_mux_config(); +} + +void usrp2_impl::update_mux_config(void){ + //calculate the rx mux + uint32_t rx_mux = 0; + ASSERT_THROW(_rx_subdevs_in_use.size() == 1); + wax::obj rx_subdev = _dboard_manager->get_rx_subdev(_rx_subdevs_in_use.at(0)); + std::cout << "Using: " << rx_subdev[SUBDEV_PROP_NAME].as() << std::endl; + if (rx_subdev[SUBDEV_PROP_QUADRATURE].as()){ + rx_mux = (0x01 << 2) | (0x00 << 0); //Q=ADC1, I=ADC0 + }else{ + rx_mux = 0x00; //ADC0 + } + if (rx_subdev[SUBDEV_PROP_IQ_SWAPPED].as()){ + rx_mux = (((rx_mux >> 0) & 0x3) << 2) | (((rx_mux >> 2) & 0x3) << 0); + } + + //calculate the tx mux + uint32_t tx_mux = 0x10; + ASSERT_THROW(_tx_subdevs_in_use.size() == 1); + wax::obj tx_subdev = _dboard_manager->get_tx_subdev(_tx_subdevs_in_use.at(0)); + std::cout << "Using: " << tx_subdev[SUBDEV_PROP_NAME].as() << std::endl; + if (tx_subdev[SUBDEV_PROP_IQ_SWAPPED].as()){ + tx_mux = (((tx_mux >> 0) & 0x1) << 1) | (((tx_mux >> 1) & 0x1) << 0); + } + + //setup the out data + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_UPDATE_THOSE_MUX_SETTINGS_BRO); + out_data.data.mux_args.rx_mux = htonl(rx_mux); + out_data.data.mux_args.tx_mux = htonl(tx_mux); + + //send and recv + usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data); + ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_UPDATED_THE_MUX_SETTINGS_DUDE); } /*********************************************************************** @@ -84,12 +116,22 @@ void usrp2_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){ val = _dboard_manager->get_rx_subdev_names(); return; + case DBOARD_PROP_USED_SUBDEVS: + val = _rx_subdevs_in_use; + return; + //case DBOARD_PROP_CODEC: // throw std::runtime_error("unhandled prop in usrp2 dboard"); } } -void usrp2_impl::rx_dboard_set(const wax::obj &, const wax::obj &){ +void usrp2_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){ + if (key.as() == DBOARD_PROP_USED_SUBDEVS){ + _rx_subdevs_in_use = val.as(); + update_mux_config(); //if the val is bad, this will throw + return; + } + throw std::runtime_error("Cannot set on usrp2 dboard"); } @@ -114,11 +156,21 @@ void usrp2_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){ val = _dboard_manager->get_tx_subdev_names(); return; + case DBOARD_PROP_USED_SUBDEVS: + val = _tx_subdevs_in_use; + return; + //case DBOARD_PROP_CODEC: // throw std::runtime_error("unhandled prop in usrp2 dboard"); } } -void usrp2_impl::tx_dboard_set(const wax::obj &, const wax::obj &){ +void usrp2_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val){ + if (key.as() == DBOARD_PROP_USED_SUBDEVS){ + _tx_subdevs_in_use = val.as(); + update_mux_config(); //if the val is bad, this will throw + return; + } + throw std::runtime_error("Cannot set on usrp2 dboard"); } diff --git a/host/lib/usrp/usrp2/dboard_interface.cpp b/host/lib/usrp/usrp2/dboard_interface.cpp index f12b101f3..cefd69ba9 100644 --- a/host/lib/usrp/usrp2/dboard_interface.cpp +++ b/host/lib/usrp/usrp2/dboard_interface.cpp @@ -16,11 +16,48 @@ // #include -#include "dboard_interface.hpp" #include "usrp2_impl.hpp" using namespace uhd::usrp; +class usrp2_dboard_interface : public dboard_interface{ +public: + usrp2_dboard_interface(usrp2_impl *impl); + ~usrp2_dboard_interface(void); + + void write_aux_dac(unit_type_t, int, int); + int read_aux_adc(unit_type_t, int); + + void set_atr_reg(gpio_bank_t, uint16_t, uint16_t, uint16_t); + void set_gpio_ddr(gpio_bank_t, uint16_t, uint16_t); + void write_gpio(gpio_bank_t, uint16_t, uint16_t); + uint16_t read_gpio(gpio_bank_t); + + void write_i2c(int, const byte_vector_t &); + byte_vector_t read_i2c(int, size_t); + + double get_rx_clock_rate(void); + double get_tx_clock_rate(void); + +private: + byte_vector_t transact_spi( + spi_dev_t dev, + spi_latch_t latch, + spi_push_t push, + const byte_vector_t &buf, + bool readback + ); + + usrp2_impl *_impl; +}; + +/*********************************************************************** + * Make Function + **********************************************************************/ +dboard_interface::sptr make_usrp2_dboard_interface(usrp2_impl *impl){ + return dboard_interface::sptr(new usrp2_dboard_interface(impl)); +} + /*********************************************************************** * Structors **********************************************************************/ diff --git a/host/lib/usrp/usrp2/dboard_interface.hpp b/host/lib/usrp/usrp2/dboard_interface.hpp deleted file mode 100644 index a06359e5e..000000000 --- a/host/lib/usrp/usrp2/dboard_interface.hpp +++ /dev/null @@ -1,63 +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 . -// - -#include - -#ifndef INCLUDED_DBOARD_INTERFACE_HPP -#define INCLUDED_DBOARD_INTERFACE_HPP - -class usrp2_impl; //dummy class declaration - -class usrp2_dboard_interface : public uhd::usrp::dboard_interface{ -public: - usrp2_dboard_interface(usrp2_impl *impl); - - ~usrp2_dboard_interface(void); - - void write_aux_dac(unit_type_t, int, int); - - int read_aux_adc(unit_type_t, int); - - void set_atr_reg(gpio_bank_t, uint16_t, uint16_t, uint16_t); - - void set_gpio_ddr(gpio_bank_t, uint16_t, uint16_t); - - void write_gpio(gpio_bank_t, uint16_t, uint16_t); - - uint16_t read_gpio(gpio_bank_t); - - void write_i2c(int, const byte_vector_t &); - - byte_vector_t read_i2c(int, size_t); - - double get_rx_clock_rate(void); - - double get_tx_clock_rate(void); - -private: - byte_vector_t transact_spi( - spi_dev_t dev, - spi_latch_t latch, - spi_push_t push, - const byte_vector_t &buf, - bool readback - ); - - usrp2_impl *_impl; -}; - -#endif /* INCLUDED_DBOARD_INTERFACE_HPP */ diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index 10c1ef8cf..03e8d3a37 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -94,6 +94,9 @@ typedef enum{ USRP2_CTRL_ID_GOT_A_NEW_TIME_FOR_YOU_BRO, USRP2_CTRL_ID_SWEET_I_GOT_THAT_TIME_DUDE, + USRP2_CTRL_ID_UPDATE_THOSE_MUX_SETTINGS_BRO, + USRP2_CTRL_ID_UPDATED_THE_MUX_SETTINGS_DUDE, + USRP2_CTRL_ID_PEACE_OUT } usrp2_ctrl_id_t; @@ -194,6 +197,10 @@ typedef struct{ uint32_t ticks; uint8_t now; } time_args; + struct { + uint32_t rx_mux; + uint32_t tx_mux; + } mux_args; } data; } usrp2_ctrl_data_t; diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp index fc713c2bf..2c6b6f8c9 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.hpp +++ b/host/lib/usrp/usrp2/usrp2_impl.hpp @@ -31,6 +31,15 @@ #ifndef INCLUDED_USRP2_IMPL_HPP #define INCLUDED_USRP2_IMPL_HPP +class usrp2_impl; //dummy class declaration + +/*! + * Make a usrp2 dboard interface. + * \param impl a pointer to the usrp2 impl object + * \return a sptr to a new dboard interface + */ +uhd::usrp::dboard_interface::sptr make_usrp2_dboard_interface(usrp2_impl *impl); + /*! * Simple wax obj proxy class: * Provides a wax obj interface for a set and a get function. @@ -156,11 +165,14 @@ private: void rx_dboard_get(const wax::obj &, wax::obj &); void rx_dboard_set(const wax::obj &, const wax::obj &); uhd::dict _rx_dboards; + uhd::prop_names_t _rx_subdevs_in_use; //properties interface for tx dboard void tx_dboard_get(const wax::obj &, wax::obj &); void tx_dboard_set(const wax::obj &, const wax::obj &); uhd::dict _tx_dboards; + uhd::prop_names_t _tx_subdevs_in_use; + void update_mux_config(void); //methods and shadows for the ddc dsp std::vector _allowed_decim_and_interp_rates; -- cgit v1.2.3 From 52dc73891474827a9c686f73cbfe70618a2dd6e4 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 16 Mar 2010 15:52:56 -0700 Subject: reimplemented dict to preserve order of insertion --- host/include/uhd/dict.hpp | 43 ++++++++++++++++++------------------------ host/lib/usrp/dboard/basic.cpp | 4 ++-- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/host/include/uhd/dict.hpp b/host/include/uhd/dict.hpp index 2224a0063..8f7cd5a0f 100644 --- a/host/include/uhd/dict.hpp +++ b/host/include/uhd/dict.hpp @@ -18,7 +18,7 @@ #ifndef INCLUDED_UHD_DICT_HPP #define INCLUDED_UHD_DICT_HPP -#include +#include #include #include #include @@ -27,11 +27,9 @@ namespace uhd{ /*! * A templated dictionary class with a python-like interface. - * Its wraps around a std::map internally. */ template class dict{ public: - typedef std::map map_t; typedef std::pair pair_t; /*! @@ -41,14 +39,6 @@ namespace uhd{ /* NOP */ } - /*! - * Create a dictionary from a map. - * \param map a map with key value pairs - */ - dict(const map_t &map){ - _map = map; - } - /*! * Destroy this dict. */ @@ -66,11 +56,12 @@ namespace uhd{ /*! * Get a list of the keys in this dict. + * Key order depends on insertion precedence. * \return vector of keys */ std::vector get_keys(void) const{ std::vector keys; - BOOST_FOREACH(pair_t p, _map){ + BOOST_FOREACH(const pair_t &p, _map){ keys.push_back(p.first); } return keys; @@ -78,11 +69,12 @@ namespace uhd{ /*! * Get a list of the values in this dict. + * Value order depends on insertion precedence. * \return vector of values */ std::vector get_vals(void) const{ std::vector vals; - BOOST_FOREACH(pair_t p, _map){ + BOOST_FOREACH(const pair_t &p, _map){ vals.push_back(p.second); } return vals; @@ -94,7 +86,7 @@ namespace uhd{ * \return true if found */ bool has_key(const Key &key) const{ - BOOST_FOREACH(pair_t p, _map){ + BOOST_FOREACH(const pair_t &p, _map){ if (p.first == key) return true; } return false; @@ -108,8 +100,8 @@ namespace uhd{ * \throw an exception when not found */ const Val &operator[](const Key &key) const{ - if (has_key(key)){ - return _map.find(key)->second; + BOOST_FOREACH(const pair_t &p, _map){ + if (p.first == key) return p.second; } throw std::invalid_argument("key not found in dict"); } @@ -121,7 +113,11 @@ namespace uhd{ * \return a reference to the value */ Val &operator[](const Key &key){ - return _map[key]; + BOOST_FOREACH(pair_t &p, _map){ + if (p.first == key) return p.second; + } + _map.push_back(pair_t(key, Val())); + return _map.back().second; } /*! @@ -130,17 +126,14 @@ namespace uhd{ * \return the value of the item * \throw an exception when not found */ - Val pop_key(const Key &key){ - if (has_key(key)){ - Val val = _map.find(key)->second; - _map.erase(key); - return val; - } - throw std::invalid_argument("key not found in dict"); + Val pop(const Key &key){ + Val val = (*this)[key]; + _map.remove(pair_t(key, val)); + return val; } private: - map_t _map; //private container + std::list _map; //private container }; } //namespace uhd diff --git a/host/lib/usrp/dboard/basic.cpp b/host/lib/usrp/dboard/basic.cpp index 5a82bf145..f88faf6a0 100644 --- a/host/lib/usrp/dboard/basic.cpp +++ b/host/lib/usrp/dboard/basic.cpp @@ -75,9 +75,9 @@ static dboard_base::sptr make_lf_tx(dboard_base::ctor_args_t const& args){ STATIC_BLOCK(reg_dboards){ dboard_manager::register_dboard(0x0000, &make_basic_tx, "Basic TX", list_of("")); - dboard_manager::register_dboard(0x0001, &make_basic_rx, "Basic RX", list_of("a")("b")("ab")); + dboard_manager::register_dboard(0x0001, &make_basic_rx, "Basic RX", list_of("ab")("a")("b")); dboard_manager::register_dboard(0x000e, &make_lf_tx, "LF TX", list_of("")); - dboard_manager::register_dboard(0x000f, &make_lf_rx, "LF RX", list_of("a")("b")("ab")); + dboard_manager::register_dboard(0x000f, &make_lf_rx, "LF RX", list_of("ab")("a")("b")); } /*********************************************************************** -- cgit v1.2.3 From 6458eca9540f11fb8dd5bee184e6124998023c4f Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 16 Mar 2010 17:54:54 -0700 Subject: Added recovery app to use raw socket to burn known ip addr. Fixed up fw so the device can reply after new addrs are set. --- firmware/microblaze/apps/txrx.c | 30 ++++++++++++++-------- firmware/microblaze/lib/ethernet.c | 2 +- firmware/microblaze/lib/net_common.c | 23 ++++++++--------- firmware/microblaze/lib/net_common.h | 13 ++-------- host/apps/usrp2_burner.cpp | 1 + host/apps/usrp2_recovery.py | 50 ++++++++++++++++++++++++++++++++++++ host/lib/device.cpp | 4 +-- host/lib/transport/udp_simple.cpp | 2 +- 8 files changed, 86 insertions(+), 39 deletions(-) create mode 100755 host/apps/usrp2_recovery.py diff --git a/firmware/microblaze/apps/txrx.c b/firmware/microblaze/apps/txrx.c index 8949f1263..b82c7702b 100644 --- a/firmware/microblaze/apps/txrx.c +++ b/firmware/microblaze/apps/txrx.c @@ -148,14 +148,6 @@ static struct socket_address fp_socket_src, fp_socket_dst; void start_rx_streaming_cmd(void); void stop_rx_cmd(void); -static eth_mac_addr_t get_my_eth_mac_addr(void){ - return *ethernet_mac_addr(); -} - -static struct ip_addr get_my_ip_addr(void){ - return *get_ip_addr(); -} - static void print_ip_addr(const void *t){ uint8_t *p = (uint8_t *)t; printf("%d.%d.%d.%d", p[0], p[1], p[2], p[3]); @@ -166,7 +158,7 @@ void handle_udp_data_packet( unsigned char *payload, int payload_len ){ //its a tiny payload, load the fast-path variables - fp_mac_addr_src = get_my_eth_mac_addr(); + fp_mac_addr_src = *ethernet_mac_addr(); arp_cache_lookup_mac(&src.addr, &fp_mac_addr_dst); fp_socket_src = dst; fp_socket_dst = src; @@ -540,6 +532,21 @@ eth_pkt_inspector(dbsm_t *sm, int bufno) ((buff + ((2 + 14 + 20 + 8)/sizeof(uint32_t)))[0] != 0) ) return false; + //test if its an ip recovery packet + typedef struct{ + padded_eth_hdr_t eth_hdr; + char code[4]; + union { + struct ip_addr ip_addr; + } data; + }recovery_packet_t; + recovery_packet_t *recovery_packet = (recovery_packet_t *)buff; + if (recovery_packet->eth_hdr.ethertype == 0xbeee && strncmp(recovery_packet->code, "addr", 4) == 0){ + printf("Got ip recovery packet: "); print_ip_addr(&recovery_packet->data.ip_addr); newline(); + set_ip_addr(&recovery_packet->data.ip_addr); + return true; + } + //pass it to the slow-path handler size_t len = buffer_pool_status->last_line[bufno] - 3; handle_eth_packet(buff, len); @@ -737,8 +744,9 @@ main(void) ethernet_register_link_changed_callback(link_changed_callback); ethernet_init(); - register_get_eth_mac_addr(get_my_eth_mac_addr); - register_get_ip_addr(get_my_ip_addr); + register_mac_addr(ethernet_mac_addr()); + register_ip_addr(get_ip_addr()); + register_udp_listener(USRP2_UDP_CTRL_PORT, handle_udp_ctrl_packet); register_udp_listener(USRP2_UDP_DATA_PORT, handle_udp_data_packet); diff --git a/firmware/microblaze/lib/ethernet.c b/firmware/microblaze/lib/ethernet.c index 0e731c68c..34a3ad7c1 100644 --- a/firmware/microblaze/lib/ethernet.c +++ b/firmware/microblaze/lib/ethernet.c @@ -320,7 +320,7 @@ ethernet_set_mac_addr(const eth_mac_addr_t *t) if (ok){ src_mac_addr = *t; src_mac_addr_initialized = true; - eth_mac_set_addr(t); + //eth_mac_set_addr(t); //this breaks the link } return ok; diff --git a/firmware/microblaze/lib/net_common.c b/firmware/microblaze/lib/net_common.c index 693502d18..67a3ff964 100644 --- a/firmware/microblaze/lib/net_common.c +++ b/firmware/microblaze/lib/net_common.c @@ -51,16 +51,14 @@ ip_addr_eq(const struct ip_addr a, const struct ip_addr b) // ------------------------------------------------------------------------ -get_eth_mac_addr_t _get_eth_mac_addr = NULL; - -void register_get_eth_mac_addr(get_eth_mac_addr_t get_eth_mac_addr){ - _get_eth_mac_addr = get_eth_mac_addr; +static eth_mac_addr_t _local_mac_addr; +void register_mac_addr(const eth_mac_addr_t *mac_addr){ + _local_mac_addr = *mac_addr; } -get_ip_addr_t _get_ip_addr = NULL; - -void register_get_ip_addr(get_ip_addr_t get_ip_addr){ - _get_ip_addr = get_ip_addr; +static struct ip_addr _local_ip_addr; +void register_ip_addr(const struct ip_addr *ip_addr){ + _local_ip_addr = *ip_addr; } //------------------------------------------------------------------------- @@ -140,7 +138,7 @@ send_pkt(eth_mac_addr_t dst, int ethertype, padded_eth_hdr_t ehdr; ehdr.pad = 0; ehdr.dst = dst; - ehdr.src = _get_eth_mac_addr(); + ehdr.src = _local_mac_addr; ehdr.ethertype = ethertype; uint32_t *p = buffer_ram(CPU_TX_BUF); @@ -218,7 +216,6 @@ send_ip_pkt(struct ip_addr dst, int protocol, const void *buf0, size_t len0, const void *buf1, size_t len1) { - struct ip_addr src = _get_ip_addr(); int ttl = 32; struct ip_hdr ip; @@ -228,7 +225,7 @@ send_ip_pkt(struct ip_addr dst, int protocol, IPH_OFFSET_SET(&ip, IP_DF); /* don't fragment */ ip._ttl_proto = (ttl << 8) | (protocol & 0xff); ip._chksum = 0; - ip.src = src; + ip.src = _local_ip_addr; ip.dest = dst; ip._chksum = ~chksum_buffer((unsigned short *) &ip, @@ -373,8 +370,8 @@ handle_arp_packet(struct arp_eth_ipv4 *p, size_t size) sip.addr = get_int32(p->ar_sip); tip.addr = get_int32(p->ar_tip); - if (ip_addr_eq(tip, _get_ip_addr())){ // They're looking for us... - send_arp_reply(p, _get_eth_mac_addr()); + if (ip_addr_eq(tip, _local_ip_addr)){ // They're looking for us... + send_arp_reply(p, _local_mac_addr); } } diff --git a/firmware/microblaze/lib/net_common.h b/firmware/microblaze/lib/net_common.h index 6cd45bf69..112669b46 100644 --- a/firmware/microblaze/lib/net_common.h +++ b/firmware/microblaze/lib/net_common.h @@ -33,21 +33,12 @@ extern dbsm_t *ac_could_be_sending_to_eth; void stop_streaming(void); -/*! - * Helpful typedefs for callback - */ typedef void (*udp_receiver_t)(struct socket_address src, struct socket_address dst, unsigned char *payload, int payload_len); -typedef eth_mac_addr_t (*get_eth_mac_addr_t)(void); -typedef struct ip_addr (*get_ip_addr_t)(void); - -/*! - * Functions to register callbacks - */ -void register_get_eth_mac_addr(get_eth_mac_addr_t get_eth_mac_addr); +void register_mac_addr(const eth_mac_addr_t *mac_addr); -void register_get_ip_addr(get_ip_addr_t get_ip_addr); +void register_ip_addr(const struct ip_addr *ip_addr); void register_udp_listener(int port, udp_receiver_t rcvr); diff --git a/host/apps/usrp2_burner.cpp b/host/apps/usrp2_burner.cpp index 08ec8daf9..941e71d0c 100644 --- a/host/apps/usrp2_burner.cpp +++ b/host/apps/usrp2_burner.cpp @@ -79,5 +79,6 @@ int main(int argc, char *argv[]){ std::cout << " Done" << std::endl; } + std::cout << "Power-cycle the usrp2 for the changes to take effect." << std::endl; return 0; } diff --git a/host/apps/usrp2_recovery.py b/host/apps/usrp2_recovery.py new file mode 100755 index 000000000..00d231cdb --- /dev/null +++ b/host/apps/usrp2_recovery.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python + +""" +The usrp2 recovery app: + +When the usrp2 has an unknown or bad ip address in its eeprom, +it may not be possible to communicate with the usrp2 over ip/udp. + +This app will send a raw ethernet packet to bypass the ip layer. +The packet will contain a known ip address to burn into eeprom. +Because the recovery packet is sent with a broadcast mac address, +only one usrp2 should be present on the interface upon execution. + +This app requires super-user privileges and only works on linux. +""" + +import socket +import struct +import optparse + +BCAST_MAC_ADDR = 'ff:ff:ff:ff:ff:ff' +RECOVERY_ETHERTYPE = 0xbeee +IP_RECOVERY_CODE = 'addr' + +def mac_addr_repr_to_binary_string(mac_addr): + return ''.join(map(lambda x: chr(int(x, 16)), mac_addr.split(':'))) + +if __name__ == '__main__': + parser = optparse.OptionParser() + parser.add_option('--ifc', type='string', help='ethernet interface name [default=%default]', default='eth0') + parser.add_option('--new-ip', type='string', help='ip address to set [default=%default]', default='192.168.10.2') + (options, args) = parser.parse_args() + + #create the raw socket + print "Opening raw socket on interface: ", options.ifc + soc = socket.socket(socket.PF_PACKET, socket.SOCK_RAW) + soc.bind((options.ifc, RECOVERY_ETHERTYPE)) + + #create the recovery packet + print "Loading packet with new ip address: ", options.new_ip + packet = struct.pack( + '!6s6sH4s4s', + mac_addr_repr_to_binary_string(BCAST_MAC_ADDR), + mac_addr_repr_to_binary_string(BCAST_MAC_ADDR), + RECOVERY_ETHERTYPE, + IP_RECOVERY_CODE, + socket.inet_aton(options.new_ip), + ) + soc.send(packet) + print "Done" diff --git a/host/lib/device.cpp b/host/lib/device.cpp index a87ba83eb..897084427 100644 --- a/host/lib/device.cpp +++ b/host/lib/device.cpp @@ -109,14 +109,14 @@ device::sptr device::make(const device_addr_t &hint, size_t which){ //check that we found any devices if (dev_addr_makers.size() == 0){ throw std::runtime_error(str( - boost::format("No devices found for %s") % device_addr::to_string(hint) + boost::format("No devices found for ----->\n%s") % device_addr::to_string(hint) )); } //check that the which index is valid if (dev_addr_makers.size() <= which){ throw std::runtime_error(str( - boost::format("No device at index %d for %s") % which % device_addr::to_string(hint) + boost::format("No device at index %d for ----->\n%s") % which % device_addr::to_string(hint) )); } diff --git a/host/lib/transport/udp_simple.cpp b/host/lib/transport/udp_simple.cpp index 7004bdfdf..3c8ecb70d 100644 --- a/host/lib/transport/udp_simple.cpp +++ b/host/lib/transport/udp_simple.cpp @@ -38,7 +38,7 @@ static void reasonable_recv_timeout( boost::asio::ip::udp::socket &socket ){ boost::asio::deadline_timer timer(socket.get_io_service()); - timer.expires_from_now(boost::posix_time::milliseconds(50)); + timer.expires_from_now(boost::posix_time::milliseconds(100)); while (not (socket.available() or timer.expires_from_now().is_negative())){ boost::this_thread::sleep(boost::posix_time::milliseconds(1)); } -- cgit v1.2.3 From 12ca1b612c7d82d003b5ea9683417903e4cb043f Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 16 Mar 2010 18:18:25 -0700 Subject: added more help and verbose on recovery app --- host/apps/usrp2_recovery.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/host/apps/usrp2_recovery.py b/host/apps/usrp2_recovery.py index 00d231cdb..48c1121cb 100755 --- a/host/apps/usrp2_recovery.py +++ b/host/apps/usrp2_recovery.py @@ -26,18 +26,18 @@ def mac_addr_repr_to_binary_string(mac_addr): return ''.join(map(lambda x: chr(int(x, 16)), mac_addr.split(':'))) if __name__ == '__main__': - parser = optparse.OptionParser() + parser = optparse.OptionParser(usage='usage: %prog [options]\n'+__doc__) parser.add_option('--ifc', type='string', help='ethernet interface name [default=%default]', default='eth0') parser.add_option('--new-ip', type='string', help='ip address to set [default=%default]', default='192.168.10.2') (options, args) = parser.parse_args() #create the raw socket - print "Opening raw socket on interface: ", options.ifc + print "Opening raw socket on interface:", options.ifc soc = socket.socket(socket.PF_PACKET, socket.SOCK_RAW) soc.bind((options.ifc, RECOVERY_ETHERTYPE)) #create the recovery packet - print "Loading packet with new ip address: ", options.new_ip + print "Loading packet with ip address:", options.new_ip packet = struct.pack( '!6s6sH4s4s', mac_addr_repr_to_binary_string(BCAST_MAC_ADDR), @@ -46,5 +46,7 @@ if __name__ == '__main__': IP_RECOVERY_CODE, socket.inet_aton(options.new_ip), ) + + print "Sending packet (%d bytes)"%len(packet) soc.send(packet) print "Done" -- cgit v1.2.3 From 83c463d09613b72817a837117c5f0b23975c8def Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 16 Mar 2010 19:42:38 -0700 Subject: changes to get tuning working --- host/lib/simple_device.cpp | 12 ++++++++++-- host/lib/usrp/dboard/basic.cpp | 8 ++++++-- host/lib/usrp/usrp2/io_impl.cpp | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/host/lib/simple_device.cpp b/host/lib/simple_device.cpp index 62a38cb79..79b035071 100644 --- a/host/lib/simple_device.cpp +++ b/host/lib/simple_device.cpp @@ -133,8 +133,16 @@ public: _mboard = (*_dev)[DEVICE_PROP_MBOARD]; _rx_ddc = _mboard[named_prop_t(MBOARD_PROP_RX_DSP, "ddc0")]; _tx_duc = _mboard[named_prop_t(MBOARD_PROP_TX_DSP, "duc0")]; - _rx_subdev = _mboard[MBOARD_PROP_RX_DBOARD][DBOARD_PROP_SUBDEV]; - _tx_subdev = _mboard[MBOARD_PROP_TX_DBOARD][DBOARD_PROP_SUBDEV]; + + //extract rx subdevice + wax::obj rx_dboard = _mboard[MBOARD_PROP_RX_DBOARD]; + std::string rx_subdev_in_use = rx_dboard[DBOARD_PROP_USED_SUBDEVS].as().at(0); + _rx_subdev = rx_dboard[named_prop_t(DBOARD_PROP_SUBDEV, rx_subdev_in_use)]; + + //extract tx subdevice + wax::obj tx_dboard = _mboard[MBOARD_PROP_TX_DBOARD]; + std::string tx_subdev_in_use = tx_dboard[DBOARD_PROP_USED_SUBDEVS].as().at(0); + _tx_subdev = tx_dboard[named_prop_t(DBOARD_PROP_SUBDEV, tx_subdev_in_use)]; } ~simple_device_impl(void){ diff --git a/host/lib/usrp/dboard/basic.cpp b/host/lib/usrp/dboard/basic.cpp index f88faf6a0..02b391244 100644 --- a/host/lib/usrp/dboard/basic.cpp +++ b/host/lib/usrp/dboard/basic.cpp @@ -172,11 +172,13 @@ void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){ case SUBDEV_PROP_ENABLED: return; // it wont do you much good, but you can set it + case SUBDEV_PROP_FREQ: + return; // it wont do you much good, but you can set it + case SUBDEV_PROP_NAME: case SUBDEV_PROP_OTHERS: case SUBDEV_PROP_GAIN_RANGE: case SUBDEV_PROP_GAIN_NAMES: - case SUBDEV_PROP_FREQ: case SUBDEV_PROP_FREQ_RANGE: case SUBDEV_PROP_ANTENNA_NAMES: case SUBDEV_PROP_QUADRATURE: @@ -278,11 +280,13 @@ void basic_tx::tx_set(const wax::obj &key_, const wax::obj &val){ case SUBDEV_PROP_ENABLED: return; // it wont do you much good, but you can set it + case SUBDEV_PROP_FREQ: + return; // it wont do you much good, but you can set it + case SUBDEV_PROP_NAME: case SUBDEV_PROP_OTHERS: case SUBDEV_PROP_GAIN_RANGE: case SUBDEV_PROP_GAIN_NAMES: - case SUBDEV_PROP_FREQ: case SUBDEV_PROP_FREQ_RANGE: case SUBDEV_PROP_ANTENNA_NAMES: case SUBDEV_PROP_QUADRATURE: diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp index cc7746720..e52c1e576 100644 --- a/host/lib/usrp/usrp2/io_impl.cpp +++ b/host/lib/usrp/usrp2/io_impl.cpp @@ -149,7 +149,7 @@ void usrp2_impl::recv_raw(rx_metadata_t &metadata){ //handle the packet count / sequence number size_t expected_packet_count = _rx_stream_id_to_packet_seq[metadata.stream_id]; if (packet_count_out != expected_packet_count){ - std::cerr << "bad packet count: " << packet_count_out << std::endl; + std::cerr << "S" << (packet_count_out - expected_packet_count)%16; } _rx_stream_id_to_packet_seq[metadata.stream_id] = (packet_count_out+1)%16; -- cgit v1.2.3 From 69aaffa6d8d4614dbf6b751fe058e39fced68153 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 17 Mar 2010 17:55:20 -0800 Subject: got uhd almost compiling in windowze. figured out special flags. also had to use boost stdint because its missing in visual c++, added a bunch of numeric casts to reduce warnings --- host/CMakeLists.txt | 19 ++++-- host/include/uhd/device_addr.hpp | 5 +- host/include/uhd/metadata.hpp | 8 +-- host/include/uhd/time_spec.hpp | 8 +-- host/include/uhd/transport/vrt.hpp | 14 ++-- host/include/uhd/usrp/dboard_id.hpp | 4 +- host/include/uhd/usrp/dboard_interface.hpp | 12 ++-- host/lib/CMakeLists.txt | 5 +- host/lib/device.cpp | 2 +- host/lib/device_addr.cpp | 6 +- host/lib/time_spec.cpp | 8 +-- host/lib/transport/udp_zero_copy_none.cpp | 10 +-- host/lib/transport/vrt.cpp | 21 +++--- host/lib/usrp/usrp2/dboard_impl.cpp | 4 +- host/lib/usrp/usrp2/dboard_interface.cpp | 28 ++++---- host/lib/usrp/usrp2/dsp_impl.cpp | 23 ++++--- host/lib/usrp/usrp2/fw_common.h | 100 +++++++++++++++-------------- host/lib/usrp/usrp2/io_impl.cpp | 65 ++++++++++--------- host/lib/usrp/usrp2/usrp2_impl.hpp | 10 +-- host/test/vrt_test.cpp | 2 +- host/test/wax_test.cpp | 2 +- 21 files changed, 191 insertions(+), 165 deletions(-) diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 30f4789a3..3576a690f 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -53,10 +53,18 @@ FUNCTION(UHD_ADD_OPTIONAL_CXX_COMPILER_FLAG flag have) ENDIF(${have}) ENDFUNCTION(UHD_ADD_OPTIONAL_CXX_COMPILER_FLAG) -UHD_ADD_OPTIONAL_CXX_COMPILER_FLAG(-Wall HAVE_WALL) -UHD_ADD_OPTIONAL_CXX_COMPILER_FLAG(-Wextra HAVE_WEXTRA) -UHD_ADD_OPTIONAL_CXX_COMPILER_FLAG(-pedantic HAVE_PEDANTIC) -UHD_ADD_OPTIONAL_CXX_COMPILER_FLAG(-ansi HAVE_ANSI) +IF(UNIX) + UHD_ADD_OPTIONAL_CXX_COMPILER_FLAG(-Wall HAVE_WALL) + UHD_ADD_OPTIONAL_CXX_COMPILER_FLAG(-Wextra HAVE_WEXTRA) + UHD_ADD_OPTIONAL_CXX_COMPILER_FLAG(-pedantic HAVE_PEDANTIC) + UHD_ADD_OPTIONAL_CXX_COMPILER_FLAG(-ansi HAVE_ANSI) +ENDIF(UNIX) + +IF(WIN32) + ADD_DEFINITIONS(-Dnot=! -Dand=&& -Dor=||) #logical operators + ADD_DEFINITIONS(-D_WIN32_WINNT=0x0501) #as requested by vs + ADD_DEFINITIONS(-DNOMINMAX) #disables stupidity and enables std::min and std::max +ENDIF(WIN32) ######################################################################## # Setup Boost @@ -64,6 +72,7 @@ UHD_ADD_OPTIONAL_CXX_COMPILER_FLAG(-ansi HAVE_ANSI) FIND_PACKAGE(Boost 1.36 REQUIRED date_time program_options + regex system thread unit_test_framework @@ -78,7 +87,7 @@ LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) INCLUDE(TestBigEndian) TEST_BIG_ENDIAN(HAVE_BIG_ENDIAN) IF(HAVE_BIG_ENDIAN) - ADD_DEFINITIONS("-DHAVE_BIG_ENDIAN=/* */") + ADD_DEFINITIONS(-DHAVE_BIG_ENDIAN) ENDIF(HAVE_BIG_ENDIAN) ######################################################################## diff --git a/host/include/uhd/device_addr.hpp b/host/include/uhd/device_addr.hpp index ed538453a..1b624b770 100644 --- a/host/include/uhd/device_addr.hpp +++ b/host/include/uhd/device_addr.hpp @@ -19,10 +19,9 @@ #define INCLUDED_UHD_DEVICE_ADDR_HPP #include +#include #include #include -#include -#include #include namespace uhd{ @@ -32,7 +31,7 @@ namespace uhd{ * Provides conversion between string and binary formats. */ struct mac_addr_t{ - struct ether_addr mac_addr; + boost::uint8_t mac_addr[6]; mac_addr_t(const std::string &mac_addr_str = "00:00:00:00:00:00"); std::string to_string(void) const; }; diff --git a/host/include/uhd/metadata.hpp b/host/include/uhd/metadata.hpp index 0588ef0ed..ce72ff14b 100644 --- a/host/include/uhd/metadata.hpp +++ b/host/include/uhd/metadata.hpp @@ -28,9 +28,9 @@ namespace uhd{ * The receive routines will convert IF data headers into metadata. */ struct rx_metadata_t{ - uint32_t stream_id; - bool has_stream_id; + boost::uint32_t stream_id; time_spec_t time_spec; + bool has_stream_id; bool has_time_spec; bool is_fragment; @@ -44,9 +44,9 @@ struct rx_metadata_t{ * The send routines will convert the metadata to IF data headers. */ struct tx_metadata_t{ - uint32_t stream_id; - bool has_stream_id; + boost::uint32_t stream_id; time_spec_t time_spec; + bool has_stream_id; bool has_time_spec; bool start_of_burst; bool end_of_burst; diff --git a/host/include/uhd/time_spec.hpp b/host/include/uhd/time_spec.hpp index 7e182236b..588758824 100644 --- a/host/include/uhd/time_spec.hpp +++ b/host/include/uhd/time_spec.hpp @@ -16,7 +16,7 @@ // #include -#include +#include #ifndef INCLUDED_UHD_TIME_SPEC_HPP #define INCLUDED_UHD_TIME_SPEC_HPP @@ -30,8 +30,8 @@ namespace uhd{ * and for controlling the start of streaming for applicable dsps. */ struct time_spec_t{ - uint32_t secs; - uint32_t ticks; + boost::uint32_t secs; + boost::uint32_t ticks; /*! * Create a time_spec_t that holds a wildcard time. @@ -44,7 +44,7 @@ namespace uhd{ * \param new_secs the new seconds * \param new_ticks the new ticks (default = 0) */ - time_spec_t(uint32_t new_secs, uint32_t new_ticks = 0); + time_spec_t(boost::uint32_t new_secs, boost::uint32_t new_ticks = 0); /*! * Create a time_spec_t from boost posix time. diff --git a/host/include/uhd/transport/vrt.hpp b/host/include/uhd/transport/vrt.hpp index 1700d2785..3b5bf41bf 100644 --- a/host/include/uhd/transport/vrt.hpp +++ b/host/include/uhd/transport/vrt.hpp @@ -38,7 +38,7 @@ namespace vrt{ */ void pack( const tx_metadata_t &metadata, //input - uint32_t *header_buff, //output + boost::uint32_t *header_buff, //output size_t &num_header_words32, //output size_t num_payload_words32, //input size_t &num_packet_words32, //output @@ -55,12 +55,12 @@ namespace vrt{ * \param packet_count the packet count sequence number */ void unpack( - rx_metadata_t &metadata, //output - const uint32_t *header_buff, //input - size_t &num_header_words32, //output - size_t &num_payload_words32, //output - size_t num_packet_words32, //input - size_t &packet_count //output + rx_metadata_t &metadata, //output + const boost::uint32_t *header_buff, //input + size_t &num_header_words32, //output + size_t &num_payload_words32, //output + size_t num_packet_words32, //input + size_t &packet_count //output ); } //namespace vrt diff --git a/host/include/uhd/usrp/dboard_id.hpp b/host/include/uhd/usrp/dboard_id.hpp index 34406863d..62c61661c 100644 --- a/host/include/uhd/usrp/dboard_id.hpp +++ b/host/include/uhd/usrp/dboard_id.hpp @@ -15,15 +15,15 @@ // along with this program. If not, see . // +#include #include -#include #ifndef INCLUDED_UHD_USRP_DBOARD_ID_HPP #define INCLUDED_UHD_USRP_DBOARD_ID_HPP namespace uhd{ namespace usrp{ -typedef uint16_t dboard_id_t; +typedef boost::uint16_t dboard_id_t; static const dboard_id_t ID_NONE = 0xffff; diff --git a/host/include/uhd/usrp/dboard_interface.hpp b/host/include/uhd/usrp/dboard_interface.hpp index 84e1f5b22..b00643550 100644 --- a/host/include/uhd/usrp/dboard_interface.hpp +++ b/host/include/uhd/usrp/dboard_interface.hpp @@ -19,8 +19,8 @@ #define INCLUDED_UHD_USRP_DBOARD_INTERFACE_HPP #include +#include #include -#include namespace uhd{ namespace usrp{ @@ -33,7 +33,7 @@ namespace uhd{ namespace usrp{ class dboard_interface{ public: typedef boost::shared_ptr sptr; - typedef std::vector byte_vector_t; + typedef std::vector byte_vector_t; //tells the host which unit to use enum unit_type_t{ @@ -96,7 +96,7 @@ public: * \param rx_value 16-bits, 0=FPGA output low, 1=FPGA output high * \param mask 16-bits, 0=software, 1=atr */ - virtual void set_atr_reg(gpio_bank_t bank, uint16_t tx_value, uint16_t rx_value, uint16_t mask) = 0; + virtual void set_atr_reg(gpio_bank_t bank, boost::uint16_t tx_value, boost::uint16_t rx_value, boost::uint16_t mask) = 0; /*! * Set daughterboard GPIO data direction register. @@ -105,7 +105,7 @@ public: * \param value 16-bits, 0=FPGA input, 1=FPGA output * \param mask 16-bits, 0=ignore, 1=set */ - virtual void set_gpio_ddr(gpio_bank_t bank, uint16_t value, uint16_t mask) = 0; + virtual void set_gpio_ddr(gpio_bank_t bank, boost::uint16_t value, boost::uint16_t mask) = 0; /*! * Set daughterboard GPIO pin values. @@ -114,7 +114,7 @@ public: * \param value 16 bits, 0=low, 1=high * \param mask 16 bits, 0=ignore, 1=set */ - virtual void write_gpio(gpio_bank_t bank, uint16_t value, uint16_t mask) = 0; + virtual void write_gpio(gpio_bank_t bank, boost::uint16_t value, boost::uint16_t mask) = 0; /*! * Read daughterboard GPIO pin values @@ -122,7 +122,7 @@ public: * \param bank GPIO_TX_BANK or GPIO_RX_BANK * \return the value of the gpio bank */ - virtual uint16_t read_gpio(gpio_bank_t bank) = 0; + virtual boost::uint16_t read_gpio(gpio_bank_t bank) = 0; /*! * \brief Write to I2C peripheral diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index 1d2c5471b..46e1b0947 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -61,4 +61,7 @@ ADD_LIBRARY(uhd SHARED ${libuhd_sources}) TARGET_LINK_LIBRARIES(uhd ${Boost_LIBRARIES}) -INSTALL(TARGETS uhd LIBRARY DESTINATION ${LIBRARY_DIR}) +INSTALL(TARGETS uhd + LIBRARY DESTINATION ${LIBRARY_DIR} + ARCHIVE DESTINATION ${LIBRARY_DIR} +) diff --git a/host/lib/device.cpp b/host/lib/device.cpp index 897084427..cd8a01ab4 100644 --- a/host/lib/device.cpp +++ b/host/lib/device.cpp @@ -136,7 +136,7 @@ device::sptr device::make(const device_addr_t &hint, size_t which){ return hash_to_device[dev_hash].lock(); } //create and register a new device - catch(const std::assert_error &e){ + catch(const std::assert_error &){ device::sptr dev = maker(dev_addr); hash_to_device[dev_hash] = dev; return dev; diff --git a/host/lib/device_addr.cpp b/host/lib/device_addr.cpp index 9514df981..d26bb4b9d 100644 --- a/host/lib/device_addr.cpp +++ b/host/lib/device_addr.cpp @@ -28,7 +28,7 @@ uhd::mac_addr_t::mac_addr_t(const std::string &mac_addr_str_){ std::string mac_addr_str = (mac_addr_str_ == "")? "ff:ff:ff:ff:ff:ff" : mac_addr_str_; //ether_aton_r(str.c_str(), &mac_addr); - uint8_t p[6] = {0x00, 0x50, 0xC2, 0x85, 0x30, 0x00}; // Matt's IAB + boost::uint8_t p[6] = {0x00, 0x50, 0xC2, 0x85, 0x30, 0x00}; // Matt's IAB try{ //only allow patterns of xx:xx or xx:xx:xx:xx:xx:xx @@ -43,7 +43,7 @@ uhd::mac_addr_t::mac_addr_t(const std::string &mac_addr_str_){ int hex_num; std::istringstream iss(hex_strs[i]); iss >> std::hex >> hex_num; - p[i] = uint8_t(hex_num); + p[i] = boost::uint8_t(hex_num); } } @@ -58,7 +58,7 @@ uhd::mac_addr_t::mac_addr_t(const std::string &mac_addr_str_){ std::string uhd::mac_addr_t::to_string(void) const{ //ether_ntoa_r(&mac_addr, addr_buf); - const uint8_t *p = reinterpret_cast(&mac_addr); + const boost::uint8_t *p = reinterpret_cast(&mac_addr); return str( boost::format("%02x:%02x:%02x:%02x:%02x:%02x") % int(p[0]) % int(p[1]) % int(p[2]) diff --git a/host/lib/time_spec.cpp b/host/lib/time_spec.cpp index 193441342..210010394 100644 --- a/host/lib/time_spec.cpp +++ b/host/lib/time_spec.cpp @@ -24,17 +24,17 @@ time_spec_t::time_spec_t(void){ ticks = ~0; } -time_spec_t::time_spec_t(uint32_t new_secs, uint32_t new_ticks){ +time_spec_t::time_spec_t(boost::uint32_t new_secs, boost::uint32_t new_ticks){ secs = new_secs; ticks = new_ticks; } static const boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1)); -static double time_tick_rate(boost::posix_time::time_duration::ticks_per_second()); +static double time_tick_rate = double(boost::posix_time::time_duration::ticks_per_second()); time_spec_t::time_spec_t(boost::posix_time::ptime time, double tick_rate){ boost::posix_time::time_duration td = time - epoch; - secs = td.total_seconds(); + secs = boost::uint32_t(td.total_seconds()); double time_ticks_per_device_ticks = time_tick_rate/tick_rate; - ticks = td.fractional_seconds()/time_ticks_per_device_ticks; + ticks = boost::uint32_t(td.fractional_seconds()/time_ticks_per_device_ticks); } diff --git a/host/lib/transport/udp_zero_copy_none.cpp b/host/lib/transport/udp_zero_copy_none.cpp index e29530cf1..219ae8720 100644 --- a/host/lib/transport/udp_zero_copy_none.cpp +++ b/host/lib/transport/udp_zero_copy_none.cpp @@ -16,8 +16,10 @@ // #include +#include #include #include +#include using namespace uhd::transport; @@ -36,7 +38,7 @@ public: } ~smart_buffer_impl(void){ - delete [] boost::asio::buffer_cast(_buff); + delete [] boost::asio::buffer_cast(_buff); } const boost::asio::const_buffer &get(void) const{ @@ -89,12 +91,12 @@ udp_zero_copy_impl::udp_zero_copy_impl(const std::string &addr, const std::strin // set the rx socket buffer size: // pick a huge size, and deal with whatever we get - set_recv_buff_size(54321e3); //some big number! + set_recv_buff_size(size_t(54321e3)); //some big number! size_t current_buff_size = get_recv_buff_size(); std::cout << boost::format( "Current rx socket buffer size: %d\n" ) % current_buff_size; - if (current_buff_size < .1e6) std::cout << boost::format( + if (current_buff_size < size_t(.1e6)) std::cout << boost::format( "Adjust max rx socket buffer size (linux only):\n" " sysctl -w net.core.rmem_max=VALUE\n" ); @@ -119,7 +121,7 @@ smart_buffer::sptr udp_zero_copy_impl::recv(void){ } //allocate memory and create buffer - uint32_t *buff_mem = new uint32_t[available/sizeof(uint32_t)]; + boost::uint32_t *buff_mem = new boost::uint32_t[available/sizeof(boost::uint32_t)]; boost::asio::mutable_buffer buff(buff_mem, available); //receive only if data is available diff --git a/host/lib/transport/vrt.cpp b/host/lib/transport/vrt.cpp index 5029df217..a06b5bf21 100644 --- a/host/lib/transport/vrt.cpp +++ b/host/lib/transport/vrt.cpp @@ -16,20 +16,21 @@ // #include -#include +#include //endianness conversion #include +using namespace uhd; using namespace uhd::transport; void vrt::pack( const tx_metadata_t &metadata, //input - uint32_t *header_buff, //output + boost::uint32_t *header_buff, //output size_t &num_header_words32, //output size_t num_payload_words32, //input size_t &num_packet_words32, //output size_t packet_count //input ){ - uint32_t vrt_hdr_flags = 0; + boost::uint32_t vrt_hdr_flags = 0; num_header_words32 = 1; //load the vrt header and flags @@ -58,18 +59,18 @@ void vrt::pack( } void vrt::unpack( - rx_metadata_t &metadata, //output - const uint32_t *header_buff, //input - size_t &num_header_words32, //output - size_t &num_payload_words32, //output - size_t num_packet_words32, //input - size_t &packet_count //output + rx_metadata_t &metadata, //output + const boost::uint32_t *header_buff, //input + size_t &num_header_words32, //output + size_t &num_payload_words32, //output + size_t num_packet_words32, //input + size_t &packet_count //output ){ //clear the metadata metadata = rx_metadata_t(); //extract vrt header - uint32_t vrt_hdr_word = ntohl(header_buff[0]); + boost::uint32_t vrt_hdr_word = ntohl(header_buff[0]); size_t packet_words32 = vrt_hdr_word & 0xffff; packet_count = (vrt_hdr_word >> 16) & 0xf; diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index 502a7daa0..60622ca47 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -62,7 +62,7 @@ void usrp2_impl::dboard_init(void){ void usrp2_impl::update_mux_config(void){ //calculate the rx mux - uint32_t rx_mux = 0; + boost::uint32_t rx_mux = 0; ASSERT_THROW(_rx_subdevs_in_use.size() == 1); wax::obj rx_subdev = _dboard_manager->get_rx_subdev(_rx_subdevs_in_use.at(0)); std::cout << "Using: " << rx_subdev[SUBDEV_PROP_NAME].as() << std::endl; @@ -76,7 +76,7 @@ void usrp2_impl::update_mux_config(void){ } //calculate the tx mux - uint32_t tx_mux = 0x10; + boost::uint32_t tx_mux = 0x10; ASSERT_THROW(_tx_subdevs_in_use.size() == 1); wax::obj tx_subdev = _dboard_manager->get_tx_subdev(_tx_subdevs_in_use.at(0)); std::cout << "Using: " << tx_subdev[SUBDEV_PROP_NAME].as() << std::endl; diff --git a/host/lib/usrp/usrp2/dboard_interface.cpp b/host/lib/usrp/usrp2/dboard_interface.cpp index cefd69ba9..d20465147 100644 --- a/host/lib/usrp/usrp2/dboard_interface.cpp +++ b/host/lib/usrp/usrp2/dboard_interface.cpp @@ -28,10 +28,10 @@ public: void write_aux_dac(unit_type_t, int, int); int read_aux_adc(unit_type_t, int); - void set_atr_reg(gpio_bank_t, uint16_t, uint16_t, uint16_t); - void set_gpio_ddr(gpio_bank_t, uint16_t, uint16_t); - void write_gpio(gpio_bank_t, uint16_t, uint16_t); - uint16_t read_gpio(gpio_bank_t); + void set_atr_reg(gpio_bank_t, boost::uint16_t, boost::uint16_t, boost::uint16_t); + void set_gpio_ddr(gpio_bank_t, boost::uint16_t, boost::uint16_t); + void write_gpio(gpio_bank_t, boost::uint16_t, boost::uint16_t); + boost::uint16_t read_gpio(gpio_bank_t); void write_i2c(int, const byte_vector_t &); byte_vector_t read_i2c(int, size_t); @@ -89,7 +89,7 @@ double usrp2_dboard_interface::get_tx_clock_rate(void){ * \param bank the dboard interface gpio bank enum * \return an over the wire representation */ -static uint8_t gpio_bank_to_otw(dboard_interface::gpio_bank_t bank){ +static boost::uint8_t gpio_bank_to_otw(dboard_interface::gpio_bank_t bank){ switch(bank){ case uhd::usrp::dboard_interface::GPIO_TX_BANK: return USRP2_DIR_TX; case uhd::usrp::dboard_interface::GPIO_RX_BANK: return USRP2_DIR_RX; @@ -97,7 +97,7 @@ static uint8_t gpio_bank_to_otw(dboard_interface::gpio_bank_t bank){ throw std::invalid_argument("unknown gpio bank type"); } -void usrp2_dboard_interface::set_gpio_ddr(gpio_bank_t bank, uint16_t value, uint16_t mask){ +void usrp2_dboard_interface::set_gpio_ddr(gpio_bank_t bank, boost::uint16_t value, boost::uint16_t mask){ //setup the out data usrp2_ctrl_data_t out_data; out_data.id = htonl(USRP2_CTRL_ID_USE_THESE_GPIO_DDR_SETTINGS_BRO); @@ -110,7 +110,7 @@ void usrp2_dboard_interface::set_gpio_ddr(gpio_bank_t bank, uint16_t value, uint ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_GOT_THE_GPIO_DDR_SETTINGS_DUDE); } -void usrp2_dboard_interface::write_gpio(gpio_bank_t bank, uint16_t value, uint16_t mask){ +void usrp2_dboard_interface::write_gpio(gpio_bank_t bank, boost::uint16_t value, boost::uint16_t mask){ //setup the out data usrp2_ctrl_data_t out_data; out_data.id = htonl(USRP2_CTRL_ID_SET_YOUR_GPIO_PIN_OUTS_BRO); @@ -123,7 +123,7 @@ void usrp2_dboard_interface::write_gpio(gpio_bank_t bank, uint16_t value, uint16 ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_I_SET_THE_GPIO_PIN_OUTS_DUDE); } -uint16_t usrp2_dboard_interface::read_gpio(gpio_bank_t bank){ +boost::uint16_t usrp2_dboard_interface::read_gpio(gpio_bank_t bank){ //setup the out data usrp2_ctrl_data_t out_data; out_data.id = htonl(USRP2_CTRL_ID_GIVE_ME_YOUR_GPIO_PIN_VALS_BRO); @@ -135,7 +135,7 @@ uint16_t usrp2_dboard_interface::read_gpio(gpio_bank_t bank){ return ntohs(in_data.data.gpio_config.value); } -void usrp2_dboard_interface::set_atr_reg(gpio_bank_t bank, uint16_t tx_value, uint16_t rx_value, uint16_t mask){ +void usrp2_dboard_interface::set_atr_reg(gpio_bank_t bank, boost::uint16_t tx_value, boost::uint16_t rx_value, boost::uint16_t mask){ //setup the out data usrp2_ctrl_data_t out_data; out_data.id = htonl(USRP2_CTRL_ID_USE_THESE_ATR_SETTINGS_BRO); @@ -158,7 +158,7 @@ void usrp2_dboard_interface::set_atr_reg(gpio_bank_t bank, uint16_t tx_value, ui * \param dev the dboard interface spi dev enum * \return an over the wire representation */ -static uint8_t spi_dev_to_otw(dboard_interface::spi_dev_t dev){ +static boost::uint8_t spi_dev_to_otw(dboard_interface::spi_dev_t dev){ switch(dev){ case uhd::usrp::dboard_interface::SPI_TX_DEV: return USRP2_DIR_TX; case uhd::usrp::dboard_interface::SPI_RX_DEV: return USRP2_DIR_RX; @@ -172,7 +172,7 @@ static uint8_t spi_dev_to_otw(dboard_interface::spi_dev_t dev){ * \param latch the dboard interface spi latch enum * \return an over the wire representation */ -static uint8_t spi_latch_to_otw(dboard_interface::spi_latch_t latch){ +static boost::uint8_t spi_latch_to_otw(dboard_interface::spi_latch_t latch){ switch(latch){ case uhd::usrp::dboard_interface::SPI_LATCH_RISE: return USRP2_CLK_EDGE_RISE; case uhd::usrp::dboard_interface::SPI_LATCH_FALL: return USRP2_CLK_EDGE_FALL; @@ -186,7 +186,7 @@ static uint8_t spi_latch_to_otw(dboard_interface::spi_latch_t latch){ * \param push the dboard interface spi push enum * \return an over the wire representation */ -static uint8_t spi_push_to_otw(dboard_interface::spi_push_t push){ +static boost::uint8_t spi_push_to_otw(dboard_interface::spi_push_t push){ switch(push){ case uhd::usrp::dboard_interface::SPI_PUSH_RISE: return USRP2_CLK_EDGE_RISE; case uhd::usrp::dboard_interface::SPI_PUSH_FALL: return USRP2_CLK_EDGE_FALL; @@ -286,7 +286,7 @@ dboard_interface::byte_vector_t usrp2_dboard_interface::read_i2c(int i2c_addr, s * \param unit the dboard interface unit type enum * \return an over the wire representation */ -static uint8_t spi_dev_to_otw(dboard_interface::unit_type_t unit){ +static boost::uint8_t spi_dev_to_otw(dboard_interface::unit_type_t unit){ switch(unit){ case uhd::usrp::dboard_interface::UNIT_TYPE_TX: return USRP2_DIR_TX; case uhd::usrp::dboard_interface::UNIT_TYPE_RX: return USRP2_DIR_RX; @@ -300,7 +300,7 @@ void usrp2_dboard_interface::write_aux_dac(dboard_interface::unit_type_t unit, i out_data.id = htonl(USRP2_CTRL_ID_WRITE_THIS_TO_THE_AUX_DAC_BRO); out_data.data.aux_args.dir = spi_dev_to_otw(unit); out_data.data.aux_args.which = which; - out_data.data.aux_args.dir = htonl(value); + out_data.data.aux_args.value = htonl(value); //send and recv usrp2_ctrl_data_t in_data = _impl->ctrl_send_and_recv(out_data); diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp index 7520c1757..54ed45e41 100644 --- a/host/lib/usrp/usrp2/dsp_impl.cpp +++ b/host/lib/usrp/usrp2/dsp_impl.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "usrp2_impl.hpp" using namespace uhd; @@ -25,14 +26,20 @@ using namespace uhd; static const size_t default_decim = 16; static const size_t default_interp = 16; +#define rint boost::math::iround + +template T log2(T num){ + return std::log(num)/std::log(T(2)); +} + /*********************************************************************** * DDC Helper Methods **********************************************************************/ -static uint32_t calculate_freq_word_and_update_actual_freq(freq_t &freq, freq_t clock_freq){ - double scale_factor = pow(2.0, 32); +static boost::uint32_t calculate_freq_word_and_update_actual_freq(freq_t &freq, freq_t clock_freq){ + double scale_factor = std::pow(2.0, 32); //calculate the freq register word - uint32_t freq_word = rint((freq / clock_freq) * scale_factor); + boost::uint32_t freq_word = rint((freq / clock_freq) * scale_factor); //update the actual frequency freq = (double(freq_word) / scale_factor) * clock_freq; @@ -40,8 +47,8 @@ static uint32_t calculate_freq_word_and_update_actual_freq(freq_t &freq, freq_t return freq_word; } -static uint32_t calculate_iq_scale_word(int16_t i, int16_t q){ - return (uint16_t(i) << 16) | (uint16_t(q) << 0); +static boost::uint32_t calculate_iq_scale_word(boost::int16_t i, boost::int16_t q){ + return (boost::uint16_t(i) << 16) | (boost::uint16_t(q) << 0); } void usrp2_impl::init_ddc_config(void){ @@ -69,7 +76,7 @@ void usrp2_impl::update_ddc_config(void){ calculate_freq_word_and_update_actual_freq(_ddc_freq, get_master_clock_freq()) ); out_data.data.ddc_args.decim = htonl(_ddc_decim); - static const uint32_t default_rx_scale_iq = 1024; + static const boost::int16_t default_rx_scale_iq = 1024; out_data.data.ddc_args.scale_iq = htonl( calculate_iq_scale_word(default_rx_scale_iq, default_rx_scale_iq) ); @@ -211,8 +218,8 @@ void usrp2_impl::update_duc_config(void){ while(tmp_interp > 128) tmp_interp /= 2; // Calculate closest multiplier constant to reverse gain absent scale multipliers - size_t interp_cubed = pow(tmp_interp, 3); - size_t scale = rint((4096*pow(2, ceil(log2(interp_cubed))))/(1.65*interp_cubed)); + double interp_cubed = std::pow(double(tmp_interp), 3); + boost::int16_t scale = rint((4096*std::pow(2, ceil(log2(interp_cubed))))/(1.65*interp_cubed)); //setup the out data usrp2_ctrl_data_t out_data; diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index 03e8d3a37..9740448ee 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -24,7 +24,11 @@ * Therefore, this header may only contain valid C code. */ #ifdef __cplusplus +#include +#define _SINS_ boost:://stdint namespace when in c++ extern "C" { +#else +#include #endif // size of the vrt header and trailer to the host @@ -128,78 +132,78 @@ typedef enum{ } usrp2_clk_edge_t; typedef struct{ - uint32_t id; - uint32_t seq; + _SINS_ uint32_t id; + _SINS_ uint32_t seq; union{ - uint32_t ip_addr; - uint8_t mac_addr[6]; + _SINS_ uint32_t ip_addr; + _SINS_ uint8_t mac_addr[6]; struct { - uint16_t rx_id; - uint16_t tx_id; + _SINS_ uint16_t rx_id; + _SINS_ uint16_t tx_id; } dboard_ids; struct { - uint8_t pps_source; - uint8_t pps_polarity; - uint8_t ref_source; - uint8_t _pad; + _SINS_ uint8_t pps_source; + _SINS_ uint8_t pps_polarity; + _SINS_ uint8_t ref_source; + _SINS_ uint8_t _pad; } clock_config; struct { - uint8_t bank; - uint8_t _pad[3]; - uint16_t value; - uint16_t mask; + _SINS_ uint8_t bank; + _SINS_ uint8_t _pad[3]; + _SINS_ uint16_t value; + _SINS_ uint16_t mask; } gpio_config; struct { - uint8_t bank; - uint8_t _pad[3]; - uint16_t tx_value; - uint16_t rx_value; - uint16_t mask; + _SINS_ uint8_t bank; + _SINS_ uint8_t _pad[3]; + _SINS_ uint16_t tx_value; + _SINS_ uint16_t rx_value; + _SINS_ uint16_t mask; } atr_config; struct { - uint8_t dev; - uint8_t latch; - uint8_t push; - uint8_t readback; - uint8_t bytes; - uint8_t data[sizeof(uint32_t)]; + _SINS_ uint8_t dev; + _SINS_ uint8_t latch; + _SINS_ uint8_t push; + _SINS_ uint8_t readback; + _SINS_ uint8_t bytes; + _SINS_ uint8_t data[sizeof(_SINS_ uint32_t)]; } spi_args; struct { - uint8_t addr; - uint8_t bytes; - uint8_t data[sizeof(uint32_t)]; + _SINS_ uint8_t addr; + _SINS_ uint8_t bytes; + _SINS_ uint8_t data[sizeof(_SINS_ uint32_t)]; } i2c_args; struct { - uint8_t dir; - uint8_t which; - uint8_t _pad[2]; - uint32_t value; + _SINS_ uint8_t dir; + _SINS_ uint8_t which; + _SINS_ uint8_t _pad[2]; + _SINS_ uint32_t value; } aux_args; struct { - uint32_t freq_word; - uint32_t decim; - uint32_t scale_iq; + _SINS_ uint32_t freq_word; + _SINS_ uint32_t decim; + _SINS_ uint32_t scale_iq; } ddc_args; struct { - uint8_t enabled; - uint8_t _pad[3]; - uint32_t secs; - uint32_t ticks; - uint32_t samples; + _SINS_ uint8_t enabled; + _SINS_ uint8_t _pad[3]; + _SINS_ uint32_t secs; + _SINS_ uint32_t ticks; + _SINS_ uint32_t samples; } streaming; struct { - uint32_t freq_word; - uint32_t interp; - uint32_t scale_iq; + _SINS_ uint32_t freq_word; + _SINS_ uint32_t interp; + _SINS_ uint32_t scale_iq; } duc_args; struct { - uint32_t secs; - uint32_t ticks; - uint8_t now; + _SINS_ uint32_t secs; + _SINS_ uint32_t ticks; + _SINS_ uint8_t now; } time_args; struct { - uint32_t rx_mux; - uint32_t tx_mux; + _SINS_ uint32_t rx_mux; + _SINS_ uint32_t tx_mux; } mux_args; } data; } usrp2_ctrl_data_t; diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp index e52c1e576..dc8eea243 100644 --- a/host/lib/usrp/usrp2/io_impl.cpp +++ b/host/lib/usrp/usrp2/io_impl.cpp @@ -16,6 +16,7 @@ // #include +#include #include #include "usrp2_impl.hpp" @@ -27,11 +28,11 @@ namespace asio = boost::asio; /*********************************************************************** * Constants **********************************************************************/ -typedef std::complex fc32_t; -typedef std::complex sc16_t; +typedef std::complex fc32_t; +typedef std::complex sc16_t; -static const float shorts_per_float = pow(2.0, 15); -static const float floats_per_short = 1.0/shorts_per_float; +static const float shorts_per_float = float(1 << 15); +static const float floats_per_short = float(1.0/shorts_per_float); /*********************************************************************** * Helper Functions @@ -41,7 +42,7 @@ void usrp2_impl::io_init(void){ _rx_copy_buff = asio::buffer("", 0); //send a small data packet so the usrp2 knows the udp source port - uint32_t zero_data = 0; + boost::uint32_t zero_data = 0; _data_transport->send(asio::buffer(&zero_data, sizeof(zero_data))); } @@ -66,37 +67,37 @@ static const bool is_big_endian = false; #endif static inline void host_floats_to_usrp2_items( - uint32_t *usrp2_items, + boost::uint32_t *usrp2_items, const fc32_t *host_floats, size_t num_samps ){ unrolled_loop(i, num_samps,{ - uint16_t real = host_floats[i].real()*shorts_per_float; - uint16_t imag = host_floats[i].imag()*shorts_per_float; + boost::uint16_t real = boost::int16_t(host_floats[i].real()*shorts_per_float); + boost::uint16_t imag = boost::int16_t(host_floats[i].imag()*shorts_per_float); usrp2_items[i] = htonl((real << 16) | (imag << 0)); }); } static inline void usrp2_items_to_host_floats( fc32_t *host_floats, - const uint32_t *usrp2_items, + const boost::uint32_t *usrp2_items, size_t num_samps ){ unrolled_loop(i, num_samps,{ - uint32_t item = ntohl(usrp2_items[i]); - int16_t real = item >> 16; - int16_t imag = item >> 0; - host_floats[i] = fc32_t(real*floats_per_short, imag*floats_per_short); + boost::uint32_t item = ntohl(usrp2_items[i]); + boost::int16_t real = boost::uint16_t(item >> 16); + boost::int16_t imag = boost::uint16_t(item >> 0); + host_floats[i] = fc32_t(float(real*floats_per_short), float(imag*floats_per_short)); }); } static inline void host_items_to_usrp2_items( - uint32_t *usrp2_items, - const uint32_t *host_items, + boost::uint32_t *usrp2_items, + const boost::uint32_t *host_items, size_t num_samps ){ if (is_big_endian){ - std::memcpy(usrp2_items, host_items, num_samps*sizeof(uint32_t)); + std::memcpy(usrp2_items, host_items, num_samps*sizeof(boost::uint32_t)); } else{ unrolled_loop(i, num_samps, usrp2_items[i] = htonl(host_items[i])); @@ -104,12 +105,12 @@ static inline void host_items_to_usrp2_items( } static inline void usrp2_items_to_host_items( - uint32_t *host_items, - const uint32_t *usrp2_items, + boost::uint32_t *host_items, + const boost::uint32_t *usrp2_items, size_t num_samps ){ if (is_big_endian){ - std::memcpy(host_items, usrp2_items, num_samps*sizeof(uint32_t)); + std::memcpy(host_items, usrp2_items, num_samps*sizeof(boost::uint32_t)); } else{ unrolled_loop(i, num_samps, host_items[i] = ntohl(usrp2_items[i])); @@ -124,12 +125,12 @@ void usrp2_impl::recv_raw(rx_metadata_t &metadata){ _rx_smart_buff = _data_transport->recv(); //unpack the vrt header - size_t num_packet_words32 = asio::buffer_size(_rx_smart_buff->get())/sizeof(uint32_t); + size_t num_packet_words32 = asio::buffer_size(_rx_smart_buff->get())/sizeof(boost::uint32_t); if (num_packet_words32 == 0){ _rx_copy_buff = boost::asio::buffer("", 0); return; //must exit here after setting the buffer } - const uint32_t *vrt_hdr = asio::buffer_cast(_rx_smart_buff->get()); + const boost::uint32_t *vrt_hdr = asio::buffer_cast(_rx_smart_buff->get()); size_t num_header_words32_out, num_payload_words32_out, packet_count_out; try{ vrt::unpack( @@ -156,7 +157,7 @@ void usrp2_impl::recv_raw(rx_metadata_t &metadata){ //setup the rx buffer to point to the data _rx_copy_buff = asio::buffer( vrt_hdr + num_header_words32_out, - num_payload_words32_out*sizeof(uint32_t) + num_payload_words32_out*sizeof(boost::uint32_t) ); } @@ -168,8 +169,8 @@ size_t usrp2_impl::send( const tx_metadata_t &metadata, const std::string &type ){ - uint32_t tx_mem[_mtu/sizeof(uint32_t)]; - uint32_t *items = tx_mem + vrt::max_header_words32; //offset for data + boost::uint32_t tx_mem[_mtu/sizeof(boost::uint32_t)]; + boost::uint32_t *items = tx_mem + vrt::max_header_words32; //offset for data size_t num_samps = _max_tx_samples_per_packet; //calculate the number of samples to be copied @@ -180,13 +181,13 @@ size_t usrp2_impl::send( } else if (type == "16sc"){ num_samps = std::min(asio::buffer_size(buff)/sizeof(sc16_t), num_samps); - host_items_to_usrp2_items(items, asio::buffer_cast(buff), num_samps); + host_items_to_usrp2_items(items, asio::buffer_cast(buff), num_samps); } else{ throw std::runtime_error(str(boost::format("usrp2 send: cannot handle type \"%s\"") % type)); } - uint32_t vrt_hdr[vrt::max_header_words32]; + boost::uint32_t vrt_hdr[vrt::max_header_words32]; size_t num_header_words32, num_packet_words32; size_t packet_count = _tx_stream_id_to_packet_seq[metadata.stream_id]++; @@ -202,10 +203,10 @@ size_t usrp2_impl::send( //copy in the vrt header (yes we left space) items -= num_header_words32; - std::memcpy(items, vrt_hdr, num_header_words32*sizeof(uint32_t)); + std::memcpy(items, vrt_hdr, num_header_words32*sizeof(boost::uint32_t)); //send and return number of samples - _data_transport->send(asio::buffer(items, num_packet_words32*sizeof(uint32_t))); + _data_transport->send(asio::buffer(items, num_packet_words32*sizeof(boost::uint32_t))); return num_samps; } @@ -231,8 +232,8 @@ size_t usrp2_impl::recv( //and a pointer into the usrp2 received items memory size_t bytes_to_copy = asio::buffer_size(_rx_copy_buff); if (bytes_to_copy == 0) return 0; //nothing to receive - size_t num_samps = bytes_to_copy/sizeof(uint32_t); - const uint32_t *items = asio::buffer_cast(_rx_copy_buff); + size_t num_samps = bytes_to_copy/sizeof(boost::uint32_t); + const boost::uint32_t *items = asio::buffer_cast(_rx_copy_buff); //calculate the number of samples to be copied //and copy the samples from the recv buffer @@ -242,7 +243,7 @@ size_t usrp2_impl::recv( } else if (type == "16sc"){ num_samps = std::min(asio::buffer_size(buff)/sizeof(sc16_t), num_samps); - usrp2_items_to_host_items(asio::buffer_cast(buff), items, num_samps); + usrp2_items_to_host_items(asio::buffer_cast(buff), items, num_samps); } else{ throw std::runtime_error(str(boost::format("usrp2 recv: cannot handle type \"%s\"") % type)); @@ -250,7 +251,7 @@ size_t usrp2_impl::recv( //update the rx copy buffer to reflect the bytes copied _rx_copy_buff = asio::buffer( - items + num_samps, bytes_to_copy - num_samps*sizeof(uint32_t) + items + num_samps, bytes_to_copy - num_samps*sizeof(boost::uint32_t) ); return num_samps; diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp index 2c6b6f8c9..765c523fe 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.hpp +++ b/host/lib/usrp/usrp2/usrp2_impl.hpp @@ -115,17 +115,17 @@ public: private: //the raw io interface (samples are in the usrp2 native format) void recv_raw(uhd::rx_metadata_t &); - uhd::dict _tx_stream_id_to_packet_seq; - uhd::dict _rx_stream_id_to_packet_seq; + uhd::dict _tx_stream_id_to_packet_seq; + uhd::dict _rx_stream_id_to_packet_seq; static const size_t _mtu = 1500; //FIXME we have no idea static const size_t _hdrs = (2 + 14 + 20 + 8); //size of headers (pad, eth, ip, udp) static const size_t _max_rx_samples_per_packet = - (_mtu - _hdrs)/sizeof(uint32_t) - + (_mtu - _hdrs)/sizeof(boost::uint32_t) - USRP2_HOST_RX_VRT_HEADER_WORDS32 - USRP2_HOST_RX_VRT_TRAILER_WORDS32 ; static const size_t _max_tx_samples_per_packet = - (_mtu - _hdrs)/sizeof(uint32_t) - + (_mtu - _hdrs)/sizeof(boost::uint32_t) - uhd::transport::vrt::max_header_words32 ; uhd::transport::smart_buffer::sptr _rx_smart_buff; @@ -137,7 +137,7 @@ private: uhd::transport::udp_zero_copy::sptr _data_transport; //private vars for dealing with send/recv control - uint32_t _ctrl_seq_num; + boost::uint32_t _ctrl_seq_num; boost::mutex _ctrl_mutex; //methods and shadows for clock configuration diff --git a/host/test/vrt_test.cpp b/host/test/vrt_test.cpp index d80908c74..40116e110 100644 --- a/host/test/vrt_test.cpp +++ b/host/test/vrt_test.cpp @@ -25,7 +25,7 @@ static void pack_and_unpack( size_t num_payload_words32, size_t packet_count ){ - uint32_t header_buff[vrt::max_header_words32]; + boost::uint32_t header_buff[vrt::max_header_words32]; size_t num_header_words32; size_t num_packet_words32; diff --git a/host/test/wax_test.cpp b/host/test/wax_test.cpp index b793b2690..cb3b12052 100644 --- a/host/test/wax_test.cpp +++ b/host/test/wax_test.cpp @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(test_set_get){ for (size_t i = 0; i < 10; i++){ for (size_t j = 0; j < 10; j++){ for (size_t k = 0; k < 10; k++){ - float val = i * j * k + i + j + k; + float val = float(i * j * k + i + j + k); //std::cout << i << " " << j << " " << k << std::endl; wd[i][j][k] = val; BOOST_CHECK_EQUAL(val, wd[i][j][k].as()); -- cgit v1.2.3 From f2a86eb6389210a8ebd475782ab707f814c6e49c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 18 Mar 2010 10:01:09 -0700 Subject: define namespace hack when in c compiling --- host/lib/usrp/usrp2/fw_common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index 9740448ee..7fcae6fb2 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -29,6 +29,7 @@ extern "C" { #else #include +#define _SINS_ #endif // size of the vrt header and trailer to the host -- cgit v1.2.3