commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r8507 - in usrp2/trunk/host: apps lib


From: eb
Subject: [Commit-gnuradio] r8507 - in usrp2/trunk/host: apps lib
Date: Sun, 25 May 2008 23:37:04 -0600 (MDT)

Author: eb
Date: 2008-05-25 23:37:03 -0600 (Sun, 25 May 2008)
New Revision: 8507

Modified:
   usrp2/trunk/host/apps/rx_streaming_samples2.cc
   usrp2/trunk/host/lib/usrp2_basic.cc
   usrp2/trunk/host/lib/usrp2_basic.h
   usrp2/trunk/host/lib/usrp2_basic_thread.cc
Log:
rx_streaming_samples2 now working

Modified: usrp2/trunk/host/apps/rx_streaming_samples2.cc
===================================================================
--- usrp2/trunk/host/apps/rx_streaming_samples2.cc      2008-05-26 04:34:43 UTC 
(rev 8506)
+++ usrp2/trunk/host/apps/rx_streaming_samples2.cc      2008-05-26 05:37:03 UTC 
(rev 8507)
@@ -232,11 +232,21 @@
   
   uint64_t total_samples_recvd = 0;
 
+  static const size_t MAX_SAMPLES = 16384;
+  
   while (!signaled && total_samples_recvd < nsamples){
-    uint32_t samples[250];
-    int n = u2->rx_samples(250, samples, NULL);
+    uint32_t samples[MAX_SAMPLES];
+    size_t n_to_read = std::min((uint64_t) MAX_SAMPLES, total_samples_recvd - 
nsamples);
+    int n = u2->rx_samples(n_to_read, samples, NULL);
     total_samples_recvd += n;
 
+    // FIXME I don't think the endianness stuff should be handled here
+
+#ifndef WORDS_BIGENDIAN
+    for (int i = 0; i < n; i++)
+      samples[i] = ntohl(samples[i]);
+#endif  
+
     ::write(ofd, samples, n*sizeof(uint32_t));
   }
   

Modified: usrp2/trunk/host/lib/usrp2_basic.cc
===================================================================
--- usrp2/trunk/host/lib/usrp2_basic.cc 2008-05-26 04:34:43 UTC (rev 8506)
+++ usrp2/trunk/host/lib/usrp2_basic.cc 2008-05-26 05:37:03 UTC (rev 8507)
@@ -39,6 +39,15 @@
 #include <unistd.h>
 #endif
 
+static void
+udelay(long usecs)
+{
+  struct timeval t;
+  t.tv_sec = 0;
+  t.tv_usec = usecs;
+  select(0, 0, 0, 0, &t);
+}
+
 #define USRP2_BASIC_DEBUG 0
 #if USRP2_BASIC_DEBUG
 #define DEBUG_LOG(x) ::write(2, x, 1)
@@ -73,8 +82,8 @@
 
 usrp2_basic::usrp2_basic(const std::string &ifc, const u2_mac_addr_t &addr)
   : d_ethernet(new gri_ethernet()), d_pf(0), d_seqno(0), d_next_rid(0),
-    d_rx_started(false), d_tx_started(false), d_thread(0), 
-    d_rx_samples(65535, 255), d_tx_samples(65535, 255)
+    d_rx_active(false), d_tx_active(false), d_thread(0), 
+    d_rx_samples(256 * (1<<10), 1000), d_tx_samples(256 * (1<<10), 1000)
 {
   if (USRP2_BASIC_DEBUG)
     std::cerr << "usrp2_basic: constructor" << std::endl;
@@ -88,6 +97,11 @@
   if (!d_ethernet->attach_pktfilter(d_pf))
     throw std::runtime_error("Unable to attach packet filter.");
   d_addr = addr;
+
+  d_thread = new usrp2_basic_thread(this);
+  d_thread->start();
+
+  udelay(1000);        // block for 1ms to allow thread to start
 }
 
 usrp2_basic::~usrp2_basic()
@@ -99,6 +113,9 @@
 
   d_ethernet->close();
   delete d_ethernet;
+
+  d_thread->stop();
+  d_thread = 0; // pthread derived objects delete themselves
 }
 
 // ------------------------------------------------------------------------
