commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r6244 - gnuradio/branches/developers/gnychis/inband/us


From: gnychis
Subject: [Commit-gnuradio] r6244 - gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband
Date: Fri, 31 Aug 2007 16:34:57 -0600 (MDT)

Author: gnychis
Date: 2007-08-31 16:34:57 -0600 (Fri, 31 Aug 2007)
New Revision: 6244

Modified:
   
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:
New usrp_server RID generation and user RID storage mechanism.  The user can now
use all 6-bits for the RID, the usrp_server will store the user RID locally and
replace it with a server generated RID for communication with the USRP, and then
on the response replace the server RID with the user RID.


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-08-31 19:09:38 UTC (rev 6243)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc 
    2007-08-31 22:34:57 UTC (rev 6244)
@@ -97,24 +97,9 @@
 
   d_rx_chan_mask = 0;
 
-  // Initialize request ID's to 0
-  d_op_ping_fixed_rid = 0;
-  d_op_read_reg_rid = 0;
-  d_op_i2c_read_rid = 0;
-  d_op_spi_read_rid = 0;
+  for(int i=0; i < D_MAX_RID; i++) 
+    d_rids.push_back(rid_info());
 
-  for(int i=0; i < D_OP_PING_FIXED_MAX_RID; i++)
-    d_op_ping_fixed_owners.push_back(PMT_NIL);
-
-  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);
-  
-  for(int i=0; i < D_OP_SPI_READ_MAX_RID; i++)
-    d_op_spi_read_owners.push_back(PMT_NIL);
-
   //d_fake_rx=true;
 }
 
@@ -712,22 +697,20 @@
       long pingval  = pmt_to_long(pmt_nth(1, subp_data));
 
       // 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.  The higher 3 bits will be the
-      // user specified RID value, and the lower 3 bits will be the USRP server
-      // marking.
-      long srid = d_op_ping_fixed_rid++ % D_OP_PING_FIXED_MAX_RID;
-      long rid = (
-          ((urid & 0x07) << 3)
-        | ((srid & 0x07)));
+      // what response back.  To allow a full 6-bits for an RID to the user, we
+      // keep a mapping and replace the RID's as the packets go in and out.  If
+      // there are no RID's available, the command is thrown away silently. 
+      long srid;
+      if((srid = next_rid()) == -1)
+        goto subpkt_bail;
 
       // 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[srid] = port->port_symbol();
-
+      // to send the request on any RX port they own. 
+      d_rids[srid].owner = port->port_symbol();
+      d_rids[srid].user_rid = urid;
+        
       // Adds a ping after the previous command in the pkt
-      if(!pkt->cs_ping(rid, pingval))
+      if(!pkt->cs_ping(srid, pingval))
       {
         d_cs_usrp->send(s_cmd_usrp_write, 
                         pmt_list3(invocation_handle, 
@@ -735,8 +718,7 @@
                                   v_packet));
 
         // Return the RID
-        d_op_ping_fixed_owners[srid] = PMT_NIL;
-        d_op_ping_fixed_rid--;
+        d_rids[srid].owner = PMT_NIL;
 
         goto new_packet;
       }
@@ -798,14 +780,14 @@
       long urid     = pmt_to_long(pmt_nth(0, subp_data));
       long reg_num  = pmt_to_long(pmt_nth(1, subp_data));
 
-      long srid = d_op_read_reg_rid++ % D_OP_READ_REG_MAX_RID;
-      long rid = (
-          ((urid & 0x07) << 3)
-        | ((srid & 0x07)));
+      long srid;
+      if((srid = next_rid()) == -1)
+        goto subpkt_bail;
 
-      d_op_read_reg_owners[srid] = port->port_symbol();
+      d_rids[srid].owner = port->port_symbol();
+      d_rids[srid].user_rid = urid;
 
-      if(!pkt->cs_read_reg(rid, reg_num))
+      if(!pkt->cs_read_reg(srid, reg_num))
       {
         d_cs_usrp->send(s_cmd_usrp_write, 
                         pmt_list3(invocation_handle, 
@@ -813,8 +795,7 @@
                                   v_packet));
 
         // Return the rid
-        d_op_read_reg_owners[srid] = PMT_NIL;
-        d_op_read_reg_rid--;
+        d_rids[srid].owner = PMT_NIL;
         
         goto new_packet;
       }
@@ -878,14 +859,14 @@
       long i2c_addr   = pmt_to_long(pmt_nth(1, subp_data));
       long i2c_bytes  = pmt_to_long(pmt_nth(2, subp_data));
 
