commit 7fcc44f203721f560b9cd4ee13309da0a3acc528
parent e427519f0dc124434c94edef2504a9549a273027
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date: Mon, 29 Sep 2025 14:06:33 -0300
Fix formatting; `set ff=unix`
Follow Michael Barr C coding standard
Diffstat:
2 files changed, 284 insertions(+), 275 deletions(-)
diff --git a/app/inc/task_system_attribute.h b/app/inc/task_system_attribute.h
@@ -49,65 +49,73 @@ extern "C" {
/********************** typedef **********************************************/
/* System Statechart - State Transition Table */
-/* ------------------------+-----------------------+-----------------------+-----------------------+------------------------
- * | Current | Event | | Next | |
- * | State | (Parameters) | [Guard] | State | Actions |
- * |=======================+=======================+=======================+=======================+=======================|
- * | INICIAL | | | ST_SYS_IDLE | |
- * |-----------------------+-----------------------+-----------------------+-----------------------+-----------------------|
- * | ST_SYS_IDLE | EV_SYS_LOOP_DET | | ST_SYS_ACTIVE_01 | |
- * | | | | | |
- * |-----------------------+-----------------------+-----------------------+-----------------------+-----------------------|
- * | ST_SYS_ACTIVE_01 | EV_SYS_MANUAL_BTN | | ST_SYS_ACTIVE_02 | tick = TICK_MAX |
- * | | | | | put_event_t.._actuator|
- * | | | | | (event, identifier) |
- * |-----------------------+-----------------------+-----------------------+-----------------------+-----------------------|
- * | ST_SYS_ACTIVE_02 | | [tick == 0] | ST_SYS_ACTIVE_03 | put_event_t.._actuator|
- * | | | | | (event, identifier) |
- * | | +-----------------------+-----------------------+-----------------------|
- * | | | [tick > 0] | ST_SYS_ACTIVE_02 | tick-- |
- * |-----------------------+-----------------------+-----------------------+-----------------------+-----------------------|
- * | ST_SYS_ACTIVE_03 | EV_SYS_NOT_LOOP_DET | | ST_SYS_ACTIVE_04 | |
- * | | | | | |
- * |-----------------------+-----------------------+-----------------------+-----------------------+-----------------------|
- * | ST_SYS_ACTIVE_04 | EV_SYS_IR_PHO_CELL | | ST_SYS_ACTIVE_05 | |
- * | | | | | |
- * |-----------------------+-----------------------+-----------------------+-----------------------+-----------------------|
- * | ST_SYS_ACTIVE_05 | EV_SYS_IR_NOT_PHO_CELL| | ST_SYS_ACTIVE_06 | tick = TICK_MAX |
- * | | | | | put_event_t.._actuator|
- * | | | | | (event, identifier) |
- * |-----------------------+-----------------------+-----------------------+-----------------------+-----------------------|
- * | ST_SYS_ACTIVE_06 | | [tick == 0] | ST_SYS_IDLE | put_event_t.._actuator|
- * | | | | | (event, identifier) |
- * | | +-----------------------+-----------------------+-----------------------|
- * | | | [tick > 0] | ST_SYS_ACTIVE_06 | tick-- |
- * ------------------------+-----------------------+-----------------------+-----------------------+------------------------
+/* +------------------+----------------------- +-------------+------------------+-----------------------+
+ * | Current | Event | | Next | |
+ * | State | (Parameters) | [Guard] | State | Actions |
+ * |==================+======================= +=============+==================+=======================|
+ * | INICIAL | | | ST_SYS_IDLE | |
+ * |------------------+----------------------- +-------------+------------------+-----------------------|
+ * | ST_SYS_IDLE | EV_SYS_LOOP_DET | | ST_SYS_ACTIVE_01 | |
+ * | | | | | |
+ * |------------------+----------------------- +-------------+------------------+-----------------------|
+ * | ST_SYS_ACTIVE_01 | EV_SYS_MANUAL_BTN | | ST_SYS_ACTIVE_02 | tick = TICK_MAX |
+ * | | | | | put_event_t.._actuator|
+ * | | | | | (event, identifier) |
+ * |------------------+----------------------- +-------------+------------------+-----------------------|
+ * | ST_SYS_ACTIVE_02 | | [tick == 0] | ST_SYS_ACTIVE_03 | put_event_t.._actuator|
+ * | | | | | (event, identifier) |
+ * | | +-------------+------------------+-----------------------|
+ * | | | [tick > 0] | ST_SYS_ACTIVE_02 | tick-- |
+ * | | | | | |
+ * |------------------+----------------------- +-------------+------------------+-----------------------|
+ * | ST_SYS_ACTIVE_03 | EV_SYS_NOT_LOOP_DET | | ST_SYS_ACTIVE_04 | |
+ * | | | | | |
+ * |------------------+----------------------- +-------------+------------------+-----------------------|
+ * | ST_SYS_ACTIVE_04 | EV_SYS_IR_PHO_CELL | | ST_SYS_ACTIVE_05 | |
+ * | | | | | |
+ * |------------------+----------------------- +-------------+------------------+-----------------------|
+ * | ST_SYS_ACTIVE_05 | EV_SYS_IR_NOT_PHO_CELL | | ST_SYS_ACTIVE_06 | tick = TICK_MAX |
+ * | | | | | put_event_t.._actuator|
+ * | | | | | (event, identifier) |
+ * |------------------+----------------------- +-------------+------------------+-----------------------|
+ * | ST_SYS_ACTIVE_06 | | [tick == 0] | ST_SYS_IDLE | put_event_t.._actuator|
+ * | | | | | (event, identifier) |
+ * | | +-------------+------------------+-----------------------|
+ * | | | [tick > 0] | ST_SYS_ACTIVE_06 | tick-- |
+ * | | | | | |
+ * +------------------+----------------------- +-------------+------------------+-----------------------+
*/
/* Events to excite Task System */
-typedef enum task_system_ev {EV_SYS_IDLE,
- EV_SYS_LOOP_DET,
- EV_SYS_NOT_LOOP_DET,
- EV_SYS_MANUAL_BTN,
- EV_SYS_NOT_MANUAL_BTN,
- EV_SYS_IR_PHO_CELL,
- EV_SYS_NOT_IR_PHO_CELL} task_system_ev_t;
+typedef enum
+{
+ EV_SYS_IDLE,
+ EV_SYS_LOOP_DET,
+ EV_SYS_NOT_LOOP_DET,
+ EV_SYS_MANUAL_BTN,
+ EV_SYS_NOT_MANUAL_BTN,
+ EV_SYS_IR_PHO_CELL,
+ EV_SYS_NOT_IR_PHO_CELL
+} task_system_ev_t;
/* State of Task System */
-typedef enum task_system_st {ST_SYS_IDLE,
- ST_SYS_ACTIVE_01,
- ST_SYS_ACTIVE_02,
- ST_SYS_ACTIVE_03,
- ST_SYS_ACTIVE_04,
- ST_SYS_ACTIVE_05,
- ST_SYS_ACTIVE_06} task_system_st_t;
+typedef enum
+{
+ ST_SYS_IDLE,
+ ST_SYS_ACTIVE_01,
+ ST_SYS_ACTIVE_02,
+ ST_SYS_ACTIVE_03,
+ ST_SYS_ACTIVE_04,
+ ST_SYS_ACTIVE_05,
+ ST_SYS_ACTIVE_06
+} task_system_st_t;
typedef struct
{
- uint32_t tick;
- task_system_st_t state;
- task_system_ev_t event;
- bool flag;
+ uint32_t tick;
+ task_system_st_t state;
+ task_system_ev_t event;
+ bool flag;
} task_system_dta_t;
/********************** external data declaration ****************************/
diff --git a/app/src/task_system.c b/app/src/task_system.c
@@ -1,224 +1,225 @@
-/*
- * Copyright (c) 2023 Juan Manuel Cruz <jcruz@fi.uba.ar> <jcruz@frba.utn.edu.ar>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * @file : task_system.c
- * @date : Set 26, 2023
- * @author : Juan Manuel Cruz <jcruz@fi.uba.ar> <jcruz@frba.utn.edu.ar>
- * @version v1.0.0
- */
-
-/********************** inclusions *******************************************/
-/* Project includes */
-#include "main.h"
-
-/* Demo includes */
-#include "logger.h"
-#include "dwt.h"
-
-/* Application & Tasks includes */
-#include "board.h"
-#include "app.h"
-#include "task_system_attribute.h"
-#include "task_system_interface.h"
-#include "task_actuator_attribute.h"
-#include "task_actuator_interface.h"
-
-/********************** macros and definitions *******************************/
-#define G_TASK_SYS_CNT_INI 0ul
-#define G_TASK_SYS_TICK_CNT_INI 0ul
-
-#define DEL_SYS_MIN 0ul
-#define DEL_SYS_MED 50ul
-#define DEL_SYS_MAX 500ul
-
-/********************** internal data declaration ****************************/
-task_system_dta_t task_system_dta =
- {DEL_SYS_MIN, ST_SYS_IDLE, EV_SYS_IDLE, false};
-
-#define SYSTEM_DTA_QTY (sizeof(task_system_dta)/sizeof(task_system_dta_t))
-
-/********************** internal functions declaration ***********************/
-void task_system_statechart(void);
-
-/********************** internal data definition *****************************/
-const char *p_task_system = "Task System (System Statechart)";
-const char *p_task_system_ = "Non-Blocking & Update By Time Code";
-
-/********************** external data declaration ****************************/
-uint32_t g_task_system_cnt;
-volatile uint32_t g_task_system_tick_cnt;
-
-/********************** external functions definition ************************/
-void task_system_init(void *parameters)
-{
- task_system_dta_t *p_task_system_dta;
- task_system_st_t state;
- task_system_ev_t event;
- bool b_event;
-
- /* Print out: Task Initialized */
- LOGGER_INFO(" ");
- LOGGER_INFO(" %s is running - %s", GET_NAME(task_system_init), p_task_system);
- LOGGER_INFO(" %s is a %s", GET_NAME(task_system), p_task_system_);
-
- /* Init & Print out: Task execution counter */
- g_task_system_cnt = G_TASK_SYS_CNT_INI;
- LOGGER_INFO(" %s = %lu", GET_NAME(g_task_system_cnt), g_task_system_cnt);
-
- init_queue_event_task_system();
-
- /* Update Task Actuator Configuration & Data Pointer */
- p_task_system_dta = &task_system_dta;
-
- /* Init & Print out: Task execution FSM */
- state = ST_SYS_IDLE;
- p_task_system_dta->state = state;
-
- event = EV_SYS_IDLE;
- p_task_system_dta->event = event;
-
- b_event = false;
- p_task_system_dta->flag = b_event;
-
- LOGGER_INFO(" ");
- LOGGER_INFO(" %s = %lu %s = %lu %s = %s",
- GET_NAME(state), (uint32_t)state,
- GET_NAME(event), (uint32_t)event,
- GET_NAME(b_event), (b_event ? "true" : "false"));
-}
-
-void task_system_update(void *parameters)
-{
- bool b_time_update_required = false;
-
- /* Protect shared resource */
- __asm("CPSID i"); /* disable interrupts */
- if (G_TASK_SYS_TICK_CNT_INI < g_task_system_tick_cnt)
- {
- /* Update Tick Counter */
- g_task_system_tick_cnt--;
- b_time_update_required = true;
- }
- __asm("CPSIE i"); /* enable interrupts */
-
- while (b_time_update_required)
- {
- /* Update Task Counter */
- g_task_system_cnt++;
-
- /* Run Task Statechart */
- task_system_statechart();
-
- /* Protect shared resource */
- __asm("CPSID i"); /* disable interrupts */
- if (G_TASK_SYS_TICK_CNT_INI < g_task_system_tick_cnt)
- {
- /* Update Tick Counter */
- g_task_system_tick_cnt--;
- b_time_update_required = true;
- }
- else
- {
- b_time_update_required = false;
- }
- __asm("CPSIE i"); /* enable interrupts */
- }
-}
-
-void task_system_statechart(void)
-{
- task_system_dta_t *p_task_system_dta;
-
- /* Update Task System Data Pointer */
- p_task_system_dta = &task_system_dta;
-
- if (true == any_event_task_system())
- {
- p_task_system_dta->flag = true;
- p_task_system_dta->event = get_event_task_system();
- }
-
- switch (p_task_system_dta->state)
- {
- case ST_SYS_IDLE:
-
- if ((true == p_task_system_dta->flag) && (EV_SYS_LOOP_DET == p_task_system_dta->event))
- {
- p_task_system_dta->flag = false;
- put_event_task_actuator(EV_LED_XX_ON, ID_LED_A);
- p_task_system_dta->state = ST_SYS_ACTIVE_01;
- }
-
- break;
-
- case ST_SYS_ACTIVE_01:
-
- if ((true == p_task_system_dta->flag) && (EV_SYS_IDLE == p_task_system_dta->event))
- {
- p_task_system_dta->flag = false;
- put_event_task_actuator(EV_LED_XX_OFF, ID_LED_A);
- p_task_system_dta->state = ST_SYS_IDLE;
- }
-
- break;
-
- case ST_SYS_ACTIVE_02:
-
- break;
-
- case ST_SYS_ACTIVE_03:
-
- break;
-
- case ST_SYS_ACTIVE_04:
-
- break;
-
- case ST_SYS_ACTIVE_05:
-
- break;
-
- case ST_SYS_ACTIVE_06:
-
- break;
-
- default:
-
- p_task_system_dta->tick = DEL_SYS_MIN;
- p_task_system_dta->state = ST_SYS_IDLE;
- p_task_system_dta->event = EV_SYS_IDLE;
- p_task_system_dta->flag = false;
-
- break;
- }
-}
-
-/********************** end of file ******************************************/
+/*
+ * Copyright (c) 2023 Juan Manuel Cruz <jcruz@fi.uba.ar> <jcruz@frba.utn.edu.ar>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @file : task_system.c
+ * @date : Set 26, 2023
+ * @author : Juan Manuel Cruz <jcruz@fi.uba.ar> <jcruz@frba.utn.edu.ar>
+ * @version v1.0.0
+ */
+
+/********************** inclusions *******************************************/
+/* Project includes */
+#include "main.h"
+
+/* Demo includes */
+#include "logger.h"
+#include "dwt.h"
+
+/* Application & Tasks includes */
+#include "board.h"
+#include "app.h"
+#include "task_system_attribute.h"
+#include "task_system_interface.h"
+#include "task_actuator_attribute.h"
+#include "task_actuator_interface.h"
+
+/********************** macros and definitions *******************************/
+#define G_TASK_SYS_CNT_INI 0ul
+#define G_TASK_SYS_TICK_CNT_INI 0ul
+
+#define DEL_SYS_MIN 0ul
+#define DEL_SYS_MED 50ul
+#define DEL_SYS_MAX 500ul
+
+/********************** internal data declaration ****************************/
+task_system_dta_t task_system_dta = {
+ DEL_SYS_MIN, ST_SYS_IDLE, EV_SYS_IDLE, false
+};
+
+#define SYSTEM_DTA_QTY (sizeof(task_system_dta)/sizeof(task_system_dta_t))
+
+/********************** internal functions declaration ***********************/
+void task_system_statechart(void);
+
+/********************** internal data definition *****************************/
+const char *p_task_system = "Task System (System Statechart)";
+const char *p_task_system_ = "Non-Blocking & Update By Time Code";
+
+/********************** external data declaration ****************************/
+uint32_t g_task_system_cnt;
+volatile uint32_t g_task_system_tick_cnt;
+
+/********************** external functions definition ************************/
+void task_system_init(void *parameters)
+{
+ task_system_dta_t *p_task_system_dta;
+ task_system_st_t state;
+ task_system_ev_t event;
+ bool b_event;
+
+ /* Print out: Task Initialized */
+ LOGGER_INFO(" ");
+ LOGGER_INFO(" %s is running - %s", GET_NAME(task_system_init), p_task_system);
+ LOGGER_INFO(" %s is a %s", GET_NAME(task_system), p_task_system_);
+
+ /* Init & Print out: Task execution counter */
+ g_task_system_cnt = G_TASK_SYS_CNT_INI;
+ LOGGER_INFO(" %s = %lu", GET_NAME(g_task_system_cnt), g_task_system_cnt);
+
+ init_queue_event_task_system();
+
+ /* Update Task Actuator Configuration & Data Pointer */
+ p_task_system_dta = &task_system_dta;
+
+ /* Init & Print out: Task execution FSM */
+ state = ST_SYS_IDLE;
+ p_task_system_dta->state = state;
+
+ event = EV_SYS_IDLE;
+ p_task_system_dta->event = event;
+
+ b_event = false;
+ p_task_system_dta->flag = b_event;
+
+ LOGGER_INFO(" ");
+ LOGGER_INFO(" %s = %lu %s = %lu %s = %s",
+ GET_NAME(state), (uint32_t)state,
+ GET_NAME(event), (uint32_t)event,
+ GET_NAME(b_event), (b_event ? "true" : "false"));
+}
+
+void task_system_update(void *parameters)
+{
+ bool b_time_update_required = false;
+
+ /* Protect shared resource */
+ __asm("CPSID i"); /* disable interrupts */
+ if (G_TASK_SYS_TICK_CNT_INI < g_task_system_tick_cnt)
+ {
+ /* Update Tick Counter */
+ g_task_system_tick_cnt--;
+ b_time_update_required = true;
+ }
+ __asm("CPSIE i"); /* enable interrupts */
+
+ while (b_time_update_required)
+ {
+ /* Update Task Counter */
+ g_task_system_cnt++;
+
+ /* Run Task Statechart */
+ task_system_statechart();
+
+ /* Protect shared resource */
+ __asm("CPSID i"); /* disable interrupts */
+ if (G_TASK_SYS_TICK_CNT_INI < g_task_system_tick_cnt)
+ {
+ /* Update Tick Counter */
+ g_task_system_tick_cnt--;
+ b_time_update_required = true;
+ }
+ else
+ {
+ b_time_update_required = false;
+ }
+ __asm("CPSIE i"); /* enable interrupts */
+ }
+}
+
+void task_system_statechart(void)
+{
+ task_system_dta_t *p_task_system_dta;
+
+ /* Update Task System Data Pointer */
+ p_task_system_dta = &task_system_dta;
+
+ if (true == any_event_task_system())
+ {
+ p_task_system_dta->flag = true;
+ p_task_system_dta->event = get_event_task_system();
+ }
+
+ switch (p_task_system_dta->state)
+ {
+ case ST_SYS_IDLE:
+
+ if ((true == p_task_system_dta->flag) && (EV_SYS_LOOP_DET == p_task_system_dta->event))
+ {
+ p_task_system_dta->flag = false;
+ put_event_task_actuator(EV_LED_XX_ON, ID_LED_A);
+ p_task_system_dta->state = ST_SYS_ACTIVE_01;
+ }
+
+ break;
+
+ case ST_SYS_ACTIVE_01:
+
+ if ((true == p_task_system_dta->flag) && (EV_SYS_IDLE == p_task_system_dta->event))
+ {
+ p_task_system_dta->flag = false;
+ put_event_task_actuator(EV_LED_XX_OFF, ID_LED_A);
+ p_task_system_dta->state = ST_SYS_IDLE;
+ }
+
+ break;
+
+ case ST_SYS_ACTIVE_02:
+
+ break;
+
+ case ST_SYS_ACTIVE_03:
+
+ break;
+
+ case ST_SYS_ACTIVE_04:
+
+ break;
+
+ case ST_SYS_ACTIVE_05:
+
+ break;
+
+ case ST_SYS_ACTIVE_06:
+
+ break;
+
+ default:
+
+ p_task_system_dta->tick = DEL_SYS_MIN;
+ p_task_system_dta->state = ST_SYS_IDLE;
+ p_task_system_dta->event = EV_SYS_IDLE;
+ p_task_system_dta->flag = false;
+
+ break;
+ }
+}
+
+/********************** end of file ******************************************/