[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8600 - in usrp2/trunk/host-ng: apps lib
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r8600 - in usrp2/trunk/host-ng: apps lib |
Date: |
Tue, 17 Jun 2008 16:55:26 -0600 (MDT) |
Author: jcorgan
Date: 2008-06-17 16:55:23 -0600 (Tue, 17 Jun 2008)
New Revision: 8600
Added:
usrp2/trunk/host-ng/lib/control.cc
usrp2/trunk/host-ng/lib/control.h
Modified:
usrp2/trunk/host-ng/apps/Makefile.am
usrp2/trunk/host-ng/apps/test_usrp2.cc
usrp2/trunk/host-ng/lib/Makefile.am
usrp2/trunk/host-ng/lib/copy_handler.cc
usrp2/trunk/host-ng/lib/eth_buffer.cc
usrp2/trunk/host-ng/lib/usrp2_impl.cc
usrp2/trunk/host-ng/lib/usrp2_impl.h
Log:
work-in-progress
Modified: usrp2/trunk/host-ng/apps/Makefile.am
===================================================================
--- usrp2/trunk/host-ng/apps/Makefile.am 2008-06-17 22:13:20 UTC (rev
8599)
+++ usrp2/trunk/host-ng/apps/Makefile.am 2008-06-17 22:55:23 UTC (rev
8600)
@@ -17,6 +17,7 @@
include $(top_srcdir)/Makefile.common
+AM_CPPFLAGS = -Wall -Werror
INCLUDES = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES)
LDADD = \
Modified: usrp2/trunk/host-ng/apps/test_usrp2.cc
===================================================================
--- usrp2/trunk/host-ng/apps/test_usrp2.cc 2008-06-17 22:13:20 UTC (rev
8599)
+++ usrp2/trunk/host-ng/apps/test_usrp2.cc 2008-06-17 22:55:23 UTC (rev
8600)
@@ -78,7 +78,7 @@
u2->set_rx_gain(1.0);
u2->set_rx_freq(0.0, NULL);
u2->set_rx_decim(5);
- u2->start_rx_streaming();
+ //u2->start_rx_streaming();
struct timespec ts;
ts.tv_sec = 10;
@@ -87,7 +87,7 @@
if (r == -1)
perror("nanosleep");
- u2->stop_rx_streaming();
+ //u2->stop_rx_streaming();
return 0;
}
Modified: usrp2/trunk/host-ng/lib/Makefile.am
===================================================================
--- usrp2/trunk/host-ng/lib/Makefile.am 2008-06-17 22:13:20 UTC (rev 8599)
+++ usrp2/trunk/host-ng/lib/Makefile.am 2008-06-17 22:55:23 UTC (rev 8600)
@@ -17,12 +17,14 @@
include $(top_srcdir)/Makefile.common
+AM_CPPFLAGS = -Wall -Werror
INCLUDES = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES)
lib_LTLIBRARIES = \
libusrp2ng.la
libusrp2ng_la_SOURCES = \
+ control.cc \
copy_handler.cc \
eth_buffer.cc \
ethernet.cc \
@@ -37,6 +39,7 @@
# Private headers not needed for above the API development
noinst_HEADERS = \
+ control.h \
eth_buffer.h \
eth_common.h \
ethernet.h \
Added: usrp2/trunk/host-ng/lib/control.cc
===================================================================
--- usrp2/trunk/host-ng/lib/control.cc (rev 0)
+++ usrp2/trunk/host-ng/lib/control.cc 2008-06-17 22:55:23 UTC (rev 8600)
@@ -0,0 +1,57 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "control.h"
+#include <iostream>
+
+namespace usrp2 {
+
+ pending_reply::pending_reply(int rid, void *buffer, int len)
+ : d_rid(rid), d_mutex(), d_cond(&d_mutex), d_buffer(buffer), d_len(len)
+ {
+ }
+
+ pending_reply::~pending_reply()
+ {
+ signal();
+ }
+
+ int
+ pending_reply::wait(int secs, long nsecs)
+ {
+ int res = d_cond.timedwait(secs, nsecs);
+ if (res == 0)
+ std::cerr << "usrp2: no response to command packet" << std::endl;
+ return res;
+ }
+
+ void
+ pending_reply::signal()
+ {
+ d_cond.signal();
+ }
+
+} // namespace usrp2
+
Added: usrp2/trunk/host-ng/lib/control.h
===================================================================
--- usrp2/trunk/host-ng/lib/control.h (rev 0)
+++ usrp2/trunk/host-ng/lib/control.h 2008-06-17 22:55:23 UTC (rev 8600)
@@ -0,0 +1,86 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef INCLUDED_CONTROL_H
+#define INCLUDED_CONTROL_H
+
+#include <omnithread.h>
+#include <usrp2_eth_packet.h>
+
+namespace usrp2 {
+
+ /*!
+ * OP_CONFIG_RX_V2 command packet
+ */
+ struct config_rx_v2_cmd
+ {
+ u2_eth_packet_t h;
+ op_config_rx_v2_t op;
+ op_eop_t eop;
+ };
+
+ /*!
+ * Control mechanism to allow API calls to block waiting for reply packets
+ */
+ class pending_reply
+ {
+ private:
+ int d_rid;
+ omni_mutex d_mutex;
+ omni_condition d_cond;
+ void *d_buffer;
+ int d_len;
+
+ public:
+ /*!
+ * Construct a pending reply from the reply ID, response packet
+ * buffer, and buffer length.
+ */
+ pending_reply(int rid, void *buffer, int len);
+
+ /*!
+ * Destructor. Signals creating thread.
+ */
+ ~pending_reply();
+
+ /*!
+ * Block, waiting for reply packet.
+ * Returns: 1 = ok, reply packet in buffer
+ * 0 = timeout
+ */
+ int wait(int secs, long nsecs);
+
+ /*!
+ * Allows creating thread to resume after copying reply into buffer
+ */
+ void signal();
+
+ /*!
+ * Retrieve pending reply ID
+ */
+ int rid() const { return d_rid; }
+
+ /*!
+ * Retrieve destination buffer address
+ */
+ void *buffer() const { return d_buffer; }
+ };
+
+} // namespace usrp2
+
+#endif /* INCLUDED_CONTROL_H */
Modified: usrp2/trunk/host-ng/lib/copy_handler.cc
===================================================================
--- usrp2/trunk/host-ng/lib/copy_handler.cc 2008-06-17 22:13:20 UTC (rev
8599)
+++ usrp2/trunk/host-ng/lib/copy_handler.cc 2008-06-17 22:55:23 UTC (rev
8600)
@@ -50,6 +50,8 @@
if (d_space == 0)
return DONE; // don't call me anymore
+
+ return 0;
}
} // namespace usrp2
Modified: usrp2/trunk/host-ng/lib/eth_buffer.cc
===================================================================
--- usrp2/trunk/host-ng/lib/eth_buffer.cc 2008-06-17 22:13:20 UTC (rev
8599)
+++ usrp2/trunk/host-ng/lib/eth_buffer.cc 2008-06-17 22:55:23 UTC (rev
8600)
@@ -209,16 +209,13 @@
}
if (pres == 0) {
- DEBUG_LOG("T");
+ DEBUG_LOG("-");
return 2;
}
}
// Iterate through available packets
while (frame_available()) {
- if (ETH_BUFFER_DEBUG)
- DEBUG_LOG("R");
-
// Get start of ethernet frame and length
tpacket_hdr *hdr = (tpacket_hdr *)d_ring[d_head];
void *base = (uint8_t *)hdr+hdr->tp_mac;
@@ -237,6 +234,7 @@
break;
}
+ DEBUG_LOG("|");
return 1;
}
@@ -244,6 +242,7 @@
eth_buffer::tx_frame(const void *base, size_t len, int flags)
{
// TODO: implement flags
+ DEBUG_LOG("T");
int res = d_ethernet->write_packet(base, len);
if (res < 0 || (unsigned int)res != len)
Modified: usrp2/trunk/host-ng/lib/usrp2_impl.cc
===================================================================
--- usrp2/trunk/host-ng/lib/usrp2_impl.cc 2008-06-17 22:13:20 UTC (rev
8599)
+++ usrp2/trunk/host-ng/lib/usrp2_impl.cc 2008-06-17 22:55:23 UTC (rev
8600)
@@ -26,6 +26,7 @@
#include "usrp2_thread.h"
#include "eth_buffer.h"
#include "pktfilter.h"
+#include "control.h"
#include <stdexcept>
#include <iostream>
#include <stdio.h>
@@ -72,7 +73,8 @@
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_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)
+ d_num_rx_frames(0), d_num_rx_lost(0), d_num_rx_bytes(0),
+ d_pending_replies(0)
{
props_vector_t u2s = find(ifc, addr);
if (u2s.size() != 1)
@@ -169,34 +171,32 @@
if (USRP2_IMPL_DEBUG)
std::cerr << "usrp2: setting receive gain to " << gain << std::endl;
- uint8_t pktbuf[eth_buffer::MAX_PKTLEN];
- memset(pktbuf, 0, sizeof(pktbuf));
+ config_rx_v2_cmd cmd;
+ op_config_rx_v2_t reply;
+
+ memset(&cmd, 0, sizeof(cmd));
+ init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1);
- struct command {
- u2_eth_packet_t h;
- op_config_rx_v2_t op;
- op_eop_t eop;
- };
+ cmd.op.opcode = OP_CONFIG_RX_V2;
+ cmd.op.len = sizeof(op_config_rx_v2_t);
+ cmd.op.rid = d_next_rid++;
+ cmd.op.valid = htons(CFGV_GAIN);
+ cmd.op.gain = htons(u2_double_to_fxpt_gain(gain));
+ cmd.eop.opcode = OP_EOP;
+ cmd.eop.len = sizeof(op_eop_t);
- command *c = (command *) pktbuf;
- init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
-
- c->op.opcode = OP_CONFIG_RX_V2;
- c->op.len = sizeof(op_config_rx_v2_t);
- c->op.rid = d_next_rid++;
-
- c->op.valid = htons(CFGV_GAIN);
- c->op.gain = htons(u2_double_to_fxpt_gain(gain));
-
- c->eop.opcode = OP_EOP;
- c->eop.len = sizeof(op_eop_t);
-
- int len = std::max((size_t) eth_buffer::MIN_PKTLEN, sizeof(command));
- if (d_buffer->tx_frame(c, len) != len)
+ pending_reply p(cmd.op.rid, &reply, sizeof(reply));
+ // enqueue p into pending list
+
+ // Transmit command
+ if (d_buffer->tx_frame(&cmd, sizeof(cmd)) != 1)
return false;
-
- // FIXME wait for corresponding reply, etc.
-
+
+ // Wait for reply or timeout
+ if (p.wait(0, 10000000) == 0)
+ return false;
+
+ // Process reply
return true;
}
@@ -384,42 +384,72 @@
unsigned int
usrp2::impl::operator()(const void *base, unsigned int len)
{
- u2_eth_samples_t *pkt = (u2_eth_samples_t *)base;
+ u2_eth_samples_t *pkt = (u2_eth_samples_t *)base;
int chan = u2p_chan(&pkt->hdrs.fixed);
- if (chan == CONTROL_CHAN){ // control packets
- // point to beginning of payload (subpackets)
- unsigned char *p = ((unsigned char *) pkt) + sizeof(u2_eth_packet_t);
+ if (chan == CONTROL_CHAN) { // control packets
+ DEBUG_LOG("C");
+ return handle_control_packet(base, len);
+ }
+ else { // data packets
+ DEBUG_LOG("D");
+ return handle_data_packet(base, len);
+ }
- // FIXME iterate over payload, handling more than a single
- // subpacket, when (if?) the firmware starts sending them
+ // not reached
+ }
- int opcode = p[0];
- std::cerr << "control_packet: " << opcode_to_string(opcode) << std::endl;
+ unsigned int
+ usrp2::impl::handle_control_packet(const void *base, unsigned int len)
+ {
+ // point to beginning of payload (subpackets)
+ unsigned char *p = (unsigned char *)base + sizeof(u2_eth_packet_t);
+
+ // FIXME iterate over payload, handling more than a single
+ // subpacket, when (if?) the firmware starts sending them
+
+ int opcode = p[0];
+ int oplen = p[1];
+ int rid = p[2];
+
+ if (USRP2_IMPL_DEBUG) {
+ std::cerr << "cmd reply: id=" << rid
+ << " len=" << oplen
+ << " op=" << opcode_to_string(opcode)
+ << std::endl;
}
- else { // data packets
- d_num_rx_frames++;
- d_num_rx_bytes += len;
+
+ // handle command reply here
+ return 0;
+ }
+
+ unsigned int
+ usrp2::impl::handle_data_packet(const void *base, unsigned int len)
+ {
+ u2_eth_samples_t *pkt = (u2_eth_samples_t *)base;
+ 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;
+ 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_num_rx_lost += missing;
}
- d_rx_seqno = pkt->hdrs.thdr.seqno;
}
- return 0;
+ d_rx_seqno = pkt->hdrs.thdr.seqno;
+
+ // enqueue in channel ring here
+ return 0; // will be KEEP, as the channel ring runner will retire packet
}
-
+
void
usrp2::impl::stop_bg()
{
Modified: usrp2/trunk/host-ng/lib/usrp2_impl.h
===================================================================
--- usrp2/trunk/host-ng/lib/usrp2_impl.h 2008-06-17 22:13:20 UTC (rev
8599)
+++ usrp2/trunk/host-ng/lib/usrp2_impl.h 2008-06-17 22:55:23 UTC (rev
8600)
@@ -22,7 +22,9 @@
#include <usrp2/usrp2.h>
#include <usrp2/data_handler.h>
#include <usrp2_eth_packet.h>
+#include <omnithread.h>
#include <string>
+#include <list>
namespace usrp2 {
@@ -30,7 +32,8 @@
class pktfilter;
class usrp2_thread;
class usrp2_tune_result;
-
+ class pending_reply;
+
class usrp2::impl : public data_handler
{
eth_buffer *d_buffer;
@@ -42,11 +45,14 @@
int d_rx_decim;
int d_rx_seqno;
int d_tx_seqno;
- int d_next_rid;
+ int d_next_rid;
unsigned int d_num_rx_frames;
unsigned int d_num_rx_lost;
unsigned int d_num_rx_bytes;
+ std::list<pending_reply *> d_pending_replies;
+ omni_mutex d_reply_mutex;
+
public:
impl(const std::string &ifc, const std::string &addr);
~impl();
@@ -63,8 +69,10 @@
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);
+ unsigned int handle_control_packet(const void *base, unsigned int len);
+ unsigned int handle_data_packet(const void *base, unsigned int len);
};
} // namespace usrp2
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8600 - in usrp2/trunk/host-ng: apps lib,
jcorgan <=