aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/transport/CMakeLists.txt1
-rw-r--r--host/lib/transport/vrt_packet_handler.hpp50
-rw-r--r--host/lib/transport/vrt_packet_handler_state.hpp56
-rw-r--r--host/lib/usrp/usrp2/io_impl.cpp14
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.hpp2
5 files changed, 84 insertions, 39 deletions
diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt
index a74f7d527..32644a6c0 100644
--- a/host/lib/transport/CMakeLists.txt
+++ b/host/lib/transport/CMakeLists.txt
@@ -50,5 +50,6 @@ LIBUHD_APPEND_SOURCES(
${CMAKE_SOURCE_DIR}/lib/transport/udp_simple.cpp
${CMAKE_SOURCE_DIR}/lib/transport/udp_zero_copy_asio.cpp
${CMAKE_SOURCE_DIR}/lib/transport/vrt_packet_handler.hpp
+ ${CMAKE_SOURCE_DIR}/lib/transport/vrt_packet_handler_state.hpp
${CMAKE_SOURCE_DIR}/lib/transport/zero_copy.cpp
)
diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp
index e64e3383d..a179731ca 100644
--- a/host/lib/transport/vrt_packet_handler.hpp
+++ b/host/lib/transport/vrt_packet_handler.hpp
@@ -18,6 +18,7 @@
#ifndef INCLUDED_LIBUHD_TRANSPORT_VRT_PACKET_HANDLER_HPP
#define INCLUDED_LIBUHD_TRANSPORT_VRT_PACKET_HANDLER_HPP
+#include "vrt_packet_handler_state.hpp"
#include <uhd/config.hpp>
#include <uhd/device.hpp>
#include <uhd/types/io_type.hpp>
@@ -36,23 +37,7 @@ namespace vrt_packet_handler{
/***********************************************************************
* vrt packet handler for recv
**********************************************************************/
- struct recv_state{
- //init the expected seq number
- size_t next_packet_seq;
-
- //state variables to handle fragments
- uhd::transport::managed_recv_buffer::sptr managed_buff;
- boost::asio::const_buffer copy_buff;
- 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);
- }
- };
+ 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;
@@ -112,15 +97,15 @@ namespace vrt_packet_handler{
const uhd::io_type_t &io_type,
const uhd::otw_type_t &otw_type,
double tick_rate,
- uhd::transport::zero_copy_if::sptr zc_iface,
+ const get_recv_buff_t &get_recv_buff,
//use these two params to handle a layer above vrt
size_t vrt_header_offset_words32,
- const recv_cb_t& recv_cb
+ const recv_cb_t &recv_cb
){
//perform a receive if no rx data is waiting to be copied
if (boost::asio::buffer_size(state.copy_buff) == 0){
state.fragment_offset_in_samps = 0;
- state.managed_buff = zc_iface->get_recv_buff();
+ state.managed_buff = get_recv_buff();
recv_cb(state.managed_buff); //callback before vrt unpack
try{
_recv1_helper(
@@ -169,7 +154,7 @@ namespace vrt_packet_handler{
const uhd::io_type_t &io_type,
const uhd::otw_type_t &otw_type,
double tick_rate,
- uhd::transport::zero_copy_if::sptr zc_iface,
+ const get_recv_buff_t &get_recv_buff,
//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
@@ -189,7 +174,7 @@ namespace vrt_packet_handler{
metadata,
io_type, otw_type,
tick_rate,
- zc_iface,
+ get_recv_buff,
vrt_header_offset_words32,
recv_cb
);
@@ -208,7 +193,7 @@ namespace vrt_packet_handler{
(accum_num_samps == 0)? metadata : tmp_md, //only the first metadata gets kept
io_type, otw_type,
tick_rate,
- zc_iface,
+ get_recv_buff,
vrt_header_offset_words32,
recv_cb
);
@@ -225,14 +210,7 @@ namespace vrt_packet_handler{
/***********************************************************************
* vrt packet handler for send
**********************************************************************/
- struct send_state{
- //init the expected seq number
- size_t next_packet_seq;
-
- send_state(void){
- next_packet_seq = 0;
- }
- };
+ 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;
@@ -252,12 +230,12 @@ namespace vrt_packet_handler{
const uhd::io_type_t &io_type,
const uhd::otw_type_t &otw_type,
double tick_rate,
- uhd::transport::zero_copy_if::sptr zc_iface,
+ const get_send_buff_t &get_send_buff,
size_t vrt_header_offset_words32,
const send_cb_t& send_cb
){
//get a new managed send buffer
- uhd::transport::managed_send_buffer::sptr send_buff = zc_iface->get_send_buff();
+ 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;
@@ -298,7 +276,7 @@ namespace vrt_packet_handler{
const uhd::io_type_t &io_type,
const uhd::otw_type_t &otw_type,
double tick_rate,
- uhd::transport::zero_copy_if::sptr zc_iface,
+ const get_send_buff_t &get_send_buff,
size_t max_samples_per_packet,
//use these two params to handle a layer above vrt
size_t vrt_header_offset_words32 = 0,
@@ -319,7 +297,7 @@ namespace vrt_packet_handler{
metadata,
io_type, otw_type,
tick_rate,
- zc_iface,
+ get_send_buff,
vrt_header_offset_words32,
send_cb
);
@@ -353,7 +331,7 @@ namespace vrt_packet_handler{
md,
io_type, otw_type,
tick_rate,
- zc_iface,
+ get_send_buff,
vrt_header_offset_words32,
send_cb
);
diff --git a/host/lib/transport/vrt_packet_handler_state.hpp b/host/lib/transport/vrt_packet_handler_state.hpp
new file mode 100644
index 000000000..2320a3b8e
--- /dev/null
+++ b/host/lib/transport/vrt_packet_handler_state.hpp
@@ -0,0 +1,56 @@
+//
+// 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_VRT_PACKET_HANDLER_STATE_HPP
+#define INCLUDED_LIBUHD_TRANSPORT_VRT_PACKET_HANDLER_STATE_HPP
+
+#include <uhd/config.hpp>
+#include <uhd/transport/zero_copy.hpp>
+#include <boost/asio/buffer.hpp>
+
+namespace vrt_packet_handler{
+
+ struct recv_state{
+ //init the expected seq number
+ size_t next_packet_seq;
+
+ //state variables to handle fragments
+ uhd::transport::managed_recv_buffer::sptr managed_buff;
+ boost::asio::const_buffer copy_buff;
+ 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);
+ }
+ };
+
+ struct send_state{
+ //init the expected seq number
+ size_t next_packet_seq;
+
+ send_state(void){
+ next_packet_seq = 0;
+ }
+ };
+
+} //namespace vrt_packet_handler
+
+#endif /* INCLUDED_LIBUHD_TRANSPORT_VRT_PACKET_HANDLER_STATE_HPP */
diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp
index 79b18fb63..5a082bf13 100644
--- a/host/lib/usrp/usrp2/io_impl.cpp
+++ b/host/lib/usrp/usrp2/io_impl.cpp
@@ -15,11 +15,13 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
+#include "../../transport/vrt_packet_handler.hpp"
#include "usrp2_impl.hpp"
#include "usrp2_regs.hpp"
#include <uhd/transport/convert_types.hpp>
#include <boost/format.hpp>
#include <boost/asio.hpp> //htonl and ntohl
+#include <boost/bind.hpp>
#include <iostream>
using namespace uhd;
@@ -65,6 +67,10 @@ void usrp2_impl::io_init(void){
/***********************************************************************
* Send Data
**********************************************************************/
+static inline managed_send_buffer::sptr get_send_buff(zero_copy_if::sptr zc_if){
+ return zc_if->get_send_buff();
+}
+
size_t usrp2_impl::send(
const asio::const_buffer &buff,
const tx_metadata_t &metadata,
@@ -76,7 +82,7 @@ size_t usrp2_impl::send(
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
- _data_transport, //zero copy interface
+ boost::bind(get_send_buff, _data_transport),
get_max_send_samps_per_packet()
);
}
@@ -84,6 +90,10 @@ size_t usrp2_impl::send(
/***********************************************************************
* Receive Data
**********************************************************************/
+static inline managed_recv_buffer::sptr get_recv_buff(zero_copy_if::sptr zc_if){
+ return zc_if->get_recv_buff();
+}
+
size_t usrp2_impl::recv(
const asio::mutable_buffer &buff,
rx_metadata_t &metadata,
@@ -95,6 +105,6 @@ size_t usrp2_impl::recv(
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
- _data_transport //zero copy interface
+ boost::bind(get_recv_buff, _data_transport)
);
}
diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp
index 7948a2069..6a2a09349 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.hpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.hpp
@@ -33,7 +33,7 @@
#include <uhd/transport/vrt.hpp>
#include <uhd/transport/udp_zero_copy.hpp>
#include <uhd/usrp/dboard_manager.hpp>
-#include "../../transport/vrt_packet_handler.hpp"
+#include "../../transport/vrt_packet_handler_state.hpp"
/*!
* Make a usrp2 dboard interface.