commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r7644 - in usrp2/trunk: firmware/apps host/apps host/l


From: eb
Subject: [Commit-gnuradio] r7644 - in usrp2/trunk: firmware/apps host/apps host/lib
Date: Tue, 12 Feb 2008 01:16:33 -0700 (MST)

Author: eb
Date: 2008-02-12 01:16:33 -0700 (Tue, 12 Feb 2008)
New Revision: 7644

Added:
   usrp2/trunk/host/apps/README
   usrp2/trunk/host/apps/stdin_int32_fft.py
   usrp2/trunk/host/apps/streaming_fft.py
Modified:
   usrp2/trunk/firmware/apps/rx_only.c
   usrp2/trunk/host/apps/rx_streaming_samples.cc
   usrp2/trunk/host/lib/gri_ethernet.cc
   usrp2/trunk/host/lib/usrp2_basic.cc
Log:
can now stream samples into fft display

Modified: usrp2/trunk/firmware/apps/rx_only.c
===================================================================
--- usrp2/trunk/firmware/apps/rx_only.c 2008-02-12 07:10:53 UTC (rev 7643)
+++ usrp2/trunk/firmware/apps/rx_only.c 2008-02-12 08:16:33 UTC (rev 7644)
@@ -57,6 +57,13 @@
 #define        DSP_RX_BUF_1    3       // dsp rx -> eth
 
 
