diff options
-rw-r--r-- | host/include/uhd/transport/bounded_buffer.hpp | 4 | ||||
-rw-r--r-- | host/lib/transport/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/lib/transport/udp_zero_copy_asio.cpp | 2 | ||||
-rw-r--r-- | host/lib/transport/vrt_packet_handler.hpp | 29 | ||||
-rw-r--r-- | host/lib/transport/vrt_packet_handler_state.hpp | 56 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/io_impl.cpp | 73 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_impl.cpp | 3 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_impl.hpp | 5 |
8 files changed, 103 insertions, 70 deletions
diff --git a/host/include/uhd/transport/bounded_buffer.hpp b/host/include/uhd/transport/bounded_buffer.hpp index cdec05849..baecd6382 100644 --- a/host/include/uhd/transport/bounded_buffer.hpp +++ b/host/include/uhd/transport/bounded_buffer.hpp @@ -57,10 +57,14 @@ namespace uhd{ namespace transport{ if(_buffer.full()){ _buffer.pop_back(); _buffer.push_front(elem); + lock.unlock(); + _empty_cond.notify_one(); return false; } else{ _buffer.push_front(elem); + lock.unlock(); + _empty_cond.notify_one(); return true; } } diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt index 32644a6c0..a74f7d527 100644 --- a/host/lib/transport/CMakeLists.txt +++ b/host/lib/transport/CMakeLists.txt @@ -50,6 +50,5 @@ 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/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp index 4402437f3..190e3f9ce 100644 --- a/host/lib/transport/udp_zero_copy_asio.cpp +++ b/host/lib/transport/udp_zero_copy_asio.cpp @@ -28,7 +28,7 @@ using namespace uhd::transport; * Constants **********************************************************************/ static const size_t MIN_SOCK_BUFF_SIZE = size_t(100e3); -static const size_t MAX_DGRAM_SIZE = 2048; //assume max size on send and recv +static const size_t MAX_DGRAM_SIZE = 1500; //assume max size on send and recv static const double RECV_TIMEOUT = 0.1; // 100 ms /*********************************************************************** diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp index a179731ca..d6b863040 100644 --- a/host/lib/transport/vrt_packet_handler.hpp +++ b/host/lib/transport/vrt_packet_handler.hpp @@ -18,7 +18,6 @@ #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> @@ -37,6 +36,24 @@ 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; @@ -106,6 +123,7 @@ namespace vrt_packet_handler{ if (boost::asio::buffer_size(state.copy_buff) == 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 try{ _recv1_helper( @@ -210,6 +228,15 @@ 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; diff --git a/host/lib/transport/vrt_packet_handler_state.hpp b/host/lib/transport/vrt_packet_handler_state.hpp deleted file mode 100644 index 2320a3b8e..000000000 --- a/host/lib/transport/vrt_packet_handler_state.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see <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 5a082bf13..efd64d4ab 100644 --- a/host/lib/usrp/usrp2/io_impl.cpp +++ b/host/lib/usrp/usrp2/io_impl.cpp @@ -19,9 +19,11 @@ #include "usrp2_impl.hpp" #include "usrp2_regs.hpp" #include <uhd/transport/convert_types.hpp> +#include <uhd/transport/bounded_buffer.hpp> #include <boost/format.hpp> #include <boost/asio.hpp> //htonl and ntohl #include <boost/bind.hpp> +#include <boost/thread.hpp> #include <iostream> using namespace uhd; @@ -30,6 +32,60 @@ using namespace uhd::transport; namespace asio = boost::asio; /*********************************************************************** + * io impl details (internal to this file) + **********************************************************************/ +struct usrp2_impl::io_impl{ + + io_impl(zero_copy_if::sptr zc_if); + ~io_impl(void); + + managed_recv_buffer::sptr get_recv_buff(void); + + //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; +}; + +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; + recv_pirate_booty->pop_with_timed_wait(buff, boost::posix_time::milliseconds(100)); + //timeout means a null sptr... + return buff; +} + +void usrp2_impl::io_impl::recv_pirate_loop(zero_copy_if::sptr zc_if){ + recv_pirate_running = true; + while(recv_pirate_running){ + managed_recv_buffer::sptr buff = zc_if->get_recv_buff(); + if (buff->size()) recv_pirate_booty->push_with_pop_on_full(buff); + } +} + +/*********************************************************************** * Helper Functions **********************************************************************/ void usrp2_impl::io_init(void){ @@ -62,6 +118,13 @@ void usrp2_impl::io_init(void){ ); _iface->poke32(FR_RX_CTRL_VRT_STREAM_ID, 0); _iface->poke32(FR_RX_CTRL_VRT_TRAILER, 0); + + //create new io impl + _io_impl = new io_impl(_data_transport); +} + +void usrp2_impl::io_done(void){ + delete _io_impl; } /*********************************************************************** @@ -78,7 +141,7 @@ size_t usrp2_impl::send( send_mode_t send_mode ){ return vrt_packet_handler::send( - _packet_handler_send_state, //last state of the send handler + _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 @@ -90,10 +153,6 @@ 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, @@ -101,10 +160,10 @@ size_t usrp2_impl::recv( recv_mode_t recv_mode ){ return vrt_packet_handler::recv( - _packet_handler_recv_state, //last state of the recv handler + _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 - boost::bind(get_recv_buff, _data_transport) + boost::bind(&usrp2_impl::io_impl::get_recv_buff, _io_impl) ); } diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index af3ec216a..7f79c483b 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -185,7 +185,8 @@ usrp2_impl::usrp2_impl( } usrp2_impl::~usrp2_impl(void){ - /* NOP */ + //cleanup the send and recv io + io_done(); } /*********************************************************************** diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp index 6a2a09349..4b6805217 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.hpp +++ b/host/lib/usrp/usrp2/usrp2_impl.hpp @@ -33,7 +33,6 @@ #include <uhd/transport/vrt.hpp> #include <uhd/transport/udp_zero_copy.hpp> #include <uhd/usrp/dboard_manager.hpp> -#include "../../transport/vrt_packet_handler_state.hpp" /*! * Make a usrp2 dboard interface. @@ -153,10 +152,10 @@ private: uhd::transport::vrt::max_header_words32*sizeof(boost::uint32_t) ; - vrt_packet_handler::recv_state _packet_handler_recv_state; - vrt_packet_handler::send_state _packet_handler_send_state; uhd::otw_type_t _rx_otw_type, _tx_otw_type; + struct io_impl; io_impl *_io_impl; void io_init(void); + void io_done(void); //udp transports for control and data uhd::transport::udp_zero_copy::sptr _data_transport; |