changeset 1353:c93f753dce60

Fix for LEDs
author gthomas
date Fri, 07 Nov 2003 17:34:08 +0000
parents 5853b9c80558
children c8903ba86828
files packages/hal/powerpc/rattler/current/ChangeLog packages/hal/powerpc/rattler/current/src/hal_aux.c
diffstat 2 files changed, 27 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/packages/hal/powerpc/rattler/current/ChangeLog
+++ b/packages/hal/powerpc/rattler/current/ChangeLog
@@ -1,3 +1,8 @@
+2003-11-07  Gary Thomas  <gary@mlbassoc.com>
+
+	* src/hal_aux.c (_rattler_leds): New function.  Also set up I/O bits
+	properly to support LEDs.
+
 2003-10-22  Gary Thomas  <gary@mlbassoc.com>
 
 	* cdl/hal_powerpc_rattler.cdl: Add CDL to identify board model.
--- a/packages/hal/powerpc/rattler/current/src/hal_aux.c
+++ b/packages/hal/powerpc/rattler/current/src/hal_aux.c
@@ -158,16 +158,16 @@ hal_platform_init(void)
     //        +--------------------------
     //       +---------------------------
     //      +----------------------------
-    //     +-----------------------------
-    //    +------------------------------
-    //   +-------------------------------
+    //     +-----------------------------  LED2
+    //    +------------------------------  LED1
+    //   +-------------------------------  LED0
     //   ++++ ++++ ++++ ++AA AACC CC++ ++BB DDBB
     //   0000 0000 0000 0011 1111 1100 0011 1111 PAR
     //   0000 0000 0000 0000 0000 0000 0011 1111 SOR
     //   0000 0000 0000 0000 0011 1100 0000 1100 DIR
     IMM->io_regs[PORT_A].ppar = 0x0003FC3F;
     IMM->io_regs[PORT_A].psor = 0x0000003F;
-    IMM->io_regs[PORT_A].pdir = 0x00003C0C;
+    IMM->io_regs[PORT_A].pdir = 0xE0003C0C;
     IMM->io_regs[PORT_A].podr = 0x00000000;
 
     // Port B
@@ -423,4 +423,22 @@ void
     while (1) ;
 }
 
+//
+// Display a value in the LEDs
+// Note: the values used/returned by this function are positive
+// i.e. a value of 0 is all LEDs off, 0x7 is all on
+//
+#define LED_SHIFT 29  // LEDs are in bits A0..A2
+#define LED_MASK   7  // 3 bits total
+int
+_rattler_leds(int val)
+{
+    volatile t_PQ2IMM  *IMM = (volatile t_PQ2IMM *)CYGARC_IMM_BASE;
+    unsigned int old_val = ~(IMM->io_regs[PORT_A].pdat >> LED_SHIFT) & LED_MASK;
+    unsigned int new_val = (old_val & ~(LED_MASK<<LED_SHIFT)) | ((~val&LED_MASK)<<LED_SHIFT);
+
+    IMM->io_regs[PORT_A].pdat = new_val;
+    return old_val;
+}
+
 // EOF hal_aux.c