+// variables for streaming mode
+
+static bool     streaming_p = false;
+static int      streaming_frame_count = 0;
+#define FRAMES_PER_CMD 1000
+
+
 /*
  * ================================================================
  *      configure DSP RX double buffering state machine
@@ -123,18 +130,33 @@
   dsp_rx_regs->freq = p->phase_inc;
   dsp_rx_regs->scale_iq = p->scale_iq;
   dsp_rx_regs->decim_rate = p->decim - 1;      // register gets N-1
-  dsp_rx_regs->rx_command = MK_RX_CMD(p->total_samples, p->samples_per_frame);
 
-  // kick off the state machine
-  dbsm_start(&dsp_rx_sm);
+  if (p->total_samples == 0){                  // we're streaming
+    streaming_p = true;
+    streaming_frame_count = FRAMES_PER_CMD;
+    dsp_rx_regs->rx_command =
+      MK_RX_CMD(FRAMES_PER_CMD * p->samples_per_frame, p->samples_per_frame);
 
-  dsp_rx_regs->rx_time = T_NOW;                // start NOW!
+    // kick off the state machine
+    dbsm_start(&dsp_rx_sm);
+    dsp_rx_regs->rx_time = T_NOW;              // queue up two commands
+    dsp_rx_regs->rx_time = T_NOW;
+  }
+  else {
+    streaming_p = false;
+    dsp_rx_regs->rx_command = MK_RX_CMD(p->total_samples, 
p->samples_per_frame);
+
+    // kick off the state machine
+    dbsm_start(&dsp_rx_sm);
+    dsp_rx_regs->rx_time = T_NOW;              // start NOW!
+  }
 }
 
 
 void
 stop_rx_cmd(void)
 {
+  streaming_p = false;
   dsp_rx_regs->clear_state = 1;        // flush cmd queue
   bp_clear_buf(DSP_RX_BUF_0);
   bp_clear_buf(DSP_RX_BUF_1);
@@ -182,6 +204,12 @@
   t = (t & 0xffff00ff) | ((seqno & 0xff) << 8);
   p[4] = t;
 
+  // queue up another rx command when required
+  if (streaming_p && --streaming_frame_count == 0){
+    streaming_frame_count = FRAMES_PER_CMD;
+    dsp_rx_regs->rx_time = T_NOW;
+  }
+
   return false;                // we didn't handle the packet
 }
 #endif

Added: usrp2/trunk/host/apps/README
===================================================================
--- usrp2/trunk/host/apps/README                                (rev 0)
+++ usrp2/trunk/host/apps/README        2008-02-12 08:16:33 UTC (rev 7644)
@@ -0,0 +1,7 @@
+Try this:
+
+# bump up shared memory segment size
+$ sudo sh -c "echo 200000000 >/proc/sys/kernel/shmmax" 
+
+$ ./apps/streaming_fft.py -e eth0 -f 10M -d 8
+

Modified: usrp2/trunk/host/apps/rx_streaming_samples.cc
===================================================================
--- usrp2/trunk/host/apps/rx_streaming_samples.cc       2008-02-12 07:10:53 UTC 
(rev 7643)
+++ usrp2/trunk/host/apps/rx_streaming_samples.cc       2008-02-12 08:16:33 UTC 
(rev 7644)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2007 Free Software Foundation, Inc.
+ * Copyright 2007,2008 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
@@ -183,7 +183,7 @@
   fprintf(stderr, "  -o OUTPUT_FILE       set output filename 
[default=samples.dat]\n");
   fprintf(stderr, "  -f FREQ              set frequency to FREQ 
[default=0]\n");
   fprintf(stderr, "  -d DECIM             set decimation rate to DECIM 
[default=32]\n");
-  fprintf(stderr, "  -N NSAMPLES          total number of samples to receive 
[default=2.5e6]\n");
+  fprintf(stderr, "  -N NSAMPLES          total number of samples to receive 
[default=infinite]\n");
   fprintf(stderr, "  -F SAMPLES_PER_FRAME number of samples in each frame 
[default=371]\n");
   fprintf(stderr, "  -S SCALE             fpga scaling factor for I & Q 
[default=256]\n");
 }
@@ -209,7 +209,7 @@
   const char *output_filename = "samples.dat";
   double freq = 0;
   int32_t decim = 32;
-  int32_t nsamples = static_cast<int32_t>(2.5e6);
+  uint64_t nsamples = ~0;
   int32_t samples_per_frame = 371;
   int32_t scale = 256;
 
@@ -217,7 +217,7 @@
   double tmp;
   u2_mac_addr_t mac_addr;
 
-  setvbuf(stdout, 0, _IOFBF, 64 * 1024); // make stdout fully buffered
+  // setvbuf(stdout, 0, _IOFBF, 64 * 1024); // make stdout fully buffered
 
   while ((ch = getopt(argc, argv, "he:m:o:f:d:N:F:S")) != EOF){
     switch (ch){
@@ -253,7 +253,7 @@
        usage(argv[0]);
        exit(1);
       }
-      nsamples = static_cast<int32_t>(tmp);
+      nsamples = static_cast<uint64_t>(tmp);
       break;
 
     case 'F':
@@ -312,7 +312,7 @@
   std::vector<op_id_reply_t> r = u2->find_usrps();
 
   for (size_t i = 0; i < r.size(); i++){
-    std::cout << r[i] << std::endl;
+    std::cerr << r[i] << std::endl;
   }
 
   if (r.size() == 0){
@@ -333,13 +333,14 @@
   writer->start_undetached();
   
 
-  if (!u2->start_rx(which, freq, decim, nsamples, samples_per_frame, scale, 
scale)){
+  if (!u2->start_rx(which, freq, decim, 0, samples_per_frame, scale, scale)){
     std::cerr << "start_rx failed\n";
     return 1;
   }
 
 
-  long total_samples_recvd = 0;
+  uint64_t total_samples_recvd = 0;
+  int  expected_seqno = 0;
 
   while (!signaled && total_samples_recvd < nsamples){
     u2_eth_samples_t   pkt;
@@ -362,6 +363,11 @@
 
     rb->d_writer->update_write_pointer(n);
     rb->d_not_empty.post();
+
+    if (pkt.hdrs.thdr.seqno != expected_seqno)
+      ::write(2, "S", 1);
+
+    expected_seqno = (pkt.hdrs.thdr.seqno + 1) & 0xff;
   }
 
   stop_writer = true;

Added: usrp2/trunk/host/apps/stdin_int32_fft.py
===================================================================
--- usrp2/trunk/host/apps/stdin_int32_fft.py                            (rev 0)
+++ usrp2/trunk/host/apps/stdin_int32_fft.py    2008-02-12 08:16:33 UTC (rev 
7644)
@@ -0,0 +1,201 @@
+#!/usr/bin/env python
+#
+# Copyright 2004,2005,2007,2008 Free Software Foundation, Inc.
+# 
+# This file is part of GNU Radio
+# 
+# GNU Radio 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, or (at your option)
+# any later version.
+# 
+# GNU Radio 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 GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+# 
+
+from gnuradio import gr, gru
+from gnuradio import eng_notation
+from gnuradio.eng_option import eng_option
+from gnuradio.wxgui import stdgui2, fftsink2, waterfallsink2, scopesink2, 
form, slider
+from optparse import OptionParser
+import wx
+import sys
+import numpy
+
+
+class app_top_block(stdgui2.std_top_block):
+    def __init__(self, frame, panel, vbox, argv):
+        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)
+
+        self.frame = frame
+        self.panel = panel
+        
+        parser = OptionParser(option_class=eng_option)
+        parser.add_option("-d", "--decim", type="int", default=16,
+                          help="set fgpa decimation rate to DECIM 
[default=%default]")
+        parser.add_option("-f", "--freq", type="eng_float", default=None,
+                          help="set frequency to FREQ", metavar="FREQ")
+        parser.add_option("-W", "--waterfall", action="store_true", 
default=False,
+                          help="Enable waterfall display")
+        parser.add_option("-S", "--oscilloscope", action="store_true", 
default=False,
+                          help="Enable oscilloscope display")
+        (options, args) = parser.parse_args()
+        if len(args) != 0:
+            parser.print_help()
+            sys.exit(1)
+       self.options = options
+        self.options.gain = 1.0
+        self.show_debug_info = True
+        
+
+        input_rate = 100e6 / options.decim
+
+        self.src = gr.file_descriptor_source(gr.sizeof_short, 0, False);
+        self.s2c = gr.interleaved_short_to_complex()
+
+        if options.waterfall:
+            self.scope = \
+              waterfallsink2.waterfall_sink_c (panel, fft_size=1024, 
sample_rate=input_rate)
+        elif options.oscilloscope:
+            self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate)
+        else:
+            self.scope = fftsink2.fft_sink_c (panel, fft_size=1024, 
sample_rate=input_rate)
+
+        self.connect(self.src, self.s2c, self.scope)
+
+        self._build_gui(vbox)
+       self._setup_events()
+       
+        # set initial values
+
+        if options.freq is None:
+            # if no freq was specified, use the mid-point
+            options.freq = 0.0
+
+        if self.show_debug_info:
+            self.myform['decim'].set_value(self.options.decim)
+
+
+    def _set_status_msg(self, msg):
+        self.frame.GetStatusBar().SetStatusText(msg, 0)
+
+    def _build_gui(self, vbox):
+
+        def _form_set_freq(kv):
+            return self.set_freq(kv['freq'])
+            
+        vbox.Add(self.scope.win, 10, wx.EXPAND)
+        
+        # add control area at the bottom
+        self.myform = myform = form.form()
+        hbox = wx.BoxSizer(wx.HORIZONTAL)
+        hbox.Add((5,0), 0, 0)
+        myform['freq'] = form.float_field(
+            parent=self.panel, sizer=hbox, label="Center freq", weight=1,
+            callback=myform.check_input_and_call(_form_set_freq, 
self._set_status_msg))
+
+        hbox.Add((5,0), 0, 0)
+        vbox.Add(hbox, 0, wx.EXPAND)
+
+        self._build_subpanel(vbox)
+
+    def _build_subpanel(self, vbox_arg):
+        # build a secondary information panel (sometimes hidden)
+
+        # FIXME figure out how to have this be a subpanel that is always
+        # created, but has its visibility controlled by foo.Show(True/False)
+        
+        def _form_set_decim(kv):
+            return self.set_decim(kv['decim'])
+
+        if not(self.show_debug_info):
+            return
+
+        panel = self.panel
+        vbox = vbox_arg
+        myform = self.myform
+
+        #panel = wx.Panel(self.panel, -1)
+        #vbox = wx.BoxSizer(wx.VERTICAL)
+
+        hbox = wx.BoxSizer(wx.HORIZONTAL)
+        hbox.Add((5,0), 0)
+
+        myform['decim'] = form.int_field(
+            parent=panel, sizer=hbox, label="Decim",
+            callback=myform.check_input_and_call(_form_set_decim, 
self._set_status_msg))
+
+        hbox.Add((5,0), 0)
+        vbox.Add(hbox, 0, wx.EXPAND)
+
+        
+    def set_freq(self, target_freq):
+        """
+        Set the center frequency we're interested in.
+
+        @param target_freq: frequency in Hz
+        @rypte: bool
+
+        Tuning is a two step process.  First we ask the front-end to
+        tune as close to the desired frequency as it can.  Then we use
+        the result of that operation and our target_frequency to
+        determine the value for the digital down converter.
+        """
+        
+        if True:
+            self.myform['freq'].set_value(target_freq)     # update displayed 
value
+           if not self.options.waterfall and not self.options.oscilloscope:
+               self.scope.win.set_baseband_freq(target_freq)
+           return True
+
+        return False
+
+    def set_gain(self, gain):
+        self.myform['gain'].set_value(gain)     # update displayed value
+
+    def set_decim(self, decim):
+        input_rate = 100e6 / self.options.decim
+        self.scope.set_sample_rate(input_rate)
+        if self.show_debug_info:  # update displayed values
+            self.myform['decim'].set_value(self.u.decim_rate())
+        return ok
+
+    def _setup_events(self):
+       if not self.options.waterfall and not self.options.oscilloscope:
+           self.scope.win.Bind(wx.EVT_LEFT_DCLICK, self.evt_left_dclick)
+           
+    def evt_left_dclick(self, event):
+       (ux, uy) = self.scope.win.GetXY(event)
+       if event.CmdDown():
+           # Re-center on maximum power
+           points = self.scope.win._points
+           if self.scope.win.peak_hold:
+               if self.scope.win.peak_vals is not None:
+                   ind = numpy.argmax(self.scope.win.peak_vals)
+               else:
+                   ind = int(points.shape()[0]/2)
+           else:
+               ind = numpy.argmax(points[:,1])
+            (freq, pwr) = points[ind]
+           target_freq = freq/self.scope.win._scale_factor
+           print ind, freq, pwr
+            self.set_freq(target_freq)            
+       else:
+           # Re-center on clicked frequency
+           target_freq = ux/self.scope.win._scale_factor
+           self.set_freq(target_freq)
+           
+       
+def main ():
+    app = stdgui2.stdapp(app_top_block, "USRP FFT", nstatus=1)
+    app.MainLoop()
+
+if __name__ == '__main__':
+    main ()


Property changes on: usrp2/trunk/host/apps/stdin_int32_fft.py
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native

Added: usrp2/trunk/host/apps/streaming_fft.py
===================================================================
--- usrp2/trunk/host/apps/streaming_fft.py                              (rev 0)
+++ usrp2/trunk/host/apps/streaming_fft.py      2008-02-12 08:16:33 UTC (rev 
7644)
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+#
+# Copyright 2008 Free Software Foundation, Inc.
+# 
+# This file is part of GNU Radio
+# 
+# GNU Radio 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, or (at your option)
+# any later version.
+# 
+# GNU Radio 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, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+import os
+import os.path
+import sys
+from gnuradio.eng_option import eng_option
+from optparse import OptionParser
+
+def main():
+    parser = OptionParser(option_class=eng_option)
+    parser.add_option("-d", "--decim", type="int", default=16,
+                      help="set fgpa decimation rate to DECIM 
[default=%default]")
+    parser.add_option("-f", "--freq", type="eng_float", default=0.0,
+                      help="set frequency to FREQ", metavar="FREQ")
+    parser.add_option("-W", "--waterfall", action="store_true", default=False,
+                      help="Enable waterfall display")
+    parser.add_option("-S", "--oscilloscope", action="store_true", 
default=False,
+                      help="Enable oscilloscope display")
+    parser.add_option("-F", "--samples-per-frame", type="int", default=250,
+                      help="[default=%default]")
+    parser.add_option("-e", "--eth", default="eth0",
+                      help="specify ethernet interface [default=%default]")
+
+    (options, args) = parser.parse_args()
+    if len(args) != 0:
+        parser.print_help()
+        sys.exit(1)
+
+
+    path = os.path.dirname(sys.argv[0])
+    if path == '':
+        path = '.'
+    
+    cmd = "sudo %s/rx_streaming_samples -e %s -f %g -d %d -F %d -o 
/proc/self/fd/1 | %s/stdin_int32_fft.py -f %g -d %d" % (
+        path, options.eth, options.freq, options.decim, 
options.samples_per_frame,
+        path, options.freq, options.decim)
+
+    print cmd
+    os.system(cmd)
+    
+
+if __name__ == '__main__':
+    main()


Property changes on: usrp2/trunk/host/apps/streaming_fft.py
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native

Modified: usrp2/trunk/host/lib/gri_ethernet.cc
===================================================================
--- usrp2/trunk/host/lib/gri_ethernet.cc        2008-02-12 07:10:53 UTC (rev 
7643)
+++ usrp2/trunk/host/lib/gri_ethernet.cc        2008-02-12 08:16:33 UTC (rev 
7644)
@@ -35,9 +35,9 @@
 
 #include <linux/types.h>
 #include <linux/filter.h>      // packet filter
-#ifdef HAVE_LINUX_IF_PACKET_H
-#include <linux/if_packet.h>   // circular buffer defs for PF_PACKET
-#endif
+//#ifdef HAVE_LINUX_IF_PACKET_H
+//#include <linux/if_packet.h> // circular buffer defs for PF_PACKET
+//#endif
 
 static int
 open_packet_socket (std::string ifname, int protocol)

Modified: usrp2/trunk/host/lib/usrp2_basic.cc
===================================================================
--- usrp2/trunk/host/lib/usrp2_basic.cc 2008-02-12 07:10:53 UTC (rev 7643)
+++ usrp2/trunk/host/lib/usrp2_basic.cc 2008-02-12 08:16:33 UTC (rev 7644)
@@ -190,7 +190,7 @@
     op_start_rx_t      op;
   };
     
-  if (total_samples < 9 || total_samples >= (1L << 23)){
+  if ((total_samples < 9 && total_samples != 0) || total_samples >= (1L << 
23)){
     std::cerr << "usrp2_basic::start_rx: total_samples is out of range\n";
     return false;
   }





reply via email to

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