commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r10735 - in gnuradio/branches/developers/jcorgan/gpio2


From: jcorgan
Subject: [Commit-gnuradio] r10735 - in gnuradio/branches/developers/jcorgan/gpio2/usrp2: firmware/apps firmware/include host/apps host/include/usrp2 host/lib
Date: Wed, 1 Apr 2009 12:47:08 -0600 (MDT)

Author: jcorgan
Date: 2009-04-01 12:47:08 -0600 (Wed, 01 Apr 2009)
New Revision: 10735

Modified:
   
gnuradio/branches/developers/jcorgan/gpio2/usrp2/firmware/apps/app_common_v2.c
   
gnuradio/branches/developers/jcorgan/gpio2/usrp2/firmware/include/usrp2_eth_packet.h
   gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/apps/gpio.cc
   gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/include/usrp2/usrp2.h
   gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/lib/control.h
   gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/lib/usrp2.cc
   gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/lib/usrp2_impl.cc
   gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/lib/usrp2_impl.h
Log:
Firmware and libusrp2 code for GPIO operations.

Modified: 
gnuradio/branches/developers/jcorgan/gpio2/usrp2/firmware/apps/app_common_v2.c
===================================================================
--- 
gnuradio/branches/developers/jcorgan/gpio2/usrp2/firmware/apps/app_common_v2.c  
    2009-04-01 16:22:12 UTC (rev 10734)
+++ 
gnuradio/branches/developers/jcorgan/gpio2/usrp2/firmware/apps/app_common_v2.c  
    2009-04-01 18:47:08 UTC (rev 10735)
@@ -385,6 +385,26 @@
 }
 
 static size_t
+gpio_read_cmd(const op_gpio_t *p,
+             void *reply_payload, size_t reply_payload_space)
+{
+  op_gpio_read_reply_t *r = (op_gpio_read_reply_t *) reply_payload;
+  if (reply_payload_space < sizeof(*r))        // no room
+    return 0;
+
+ // Build reply subpacket
+
+  r->opcode = OP_GPIO_READ_REPLY;
+  r->len = sizeof(op_gpio_read_reply_t);
+  r->rid = p->rid;
+  r->ok = true;
+  r->mbz = 0;
+  r->value = hal_gpio_read(p->bank);
+
+  return r->len;
+}
+
+static size_t
 generic_reply(const op_generic_t *p,
              void *reply_payload, size_t reply_payload_space,
              bool ok)
@@ -509,6 +529,30 @@
       ok = sync_every_pps((op_generic_t *) payload);
       goto generic_reply;
 
+    case OP_GPIO_SET_DDR:
+      ok = true;
+      hal_gpio_set_ddr(((op_gpio_t *)payload)->bank, 
+                      ((op_gpio_t *)payload)->value, 
+                      ((op_gpio_t *)payload)->mask);
+      goto generic_reply;
+
+    case OP_GPIO_SET_SELS:
+      ok = true;
+      hal_gpio_set_sels(((op_gpio_set_sels_t *)payload)->bank,
+                       (char *)(&((op_gpio_set_sels_t *)payload)->sels));
+      goto generic_reply;
+
+    case OP_GPIO_READ:
+      subpktlen = gpio_read_cmd((op_gpio_t *) payload, reply_payload, 
reply_payload_space);
+      break;
+
+    case OP_GPIO_WRITE:
+      ok = true;
+      hal_gpio_write(((op_gpio_t *)payload)->bank, 
+                    ((op_gpio_t *)payload)->value, 
+                    ((op_gpio_t *)payload)->mask);
+      goto generic_reply;
+
     // Add new opcode handlers here
 
     generic_reply:

Modified: 
gnuradio/branches/developers/jcorgan/gpio2/usrp2/firmware/include/usrp2_eth_packet.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/gpio2/usrp2/firmware/include/usrp2_eth_packet.h
        2009-04-01 16:22:12 UTC (rev 10734)
+++ 
gnuradio/branches/developers/jcorgan/gpio2/usrp2/firmware/include/usrp2_eth_packet.h
        2009-04-01 18:47:08 UTC (rev 10735)
@@ -198,6 +198,14 @@
 #define OP_RESET_DB_REPLY            (OP_RESET_DB | OP_REPLY_BIT)
 #define OP_SYNC_EVERY_PPS            16
 #define OP_SYNC_EVERY_PPS_REPLY      (OP_SYNC_EVERY_PPS | OP_REPLY_BIT)
