[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8614 - in usrp2/branches/features/host-ng/host-ng: ap
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r8614 - in usrp2/branches/features/host-ng/host-ng: apps lib |
Date: |
Wed, 18 Jun 2008 14:02:28 -0600 (MDT) |
Author: jcorgan
Date: 2008-06-18 14:02:27 -0600 (Wed, 18 Jun 2008)
New Revision: 8614
Modified:
usrp2/branches/features/host-ng/host-ng/apps/test_usrp2.cc
usrp2/branches/features/host-ng/host-ng/lib/control.cc
usrp2/branches/features/host-ng/host-ng/lib/control.h
usrp2/branches/features/host-ng/host-ng/lib/eth_buffer.cc
usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc
usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.h
usrp2/branches/features/host-ng/host-ng/lib/usrp2_thread.cc
Log:
work-in-progress
Modified: usrp2/branches/features/host-ng/host-ng/apps/test_usrp2.cc
===================================================================
--- usrp2/branches/features/host-ng/host-ng/apps/test_usrp2.cc 2008-06-18
04:58:54 UTC (rev 8613)
+++ usrp2/branches/features/host-ng/host-ng/apps/test_usrp2.cc 2008-06-18
20:02:27 UTC (rev 8614)
@@ -77,7 +77,7 @@
u2->set_rx_gain(1.0);
u2->set_rx_freq(0.0, NULL);
- u2->set_rx_decim(50);
+ u2->set_rx_decim(5);
u2->start_rx_streaming();
struct timespec ts;
@@ -89,5 +89,10 @@
u2->stop_rx_streaming();
+ ts.tv_sec = 2;
+ r = nanosleep(&ts, 0);
+ if (r == -1)
+ perror("nanosleep");
+
return 0;
}
Modified: usrp2/branches/features/host-ng/host-ng/lib/control.cc
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/control.cc 2008-06-18
04:58:54 UTC (rev 8613)
+++ usrp2/branches/features/host-ng/host-ng/lib/control.cc 2008-06-18
20:02:27 UTC (rev 8614)
@@ -39,12 +39,12 @@
}
int
- pending_reply::wait(int secs, long nsecs)
+ pending_reply::wait(unsigned int msecs)
{
- int res = d_cond.timedwait(secs, nsecs);
- if (res == 0)
- std::cerr << "usrp2: no response to command packet" << std::endl;
- return res;
+ // TODO: implement timeout by using timedwait()
+ omni_mutex_lock l(d_mutex);
+ d_cond.wait();
+ return 1;
}
void
Modified: usrp2/branches/features/host-ng/host-ng/lib/control.h
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/control.h 2008-06-18
04:58:54 UTC (rev 8613)
+++ usrp2/branches/features/host-ng/host-ng/lib/control.h 2008-06-18
20:02:27 UTC (rev 8614)
@@ -21,6 +21,7 @@
#include <omnithread.h>
#include <usrp2_eth_packet.h>
+#include <list>
namespace usrp2 {
/*!
@@ -33,9 +34,26 @@
op_eop_t eop;
};
+ struct op_start_rx_streaming_cmd
+ {
+ u2_eth_packet_t h;
+ op_start_rx_streaming_t op;
+ op_eop_t eop;
+ };
+
+ struct op_stop_rx_cmd {
+ u2_eth_packet_t h;
+ op_id_t op;
+ op_eop_t eop;
+ };
+
/*!
* Control mechanism to allow API calls to block waiting for reply packets
*/
+ class pending_reply;
+ typedef std::list<pending_reply *> pending_reply_list_t;
+ typedef pending_reply_list_t::iterator pending_reply_iter_t;
+
class pending_reply
{
private:
@@ -62,7 +80,7 @@
* Returns: 1 = ok, reply packet in buffer
* 0 = timeout
*/
- int wait(int secs, long nsecs);
+ int wait(unsigned int msecs);
/*!
* Allows creating thread to resume after copying reply into buffer
Modified: usrp2/branches/features/host-ng/host-ng/lib/eth_buffer.cc
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/eth_buffer.cc 2008-06-18
04:58:54 UTC (rev 8613)
+++ usrp2/branches/features/host-ng/host-ng/lib/eth_buffer.cc 2008-06-18
20:02:27 UTC (rev 8614)
@@ -56,9 +56,6 @@
: 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;
-
if (rx_bufsize == 0)
d_buflen = (size_t)MAX_MEM_SIZE;
else
@@ -69,19 +66,12 @@
eth_buffer::~eth_buffer()
{
- if (ETH_BUFFER_DEBUG)
- std::cerr << "eth_buffer: destructor" << std::endl;
-
close();
}
bool
eth_buffer::open(const std::string &ifname, int protocol)
{
- if (ETH_BUFFER_DEBUG)
- std::cerr << "eth_buffer: using interface " << ifname
- << ", protocol=" << protocol << std::endl;
-
if (!d_ethernet->open(ifname, protocol)) {
std::cerr << "eth_buffer: unable to open interface "
<< ifname << std::endl;
@@ -114,6 +104,7 @@
req.tp_frame_nr = d_buflen/req.tp_frame_size;
d_frame_nr = req.tp_frame_nr;
+#if 0
if (ETH_BUFFER_DEBUG)
std::cerr << "eth_buffer:"
<< " frame_size=" << req.tp_frame_size
@@ -122,6 +113,7 @@
<< " frame_nr=" << req.tp_frame_nr
<< " buflen=" << d_buflen
<< std::endl;
+#endif
// Try to get kernel shared memory buffer
if (setsockopt(d_fd, SOL_PACKET, PACKET_RX_RING, (void *)&req,
sizeof(req))) {
@@ -132,8 +124,7 @@
return false;
}
- if (ETH_BUFFER_DEBUG)
- std::cerr << "eth_buffer: using malloc'd memory for buffer" <<
std::endl;
+ std::cerr << "eth_buffer: using malloc'd memory for buffer" << std::endl;
}
else {
d_using_tpring = true;
Modified: usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc 2008-06-18
04:58:54 UTC (rev 8613)
+++ usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc 2008-06-18
20:02:27 UTC (rev 8614)
@@ -106,7 +106,8 @@
delete d_buffer;
if (USRP2_IMPL_DEBUG) {
- std::cerr << "usrp2 destructor: received " << d_num_rx_frames
+ std::cerr << std::endl
+ << "usrp2 destructor: received " << d_num_rx_frames
<< " frames, with " << d_num_rx_lost << " lost ("
<< (int)(100.0*d_num_rx_lost/d_num_rx_frames)
<< "%), totaling " << d_num_rx_bytes
@@ -180,9 +181,6 @@
bool
usrp2::impl::set_rx_gain(double gain)
{
- if (USRP2_IMPL_DEBUG)
- std::cerr << "usrp2: setting receive gain to " << gain << std::endl;
-
op_config_rx_v2_cmd cmd;
op_config_rx_reply_v2_t reply;
@@ -191,16 +189,9 @@
cmd.op.gain = htons(u2_double_to_fxpt_gain(gain));
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)
+ if (!transmit_cmd(&cmd, sizeof(cmd), &p, 100))
return false;
- // Wait for reply or timeout
- if (p.wait(0, 10000000) == 0)
- return false;
-
// Process reply here
return true;
}
@@ -208,9 +199,6 @@
bool
usrp2::impl::set_rx_freq(double frequency, usrp2_tune_result *result)
{
- if (USRP2_IMPL_DEBUG)
- std::cerr << "usrp2: setting frequency to " << frequency << std::endl;
-
op_config_rx_v2_cmd cmd;
op_config_rx_reply_v2_t reply;
@@ -221,16 +209,9 @@
cmd.op.freq_lo = htonl(u2_fxpt_freq_lo(fxpt));
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)
+ if (!transmit_cmd(&cmd, sizeof(cmd), &p, 100))
return false;
- // Wait for reply or timeout
- if (p.wait(0, 10000000) == 0)
- return false;
-
// Process reply here
return true;
}
@@ -238,10 +219,6 @@
bool
usrp2::impl::set_rx_decim(int decimation_factor)
{
- if (USRP2_IMPL_DEBUG)
- std::cerr << "usrp2: setting receive decimation rate to "
- << decimation_factor << std::endl;
-
op_config_rx_v2_cmd cmd;
op_config_rx_reply_v2_t reply;
@@ -250,18 +227,9 @@
cmd.op.decim = htonl(decimation_factor);
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)
+ if (!transmit_cmd(&cmd, sizeof(cmd), &p, 100))
return false;
- // Wait for reply or timeout
- if (p.wait(0, 10000000) == 0)
- return false;
-
- d_rx_decim = decimation_factor;
-
// Process reply here
return true;
}
@@ -269,10 +237,6 @@
bool
usrp2::impl::set_rx_scale_iq(int scale_i, int scale_q)
{
- if (USRP2_IMPL_DEBUG)
- std::cerr << "usrp2: setting RX IQ scaling to "
- << scale_i << ", " << scale_q << std::endl;
-
op_config_rx_v2_cmd cmd;
op_config_rx_reply_v2_t reply;
@@ -281,16 +245,9 @@
cmd.op.scale_iq = htonl(((scale_i & 0xffff) << 16) | (scale_q & 0xffff));
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)
+ if (!transmit_cmd(&cmd, sizeof(cmd), &p, 100))
return false;
- // Wait for reply or timeout
- if (p.wait(0, 10000000) == 0)
- return false;
-
// Process reply here
return true;
}
@@ -302,52 +259,43 @@
if (items_per_frame == 0)
items_per_frame = 250; // TODO: calculate from d_itemsize;
- uint8_t pktbuf[eth_buffer::MAX_PKTLEN];
- memset(pktbuf, 0, sizeof(pktbuf));
+ op_start_rx_streaming_cmd cmd;
+ //op_start_rx_streaming_reply_t reply;
+
+ memset(&cmd, 0, sizeof(cmd));
+ init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1);
+ cmd.op.opcode = OP_START_RX_STREAMING;
+ cmd.op.len = sizeof(op_start_rx_streaming_t);
+ cmd.op.items_per_frame = htonl(items_per_frame);
+ cmd.eop.opcode = OP_EOP;
+ cmd.eop.len = sizeof(op_eop_t);
- struct command {
- u2_eth_packet_t h;
- op_start_rx_streaming_t op;
- op_eop_t eop;
- };
-
- command *c = (command *) pktbuf;
- init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
-
- c->op.opcode = OP_START_RX_STREAMING;
- c->op.len = sizeof(op_start_rx_streaming_t);
- c->op.items_per_frame = htonl(items_per_frame);
-
- 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));
+ if (!transmit_cmd(&cmd, sizeof(cmd), NULL))
return false;
-
+
+ // Process reply here
return true;
}
bool
usrp2::impl::stop_rx_streaming()
{
- uint8_t pktbuf[eth_buffer::MAX_PKTLEN];
- memset(pktbuf, 0, sizeof(pktbuf));
+ op_stop_rx_cmd cmd;
+ //op_stop_rx_reply_t reply;
+
+ memset(&cmd, 0, sizeof(cmd));
+ init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1);
+ cmd.op.opcode = OP_STOP_RX;
+ cmd.op.len = sizeof(op_stop_rx_t);
+ cmd.eop.opcode = OP_EOP;
+ cmd.eop.len = sizeof(op_eop_t);
- struct command {
- u2_eth_packet_t h;
- op_id_t op_stop_rx;
- };
-
- command *c = (command *) pktbuf;
- init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
-
- c->op_stop_rx.opcode = OP_STOP_RX;
- c->op_stop_rx.len = sizeof(op_stop_rx_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));
+ if (!transmit_cmd(&cmd, sizeof(cmd), NULL))
return false;
-
+
+ // Process reply here
return true;
}
@@ -356,7 +304,7 @@
{
d_bg_running = true;
while(d_bg_running) {
- int res = d_buffer->rx_frames(this, 1000);
+ int res = d_buffer->rx_frames(this, 100);
if (res == -1)
break;
}
@@ -380,6 +328,37 @@
// not reached
}
+ void
+ usrp2::impl::enqueue_pending_reply(pending_reply *p)
+ {
+ DEBUG_LOG("p");
+ omni_mutex_lock l(d_reply_mutex);
+ d_pending_replies.push_back(p);
+ }
+
+ bool
+ usrp2::impl::transmit_cmd(void *cmd, int len, pending_reply *p, unsigned int
msecs)
+ {
+ if (p)
+ enqueue_pending_reply(p);
+
+ // Transmit command
+ if (d_buffer->tx_frame(cmd, len) != 1)
+ return false;
+
+ if (p && msecs > 0) {
+ DEBUG_LOG("w");
+
+ if (p->wait(msecs) == 0) {
+ DEBUG_LOG("t");
+ return false;
+ }
+ }
+
+ DEBUG_LOG("r");
+ return true;
+ }
+
unsigned int
usrp2::impl::handle_control_packet(const void *base, unsigned int len)
{
@@ -389,19 +368,24 @@
// 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 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;
+ omni_mutex_lock l(d_reply_mutex);
+ pending_reply_iter_t rp;
+ for (rp = d_pending_replies.begin(); rp != d_pending_replies.end(); rp++) {
+ if ((*rp)->rid() == rid) {
+ DEBUG_LOG("s"); // pending blocked thread condition variable signaled
+ (*rp)->signal();
+ d_pending_replies.erase(rp);
+ return 0; // release packet
+ }
}
- // handle command reply here
- return 0;
+ // TODO: handle unsolicited or late replies
+ DEBUG_LOG("l");
+ return 0; // release packet
}
unsigned int
@@ -434,16 +418,10 @@
void
usrp2::impl::stop_bg()
{
- if (USRP2_IMPL_DEBUG)
- std::cerr << "usrp2_thread::stop: joining background thread "
- << this << std::endl;
d_bg_running = false;
void *dummy_status;
d_bg_thread->join(&dummy_status);
-
- if (USRP2_IMPL_DEBUG)
- std::cerr << "usrp2_thread::stop: join returned" << std::endl;
}
} // namespace usrp2
Modified: usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.h
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.h 2008-06-18
04:58:54 UTC (rev 8613)
+++ usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.h 2008-06-18
20:02:27 UTC (rev 8614)
@@ -51,7 +51,7 @@
unsigned int d_num_rx_lost;
unsigned int d_num_rx_bytes;
- std::list<pending_reply *> d_pending_replies;
+ pending_reply_list_t d_pending_replies;
omni_mutex d_reply_mutex;
static bool parse_mac_addr(const std::string &s, u2_mac_addr_t *p);
@@ -60,6 +60,8 @@
int word0_flags, int chan, uint32_t timestamp);
void stop_bg();
void init_config_rx_v2_cmd(op_config_rx_v2_cmd *cmd);
+ void enqueue_pending_reply(pending_reply *p);
+ bool transmit_cmd(void *cmd, int len, pending_reply *p, unsigned int
msecs=0);
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);
Modified: usrp2/branches/features/host-ng/host-ng/lib/usrp2_thread.cc
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/usrp2_thread.cc 2008-06-18
04:58:54 UTC (rev 8613)
+++ usrp2/branches/features/host-ng/host-ng/lib/usrp2_thread.cc 2008-06-18
20:02:27 UTC (rev 8614)
@@ -43,10 +43,6 @@
void
usrp2_thread::start()
{
- if (USRP2_THREAD_DEBUG)
- std::cerr << "usrp2_thread::start() "
- << this << std::endl;
-
start_undetached();
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8614 - in usrp2/branches/features/host-ng/host-ng: apps lib,
jcorgan <=