commit a84f02585a4dc217b8cb4433ba12a86e45c04453
parent 5b20b7b5953f729a09168fe9a6c78a82cdc8bd90
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date: Sun, 29 Mar 2026 13:27:48 -0300
Renombrar `task_led_*` a `task_leds_*`
Diffstat:
12 files changed, 468 insertions(+), 478 deletions(-)
diff --git a/firmware/app/inc/task_led.h b/firmware/app/inc/task_led.h
@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 2026 Martin Javier Klöckner <mklockner@fi.uba.ar>
- *
- * See file `LICENSE` for full details
- */
-
-#ifndef TASK_INC_TASK_LED_H_
-#define TASK_INC_TASK_LED_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern uint32_t g_task_led_cnt;
-extern volatile uint32_t g_task_led_tick_cnt;
-
-void task_led_init(void *parameters);
-void task_led_update(void *parameters);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* TASK_INC_TASK_LED_H_ */
diff --git a/firmware/app/inc/task_led_attribute.h b/firmware/app/inc/task_led_attribute.h
@@ -1,116 +0,0 @@
-/*
- * Copyright (c) 2026 Martin Javier Klöckner <mklockner@fi.uba.ar>
- *
- * See file `LICENSE` for full details
- */
-
-#ifndef TASK_INC_TASK_LED_ATTRIBUTE_H_
-#define TASK_INC_TASK_LED_ATTRIBUTE_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Led Statechart - State Transition Table */
-/* +-----------------------+-----------------------+-------------+-----------------------+-----------------------+
- * | Current | Event | | Next | |
- * | State | (Parameters) | [Guard] | State | Actions |
- * |=======================+=======================+=============+=======================+=======================|
- * | INICIAL | | | ST_LED_XX_OFF | led = LED_OFF |
- * | | | | | op_led(led) |
- * |-----------------------+-----------------------+-------------+-----------------------+-----------------------|
- * | ST_LED_XX_OFF | EV_LED_XX_ON | | ST_LED_XX_ON | led = LED_ON |
- * | | | | | op_led(led) |
- * | |-----------------------+-------------+-----------------------+-----------------------|
- * | | EV_LED_XX_BLINK | | ST_LED_XX_BLINK_ON | tick = tick_max |
- * | | | | | led = LED_ON |
- * | | | | | op_led(led) |
- * | |-----------------------+-------------+-----------------------+-----------------------|
- * | | EV_LED_XX_PULSE | | ST_LED_XX_PULSE | tick = tick_max |
- * | | | | | led = LED_ON |
- * | | | | | op_led(led) |
- * |-----------------------+-----------------------+-------------+-----------------------+-----------------------|
- * | ST_LED_XX_ON | EV_LED_XX_OFF | | ST_LED_XX_OFF | led = LED_OFF |
- * | | | | | op_led(led) |
- * |-----------------------+-----------------------+-------------+-----------------------+-----------------------|
- * | ST_LED_XX_BLINK_ON | EV_LED_XX_OFF | | ST_LED_XX_OFF | led = LED_OFF |
- * | | | | | op_led(led) |
- * | +-----------------------+-------------+-----------------------+-----------------------|
- * | | EV_LED_XX_ON | | ST_LED_XX_ON | led = LED_ON |
- * | | | | | op_led(led) |
- * | +-----------------------+-------------+-----------------------+-----------------------|
- * | | | [tick == 0] | ST_LED_XX_BLINK_OFF | tick = tick_max |
- * | | | | | led = LED_OFF |
- * | | | | | op_led(led) |
- * | +-----------------------+-------------+-----------------------+-----------------------|
- * | | | [tick > 0] | ST_LED_XX_BLINK_ON | tick-- |
- * |-----------------------+-----------------------+-------------+-----------------------+-----------------------|
- * | ST_LED_XX_BLINK_OFF | EV_LED_XX_OFF | | ST_LED_XX_OFF | led = LED_OFF |
- * | | | | | op_led(led) |
- * | +-----------------------+-------------+-----------------------+-----------------------|
- * | | EV_LED_XX_ON | | ST_LED_XX_ON | led = LED_ON |
- * | | | | | op_led(led) |
- * | +-----------------------+-------------+-----------------------+-----------------------|
- * | | | [tick > 0] | ST_LED_XX_BLINK_OFF | tick-- |
- * | +-----------------------+-------------+-----------------------+-----------------------|
- * | | | [tick == 0] | ST_LED_XX_BLINK_ON | tick = tick_max |
- * | | | | | led = LED_ON |
- * | | | | | op_led(led) |
- * |-----------------------+-----------------------+-------------+-----------------------+-----------------------|
- * | ST_LED_XX_PULSE | | [tick == 0] | ST_LED_XX_OFF | tick = tick_max |
- * | | | | | led = LED_OFF |
- * | | | | | op_led(led) |
- * |-----------------------+-----------------------+-------------+-----------------------+-----------------------|
- * | | | [tick > 0] | ST_LED_XX_PULSE | tick-- |
- * +-----------------------+-----------------------+-------------+-----------------------+-----------------------+ */
-
-/* Events to excite Task Led */
-typedef enum {
- EV_LED_XX_OFF,
- EV_LED_XX_ON,
- EV_LED_XX_NOT_BLINK,
- EV_LED_XX_BLINK,
- EV_LED_XX_PULSE
-} task_led_ev_t;
-
-/* States of Task Led */
-typedef enum {
- ST_LED_XX_OFF,
- ST_LED_XX_ON,
- ST_LED_XX_BLINK_ON,
- ST_LED_XX_BLINK_OFF,
- ST_LED_XX_PULSE
-} task_led_st_t;
-
-/* Identifier of Task Led */
-typedef enum {
- ID_LED_A,
- ID_LED_B
-} task_led_id_t;
-
-typedef struct
-{
- task_led_id_t identifier;
- GPIO_TypeDef *gpio_port;
- uint16_t pin;
- GPIO_PinState led_on;
- GPIO_PinState led_off;
- uint32_t tick_blink;
- uint32_t tick_pulse;
-} task_led_cfg_t;
-
-typedef struct
-{
- uint32_t tick;
- task_led_st_t state;
- task_led_ev_t event;
- bool flag;
-} task_led_dta_t;
-
-extern task_led_dta_t task_led_dta_list[];
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* TASK_INC_TASK_LED_ATTRIBUTE_H_ */
diff --git a/firmware/app/inc/task_led_interface.h b/firmware/app/inc/task_led_interface.h
@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2023 Juan Manuel Cruz <jcruz@fi.uba.ar> <jcruz@frba.utn.edu.ar>.
- * Copyright (c) 2026 Martin Javier Klöckner <mklockner@fi.uba.ar>
- *
- * See file `LICENSE` for full details
- */
-
-#ifndef TASK_INC_TASK_LED_INTERFACE_H_
-#define TASK_INC_TASK_LED_INTERFACE_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern void task_led_interface_put_event(task_led_ev_t event, task_led_id_t identifier);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* TASK_INC_TASK_LED_INTERFACE_H_ */
diff --git a/firmware/app/inc/task_leds.h b/firmware/app/inc/task_leds.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2026 Martin Javier Klöckner <mklockner@fi.uba.ar>
+ *
+ * See file `LICENSE` for full details
+ */
+
+#ifndef TASK_INC_TASK_LEDS_H_
+#define TASK_INC_TASK_LEDS_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern uint32_t g_task_leds_cnt;
+extern volatile uint32_t g_task_leds_tick_cnt;
+
+void task_leds_init(void *parameters);
+void task_leds_update(void *parameters);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TASK_INC_TASK_LEDS_H_ */
diff --git a/firmware/app/inc/task_leds_attribute.h b/firmware/app/inc/task_leds_attribute.h
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2026 Martin Javier Klöckner <mklockner@fi.uba.ar>
+ *
+ * See file `LICENSE` for full details
+ */
+
+#ifndef TASK_INC_TASK_LEDS_ATTRIBUTE_H_
+#define TASK_INC_TASK_LEDS_ATTRIBUTE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Led Statechart - State Transition Table */
+/* +-----------------------+-----------------------+-------------+-----------------------+-----------------------+
+ * | Current | Event | | Next | |
+ * | State | (Parameters) | [Guard] | State | Actions |
+ * |=======================+=======================+=============+=======================+=======================|
+ * | INICIAL | | | ST_LED_XX_OFF | led = LED_OFF |
+ * | | | | | op_led(led) |
+ * |-----------------------+-----------------------+-------------+-----------------------+-----------------------|
+ * | ST_LED_XX_OFF | EV_LED_XX_ON | | ST_LED_XX_ON | led = LED_ON |
+ * | | | | | op_led(led) |
+ * | |-----------------------+-------------+-----------------------+-----------------------|
+ * | | EV_LED_XX_BLINK | | ST_LED_XX_BLINK_ON | tick = tick_max |
+ * | | | | | led = LED_ON |
+ * | | | | | op_led(led) |
+ * | |-----------------------+-------------+-----------------------+-----------------------|
+ * | | EV_LED_XX_PULSE | | ST_LED_XX_PULSE | tick = tick_max |
+ * | | | | | led = LED_ON |
+ * | | | | | op_led(led) |
+ * |-----------------------+-----------------------+-------------+-----------------------+-----------------------|
+ * | ST_LED_XX_ON | EV_LED_XX_OFF | | ST_LED_XX_OFF | led = LED_OFF |
+ * | | | | | op_led(led) |
+ * |-----------------------+-----------------------+-------------+-----------------------+-----------------------|
+ * | ST_LED_XX_BLINK_ON | EV_LED_XX_OFF | | ST_LED_XX_OFF | led = LED_OFF |
+ * | | | | | op_led(led) |
+ * | +-----------------------+-------------+-----------------------+-----------------------|
+ * | | EV_LED_XX_ON | | ST_LED_XX_ON | led = LED_ON |
+ * | | | | | op_led(led) |
+ * | +-----------------------+-------------+-----------------------+-----------------------|
+ * | | | [tick == 0] | ST_LED_XX_BLINK_OFF | tick = tick_max |
+ * | | | | | led = LED_OFF |
+ * | | | | | op_led(led) |
+ * | +-----------------------+-------------+-----------------------+-----------------------|
+ * | | | [tick > 0] | ST_LED_XX_BLINK_ON | tick-- |
+ * |-----------------------+-----------------------+-------------+-----------------------+-----------------------|
+ * | ST_LED_XX_BLINK_OFF | EV_LED_XX_OFF | | ST_LED_XX_OFF | led = LED_OFF |
+ * | | | | | op_led(led) |
+ * | +-----------------------+-------------+-----------------------+-----------------------|
+ * | | EV_LED_XX_ON | | ST_LED_XX_ON | led = LED_ON |
+ * | | | | | op_led(led) |
+ * | +-----------------------+-------------+-----------------------+-----------------------|
+ * | | | [tick > 0] | ST_LED_XX_BLINK_OFF | tick-- |
+ * | +-----------------------+-------------+-----------------------+-----------------------|
+ * | | | [tick == 0] | ST_LED_XX_BLINK_ON | tick = tick_max |
+ * | | | | | led = LED_ON |
+ * | | | | | op_led(led) |
+ * |-----------------------+-----------------------+-------------+-----------------------+-----------------------|
+ * | ST_LED_XX_PULSE | | [tick == 0] | ST_LED_XX_OFF | tick = tick_max |
+ * | | | | | led = LED_OFF |
+ * | | | | | op_led(led) |
+ * |-----------------------+-----------------------+-------------+-----------------------+-----------------------|
+ * | | | [tick > 0] | ST_LED_XX_PULSE | tick-- |
+ * +-----------------------+-----------------------+-------------+-----------------------+-----------------------+ */
+
+/* Events to excite Task Led */
+typedef enum {
+ EV_LED_XX_OFF,
+ EV_LED_XX_ON,
+ EV_LED_XX_NOT_BLINK,
+ EV_LED_XX_BLINK,
+ EV_LED_XX_PULSE
+} task_leds_ev_t;
+
+/* States of Task Led */
+typedef enum {
+ ST_LED_XX_OFF,
+ ST_LED_XX_ON,
+ ST_LED_XX_BLINK_ON,
+ ST_LED_XX_BLINK_OFF,
+ ST_LED_XX_PULSE
+} task_leds_st_t;
+
+/* Identifier of Task Led */
+typedef enum {
+ ID_LED_A,
+ ID_LED_B
+} task_leds_id_t;
+
+typedef struct
+{
+ task_leds_id_t identifier;
+ GPIO_TypeDef *gpio_port;
+ uint16_t pin;
+ GPIO_PinState led_on;
+ GPIO_PinState led_off;
+ uint32_t tick_blink;
+ uint32_t tick_pulse;
+} task_leds_cfg_t;
+
+typedef struct
+{
+ uint32_t tick;
+ task_leds_st_t state;
+ task_leds_ev_t event;
+ bool flag;
+} task_leds_dta_t;
+
+extern task_leds_dta_t task_leds_dta_list[];
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TASK_INC_TASK_LEDS_ATTRIBUTE_H_ */
diff --git a/firmware/app/inc/task_leds_interface.h b/firmware/app/inc/task_leds_interface.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2023 Juan Manuel Cruz <jcruz@fi.uba.ar> <jcruz@frba.utn.edu.ar>.
+ * Copyright (c) 2026 Martin Javier Klöckner <mklockner@fi.uba.ar>
+ *
+ * See file `LICENSE` for full details
+ */
+
+#ifndef TASK_INC_TASK_LEDS_INTERFACE_H_
+#define TASK_INC_TASK_LEDS_INTERFACE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void task_leds_interface_put_event(task_leds_ev_t event, task_leds_id_t identifier);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TASK_INC_TASK_LEDS_INTERFACE_H_ */
diff --git a/firmware/app/src/app.c b/firmware/app/src/app.c
@@ -17,7 +17,7 @@
#include "task_temp_ctrl.h"
#include "task_buttons.h"
#include "task_menu.h"
-#include "task_led.h"
+#include "task_leds.h"
#define G_APP_CNT_INI 0ul
#define G_APP_TICK_CNT_INI 0ul
@@ -48,7 +48,7 @@ volatile uint32_t g_app_tick_cnt;
const task_cfg_t task_cfg_list[] = {
{task_system_init, task_system_update, &shared_data},
{task_buttons_init, task_buttons_update, NULL},
- {task_led_init, task_led_update, NULL},
+ {task_leds_init, task_leds_update, NULL},
{task_menu_init, task_menu_update, NULL},
{task_temp_ctrl_init, task_temp_ctrl_update, &shared_data},
{task_temp_sensor_init, task_temp_sensor_update, NULL},
@@ -155,7 +155,7 @@ void HAL_SYSTICK_Callback(void)
g_task_system_tick_cnt++;
g_task_buttons_tick_cnt++;
- g_task_led_tick_cnt++;
+ g_task_leds_tick_cnt++;
g_task_menu_tick_cnt++;
g_task_temp_ctrl_tick_cnt++;
g_task_temp_sensor_tick_cnt++;
diff --git a/firmware/app/src/task_led.c b/firmware/app/src/task_led.c
@@ -1,285 +0,0 @@
-/*
- * Copyright (c) 2023 Juan Manuel Cruz <jcruz@fi.uba.ar> <jcruz@frba.utn.edu.ar>.
- * Copyright (c) 2026 Martin Javier Klöckner <mklockner@fi.uba.ar>
- *
- * See file `LICENSE` for full details
- */
-
-/* Project includes */
-#include "main.h"
-
-/* Demo includes */
-#include "logger.h"
-#include "dwt.h"
-
-/* Application & Tasks includes */
-#include "board.h"
-#include "app.h"
-#include "task_led_attribute.h"
-#include "task_led_interface.h"
-
-#define G_TASK_LED_CNT_INIT 0ul
-#define G_TASK_LED_TICK_CNT_INI 0ul
-
-#define DEL_LED_XX_PUL 250ul
-#define DEL_LED_XX_BLI 500ul
-#define DEL_LED_XX_MIN 0ul
-
-#define LED_ON GPIO_PIN_SET
-#define LED_OFF GPIO_PIN_RESET
-
-const task_led_cfg_t task_led_cfg_list[] = {
- {ID_LED_A, LD2_GPIO_Port, LD2_Pin, LED_ON, LED_OFF, DEL_LED_XX_BLI, DEL_LED_XX_PUL},
- {ID_LED_B, LD3_GPIO_Port, LD3_Pin, LED_ON, LED_OFF, DEL_LED_XX_BLI, DEL_LED_XX_PUL},
-};
-
-#define LED_CFG_QTY (sizeof(task_led_cfg_list)/sizeof(task_led_cfg_t))
-
-task_led_dta_t task_led_dta_list[] = {
- {DEL_LED_XX_MIN, ST_LED_XX_OFF, EV_LED_XX_NOT_BLINK, false},
- {DEL_LED_XX_MIN, ST_LED_XX_OFF, EV_LED_XX_NOT_BLINK, false},
-};
-
-#define LED_DTA_QTY (sizeof(task_led_dta_list)/sizeof(task_led_dta_t))
-
-// Private functions declaration
-void task_led_statechart(void);
-
-// External data declaration
-uint32_t g_task_led_cnt;
-volatile uint32_t g_task_led_tick_cnt;
-
-// External functions definition
-void task_led_init(void *parameters)
-{
- uint32_t index;
- const task_led_cfg_t *p_task_led_cfg;
- task_led_dta_t *p_task_led_dta;
-
- LOGGER_INFO("Initializing `task_led`...");
-
- g_task_led_cnt = G_TASK_LED_CNT_INIT;
- for (index = 0; LED_DTA_QTY > index; index++)
- {
- /* Update Task led Configuration & Data Pointer */
- p_task_led_cfg = &task_led_cfg_list[index];
- p_task_led_dta = &task_led_dta_list[index];
-
- p_task_led_dta->state = ST_LED_XX_OFF;
- p_task_led_dta->event = EV_LED_XX_OFF;
- p_task_led_dta->flag = false;
-
- /*
- LOGGER_INFO(" ");
- LOGGER_INFO(" %s = %lu %s = %lu %s = %lu %s = %s",
- GET_NAME(index), index,
- GET_NAME(state), (uint32_t)state,
- GET_NAME(event), (uint32_t)event,
- GET_NAME(b_event), (b_event ? "true" : "false"));
- */
- HAL_GPIO_WritePin(p_task_led_cfg->gpio_port,
- p_task_led_cfg->pin,
- p_task_led_cfg->led_off);
- }
-}
-
-void task_led_update(void *parameters)
-{
- bool b_time_update_required = false;
-
- __asm("CPSID i");
- if (G_TASK_LED_TICK_CNT_INI < g_task_led_tick_cnt)
- {
- g_task_led_tick_cnt--;
- b_time_update_required = true;
- }
- __asm("CPSIE i");
-
- while (b_time_update_required)
- {
- g_task_led_cnt++;
-
- task_led_statechart();
-
- __asm("CPSID i");
- if (G_TASK_LED_TICK_CNT_INI < g_task_led_tick_cnt)
- {
- g_task_led_tick_cnt--;
- b_time_update_required = true;
- }
- else
- {
- b_time_update_required = false;
- }
- __asm("CPSIE i");
- }
-}
-
-void task_led_statechart(void)
-{
- uint32_t index;
- const task_led_cfg_t *p_task_led_cfg;
- task_led_dta_t *p_task_led_dta;
-
- for (index = 0; LED_DTA_QTY > index; index++)
- {
- p_task_led_cfg = &task_led_cfg_list[index];
- p_task_led_dta = &task_led_dta_list[index];
-
- switch (p_task_led_dta->state)
- {
- case ST_LED_XX_OFF:
- if (true == p_task_led_dta->flag)
- {
- p_task_led_dta->flag = false;
- switch(p_task_led_dta->event)
- {
- case EV_LED_XX_ON:
- p_task_led_dta->state = ST_LED_XX_ON;
- HAL_GPIO_WritePin(
- p_task_led_cfg->gpio_port,
- p_task_led_cfg->pin,
- p_task_led_cfg->led_on);
- break;
-
- case EV_LED_XX_BLINK:
- p_task_led_dta->tick = DEL_LED_XX_BLI;
- p_task_led_dta->state = ST_LED_XX_BLINK_ON;
- HAL_GPIO_WritePin(
- p_task_led_cfg->gpio_port,
- p_task_led_cfg->pin,
- p_task_led_cfg->led_on);
- break;
-
- case EV_LED_XX_PULSE:
- p_task_led_dta->tick = DEL_LED_XX_PUL;
- p_task_led_dta->state = ST_LED_XX_PULSE;
- HAL_GPIO_WritePin(
- p_task_led_cfg->gpio_port,
- p_task_led_cfg->pin,
- p_task_led_cfg->led_on);
- default:
- break;
- }
- }
- break;
-
- case ST_LED_XX_ON:
- if ((true == p_task_led_dta->flag)
- && (EV_LED_XX_OFF == p_task_led_dta->event))
- {
- p_task_led_dta->flag = false;
- p_task_led_dta->state = ST_LED_XX_OFF;
- HAL_GPIO_WritePin(
- p_task_led_cfg->gpio_port,
- p_task_led_cfg->pin,
- p_task_led_cfg->led_off);
- }
-
- break;
-
- case ST_LED_XX_BLINK_ON:
- if (true == p_task_led_dta->flag)
- {
- p_task_led_dta->flag = false;
- switch(p_task_led_dta->event)
- {
- case EV_LED_XX_OFF:
- p_task_led_dta->state = ST_LED_XX_OFF;
- HAL_GPIO_WritePin(
- p_task_led_cfg->gpio_port,
- p_task_led_cfg->pin,
- p_task_led_cfg->led_off);
- break;
- case EV_LED_XX_ON:
- p_task_led_dta->state = ST_LED_XX_ON;
- HAL_GPIO_WritePin(
- p_task_led_cfg->gpio_port,
- p_task_led_cfg->pin,
- p_task_led_cfg->led_on);
- default:
- break;
- }
- }
-
- if (DEL_LED_XX_MIN == p_task_led_dta->tick)
- {
- p_task_led_dta->state = ST_LED_XX_BLINK_OFF;
- p_task_led_dta->tick = DEL_LED_XX_BLI;
- HAL_GPIO_WritePin(
- p_task_led_cfg->gpio_port,
- p_task_led_cfg->pin,
- p_task_led_cfg->led_off);
- }
-
- if (DEL_LED_XX_MIN < p_task_led_dta->tick)
- {
- p_task_led_dta->tick--;
- }
- break;
-
- case ST_LED_XX_BLINK_OFF:
- if (true == p_task_led_dta->flag)
- {
- p_task_led_dta->flag = false;
- switch(p_task_led_dta->event)
- {
- case EV_LED_XX_OFF:
- p_task_led_dta->state = ST_LED_XX_OFF;
- HAL_GPIO_WritePin(
- p_task_led_cfg->gpio_port,
- p_task_led_cfg->pin,
- p_task_led_cfg->led_off);
- break;
- case EV_LED_XX_ON:
- p_task_led_dta->state = ST_LED_XX_ON;
- HAL_GPIO_WritePin(
- p_task_led_cfg->gpio_port,
- p_task_led_cfg->pin,
- p_task_led_cfg->led_on);
- default:
- break;
- }
- }
-
- if (DEL_LED_XX_MIN == p_task_led_dta->tick)
- {
- p_task_led_dta->state = ST_LED_XX_BLINK_ON;
- p_task_led_dta->tick = DEL_LED_XX_BLI;
- HAL_GPIO_WritePin(
- p_task_led_cfg->gpio_port,
- p_task_led_cfg->pin,
- p_task_led_cfg->led_on);
- }
-
- if (DEL_LED_XX_MIN < p_task_led_dta->tick)
- {
- p_task_led_dta->tick--;
- }
- break;
-
- case ST_LED_XX_PULSE:
- if (DEL_LED_XX_MIN == p_task_led_dta->tick)
- {
- p_task_led_dta->state = ST_LED_XX_OFF;
- HAL_GPIO_WritePin(
- p_task_led_cfg->gpio_port,
- p_task_led_cfg->pin,
- p_task_led_cfg->led_off);
- }
-
- if (DEL_LED_XX_MIN < p_task_led_dta->tick)
- {
- p_task_led_dta->tick--;
- }
- break;
-
- default:
- p_task_led_dta->tick = DEL_LED_XX_MIN;
- p_task_led_dta->state = ST_LED_XX_OFF;
- p_task_led_dta->event = EV_LED_XX_OFF;
- p_task_led_dta->flag = false;
- break;
- }
- }
-}
diff --git a/firmware/app/src/task_led_interface.c b/firmware/app/src/task_led_interface.c
@@ -1,23 +0,0 @@
-/*
- * Copyright (c) 2023 Juan Manuel Cruz <jcruz@fi.uba.ar> <jcruz@frba.utn.edu.ar>.
- * Copyright (c) 2026 Martin Javier Klöckner <mklockner@fi.uba.ar>
- *
- * See file `LICENSE` for full details
- */
-
-#include "main.h"
-
-#include "logger.h"
-#include "dwt.h"
-
-#include "board.h"
-#include "app.h"
-#include "task_led_attribute.h"
-
-void task_led_interface_put_event(task_led_ev_t event, task_led_id_t identifier)
-{
- task_led_dta_t *p_task_led_dta;
- p_task_led_dta = &task_led_dta_list[identifier];
- p_task_led_dta->event = event;
- p_task_led_dta->flag = true;
-}
diff --git a/firmware/app/src/task_leds.c b/firmware/app/src/task_leds.c
@@ -0,0 +1,276 @@
+/*
+ * Copyright (c) 2023 Juan Manuel Cruz <jcruz@fi.uba.ar> <jcruz@frba.utn.edu.ar>.
+ * Copyright (c) 2026 Martin Javier Klöckner <mklockner@fi.uba.ar>
+ *
+ * See file `LICENSE` for full details
+ */
+
+/* Project includes */
+#include "main.h"
+
+/* Demo includes */
+#include "logger.h"
+#include "dwt.h"
+
+/* Application & Tasks includes */
+#include "app.h"
+#include "task_leds_attribute.h"
+#include "task_leds_interface.h"
+
+#define G_TASK_LEDS_CNT_INIT 0ul
+#define G_TASK_LEDS_TICK_CNT_INI 0ul
+
+#define DEL_LED_XX_PUL 250ul
+#define DEL_LED_XX_BLI 500ul
+#define DEL_LED_XX_MIN 0ul
+
+#define LED_ON GPIO_PIN_SET
+#define LED_OFF GPIO_PIN_RESET
+
+const task_leds_cfg_t task_leds_cfg_list[] = {
+ {ID_LED_A, LD2_GPIO_Port, LD2_Pin, LED_ON, LED_OFF, DEL_LED_XX_BLI, DEL_LED_XX_PUL},
+ {ID_LED_B, LD3_GPIO_Port, LD3_Pin, LED_ON, LED_OFF, DEL_LED_XX_BLI, DEL_LED_XX_PUL},
+};
+
+#define LEDS_CFG_QTY (sizeof(task_leds_cfg_list)/sizeof(task_leds_cfg_t))
+
+task_leds_dta_t task_leds_dta_list[] = {
+ {DEL_LED_XX_MIN, ST_LED_XX_OFF, EV_LED_XX_NOT_BLINK, false},
+ {DEL_LED_XX_MIN, ST_LED_XX_OFF, EV_LED_XX_NOT_BLINK, false},
+};
+
+#define LEDS_DTA_QTY (sizeof(task_leds_dta_list)/sizeof(task_leds_dta_t))
+
+// Private functions declaration
+void task_leds_statechart(void);
+
+// External data declaration
+uint32_t g_task_leds_cnt;
+volatile uint32_t g_task_leds_tick_cnt;
+
+// External functions definition
+void task_leds_init(void *parameters)
+{
+ uint32_t index;
+ const task_leds_cfg_t *p_task_leds_cfg;
+ task_leds_dta_t *p_task_leds_dta;
+
+ LOGGER_INFO("Initializing `task_leds`...");
+
+ g_task_leds_cnt = G_TASK_LEDS_CNT_INIT;
+ for (index = 0; LEDS_DTA_QTY > index; index++)
+ {
+ /* Update Task led Configuration & Data Pointer */
+ p_task_leds_cfg = &task_leds_cfg_list[index];
+ p_task_leds_dta = &task_leds_dta_list[index];
+
+ p_task_leds_dta->state = ST_LED_XX_OFF;
+ p_task_leds_dta->event = EV_LED_XX_OFF;
+ p_task_leds_dta->flag = false;
+
+ HAL_GPIO_WritePin(p_task_leds_cfg->gpio_port,
+ p_task_leds_cfg->pin,
+ p_task_leds_cfg->led_off);
+ }
+}
+
+void task_leds_update(void *parameters)
+{
+ bool b_time_update_required = false;
+
+ __asm("CPSID i");
+ if (G_TASK_LEDS_TICK_CNT_INI < g_task_leds_tick_cnt)
+ {
+ g_task_leds_tick_cnt--;
+ b_time_update_required = true;
+ }
+ __asm("CPSIE i");
+
+ while (b_time_update_required)
+ {
+ g_task_leds_cnt++;
+
+ task_leds_statechart();
+
+ __asm("CPSID i");
+ if (G_TASK_LEDS_TICK_CNT_INI < g_task_leds_tick_cnt)
+ {
+ g_task_leds_tick_cnt--;
+ b_time_update_required = true;
+ }
+ else
+ {
+ b_time_update_required = false;
+ }
+ __asm("CPSIE i");
+ }
+}
+
+void task_leds_statechart(void)
+{
+ uint32_t index;
+ const task_leds_cfg_t *p_task_leds_cfg;
+ task_leds_dta_t *p_task_leds_dta;
+
+ for (index = 0; LEDS_DTA_QTY > index; index++)
+ {
+ p_task_leds_cfg = &task_leds_cfg_list[index];
+ p_task_leds_dta = &task_leds_dta_list[index];
+
+ switch (p_task_leds_dta->state)
+ {
+ case ST_LED_XX_OFF:
+ if (true == p_task_leds_dta->flag)
+ {
+ p_task_leds_dta->flag = false;
+ switch(p_task_leds_dta->event)
+ {
+ case EV_LED_XX_ON:
+ p_task_leds_dta->state = ST_LED_XX_ON;
+ HAL_GPIO_WritePin(
+ p_task_leds_cfg->gpio_port,
+ p_task_leds_cfg->pin,
+ p_task_leds_cfg->led_on);
+ break;
+
+ case EV_LED_XX_BLINK:
+ p_task_leds_dta->tick = DEL_LED_XX_BLI;
+ p_task_leds_dta->state = ST_LED_XX_BLINK_ON;
+ HAL_GPIO_WritePin(
+ p_task_leds_cfg->gpio_port,
+ p_task_leds_cfg->pin,
+ p_task_leds_cfg->led_on);
+ break;
+
+ case EV_LED_XX_PULSE:
+ p_task_leds_dta->tick = DEL_LED_XX_PUL;
+ p_task_leds_dta->state = ST_LED_XX_PULSE;
+ HAL_GPIO_WritePin(
+ p_task_leds_cfg->gpio_port,
+ p_task_leds_cfg->pin,
+ p_task_leds_cfg->led_on);
+ default:
+ break;
+ }
+ }
+ break;
+
+ case ST_LED_XX_ON:
+ if ((true == p_task_leds_dta->flag)
+ && (EV_LED_XX_OFF == p_task_leds_dta->event))
+ {
+ p_task_leds_dta->flag = false;
+ p_task_leds_dta->state = ST_LED_XX_OFF;
+ HAL_GPIO_WritePin(
+ p_task_leds_cfg->gpio_port,
+ p_task_leds_cfg->pin,
+ p_task_leds_cfg->led_off);
+ }
+
+ break;
+
+ case ST_LED_XX_BLINK_ON:
+ if (true == p_task_leds_dta->flag)
+ {
+ p_task_leds_dta->flag = false;
+ switch(p_task_leds_dta->event)
+ {
+ case EV_LED_XX_OFF:
+ p_task_leds_dta->state = ST_LED_XX_OFF;
+ HAL_GPIO_WritePin(
+ p_task_leds_cfg->gpio_port,
+ p_task_leds_cfg->pin,
+ p_task_leds_cfg->led_off);
+ break;
+ case EV_LED_XX_ON:
+ p_task_leds_dta->state = ST_LED_XX_ON;
+ HAL_GPIO_WritePin(
+ p_task_leds_cfg->gpio_port,
+ p_task_leds_cfg->pin,
+ p_task_leds_cfg->led_on);
+ default:
+ break;
+ }
+ }
+
+ if (DEL_LED_XX_MIN == p_task_leds_dta->tick)
+ {
+ p_task_leds_dta->state = ST_LED_XX_BLINK_OFF;
+ p_task_leds_dta->tick = DEL_LED_XX_BLI;
+ HAL_GPIO_WritePin(
+ p_task_leds_cfg->gpio_port,
+ p_task_leds_cfg->pin,
+ p_task_leds_cfg->led_off);
+ }
+
+ if (DEL_LED_XX_MIN < p_task_leds_dta->tick)
+ {
+ p_task_leds_dta->tick--;
+ }
+ break;
+
+ case ST_LED_XX_BLINK_OFF:
+ if (true == p_task_leds_dta->flag)
+ {
+ p_task_leds_dta->flag = false;
+ switch(p_task_leds_dta->event)
+ {
+ case EV_LED_XX_OFF:
+ p_task_leds_dta->state = ST_LED_XX_OFF;
+ HAL_GPIO_WritePin(
+ p_task_leds_cfg->gpio_port,
+ p_task_leds_cfg->pin,
+ p_task_leds_cfg->led_off);
+ break;
+ case EV_LED_XX_ON:
+ p_task_leds_dta->state = ST_LED_XX_ON;
+ HAL_GPIO_WritePin(
+ p_task_leds_cfg->gpio_port,
+ p_task_leds_cfg->pin,
+ p_task_leds_cfg->led_on);
+ default:
+ break;
+ }
+ }
+
+ if (DEL_LED_XX_MIN == p_task_leds_dta->tick)
+ {
+ p_task_leds_dta->state = ST_LED_XX_BLINK_ON;
+ p_task_leds_dta->tick = DEL_LED_XX_BLI;
+ HAL_GPIO_WritePin(
+ p_task_leds_cfg->gpio_port,
+ p_task_leds_cfg->pin,
+ p_task_leds_cfg->led_on);
+ }
+
+ if (DEL_LED_XX_MIN < p_task_leds_dta->tick)
+ {
+ p_task_leds_dta->tick--;
+ }
+ break;
+
+ case ST_LED_XX_PULSE:
+ if (DEL_LED_XX_MIN == p_task_leds_dta->tick)
+ {
+ p_task_leds_dta->state = ST_LED_XX_OFF;
+ HAL_GPIO_WritePin(
+ p_task_leds_cfg->gpio_port,
+ p_task_leds_cfg->pin,
+ p_task_leds_cfg->led_off);
+ }
+
+ if (DEL_LED_XX_MIN < p_task_leds_dta->tick)
+ {
+ p_task_leds_dta->tick--;
+ }
+ break;
+
+ default:
+ p_task_leds_dta->tick = DEL_LED_XX_MIN;
+ p_task_leds_dta->state = ST_LED_XX_OFF;
+ p_task_leds_dta->event = EV_LED_XX_OFF;
+ p_task_leds_dta->flag = false;
+ break;
+ }
+ }
+}
diff --git a/firmware/app/src/task_leds_interface.c b/firmware/app/src/task_leds_interface.c
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2023 Juan Manuel Cruz <jcruz@fi.uba.ar> <jcruz@frba.utn.edu.ar>.
+ * Copyright (c) 2026 Martin Javier Klöckner <mklockner@fi.uba.ar>
+ *
+ * See file `LICENSE` for full details
+ */
+
+#include "main.h"
+
+#include "logger.h"
+#include "dwt.h"
+
+#include "app.h"
+#include "task_leds_attribute.h"
+
+void task_leds_interface_put_event(task_leds_ev_t event, task_leds_id_t identifier)
+{
+ task_leds_dta_t *p_task_leds_dta;
+ p_task_leds_dta = &task_leds_dta_list[identifier];
+ p_task_leds_dta->event = event;
+ p_task_leds_dta->flag = true;
+}
diff --git a/firmware/app/src/task_system.c b/firmware/app/src/task_system.c
@@ -14,8 +14,8 @@
#include "app.h"
#include "task_system_attribute.h"
#include "task_system_interface.h"
-#include "task_led_attribute.h"
-#include "task_led_interface.h"
+#include "task_leds_attribute.h"
+#include "task_leds_interface.h"
#include "task_menu_attribute.h"
#include "task_menu_interface.h"
@@ -159,8 +159,8 @@ void task_system_statechart(void *parameters)
case EV_SYS_BTN_D_ACTIVE:
p_task_system_dta->state = ST_SYS_CLOCK;
task_menu_interface_put_event(EV_MEN_ST_CLOCK);
- task_led_interface_put_event(EV_LED_XX_BLINK, ID_LED_A);
- task_led_interface_put_event(EV_LED_XX_BLINK, ID_LED_B);
+ task_leds_interface_put_event(EV_LED_XX_BLINK, ID_LED_A);
+ task_leds_interface_put_event(EV_LED_XX_BLINK, ID_LED_B);
break;
default: break;
}
@@ -177,8 +177,8 @@ void task_system_statechart(void *parameters)
case EV_SYS_BTN_D_ACTIVE:
p_task_system_dta->state = ST_SYS_IDLE;
task_menu_interface_put_event(EV_MEN_ST_IDLE);
- task_led_interface_put_event(EV_LED_XX_OFF, ID_LED_A);
- task_led_interface_put_event(EV_LED_XX_OFF, ID_LED_B);
+ task_leds_interface_put_event(EV_LED_XX_OFF, ID_LED_A);
+ task_leds_interface_put_event(EV_LED_XX_OFF, ID_LED_B);
break;
case EV_SYS_BTN_B_ACTIVE:
task_system_rtc_increment_hour();