commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r6746 - gnuradio/branches/developers/matt/u2f/firmware


From: eb
Subject: [Commit-gnuradio] r6746 - gnuradio/branches/developers/matt/u2f/firmware
Date: Tue, 30 Oct 2007 15:05:42 -0600 (MDT)

Author: eb
Date: 2007-10-30 15:05:41 -0600 (Tue, 30 Oct 2007)
New Revision: 6746

Modified:
   gnuradio/branches/developers/matt/u2f/firmware/hal_io.c
   gnuradio/branches/developers/matt/u2f/firmware/hal_io.h
   gnuradio/branches/developers/matt/u2f/firmware/memory_map.h
   gnuradio/branches/developers/matt/u2f/firmware/u2_init.c
Log:
refactored to use new gpio direction fields

Modified: gnuradio/branches/developers/matt/u2f/firmware/hal_io.c
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/hal_io.c     2007-10-30 
20:01:10 UTC (rev 6745)
+++ gnuradio/branches/developers/matt/u2f/firmware/hal_io.c     2007-10-30 
21:05:41 UTC (rev 6746)
@@ -24,6 +24,55 @@
 #include "hal_io.h"
 #include "memory_map.h"
 
+unsigned int
+hal_gpio_mode_mask(int high_bitno, int low_bitno, int mode)
+{
+  mode &= 0x3;
+  unsigned int t = 0;
+
+  int i;
+  for (i = 15; i >= 0; i--){
+    t <<= 2;
+    if (i <= high_bitno && i >= low_bitno)
+      t |= mode;
+  }
+  return t;
+}
+
+void
+hal_gpio_set_rx_mode(int high_bitno, int low_bitno, int mode)
+{
+  unsigned mask = hal_gpio_mode_mask(high_bitno, low_bitno, 0x3);
+  unsigned val  = hal_gpio_mode_mask(high_bitno, low_bitno, mode);
+  gpio_base->rx_mode = (gpio_base->rx_mode & ~mask) | (val & mask);
+}
+
+void
+hal_gpio_set_tx_mode(int high_bitno, int low_bitno, int mode)
+{
+  unsigned mask = hal_gpio_mode_mask(high_bitno, low_bitno, 0x3);
+  unsigned val  = hal_gpio_mode_mask(high_bitno, low_bitno, mode);
+  gpio_base->tx_mode = (gpio_base->tx_mode & ~mask) | (val & mask);
+}
+
+// in top 16-bits of io reg
+void
+hal_gpio_set_tx(int value, int mask)
+{
+  value <<= 16;
+  mask <<= 16;
+  gpio_base->io = (gpio_base->io & ~mask) | (value & mask);
+}
+
+// in bottom 16-bits of io reg
+void
+hal_gpio_set_rx(int value, int mask)
+{
+  value &= 0xffff;
+  mask  &= 0xffff;
+  gpio_base->io = (gpio_base->io & ~mask) | (value & mask);
+}
+
 // ================================================================
 //                             primitives
 // ================================================================
@@ -47,18 +96,19 @@
 void
 hal_io_init(void)
 {
-  // make high 9 bits of tx daugtherboard outputs
-  gpio_base->ddr_tx = (gpio_base->ddr_tx & ~0xff80) | 0xff80;
-  gpio_base->io_tx =  (gpio_base->io_tx  & ~0xff80);;  // init to zero
+  // make high 9 bits of tx daughterboard outputs
+  hal_gpio_set_tx_mode(15, 7, GPIOM_OUTPUT);
+
+  // and set them to zero
+  hal_gpio_set_tx(0x0000, 0xff80);
 }
 
 // %c
 inline void 
 hal_putc(unsigned char s)
 {
-  int t = gpio_base->io_tx & 0x7ff;    // keep bottom bits
-  gpio_base->io_tx = (s << 8) | W | t;
-  gpio_base->io_tx = t;
+  hal_gpio_set_tx((s << 8) | W, 0xff80);
+  hal_gpio_set_tx(0, 0xff80);
 }
 
 void

Modified: gnuradio/branches/developers/matt/u2f/firmware/hal_io.h
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/hal_io.h     2007-10-30 
20:01:10 UTC (rev 6745)
+++ gnuradio/branches/developers/matt/u2f/firmware/hal_io.h     2007-10-30 
21:05:41 UTC (rev 6746)
@@ -30,3 +30,10 @@
 void hal_puthex_nl(unsigned long x);
 void hal_newline();
 void hal_finish();
+
+
+void hal_gpio_set_rx_modes(int high_bitno, int low_bitno, int mode);
+void hal_gpio_set_tx_modes(int high_bitno, int low_bitno, int mode);
+
+void hal_gpio_set_tx(int value, int mask);
+void hal_gpio_set_rx(int value, int mask);

Modified: gnuradio/branches/developers/matt/u2f/firmware/memory_map.h
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/memory_map.h 2007-10-30 
20:01:10 UTC (rev 6745)
+++ gnuradio/branches/developers/matt/u2f/firmware/memory_map.h 2007-10-30 
21:05:41 UTC (rev 6746)
@@ -115,12 +115,17 @@
 #define GPIO_BASE 0xA000
 
 typedef struct {
-  volatile unsigned short      ddr_rx; // OE mask: 1 = output
-  volatile unsigned short      ddr_tx; // OE mask: 1 = output
-  volatile unsigned short      io_rx;
-  volatile unsigned short      io_tx;
+  volatile unsigned int                io;       // tx data in high 16, rx in 
low 16
+  volatile unsigned int                rx_mode;  // 16 2-bit fields
+  volatile unsigned int                tx_mode;  // 16 2-bit fields
 } gpio_regs_t;
 
+// each 2-bit mode field is layed out this way
+#define GPIOM_INPUT    0 // pin is an input, readable by proc through io reg
+#define        GPIOM_OUTPUT    1 // pin is an output, writable by proc through 
io reg
+#define        GPIOM_FPGA_0    2 // pin is an output, writable from FPGA fabric
+#define        GPIOM_FPGA_1    3 // pin is an output, writable from FPGA fabric
+
 #define gpio_base ((gpio_regs_t *) GPIO_BASE)
 
 ///////////////////////////////////////////////////

Modified: gnuradio/branches/developers/matt/u2f/firmware/u2_init.c
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/u2_init.c    2007-10-30 
20:01:10 UTC (rev 6745)
+++ gnuradio/branches/developers/matt/u2f/firmware/u2_init.c    2007-10-30 
21:05:41 UTC (rev 6746)
@@ -13,6 +13,11 @@
 int 
 u2_init(void)
 {
+  // Set GPIOs to inputs
+  hal_gpio_set_rx_mode(15, 0, GPIOM_INPUT);
+  hal_gpio_set_tx_mode(15, 0, GPIOM_INPUT);
+  gpio_base->io  = 0x00000000;
+
   hal_io_init();
 
   hal_puts("u2_init\n");
@@ -30,11 +35,6 @@
   // Allow for clock switchover
   output_regs->clk_ctrl = 0x1C;
 
-  // Set GPIOs to outputs
-  gpio_base->ddr_rx = 0xffff;
-  gpio_base->ddr_tx = 0xffff;
-  gpio_base->io_rx  = 0xDEAD;
-  gpio_base->io_tx  = 0xBEEF;
 
   // Enable ADCs
   output_regs->adc_ctrl = 0; // Power up and enable outputs





reply via email to

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