commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r5900 - in gnuradio/branches/developers/gnychis/inband


From: gnychis
Subject: [Commit-gnuradio] r5900 - in gnuradio/branches/developers/gnychis/inband/usrp/host: apps lib/inband
Date: Tue, 3 Jul 2007 15:36:42 -0600 (MDT)

Author: gnychis
Date: 2007-07-03 15:36:41 -0600 (Tue, 03 Jul 2007)
New Revision: 5900

Modified:
   
gnuradio/branches/developers/gnychis/inband/usrp/host/apps/test_usrp_inband_rx.cc
   
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
Log:
Added code for handling an I2C write command and creates a subpacket for it,
though it is currently untested with QA code.


Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps/test_usrp_inband_rx.cc
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps/test_usrp_inband_rx.cc
   2007-07-03 19:12:07 UTC (rev 5899)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps/test_usrp_inband_rx.cc
   2007-07-03 21:36:41 UTC (rev 5900)
@@ -130,7 +130,7 @@
   // Specify the RBF to use
   pmt_dict_set(usrp_dict,
                pmt_intern("rbf"),
-               pmt_intern("last3.rbf"));
+               pmt_intern("usrp_inband_usb.rbf"));
 
   // Set TX and RX interpolations
   pmt_dict_set(usrp_dict,

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-03 19:12:07 UTC (rev 5899)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_inband_usb_packet.h
   2007-07-03 21:36:41 UTC (rev 5900)
@@ -113,6 +113,9 @@
   static const int CS_DELAY_MASK = 0xffff;
   static const int CS_DELAY_SHIFT = 0;
 
+  static const int CS_I2CADDR_MASK = 0x7f;
+  static const int CS_I2CADDR_SHIFT = 0;
+
 public:
   
   void set_timestamp(uint32_t timestamp){
@@ -417,6 +420,39 @@
     return true;
   }
 
+  bool cs_i2c_write(long i2c_addr, uint8_t *i2c_data, size_t data_len)
+  {
+    int p_len = payload_len();
+
+    int i2c_len = data_len + 2;   // 2 bytes between mbz and addr
+
+    uint32_t word0 = 0;
+
+    word0 = (
+        ((OP_I2C_WRITE & CS_OPCODE_MASK) << CS_OPCODE_SHIFT)
+      | ((i2c_len & CS_LEN_MASK) << CS_LEN_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 over the first word and write the data
+     // FIXME: Should the data be changed to usrp byte order?
+     payload += 4;
+     memcpy(payload, i2c_data, data_len);
+
+    // Update payload length
+    int h_flags = flags();
+    int h_chan = chan();
+    int h_tag = tag();
+    int h_payload_len = payload_len() + CS_FIXED_LEN + i2c_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
@@ -499,7 +535,13 @@
       }
 
       case OP_I2C_WRITE:
+      {
+        pmt_t i2c_addr    = pmt_from_long((subpkt >> CS_I2CADDR_SHIFT) & 
CS_I2CADDR_MASK);
+        
+        // FIXME: need code to make u8 vector of size after reading the length
+        // field then memcpy in to a writeable address and return the pmt
         return PMT_NIL;
+      }
 
       case OP_I2C_READ:
         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-03 19:12:07 UTC (rev 5899)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc 
    2007-07-03 21:36:41 UTC (rev 5900)
@@ -821,6 +821,32 @@
                   << ticks << " ticks\n";
     }
 
+    //--------- 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);
+
+      // Get a readable address to the data which also gives us the length
+      size_t data_len;
+      uint8_t *i2c_data = (uint8_t *) pmt_u8vector_writeable_elements(data, 
data_len);
+
+      // Make the USB packet
+      if(!pkt->cs_i2c_write(i2c_addr, i2c_data, data_len))
+      {
+        d_cs_usrp->send(s_cmd_usrp_write, 
+                        pmt_list3(invocation_handle, 
+                                  pmt_from_long(channel), 
+                                  v_packet));
+        
+        goto new_packet;
+      }
+      
+      
+      if(verbose)
+        std::cout << "[USRP_SERVER] Received I2C write";
+    }
+
     curr_subpkt++;
 
   }





reply via email to

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