[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r9019 - in usrp2/branches/features/host-ng/host-ng: in
From: |
eb |
Subject: |
[Commit-gnuradio] r9019 - in usrp2/branches/features/host-ng/host-ng: include/usrp2 lib |
Date: |
Fri, 25 Jul 2008 16:09:44 -0600 (MDT) |
Author: eb
Date: 2008-07-25 16:09:43 -0600 (Fri, 25 Jul 2008)
New Revision: 9019
Modified:
usrp2/branches/features/host-ng/host-ng/include/usrp2/data_handler.h
usrp2/branches/features/host-ng/host-ng/lib/ring.h
usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc
usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.h
Log:
usrp2 work-in-progress
Modified: usrp2/branches/features/host-ng/host-ng/include/usrp2/data_handler.h
===================================================================
--- usrp2/branches/features/host-ng/host-ng/include/usrp2/data_handler.h
2008-07-25 22:07:36 UTC (rev 9018)
+++ usrp2/branches/features/host-ng/host-ng/include/usrp2/data_handler.h
2008-07-25 22:09:43 UTC (rev 9019)
@@ -34,8 +34,9 @@
public:
enum result_bits {
- DONE = 0x0001, //< do not call this object again
- KEEP = 0x0002, //< do not discard data
+ RELEASE = 0x0000, //< OK to release data (opposite of KEEP)
+ KEEP = 0x0001, //< do not discard data
+ DONE = 0x0002, //< do not call this object again
};
typedef int result; //< bitmask of result_bits
Modified: usrp2/branches/features/host-ng/host-ng/lib/ring.h
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/ring.h 2008-07-25 22:07:36 UTC
(rev 9018)
+++ usrp2/branches/features/host-ng/host-ng/lib/ring.h 2008-07-25 22:09:43 UTC
(rev 9019)
@@ -24,9 +24,13 @@
#include <omnithread.h>
#include <stddef.h>
#include <vector>
+#include <boost/shared_ptr.hpp>
namespace usrp2 {
+ class ring;
+ typedef boost::shared_ptr<ring> ring_sptr;
+
class ring
{
private:
Modified: usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc 2008-07-25
22:07:36 UTC (rev 9018)
+++ usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc 2008-07-25
22:09:43 UTC (rev 9019)
@@ -77,20 +77,21 @@
usrp2::impl::impl(const std::string &ifc, const std::string &addr)
- : d_buffer(new eth_buffer()), d_pf(0), d_bg_thread(0), d_bg_running(false),
+ : d_eth_buf(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_missing(0), d_num_rx_overruns(0),
d_num_rx_bytes(0),
- d_num_enqueued(0), d_enqueued_mutex(),
d_bg_pending_cond(&d_enqueued_mutex)
+ d_num_enqueued(0), d_enqueued_mutex(),
d_bg_pending_cond(&d_enqueued_mutex),
+ d_channel_rings(NCHANS)
{
props_vector_t u2s = find(ifc, addr);
if (u2s.size() != 1)
throw std::runtime_error("Unable to find requested USRP2.");
- if (!d_buffer->open(ifc, htons(U2_ETHERTYPE)))
+ if (!d_eth_buf->open(ifc, htons(U2_ETHERTYPE)))
throw std::runtime_error("Unable to register USRP2 protocol");
- d_pf = pktfilter::make_ethertype_inbound(U2_ETHERTYPE, d_buffer->mac());
- if (!d_pf || !d_buffer->attach_pktfilter(d_pf))
+ d_pf = pktfilter::make_ethertype_inbound(U2_ETHERTYPE, d_eth_buf->mac());
+ if (!d_pf || !d_eth_buf->attach_pktfilter(d_pf))
throw std::runtime_error("Unable to attach packet filter.");
d_addr = u2s[0].addr;
@@ -99,7 +100,6 @@
std::cerr << "usrp2 constructor: using USRP2 at " << d_addr << std::endl;
memset(d_pending_replies, 0, sizeof(d_pending_replies));
- memset(d_channel_rings, 0, sizeof(d_channel_rings));
d_bg_thread = new usrp2_thread(this);
d_bg_thread->start();
@@ -110,8 +110,8 @@
stop_bg();
d_bg_thread = 0; // thread class deletes itself
delete d_pf;
- d_buffer->close();
- delete d_buffer;
+ d_eth_buf->close();
+ delete d_eth_buf;
if (USRP2_IMPL_DEBUG) {
std::cerr << std::endl
@@ -154,7 +154,7 @@
{
p->ehdr.ethertype = htons(U2_ETHERTYPE);
parse_mac_addr(dst, &p->ehdr.dst);
- memcpy(&p->ehdr.src, d_buffer->mac(), 6);
+ memcpy(&p->ehdr.src, d_eth_buf->mac(), 6);
p->thdr.flags = 0; // FIXME transport header values?
p->thdr.seqno = d_tx_seqno++;
p->thdr.ack = 0;
@@ -300,7 +300,7 @@
return false;
}
- d_channel_rings[channel] = new ring(d_buffer->max_frames());
+ d_channel_rings[channel] = ring_sptr(new ring(d_eth_buf->max_frames()));
if (items_per_frame == 0)
items_per_frame = U2_MAX_SAMPLES; // minimize overhead
@@ -364,11 +364,8 @@
return false;
bool success = (ntohx(reply.ok) == 1);
- if (success) {
- ring *rp = d_channel_rings[channel];
- d_channel_rings[channel] = 0;
- delete rp;
- }
+ if (success)
+ d_channel_rings[channel].reset();
return success;
}
@@ -380,7 +377,7 @@
d_pending_replies[p->rid()] = p;
// Transmit command
- if (d_buffer->tx_frame(cmd, len) != 1) {
+ if (d_eth_buf->tx_frame(cmd, len) != 1) {
d_pending_replies[p->rid()] = 0;
return false;
}
@@ -402,7 +399,7 @@
// Receive available frames from ethernet buffer. Handler will
// process control frames, enqueue data packets in channel
// rings, and signal blocked API threads
- int res = d_buffer->rx_frames(this, 100); // FIXME magic timeout
+ int res = d_eth_buf->rx_frames(this, 100); // FIXME magic timeout
if (res == -1)
break;
@@ -527,8 +524,8 @@
return false;
}
- ring *rp = d_channel_rings[channel];
- if (rp == 0) {
+ ring_sptr rp = d_channel_rings[channel];
+ if (!rp){
std::cerr << "usrp2: channel " << channel
<< " not receiving" << std::endl;
return false;
@@ -547,7 +544,7 @@
// Callers are always required to accept a frame, but then to signal when
// they are done.
- d_buffer->release_frame(p);
+ d_eth_buf->release_frame(p);
DEBUG_LOG("-");
dec_enqueued();
Modified: usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.h
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.h 2008-07-25
22:07:36 UTC (rev 9018)
+++ usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.h 2008-07-25
22:09:43 UTC (rev 9019)
@@ -22,7 +22,9 @@
#include <usrp2/usrp2.h>
#include <usrp2/data_handler.h>
#include <usrp2_eth_packet.h>
+#include <boost/scoped_ptr.hpp>
#include "control.h"
+#include "ring.h"
#include <string>
namespace usrp2 {
@@ -34,12 +36,12 @@
class pending_reply;
class ring;
- class usrp2::impl : public data_handler
+ class usrp2::impl : private data_handler
{
static const size_t NRIDS = 256;
static const size_t NCHANS = 32;
- eth_buffer *d_buffer;
+ eth_buffer *d_eth_buf;
pktfilter *d_pf;
std::string d_addr;
usrp2_thread *d_bg_thread;
@@ -58,9 +60,11 @@
omni_mutex d_enqueued_mutex;
omni_condition d_bg_pending_cond;
+ // all pending_replies are stack allocated, thus no possibility of leaking
these
pending_reply *d_pending_replies[NRIDS]; // indexed by 8-bit reply id
- ring *d_channel_rings[NCHANS]; // indexed by 5-bit channel number
+ std::vector<ring_sptr> d_channel_rings; // indexed by 5-bit channel
number
+
void inc_enqueued() {
omni_mutex_lock l(d_enqueued_mutex);
d_num_enqueued++;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r9019 - in usrp2/branches/features/host-ng/host-ng: include/usrp2 lib,
eb <=