altos/telefire: Add siren/strobe support
authorKeith Packard <keithp@keithp.com>
Wed, 10 Oct 2012 21:28:07 +0000 (14:28 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 10 Oct 2012 21:28:07 +0000 (14:28 -0700)
This also involved hacking up the code to allow for non-zero offsets
for the pad firing and continuity pins.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/cc1111/ao_adc.c
src/drivers/ao_pad.c
src/telefire-v0.1/ao_pins.h

index f7b52281ae799855008bdcb1d296779e23e5024e..f80004104130c324c19cd4e68884edc4b5a208a4 100644 (file)
 volatile __xdata struct ao_data        ao_data_ring[AO_DATA_RING];
 volatile __data uint8_t                ao_data_head;
 
+#ifndef AO_ADC_FIRST_PIN
+#define AO_ADC_FIRST_PIN       0
+#endif
+
 void
 ao_adc_poll(void)
 {
@@ -29,7 +33,7 @@ ao_adc_poll(void)
 # ifdef TELENANO_V_0_1
        ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | 1;
 # else
-       ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | 0;
+       ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | AO_ADC_FIRST_PIN;
 # endif
 #endif
 }
@@ -141,7 +145,7 @@ ao_adc_isr(void) __interrupt 1
 #endif /* telemini || telenano */
 
 #ifdef TELEFIRE_V_0_1
-       a = (uint8_t __xdata *) (&ao_data_ring[ao_data_head].adc.sense[0] + sequence);
+       a = (uint8_t __xdata *) (&ao_data_ring[ao_data_head].adc.sense[0] + sequence - AO_ADC_FIRST_PIN);
        a[0] = ADCL;
        a[1] = ADCH;
        if (sequence < 5)
index 120ce5398cfdd4162a187c1c9277bffb667ae43f..36905136394d2e0494283fdc64e7ac7d1bc74abb 100644 (file)
@@ -39,25 +39,63 @@ static __pdata uint8_t      ao_pad_debug;
 #define FLUSHD()    
 #endif
 
+static void
+ao_siren(uint8_t v)
+{
+#ifdef AO_SIREN
+       ao_gpio_set(AO_SIREN_PORT, AO_SIREN_PIN, AO_SIREN, v);
+#else
+       ao_beep(v ? AO_BEEP_MID : 0);
+#endif
+}
+
+static void
+ao_strobe(uint8_t v)
+{
+#ifdef AO_STROBE
+       ao_gpio_set(AO_STROBE_PORT, AO_STROBE_PIN, AO_STROBE, v);
+#endif
+}
+
 static void
 ao_pad_run(void)
 {
+       uint8_t pins;
+
        for (;;) {
                while (!ao_pad_ignite)
                        ao_sleep(&ao_pad_ignite);
                /*
                 * Actually set the pad bits
                 */
-               AO_PAD_PORT = (AO_PAD_PORT & (~AO_PAD_ALL_PINS)) | ao_pad_ignite;
+               pins = 0;
+#if AO_PAD_NUM > 0
+               if (ao_pad_ignite & (1 << 0))
+                       pins |= (1 << AO_PAD_PIN_0);
+#endif
+#if AO_PAD_NUM > 1
+               if (ao_pad_ignite & (1 << 1))
+                       pins |= (1 << AO_PAD_PIN_1);
+#endif
+#if AO_PAD_NUM > 2
+               if (ao_pad_ignite & (1 << 2))
+                       pins |= (1 << AO_PAD_PIN_2);
+#endif
+#if AO_PAD_NUM > 3
+               if (ao_pad_ignite & (1 << 3))
+                       pins |= (1 << AO_PAD_PIN_3);
+#endif
+               AO_PAD_PORT = (AO_PAD_PORT & (~AO_PAD_ALL_PINS)) | pins;
                while (ao_pad_ignite) {
                        ao_pad_ignite = 0;
+
                        ao_delay(AO_PAD_FIRE_TIME);
                }
                AO_PAD_PORT &= ~(AO_PAD_ALL_PINS);
        }
 }
 
-#define AO_PAD_ARM_BEEP_INTERVAL       200
+#define AO_PAD_ARM_SIREN_INTERVAL      200
 
 static void
 ao_pad_monitor(void)
@@ -143,21 +181,23 @@ ao_pad_monitor(void)
                        ao_pad_armed = 0;
 
                if (ao_pad_armed) {
+                       ao_strobe(1);
                        if (sample & 2)
-                               ao_beep(AO_BEEP_HIGH);
+                               ao_siren(1);
                        else
-                               ao_beep(AO_BEEP_LOW);
+                               ao_siren(0);
                        beeping = 1;
                } else if (query.arm_status == AO_PAD_ARM_STATUS_ARMED && !beeping) {
                        if (arm_beep_time == 0) {
-                               arm_beep_time = AO_PAD_ARM_BEEP_INTERVAL;
+                               arm_beep_time = AO_PAD_ARM_SIREN_INTERVAL;
                                beeping = 1;
-                               ao_beep(AO_BEEP_HIGH);
+                               ao_siren(1);
                        }
                        --arm_beep_time;
                } else if (beeping) {
                        beeping = 0;
-                       ao_beep(0);
+                       ao_siren(0);
+                       ao_strobe(0);
                }
        }
 }
