From 08fad28f209a2f6c79d939ad54ca3a1d4e270b0b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 29 Jun 2010 22:55:45 -0700 Subject: uhd: work vectorizing the vrt packet handler, reworked vrt packet stuff, needs testing --- host/include/uhd/device.hpp | 51 ++++++++++++++--- host/include/uhd/transport/vrt.hpp | 110 +++++++++++++++--------------------- host/include/uhd/types/metadata.hpp | 14 ----- 3 files changed, 89 insertions(+), 86 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/device.hpp b/host/include/uhd/device.hpp index d3e9015c4..f04a5b4fb 100644 --- a/host/include/uhd/device.hpp +++ b/host/include/uhd/device.hpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace uhd{ @@ -96,8 +97,22 @@ public: RECV_MODE_ONE_PACKET = 1 }; + //! wrapper call for single buffer recv //TODO put somewhere + size_t send( + const boost::asio::const_buffer &buff, + const tx_metadata_t &metadata, + const io_type_t &io_type, + send_mode_t send_mode + ){ + return send( + std::vector(1, boost::asio::buffer_cast(buff)), + boost::asio::buffer_size(buff)/io_type.size, + metadata, io_type, send_mode + ); + } + /*! - * Send a buffer containing IF data with its metadata. + * Send buffers containing IF data described by the metadata. * * Send handles fragmentation as follows: * If the buffer has more samples than the maximum per packet, @@ -108,23 +123,39 @@ public: * Fragmentation only applies in the full buffer send mode. * * This is a blocking call and will not return until the number - * of samples returned have been read out of the buffer. + * of samples returned have been read out of each buffer. * - * \param buff a buffer pointing to some read-only memory + * \param buffs a vector of read-only memory containing IF data + * \param nsamps_per_buff the number of samples to send, per buffer * \param metadata data describing the buffer's contents * \param io_type the type of data loaded in the buffer * \param send_mode tells send how to unload the buffer * \return the number of samples sent */ virtual size_t send( - const boost::asio::const_buffer &buff, + const std::vector &buffs, + size_t nsamps_per_buff, const tx_metadata_t &metadata, const io_type_t &io_type, send_mode_t send_mode ) = 0; + //! wrapper call for single buffer recv //TODO put somewhere + size_t recv( + const boost::asio::mutable_buffer &buff, + rx_metadata_t &metadata, + const io_type_t &io_type, + recv_mode_t recv_mode + ){ + return recv( + std::vector(1, boost::asio::buffer_cast(buff)), + boost::asio::buffer_size(buff)/io_type.size, + metadata, io_type, recv_mode + ); + } + /*! - * Receive a buffer containing IF data and its metadata. + * Receive buffers containing IF data described by the metadata. * * Receive handles fragmentation as follows: * If the buffer has insufficient space to hold all samples @@ -138,7 +169,7 @@ public: * See the rx metadata fragment flags and offset fields for details. * * This is a blocking call and will not return until the number - * of samples returned have been written into the buffer. + * of samples returned have been written into each buffer. * However, a call to receive may timeout and return zero samples. * The timeout duration is decided by the underlying transport layer. * The caller should assume that the call to receive will not return @@ -146,17 +177,19 @@ public: * and that the timeout duration is reasonably tuned for performance. * * When using the full buffer recv mode, the metadata only applies - * to the first packet received and written into the recv buffer. + * to the first packet received and written into the recv buffers. * Use the one packet recv mode to get per packet metadata. * - * \param buff the buffer to fill with IF data + * \param buffs a vector of writable memory to fill with IF data + * \param nsamps_per_buff the size of each buffer in number of samples * \param metadata data to fill describing the buffer * \param io_type the type of data to fill into the buffer * \param recv_mode tells recv how to load the buffer * \return the number of samples received */ virtual size_t recv( - const boost::asio::mutable_buffer &buff, + const std::vector &buffs, + size_t nsamps_per_buff, rx_metadata_t &metadata, const io_type_t &io_type, recv_mode_t recv_mode diff --git a/host/include/uhd/transport/vrt.hpp b/host/include/uhd/transport/vrt.hpp index fb6efc99c..17da2d540 100644 --- a/host/include/uhd/transport/vrt.hpp +++ b/host/include/uhd/transport/vrt.hpp @@ -19,93 +19,77 @@ #define INCLUDED_UHD_TRANSPORT_VRT_HPP #include -#include -#include +#include +#include //size_t namespace uhd{ namespace transport{ namespace vrt{ - static const size_t max_header_words32 = 5; //hdr+sid+tsi+tsf (no class id supported) + //! The maximum number of 32-bit words in a vrt if packet header + static const size_t max_if_hdr_words32 = 7; //hdr+sid+cid+tsi+tsf + + /*! + * Definition for fields that can be packed into a vrt if header. + * The size fields are used for input and output depending upon + * the operation used (ie the pack or unpack function call). + */ + struct UHD_API if_packet_info_t{ + //size fields + size_t num_payload_words32; //required in pack, derived in unpack + size_t num_header_words32; //derived in pack, derived in unpack + size_t num_packet_words32; //derived in pack, required in unpack + + //header fields + size_t packet_count; + bool sob, eob; + + //optional fields + bool has_sid; boost::uint32_t sid; + bool has_cid; boost::uint64_t cid; + bool has_tsi; boost::uint32_t tsi; + bool has_tsf; boost::uint64_t tsf; + bool has_tlr; boost::uint32_t tlr; + }; /*! * Pack a vrt header from metadata (big endian format). - * \param metadata the tx metadata with flags and timestamps - * \param header_buff memory to write the packed vrt header - * \param num_header_words32 number of words in the vrt header - * \param num_payload_words32 the length of the payload - * \param num_packet_words32 the length of the packet - * \param packet_count the packet count sequence number - * \param tick_rate ticks per second used in time conversion + * \param packet_buff memory to write the packed vrt header + * \param if_packet_info the if packet info (read/write) */ - UHD_API void pack_be( - const tx_metadata_t &metadata, //input - 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 - double tick_rate //input + UHD_API void if_hdr_pack_be( + boost::uint32_t *packet_buff, + if_packet_info_t &if_packet_info ); /*! * Unpack a vrt header to metadata (big endian format). - * \param metadata the rx metadata with flags and timestamps - * \param header_buff memory to read the packed vrt header - * \param num_header_words32 number of words in the vrt header - * \param num_payload_words32 the length of the payload - * \param num_packet_words32 the length of the packet - * \param packet_count the packet count sequence number - * \param tick_rate ticks per second used in time conversion + * \param packet_buff memory to read the packed vrt header + * \param if_packet_info the if packet info (read/write) */ - UHD_API void unpack_be( - 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 - double tick_rate //input + UHD_API void if_hdr_unpack_be( + const boost::uint32_t *packet_buff, + if_packet_info_t &if_packet_info ); /*! * Pack a vrt header from metadata (little endian format). - * \param metadata the tx metadata with flags and timestamps - * \param header_buff memory to write the packed vrt header - * \param num_header_words32 number of words in the vrt header - * \param num_payload_words32 the length of the payload - * \param num_packet_words32 the length of the packet - * \param packet_count the packet count sequence number - * \param tick_rate ticks per second used in time conversion + * \param packet_buff memory to write the packed vrt header + * \param if_packet_info the if packet info (read/write) */ - UHD_API void pack_le( - const tx_metadata_t &metadata, //input - 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 - double tick_rate //input + UHD_API void if_hdr_pack_le( + boost::uint32_t *packet_buff, + if_packet_info_t &if_packet_info ); /*! * Unpack a vrt header to metadata (little endian format). - * \param metadata the rx metadata with flags and timestamps - * \param header_buff memory to read the packed vrt header - * \param num_header_words32 number of words in the vrt header - * \param num_payload_words32 the length of the payload - * \param num_packet_words32 the length of the packet - * \param packet_count the packet count sequence number - * \param tick_rate ticks per second used in time conversion + * \param packet_buff memory to read the packed vrt header + * \param if_packet_info the if packet info (read/write) */ - UHD_API void unpack_le( - 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 - double tick_rate //input + UHD_API void if_hdr_unpack_le( + const boost::uint32_t *packet_buff, + if_packet_info_t &if_packet_info ); } //namespace vrt diff --git a/host/include/uhd/types/metadata.hpp b/host/include/uhd/types/metadata.hpp index 55add71cc..f4c962ff7 100644 --- a/host/include/uhd/types/metadata.hpp +++ b/host/include/uhd/types/metadata.hpp @@ -30,13 +30,6 @@ namespace uhd{ * The receive routines will convert IF data headers into metadata. */ struct UHD_API rx_metadata_t{ - /*! - * Stream IDs may be used to identify source DSP units. - * --Not currently used in any known device implementation.-- - */ - bool has_stream_id; - boost::uint32_t stream_id; - /*! * Time specification: * Set from timestamps on incoming data when provided. @@ -83,13 +76,6 @@ namespace uhd{ * The send routines will convert the metadata to IF data headers. */ struct UHD_API tx_metadata_t{ - /*! - * Stream IDs may be used to identify destination DSP units. - * --Not currently used in any known device implementation.-- - */ - bool has_stream_id; - boost::uint32_t stream_id; - /*! * Time specification: * Set has time spec to false to perform a send "now". -- cgit v1.2.3 From deaade7bd0ae4dd9cab7f304fb69eea153ce592a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 30 Jun 2010 17:44:47 -0700 Subject: uhd: renamed the vrt header to vrt_if_packet header --- host/include/uhd/transport/CMakeLists.txt | 2 +- host/include/uhd/transport/vrt.hpp | 99 ------------ host/include/uhd/transport/vrt_if_packet.hpp | 99 ++++++++++++ host/lib/transport/CMakeLists.txt | 4 +- host/lib/transport/gen_vrt.py | 233 --------------------------- host/lib/transport/gen_vrt_if_packet.py | 233 +++++++++++++++++++++++++++ host/lib/transport/vrt_packet_handler.hpp | 2 +- host/lib/usrp/usrp2/usrp2_impl.hpp | 2 +- host/test/vrt_test.cpp | 2 +- 9 files changed, 338 insertions(+), 338 deletions(-) delete mode 100644 host/include/uhd/transport/vrt.hpp create mode 100644 host/include/uhd/transport/vrt_if_packet.hpp delete mode 100755 host/lib/transport/gen_vrt.py create mode 100755 host/lib/transport/gen_vrt_if_packet.py (limited to 'host/include') diff --git a/host/include/uhd/transport/CMakeLists.txt b/host/include/uhd/transport/CMakeLists.txt index 23a4aae94..4e1f7aca5 100644 --- a/host/include/uhd/transport/CMakeLists.txt +++ b/host/include/uhd/transport/CMakeLists.txt @@ -23,7 +23,7 @@ INSTALL(FILES if_addrs.hpp udp_simple.hpp udp_zero_copy.hpp - vrt.hpp + vrt_if_packet.hpp zero_copy.hpp DESTINATION ${INCLUDE_DIR}/uhd/transport ) diff --git a/host/include/uhd/transport/vrt.hpp b/host/include/uhd/transport/vrt.hpp deleted file mode 100644 index 17da2d540..000000000 --- a/host/include/uhd/transport/vrt.hpp +++ /dev/null @@ -1,99 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#ifndef INCLUDED_UHD_TRANSPORT_VRT_HPP -#define INCLUDED_UHD_TRANSPORT_VRT_HPP - -#include -#include -#include //size_t - -namespace uhd{ namespace transport{ - -namespace vrt{ - - //! The maximum number of 32-bit words in a vrt if packet header - static const size_t max_if_hdr_words32 = 7; //hdr+sid+cid+tsi+tsf - - /*! - * Definition for fields that can be packed into a vrt if header. - * The size fields are used for input and output depending upon - * the operation used (ie the pack or unpack function call). - */ - struct UHD_API if_packet_info_t{ - //size fields - size_t num_payload_words32; //required in pack, derived in unpack - size_t num_header_words32; //derived in pack, derived in unpack - size_t num_packet_words32; //derived in pack, required in unpack - - //header fields - size_t packet_count; - bool sob, eob; - - //optional fields - bool has_sid; boost::uint32_t sid; - bool has_cid; boost::uint64_t cid; - bool has_tsi; boost::uint32_t tsi; - bool has_tsf; boost::uint64_t tsf; - bool has_tlr; boost::uint32_t tlr; - }; - - /*! - * Pack a vrt header from metadata (big endian format). - * \param packet_buff memory to write the packed vrt header - * \param if_packet_info the if packet info (read/write) - */ - UHD_API void if_hdr_pack_be( - boost::uint32_t *packet_buff, - if_packet_info_t &if_packet_info - ); - - /*! - * Unpack a vrt header to metadata (big endian format). - * \param packet_buff memory to read the packed vrt header - * \param if_packet_info the if packet info (read/write) - */ - UHD_API void if_hdr_unpack_be( - const boost::uint32_t *packet_buff, - if_packet_info_t &if_packet_info - ); - - /*! - * Pack a vrt header from metadata (little endian format). - * \param packet_buff memory to write the packed vrt header - * \param if_packet_info the if packet info (read/write) - */ - UHD_API void if_hdr_pack_le( - boost::uint32_t *packet_buff, - if_packet_info_t &if_packet_info - ); - - /*! - * Unpack a vrt header to metadata (little endian format). - * \param packet_buff memory to read the packed vrt header - * \param if_packet_info the if packet info (read/write) - */ - UHD_API void if_hdr_unpack_le( - const boost::uint32_t *packet_buff, - if_packet_info_t &if_packet_info - ); - -} //namespace vrt - -}} //namespace - -#endif /* INCLUDED_UHD_TRANSPORT_VRT_HPP */ diff --git a/host/include/uhd/transport/vrt_if_packet.hpp b/host/include/uhd/transport/vrt_if_packet.hpp new file mode 100644 index 000000000..ccefe14ea --- /dev/null +++ b/host/include/uhd/transport/vrt_if_packet.hpp @@ -0,0 +1,99 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#ifndef INCLUDED_UHD_TRANSPORT_VRT_IF_PACKET_HPP +#define INCLUDED_UHD_TRANSPORT_VRT_IF_PACKET_HPP + +#include +#include +#include //size_t + +namespace uhd{ namespace transport{ + +namespace vrt{ + + //! The maximum number of 32-bit words in a vrt if packet header + static const size_t max_if_hdr_words32 = 7; //hdr+sid+cid+tsi+tsf + + /*! + * Definition for fields that can be packed into a vrt if header. + * The size fields are used for input and output depending upon + * the operation used (ie the pack or unpack function call). + */ + struct UHD_API if_packet_info_t{ + //size fields + size_t num_payload_words32; //required in pack, derived in unpack + size_t num_header_words32; //derived in pack, derived in unpack + size_t num_packet_words32; //derived in pack, required in unpack + + //header fields + size_t packet_count; + bool sob, eob; + + //optional fields + bool has_sid; boost::uint32_t sid; + bool has_cid; boost::uint64_t cid; + bool has_tsi; boost::uint32_t tsi; + bool has_tsf; boost::uint64_t tsf; + bool has_tlr; boost::uint32_t tlr; + }; + + /*! + * Pack a vrt header from metadata (big endian format). + * \param packet_buff memory to write the packed vrt header + * \param if_packet_info the if packet info (read/write) + */ + UHD_API void if_hdr_pack_be( + boost::uint32_t *packet_buff, + if_packet_info_t &if_packet_info + ); + + /*! + * Unpack a vrt header to metadata (big endian format). + * \param packet_buff memory to read the packed vrt header + * \param if_packet_info the if packet info (read/write) + */ + UHD_API void if_hdr_unpack_be( + const boost::uint32_t *packet_buff, + if_packet_info_t &if_packet_info + ); + + /*! + * Pack a vrt header from metadata (little endian format). + * \param packet_buff memory to write the packed vrt header + * \param if_packet_info the if packet info (read/write) + */ + UHD_API void if_hdr_pack_le( + boost::uint32_t *packet_buff, + if_packet_info_t &if_packet_info + ); + + /*! + * Unpack a vrt header to metadata (little endian format). + * \param packet_buff memory to read the packed vrt header + * \param if_packet_info the if packet info (read/write) + */ + UHD_API void if_hdr_unpack_le( + const boost::uint32_t *packet_buff, + if_packet_info_t &if_packet_info + ); + +} //namespace vrt + +}} //namespace + +#endif /* INCLUDED_UHD_TRANSPORT_VRT_IF_PACKET_HPP */ diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt index 70cf6312d..bde2b72b9 100644 --- a/host/lib/transport/CMakeLists.txt +++ b/host/lib/transport/CMakeLists.txt @@ -50,8 +50,8 @@ ENDIF(HAVE_IFADDRS_H) # Append to the list of sources for lib uhd ######################################################################## LIBUHD_PYTHON_GEN_SOURCE( - ${CMAKE_SOURCE_DIR}/lib/transport/gen_vrt.py - ${CMAKE_BINARY_DIR}/lib/transport/vrt.cpp + ${CMAKE_SOURCE_DIR}/lib/transport/gen_vrt_if_packet.py + ${CMAKE_BINARY_DIR}/lib/transport/vrt_if_packet.cpp ) LIBUHD_PYTHON_GEN_SOURCE( diff --git a/host/lib/transport/gen_vrt.py b/host/lib/transport/gen_vrt.py deleted file mode 100755 index 06182bd39..000000000 --- a/host/lib/transport/gen_vrt.py +++ /dev/null @@ -1,233 +0,0 @@ -#!/usr/bin/env python -# -# 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 . -# - -""" -The vrt packer/unpacker code generator: - -This script will generate the pack and unpack routines that convert -metatdata into vrt headers and vrt headers into metadata. - -The generated code infers jump tables to speed-up the parsing time. -""" - -TMPL_TEXT = """ -#import time -/*********************************************************************** - * This file was generated by $file on $time.strftime("%c") - **********************************************************************/ - -\#include -\#include -\#include -\#include - -//define the endian macros to convert integers -\#ifdef BOOST_BIG_ENDIAN - \#define BE_MACRO(x) (x) - \#define LE_MACRO(x) uhd::byteswap(x) -\#else - \#define BE_MACRO(x) uhd::byteswap(x) - \#define LE_MACRO(x) (x) -\#endif - -using namespace uhd; -using namespace uhd::transport; - -######################################################################## -#def gen_code($XE_MACRO, $suffix) -######################################################################## - -######################################################################## -## setup predicates -######################################################################## -#set $sid_p = 0b00001 -#set $cid_p = 0b00010 -#set $tsi_p = 0b00100 -#set $tsf_p = 0b01000 -#set $tlr_p = 0b10000 - -static UHD_INLINE void pack_uint64_$(suffix)(boost::uint64_t num, boost::uint32_t *mem){ - *(reinterpret_cast(mem)) = $(XE_MACRO)(num); -} - -void vrt::if_hdr_pack_$(suffix)( - boost::uint32_t *packet_buff, - if_packet_info_t &if_packet_info -){ - boost::uint32_t vrt_hdr_flags = 0; - - boost::uint8_t pred = 0; - if (if_packet_info.has_sid) pred |= $hex($sid_p); - if (if_packet_info.has_cid) pred |= $hex($cid_p); - if (if_packet_info.has_tsi) pred |= $hex($tsi_p); - if (if_packet_info.has_tsf) pred |= $hex($tsf_p); - if (if_packet_info.has_tlr) pred |= $hex($tlr_p); - - switch(pred){ - #for $pred in range(2**5) - case $pred: - #set $num_header_words = 1 - #set $flags = 0 - ########## Stream ID ########## - #if $pred & $sid_p - packet_buff[$num_header_words] = $(XE_MACRO)(if_packet_info.sid); - #set $num_header_words += 1 - #set $flags |= (0x1 << 28); - #end if - ########## Class ID ########## - #if $pred & $cid_p - pack_uint64_$(suffix)(if_packet_info.cid, packet_buff+$num_header_words); - #set $num_header_words += 2 - #set $flags |= (0x1 << 27); - #end if - ########## Integer Time ########## - #if $pred & $tsi_p - packet_buff[$num_header_words] = $(XE_MACRO)(if_packet_info.tsi); - #set $num_header_words += 1 - #set $flags |= (0x3 << 22); - #end if - ########## Fractional Time ########## - #if $pred & $tsf_p - pack_uint64_$(suffix)(if_packet_info.tsf, packet_buff+$num_header_words); - #set $num_header_words += 2 - #set $flags |= (0x1 << 20); - #end if - ########## Trailer ########## - #if $pred & $tlr_p - //packet_buff[$num_header_words+if_packet_info.num_payload_words32] = $(XE_MACRO)(if_packet_info.tlr); - #set $flags |= (0x1 << 26); - #set $num_trailer_words = 1; - #else - //packet_buff[$num_header_words+if_packet_info.num_payload_words32] = 0; - #set $num_trailer_words = 0; - #end if - ########## Variables ########## - if_packet_info.num_header_words32 = $num_header_words; - if_packet_info.num_packet_words32 = $($num_header_words + $num_trailer_words) + if_packet_info.num_payload_words32; - vrt_hdr_flags = $hex($flags); - break; - #end for - } - - //set the burst flags - if (if_packet_info.sob) vrt_hdr_flags |= $hex(0x1 << 25); - if (if_packet_info.eob) vrt_hdr_flags |= $hex(0x1 << 24); - - //fill in complete header word - packet_buff[0] = $(XE_MACRO)(boost::uint32_t(0 - | vrt_hdr_flags - | ((if_packet_info.packet_count & 0xf) << 16) - | (if_packet_info.num_packet_words32 & 0xffff) - )); -} - -static UHD_INLINE void unpack_uint64_$(suffix)(boost::uint64_t &num, const boost::uint32_t *mem){ - num = $(XE_MACRO)(*reinterpret_cast(mem)); -} - -void vrt::if_hdr_unpack_$(suffix)( - const boost::uint32_t *packet_buff, - if_packet_info_t &if_packet_info -){ - //extract vrt header - boost::uint32_t vrt_hdr_word = $(XE_MACRO)(packet_buff[0]); - size_t packet_words32 = vrt_hdr_word & 0xffff; - if_packet_info.packet_count = (vrt_hdr_word >> 16) & 0xf; - - //failure cases - if (packet_words32 == 0 or if_packet_info.num_packet_words32 < packet_words32) - throw std::runtime_error("bad vrt header or packet fragment"); - if (vrt_hdr_word & (0x7 << 29)) - throw std::runtime_error("unsupported vrt packet type"); - - boost::uint8_t pred = 0; - if(vrt_hdr_word & $hex(0x1 << 28)) pred |= $hex($sid_p); - if(vrt_hdr_word & $hex(0x1 << 27)) pred |= $hex($cid_p); - if(vrt_hdr_word & $hex(0x3 << 22)) pred |= $hex($tsi_p); - if(vrt_hdr_word & $hex(0x3 << 20)) pred |= $hex($tsf_p); - if(vrt_hdr_word & $hex(0x1 << 26)) pred |= $hex($tlr_p); - - switch(pred){ - #for $pred in range(2**5) - case $pred: - #set $has_time_spec = False - #set $num_header_words = 1 - ########## Stream ID ########## - #if $pred & $sid_p - if_packet_info.has_sid = true; - if_packet_info.sid = $(XE_MACRO)(packet_buff[$num_header_words]); - #set $num_header_words += 1 - #else - if_packet_info.has_sid = false; - #end if - ########## Class ID ########## - #if $pred & $cid_p - if_packet_info.has_cid = true; - unpack_uint64_$(suffix)(if_packet_info.cid, packet_buff+$num_header_words); - #set $num_header_words += 2 - #else - if_packet_info.has_cid = false; - #end if - ########## Integer Time ########## - #if $pred & $tsi_p - if_packet_info.has_tsi = true; - if_packet_info.tsi = $(XE_MACRO)(packet_buff[$num_header_words]); - #set $num_header_words += 1 - #else - if_packet_info.has_tsi = false; - #end if - ########## Fractional Time ########## - #if $pred & $tsf_p - if_packet_info.has_tsf = true; - unpack_uint64_$(suffix)(if_packet_info.tsf, packet_buff+$num_header_words); - #set $num_header_words += 2 - #else - if_packet_info.has_tsf = false; - #end if - ########## Trailer ########## - #if $pred & $tlr_p - if_packet_info.has_tlr = true; - if_packet_info.tlr = $(XE_MACRO)(packet_buff[$num_header_words+packet_words32]); - #set $num_trailer_words = 1; - #else - if_packet_info.has_tlr = false; - #set $num_trailer_words = 0; - #end if - ########## Variables ########## - if_packet_info.num_header_words32 = $num_header_words; - if_packet_info.num_payload_words32 = packet_words32 - $($num_header_words + $num_trailer_words); - break; - #end for - } -} - -######################################################################## -#end def -######################################################################## - -$gen_code("BE_MACRO", "be") -$gen_code("LE_MACRO", "le") -""" - -def parse_tmpl(_tmpl_text, **kwargs): - from Cheetah.Template import Template - return str(Template(_tmpl_text, kwargs)) - -if __name__ == '__main__': - import sys - open(sys.argv[1], 'w').write(parse_tmpl(TMPL_TEXT, file=__file__)) diff --git a/host/lib/transport/gen_vrt_if_packet.py b/host/lib/transport/gen_vrt_if_packet.py new file mode 100755 index 000000000..536409b2e --- /dev/null +++ b/host/lib/transport/gen_vrt_if_packet.py @@ -0,0 +1,233 @@ +#!/usr/bin/env python +# +# 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 . +# + +""" +The vrt packer/unpacker code generator: + +This script will generate the pack and unpack routines that convert +metatdata into vrt headers and vrt headers into metadata. + +The generated code infers jump tables to speed-up the parsing time. +""" + +TMPL_TEXT = """ +#import time +/*********************************************************************** + * This file was generated by $file on $time.strftime("%c") + **********************************************************************/ + +\#include +\#include +\#include +\#include + +//define the endian macros to convert integers +\#ifdef BOOST_BIG_ENDIAN + \#define BE_MACRO(x) (x) + \#define LE_MACRO(x) uhd::byteswap(x) +\#else + \#define BE_MACRO(x) uhd::byteswap(x) + \#define LE_MACRO(x) (x) +\#endif + +using namespace uhd; +using namespace uhd::transport; + +######################################################################## +#def gen_code($XE_MACRO, $suffix) +######################################################################## + +######################################################################## +## setup predicates +######################################################################## +#set $sid_p = 0b00001 +#set $cid_p = 0b00010 +#set $tsi_p = 0b00100 +#set $tsf_p = 0b01000 +#set $tlr_p = 0b10000 + +static UHD_INLINE void pack_uint64_$(suffix)(boost::uint64_t num, boost::uint32_t *mem){ + *(reinterpret_cast(mem)) = $(XE_MACRO)(num); +} + +void vrt::if_hdr_pack_$(suffix)( + boost::uint32_t *packet_buff, + if_packet_info_t &if_packet_info +){ + boost::uint32_t vrt_hdr_flags = 0; + + boost::uint8_t pred = 0; + if (if_packet_info.has_sid) pred |= $hex($sid_p); + if (if_packet_info.has_cid) pred |= $hex($cid_p); + if (if_packet_info.has_tsi) pred |= $hex($tsi_p); + if (if_packet_info.has_tsf) pred |= $hex($tsf_p); + if (if_packet_info.has_tlr) pred |= $hex($tlr_p); + + switch(pred){ + #for $pred in range(2**5) + case $pred: + #set $num_header_words = 1 + #set $flags = 0 + ########## Stream ID ########## + #if $pred & $sid_p + packet_buff[$num_header_words] = $(XE_MACRO)(if_packet_info.sid); + #set $num_header_words += 1 + #set $flags |= (0x1 << 28); + #end if + ########## Class ID ########## + #if $pred & $cid_p + pack_uint64_$(suffix)(if_packet_info.cid, packet_buff+$num_header_words); + #set $num_header_words += 2 + #set $flags |= (0x1 << 27); + #end if + ########## Integer Time ########## + #if $pred & $tsi_p + packet_buff[$num_header_words] = $(XE_MACRO)(if_packet_info.tsi); + #set $num_header_words += 1 + #set $flags |= (0x3 << 22); + #end if + ########## Fractional Time ########## + #if $pred & $tsf_p + pack_uint64_$(suffix)(if_packet_info.tsf, packet_buff+$num_header_words); + #set $num_header_words += 2 + #set $flags |= (0x1 << 20); + #end if + ########## Trailer ########## + #if $pred & $tlr_p + //packet_buff[$num_header_words+if_packet_info.num_payload_words32] = $(XE_MACRO)(if_packet_info.tlr); + #set $flags |= (0x1 << 26); + #set $num_trailer_words = 1; + #else + //packet_buff[$num_header_words+if_packet_info.num_payload_words32] = 0; + #set $num_trailer_words = 0; + #end if + ########## Variables ########## + if_packet_info.num_header_words32 = $num_header_words; + if_packet_info.num_packet_words32 = $($num_header_words + $num_trailer_words) + if_packet_info.num_payload_words32; + vrt_hdr_flags = $hex($flags); + break; + #end for + } + + //set the burst flags + if (if_packet_info.sob) vrt_hdr_flags |= $hex(0x1 << 25); + if (if_packet_info.eob) vrt_hdr_flags |= $hex(0x1 << 24); + + //fill in complete header word + packet_buff[0] = $(XE_MACRO)(boost::uint32_t(0 + | vrt_hdr_flags + | ((if_packet_info.packet_count & 0xf) << 16) + | (if_packet_info.num_packet_words32 & 0xffff) + )); +} + +static UHD_INLINE void unpack_uint64_$(suffix)(boost::uint64_t &num, const boost::uint32_t *mem){ + num = $(XE_MACRO)(*reinterpret_cast(mem)); +} + +void vrt::if_hdr_unpack_$(suffix)( + const boost::uint32_t *packet_buff, + if_packet_info_t &if_packet_info +){ + //extract vrt header + boost::uint32_t vrt_hdr_word = $(XE_MACRO)(packet_buff[0]); + size_t packet_words32 = vrt_hdr_word & 0xffff; + if_packet_info.packet_count = (vrt_hdr_word >> 16) & 0xf; + + //failure cases + if (packet_words32 == 0 or if_packet_info.num_packet_words32 < packet_words32) + throw std::runtime_error("bad vrt header or packet fragment"); + if (vrt_hdr_word & (0x7 << 29)) + throw std::runtime_error("unsupported vrt packet type"); + + boost::uint8_t pred = 0; + if(vrt_hdr_word & $hex(0x1 << 28)) pred |= $hex($sid_p); + if(vrt_hdr_word & $hex(0x1 << 27)) pred |= $hex($cid_p); + if(vrt_hdr_word & $hex(0x3 << 22)) pred |= $hex($tsi_p); + if(vrt_hdr_word & $hex(0x3 << 20)) pred |= $hex($tsf_p); + if(vrt_hdr_word & $hex(0x1 << 26)) pred |= $hex($tlr_p); + + switch(pred){ + #for $pred in range(2**5) + case $pred: + #set $has_time_spec = False + #set $num_header_words = 1 + ########## Stream ID ########## + #if $pred & $sid_p + if_packet_info.has_sid = true; + if_packet_info.sid = $(XE_MACRO)(packet_buff[$num_header_words]); + #set $num_header_words += 1 + #else + if_packet_info.has_sid = false; + #end if + ########## Class ID ########## + #if $pred & $cid_p + if_packet_info.has_cid = true; + unpack_uint64_$(suffix)(if_packet_info.cid, packet_buff+$num_header_words); + #set $num_header_words += 2 + #else + if_packet_info.has_cid = false; + #end if + ########## Integer Time ########## + #if $pred & $tsi_p + if_packet_info.has_tsi = true; + if_packet_info.tsi = $(XE_MACRO)(packet_buff[$num_header_words]); + #set $num_header_words += 1 + #else + if_packet_info.has_tsi = false; + #end if + ########## Fractional Time ########## + #if $pred & $tsf_p + if_packet_info.has_tsf = true; + unpack_uint64_$(suffix)(if_packet_info.tsf, packet_buff+$num_header_words); + #set $num_header_words += 2 + #else + if_packet_info.has_tsf = false; + #end if + ########## Trailer ########## + #if $pred & $tlr_p + if_packet_info.has_tlr = true; + if_packet_info.tlr = $(XE_MACRO)(packet_buff[$num_header_words+packet_words32]); + #set $num_trailer_words = 1; + #else + if_packet_info.has_tlr = false; + #set $num_trailer_words = 0; + #end if + ########## Variables ########## + if_packet_info.num_header_words32 = $num_header_words; + if_packet_info.num_payload_words32 = packet_words32 - $($num_header_words + $num_trailer_words); + break; + #end for + } +} + +######################################################################## +#end def +######################################################################## + +$gen_code("BE_MACRO", "be") +$gen_code("LE_MACRO", "le") +""" + +def parse_tmpl(_tmpl_text, **kwargs): + from Cheetah.Template import Template + return str(Template(_tmpl_text, kwargs)) + +if __name__ == '__main__': + import sys + open(sys.argv[1], 'w').write(parse_tmpl(TMPL_TEXT, file=__file__)) diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp index 8cbc71008..31b7e6614 100644 --- a/host/lib/transport/vrt_packet_handler.hpp +++ b/host/lib/transport/vrt_packet_handler.hpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp index 719cf3f16..df1dba663 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.hpp +++ b/host/lib/usrp/usrp2/usrp2_impl.hpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include diff --git a/host/test/vrt_test.cpp b/host/test/vrt_test.cpp index 3f74a836e..b90b2fc15 100644 --- a/host/test/vrt_test.cpp +++ b/host/test/vrt_test.cpp @@ -16,7 +16,7 @@ // #include -#include +#include #include using namespace uhd::transport; -- cgit v1.2.3 From 3b1473d5a3fbfb89e9ddc5575e855644707718d0 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 1 Jul 2010 16:08:33 -0700 Subject: usrp2: removed usrp2.hpp header, its not needed, just use the discovery/factory system uhd: added usrp_mimo skeleton code/header --- host/include/uhd/usrp/CMakeLists.txt | 6 ++-- host/include/uhd/usrp/mimo_usrp.hpp | 69 ++++++++++++++++++++++++++++++++++++ host/include/uhd/usrp/usrp2.hpp | 62 -------------------------------- host/lib/usrp/usrp2/usrp2_impl.cpp | 22 ++++++------ host/lib/usrp/usrp2/usrp2_impl.hpp | 2 +- host/utils/usrp2_addr_burner.cpp | 5 +-- 6 files changed, 87 insertions(+), 79 deletions(-) create mode 100644 host/include/uhd/usrp/mimo_usrp.hpp delete mode 100644 host/include/uhd/usrp/usrp2.hpp (limited to 'host/include') diff --git a/host/include/uhd/usrp/CMakeLists.txt b/host/include/uhd/usrp/CMakeLists.txt index bbd124ed8..6f8c1a2d8 100644 --- a/host/include/uhd/usrp/CMakeLists.txt +++ b/host/include/uhd/usrp/CMakeLists.txt @@ -31,12 +31,12 @@ INSTALL(FILES dboard_iface.hpp dboard_manager.hpp - ### usrp headers ### - usrp2.hpp - ### utilities ### tune_helper.hpp + + ### interfaces ### simple_usrp.hpp + mimo_usrp.hpp DESTINATION ${INCLUDE_DIR}/uhd/usrp ) diff --git a/host/include/uhd/usrp/mimo_usrp.hpp b/host/include/uhd/usrp/mimo_usrp.hpp new file mode 100644 index 000000000..2262b324e --- /dev/null +++ b/host/include/uhd/usrp/mimo_usrp.hpp @@ -0,0 +1,69 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#ifndef INCLUDED_UHD_USRP_MIMO_USRP_HPP +#define INCLUDED_UHD_USRP_MIMO_USRP_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace uhd{ namespace usrp{ + +/*! + * The MIMO USRP device class: + * A mimo usrp facilitates ease-of-use for multi-usrp scenarios. + * The wrapper provides convenience functions to control the group + * of underlying devices as if they consisted of a single device. + */ +class UHD_API mimo_usrp : boost::noncopyable{ +public: + typedef boost::shared_ptr sptr; + + /*! + * Make a new mimo usrp from the device address. + * \param dev_addr the device address + * \return a new mimo usrp object + */ + static sptr make(const device_addr_t &dev_addr); + + /*! + * Get the underlying device object. + * This is needed to get access to the streaming API and properties. + * \return the device object within this simple usrp + */ + virtual device::sptr get_device(void) = 0; + + /*! + * Get a printable name for this mimo usrp. + * \return a printable string + */ + virtual std::string get_name(void) = 0; + + //TODO + +}; + +}} + +#endif /* INCLUDED_UHD_USRP_MIMO_USRP_HPP */ diff --git a/host/include/uhd/usrp/usrp2.hpp b/host/include/uhd/usrp/usrp2.hpp deleted file mode 100644 index 7387e5dd4..000000000 --- a/host/include/uhd/usrp/usrp2.hpp +++ /dev/null @@ -1,62 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#ifndef INCLUDED_UHD_USRP_USRP2_HPP -#define INCLUDED_UHD_USRP_USRP2_HPP - -#include -#include - -namespace uhd{ namespace usrp{ - -/*! - * The usrp2 device class. - */ -class UHD_API usrp2 : public device{ -public: - /*! - * Find usrp2 devices over the ethernet. - * - * Recommended key/value pairs for the device hint address: - * hint["addr"] = address, where address is a resolvable address - * or ip address, which may or may not be a broadcast address. - * - * Other optional device address keys: - * recv_buff_size: resizes the recv buffer on the data socket - * send_buff_size: resizes the send buffer on the data socket - * - * \param hint a device addr with the usrp2 address filled in - * \return a vector of device addresses for all usrp2s found - */ - static device_addrs_t find(const device_addr_t &hint); - - /*! - * Make a usrp2 from a device address. - * - * Required key/value pairs for the device address: - * hint["addr"] = address, where address is a resolvable address - * or ip address, which must be the specific address of a usrp2. - * - * \param addr the device address - * \return a device sptr to a new usrp2 - */ - static device::sptr make(const device_addr_t &addr); -}; - -}} //namespace - -#endif /* INCLUDED_UHD_USRP_USRP2_HPP */ diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 436146a48..cdba19f50 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -35,10 +35,6 @@ using namespace uhd::usrp; using namespace uhd::transport; namespace asio = boost::asio; -UHD_STATIC_BLOCK(register_usrp2_device){ - device::register_device(&usrp2::find, &usrp2::make); -} - /*********************************************************************** * Helper Functions **********************************************************************/ @@ -48,10 +44,14 @@ std::vector split_addrs(const std::string &addrs_str){ return addrs; } +template std::string num2str(T num){ + return boost::lexical_cast(num); +} + /*********************************************************************** * Discovery over the udp transport **********************************************************************/ -uhd::device_addrs_t usrp2::find(const device_addr_t &hint){ +static uhd::device_addrs_t usrp2_find(const device_addr_t &hint){ device_addrs_t usrp2_addrs; //return an empty list of addresses when type is set to non-usrp2 @@ -68,7 +68,7 @@ uhd::device_addrs_t usrp2::find(const device_addr_t &hint){ new_hint["addr"] = if_addrs.bcast; //call discover with the new hint and append results - device_addrs_t new_usrp2_addrs = usrp2::find(new_hint); + device_addrs_t new_usrp2_addrs = usrp2_find(new_hint); usrp2_addrs.insert(usrp2_addrs.begin(), new_usrp2_addrs.begin(), new_usrp2_addrs.end() ); @@ -127,11 +127,7 @@ uhd::device_addrs_t usrp2::find(const device_addr_t &hint){ /*********************************************************************** * Make **********************************************************************/ -template std::string num2str(T num){ - return boost::lexical_cast(num); -} - -device::sptr usrp2::make(const device_addr_t &device_addr){ +static device::sptr usrp2_make(const device_addr_t &device_addr){ //extract the receive and send buffer sizes size_t recv_buff_size = 0, send_buff_size= 0 ; if (device_addr.has_key("recv_buff_size")){ @@ -161,6 +157,10 @@ device::sptr usrp2::make(const device_addr_t &device_addr){ ); } +UHD_STATIC_BLOCK(register_usrp2_device){ + device::register_device(&usrp2_find, &usrp2_make); +} + /*********************************************************************** * Structors **********************************************************************/ diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp index df1dba663..07e29eadd 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.hpp +++ b/host/lib/usrp/usrp2/usrp2_impl.hpp @@ -22,7 +22,7 @@ #include "clock_ctrl.hpp" #include "codec_ctrl.hpp" #include "serdes_ctrl.hpp" -#include +#include #include #include #include diff --git a/host/utils/usrp2_addr_burner.cpp b/host/utils/usrp2_addr_burner.cpp index 08fc1e218..f0e3434b7 100644 --- a/host/utils/usrp2_addr_burner.cpp +++ b/host/utils/usrp2_addr_burner.cpp @@ -16,7 +16,7 @@ // #include -#include +#include #include #include #include @@ -45,6 +45,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //load the options into the address uhd::device_addr_t device_addr; + device_addr["type"] = "usrp2"; if (vm.count("addr")){ device_addr["addr"] = vm["addr"].as(); } @@ -54,7 +55,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ } //create a usrp2 device - uhd::device::sptr u2_dev = uhd::usrp::usrp2::make(device_addr); + uhd::device::sptr u2_dev = uhd::device::make(device_addr); //FIXME usees the default mboard for now (until the mimo link is supported) wax::obj u2_mb = (*u2_dev)[uhd::usrp::DEVICE_PROP_MBOARD]; std::cout << std::endl; -- cgit v1.2.3 From 6469d2419f8564c37f8fd6870aedbc990f06e108 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 1 Jul 2010 18:32:37 -0700 Subject: uhd: filling in mimo usrp implementation, renamed get_name to get_pp_string for simple and mimo usrp --- host/examples/benchmark_rx_rate.cpp | 2 +- host/examples/rx_timed_samples.cpp | 2 +- host/examples/tx_timed_samples.cpp | 2 +- host/include/uhd/usrp/mimo_usrp.hpp | 41 +++++++++- host/include/uhd/usrp/simple_usrp.hpp | 16 ++-- host/lib/usrp/CMakeLists.txt | 1 + host/lib/usrp/mimo_usrp.cpp | 149 ++++++++++++++++++++++++++++++++++ host/lib/usrp/simple_usrp.cpp | 12 +-- host/lib/usrp/usrp2/usrp2_impl.cpp | 3 +- 9 files changed, 208 insertions(+), 20 deletions(-) create mode 100644 host/lib/usrp/mimo_usrp.cpp (limited to 'host/include') diff --git a/host/examples/benchmark_rx_rate.cpp b/host/examples/benchmark_rx_rate.cpp index 53f4a3c68..e7e358e4c 100644 --- a/host/examples/benchmark_rx_rate.cpp +++ b/host/examples/benchmark_rx_rate.cpp @@ -124,7 +124,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << std::endl; std::cout << boost::format("Creating the usrp device with: %s...") % args << std::endl; uhd::usrp::simple_usrp::sptr sdev = uhd::usrp::simple_usrp::make(args); - std::cout << boost::format("Using Device: %s") % sdev->get_name() << std::endl; + std::cout << boost::format("Using Device: %s") % sdev->get_pp_string() << std::endl; sdev->set_rx_rate(500e3); //initial rate while(true){ diff --git a/host/examples/rx_timed_samples.cpp b/host/examples/rx_timed_samples.cpp index 8db312690..3c3c3fdc6 100644 --- a/host/examples/rx_timed_samples.cpp +++ b/host/examples/rx_timed_samples.cpp @@ -59,7 +59,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << boost::format("Creating the usrp device with: %s...") % args << std::endl; uhd::usrp::simple_usrp::sptr sdev = uhd::usrp::simple_usrp::make(args); uhd::device::sptr dev = sdev->get_device(); - std::cout << boost::format("Using Device: %s") % sdev->get_name() << std::endl; + std::cout << boost::format("Using Device: %s") % sdev->get_pp_string() << std::endl; //set properties on the device std::cout << boost::format("Setting RX Rate: %f Msps...") % (rx_rate/1e6) << std::endl; diff --git a/host/examples/tx_timed_samples.cpp b/host/examples/tx_timed_samples.cpp index 333f03fbe..846d9b6f4 100644 --- a/host/examples/tx_timed_samples.cpp +++ b/host/examples/tx_timed_samples.cpp @@ -61,7 +61,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << boost::format("Creating the usrp device with: %s...") % args << std::endl; uhd::usrp::simple_usrp::sptr sdev = uhd::usrp::simple_usrp::make(args); uhd::device::sptr dev = sdev->get_device(); - std::cout << boost::format("Using Device: %s") % sdev->get_name() << std::endl; + std::cout << boost::format("Using Device: %s") % sdev->get_pp_string() << std::endl; //set properties on the device std::cout << boost::format("Setting TX Rate: %f Msps...") % (tx_rate/1e6) << std::endl; diff --git a/host/include/uhd/usrp/mimo_usrp.hpp b/host/include/uhd/usrp/mimo_usrp.hpp index 2262b324e..8820c91c1 100644 --- a/host/include/uhd/usrp/mimo_usrp.hpp +++ b/host/include/uhd/usrp/mimo_usrp.hpp @@ -58,9 +58,46 @@ public: * Get a printable name for this mimo usrp. * \return a printable string */ - virtual std::string get_name(void) = 0; + virtual std::string get_pp_string(void) = 0; - //TODO + /*! + * Get the number of channels in this mimo configuration. + * The number of rx channels == the number of tx channels. + * \return the number of channels + */ + virtual size_t get_num_channels(void) = 0; + + /******************************************************************* + * Misc + ******************************************************************/ + /*! + * Set the time registers on the usrp at the next pps tick. + * The values will not be latched in until the pulse occurs. + * It is recommended that the user sleep(1) after calling to ensure + * that the time registers will be in a known state prior to use. + * + * Note: Because this call sets the time on the "next" pps, + * the seconds in the time spec should be current seconds + 1. + * + * \param time_spec the time to latch into the usrp device + */ + virtual void set_time_next_pps(const time_spec_t &time_spec) = 0; + + /*! + * Issue a stream command to the usrp device. + * This tells the usrp to send samples into the host. + * See the documentation for stream_cmd_t for more info. + * \param stream_cmd the stream command to issue + */ + virtual void issue_stream_cmd(const stream_cmd_t &stream_cmd) = 0; + + /******************************************************************* + * RX methods + ******************************************************************/ + + /******************************************************************* + * TX methods + ******************************************************************/ }; diff --git a/host/include/uhd/usrp/simple_usrp.hpp b/host/include/uhd/usrp/simple_usrp.hpp index 6ba1b90dd..1d817e030 100644 --- a/host/include/uhd/usrp/simple_usrp.hpp +++ b/host/include/uhd/usrp/simple_usrp.hpp @@ -58,7 +58,7 @@ public: * Get a printable name for this simple usrp. * \return a printable string */ - virtual std::string get_name(void) = 0; + virtual std::string get_pp_string(void) = 0; /******************************************************************* * Misc @@ -98,13 +98,6 @@ public: */ virtual void set_clock_config(const clock_config_t &clock_config) = 0; - /*! - * Read the RSSI value from a usrp device. - * Or throw if the dboard does not support an RSSI readback. - * \return the rssi in dB - */ - virtual float read_rssi(void) = 0; - /******************************************************************* * RX methods ******************************************************************/ @@ -125,6 +118,13 @@ public: virtual bool get_rx_lo_locked(void) = 0; + /*! + * Read the RSSI value from a usrp device. + * Or throw if the dboard does not support an RSSI readback. + * \return the rssi in dB + */ + virtual float read_rssi(void) = 0; + /******************************************************************* * TX methods ******************************************************************/ diff --git a/host/lib/usrp/CMakeLists.txt b/host/lib/usrp/CMakeLists.txt index 3e12c087e..814affdd0 100644 --- a/host/lib/usrp/CMakeLists.txt +++ b/host/lib/usrp/CMakeLists.txt @@ -23,6 +23,7 @@ LIBUHD_APPEND_SOURCES( ${CMAKE_SOURCE_DIR}/lib/usrp/dboard_id.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/dboard_manager.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/dsp_utils.hpp + ${CMAKE_SOURCE_DIR}/lib/usrp/mimo_usrp.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/simple_usrp.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/tune_helper.cpp ) diff --git a/host/lib/usrp/mimo_usrp.cpp b/host/lib/usrp/mimo_usrp.cpp new file mode 100644 index 000000000..54c921ac7 --- /dev/null +++ b/host/lib/usrp/mimo_usrp.cpp @@ -0,0 +1,149 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace uhd; +using namespace uhd::usrp; + +/*********************************************************************** + * MIMO USRP Implementation + **********************************************************************/ +class mimo_usrp_impl : public mimo_usrp{ +public: + mimo_usrp_impl(const device_addr_t &addr){ + _dev = device::make(addr); + + //extract each mboard and its sub-devices + BOOST_FOREACH(const std::string &name, (*_dev)[DEVICE_PROP_MBOARD_NAMES].as()){ + _mboards.push_back((*_dev)[named_prop_t(DEVICE_PROP_MBOARD, name)]); + _rx_dsps.push_back(_mboards.back()[MBOARD_PROP_RX_DSP]); + _tx_dsps.push_back(_mboards.back()[MBOARD_PROP_TX_DSP]); + + //extract rx subdevice + _rx_dboards.push_back(_mboards.back()[MBOARD_PROP_RX_DBOARD]); + std::string rx_subdev_in_use = _rx_dboards.back()[DBOARD_PROP_USED_SUBDEVS].as().at(0); + _rx_subdevs.push_back(_rx_dboards.back()[named_prop_t(DBOARD_PROP_SUBDEV, rx_subdev_in_use)]); + + //extract tx subdevice + _tx_dboards.push_back(_mboards.back()[MBOARD_PROP_TX_DBOARD]); + std::string tx_subdev_in_use = _tx_dboards.back()[DBOARD_PROP_USED_SUBDEVS].as().at(0); + _tx_subdevs.push_back(_tx_dboards.back()[named_prop_t(DBOARD_PROP_SUBDEV, tx_subdev_in_use)]); + } + + //set the clock config across all mboards (TODO set through api) + clock_config_t clock_config; + clock_config.ref_source = clock_config_t::REF_SMA; + clock_config.pps_source = clock_config_t::PPS_SMA; + BOOST_FOREACH(wax::obj mboard, _mboards){ + mboard[MBOARD_PROP_CLOCK_CONFIG] = clock_config; + } + + } + + ~mimo_usrp_impl(void){ + /* NOP */ + } + + device::sptr get_device(void){ + return _dev; + } + + std::string get_pp_string(void){ + std::string buff = str(boost::format( + "MIMO USRP:\n" + " Device: %s\n" + ) + % (*_dev)[DEVICE_PROP_NAME].as() + ); + for (size_t i = 0; i < get_num_channels(); i++){ + buff += str(boost::format( + " Channel: %u\n" + " Mboard: %s\n" + " RX DSP: %s\n" + " RX Dboard: %s\n" + " RX Subdev: %s\n" + " TX DSP: %s\n" + " TX Dboard: %s\n" + " TX Subdev: %s\n" + ) % i + % _mboards.at(i)[MBOARD_PROP_NAME].as() + % _rx_dsps.at(i)[DSP_PROP_NAME].as() + % _rx_dboards.at(i)[DBOARD_PROP_NAME].as() + % _rx_subdevs.at(i)[SUBDEV_PROP_NAME].as() + % _tx_dsps.at(i)[DSP_PROP_NAME].as() + % _tx_dboards.at(i)[DBOARD_PROP_NAME].as() + % _tx_subdevs.at(i)[SUBDEV_PROP_NAME].as() + ); + } + return buff; + } + + size_t get_num_channels(void){ + return _mboards.size(); + } + + /******************************************************************* + * Misc + ******************************************************************/ + void set_time_next_pps(const time_spec_t &time_spec){ + BOOST_FOREACH(wax::obj mboard, _mboards){ + mboard[MBOARD_PROP_TIME_NEXT_PPS] = time_spec; + } + } + + void issue_stream_cmd(const stream_cmd_t &stream_cmd){ + BOOST_FOREACH(wax::obj mboard, _mboards){ + mboard[MBOARD_PROP_STREAM_CMD] = stream_cmd; + } + } + + /******************************************************************* + * RX methods + ******************************************************************/ + + /******************************************************************* + * TX methods + ******************************************************************/ + +private: + device::sptr _dev; + std::vector _mboards; + std::vector _rx_dsps; + std::vector _tx_dsps; + std::vector _rx_dboards; + std::vector _tx_dboards; + std::vector _rx_subdevs; + std::vector _tx_subdevs; +}; + +/*********************************************************************** + * The Make Function + **********************************************************************/ +mimo_usrp::sptr mimo_usrp::make(const device_addr_t &dev_addr){ + return sptr(new mimo_usrp_impl(dev_addr)); +} diff --git a/host/lib/usrp/simple_usrp.cpp b/host/lib/usrp/simple_usrp.cpp index f4aa82669..4a5171cf7 100644 --- a/host/lib/usrp/simple_usrp.cpp +++ b/host/lib/usrp/simple_usrp.cpp @@ -31,7 +31,7 @@ using namespace uhd; using namespace uhd::usrp; /*********************************************************************** - * Simple Device Implementation + * Simple USRP Implementation **********************************************************************/ class simple_usrp_impl : public simple_usrp{ public: @@ -60,7 +60,7 @@ public: return _dev; } - std::string get_name(void){ + std::string get_pp_string(void){ return str(boost::format( "Simple USRP:\n" " Device: %s\n" @@ -102,10 +102,6 @@ public: _mboard[MBOARD_PROP_CLOCK_CONFIG] = clock_config; } - float read_rssi(void){ - return _rx_subdev[SUBDEV_PROP_RSSI].as(); - } - /******************************************************************* * RX methods ******************************************************************/ @@ -157,6 +153,10 @@ public: return _rx_subdev[SUBDEV_PROP_LO_LOCKED].as(); } + float read_rssi(void){ + return _rx_subdev[SUBDEV_PROP_RSSI].as(); + } + /******************************************************************* * TX methods ******************************************************************/ diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index cdba19f50..3402c26b1 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -199,7 +199,8 @@ void usrp2_impl::get(const wax::obj &key_, wax::obj &val){ //handle the get request conditioned on the key switch(key.as()){ case DEVICE_PROP_NAME: - val = std::string("usrp2 device"); + if (_mboards.size() > 1) val = std::string("usrp2 mimo device"); + else val = std::string("usrp2 device"); return; case DEVICE_PROP_MBOARD: -- cgit v1.2.3 From 09ad8e1337c76ae9ca8bbf18791519fa786a286a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 2 Jul 2010 10:48:43 -0700 Subject: uhd: filled in mimo usrp rx and tx methods --- host/include/uhd/usrp/mimo_usrp.hpp | 40 ++++++++++++ host/include/uhd/utils/algorithm.hpp | 29 +++++++++ host/lib/usrp/mimo_usrp.cpp | 118 +++++++++++++++++++++++++++++++++++ 3 files changed, 187 insertions(+) (limited to 'host/include') diff --git a/host/include/uhd/usrp/mimo_usrp.hpp b/host/include/uhd/usrp/mimo_usrp.hpp index 8820c91c1..483feca29 100644 --- a/host/include/uhd/usrp/mimo_usrp.hpp +++ b/host/include/uhd/usrp/mimo_usrp.hpp @@ -94,10 +94,50 @@ public: /******************************************************************* * RX methods ******************************************************************/ + virtual void set_rx_rate_all(double rate) = 0; + virtual double get_rx_rate_all(void) = 0; + + virtual tune_result_t set_rx_freq(size_t chan, double freq) = 0; + virtual tune_result_t set_rx_freq(size_t chan, double freq, double lo_off) = 0; + virtual freq_range_t get_rx_freq_range(size_t chan) = 0; + + virtual void set_rx_gain(size_t chan, float gain) = 0; + virtual float get_rx_gain(size_t chan) = 0; + virtual gain_range_t get_rx_gain_range(size_t chan) = 0; + + virtual void set_rx_antenna(size_t chan, const std::string &ant) = 0; + virtual std::string get_rx_antenna(size_t chan) = 0; + virtual std::vector get_rx_antennas(size_t chan) = 0; + + virtual bool get_rx_lo_locked(size_t chan) = 0; + + /*! + * Read the RSSI value from a usrp device. + * Or throw if the dboard does not support an RSSI readback. + * \param chan which mimo channel 0 to N-1 + * \return the rssi in dB + */ + virtual float read_rssi(size_t chan) = 0; /******************************************************************* * TX methods ******************************************************************/ + virtual void set_tx_rate_all(double rate) = 0; + virtual double get_tx_rate_all(void) = 0; + + virtual tune_result_t set_tx_freq(size_t chan, double freq) = 0; + virtual tune_result_t set_tx_freq(size_t chan, double freq, double lo_off) = 0; + virtual freq_range_t get_tx_freq_range(size_t chan) = 0; + + virtual void set_tx_gain(size_t chan, float gain) = 0; + virtual float get_tx_gain(size_t chan) = 0; + virtual gain_range_t get_tx_gain_range(size_t chan) = 0; + + virtual void set_tx_antenna(size_t chan, const std::string &ant) = 0; + virtual std::string get_tx_antenna(size_t chan) = 0; + virtual std::vector get_tx_antennas(size_t chan) = 0; + + virtual bool get_tx_lo_locked(size_t chan) = 0; }; diff --git a/host/include/uhd/utils/algorithm.hpp b/host/include/uhd/utils/algorithm.hpp index 08977a69f..b52edc6b5 100644 --- a/host/include/uhd/utils/algorithm.hpp +++ b/host/include/uhd/utils/algorithm.hpp @@ -82,6 +82,35 @@ namespace std{ return boost::end(range) != std::find(boost::begin(range), boost::end(range), value); } + /*! + * Count the number of appearances of a value in a range. + * + * Uses std::count to count the appearances in the range. + * + * \param range the elements to iterate through + * \param value the value to count in the range + * \return the number of appearances of the value + */ + template inline + size_t count(const Range &range, const T &value){ + return std::count(boost::begin(range), boost::end(range), value); + } + + /*! + * Are the ranges equal (are their elements equivalent)? + * + * Uses std::equal to search the iterable for an element. + * + * \param range1 the first range of elements + * \param range2 the second range of elements + * \return true when the elements are equivalent + */ + template inline + bool equal(const Range &range1, const Range &range2){ + return (boost::size(range1) == boost::size(range2)) and + std::equal(boost::begin(range1), boost::end(range1), boost::begin(range2)); + } + /*! * A templated signum implementation. * \param n the comparable to process diff --git a/host/lib/usrp/mimo_usrp.cpp b/host/lib/usrp/mimo_usrp.cpp index 54c921ac7..3c9788388 100644 --- a/host/lib/usrp/mimo_usrp.cpp +++ b/host/lib/usrp/mimo_usrp.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -125,10 +126,124 @@ public: /******************************************************************* * RX methods ******************************************************************/ + void set_rx_rate_all(double rate){ + std::vector _actual_rates; + BOOST_FOREACH(wax::obj rx_dsp, _rx_dsps){ + rx_dsp[DSP_PROP_HOST_RATE] = rate; + _actual_rates.push_back(rx_dsp[DSP_PROP_HOST_RATE].as()); + } + _rx_rate = _actual_rates.front(); + if (std::count(_actual_rates, _rx_rate) != _actual_rates.size()) throw std::runtime_error( + "MIMO configuratio error: rx rate inconsistent across mboards" + ); + } + + double get_rx_rate_all(void){ + return _rx_rate; + } + + tune_result_t set_rx_freq(size_t chan, double target_freq){ + return tune_rx_subdev_and_ddc(_rx_subdevs.at(chan), _rx_dsps.at(chan), target_freq); + } + + tune_result_t set_rx_freq(size_t chan, double target_freq, double lo_off){ + return tune_rx_subdev_and_ddc(_rx_subdevs.at(chan), _rx_dsps.at(chan), target_freq, lo_off); + } + + freq_range_t get_rx_freq_range(size_t chan){ + return _rx_subdevs.at(chan)[SUBDEV_PROP_FREQ_RANGE].as(); + } + + void set_rx_gain(size_t chan, float gain){ + _rx_subdevs.at(chan)[SUBDEV_PROP_GAIN] = gain; + } + + float get_rx_gain(size_t chan){ + return _rx_subdevs.at(chan)[SUBDEV_PROP_GAIN].as(); + } + + gain_range_t get_rx_gain_range(size_t chan){ + return _rx_subdevs.at(chan)[SUBDEV_PROP_GAIN_RANGE].as(); + } + + void set_rx_antenna(size_t chan, const std::string &ant){ + _rx_subdevs.at(chan)[SUBDEV_PROP_ANTENNA] = ant; + } + + std::string get_rx_antenna(size_t chan){ + return _rx_subdevs.at(chan)[SUBDEV_PROP_ANTENNA].as(); + } + + std::vector get_rx_antennas(size_t chan){ + return _rx_subdevs.at(chan)[SUBDEV_PROP_ANTENNA_NAMES].as(); + } + + bool get_rx_lo_locked(size_t chan){ + return _rx_subdevs.at(chan)[SUBDEV_PROP_LO_LOCKED].as(); + } + + float read_rssi(size_t chan){ + return _rx_subdevs.at(chan)[SUBDEV_PROP_RSSI].as(); + } /******************************************************************* * TX methods ******************************************************************/ + void set_tx_rate_all(double rate){ + std::vector _actual_rates; + BOOST_FOREACH(wax::obj tx_dsp, _tx_dsps){ + tx_dsp[DSP_PROP_HOST_RATE] = rate; + _actual_rates.push_back(tx_dsp[DSP_PROP_HOST_RATE].as()); + } + _tx_rate = _actual_rates.front(); + if (std::count(_actual_rates, _tx_rate) != _actual_rates.size()) throw std::runtime_error( + "MIMO configuratio error: tx rate inconsistent across mboards" + ); + } + + double get_tx_rate_all(void){ + return _rx_rate; + } + + tune_result_t set_tx_freq(size_t chan, double target_freq){ + return tune_tx_subdev_and_duc(_tx_subdevs.at(chan), _tx_dsps.at(chan), target_freq); + } + + tune_result_t set_tx_freq(size_t chan, double target_freq, double lo_off){ + return tune_tx_subdev_and_duc(_tx_subdevs.at(chan), _tx_dsps.at(chan), target_freq, lo_off); + } + + freq_range_t get_tx_freq_range(size_t chan){ + return _tx_subdevs.at(chan)[SUBDEV_PROP_FREQ_RANGE].as(); + } + + void set_tx_gain(size_t chan, float gain){ + _tx_subdevs.at(chan)[SUBDEV_PROP_GAIN] = gain; + } + + float get_tx_gain(size_t chan){ + return _tx_subdevs.at(chan)[SUBDEV_PROP_GAIN].as(); + } + + gain_range_t get_tx_gain_range(size_t chan){ + return _tx_subdevs.at(chan)[SUBDEV_PROP_GAIN_RANGE].as(); + } + + void set_tx_antenna(size_t chan, const std::string &ant){ + _tx_subdevs.at(chan)[SUBDEV_PROP_ANTENNA] = ant; + } + + std::string get_tx_antenna(size_t chan){ + return _tx_subdevs.at(chan)[SUBDEV_PROP_ANTENNA].as(); + } + + std::vector get_tx_antennas(size_t chan){ + return _tx_subdevs.at(chan)[SUBDEV_PROP_ANTENNA_NAMES].as(); + } + + bool get_tx_lo_locked(size_t chan){ + return _tx_subdevs.at(chan)[SUBDEV_PROP_LO_LOCKED].as(); + } private: device::sptr _dev; @@ -139,6 +254,9 @@ private: std::vector _tx_dboards; std::vector _rx_subdevs; std::vector _tx_subdevs; + + //shadows + double _rx_rate, _tx_rate; }; /*********************************************************************** -- cgit v1.2.3 From 37bc860d52c937fb35925af3590d9bca1ecad559 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 2 Jul 2010 18:29:19 -0700 Subject: mimo: added call to set time to zero at next pps on init --- host/include/uhd/usrp/mimo_usrp.hpp | 1 + host/lib/usrp/mimo_usrp.cpp | 4 ++++ 2 files changed, 5 insertions(+) (limited to 'host/include') diff --git a/host/include/uhd/usrp/mimo_usrp.hpp b/host/include/uhd/usrp/mimo_usrp.hpp index 483feca29..a3cbde483 100644 --- a/host/include/uhd/usrp/mimo_usrp.hpp +++ b/host/include/uhd/usrp/mimo_usrp.hpp @@ -75,6 +75,7 @@ public: * The values will not be latched in until the pulse occurs. * It is recommended that the user sleep(1) after calling to ensure * that the time registers will be in a known state prior to use. + * This call works across all mboards in the mimo configuration. * * Note: Because this call sets the time on the "next" pps, * the seconds in the time spec should be current seconds + 1. diff --git a/host/lib/usrp/mimo_usrp.cpp b/host/lib/usrp/mimo_usrp.cpp index 3c9788388..bd7753d09 100644 --- a/host/lib/usrp/mimo_usrp.cpp +++ b/host/lib/usrp/mimo_usrp.cpp @@ -64,6 +64,10 @@ public: mboard[MBOARD_PROP_CLOCK_CONFIG] = clock_config; } + //set the times to zero at the next pps and sleep + this->set_time_next_pps(time_spec_t(0, 0)); + sleep(1); + } ~mimo_usrp_impl(void){ -- cgit v1.2.3 From 11f2aa1ea0fd6c28a20c6d85f94e41a06b3a6770 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 3 Jul 2010 16:50:45 -0700 Subject: uhd: replaced old send and recv with inline wrappers that take a single buffer and look more like the vectored send/recv --- host/examples/benchmark_rx_rate.cpp | 4 +-- host/examples/rx_timed_samples.cpp | 2 +- host/examples/tx_timed_samples.cpp | 4 +-- host/include/uhd/device.hpp | 53 +++++++++++++++++-------------- host/lib/transport/vrt_packet_handler.hpp | 1 - 5 files changed, 34 insertions(+), 30 deletions(-) (limited to 'host/include') diff --git a/host/examples/benchmark_rx_rate.cpp b/host/examples/benchmark_rx_rate.cpp index e7e358e4c..6984d7eff 100644 --- a/host/examples/benchmark_rx_rate.cpp +++ b/host/examples/benchmark_rx_rate.cpp @@ -49,7 +49,7 @@ static inline void test_device( sdev->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS); do { size_t num_rx_samps = dev->recv( - boost::asio::buffer(buff), md, + &buff.front(), buff.size(), md, uhd::io_type_t::COMPLEX_FLOAT32, uhd::device::RECV_MODE_ONE_PACKET ); @@ -79,7 +79,7 @@ static inline void test_device( //flush the buffers while(dev->recv( - boost::asio::buffer(buff), md, + &buff.front(), buff.size(), md, uhd::io_type_t::COMPLEX_FLOAT32, uhd::device::RECV_MODE_ONE_PACKET )); diff --git a/host/examples/rx_timed_samples.cpp b/host/examples/rx_timed_samples.cpp index 3c3c3fdc6..9ff8772bc 100644 --- a/host/examples/rx_timed_samples.cpp +++ b/host/examples/rx_timed_samples.cpp @@ -85,7 +85,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ uhd::rx_metadata_t md; std::vector > buff(dev->get_max_recv_samps_per_packet()); size_t num_rx_samps = dev->recv( - boost::asio::buffer(buff), md, + &buff.front(), buff.size(), md, uhd::io_type_t::COMPLEX_FLOAT32, uhd::device::RECV_MODE_ONE_PACKET ); diff --git a/host/examples/tx_timed_samples.cpp b/host/examples/tx_timed_samples.cpp index 846d9b6f4..4226aa4c8 100644 --- a/host/examples/tx_timed_samples.cpp +++ b/host/examples/tx_timed_samples.cpp @@ -81,8 +81,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //send the entire buffer, let the driver handle fragmentation size_t num_tx_samps = dev->send( - boost::asio::buffer(buff), - md, uhd::io_type_t::COMPLEX_FLOAT32, + &buff.front(), buff.size(), md, + uhd::io_type_t::COMPLEX_FLOAT32, uhd::device::SEND_MODE_FULL_BUFF ); std::cout << std::endl << boost::format("Sent %d samples") % num_tx_samps << std::endl; diff --git a/host/include/uhd/device.hpp b/host/include/uhd/device.hpp index f04a5b4fb..e5ef1181f 100644 --- a/host/include/uhd/device.hpp +++ b/host/include/uhd/device.hpp @@ -26,7 +26,6 @@ #include #include #include -#include #include namespace uhd{ @@ -97,20 +96,6 @@ public: RECV_MODE_ONE_PACKET = 1 }; - //! wrapper call for single buffer recv //TODO put somewhere - size_t send( - const boost::asio::const_buffer &buff, - const tx_metadata_t &metadata, - const io_type_t &io_type, - send_mode_t send_mode - ){ - return send( - std::vector(1, boost::asio::buffer_cast(buff)), - boost::asio::buffer_size(buff)/io_type.size, - metadata, io_type, send_mode - ); - } - /*! * Send buffers containing IF data described by the metadata. * @@ -140,17 +125,20 @@ public: send_mode_t send_mode ) = 0; - //! wrapper call for single buffer recv //TODO put somewhere - size_t recv( - const boost::asio::mutable_buffer &buff, - rx_metadata_t &metadata, + /*! + * Convenience wrapper for send that takes a single buffer. + */ + inline size_t send( + const void *buff, + size_t nsamps_per_buff, + const tx_metadata_t &metadata, const io_type_t &io_type, - recv_mode_t recv_mode + send_mode_t send_mode ){ - return recv( - std::vector(1, boost::asio::buffer_cast(buff)), - boost::asio::buffer_size(buff)/io_type.size, - metadata, io_type, recv_mode + return send( + std::vector(1, buff), + nsamps_per_buff, metadata, + io_type, send_mode ); } @@ -195,6 +183,23 @@ public: recv_mode_t recv_mode ) = 0; + /*! + * Convenience wrapper for recv that takes a single buffer. + */ + inline size_t recv( + void *buff, + size_t nsamps_per_buff, + rx_metadata_t &metadata, + const io_type_t &io_type, + recv_mode_t recv_mode + ){ + return recv( + std::vector(1, buff), + nsamps_per_buff, metadata, + io_type, recv_mode + ); + } + /*! * Get the maximum number of samples per packet on send. * \return the number of samples diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp index 31b7e6614..42cbb7e5a 100644 --- a/host/lib/transport/vrt_packet_handler.hpp +++ b/host/lib/transport/vrt_packet_handler.hpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include -- cgit v1.2.3 From 5e14653f241070791d46893e68e341357e040add Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 4 Jul 2010 19:13:59 -0700 Subject: usrp2: bug fix for readback registers added readback for time64 fixed bug for fragment flag in vrt packet handler --- host/include/uhd/transport/zero_copy.hpp | 8 ++++---- host/include/uhd/usrp/mboard_props.hpp | 2 +- host/lib/transport/vrt_packet_handler.hpp | 18 +++++++++--------- host/lib/usrp/usrp2/fw_common.h | 2 +- host/lib/usrp/usrp2/mboard_impl.cpp | 10 ++++++++++ host/lib/usrp/usrp2/usrp2_regs.hpp | 10 ++++++---- 6 files changed, 31 insertions(+), 19 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/transport/zero_copy.hpp b/host/include/uhd/transport/zero_copy.hpp index 2815e3189..da10bfbe2 100644 --- a/host/include/uhd/transport/zero_copy.hpp +++ b/host/include/uhd/transport/zero_copy.hpp @@ -47,7 +47,7 @@ namespace uhd{ namespace transport{ * Get the size of the underlying buffer. * \return the number of bytes */ - size_t size(void) const{ + inline size_t size(void) const{ return boost::asio::buffer_size(this->get()); } @@ -55,7 +55,7 @@ namespace uhd{ namespace transport{ * Get a pointer to the underlying buffer. * \return a pointer into memory */ - template T cast(void) const{ + template inline T cast(void) const{ return boost::asio::buffer_cast(this->get()); } @@ -89,7 +89,7 @@ namespace uhd{ namespace transport{ * Get the size of the underlying buffer. * \return the number of bytes */ - size_t size(void) const{ + inline size_t size(void) const{ return boost::asio::buffer_size(this->get()); } @@ -97,7 +97,7 @@ namespace uhd{ namespace transport{ * Get a pointer to the underlying buffer. * \return a pointer into memory */ - template T cast(void) const{ + template inline T cast(void) const{ return boost::asio::buffer_cast(this->get()); } diff --git a/host/include/uhd/usrp/mboard_props.hpp b/host/include/uhd/usrp/mboard_props.hpp index 7ff454472..a432ce50c 100644 --- a/host/include/uhd/usrp/mboard_props.hpp +++ b/host/include/uhd/usrp/mboard_props.hpp @@ -40,7 +40,7 @@ namespace uhd{ namespace usrp{ MBOARD_PROP_TX_DBOARD = 'v', //ro, wax::obj MBOARD_PROP_TX_DBOARD_NAMES = 'V', //ro, prop_names_t MBOARD_PROP_CLOCK_CONFIG = 'C', //rw, clock_config_t - MBOARD_PROP_TIME_NOW = 't', //wo, time_spec_t + MBOARD_PROP_TIME_NOW = 't', //rw, time_spec_t MBOARD_PROP_TIME_NEXT_PPS = 'T', //wo, time_spec_t MBOARD_PROP_STREAM_CMD = 's' //wo, stream_cmd_t }; diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp index 42cbb7e5a..177239509 100644 --- a/host/lib/transport/vrt_packet_handler.hpp +++ b/host/lib/transport/vrt_packet_handler.hpp @@ -151,20 +151,15 @@ namespace vrt_packet_handler{ //extract the number of samples available to copy size_t bytes_per_item = otw_type.get_sample_size(); size_t bytes_available = state.size_of_copy_buffs; - size_t num_samps = std::min(total_samps, bytes_available/bytes_per_item); - size_t bytes_to_copy = num_samps*bytes_per_item; - - //setup the fragment flags and offset - metadata.more_fragments = total_samps < num_samps; - metadata.fragment_offset = state.fragment_offset_in_samps; - state.fragment_offset_in_samps += num_samps; //set for next call + size_t nsamps_to_copy = std::min(total_samps, bytes_available/bytes_per_item); + size_t bytes_to_copy = nsamps_to_copy*bytes_per_item; for (size_t i = 0; i < state.width; i++){ //copy-convert the samples from the recv buffer uhd::transport::convert_otw_type_to_io_type( state.copy_buffs[i], otw_type, reinterpret_cast(buffs[i]) + offset_bytes, - io_type, num_samps + io_type, nsamps_to_copy ); //update the rx copy buffer to reflect the bytes copied @@ -173,7 +168,12 @@ namespace vrt_packet_handler{ //update the copy buffer's availability state.size_of_copy_buffs -= bytes_to_copy; - return num_samps; + //setup the fragment flags and offset + metadata.more_fragments = state.size_of_copy_buffs != 0; + metadata.fragment_offset = state.fragment_offset_in_samps; + state.fragment_offset_in_samps += nsamps_to_copy; //set for next call + + return nsamps_to_copy; } /******************************************************************* diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index 242d268ec..12daa6286 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -38,7 +38,7 @@ extern "C" { //defines the protocol version in this shared header //increment this value when the protocol is changed -#define USRP2_PROTO_VERSION 4 +#define USRP2_PROTO_VERSION 5 //used to differentiate control packets over data port #define USRP2_INVALID_VRT_HEADER 0 diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 28a346be7..36ac6275f 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -25,6 +25,7 @@ #include #include #include +#include using namespace uhd; using namespace uhd::usrp; @@ -72,6 +73,7 @@ usrp2_mboard_impl::usrp2_mboard_impl( ); _iface->poke32(U2_REG_RX_CTRL_VRT_STREAM_ID, 0); _iface->poke32(U2_REG_RX_CTRL_VRT_TRAILER, 0); + _iface->poke32(U2_REG_TIME64_TPS, size_t(get_master_clock_freq())); //init the ddc init_ddc_config(); @@ -254,6 +256,14 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ val = _clock_config; return; + case MBOARD_PROP_TIME_NOW: + val = time_spec_t( + _iface->peek32(U2_REG_TIME64_SECS_RB), + _iface->peek32(U2_REG_TIME64_TICKS_RB), + get_master_clock_freq() + ); + return; + default: UHD_THROW_PROP_GET_ERROR(); } } diff --git a/host/lib/usrp/usrp2/usrp2_regs.hpp b/host/lib/usrp/usrp2/usrp2_regs.hpp index 589fa71a3..c859d3603 100644 --- a/host/lib/usrp/usrp2/usrp2_regs.hpp +++ b/host/lib/usrp/usrp2/usrp2_regs.hpp @@ -18,8 +18,6 @@ #ifndef INCLUDED_USRP2_REGS_HPP #define INCLUDED_USRP2_REGS_HPP -#include - //////////////////////////////////////////////////// // Settings Bus, Slave #7, Not Byte Addressable! // @@ -46,7 +44,7 @@ #define SR_SIMTIMER 198 #define SR_LAST 255 -#define _SR_ADDR(sr) (MISC_OUTPUT_BASE + (sr) * sizeof(boost::uint32_t)) +#define _SR_ADDR(sr) ((MISC_OUTPUT_BASE) + (4*(sr))) ///////////////////////////////////////////////// // SPI Slave Constants @@ -104,7 +102,11 @@ #define U2_REG_TIME64_SECS _SR_ADDR(SR_TIME64 + 0) // value to set absolute secs to on next PPS #define U2_REG_TIME64_TICKS _SR_ADDR(SR_TIME64 + 1) // value to set absolute ticks to on next PPS #define U2_REG_TIME64_FLAGS _SR_ADDR(SR_TIME64 + 2) // flags - see chart above -#define U2_REG_TIME64_IMM _SR_ADDR(SR_TIME64 + 3) // set immediate (0=latch on next pps, 1=latch immediate, default=0) +#define U2_REG_TIME64_IMM _SR_ADDR(SR_TIME64 + 3) // set immediate (0=latch on next pps, 1=latch immediate, default=0) +#define U2_REG_TIME64_TPS _SR_ADDR(SR_TIME64 + 4) // the ticks per second rollover count + +#define U2_REG_TIME64_SECS_RB (0xCC00 + 4*10) +#define U2_REG_TIME64_TICKS_RB (0xCC00 + 4*11) //pps flags (see above) #define U2_FLAG_TIME64_PPS_NEGEDGE (0 << 0) -- cgit v1.2.3 From 549a0170a409904f123a4eef975362978ca62bf3 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 4 Jul 2010 20:21:09 -0700 Subject: uhd: added get time now call to simple and mimo usrp --- host/include/uhd/usrp/mimo_usrp.hpp | 6 ++++++ host/include/uhd/usrp/simple_usrp.hpp | 6 ++++++ host/lib/usrp/mimo_usrp.cpp | 10 +++++----- host/lib/usrp/simple_usrp.cpp | 4 ++++ 4 files changed, 21 insertions(+), 5 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/usrp/mimo_usrp.hpp b/host/include/uhd/usrp/mimo_usrp.hpp index a3cbde483..e85c06046 100644 --- a/host/include/uhd/usrp/mimo_usrp.hpp +++ b/host/include/uhd/usrp/mimo_usrp.hpp @@ -70,6 +70,12 @@ public: /******************************************************************* * Misc ******************************************************************/ + /*! + * Gets the current time in the usrp time registers. + * \return a timespec representing current usrp time + */ + virtual time_spec_t get_time_now(void) = 0; + /*! * Set the time registers on the usrp at the next pps tick. * The values will not be latched in until the pulse occurs. diff --git a/host/include/uhd/usrp/simple_usrp.hpp b/host/include/uhd/usrp/simple_usrp.hpp index 1d817e030..1d9136f08 100644 --- a/host/include/uhd/usrp/simple_usrp.hpp +++ b/host/include/uhd/usrp/simple_usrp.hpp @@ -63,6 +63,12 @@ public: /******************************************************************* * Misc ******************************************************************/ + /*! + * Gets the current time in the usrp time registers. + * \return a timespec representing current usrp time + */ + virtual time_spec_t get_time_now(void) = 0; + /*! * Sets the time registers on the usrp immediately. * \param time_spec the time to latch into the usrp device diff --git a/host/lib/usrp/mimo_usrp.cpp b/host/lib/usrp/mimo_usrp.cpp index bd7753d09..440aaf9f6 100644 --- a/host/lib/usrp/mimo_usrp.cpp +++ b/host/lib/usrp/mimo_usrp.cpp @@ -63,11 +63,6 @@ public: BOOST_FOREACH(wax::obj mboard, _mboards){ mboard[MBOARD_PROP_CLOCK_CONFIG] = clock_config; } - - //set the times to zero at the next pps and sleep - this->set_time_next_pps(time_spec_t(0, 0)); - sleep(1); - } ~mimo_usrp_impl(void){ @@ -115,6 +110,11 @@ public: /******************************************************************* * Misc ******************************************************************/ + time_spec_t get_time_now(void){ + //the time on the first mboard better be the same on all + return _mboards.front()[MBOARD_PROP_TIME_NOW].as(); + } + void set_time_next_pps(const time_spec_t &time_spec){ BOOST_FOREACH(wax::obj mboard, _mboards){ mboard[MBOARD_PROP_TIME_NEXT_PPS] = time_spec; diff --git a/host/lib/usrp/simple_usrp.cpp b/host/lib/usrp/simple_usrp.cpp index 4a5171cf7..56e82d7ee 100644 --- a/host/lib/usrp/simple_usrp.cpp +++ b/host/lib/usrp/simple_usrp.cpp @@ -86,6 +86,10 @@ public: /******************************************************************* * Misc ******************************************************************/ + time_spec_t get_time_now(void){ + return _mboard[MBOARD_PROP_TIME_NOW].as(); + } + void set_time_now(const time_spec_t &time_spec){ _mboard[MBOARD_PROP_TIME_NOW] = time_spec; } -- cgit v1.2.3 From 8047f25c601c43d6941cd0d094360a56917917c8 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 5 Jul 2010 12:02:21 -0700 Subject: uhd: added clear capability to alignment buffer (fixes case when next seq is less than prev) --- host/include/uhd/transport/alignment_buffer.hpp | 22 +++++++++++++++++++++- host/include/uhd/transport/bounded_buffer.hpp | 10 ++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) (limited to 'host/include') diff --git a/host/include/uhd/transport/alignment_buffer.hpp b/host/include/uhd/transport/alignment_buffer.hpp index dc6ccc3ed..5766c2284 100644 --- a/host/include/uhd/transport/alignment_buffer.hpp +++ b/host/include/uhd/transport/alignment_buffer.hpp @@ -56,6 +56,11 @@ namespace uhd{ namespace transport{ const seq_type &seq, size_t index ){ + //clear the buffer for this index if the seqs are mis-ordered + if (seq < _last_seqs[index]){ + _buffs[index]->clear(); + _there_was_a_clear = true; + } _last_seqs[index] = seq; return _buffs[index]->push_with_pop_on_full(buff_contents_type(elem, seq)); } @@ -79,6 +84,18 @@ namespace uhd{ namespace transport{ //get an aligned set of elements from the buffers: while(indexes_to_do.size() != 0){ + + //respond to a clear by starting from scratch + if(_there_was_a_clear){ + _there_was_a_clear = false; + indexes_to_do = _all_indexes; + index = indexes_to_do.front(); + if (not _buffs[index]->pop_with_timed_wait(buff_contents_tmp, time)) return false; + elems[index] = buff_contents_tmp.first; + expected_seq_id = buff_contents_tmp.second; + indexes_to_do.pop_front(); + } + //pop an element off for this index index = indexes_to_do.front(); if (not _buffs[index]->pop_with_timed_wait(buff_contents_tmp, time)) return false; @@ -118,14 +135,17 @@ namespace uhd{ namespace transport{ typedef bounded_buffer bounded_buffer_type; typedef boost::shared_ptr bounded_buffer_sptr; std::vector _buffs; + std::vector _last_seqs; std::list _all_indexes; + bool _there_was_a_clear; //private constructor - alignment_buffer(size_t capacity, size_t width){ + alignment_buffer(size_t capacity, size_t width) : _last_seqs(width){ for (size_t i = 0; i < width; i++){ _buffs.push_back(bounded_buffer_type::make(capacity)); _all_indexes.push_back(i); } + _there_was_a_clear = false; } }; diff --git a/host/include/uhd/transport/bounded_buffer.hpp b/host/include/uhd/transport/bounded_buffer.hpp index baecd6382..94c360fba 100644 --- a/host/include/uhd/transport/bounded_buffer.hpp +++ b/host/include/uhd/transport/bounded_buffer.hpp @@ -129,6 +129,16 @@ namespace uhd{ namespace transport{ return true; } + /*! + * Clear all elements from the bounded_buffer. + */ + UHD_INLINE void clear(void){ + boost::unique_lock lock(_mutex); + while (not_empty()) _buffer.pop_back(); + lock.unlock(); + _full_cond.notify_one(); + } + private: boost::mutex _mutex; boost::condition _empty_cond, _full_cond; -- cgit v1.2.3 From a95eaac42f6cc85fd2ad3f32dc29eeab38ef5194 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 5 Jul 2010 19:12:01 -0700 Subject: usrp2: Added a peek64 to read pairs of 32 bit numbers such as time64 also added a templated host to/from network conversion in byteswap.hpp (didnt use it though) --- firmware/microblaze/apps/txrx_uhd.c | 8 ++++++++ host/include/uhd/utils/byteswap.hpp | 27 +++++++++++++++++++++++++++ host/lib/usrp/usrp2/fw_common.h | 4 +++- host/lib/usrp/usrp2/mboard_impl.cpp | 14 ++++++++------ host/lib/usrp/usrp2/usrp2_iface.cpp | 24 +++++++++++++++++++----- host/lib/usrp/usrp2/usrp2_iface.hpp | 10 ++++++++++ 6 files changed, 75 insertions(+), 12 deletions(-) (limited to 'host/include') diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index 21803b199..99c149d45 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -269,6 +269,10 @@ void handle_udp_ctrl_packet( printf("error! tried to poke into 0x%x\n", ctrl_data_in->data.poke_args.addr); } else switch(ctrl_data_in->data.poke_args.num_bytes){ + case sizeof(uint64_t): + *((uint32_t *) ctrl_data_in->data.poke_args.addrhi) = (uint32_t)ctrl_data_in->data.poke_args.datahi; + //continue to uint32_t for low addr: + case sizeof(uint32_t): *((uint32_t *) ctrl_data_in->data.poke_args.addr) = (uint32_t)ctrl_data_in->data.poke_args.data; break; @@ -287,6 +291,10 @@ void handle_udp_ctrl_packet( case USRP2_CTRL_ID_PEEK_AT_THIS_REGISTER_FOR_ME_BRO: switch(ctrl_data_in->data.poke_args.num_bytes){ + case sizeof(uint64_t): + ctrl_data_out.data.poke_args.datahi = *((uint32_t *) ctrl_data_in->data.poke_args.addrhi); + //continue to uint32_t for low addr: + case sizeof(uint32_t): ctrl_data_out.data.poke_args.data = *((uint32_t *) ctrl_data_in->data.poke_args.addr); break; diff --git a/host/include/uhd/utils/byteswap.hpp b/host/include/uhd/utils/byteswap.hpp index dd5dcbc09..26d60c2ab 100644 --- a/host/include/uhd/utils/byteswap.hpp +++ b/host/include/uhd/utils/byteswap.hpp @@ -37,6 +37,12 @@ namespace uhd{ //! perform a byteswap on a 64 bit integer boost::uint64_t byteswap(boost::uint64_t); + //! network to host: short, long, or long-long + template T ntohx(T); + + //! host to network: short, long, or long-long + template T htonx(T); + } //namespace uhd /*********************************************************************** @@ -117,4 +123,25 @@ namespace uhd{ #endif +/*********************************************************************** + * Define the templated network to/from host conversions + **********************************************************************/ +#include + +template UHD_INLINE T uhd::ntohx(T num){ + #ifdef BOOST_BIG_ENDIAN + return num; + #else + return uhd::byteswap(num); + #endif +} + +template UHD_INLINE T uhd::htonx(T num){ + #ifdef BOOST_BIG_ENDIAN + return num; + #else + return uhd::byteswap(num); + #endif +} + #endif /* INCLUDED_UHD_UTILS_BYTESWAP_HPP */ diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index 12daa6286..4c66aa41e 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -111,7 +111,9 @@ typedef struct{ struct { _SINS_ uint32_t addr; _SINS_ uint32_t data; - _SINS_ uint8_t num_bytes; //1, 2, 4 + _SINS_ uint32_t addrhi; + _SINS_ uint32_t datahi; + _SINS_ uint8_t num_bytes; //1, 2, 4, 8 } poke_args; } data; } usrp2_ctrl_data_t; diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 36ac6275f..952954286 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -256,12 +256,14 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ val = _clock_config; return; - case MBOARD_PROP_TIME_NOW: - val = time_spec_t( - _iface->peek32(U2_REG_TIME64_SECS_RB), - _iface->peek32(U2_REG_TIME64_TICKS_RB), - get_master_clock_freq() - ); + case MBOARD_PROP_TIME_NOW:{ + usrp2_iface::pair64 time64( + _iface->peek64(U2_REG_TIME64_SECS_RB, U2_REG_TIME64_TICKS_RB) + ); + val = time_spec_t( + time64.first, time64.second, get_master_clock_freq() + ); + } return; default: UHD_THROW_PROP_GET_ERROR(); diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 66a1a57f6..faf4a5c7e 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -59,6 +59,20 @@ public: return this->peek(addr); } + pair64 peek64(boost::uint32_t addrlo, boost::uint32_t addrhi){ + //setup the out data + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_PEEK_AT_THIS_REGISTER_FOR_ME_BRO); + out_data.data.poke_args.addr = htonl(addrlo); + out_data.data.poke_args.addrhi = htonl(addrhi); + out_data.data.poke_args.num_bytes = sizeof(boost::uint64_t); + + //send and recv + usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data); + UHD_ASSERT_THROW(ntohl(in_data.id) == USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE); + return pair64(ntohl(in_data.data.poke_args.data), ntohl(in_data.data.poke_args.datahi)); + } + /*********************************************************************** * SPI **********************************************************************/ @@ -86,7 +100,7 @@ public: //send and recv usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data); - UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE); + UHD_ASSERT_THROW(ntohl(in_data.id) == USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE); return ntohl(in_data.data.spi_args.data); } @@ -109,7 +123,7 @@ public: //send and recv usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data); - UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE); + UHD_ASSERT_THROW(ntohl(in_data.id) == USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE); } byte_vector_t read_i2c(boost::uint8_t addr, size_t num_bytes){ @@ -124,7 +138,7 @@ public: //send and recv usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data); - UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_HERES_THE_I2C_DATA_DUDE); + UHD_ASSERT_THROW(ntohl(in_data.id) == USRP2_CTRL_ID_HERES_THE_I2C_DATA_DUDE); UHD_ASSERT_THROW(in_data.data.i2c_args.addr = num_bytes); //copy out the data @@ -187,7 +201,7 @@ private: //send and recv usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data); - UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_OMG_POKED_REGISTER_SO_BAD_DUDE); + UHD_ASSERT_THROW(ntohl(in_data.id) == USRP2_CTRL_ID_OMG_POKED_REGISTER_SO_BAD_DUDE); } template T peek(boost::uint32_t addr){ @@ -199,7 +213,7 @@ private: //send and recv usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data); - UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE); + UHD_ASSERT_THROW(ntohl(in_data.id) == USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE); return T(ntohl(in_data.data.poke_args.data)); } diff --git a/host/lib/usrp/usrp2/usrp2_iface.hpp b/host/lib/usrp/usrp2/usrp2_iface.hpp index 7b2a3a89d..9cc32104e 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.hpp +++ b/host/lib/usrp/usrp2/usrp2_iface.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "fw_common.h" //////////////////////////////////////////////////////////////////////// @@ -49,6 +50,7 @@ class usrp2_iface : public uhd::i2c_iface, boost::noncopyable{ public: typedef boost::shared_ptr sptr; + typedef std::pair pair64; /*! * Make a new usrp2 interface with the control transport. @@ -64,6 +66,14 @@ public: */ virtual usrp2_ctrl_data_t ctrl_send_and_recv(const usrp2_ctrl_data_t &data) = 0; + /*! + * Read a dual register (64 bits) + * \param addrlo the address for the low-32 bits + * \param addrhi the address for the high-32 bits + * \return a pair of 32 bit integers lo, hi + */ + virtual pair64 peek64(boost::uint32_t addrlo, boost::uint32_t addrhi) = 0; + /*! * Write a register (32 bits) * \param addr the address -- cgit v1.2.3 From 4840c5bc95771e8f2485e002da0d81521cb4a16c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 5 Jul 2010 21:17:49 -0700 Subject: uhd: moved header file implementation code into ipp files byteswap, bounded_buffer, and alignment_buffer --- host/include/uhd/transport/CMakeLists.txt | 2 + host/include/uhd/transport/alignment_buffer.hpp | 104 ++---------------- host/include/uhd/transport/alignment_buffer.ipp | 140 ++++++++++++++++++++++++ host/include/uhd/transport/bounded_buffer.hpp | 86 +++------------ host/include/uhd/transport/bounded_buffer.ipp | 112 +++++++++++++++++++ host/include/uhd/utils/CMakeLists.txt | 1 + host/include/uhd/utils/byteswap.hpp | 99 +---------------- host/include/uhd/utils/byteswap.ipp | 120 ++++++++++++++++++++ 8 files changed, 401 insertions(+), 263 deletions(-) create mode 100644 host/include/uhd/transport/alignment_buffer.ipp create mode 100644 host/include/uhd/transport/bounded_buffer.ipp create mode 100644 host/include/uhd/utils/byteswap.ipp (limited to 'host/include') diff --git a/host/include/uhd/transport/CMakeLists.txt b/host/include/uhd/transport/CMakeLists.txt index 4e1f7aca5..93e9a6485 100644 --- a/host/include/uhd/transport/CMakeLists.txt +++ b/host/include/uhd/transport/CMakeLists.txt @@ -18,7 +18,9 @@ INSTALL(FILES alignment_buffer.hpp + alignment_buffer.ipp bounded_buffer.hpp + bounded_buffer.ipp convert_types.hpp if_addrs.hpp udp_simple.hpp diff --git a/host/include/uhd/transport/alignment_buffer.hpp b/host/include/uhd/transport/alignment_buffer.hpp index 5766c2284..29ba74efc 100644 --- a/host/include/uhd/transport/alignment_buffer.hpp +++ b/host/include/uhd/transport/alignment_buffer.hpp @@ -19,16 +19,14 @@ #define INCLUDED_UHD_TRANSPORT_ALIGNMENT_BUFFER_HPP #include -#include -#include +#include //time_duration_t #include -#include #include namespace uhd{ namespace transport{ /*! - * Imlement a templated alignment buffer: + * Implement a templated alignment buffer: * Used for aligning asynchronously pushed elements with matching ids. */ template class alignment_buffer{ @@ -40,9 +38,7 @@ namespace uhd{ namespace transport{ * \param capacity the maximum elements per index * \param width the number of elements to align */ - static sptr make(size_t capacity, size_t width){ - return sptr(new alignment_buffer(capacity, width)); - } + static sptr make(size_t capacity, size_t width); /*! * Push an element with sequence id into the buffer at index. @@ -51,18 +47,11 @@ namespace uhd{ namespace transport{ * \param index the buffer index * \return true if the element fit without popping for space */ - UHD_INLINE bool push_with_pop_on_full( + virtual bool push_with_pop_on_full( const elem_type &elem, const seq_type &seq, size_t index - ){ - //clear the buffer for this index if the seqs are mis-ordered - if (seq < _last_seqs[index]){ - _buffs[index]->clear(); - _there_was_a_clear = true; - } _last_seqs[index] = seq; - return _buffs[index]->push_with_pop_on_full(buff_contents_type(elem, seq)); - } + ) = 0; /*! * Pop an aligned set of elements from this alignment buffer. @@ -70,85 +59,14 @@ namespace uhd{ namespace transport{ * \param time the timeout time * \return false when the operation times out */ - template - bool pop_elems_with_timed_wait(elems_type &elems, const time_type &time){ - buff_contents_type buff_contents_tmp; - std::list indexes_to_do(_all_indexes); - - //do an initial pop to load an initial sequence id - size_t index = indexes_to_do.front(); - if (not _buffs[index]->pop_with_timed_wait(buff_contents_tmp, time)) return false; - elems[index] = buff_contents_tmp.first; - seq_type expected_seq_id = buff_contents_tmp.second; - indexes_to_do.pop_front(); - - //get an aligned set of elements from the buffers: - while(indexes_to_do.size() != 0){ - - //respond to a clear by starting from scratch - if(_there_was_a_clear){ - _there_was_a_clear = false; - indexes_to_do = _all_indexes; - index = indexes_to_do.front(); - if (not _buffs[index]->pop_with_timed_wait(buff_contents_tmp, time)) return false; - elems[index] = buff_contents_tmp.first; - expected_seq_id = buff_contents_tmp.second; - indexes_to_do.pop_front(); - } - - //pop an element off for this index - index = indexes_to_do.front(); - if (not _buffs[index]->pop_with_timed_wait(buff_contents_tmp, time)) return false; - - //if the sequence id matches: - // store the popped element into the output, - // remove this index from the list and continue - if (buff_contents_tmp.second == expected_seq_id){ - elems[index] = buff_contents_tmp.first; - indexes_to_do.pop_front(); - continue; - } - - //if the sequence id is older: - // continue with the same index to try again - if (buff_contents_tmp.second < expected_seq_id){ - continue; - } - - //if the sequence id is newer: - // store the popped element into the output, - // add all other indexes back into the list - if (buff_contents_tmp.second > expected_seq_id){ - elems[index] = buff_contents_tmp.first; - expected_seq_id = buff_contents_tmp.second; - indexes_to_do = _all_indexes; - indexes_to_do.remove(index); - continue; - } - } - return true; - } - - private: - //a vector of bounded buffers for each index - typedef std::pair buff_contents_type; - typedef bounded_buffer bounded_buffer_type; - typedef boost::shared_ptr bounded_buffer_sptr; - std::vector _buffs; - std::vector _last_seqs; - std::list _all_indexes; - bool _there_was_a_clear; - - //private constructor - alignment_buffer(size_t capacity, size_t width) : _last_seqs(width){ - for (size_t i = 0; i < width; i++){ - _buffs.push_back(bounded_buffer_type::make(capacity)); - _all_indexes.push_back(i); - } - _there_was_a_clear = false; - } + virtual bool pop_elems_with_timed_wait( + std::vector &elems, + const time_duration_t &time + ) = 0; }; }} //namespace +#include + #endif /* INCLUDED_UHD_TRANSPORT_ALIGNMENT_BUFFER_HPP */ diff --git a/host/include/uhd/transport/alignment_buffer.ipp b/host/include/uhd/transport/alignment_buffer.ipp new file mode 100644 index 000000000..f89f2886e --- /dev/null +++ b/host/include/uhd/transport/alignment_buffer.ipp @@ -0,0 +1,140 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#ifndef INCLUDED_UHD_TRANSPORT_ALIGNMENT_BUFFER_IPP +#define INCLUDED_UHD_TRANSPORT_ALIGNMENT_BUFFER_IPP + +#include +#include +#include + +namespace uhd{ namespace transport{ namespace{ /*anon*/ + + /*! + * Imlement a templated alignment buffer: + * Used for aligning asynchronously pushed elements with matching ids. + */ + template + class alignment_buffer_impl : public alignment_buffer{ + public: + + alignment_buffer_impl(size_t capacity, size_t width) : _last_seqs(width){ + for (size_t i = 0; i < width; i++){ + _buffs.push_back(bounded_buffer::make(capacity)); + _all_indexes.push_back(i); + } + _there_was_a_clear = false; + } + + UHD_INLINE bool push_with_pop_on_full( + const elem_type &elem, + const seq_type &seq, + size_t index + ){ + //clear the buffer for this index if the seqs are mis-ordered + if (seq < _last_seqs[index]){ + _buffs[index]->clear(); + _there_was_a_clear = true; + } _last_seqs[index] = seq; + return _buffs[index]->push_with_pop_on_full(buff_contents_type(elem, seq)); + } + + UHD_INLINE bool pop_elems_with_timed_wait( + std::vector &elems, + const time_duration_t &time + ){ + buff_contents_type buff_contents_tmp; + std::list indexes_to_do(_all_indexes); + + //do an initial pop to load an initial sequence id + size_t index = indexes_to_do.front(); + if (not _buffs[index]->pop_with_timed_wait(buff_contents_tmp, time)) return false; + elems[index] = buff_contents_tmp.first; + seq_type expected_seq_id = buff_contents_tmp.second; + indexes_to_do.pop_front(); + + //get an aligned set of elements from the buffers: + while(indexes_to_do.size() != 0){ + + //respond to a clear by starting from scratch + if(_there_was_a_clear){ + _there_was_a_clear = false; + indexes_to_do = _all_indexes; + index = indexes_to_do.front(); + if (not _buffs[index]->pop_with_timed_wait(buff_contents_tmp, time)) return false; + elems[index] = buff_contents_tmp.first; + expected_seq_id = buff_contents_tmp.second; + indexes_to_do.pop_front(); + } + + //pop an element off for this index + index = indexes_to_do.front(); + if (not _buffs[index]->pop_with_timed_wait(buff_contents_tmp, time)) return false; + + //if the sequence id matches: + // store the popped element into the output, + // remove this index from the list and continue + if (buff_contents_tmp.second == expected_seq_id){ + elems[index] = buff_contents_tmp.first; + indexes_to_do.pop_front(); + continue; + } + + //if the sequence id is older: + // continue with the same index to try again + if (buff_contents_tmp.second < expected_seq_id){ + continue; + } + + //if the sequence id is newer: + // store the popped element into the output, + // add all other indexes back into the list + if (buff_contents_tmp.second > expected_seq_id){ + elems[index] = buff_contents_tmp.first; + expected_seq_id = buff_contents_tmp.second; + indexes_to_do = _all_indexes; + indexes_to_do.remove(index); + continue; + } + } + return true; + } + + private: + //a vector of bounded buffers for each index + typedef std::pair buff_contents_type; + std::vector::sptr> _buffs; + std::vector _last_seqs; + std::list _all_indexes; + bool _there_was_a_clear; + }; + +}}} //namespace + +namespace uhd{ namespace transport{ + + template + typename alignment_buffer::sptr + alignment_buffer::make(size_t capacity, size_t width){ + return alignment_buffer::sptr( + new alignment_buffer_impl(capacity, width) + ); + } + +}} //namespace + +#endif /* INCLUDED_UHD_TRANSPORT_ALIGNMENT_BUFFER_IPP */ diff --git a/host/include/uhd/transport/bounded_buffer.hpp b/host/include/uhd/transport/bounded_buffer.hpp index 94c360fba..d1deece96 100644 --- a/host/include/uhd/transport/bounded_buffer.hpp +++ b/host/include/uhd/transport/bounded_buffer.hpp @@ -19,15 +19,16 @@ #define INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_HPP #include -#include #include -#include -#include +#include namespace uhd{ namespace transport{ + //! typedef for the time duration type for wait operations + typedef boost::posix_time::time_duration time_duration_t; + /*! - * Imlement a templated bounded buffer: + * Implement a templated bounded buffer: * Used for passing elements between threads in a producer-consumer model. * The bounded buffer implemented waits and timed waits with condition variables. * The pop operation blocks on the bounded_buffer to become non empty. @@ -41,9 +42,7 @@ namespace uhd{ namespace transport{ * Make a new bounded buffer object. * \param capacity the bounded_buffer capacity */ - static sptr make(size_t capacity){ - return sptr(new bounded_buffer(capacity)); - } + static sptr make(size_t capacity); /*! * Push a new element into the bounded buffer. @@ -52,35 +51,14 @@ namespace uhd{ namespace transport{ * \param elem the new element to push * \return true if the element fit without popping for space */ - UHD_INLINE bool push_with_pop_on_full(const elem_type &elem){ - boost::unique_lock lock(_mutex); - if(_buffer.full()){ - _buffer.pop_back(); - _buffer.push_front(elem); - lock.unlock(); - _empty_cond.notify_one(); - return false; - } - else{ - _buffer.push_front(elem); - lock.unlock(); - _empty_cond.notify_one(); - return true; - } - } + virtual bool push_with_pop_on_full(const elem_type &elem) = 0; /*! * Push a new element into the bounded_buffer. * Wait until the bounded_buffer becomes non-full. * \param elem the new element to push */ - UHD_INLINE void push_with_wait(const elem_type &elem){ - boost::unique_lock lock(_mutex); - _full_cond.wait(lock, boost::bind(&bounded_buffer::not_full, this)); - _buffer.push_front(elem); - lock.unlock(); - _empty_cond.notify_one(); - } + virtual void push_with_wait(const elem_type &elem) = 0; /*! * Push a new element into the bounded_buffer. @@ -89,28 +67,14 @@ namespace uhd{ namespace transport{ * \param time the timeout time * \return false when the operation times out */ - template UHD_INLINE - bool push_with_timed_wait(const elem_type &elem, const time_type &time){ - boost::unique_lock lock(_mutex); - if (not _full_cond.timed_wait(lock, time, boost::bind(&bounded_buffer::not_full, this))) return false; - _buffer.push_front(elem); - lock.unlock(); - _empty_cond.notify_one(); - return true; - } + virtual bool push_with_timed_wait(const elem_type &elem, const time_duration_t &time) = 0; /*! * Pop an element from the bounded_buffer. * Wait until the bounded_buffer becomes non-empty. * \param elem the element reference pop to */ - UHD_INLINE void pop_with_wait(elem_type &elem){ - boost::unique_lock lock(_mutex); - _empty_cond.wait(lock, boost::bind(&bounded_buffer::not_empty, this)); - elem = _buffer.back(); _buffer.pop_back(); - lock.unlock(); - _full_cond.notify_one(); - } + virtual void pop_with_wait(elem_type &elem) = 0; /*! * Pop an element from the bounded_buffer. @@ -119,38 +83,16 @@ namespace uhd{ namespace transport{ * \param time the timeout time * \return false when the operation times out */ - template UHD_INLINE - bool pop_with_timed_wait(elem_type &elem, const time_type &time){ - boost::unique_lock lock(_mutex); - if (not _empty_cond.timed_wait(lock, time, boost::bind(&bounded_buffer::not_empty, this))) return false; - elem = _buffer.back(); _buffer.pop_back(); - lock.unlock(); - _full_cond.notify_one(); - return true; - } + virtual bool pop_with_timed_wait(elem_type &elem, const time_duration_t &time) = 0; /*! * Clear all elements from the bounded_buffer. */ - UHD_INLINE void clear(void){ - boost::unique_lock lock(_mutex); - while (not_empty()) _buffer.pop_back(); - lock.unlock(); - _full_cond.notify_one(); - } - - private: - boost::mutex _mutex; - boost::condition _empty_cond, _full_cond; - boost::circular_buffer _buffer; - - bool not_full(void) const{return not _buffer.full();} - bool not_empty(void) const{return not _buffer.empty();} - - //private constructor - bounded_buffer(size_t capacity) : _buffer(capacity){} + virtual void clear(void) = 0; }; }} //namespace +#include + #endif /* INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_HPP */ diff --git a/host/include/uhd/transport/bounded_buffer.ipp b/host/include/uhd/transport/bounded_buffer.ipp new file mode 100644 index 000000000..6885b357d --- /dev/null +++ b/host/include/uhd/transport/bounded_buffer.ipp @@ -0,0 +1,112 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#ifndef INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_IPP +#define INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_IPP + +#include +#include +#include + +namespace uhd{ namespace transport{ namespace{ /*anon*/ + + template + class bounded_buffer_impl : public bounded_buffer{ + public: + + bounded_buffer_impl(size_t capacity) : _buffer(capacity){ + /* NOP */ + } + + UHD_INLINE bool push_with_pop_on_full(const elem_type &elem){ + boost::unique_lock lock(_mutex); + if(_buffer.full()){ + _buffer.pop_back(); + _buffer.push_front(elem); + lock.unlock(); + _empty_cond.notify_one(); + return false; + } + else{ + _buffer.push_front(elem); + lock.unlock(); + _empty_cond.notify_one(); + return true; + } + } + + UHD_INLINE void push_with_wait(const elem_type &elem){ + boost::unique_lock lock(_mutex); + _full_cond.wait(lock, boost::bind(&bounded_buffer_impl::not_full, this)); + _buffer.push_front(elem); + lock.unlock(); + _empty_cond.notify_one(); + } + + bool push_with_timed_wait(const elem_type &elem, const time_duration_t &time){ + boost::unique_lock lock(_mutex); + if (not _full_cond.timed_wait(lock, time, boost::bind(&bounded_buffer_impl::not_full, this))) return false; + _buffer.push_front(elem); + lock.unlock(); + _empty_cond.notify_one(); + return true; + } + + UHD_INLINE void pop_with_wait(elem_type &elem){ + boost::unique_lock lock(_mutex); + _empty_cond.wait(lock, boost::bind(&bounded_buffer_impl::not_empty, this)); + elem = _buffer.back(); _buffer.pop_back(); + lock.unlock(); + _full_cond.notify_one(); + } + + bool pop_with_timed_wait(elem_type &elem, const time_duration_t &time){ + boost::unique_lock lock(_mutex); + if (not _empty_cond.timed_wait(lock, time, boost::bind(&bounded_buffer_impl::not_empty, this))) return false; + elem = _buffer.back(); _buffer.pop_back(); + lock.unlock(); + _full_cond.notify_one(); + return true; + } + + UHD_INLINE void clear(void){ + boost::unique_lock lock(_mutex); + while (not_empty()) _buffer.pop_back(); + lock.unlock(); + _full_cond.notify_one(); + } + + private: + boost::mutex _mutex; + boost::condition _empty_cond, _full_cond; + boost::circular_buffer _buffer; + + bool not_full(void) const{return not _buffer.full();} + bool not_empty(void) const{return not _buffer.empty();} + }; +}}} //namespace + +namespace uhd{ namespace transport{ + + template typename bounded_buffer::sptr + bounded_buffer::make(size_t capacity){ + return bounded_buffer::sptr(new bounded_buffer_impl(capacity)); + } + +}} //namespace + +#endif /* INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_IPP */ diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt index c98eec639..36f86054a 100644 --- a/host/include/uhd/utils/CMakeLists.txt +++ b/host/include/uhd/utils/CMakeLists.txt @@ -19,6 +19,7 @@ INSTALL(FILES algorithm.hpp assert.hpp byteswap.hpp + byteswap.ipp exception.hpp gain_handler.hpp pimpl.hpp diff --git a/host/include/uhd/utils/byteswap.hpp b/host/include/uhd/utils/byteswap.hpp index 26d60c2ab..9a1871210 100644 --- a/host/include/uhd/utils/byteswap.hpp +++ b/host/include/uhd/utils/byteswap.hpp @@ -45,103 +45,6 @@ namespace uhd{ } //namespace uhd -/*********************************************************************** - * Platform-specific implementation details for byteswap below: - **********************************************************************/ -#ifdef BOOST_MSVC //http://msdn.microsoft.com/en-us/library/a3140177%28VS.80%29.aspx - #include - - UHD_INLINE boost::uint16_t uhd::byteswap(boost::uint16_t x){ - return _byteswap_ushort(x); - } - - UHD_INLINE boost::uint32_t uhd::byteswap(boost::uint32_t x){ - return _byteswap_ulong(x); - } - - UHD_INLINE boost::uint64_t uhd::byteswap(boost::uint64_t x){ - return _byteswap_uint64(x); - } - -#elif defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 2 - - UHD_INLINE boost::uint16_t uhd::byteswap(boost::uint16_t x){ - return (x>>8) | (x<<8); //DNE return __builtin_bswap16(x); - } - - UHD_INLINE boost::uint32_t uhd::byteswap(boost::uint32_t x){ - return __builtin_bswap32(x); - } - - UHD_INLINE boost::uint64_t uhd::byteswap(boost::uint64_t x){ - return __builtin_bswap64(x); - } - -#elif defined(__FreeBSD__) || defined(__MACOSX__) || defined(__APPLE__) - #include - - UHD_INLINE boost::uint16_t uhd::byteswap(boost::uint16_t x){ - return OSSwapInt16(x); - } - - UHD_INLINE boost::uint32_t uhd::byteswap(boost::uint32_t x){ - return OSSwapInt32(x); - } - - UHD_INLINE boost::uint64_t uhd::byteswap(boost::uint64_t x){ - return OSSwapInt64(x); - } - -#elif defined(linux) || defined(__linux) - #include - - UHD_INLINE boost::uint16_t uhd::byteswap(boost::uint16_t x){ - return bswap_16(x); - } - - UHD_INLINE boost::uint32_t uhd::byteswap(boost::uint32_t x){ - return bswap_32(x); - } - - UHD_INLINE boost::uint64_t uhd::byteswap(boost::uint64_t x){ - return bswap_64(x); - } - -#else //http://www.koders.com/c/fidB93B34CD44F0ECF724F1A4EAE3854BA2FE692F59.aspx - - UHD_INLINE boost::uint16_t uhd::byteswap(boost::uint16_t x){ - return (x>>8) | (x<<8); - } - - UHD_INLINE boost::uint32_t uhd::byteswap(boost::uint32_t x){ - return (boost::uint32_t(uhd::byteswap(boost::uint16_t(x&0xfffful)))<<16) | (uhd::byteswap(boost::uint16_t(x>>16))); - } - - UHD_INLINE boost::uint64_t uhd::byteswap(boost::uint64_t x){ - return (boost::uint64_t(uhd::byteswap(boost::uint32_t(x&0xffffffffull)))<<32) | (uhd::byteswap(boost::uint32_t(x>>32))); - } - -#endif - -/*********************************************************************** - * Define the templated network to/from host conversions - **********************************************************************/ -#include - -template UHD_INLINE T uhd::ntohx(T num){ - #ifdef BOOST_BIG_ENDIAN - return num; - #else - return uhd::byteswap(num); - #endif -} - -template UHD_INLINE T uhd::htonx(T num){ - #ifdef BOOST_BIG_ENDIAN - return num; - #else - return uhd::byteswap(num); - #endif -} +#include #endif /* INCLUDED_UHD_UTILS_BYTESWAP_HPP */ diff --git a/host/include/uhd/utils/byteswap.ipp b/host/include/uhd/utils/byteswap.ipp new file mode 100644 index 000000000..11c82a4ec --- /dev/null +++ b/host/include/uhd/utils/byteswap.ipp @@ -0,0 +1,120 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#ifndef INCLUDED_UHD_UTILS_BYTESWAP_IPP +#define INCLUDED_UHD_UTILS_BYTESWAP_IPP + +/*********************************************************************** + * Platform-specific implementation details for byteswap below: + **********************************************************************/ +#ifdef BOOST_MSVC //http://msdn.microsoft.com/en-us/library/a3140177%28VS.80%29.aspx + #include + + UHD_INLINE boost::uint16_t uhd::byteswap(boost::uint16_t x){ + return _byteswap_ushort(x); + } + + UHD_INLINE boost::uint32_t uhd::byteswap(boost::uint32_t x){ + return _byteswap_ulong(x); + } + + UHD_INLINE boost::uint64_t uhd::byteswap(boost::uint64_t x){ + return _byteswap_uint64(x); + } + +#elif defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 2 + + UHD_INLINE boost::uint16_t uhd::byteswap(boost::uint16_t x){ + return (x>>8) | (x<<8); //DNE return __builtin_bswap16(x); + } + + UHD_INLINE boost::uint32_t uhd::byteswap(boost::uint32_t x){ + return __builtin_bswap32(x); + } + + UHD_INLINE boost::uint64_t uhd::byteswap(boost::uint64_t x){ + return __builtin_bswap64(x); + } + +#elif defined(__FreeBSD__) || defined(__MACOSX__) || defined(__APPLE__) + #include + + UHD_INLINE boost::uint16_t uhd::byteswap(boost::uint16_t x){ + return OSSwapInt16(x); + } + + UHD_INLINE boost::uint32_t uhd::byteswap(boost::uint32_t x){ + return OSSwapInt32(x); + } + + UHD_INLINE boost::uint64_t uhd::byteswap(boost::uint64_t x){ + return OSSwapInt64(x); + } + +#elif defined(linux) || defined(__linux) + #include + + UHD_INLINE boost::uint16_t uhd::byteswap(boost::uint16_t x){ + return bswap_16(x); + } + + UHD_INLINE boost::uint32_t uhd::byteswap(boost::uint32_t x){ + return bswap_32(x); + } + + UHD_INLINE boost::uint64_t uhd::byteswap(boost::uint64_t x){ + return bswap_64(x); + } + +#else //http://www.koders.com/c/fidB93B34CD44F0ECF724F1A4EAE3854BA2FE692F59.aspx + + UHD_INLINE boost::uint16_t uhd::byteswap(boost::uint16_t x){ + return (x>>8) | (x<<8); + } + + UHD_INLINE boost::uint32_t uhd::byteswap(boost::uint32_t x){ + return (boost::uint32_t(uhd::byteswap(boost::uint16_t(x&0xfffful)))<<16) | (uhd::byteswap(boost::uint16_t(x>>16))); + } + + UHD_INLINE boost::uint64_t uhd::byteswap(boost::uint64_t x){ + return (boost::uint64_t(uhd::byteswap(boost::uint32_t(x&0xffffffffull)))<<32) | (uhd::byteswap(boost::uint32_t(x>>32))); + } + +#endif + +/*********************************************************************** + * Define the templated network to/from host conversions + **********************************************************************/ +#include + +template UHD_INLINE T uhd::ntohx(T num){ + #ifdef BOOST_BIG_ENDIAN + return num; + #else + return uhd::byteswap(num); + #endif +} + +template UHD_INLINE T uhd::htonx(T num){ + #ifdef BOOST_BIG_ENDIAN + return num; + #else + return uhd::byteswap(num); + #endif +} + +#endif /* INCLUDED_UHD_UTILS_BYTESWAP_IPP */ -- cgit v1.2.3 From 1ca30a49030da2ef248048e17a46738bb3823c4c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 6 Jul 2010 15:44:15 -0700 Subject: uhd: added set time w/ unknown pps to mimo usrp, get tx rate bug fix --- host/include/uhd/usrp/mimo_usrp.hpp | 18 ++++++++++++++++++ host/lib/usrp/mimo_usrp.cpp | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) (limited to 'host/include') diff --git a/host/include/uhd/usrp/mimo_usrp.hpp b/host/include/uhd/usrp/mimo_usrp.hpp index e85c06046..68a42cad8 100644 --- a/host/include/uhd/usrp/mimo_usrp.hpp +++ b/host/include/uhd/usrp/mimo_usrp.hpp @@ -90,6 +90,24 @@ public: */ virtual void set_time_next_pps(const time_spec_t &time_spec) = 0; + /*! + * Synchronize the times across all motherboards in this configuration. + * Use this method to sync the times when the edge of the PPS is unknown. + * + * Ex: Host machine is not attached to serial port of GPSDO + * and can therefore not query the GPSDO for the PPS edge. + * + * This is a 3-step process, and will take at most 3 seconds to complete. + * Upon completion, the times will be synchronized to the time provided. + * + * - Step1: set the time at the next pps (potential race condition) + * - Step2: wait for the seconds to rollover to catch the pps edge + * - Step3: set the time at the next pps (synchronous for all boards) + * + * \param time_spec the time to latch into the usrp device + */ + virtual void set_time_unknown_pps(const time_spec_t &time_spec) = 0; + /*! * Issue a stream command to the usrp device. * This tells the usrp to send samples into the host. diff --git a/host/lib/usrp/mimo_usrp.cpp b/host/lib/usrp/mimo_usrp.cpp index 440aaf9f6..f5441e19d 100644 --- a/host/lib/usrp/mimo_usrp.cpp +++ b/host/lib/usrp/mimo_usrp.cpp @@ -27,6 +27,7 @@ #include #include #include +#include using namespace uhd; using namespace uhd::usrp; @@ -121,6 +122,22 @@ public: } } + void set_time_unknown_pps(const time_spec_t &time_spec){ + std::cout << "Set time with unknown pps edge:" << std::endl; + std::cout << " 1) set times next pps (race condition)" << std::endl; + set_time_next_pps(time_spec); sleep(1); + + std::cout << " 2) catch seconds rollover at pps edge" << std::endl; + time_t last_secs = 0, curr_secs = 0; + while(curr_secs == last_secs){ + last_secs = curr_secs; + curr_secs = get_time_now().get_full_secs(); + } + + std::cout << " 3) set times next pps (synchronously)" << std::endl; + set_time_next_pps(time_spec); sleep(1); + } + void issue_stream_cmd(const stream_cmd_t &stream_cmd){ BOOST_FOREACH(wax::obj mboard, _mboards){ mboard[MBOARD_PROP_STREAM_CMD] = stream_cmd; @@ -206,7 +223,7 @@ public: } double get_tx_rate_all(void){ - return _rx_rate; + return _tx_rate; } tune_result_t set_tx_freq(size_t chan, double target_freq){ -- cgit v1.2.3 From e771e157f6d210fe2e66294c60581c5953006ba1 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 6 Jul 2010 16:15:49 -0700 Subject: uhd: added back into old send/recv but with deprecation attributes, moved inline device stuff into device.ipp --- host/include/uhd/CMakeLists.txt | 1 + host/include/uhd/config.hpp | 11 +++++- host/include/uhd/device.hpp | 35 +++++++++--------- host/include/uhd/device.ipp | 79 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 17 deletions(-) create mode 100644 host/include/uhd/device.ipp (limited to 'host/include') diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt index d63062032..c0339dbd3 100644 --- a/host/include/uhd/CMakeLists.txt +++ b/host/include/uhd/CMakeLists.txt @@ -24,6 +24,7 @@ ADD_SUBDIRECTORY(utils) INSTALL(FILES config.hpp device.hpp + device.ipp wax.hpp DESTINATION ${INCLUDE_DIR}/uhd ) diff --git a/host/include/uhd/config.hpp b/host/include/uhd/config.hpp index b23a4dc00..013354d33 100644 --- a/host/include/uhd/config.hpp +++ b/host/include/uhd/config.hpp @@ -78,7 +78,7 @@ #endif // UHD_DLL // Define force inline macro -#ifdef BOOST_MSVC +#if defined(BOOST_MSVC) #define UHD_INLINE __forceinline #elif defined(__GNUG__) && __GNUG__ >= 4 #define UHD_INLINE inline __attribute__((always_inline)) @@ -86,4 +86,13 @@ #define UHD_INLINE inline #endif +// Define deprecated attribute macro +#if defined(BOOST_MSVC) + #define UHD_DEPRECATED __declspec(deprecated) +#elif defined(__GNUG__) && __GNUG__ >= 4 + #define UHD_DEPRECATED __attribute__ ((deprecated)) +#else + #define UHD_DEPRECATED +#endif + #endif /* INCLUDED_UHD_CONFIG_HPP */ diff --git a/host/include/uhd/device.hpp b/host/include/uhd/device.hpp index e5ef1181f..a0c29f2e6 100644 --- a/host/include/uhd/device.hpp +++ b/host/include/uhd/device.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include namespace uhd{ @@ -128,19 +129,19 @@ public: /*! * Convenience wrapper for send that takes a single buffer. */ - inline size_t send( + size_t send( const void *buff, size_t nsamps_per_buff, const tx_metadata_t &metadata, const io_type_t &io_type, send_mode_t send_mode - ){ - return send( - std::vector(1, buff), - nsamps_per_buff, metadata, - io_type, send_mode - ); - } + ); + + //! Deprecated + size_t send( + const boost::asio::const_buffer &, const tx_metadata_t &, + const io_type_t &, send_mode_t send_mode + ); /*! * Receive buffers containing IF data described by the metadata. @@ -186,19 +187,19 @@ public: /*! * Convenience wrapper for recv that takes a single buffer. */ - inline size_t recv( + size_t recv( void *buff, size_t nsamps_per_buff, rx_metadata_t &metadata, const io_type_t &io_type, recv_mode_t recv_mode - ){ - return recv( - std::vector(1, buff), - nsamps_per_buff, metadata, - io_type, recv_mode - ); - } + ); + + //! Deprecated + size_t recv( + const boost::asio::mutable_buffer &, rx_metadata_t &, + const io_type_t &, recv_mode_t + ); /*! * Get the maximum number of samples per packet on send. @@ -216,4 +217,6 @@ public: } //namespace uhd +#include + #endif /* INCLUDED_UHD_DEVICE_HPP */ diff --git a/host/include/uhd/device.ipp b/host/include/uhd/device.ipp new file mode 100644 index 000000000..c38a2e43e --- /dev/null +++ b/host/include/uhd/device.ipp @@ -0,0 +1,79 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#ifndef INCLUDED_UHD_DEVICE_IPP +#define INCLUDED_UHD_DEVICE_IPP + +namespace uhd{ + + UHD_INLINE size_t device::send( + const void *buff, + size_t nsamps_per_buff, + const tx_metadata_t &metadata, + const io_type_t &io_type, + send_mode_t send_mode + ){ + return this->send( + std::vector(1, buff), + nsamps_per_buff, metadata, + io_type, send_mode + ); + } + + UHD_DEPRECATED UHD_INLINE size_t device::send( + const boost::asio::const_buffer &buff, + const tx_metadata_t &metadata, + const io_type_t &io_type, + send_mode_t send_mode + ){ + return this->send( + boost::asio::buffer_cast(buff), + boost::asio::buffer_size(buff)/io_type.size, + metadata, io_type, send_mode + ); + } + + UHD_INLINE size_t device::recv( + void *buff, + size_t nsamps_per_buff, + rx_metadata_t &metadata, + const io_type_t &io_type, + recv_mode_t recv_mode + ){ + return this->recv( + std::vector(1, buff), + nsamps_per_buff, metadata, + io_type, recv_mode + ); + } + + UHD_DEPRECATED UHD_INLINE size_t device::recv( + const boost::asio::mutable_buffer &buff, + rx_metadata_t &metadata, + const io_type_t &io_type, + recv_mode_t recv_mode + ){ + return this->recv( + boost::asio::buffer_cast(buff), + boost::asio::buffer_size(buff)/io_type.size, + metadata, io_type, recv_mode + ); + } + +} //namespace uhd + +#endif /* INCLUDED_UHD_DEVICE_IPP */ -- cgit v1.2.3