commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 35/148: got vrt rx somewhat working


From: git
Subject: [Commit-gnuradio] [gnuradio] 35/148: got vrt rx somewhat working
Date: Mon, 15 Aug 2016 00:47:22 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

nwest pushed a commit to annotated tag old_usrp_devel_udp
in repository gnuradio.

commit 3d59bf9b313ed2d1641914784dd7f3980b4e74a4
Author: Josh Blum <address@hidden>
Date:   Sat Nov 7 00:09:22 2009 -0800

    got vrt rx somewhat working
---
 usrp2/firmware/apps/txrx.c                |   9 +-
 usrp2/firmware/include/Makefile.am        |   4 +-
 usrp2/firmware/include/usrp2_eth_packet.h |   2 +-
 usrp2/firmware/include/vrt/bits.h         |  92 ++++++++++++++++++++
 usrp2/firmware/include/vrt/types.h        | 138 ++++++++++++++++++++++++++++++
 usrp2/host/lib/Makefile.am                |   7 +-
 usrp2/host/lib/eth_data_transport.cc      |   2 +-
 usrp2/host/lib/sbuff.h                    |  16 +++-
 usrp2/host/lib/usrp2_impl.cc              |  19 +++-
 9 files changed, 280 insertions(+), 9 deletions(-)

diff --git a/usrp2/firmware/apps/txrx.c b/usrp2/firmware/apps/txrx.c
index 78b771e..5048aa2 100644
--- a/usrp2/firmware/apps/txrx.c
+++ b/usrp2/firmware/apps/txrx.c
@@ -36,6 +36,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include "clocks.h"
+#include <vrt/bits.h>
 
 #define FW_SETS_SEQNO  1       // define to 0 or 1 (FIXME must be 1 for now)
 
@@ -128,7 +129,6 @@ bool is_streaming(void){ return streaming_p; }
 
 // ----------------------------------------------------------------
 
