Refactor handler to external
Moved task handler functions to external functions, signatures are in tasks.h, each function has its own .c file in Src/tasks
This commit is contained in:
@@ -62,6 +62,8 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE
|
|||||||
Core/Src/ring_buffer.c
|
Core/Src/ring_buffer.c
|
||||||
Core/Src/SEGGER_RTT.c
|
Core/Src/SEGGER_RTT.c
|
||||||
Core/Src/SEGGER_RTT_printf.c
|
Core/Src/SEGGER_RTT_printf.c
|
||||||
|
Core/Src/tasks/crank.c
|
||||||
|
Core/Src/tasks/cam.c
|
||||||
)
|
)
|
||||||
|
|
||||||
# Link directories setup
|
# Link directories setup
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
/* USER CODE BEGIN Header */
|
/* USER CODE BEGIN Header */
|
||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @file : main.h
|
* @file : main.h
|
||||||
* @brief : Header for main.c file.
|
* @brief : Header for main.c file.
|
||||||
* This file contains the common defines of the application.
|
* This file contains the common defines of the application.
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @attention
|
* @attention
|
||||||
*
|
*
|
||||||
* Copyright (c) 2026 STMicroelectronics.
|
* Copyright (c) 2026 STMicroelectronics.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
* in the root directory of this software component.
|
* in the root directory of this software component.
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
/* USER CODE END Header */
|
/* USER CODE END Header */
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
@@ -31,6 +31,7 @@ extern "C" {
|
|||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "global_state.h"
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ extern "C" {
|
|||||||
|
|
||||||
/* Exported constants --------------------------------------------------------*/
|
/* Exported constants --------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN EC */
|
/* USER CODE BEGIN EC */
|
||||||
|
extern volatile global_state_t state_g;
|
||||||
|
|
||||||
/* USER CODE END EC */
|
/* USER CODE END EC */
|
||||||
|
|
||||||
|
|||||||
7
STM32/CM7/Core/Inc/tasks.h
Normal file
7
STM32/CM7/Core/Inc/tasks.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
// Copyright (C) 2026 Hector van der Aa <hector@h3cx.dev>
|
||||||
|
// Copyright (C) 2026 Pierre Barbier <pierrebarbier741@gmail.com>
|
||||||
|
// Copyright (C) 2026 Association Exergie <association.exergie@gmail.com>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
void crankHandler(void *argument);
|
||||||
|
void camHandler(void *argument);
|
||||||
@@ -11,8 +11,9 @@
|
|||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
#include "global_state.h"
|
|
||||||
#include "ring_buffer.h"
|
#include "ring_buffer.h"
|
||||||
|
#include "tasks.h"
|
||||||
|
#include <assert.h>
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#include "SEGGER_RTT.h"
|
#include "SEGGER_RTT.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -53,36 +54,36 @@ TIM_HandleTypeDef htim2;
|
|||||||
/* Definitions for defaultTask */
|
/* Definitions for defaultTask */
|
||||||
osThreadId_t defaultTaskHandle;
|
osThreadId_t defaultTaskHandle;
|
||||||
const osThreadAttr_t defaultTask_attributes = {
|
const osThreadAttr_t defaultTask_attributes = {
|
||||||
.name = "defaultTask",
|
.name = "defaultTask",
|
||||||
.stack_size = 128 * 4,
|
.stack_size = 128 * 4,
|
||||||
.priority = (osPriority_t)osPriorityNormal,
|
.priority = (osPriority_t) osPriorityNormal,
|
||||||
};
|
};
|
||||||
/* Definitions for crankTask */
|
/* Definitions for crankTask */
|
||||||
osThreadId_t crankTaskHandle;
|
osThreadId_t crankTaskHandle;
|
||||||
uint32_t crankTaskBuffer[128];
|
uint32_t crankTaskBuffer[ 128 ];
|
||||||
osStaticThreadDef_t crankTaskControlBlock;
|
osStaticThreadDef_t crankTaskControlBlock;
|
||||||
const osThreadAttr_t crankTask_attributes = {
|
const osThreadAttr_t crankTask_attributes = {
|
||||||
.name = "crankTask",
|
.name = "crankTask",
|
||||||
.cb_mem = &crankTaskControlBlock,
|
.cb_mem = &crankTaskControlBlock,
|
||||||
.cb_size = sizeof(crankTaskControlBlock),
|
.cb_size = sizeof(crankTaskControlBlock),
|
||||||
.stack_mem = &crankTaskBuffer[0],
|
.stack_mem = &crankTaskBuffer[0],
|
||||||
.stack_size = sizeof(crankTaskBuffer),
|
.stack_size = sizeof(crankTaskBuffer),
|
||||||
.priority = (osPriority_t)osPriorityRealtime7,
|
.priority = (osPriority_t) osPriorityRealtime7,
|
||||||
};
|
};
|
||||||
/* Definitions for camTask */
|
/* Definitions for camTask */
|
||||||
osThreadId_t camTaskHandle;
|
osThreadId_t camTaskHandle;
|
||||||
uint32_t camTaskBuffer[128];
|
uint32_t camTaskBuffer[ 128 ];
|
||||||
osStaticThreadDef_t camTaskControlBlock;
|
osStaticThreadDef_t camTaskControlBlock;
|
||||||
const osThreadAttr_t camTask_attributes = {
|
const osThreadAttr_t camTask_attributes = {
|
||||||
.name = "camTask",
|
.name = "camTask",
|
||||||
.cb_mem = &camTaskControlBlock,
|
.cb_mem = &camTaskControlBlock,
|
||||||
.cb_size = sizeof(camTaskControlBlock),
|
.cb_size = sizeof(camTaskControlBlock),
|
||||||
.stack_mem = &camTaskBuffer[0],
|
.stack_mem = &camTaskBuffer[0],
|
||||||
.stack_size = sizeof(camTaskBuffer),
|
.stack_size = sizeof(camTaskBuffer),
|
||||||
.priority = (osPriority_t)osPriorityRealtime7,
|
.priority = (osPriority_t) osPriorityRealtime7,
|
||||||
};
|
};
|
||||||
/* USER CODE BEGIN PV */
|
/* USER CODE BEGIN PV */
|
||||||
static volatile global_state_t state_g = {0};
|
volatile global_state_t state_g = {0};
|
||||||
/* USER CODE END PV */
|
/* USER CODE END PV */
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
@@ -91,8 +92,8 @@ static void MPU_Config(void);
|
|||||||
static void MX_GPIO_Init(void);
|
static void MX_GPIO_Init(void);
|
||||||
static void MX_TIM2_Init(void);
|
static void MX_TIM2_Init(void);
|
||||||
void StartDefaultTask(void *argument);
|
void StartDefaultTask(void *argument);
|
||||||
void crankHandler(void *argument);
|
extern void crankHandler(void *argument);
|
||||||
void camHandler(void *argument);
|
extern void camHandler(void *argument);
|
||||||
|
|
||||||
/* USER CODE BEGIN PFP */
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
@@ -124,10 +125,11 @@ void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) {
|
|||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The application entry point.
|
* @brief The application entry point.
|
||||||
* @retval int
|
* @retval int
|
||||||
*/
|
*/
|
||||||
int main(void) {
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
@@ -136,7 +138,7 @@ int main(void) {
|
|||||||
#if defined(DUAL_CORE_BOOT_SYNC_SEQUENCE)
|
#if defined(DUAL_CORE_BOOT_SYNC_SEQUENCE)
|
||||||
int32_t timeout;
|
int32_t timeout;
|
||||||
#endif /* DUAL_CORE_BOOT_SYNC_SEQUENCE */
|
#endif /* DUAL_CORE_BOOT_SYNC_SEQUENCE */
|
||||||
/* USER CODE END Boot_Mode_Sequence_0 */
|
/* USER CODE END Boot_Mode_Sequence_0 */
|
||||||
|
|
||||||
/* MPU Configuration--------------------------------------------------------*/
|
/* MPU Configuration--------------------------------------------------------*/
|
||||||
MPU_Config();
|
MPU_Config();
|
||||||
@@ -151,11 +153,10 @@ int main(void) {
|
|||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
#endif /* DUAL_CORE_BOOT_SYNC_SEQUENCE */
|
#endif /* DUAL_CORE_BOOT_SYNC_SEQUENCE */
|
||||||
/* USER CODE END Boot_Mode_Sequence_1 */
|
/* USER CODE END Boot_Mode_Sequence_1 */
|
||||||
/* MCU Configuration--------------------------------------------------------*/
|
/* MCU Configuration--------------------------------------------------------*/
|
||||||
|
|
||||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick.
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||||
*/
|
|
||||||
HAL_Init();
|
HAL_Init();
|
||||||
|
|
||||||
/* USER CODE BEGIN Init */
|
/* USER CODE BEGIN Init */
|
||||||
@@ -182,7 +183,7 @@ int main(void) {
|
|||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
#endif /* DUAL_CORE_BOOT_SYNC_SEQUENCE */
|
#endif /* DUAL_CORE_BOOT_SYNC_SEQUENCE */
|
||||||
/* USER CODE END Boot_Mode_Sequence_2 */
|
/* USER CODE END Boot_Mode_Sequence_2 */
|
||||||
|
|
||||||
/* USER CODE BEGIN SysInit */
|
/* USER CODE BEGIN SysInit */
|
||||||
|
|
||||||
@@ -222,8 +223,7 @@ int main(void) {
|
|||||||
|
|
||||||
/* Create the thread(s) */
|
/* Create the thread(s) */
|
||||||
/* creation of defaultTask */
|
/* creation of defaultTask */
|
||||||
defaultTaskHandle =
|
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
|
||||||
osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
|
|
||||||
|
|
||||||
/* creation of crankTask */
|
/* creation of crankTask */
|
||||||
crankTaskHandle = osThreadNew(crankHandler, NULL, &crankTask_attributes);
|
crankTaskHandle = osThreadNew(crankHandler, NULL, &crankTask_attributes);
|
||||||
@@ -255,27 +255,27 @@ int main(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief System Clock Configuration
|
* @brief System Clock Configuration
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void SystemClock_Config(void) {
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
/** Supply configuration update enable
|
/** Supply configuration update enable
|
||||||
*/
|
*/
|
||||||
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
|
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
|
||||||
|
|
||||||
/** Configure the main internal regulator output voltage
|
/** Configure the main internal regulator output voltage
|
||||||
*/
|
*/
|
||||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
|
||||||
|
|
||||||
while (!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {
|
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
|
||||||
}
|
|
||||||
|
|
||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
* in the RCC_OscInitTypeDef structure.
|
* in the RCC_OscInitTypeDef structure.
|
||||||
*/
|
*/
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
@@ -288,15 +288,16 @@ void SystemClock_Config(void) {
|
|||||||
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
|
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
|
||||||
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
|
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
|
||||||
RCC_OscInitStruct.PLL.PLLFRACN = 0;
|
RCC_OscInitStruct.PLL.PLLFRACN = 0;
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Initializes the CPU, AHB and APB buses clocks
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
*/
|
*/
|
||||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 |
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|
||||||
RCC_CLOCKTYPE_D3PCLK1 | RCC_CLOCKTYPE_D1PCLK1;
|
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
|
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
|
||||||
@@ -305,17 +306,19 @@ void SystemClock_Config(void) {
|
|||||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
|
||||||
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
|
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
|
||||||
|
|
||||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TIM2 Initialization Function
|
* @brief TIM2 Initialization Function
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void MX_TIM2_Init(void) {
|
static void MX_TIM2_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM2_Init 0 */
|
/* USER CODE BEGIN TIM2_Init 0 */
|
||||||
|
|
||||||
@@ -334,44 +337,52 @@ static void MX_TIM2_Init(void) {
|
|||||||
htim2.Init.Period = 4294967295;
|
htim2.Init.Period = 4294967295;
|
||||||
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4;
|
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4;
|
||||||
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
if (HAL_TIM_Base_Init(&htim2) != HAL_OK) {
|
if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||||
if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) {
|
if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
if (HAL_TIM_IC_Init(&htim2) != HAL_OK) {
|
if (HAL_TIM_IC_Init(&htim2) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) {
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;
|
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;
|
||||||
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
|
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
|
||||||
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
|
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
|
||||||
sConfigIC.ICFilter = 0;
|
sConfigIC.ICFilter = 0;
|
||||||
if (HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_1) != HAL_OK) {
|
if (HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
|
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
|
||||||
if (HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_2) != HAL_OK) {
|
if (HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_2) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
/* USER CODE BEGIN TIM2_Init 2 */
|
/* USER CODE BEGIN TIM2_Init 2 */
|
||||||
HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_1);
|
HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_1);
|
||||||
HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_2);
|
HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_2);
|
||||||
/* USER CODE END TIM2_Init 2 */
|
/* USER CODE END TIM2_Init 2 */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief GPIO Initialization Function
|
* @brief GPIO Initialization Function
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void MX_GPIO_Init(void) {
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
@@ -407,7 +418,8 @@ static void MX_GPIO_Init(void) {
|
|||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
/* USER CODE END Header_StartDefaultTask */
|
/* USER CODE END Header_StartDefaultTask */
|
||||||
void StartDefaultTask(void *argument) {
|
void StartDefaultTask(void *argument)
|
||||||
|
{
|
||||||
/* USER CODE BEGIN 5 */
|
/* USER CODE BEGIN 5 */
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@@ -416,62 +428,17 @@ void StartDefaultTask(void *argument) {
|
|||||||
/* USER CODE END 5 */
|
/* USER CODE END 5 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN Header_crankHandler */
|
/* MPU Configuration */
|
||||||
/**
|
|
||||||
* @brief Function implementing the crankTask thread.
|
|
||||||
* @param argument: Not used
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header_crankHandler */
|
|
||||||
void crankHandler(void *argument) {
|
|
||||||
/* USER CODE BEGIN crankHandler */
|
|
||||||
/* Infinite loop */
|
|
||||||
for (;;) {
|
|
||||||
osThreadFlagsWait(0x01, osFlagsWaitAny, osWaitForever);
|
|
||||||
#ifdef DEBUG
|
|
||||||
SEGGER_RTT_printf(0, "Crank pulse detected at: %lu\n\r",
|
|
||||||
ringBufferRead(&state_g.crank_RB, 0));
|
|
||||||
#endif /* ifdef DEBUG */
|
|
||||||
if (state_g.sync == SYNC_OK) {
|
|
||||||
// TODO complete algorithm for scheduling spark
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* USER CODE END crankHandler */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Header_camHandler */
|
void MPU_Config(void)
|
||||||
/**
|
{
|
||||||
* @brief Function implementing the camTask thread.
|
|
||||||
* @param argument: Not used
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header_camHandler */
|
|
||||||
void camHandler(void *argument) {
|
|
||||||
/* USER CODE BEGIN camHandler */
|
|
||||||
/* Infinite loop */
|
|
||||||
for (;;) {
|
|
||||||
osThreadFlagsWait(0x01, osFlagsWaitAny, osWaitForever);
|
|
||||||
#ifdef DEBUG
|
|
||||||
SEGGER_RTT_printf(0, "Cam pulse detected at: %lu\n\r",
|
|
||||||
ringBufferRead(&state_g.cam_RB, 0));
|
|
||||||
#endif /* ifdef DEBUG */
|
|
||||||
if (state_g.sync == SYNC_OK) {
|
|
||||||
// TODO complete algorithm for scheduling spark
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* USER CODE END camHandler */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* MPU Configuration */
|
|
||||||
|
|
||||||
void MPU_Config(void) {
|
|
||||||
MPU_Region_InitTypeDef MPU_InitStruct = {0};
|
MPU_Region_InitTypeDef MPU_InitStruct = {0};
|
||||||
|
|
||||||
/* Disables the MPU */
|
/* Disables the MPU */
|
||||||
HAL_MPU_Disable();
|
HAL_MPU_Disable();
|
||||||
|
|
||||||
/** Initializes and configures the Region and the memory to be protected
|
/** Initializes and configures the Region and the memory to be protected
|
||||||
*/
|
*/
|
||||||
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
|
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
|
||||||
MPU_InitStruct.Number = MPU_REGION_NUMBER0;
|
MPU_InitStruct.Number = MPU_REGION_NUMBER0;
|
||||||
MPU_InitStruct.BaseAddress = 0x0;
|
MPU_InitStruct.BaseAddress = 0x0;
|
||||||
@@ -487,13 +454,15 @@ void MPU_Config(void) {
|
|||||||
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
||||||
/* Enables the MPU */
|
/* Enables the MPU */
|
||||||
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
|
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function is executed in case of error occurrence.
|
* @brief This function is executed in case of error occurrence.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void Error_Handler(void) {
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
/* USER CODE BEGIN Error_Handler_Debug */
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
/* User can add his own implementation to report the HAL error return state */
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
@@ -503,13 +472,14 @@ void Error_Handler(void) {
|
|||||||
}
|
}
|
||||||
#ifdef USE_FULL_ASSERT
|
#ifdef USE_FULL_ASSERT
|
||||||
/**
|
/**
|
||||||
* @brief Reports the name of the source file and the source line number
|
* @brief Reports the name of the source file and the source line number
|
||||||
* where the assert_param error has occurred.
|
* where the assert_param error has occurred.
|
||||||
* @param file: pointer to the source file name
|
* @param file: pointer to the source file name
|
||||||
* @param line: assert_param error line source number
|
* @param line: assert_param error line source number
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void assert_failed(uint8_t *file, uint32_t line) {
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
/* USER CODE BEGIN 6 */
|
/* USER CODE BEGIN 6 */
|
||||||
/* User can add his own implementation to report the file name and line
|
/* 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,
|
number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file,
|
||||||
|
|||||||
25
STM32/CM7/Core/Src/tasks/cam.c
Normal file
25
STM32/CM7/Core/Src/tasks/cam.c
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) 2026 Hector van der Aa <hector@h3cx.dev>
|
||||||
|
// Copyright (C) 2026 Pierre Barbier <pierrebarbier741@gmail.com>
|
||||||
|
// Copyright (C) 2026 Association Exergie <association.exergie@gmail.com>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
#include "cmsis_os2.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include "ring_buffer.h"
|
||||||
|
#include "tasks.h"
|
||||||
|
#ifdef DEBUG
|
||||||
|
#include "SEGGER_RTT.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void camHandler(void *argument) {
|
||||||
|
for (;;) {
|
||||||
|
osThreadFlagsWait(0x01, osFlagsWaitAny, osWaitForever);
|
||||||
|
#ifdef DEBUG
|
||||||
|
SEGGER_RTT_printf(0, "Cam pulse detected at: %lu\n\r",
|
||||||
|
ringBufferRead(&state_g.cam_RB, 0));
|
||||||
|
#endif /* ifdef DEBUG */
|
||||||
|
if (state_g.sync == SYNC_OK) {
|
||||||
|
// TODO complete algorithm for scheduling spark
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
25
STM32/CM7/Core/Src/tasks/crank.c
Normal file
25
STM32/CM7/Core/Src/tasks/crank.c
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) 2026 Hector van der Aa <hector@h3cx.dev>
|
||||||
|
// Copyright (C) 2026 Pierre Barbier <pierrebarbier741@gmail.com>
|
||||||
|
// Copyright (C) 2026 Association Exergie <association.exergie@gmail.com>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
#include "cmsis_os2.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include "ring_buffer.h"
|
||||||
|
#include "tasks.h"
|
||||||
|
#ifdef DEBUG
|
||||||
|
#include "SEGGER_RTT.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void crankHandler(void *argument) {
|
||||||
|
for (;;) {
|
||||||
|
osThreadFlagsWait(0x01, osFlagsWaitAny, osWaitForever);
|
||||||
|
#ifdef DEBUG
|
||||||
|
SEGGER_RTT_printf(0, "Crank pulse detected at: %lu\n\r",
|
||||||
|
ringBufferRead(&state_g.crank_RB, 0));
|
||||||
|
#endif /* ifdef DEBUG */
|
||||||
|
if (state_g.sync == SYNC_OK) {
|
||||||
|
// TODO complete algorithm for scheduling spark
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ CortexM7.IPs=CORTEX_M7\:I,FATFS_M7\:I,FREERTOS_M7\:I,IWDG1\:I,OPENAMP_M7\:I,PDM2
|
|||||||
CortexM7.Pins=PI12
|
CortexM7.Pins=PI12
|
||||||
FREERTOS_M7.FootprintOK=true
|
FREERTOS_M7.FootprintOK=true
|
||||||
FREERTOS_M7.IPParameters=Tasks01,configENABLE_FPU,FootprintOK
|
FREERTOS_M7.IPParameters=Tasks01,configENABLE_FPU,FootprintOK
|
||||||
FREERTOS_M7.Tasks01=defaultTask,24,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL;crankTask,55,128,crankHandler,Default,NULL,Static,crankTaskBuffer,crankTaskControlBlock;camTask,55,128,camHandler,Default,NULL,Static,camTaskBuffer,camTaskControlBlock
|
FREERTOS_M7.Tasks01=defaultTask,24,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL;crankTask,55,128,crankHandler,As external,NULL,Static,crankTaskBuffer,crankTaskControlBlock;camTask,55,128,camHandler,As external,NULL,Static,camTaskBuffer,camTaskControlBlock
|
||||||
FREERTOS_M7.configENABLE_FPU=1
|
FREERTOS_M7.configENABLE_FPU=1
|
||||||
File.Version=6
|
File.Version=6
|
||||||
GPIO.groupedBy=Group By Peripherals
|
GPIO.groupedBy=Group By Peripherals
|
||||||
|
|||||||
Reference in New Issue
Block a user