commit b96a32ad6862a3b6ba423d573da690bcd1620454
parent 3d0c1ba115b1f809258ef6dac9c50ae7b918d319
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date: Mon, 29 Sep 2025 11:38:55 -0300
fix format: apply Michael Barr C coding standard
replace tabs for spaces, set unix file format (instead of dos)
Diffstat:
3 files changed, 535 insertions(+), 549 deletions(-)
diff --git a/Core/Src/main.c b/Core/Src/main.c
@@ -1,273 +1,268 @@
-/* USER CODE BEGIN Header */
-/**
- ******************************************************************************
- * @file : main.c
- * @brief : Main program body
- ******************************************************************************
- * @attention
- *
- * Copyright (c) 2025 STMicroelectronics.
- * All rights reserved.
- *
- * This software is licensed under terms that can be found in the LICENSE file
- * in the root directory of this software component.
- * If no LICENSE file comes with this software, it is provided AS-IS.
- *
- ******************************************************************************
- */
-/* USER CODE END Header */
-/* Includes ------------------------------------------------------------------*/
-#include "main.h"
-
-/* Private includes ----------------------------------------------------------*/
-/* USER CODE BEGIN Includes */
-
-/* Application includes. */
-#include "logger.h"
-#include "app.h"
-
-/* USER CODE END Includes */
-
-/* Private typedef -----------------------------------------------------------*/
-/* USER CODE BEGIN PTD */
-
-/* USER CODE END PTD */
-
-/* Private define ------------------------------------------------------------*/
-/* USER CODE BEGIN PD */
-
-/* USER CODE END PD */
-
-/* Private macro -------------------------------------------------------------*/
-/* USER CODE BEGIN PM */
-
-/* USER CODE END PM */
-
-/* Private variables ---------------------------------------------------------*/
-UART_HandleTypeDef huart2;
-
-/* USER CODE BEGIN PV */
-
-/* USER CODE END PV */
-
-/* Private function prototypes -----------------------------------------------*/
-void SystemClock_Config(void);
-static void MX_GPIO_Init(void);
-static void MX_USART2_UART_Init(void);
-/* USER CODE BEGIN PFP */
-
-/* USER CODE END PFP */
-
-/* Private user code ---------------------------------------------------------*/
-/* USER CODE BEGIN 0 */
-#if (1 == LOGGER_CONFIG_USE_SEMIHOSTING)
-
-extern void initialise_monitor_handles(void);
-
-#endif
-
-/* USER CODE END 0 */
-
-/**
- * @brief The application entry point.
- * @retval int
- */
-int main(void)
-{
-
- /* USER CODE BEGIN 1 */
- #if (1 == LOGGER_CONFIG_USE_SEMIHOSTING)
-
- initialise_monitor_handles();
-
- #endif
-
- /* USER CODE END 1 */
-
- /* MCU Configuration--------------------------------------------------------*/
-
- /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
- HAL_Init();
-
- /* USER CODE BEGIN Init */
-
- /* USER CODE END Init */
-
- /* Configure the system clock */
- SystemClock_Config();
-
- /* USER CODE BEGIN SysInit */
-
- /* USER CODE END SysInit */
-
- /* Initialize all configured peripherals */
- MX_GPIO_Init();
- MX_USART2_UART_Init();
- /* USER CODE BEGIN 2 */
-
- /* Application Init */
- app_init();
-
- /* USER CODE END 2 */
-
- /* Infinite loop */
- /* USER CODE BEGIN WHILE */
- while (1)
- {
- /* USER CODE END WHILE */
-
- /* USER CODE BEGIN 3 */
-
- /* Application Update */
- app_update();
- }
- /* USER CODE END 3 */
-}
-
-/**
- * @brief System Clock Configuration
- * @retval None
- */
-void SystemClock_Config(void)
-{
- RCC_OscInitTypeDef RCC_OscInitStruct = {0};
- RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
-
- /** Initializes the RCC Oscillators according to the specified parameters
- * in the RCC_OscInitTypeDef structure.
- */
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
- RCC_OscInitStruct.HSIState = RCC_HSI_ON;
- RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
- RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
- RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
- if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
- {
- Error_Handler();
- }
-
- /** Initializes the CPU, AHB and APB buses clocks
- */
- RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
- |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
- RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
- RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
- RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
- RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
-
- if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
- {
- Error_Handler();
- }
-}
-
-/**
- * @brief USART2 Initialization Function
- * @param None
- * @retval None
- */
-static void MX_USART2_UART_Init(void)
-{
-
- /* USER CODE BEGIN USART2_Init 0 */
-
- /* USER CODE END USART2_Init 0 */
-
- /* USER CODE BEGIN USART2_Init 1 */
-
- /* USER CODE END USART2_Init 1 */
- huart2.Instance = USART2;
- huart2.Init.BaudRate = 115200;
- huart2.Init.WordLength = UART_WORDLENGTH_8B;
- huart2.Init.StopBits = UART_STOPBITS_1;
- huart2.Init.Parity = UART_PARITY_NONE;
- huart2.Init.Mode = UART_MODE_TX_RX;
- huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart2.Init.OverSampling = UART_OVERSAMPLING_16;
- if (HAL_UART_Init(&huart2) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN USART2_Init 2 */
-
- /* USER CODE END USART2_Init 2 */
-
-}
-
-/**
- * @brief GPIO Initialization Function
- * @param None
- * @retval None
- */
-static void MX_GPIO_Init(void)
-{
- GPIO_InitTypeDef GPIO_InitStruct = {0};
-/* USER CODE BEGIN MX_GPIO_Init_1 */
-/* USER CODE END MX_GPIO_Init_1 */
-
- /* GPIO Ports Clock Enable */
- __HAL_RCC_GPIOC_CLK_ENABLE();
- __HAL_RCC_GPIOD_CLK_ENABLE();
- __HAL_RCC_GPIOA_CLK_ENABLE();
- __HAL_RCC_GPIOB_CLK_ENABLE();
-
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
-
- /*Configure GPIO pin : B1_Pin */
- GPIO_InitStruct.Pin = B1_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
-
- /*Configure GPIO pin : LD2_Pin */
- GPIO_InitStruct.Pin = LD2_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);
-
- /* EXTI interrupt init*/
- HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
- HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
-
-/* USER CODE BEGIN MX_GPIO_Init_2 */
-/* USER CODE END MX_GPIO_Init_2 */
-}
-
-/* USER CODE BEGIN 4 */
-
-/* USER CODE END 4 */
-
-/**
- * @brief This function is executed in case of error occurrence.
- * @retval None
- */
-void Error_Handler(void)
-{
- /* USER CODE BEGIN Error_Handler_Debug */
- /* User can add his own implementation to report the HAL error return state */
- __disable_irq();
- while (1)
- {
- }
- /* USER CODE END Error_Handler_Debug */
-}
-
-#ifdef USE_FULL_ASSERT
-/**
- * @brief Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * @param file: pointer to the source file name
- * @param line: assert_param error line source number
- * @retval None
- */
-void assert_failed(uint8_t *file, uint32_t line)
-{
- /* USER CODE BEGIN 6 */
- /* User can add his own implementation to report the file name and line number,
- ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
- /* USER CODE END 6 */
-}
-#endif /* USE_FULL_ASSERT */
+/* USER CODE BEGIN Header */
+/**
+ ******************************************************************************
+ * @file : main.c
+ * @brief : Main program body
+ ******************************************************************************
+ * @attention
+ *
+ * Copyright (c) 2025 STMicroelectronics.
+ * All rights reserved.
+ *
+ * This software is licensed under terms that can be found in the LICENSE file
+ * in the root directory of this software component.
+ * If no LICENSE file comes with this software, it is provided AS-IS.
+ *
+ ******************************************************************************
+ */
+/* USER CODE END Header */
+/* Includes ------------------------------------------------------------------*/
+#include "main.h"
+
+/* Private includes ----------------------------------------------------------*/
+/* USER CODE BEGIN Includes */
+
+/* Application includes. */
+#include "logger.h"
+#include "app.h"
+
+/* USER CODE END Includes */
+
+/* Private typedef -----------------------------------------------------------*/
+/* USER CODE BEGIN PTD */
+
+/* USER CODE END PTD */
+
+/* Private define ------------------------------------------------------------*/
+/* USER CODE BEGIN PD */
+
+/* USER CODE END PD */
+
+/* Private macro -------------------------------------------------------------*/
+/* USER CODE BEGIN PM */
+
+/* USER CODE END PM */
+
+/* Private variables ---------------------------------------------------------*/
+UART_HandleTypeDef huart2;
+
+/* USER CODE BEGIN PV */
+
+/* USER CODE END PV */
+
+/* Private function prototypes -----------------------------------------------*/
+void SystemClock_Config(void);
+static void MX_GPIO_Init(void);
+static void MX_USART2_UART_Init(void);
+/* USER CODE BEGIN PFP */
+
+/* USER CODE END PFP */
+
+/* Private user code ---------------------------------------------------------*/
+/* USER CODE BEGIN 0 */
+#if (1 == LOGGER_CONFIG_USE_SEMIHOSTING)
+extern void initialise_monitor_handles(void);
+#endif
+
+/* USER CODE END 0 */
+
+/**
+ * @brief The application entry point.
+ * @retval int
+ */
+int main(void)
+{
+ /* USER CODE BEGIN 1 */
+#if (1 == LOGGER_CONFIG_USE_SEMIHOSTING)
+ initialise_monitor_handles();
+#endif
+ /* USER CODE END 1 */
+
+ /* MCU Configuration------------------------------------------------------*/
+
+ /* Reset of all peripherals, Initializes Flash interface and Systick. */
+ HAL_Init();
+
+ /* USER CODE BEGIN Init */
+
+ /* USER CODE END Init */
+
+ /* Configure the system clock */
+ SystemClock_Config();
+
+ /* USER CODE BEGIN SysInit */
+
+ /* USER CODE END SysInit */
+
+ /* Initialize all configured peripherals */
+ MX_GPIO_Init();
+ MX_USART2_UART_Init();
+ /* USER CODE BEGIN 2 */
+
+ /* Application Init */
+ app_init();
+
+ /* USER CODE END 2 */
+
+ /* Infinite loop */
+ /* USER CODE BEGIN WHILE */
+ while (1)
+ {
+ /* USER CODE END WHILE */
+
+ /* USER CODE BEGIN 3 */
+
+ /* Application Update */
+ app_update();
+ }
+ /* USER CODE END 3 */
+}
+
+/**
+ * @brief System Clock Configuration
+ * @retval None
+ */
+void SystemClock_Config(void)
+{
+ RCC_OscInitTypeDef RCC_OscInitStruct = {0};
+ RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
+
+ /** Initializes the RCC Oscillators according to the specified parameters
+ * in the RCC_OscInitTypeDef structure.
+ */
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
+ RCC_OscInitStruct.HSIState = RCC_HSI_ON;
+ RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
+ RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
+ RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
+ RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
+ if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
+ {
+ Error_Handler();
+ }
+
+ /** Initializes the CPU, AHB and APB buses clocks
+ */
+ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
+ |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
+ RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
+ RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
+ RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
+ RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
+
+ if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
+ {
+ Error_Handler();
+ }
+}
+
+/**
+ * @brief USART2 Initialization Function
+ * @param None
+ * @retval None
+ */
+static void MX_USART2_UART_Init(void)
+{
+ /* USER CODE BEGIN USART2_Init 0 */
+
+ /* USER CODE END USART2_Init 0 */
+
+ /* USER CODE BEGIN USART2_Init 1 */
+
+ /* USER CODE END USART2_Init 1 */
+ huart2.Instance = USART2;
+ huart2.Init.BaudRate = 115200;
+ huart2.Init.WordLength = UART_WORDLENGTH_8B;
+ huart2.Init.StopBits = UART_STOPBITS_1;
+ huart2.Init.Parity = UART_PARITY_NONE;
+ huart2.Init.Mode = UART_MODE_TX_RX;
+ huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
+ huart2.Init.OverSampling = UART_OVERSAMPLING_16;
+ if (HAL_UART_Init(&huart2) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ /* USER CODE BEGIN USART2_Init 2 */
+
+ /* USER CODE END USART2_Init 2 */
+}
+
+/**
+ * @brief GPIO Initialization Function
+ * @param None
+ * @retval None
+ */
+static void MX_GPIO_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStruct = {0};
+ /* USER CODE BEGIN MX_GPIO_Init_1 */
+ /* USER CODE END MX_GPIO_Init_1 */
+
+ /* GPIO Ports Clock Enable */
+ __HAL_RCC_GPIOC_CLK_ENABLE();
+ __HAL_RCC_GPIOD_CLK_ENABLE();
+ __HAL_RCC_GPIOA_CLK_ENABLE();
+ __HAL_RCC_GPIOB_CLK_ENABLE();
+
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
+
+ /*Configure GPIO pin : B1_Pin */
+ GPIO_InitStruct.Pin = B1_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
+
+ /*Configure GPIO pin : LD2_Pin */
+ GPIO_InitStruct.Pin = LD2_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+ HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);
+
+ /* EXTI interrupt init*/
+ HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
+ HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
+
+ /* USER CODE BEGIN MX_GPIO_Init_2 */
+ /* USER CODE END MX_GPIO_Init_2 */
+}
+
+/* USER CODE BEGIN 4 */
+
+/* USER CODE END 4 */
+
+/**
+ * @brief This function is executed in case of error occurrence.
+ * @retval None
+ */
+void Error_Handler(void)
+{
+ /* USER CODE BEGIN Error_Handler_Debug */
+ /* User can add his own implementation to report the HAL error return state */
+ __disable_irq();
+ while (1)
+ {
+ ;
+ }
+ /* USER CODE END Error_Handler_Debug */
+}
+
+#ifdef USE_FULL_ASSERT
+/**
+ * @brief Reports the name of the source file and the source line number
+ * where the assert_param error has occurred.
+ * @param file: pointer to the source file name
+ * @param line: assert_param error line source number
+ * @retval None
+ */
+void assert_failed(uint8_t *file, uint32_t line)
+{
+ /* USER CODE BEGIN 6 */
+ /*
+ * User can add his own implementation to report the file name and line
+ * number, i.e. `printf("Error: file %s on line %d\r\n", file, line)
+ */
+ /* USER CODE END 6 */
+}
+#endif /* USE_FULL_ASSERT */
diff --git a/app/inc/dwt.h b/app/inc/dwt.h
@@ -32,7 +32,7 @@
* @file : dwt.h
* @date : Set 26, 2023
* @author : Juan Manuel Cruz <jcruz@fi.uba.ar> <jcruz@frba.utn.edu.ar>
- * @version v1.0.0
+ * @version v1.0.0
*/
#ifndef DWT_INC_DWT_H_
@@ -56,9 +56,9 @@ extern "C" {
static inline void cycle_counter_init(void) __attribute__((always_inline));
static inline void cycle_counter_init(void)
{
- CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;/* enable DWT hardware */
- DWT->CYCCNT = 0; /* reset cycle counter */
- DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; /* start counting */
+ CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; /* enable DWT hardware */
+ DWT->CYCCNT = 0; /* reset cycle counter */
+ DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; /* start counting */
}
/* reset cycle counter */
diff --git a/app/src/task_sensor.c b/app/src/task_sensor.c
@@ -1,272 +1,263 @@
-/*
- * 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_sensor.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_sensor_attribute.h"
-#include "task_system_attribute.h"
-#include "task_system_interface.h"
-
-/********************** macros and definitions *******************************/
-#define G_TASK_SEN_CNT_INIT 0ul
-#define G_TASK_SEN_TICK_CNT_INI 0ul
-
-#define DEL_BTN_XX_MIN 0ul
-#define DEL_BTN_XX_MED 25ul
-#define DEL_BTN_XX_MAX 50ul
-
-/********************** internal data declaration ****************************/
-const task_sensor_cfg_t task_sensor_cfg_list[] = {
- {ID_BTN_A, BTN_A_PORT, BTN_A_PIN, BTN_A_PRESSED, DEL_BTN_XX_MAX,
- EV_SYS_IDLE, EV_SYS_LOOP_DET}
-};
-
-#define SENSOR_CFG_QTY (sizeof(task_sensor_cfg_list)/sizeof(task_sensor_cfg_t))
-
-task_sensor_dta_t task_sensor_dta_list[] = {
- {DEL_BTN_XX_MIN, ST_BTN_XX_UP, EV_BTN_XX_UP}
-};
-
-#define SENSOR_DTA_QTY (sizeof(task_sensor_dta_list)/sizeof(task_sensor_dta_t))
-
-/********************** internal functions declaration ***********************/
-void task_sensor_statechart(void);
-
-/********************** internal data definition *****************************/
-const char *p_task_sensor = "Task Sensor (Sensor Statechart)";
-const char *p_task_sensor_ = "Non-Blocking & Update By Time Code";
-
-/********************** external data declaration ****************************/
-uint32_t g_task_sensor_cnt;
-volatile uint32_t g_task_sensor_tick_cnt;
-
-/********************** external functions definition ************************/
-void task_sensor_init(void *parameters)
-{
- uint32_t index;
- task_sensor_dta_t *p_task_sensor_dta;
- task_sensor_st_t state;
- task_sensor_ev_t event;
-
- /* Print out: Task Initialized */
- LOGGER_INFO(" ");
- LOGGER_INFO(" %s is running - %s", GET_NAME(task_sensor_init), p_task_sensor);
- LOGGER_INFO(" %s is a %s", GET_NAME(task_sensor), p_task_sensor_);
-
- /* Init & Print out: Task execution counter */
- g_task_sensor_cnt = G_TASK_SEN_CNT_INIT;
- LOGGER_INFO(" %s = %lu", GET_NAME(g_task_sensor_cnt), g_task_sensor_cnt);
-
- for (index = 0; SENSOR_DTA_QTY > index; index++)
- {
- /* Update Task Sensor Data Pointer */
- p_task_sensor_dta = &task_sensor_dta_list[index];
-
- /* Init & Print out: Index & Task execution FSM */
- state = ST_BTN_XX_UP;
- p_task_sensor_dta->state = state;
-
- event = EV_BTN_XX_UP;
- p_task_sensor_dta->event = event;
-
- LOGGER_INFO(" ");
- LOGGER_INFO(" %s = %lu %s = %lu %s = %lu",
- GET_NAME(index), index,
- GET_NAME(state), (uint32_t)state,
- GET_NAME(event), (uint32_t)event);
- }
-}
-
-void task_sensor_update(void *parameters)
-{
- bool b_time_update_required = false;
-
- /* Protect shared resource */
- __asm("CPSID i"); /* disable interrupts */
- if (G_TASK_SEN_TICK_CNT_INI < g_task_sensor_tick_cnt)
- {
- /* Update Tick Counter */
- g_task_sensor_tick_cnt--;
- b_time_update_required = true;
- }
- __asm("CPSIE i"); /* enable interrupts */
-
- while (b_time_update_required)
- {
- /* Update Task Counter */
- g_task_sensor_cnt++;
-
- /* Run Task Statechart */
- task_sensor_statechart();
-
- /* Protect shared resource */
- __asm("CPSID i"); /* disable interrupts */
- if (G_TASK_SEN_TICK_CNT_INI < g_task_sensor_tick_cnt)
- {
- /* Update Tick Counter */
- g_task_sensor_tick_cnt--;
- b_time_update_required = true;
- }
- else
- {
- b_time_update_required = false;
- }
- __asm("CPSIE i"); /* enable interrupts */
- }
-}
-
-void task_sensor_statechart(void)
-{
- uint32_t index;
- const task_sensor_cfg_t *p_task_sensor_cfg;
- task_sensor_dta_t *p_task_sensor_dta;
-
- for (index = 0; SENSOR_DTA_QTY > index; index++)
- {
- /* Update Task Sensor Configuration & Data Pointer */
- p_task_sensor_cfg = &task_sensor_cfg_list[index];
- p_task_sensor_dta = &task_sensor_dta_list[index];
-
- if (p_task_sensor_cfg->pressed
- == HAL_GPIO_ReadPin(p_task_sensor_cfg->gpio_port, p_task_sensor_cfg->pin))
- {
- p_task_sensor_dta->event = EV_BTN_XX_DOWN;
- }
- else
- {
- p_task_sensor_dta->event = EV_BTN_XX_UP;
- }
-
- switch (p_task_sensor_dta->state)
- {
- case ST_BTN_XX_UP:
-
- if (EV_BTN_XX_DOWN == p_task_sensor_dta->event)
- {
- // put_event_task_system(p_task_sensor_cfg->signal_down);
- p_task_sensor_dta->state = ST_BTN_XX_FALLING;
- p_task_sensor_dta->tick = DEL_BTN_XX_MAX;
- }
-
- break;
-
- case ST_BTN_XX_FALLING:
-
- if (EV_BTN_XX_UP == p_task_sensor_dta->event)
- {
- if (0 == p_task_sensor_dta->tick) {
- p_task_sensor_dta->state = ST_BTN_XX_UP;
- }
-
- if (p_task_sensor_dta->tick > 0) {
- p_task_sensor_dta->state = ST_BTN_XX_FALLING;
- p_task_sensor_dta->tick--;
- }
- }
-
- if (EV_BTN_XX_DOWN == p_task_sensor_dta->event)
- {
- if (0 == p_task_sensor_dta->tick) {
- p_task_sensor_dta->state = ST_BTN_XX_DOWN;
- put_event_task_system(p_task_sensor_cfg->signal_down);
- }
-
- if (p_task_sensor_dta->tick > 0) {
- p_task_sensor_dta->tick--;
- }
- }
-
- break;
-
- case ST_BTN_XX_DOWN:
-
- if (EV_BTN_XX_UP == p_task_sensor_dta->event)
- {
- p_task_sensor_dta->state = ST_BTN_XX_RISING;
- p_task_sensor_dta->tick = DEL_BTN_XX_MAX;
- }
-
- break;
-
- case ST_BTN_XX_RISING:
-
- if (EV_BTN_XX_UP == p_task_sensor_dta->event)
- {
- if (0 == p_task_sensor_dta->tick) {
- put_event_task_system(p_task_sensor_cfg->signal_up);
- p_task_sensor_dta->state = ST_BTN_XX_UP;
- }
-
- if (p_task_sensor_dta->tick > 0) {
- p_task_sensor_dta->tick--;
- }
- }
-
- if (EV_BTN_XX_DOWN == p_task_sensor_dta->event)
- {
- if (0 == p_task_sensor_dta->tick) {
- p_task_sensor_dta->state = ST_BTN_XX_DOWN;
- }
-
- if (p_task_sensor_dta->tick > 0) {
- p_task_sensor_dta->tick--;
- }
- }
-
- break;
-
- default:
-
- p_task_sensor_dta->tick = DEL_BTN_XX_MIN;
- p_task_sensor_dta->state = ST_BTN_XX_UP;
- p_task_sensor_dta->event = EV_BTN_XX_UP;
-
- 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_sensor.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_sensor_attribute.h"
+#include "task_system_attribute.h"
+#include "task_system_interface.h"
+
+/********************** macros and definitions *******************************/
+#define G_TASK_SEN_CNT_INIT 0ul
+#define G_TASK_SEN_TICK_CNT_INI 0ul
+
+#define DEL_BTN_XX_MIN 0ul
+#define DEL_BTN_XX_MED 25ul
+#define DEL_BTN_XX_MAX 50ul
+
+/********************** internal data declaration ****************************/
+const task_sensor_cfg_t task_sensor_cfg_list[] = {
+ {ID_BTN_A, BTN_A_PORT, BTN_A_PIN, BTN_A_PRESSED, DEL_BTN_XX_MAX,
+ EV_SYS_IDLE, EV_SYS_LOOP_DET}
+};
+
+#define SENSOR_CFG_QTY (sizeof(task_sensor_cfg_list)/sizeof(task_sensor_cfg_t))
+
+task_sensor_dta_t task_sensor_dta_list[] = {
+ {DEL_BTN_XX_MIN, ST_BTN_XX_UP, EV_BTN_XX_UP}
+};
+
+#define SENSOR_DTA_QTY (sizeof(task_sensor_dta_list)/sizeof(task_sensor_dta_t))
+
+/********************** internal functions declaration ***********************/
+void task_sensor_statechart(void);
+
+/********************** internal data definition *****************************/
+const char *p_task_sensor = "Task Sensor (Sensor Statechart)";
+const char *p_task_sensor_ = "Non-Blocking & Update By Time Code";
+
+/********************** external data declaration ****************************/
+uint32_t g_task_sensor_cnt;
+volatile uint32_t g_task_sensor_tick_cnt;
+
+/********************** external functions definition ************************/
+void task_sensor_init(void *parameters)
+{
+ uint32_t index;
+ task_sensor_dta_t *p_task_sensor_dta;
+ task_sensor_st_t state;
+ task_sensor_ev_t event;
+
+ /* Print out: Task Initialized */
+ LOGGER_INFO(" ");
+ LOGGER_INFO(" %s is running - %s", GET_NAME(task_sensor_init), p_task_sensor);
+ LOGGER_INFO(" %s is a %s", GET_NAME(task_sensor), p_task_sensor_);
+
+ /* Init & Print out: Task execution counter */
+ g_task_sensor_cnt = G_TASK_SEN_CNT_INIT;
+ LOGGER_INFO(" %s = %lu", GET_NAME(g_task_sensor_cnt), g_task_sensor_cnt);
+
+ for (index = 0; SENSOR_DTA_QTY > index; index++)
+ {
+ /* Update Task Sensor Data Pointer */
+ p_task_sensor_dta = &task_sensor_dta_list[index];
+
+ /* Init & Print out: Index & Task execution FSM */
+ state = ST_BTN_XX_UP;
+ p_task_sensor_dta->state = state;
+
+ event = EV_BTN_XX_UP;
+ p_task_sensor_dta->event = event;
+
+ LOGGER_INFO(" ");
+ LOGGER_INFO(" %s = %lu %s = %lu %s = %lu",
+ GET_NAME(index), index,
+ GET_NAME(state), (uint32_t)state,
+ GET_NAME(event), (uint32_t)event);
+ }
+}
+
+void task_sensor_update(void *parameters)
+{
+ bool b_time_update_required = false;
+
+ /* Protect shared resource */
+ __asm("CPSID i"); /* disable interrupts */
+ if (G_TASK_SEN_TICK_CNT_INI < g_task_sensor_tick_cnt)
+ {
+ /* Update Tick Counter */
+ g_task_sensor_tick_cnt--;
+ b_time_update_required = true;
+ }
+ __asm("CPSIE i"); /* enable interrupts */
+
+ while (b_time_update_required)
+ {
+ /* Update Task Counter */
+ g_task_sensor_cnt++;
+
+ /* Run Task Statechart */
+ task_sensor_statechart();
+
+ /* Protect shared resource */
+ __asm("CPSID i"); /* disable interrupts */
+ if (G_TASK_SEN_TICK_CNT_INI < g_task_sensor_tick_cnt)
+ {
+ /* Update Tick Counter */
+ g_task_sensor_tick_cnt--;
+ b_time_update_required = true;
+ }
+ else
+ {
+ b_time_update_required = false;
+ }
+ __asm("CPSIE i"); /* enable interrupts */
+ }
+}
+
+void task_sensor_statechart(void)
+{
+ uint32_t index;
+ uint8_t sensor_pin_status;
+ const task_sensor_cfg_t *p_task_sensor_cfg;
+ task_sensor_dta_t *p_task_sensor_dta;
+
+ for (index = 0; SENSOR_DTA_QTY > index; index++)
+ {
+ /* Update Task Sensor Configuration & Data Pointer */
+ p_task_sensor_cfg = &task_sensor_cfg_list[index];
+ p_task_sensor_dta = &task_sensor_dta_list[index];
+
+ sensor_pin_status = HAL_GPIO_ReadPin(p_task_sensor_cfg->gpio_port, p_task_sensor_cfg->pin);
+ if (sensor_pin_status == p_task_sensor_cfg->pressed)
+ {
+ p_task_sensor_dta->event = EV_BTN_XX_DOWN;
+ }
+ else
+ {
+ p_task_sensor_dta->event = EV_BTN_XX_UP;
+ }
+
+ switch (p_task_sensor_dta->state)
+ {
+ case ST_BTN_XX_UP:
+ if (EV_BTN_XX_DOWN == p_task_sensor_dta->event)
+ {
+ // put_event_task_system(p_task_sensor_cfg->signal_down);
+ p_task_sensor_dta->state = ST_BTN_XX_FALLING;
+ p_task_sensor_dta->tick = DEL_BTN_XX_MAX;
+ }
+ break;
+
+ case ST_BTN_XX_FALLING:
+ if (EV_BTN_XX_UP == p_task_sensor_dta->event)
+ {
+ if (0 == p_task_sensor_dta->tick) {
+ p_task_sensor_dta->state = ST_BTN_XX_UP;
+ }
+
+ if (p_task_sensor_dta->tick > 0) {
+ p_task_sensor_dta->state = ST_BTN_XX_FALLING;
+ p_task_sensor_dta->tick--;
+ }
+ }
+
+ if (EV_BTN_XX_DOWN == p_task_sensor_dta->event)
+ {
+ if (0 == p_task_sensor_dta->tick) {
+ p_task_sensor_dta->state = ST_BTN_XX_DOWN;
+ put_event_task_system(p_task_sensor_cfg->signal_down);
+ }
+
+ if (p_task_sensor_dta->tick > 0) {
+ p_task_sensor_dta->tick--;
+ }
+ }
+ break;
+
+ case ST_BTN_XX_DOWN:
+ if (EV_BTN_XX_UP == p_task_sensor_dta->event)
+ {
+ p_task_sensor_dta->state = ST_BTN_XX_RISING;
+ p_task_sensor_dta->tick = DEL_BTN_XX_MAX;
+ }
+ break;
+
+ case ST_BTN_XX_RISING:
+ if (EV_BTN_XX_UP == p_task_sensor_dta->event)
+ {
+ if (0 == p_task_sensor_dta->tick) {
+ put_event_task_system(p_task_sensor_cfg->signal_up);
+ p_task_sensor_dta->state = ST_BTN_XX_UP;
+ }
+
+ if (p_task_sensor_dta->tick > 0) {
+ p_task_sensor_dta->tick--;
+ }
+ }
+
+ if (EV_BTN_XX_DOWN == p_task_sensor_dta->event)
+ {
+ if (0 == p_task_sensor_dta->tick) {
+ p_task_sensor_dta->state = ST_BTN_XX_DOWN;
+ }
+
+ if (p_task_sensor_dta->tick > 0) {
+ p_task_sensor_dta->tick--;
+ }
+ }
+ break;
+
+ default:
+ p_task_sensor_dta->tick = DEL_BTN_XX_MIN;
+ p_task_sensor_dta->state = ST_BTN_XX_UP;
+ p_task_sensor_dta->event = EV_BTN_XX_UP;
+ break;
+ }
+ }
+}
+
+/********************** end of file ******************************************/