diff options
Diffstat (limited to 'host/lib')
-rw-r--r-- | host/lib/CMakeLists.txt | 5 | ||||
-rw-r--r-- | host/lib/device.cpp | 2 | ||||
-rw-r--r-- | host/lib/device_addr.cpp | 6 | ||||
-rw-r--r-- | host/lib/time_spec.cpp | 8 | ||||
-rw-r--r-- | host/lib/transport/udp_zero_copy_none.cpp | 10 | ||||
-rw-r--r-- | host/lib/transport/vrt.cpp | 21 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/dboard_impl.cpp | 4 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/dboard_interface.cpp | 28 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/dsp_impl.cpp | 23 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/fw_common.h | 100 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/io_impl.cpp | 65 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_impl.hpp | 10 |
12 files changed, 150 insertions, 132 deletions
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<const uint8_t *>(&mac_addr); + const boost::uint8_t *p = reinterpret_cast<const boost::uint8_t *>(&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 <uhd/transport/udp_zero_copy.hpp> +#include <boost/cstdint.hpp> #include <boost/thread.hpp> #include <boost/format.hpp> +#include <iostream> using namespace uhd::transport; @@ -36,7 +38,7 @@ public: } ~smart_buffer_impl(void){ - delete [] boost::asio::buffer_cast<const uint32_t *>(_buff); + delete [] boost::asio::buffer_cast<const boost::uint32_t *>(_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 <uhd/transport/vrt.hpp> -#include <netinet/in.h> +#include <boost/asio.hpp> //endianness conversion #include <stdexcept> +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::string>() << 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::string>() << 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 <uhd/utils.hpp> #include <boost/format.hpp> #include <boost/assign/list_of.hpp> +#include <boost/math/special_functions/round.hpp> #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 <class T> 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 <boost/cstdint.hpp> +#define _SINS_ boost:://stdint namespace when in c++ extern "C" { +#else +#include <stdint.h> #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 <complex> +#include <algorithm> #include <boost/format.hpp> #include "usrp2_impl.hpp" @@ -27,11 +28,11 @@ namespace asio = boost::asio; /*********************************************************************** * Constants **********************************************************************/ -typedef std::complex<float> fc32_t; -typedef std::complex<int16_t> sc16_t; +typedef std::complex<float> fc32_t; +typedef std::complex<boost::int16_t> 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<const uint32_t *>(_rx_smart_buff->get()); + const boost::uint32_t *vrt_hdr = asio::buffer_cast<const boost::uint32_t *>(_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<const uint32_t*>(buff), num_samps); + host_items_to_usrp2_items(items, asio::buffer_cast<const boost::uint32_t*>(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<const uint32_t*>(_rx_copy_buff); + size_t num_samps = bytes_to_copy/sizeof(boost::uint32_t); + const boost::uint32_t *items = asio::buffer_cast<const boost::uint32_t*>(_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<uint32_t*>(buff), items, num_samps); + usrp2_items_to_host_items(asio::buffer_cast<boost::uint32_t*>(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<uint32_t, size_t> _tx_stream_id_to_packet_seq; - uhd::dict<uint32_t, size_t> _rx_stream_id_to_packet_seq; + uhd::dict<boost::uint32_t, size_t> _tx_stream_id_to_packet_seq; + uhd::dict<boost::uint32_t, size_t> _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 |