From 5e904177debc17f71da684aee614e4db031054f2 Mon Sep 17 00:00:00 2001 From: Pierre Barbier Date: Tue, 2 Jun 2026 16:34:35 +0200 Subject: [PATCH] Basic code to handle the interupts for cam&crank using osThreads to call the respective handler TODO add the ring buffers to be able to process the timestamps --- STM32/CM7/Core/Src/main.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/STM32/CM7/Core/Src/main.c b/STM32/CM7/Core/Src/main.c index 1bbc3e6..a132e1e 100644 --- a/STM32/CM7/Core/Src/main.c +++ b/STM32/CM7/Core/Src/main.c @@ -20,6 +20,7 @@ #include "main.h" #include "FreeRTOS.h" #include "cmsis_os2.h" +#include "stm32h7xx_hal_tim.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -108,6 +109,24 @@ void camHandler(void *argument); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ +void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) { + if (htim->Instance == TIM2) { + switch (htim->Channel) { + //HAL_TIM_ACTIVE_CHANNEL_2 is the channel used for cam interupts + case HAL_TIM_ACTIVE_CHANNEL_2: + // TODO push timestamp to the cam ring buffer + osThreadFlagsSet(camTaskHandle,0x01); + break; + //HAL_TIM_ACTIVE_CHANNEL_1 is the channel used for crank interupts + case HAL_TIM_ACTIVE_CHANNEL_1: + // TODO push timestamp to the crank ring buffer + osThreadFlagsSet(crankTaskHandle,0x01); + break; + default: + break; + } + } +} /* USER CODE END 0 */ @@ -420,7 +439,8 @@ void crankHandler(void *argument) /* Infinite loop */ for(;;) { - osDelay(1); + osThreadFlagsWait(0x01,osFlagsWaitAny,osWaitForever); + //TODO Handle the call } /* USER CODE END crankHandler */ } @@ -438,7 +458,8 @@ void camHandler(void *argument) /* Infinite loop */ for(;;) { - osDelay(1); + osThreadFlagsWait(0x01,osFlagsWaitAny,osWaitForever); + //TODO Handle the call } /* USER CODE END camHandler */ }