From 42b10fee5167354a2927c2874cec46fc0d71a245 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Thu, 3 Sep 2009 16:12:40 -0700 Subject: removed hard-coded link_is_up = true; --- usrp2/firmware/apps/gen_eth_packets.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/usrp2/firmware/apps/gen_eth_packets.c b/usrp2/firmware/apps/gen_eth_packets.c index dd2996752..530f448ee 100644 --- a/usrp2/firmware/apps/gen_eth_packets.c +++ b/usrp2/firmware/apps/gen_eth_packets.c @@ -148,8 +148,6 @@ main(void) } */ - link_is_up = true; /* FIXME tell s/w link is up */ - // fire off a receive from the ethernet bp_receive_to_buf(CPU_RX_BUF, PORT_ETH, 1, 0, BP_LAST_LINE); -- cgit From 5d040bc94b40cab5420303f959695d89fe83e031 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Fri, 4 Sep 2009 01:51:29 -0700 Subject: Fix race condition that caused commands such as stop_rx_streaming to fail. This fixes the bulk of the problem. Next step is to drop data packets while waiting for the reply. --- usrp2/host/lib/control.cc | 20 ++++++++---- usrp2/host/lib/control.h | 11 ++++--- usrp2/host/lib/usrp2_impl.cc | 74 +++++++++++++++++++++++--------------------- usrp2/host/lib/usrp2_impl.h | 3 +- 4 files changed, 62 insertions(+), 46 deletions(-) diff --git a/usrp2/host/lib/control.cc b/usrp2/host/lib/control.cc index 4b8597c60..bb71f79c2 100644 --- a/usrp2/host/lib/control.cc +++ b/usrp2/host/lib/control.cc @@ -30,26 +30,34 @@ namespace usrp2 { pending_reply::pending_reply(unsigned int rid, void *buffer, size_t len) - : d_rid(rid), d_mutex(), d_cond(&d_mutex), d_buffer(buffer), d_len(len) + : d_rid(rid), d_buffer(buffer), d_len(len), d_mutex(), d_cond(&d_mutex), + d_complete(false) { } pending_reply::~pending_reply() { - signal(); // Needed? + notify_completion(); // Needed? } int - pending_reply::wait(double secs) + pending_reply::wait_for_completion(double secs) { - omni_mutex_lock l(d_mutex); omni_time abs_timeout = omni_time::time(omni_time(secs)); - return d_cond.timedwait(abs_timeout.d_secs, abs_timeout.d_nsecs); + omni_mutex_lock l(d_mutex); + while (!d_complete){ + int r = d_cond.timedwait(abs_timeout.d_secs, abs_timeout.d_nsecs); + if (r == 0) // timed out + return 0; + } + return 1; } void - pending_reply::signal() + pending_reply::notify_completion() { + omni_mutex_lock l(d_mutex); + d_complete = true; d_cond.signal(); } diff --git a/usrp2/host/lib/control.h b/usrp2/host/lib/control.h index 9adc1618f..8769e4522 100644 --- a/usrp2/host/lib/control.h +++ b/usrp2/host/lib/control.h @@ -118,10 +118,13 @@ namespace usrp2 { { private: unsigned int d_rid; - omni_mutex d_mutex; - omni_condition d_cond; void *d_buffer; size_t d_len; + + // d_mutex is used with d_cond and also protects d_complete + omni_mutex d_mutex; + omni_condition d_cond; + bool d_complete; public: /*! @@ -140,12 +143,12 @@ namespace usrp2 { * Returns: 1 = ok, reply packet in buffer * 0 = timeout */ - int wait(double secs); + int wait_for_completion(double secs); /*! * Allows creating thread to resume after copying reply into buffer */ - void signal(); + void notify_completion(); /*! * Retrieve pending reply ID diff --git a/usrp2/host/lib/usrp2_impl.cc b/usrp2/host/lib/usrp2_impl.cc index 1ecfd7348..b81b3cd61 100644 --- a/usrp2/host/lib/usrp2_impl.cc +++ b/usrp2/host/lib/usrp2_impl.cc @@ -298,22 +298,24 @@ namespace usrp2 { cmd->eop.len = sizeof(cmd->eop); } + + bool + usrp2::impl::transmit_cmd(void *cmd, size_t len) + { + return d_eth_buf->tx_frame(cmd, len) == eth_buffer::EB_OK; + } + bool - usrp2::impl::transmit_cmd(void *cmd, size_t len, pending_reply *p, double secs) + usrp2::impl::transmit_cmd_and_wait(void *cmd, size_t len, pending_reply *p, double secs) { - if (p) - d_pending_replies[p->rid()] = p; + d_pending_replies[p->rid()] = p; - // Transmit command - if (d_eth_buf->tx_frame(cmd, len) != eth_buffer::EB_OK) { + if (!transmit_cmd(cmd, len)){ d_pending_replies[p->rid()] = 0; return false; } - int res = 1; - if (p) - res = p->wait(secs); - + int res = p->wait_for_completion(secs); d_pending_replies[p->rid()] = 0; return res == 1; } @@ -404,7 +406,7 @@ namespace usrp2 { // Copy reply into caller's buffer memcpy(rp->buffer(), p, std::min(oplen, buflen)); - rp->signal(); + rp->notify_completion(); d_pending_replies[rid] = 0; return data_handler::RELEASE; } @@ -485,7 +487,7 @@ namespace usrp2 { cmd.op.gain = htons(u2_double_to_fxpt_gain(gain)); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; bool success = (ntohx(reply.ok) == 1); @@ -512,7 +514,7 @@ namespace usrp2 { cmd.eop.len = sizeof(cmd.eop); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; bool success = (ntohx(reply.ok) == 1); @@ -532,7 +534,7 @@ namespace usrp2 { cmd.op.freq_lo = htonl(u2_fxpt_freq_lo(fxpt)); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; bool success = (ntohx(reply.ok) == 1); @@ -569,7 +571,7 @@ namespace usrp2 { cmd.op.decim = htonl(decimation_factor); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; bool success = (ntohx(reply.ok) == 1); @@ -589,7 +591,7 @@ namespace usrp2 { cmd.op.scale_iq = htonl(((scale_i & 0xffff) << 16) | (scale_q & 0xffff)); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; bool success = (ntohx(reply.ok) == 1); @@ -636,12 +638,13 @@ namespace usrp2 { bool success = false; pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - success = transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT); + success = transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT); success = success && (ntohx(reply.ok) == 1); if (success) d_channel_rings[channel] = ring_sptr(new ring(d_eth_buf->max_frames())); + //fprintf(stderr, "usrp2::start_rx_streaming: success = %d\n", success); return success; } } @@ -677,9 +680,10 @@ namespace usrp2 { bool success = false; pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - success = transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT); + success = transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, 10 * DEF_CMD_TIMEOUT); success = success && (ntohx(reply.ok) == 1); d_channel_rings[channel].reset(); + //fprintf(stderr, "usrp2::stop_rx_streaming: success = %d\n", success); return success; } } @@ -747,7 +751,7 @@ namespace usrp2 { cmd.op.gain = htons(u2_double_to_fxpt_gain(gain)); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; bool success = (ntohx(reply.ok) == 1); @@ -774,7 +778,7 @@ namespace usrp2 { cmd.eop.len = sizeof(cmd.eop); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; bool success = (ntohx(reply.ok) == 1); @@ -794,7 +798,7 @@ namespace usrp2 { cmd.op.freq_lo = htonl(u2_fxpt_freq_lo(fxpt)); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; bool success = (ntohx(reply.ok) == 1); @@ -831,7 +835,7 @@ namespace usrp2 { cmd.op.interp = htonl(interpolation_factor); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; bool success = (ntohx(reply.ok) == 1); @@ -882,7 +886,7 @@ namespace usrp2 { cmd.op.scale_iq = htonl(((scale_i & 0xffff) << 16) | (scale_q & 0xffff)); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; bool success = (ntohx(reply.ok) == 1); @@ -1010,7 +1014,7 @@ namespace usrp2 { cmd.eop.len = sizeof(cmd.eop); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; return ntohx(reply.ok) == 1; @@ -1069,7 +1073,7 @@ namespace usrp2 { return false; pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, 4*DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, 4*DEF_CMD_TIMEOUT)) return false; bool success = (ntohx(reply.ok) == 1); @@ -1108,7 +1112,7 @@ namespace usrp2 { cmd.eop.len = sizeof(cmd.eop); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; bool success = (ntohx(reply.ok) == 1); @@ -1135,7 +1139,7 @@ namespace usrp2 { cmd.eop.len = sizeof(cmd.eop); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; return ntohx(reply.ok) == 1; @@ -1157,7 +1161,7 @@ namespace usrp2 { cmd.eop.len = sizeof(cmd.eop); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; return ntohx(reply.ok) == 1; @@ -1197,7 +1201,7 @@ namespace usrp2 { reply = (op_generic_t *)malloc(rlen+bytes); pending_reply p(cmd.op.rid, reply, rlen+bytes); - if (transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) { + if (transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) { uint32_t nwords = (reply->len-rlen)/sizeof(uint32_t); uint32_t *data = (uint32_t *)(reply+rlen/wlen); for (unsigned int i = 0; i < nwords; i++) @@ -1264,7 +1268,7 @@ namespace usrp2 { bool ok = false; op_generic_t reply; pending_reply p(cmd->op.rid, &reply, sizeof(reply)); - if (transmit_cmd(cmd, l, &p, DEF_CMD_TIMEOUT)) + if (transmit_cmd_and_wait(cmd, l, &p, DEF_CMD_TIMEOUT)) ok = (ntohx(reply.ok) == 1); free(cmd); @@ -1286,7 +1290,7 @@ namespace usrp2 { cmd.eop.len = sizeof(cmd.eop); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; bool success = (ntohx(reply.ok) == 1); @@ -1315,7 +1319,7 @@ namespace usrp2 { cmd.eop.len = sizeof(cmd.eop); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; bool success = (ntohx(reply.ok) == 1); @@ -1348,7 +1352,7 @@ namespace usrp2 { cmd.eop.len = sizeof(cmd.eop); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; bool success = (ntohx(reply.ok) == 1); @@ -1377,7 +1381,7 @@ namespace usrp2 { cmd.eop.len = sizeof(cmd.eop); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; bool success = (ntohx(reply.ok) == 1); @@ -1406,7 +1410,7 @@ namespace usrp2 { cmd.eop.len = sizeof(cmd.eop); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; bool success = (ntohx(reply.ok) == 1); @@ -1443,7 +1447,7 @@ namespace usrp2 { cmd.eop.len = sizeof(cmd.eop); pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) + if (!transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT)) return false; bool success = (ntohx(reply.ok) == 1); diff --git a/usrp2/host/lib/usrp2_impl.h b/usrp2/host/lib/usrp2_impl.h index ec96f3a70..434e0e9b1 100644 --- a/usrp2/host/lib/usrp2_impl.h +++ b/usrp2/host/lib/usrp2_impl.h @@ -105,7 +105,8 @@ namespace usrp2 { void stop_bg(); void init_config_rx_v2_cmd(op_config_rx_v2_cmd *cmd); void init_config_tx_v2_cmd(op_config_tx_v2_cmd *cmd); - bool transmit_cmd(void *cmd, size_t len, pending_reply *p, double secs=0.0); + bool transmit_cmd_and_wait(void *cmd, size_t len, pending_reply *p, double secs=0.0); + bool transmit_cmd(void *cmd, size_t len); virtual data_handler::result operator()(const void *base, size_t len); data_handler::result handle_control_packet(const void *base, size_t len); data_handler::result handle_data_packet(const void *base, size_t len); -- cgit From 96b6c7b97e3fb9188bc6906153254dc36cedc2cb Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Fri, 4 Sep 2009 03:32:32 -0700 Subject: Fix problem with commands timing out (specifically stop_rx_streaming) After fixing the race, this change uses Tom's idea to stop enqueuing data when trying to stop, and adds a new flush_rx_samples method to drop any samples that may have already been accumulated. I ran Tom's test case 500 times with 0 failures ;-) --- usrp2/host/lib/usrp2_impl.cc | 44 ++++++++++++++++++++++++++++++++++++++++++-- usrp2/host/lib/usrp2_impl.h | 3 +++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/usrp2/host/lib/usrp2_impl.cc b/usrp2/host/lib/usrp2_impl.cc index b81b3cd61..d1e85805c 100644 --- a/usrp2/host/lib/usrp2_impl.cc +++ b/usrp2/host/lib/usrp2_impl.cc @@ -133,7 +133,7 @@ namespace usrp2 { d_bg_running(false), 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_channel_rings(NCHANS), d_tx_interp(0), d_rx_decim(0) + d_channel_rings(NCHANS), d_tx_interp(0), d_rx_decim(0), d_dont_enqueue(true) { if (!d_eth_buf->open(ifc, htons(U2_ETHERTYPE))) throw std::runtime_error("Unable to register USRP2 protocol"); @@ -375,6 +375,10 @@ namespace usrp2 { return handle_control_packet(base, len); } else { // data packets + + if (d_dont_enqueue) // toss packet + return data_handler::RELEASE; + return handle_data_packet(base, len); } @@ -636,6 +640,7 @@ namespace usrp2 { cmd.eop.opcode = OP_EOP; cmd.eop.len = sizeof(cmd.eop); + d_dont_enqueue = false; bool success = false; pending_reply p(cmd.op.rid, &reply, sizeof(reply)); success = transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT); @@ -643,6 +648,8 @@ namespace usrp2 { if (success) d_channel_rings[channel] = ring_sptr(new ring(d_eth_buf->max_frames())); + else + d_dont_enqueue = true; //fprintf(stderr, "usrp2::start_rx_streaming: success = %d\n", success); return success; @@ -664,6 +671,9 @@ namespace usrp2 { return false; } + d_dont_enqueue = true; // no new samples + flush_rx_samples(channel); // dump any we may already have + op_stop_rx_cmd cmd; op_generic_t reply; @@ -680,7 +690,7 @@ namespace usrp2 { bool success = false; pending_reply p(cmd.op.rid, &reply, sizeof(reply)); - success = transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, 10 * DEF_CMD_TIMEOUT); + success = transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT); success = success && (ntohx(reply.ok) == 1); d_channel_rings[channel].reset(); //fprintf(stderr, "usrp2::stop_rx_streaming: success = %d\n", success); @@ -736,6 +746,36 @@ namespace usrp2 { return true; } + bool + usrp2::impl::flush_rx_samples(unsigned int channel) + { + if (channel > MAX_CHAN) { + std::cerr << "usrp2: invalid channel (" << channel + << " )" << std::endl; + return false; + } + + if (channel > 0) { + std::cerr << "usrp2: channel " << channel + << " not implemented" << std::endl; + return false; + } + + ring_sptr rp = d_channel_rings[channel]; + if (!rp){ + return false; + } + + // Iterate through frames and drop them + void *p; + size_t frame_len_in_bytes; + while (rp->dequeue(&p, &frame_len_in_bytes)) { + d_eth_buf->release_frame(p); + dec_enqueued(); + } + return true; + } + // ---------------------------------------------------------------- // Transmit // ---------------------------------------------------------------- diff --git a/usrp2/host/lib/usrp2_impl.h b/usrp2/host/lib/usrp2_impl.h index 434e0e9b1..ed71a6ba3 100644 --- a/usrp2/host/lib/usrp2_impl.h +++ b/usrp2/host/lib/usrp2_impl.h @@ -87,6 +87,8 @@ namespace usrp2 { int d_tx_interp; // shadow tx interp int d_rx_decim; // shadow rx decim + bool d_dont_enqueue; + void inc_enqueued() { omni_mutex_lock l(d_enqueued_mutex); d_num_enqueued++; @@ -142,6 +144,7 @@ namespace usrp2 { bool read_gpio(int bank, uint16_t *value); bool start_rx_streaming(unsigned int channel, unsigned int items_per_frame); bool rx_samples(unsigned int channel, rx_sample_handler *handler); + bool flush_rx_samples(unsigned int channel); bool stop_rx_streaming(unsigned int channel); unsigned int rx_overruns() const { return d_num_rx_overruns; } unsigned int rx_missing() const { return d_num_rx_missing; } -- cgit From f945bc6d3188d15c767706a2edbbda950a101c61 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Fri, 4 Sep 2009 03:48:15 -0700 Subject: stop sending short ethernet command packets. --- usrp2/host/lib/usrp2_impl.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/usrp2/host/lib/usrp2_impl.cc b/usrp2/host/lib/usrp2_impl.cc index d1e85805c..3d0304324 100644 --- a/usrp2/host/lib/usrp2_impl.cc +++ b/usrp2/host/lib/usrp2_impl.cc @@ -300,8 +300,19 @@ namespace usrp2 { bool - usrp2::impl::transmit_cmd(void *cmd, size_t len) + usrp2::impl::transmit_cmd(void *cmd_, size_t len_) { + const void *cmd = cmd_; + int len = len_; + unsigned char tmp[64]; + + if (len_ < 64){ // pad to minimum ethernet frame size + memset(tmp, 0, sizeof(tmp)); + memcpy(tmp, cmd_, len_); + cmd = tmp; + len = sizeof(tmp); + } + return d_eth_buf->tx_frame(cmd, len) == eth_buffer::EB_OK; } -- cgit From 49a17dca1ee9cf7c0fd02b6baf83814a68c4e5e8 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Fri, 4 Sep 2009 15:35:01 -0700 Subject: Firmware now inserts mac source address value in each frame. The old mac used to do this automatically. --- usrp2/firmware/apps/app_common_v2.c | 1 + usrp2/firmware/apps/app_passthru_v2.c | 1 + usrp2/firmware/apps/factory_test.c | 1 + usrp2/firmware/apps/gen_eth_packets.c | 3 +-- usrp2/firmware/apps/gen_pause_frames.c | 4 ++-- usrp2/firmware/apps/mimo_app_common_v2.c | 1 + usrp2/firmware/apps/mimo_tx.c | 1 + usrp2/firmware/apps/mimo_tx_slave.c | 1 + usrp2/firmware/apps/rcv_eth_packets.c | 2 +- usrp2/firmware/apps/serdes_txrx.c | 1 + usrp2/firmware/apps/tx_standalone.c | 1 + usrp2/firmware/apps/txrx.c | 1 + 12 files changed, 13 insertions(+), 5 deletions(-) diff --git a/usrp2/firmware/apps/app_common_v2.c b/usrp2/firmware/apps/app_common_v2.c index 6d9606d45..1568ca70b 100644 --- a/usrp2/firmware/apps/app_common_v2.c +++ b/usrp2/firmware/apps/app_common_v2.c @@ -70,6 +70,7 @@ void set_reply_hdr(u2_eth_packet_t *reply_pkt, u2_eth_packet_t const *cmd_pkt) { reply_pkt->ehdr.dst = cmd_pkt->ehdr.src; + reply_pkt->ehdr.src = *ethernet_mac_addr(); reply_pkt->ehdr.ethertype = U2_ETHERTYPE; reply_pkt->thdr.flags = 0; reply_pkt->thdr.fifo_status = 0; // written by protocol engine diff --git a/usrp2/firmware/apps/app_passthru_v2.c b/usrp2/firmware/apps/app_passthru_v2.c index 660bcd774..406c56b3b 100644 --- a/usrp2/firmware/apps/app_passthru_v2.c +++ b/usrp2/firmware/apps/app_passthru_v2.c @@ -42,6 +42,7 @@ void set_reply_hdr(u2_eth_packet_t *reply_pkt, u2_eth_packet_t const *cmd_pkt) { reply_pkt->ehdr.dst = cmd_pkt->ehdr.src; + reply_pkt->ehdr.src = *ethernet_mac_addr(); reply_pkt->ehdr.ethertype = U2_ETHERTYPE; reply_pkt->thdr.flags = 0; reply_pkt->thdr.fifo_status = 0; // written by protocol engine diff --git a/usrp2/firmware/apps/factory_test.c b/usrp2/firmware/apps/factory_test.c index b4b44dbdb..a4bc06d58 100644 --- a/usrp2/firmware/apps/factory_test.c +++ b/usrp2/firmware/apps/factory_test.c @@ -170,6 +170,7 @@ start_rx_streaming_cmd(const u2_mac_addr_t *host, op_start_rx_streaming_t *p) u2_eth_packet_t pkt; memset(&pkt, 0, sizeof(pkt)); pkt.ehdr.dst = *host; + pkt.ehdr.src = *ethernet_mac_addr(); pkt.ehdr.ethertype = U2_ETHERTYPE; u2p_set_word0(&pkt.fixed, 0, 0); // DSP RX will fill in timestamp diff --git a/usrp2/firmware/apps/gen_eth_packets.c b/usrp2/firmware/apps/gen_eth_packets.c index 530f448ee..5cda5bb8e 100644 --- a/usrp2/firmware/apps/gen_eth_packets.c +++ b/usrp2/firmware/apps/gen_eth_packets.c @@ -104,8 +104,7 @@ init_packets(void) memset(&pkt, 0, sizeof(pkt)); pkt.ehdr.dst = dst_mac_addr; - // src address filled in by mac - + pkt.ehdr.src = *ethernet_mac_addr(); pkt.ehdr.ethertype = U2_ETHERTYPE; pkt.fixed.word0 = 0x01234567; pkt.fixed.timestamp = 0xffffffff; diff --git a/usrp2/firmware/apps/gen_pause_frames.c b/usrp2/firmware/apps/gen_pause_frames.c index 4eaebcc4a..8f2b2df03 100644 --- a/usrp2/firmware/apps/gen_pause_frames.c +++ b/usrp2/firmware/apps/gen_pause_frames.c @@ -132,9 +132,9 @@ init_packets(void) u2_eth_packet_t pkt __attribute__((aligned (4))); for (i = 0; i < 6; i++){ - pkt.ehdr.dst_addr[i] = dst_mac_addr[i]; - pkt.ehdr.src_addr[i] = 0; // filled in by mac + pkt.ehdr.dst.addr[i] = dst_mac_addr[i]; } + pkt.ehdr.src = *ethernet_mac_addr(); pkt.ehdr.ethertype = U2_ETHERTYPE; // fill ALL buffers for debugging diff --git a/usrp2/firmware/apps/mimo_app_common_v2.c b/usrp2/firmware/apps/mimo_app_common_v2.c index e5ab55fac..5dbecb0d0 100644 --- a/usrp2/firmware/apps/mimo_app_common_v2.c +++ b/usrp2/firmware/apps/mimo_app_common_v2.c @@ -67,6 +67,7 @@ void set_reply_hdr(u2_eth_packet_t *reply_pkt, u2_eth_packet_t const *cmd_pkt) { reply_pkt->ehdr.dst = cmd_pkt->ehdr.src; + reply_pkt->ehdr.src = *ethernet_mac_addr(); reply_pkt->ehdr.ethertype = U2_ETHERTYPE; reply_pkt->thdr.flags = 0; reply_pkt->thdr.fifo_status = 0; // written by protocol engine diff --git a/usrp2/firmware/apps/mimo_tx.c b/usrp2/firmware/apps/mimo_tx.c index 730433bf4..7fc7b486f 100644 --- a/usrp2/firmware/apps/mimo_tx.c +++ b/usrp2/firmware/apps/mimo_tx.c @@ -179,6 +179,7 @@ start_rx_streaming_cmd(const u2_mac_addr_t *host, op_start_rx_streaming_t *p) u2_eth_packet_t pkt; memset(&pkt, 0, sizeof(pkt)); pkt.ehdr.dst = *host; + pkt.ehdr.src = *ethernet_mac_addr(); pkt.ehdr.ethertype = U2_ETHERTYPE; u2p_set_word0(&pkt.fixed, 0, 0); // DSP RX will fill in timestamp diff --git a/usrp2/firmware/apps/mimo_tx_slave.c b/usrp2/firmware/apps/mimo_tx_slave.c index df7ddf9c4..e7da984c5 100644 --- a/usrp2/firmware/apps/mimo_tx_slave.c +++ b/usrp2/firmware/apps/mimo_tx_slave.c @@ -176,6 +176,7 @@ start_rx_streaming_cmd(const u2_mac_addr_t *host, op_start_rx_streaming_t *p) u2_eth_packet_t pkt; memset(&pkt, 0, sizeof(pkt)); pkt.ehdr.dst = *host; + pkt.ehdr.src = *ethernet_mac_addr(); pkt.ehdr.ethertype = U2_ETHERTYPE; u2p_set_word0(&pkt.fixed, 0, 0); // DSP RX will fill in timestamp diff --git a/usrp2/firmware/apps/rcv_eth_packets.c b/usrp2/firmware/apps/rcv_eth_packets.c index 92e41d92b..ec772ca75 100644 --- a/usrp2/firmware/apps/rcv_eth_packets.c +++ b/usrp2/firmware/apps/rcv_eth_packets.c @@ -135,7 +135,7 @@ init_packets(void) u2_eth_packet_t pkt __attribute__((aligned (4))); pkt.ehdr.dst = dst_mac_addr; - // src filled in by mac + pkt.ehdr.src = *ethernet_mac_addr(); pkt.ehdr.ethertype = U2_ETHERTYPE; // fill ALL buffers for debugging diff --git a/usrp2/firmware/apps/serdes_txrx.c b/usrp2/firmware/apps/serdes_txrx.c index 1becc205e..7816f7a65 100644 --- a/usrp2/firmware/apps/serdes_txrx.c +++ b/usrp2/firmware/apps/serdes_txrx.c @@ -168,6 +168,7 @@ start_rx_streaming_cmd(const u2_mac_addr_t *host, op_start_rx_streaming_t *p) u2_eth_packet_t pkt; memset(&pkt, 0, sizeof(pkt)); pkt.ehdr.dst = *host; + pkt.ehdr.src = *ethernet_mac_addr(); pkt.ehdr.ethertype = U2_ETHERTYPE; u2p_set_word0(&pkt.fixed, 0, 0); // DSP RX will fill in timestamp diff --git a/usrp2/firmware/apps/tx_standalone.c b/usrp2/firmware/apps/tx_standalone.c index 25ba8fd40..6350a6956 100644 --- a/usrp2/firmware/apps/tx_standalone.c +++ b/usrp2/firmware/apps/tx_standalone.c @@ -195,6 +195,7 @@ start_tx_transfers(void) u2_eth_packet_t pkt; memset(&pkt, 0, sizeof(pkt)); //pkt.ehdr.dst = *host; + pkt.ehdr.src = *ethernet_mac_addr(); pkt.ehdr.ethertype = U2_ETHERTYPE; u2p_set_word0(&pkt.fixed, U2P_TX_IMMEDIATE | U2P_TX_START_OF_BURST, 0); diff --git a/usrp2/firmware/apps/txrx.c b/usrp2/firmware/apps/txrx.c index 935e62a72..fc2f8a49e 100644 --- a/usrp2/firmware/apps/txrx.c +++ b/usrp2/firmware/apps/txrx.c @@ -168,6 +168,7 @@ start_rx_streaming_cmd(const u2_mac_addr_t *host, op_start_rx_streaming_t *p) u2_eth_packet_t pkt; memset(&pkt, 0, sizeof(pkt)); pkt.ehdr.dst = *host; + pkt.ehdr.src = *ethernet_mac_addr(); pkt.ehdr.ethertype = U2_ETHERTYPE; u2p_set_word0(&pkt.fixed, 0, 0); // DSP RX will fill in timestamp -- cgit