+#define OP_GPIO_SET_DDR              17
+#define OP_GPIO_SET_DDR_REPLY        (OP_GPIO_SET_DDR | OP_REPLY_BIT)
+#define OP_GPIO_SET_SELS             18
+#define OP_GPIO_SET_SELS_REPLY       (OP_GPIO_SET_SELS | OP_REPLY_BIT)
+#define OP_GPIO_READ                 19
+#define OP_GPIO_READ_REPLY           (OP_GPIO_READ | OP_REPLY_BIT)
+#define OP_GPIO_WRITE                20
+#define OP_GPIO_WRITE_REPLY          (OP_GPIO_WRITE | OP_REPLY_BIT)
 
 /*
  * All subpackets are a multiple of 4 bytes long.
@@ -425,6 +433,35 @@
 } _AL4 op_freq_t;
 
 /*
+ * Structures for commands in GPIO system
+ */
+typedef struct {
+  uint8_t       opcode;                // OP_GPIO_SET_DDR, OP_GPIO_WRITE
+  uint8_t       len;
+  uint8_t       rid;
+  uint8_t       bank;
+  uint16_t      value;
+  uint16_t      mask;
+} _AL4 op_gpio_t;
+
+typedef struct {
+  uint8_t       opcode;                // OP_GPIO_SET_SELS
+  uint8_t       len;
+  uint8_t       rid;
+  uint8_t       bank;
+  uint8_t       sels[16];
+} _AL4 op_gpio_set_sels_t;
+
+typedef struct {
+  uint8_t      opcode;         // OP_GPIO_READ_REPLY
+  uint8_t      len;
+  uint8_t      rid;
+  uint8_t      ok;
+  uint16_t      mbz;
+  uint16_t     value;
+} _AL4 op_gpio_read_reply_t;
+
+/*
  * ================================================================
  *             union of all of subpacket types
  * ================================================================
@@ -444,6 +481,9 @@
   op_peek_t                     op_peek;
   op_poke_t                     op_poke;
   op_freq_t                     op_freq;
+  op_gpio_t                     op_gpio;
+  op_gpio_set_sels_t            op_gpio_set_sels;
+  op_gpio_read_reply_t          op_gpio_read_reply;
 
 } u2_subpkt_t;
 

Modified: gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/apps/gpio.cc
===================================================================
--- gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/apps/gpio.cc  
2009-04-01 16:22:12 UTC (rev 10734)
+++ gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/apps/gpio.cc  
2009-04-01 18:47:08 UTC (rev 10735)
@@ -21,6 +21,7 @@
 #endif
 
 #include <usrp2/usrp2.h>
+#include <iostream>
 
 int
 main(int argc, char **argv)
@@ -29,19 +30,17 @@
 
   // Set io_tx[15] as FPGA output
   u2->set_gpio_ddr(usrp2::GPIO_TX_BANK, 0x8000, 0x8000);
-  
+
   // Set io_tx[15] under host sofware control
-  u2->set_gpio_src(usrp2::GPIO_TX_BANK, "s...............");
+  u2->set_gpio_sels(usrp2::GPIO_TX_BANK, "s...............");
 
   // Write pins
-  uint16_t v = 0x8000;
+  uint16_t v = 0x8765;
   u2->write_gpio(usrp2::GPIO_TX_BANK, v, 0x8000);
 
   // Read back
   v = 0;
   u2->read_gpio(usrp2::GPIO_TX_BANK, &v);
-
   printf("TX GPIO read: %04X\n", v);
-
   return 0;
 }

Modified: 
gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/include/usrp2/usrp2.h
===================================================================
--- gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/include/usrp2/usrp2.h 
2009-04-01 16:22:12 UTC (rev 10734)
+++ gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/include/usrp2/usrp2.h 
2009-04-01 18:47:08 UTC (rev 10735)
@@ -438,7 +438,7 @@
      * of the pin value.
      *
      * \param bank      GPIO_TX_BANK or GPIO_RX_BANK
-     * \param codes     Exactly 16 character MSB->LSB string. For each 
position:
+     * \param sels      Exactly 16 character MSB->LSB string. For each 
position:
      *                    '.' = ignore this bit, i.e., leave current value
      *                    'a' = Output ATR value
      *                    's' = Output host software controlled value
@@ -450,7 +450,7 @@
      * WARNING: Improper usage of this function may result in damage to the 
USRP2
      *
      */
