From a75d42faebbfc8d44ee0c0bb5ce944058c1eee4d Mon Sep 17 00:00:00 2001 From: Erick Ahmed Date: Sun, 14 Jun 2026 15:16:23 +0200 Subject: [PATCH] Create context structure for timer callback Strucure is made of - LED (port, pin) - Semaphore - Timer handle --- Core/Src/canlog.c | 1 - Core/Src/main.c | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Core/Src/canlog.c b/Core/Src/canlog.c index 784e805..5164a5a 100644 --- a/Core/Src/canlog.c +++ b/Core/Src/canlog.c @@ -141,7 +141,6 @@ void vLEDHeartbeat(void *argument) { HAL_GPIO_WritePin(led->port, led->pin, GPIO_PIN_RESET); } - /* CODE END */ } /* END vLEDHeartbeat */ diff --git a/Core/Src/main.c b/Core/Src/main.c index e67881e..13e4cae 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -41,6 +41,12 @@ typedef struct { //uint32_t timestamp; //Enable TIM2: 42 MHz / (41+1) = 1 MHz → 1 µs tick; 32bit autoreload freerunning // this is for getting timestamps on can messages } CanMessage_t; + +typedef struct { + LED_Config *led; + osSemaphoreId_t sem; + osTimerId_t timer; +} LEDContext; /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ @@ -66,6 +72,9 @@ LED_Config led_can1 = {GPIOB, GPIO_PIN_2}; LED_Config led_can2 = {GPIOB, GPIO_PIN_5}; LED_Config led_error = {GPIOB, GPIO_PIN_3}; +LEDContext ledCtxCAN1; +LEDContext ledCtxCAN2; + osSemaphoreId_t xLEDSemaphoreCAN1; osSemaphoreId_t xLEDSemaphoreCAN2; @@ -109,7 +118,13 @@ int main(void) HAL_Init(); /* USER CODE BEGIN Init */ + ledCtxCAN1.led = &led_can1; + ledCtxCAN1.sem = xLEDSemaphoreCAN1; + ledCtxCAN1.timer = xHeartbeatTimerCAN1; + ledCtxCAN2.led = &led_can2; + ledCtxCAN2.sem = xLEDSemaphoreCAN2; + ledCtxCAN2.timer = xHeartbeatTimerCAN2; /* USER CODE END Init */ /* Configure the system clock */