4 Commits

Author SHA1 Message Date
eeeck 5f1695dc0d Start timer once for automatic rearming with semaphore release 2026-06-14 14:51:46 +02:00
eeeck de6dc24dd3 Acquire semaphore and restart timer if new message incoming 2026-06-14 14:51:33 +02:00
eeeck 1b38c0f29a Release semaphore on incoming message
- Discard previous solution with timer only
2026-06-14 14:50:49 +02:00
eeeck 7ece650f72 Move declaration on top 2026-06-14 14:49:54 +02:00
2 changed files with 24 additions and 9 deletions
+15 -3
View File
@@ -113,9 +113,11 @@ void vCANLoggerListen(void *argument)
{
// TODO: parse message send message to serial/uart
HAL_GPIO_WritePin(led_can1.port, led_can1.pin, GPIO_PIN_SET);
osTimerStart(xHeartbeatTimerCAN1, 25U);
bus = (hcan->Instance == CAN1) ? xLEDSemaphoreCAN1 : xLEDSemaphoreCAN2
osSemaphoreRelease(bus);
}
}
/* CODE END */
}
@@ -131,7 +133,17 @@ void vLEDHeartbeat(void *argument)
{
/* CODE BEGIN */
LED_Config *led = (LED_Config*)argument;
HAL_GPIO_WritePin(led->port, led->pin, GPIO_PIN_RESET);
if (osSemaphoreAcquire(xCanActivitySemaphore, 0U) == osOK)
{
HAL_GPIO_WritePin(led->port, led->pin, GPIO_PIN_SET);
osTimerStart(xHeartbeatTimerCAN1, 25U);
}
else
{
HAL_GPIO_WritePin(led->port, led->pin, GPIO_PIN_RESET);
}
/* CODE END */
}
/* END vLEDHeartbeat */
+9 -6
View File
@@ -66,8 +66,14 @@ LED_Config led_can1 = {GPIOB, GPIO_PIN_2};
LED_Config led_can2 = {GPIOB, GPIO_PIN_5};
LED_Config led_error = {GPIOB, GPIO_PIN_3};
osSemaphoreId_t xLEDSemaphoreCAN1;
osSemaphoreId_t xLEDSemaphoreCAN2;
osTimerId_t xHeartbeatTimerCAN1;
osTimerId_t xHeartbeatTimerCAN2;
osMessageQueueId_t xCAN1RxQueue;
osMessageQueueId_t xCAN2RxQueue;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
@@ -147,10 +153,7 @@ int main(void)
/* USER CODE END RTOS_MUTEX */
/* USER CODE BEGIN RTOS_SEMAPHORES */
osSemaphoreId_t xLEDSemaphoreCAN1;
xLEDSemaphoreCAN1 = osSemaphoreNew(255, 0, NULL);
osSemaphoreId_t xLEDSemaphoreCAN2;
xLEDSemaphoreCAN2 = osSemaphoreNew(255, 0, NULL);
if (xLEDSemaphoreCAN1 == NULL || xLEDSemaphoreCAN2 == NULL) Error_Handler();
@@ -160,14 +163,14 @@ int main(void)
xHeartbeatTimerCAN1 = osTimerNew(vLEDHeartbeat, osTimerOnce, &led_can1, NULL);
xHeartbeatTimerCAN2 = osTimerNew(vLEDHeartbeat, osTimerOnce, &led_can2, NULL);
osTimerStart(xHeartbeatTimerCAN1, 25U);
osTimerStart(xHeartbeatTimerCAN2, 25U);
if (xHeartbeatTimerCAN1 == NULL || xHeartbeatTimerCAN2 == NULL) Error_Handler();
/* USER CODE END RTOS_TIMERS */
/* USER CODE BEGIN RTOS_QUEUES */
osMessageQueueId_t xCAN1RxQueue;
xCAN1RxQueue = osMessageQueueNew(32, sizeof(CanMessage_t), NULL);
osMessageQueueId_t xCAN2RxQueue;
xCAN2RxQueue = osMessageQueueNew(32, sizeof(CanMessage_t), NULL);
if (xCAN1RxQueue == NULL || xCAN2RxQueue == NULL) Error_Handler();