altos: Fix BT link status pin for real TBT hardware
authorKeith Packard <keithp@keithp.com>
Sat, 7 May 2011 04:13:19 +0000 (21:13 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 7 May 2011 04:13:19 +0000 (21:13 -0700)
The prototype used P2_1, while the real hardware uses P1_7. Lots of
defines to make this work...

Signed-off-by: Keith Packard <keithp@keithp.com>
src/ao_btm.c
src/ao_pins.h

index db0ff6b09371508a67c806856e7ec21b4c2b27c3..355c3ca4f6e3529307dcc3393d7ea08d071e1441 100644 (file)
@@ -208,26 +208,44 @@ ao_btm(void)
 
 __xdata struct ao_task ao_btm_task;
 
 
 __xdata struct ao_task ao_btm_task;
 
+#if BT_LINK_ON_P2
+#define BT_PICTL_ICON  PICTL_P2ICON
+#define BT_PIFG                P2IFG
+#define BT_PDIR                P2DIR
+#define BT_PINP                P2INP
+#define BT_IEN2_PIE    IEN2_P2IE
+#endif
+#if BT_LINK_ON_P1
+#define BT_PICTL_ICON  PICTL_P1ICON
+#define BT_PIFG                P1IFG
+#define BT_PDIR                P1DIR
+#define BT_PINP                P1INP
+#define BT_IEN2_PIE    IEN2_P1IE
+#endif
+
 void
 ao_btm_check_link() __critical
 {
 void
 ao_btm_check_link() __critical
 {
-       if (P2_1) {
+       /* Check the pin and configure the interrupt detector to wait for the
+        * pin to flip the other way
+        */
+       if (BT_LINK_PIN) {
                ao_btm_connected = 0;
                ao_btm_connected = 0;
-               PICTL |= PICTL_P2ICON;
+               PICTL |= BT_PICTL_ICON;
        } else {
                ao_btm_connected = 1;
        } else {
                ao_btm_connected = 1;
-               PICTL &= ~PICTL_P2ICON;
+               PICTL &= ~BT_PICTL_ICON;
        }
 }
 
 void
 ao_btm_isr(void)
 {
        }
 }
 
 void
 ao_btm_isr(void)
 {
-       if (P2IFG & (1 << 1)) {
+       if (BT_PIFG & (1 << BT_LINK_PIN_INDEX)) {
                ao_btm_check_link();
                ao_wakeup(&ao_btm_connected);
        }
                ao_btm_check_link();
                ao_wakeup(&ao_btm_connected);
        }
-       P2IFG = 0;
+       BT_PIFG = 0;
 }
 
 void
 }
 
 void
@@ -240,14 +258,26 @@ ao_btm_init (void)
         * Configure link status line
         */
 
         * Configure link status line
         */
 
-       /* Set P2_1 to input, pull-down */
-       P2DIR &= ~(1 << 1);
-       P2INP |= P2INP_MDP2_1_TRISTATE;
+       /* Set pin to input */
+       BT_PDIR &= ~(1 << BT_LINK_PIN_INDEX);
+
+       /* Set pin to tri-state */
+       BT_PINP |= (1 << BT_LINK_PIN_INDEX);
 
 
-       /* Enable P2 interrupts */
-       IEN2 |= IEN2_P2IE;
+       /* Enable interrupts */
+       IEN2 |= BT_IEN2_PIE;
+
+       /* Check current pin state */
        ao_btm_check_link();
        ao_btm_check_link();
+
+#if BT_LINK_ON_P2
+       /* Eable the pin interrupt */
        PICTL |= PICTL_P2IEN;
        PICTL |= PICTL_P2IEN;
+#endif
+#if BT_LINK_ON_P1
+       /* Enable pin interrupt */
+       P1IEN |= (1 << BT_LINK_PIN_INDEX);
+#endif
 
        ao_add_task(&ao_btm_task, ao_btm, "bt");
 }
 
        ao_add_task(&ao_btm_task, ao_btm, "bt");
 }
index 4c31f75551498db6168748a22ec2dca6aee4c2ec..21b99027096b535f3ab7a27aeb09a6f77fffa623 100644 (file)
        #define SPI_CS_ON_P1            1
        #define SPI_CS_ON_P0            0
        #define HAS_IGNITE              0
        #define SPI_CS_ON_P1            1
        #define SPI_CS_ON_P0            0
        #define HAS_IGNITE              0
+       #define BT_LINK_ON_P2           1
+       #define BT_LINK_ON_P1           0
+       #define BT_LINK_PIN_INDEX       7
+       #define BT_LINK_PIN             P2_1
 #endif
 
 #if defined(TELEBT_V_0_1)
 #endif
 
 #if defined(TELEBT_V_0_1)
        #define M25_MAX_CHIPS           1
        #define HAS_ACCEL               0
        #define HAS_IGNITE              0
        #define M25_MAX_CHIPS           1
        #define HAS_ACCEL               0
        #define HAS_IGNITE              0
+       #define BT_LINK_ON_P2           0
+       #define BT_LINK_ON_P1           1
+       #define BT_LINK_PIN_INDEX       7
+       #define BT_LINK_PIN             P1_7
 #endif
 
 #if DBG_ON_P1
 #endif
 
 #if DBG_ON_P1