-      long srid = d_op_i2c_read_rid++ % D_OP_I2C_READ_MAX_RID;
-      long rid = (
-          ((urid & 0x07) << 3)
-        | ((srid & 0x07)));
+      long srid;
+      if((srid = next_rid()) == -1)
+        goto subpkt_bail;
+      
+      d_rids[srid].owner = port->port_symbol();
+      d_rids[srid].user_rid = urid;
 
-      d_op_i2c_read_owners[srid] = port->port_symbol();
-
-      if(!pkt->cs_i2c_read(rid, i2c_addr, i2c_bytes))
+      if(!pkt->cs_i2c_read(srid, i2c_addr, i2c_bytes))
       {
         
         d_cs_usrp->send(s_cmd_usrp_write, 
@@ -893,8 +874,7 @@
                                   pmt_from_long(channel), 
                                   v_packet));
 
-        d_op_i2c_read_owners[srid] = PMT_NIL;
-        d_op_i2c_read_rid--;
+        d_rids[srid].owner = PMT_NIL;
 
         goto new_packet;
       }
@@ -939,16 +919,15 @@
       long opt      = pmt_to_long(pmt_nth(3, subp_data));
       long n_bytes  = pmt_to_long(pmt_nth(4, subp_data));
       
-      // Generate an RID for the READ
-      long srid = d_op_spi_read_rid % D_OP_SPI_READ_MAX_RID;
-      long rid = (
-          ((urid & 0x07) << 3)
-        | ((srid & 0x07)));
-      
-      d_op_spi_read_owners[srid] = port->port_symbol();
+      long srid;
+      if((srid = next_rid()) == -1)
+        goto subpkt_bail;
 
+      d_rids[srid].owner = port->port_symbol();
+      d_rids[srid].user_rid = urid;
+
       // Make the USB packet
-      if(!pkt->cs_spi_read(rid, enables, format, opt, n_bytes))
+      if(!pkt->cs_spi_read(srid, enables, format, opt, n_bytes))
       {
         d_cs_usrp->send(s_cmd_usrp_write, 
                         pmt_list3(invocation_handle, 
@@ -956,8 +935,7 @@
                                   v_packet));
         
         // Return the rid
-        d_op_spi_read_owners[srid] = PMT_NIL;
-        d_op_spi_read_rid--;
+        d_rids[srid].owner = PMT_NIL;
 
         goto new_packet;
       }
@@ -966,6 +944,7 @@
         std::cout << "[USRP_SERVER] Received SPI read\n";
     }
 
+  subpkt_bail:
     curr_subpkt++;
 
   }
