[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r5871 - gnuradio/branches/developers/gnychis/inband/us
From: |
gnychis |
Subject: |
[Commit-gnuradio] r5871 - gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband |
Date: |
Thu, 28 Jun 2007 12:24:43 -0600 (MDT) |
Author: gnychis
Date: 2007-06-28 12:24:43 -0600 (Thu, 28 Jun 2007)
New Revision: 5871
Modified:
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_inband_usb_packet.h
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h
Log:
Basic code to read USB control block responses.
Will be tested by faking responses in usrp_rx_stub, but needs to have
communication with the TX stub to get the proper RID.
Modified:
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_inband_usb_packet.h
===================================================================
---
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_inband_usb_packet.h
2007-06-28 18:16:29 UTC (rev 5870)
+++
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_inband_usb_packet.h
2007-06-28 18:24:43 UTC (rev 5871)
@@ -24,7 +24,10 @@
#include <usrp_bytesex.h>
#include <mb_mblock.h>
+#include <pmt.h>
+#include <symbols_usrp_low_level_cs.h>
+
static const int USB_PKT_SIZE = 512; // bytes
static const int MAX_PAYLOAD = USB_PKT_SIZE-2*sizeof(uint32_t);
@@ -92,6 +95,7 @@
static const int CS_RID_SHIFT = 10;
static const int CS_PINGVAL_MASK = 0x3ff;
+ static const int CS_PINGVAL_SHIFT = 0x0;
public:
@@ -200,6 +204,82 @@
return ping;
}
+ // The following method takes an offset within the packet payload to extract
+ // a control/status subpacket and construct a pmt response which includes the
+ // proper signal and arguments specified by usrp-low-level-cs. The USRP
+ // server could therefore use this to read subpackets and pass them responses
+ // back up to the application. It's arguable that only reply packets should
+ // be parsed here, however we parse others for use in debugging or failure
+ // reporting on the transmit side of packets.
+ pmt_t read_subpacket(int payload_offset) {
+
+ uint32_t subpkt = usrp_to_host_u32(*((uint32_t *)d_payload +
payload_offset));
+ uint32_t opcode = (subpkt & CS_OPCODE_MASK) << CS_OPCODE_SHIFT;
+ uint32_t len = (subpkt & CS_LENGTH_MASK) << CS_LENGTH_SHIFT;
+
+ pmt_t response;
+
+ switch(opcode) {
+
+ case OP_PING_FIXED_REPLY:
+ {
+ pmt_t rid = pmt_from_long((subpkt & CS_RID_MASK) << CS_RID_SHIFT);
+ pmt_t pingval = pmt_from_long((subpkt & CS_PINGVAL_MASK) <<
CS_PINGVAL_SHIFT);
+ response = pmt_list3(s_op_ping_fixed_reply, rid, pingval);
+ break;
+ }
+
+ case OP_READ_REG_REPLY:
+ return PMT_NIL;
+
+ case OP_I2C_READ_REPLY:
+ return PMT_NIL;
+
+ case OP_SPI_READ_REPLY:
+ return PMT_NIL;
+
+ case OP_PING_FIXED:
+ return PMT_NIL;
+
+ case OP_WRITE_REG:
+ return PMT_NIL;
+
+ case OP_WRITE_REG_MASKED:
+ return PMT_NIL;
+
+ case OP_READ_REG:
+ return PMT_NIL;
+
+ case OP_I2C_WRITE:
+ return PMT_NIL;
+
+ case OP_I2C_READ:
+ return PMT_NIL;
+
+ case OP_SPI_WRITE:
+ return PMT_NIL;
+
+ case OP_SPI_READ:
+ return PMT_NIL;
+
+ case OP_DELAY:
+ return PMT_NIL;
+
+ default:
+ return PMT_NIL;
+
+ }
+
+ return response;
+ }
+
+ // Takes an offset to the beginning of a subpacket and extracts the
+ // length of the subpacket
+ int cs_len(int payload_offset) {
+ uint32_t subpkt = usrp_to_host_u32(*((uint32_t *)d_payload +
payload_offset));
+ return (subpkt & CS_LENGTH_MASK) << CS_LENGTH_SHIFT;
+ }
+
};
#endif
Modified:
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
===================================================================
---
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
2007-06-28 18:16:29 UTC (rev 5870)
+++
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
2007-06-28 18:24:43 UTC (rev 5871)
@@ -97,6 +97,12 @@
d_rx_chan_mask = 0;
+ // Initialize request ID's to 0
+ d_op_ping_fixed_rid = 0;
+
+ for(int i=0; i < D_OP_PING_FIXED_MAX_RID; i++)
+ d_op_ping_fixed_owners[i] = PMT_NIL;
+
//d_fake_rx=true;
}
@@ -684,9 +690,18 @@
//--------- PING FIXED --------------//
if(pmt_eq(subp_cmd, s_op_ping_fixed)) {
- long rid = 0;
long pingval = 0;
+ // USRP server sets request ID's to keep track of which application gets
+ // what response back. We do not handle wrap around, if we wrap before
we
+ // got responses then they will be lost.
+ long rid = d_op_ping_fixed_rid++ % D_OP_PING_FIXED_MAX_RID;
+
+ // We use a vector to store the owner of the ping request and will use it
+ // to send the request on any RX port they own. There is currently no
way
+ // for the requester to specify the RX port to receive the response on.
+ d_op_ping_fixed_owners[rid] = port->port_symbol();
+
// Adds a ping after the previous command in the pkt
pkt->cs_ping(rid, pingval);
@@ -816,30 +831,30 @@
long payload_len = pkt->payload_len();
long port;
+ // Ignore packets which seem to have incorrect size or size 0
+ if(payload_len > pkt->max_payload() || payload_len == 0)
+ return;
+
// If the packet is a C/S packet, parse it separately
if(channel == 0x1f) {
parse_control_pkt(pkt);
return;
}
- // Ignore packets which seem to have incorrect size or size 0
- if(payload_len > pkt->max_payload() || payload_len == 0)
- return;
-
if((port = rx_port_index(d_chaninfo_rx[channel].owner)) == -1)
return; // Don't know where to send the sample... possibility on abrupt
close
-
+
pmt_t v_samples = pmt_make_u8vector(payload_len, 0);
uint8_t *samples = pmt_u8vector_writeable_elements(v_samples, ignore);
memcpy(samples, pkt->payload(), payload_len);
- d_cs->send(s_response_recv_raw_samples,
- pmt_list5(invocation_handle,
- status,
- v_samples,
- pmt_from_long(pkt->timestamp()),
- PMT_NIL));
+ d_rx[port]->send(s_response_recv_raw_samples,
+ pmt_list5(invocation_handle,
+ status,
+ v_samples,
+ pmt_from_long(pkt->timestamp()),
+ PMT_NIL));
return;
}
@@ -848,8 +863,39 @@
{
long payload_len = pkt->payload_len();
+ unsigned char *payload = pkt->payload();
+ long curr_payload = 0;
long port;
+ // We dispatch based on the control packet type, however we can extract the
+ // opcode and the length immediately which is consistent in all responses.
+ //
+ // Since each control packet can have multiple responses, we keep reading the
+ // lengths of each subpacket until we reach the payload length.
+ while(curr_payload < payload_len) {
+
+ pmt_t sub_packet = pkt->read_subpacket(curr_payload);
+ pmt_t op_symbol = pmt_nth(0, sub_packet);
+
+ int len = pkt->cs_len(curr_payload);
+
+ //----------------- PING RESPONSE ------------------//
+ if(pmt_eq(op_symbol, s_op_ping_fixed_reply)) {
+
+ pmt_t rid = pmt_nth(1, sub_packet);
+ pmt_t pingval = pmt_nth(2, sub_packet);
+ pmt_t owner = d_op_ping_fixed_owners[pmt_to_long(rid)];
+
+ // FIXME: is the response really supposed to come back on the TX port?
+ if((port = tx_port_index(owner)) != -1)
+ d_tx[port]->send(op_symbol, pmt_list2(rid, pingval));
+
+ }
+
+ // Each subpacket has an unaccounted for 2 bytes which is the opcode
+ // and the length field
+ curr_payload += len + 2;
+ }
}
void
Modified:
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h
===================================================================
---
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h
2007-06-28 18:16:29 UTC (rev 5870)
+++
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h
2007-06-28 18:24:43 UTC (rev 5871)
@@ -58,6 +58,12 @@
long d_ntx_chan;
long d_nrx_chan;
+ // USRP server assigns and keeps track of request IDs.
+ long d_op_ping_fixed_rid;
+ static const long D_OP_PING_FIXED_MAX_RID = 6;
+ std::vector<pmt_t> d_op_ping_fixed_owners;
+
+
struct channel_info {
long assigned_capacity; // the capacity currently assignedby the channel
pmt_t owner; // port ID of the owner of the channel
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r5871 - gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband,
gnychis <=