@@ -395,9 +412,7 @@
   if (d_ethernet->write_packet(c, len) != len)
     return false;
 
-  d_rx_started = true;
-  d_thread = new usrp2_basic_thread(this);
-  d_thread->start();
+  d_rx_active = true;
   return true;
 }
 
@@ -421,10 +436,7 @@
   if (d_ethernet->write_packet(c, len) != len)
     return false;
 
-  d_thread->stop();
-  d_rx_started = false;
-
-  d_thread = 0; // pthread derived objects delete themselves
+  d_rx_active = false;
   return true;
 }
 
@@ -825,15 +837,15 @@
   return memcmp(&a, &b, sizeof(u2_mac_addr_t)) == 0;
 }
 
-void usrp2_basic::loop()
+void usrp2_basic::loop_body()
 {
   fd_set read_fds, write_fds;
   FD_ZERO(&read_fds);
   FD_ZERO(&write_fds);
 
-  if (d_rx_started)
-    FD_SET(d_ethernet->fd(), &read_fds);
-  if (d_tx_started)
+  FD_SET(d_ethernet->fd(), &read_fds);
+
+  if (d_tx_active)
     FD_SET(d_ethernet->fd(), &write_fds);
     
   struct timeval timeout;
@@ -875,6 +887,7 @@
   int len;
   while (1) {
     len = d_ethernet->read_packet_dont_block(pktbuf, sizeof(pktbuf));
+
     if (len < 0) {
       DEBUG_LOG("!"); // error
       return;
@@ -895,6 +908,9 @@
       continue;
     }    
 
+    if (!d_rx_active)
+      continue;
+
     u2_eth_samples_t *s = (u2_eth_samples_t *)pktbuf;
     size_t plen = (len-sizeof(s->hdrs))/sizeof(uint32_t);
     if (d_rx_samples.space_available() < plen) {
@@ -902,7 +918,7 @@
       return;
     }
 
-    d_rx_samples.write(plen, (uint32_t *)(&s->samples[0]), 0);
+    d_rx_samples.write(plen, &s->samples[0], 0);
   }   
 }
 

Modified: usrp2/trunk/host/lib/usrp2_basic.h
===================================================================
--- usrp2/trunk/host/lib/usrp2_basic.h  2008-05-26 04:34:43 UTC (rev 8506)
+++ usrp2/trunk/host/lib/usrp2_basic.h  2008-05-26 05:37:03 UTC (rev 8507)
@@ -49,8 +49,8 @@
   int           d_next_rid;
   u2_mac_addr_t  d_addr;
   int            d_rx_decim;
-  bool           d_rx_started;
-  bool           d_tx_started;
+  bool           d_rx_active;
+  bool           d_tx_active;
   
   usrp2_basic_thread *d_thread;
   sample_buffer   d_rx_samples;
@@ -62,7 +62,7 @@
                     const u2_mac_addr_t &dst,
                     int word0_flags, int chan, uint32_t timestamp);
 
-  void loop();
+  void loop_body();
   void rx_frames();
   void tx_frames();
   

Modified: usrp2/trunk/host/lib/usrp2_basic_thread.cc
===================================================================
--- usrp2/trunk/host/lib/usrp2_basic_thread.cc  2008-05-26 04:34:43 UTC (rev 
8506)
+++ usrp2/trunk/host/lib/usrp2_basic_thread.cc  2008-05-26 05:37:03 UTC (rev 
8507)
@@ -25,6 +25,7 @@
 #endif
 
 #include <usrp2_basic_thread.h>
+#include <gr_realtime.h>
 
 #define USRP2_BASIC_THREAD_DEBUG 0
 
@@ -60,9 +61,14 @@
 void *
 usrp2_basic_thread::run_undetached(void *arg)
 {
+  // FIXME hoist this from gnuradio-core into another library.
+  gr_rt_status_t rt = gr_enable_realtime_scheduling();
+  if (rt != RT_OK)
+    std::cerr << "failed to enable realtime scheduling\n";
+
   // This is the first code to run in the new thread context.
   while(d_keep_running)
-    d_u2->loop();
+    d_u2->loop_body();
 
   return 0;
 }





reply via email to

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