[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8476 - usrp2/branches/developers/jcorgan/u2/host/lib
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r8476 - usrp2/branches/developers/jcorgan/u2/host/lib |
Date: |
Wed, 21 May 2008 15:12:30 -0600 (MDT) |
Author: jcorgan
Date: 2008-05-21 15:12:11 -0600 (Wed, 21 May 2008)
New Revision: 8476
Modified:
usrp2/branches/developers/jcorgan/u2/host/lib/ring_buffer.h
usrp2/branches/developers/jcorgan/u2/host/lib/sample_buffer.cc
usrp2/branches/developers/jcorgan/u2/host/lib/sample_buffer.h
usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h
usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic_thread.cc
Log:
Wip. usrp2_basic network thread sucessfully receiving packets.
Modified: usrp2/branches/developers/jcorgan/u2/host/lib/ring_buffer.h
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/ring_buffer.h 2008-05-21
20:23:23 UTC (rev 8475)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/ring_buffer.h 2008-05-21
21:12:11 UTC (rev 8476)
@@ -34,7 +34,8 @@
size_t space_available() const;
size_t items_available() const;
-
+ size_t size() const { return d_size; }
+
void write(size_t nitems, const T *items);
void read(size_t nitems, T *items);
@@ -48,7 +49,7 @@
template<class T>
ring_buffer<T>::ring_buffer(size_t nitems)
- : d_size((int)pow(2, ceil(log2((double)nitems + 1)))),
+ : d_size(pow(2, ceil(log2(nitems+1)))),
d_read_index(0),
d_write_index(0),
d_items(d_size)
Modified: usrp2/branches/developers/jcorgan/u2/host/lib/sample_buffer.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/sample_buffer.cc
2008-05-21 20:23:23 UTC (rev 8475)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/sample_buffer.cc
2008-05-21 21:12:11 UTC (rev 8476)
@@ -23,24 +23,26 @@
#include "sample_buffer.h"
#include <cstdio>
-#define SAMPLE_BUFFER_DEBUG 1
+#define SAMPLE_BUFFER_DEBUG 0
sample_buffer::sample_buffer(size_t nsamples, size_t ndescs)
- : d_samples(nsamples), d_descs(ndescs),
- d_not_empty(&d_mutex), d_not_full(&d_mutex)
+ : d_samples(nsamples),
+ d_descs(ndescs),
+ d_not_empty(&d_mutex),
+ d_not_full(&d_mutex)
{
}
void
-write(size_t nsamples, const uint32_t *samples, uint32_t flags)
+sample_buffer::write(size_t nsamples, const uint32_t *samples, uint32_t flags)
{
if (SAMPLE_BUFFER_DEBUG)
- printf("sample_buffer::write(%li, %0X, %08X)", nsamples, samples, flags);
+ printf("sample_buffer::write(%li, %0X, %08X)\n", nsamples, samples, flags);
}
size_t
-read(uint32_t *samples, size_t nmax, uint32_t *flags)
+sample_buffer::read(uint32_t *samples, size_t nmax, uint32_t *flags)
{
if (SAMPLE_BUFFER_DEBUG)
- printf("sample_buffer::read(%0X, %li, %08X)", samples, nmax, flags);
+ printf("sample_buffer::read(%0X, %li, %08X)\n", samples, nmax, flags);
}
Modified: usrp2/branches/developers/jcorgan/u2/host/lib/sample_buffer.h
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/sample_buffer.h
2008-05-21 20:23:23 UTC (rev 8475)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/sample_buffer.h
2008-05-21 21:12:11 UTC (rev 8476)
@@ -66,14 +66,19 @@
/*!
* Returns true if there are no samples available for reading.
*/
- bool is_empty_p() { return d_descs.items_available() == 0; }
+ bool is_empty_p() const { return d_descs.items_available() == 0; }
/*!
* Returns true if there is either no space available for samples OR there
* is no space available for enqueuing descriptors.
*/
- bool is_full_p() { return d_descs.space_available() == 0 |
- d_samples.space_available() == 0; }
+ bool is_full_p() const { return d_descs.space_available() == 0 |
+ d_samples.space_available() == 0; }
+
+ /*!
+ * Returns sample space available if not full.
+ */
+ size_t space_available() const { return is_full_p() ? 0 :
d_samples.space_available(); }
}
sample_buffer_t;
Modified: usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
2008-05-21 20:23:23 UTC (rev 8475)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
2008-05-21 21:12:11 UTC (rev 8476)
@@ -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
@@ -25,10 +25,12 @@
#include "gri_ethernet_pfring.h" // FIXME
#include "gri_pktfilter.h"
#include <usrp2_types.h>
+#include <usrp2_eth_packet.h>
#include <iostream>
#include <stdexcept>
#include <math.h>
-#include <time.h> // debug
+#include <time.h>
+#include <errno.h>
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
@@ -67,7 +69,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_thread(0), d_rx_samples(65535, 255), d_tx_samples(65535, 255)
+ d_rx_started(false), d_tx_started(false), d_thread(0),
+ d_rx_samples(65535, 255), d_tx_samples(65535, 255)
{
if (USRP2_BASIC_DEBUG)
std::cout << "usrp2_basic: constructor" << std::endl;
@@ -402,6 +405,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();
return true;
@@ -428,8 +432,9 @@
return false;
d_thread->stop();
+ d_rx_started = false;
+
d_thread = 0; // pthread derived objects delete themselves
-
return true;
}
@@ -832,7 +837,87 @@
void usrp2_basic::loop()
{
- ::write(1, "B", 1);
- struct timespec ts = { (__time_t)0.01, 0 };
- nanosleep(&ts, NULL);
+ 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(), &write_fds);
+
+ struct timeval timeout;
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 100 * 1000; // 100 ms
+
+ ::write(1, "S", 1); // 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)) {
+ ::write(1, "r", 1); // data to read()
+ rx_frames();
+ }
+
+ if (FD_ISSET(d_ethernet->fd(), &write_fds)) {
+ ::write(1, "r", 1); // data to write()
+ tx_frames();
+ }
+ }
+ else if (r == 0) {
+ ::write(1, "T", 1); // socket timeout
+ return;
+ }
+ else {
+ if (errno == EINTR)
+ ::write(1, "I", 1); // interrupted system call
+ else
+ ::write(1, "!", 1); // error on socket
+ return;
+ }
}
+
+void
+usrp2_basic::rx_frames()
+{
+ uint8_t pktbuf[MAX_PKTLEN];
+ memset(pktbuf, 0, sizeof(pktbuf));
+
+ int len;
+ while (1) {
+ len = d_ethernet->read_packet_dont_block(pktbuf, sizeof(pktbuf));
+ if (len < 0) {
+ ::write(1, "!", 1); // error
+ return;
+ }
+ else if (len == 0) {
+ ::write(1, "Z", 1); // no more frames
+ return;
+ }
+ else if ((size_t)len < sizeof(u2_eth_packet_t)) {
+ ::write(1, "<", 1); // short frame
+ }
+ else
+ ::write(1, "R", 1); // rx ok
+
+ u2_eth_packet_t *p = (u2_eth_packet_t *)pktbuf;
+ if (u2p_chan(&p->fixed) == CONTROL_CHAN) {
+ ::write(1, "-", 1); // ignore (FIXME: multiple channels, control channel)
+ 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) {
+ ::write(1, "uO", 2); // overrun
+ return;
+ }
+
+ d_rx_samples.write(plen, (uint32_t *)(&s->samples[0]), 0);
+ }
+}
+
+void
+usrp2_basic::tx_frames()
+{
+}
+
Modified: usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h 2008-05-21
20:23:23 UTC (rev 8475)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h 2008-05-21
21:12:11 UTC (rev 8476)
@@ -52,6 +52,9 @@
int d_next_rid;
u2_mac_addr_t d_addr;
int d_rx_decim;
+ bool d_rx_started;
+ bool d_tx_started;
+
usrp2_basic_thread *d_thread;
sample_buffer_t d_rx_samples;
sample_buffer_t d_tx_samples;
@@ -63,7 +66,9 @@
int word0_flags, int chan, uint32_t timestamp);
void loop();
-
+ void rx_frames();
+ void tx_frames();
+
public:
// ---- Static methods ----
Modified: usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic_thread.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic_thread.cc
2008-05-21 20:23:23 UTC (rev 8475)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic_thread.cc
2008-05-21 21:12:11 UTC (rev 8476)
@@ -70,10 +70,11 @@
void
usrp2_basic_thread::stop()
{
- if (0 && USRP2_BASIC_THREAD_DEBUG) // FIXME not safe to call from
signal handler
+ if (USRP2_BASIC_THREAD_DEBUG)
std::cout << "usrp2_basic_thread::stop() "
<< this << std::endl;
d_keep_running = false;
+
void *dummy_status;
join(&dummy_status);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8476 - usrp2/branches/developers/jcorgan/u2/host/lib,
jcorgan <=