From 612cb04bdda3207e6a7f5bd2400258c9e32ea188 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Sat, 27 Jul 2024 17:40:18 -0600 Subject: [PATCH] first cut at adding "health" LED management task --- src/quantimotor-v1/Makefile | 3 ++- src/quantimotor-v1/ao_pins.h | 12 ++++++++++++ src/quantimotor-v1/ao_quantimotor.c | 30 +++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/quantimotor-v1/Makefile b/src/quantimotor-v1/Makefile index d033f920..3022bd0d 100644 --- a/src/quantimotor-v1/Makefile +++ b/src/quantimotor-v1/Makefile @@ -33,7 +33,8 @@ ALTOS_SRC = \ ao_romconfig.c \ ao_adc_lpc.c \ ao_serial_lpc.c \ - ao_usb_lpc.c + ao_usb_lpc.c \ + ao_led_lpc.c PRODUCT=QuantiMotor-v1 PRODUCT_DEF=-DQUANTIMOTOR_V_1 diff --git a/src/quantimotor-v1/ao_pins.h b/src/quantimotor-v1/ao_pins.h index 22a731fe..e352cf6e 100644 --- a/src/quantimotor-v1/ao_pins.h +++ b/src/quantimotor-v1/ao_pins.h @@ -56,6 +56,18 @@ #define AO_DATA_RING 16 +/* SOM sets "health" high when system is ready */ +#define HEALTH_PORT 1 +#define HEALTH_PIN 19 + +/* LED */ + +#define LED_PORT 0 +#define LED_PIN_HEALTH 8 +#define AO_LED_HEALTH (1 << LED_PIN_HEALTH) +#define LEDS_AVAILABLE (AO_LED_HEALTH) +#define AO_LED_PANIC AO_LED_HEALTH + /* * ADC */ diff --git a/src/quantimotor-v1/ao_quantimotor.c b/src/quantimotor-v1/ao_quantimotor.c index d15f248f..33ba6940 100644 --- a/src/quantimotor-v1/ao_quantimotor.c +++ b/src/quantimotor-v1/ao_quantimotor.c @@ -5,9 +5,11 @@ #include #include +#include static struct ao_task ao_console_read_task; static struct ao_task ao_console_write_task; +static struct ao_task ao_health_indicator_task; static void ao_console_read(void) @@ -35,6 +37,27 @@ ao_console_write(void) } } +static void +ao_health_indicator(void) +{ + int ledstate = 0; + + for (;;) { + if (ao_gpio_get(HEALTH_PORT, HEALTH_PIN)) { + ao_led_on(AO_LED_HEALTH); + } else { + if (ledstate) { + ledstate = 0; + ao_led_off(AO_LED_HEALTH); + } else { + ledstate = 1; + ao_led_on(AO_LED_HEALTH); + } + } + ao_delay(AO_MS_TO_TICKS(1000)); + } +} + int main(void) { @@ -42,6 +65,12 @@ main(void) ao_task_init(); ao_timer_init(); + ao_led_init(); + + /* set up the input we watch to sense SOM "health" */ + /* choosing pull down so SOM has to actually assert readiness */ + ao_enable_input(HEALTH_PORT, HEALTH_PIN, AO_EXTI_MODE_PULL_DOWN); + ao_adc_init(); ao_usb_init(); @@ -54,6 +83,7 @@ main(void) ao_add_task(&ao_console_read_task, ao_console_read, "console_read"); ao_add_task(&ao_console_write_task, ao_console_write, "console_write"); + ao_add_task(&ao_health_indicator_task, ao_health_indicator, "health_indicator"); ao_start_scheduler(); return 0; -- 2.47.2