commit 2aea0164f60088ec3a3029537bf68cf1a8557fff
parent e837999a0d7f554cc16fa213a426fc8a3ea3bbcd
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date: Tue, 31 Mar 2026 13:15:46 -0300
Agregar nueva tarea `task_buzzer`
Diffstat:
8 files changed, 342 insertions(+), 5 deletions(-)
diff --git a/firmware/app/inc/task_buzzer.h b/firmware/app/inc/task_buzzer.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_BUZZER_H_
+#define TASK_INC_TASK_BUZZER_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern uint32_t g_task_buzzer_cnt;
+extern volatile uint32_t g_task_buzzer_tick_cnt;
+
+void task_buzzer_init(void *parameters);
+void task_buzzer_update(void *parameters);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TASK_INC_TASK_BUZZER_H_ */
diff --git a/firmware/app/inc/task_buzzer_attribute.h b/firmware/app/inc/task_buzzer_attribute.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2026 Martin Javier Klöckner <mklockner@fi.uba.ar>
+ *
+ * See file `LICENSE` for full details
+ */
+
+#ifndef TASK_INC_TASK_BUZZER_ATTRIBUTE_H_
+#define TASK_INC_TASK_BUZZER_ATTRIBUTE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Buzzer Statechart - State Transition Table
+ *
+ * +---------+--------------+---------+-------+---------+
+ * | Current | Event | | Next | |
+ * | State | (Parameters) | [Guard] | State | Actions |
+ * |=========+==============+=========+=======+=========|
+ * | INICIAL | | | | |
+ * +---------+--------------+---------+-------+---------+
+ *
+ */
+
+typedef enum {
+ EV_BUZ_XX_OFF,
+ EV_BUZ_XX_SHORT_BEEP,
+ EV_BUZ_XX_LONG_BEEP
+} task_buzzer_ev_t;
+
+typedef enum {
+ ST_BUZ_XX_OFF,
+ ST_BUZ_XX_ON
+} task_buzzer_st_t;
+
+typedef enum {
+ ID_BUZ_A
+} task_buzzer_id_t;
+
+typedef struct {
+ task_buzzer_id_t identifier;
+ TIM_HandleTypeDef *htim;
+ uint32_t tim_channel;
+ uint16_t freq;
+ uint32_t short_beep_ms;
+ uint32_t long_beep_ms;
+} task_buzzer_cfg_t;
+
+typedef struct {
+ uint32_t tick;
+ task_buzzer_st_t state;
+ task_buzzer_ev_t event;
+ bool event_flag;
+} task_buzzer_dta_t;
+
+extern task_buzzer_dta_t task_buzzer_dta_list[];
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TASK_INC_TASK_BUZZER_ATTRIBUTE_H_ */
diff --git a/firmware/app/inc/task_buzzer_interface.h b/firmware/app/inc/task_buzzer_interface.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2026 Martin Javier Klöckner <mklockner@fi.uba.ar>
+ *
+ * See file `LICENSE` for full details
+ */
+
+#ifndef TASK_INC_TASK_BUZZER_INTERFACE_H_
+#define TASK_INC_TASK_BUZZER_INTERFACE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void task_buzzer_interface_put_event(task_buzzer_ev_t event, task_buzzer_id_t identifier);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TASK_INC_TASK_BUZZER_INTERFACE_H_ */
diff --git a/firmware/app/src/app.c b/firmware/app/src/app.c
@@ -12,11 +12,12 @@
#include "app.h"
#include "task_system.h"
-#include "task_temp_sensor.h"
-#include "task_temp_ctrl.h"
#include "task_buttons.h"
-#include "task_menu.h"
+#include "task_buzzer.h"
#include "task_leds.h"
+#include "task_menu.h"
+#include "task_temp_ctrl.h"
+#include "task_temp_sensor.h"
#define G_APP_CNT_INI 0ul
#define G_APP_TICK_CNT_INI 0ul
@@ -47,6 +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_buzzer_init, task_buzzer_update, NULL},
{task_leds_init, task_leds_update, NULL},
{task_menu_init, task_menu_update, &shared_data},
{task_temp_ctrl_init, task_temp_ctrl_update, &shared_data},
@@ -164,6 +166,7 @@ void HAL_SYSTICK_Callback(void)
g_task_system_tick_cnt++;
g_task_buttons_tick_cnt++;
+ g_task_buzzer_tick_cnt++;
g_task_leds_tick_cnt++;
g_task_menu_tick_cnt++;
g_task_temp_ctrl_tick_cnt++;
diff --git a/firmware/app/src/task_buttons.c b/firmware/app/src/task_buttons.c
@@ -14,8 +14,8 @@
#include "task_buttons_attribute.h"
#include "task_system_attribute.h"
#include "task_system_interface.h"
-#include "task_menu_attribute.h"
-#include "task_menu_interface.h"
+#include "task_buzzer_attribute.h"
+#include "task_buzzer_interface.h"
#define TASK_BTN_TICK_CNT_INI 0ul
@@ -149,6 +149,7 @@ void task_buttons_statechart(void)
if (0 == p_task_buttons_dta->tick) {
p_task_buttons_dta->state = ST_BTN_XX_DOWN;
task_system_interface_put_event(p_task_buttons_cfg->signal_down);
+ task_buzzer_interface_put_event(EV_BUZ_XX_SHORT_BEEP, ID_BUZ_A);
}
else
{
diff --git a/firmware/app/src/task_buzzer.c b/firmware/app/src/task_buzzer.c
@@ -0,0 +1,202 @@
+/*
+ * 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_buzzer_attribute.h"
+#include "task_buzzer_interface.h"
+
+#define G_TASK_BUZZER_TICK_CNT_INI 0ul
+
+#define TICK_INI_MS 0ul
+#define BUZZER_FREQ (1000ul)
+#define SHORT_BEEP_MS 35ul
+#define LONG_BEEP_MS 500ul
+
+const task_buzzer_cfg_t task_buzzer_cfg_list[] = {
+ {ID_BUZ_A, &htim3, TIM_CHANNEL_1, BUZZER_FREQ, SHORT_BEEP_MS, LONG_BEEP_MS}
+};
+
+#define BUZZER_CFG_QTY (sizeof(task_buzzer_cfg_list)/sizeof(task_buzzer_cfg_t))
+
+task_buzzer_dta_t task_buzzer_dta_list[] = {
+ {TICK_INI_MS, ST_BUZ_XX_OFF, EV_BUZ_XX_OFF, false},
+};
+
+#define BUZZER_DTA_QTY (sizeof(task_buzzer_dta_list)/sizeof(task_buzzer_dta_t))
+
+// Private functions declaration
+void task_buzzer_statechart(void);
+uint16_t task_buzzer_freq_to_pres(uint16_t freq);
+
+// External data declaration
+volatile uint32_t g_task_buzzer_tick_cnt;
+
+// External functions definition
+void task_buzzer_init(void *parameters)
+{
+ uint32_t index;
+ const task_buzzer_cfg_t *p_task_buzzer_cfg;
+ task_buzzer_dta_t *p_task_buzzer_dta;
+
+ LOGGER_INFO("Initializing `task_buzzer`...");
+
+ g_task_buzzer_tick_cnt = G_TASK_BUZZER_TICK_CNT_INI;
+
+ for (index = 0; BUZZER_DTA_QTY > index; index++)
+ {
+ p_task_buzzer_cfg = &task_buzzer_cfg_list[index];
+ p_task_buzzer_dta = &task_buzzer_dta_list[index];
+
+ p_task_buzzer_dta->tick = TICK_INI_MS;
+ p_task_buzzer_dta->state = ST_BUZ_XX_OFF;
+ p_task_buzzer_dta->event = EV_BUZ_XX_OFF;
+ p_task_buzzer_dta->event_flag = false;
+
+ __HAL_TIM_SET_PRESCALER(p_task_buzzer_cfg->htim,
+ task_buzzer_freq_to_pres(BUZZER_FREQ));
+
+ HAL_TIM_PWM_Stop(p_task_buzzer_cfg->htim, p_task_buzzer_cfg->tim_channel);
+ }
+}
+
+void task_buzzer_update(void *parameters)
+{
+ bool b_time_update_required = false;
+
+ __asm("CPSID i");
+ if (G_TASK_BUZZER_TICK_CNT_INI < g_task_buzzer_tick_cnt)
+ {
+ g_task_buzzer_tick_cnt--;
+ b_time_update_required = true;
+ }
+ __asm("CPSIE i");
+
+ while (b_time_update_required)
+ {
+ task_buzzer_statechart();
+
+ __asm("CPSID i");
+ if (G_TASK_BUZZER_TICK_CNT_INI < g_task_buzzer_tick_cnt)
+ {
+ g_task_buzzer_tick_cnt--;
+ b_time_update_required = true;
+ }
+ else
+ {
+ b_time_update_required = false;
+ }
+ __asm("CPSIE i");
+ }
+}
+
+void task_buzzer_statechart(void)
+{
+ uint32_t index;
+ const task_buzzer_cfg_t *p_task_buzzer_cfg;
+ task_buzzer_dta_t *p_task_buzzer_dta;
+
+ for (index = 0; BUZZER_DTA_QTY > index; index++)
+ {
+ p_task_buzzer_cfg = &task_buzzer_cfg_list[index];
+ p_task_buzzer_dta = &task_buzzer_dta_list[index];
+
+ switch (p_task_buzzer_dta->state)
+ {
+ case ST_BUZ_XX_OFF:
+ if (true == p_task_buzzer_dta->event_flag)
+ {
+ p_task_buzzer_dta->event_flag = false;
+ switch(p_task_buzzer_dta->event)
+ {
+ case EV_BUZ_XX_SHORT_BEEP:
+ p_task_buzzer_dta->tick = SHORT_BEEP_MS;
+ p_task_buzzer_dta->state = ST_BUZ_XX_ON;
+ HAL_TIM_PWM_Start(p_task_buzzer_cfg->htim,
+ p_task_buzzer_cfg->tim_channel);
+ break;
+
+ case EV_BUZ_XX_LONG_BEEP:
+ p_task_buzzer_dta->tick = LONG_BEEP_MS;
+ p_task_buzzer_dta->state = ST_BUZ_XX_ON;
+ HAL_TIM_PWM_Start(p_task_buzzer_cfg->htim,
+ p_task_buzzer_cfg->tim_channel);
+ break;
+
+ default: break;
+ }
+ }
+ break;
+
+ case ST_BUZ_XX_ON:
+ if (true == p_task_buzzer_dta->event_flag)
+ {
+ p_task_buzzer_dta->event_flag = false;
+ switch(p_task_buzzer_dta->event)
+ {
+ case EV_BUZ_XX_SHORT_BEEP:
+ p_task_buzzer_dta->tick = SHORT_BEEP_MS;
+ p_task_buzzer_dta->state = ST_BUZ_XX_ON;
+ HAL_TIM_PWM_Start(p_task_buzzer_cfg->htim,
+ p_task_buzzer_cfg->tim_channel);
+ break;
+
+ case EV_BUZ_XX_LONG_BEEP:
+ p_task_buzzer_dta->tick = LONG_BEEP_MS;
+ p_task_buzzer_dta->state = ST_BUZ_XX_ON;
+ HAL_TIM_PWM_Start(p_task_buzzer_cfg->htim,
+ p_task_buzzer_cfg->tim_channel);
+ break;
+
+ case EV_BUZ_XX_OFF:
+ default:
+ p_task_buzzer_dta->tick = TICK_INI_MS;
+ p_task_buzzer_dta->state = ST_BUZ_XX_OFF;
+ HAL_TIM_PWM_Stop(p_task_buzzer_cfg->htim,
+ p_task_buzzer_cfg->tim_channel);
+ break;
+ }
+ }
+
+ if (0 == p_task_buzzer_dta->tick)
+ {
+ p_task_buzzer_dta->state = ST_BUZ_XX_OFF;
+ HAL_TIM_PWM_Stop(p_task_buzzer_cfg->htim,
+ p_task_buzzer_cfg->tim_channel);
+ }
+ else
+ {
+ p_task_buzzer_dta->tick--;
+ }
+ break;
+
+ default:
+ p_task_buzzer_dta->tick = TICK_INI_MS;
+ p_task_buzzer_dta->state = ST_BUZ_XX_OFF;
+ p_task_buzzer_dta->event = EV_BUZ_XX_OFF;
+ p_task_buzzer_dta->event_flag = false;
+ HAL_TIM_PWM_Start(p_task_buzzer_cfg->htim,
+ p_task_buzzer_cfg->tim_channel);
+ break;
+ }
+ }
+}
+
+#define APB1_TIMER_CLOCK 64000000UL
+#define TIMER3_ARR 8000UL
+
+uint16_t task_buzzer_freq_to_pres(uint16_t freq)
+{
+ if (0 == freq)
+ {
+ return 0;
+ }
+ return ((APB1_TIMER_CLOCK / (freq * (TIMER3_ARR - 1))) - 1);
+}
diff --git a/firmware/app/src/task_buzzer_interface.c b/firmware/app/src/task_buzzer_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_buzzer_attribute.h"
+
+void task_buzzer_interface_put_event(task_buzzer_ev_t event, task_buzzer_id_t identifier)
+{
+ task_buzzer_dta_t *p_task_buzzer_dta;
+ p_task_buzzer_dta = &task_buzzer_dta_list[identifier];
+ p_task_buzzer_dta->event = event;
+ p_task_buzzer_dta->event_flag = true;
+}
diff --git a/firmware/app/src/task_system.c b/firmware/app/src/task_system.c
@@ -17,6 +17,8 @@
#include "task_leds_interface.h"
#include "task_menu_attribute.h"
#include "task_menu_interface.h"
+#include "task_buzzer_attribute.h"
+#include "task_buzzer_interface.h"
#define G_TASK_SYS_CNT_INI 0ul
#define G_TASK_SYS_TICK_CNT_INI 0ul
@@ -248,6 +250,7 @@ void task_system_statechart(void *parameters)
case EV_SYS_BTN_C_ACTIVE:
p_shared_data->temp_ctrl_enabled = !p_shared_data->temp_ctrl_enabled;
task_menu_interface_put_event(EV_MEN_DISPLAY_UPDATE);
+ task_buzzer_interface_put_event(EV_BUZ_XX_LONG_BEEP, ID_BUZ_A);
break;
case EV_SYS_BTN_A_ACTIVE:
case EV_SYS_BTN_D_ACTIVE: