summaryrefslogtreecommitdiffstats
path: root/host/lib/transport
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-04-12 15:19:25 -0700
committerJosh Blum <josh@joshknows.com>2010-04-12 15:19:25 -0700
commitb87d9afe82e962718f5f5d514abf9d79b9603b98 (patch)
treecaa53a69eaa9847994737748c1385a2dfd3153f8 /host/lib/transport
parent24ca9fbd0784c7c53af6ad4f9035e8d43e888290 (diff)
parentfa96b25b99dbd19ac0689cab9bcab84063287ad3 (diff)
downloaduhd-b87d9afe82e962718f5f5d514abf9d79b9603b98.tar.gz
uhd-b87d9afe82e962718f5f5d514abf9d79b9603b98.tar.bz2
uhd-b87d9afe82e962718f5f5d514abf9d79b9603b98.zip
Merge branch 'rfx' of git@ettus.sourcerepo.com:ettus/uhd into io
Conflicts: host/lib/usrp/usrp2/io_impl.cpp
Diffstat (limited to 'host/lib/transport')
-rwxr-xr-xhost/lib/transport/gen_vrt.py24
-rw-r--r--host/lib/transport/vrt.cpp547
2 files changed, 16 insertions, 555 deletions
diff --git a/host/lib/transport/gen_vrt.py b/host/lib/transport/gen_vrt.py
index 918de3ad7..38a394dee 100755
--- a/host/lib/transport/gen_vrt.py
+++ b/host/lib/transport/gen_vrt.py
@@ -54,7 +54,8 @@ void vrt::pack(
size_t &num_header_words32, //output
size_t num_payload_words32, //input
size_t &num_packet_words32, //output
- size_t packet_count //input
+ size_t packet_count, //input
+ double tick_rate //input
){
boost::uint32_t vrt_hdr_flags;
@@ -91,7 +92,7 @@ void vrt::pack(
#if $pred & $tsf_p
header_buff[$num_header_words] = htonl(0);
#set $num_header_words += 1
- header_buff[$num_header_words] = htonl(metadata.time_spec.ticks);
+ header_buff[$num_header_words] = htonl(metadata.time_spec.get_ticks(tick_rate));
#set $num_header_words += 1
#set $flags |= (0x1 << 20);
#end if
@@ -127,7 +128,8 @@ void vrt::unpack(
size_t &num_header_words32, //output
size_t &num_payload_words32, //output
size_t num_packet_words32, //input
- size_t &packet_count //output
+ size_t &packet_count, //output
+ double tick_rate //input
){
//clear the metadata
metadata = rx_metadata_t();
@@ -180,7 +182,7 @@ void vrt::unpack(
#set $set_has_time_spec = True
#end if
#set $num_header_words += 1
- metadata.time_spec.ticks = ntohl(header_buff[$num_header_words]);
+ metadata.time_spec.set_ticks(ntohl(header_buff[$num_header_words]), tick_rate);
#set $num_header_words += 1
#end if
########## Trailer ##########
@@ -198,9 +200,15 @@ void vrt::unpack(
}
"""
-from Cheetah import Template
-def parse_str(_tmpl_text, **kwargs): return str(Template.Template(_tmpl_text, kwargs))
+import os
+import sys
+
+from Cheetah.Template import Template
+def parse_tmpl(_tmpl_text, **kwargs):
+ return str(Template(_tmpl_text, kwargs))
+def safe_makedirs(path):
+ not os.path.isdir(path) and os.makedirs(path)
if __name__ == '__main__':
- from Cheetah import Template
- print parse_str(TMPL_TEXT, file=__file__)
+ safe_makedirs(os.path.dirname(sys.argv[1]))
+ open(sys.argv[1], 'w').write(parse_tmpl(TMPL_TEXT, file=__file__))
diff --git a/host/lib/transport/vrt.cpp b/host/lib/transport/vrt.cpp
deleted file mode 100644
index bebca5db9..000000000
--- a/host/lib/transport/vrt.cpp
+++ /dev/null
@@ -1,547 +0,0 @@
-
-
-
-/***********************************************************************
- * This file was generated by ./gen_vrt.py on Fri Mar 26 15:33:00 2010
- **********************************************************************/
-
-#include <uhd/transport/vrt.hpp>
-#include <boost/asio.hpp> //endianness conversion
-#include <stdexcept>
-
-using namespace uhd;
-using namespace uhd::transport;
-
-void vrt::pack(
- 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
-){
- boost::uint32_t vrt_hdr_flags;
-
- boost::uint8_t pred = 0;
- if (metadata.has_stream_id) pred |= 0x1;
- if (metadata.has_time_spec) pred |= 0xc;
-
- switch(pred){
- case 0:
- num_header_words32 = 1;
- num_packet_words32 = 1 + num_payload_words32;
- vrt_hdr_flags = 0x0;
- break;
- case 1:
- header_buff[1] = htonl(metadata.stream_id);
- num_header_words32 = 2;
- num_packet_words32 = 2 + num_payload_words32;
- vrt_hdr_flags = 0x10000000;
- break;
- case 2:
- header_buff[1] = htonl(0);
- header_buff[2] = htonl(0);
- num_header_words32 = 3;
- num_packet_words32 = 3 + num_payload_words32;
- vrt_hdr_flags = 0x8000000;
- break;
- case 3:
- header_buff[1] = htonl(metadata.stream_id);
- header_buff[2] = htonl(0);
- header_buff[3] = htonl(0);
- num_header_words32 = 4;
- num_packet_words32 = 4 + num_payload_words32;
- vrt_hdr_flags = 0x18000000;
- break;
- case 4:
- header_buff[1] = htonl(metadata.time_spec.secs);
- num_header_words32 = 2;
- num_packet_words32 = 2 + num_payload_words32;
- vrt_hdr_flags = 0xc00000;
- break;
- case 5:
- header_buff[1] = htonl(metadata.stream_id);
- header_buff[2] = htonl(metadata.time_spec.secs);
- num_header_words32 = 3;
- num_packet_words32 = 3 + num_payload_words32;
- vrt_hdr_flags = 0x10c00000;
- break;
- case 6:
- header_buff[1] = htonl(0);
- header_buff[2] = htonl(0);
- header_buff[3] = htonl(metadata.time_spec.secs);
- num_header_words32 = 4;
- num_packet_words32 = 4 + num_payload_words32;
- vrt_hdr_flags = 0x8c00000;
- break;
- case 7:
- header_buff[1] = htonl(metadata.stream_id);
- header_buff[2] = htonl(0);
- header_buff[3] = htonl(0);
- header_buff[4] = htonl(metadata.time_spec.secs);
- num_header_words32 = 5;
- num_packet_words32 = 5 + num_payload_words32;
- vrt_hdr_flags = 0x18c00000;
- break;
- case 8:
- header_buff[1] = htonl(0);
- header_buff[2] = htonl(metadata.time_spec.ticks);
- num_header_words32 = 3;
- num_packet_words32 = 3 + num_payload_words32;
- vrt_hdr_flags = 0x100000;
- break;
- case 9:
- header_buff[1] = htonl(metadata.stream_id);
- header_buff[2] = htonl(0);
- header_buff[3] = htonl(metadata.time_spec.ticks);
- num_header_words32 = 4;
- num_packet_words32 = 4 + num_payload_words32;
- vrt_hdr_flags = 0x10100000;
- break;
- case 10:
- header_buff[1] = htonl(0);
- header_buff[2] = htonl(0);
- header_buff[3] = htonl(0);
- header_buff[4] = htonl(metadata.time_spec.ticks);
- num_header_words32 = 5;
- num_packet_words32 = 5 + num_payload_words32;
- vrt_hdr_flags = 0x8100000;
- break;
- case 11:
- header_buff[1] = htonl(metadata.stream_id);
- header_buff[2] = htonl(0);
- header_buff[3] = htonl(0);
- header_buff[4] = htonl(0);
- header_buff[5] = htonl(metadata.time_spec.ticks);
- num_header_words32 = 6;
- num_packet_words32 = 6 + num_payload_words32;
- vrt_hdr_flags = 0x18100000;
- break;
- case 12:
- header_buff[1] = htonl(metadata.time_spec.secs);
- header_buff[2] = htonl(0);
- header_buff[3] = htonl(metadata.time_spec.ticks);
- num_header_words32 = 4;
- num_packet_words32 = 4 + num_payload_words32;
- vrt_hdr_flags = 0xd00000;
- break;
- case 13:
- header_buff[1] = htonl(metadata.stream_id);
- header_buff[2] = htonl(metadata.time_spec.secs);
- header_buff[3] = htonl(0);
- header_buff[4] = htonl(metadata.time_spec.ticks);
- num_header_words32 = 5;
- num_packet_words32 = 5 + num_payload_words32;
- vrt_hdr_flags = 0x10d00000;
- break;
- case 14:
- header_buff[1] = htonl(0);
- header_buff[2] = htonl(0);
- header_buff[3] = htonl(metadata.time_spec.secs);
- header_buff[4] = htonl(0);
- header_buff[5] = htonl(metadata.time_spec.ticks);
- num_header_words32 = 6;
- num_packet_words32 = 6 + num_payload_words32;
- vrt_hdr_flags = 0x8d00000;
- break;
- case 15:
- header_buff[1] = htonl(metadata.stream_id);
- header_buff[2] = htonl(0);
- header_buff[3] = htonl(0);
- header_buff[4] = htonl(metadata.time_spec.secs);
- header_buff[5] = htonl(0);
- header_buff[6] = htonl(metadata.time_spec.ticks);
- num_header_words32 = 7;
- num_packet_words32 = 7 + num_payload_words32;
- vrt_hdr_flags = 0x18d00000;
- break;
- case 16:
- num_header_words32 = 1;
- num_packet_words32 = 2 + num_payload_words32;
- vrt_hdr_flags = 0x4000000;
- break;
- case 17:
- header_buff[1] = htonl(metadata.stream_id);
- num_header_words32 = 2;
- num_packet_words32 = 3 + num_payload_words32;
- vrt_hdr_flags = 0x14000000;
- break;
- case 18:
- header_buff[1] = htonl(0);
- header_buff[2] = htonl(0);
- num_header_words32 = 3;
- num_packet_words32 = 4 + num_payload_words32;
- vrt_hdr_flags = 0xc000000;
- break;
- case 19:
- header_buff[1] = htonl(metadata.stream_id);
- header_buff[2] = htonl(0);
- header_buff[3] = htonl(0);
- num_header_words32 = 4;
- num_packet_words32 = 5 + num_payload_words32;
- vrt_hdr_flags = 0x1c000000;
- break;
- case 20:
- header_buff[1] = htonl(metadata.time_spec.secs);
- num_header_words32 = 2;
- num_packet_words32 = 3 + num_payload_words32;
- vrt_hdr_flags = 0x4c00000;
- break;
- case 21:
- header_buff[1] = htonl(metadata.stream_id);
- header_buff[2] = htonl(metadata.time_spec.secs);
- num_header_words32 = 3;
- num_packet_words32 = 4 + num_payload_words32;
- vrt_hdr_flags = 0x14c00000;
- break;
- case 22:
- header_buff[1] = htonl(0);
- header_buff[2] = htonl(0);
- header_buff[3] = htonl(metadata.time_spec.secs);
- num_header_words32 = 4;
- num_packet_words32 = 5 + num_payload_words32;
- vrt_hdr_flags = 0xcc00000;
- break;
- case 23:
- header_buff[1] = htonl(metadata.stream_id);
- header_buff[2] = htonl(0);
- header_buff[3] = htonl(0);
- header_buff[4] = htonl(metadata.time_spec.secs);
- num_header_words32 = 5;
- num_packet_words32 = 6 + num_payload_words32;
- vrt_hdr_flags = 0x1cc00000;
- break;
- case 24:
- header_buff[1] = htonl(0);
- header_buff[2] = htonl(metadata.time_spec.ticks);
- num_header_words32 = 3;
- num_packet_words32 = 4 + num_payload_words32;
- vrt_hdr_flags = 0x4100000;
- break;
- case 25:
- header_buff[1] = htonl(metadata.stream_id);
- header_buff[2] = htonl(0);
- header_buff[3] = htonl(metadata.time_spec.ticks);
- num_header_words32 = 4;
- num_packet_words32 = 5 + num_payload_words32;
- vrt_hdr_flags = 0x14100000;
- break;
- case 26:
- header_buff[1] = htonl(0);
- header_buff[2] = htonl(0);
- header_buff[3] = htonl(0);
- header_buff[4] = htonl(metadata.time_spec.ticks);
- num_header_words32 = 5;
- num_packet_words32 = 6 + num_payload_words32;
- vrt_hdr_flags = 0xc100000;
- break;
- case 27:
- header_buff[1] = htonl(metadata.stream_id);
- header_buff[2] = htonl(0);
- header_buff[3] = htonl(0);
- header_buff[4] = htonl(0);
- header_buff[5] = htonl(metadata.time_spec.ticks);
- num_header_words32 = 6;
- num_packet_words32 = 7 + num_payload_words32;
- vrt_hdr_flags = 0x1c100000;
- break;
- case 28:
- header_buff[1] = htonl(metadata.time_spec.secs);
- header_buff[2] = htonl(0);
- header_buff[3] = htonl(metadata.time_spec.ticks);
- num_header_words32 = 4;
- num_packet_words32 = 5 + num_payload_words32;
- vrt_hdr_flags = 0x4d00000;
- break;
- case 29:
- header_buff[1] = htonl(metadata.stream_id);
- header_buff[2] = htonl(metadata.time_spec.secs);
- header_buff[3] = htonl(0);
- header_buff[4] = htonl(metadata.time_spec.ticks);
- num_header_words32 = 5;
- num_packet_words32 = 6 + num_payload_words32;
- vrt_hdr_flags = 0x14d00000;
- break;
- case 30:
- header_buff[1] = htonl(0);
- header_buff[2] = htonl(0);
- header_buff[3] = htonl(metadata.time_spec.secs);
- header_buff[4] = htonl(0);
- header_buff[5] = htonl(metadata.time_spec.ticks);
- num_header_words32 = 6;
- num_packet_words32 = 7 + num_payload_words32;
- vrt_hdr_flags = 0xcd00000;
- break;
- case 31:
- header_buff[1] = htonl(metadata.stream_id);
- header_buff[2] = htonl(0);
- header_buff[3] = htonl(0);
- header_buff[4] = htonl(metadata.time_spec.secs);
- header_buff[5] = htonl(0);
- header_buff[6] = htonl(metadata.time_spec.ticks);
- num_header_words32 = 7;
- num_packet_words32 = 8 + num_payload_words32;
- vrt_hdr_flags = 0x1cd00000;
- break;
- }
-
- //set the burst flags
- if (metadata.start_of_burst) vrt_hdr_flags |= 0x2000000;
- if (metadata.end_of_burst) vrt_hdr_flags |= 0x1000000;
-
- //fill in complete header word
- header_buff[0] = htonl(vrt_hdr_flags |
- ((packet_count & 0xf) << 16) |
- (num_packet_words32 & 0xffff)
- );
-}
-
-void vrt::unpack(
- 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
-){
- //clear the metadata
- metadata = rx_metadata_t();
-
- //extract vrt header
- boost::uint32_t vrt_hdr_word = ntohl(header_buff[0]);
- size_t packet_words32 = vrt_hdr_word & 0xffff;
- packet_count = (vrt_hdr_word >> 16) & 0xf;
-
- //failure cases
- if (packet_words32 == 0 or 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");
-
- boost::uint8_t pred = 0;
- if(vrt_hdr_word & 0x10000000) pred |= 0x1;
- if(vrt_hdr_word & 0x8000000) pred |= 0x2;
- if(vrt_hdr_word & 0xc00000) pred |= 0x4;
- if(vrt_hdr_word & 0x300000) pred |= 0x8;
- if(vrt_hdr_word & 0x4000000) pred |= 0x10;
-
- switch(pred){
- case 0:
- num_header_words32 = 1;
- num_payload_words32 = packet_words32 - 1;
- break;
- case 1:
- metadata.has_stream_id = true;
- metadata.stream_id = ntohl(header_buff[1]);
- num_header_words32 = 2;
- num_payload_words32 = packet_words32 - 2;
- break;
- case 2:
- num_header_words32 = 3;
- num_payload_words32 = packet_words32 - 3;
- break;
- case 3:
- metadata.has_stream_id = true;
- metadata.stream_id = ntohl(header_buff[1]);
- num_header_words32 = 4;
- num_payload_words32 = packet_words32 - 4;
- break;
- case 4:
- metadata.has_time_spec = true;
- metadata.time_spec.secs = ntohl(header_buff[1]);
- num_header_words32 = 2;
- num_payload_words32 = packet_words32 - 2;
- break;
- case 5:
- metadata.has_stream_id = true;
- metadata.stream_id = ntohl(header_buff[1]);
- metadata.has_time_spec = true;
- metadata.time_spec.secs = ntohl(header_buff[2]);
- num_header_words32 = 3;
- num_payload_words32 = packet_words32 - 3;
- break;
- case 6:
- metadata.has_time_spec = true;
- metadata.time_spec.secs = ntohl(header_buff[3]);
- num_header_words32 = 4;
- num_payload_words32 = packet_words32 - 4;
- break;
- case 7:
- metadata.has_stream_id = true;
- metadata.stream_id = ntohl(header_buff[1]);
- metadata.has_time_spec = true;
- metadata.time_spec.secs = ntohl(header_buff[4]);
- num_header_words32 = 5;
- num_payload_words32 = packet_words32 - 5;
- break;
- case 8:
- metadata.has_time_spec = true;
- metadata.time_spec.ticks = ntohl(header_buff[2]);
- num_header_words32 = 3;
- num_payload_words32 = packet_words32 - 3;
- break;
- case 9:
- metadata.has_stream_id = true;
- metadata.stream_id = ntohl(header_buff[1]);
- metadata.has_time_spec = true;
- metadata.time_spec.ticks = ntohl(header_buff[3]);
- num_header_words32 = 4;
- num_payload_words32 = packet_words32 - 4;
- break;
- case 10:
- metadata.has_time_spec = true;
- metadata.time_spec.ticks = ntohl(header_buff[4]);
- num_header_words32 = 5;
- num_payload_words32 = packet_words32 - 5;
- break;
- case 11:
- metadata.has_stream_id = true;
- metadata.stream_id = ntohl(header_buff[1]);
- metadata.has_time_spec = true;
- metadata.time_spec.ticks = ntohl(header_buff[5]);
- num_header_words32 = 6;
- num_payload_words32 = packet_words32 - 6;
- break;
- case 12:
- metadata.has_time_spec = true;
- metadata.time_spec.secs = ntohl(header_buff[1]);
- metadata.time_spec.ticks = ntohl(header_buff[3]);
- num_header_words32 = 4;
- num_payload_words32 = packet_words32 - 4;
- break;
- case 13:
- metadata.has_stream_id = true;
- metadata.stream_id = ntohl(header_buff[1]);
- metadata.has_time_spec = true;
- metadata.time_spec.secs = ntohl(header_buff[2]);
- metadata.time_spec.ticks = ntohl(header_buff[4]);
- num_header_words32 = 5;
- num_payload_words32 = packet_words32 - 5;
- break;
- case 14:
- metadata.has_time_spec = true;
- metadata.time_spec.secs = ntohl(header_buff[3]);
- metadata.time_spec.ticks = ntohl(header_buff[5]);
- num_header_words32 = 6;
- num_payload_words32 = packet_words32 - 6;
- break;
- case 15:
- metadata.has_stream_id = true;
- metadata.stream_id = ntohl(header_buff[1]);
- metadata.has_time_spec = true;
- metadata.time_spec.secs = ntohl(header_buff[4]);
- metadata.time_spec.ticks = ntohl(header_buff[6]);
- num_header_words32 = 7;
- num_payload_words32 = packet_words32 - 7;
- break;
- case 16:
- num_header_words32 = 1;
- num_payload_words32 = packet_words32 - 2;
- break;
- case 17:
- metadata.has_stream_id = true;
- metadata.stream_id = ntohl(header_buff[1]);
- num_header_words32 = 2;
- num_payload_words32 = packet_words32 - 3;
- break;
- case 18:
- num_header_words32 = 3;
- num_payload_words32 = packet_words32 - 4;
- break;
- case 19:
- metadata.has_stream_id = true;
- metadata.stream_id = ntohl(header_buff[1]);
- num_header_words32 = 4;
- num_payload_words32 = packet_words32 - 5;
- break;
- case 20:
- metadata.has_time_spec = true;
- metadata.time_spec.secs = ntohl(header_buff[1]);
- num_header_words32 = 2;
- num_payload_words32 = packet_words32 - 3;
- break;
- case 21:
- metadata.has_stream_id = true;
- metadata.stream_id = ntohl(header_buff[1]);
- metadata.has_time_spec = true;
- metadata.time_spec.secs = ntohl(header_buff[2]);
- num_header_words32 = 3;
- num_payload_words32 = packet_words32 - 4;
- break;
- case 22:
- metadata.has_time_spec = true;
- metadata.time_spec.secs = ntohl(header_buff[3]);
- num_header_words32 = 4;
- num_payload_words32 = packet_words32 - 5;
- break;
- case 23:
- metadata.has_stream_id = true;
- metadata.stream_id = ntohl(header_buff[1]);
- metadata.has_time_spec = true;
- metadata.time_spec.secs = ntohl(header_buff[4]);
- num_header_words32 = 5;
- num_payload_words32 = packet_words32 - 6;
- break;
- case 24:
- metadata.has_time_spec = true;
- metadata.time_spec.ticks = ntohl(header_buff[2]);
- num_header_words32 = 3;
- num_payload_words32 = packet_words32 - 4;
- break;
- case 25:
- metadata.has_stream_id = true;
- metadata.stream_id = ntohl(header_buff[1]);
- metadata.has_time_spec = true;
- metadata.time_spec.ticks = ntohl(header_buff[3]);
- num_header_words32 = 4;
- num_payload_words32 = packet_words32 - 5;
- break;
- case 26:
- metadata.has_time_spec = true;
- metadata.time_spec.ticks = ntohl(header_buff[4]);
- num_header_words32 = 5;
- num_payload_words32 = packet_words32 - 6;
- break;
- case 27:
- metadata.has_stream_id = true;
- metadata.stream_id = ntohl(header_buff[1]);
- metadata.has_time_spec = true;
- metadata.time_spec.ticks = ntohl(header_buff[5]);
- num_header_words32 = 6;
- num_payload_words32 = packet_words32 - 7;
- break;
- case 28:
- metadata.has_time_spec = true;
- metadata.time_spec.secs = ntohl(header_buff[1]);
- metadata.time_spec.ticks = ntohl(header_buff[3]);
- num_header_words32 = 4;
- num_payload_words32 = packet_words32 - 5;
- break;
- case 29:
- metadata.has_stream_id = true;
- metadata.stream_id = ntohl(header_buff[1]);
- metadata.has_time_spec = true;
- metadata.time_spec.secs = ntohl(header_buff[2]);
- metadata.time_spec.ticks = ntohl(header_buff[4]);
- num_header_words32 = 5;
- num_payload_words32 = packet_words32 - 6;
- break;
- case 30:
- metadata.has_time_spec = true;
- metadata.time_spec.secs = ntohl(header_buff[3]);
- metadata.time_spec.ticks = ntohl(header_buff[5]);
- num_header_words32 = 6;
- num_payload_words32 = packet_words32 - 7;
- break;
- case 31:
- metadata.has_stream_id = true;
- metadata.stream_id = ntohl(header_buff[1]);
- metadata.has_time_spec = true;
- metadata.time_spec.secs = ntohl(header_buff[4]);
- metadata.time_spec.ticks = ntohl(header_buff[6]);
- num_header_words32 = 7;
- num_payload_words32 = packet_words32 - 8;
- break;
- }
-}
-