-    bool set_gpio_src(int bank, std::string src);
+    bool set_gpio_sels(int bank, std::string sels);
 
     /*!
      * Set daughterboard GPIO pin values.

Modified: gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/lib/control.h
===================================================================
--- gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/lib/control.h 
2009-04-01 16:22:12 UTC (rev 10734)
+++ gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/lib/control.h 
2009-04-01 18:47:08 UTC (rev 10735)
@@ -99,6 +99,18 @@
     op_generic_t    eop;
   };
 
+  struct op_gpio_cmd {
+    u2_eth_packet_t h;
+    op_gpio_t       op;
+    op_generic_t    eop;
+  };
+
+  struct op_gpio_set_sels_cmd {
+    u2_eth_packet_t h;
+    op_gpio_set_sels_t op;
+    op_generic_t    eop;
+  };
+
   /*!
    * Control mechanism to allow API calls to block waiting for reply packets
    */    

Modified: gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/lib/usrp2.cc
===================================================================
--- gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/lib/usrp2.cc  
2009-04-01 16:22:12 UTC (rev 10734)
+++ gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/lib/usrp2.cc  
2009-04-01 18:47:08 UTC (rev 10735)
@@ -442,9 +442,9 @@
     return d_impl->set_gpio_ddr(bank, value, mask);
   }
 
-  bool usrp2::set_gpio_src(int bank, std::string src)
+  bool usrp2::set_gpio_sels(int bank, std::string src)
   {
-    return d_impl->set_gpio_src(bank, src);
+    return d_impl->set_gpio_sels(bank, src);
   }
 
   bool usrp2::write_gpio(int bank, uint16_t value, uint16_t mask)

Modified: 
gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/lib/usrp2_impl.cc
===================================================================
--- gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/lib/usrp2_impl.cc     
2009-04-01 16:22:12 UTC (rev 10734)
+++ gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/lib/usrp2_impl.cc     
2009-04-01 18:47:08 UTC (rev 10735)
@@ -1296,25 +1296,118 @@
   bool usrp2::impl::set_gpio_ddr(int bank, uint16_t value, uint16_t mask)
   {
     fprintf(stderr, "set_gpio_ddr: bank=%i, value=%04X, mask=%04X\n", bank, 
value, mask);
-    return true;
+    if (bank != GPIO_TX_BANK && bank != GPIO_RX_BANK)
+      throw std::runtime_error("set_gpio_ddr: bank must be one of GPIO_RX_BANK 
or GPIO_TX_BANK");
+
+    op_gpio_cmd cmd;
+    op_generic_t reply;
+
+    memset(&cmd, 0, sizeof(cmd));
+    init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1);
+    cmd.op.opcode = OP_GPIO_SET_DDR;
+    cmd.op.len = sizeof(cmd.op);
+    cmd.op.rid = d_next_rid++;
+    cmd.op.bank = static_cast<uint8_t>(bank);
+    cmd.op.value = htons(value);
+    cmd.op.mask = htons(mask);
+    cmd.eop.opcode = OP_EOP;
+    cmd.eop.len = sizeof(cmd.eop);
+    
+    pending_reply p(cmd.op.rid, &reply, sizeof(reply));
+    if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT))
+      return false;
+
+    bool success = (ntohx(reply.ok) == 1);
+    return success;
   }
 
