altos: Add custom panic noise for self-test failures
authorKeith Packard <keithp@keithp.com>
Sat, 1 Sep 2012 02:01:21 +0000 (21:01 -0500)
committerKeith Packard <keithp@keithp.com>
Sat, 1 Sep 2012 02:01:21 +0000 (21:01 -0500)
Make it easier to tell which component is failing self test

Signed-off-by: Keith Packard <keithp@keithp.com>
src/core/ao.h
src/core/ao_panic.c
src/drivers/ao_cc1120.c
src/drivers/ao_mpu6000.c
src/drivers/ao_ms5607.c

index 66c0881f7862cb01a949c4e8d1cca9be5d0da804..4f4779ecdef288d79ea920970e5a7bc67ed4eeec 100644 (file)
@@ -115,7 +115,10 @@ ao_start_scheduler(void);
 #define AO_PANIC_BT            11      /* Communications with bluetooth device failed */
 #define AO_PANIC_STACK         12      /* Stack overflow */
 #define AO_PANIC_SPI           13      /* SPI communication failure */
-#define AO_PANIC_SELF_TEST     14      /* Self test failure */
+#define AO_PANIC_SELF_TEST_CC1120      0x40 | 1        /* Self test failure */
+#define AO_PANIC_SELF_TEST_HMC5883     0x40 | 2        /* Self test failure */
+#define AO_PANIC_SELF_TEST_MPU6000     0x40 | 3        /* Self test failure */
+#define AO_PANIC_SELF_TEST_MS5607      0x40 | 4        /* Self test failure */
 
 /* Stop the operating system, beeping and blinking the reason */
 void
index 25dc145eea69ecd9c3b7320bee32a4b43b3f67f7..524330447b248b550c5ba068d2c3d74316a63ac9 100644 (file)
@@ -65,7 +65,15 @@ ao_panic(uint8_t reason)
 #ifdef SDCC
 #pragma disable_warning 126
 #endif
