[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8588 - in usrp2/trunk/host-ng: apps lib
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r8588 - in usrp2/trunk/host-ng: apps lib |
Date: |
Fri, 13 Jun 2008 08:34:44 -0600 (MDT) |
Author: jcorgan
Date: 2008-06-13 08:34:42 -0600 (Fri, 13 Jun 2008)
New Revision: 8588
Removed:
usrp2/trunk/host-ng/apps/test_eth.cc
Modified:
usrp2/trunk/host-ng/apps/Makefile.am
usrp2/trunk/host-ng/apps/test.sh
usrp2/trunk/host-ng/lib/Makefile.am
usrp2/trunk/host-ng/lib/eth_buffer.cc
usrp2/trunk/host-ng/lib/eth_buffer.h
usrp2/trunk/host-ng/lib/usrp2.cc
Log:
work-in-progress, usrp2 class now using kernel packet ring
Modified: usrp2/trunk/host-ng/apps/Makefile.am
===================================================================
--- usrp2/trunk/host-ng/apps/Makefile.am 2008-06-12 23:33:50 UTC (rev
8587)
+++ usrp2/trunk/host-ng/apps/Makefile.am 2008-06-13 14:34:42 UTC (rev
8588)
@@ -24,14 +24,8 @@
$(GNURADIO_CORE_LIBS)
noinst_PROGRAMS = \
- test_usrp2 \
- test_eth
+ test_usrp2
test_usrp2_SOURCES = \
test_usrp2.cc
-test_eth_SOURCES = \
- test_eth.cc
-
-TESTS = \
- test_eth
Modified: usrp2/trunk/host-ng/apps/test.sh
===================================================================
--- usrp2/trunk/host-ng/apps/test.sh 2008-06-12 23:33:50 UTC (rev 8587)
+++ usrp2/trunk/host-ng/apps/test.sh 2008-06-13 14:34:42 UTC (rev 8588)
@@ -1,5 +1,5 @@
#!/bin/sh
-sudo ./test_eth
+sudo ./test_usrp2 2>cerr
Deleted: usrp2/trunk/host-ng/apps/test_eth.cc
Modified: usrp2/trunk/host-ng/lib/Makefile.am
===================================================================
--- usrp2/trunk/host-ng/lib/Makefile.am 2008-06-12 23:33:50 UTC (rev 8587)
+++ usrp2/trunk/host-ng/lib/Makefile.am 2008-06-13 14:34:42 UTC (rev 8588)
@@ -36,6 +36,7 @@
# Private headers not needed for above the API development
noinst_HEADERS = \
eth_buffer.h \
+ eth_common.h \
ethernet.h \
pktfilter.h \
usrp2_thread.h
Modified: usrp2/trunk/host-ng/lib/eth_buffer.cc
===================================================================
--- usrp2/trunk/host-ng/lib/eth_buffer.cc 2008-06-12 23:33:50 UTC (rev
8587)
+++ usrp2/trunk/host-ng/lib/eth_buffer.cc 2008-06-13 14:34:42 UTC (rev
8588)
@@ -34,7 +34,7 @@
#include <cmath>
#include <errno.h>
-#define ETH_BUFFER_DEBUG 0 // define to 0 or 1
+#define ETH_BUFFER_DEBUG 1 // define to 0 or 1
#if ETH_BUFFER_DEBUG
#define DEBUG_LOG(x) ::write(2, (x), 1)
#else
@@ -71,11 +71,8 @@
{
if (ETH_BUFFER_DEBUG)
std::cerr << "eth_buffer: destructor" << std::endl;
-
- if (!d_using_tpring && d_buf)
- free(d_buf);
-
- d_ethernet->close();
+
+ close();
}
bool
@@ -162,6 +159,23 @@
return true;
}
+ bool
+ eth_buffer::close()
+ {
+ // if we have background thread, stop it here
+
+ if (!d_using_tpring && d_buf)
+ free(d_buf);
+
+ return d_ethernet->close();
+ }
+
+ bool
+ eth_buffer::attach_pktfilter(pktfilter *pf)
+ {
+ return d_ethernet->attach_pktfilter(pf);
+ }
+
inline bool
eth_buffer::frame_available()
{
@@ -211,8 +225,7 @@
// Invoke data handler
unsigned int r = 0;
- if (f)
- r = (*f)(base, len);
+ r = (*f)(base, len);
// data_handler::KEEP not yet implemented
hdr->tp_status = TP_STATUS_KERNEL; // mark it free
@@ -225,6 +238,18 @@
return 1;
}
+
+ int
+ eth_buffer::tx_frame(const void *base, size_t len, int flags)
+ {
+ // TODO: implement flags
+ int res = d_ethernet->write_packet(base, len);
+
+ if (res < 0 || (unsigned int)res != len)
+ return -1;
+
+ return 1;
+ }
} // namespace usrp2
Modified: usrp2/trunk/host-ng/lib/eth_buffer.h
===================================================================
--- usrp2/trunk/host-ng/lib/eth_buffer.h 2008-06-12 23:33:50 UTC (rev
8587)
+++ usrp2/trunk/host-ng/lib/eth_buffer.h 2008-06-13 14:34:42 UTC (rev
8588)
@@ -40,7 +40,8 @@
*
* \internal
*/
- class eth_buffer : boost::noncopyable {
+ class eth_buffer : boost::noncopyable
+ {
int d_fd; // socket file descriptor
uint8_t d_mac[6]; // our mac address
@@ -52,11 +53,14 @@
std::vector<uint8_t *> d_ring; // pointers into buffer
std::auto_ptr<ethernet> d_ethernet; // our underlying interface
-
+
bool frame_available();
public:
+ static const unsigned int MAX_PKTLEN = 1512;
+ static const unsigned int MIN_PKTLEN = 64;
+
/*!
* \param rx_bufsize is a hint as to the number of bytes of memory
* to allocate for received ethernet frames (0 -> reasonable default)
@@ -89,7 +93,6 @@
*/
const uint8_t *mac() const { return d_mac; }
-
/*!
* \brief Call \p f for each frame in the receive buffer.
* \param f is the frame data handler
Modified: usrp2/trunk/host-ng/lib/usrp2.cc
===================================================================
--- usrp2/trunk/host-ng/lib/usrp2.cc 2008-06-12 23:33:50 UTC (rev 8587)
+++ usrp2/trunk/host-ng/lib/usrp2.cc 2008-06-13 14:34:42 UTC (rev 8588)
@@ -21,9 +21,10 @@
#endif
#include <usrp2/usrp2.h>
+#include <usrp2/data_handler.h>
#include <usrp2_eth_packet.h>
#include <usrp2_types.h>
-#include "ethernet.h"
+#include "eth_buffer.h"
#include "pktfilter.h"
#include "usrp2_thread.h"
@@ -32,7 +33,7 @@
#include <netinet/in.h>
#include <errno.h>
-#define USRP2_DEBUG 0
+#define USRP2_DEBUG 1
#if USRP2_DEBUG
#define DEBUG_LOG(x) ::write(2, x, 1)
@@ -44,15 +45,14 @@
// --- Private implementation class -------------------------------------
-class usrp2::impl
+class usrp2::impl : data_handler
{
- ethernet *d_ethernet;
+ eth_buffer *d_buffer;
pktfilter *d_pf;
std::string d_addr;
usrp2_thread *d_bg_thread;
volatile bool d_bg_running; // TODO: multistate if needed
- bool d_tx_active;
int d_rx_decim;
int d_rx_seqno;
int d_tx_seqno;
@@ -71,14 +71,14 @@
int word0_flags, int chan, uint32_t timestamp);
void bg_loop();
void stop_bg();
- void rx_frames();
- void tx_frames();
bool set_rx_gain(double gain);
bool set_rx_freq(double frequency, usrp2_tune_result *result);
bool set_rx_decim(int decimation_factor);
bool set_rx_scale_iq(int scale_i, int scale_q);
bool start_rx_streaming(unsigned int items_per_frame);
bool stop_rx_streaming();
+
+ virtual unsigned int operator()(const void *base, unsigned int len);
};
// ----------------------------------------------------------------------
@@ -144,7 +144,7 @@
// ----------------------------------------------------------------------
usrp2::impl::impl(const std::string &ifc, const std::string &addr)
- : d_ethernet(new ethernet()), d_pf(0), d_bg_thread(0), d_bg_running(false),
+ : d_buffer(new eth_buffer()), d_pf(0), d_bg_thread(0), d_bg_running(false),
d_rx_decim(0), d_rx_seqno(-1), d_tx_seqno(0), d_next_rid(0),
d_num_rx_frames(0), d_num_rx_lost(0), d_num_rx_bytes(0)
{
@@ -152,11 +152,11 @@
if (u2s.size() != 1)
throw std::runtime_error("Unable to find requested USRP2.");
- if (!d_ethernet->open(ifc, htons(U2_ETHERTYPE)))
+ if (!d_buffer->open(ifc, htons(U2_ETHERTYPE)))
throw std::runtime_error("Unable to register USRP2 protocol");
- d_pf = pktfilter::make_ethertype_inbound(U2_ETHERTYPE, d_ethernet->mac());
- if (!d_pf || !d_ethernet->attach_pktfilter(d_pf))
+ d_pf = pktfilter::make_ethertype_inbound(U2_ETHERTYPE, d_buffer->mac());
+ if (!d_pf || !d_buffer->attach_pktfilter(d_pf))
throw std::runtime_error("Unable to attach packet filter.");
d_addr = u2s[0].addr;
@@ -174,8 +174,8 @@
stop_bg();
d_bg_thread = 0; // thread class deletes itself
delete d_pf;
- d_ethernet->close();
- delete d_ethernet;
+ d_buffer->close();
+ delete d_buffer;
if (USRP2_DEBUG) {
std::cerr << "usrp2 destructor: received " << d_num_rx_frames
@@ -217,7 +217,7 @@
{
p->ehdr.ethertype = htons(U2_ETHERTYPE);
parse_mac_addr(dst, &p->ehdr.dst);
- memcpy(&p->ehdr.src, d_ethernet->mac(), 6);
+ memcpy(&p->ehdr.src, d_buffer->mac(), 6);
p->thdr.flags = 0; // FIXME transport header values?
p->thdr.seqno = d_tx_seqno++;
p->thdr.ack = 0;
@@ -243,7 +243,7 @@
if (USRP2_DEBUG)
std::cerr << "usrp2: setting receive gain to " << gain << std::endl;
- uint8_t pktbuf[ethernet::MAX_PKTLEN];
+ uint8_t pktbuf[eth_buffer::MAX_PKTLEN];
memset(pktbuf, 0, sizeof(pktbuf));
struct command {
@@ -265,8 +265,8 @@
c->eop.opcode = OP_EOP;
c->eop.len = sizeof(op_eop_t);
- int len = std::max((size_t) ethernet::MIN_PKTLEN, sizeof(command));
- if (d_ethernet->write_packet(c, len) != len)
+ int len = std::max((size_t) eth_buffer::MIN_PKTLEN, sizeof(command));
+ if (d_buffer->tx_frame(c, len) != len)
return false;
// FIXME wait for corresponding reply, etc.
@@ -280,7 +280,7 @@
if (USRP2_DEBUG)
std::cerr << "usrp2: setting frequency to " << frequency << std::endl;
- uint8_t pktbuf[ethernet::MAX_PKTLEN];
+ uint8_t pktbuf[eth_buffer::MAX_PKTLEN];
memset(pktbuf, 0, sizeof(pktbuf));
struct command {
@@ -304,8 +304,8 @@
c->eop.opcode = OP_EOP;
c->eop.len = sizeof(op_eop_t);
- int len = std::max((size_t) ethernet::MIN_PKTLEN, sizeof(command));
- if (d_ethernet->write_packet(c, len) == len) {
+ int len = std::max((size_t) eth_buffer::MIN_PKTLEN, sizeof(command));
+ if (d_buffer->tx_frame(c, len) == len) {
// FIXME: wait for corresponding reply, set tune result members
}
@@ -318,7 +318,7 @@
if (USRP2_DEBUG)
std::cerr << "usrp2: setting receive decimation rate to "
<< decimation_factor << std::endl;
- uint8_t pktbuf[ethernet::MAX_PKTLEN];
+ uint8_t pktbuf[eth_buffer::MAX_PKTLEN];
memset(pktbuf, 0, sizeof(pktbuf));
struct command {
@@ -340,8 +340,8 @@
c->eop.opcode = OP_EOP;
c->eop.len = sizeof(op_eop_t);
- int len = std::max((size_t) ethernet::MIN_PKTLEN, sizeof(command));
- if (d_ethernet->write_packet(c, len) != len)
+ int len = std::max((size_t) eth_buffer::MIN_PKTLEN, sizeof(command));
+ if (d_buffer->tx_frame(c, len) != len)
return false;
// FIXME wait for corresponding reply, etc.
@@ -357,7 +357,7 @@
std::cerr << "usrp2: setting RX IQ scaling to "
<< scale_i << ", " << scale_q << std::endl;
- uint8_t pktbuf[ethernet::MAX_PKTLEN];
+ uint8_t pktbuf[eth_buffer::MAX_PKTLEN];
memset(pktbuf, 0, sizeof(pktbuf));
struct command {
@@ -379,8 +379,8 @@
c->eop.opcode = OP_EOP;
c->eop.len = sizeof(op_eop_t);
- int len = std::max((size_t) ethernet::MIN_PKTLEN, sizeof(command));
- if (d_ethernet->write_packet(c, len) != len)
+ int len = std::max((size_t) eth_buffer::MIN_PKTLEN, sizeof(command));
+ if (d_buffer->tx_frame(c, len) != len)
return false;
// FIXME wait for corresponding reply, etc.
@@ -395,7 +395,7 @@
if (items_per_frame == 0)
items_per_frame = 250; // TODO: calculate from d_itemsize;
- uint8_t pktbuf[ethernet::MAX_PKTLEN];
+ uint8_t pktbuf[eth_buffer::MAX_PKTLEN];
memset(pktbuf, 0, sizeof(pktbuf));
struct command {
@@ -414,8 +414,8 @@
c->eop.opcode = OP_EOP;
c->eop.len = sizeof(op_eop_t);
- int len = std::max((size_t) ethernet::MIN_PKTLEN, sizeof(command));
- if (d_ethernet->write_packet(c, len) != len)
+ int len = std::max((size_t) eth_buffer::MIN_PKTLEN, sizeof(command));
+ if (d_buffer->tx_frame(c, len) != len)
return false;
return true;
@@ -424,7 +424,7 @@
bool
usrp2::impl::stop_rx_streaming()
{
- uint8_t pktbuf[ethernet::MAX_PKTLEN];
+ uint8_t pktbuf[eth_buffer::MAX_PKTLEN];
memset(pktbuf, 0, sizeof(pktbuf));
struct command {
@@ -437,8 +437,8 @@
c->op_stop_rx.opcode = OP_STOP_RX;
c->op_stop_rx.len = sizeof(op_stop_rx_t);
- int len = std::max((size_t) ethernet::MIN_PKTLEN, sizeof(command));
- if (d_ethernet->write_packet(c, len) != len)
+ int len = std::max((size_t) eth_buffer::MIN_PKTLEN, sizeof(command));
+ if (d_buffer->tx_frame(c, len) != len)
return false;
return true;
@@ -449,98 +449,39 @@
{
d_bg_running = true;
while(d_bg_running) {
-
- fd_set read_fds, write_fds;
- FD_ZERO(&read_fds);
- FD_ZERO(&write_fds);
-
- FD_SET(d_ethernet->fd(), &read_fds);
-
- if (d_tx_active)
- FD_SET(d_ethernet->fd(), &write_fds);
-
- struct timeval timeout;
- timeout.tv_sec = 0;
- timeout.tv_usec = 100 * 1000; // 100 ms
-
- DEBUG_LOG("S"); // select
- int r = select(d_ethernet->fd()+1, &read_fds, &write_fds, 0, &timeout);
- if (r > 0) { // Socket available for read or for write
- if (FD_ISSET(d_ethernet->fd(), &read_fds)) {
- DEBUG_LOG("r"); // data to read()
- rx_frames();
- }
-
- if (FD_ISSET(d_ethernet->fd(), &write_fds)) {
- DEBUG_LOG("w"); // can write()
- tx_frames();
- }
- }
- else if (r == 0) {
- DEBUG_LOG("T"); // socket timeout
- return;
- }
- else {
- if (errno == EINTR)
- DEBUG_LOG("I"); // interrupted system call
- else
- DEBUG_LOG("!"); // error on socket
- return;
- }
+ int res = d_buffer->rx_frames(this, 1000);
+ if (res == -1)
+ break;
}
}
-void
-usrp2::impl::rx_frames()
+unsigned int
+usrp2::impl::operator()(const void *base, unsigned int len)
{
- u2_eth_samples_t pkt;
-
- int len;
- while (1) {
- len = d_ethernet->read_packet_dont_block(&pkt, sizeof(pkt));
-
- if (len < 0) {
- DEBUG_LOG("!"); // error
- return;
- }
- else if (len == 0) {
- DEBUG_LOG("|"); // no more frames this select
- return;
- }
- else if ((size_t)len < sizeof(u2_eth_packet_t)) {
- DEBUG_LOG("<"); // short packet
- }
- else {
- DEBUG_LOG("R"); // read ok
- }
+ u2_eth_samples_t *pkt = (u2_eth_samples_t *)base;
- d_num_rx_frames += 1;
- d_num_rx_bytes += len;
+ d_num_rx_frames++;
+ d_num_rx_bytes += len;
- if (d_rx_seqno != -1) {
- int expected_seqno = (d_rx_seqno + 1) & 0xFF;
- int seqno = pkt.hdrs.thdr.seqno;
+ if (d_rx_seqno != -1) {
+ int expected_seqno = (d_rx_seqno + 1) & 0xFF;
+ int seqno = pkt->hdrs.thdr.seqno;
- if (seqno != expected_seqno) {
- ::write(2, "uS", 2); // missing sequence number
- int missing = expected_seqno - seqno;
- if (missing < 0)
- missing += 256;
-
- d_num_rx_lost += missing;
- }
+ if (seqno != expected_seqno) {
+ ::write(2, "uS", 2); // missing sequence number
+ int missing = expected_seqno - seqno;
+ if (missing < 0)
+ missing += 256;
+
+ d_num_rx_lost += missing;
}
-
- d_rx_seqno = pkt.hdrs.thdr.seqno;
}
+
+ d_rx_seqno = pkt->hdrs.thdr.seqno;
+ return 0;
}
void
-usrp2::impl::tx_frames()
-{
-}
-
-void
usrp2::impl::stop_bg()
{
if (USRP2_DEBUG)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8588 - in usrp2/trunk/host-ng: apps lib,
jcorgan <=