commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: jcorgan
Subject: [Commit-gnuradio] r8565 - in usrp2/trunk/host-ng: apps lib
Date: Mon, 9 Jun 2008 11:52:16 -0600 (MDT)

Author: jcorgan
Date: 2008-06-09 11:52:11 -0600 (Mon, 09 Jun 2008)
New Revision: 8565

Modified:
   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_eth.cc
===================================================================
--- usrp2/trunk/host-ng/apps/test_eth.cc        2008-06-07 23:46:50 UTC (rev 
8564)
+++ usrp2/trunk/host-ng/apps/test_eth.cc        2008-06-09 17:52:11 UTC (rev 
8565)
@@ -32,7 +32,7 @@
     std::cerr << "Failed to enable realtime scheduling" << std::endl;
 
   usrp2::eth_buffer buf;
-  bool ok = buf.open("eth0", 0xBEEF);
+  bool ok = buf.open("eth1", 0x0800);
 
   return ok ? 0 : 1;
 }

Modified: usrp2/trunk/host-ng/lib/eth_buffer.cc
===================================================================
--- usrp2/trunk/host-ng/lib/eth_buffer.cc       2008-06-07 23:46:50 UTC (rev 
8564)
+++ usrp2/trunk/host-ng/lib/eth_buffer.cc       2008-06-09 17:52:11 UTC (rev 
8565)
@@ -46,8 +46,8 @@
   }
   
   eth_buffer::eth_buffer(size_t rx_bufsize)
-    : d_fd(0), d_buf(0),
-      d_ethernet(new ethernet())
+    : d_fd(0), d_using_tpring(false), d_buflen(0), d_buf(0), d_frame_nr(0),
+      d_head(0), d_ring(0), d_ethernet(new ethernet())
   {
     if (ETH_BUFFER_DEBUG)
       std::cerr << "eth_buffer: constructor" << std::endl;
@@ -96,18 +96,17 @@
     int npages = (page_size > req.tp_frame_size) ? 1 : 
ceil(req.tp_frame_size/page_size);
     req.tp_block_size = page_size << (int)ceil(log2(npages));
 
-    // Calculate maximum number of blocks kernel can handle
-    int max_blocks = MAX_SLAB_SIZE/sizeof(void *);
-
-    // Calculate actual number of blocks
+    // Calculate number of blocks
     req.tp_block_nr = std::min((int)(MAX_SLAB_SIZE/sizeof(void*)),
                               (int)(d_buflen/req.tp_block_size));
 
     // Recalculate buffer length
     d_buflen = req.tp_block_nr*req.tp_block_size;
 
-    // Finally, calculate total number of frames
+    // Finally, calculate total number of frames.  Since frames, blocks,
+    // and pages are all power-of-two aligned, frames are contiguous
     req.tp_frame_nr = d_buflen/req.tp_frame_size;
+    d_frame_nr = req.tp_frame_nr;
 
     if (ETH_BUFFER_DEBUG)
       std::cerr << "eth_buffer:" 
@@ -142,6 +141,16 @@
         std::cerr << "eth_buffer: using kernel shared mem for buffer" << 
std::endl;
     }
 
+    // Initialize packet ring
+    d_ring = std::vector<uint8_t *>(req.tp_frame_nr);
+    for (unsigned int i=0; i < req.tp_frame_nr; i++) {
+      d_ring[i] = (uint8_t *)(d_buf+i*req.tp_frame_size);
+      ((tpacket_hdr *)(d_ring[i]))->tp_status = TP_STATUS_KERNEL; // free
+      ((tpacket_hdr *)(d_ring[i]))->tp_len = req.tp_frame_size;
+    }
+
+    // If not using kernel ring, instantiate select/read thread here
+
     return true;
   }
 

Modified: usrp2/trunk/host-ng/lib/eth_buffer.h
===================================================================
--- usrp2/trunk/host-ng/lib/eth_buffer.h        2008-06-07 23:46:50 UTC (rev 
8564)
+++ usrp2/trunk/host-ng/lib/eth_buffer.h        2008-06-09 17:52:11 UTC (rev 
8565)
@@ -21,10 +21,11 @@
 #ifndef INCLUDED_USRP2_ETH_BUFFER_H
 #define INCLUDED_USRP2_ETH_BUFFER_H
 
+#include "pktfilter.h"
+#include "eth_common.h"
 #include <boost/utility.hpp>
+#include <vector>
 #include <stdint.h>
-#include "pktfilter.h"
-#include "eth_common.h"
 
 namespace usrp2 {
 
@@ -40,12 +41,15 @@
    */
   class eth_buffer : boost::noncopyable {
     
-    int                d_fd;                   // socket file descriptor
-    uint8_t    d_mac[6];               // our mac address
-    bool        d_using_tpring;         // using kernel mapped packet ring
-    size_t      d_buflen;               // length of our buffer
-    uint8_t    *d_buf;                  // packet ring
-    
+    int                  d_fd;                 // socket file descriptor
+    uint8_t      d_mac[6];             // our mac address
+    bool          d_using_tpring;       // using kernel mapped packet ring
+    size_t        d_buflen;             // length of our buffer
+    uint8_t      *d_buf;                // packet ring
+    unsigned int  d_frame_nr;           // max frames on ring
+    unsigned int  d_head;               // pointer to next frame
+
+    std::vector<uint8_t *>  d_ring;     // pointers into buffer
     std::auto_ptr<ethernet> d_ethernet; // our underlying interface
 
   public:





reply via email to

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