summaryrefslogtreecommitdiffstats
path: root/host/lib/transport
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib/transport')
-rw-r--r--host/lib/transport/CMakeLists.txt4
-rwxr-xr-xhost/lib/transport/gen_convert_types.py10
-rw-r--r--host/lib/transport/include/stdint.h35
-rw-r--r--host/lib/transport/libusb1_base.cpp2
-rw-r--r--host/lib/transport/libusb1_base.hpp6
-rw-r--r--host/lib/transport/libusb1_device_handle.cpp18
-rw-r--r--host/lib/transport/libusb1_zero_copy.cpp3
-rw-r--r--host/lib/transport/vrt_packet_handler.hpp58
8 files changed, 95 insertions, 41 deletions
diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt
index 96ef8e505..62c4f62b1 100644
--- a/host/lib/transport/CMakeLists.txt
+++ b/host/lib/transport/CMakeLists.txt
@@ -30,8 +30,12 @@ IF(LIBUSB_FOUND)
${CMAKE_SOURCE_DIR}/lib/transport/libusb1_control.cpp
${CMAKE_SOURCE_DIR}/lib/transport/libusb1_zero_copy.cpp
${CMAKE_SOURCE_DIR}/lib/transport/libusb1_base.cpp
+ ${CMAKE_SOURCE_DIR}/lib/transport/libusb1_base.hpp
${CMAKE_SOURCE_DIR}/lib/transport/libusb1_device_handle.cpp
)
+ IF(WIN32) #include our custom stdint for libusb
+ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/transport/include)
+ ENDIF(WIN32)
SET(HAVE_USB_SUPPORT TRUE)
ENDIF(LIBUSB_FOUND)
diff --git a/host/lib/transport/gen_convert_types.py b/host/lib/transport/gen_convert_types.py
index adbd22868..f9509c81d 100755
--- a/host/lib/transport/gen_convert_types.py
+++ b/host/lib/transport/gen_convert_types.py
@@ -99,9 +99,9 @@ void transport::convert_io_type_to_otw_type(
nsamps_per_io_buff
);
#else
- for (size_t i = 0; i < nsamps_per_io_buff; i++){
+ for (size_t i = 0, j = 0; i < nsamps_per_io_buff; i++){
#for $j in range($num_chans)
- reinterpret_cast<$(out_type)_t *>(otw_buff)[i*$num_chans + $j] =
+ reinterpret_cast<$(out_type)_t *>(otw_buff)[j++] =
#if $ph.get_swap_type($pred) == 'bswap'
uhd::byteswap($(converter)(reinterpret_cast<const $(in_type)_t *>(io_buffs[$j])[i]));
#else
@@ -139,13 +139,13 @@ void transport::convert_otw_type_to_io_type(
nsamps_per_io_buff
);
#else
- for (size_t i = 0; i < nsamps_per_io_buff; i++){
+ for (size_t i = 0, j = 0; i < nsamps_per_io_buff; i++){
#for $j in range($num_chans)
reinterpret_cast<$(out_type)_t *>(io_buffs[$j])[i] =
#if $ph.get_swap_type($pred) == 'bswap'
- $(converter)(uhd::byteswap(reinterpret_cast<const $(in_type)_t *>(otw_buff)[i*$num_chans + $j]));
+ $(converter)(uhd::byteswap(reinterpret_cast<const $(in_type)_t *>(otw_buff)[j++]));
#else
- $(converter)(reinterpret_cast<const $(in_type)_t *>(otw_buff)[i*$num_chans + $j]);
+ $(converter)(reinterpret_cast<const $(in_type)_t *>(otw_buff)[j++]);
#end if
#end for
}
diff --git a/host/lib/transport/include/stdint.h b/host/lib/transport/include/stdint.h
new file mode 100644
index 000000000..b3eb61aae
--- /dev/null
+++ b/host/lib/transport/include/stdint.h
@@ -0,0 +1,35 @@
+//
+// 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_STDINT_H
+#define INCLUDED_LIBUHD_TRANSPORT_STDINT_H
+
+#include <boost/cstdint.hpp>
+
+//provide a stdint implementation for libusb
+
+typedef boost::uint64_t uint64_t;
+typedef boost::uint32_t uint32_t;
+typedef boost::uint16_t uint16_t;
+typedef boost::uint8_t uint8_t;
+
+typedef boost::int64_t int64_t;
+typedef boost::int32_t int32_t;
+typedef boost::int16_t int16_t;
+typedef boost::int8_t int8_t;
+
+#endif /* INCLUDED_LIBUHD_TRANSPORT_STDINT_H */
diff --git a/host/lib/transport/libusb1_base.cpp b/host/lib/transport/libusb1_base.cpp
index e21c39aa3..1f816c6e2 100644
--- a/host/lib/transport/libusb1_base.cpp
+++ b/host/lib/transport/libusb1_base.cpp
@@ -67,7 +67,7 @@ bool libusb::compare_device(libusb_device *dev,
std::string serial = handle->get_serial();
boost::uint16_t vendor_id = handle->get_vendor_id();
boost::uint16_t product_id = handle->get_product_id();
- boost::uint8_t device_addr = handle->get_device_addr();
+ boost::uint16_t device_addr = handle->get_device_addr();
libusb_device_descriptor libusb_desc;
if (libusb_get_device_descriptor(dev, &libusb_desc) < 0)
diff --git a/host/lib/transport/libusb1_base.hpp b/host/lib/transport/libusb1_base.hpp
index abe5e22a2..484bcf3d9 100644
--- a/host/lib/transport/libusb1_base.hpp
+++ b/host/lib/transport/libusb1_base.hpp
@@ -15,8 +15,8 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
-#ifndef INCLUDED_TRANSPORT_LIBUSB_HPP
-#define INCLUDED_TRANSPORT_LIBUSB_HPP
+#ifndef INCLUDED_LIBUHD_TRANSPORT_LIBUSB_HPP
+#define INCLUDED_LIBUHD_TRANSPORT_LIBUSB_HPP
#include <uhd/config.hpp>
#include <uhd/transport/usb_device_handle.hpp>
@@ -91,4 +91,4 @@ namespace libusb {
}} //namespace
-#endif /* INCLUDED_TRANSPORT_LIBUSB_HPP */
+#endif /* INCLUDED_LIBUHD_TRANSPORT_LIBUSB_HPP */
diff --git a/host/lib/transport/libusb1_device_handle.cpp b/host/lib/transport/libusb1_device_handle.cpp
index 43d0f0e26..7efddd410 100644
--- a/host/lib/transport/libusb1_device_handle.cpp
+++ b/host/lib/transport/libusb1_device_handle.cpp
@@ -29,9 +29,9 @@ const int libusb_debug_level = 0;
class libusb1_device_handle_impl : public usb_device_handle {
public:
libusb1_device_handle_impl(std::string serial,
- boost::uint32_t product_id,
- boost::uint32_t vendor_id,
- boost::uint32_t device_addr)
+ boost::uint16_t product_id,
+ boost::uint16_t vendor_id,
+ boost::uint16_t device_addr)
: _serial(serial), _product_id(product_id),
_vendor_id(vendor_id), _device_addr(device_addr)
{
@@ -66,9 +66,9 @@ public:
private:
std::string _serial;
- boost::uint32_t _product_id;
- boost::uint32_t _vendor_id;
- boost::uint32_t _device_addr;
+ boost::uint16_t _product_id;
+ boost::uint16_t _vendor_id;
+ boost::uint16_t _device_addr;
};
@@ -81,9 +81,9 @@ usb_device_handle::sptr make_usb_device_handle(libusb_device *dev)
}
std::string serial = libusb::get_serial(dev);
- boost::uint32_t product_id = desc.idProduct;
- boost::uint32_t vendor_id = desc.idVendor;
- boost::uint32_t device_addr = libusb_get_device_address(dev);
+ boost::uint16_t product_id = desc.idProduct;
+ boost::uint16_t vendor_id = desc.idVendor;
+ boost::uint16_t device_addr = libusb_get_device_address(dev);
return usb_device_handle::sptr(new libusb1_device_handle_impl(
serial,
diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp
index b890a87f9..b3a160462 100644
--- a/host/lib/transport/libusb1_zero_copy.cpp
+++ b/host/lib/transport/libusb1_zero_copy.cpp
@@ -18,7 +18,6 @@
#include "libusb1_base.hpp"
#include <uhd/transport/usb_zero_copy.hpp>
#include <uhd/utils/assert.hpp>
-#include <boost/asio.hpp>
#include <boost/format.hpp>
#include <iostream>
#include <iomanip>
@@ -208,7 +207,7 @@ libusb_transfer *usb_endpoint::allocate_transfer(int buff_len)
endpoint, // endpoint
buff, // buffer
buff_len, // length
- callback, // callback
+ libusb_transfer_cb_fn(callback), // callback
this, // user_data
0); // timeout
return lut;
diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp
index 7e0588f03..b603f1371 100644
--- a/host/lib/transport/vrt_packet_handler.hpp
+++ b/host/lib/transport/vrt_packet_handler.hpp
@@ -150,7 +150,8 @@ template <typename T> UHD_INLINE T get_context_code(
const vrt_unpacker_t &vrt_unpacker,
const get_recv_buffs_t &get_recv_buffs,
const handle_overflow_t &handle_overflow,
- size_t vrt_header_offset_words32
+ size_t vrt_header_offset_words32,
+ size_t chans_per_otw_buff
){
metadata.error_code = uhd::rx_metadata_t::ERROR_CODE_NONE;
@@ -184,15 +185,21 @@ template <typename T> UHD_INLINE T get_context_code(
//extract the number of samples available to copy
size_t bytes_per_item = otw_type.get_sample_size();
size_t nsamps_available = state.size_of_copy_buffs/bytes_per_item;
- size_t nsamps_to_copy = std::min(total_samps, nsamps_available);
+ size_t nsamps_to_copy = std::min(total_samps*chans_per_otw_buff, nsamps_available);
size_t bytes_to_copy = nsamps_to_copy*bytes_per_item;
+ size_t nsamps_to_copy_per_io_buff = nsamps_to_copy/chans_per_otw_buff;
+
+ std::vector<void *> io_buffs(chans_per_otw_buff);
+ for (size_t i = 0; i < state.width; i+=chans_per_otw_buff){
+
+ //fill a vector with pointers to the io buffers
+ for (size_t j = 0; j < chans_per_otw_buff; j++){
+ io_buffs[j] = reinterpret_cast<boost::uint8_t *>(buffs[i+j]) + offset_bytes;
+ }
- 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
+ state.copy_buffs[i], otw_type, io_buffs, io_type, nsamps_to_copy_per_io_buff
);
//update the rx copy buffer to reflect the bytes copied
@@ -206,7 +213,7 @@ template <typename T> UHD_INLINE T get_context_code(
metadata.fragment_offset = state.fragment_offset_in_samps;
state.fragment_offset_in_samps += nsamps_to_copy; //set for next call
- return nsamps_to_copy;
+ return nsamps_to_copy_per_io_buff;
}
/*******************************************************************
@@ -224,7 +231,8 @@ template <typename T> UHD_INLINE T get_context_code(
const vrt_unpacker_t &vrt_unpacker,
const get_recv_buffs_t &get_recv_buffs,
const handle_overflow_t &handle_overflow = &handle_overflow_nop,
- size_t vrt_header_offset_words32 = 0
+ size_t vrt_header_offset_words32 = 0,
+ size_t chans_per_otw_buff = 1
){
switch(recv_mode){
@@ -241,7 +249,8 @@ template <typename T> UHD_INLINE T get_context_code(
vrt_unpacker,
get_recv_buffs,
handle_overflow,
- vrt_header_offset_words32
+ vrt_header_offset_words32,
+ chans_per_otw_buff
);
}
@@ -261,7 +270,8 @@ template <typename T> UHD_INLINE T get_context_code(
vrt_unpacker,
get_recv_buffs,
handle_overflow,
- vrt_header_offset_words32
+ vrt_header_offset_words32,
+ chans_per_otw_buff
);
if (num_samps == 0) break; //had a recv timeout or error, break loop
accum_num_samps += num_samps;
@@ -303,29 +313,32 @@ template <typename T> UHD_INLINE T get_context_code(
const uhd::otw_type_t &otw_type,
const vrt_packer_t &vrt_packer,
const get_send_buffs_t &get_send_buffs,
- size_t vrt_header_offset_words32
+ size_t vrt_header_offset_words32,
+ size_t chans_per_otw_buff
){
//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.num_payload_words32 = (num_samps*chans_per_otw_buff*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());
+ managed_send_buffs_t send_buffs(buffs.size()/chans_per_otw_buff);
UHD_ASSERT_THROW(get_send_buffs(send_buffs));
- for (size_t i = 0; i < buffs.size(); i++){
+ std::vector<const void *> io_buffs(chans_per_otw_buff);
+ for (size_t i = 0; i < buffs.size(); i+=chans_per_otw_buff){
//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;
+ for (size_t j = 0; j < chans_per_otw_buff; j++){
+ io_buffs[j] = reinterpret_cast<const boost::uint8_t *>(buffs[i+j]) + 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);
+ otw_mem += if_packet_info.num_header_words32;
//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
+ io_buffs, io_type, otw_mem, otw_type, num_samps
);
//commit the samples to the zero-copy interface
@@ -351,7 +364,8 @@ template <typename T> UHD_INLINE T get_context_code(
const vrt_packer_t &vrt_packer,
const get_send_buffs_t &get_send_buffs,
size_t max_samples_per_packet,
- size_t vrt_header_offset_words32 = 0
+ size_t vrt_header_offset_words32 = 0,
+ size_t chans_per_otw_buff = 1
){
//translate the metadata to vrt if packet info
uhd::transport::vrt::if_packet_info_t if_packet_info;
@@ -383,7 +397,8 @@ template <typename T> UHD_INLINE T get_context_code(
io_type, otw_type,
vrt_packer,
get_send_buffs,
- vrt_header_offset_words32
+ vrt_header_offset_words32,
+ chans_per_otw_buff
);
return num_samps;
}
@@ -414,7 +429,8 @@ template <typename T> UHD_INLINE T get_context_code(
io_type, otw_type,
vrt_packer,
get_send_buffs,
- vrt_header_offset_words32
+ vrt_header_offset_words32,
+ chans_per_otw_buff
);
}
return total_num_samps;