commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: jcorgan
Subject: [Commit-gnuradio] r8566 - in usrp2/trunk/host-ng: apps lib
Date: Mon, 9 Jun 2008 17:19:25 -0600 (MDT)

Author: jcorgan
Date: 2008-06-09 17:19:25 -0600 (Mon, 09 Jun 2008)
New Revision: 8566

Modified:
   usrp2/trunk/host-ng/apps/test.sh
   usrp2/trunk/host-ng/apps/test_eth.cc
   usrp2/trunk/host-ng/lib/eth_buffer.cc
   usrp2/trunk/host-ng/lib/eth_buffer.h
Log:
work-in-progress

Modified: usrp2/trunk/host-ng/apps/test.sh
===================================================================
--- usrp2/trunk/host-ng/apps/test.sh    2008-06-09 17:52:11 UTC (rev 8565)
+++ usrp2/trunk/host-ng/apps/test.sh    2008-06-09 23:19:25 UTC (rev 8566)
@@ -1,5 +1,5 @@
 #!/bin/sh
 
-sudo ./test_eth 2>cerr
+sudo ./test_eth
 
 

Modified: usrp2/trunk/host-ng/apps/test_eth.cc
===================================================================
--- usrp2/trunk/host-ng/apps/test_eth.cc        2008-06-09 17:52:11 UTC (rev 
8565)
+++ usrp2/trunk/host-ng/apps/test_eth.cc        2008-06-09 23:19:25 UTC (rev 
8566)
@@ -22,6 +22,7 @@
 
 #include <../lib/eth_buffer.h>
 #include <gr_realtime.h>
+#include <linux/if_ether.h>
 #include <iostream>
 
 int
@@ -32,7 +33,17 @@
     std::cerr << "Failed to enable realtime scheduling" << std::endl;
 
   usrp2::eth_buffer buf;
-  bool ok = buf.open("eth1", 0x0800);
-
-  return ok ? 0 : 1;
+  if (!buf.open("eth1", 0)) {
+    std::cerr << "Failed to open eth_buffer." << std::endl;;
+    return 1;
+  }
+  
+  int res;    
+  do {
+    res = buf.rx_frames(NULL, 0);
+  }
+  while (res != -1);
+    
+  std::cerr << std::endl;
+  return 0;
 }

Modified: usrp2/trunk/host-ng/lib/eth_buffer.cc
===================================================================
--- usrp2/trunk/host-ng/lib/eth_buffer.cc       2008-06-09 17:52:11 UTC (rev 
8565)
+++ usrp2/trunk/host-ng/lib/eth_buffer.cc       2008-06-09 23:19:25 UTC (rev 
8566)
@@ -28,11 +28,17 @@
 #include <linux/if_packet.h>
 #include <sys/socket.h>
 #include <sys/mman.h>
+#include <sys/poll.h>
 #include <iostream>
 #include <cmath>
 #include <errno.h>
 
 #define ETH_BUFFER_DEBUG      1 // define to 0 or 1
+#if ETH_BUFFER_DEBUG
+#define DEBUG_LOG(x) ::write(2, (x), 1)
+#else
+#define DEBUG_LOG(X)
+#endif
 
 #define MAX_MEM_SIZE       25e6 // ~0.25s @ 100 MB/s
 #define MAX_SLAB_SIZE    131702 // 128 KB (FIXME fish out of /proc/slabinfo)
@@ -71,7 +77,8 @@
     d_ethernet->close();
   }
   
-  bool eth_buffer::open(const std::string &ifname, int protocol)
+  bool 
+  eth_buffer::open(const std::string &ifname, int protocol)
   {
     if (ETH_BUFFER_DEBUG)
       std::cerr << "eth_buffer: using interface " << ifname
@@ -154,5 +161,59 @@
     return true;
   }
 
+  inline bool
+  eth_buffer::frame_available()
+  {
+    return (((tpacket_hdr *)d_ring[d_head])->tp_status != TP_STATUS_KERNEL);
+  }
+  
+  int 
+  eth_buffer::rx_frames(handler *f, int flags)
+  {
+    if (ETH_BUFFER_DEBUG)
+      DEBUG_LOG("'");
+      
+    while (!frame_available()) {
+      if (flags & EF_DONTWAIT) {
+        DEBUG_LOG("w");
+        return 0; // would block
+      }
+      
+      struct pollfd pfd;
+      pfd.fd = d_fd;
+      pfd.revents = 0;
+      pfd.events = POLLIN;
+
+      DEBUG_LOG("P");
+
+      int pres = poll(&pfd, 1, -1); // no timeout
+      if (pres < 1) {
+        DEBUG_LOG("E");
+        return -1;
+      }
+      
+      if (pres == 0) {
+        DEBUG_LOG("T");
+       continue;
+      }
+    }
+
+    DEBUG_LOG("r");
+
+    // Iterate through available packets
+    while (frame_available()) {
+      if (ETH_BUFFER_DEBUG)
+       DEBUG_LOG("R");
+      
+      // Do stuff with it
+
+      ((tpacket_hdr *)d_ring[d_head])->tp_status = TP_STATUS_KERNEL; // mark 
it done
+      if (++d_head == d_frame_nr)
+       d_head = 0;
+    }
+
+    return 1;
+  }
+  
 } // namespace usrp2
 

Modified: usrp2/trunk/host-ng/lib/eth_buffer.h
===================================================================
--- usrp2/trunk/host-ng/lib/eth_buffer.h        2008-06-09 17:52:11 UTC (rev 
8565)
+++ usrp2/trunk/host-ng/lib/eth_buffer.h        2008-06-09 23:19:25 UTC (rev 
8566)
@@ -52,6 +52,8 @@
     std::vector<uint8_t *>  d_ring;     // pointers into buffer
     std::auto_ptr<ethernet> d_ethernet; // our underlying interface
 
+    bool frame_available();
+
   public:
 
     // 
----------------------------------------------------------------------------





reply via email to

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