altos: Record all failed sensors and report status at power up
authorKeith Packard <keithp@keithp.com>
Tue, 16 Jul 2019 18:12:49 +0000 (11:12 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 16 Jul 2019 18:12:49 +0000 (11:12 -0700)
Use DATA bits to mark which sensors have failed, then report that in
beeps at startup time to help diagnose hardware failures while still
allowing the board to be used over USB.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/drivers/ao_adxl375.c
src/drivers/ao_mma655x.c
src/drivers/ao_mpu6000.c
src/drivers/ao_mpu9250.c
src/drivers/ao_ms5607.c
src/kernel/ao_data.h
src/kernel/ao_report.c

index 66d39ff915b625c6f87acac828594ff1f8a6ad4b..4f6b816948709632e5462e1d8d0460a0f3911b49 100644 (file)
@@ -143,7 +143,7 @@ ao_adxl375_setup(void)
 
        uint8_t devid = ao_adxl375_reg_read(AO_ADXL375_DEVID);
        if (devid != AO_ADXL375_DEVID_ID)
 
        uint8_t devid = ao_adxl375_reg_read(AO_ADXL375_DEVID);
        if (devid != AO_ADXL375_DEVID_ID)
-               ao_sensor_errors = 1;
+               AO_SENSOR_ERROR(AO_DATA_ADXL375);
 
        /* Set the data rate */
        ao_adxl375_reg_write(AO_ADXL375_BW_RATE,
 
        /* Set the data rate */
        ao_adxl375_reg_write(AO_ADXL375_BW_RATE,
@@ -204,12 +204,12 @@ ao_adxl375_setup(void)
        self_test_value = z_change;
 
        if (z_change < MIN_SELF_TEST)
        self_test_value = z_change;
 
        if (z_change < MIN_SELF_TEST)
-               ao_sensor_errors = 1;
+               AO_SENSOR_ERROR(AO_DATA_ADXL375);
 
        /* This check is commented out as maximum self test is unreliable
 
           if (z_change > MAX_SELF_TEST)
 
        /* This check is commented out as maximum self test is unreliable
 
           if (z_change > MAX_SELF_TEST)
-               ao_sensor_errors = 1;
+               AO_SENSOR_ERROR(AO_DATA_ADXL375);
 
        */
 
 
        */
 
index e8eeea6e4b6dc8d424a9bf242ab60b706fbe399e..b0217368692fb7939ce391663aa815f4aa46132b 100644 (file)
@@ -232,7 +232,7 @@ ao_mma655x_setup(void)
                ao_delay(AO_ST_DELAY);
        }
        if (tries == AO_ST_TRIES)
                ao_delay(AO_ST_DELAY);
        }
        if (tries == AO_ST_TRIES)
-               ao_sensor_errors = 1;
+               AO_SENSOR_ERROR(AO_DATA_MMA655X);
 
        ao_mma655x_reg_write(AO_MMA655X_DEVCFG,
                             DEVCFG_VALUE | (1 << AO_MMA655X_DEVCFG_ENDINIT));
 
        ao_mma655x_reg_write(AO_MMA655X_DEVCFG,
                             DEVCFG_VALUE | (1 << AO_MMA655X_DEVCFG_ENDINIT));
index 8c85ab01fd82c00041128a9147e3f6a26f2caa39..c894239ec0e54ae0934781886c44a759e8bcc38b 100644 (file)
@@ -305,7 +305,7 @@ _ao_mpu6000_setup(void)
        }
 
        if (st_tries == ST_TRIES)
        }
 
        if (st_tries == ST_TRIES)
