5 Commits

Author SHA1 Message Date
eeeck ac16f8150e Use a more sensible number of semaphores 2026-06-14 16:10:18 +02:00
eeeck f0d2990b8d Move below timer setup 2026-06-14 16:10:00 +02:00
eeeck 72ffb2644e Use more clear variable names 2026-06-14 16:09:45 +02:00
eeeck 2a3d5d17b3 Remove unnecessary declarations 2026-06-14 16:08:43 +02:00
eeeck 151bac7a13 Fix typo 2026-06-14 16:08:21 +02:00
2 changed files with 20 additions and 26 deletions
+3 -13
View File
@@ -24,27 +24,17 @@
#include "main.h" #include "main.h"
/* Decladerations for queues */
extern osMessageQueueId_t xCAN1RxQueue; extern osMessageQueueId_t xCAN1RxQueue;
extern osMessageQueueId_t xCAN2RxQueue; extern osMessageQueueId_t xCAN2RxQueue;
extern osSemaphoreId_t xLEDSemaphoreCAN1;
/* Decladerations for thread handles and attributes */ extern osSemaphoreId_t xLEDSemaphoreCAN2;
extern osThreadId_t vCAN1_rx;
extern osThreadId_t vCAN2_rx;
extern osThreadId_t vLED_CAN1_Heartbeat;
extern osThreadId_t vLED_CAN2_Heartbeat;
extern const osThreadAttr_t vCAN1_rx_attributes;
extern const osThreadAttr_t vCAN2_rx_attributes;
extern const osThreadAttr_t vLED_CAN1_Heartbeat_attributes;
extern const osThreadAttr_t vLED_CAN2_Heartbeat_attributes;
/** /**
* @brief Initializes the CAN logger modules, OS threads, queues, and hardware. * @brief Initializes the CAN logger modules, OS threads, queues, and hardware.
* @param hcan1 Pointer to the CAN1 handle * @param hcan1 Pointer to the CAN1 handle
* @param hcan2 Pointer to the CAN2 handle * @param hcan2 Pointer to the CAN2 handle
*/ */
void vCANLoggerInit(CAN_HandleTypeDef *hcan1, CAN_HandleTypeDef *hcan2); void CAN_Logger_Init(CAN_HandleTypeDef *hcan1, CAN_HandleTypeDef *hcan2);
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan);
void vCANLoggerListen(void *argument); void vCANLoggerListen(void *argument);
void vLEDHeartbeat(void *argument); void vLEDHeartbeat(void *argument);
+17 -13
View File
@@ -44,7 +44,7 @@ typedef struct {
typedef struct { typedef struct {
LED_Config *led; LED_Config *led;
osSemaphoreId_t sem; osSemaphoreId_t semaphore;
osTimerId_t timer; osTimerId_t timer;
} LEDContext; } LEDContext;
/* USER CODE END PTD */ /* USER CODE END PTD */
@@ -72,8 +72,8 @@ LED_Config led_can1 = {GPIOB, GPIO_PIN_2};
LED_Config led_can2 = {GPIOB, GPIO_PIN_5}; LED_Config led_can2 = {GPIOB, GPIO_PIN_5};
LED_Config led_error = {GPIOB, GPIO_PIN_3}; LED_Config led_error = {GPIOB, GPIO_PIN_3};
LEDContext ledCtxCAN1; LEDContext ledContextCAN1;
LEDContext ledCtxCAN2; LEDContext ledContextCAN2;
osSemaphoreId_t xLEDSemaphoreCAN1; osSemaphoreId_t xLEDSemaphoreCAN1;
osSemaphoreId_t xLEDSemaphoreCAN2; osSemaphoreId_t xLEDSemaphoreCAN2;
@@ -118,13 +118,7 @@ int main(void)
HAL_Init(); HAL_Init();
/* USER CODE BEGIN 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 */ /* USER CODE END Init */
/* Configure the system clock */ /* Configure the system clock */
@@ -168,15 +162,15 @@ int main(void)
/* USER CODE END RTOS_MUTEX */ /* USER CODE END RTOS_MUTEX */
/* USER CODE BEGIN RTOS_SEMAPHORES */ /* USER CODE BEGIN RTOS_SEMAPHORES */
xLEDSemaphoreCAN1 = osSemaphoreNew(255, 0, NULL); xLEDSemaphoreCAN1 = osSemaphoreNew(10, 0, NULL);
xLEDSemaphoreCAN2 = osSemaphoreNew(255, 0, NULL); xLEDSemaphoreCAN2 = osSemaphoreNew(10, 0, NULL);
if (xLEDSemaphoreCAN1 == NULL || xLEDSemaphoreCAN2 == NULL) Error_Handler(); if (xLEDSemaphoreCAN1 == NULL || xLEDSemaphoreCAN2 == NULL) Error_Handler();
/* USER CODE END RTOS_SEMAPHORES */ /* USER CODE END RTOS_SEMAPHORES */
/* USER CODE BEGIN RTOS_TIMERS */ /* USER CODE BEGIN RTOS_TIMERS */
xHeartbeatTimerCAN1 = osTimerNew(vLEDHeartbeat, osTimerOnce, &led_can1, NULL); xHeartbeatTimerCAN1 = osTimerNew(vLEDHeartbeat, osTimerOnce, &ledContextCAN1, NULL);
xHeartbeatTimerCAN2 = osTimerNew(vLEDHeartbeat, osTimerOnce, &led_can2, NULL); xHeartbeatTimerCAN2 = osTimerNew(vLEDHeartbeat, osTimerOnce, &ledContextCAN2, NULL);
osTimerStart(xHeartbeatTimerCAN1, 25U); osTimerStart(xHeartbeatTimerCAN1, 25U);
osTimerStart(xHeartbeatTimerCAN2, 25U); osTimerStart(xHeartbeatTimerCAN2, 25U);
@@ -200,6 +194,16 @@ int main(void)
/* add events, ... */ /* add events, ... */
/* USER CODE END RTOS_EVENTS */ /* USER CODE END RTOS_EVENTS */
/* USER CODE BEGIN 3 */
ledContextCAN1.led = &led_can1;
ledContextCAN1.semaphore = xLEDSemaphoreCAN1;
ledContextCAN1.timer = xHeartbeatTimerCAN1;
ledContextCAN2.led = &led_can2;
ledContextCAN2.semaphore = xLEDSemaphoreCAN2;
ledContextCAN2.timer = xHeartbeatTimerCAN2;
/* USER CODE END 3 */
/* Start scheduler */ /* Start scheduler */
osKernelStart(); osKernelStart();