[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r5904 - gnuradio/branches/developers/gnychis/inband/us
From: |
gnychis |
Subject: |
[Commit-gnuradio] r5904 - gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband |
Date: |
Wed, 4 Jul 2007 11:35:18 -0600 (MDT) |
Author: gnychis
Date: 2007-07-04 11:35:18 -0600 (Wed, 04 Jul 2007)
New Revision: 5904
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
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx_stub.cc
Log:
Handling C/S I2C read subpacket creation.
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-07-04 17:10:23 UTC (rev 5903)
+++
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_inband_usb_packet.h
2007-07-04 17:35:18 UTC (rev 5904)
@@ -116,6 +116,10 @@
static const int CS_I2CADDR_MASK = 0x7f;
static const int CS_I2CADDR_SHIFT = 0;
+ static const int CS_I2CWRITE_LEN = 6;
+ static const int CS_I2CWRITEBYTES_MASK = 0x7f;
+ static const int CS_I2CWRITEBYTES_SHIFT = 24;
+
public:
void set_timestamp(uint32_t timestamp){
@@ -426,6 +430,9 @@
int i2c_len = data_len + 2; // 2 bytes between mbz and addr
+ if((MAX_PAYLOAD - p_len) < (i2c_len + CS_FIXED_LEN))
+ return false;
+
uint32_t word0 = 0;
word0 = (
@@ -453,6 +460,42 @@
return true;
}
+ bool cs_i2c_read(long rid, long i2c_addr, long n_bytes)
+ {
+ int p_len = payload_len();
+
+ if((MAX_PAYLOAD - p_len) < (CS_I2CWRITE_LEN + CS_FIXED_LEN))
+ return false;
+
+ uint32_t word0 = 0;
+
+ word0 = (
+ ((OP_READ_REG & CS_OPCODE_MASK) << CS_OPCODE_SHIFT)
+ | ((CS_I2CWRITE_LEN & CS_LEN_MASK) << CS_LEN_SHIFT)
+ | ((rid & CS_RID_MASK) << CS_RID_SHIFT)
+ | ((i2c_addr & CS_I2CADDR_MASK) << CS_I2CADDR_SHIFT)
+ );
+
+ uint32_t *payload = (uint32_t *) d_payload + p_len;
+ *payload = host_to_usrp_u32(word0);
+
+ // Jump a word and write the number of bytes to read
+ payload += 4;
+ uint32_t word1 =
+ (n_bytes & CS_I2CWRITEBYTES_MASK) << CS_I2CWRITEBYTES_SHIFT;
+ *payload = host_to_usrp_u32(word1);
+
+ // Update payload length
+ int h_flags = flags();
+ int h_chan = chan();
+ int h_tag = tag();
+ int h_payload_len = payload_len() + CS_FIXED_LEN + CS_I2CWRITE_LEN;
+
+ set_header(h_flags, h_chan, h_tag, h_payload_len);
+
+ return true;
+ }
+
// 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
@@ -551,8 +594,17 @@
}
case OP_I2C_READ:
- return PMT_NIL;
+ {
+ pmt_t rid = pmt_from_long((subpkt >> CS_RID_SHIFT) &
CS_RID_MASK);
+ pmt_t i2c_addr = pmt_from_long((subpkt >> CS_I2CADDR_SHIFT) &
CS_I2CADDR_MASK);
+
+ // The number of bytes is in the next word
+ uint32_t bytes = usrp_to_host_u32(*((uint32_t *)d_payload +
payload_offset + 4));
+ pmt_t i2c_bytes = pmt_from_long(bytes);
+ return pmt_list4(s_op_i2c_read, rid, i2c_addr, i2c_bytes);
+ }
+
case OP_SPI_WRITE:
return PMT_NIL;
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-07-04 17:10:23 UTC (rev 5903)
+++
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
2007-07-04 17:35:18 UTC (rev 5904)
@@ -100,6 +100,7 @@
// Initialize request ID's to 0
d_op_ping_fixed_rid = 0;
d_op_read_reg_rid = 0;
+ d_op_i2c_read_rid = 0;
for(int i=0; i < D_OP_PING_FIXED_MAX_RID; i++)
d_op_ping_fixed_owners.push_back(PMT_NIL);
@@ -107,6 +108,9 @@
for(int i=0; i < D_OP_READ_REG_MAX_RID; i++)
d_op_read_reg_owners.push_back(PMT_NIL);
+ for(int i=0; i < D_OP_I2C_READ_MAX_RID; i++)
+ d_op_i2c_read_owners.push_back(PMT_NIL);
+
//d_fake_rx=true;
}
@@ -824,8 +828,8 @@
//--------- I2C WRITE -----------//
if(pmt_eq(subp_cmd, s_op_i2c_write)) {
- long i2c_addr = pmt_to_long(pmt_nth(0, subp_data));
- pmt_t data = pmt_nth(1, subp_data);
+ long i2c_addr = pmt_to_long(pmt_nth(0, subp_data));
+ pmt_t data = pmt_nth(1, subp_data);
// Get a readable address to the data which also gives us the length
size_t data_len;
@@ -842,15 +846,42 @@
goto new_packet;
}
-
if(verbose)
std::cout << "[USRP_SERVER] Received I2C write";
}
+
+ //----------- I2C Read -------------//
+ if(pmt_eq(subp_cmd, s_op_i2c_read)) {
+
+ long i2c_addr = pmt_to_long(pmt_nth(1, subp_data));
+ long i2c_bytes = pmt_to_long(pmt_nth(2, subp_data));
+ long rid = d_op_i2c_read_rid++ % D_OP_I2C_READ_MAX_RID;
+ d_op_i2c_read_owners[rid] = port->port_symbol();
+
+ if(!pkt->cs_i2c_read(rid, i2c_addr, i2c_bytes))
+ {
+
+ d_cs_usrp->send(s_cmd_usrp_write,
+ pmt_list3(invocation_handle,
+ pmt_from_long(channel),
+ v_packet));
+
+ d_op_i2c_read_owners[rid] = PMT_NIL;
+ d_op_i2c_read_rid--;
+
+ goto new_packet;
+ }
+
+ if(verbose)
+ std::cout << "[USRP_SERVER] Received I2C read";
+ }
+
curr_subpkt++;
}
+
// If the current packets length is > 0, we know there are subpackets that
// need to be sent out still.
if(pkt->payload_len() > 0)
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-07-04 17:10:23 UTC (rev 5903)
+++
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h
2007-07-04 17:35:18 UTC (rev 5904)
@@ -67,7 +67,11 @@
static const long D_OP_READ_REG_MAX_RID = 64;
std::vector<pmt_t> d_op_read_reg_owners;
+ long d_op_i2c_read_rid;
+ static const long D_OP_I2C_READ_MAX_RID = 64;
+ std::vector<pmt_t> d_op_i2c_read_owners;
+
struct channel_info {
long assigned_capacity; // the capacity currently assignedby the channel
pmt_t owner; // port ID of the owner of the channel
Modified:
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx_stub.cc
===================================================================
---
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx_stub.cc
2007-07-04 17:10:23 UTC (rev 5903)
+++
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx_stub.cc
2007-07-04 17:35:18 UTC (rev 5904)
@@ -199,7 +199,7 @@
<< ")\n";
}
- //----------------- READ REG ------------------//
+ //----------------- DELAY ------------------//
if(pmt_eq(op_symbol, s_op_delay)) {
long ticks = pmt_to_long(pmt_nth(1, sub_packet));
@@ -241,6 +241,35 @@
<< ")\n";
}
+ //---------------- I2C WRITE ------------------//
+ if(pmt_eq(op_symbol, s_op_i2c_write)) {
+ pmt_t rid = pmt_nth(1, sub_packet);
+ pmt_t i2c_data = pmt_nth(2, sub_packet);
+
+ if(verbose)
+ std::cout << "[USRP_TX_STUB] Received i2c write command "
+ << "("
+ << "RID: " << rid
+ << ")\n";
+ }
+
+ //---------------- I2C READ ------------------//
+ if(pmt_eq(op_symbol, s_op_i2c_read)) {
+ pmt_t rid = pmt_nth(1, sub_packet);
+ pmt_t i2c_addr = pmt_nth(2, sub_packet);
+ pmt_t i2c_bytes = pmt_nth(3, sub_packet);
+
+ // FIXME: need to generate fake response
+
+ if(verbose)
+ std::cout << "[USRP_TX_STUB] Received i2c read "
+ << "("
+ << "RID: " << rid << ", "
+ << "Addr: " << i2c_addr << ", "
+ << "Bytes: " << i2c_bytes
+ << ")\n";
+ }
+
// Each subpacket has an unaccounted for 2 bytes which is the opcode
// and the length field
curr_payload += len + 2;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r5904 - gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband,
gnychis <=