@@ -184,7 +224,6 @@ ao_pad(void)
        int16_t time_difference;
        int8_t  ret;
 
-       ao_beep_for(AO_BEEP_MID, AO_MS_TO_TICKS(200));
        ao_pad_box = 0;
        ao_led_set(0);
        ao_led_on(AO_LED_POWER);
@@ -207,7 +246,7 @@ ao_pad(void)
                                break;
                        }
 
-                       if (command.channels & ~(AO_PAD_ALL_PINS))
+                       if (command.channels & ~(AO_PAD_ALL_CHANNELS))
                                break;
 
                        time_difference = command.tick - ao_time();
@@ -348,6 +387,12 @@ ao_pad_init(void)
 #endif
 #if AO_PAD_NUM > 3
        ao_enable_output(AO_PAD_PORT, AO_PAD_PIN_3, AO_PAD_3, 0);
+#endif
+#ifdef AO_STROBE
+       ao_enable_output(AO_STROBE_PORT, AO_STROBE_PIN, AO_STROBE, 0);
+#endif
+#ifdef AO_SIREN
+       ao_enable_output(AO_SIREN_PORT, AO_SIREN_PIN, AO_SIREN, 0);
 #endif
        ao_cmd_register(&ao_pad_cmds[0]);
        ao_add_task(&ao_pad_task, ao_pad, "pad listener");
index eecf783e50790e29c7b20993134d85bb7eb1380e..774d59f45631ba155424df7a93f34ab48af58a76 100644 (file)
@@ -38,8 +38,8 @@
 #define PACKET_HAS_MASTER      0
 #define PACKET_HAS_SLAVE       0
 
-#define AO_LED_CONTINUITY(c)   (1 << (c))
-#define AO_LED_CONTINUITY_MASK (0xf)
+#define AO_LED_CONTINUITY(c)   (1 << ((c) + 2))
+#define AO_LED_CONTINUITY_MASK (0xc)
 #define AO_LED_RX              0x10
 #define AO_LED_TX              0x20
 #define AO_LED_ARMED           0x40
 #define AO_PCA9922_CS_PIN      4
 #define AO_PCA9922_CS          P1_4
 
-#define AO_PAD_NUM             4
+#define AO_PAD_NUM             2
 #define        AO_PAD_PORT             P1
 #define AO_PAD_DIR             P1DIR
-#define AO_PAD_PIN_0           0
-#define AO_PAD_0               P1_0
-#define AO_PAD_PIN_1           1
-#define AO_PAD_1               P1_1
-#define AO_PAD_PIN_2           2
-#define AO_PAD_2               P1_2
-#define AO_PAD_PIN_3           3
-#define AO_PAD_3               P1_3
-#define AO_PAD_ALL_PINS                ((1 << AO_PAD_PIN_0) | (1 << AO_PAD_PIN_1) | (1 << AO_PAD_PIN_2) | (1 << AO_PAD_PIN_3))
+
+#define AO_PAD_PIN_0           2
+#define AO_PAD_0               P1_2
+#define AO_PAD_ADC_0           2
+
+#define AO_PAD_PIN_1           3
+#define AO_PAD_1               P1_3
+#define AO_PAD_ADC_1           3
+
+#define AO_PAD_ALL_PINS                ((1 << AO_PAD_PIN_0) | (1 << AO_PAD_PIN_1))
+#define AO_PAD_ALL_CHANNELS    ((1 << 0) | (1 << 1))
+
+#define AO_SIREN_PORT          P1
+#define AO_SIREN_DIR           P1DIR
+#define AO_SIREN_PIN           0
+#define AO_SIREN               P1_0
+
+#define AO_STROBE_PORT         P1
+#define AO_STROBE_DIR          P1DIR
+#define AO_STROBE_PIN          1
+#define AO_STROBE              P1_1
 
 /* test these values with real igniters */
 #define AO_PAD_RELAY_CLOSED    3524
 #define AO_PAD_NO_IGNITER      16904
 #define AO_PAD_GOOD_IGNITER    22514
 
+#define AO_PAD_ADC_PYRO                4
+#define AO_PAD_ADC_BATT                5
+
+#define AO_ADC_FIRST_PIN       2
+
 struct ao_adc {
-       int16_t         sense[4];
+       int16_t         sense[AO_PAD_NUM];
        int16_t         pyro;
        int16_t         batt;
 };
 
 #define AO_ADC_DUMP(p)                                                 \
-       printf ("tick: %5u 0: %5d 1: %5d 2: %5d 3: %5d pyro: %5d batt %5d\n", \
+       printf ("tick: %5u 0: %5d 1: %5d pyro: %5d batt %5d\n",         \
                (p)->tick,                                              \
                (p)->adc.sense[0],                                      \
                (p)->adc.sense[1],                                      \
-               (p)->adc.sense[2],                                      \
-               (p)->adc.sense[3],                                      \
                (p)->adc.pyro,                                          \
                (p)->adc.batt)
 
-#define AO_ADC_PINS    ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5))
+#define AO_ADC_PINS    ((1 << AO_PAD_ADC_0) | (1 << AO_PAD_ADC_1) | (1 << AO_PAD_ADC_PYRO) | (1 << AO_PAD_ADC_BATT))
 
 #endif /* _AO_PINS_H_ */