From 93def58b9d1ad2370247f41f47d6c2e9bbf595fa Mon Sep 17 00:00:00 2001 From: Abdelatif Guettouche Date: Sat, 11 Dec 2021 01:15:26 +0100 Subject: [PATCH] esp32-wrover-kit/esp32_autoleds.c: Use LEDs to show CPUs activity. Signed-off-by: Abdelatif Guettouche --- .../esp32/esp32-wrover-kit/include/board.h | 19 +++++++ .../esp32-wrover-kit/src/esp32_autoleds.c | 56 ++++++++++++++++--- 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/boards/xtensa/esp32/esp32-wrover-kit/include/board.h b/boards/xtensa/esp32/esp32-wrover-kit/include/board.h index 4725215cdb..aeda9d47b1 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/include/board.h +++ b/boards/xtensa/esp32/esp32-wrover-kit/include/board.h @@ -105,6 +105,10 @@ * NuttX controls the LEDs: */ +/* These values index an array that contains the bit definitions for the + * correct LEDs (see esp32_autoleds.c). + */ + #define LED_STARTED 0 /* LED2 */ #define LED_HEAPALLOCATE 1 /* LED3 */ #define LED_IRQSENABLED 2 /* LED3 + LED2 */ @@ -114,6 +118,21 @@ #define LED_ASSERTION 6 /* LED1 + LED2 + LED3 */ #define LED_PANIC 7 /* LED1 + N/C + N/C */ +/* The values below are used only to distinguish between the CPUs. + * The LEDs are actually mapped as: + * CPU0 -> GPIO_LED1 (Red LED) + * CPU1 -> GPIO_LED2 (Green LED) + * Note that from the previous list only LED_HEAPALLOCATE will still be + * valid. This is to avoid collisions and to keep a way to show a successful + * heap allocation. The LED used is still LED3 (Blue LED). + */ + +#ifdef CONFIG_ARCH_LEDS_CPU_ACTIVITY +# define LED_CPU0 8 +# define LED_CPU1 9 +# define LED_CPU (LED_CPU0 + up_cpu_index()) +#endif + /* GPIO pins used by the GPIO Subsystem */ #define BOARD_NGPIOIN 1 /* Amount of GPIO Input pins */ diff --git a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_autoleds.c b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_autoleds.c index eeedc32bc5..ef658a7035 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_autoleds.c +++ b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_autoleds.c @@ -42,20 +42,23 @@ /* The following definitions map the encoded LED setting to GPIO settings */ -#define LED_STARTED_BITS (BOARD_LED2_BIT) -#define LED_HEAPALLOCATE_BITS (BOARD_LED3_BIT) -#define LED_IRQSENABLED_BITS (BOARD_LED3_BIT | BOARD_LED2_BIT) -#define LED_STACKCREATED_BITS (BOARD_LED3_BIT) -#define LED_INIRQ_BITS (BOARD_LED1_BIT | BOARD_LED3_BIT) -#define LED_SIGNAL_BITS (BOARD_LED2_BIT | BOARD_LED3_BIT) -#define LED_ASSERTION_BITS (BOARD_LED1_BIT | BOARD_LED2_BIT |\ - BOARD_LED3_BIT) -#define LED_PANIC_BITS (BOARD_LED1_BIT) +#ifndef CONFIG_ARCH_LEDS_CPU_ACTIVITY +# define LED_STARTED_BITS (BOARD_LED2_BIT) +# define LED_HEAPALLOCATE_BITS (BOARD_LED3_BIT) +# define LED_IRQSENABLED_BITS (BOARD_LED3_BIT | BOARD_LED2_BIT) +# define LED_STACKCREATED_BITS (BOARD_LED3_BIT) +# define LED_INIRQ_BITS (BOARD_LED1_BIT | BOARD_LED3_BIT) +# define LED_SIGNAL_BITS (BOARD_LED2_BIT | BOARD_LED3_BIT) +# define LED_ASSERTION_BITS (BOARD_LED1_BIT | BOARD_LED2_BIT |\ + BOARD_LED3_BIT) +# define LED_PANIC_BITS (BOARD_LED1_BIT) +#endif /**************************************************************************** * Private Data ****************************************************************************/ +#ifndef CONFIG_ARCH_LEDS_CPU_ACTIVITY static const unsigned int g_ledbits[8] = { LED_STARTED_BITS, @@ -67,6 +70,7 @@ static const unsigned int g_ledbits[8] = LED_ASSERTION_BITS, LED_PANIC_BITS }; +#endif /**************************************************************************** * Private Functions @@ -131,8 +135,25 @@ void board_autoled_initialize(void) void board_autoled_on(int led) { +#ifdef CONFIG_ARCH_LEDS_CPU_ACTIVITY + switch (led) + { + case LED_CPU0: + esp32_gpiowrite(GPIO_LED1, true); + break; + case LED_CPU1: + esp32_gpiowrite(GPIO_LED2, true); + break; + case LED_HEAPALLOCATE: + esp32_gpiowrite(GPIO_LED3, true); + break; + default: + break; + } +#else led_clrbits(BOARD_LED1_BIT | BOARD_LED2_BIT | BOARD_LED3_BIT); led_setbits(g_ledbits[led]); +#endif } /**************************************************************************** @@ -141,7 +162,24 @@ void board_autoled_on(int led) void board_autoled_off(int led) { +#ifdef CONFIG_ARCH_LEDS_CPU_ACTIVITY + switch (led) + { + case LED_CPU0: + esp32_gpiowrite(GPIO_LED1, false); + break; + case LED_CPU1: + esp32_gpiowrite(GPIO_LED2, false); + break; + case LED_HEAPALLOCATE: + esp32_gpiowrite(GPIO_LED3, false); + break; + default: + break; + } +#else led_clrbits(g_ledbits[led]); +#endif } #endif /* CONFIG_ARCH_LEDS */