aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-07-07 02:23:38 +0000
committerJosh Blum <josh@joshknows.com>2010-07-07 02:23:38 +0000
commitf2e9d3ed0941dc5738149dd82d1eac158bdf0a0f (patch)
tree82a350987e32cd329ab5fe56b6dd9fbfef08230f /host/lib
parent998fee6ef064f1d53a61dd0eec79276d1e85291e (diff)
parent5c2cccfe8c4a9c6c912a4d18dc1e7a6f84c79609 (diff)
downloaduhd-f2e9d3ed0941dc5738149dd82d1eac158bdf0a0f.tar.gz
uhd-f2e9d3ed0941dc5738149dd82d1eac158bdf0a0f.tar.bz2
uhd-f2e9d3ed0941dc5738149dd82d1eac158bdf0a0f.zip
Merge branch 'master' of ettus.sourcerepo.com:ettus/uhdpriv into usrp_e
Conflicts: host/examples/rx_timed_samples.cpp
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/transport/CMakeLists.txt24
-rw-r--r--host/lib/transport/convert_types_impl.hpp201
-rwxr-xr-xhost/lib/transport/gen_convert_types.py122
-rwxr-xr-xhost/lib/transport/gen_vrt_if_packet.py (renamed from host/lib/transport/gen_vrt.py)126
-rw-r--r--host/lib/transport/udp_zero_copy_asio.cpp9
-rw-r--r--host/lib/transport/vrt_packet_handler.hpp301
-rw-r--r--host/lib/types.cpp62
-rw-r--r--host/lib/usrp/CMakeLists.txt1
-rw-r--r--host/lib/usrp/mimo_usrp.cpp291
-rw-r--r--host/lib/usrp/simple_usrp.cpp16
-rw-r--r--host/lib/usrp/usrp2/dboard_impl.cpp18
-rw-r--r--host/lib/usrp/usrp2/dsp_impl.cpp20
-rw-r--r--host/lib/usrp/usrp2/fw_common.h6
-rw-r--r--host/lib/usrp/usrp2/io_impl.cpp195
-rw-r--r--host/lib/usrp/usrp2/mboard_impl.cpp100
-rw-r--r--host/lib/usrp/usrp2/usrp2_iface.cpp26
-rw-r--r--host/lib/usrp/usrp2/usrp2_iface.hpp10
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.cpp123
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.hpp198
-rw-r--r--host/lib/usrp/usrp2/usrp2_regs.hpp10
20 files changed, 1277 insertions, 582 deletions
diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt
index 872865d6c..bde2b72b9 100644
--- a/host/lib/transport/CMakeLists.txt
+++ b/host/lib/transport/CMakeLists.txt
@@ -18,6 +18,16 @@
#This file will be included by cmake, use absolute paths!
########################################################################
+# Check for SIMD headers
+########################################################################
+INCLUDE(CheckIncludeFileCXX)
+CHECK_INCLUDE_FILE_CXX(emmintrin.h HAVE_EMMINTRIN_H)
+
+IF(HAVE_EMMINTRIN_H)
+ ADD_DEFINITIONS(-DHAVE_EMMINTRIN_H)
+ENDIF(HAVE_EMMINTRIN_H)
+
+########################################################################
# Setup defines for interface address discovery
########################################################################
MESSAGE(STATUS "Configuring interface address discovery...")
@@ -40,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(
@@ -49,6 +59,16 @@ LIBUHD_PYTHON_GEN_SOURCE(
${CMAKE_BINARY_DIR}/lib/transport/convert_types.cpp
)
+# append this directory to the include path so the generated convert types
+# can include the implementation convert types file in the source directory
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/transport)
+
+# make the generated convert types depend on the implementation header
+SET_SOURCE_FILES_PROPERTIES(
+ ${CMAKE_BINARY_DIR}/lib/transport/convert_types.cpp PROPERTIES
+ OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/lib/transport/convert_types_impl.hpp
+)
+
LIBUHD_APPEND_SOURCES(
${CMAKE_SOURCE_DIR}/lib/transport/if_addrs.cpp
${CMAKE_SOURCE_DIR}/lib/transport/udp_simple.cpp
diff --git a/host/lib/transport/convert_types_impl.hpp b/host/lib/transport/convert_types_impl.hpp
new file mode 100644
index 000000000..5958b08cb
--- /dev/null
+++ b/host/lib/transport/convert_types_impl.hpp
@@ -0,0 +1,201 @@
+//
+// 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 <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_LIBUHD_TRANSPORT_CONVERT_TYPES_IMPL_HPP
+#define INCLUDED_LIBUHD_TRANSPORT_CONVERT_TYPES_IMPL_HPP
+
+#include <uhd/config.hpp>
+#include <uhd/utils/byteswap.hpp>
+#include <boost/cstdint.hpp>
+#include <cstring>
+#include <complex>
+
+#ifdef HAVE_EMMINTRIN_H
+ #define USE_EMMINTRIN_H //use sse2 intrinsics
+#endif
+
+/***********************************************************************
+ * Typedefs
+ **********************************************************************/
+typedef std::complex<float> fc32_t;
+typedef std::complex<boost::int16_t> sc16_t;
+typedef boost::uint32_t item32_t;
+
+/***********************************************************************
+ * Convert complex short buffer to items32
+ **********************************************************************/
+static UHD_INLINE void sc16_to_item32_nswap(
+ const sc16_t *input, item32_t *output, size_t nsamps
+){
+ std::memcpy(output, input, nsamps*sizeof(item32_t));
+}
+
+static UHD_INLINE void sc16_to_item32_bswap(
+ const sc16_t *input, item32_t *output, size_t nsamps
+){
+ const item32_t *item32_input = (const item32_t *)input;
+ for (size_t i = 0; i < nsamps; i++){
+ output[i] = uhd::byteswap(item32_input[i]);
+ }
+}
+
+/***********************************************************************
+ * Convert items32 buffer to complex short
+ **********************************************************************/
+static UHD_INLINE void item32_to_sc16_nswap(
+ const item32_t *input, sc16_t *output, size_t nsamps
+){
+ std::memcpy(output, input, nsamps*sizeof(item32_t));
+}
+
+static UHD_INLINE void item32_to_sc16_bswap(
+ const item32_t *input, sc16_t *output, size_t nsamps
+){
+ item32_t *item32_output = (item32_t *)output;
+ for (size_t i = 0; i < nsamps; i++){
+ item32_output[i] = uhd::byteswap(input[i]);
+ }
+}
+
+/***********************************************************************
+ * Convert complex float buffer to items32
+ **********************************************************************/
+static const float shorts_per_float = float(32767);
+
+static UHD_INLINE item32_t fc32_to_item32(fc32_t num){
+ boost::uint16_t real = boost::int16_t(num.real()*shorts_per_float);
+ boost::uint16_t imag = boost::int16_t(num.imag()*shorts_per_float);
+ return (item32_t(real) << 16) | (item32_t(imag) << 0);
+}
+
+static UHD_INLINE void fc32_to_item32_nswap(
+ const fc32_t *input, item32_t *output, size_t nsamps
+){
+ for (size_t i = 0; i < nsamps; i++){
+ output[i] = fc32_to_item32(input[i]);
+ }
+}
+
+#if defined(USE_EMMINTRIN_H)
+#include <emmintrin.h>
+
+static UHD_INLINE void fc32_to_item32_bswap(
+ const fc32_t *input, item32_t *output, size_t nsamps
+){
+ __m128 scalar = _mm_set_ps1(shorts_per_float);
+
+ //convert blocks of samples with intrinsics
+ size_t i = 0; for (; i < (nsamps & ~0x3); i+=4){
+ //load from input
+ __m128 tmplo = _mm_loadu_ps(reinterpret_cast<const float *>(input+i+0));
+ __m128 tmphi = _mm_loadu_ps(reinterpret_cast<const float *>(input+i+2));
+
+ //convert and scale
+ __m128i tmpilo = _mm_cvtps_epi32(_mm_mul_ps(tmplo, scalar));
+ __m128i tmpihi = _mm_cvtps_epi32(_mm_mul_ps(tmphi, scalar));
+
+ //pack + byteswap -> byteswap 32 bit words
+ __m128i tmpi = _mm_packs_epi32(tmpilo, tmpihi);
+ tmpi = _mm_or_si128(_mm_srli_epi16(tmpi, 8), _mm_slli_epi16(tmpi, 8));
+
+ //store to output
+ _mm_storeu_si128(reinterpret_cast<__m128i *>(output+i), tmpi);
+ }
+
+ //convert remainder
+ for (; i < nsamps; i++){
+ output[i] = uhd::byteswap(fc32_to_item32(input[i]));
+ }
+}
+
+#else
+static UHD_INLINE void fc32_to_item32_bswap(
+ const fc32_t *input, item32_t *output, size_t nsamps
+){
+ for (size_t i = 0; i < nsamps; i++){
+ output[i] = uhd::byteswap(fc32_to_item32(input[i]));
+ }
+}
+
+#endif
+
+/***********************************************************************
+ * Convert items32 buffer to complex float
+ **********************************************************************/
+static const float floats_per_short = float(1.0/shorts_per_float);
+
+static UHD_INLINE fc32_t item32_to_fc32(item32_t item){
+ return fc32_t(
+ float(boost::int16_t(item >> 16)*floats_per_short),
+ float(boost::int16_t(item >> 0)*floats_per_short)
+ );
+}
+
+static UHD_INLINE void item32_to_fc32_nswap(
+ const item32_t *input, fc32_t *output, size_t nsamps
+){
+ for (size_t i = 0; i < nsamps; i++){
+ output[i] = item32_to_fc32(input[i]);
+ }
+}
+
+#if defined(USE_EMMINTRIN_H)
+#include <emmintrin.h>
+
+static UHD_INLINE void item32_to_fc32_bswap(
+ const item32_t *input, fc32_t *output, size_t nsamps
+){
+ __m128 scalar = _mm_set_ps1(floats_per_short/(1 << 16));
+ __m128i zeroi = _mm_setzero_si128();
+
+ //convert blocks of samples with intrinsics
+ size_t i = 0; for (; i < (nsamps & ~0x3); i+=4){
+ //load from input
+ __m128i tmpi = _mm_loadu_si128(reinterpret_cast<const __m128i *>(input+i));
+
+ //byteswap + unpack -> byteswap 32 bit words
+ tmpi = _mm_or_si128(_mm_srli_epi16(tmpi, 8), _mm_slli_epi16(tmpi, 8));
+ __m128i tmpilo = _mm_unpacklo_epi16(zeroi, tmpi); //value in upper 16 bits
+ __m128i tmpihi = _mm_unpackhi_epi16(zeroi, tmpi);
+
+ //convert and scale
+ __m128 tmplo = _mm_mul_ps(_mm_cvtepi32_ps(tmpilo), scalar);
+ __m128 tmphi = _mm_mul_ps(_mm_cvtepi32_ps(tmpihi), scalar);
+
+ //store to output
+ _mm_storeu_ps(reinterpret_cast<float *>(output+i+0), tmplo);
+ _mm_storeu_ps(reinterpret_cast<float *>(output+i+2), tmphi);
+ }
+
+ //convert remainder
+ for (; i < nsamps; i++){
+ output[i] = item32_to_fc32(uhd::byteswap(input[i]));
+ }
+}
+
+#else
+static UHD_INLINE void item32_to_fc32_bswap(
+ const item32_t *input, fc32_t *output, size_t nsamps
+){
+ for (size_t i = 0; i < nsamps; i++){
+ output[i] = item32_to_fc32(uhd::byteswap(input[i]));
+ }
+}
+
+#endif
+
+#endif /* INCLUDED_LIBUHD_TRANSPORT_CONVERT_TYPES_IMPL_HPP */
diff --git a/host/lib/transport/gen_convert_types.py b/host/lib/transport/gen_convert_types.py
index af2bcc7cb..951b634d9 100755
--- a/host/lib/transport/gen_convert_types.py
+++ b/host/lib/transport/gen_convert_types.py
@@ -24,66 +24,15 @@ TMPL_TEXT = """
\#include <uhd/config.hpp>
\#include <uhd/transport/convert_types.hpp>
-\#include <uhd/utils/byteswap.hpp>
\#include <boost/cstdint.hpp>
\#include <boost/detail/endian.hpp>
\#include <stdexcept>
-\#include <complex>
-
-//define the endian macros to convert integers
-\#ifdef BOOST_BIG_ENDIAN
- \#define BE_MACRO(x) x
- \#define LE_MACRO(x) uhd::byteswap(x)
- static const bool is_big_endian = true;
-\#else
- \#define BE_MACRO(x) uhd::byteswap(x)
- \#define LE_MACRO(x) x
- static const bool is_big_endian = false;
-\#endif
+\#include "convert_types_impl.hpp"
using namespace uhd;
/***********************************************************************
- * Constants
- **********************************************************************/
-typedef std::complex<float> fc32_t;
-typedef std::complex<boost::int16_t> sc16_t;
-typedef boost::uint32_t item32_t;
-
-static const float shorts_per_float = float(32767);
-static const float floats_per_short = float(1.0/shorts_per_float);
-
-/***********************************************************************
- * Single-sample converters
- **********************************************************************/
-static UHD_INLINE item32_t sc16_to_item32(sc16_t num){
- boost::uint16_t real = boost::int16_t(num.real());
- boost::uint16_t imag = boost::int16_t(num.imag());
- return (item32_t(real) << 16) | (item32_t(imag) << 0);
-}
-
-static UHD_INLINE sc16_t item32_to_sc16(item32_t item){
- return sc16_t(
- boost::uint16_t(item >> 16),
- boost::uint16_t(item >> 0)
- );
-}
-
-static UHD_INLINE item32_t fc32_to_item32(fc32_t num){
- boost::uint16_t real = boost::int16_t(num.real()*shorts_per_float);
- boost::uint16_t imag = boost::int16_t(num.imag()*shorts_per_float);
- return (item32_t(real) << 16) | (item32_t(imag) << 0);
-}
-
-static UHD_INLINE fc32_t item32_to_fc32(item32_t item){
- return fc32_t(
- float(boost::int16_t(item >> 16)*floats_per_short),
- float(boost::int16_t(item >> 0)*floats_per_short)
- );
-}
-
-/***********************************************************************
- * Sample-buffer converters
+ * Generate predicate for jump table
**********************************************************************/
UHD_INLINE boost::uint8_t get_pred(
const io_type_t &io_type,
@@ -92,27 +41,34 @@ UHD_INLINE boost::uint8_t get_pred(
boost::uint8_t pred = 0;
switch(otw_type.byteorder){
- case otw_type_t::BO_BIG_ENDIAN: pred |= $ph.be_p; break;
- case otw_type_t::BO_LITTLE_ENDIAN: pred |= $ph.le_p; break;
- ##let the compiler determine the native byte order (we could use python sys.byteorder)
- case otw_type_t::BO_NATIVE: pred |= (is_big_endian)? $ph.be_p : $ph.le_p; break;
- default: throw std::runtime_error("unhandled byteorder type");
+ \#ifdef BOOST_BIG_ENDIAN
+ case otw_type_t::BO_BIG_ENDIAN: pred |= $ph.nswap_p; break;
+ case otw_type_t::BO_LITTLE_ENDIAN: pred |= $ph.bswap_p; break;
+ \#else
+ case otw_type_t::BO_BIG_ENDIAN: pred |= $ph.bswap_p; break;
+ case otw_type_t::BO_LITTLE_ENDIAN: pred |= $ph.nswap_p; break;
+ \#endif
+ case otw_type_t::BO_NATIVE: pred |= $ph.nswap_p; break;
+ default: throw std::runtime_error("unhandled otw byteorder type");
}
- switch(otw_type.width){
- case 16: pred |= $ph.w16_p; break;
- default: throw std::runtime_error("unhandled bit width");
+ switch(otw_type.get_sample_size()){
+ case sizeof(boost::uint32_t): pred |= $ph.item32_p; break;
+ default: throw std::runtime_error("unhandled otw sample size");
}
switch(io_type.tid){
- case io_type_t::COMPLEX_INT16: pred |= $ph.sc16_p; break;
case io_type_t::COMPLEX_FLOAT32: pred |= $ph.fc32_p; break;
+ case io_type_t::COMPLEX_INT16: pred |= $ph.sc16_p; break;
default: throw std::runtime_error("unhandled io type id");
}
return pred;
}
+/***********************************************************************
+ * Convert host type to device type
+ **********************************************************************/
void transport::convert_io_type_to_otw_type(
const void *io_buff, const io_type_t &io_type,
void *otw_buff, const otw_type_t &otw_type,
@@ -123,16 +79,16 @@ void transport::convert_io_type_to_otw_type(
case $pred:
#set $out_type = $ph.get_dev_type($pred)
#set $in_type = $ph.get_host_type($pred)
- #set $converter = $in_type+"_to_"+$out_type
- #set $xe_macro = $ph.get_xe_macro($pred)
- for (size_t i = 0; i < num_samps; i++){
- (($(out_type)_t *)otw_buff)[i] = $(xe_macro)($(converter)(((const $(in_type)_t *)io_buff)[i]));
- }
+ #set $converter = '_'.join([$in_type, 'to', $out_type, $ph.get_swap_type($pred)])
+ $(converter)((const $(in_type)_t *)io_buff, ($(out_type)_t *)otw_buff, num_samps);
break;
#end for
}
}
+/***********************************************************************
+ * Convert device type to host type
+ **********************************************************************/
void transport::convert_otw_type_to_io_type(
const void *otw_buff, const otw_type_t &otw_type,
void *io_buff, const io_type_t &io_type,
@@ -143,11 +99,8 @@ void transport::convert_otw_type_to_io_type(
case $pred:
#set $out_type = $ph.get_host_type($pred)
#set $in_type = $ph.get_dev_type($pred)
- #set $converter = $in_type+"_to_"+$out_type
- #set $xe_macro = $ph.get_xe_macro($pred)
- for (size_t i = 0; i < num_samps; i++){
- (($(out_type)_t *)io_buff)[i] = $(converter)($(xe_macro)(((const $(in_type)_t *)otw_buff)[i]));
- }
+ #set $converter = '_'.join([$in_type, 'to', $out_type, $ph.get_swap_type($pred)])
+ $(converter)((const $(in_type)_t *)otw_buff, ($(out_type)_t *)io_buff, num_samps);
break;
#end for
}
@@ -160,29 +113,32 @@ def parse_tmpl(_tmpl_text, **kwargs):
return str(Template(_tmpl_text, kwargs))
class ph:
- be_p = 0b00001
- le_p = 0b00000
- w16_p = 0b00000
- sc16_p = 0b00010
- fc32_p = 0b00000
+ bswap_p = 0b00001
+ nswap_p = 0b00000
+ item32_p = 0b00000
+ sc16_p = 0b00010
+ fc32_p = 0b00000
nbits = 2 #see above
@staticmethod
- def get_xe_macro(pred):
- if (pred & ph.be_p) == ph.be_p: return 'BE_MACRO'
- if (pred & ph.le_p) == ph.le_p: return 'LE_MACRO'
+ def has(pred, flag): return (pred & flag) == flag
+
+ @staticmethod
+ def get_swap_type(pred):
+ if ph.has(pred, ph.bswap_p): return 'bswap'
+ if ph.has(pred, ph.nswap_p): return 'nswap'
raise NotImplementedError
@staticmethod
def get_dev_type(pred):
- if (pred & ph.w16_p) == ph.w16_p: return 'item32'
+ if ph.has(pred, ph.item32_p): return 'item32'
raise NotImplementedError
@staticmethod
def get_host_type(pred):
- if (pred & ph.sc16_p) == ph.sc16_p: return 'sc16'
- if (pred & ph.fc32_p) == ph.fc32_p: return 'fc32'
+ if ph.has(pred, ph.sc16_p): return 'sc16'
+ if ph.has(pred, ph.fc32_p): return 'fc32'
raise NotImplementedError
if __name__ == '__main__':
diff --git a/host/lib/transport/gen_vrt.py b/host/lib/transport/gen_vrt_if_packet.py
index 6cdd6645d..7910ff60d 100755
--- a/host/lib/transport/gen_vrt.py
+++ b/host/lib/transport/gen_vrt_if_packet.py
@@ -31,7 +31,7 @@ TMPL_TEXT = """
* This file was generated by $file on $time.strftime("%c")
**********************************************************************/
-\#include <uhd/transport/vrt.hpp>
+\#include <uhd/transport/vrt_if_packet.hpp>
\#include <uhd/utils/byteswap.hpp>
\#include <boost/detail/endian.hpp>
\#include <stdexcept>
@@ -61,20 +61,22 @@ using namespace uhd::transport;
#set $tsf_p = 0b01000
#set $tlr_p = 0b10000
-void vrt::pack_$(suffix)(
- 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
+static UHD_INLINE void pack_uint64_$(suffix)(boost::uint64_t num, boost::uint32_t *mem){
+ *(reinterpret_cast<boost::uint64_t *>(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 (metadata.has_stream_id) pred |= $hex($sid_p);
- if (metadata.has_time_spec) pred |= $hex($tsi_p | $tsf_p);
+ 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)
@@ -83,81 +85,75 @@ void vrt::pack_$(suffix)(
#set $flags = 0
########## Stream ID ##########
#if $pred & $sid_p
- header_buff[$num_header_words] = $(XE_MACRO)(metadata.stream_id);
+ 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
- header_buff[$num_header_words] = 0;
- #set $num_header_words += 1
- header_buff[$num_header_words] = 0;
- #set $num_header_words += 1
+ 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
- header_buff[$num_header_words] = $(XE_MACRO)(metadata.time_spec.secs);
+ 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
- header_buff[$num_header_words] = 0;
- #set $num_header_words += 1
- header_buff[$num_header_words] = $(XE_MACRO)(metadata.time_spec.get_ticks(tick_rate));
- #set $num_header_words += 1
+ 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 ##########
- num_header_words32 = $num_header_words;
- num_packet_words32 = $($num_header_words + $num_trailer_words) + num_payload_words32;
+ 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 (metadata.start_of_burst) vrt_hdr_flags |= $hex(0x1 << 25);
- if (metadata.end_of_burst) vrt_hdr_flags |= $hex(0x1 << 24);
+ 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
- header_buff[0] = $(XE_MACRO)(boost::uint32_t(0
+ packet_buff[0] = $(XE_MACRO)(boost::uint32_t(0
| vrt_hdr_flags
- | ((packet_count & 0xf) << 16)
- | (num_packet_words32 & 0xffff)
+ | ((if_packet_info.packet_count & 0xf) << 16)
+ | (if_packet_info.num_packet_words32 & 0xffff)
));
}
-void vrt::unpack_$(suffix)(
- 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
-){
- //clear the metadata
- metadata = rx_metadata_t();
+static UHD_INLINE void unpack_uint64_$(suffix)(boost::uint64_t &num, const boost::uint32_t *mem){
+ num = $(XE_MACRO)(*reinterpret_cast<const boost::uint64_t *>(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)(header_buff[0]);
+ boost::uint32_t vrt_hdr_word = $(XE_MACRO)(packet_buff[0]);
size_t packet_words32 = vrt_hdr_word & 0xffff;
- packet_count = (vrt_hdr_word >> 16) & 0xf;
+ if_packet_info.packet_count = (vrt_hdr_word >> 16) & 0xf;
//failure cases
- if (packet_words32 == 0 or num_packet_words32 < packet_words32)
+ if (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");
+ throw std::runtime_error("bad vrt header or unsupported packet type");
boost::uint8_t pred = 0;
if(vrt_hdr_word & $hex(0x1 << 28)) pred |= $hex($sid_p);
@@ -169,45 +165,55 @@ void vrt::unpack_$(suffix)(
switch(pred){
#for $pred in range(2**5)
case $pred:
- #set $set_has_time_spec = False
+ #set $has_time_spec = False
#set $num_header_words = 1
########## Stream ID ##########
#if $pred & $sid_p
- metadata.has_stream_id = true;
- metadata.stream_id = $(XE_MACRO)(header_buff[$num_header_words]);
+ 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
- #set $num_header_words += 1
- #set $num_header_words += 1
+ 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
- metadata.has_time_spec = true;
- #set $set_has_time_spec = True
- metadata.time_spec.secs = $(XE_MACRO)(header_buff[$num_header_words]);
+ 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 not $set_has_time_spec
- metadata.has_time_spec = true;
- #set $set_has_time_spec = True
- #end if
- #set $num_header_words += 1
- metadata.time_spec.set_ticks($(XE_MACRO)(header_buff[$num_header_words]), tick_rate);
- #set $num_header_words += 1
+ 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 ##########
- num_header_words32 = $num_header_words;
- num_payload_words32 = packet_words32 - $($num_header_words + $num_trailer_words);
+ //another failure case
+ if (packet_words32 < $($num_header_words + $num_trailer_words))
+ throw std::runtime_error("bad vrt header or invalid packet length");
+ 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
}
diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp
index c3c02707e..7f9292d24 100644
--- a/host/lib/transport/udp_zero_copy_asio.cpp
+++ b/host/lib/transport/udp_zero_copy_asio.cpp
@@ -27,7 +27,8 @@ using namespace uhd::transport;
/***********************************************************************
* Constants
**********************************************************************/
-static const size_t MIN_SOCK_BUFF_SIZE = size_t(100e3);
+//enough buffering for half a second of samples at full rate on usrp2
+static const size_t MIN_SOCK_BUFF_SIZE = size_t(sizeof(boost::uint32_t) * 25e6 * 0.5);
static const size_t MAX_DGRAM_SIZE = 1500; //assume max size on send and recv
static const double RECV_TIMEOUT = 0.1; //100 ms
@@ -159,6 +160,12 @@ template<typename Opt> static void resize_buff_helper(
//otherwise, ensure that the buffer is at least the minimum size
else if (udp_trans->get_buff_size<Opt>() < MIN_SOCK_BUFF_SIZE){
resize_buff_helper<Opt>(udp_trans, MIN_SOCK_BUFF_SIZE, name);
+ if (udp_trans->get_buff_size<Opt>() < MIN_SOCK_BUFF_SIZE){
+ std::cerr << boost::format(
+ "Warning: the %s buffer size is smaller than the recommended size of %d bytes.\n"
+ " See the USRP2 application notes on buffer resizing."
+ ) % name % MIN_SOCK_BUFF_SIZE << std::endl;
+ }
}
}
diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp
index 8dfc7b3d0..68edeb1e1 100644
--- a/host/lib/transport/vrt_packet_handler.hpp
+++ b/host/lib/transport/vrt_packet_handler.hpp
@@ -20,48 +20,51 @@
#include <uhd/config.hpp>
#include <uhd/device.hpp>
+#include <uhd/utils/assert.hpp>
#include <uhd/types/io_type.hpp>
#include <uhd/types/otw_type.hpp>
#include <uhd/types/metadata.hpp>
-#include <uhd/transport/vrt.hpp>
+#include <uhd/transport/vrt_if_packet.hpp>
#include <uhd/transport/convert_types.hpp>
#include <uhd/transport/zero_copy.hpp>
-#include <boost/asio/buffer.hpp>
#include <boost/function.hpp>
#include <stdexcept>
#include <iostream>
+#include <vector>
namespace vrt_packet_handler{
/***********************************************************************
* vrt packet handler for recv
**********************************************************************/
+ typedef std::vector<uhd::transport::managed_recv_buffer::sptr> managed_recv_buffs_t;
+ typedef boost::function<bool(managed_recv_buffs_t &)> get_recv_buffs_t;
+
struct recv_state{
+ //width of the receiver in channels
+ size_t width;
+
//init the expected seq number
- size_t next_packet_seq;
+ std::vector<size_t> next_packet_seq;
//state variables to handle fragments
- uhd::transport::managed_recv_buffer::sptr managed_buff;
- boost::asio::const_buffer copy_buff;
+ managed_recv_buffs_t managed_buffs;
+ std::vector<const boost::uint8_t *> copy_buffs;
+ size_t size_of_copy_buffs;
size_t fragment_offset_in_samps;
- recv_state(void){
- //first expected seq is zero
- next_packet_seq = 0;
-
- //initially empty copy buffer
- copy_buff = boost::asio::buffer("", 0);
+ recv_state(size_t width):
+ width(width),
+ next_packet_seq(width, 0),
+ managed_buffs(width),
+ copy_buffs(width, NULL),
+ size_of_copy_buffs(0),
+ fragment_offset_in_samps(0)
+ {
+ /* NOP */
}
};
- typedef boost::function<uhd::transport::managed_recv_buffer::sptr(void)> get_recv_buff_t;
-
- typedef boost::function<void(uhd::transport::managed_recv_buffer::sptr)> recv_cb_t;
-
- static UHD_INLINE void recv_cb_nop(uhd::transport::managed_recv_buffer::sptr){
- /* NOP */
- }
-
/*******************************************************************
* Unpack a received vrt header and set the copy buffer.
* - helper function for vrt_packet_handler::_recv1
@@ -74,33 +77,39 @@ namespace vrt_packet_handler{
vrt_unpacker_type vrt_unpacker,
size_t vrt_header_offset_words32
){
- size_t num_packet_words32 = state.managed_buff->size()/sizeof(boost::uint32_t);
+ size_t num_packet_words32 = state.managed_buffs[0]->size()/sizeof(boost::uint32_t);
if (num_packet_words32 <= vrt_header_offset_words32){
- state.copy_buff = boost::asio::buffer("", 0);
+ state.size_of_copy_buffs = 0;
return; //must exit here after setting the buffer
}
- const boost::uint32_t *vrt_hdr = state.managed_buff->cast<const boost::uint32_t *>() + vrt_header_offset_words32;
- size_t num_header_words32_out, num_payload_words32_out, packet_count_out;
- vrt_unpacker(
- metadata, //output
- vrt_hdr, //input
- num_header_words32_out, //output
- num_payload_words32_out, //output
- num_packet_words32, //input
- packet_count_out, //output
- tick_rate
- );
- //handle the packet count / sequence number
- if (packet_count_out != state.next_packet_seq){
- std::cerr << "S" << (packet_count_out - state.next_packet_seq)%16;
+ //vrt unpack each managed buffer
+ uhd::transport::vrt::if_packet_info_t if_packet_info;
+ for (size_t i = 0; i < state.width; i++){
+ const boost::uint32_t *vrt_hdr = state.managed_buffs[i]->cast<const boost::uint32_t *>() + vrt_header_offset_words32;
+ if_packet_info.num_packet_words32 = num_packet_words32 - vrt_header_offset_words32;
+ vrt_unpacker(vrt_hdr, if_packet_info);
+
+ //handle the packet count / sequence number
+ if (if_packet_info.packet_count != state.next_packet_seq[i]){
+ std::cerr << "S" << (if_packet_info.packet_count - state.next_packet_seq[i])%16;
+ }
+ state.next_packet_seq[i] = (if_packet_info.packet_count+1)%16;
+
+ //setup the buffer to point to the data
+ state.copy_buffs[i] = reinterpret_cast<const boost::uint8_t *>(vrt_hdr + if_packet_info.num_header_words32);
+
+ //store the minimum payload length into the copy buffer length
+ size_t num_payload_bytes = if_packet_info.num_payload_words32*sizeof(boost::uint32_t);
+ if (i == 0 or state.size_of_copy_buffs > num_payload_bytes){
+ state.size_of_copy_buffs = num_payload_bytes;
+ }
}
- state.next_packet_seq = (packet_count_out+1)%16;
- //setup the buffer to point to the data
- state.copy_buff = boost::asio::buffer(
- vrt_hdr + num_header_words32_out,
- num_payload_words32_out*sizeof(boost::uint32_t)
+ //store the last vrt info into the metadata
+ metadata.has_time_spec = if_packet_info.has_tsi and if_packet_info.has_tsf;
+ metadata.time_spec = uhd::time_spec_t(
+ time_t(if_packet_info.tsi), size_t(if_packet_info.tsf), tick_rate
);
}
@@ -111,24 +120,24 @@ namespace vrt_packet_handler{
template<typename vrt_unpacker_type>
static UHD_INLINE size_t _recv1(
recv_state &state,
- void *recv_mem,
+ const std::vector<void *> &buffs,
+ size_t offset_bytes,
size_t total_samps,
uhd::rx_metadata_t &metadata,
const uhd::io_type_t &io_type,
const uhd::otw_type_t &otw_type,
double tick_rate,
vrt_unpacker_type vrt_unpacker,
- const get_recv_buff_t &get_recv_buff,
+ const get_recv_buffs_t &get_recv_buffs,
//use these two params to handle a layer above vrt
- size_t vrt_header_offset_words32,
- const recv_cb_t &recv_cb
+ size_t vrt_header_offset_words32
){
+ metadata.has_time_spec = false; //false unless set in the helper
+
//perform a receive if no rx data is waiting to be copied
- if (boost::asio::buffer_size(state.copy_buff) == 0){
+ if (state.size_of_copy_buffs == 0){
state.fragment_offset_in_samps = 0;
- state.managed_buff = get_recv_buff();
- if (state.managed_buff.get() == NULL) return 0;
- recv_cb(state.managed_buff); //callback before vrt unpack
+ if (not get_recv_buffs(state.managed_buffs)) return 0;
try{
_recv1_helper(
state, metadata, tick_rate, vrt_unpacker, vrt_header_offset_words32
@@ -141,28 +150,30 @@ 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 = boost::asio::buffer_size(state.copy_buff);
- size_t num_samps = std::min(total_samps, bytes_available/bytes_per_item);
+ size_t bytes_available = state.size_of_copy_buffs;
+ 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<boost::uint8_t *>(buffs[i]) + offset_bytes,
+ io_type, nsamps_to_copy
+ );
+
+ //update the rx copy buffer to reflect the bytes copied
+ state.copy_buffs[i] += bytes_to_copy;
+ }
+ //update the copy buffer's availability
+ state.size_of_copy_buffs -= bytes_to_copy;
//setup the fragment flags and offset
- metadata.more_fragments = total_samps < num_samps;
+ metadata.more_fragments = state.size_of_copy_buffs != 0;
metadata.fragment_offset = state.fragment_offset_in_samps;
- state.fragment_offset_in_samps += num_samps; //set for next call
-
- //copy-convert the samples from the recv buffer
- uhd::transport::convert_otw_type_to_io_type(
- boost::asio::buffer_cast<const void*>(state.copy_buff), otw_type,
- recv_mem, io_type, num_samps
- );
-
- //update the rx copy buffer to reflect the bytes copied
- size_t bytes_copied = num_samps*bytes_per_item;
- state.copy_buff = boost::asio::buffer(
- boost::asio::buffer_cast<const boost::uint8_t*>(state.copy_buff) + bytes_copied,
- bytes_available - bytes_copied
- );
+ state.fragment_offset_in_samps += nsamps_to_copy; //set for next call
- return num_samps;
+ return nsamps_to_copy;
}
/*******************************************************************
@@ -171,21 +182,18 @@ namespace vrt_packet_handler{
template<typename vrt_unpacker_type>
static UHD_INLINE size_t recv(
recv_state &state,
- const boost::asio::mutable_buffer &buff,
+ const std::vector<void *> &buffs,
+ const size_t total_num_samps,
uhd::rx_metadata_t &metadata,
uhd::device::recv_mode_t recv_mode,
const uhd::io_type_t &io_type,
const uhd::otw_type_t &otw_type,
double tick_rate,
vrt_unpacker_type vrt_unpacker,
- const get_recv_buff_t &get_recv_buff,
+ const get_recv_buffs_t &get_recv_buffs,
//use these two params to handle a layer above vrt
- size_t vrt_header_offset_words32 = 0,
- const recv_cb_t& recv_cb = &recv_cb_nop
+ size_t vrt_header_offset_words32 = 0
){
- metadata = uhd::rx_metadata_t(); //init the metadata
- const size_t total_num_samps = boost::asio::buffer_size(buff)/io_type.size;
-
switch(recv_mode){
////////////////////////////////////////////////////////////////
@@ -193,15 +201,14 @@ namespace vrt_packet_handler{
////////////////////////////////////////////////////////////////
return _recv1(
state,
- boost::asio::buffer_cast<void *>(buff),
+ buffs, 0,
total_num_samps,
metadata,
io_type, otw_type,
tick_rate,
vrt_unpacker,
- get_recv_buff,
- vrt_header_offset_words32,
- recv_cb
+ get_recv_buffs,
+ vrt_header_offset_words32
);
}
@@ -213,15 +220,14 @@ namespace vrt_packet_handler{
while(accum_num_samps < total_num_samps){
size_t num_samps = _recv1(
state,
- boost::asio::buffer_cast<boost::uint8_t *>(buff) + (accum_num_samps*io_type.size),
+ buffs, accum_num_samps*io_type.size,
total_num_samps - accum_num_samps,
(accum_num_samps == 0)? metadata : tmp_md, //only the first metadata gets kept
io_type, otw_type,
tick_rate,
vrt_unpacker,
- get_recv_buff,
- vrt_header_offset_words32,
- recv_cb
+ get_recv_buffs,
+ vrt_header_offset_words32
);
if (num_samps == 0) break; //had a recv timeout or error, break loop
accum_num_samps += num_samps;
@@ -236,23 +242,18 @@ namespace vrt_packet_handler{
/***********************************************************************
* vrt packet handler for send
**********************************************************************/
+ typedef std::vector<uhd::transport::managed_send_buffer::sptr> managed_send_buffs_t;
+ typedef boost::function<bool(managed_send_buffs_t &)> get_send_buffs_t;
+
struct send_state{
//init the expected seq number
size_t next_packet_seq;
- send_state(void){
- next_packet_seq = 0;
+ send_state(void) : next_packet_seq(0){
+ /* NOP */
}
};
- typedef boost::function<uhd::transport::managed_send_buffer::sptr(void)> get_send_buff_t;
-
- typedef boost::function<void(uhd::transport::managed_send_buffer::sptr)> send_cb_t;
-
- static UHD_INLINE void send_cb_nop(uhd::transport::managed_send_buffer::sptr){
- /* NOP */
- }
-
/*******************************************************************
* Pack a vrt header, copy-convert the data, and send it.
* - helper function for vrt_packet_handler::send
@@ -260,46 +261,42 @@ namespace vrt_packet_handler{
template<typename vrt_packer_type>
static UHD_INLINE void _send1(
send_state &state,
- const void *send_mem,
+ const std::vector<const void *> &buffs,
+ size_t offset_bytes,
size_t num_samps,
- const uhd::tx_metadata_t &metadata,
+ uhd::transport::vrt::if_packet_info_t &if_packet_info,
const uhd::io_type_t &io_type,
const uhd::otw_type_t &otw_type,
- double tick_rate,
vrt_packer_type vrt_packer,
- const get_send_buff_t &get_send_buff,
- size_t vrt_header_offset_words32,
- const send_cb_t& send_cb
+ const get_send_buffs_t &get_send_buffs,
+ size_t vrt_header_offset_words32
){
- //get a new managed send buffer
- uhd::transport::managed_send_buffer::sptr send_buff = get_send_buff();
- boost::uint32_t *tx_mem = send_buff->cast<boost::uint32_t *>() + vrt_header_offset_words32;
-
- size_t num_header_words32, num_packet_words32;
- size_t packet_count = state.next_packet_seq++;
-
- //pack metadata into a vrt header
- vrt_packer(
- metadata, //input
- tx_mem, //output
- num_header_words32, //output
- num_samps, //input
- num_packet_words32, //output
- packet_count, //input
- tick_rate
- );
-
- //copy-convert the samples into the send buffer
- uhd::transport::convert_io_type_to_otw_type(
- send_mem, io_type,
- tx_mem + num_header_words32, otw_type,
- num_samps
- );
-
- send_cb(send_buff); //callback after memory filled
+ //load the rest of the if_packet_info in here
+ if_packet_info.num_payload_words32 = (num_samps*otw_type.get_sample_size())/sizeof(boost::uint32_t);
+ if_packet_info.packet_count = state.next_packet_seq++;
+
+ //get send buffers for each channel
+ managed_send_buffs_t send_buffs(buffs.size());
+ UHD_ASSERT_THROW(get_send_buffs(send_buffs));
+
+ for (size_t i = 0; i < buffs.size(); i++){
+ //calculate pointers with offsets to io and otw memory
+ const boost::uint8_t *io_mem = reinterpret_cast<const boost::uint8_t *>(buffs[i]) + offset_bytes;
+ boost::uint32_t *otw_mem = send_buffs[i]->cast<boost::uint32_t *>() + vrt_header_offset_words32;
+
+ //pack metadata into a vrt header
+ vrt_packer(otw_mem, if_packet_info);
+
+ //copy-convert the samples into the send buffer
+ uhd::transport::convert_io_type_to_otw_type(
+ io_mem, io_type,
+ otw_mem + if_packet_info.num_header_words32, otw_type,
+ num_samps
+ );
- //commit the samples to the zero-copy interface
- send_buff->commit(num_packet_words32*sizeof(boost::uint32_t));
+ //commit the samples to the zero-copy interface
+ send_buffs[i]->commit(if_packet_info.num_packet_words32*sizeof(boost::uint32_t));
+ }
}
/*******************************************************************
@@ -308,20 +305,27 @@ namespace vrt_packet_handler{
template<typename vrt_packer_type>
static UHD_INLINE size_t send(
send_state &state,
- const boost::asio::const_buffer &buff,
+ const std::vector<const void *> &buffs,
+ const size_t total_num_samps,
const uhd::tx_metadata_t &metadata,
uhd::device::send_mode_t send_mode,
const uhd::io_type_t &io_type,
const uhd::otw_type_t &otw_type,
double tick_rate,
vrt_packer_type vrt_packer,
- const get_send_buff_t &get_send_buff,
+ const get_send_buffs_t &get_send_buffs,
size_t max_samples_per_packet,
//use these two params to handle a layer above vrt
- size_t vrt_header_offset_words32 = 0,
- const send_cb_t& send_cb = &send_cb_nop
+ size_t vrt_header_offset_words32 = 0
){
- const size_t total_num_samps = boost::asio::buffer_size(buff)/io_type.size;
+ //translate the metadata to vrt if packet info
+ uhd::transport::vrt::if_packet_info_t if_packet_info;
+ if_packet_info.has_sid = false;
+ if_packet_info.has_cid = false;
+ if_packet_info.has_tlr = false;
+ if_packet_info.tsi = boost::uint32_t(metadata.time_spec.get_full_secs());
+ if_packet_info.tsf = boost::uint64_t(metadata.time_spec.get_tick_count(tick_rate));
+
if (total_num_samps <= max_samples_per_packet) send_mode = uhd::device::SEND_MODE_ONE_PACKET;
switch(send_mode){
@@ -329,17 +333,22 @@ namespace vrt_packet_handler{
case uhd::device::SEND_MODE_ONE_PACKET:{
////////////////////////////////////////////////////////////////
size_t num_samps = std::min(total_num_samps, max_samples_per_packet);
+
+ //fill in parts of the packet info overwrote in full buff mode
+ if_packet_info.has_tsi = metadata.has_time_spec;
+ if_packet_info.has_tsf = metadata.has_time_spec;
+ if_packet_info.sob = metadata.start_of_burst;
+ if_packet_info.eob = metadata.end_of_burst;
+
_send1(
state,
- boost::asio::buffer_cast<const void *>(buff),
+ buffs, 0,
num_samps,
- metadata,
+ if_packet_info,
io_type, otw_type,
- tick_rate,
vrt_packer,
- get_send_buff,
- vrt_header_offset_words32,
- send_cb
+ get_send_buffs,
+ vrt_header_offset_words32
);
return num_samps;
}
@@ -352,29 +361,25 @@ namespace vrt_packet_handler{
static const size_t first_fragment_index = 0;
const size_t final_fragment_index = num_fragments-1;
- //make a rw copy of the metadata to re-flag below
- uhd::tx_metadata_t md(metadata);
-
//loop through the following fragment indexes
for (size_t n = first_fragment_index; n <= final_fragment_index; n++){
//calculate new flags for the fragments
- md.has_time_spec = metadata.has_time_spec and (n == first_fragment_index);
- md.start_of_burst = metadata.start_of_burst and (n == first_fragment_index);
- md.end_of_burst = metadata.end_of_burst and (n == final_fragment_index);
+ if_packet_info.has_tsi = metadata.has_time_spec and (n == first_fragment_index);
+ if_packet_info.has_tsf = metadata.has_time_spec and (n == first_fragment_index);
+ if_packet_info.sob = metadata.start_of_burst and (n == first_fragment_index);
+ if_packet_info.eob = metadata.end_of_burst and (n == final_fragment_index);
//send the fragment with the helper function
_send1(
state,
- boost::asio::buffer_cast<const boost::uint8_t *>(buff) + (n*max_samples_per_packet*io_type.size),
+ buffs, n*max_samples_per_packet*io_type.size,
(n == final_fragment_index)?(total_num_samps%max_samples_per_packet):max_samples_per_packet,
- md,
+ if_packet_info,
io_type, otw_type,
- tick_rate,
vrt_packer,
- get_send_buff,
- vrt_header_offset_words32,
- send_cb
+ get_send_buffs,
+ vrt_header_offset_words32
);
}
return total_num_samps;
diff --git a/host/lib/types.cpp b/host/lib/types.cpp
index daf3be7f7..9cf2a2220 100644
--- a/host/lib/types.cpp
+++ b/host/lib/types.cpp
@@ -96,8 +96,6 @@ stream_cmd_t::stream_cmd_t(const stream_mode_t &stream_mode):
* metadata
**********************************************************************/
rx_metadata_t::rx_metadata_t(void):
- has_stream_id(false),
- stream_id(0),
has_time_spec(false),
time_spec(time_spec_t()),
more_fragments(false),
@@ -107,8 +105,6 @@ rx_metadata_t::rx_metadata_t(void):
}
tx_metadata_t::tx_metadata_t(void):
- has_stream_id(false),
- stream_id(0),
has_time_spec(false),
time_spec(time_spec_t()),
start_of_burst(false),
@@ -120,19 +116,63 @@ tx_metadata_t::tx_metadata_t(void):
/***********************************************************************
* time spec
**********************************************************************/
-time_spec_t::time_spec_t(boost::uint32_t secs, double nsecs):
- secs(secs),
- nsecs(nsecs)
+time_spec_t::time_spec_t(double secs):
+ _full_secs(0),
+ _frac_secs(secs)
{
/* NOP */
}
-boost::uint32_t time_spec_t::get_ticks(double tick_rate) const{
- return boost::math::iround(nsecs*tick_rate*1e-9);
+time_spec_t::time_spec_t(time_t full_secs, double frac_secs):
+ _full_secs(full_secs),
+ _frac_secs(frac_secs)
+{
+ /* NOP */
+}
+
+time_spec_t::time_spec_t(time_t full_secs, size_t tick_count, double tick_rate):
+ _full_secs(full_secs),
+ _frac_secs(double(tick_count)/tick_rate)
+{
+ /* NOP */
+}
+
+size_t time_spec_t::get_tick_count(double tick_rate) const{
+ return boost::math::iround(this->get_frac_secs()*tick_rate);
+}
+
+double time_spec_t::get_real_secs(void) const{
+ return this->_full_secs + this->_frac_secs;
+}
+
+time_t time_spec_t::get_full_secs(void) const{
+ return this->_full_secs + time_t(std::floor(this->_frac_secs));
+}
+
+double time_spec_t::get_frac_secs(void) const{
+ return std::fmod(this->_frac_secs, 1.0);
+}
+
+time_spec_t &time_spec_t::operator+=(const time_spec_t &rhs){
+ this->_full_secs += rhs.get_full_secs();
+ this->_frac_secs += rhs.get_frac_secs();
+ return *this;
+}
+
+time_spec_t &time_spec_t::operator-=(const time_spec_t &rhs){
+ this->_full_secs -= rhs.get_full_secs();
+ this->_frac_secs -= rhs.get_frac_secs();
+ return *this;
+}
+
+bool uhd::operator==(const time_spec_t &lhs, const time_spec_t &rhs){
+ return lhs.get_full_secs() == rhs.get_full_secs() and lhs.get_frac_secs() == rhs.get_frac_secs();
}
-void time_spec_t::set_ticks(boost::uint32_t ticks, double tick_rate){
- nsecs = double(ticks)*1e9/tick_rate;
+bool uhd::operator<(const time_spec_t &lhs, const time_spec_t &rhs){
+ if (lhs.get_full_secs() < rhs.get_full_secs()) return true;
+ if (lhs.get_full_secs() > rhs.get_full_secs()) return false;
+ return lhs.get_frac_secs() < rhs.get_frac_secs();
}
/***********************************************************************
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..fd8225074
--- /dev/null
+++ b/host/lib/usrp/mimo_usrp.cpp
@@ -0,0 +1,291 @@
+//
+// 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 <http://www.gnu.org/licenses/>.
+//
+
+#include <uhd/usrp/mimo_usrp.hpp>
+#include <uhd/usrp/tune_helper.hpp>
+#include <uhd/utils/assert.hpp>
+#include <uhd/utils/algorithm.hpp>
+#include <uhd/usrp/subdev_props.hpp>
+#include <uhd/usrp/mboard_props.hpp>
+#include <uhd/usrp/device_props.hpp>
+#include <uhd/usrp/dboard_props.hpp>
+#include <uhd/usrp/dsp_props.hpp>
+#include <boost/foreach.hpp>
+#include <boost/format.hpp>
+#include <boost/thread.hpp>
+#include <stdexcept>
+#include <iostream>
+
+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<prop_names_t>()){
+ _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<prop_names_t>().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<prop_names_t>().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<std::string>()
+ );
+ 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<std::string>()
+ % _rx_dsps.at(i)[DSP_PROP_NAME].as<std::string>()
+ % _rx_dboards.at(i)[DBOARD_PROP_NAME].as<std::string>()
+ % _rx_subdevs.at(i)[SUBDEV_PROP_NAME].as<std::string>()
+ % _tx_dsps.at(i)[DSP_PROP_NAME].as<std::string>()
+ % _tx_dboards.at(i)[DBOARD_PROP_NAME].as<std::string>()
+ % _tx_subdevs.at(i)[SUBDEV_PROP_NAME].as<std::string>()
+ );
+ }
+ return buff;
+ }
+
+ size_t get_num_channels(void){
+ return _mboards.size();
+ }
+
+ /*******************************************************************
+ * 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<time_spec_t>();
+ }
+
+ 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 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);
+ boost::this_thread::sleep(boost::posix_time::seconds(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);
+ boost::this_thread::sleep(boost::posix_time::seconds(1));
+ }
+
+ 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
+ ******************************************************************/
+ void set_rx_rate_all(double rate){
+ std::vector<double> _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<double>());
+ }
+ _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<freq_range_t>();
+ }
+
+ 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<float>();
+ }
+
+ gain_range_t get_rx_gain_range(size_t chan){
+ return _rx_subdevs.at(chan)[SUBDEV_PROP_GAIN_RANGE].as<gain_range_t>();
+ }
+
+ 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::string>();
+ }
+
+ std::vector<std::string> get_rx_antennas(size_t chan){
+ return _rx_subdevs.at(chan)[SUBDEV_PROP_ANTENNA_NAMES].as<prop_names_t>();
+ }
+
+ bool get_rx_lo_locked(size_t chan){
+ return _rx_subdevs.at(chan)[SUBDEV_PROP_LO_LOCKED].as<bool>();
+ }
+
+ float read_rssi(size_t chan){
+ return _rx_subdevs.at(chan)[SUBDEV_PROP_RSSI].as<float>();
+ }
+
+ /*******************************************************************
+ * TX methods
+ ******************************************************************/
+ void set_tx_rate_all(double rate){
+ std::vector<double> _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<double>());
+ }
+ _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 _tx_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<freq_range_t>();
+ }
+
+ 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<float>();
+ }
+
+ gain_range_t get_tx_gain_range(size_t chan){
+ return _tx_subdevs.at(chan)[SUBDEV_PROP_GAIN_RANGE].as<gain_range_t>();
+ }
+
+ 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::string>();
+ }
+
+ std::vector<std::string> get_tx_antennas(size_t chan){
+ return _tx_subdevs.at(chan)[SUBDEV_PROP_ANTENNA_NAMES].as<prop_names_t>();
+ }
+
+ bool get_tx_lo_locked(size_t chan){
+ return _tx_subdevs.at(chan)[SUBDEV_PROP_LO_LOCKED].as<bool>();
+ }
+
+private:
+ device::sptr _dev;
+ std::vector<wax::obj> _mboards;
+ std::vector<wax::obj> _rx_dsps;
+ std::vector<wax::obj> _tx_dsps;
+ std::vector<wax::obj> _rx_dboards;
+ std::vector<wax::obj> _tx_dboards;
+ std::vector<wax::obj> _rx_subdevs;
+ std::vector<wax::obj> _tx_subdevs;
+
+ //shadows
+ double _rx_rate, _tx_rate;
+};
+
+/***********************************************************************
+ * 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..56e82d7ee 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"
@@ -86,6 +86,10 @@ public:
/*******************************************************************
* Misc
******************************************************************/
+ time_spec_t get_time_now(void){
+ return _mboard[MBOARD_PROP_TIME_NOW].as<time_spec_t>();
+ }
+
void set_time_now(const time_spec_t &time_spec){
_mboard[MBOARD_PROP_TIME_NOW] = time_spec;
}
@@ -102,10 +106,6 @@ public:
_mboard[MBOARD_PROP_CLOCK_CONFIG] = clock_config;
}
- float read_rssi(void){
- return _rx_subdev[SUBDEV_PROP_RSSI].as<float>();
- }
-
/*******************************************************************
* RX methods
******************************************************************/
@@ -157,6 +157,10 @@ public:
return _rx_subdev[SUBDEV_PROP_LO_LOCKED].as<bool>();
}
+ float read_rssi(void){
+ return _rx_subdev[SUBDEV_PROP_RSSI].as<float>();
+ }
+
/*******************************************************************
* TX methods
******************************************************************/
diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp
index fef486771..fa8d1a674 100644
--- a/host/lib/usrp/usrp2/dboard_impl.cpp
+++ b/host/lib/usrp/usrp2/dboard_impl.cpp
@@ -33,7 +33,7 @@ using namespace uhd::usrp;
/***********************************************************************
* Helper Methods
**********************************************************************/
-void usrp2_impl::dboard_init(void){
+void usrp2_mboard_impl::dboard_init(void){
//read the dboard eeprom to extract the dboard ids
_rx_db_eeprom = dboard_eeprom_t(_iface->read_eeprom(I2C_ADDR_RX_DB, 0, dboard_eeprom_t::num_bytes()));
_tx_db_eeprom = dboard_eeprom_t(_iface->read_eeprom(I2C_ADDR_TX_DB, 0, dboard_eeprom_t::num_bytes()));
@@ -46,12 +46,12 @@ void usrp2_impl::dboard_init(void){
//load dboards
_rx_dboard_proxy = wax_obj_proxy::make(
- boost::bind(&usrp2_impl::rx_dboard_get, this, _1, _2),
- boost::bind(&usrp2_impl::rx_dboard_set, this, _1, _2)
+ boost::bind(&usrp2_mboard_impl::rx_dboard_get, this, _1, _2),
+ boost::bind(&usrp2_mboard_impl::rx_dboard_set, this, _1, _2)
);
_tx_dboard_proxy = wax_obj_proxy::make(
- boost::bind(&usrp2_impl::tx_dboard_get, this, _1, _2),
- boost::bind(&usrp2_impl::tx_dboard_set, this, _1, _2)
+ boost::bind(&usrp2_mboard_impl::tx_dboard_get, this, _1, _2),
+ boost::bind(&usrp2_mboard_impl::tx_dboard_set, this, _1, _2)
);
//init the subdevs in use (use the first subdevice)
@@ -62,7 +62,7 @@ void usrp2_impl::dboard_init(void){
/***********************************************************************
* RX DBoard Properties
**********************************************************************/
-void usrp2_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){
+void usrp2_mboard_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){
wax::obj key; std::string name;
boost::tie(key, name) = extract_named_prop(key_);
@@ -96,7 +96,7 @@ void usrp2_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){
}
}
-void usrp2_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){
+void usrp2_mboard_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){
switch(key.as<dboard_prop_t>()){
case DBOARD_PROP_USED_SUBDEVS:{
_rx_subdevs_in_use = val.as<prop_names_t>();
@@ -122,7 +122,7 @@ void usrp2_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){
/***********************************************************************
* TX DBoard Properties
**********************************************************************/
-void usrp2_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){
+void usrp2_mboard_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){
wax::obj key; std::string name;
boost::tie(key, name) = extract_named_prop(key_);
@@ -156,7 +156,7 @@ void usrp2_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){
}
}
-void usrp2_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val){
+void usrp2_mboard_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val){
switch(key.as<dboard_prop_t>()){
case DBOARD_PROP_USED_SUBDEVS:{
_tx_subdevs_in_use = val.as<prop_names_t>();
diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp
index 367cde2e1..c315a2eec 100644
--- a/host/lib/usrp/usrp2/dsp_impl.cpp
+++ b/host/lib/usrp/usrp2/dsp_impl.cpp
@@ -41,11 +41,11 @@ pick_closest_rate(double exact_rate, const std::vector<rate_t> &rates){
return closest_match;
}
-void usrp2_impl::init_ddc_config(void){
+void usrp2_mboard_impl::init_ddc_config(void){
//create the ddc in the rx dsp dict
_rx_dsp_proxy = wax_obj_proxy::make(
- boost::bind(&usrp2_impl::ddc_get, this, _1, _2),
- boost::bind(&usrp2_impl::ddc_set, this, _1, _2)
+ boost::bind(&usrp2_mboard_impl::ddc_get, this, _1, _2),
+ boost::bind(&usrp2_mboard_impl::ddc_set, this, _1, _2)
);
//initial config and update
@@ -56,7 +56,7 @@ void usrp2_impl::init_ddc_config(void){
/***********************************************************************
* DDC Properties
**********************************************************************/
-void usrp2_impl::ddc_get(const wax::obj &key, wax::obj &val){
+void usrp2_mboard_impl::ddc_get(const wax::obj &key, wax::obj &val){
switch(key.as<dsp_prop_t>()){
case DSP_PROP_NAME:
val = std::string("usrp2 ddc0");
@@ -82,7 +82,7 @@ void usrp2_impl::ddc_get(const wax::obj &key, wax::obj &val){
}
}
-void usrp2_impl::ddc_set(const wax::obj &key, const wax::obj &val){
+void usrp2_mboard_impl::ddc_set(const wax::obj &key, const wax::obj &val){
switch(key.as<dsp_prop_t>()){
case DSP_PROP_FREQ_SHIFT:{
@@ -116,11 +116,11 @@ void usrp2_impl::ddc_set(const wax::obj &key, const wax::obj &val){
/***********************************************************************
* DUC Helper Methods
**********************************************************************/
-void usrp2_impl::init_duc_config(void){
+void usrp2_mboard_impl::init_duc_config(void){
//create the duc in the tx dsp dict
_tx_dsp_proxy = wax_obj_proxy::make(
- boost::bind(&usrp2_impl::duc_get, this, _1, _2),
- boost::bind(&usrp2_impl::duc_set, this, _1, _2)
+ boost::bind(&usrp2_mboard_impl::duc_get, this, _1, _2),
+ boost::bind(&usrp2_mboard_impl::duc_set, this, _1, _2)
);
//initial config and update
@@ -131,7 +131,7 @@ void usrp2_impl::init_duc_config(void){
/***********************************************************************
* DUC Properties
**********************************************************************/
-void usrp2_impl::duc_get(const wax::obj &key, wax::obj &val){
+void usrp2_mboard_impl::duc_get(const wax::obj &key, wax::obj &val){
switch(key.as<dsp_prop_t>()){
case DSP_PROP_NAME:
val = std::string("usrp2 duc0");
@@ -157,7 +157,7 @@ void usrp2_impl::duc_get(const wax::obj &key, wax::obj &val){
}
}
-void usrp2_impl::duc_set(const wax::obj &key, const wax::obj &val){
+void usrp2_mboard_impl::duc_set(const wax::obj &key, const wax::obj &val){
switch(key.as<dsp_prop_t>()){
case DSP_PROP_FREQ_SHIFT:{
diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h
index 242d268ec..4c66aa41e 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
@@ -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/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp
index aa0f63321..c96528694 100644
--- a/host/lib/usrp/usrp2/io_impl.cpp
+++ b/host/lib/usrp/usrp2/io_impl.cpp
@@ -20,7 +20,7 @@
#include "usrp2_regs.hpp"
#include <uhd/utils/thread_priority.hpp>
#include <uhd/transport/convert_types.hpp>
-#include <uhd/transport/bounded_buffer.hpp>
+#include <uhd/transport/alignment_buffer.hpp>
#include <boost/format.hpp>
#include <boost/asio.hpp> //htonl and ntohl
#include <boost/bind.hpp>
@@ -34,56 +34,81 @@ namespace asio = boost::asio;
/***********************************************************************
* io impl details (internal to this file)
+ * - pirate crew
+ * - alignment buffer
+ * - thread loop
+ * - vrt packet handler states
**********************************************************************/
struct usrp2_impl::io_impl{
+ typedef alignment_buffer<managed_recv_buffer::sptr, time_spec_t> alignment_buffer_type;
- io_impl(zero_copy_if::sptr zc_if);
- ~io_impl(void);
+ io_impl(size_t num_frames, size_t width):
+ packet_handler_recv_state(width),
+ recv_pirate_booty(alignment_buffer_type::make(num_frames, width))
+ {
+ /* NOP */
+ }
+
+ ~io_impl(void){
+ recv_pirate_crew_raiding = false;
+ recv_pirate_crew.interrupt_all();
+ recv_pirate_crew.join_all();
+ }
- managed_recv_buffer::sptr get_recv_buff(void);
+ bool get_recv_buffs(vrt_packet_handler::managed_recv_buffs_t &buffs){
+ boost::this_thread::disable_interruption di; //disable because the wait can throw
+ return recv_pirate_booty->pop_elems_with_timed_wait(buffs, boost::posix_time::milliseconds(100));
+ }
//state management for the vrt packet handler code
vrt_packet_handler::recv_state packet_handler_recv_state;
vrt_packet_handler::send_state packet_handler_send_state;
- //methods and variables for the recv pirate
- void recv_pirate_loop(zero_copy_if::sptr zc_if);
- boost::thread *recv_pirate_thread; bool recv_pirate_running;
- bounded_buffer<managed_recv_buffer::sptr>::sptr recv_pirate_booty;
+ //methods and variables for the pirate crew
+ void recv_pirate_loop(zero_copy_if::sptr, usrp2_mboard_impl::sptr, size_t);
+ boost::thread_group recv_pirate_crew;
+ bool recv_pirate_crew_raiding;
+ alignment_buffer_type::sptr recv_pirate_booty;
};
-usrp2_impl::io_impl::io_impl(zero_copy_if::sptr zc_if){
- //create a large enough booty
- size_t num_frames = zc_if->get_num_recv_frames();
- std::cout << "Recv pirate num frames: " << num_frames << std::endl;
- recv_pirate_booty = bounded_buffer<managed_recv_buffer::sptr>::make(num_frames);
-
- //create a new pirate thread (yarr!!)
- recv_pirate_thread = new boost::thread(
- boost::bind(&usrp2_impl::io_impl::recv_pirate_loop, this, zc_if)
- );
-}
-
-usrp2_impl::io_impl::~io_impl(void){
- recv_pirate_running = false;
- recv_pirate_thread->interrupt();
- recv_pirate_thread->join();
- delete recv_pirate_thread;
-}
-
-managed_recv_buffer::sptr usrp2_impl::io_impl::get_recv_buff(void){
- managed_recv_buffer::sptr buff;
- boost::this_thread::disable_interruption di; //disable because the wait can throw
- recv_pirate_booty->pop_with_timed_wait(buff, boost::posix_time::milliseconds(100));
- return buff; //a timeout means that we return a null sptr...
-}
-
-void usrp2_impl::io_impl::recv_pirate_loop(zero_copy_if::sptr zc_if){
+/***********************************************************************
+ * Receive Pirate Loop
+ * - while raiding, loot for recv buffers
+ * - put booty into the alignment buffer
+ **********************************************************************/
+void usrp2_impl::io_impl::recv_pirate_loop(
+ zero_copy_if::sptr zc_if,
+ usrp2_mboard_impl::sptr mboard,
+ size_t index
+){
set_thread_priority_safe();
- recv_pirate_running = true;
- while(recv_pirate_running){
+ recv_pirate_crew_raiding = true;
+ while(recv_pirate_crew_raiding){
managed_recv_buffer::sptr buff = zc_if->get_recv_buff();
- if (buff->size()) recv_pirate_booty->push_with_pop_on_full(buff);
+ if (buff->size() == 0) continue; //ignore timeout buffers
+
+ try{
+ //extract the vrt header packet info
+ vrt::if_packet_info_t if_packet_info;
+ if_packet_info.num_packet_words32 = buff->size()/sizeof(boost::uint32_t);
+ vrt::if_hdr_unpack_be(buff->cast<const boost::uint32_t *>(), if_packet_info);
+
+ //extract the timespec and round to the nearest packet
+ UHD_ASSERT_THROW(if_packet_info.has_tsi and if_packet_info.has_tsf);
+
+ //size_t pkt_dur_ticks = mboard->get_master_clock_freq() * 1; //TODO FIXME
+ //size_t(if_packet_info.tsf) - size_t(if_packet_info.tsf)%pkt_dur_ticks
+ //the idea is to round the time specs to packet boundaries to avoid the issue
+ //of never getting alignment when things are not locked properly
+ time_spec_t time(
+ time_t(if_packet_info.tsi), size_t(if_packet_info.tsf), mboard->get_master_clock_freq()
+ );
+
+ //push the packet into the buffer with the new time
+ recv_pirate_booty->push_with_pop_on_full(buff, time, index);
+ }catch(const std::exception &e){
+ std::cerr << "Error (usrp2 recv pirate loop): " << e.what() << std::endl;
+ }
}
}
@@ -91,58 +116,64 @@ void usrp2_impl::io_impl::recv_pirate_loop(zero_copy_if::sptr zc_if){
* Helper Functions
**********************************************************************/
void usrp2_impl::io_init(void){
- //setup rx otw type
- _rx_otw_type.width = 16;
- _rx_otw_type.shift = 0;
- _rx_otw_type.byteorder = otw_type_t::BO_BIG_ENDIAN;
+ //send a small data packet so the usrp2 knows the udp source port
+ for(size_t i = 0; i < _data_transports.size(); i++){
+ managed_send_buffer::sptr send_buff = _data_transports[i]->get_send_buff();
+ boost::uint32_t data = htonl(USRP2_INVALID_VRT_HEADER);
+ memcpy(send_buff->cast<void*>(), &data, sizeof(data));
+ send_buff->commit(sizeof(data));
+ }
- //setup tx otw type
- _tx_otw_type.width = 16;
- _tx_otw_type.shift = 0;
- _tx_otw_type.byteorder = otw_type_t::BO_BIG_ENDIAN;
+ //the number of recv frames is the number for the first transport
+ //the assumption is that all data transports should be identical
+ size_t num_frames = _data_transports.front()->get_num_recv_frames();
- //send a small data packet so the usrp2 knows the udp source port
- managed_send_buffer::sptr send_buff = _data_transport->get_send_buff();
- boost::uint32_t data = htonl(USRP2_INVALID_VRT_HEADER);
- memcpy(send_buff->cast<void*>(), &data, sizeof(data));
- send_buff->commit(sizeof(data));
+ //create new io impl
+ _io_impl = UHD_PIMPL_MAKE(io_impl, (num_frames, _data_transports.size()));
+
+ //create a new pirate thread for each zc if (yarr!!)
+ for (size_t i = 0; i < _data_transports.size(); i++){
+ _io_impl->recv_pirate_crew.create_thread(boost::bind(
+ &usrp2_impl::io_impl::recv_pirate_loop,
+ _io_impl, _data_transports.at(i),
+ _mboards.at(i), i
+ ));
+ }
- //setup RX DSP regs
std::cout << "RX samples per packet: " << get_max_recv_samps_per_packet() << std::endl;
- _iface->poke32(U2_REG_RX_CTRL_NSAMPS_PER_PKT, get_max_recv_samps_per_packet());
- _iface->poke32(U2_REG_RX_CTRL_NCHANNELS, 1);
- _iface->poke32(U2_REG_RX_CTRL_CLEAR_OVERRUN, 1); //reset
- _iface->poke32(U2_REG_RX_CTRL_VRT_HEADER, 0
- | (0x1 << 28) //if data with stream id
- | (0x1 << 26) //has trailer
- | (0x3 << 22) //integer time other
- | (0x1 << 20) //fractional time sample count
- );
- _iface->poke32(U2_REG_RX_CTRL_VRT_STREAM_ID, 0);
- _iface->poke32(U2_REG_RX_CTRL_VRT_TRAILER, 0);
-
std::cout << "TX samples per packet: " << get_max_send_samps_per_packet() << std::endl;
-
- //create new io impl
- _io_impl = UHD_PIMPL_MAKE(io_impl, (_data_transport));
+ std::cout << "Recv pirate num frames: " << num_frames << std::endl;
}
/***********************************************************************
* Send Data
**********************************************************************/
+bool get_send_buffs(
+ const std::vector<udp_zero_copy::sptr> &trans,
+ vrt_packet_handler::managed_send_buffs_t &buffs
+){
+ UHD_ASSERT_THROW(trans.size() == buffs.size());
+ for (size_t i = 0; i < buffs.size(); i++){
+ buffs[i] = trans[i]->get_send_buff();
+ }
+ return true;
+}
+
size_t usrp2_impl::send(
- const asio::const_buffer &buff,
+ const std::vector<const void *> &buffs,
+ size_t num_samps,
const tx_metadata_t &metadata,
const io_type_t &io_type,
send_mode_t send_mode
){
return vrt_packet_handler::send(
- _io_impl->packet_handler_send_state, //last state of the send handler
- buff, metadata, send_mode, //buffer to empty and samples metadata
- io_type, _tx_otw_type, //input and output types to convert
- get_master_clock_freq(), //master clock tick rate
- uhd::transport::vrt::pack_be,
- boost::bind(&zero_copy_if::get_send_buff, _data_transport),
+ _io_impl->packet_handler_send_state, //last state of the send handler
+ buffs, num_samps, //buffer to fill
+ metadata, send_mode, //samples metadata
+ io_type, _io_helper.get_tx_otw_type(), //input and output types to convert
+ _mboards.front()->get_master_clock_freq(), //master clock tick rate
+ uhd::transport::vrt::if_hdr_pack_be,
+ boost::bind(&get_send_buffs, _data_transports, _1),
get_max_send_samps_per_packet()
);
}
@@ -151,17 +182,19 @@ size_t usrp2_impl::send(
* Receive Data
**********************************************************************/
size_t usrp2_impl::recv(
- const asio::mutable_buffer &buff,
+ const std::vector<void *> &buffs,
+ size_t num_samps,
rx_metadata_t &metadata,
const io_type_t &io_type,
recv_mode_t recv_mode
){
return vrt_packet_handler::recv(
- _io_impl->packet_handler_recv_state, //last state of the recv handler
- buff, metadata, recv_mode, //buffer to fill and samples metadata
- io_type, _rx_otw_type, //input and output types to convert
- get_master_clock_freq(), //master clock tick rate
- uhd::transport::vrt::unpack_be,
- boost::bind(&usrp2_impl::io_impl::get_recv_buff, _io_impl)
+ _io_impl->packet_handler_recv_state, //last state of the recv handler
+ buffs, num_samps, //buffer to fill
+ metadata, recv_mode, //samples metadata
+ io_type, _io_helper.get_rx_otw_type(), //input and output types to convert
+ _mboards.front()->get_master_clock_freq(), //master clock tick rate
+ uhd::transport::vrt::if_hdr_unpack_be,
+ boost::bind(&usrp2_impl::io_impl::get_recv_buffs, _io_impl, _1)
);
}
diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp
index 78fc5dc23..952954286 100644
--- a/host/lib/usrp/usrp2/mboard_impl.cpp
+++ b/host/lib/usrp/usrp2/mboard_impl.cpp
@@ -25,21 +25,77 @@
#include <boost/bind.hpp>
#include <boost/asio/ip/address_v4.hpp>
#include <boost/assign/list_of.hpp>
+#include <iostream>
using namespace uhd;
using namespace uhd::usrp;
/***********************************************************************
- * Helper Methods
+ * Structors
**********************************************************************/
-void usrp2_impl::mboard_init(void){
- _mboard_proxy = wax_obj_proxy::make(
- boost::bind(&usrp2_impl::mboard_get, this, _1, _2),
- boost::bind(&usrp2_impl::mboard_set, this, _1, _2)
+usrp2_mboard_impl::usrp2_mboard_impl(
+ size_t index,
+ transport::udp_simple::sptr ctrl_transport,
+ const usrp2_io_helper &io_helper
+):
+ _index(index),
+ _io_helper(io_helper)
+{
+ //make a new interface for usrp2 stuff
+ _iface = usrp2_iface::make(ctrl_transport);
+ _clock_ctrl = usrp2_clock_ctrl::make(_iface);
+ _codec_ctrl = usrp2_codec_ctrl::make(_iface);
+ _serdes_ctrl = usrp2_serdes_ctrl::make(_iface);
+
+ //TODO move to dsp impl...
+ //load the allowed decim/interp rates
+ //_USRP2_RATES = range(4, 128+1, 1) + range(130, 256+1, 2) + range(260, 512+1, 4)
+ _allowed_decim_and_interp_rates.clear();
+ for (size_t i = 4; i <= 128; i+=1){
+ _allowed_decim_and_interp_rates.push_back(i);
+ }
+ for (size_t i = 130; i <= 256; i+=2){
+ _allowed_decim_and_interp_rates.push_back(i);
+ }
+ for (size_t i = 260; i <= 512; i+=4){
+ _allowed_decim_and_interp_rates.push_back(i);
+ }
+
+ //setup the vrt rx registers
+ _iface->poke32(U2_REG_RX_CTRL_NSAMPS_PER_PKT, _io_helper.get_max_recv_samps_per_packet());
+ _iface->poke32(U2_REG_RX_CTRL_NCHANNELS, 1);
+ _iface->poke32(U2_REG_RX_CTRL_CLEAR_OVERRUN, 1); //reset
+ _iface->poke32(U2_REG_RX_CTRL_VRT_HEADER, 0
+ | (0x1 << 28) //if data with stream id
+ | (0x1 << 26) //has trailer
+ | (0x3 << 22) //integer time other
+ | (0x1 << 20) //fractional time sample count
);
+ _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();
+
+ //init the duc
+ init_duc_config();
+
+ //initialize the clock configuration
+ init_clock_config();
+
+ //init the tx and rx dboards (do last)
+ dboard_init();
}
-void usrp2_impl::init_clock_config(void){
+usrp2_mboard_impl::~usrp2_mboard_impl(void){
+ /* NOP */
+}
+
+/***********************************************************************
+ * Helper Methods
+ **********************************************************************/
+void usrp2_mboard_impl::init_clock_config(void){
//setup the clock configuration settings
_clock_config.ref_source = clock_config_t::REF_INT;
_clock_config.pps_source = clock_config_t::PPS_SMA;
@@ -49,7 +105,7 @@ void usrp2_impl::init_clock_config(void){
update_clock_config();
}
-void usrp2_impl::update_clock_config(void){
+void usrp2_mboard_impl::update_clock_config(void){
boost::uint32_t pps_flags = 0;
//translate pps source enums
@@ -82,19 +138,19 @@ void usrp2_impl::update_clock_config(void){
_clock_ctrl->enable_external_ref(use_external);
}
-void usrp2_impl::set_time_spec(const time_spec_t &time_spec, bool now){
+void usrp2_mboard_impl::set_time_spec(const time_spec_t &time_spec, bool now){
//set the ticks
- _iface->poke32(U2_REG_TIME64_TICKS, time_spec.get_ticks(get_master_clock_freq()));
+ _iface->poke32(U2_REG_TIME64_TICKS, time_spec.get_tick_count(get_master_clock_freq()));
//set the flags register
boost::uint32_t imm_flags = (now)? U2_FLAG_TIME64_LATCH_NOW : U2_FLAG_TIME64_LATCH_NEXT_PPS;
_iface->poke32(U2_REG_TIME64_IMM, imm_flags);
//set the seconds (latches in all 3 registers)
- _iface->poke32(U2_REG_TIME64_SECS, time_spec.secs);
+ _iface->poke32(U2_REG_TIME64_SECS, boost::uint32_t(time_spec.get_full_secs()));
}
-void usrp2_impl::issue_ddc_stream_cmd(const stream_cmd_t &stream_cmd){
+void usrp2_mboard_impl::issue_ddc_stream_cmd(const stream_cmd_t &stream_cmd){
UHD_ASSERT_THROW(stream_cmd.num_samps <= U2_REG_RX_CTRL_MAX_SAMPS_PER_CMD);
//setup the mode to instruction flags
@@ -113,19 +169,19 @@ void usrp2_impl::issue_ddc_stream_cmd(const stream_cmd_t &stream_cmd){
//issue the stream command
_iface->poke32(U2_REG_RX_CTRL_STREAM_CMD, U2_REG_RX_CTRL_MAKE_CMD(
- (inst_samps)? stream_cmd.num_samps : ((inst_chain)? get_max_recv_samps_per_packet() : 1),
+ (inst_samps)? stream_cmd.num_samps : ((inst_chain)? _io_helper.get_max_recv_samps_per_packet() : 1),
(stream_cmd.stream_now)? 1 : 0,
(inst_chain)? 1 : 0,
(inst_reload)? 1 : 0
));
- _iface->poke32(U2_REG_RX_CTRL_TIME_SECS, stream_cmd.time_spec.secs);
- _iface->poke32(U2_REG_RX_CTRL_TIME_TICKS, stream_cmd.time_spec.get_ticks(get_master_clock_freq()));
+ _iface->poke32(U2_REG_RX_CTRL_TIME_SECS, boost::uint32_t(stream_cmd.time_spec.get_full_secs()));
+ _iface->poke32(U2_REG_RX_CTRL_TIME_TICKS, stream_cmd.time_spec.get_tick_count(get_master_clock_freq()));
}
/***********************************************************************
* MBoard Get Properties
**********************************************************************/
-void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){
+void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){
wax::obj key; std::string name;
boost::tie(key, name) = extract_named_prop(key_);
@@ -148,7 +204,7 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){
//handle the get request conditioned on the key
switch(key.as<mboard_prop_t>()){
case MBOARD_PROP_NAME:
- val = std::string("usrp2 mboard");
+ val = str(boost::format("usrp2 mboard %d") % _index);
return;
case MBOARD_PROP_OTHERS:{
@@ -200,6 +256,16 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){
val = _clock_config;
return;
+ 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();
}
}
@@ -207,7 +273,7 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){
/***********************************************************************
* MBoard Set Properties
**********************************************************************/
-void usrp2_impl::mboard_set(const wax::obj &key, const wax::obj &val){
+void usrp2_mboard_impl::set(const wax::obj &key, const wax::obj &val){
//handle the other props
if (key.type() == typeid(std::string)){
if (key.as<std::string>() == "mac-addr"){
diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp
index 83e98904e..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<boost::uint16_t>(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 <class T> T peek(boost::uint32_t addr){
@@ -199,8 +213,8 @@ 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);
- return T(ntohl(out_data.data.poke_args.data));
+ 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 <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
#include <boost/cstdint.hpp>
+#include <utility>
#include "fw_common.h"
////////////////////////////////////////////////////////////////////////
@@ -49,6 +50,7 @@
class usrp2_iface : public uhd::i2c_iface, boost::noncopyable{
public:
typedef boost::shared_ptr<usrp2_iface> sptr;
+ typedef std::pair<boost::uint32_t, boost::uint32_t> pair64;
/*!
* Make a new usrp2 interface with the control transport.
@@ -65,6 +67,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
* \param data the 32bit data
diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp
index 36c264c3c..3402c26b1 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.cpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.cpp
@@ -21,6 +21,7 @@
#include <uhd/usrp/device_props.hpp>
#include <uhd/utils/assert.hpp>
#include <uhd/utils/static.hpp>
+#include <boost/algorithm/string.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/format.hpp>
#include <boost/foreach.hpp>
@@ -34,14 +35,23 @@ 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
+ **********************************************************************/
+std::vector<std::string> split_addrs(const std::string &addrs_str){
+ std::vector<std::string> addrs;
+ boost::split(addrs, addrs_str, boost::is_any_of("\t "));
+ return addrs;
+}
+
+template <class T> std::string num2str(T num){
+ return boost::lexical_cast<std::string>(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
@@ -58,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()
);
@@ -66,6 +76,16 @@ uhd::device_addrs_t usrp2::find(const device_addr_t &hint){
return usrp2_addrs;
}
+ //if there are multiple addresses, just return good, dont test
+ std::vector<std::string> addrs = split_addrs(hint["addr"]);
+ if (addrs.size() > 1){
+ device_addr_t new_addr;
+ new_addr["type"] = "usrp2";
+ new_addr["addr"] = hint["addr"];
+ usrp2_addrs.push_back(new_addr);
+ return usrp2_addrs;
+ }
+
//create a udp transport to communicate
std::string ctrl_port = boost::lexical_cast<std::string>(USRP2_UDP_CTRL_PORT);
udp_simple::sptr udp_transport = udp_simple::make_broadcast(
@@ -107,16 +127,7 @@ uhd::device_addrs_t usrp2::find(const device_addr_t &hint){
/***********************************************************************
* Make
**********************************************************************/
-template <class T> std::string num2str(T num){
- return boost::lexical_cast<std::string>(num);
-}
-
-device::sptr usrp2::make(const device_addr_t &device_addr){
- //create a control transport
- udp_simple::sptr ctrl_transport = udp_simple::make_connected(
- device_addr["addr"], num2str(USRP2_UDP_CTRL_PORT)
- );
-
+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")){
@@ -126,62 +137,48 @@ device::sptr usrp2::make(const device_addr_t &device_addr){
send_buff_size = size_t(boost::lexical_cast<double>(device_addr["send_buff_size"]));
}
- //create a data transport
- udp_zero_copy::sptr data_transport = udp_zero_copy::make(
- device_addr["addr"],
- num2str(USRP2_UDP_DATA_PORT),
- recv_buff_size,
- send_buff_size
- );
+ //create a ctrl and data transport for each address
+ std::vector<udp_simple::sptr> ctrl_transports;
+ std::vector<udp_zero_copy::sptr> data_transports;
+
+ BOOST_FOREACH(const std::string &addr, split_addrs(device_addr["addr"])){
+ ctrl_transports.push_back(udp_simple::make_connected(
+ addr, num2str(USRP2_UDP_CTRL_PORT)
+ ));
+ data_transports.push_back(udp_zero_copy::make(
+ addr, num2str(USRP2_UDP_DATA_PORT),
+ recv_buff_size, send_buff_size
+ ));
+ }
//create the usrp2 implementation guts
return device::sptr(
- new usrp2_impl(ctrl_transport, data_transport)
+ new usrp2_impl(ctrl_transports, data_transports)
);
}
+UHD_STATIC_BLOCK(register_usrp2_device){
+ device::register_device(&usrp2_find, &usrp2_make);
+}
+
/***********************************************************************
* Structors
**********************************************************************/
usrp2_impl::usrp2_impl(
- udp_simple::sptr ctrl_transport,
- udp_zero_copy::sptr data_transport
-){
- _data_transport = data_transport;
-
- //make a new interface for usrp2 stuff
- _iface = usrp2_iface::make(ctrl_transport);
- _clock_ctrl = usrp2_clock_ctrl::make(_iface);
- _codec_ctrl = usrp2_codec_ctrl::make(_iface);
- _serdes_ctrl = usrp2_serdes_ctrl::make(_iface);
-
- //load the allowed decim/interp rates
- //_USRP2_RATES = range(4, 128+1, 1) + range(130, 256+1, 2) + range(260, 512+1, 4)
- _allowed_decim_and_interp_rates.clear();
- for (size_t i = 4; i <= 128; i+=1){
- _allowed_decim_and_interp_rates.push_back(i);
+ std::vector<udp_simple::sptr> ctrl_transports,
+ std::vector<udp_zero_copy::sptr> data_transports
+):
+ _data_transports(data_transports)
+{
+ //create a new mboard handler for each control transport
+ for(size_t i = 0; i < ctrl_transports.size(); i++){
+ _mboards.push_back(usrp2_mboard_impl::sptr(
+ new usrp2_mboard_impl(i, ctrl_transports[i], _io_helper)
+ ));
+ //use an empty name when there is only one mboard
+ std::string name = (ctrl_transports.size() > 1)? boost::lexical_cast<std::string>(i) : "";
+ _mboard_dict[name] = _mboards.back();
}
- for (size_t i = 130; i <= 256; i+=2){
- _allowed_decim_and_interp_rates.push_back(i);
- }
- for (size_t i = 260; i <= 512; i+=4){
- _allowed_decim_and_interp_rates.push_back(i);
- }
-
- //init the mboard
- mboard_init();
-
- //init the ddc
- init_ddc_config();
-
- //init the duc
- init_duc_config();
-
- //initialize the clock configuration
- init_clock_config();
-
- //init the tx and rx dboards (do last)
- dboard_init();
//init the send and recv io
io_init();
@@ -202,16 +199,16 @@ void usrp2_impl::get(const wax::obj &key_, wax::obj &val){
//handle the get request conditioned on the key
switch(key.as<device_prop_t>()){
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:
- UHD_ASSERT_THROW(name == "");
- val = _mboard_proxy->get_link();
+ val = _mboard_dict[name]->get_link();
return;
case DEVICE_PROP_MBOARD_NAMES:
- val = prop_names_t(1, "");
+ val = prop_names_t(_mboard_dict.keys());
return;
default: UHD_THROW_PROP_GET_ERROR();
diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp
index 2126b9565..42630a3e4 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 <uhd/usrp/usrp2.hpp>
+#include <uhd/device.hpp>
#include <uhd/utils/pimpl.hpp>
#include <uhd/types/dict.hpp>
#include <uhd/types/otw_type.hpp>
@@ -31,7 +31,7 @@
#include <uhd/usrp/dboard_eeprom.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
-#include <uhd/transport/vrt.hpp>
+#include <uhd/transport/vrt_if_packet.hpp>
#include <uhd/transport/udp_zero_copy.hpp>
#include <uhd/usrp/dboard_manager.hpp>
@@ -62,73 +62,84 @@ public:
return sptr(new wax_obj_proxy(get, set));
}
- ~wax_obj_proxy(void){
- /* NOP */
+private:
+ get_t _get; set_t _set;
+ wax_obj_proxy(const get_t &get, const set_t &set): _get(get), _set(set){};
+ void get(const wax::obj &key, wax::obj &val){return _get(key, val);}
+ void set(const wax::obj &key, const wax::obj &val){return _set(key, val);}
+};
+
+/*!
+ * The io helper class encapculates the max packet sizes and otw types.
+ * The otw types are read-only for now, this will be reimplemented
+ * when it becomes possible to change the otw type in the usrp2.
+ */
+class usrp2_io_helper{
+public:
+ usrp2_io_helper(void){
+ //setup rx otw type
+ _rx_otw_type.width = 16;
+ _rx_otw_type.shift = 0;
+ _rx_otw_type.byteorder = uhd::otw_type_t::BO_BIG_ENDIAN;
+
+ //setup tx otw type
+ _tx_otw_type.width = 16;
+ _tx_otw_type.shift = 0;
+ _tx_otw_type.byteorder = uhd::otw_type_t::BO_BIG_ENDIAN;
}
-private:
- get_t _get;
- set_t _set;
+ inline size_t get_max_send_samps_per_packet(void) const{
+ return _max_tx_bytes_per_packet/_tx_otw_type.get_sample_size();
+ }
- wax_obj_proxy(const get_t &get, const set_t &set){
- _get = get;
- _set = set;
- };
+ inline size_t get_max_recv_samps_per_packet(void) const{
+ return _max_rx_bytes_per_packet/_rx_otw_type.get_sample_size();
+ }
- void get(const wax::obj &key, wax::obj &val){
- return _get(key, val);
+ inline const uhd::otw_type_t &get_rx_otw_type(void) const{
+ return _rx_otw_type;
}
- void set(const wax::obj &key, const wax::obj &val){
- return _set(key, val);
+ inline const uhd::otw_type_t &get_tx_otw_type(void) const{
+ return _tx_otw_type;
}
+
+private:
+ uhd::otw_type_t _rx_otw_type, _tx_otw_type;
+ static const size_t _max_rx_bytes_per_packet =
+ USRP2_UDP_BYTES -
+ USRP2_HOST_RX_VRT_HEADER_WORDS32*sizeof(boost::uint32_t) -
+ USRP2_HOST_RX_VRT_TRAILER_WORDS32*sizeof(boost::uint32_t)
+ ;
+ static const size_t _max_tx_bytes_per_packet =
+ USRP2_UDP_BYTES -
+ uhd::transport::vrt::max_if_hdr_words32*sizeof(boost::uint32_t) -
+ sizeof(uhd::transport::vrt::if_packet_info_t().cid) //no class id ever used
+ ;
};
/*!
- * USRP2 implementation guts:
+ * USRP2 mboard implementation guts:
* The implementation details are encapsulated here.
* Handles properties on the mboard, dboard, dsps...
*/
-class usrp2_impl : public uhd::device{
+class usrp2_mboard_impl : public wax::obj{
public:
- /*!
- * Create a new usrp2 impl base.
- * \param ctrl_transport the udp transport for control
- * \param data_transport the udp transport for data
- */
- usrp2_impl(
- uhd::transport::udp_simple::sptr ctrl_transport,
- uhd::transport::udp_zero_copy::sptr data_transport
- );
+ typedef boost::shared_ptr<usrp2_mboard_impl> sptr;
- ~usrp2_impl(void);
+ //structors
+ usrp2_mboard_impl(size_t index, uhd::transport::udp_simple::sptr, const usrp2_io_helper &);
+ ~usrp2_mboard_impl(void);
- //the io interface
- size_t get_max_send_samps_per_packet(void) const{
- return _max_tx_bytes_per_packet/_tx_otw_type.get_sample_size();
- }
- size_t send(
- const boost::asio::const_buffer &,
- const uhd::tx_metadata_t &,
- const uhd::io_type_t &,
- uhd::device::send_mode_t
- );
- size_t get_max_recv_samps_per_packet(void) const{
- return _max_rx_bytes_per_packet/_rx_otw_type.get_sample_size();
- }
- size_t recv(
- const boost::asio::mutable_buffer &,
- uhd::rx_metadata_t &,
- const uhd::io_type_t &,
- uhd::device::recv_mode_t
- );
-
-private:
inline double get_master_clock_freq(void){
return _clock_ctrl->get_master_clock_rate();
}
- //device properties interface
+private:
+ size_t _index;
+ const usrp2_io_helper &_io_helper;
+
+ //properties for this mboard
void get(const wax::obj &, wax::obj &);
void set(const wax::obj &, const wax::obj &);
@@ -138,25 +149,10 @@ private:
usrp2_codec_ctrl::sptr _codec_ctrl;
usrp2_serdes_ctrl::sptr _serdes_ctrl;
- /*******************************************************************
- * Deal with the rx and tx packet sizes
- ******************************************************************/
- static const size_t _max_rx_bytes_per_packet =
- USRP2_UDP_BYTES -
- USRP2_HOST_RX_VRT_HEADER_WORDS32*sizeof(boost::uint32_t) -
- USRP2_HOST_RX_VRT_TRAILER_WORDS32*sizeof(boost::uint32_t)
- ;
- static const size_t _max_tx_bytes_per_packet =
- USRP2_UDP_BYTES -
- uhd::transport::vrt::max_header_words32*sizeof(boost::uint32_t)
- ;
-
- uhd::otw_type_t _rx_otw_type, _tx_otw_type;
- UHD_PIMPL_DECL(io_impl) _io_impl;
- void io_init(void);
-
- //udp transports for control and data
- uhd::transport::udp_zero_copy::sptr _data_transport;
+ //rx and tx dboard methods and objects
+ uhd::usrp::dboard_manager::sptr _dboard_manager;
+ uhd::usrp::dboard_iface::sptr _dboard_iface;
+ void dboard_init(void);
//methods and shadows for clock configuration
uhd::clock_config_t _clock_config;
@@ -164,17 +160,6 @@ private:
void update_clock_config(void);
void set_time_spec(const uhd::time_spec_t &time_spec, bool now);
- //rx and tx dboard methods and objects
- uhd::usrp::dboard_manager::sptr _dboard_manager;
- uhd::usrp::dboard_iface::sptr _dboard_iface;
- void dboard_init(void);
-
- //properties for the mboard
- void mboard_init(void);
- void mboard_get(const wax::obj &, wax::obj &);
- void mboard_set(const wax::obj &, const wax::obj &);
- wax_obj_proxy::sptr _mboard_proxy;
-
//properties interface for rx dboard
void rx_dboard_get(const wax::obj &, wax::obj &);
void rx_dboard_set(const wax::obj &, const wax::obj &);
@@ -213,4 +198,59 @@ private:
};
+/*!
+ * USRP2 implementation guts:
+ * The implementation details are encapsulated here.
+ * Handles device properties and streaming...
+ */
+class usrp2_impl : public uhd::device{
+public:
+ /*!
+ * Create a new usrp2 impl base.
+ * \param ctrl_transports the udp transports for control
+ * \param data_transports the udp transports for data
+ */
+ usrp2_impl(
+ std::vector<uhd::transport::udp_simple::sptr> ctrl_transports,
+ std::vector<uhd::transport::udp_zero_copy::sptr> data_transports
+ );
+
+ ~usrp2_impl(void);
+
+ //the io interface
+ size_t get_max_send_samps_per_packet(void) const{
+ return _io_helper.get_max_send_samps_per_packet();
+ }
+ size_t send(
+ const std::vector<const void *> &, size_t,
+ const uhd::tx_metadata_t &,
+ const uhd::io_type_t &,
+ uhd::device::send_mode_t
+ );
+ size_t get_max_recv_samps_per_packet(void) const{
+ return _io_helper.get_max_recv_samps_per_packet();
+ }
+ size_t recv(
+ const std::vector<void *> &, size_t,
+ uhd::rx_metadata_t &,
+ const uhd::io_type_t &,
+ uhd::device::recv_mode_t
+ );
+
+private:
+ //device properties interface
+ void get(const wax::obj &, wax::obj &);
+ void set(const wax::obj &, const wax::obj &);
+
+ //pointers to mboards on this device (think mimo setup)
+ std::vector<usrp2_mboard_impl::sptr> _mboards;
+ uhd::dict<std::string, usrp2_mboard_impl::sptr> _mboard_dict;
+
+ //io impl methods and members
+ std::vector<uhd::transport::udp_zero_copy::sptr> _data_transports;
+ const usrp2_io_helper _io_helper;
+ UHD_PIMPL_DECL(io_impl) _io_impl;
+ void io_init(void);
+};
+
#endif /* INCLUDED_USRP2_IMPL_HPP */
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 <boost/cstdint.hpp>
-
////////////////////////////////////////////////////
// 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)