-               for (n = 0; n < reason; n++) {
+               if (reason & 0x40) {
+                       ao_led_on(AO_LED_RED);
+                       ao_beep(AO_BEEP_HIGH);
+                       ao_panic_delay(40);
+                       ao_led_off(AO_LED_RED);
+                       ao_beep(AO_BEEP_OFF);
+                       ao_panic_delay(10);
+               }
+               for (n = 0; n < (reason & 0x3f); n++) {
                        ao_led_on(AO_LED_RED);
                        ao_beep(AO_BEEP_MID);
                        ao_panic_delay(10);
index 4df931b5094b0349b9c903f768170dc21553f89f..2f9c296f25372926f99a92e88cf8ab593ad8a539 100644 (file)
@@ -1028,12 +1028,12 @@ ao_radio_init(void)
 
        AO_CC1120_SPI_CS_PORT->bsrr = ((uint32_t) (1 << AO_CC1120_SPI_CS_PIN));
        for (i = 0; i < 10000; i++) {
-               if ((SPI_2_GPIO->idr & (1 << SPI_2_MISO)) == 0)
+               if ((SPI_2_PORT->idr & (1 << SPI_2_MISO_PIN)) == 0)
                        break;
        }
        AO_CC1120_SPI_CS_PORT->bsrr = (1 << AO_CC1120_SPI_CS_PIN);
        if (i == 10000)
-               ao_panic(AO_PANIC_SELF_TEST);
+               ao_panic(AO_PANIC_SELF_TEST_CC1120);
 
        /* Enable the EXTI interrupt for the appropriate pin */
        ao_enable_port(AO_CC1120_INT_PORT);
index e8c80f12428943bf365977a03dbc9695656003ac..b3e284e0bfb2988f0ff7e40e525c4a892a736704 100644 (file)
@@ -225,7 +225,7 @@ ao_mpu6000_setup(void)
        errors += ao_mpu6000_gyro_check(normal_mode.gyro_z, test_mode.gyro_z, "z");
 
        if (errors)
-               ao_panic(AO_PANIC_SELF_TEST);
+               ao_panic(AO_PANIC_SELF_TEST_MPU6000);
 
        /* Filter to about 100Hz, which also sets the gyro rate to 1000Hz */
        ao_mpu6000_reg_write(MPU6000_CONFIG,
index ec0d2202216c3fcff64f06a950de37b47d5fd4d8..704b4583ec9e973848b82e22e1a9ef52aed82241 100644 (file)
@@ -27,12 +27,12 @@ static uint8_t                      ms5607_configured;
 static void
 ao_ms5607_start(void) {
        ao_spi_get(AO_MS5607_SPI_INDEX,AO_SPI_SPEED_FAST);
-       stm_gpio_set(AO_MS5607_CS_GPIO, AO_MS5607_CS, 0);
+       stm_gpio_set(AO_MS5607_CS_PORT, AO_MS5607_CS_PIN, 0);
 }
 
 static void
 ao_ms5607_stop(void) {
-       stm_gpio_set(AO_MS5607_CS_GPIO, AO_MS5607_CS, 1);
+       stm_gpio_set(AO_MS5607_CS_PORT, AO_MS5607_CS_PIN, 1);
        ao_spi_put(AO_MS5607_SPI_INDEX);
 }
 
@@ -92,7 +92,7 @@ ao_ms5607_prom_read(struct ao_ms5607_prom *prom)
                printf ("MS5607 PROM CRC error (computed %x actual %x)\n",
                        crc, (((uint8_t *) prom)[15] & 0xf));
                flush();
-               ao_panic(AO_PANIC_SELF_TEST);
+//             ao_panic(AO_PANIC_SELF_TEST_MS5607);
        }
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -120,7 +120,7 @@ static uint8_t      ao_ms5607_done;
 static void
 ao_ms5607_isr(void)
 {
-       ao_exti_disable(AO_MS5607_MISO_GPIO, AO_MS5607_MISO);
+       ao_exti_disable(AO_MS5607_MISO_PORT, AO_MS5607_MISO_PIN);
        ao_ms5607_done = 1;
        ao_wakeup(&ao_ms5607_done);
 }
@@ -135,7 +135,7 @@ ao_ms5607_get_sample(uint8_t cmd) {
 
        ao_ms5607_start();
        ao_spi_send(&cmd, 1, AO_MS5607_SPI_INDEX);
-       ao_exti_enable(AO_MS5607_MISO_GPIO, AO_MS5607_MISO);
+       ao_exti_enable(AO_MS5607_MISO_PORT, AO_MS5607_MISO_PIN);
 #if AO_MS5607_PRIVATE_PINS
        ao_spi_put(AO_MS5607_SPI_INDEX);
 #endif
@@ -144,7 +144,7 @@ ao_ms5607_get_sample(uint8_t cmd) {
                ao_sleep(&ao_ms5607_done);
        sei();
 #if AO_MS5607_PRIVATE_PINS
-       stm_gpio_set(AO_MS5607_CS_GPIO, AO_MS5607_CS, 1);
+       stm_gpio_set(AO_MS5607_CS_PORT, AO_MS5607_CS_PIN, 1);
 #else
        ao_ms5607_stop();
 #endif
@@ -235,13 +235,14 @@ ao_ms5607_info(void)
 static void
 ao_ms5607_dump(void)
 {
-       struct ao_data  sample;
+       struct ao_ms5607_sample sample;
        struct ao_ms5607_value value;
 
-       ao_data_get(&sample);
-       ao_ms5607_convert(&sample.ms5607_raw, &value);
-       printf ("Pressure:    %8u %8d\n", sample.ms5607_raw.pres, value.pres);
-       printf ("Temperature: %8u %8d\n", sample.ms5607_raw.temp, value.temp);
+       ao_ms5607_setup();
+       ao_ms5607_sample(&sample);
+       ao_ms5607_convert(&sample, &value);
+       printf ("Pressure:    %8u %8d\n", sample.pres, value.pres);
+       printf ("Temperature: %8u %8d\n", sample.temp, value.temp);
        printf ("Altitude: %ld\n", ao_pa_to_altitude(value.pres));
 }
 
@@ -255,24 +256,24 @@ ao_ms5607_init(void)
 {
        ms5607_configured = 0;
        ao_cmd_register(&ao_ms5607_cmds[0]);
-       ao_spi_init_cs(AO_MS5607_CS_GPIO, (1 << AO_MS5607_CS));
+       ao_spi_init_cs(AO_MS5607_CS_PORT, (1 << AO_MS5607_CS_PIN));
 
-       ao_add_task(&ao_ms5607_task, ao_ms5607, "ms5607");
+//     ao_add_task(&ao_ms5607_task, ao_ms5607, "ms5607");
 
        /* Configure the MISO pin as an interrupt; when the
         * conversion is complete, the MS5607 will raise this
         * pin as a signal
         */
-       ao_exti_setup(AO_MS5607_MISO_GPIO,
-                     AO_MS5607_MISO,
+       ao_exti_setup(AO_MS5607_MISO_PORT,
+                     AO_MS5607_MISO_PIN,
                      AO_EXTI_MODE_RISING,
                      ao_ms5607_isr);
 
        /* Reset the pin from INPUT to ALTERNATE so that SPI works
         * This needs an abstraction at some point...
         */
-       stm_moder_set(AO_MS5607_MISO_GPIO,
-                     AO_MS5607_MISO,
+       stm_moder_set(AO_MS5607_MISO_PORT,
+                     AO_MS5607_MISO_PIN,
                      STM_MODER_ALTERNATE);
 }