-
 void
 restart_streaming(void)
 {
@@ -136,6 +136,13 @@ restart_streaming(void)
   sr_rx_ctrl->nsamples_per_pkt = streaming_items_per_frame;
   sr_rx_ctrl->nchannels = 1;
   sr_rx_ctrl->clear_overrun = 1;                       // reset
+  sr_rx_ctrl->vrt_header = (0
+     | VRTH_PT_IF_DATA_WITH_SID
+     | VRTH_HAS_TRAILER
+     | VRTH_TSF_SAMPLE_CNT
+     | (6+streaming_items_per_frame)); //MAGIC number 6
+  sr_rx_ctrl->vrt_stream_id = 0xabab;
+  sr_rx_ctrl->vrt_trailer = 0;
 
   streaming_p = true;
   streaming_frame_count = FRAMES_PER_CMD;
diff --git a/usrp2/firmware/include/Makefile.am 
b/usrp2/firmware/include/Makefile.am
index a5e3391..62f63fc 100644
--- a/usrp2/firmware/include/Makefile.am
+++ b/usrp2/firmware/include/Makefile.am
@@ -24,4 +24,6 @@ noinst_HEADERS = \
     usrp2_i2c_addr.h \
     usrp2_mac_addr.h \
     usrp2_mimo_config.h \
-    usrp2_types.h
+    usrp2_types.h \
+    vrt/bits.h \
+    vrt/types.h
diff --git a/usrp2/firmware/include/usrp2_eth_packet.h 
b/usrp2/firmware/include/usrp2_eth_packet.h
index df12761..4fc75e3 100644
--- a/usrp2/firmware/include/usrp2_eth_packet.h
+++ b/usrp2/firmware/include/usrp2_eth_packet.h
@@ -158,7 +158,7 @@ typedef struct {
  *   (sample numbers are made even to force pairwise alignment in the 
interleaved case)
  */
 
-#define U2_MAX_SAMPLES 370
+#define U2_MAX_SAMPLES 350
 #define        U2_MIN_SAMPLES   10
 
 /*
diff --git a/usrp2/firmware/include/vrt/bits.h 
b/usrp2/firmware/include/vrt/bits.h
new file mode 100644
index 0000000..54eeec7
--- /dev/null
+++ b/usrp2/firmware/include/vrt/bits.h
@@ -0,0 +1,92 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 Free Software Foundation, Inc.
+ *
+ * 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_VRT_BITS_H
+#define INCLUDED_VRT_BITS_H
+
+#include <stdint.h>
+
+
+/* VRT Header bits */
+
+#define        VRTH_PT_MASK              (0xf << 28)
+#define        VRTH_PT_IF_DATA_NO_SID    (0x0 << 28)   // IF-Data, no stream id
+#define        VRTH_PT_IF_DATA_WITH_SID  (0x1 << 28)   // IF-Data, w/ stream id
+#define VRTH_PT_EXT_DATA_NO_SID          (0x2 << 28)
+#define        VRTH_PT_EXT_DATA_WITH_SID (0x3 << 28)
+#define        VRTH_PT_IF_CONTEXT        (0x4 << 28)
+#define        VRTH_PT_EXT_CONTEXT       (0x5 << 28)
+
+#define        VRTH_HAS_CLASSID          (1 << 27)
+#define        VRTH_HAS_TRAILER          (1 << 26)     // Data pkts only
+#define        VRTH_START_OF_BURST       (1 << 25)     // Data (Tx) pkts only
+#define        VRTH_END_OF_BURST         (1 << 24)     // Data (Tx) pkts only
+#define        VRTH_TSM                  (1 << 24)     // Context pkts only
+
+#define        VRTH_TSI_MASK             (0x3 << 22)
+#define        VRTH_TSI_NONE             (0x0 << 22)
+#define        VRTH_TSI_UTC              (0x1 << 22)
+#define        VRTH_TSI_GPS              (0x2 << 22)
+#define VRTH_TSI_OTHER           (0x3 << 22)
+
+#define        VRTH_TSF_MASK             (0x3 << 20)
+#define        VRTH_TSF_NONE             (0x0 << 20)
+#define        VRTH_TSF_SAMPLE_CNT       (0x1 << 20)
+#define        VRTH_TSF_REAL_TIME_PS     (0x2 << 20)
+#define        VRTH_TSF_FREE_RUNNING     (0x3 << 20)
+
+#define        VRTH_PKT_CNT_SHIFT        16
+#define        VRTH_PKT_CNT_MASK         (0xf << 16)
+
+#define        VRTH_PKT_SIZE_MASK        0xffff                    
+
+
+static inline int
+vrth_pkt_cnt(uint32_t h)
+{
+  return (h & VRTH_PKT_CNT_MASK) >> 16;
+}
+
+static inline int
+vrth_pkt_size(uint32_t h)
+{
+  return h & VRTH_PKT_SIZE_MASK;
+}
+
+/*
+ * Trailer bits
+ */
+#define        TR_E                  (1 << 8)
+
+#define TR_ENABLE(x) ((x) << 20)
+#define        TR_STATE(x)  ((x) <<  8)
+
+// Use these with TR_ENABLE and TR_STATE
+#define        TR_CAL_TIME           (1 << 11)
+#define        TR_VALID_DATA         (1 << 10)
+#define TR_REF_LOCK          (1 <<  9)
+#define        TR_AGC                (1 <<  8)
+#define TR_DETECTED_SIG              (1 <<  7)
+#define        TR_SPECTRAL_INVERSION (1 <<  6)
+#define        TR_OVER_RANGE         (1 <<  5)
+#define        TR_SAMPLE_LOSS        (1 <<  4)
+#define TR_USER_3            (1 <<  3)
+#define TR_USER_2            (1 <<  2)
+#define TR_USER_1            (1 <<  1)
+#define TR_USER_0            (1 <<  0)
+
+#endif /* INCLUDED_VRT_BITS_H */
diff --git a/usrp2/firmware/include/vrt/types.h 
b/usrp2/firmware/include/vrt/types.h
new file mode 100644
index 0000000..edfa4ec
--- /dev/null
+++ b/usrp2/firmware/include/vrt/types.h
@@ -0,0 +1,138 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 Free Software Foundation, Inc.
+ *
+ * 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_VRT_TYPES_H
+#define INCLUDED_VRT_TYPES_H
+
+#include <stdint.h>
+
+/* macros for dealing with fixed point numbers */
+#define _FXPT_C(_type, _x, _rp) ((_type)((_x)*(1ll << _rp)))
+#define _FXPT_TO_INT(_x, _one) (((_x) + ((_one)/2))/(_one))
+#define _FXPT_TO_DOUBLE(_x, _one) ((double)(_x) * (1.0/(_one)))
+
+/***********************************************************************
+ * The VRT Altitude Type (meters)
+ **********************************************************************/
+typedef int32_t vrt_altitude_t;
+#define VRT_ALTITUDE_RP 5
+#define VRT_ALTITUDE_C(_x) _FXPT_C(vrt_altitude_t, _x, VRT_ALTITUDE_RP)
+
+static inline vrt_altitude_t
+double_to_vrt_altitude(double num){
+  return VRT_ALTITUDE_C(num);
+}
+
+static inline int32_t
+vrt_altitude_round_to_int(vrt_altitude_t fx){
+  return _FXPT_TO_INT(fx, VRT_ALTITUDE_C(1));
+}
+
+static inline double
+vrt_altitude_to_double(vrt_altitude_t fx){
+  return _FXPT_TO_DOUBLE(fx, VRT_ALTITUDE_C(1));
+}
+
+/***********************************************************************
+ * The VRT Geolocation Angle Type (degrees)
+ **********************************************************************/
+typedef int32_t vrt_geo_angle_t;
+#define VRT_GEO_ANGLE_RP 22
+#define VRT_GEO_ANGLE_C(_x) _FXPT_C(vrt_geo_angle_t, _x, VRT_GEO_ANGLE_RP)
+
+static inline vrt_geo_angle_t
+double_to_vrt_geo_angle(double num){
+  return VRT_GEO_ANGLE_C(num);
+}
+
+static inline int16_t
+vrt_geo_angle_round_to_int(vrt_geo_angle_t fx){
+  return _FXPT_TO_INT(fx, VRT_GEO_ANGLE_C(1));
+}
+
+static inline double
+vrt_geo_angle_to_double(vrt_geo_angle_t fx){
+  return _FXPT_TO_DOUBLE(fx, VRT_GEO_ANGLE_C(1));
+}
+
+/***********************************************************************
+ * The VRT Frequency Type (Hz)
+ **********************************************************************/
+typedef int64_t vrt_freq_t;
+#define VRT_FREQ_RP 20
+#define VRT_FREQ_C(_x) _FXPT_C(vrt_freq_t, _x, VRT_FREQ_RP)
+
+static inline vrt_freq_t
+double_to_vrt_freq(double num){
+  return VRT_FREQ_C(num);
+}
+
+static inline int64_t
+vrt_freq_round_to_int(vrt_freq_t fx){
+  return _FXPT_TO_INT(fx, VRT_FREQ_C(1));
+}
+
+static inline double
+vrt_freq_to_double(vrt_freq_t fx){
+  return _FXPT_TO_DOUBLE(fx, VRT_FREQ_C(1));
+}
+
+/***********************************************************************
+ * The VRT Gain Type (dB)
+ **********************************************************************/
+typedef int16_t vrt_gain_t;
+#define VRT_GAIN_RP 7
+#define VRT_GAIN_C(_x) _FXPT_C(vrt_gain_t, _x, VRT_GAIN_RP)
+
+static inline vrt_gain_t
+double_to_vrt_gain(double num){
+  return VRT_GAIN_C(num);
+}
+
+static inline int16_t
+vrt_gain_round_to_int(vrt_gain_t fx){
+  return _FXPT_TO_INT(fx, VRT_GAIN_C(1));
+}
+
+static inline double
+vrt_gain_to_double(vrt_gain_t fx){
+  return _FXPT_TO_DOUBLE(fx, VRT_GAIN_C(1));
+}
+
+/***********************************************************************
+ * The VRT Temperature Type (Celcius)
+ **********************************************************************/
+typedef int16_t vrt_temp_t;
+#define VRT_TEMP_RP 6
+#define VRT_TEMP_C(_x) _FXPT_C(vrt_temp_t, _x, VRT_TEMP_RP)
+
+static inline vrt_temp_t
+double_to_vrt_temp(double num){
+  return VRT_TEMP_C(num);
+}
+
+static inline int16_t
+vrt_temp_round_to_int(vrt_temp_t fx){
+  return _FXPT_TO_INT(fx, VRT_TEMP_C(1));
+}
+
+static inline double
+vrt_temp_to_double(vrt_temp_t fx){
+  return _FXPT_TO_DOUBLE(fx, VRT_TEMP_C(1));
+}
+
+#endif /* INCLUDED_VRT_TYPES_H */
diff --git a/usrp2/host/lib/Makefile.am b/usrp2/host/lib/Makefile.am
index 9d65257..d154ab5 100644
--- a/usrp2/host/lib/Makefile.am
+++ b/usrp2/host/lib/Makefile.am
@@ -22,7 +22,8 @@ AM_CPPFLAGS = \
     $(BOOST_CPPFLAGS) \
     $(STD_DEFINES_AND_INCLUDES) \
     $(CPPUNIT_INCLUDES) \
-    $(GRUEL_INCLUDES) 
+    $(GRUEL_INCLUDES) \
+    $(VRT_INCLUDES)
 
 bin_PROGRAMS = usrp2_socket_opener
 usrp2_socket_opener_SOURCES = usrp2_socket_opener.cc
@@ -52,7 +53,9 @@ libusrp2_la_SOURCES = \
 
 libusrp2_la_LIBADD = \
        $(GRUEL_LA) \
-       $(BOOST_LDFLAGS) $(BOOST_THREAD_LIB)
+       $(BOOST_LDFLAGS) \
+       $(BOOST_THREAD_LIB) \
+       $(VRT_LA)
 
 # Private headers not needed for above the API development
 noinst_HEADERS = \
diff --git a/usrp2/host/lib/eth_data_transport.cc 
b/usrp2/host/lib/eth_data_transport.cc
index 2dfae43..eaca5e3 100644
--- a/usrp2/host/lib/eth_data_transport.cc
+++ b/usrp2/host/lib/eth_data_transport.cc
@@ -84,7 +84,7 @@ std::vector<usrp2::sbuff::sptr> 
usrp2::eth_data_transport::recv(){
         u2_eth_packet_only_t *hdr = (u2_eth_packet_only_t *)base;
         d_num_rx_frames++;
         d_num_rx_bytes += len;
-        
+
         /* --- FIXME start of fake transport layer handler --- */
 
         if (d_rx_seqno != -1) {
diff --git a/usrp2/host/lib/sbuff.h b/usrp2/host/lib/sbuff.h
index dc5912a..caef07f 100644
--- a/usrp2/host/lib/sbuff.h
+++ b/usrp2/host/lib/sbuff.h
@@ -64,10 +64,24 @@ namespace usrp2 {
         }
         sbuff(void *buff, size_t len, cb_t cb)
          : d_buff(buff), d_len(len), d_cb(cb){}
-        ~sbuff(){if (d_cb) d_cb();}
+        ~sbuff(){done();}
         //access methods
         void *buff(){return d_buff;}
         size_t len(){return d_len;}
+        /*!
+         * \brief mark this sbuff as done
+         * This method allows one to explicitly tell the sbuff that its no 
longer needed.
+         * Doing so will make the callback (if set) and zero out the other 
data.
+         *
+         * Although this method will be called automatically when the sptr 
calls delete,
+         * it is useful for the fast-path to have the ability to call done 
explicitly.
+         */
+        void done(){
+            if (d_cb) d_cb();
+            d_buff = NULL;
+            d_len = 0;
+            d_cb = NULL;
+        }
 
     };
 
diff --git a/usrp2/host/lib/usrp2_impl.cc b/usrp2/host/lib/usrp2_impl.cc
index 8800862..096ecf7 100644
--- a/usrp2/host/lib/usrp2_impl.cc
+++ b/usrp2/host/lib/usrp2_impl.cc
@@ -39,6 +39,7 @@
 #include <stddef.h>
 #include <assert.h>
 #include <string.h>
+#include <vrt/expanded_header.h>
 
 static const int DEFAULT_RX_SCALE = 1024;
 
@@ -93,6 +94,18 @@ namespace usrp2 {
   parse_rx_metadata(void *p, size_t payload_len_in_bytes,
                    uint32_t **items, size_t *nitems_in_uint32s, rx_metadata 
*md)
   {
+
+    uint32_t *d = (uint32_t*)p;
+    vrt::expanded_header vrt_hdr;
+
+    if (vrt::expanded_header::parse(
+        (const uint32_t*)(d+1), payload_len_in_bytes/sizeof(uint32_t), //in
+        &vrt_hdr, (const uint32_t**)items, nitems_in_uint32s) and 
vrt_hdr.if_data_p()){ //out
+        return true;
+    } else {
+        printf("Bad vrt header %x\n", vrt_hdr.header);
+    }
+
     if (payload_len_in_bytes < sizeof(u2_fixed_hdr_t)) // invalid format
       return false;
 
@@ -309,6 +322,7 @@ namespace usrp2 {
 
         if (!d_channel_rings[chan]) {
             DEBUG_LOG("!");
+            sb->done(); //mark done, this sbuff is no longer needed
             continue;  // discard packet, no channel handler
         }
 
@@ -317,6 +331,7 @@ namespace usrp2 {
             DEBUG_LOG("+");
         } else {
             DEBUG_LOG("!");
+            sb->done(); //mark done, this sbuff is no longer needed
             continue;     //discard packet, enqueue failed
         }
     }
@@ -592,7 +607,7 @@ namespace usrp2 {
 
       bool want_more = (*handler)(items, nitems_in_uint32s, &md);
       DEBUG_LOG("-");
-      sb.reset(); //reset to call cleanup callback
+      sb->done(); //mark done, this sbuff is no longer needed
       dec_enqueued();
 
       if (!want_more)
@@ -624,7 +639,7 @@ namespace usrp2 {
     // Iterate through frames and drop them
     sbuff::sptr sb;
     while (rp->dequeue(sb)) {
-      sb.reset(); //reset to call cleanup callback
+      sb->done(); //mark done, this sbuff is no longer needed
       dec_enqueued();
     }
     return true;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]