@@ -1154,11 +1133,10 @@
     //----------------- PING RESPONSE ------------------//
     if(pmt_eq(op_symbol, s_op_ping_fixed_reply)) {
 
-      long rid      = pmt_to_long(pmt_nth(1, sub_packet));
+      long srid     = pmt_to_long(pmt_nth(1, sub_packet));
       pmt_t pingval = pmt_nth(2, sub_packet);
 
-      long urid = (rid >> 3) & 0x7;
-      long srid = rid & 0x7;
+      long urid = d_rids[srid].user_rid;
       
       if(verbose)
         std::cout << "[USRP_SERVER] Found ping response "
@@ -1169,10 +1147,10 @@
                   << ")\n";
       
       // Do some bounds checking incase of bogus/corrupt responses
-      if(srid > D_OP_PING_FIXED_MAX_RID)
+      if(srid > D_MAX_RID)
         return;
 
-      pmt_t owner = d_op_ping_fixed_owners[srid];
+      pmt_t owner = d_rids[srid].owner;
 
       // FIXME: should be 1 response for all subpackets here ?
       if((port = tx_port_index(owner)) != -1)
@@ -1188,12 +1166,11 @@
     //----------------- READ REG RESPONSE ------------------//
     else if(pmt_eq(op_symbol, s_op_read_reg_reply)) {
 
-      long rid      = pmt_to_long(pmt_nth(1, sub_packet));
+      long srid     = pmt_to_long(pmt_nth(1, sub_packet));
       pmt_t reg_num = pmt_nth(2, sub_packet);
       pmt_t reg_val = pmt_nth(3, sub_packet);
 
-      long urid = (rid >> 3) & 0x7;
-      long srid = rid & 0x7;
+      long urid = d_rids[srid].user_rid;
       
       if(verbose)
         std::cout << "[USRP_SERVER] Found read register response "
@@ -1205,10 +1182,10 @@
                   << ")\n";
 
       // Do some bounds checking to avoid seg faults
-      if(srid > D_OP_READ_REG_MAX_RID)
+      if(srid > D_MAX_RID)
         return;
       
-      pmt_t owner = d_op_read_reg_owners[srid];
+      pmt_t owner = d_rids[srid].owner;
 
       // FIXME: should be 1 response for all subpackets here ?
       if((port = tx_port_index(owner)) != -1)
@@ -1225,12 +1202,11 @@
     //------------------ I2C READ REPLY -------------------//
     else if(pmt_eq(op_symbol, s_op_i2c_read_reply)) {
 
-      long rid        = pmt_to_long(pmt_nth(1, sub_packet));
+      long srid       = pmt_to_long(pmt_nth(1, sub_packet));
       pmt_t i2c_addr  = pmt_nth(2, sub_packet);
       pmt_t i2c_data  = pmt_nth(3, sub_packet);
 
-      long urid = (rid >> 3) & 0x7;
-      long srid = rid & 0x7;
+      long urid = d_rids[srid].user_rid;
 
       if(verbose)
         std::cout << "[USRP_SERVER] Found i2c read reply "
@@ -1242,10 +1218,10 @@
                   << ")\n";
       
       // Do some bounds checking to avoid seg faults
-      if(srid > D_OP_I2C_READ_MAX_RID)
+      if(srid > D_MAX_RID)
         return;
 
-      pmt_t owner = d_op_i2c_read_owners[srid];
+      pmt_t owner = d_rids[srid].owner;
 
       if((port = tx_port_index(owner)) != -1)
         d_tx[port]->send(s_response_from_control_channel,
@@ -1261,11 +1237,10 @@
     //------------------ SPI READ REPLY -------------------//
     else if(pmt_eq(op_symbol, s_op_spi_read_reply)) {
       
-      long rid        = pmt_to_long(pmt_nth(1, sub_packet));
+      long srid       = pmt_to_long(pmt_nth(1, sub_packet));
       pmt_t spi_data  = pmt_nth(2, sub_packet);
       
-      long urid = (rid >> 3) & 0x7;
-      long srid = rid & 0x7;
+      long urid = d_rids[srid].user_rid;
 
       if(verbose)
         std::cout << "[USRP_SERVER] Found SPI read reply "
@@ -1276,10 +1251,10 @@
                   << ")\n";
 
       // Bounds check the RID
-      if(srid > D_OP_SPI_READ_MAX_RID)
+      if(srid > D_MAX_RID)
         return;
 
-      pmt_t owner = d_op_spi_read_owners[srid];
+      pmt_t owner = d_rids[srid].owner;
 
       if((port = tx_port_index(owner)) != -1)
         d_tx[port]->send(s_response_from_control_channel,
@@ -1363,4 +1338,16 @@
   return true;
 }
 
+// Goes through the vector of RIDs and retreieves an
+// available one for use
+long
+usrp_server::next_rid()
+{
+  for(int i = 0; i < D_MAX_RID; i++)
+    if(pmt_eqv(d_rids[i].owner, PMT_NIL))
+      return i;
+
+  return -1;
+}
+
 REGISTER_MBLOCK_CLASS(usrp_server);

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-08-31 19:09:38 UTC (rev 6243)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h  
    2007-08-31 22:34:57 UTC (rev 6244)
@@ -58,23 +58,20 @@
   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 = 8;
-  std::vector<pmt_t> d_op_ping_fixed_owners;
-  
-  long d_op_read_reg_rid;
-  static const long D_OP_READ_REG_MAX_RID = 8;
-  std::vector<pmt_t> d_op_read_reg_owners;
+  // Keep track of the request IDs
+  struct rid_info {
+    pmt_t owner;
+    long user_rid;
 
-  long d_op_i2c_read_rid;
-  static const long D_OP_I2C_READ_MAX_RID = 8;
-  std::vector<pmt_t> d_op_i2c_read_owners;
+    rid_info() {
+      owner = PMT_NIL;
+      user_rid = 0;
+    }
+  };
 
-  long d_op_spi_read_rid;
-  static const long D_OP_SPI_READ_MAX_RID = 8;
-  std::vector<pmt_t> d_op_spi_read_owners;
-
+  static const long D_MAX_RID = 64;
+  std::vector<rid_info> d_rids;
+  
   struct channel_info {
     long assigned_capacity;   // the capacity currently assignedby the channel
     pmt_t owner;              // port ID of the owner of the channel
@@ -123,6 +120,7 @@
   void handle_response_usrp_read(pmt_t data);
   bool check_valid(mb_port_sptr port, long channel, std::vector<struct 
channel_info> &chan_info, pmt_t signal_info);
   void parse_control_pkt(pmt_t invocation_handle, transport_pkt *pkt);
+  long next_rid();
 };
 
 #endif /* INCLUDED_USRP_SERVER_H */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]