2 Commits

Author SHA1 Message Date
eeeck 75efc4840d Use new context structure instead of direct pass 2026-06-14 15:17:03 +02:00
eeeck a75d42faeb Create context structure for timer callback
Strucure is made of
-  LED (port, pin)
- Semaphore
- Timer handle
2026-06-14 15:16:23 +02:00
2 changed files with 20 additions and 6 deletions
+5 -6
View File
@@ -130,18 +130,17 @@ void vCANLoggerListen(void *argument)
void vLEDHeartbeat(void *argument)
{
/* CODE BEGIN */
LED_Config *led = (LED_Config*)argument;
LEDContext *ctx = (LEDContext*)argument;
if (osSemaphoreAcquire(xCanActivitySemaphore, 0U) == osOK)
if (osSemaphoreAcquire(ctx->sem, 0U) == osOK)
{
HAL_GPIO_WritePin(led->port, led->pin, GPIO_PIN_SET);
osTimerStart(xHeartbeatTimerCAN1, 25U);
HAL_GPIO_WritePin(ctx->led->port, ctx->led->pin, GPIO_PIN_SET);
osTimerStart(ctx->timer, 25U);
}
else
{
HAL_GPIO_WritePin(led->port, led->pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(ctx->led->port, ctx->led->pin, GPIO_PIN_RESET);
}
/* CODE END */
}
/* END vLEDHeartbeat */
+15
View File
@@ -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 */