-               ao_sensor_errors = 1;
+               AO_SENSOR_ERROR(AO_DATA_MPU6000);
 
        /* Filter to about 100Hz, which also sets the gyro rate to 1000Hz */
        _ao_mpu6000_reg_write(MPU6000_CONFIG,
 
        /* Filter to about 100Hz, which also sets the gyro rate to 1000Hz */
        _ao_mpu6000_reg_write(MPU6000_CONFIG,
index 74e444a9d0950ba21a4439d19a5adcc5999a0f3c..1b31edf4611754fe1b8c8d8fe52562b161e8579e 100644 (file)
@@ -26,8 +26,6 @@
 
 static uint8_t ao_mpu9250_configured;
 
 
 static uint8_t ao_mpu9250_configured;
 
-extern uint8_t ao_sensor_errors;
-
 #ifndef AO_MPU9250_I2C_INDEX
 #define AO_MPU9250_SPI 1
 #else
 #ifndef AO_MPU9250_I2C_INDEX
 #define AO_MPU9250_SPI 1
 #else
@@ -361,7 +359,7 @@ _ao_mpu9250_setup(void)
        }
 
        if (st_tries == ST_TRIES)
        }
 
        if (st_tries == ST_TRIES)
-               ao_sensor_errors = 1;
+               AO_SENSOR_ERROR(AO_DATA_MPU9250);
 
        /* Set up the mag sensor */
 
 
        /* Set up the mag sensor */
 
@@ -372,7 +370,7 @@ _ao_mpu9250_setup(void)
        }
 
        if (mag_tries == MAG_TRIES)
        }
 
        if (mag_tries == MAG_TRIES)
-               ao_sensor_errors = 1;
+               AO_SENSOR_ERROR(AO_DATA_MPU9250);
 
        /* Select continuous mode 2 (100Hz), 16 bit samples */
 
 
        /* Select continuous mode 2 (100Hz), 16 bit samples */
 
index febe01117dbc614e11d309327d830d660f8a2e86..1ebba3e9c6f99ccfb0fd7a7bbebd42b1e7da2c58 100644 (file)
@@ -115,7 +115,7 @@ ao_ms5607_prom_read(struct ao_ms5607_prom *prom)
 
        if (!ao_ms5607_prom_valid((uint8_t *) prom)) {
 #if HAS_SENSOR_ERRORS
 
        if (!ao_ms5607_prom_valid((uint8_t *) prom)) {
 #if HAS_SENSOR_ERRORS
-               ao_sensor_errors = 1;
+               AO_SENSOR_ERROR(AO_DATA_MS5607);
 #else
                ao_panic(AO_PANIC_SELF_TEST_MS5607);
 #endif
 #else
                ao_panic(AO_PANIC_SELF_TEST_MS5607);
 #endif
index 5a340c3f3b4526f5700ba487063368dcb5602f9c..4fc9db8f16a7810ba8b54c89619bf9331f97608e 100644 (file)
@@ -142,6 +142,12 @@ extern volatile uint8_t            ao_data_count;
  */
 #define AO_DATA_PRESENT(bit)   (ao_data_present |= (bit))
 
  */
 #define AO_DATA_PRESENT(bit)   (ao_data_present |= (bit))
 
+/*
+ * Mark sensor failed, and unblock the sample collection code by
+ * marking the data as present
+ */
+#define AO_SENSOR_ERROR(bit)   (ao_data_present |= (ao_sensor_errors |= (bit)))
+
 /*
  * Wait until it is time to write a sensor sample; this is
  * signaled by the timer tick
 /*
  * Wait until it is time to write a sensor sample; this is
  * signaled by the timer tick
index 872dcd48cea9c237a6a1cf974f1980a5fab7dfe3..12c3a1e90acabb589114ed786edb08caf9a7c0fb 100644 (file)
@@ -262,6 +262,11 @@ ao_report(void)
                else
 #endif
                        ao_report_beep();
                else
 #endif
                        ao_report_beep();
+#if HAS_SENSOR_ERRORS
+               if (ao_report_state == ao_flight_invalid && ao_sensor_errors)
+                       ao_report_number(ao_sensor_errors);
+#endif
+
                if (ao_report_state == ao_flight_landed) {
                        ao_report_altitude();
 #if HAS_FLIGHT
                if (ao_report_state == ao_flight_landed) {
                        ao_report_altitude();
 #if HAS_FLIGHT