altos: Record all failed sensors and report status at power up
[fw/altos] / src / drivers / ao_adxl375.c
index e0d094f214b3a42a8f48a9f5cced8f0685f5debb..4f6b816948709632e5462e1d8d0460a0f3911b49 100644 (file)
@@ -98,8 +98,8 @@ struct ao_adxl375_total {
        int32_t z;
 };
 
-#define AO_ADXL375_SELF_TEST_SAMPLES   16
-#define AO_ADXL375_SELF_TEST_SETTLE    6
+#define AO_ADXL375_SELF_TEST_SAMPLES   10
+#define AO_ADXL375_SELF_TEST_SETTLE    4
 
 #define MIN_LSB_G      18.4
 #define MAX_LSB_G      22.6
@@ -109,9 +109,6 @@ struct ao_adxl375_total {
 #define MIN_SELF_TEST  ((int32_t) (MIN_LSB_G * SELF_TEST_MIN_G * AO_ADXL375_SELF_TEST_SAMPLES + 0.5))
 #define MAX_SELF_TEST  ((int32_t) (MAX_LSB_G * SELF_TEST_MAX_G * AO_ADXL375_SELF_TEST_SAMPLES + 0.5))
 
-static const int32_t   min_self_test = MIN_SELF_TEST;
-static const int32_t   max_self_test = MAX_SELF_TEST;
-
 static void
 ao_adxl375_total_value(struct ao_adxl375_total *total, int samples)
 {
@@ -146,7 +143,7 @@ ao_adxl375_setup(void)
 
        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,
@@ -175,12 +172,8 @@ ao_adxl375_setup(void)
                             (0 << AO_ADXL375_POWER_CTL_SLEEP) |
                             (AO_ADXL375_POWER_CTL_WAKEUP_8 << AO_ADXL375_POWER_CTL_WAKEUP));
 
-       (void) ao_adxl375_total_value;
        /* Perform self-test */
 
-#define AO_ADXL375_SELF_TEST_SAMPLES   16
-#define AO_ADXL375_SELF_TEST_SETTLE    6
-
        struct ao_adxl375_total self_test_off, self_test_on;
 
        /* Discard some samples to let it settle down */
@@ -210,22 +203,26 @@ ao_adxl375_setup(void)
 
        self_test_value = z_change;
 
-       if (z_change < min_self_test || max_self_test < z_change)
-               ao_sensor_errors = 1;
+       if (z_change < MIN_SELF_TEST)
+               AO_SENSOR_ERROR(AO_DATA_ADXL375);
+
+       /* This check is commented out as maximum self test is unreliable
+
+          if (z_change > MAX_SELF_TEST)
+               AO_SENSOR_ERROR(AO_DATA_ADXL375);
+
+       */
 
        /* Discard some samples to let it settle down */
        ao_adxl375_total_value(&self_test_off, AO_ADXL375_SELF_TEST_SETTLE);
 }
 
-static int     adxl375_count;
-
 static void
 ao_adxl375(void)
 {
        ao_adxl375_setup();
        for (;;) {
                ao_adxl375_value(&ao_adxl375_current);
-               ++adxl375_count;
                ao_arch_critical(
                        AO_DATA_PRESENT(AO_DATA_ADXL375);
                        AO_DATA_WAIT();
@@ -238,11 +235,10 @@ static struct ao_task ao_adxl375_task;
 static void
 ao_adxl375_dump(void)
 {
-       printf ("ADXL375 value %d %d %d count %d self test %d min %d max %d\n",
+       printf ("ADXL375 value %d %d %d self test %d min %d max %d\n",
                ao_adxl375_current.x,
                ao_adxl375_current.y,
                ao_adxl375_current.z,
-               adxl375_count,
                self_test_value,
                MIN_SELF_TEST,
                MAX_SELF_TEST);