altos: clear CPU port 1 interrupt flag when handled
[fw/altos] / src / ao_btm.c
index 355c3ca4f6e3529307dcc3393d7ea08d071e1441..a9306c101f715c40b703e39900007c837abf3100 100644 (file)
 
 #include "ao.h"
 
+#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
+
 int8_t                 ao_btm_stdio;
 __xdata uint8_t                ao_btm_connected;
 
@@ -166,6 +181,19 @@ ao_btm(void)
         */
        ao_delay(AO_SEC_TO_TICKS(3));
 
+#if BT_LINK_ON_P1
+       if ((P1DIR & (1 << 6)) == 0)
+               ao_panic(AO_PANIC_BT);
+       if ((P1DIR & (1 << 7)) != 0)
+               ao_panic(AO_PANIC_BT);
+       if ((P0SEL & ((1 << 5) | (1 << 4) | (1 << 3) | (1 << 2))) !=
+           ((1 << 5) | (1 << 4) | (1 << 3) | (1 << 2)))
+               ao_panic(AO_PANIC_BT);
+#endif
+#if HAS_BEEP
+       ao_beep_for(AO_BEEP_MID, AO_MS_TO_TICKS(200));
+#endif
+
        /*
         * The first time we connect, the BTM-180 comes up at 19200 baud.
         * After that, it will remember and come up at 57600 baud. So, see
@@ -208,21 +236,6 @@ ao_btm(void)
 
 __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
 {
@@ -240,7 +253,13 @@ ao_btm_check_link() __critical
 
 void
 ao_btm_isr(void)
+#if BT_LINK_ON_P1
+       __interrupt 15
+#endif
 {
+#if BT_LINK_ON_P1
+       P1IF = 0;
+#endif
        if (BT_PIFG & (1 << BT_LINK_PIN_INDEX)) {
                ao_btm_check_link();
                ao_wakeup(&ao_btm_connected);
@@ -254,6 +273,15 @@ ao_btm_init (void)
        ao_serial_init();
        ao_serial_set_speed(AO_SERIAL_SPEED_19200);
 
+#if BT_LINK_ON_P1
+       /*
+        * Configure ser reset line
+        */
+
+       P1_6 = 0;
+       P1DIR |= (1 << 6);
+#endif
+
        /*
         * Configure link status line
         */