-  bool usrp2::impl::set_gpio_src(int bank, std::string src)
+  bool usrp2::impl::set_gpio_sels(int bank, std::string sels)
   {
-    fprintf(stderr, "set_gpio_src: bank=%i, src=%s\n", bank, src.c_str());
-    return true;
+    fprintf(stderr, "set_gpio_sels: bank=%i, sels=%s\n", bank, sels.c_str());
+    if (bank != GPIO_TX_BANK && bank != GPIO_RX_BANK)
+      throw std::runtime_error("set_gpio_ddr: bank must be one of GPIO_RX_BANK 
or GPIO_TX_BANK");
+
+    if (sels.size() != 16)
+      throw std::runtime_error("set_gpio_sels: sels must be exactly 16 bytes");
+
+    op_gpio_set_sels_cmd cmd;
+    op_generic_t reply;
+
+    memset(&cmd, 0, sizeof(cmd));
+    init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1);
+    cmd.op.opcode = OP_GPIO_SET_SELS;
+    cmd.op.len = sizeof(cmd.op);
+    cmd.op.rid = d_next_rid++;
+    cmd.op.bank = static_cast<uint8_t>(bank);
+    memcpy(&cmd.op.sels, sels.c_str(), 16);
+    cmd.eop.opcode = OP_EOP;
+    cmd.eop.len = sizeof(cmd.eop);
+    
+    pending_reply p(cmd.op.rid, &reply, sizeof(reply));
+    if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT))
+      return false;
+
+    bool success = (ntohx(reply.ok) == 1);
+    return success;
   }
 
   bool usrp2::impl::write_gpio(int bank, uint16_t value, uint16_t mask)
   {
     fprintf(stderr, "  write_gpio: bank=%i, value=%04X, mask=%04X\n", bank, 
value, mask);
-    return true;
+    if (bank != GPIO_TX_BANK && bank != GPIO_RX_BANK)
+      throw std::runtime_error("set_gpio_ddr: bank must be one of GPIO_RX_BANK 
or GPIO_TX_BANK");
+
+    op_gpio_cmd cmd;
+    op_generic_t reply;
+
+    memset(&cmd, 0, sizeof(cmd));
+    init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1);
+    cmd.op.opcode = OP_GPIO_WRITE;
+    cmd.op.len = sizeof(cmd.op);
+    cmd.op.rid = d_next_rid++;
+    cmd.op.bank = static_cast<uint8_t>(bank);
+    cmd.op.value = htons(value);
+    cmd.op.mask = htons(mask);
+    cmd.eop.opcode = OP_EOP;
+    cmd.eop.len = sizeof(cmd.eop);
+    
+    pending_reply p(cmd.op.rid, &reply, sizeof(reply));
+    if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT))
+      return false;
+
+    bool success = (ntohx(reply.ok) == 1);
+    return success;
   }
 
   bool usrp2::impl::read_gpio(int bank, uint16_t *value)
   {
     fprintf(stderr, "   read_gpio: bank=%i, address@hidden", bank, value);
-    return true;
+    if (bank != GPIO_TX_BANK && bank != GPIO_RX_BANK)
+      throw std::runtime_error("set_gpio_ddr: bank must be one of GPIO_RX_BANK 
or GPIO_TX_BANK");
+
+    op_gpio_cmd cmd;
+    op_gpio_read_reply_t reply;
+
+    memset(&cmd, 0, sizeof(cmd));
+    init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1);
+    cmd.op.opcode = OP_GPIO_READ;
+    cmd.op.len = sizeof(cmd.op);
+    cmd.op.rid = d_next_rid++;
+    cmd.op.bank = static_cast<uint8_t>(bank);
+    cmd.op.value = 0; // not used
+    cmd.op.mask = 0;  // not used
+    cmd.eop.opcode = OP_EOP;
+    cmd.eop.len = sizeof(cmd.eop);
+    
+    pending_reply p(cmd.op.rid, &reply, sizeof(reply));
+    if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT))
+      return false;
+
+    bool success = (ntohx(reply.ok) == 1);
+    if (success && (value != NULL))
+      *value = ntohs(reply.value);
+
+    return success;
   }
 
 } // namespace usrp2

Modified: gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/lib/usrp2_impl.h
===================================================================
--- gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/lib/usrp2_impl.h      
2009-04-01 16:22:12 UTC (rev 10734)
+++ gnuradio/branches/developers/jcorgan/gpio2/usrp2/host/lib/usrp2_impl.h      
2009-04-01 18:47:08 UTC (rev 10735)
@@ -134,7 +134,7 @@
     int rx_decim() { return d_rx_decim; }
     bool set_rx_scale_iq(int scale_i, int scale_q);
     bool set_gpio_ddr(int bank, uint16_t value, uint16_t mask);
-    bool set_gpio_src(int bank, std::string src);
+    bool set_gpio_sels(int bank, std::string src);
     bool write_gpio(int bank, uint16_t value, uint16_t mask);
     bool read_gpio(int bank, uint16_t *value);
     bool start_rx_streaming(unsigned int channel, unsigned int 
items_per_frame);





reply via email to

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