summaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-07-07 23:48:09 -0700
committerJosh Blum <josh@joshknows.com>2010-07-07 23:48:09 -0700
commitc72bc56ba6d5b0457f03967a8f8d8e5602fdf14d (patch)
tree13acfd23ac9906977c8364044e4cf0f90fb389a7 /host
parentbe430761fb7e526e80b67d70e3cf488c6dd02495 (diff)
downloaduhd-c72bc56ba6d5b0457f03967a8f8d8e5602fdf14d.tar.gz
uhd-c72bc56ba6d5b0457f03967a8f8d8e5602fdf14d.tar.bz2
uhd-c72bc56ba6d5b0457f03967a8f8d8e5602fdf14d.zip
usrp2: moved common defined for udp mtu and implemented change.
The uhp mtu is now defined in uhd_simple.hpp. The fw common code does not need to know this information. Fixed a calculation bug in the usrp2 impl code for max samples.
Diffstat (limited to 'host')
-rw-r--r--host/include/uhd/transport/udp_simple.hpp3
-rw-r--r--host/lib/transport/udp_zero_copy_asio.cpp10
-rw-r--r--host/lib/usrp/usrp2/fw_common.h8
-rw-r--r--host/lib/usrp/usrp2/usrp2_iface.cpp9
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.cpp4
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.hpp16
6 files changed, 23 insertions, 27 deletions
diff --git a/host/include/uhd/transport/udp_simple.hpp b/host/include/uhd/transport/udp_simple.hpp
index 793ec4fd7..98dca02f0 100644
--- a/host/include/uhd/transport/udp_simple.hpp
+++ b/host/include/uhd/transport/udp_simple.hpp
@@ -29,6 +29,9 @@ class UHD_API udp_simple : boost::noncopyable{
public:
typedef boost::shared_ptr<udp_simple> sptr;
+ //! The maximum number of bytes per udp packet.
+ static const size_t mtu = 1500 - 20 - 8; //default ipv4 mtu - ipv4 header - udp header
+
/*!
* Make a new connected udp transport:
* This transport is for sending and receiving
diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp
index 7f9292d24..86ea275c1 100644
--- a/host/lib/transport/udp_zero_copy_asio.cpp
+++ b/host/lib/transport/udp_zero_copy_asio.cpp
@@ -16,6 +16,7 @@
//
#include <uhd/transport/udp_zero_copy.hpp>
+#include <uhd/transport/udp_simple.hpp> //mtu
#include <uhd/utils/assert.hpp>
#include <boost/cstdint.hpp>
#include <boost/asio.hpp>
@@ -29,7 +30,6 @@ using namespace uhd::transport;
**********************************************************************/
//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
/***********************************************************************
@@ -51,8 +51,8 @@ public:
const std::string &addr,
const std::string &port
):
- phony_zero_copy_recv_if(MAX_DGRAM_SIZE),
- phony_zero_copy_send_if(MAX_DGRAM_SIZE)
+ phony_zero_copy_recv_if(udp_simple::mtu),
+ phony_zero_copy_send_if(udp_simple::mtu)
{
//std::cout << boost::format("Creating udp transport for %s %s") % addr % port << std::endl;
@@ -93,11 +93,11 @@ public:
//This way, the transport caller will have an idea about how much buffering to create.
size_t get_num_recv_frames(void) const{
- return this->get_buff_size<boost::asio::socket_base::receive_buffer_size>()/MAX_DGRAM_SIZE;
+ return this->get_buff_size<boost::asio::socket_base::receive_buffer_size>()/udp_simple::mtu;
}
size_t get_num_send_frames(void) const{
- return this->get_buff_size<boost::asio::socket_base::send_buffer_size>()/MAX_DGRAM_SIZE;
+ return this->get_buff_size<boost::asio::socket_base::send_buffer_size>()/udp_simple::mtu;
}
private:
diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h
index 4c66aa41e..f1761c5a6 100644
--- a/host/lib/usrp/usrp2/fw_common.h
+++ b/host/lib/usrp/usrp2/fw_common.h
@@ -32,10 +32,6 @@ extern "C" {
#define _SINS_
#endif
-// define limits on bytes per udp packet
-#define USRP2_MTU_BYTES 1500
-#define USRP2_UDP_BYTES ((USRP2_MTU_BYTES) - (2 + 14 + 20 + 8)) //size of headers (pad, eth, ip, udp)
-
//defines the protocol version in this shared header
//increment this value when the protocol is changed
#define USRP2_PROTO_VERSION 5
@@ -43,10 +39,6 @@ extern "C" {
//used to differentiate control packets over data port
#define USRP2_INVALID_VRT_HEADER 0
-// size of the vrt header and trailer to the host
-#define USRP2_HOST_RX_VRT_HEADER_WORDS32 5
-#define USRP2_HOST_RX_VRT_TRAILER_WORDS32 1 //FIXME fpga sets wrong header size when no trailer present
-
// udp ports for the usrp2 communication
// Dynamic and/or private ports: 49152-65535
#define USRP2_UDP_CTRL_PORT 49152
diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp
index 8552edd1f..eaaa722ac 100644
--- a/host/lib/usrp/usrp2/usrp2_iface.cpp
+++ b/host/lib/usrp/usrp2/usrp2_iface.cpp
@@ -26,13 +26,14 @@
#include <algorithm>
using namespace uhd;
+using namespace uhd::transport;
class usrp2_iface_impl : public usrp2_iface{
public:
/***********************************************************************
* Structors
**********************************************************************/
- usrp2_iface_impl(transport::udp_simple::sptr ctrl_transport){
+ usrp2_iface_impl(udp_simple::sptr ctrl_transport){
_ctrl_transport = ctrl_transport;
}
@@ -160,7 +161,7 @@ public:
_ctrl_transport->send(boost::asio::buffer(&out_copy, sizeof(usrp2_ctrl_data_t)));
//loop until we get the packet or timeout
- boost::uint8_t usrp2_ctrl_data_in_mem[USRP2_UDP_BYTES]; //allocate max bytes for recv
+ boost::uint8_t usrp2_ctrl_data_in_mem[udp_simple::mtu]; //allocate max bytes for recv
const usrp2_ctrl_data_t *ctrl_data_in = reinterpret_cast<const usrp2_ctrl_data_t *>(usrp2_ctrl_data_in_mem);
while(true){
size_t len = _ctrl_transport->recv(boost::asio::buffer(usrp2_ctrl_data_in_mem));
@@ -182,7 +183,7 @@ public:
private:
//this lovely lady makes it all possible
- transport::udp_simple::sptr _ctrl_transport;
+ udp_simple::sptr _ctrl_transport;
//used in send/recv
boost::mutex _ctrl_mutex;
@@ -222,6 +223,6 @@ private:
/***********************************************************************
* Public make function for usrp2 interface
**********************************************************************/
-usrp2_iface::sptr usrp2_iface::make(transport::udp_simple::sptr ctrl_transport){
+usrp2_iface::sptr usrp2_iface::make(udp_simple::sptr ctrl_transport){
return usrp2_iface::sptr(new usrp2_iface_impl(ctrl_transport));
}
diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp
index 3402c26b1..9d1ac991f 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.cpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.cpp
@@ -99,8 +99,8 @@ static uhd::device_addrs_t usrp2_find(const device_addr_t &hint){
udp_transport->send(boost::asio::buffer(&ctrl_data_out, sizeof(ctrl_data_out)));
//loop and recieve until the timeout
- boost::uint8_t usrp2_ctrl_data_in_mem[USRP2_UDP_BYTES]; //allocate max bytes for recv
- usrp2_ctrl_data_t *ctrl_data_in = reinterpret_cast<usrp2_ctrl_data_t *>(usrp2_ctrl_data_in_mem);
+ boost::uint8_t usrp2_ctrl_data_in_mem[udp_simple::mtu]; //allocate max bytes for recv
+ const usrp2_ctrl_data_t *ctrl_data_in = reinterpret_cast<const usrp2_ctrl_data_t *>(usrp2_ctrl_data_in_mem);
while(true){
size_t len = udp_transport->recv(asio::buffer(usrp2_ctrl_data_in_mem));
//std::cout << len << "\n";
diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp
index 42630a3e4..186516447 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.hpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.hpp
@@ -32,6 +32,7 @@
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include <uhd/transport/vrt_if_packet.hpp>
+#include <uhd/transport/udp_simple.hpp> //mtu
#include <uhd/transport/udp_zero_copy.hpp>
#include <uhd/usrp/dboard_manager.hpp>
@@ -106,15 +107,14 @@ public:
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_rx_bytes_per_packet = uhd::transport::udp_simple::mtu
+ - uhd::transport::vrt::max_if_hdr_words32*sizeof(boost::uint32_t)
+ - sizeof(uhd::transport::vrt::if_packet_info_t().tlr) //forced to have trailer
+ + sizeof(uhd::transport::vrt::if_packet_info_t().cid) //no class id ever used
;
- 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
+ static const size_t _max_tx_bytes_per_packet = uhd::transport::udp_simple::mtu
+ - 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
;
};