Make it easier to tell which component is failing self test
Signed-off-by: Keith Packard <keithp@keithp.com>
#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_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
/* Stop the operating system, beeping and blinking the reason */
void
#ifdef SDCC
#pragma disable_warning 126
#endif
#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);
ao_led_on(AO_LED_RED);
ao_beep(AO_BEEP_MID);
ao_panic_delay(10);
AO_CC1120_SPI_CS_PORT->bsrr = ((uint32_t) (1 << AO_CC1120_SPI_CS_PIN));
for (i = 0; i < 10000; i++) {
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)
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);
/* Enable the EXTI interrupt for the appropriate pin */
ao_enable_port(AO_CC1120_INT_PORT);
errors += ao_mpu6000_gyro_check(normal_mode.gyro_z, test_mode.gyro_z, "z");
if (errors)
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,
/* Filter to about 100Hz, which also sets the gyro rate to 1000Hz */
ao_mpu6000_reg_write(MPU6000_CONFIG,
static void
ao_ms5607_start(void) {
ao_spi_get(AO_MS5607_SPI_INDEX,AO_SPI_SPEED_FAST);
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) {
}
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);
}
ao_spi_put(AO_MS5607_SPI_INDEX);
}
printf ("MS5607 PROM CRC error (computed %x actual %x)\n",
crc, (((uint8_t *) prom)[15] & 0xf));
flush();
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
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
static void
ao_ms5607_isr(void)
{
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);
}
ao_ms5607_done = 1;
ao_wakeup(&ao_ms5607_done);
}
ao_ms5607_start();
ao_spi_send(&cmd, 1, AO_MS5607_SPI_INDEX);
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
#if AO_MS5607_PRIVATE_PINS
ao_spi_put(AO_MS5607_SPI_INDEX);
#endif
ao_sleep(&ao_ms5607_done);
sei();
#if AO_MS5607_PRIVATE_PINS
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
#else
ao_ms5607_stop();
#endif
static void
ao_ms5607_dump(void)
{
static void
ao_ms5607_dump(void)
{
+ struct ao_ms5607_sample sample;
struct ao_ms5607_value value;
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));
}
printf ("Altitude: %ld\n", ao_pa_to_altitude(value.pres));
}
{
ms5607_configured = 0;
ao_cmd_register(&ao_ms5607_cmds[0]);
{
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
*/
/* 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...
*/
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,