aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/transport/gen_vrt.py
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-06-07 20:42:32 +0000
committerJosh Blum <josh@joshknows.com>2010-06-07 20:42:32 +0000
commit8329c5eafc486c9eec6edabbdc2533436127c252 (patch)
tree79b4ebbfe3a6fa192c6ccf04c2a49c60f81a90b8 /host/lib/transport/gen_vrt.py
parent7332fc3198a81d9f747ea2a033c1cca168858944 (diff)
parent0f4eff49c820a8d2ccb38e191604eb86c81b30af (diff)
downloaduhd-8329c5eafc486c9eec6edabbdc2533436127c252.tar.gz
uhd-8329c5eafc486c9eec6edabbdc2533436127c252.tar.bz2
uhd-8329c5eafc486c9eec6edabbdc2533436127c252.zip
Merge branch 'work' of ettus.sourcerepo.com:ettus/uhdpriv into usrp_e
Diffstat (limited to 'host/lib/transport/gen_vrt.py')
-rwxr-xr-xhost/lib/transport/gen_vrt.py74
1 files changed, 47 insertions, 27 deletions
diff --git a/host/lib/transport/gen_vrt.py b/host/lib/transport/gen_vrt.py
index c34ffb198..1417240ab 100755
--- a/host/lib/transport/gen_vrt.py
+++ b/host/lib/transport/gen_vrt.py
@@ -27,28 +27,42 @@ The generated code infers jump tables to speed-up the parsing time.
TMPL_TEXT = """
#import time
-
-########################################################################
-## setup predicates
-########################################################################
-#set $sid_p = 0b00001
-#set $cid_p = 0b00010
-#set $tsi_p = 0b00100
-#set $tsf_p = 0b01000
-#set $tlr_p = 0b10000
-
/***********************************************************************
* This file was generated by $file on $time.strftime("%c")
**********************************************************************/
\#include <uhd/transport/vrt.hpp>
-\#include <boost/asio.hpp> //endianness conversion
+\#include <uhd/utils/byteswap.hpp>
\#include <stdexcept>
+//define the endian macros to convert integers
+\#ifdef HAVE_BIG_ENDIAN
+ \#define BE_MACRO(x) (x)
+ \#define LE_MACRO(x) uhd::byteswap(x)
+\#else
+ \#define BE_MACRO(x) uhd::byteswap(x)
+ \#define LE_MACRO(x) (x)
+\#endif
+
+#set $XE_MACRO = "BE_MACRO"
+
using namespace uhd;
using namespace uhd::transport;
-void vrt::pack(
+########################################################################
+#def gen_code($XE_MACRO, $suffix)
+########################################################################
+
+########################################################################
+## setup predicates
+########################################################################
+#set $sid_p = 0b00001
+#set $cid_p = 0b00010
+#set $tsi_p = 0b00100
+#set $tsf_p = 0b01000
+#set $tlr_p = 0b10000
+
+void vrt::pack_$(suffix)(
const tx_metadata_t &metadata, //input
boost::uint32_t *header_buff, //output
size_t &num_header_words32, //output
@@ -70,29 +84,29 @@ void vrt::pack(
#set $flags = 0
########## Stream ID ##########
#if $pred & $sid_p
- header_buff[$num_header_words] = htonl(metadata.stream_id);
+ header_buff[$num_header_words] = $(XE_MACRO)(metadata.stream_id);
#set $num_header_words += 1
#set $flags |= (0x1 << 28);
#end if
########## Class ID ##########
#if $pred & $cid_p
- header_buff[$num_header_words] = htonl(0);
+ header_buff[$num_header_words] = 0;
#set $num_header_words += 1
- header_buff[$num_header_words] = htonl(0);
+ header_buff[$num_header_words] = 0;
#set $num_header_words += 1
#set $flags |= (0x1 << 27);
#end if
########## Integer Time ##########
#if $pred & $tsi_p
- header_buff[$num_header_words] = htonl(metadata.time_spec.secs);
+ header_buff[$num_header_words] = $(XE_MACRO)(metadata.time_spec.secs);
#set $num_header_words += 1
#set $flags |= (0x3 << 22);
#end if
########## Fractional Time ##########
#if $pred & $tsf_p
- header_buff[$num_header_words] = htonl(0);
+ header_buff[$num_header_words] = 0;
#set $num_header_words += 1
- header_buff[$num_header_words] = htonl(metadata.time_spec.get_ticks(tick_rate));
+ header_buff[$num_header_words] = $(XE_MACRO)(metadata.time_spec.get_ticks(tick_rate));
#set $num_header_words += 1
#set $flags |= (0x1 << 20);
#end if
@@ -116,13 +130,13 @@ void vrt::pack(
if (metadata.end_of_burst) vrt_hdr_flags |= $hex(0x1 << 24);
//fill in complete header word
- header_buff[0] = htonl(vrt_hdr_flags |
+ header_buff[0] = $(XE_MACRO)(vrt_hdr_flags |
((packet_count & 0xf) << 16) |
(num_packet_words32 & 0xffff)
);
}
-void vrt::unpack(
+void vrt::unpack_$(suffix)(
rx_metadata_t &metadata, //output
const boost::uint32_t *header_buff, //input
size_t &num_header_words32, //output
@@ -135,7 +149,7 @@ void vrt::unpack(
metadata = rx_metadata_t();
//extract vrt header
- boost::uint32_t vrt_hdr_word = ntohl(header_buff[0]);
+ boost::uint32_t vrt_hdr_word = $(XE_MACRO)(header_buff[0]);
size_t packet_words32 = vrt_hdr_word & 0xffff;
packet_count = (vrt_hdr_word >> 16) & 0xf;
@@ -160,7 +174,7 @@ void vrt::unpack(
########## Stream ID ##########
#if $pred & $sid_p
metadata.has_stream_id = true;
- metadata.stream_id = ntohl(header_buff[$num_header_words]);
+ metadata.stream_id = $(XE_MACRO)(header_buff[$num_header_words]);
#set $num_header_words += 1
#end if
########## Class ID ##########
@@ -172,7 +186,7 @@ void vrt::unpack(
#if $pred & $tsi_p
metadata.has_time_spec = true;
#set $set_has_time_spec = True
- metadata.time_spec.secs = ntohl(header_buff[$num_header_words]);
+ metadata.time_spec.secs = $(XE_MACRO)(header_buff[$num_header_words]);
#set $num_header_words += 1
#end if
########## Fractional Time ##########
@@ -182,7 +196,7 @@ void vrt::unpack(
#set $set_has_time_spec = True
#end if
#set $num_header_words += 1
- metadata.time_spec.set_ticks(ntohl(header_buff[$num_header_words]), tick_rate);
+ metadata.time_spec.set_ticks($(XE_MACRO)(header_buff[$num_header_words]), tick_rate);
#set $num_header_words += 1
#end if
########## Trailer ##########
@@ -198,13 +212,19 @@ void vrt::unpack(
#end for
}
}
-"""
-import sys
+########################################################################
+#end def
+########################################################################
+
+$gen_code("BE_MACRO", "be")
+$gen_code("LE_MACRO", "le")
+"""
-from Cheetah.Template import Template
def parse_tmpl(_tmpl_text, **kwargs):
+ from Cheetah.Template import Template
return str(Template(_tmpl_text, kwargs))
if __name__ == '__main__':
+ import sys
open(sys.argv[1], 'w').write(parse_tmpl(TMPL_TEXT, file=__file__))