commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: gnychis
Subject: [Commit-gnuradio] r6016 - gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband
Date: Wed, 18 Jul 2007 14:38:02 -0600 (MDT)

Author: gnychis
Date: 2007-07-18 14:38:02 -0600 (Wed, 18 Jul 2007)
New Revision: 6016

Modified:
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_inband_usb_packet.h
Log:
Functionality to build SPI write subpacket


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-18 20:24:53 UTC (rev 6015)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_inband_usb_packet.h
   2007-07-18 20:38:02 UTC (rev 6016)
@@ -120,6 +120,15 @@
   static const int CS_I2CREADBYTES_MASK = 0x7f;
   static const int CS_I2CREADBYTES_SHIFT = 24;
 
+  static const int CS_SPIOPT_MASK = 0xffff;
+  static const int CS_SPIOPT_SHIFT = 0;
+  static const int CS_SPIFORMAT_MASK = 0xff;
+  static const int CS_SPIFORMAT_SHIFT = 16;
+  static const int CS_SPIENABLES_MASK = 0xff;
+  static const int CS_SPIENABLES_SHIFT = 24;
+  static const int CS_SPIREAD_LEN = 7;
+
+
 public:
   
   void set_timestamp(uint32_t timestamp){
@@ -557,11 +566,8 @@
 
     int i2c_len = i2c_data_len + 2;
 
-    if((MAX_PAYLOAD - p_len) < (i2c_len + CS_FIXED_LEN)) {
-      std::cout << "(" << MAX_PAYLOAD << " - " << p_len << ") < ("
-                << i2c_len << " + " << CS_FIXED_LEN << ")\n";
+    if((MAX_PAYLOAD - p_len) < (i2c_len + CS_FIXED_LEN)) 
       return false;
-    }
     
     uint32_t word0 = 0;
     
@@ -590,6 +596,54 @@
     return true;
   }
 
+  bool cs_spi_write(long enables, long format, long opt_header_bytes, uint8_t 
*spi_data, long spi_data_len)
+  {
+    if(!align32())
+      return false;
+
+    int p_len = payload_len();
+
+    int spi_len = spi_data_len + 6;
+
+    if((MAX_PAYLOAD - p_len) < (spi_len + CS_FIXED_LEN))
+      return false;
+
+    uint32_t word = 0;
+
+    // First word contains the opcode and length, then mbz
+    word = (
+        ((OP_SPI_WRITE & CS_OPCODE_MASK) << CS_OPCODE_SHIFT)
+      | ((spi_len & CS_LEN_MASK) << CS_LEN_SHIFT)
+      );
+    uint32_t *payload = (uint32_t *) (d_payload + p_len);
+    *payload = host_to_usrp_u32(word);
+
+    payload += 1;
+
+    // Second word contains the enables, format, and optional tx bytes
+    word = 0;
+    word = (
+        ((enables & CS_SPIENABLES_MASK) << CS_SPIENABLES_SHIFT)
+      | ((format & CS_SPIFORMAT_MASK) << CS_SPIFORMAT_SHIFT)
+      | ((opt_header_bytes & CS_SPIOPT_MASK) << CS_SPIOPT_SHIFT)
+      );
+    payload = (uint32_t *) (d_payload + p_len);
+    *payload = host_to_usrp_u32(word);
+
+    payload += 1;
+    memcpy(payload, spi_data, spi_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 + spi_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





reply via email to

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