Non-blocking on CAN1 queue check

- Check queue instantly
- Use DMA to move tx_buffer to UART peripheral
- Use a semaphore to DMA is being done, to avoid moving to next loop
  iteration and overwriting tx_buffer
- HAL_UART_TxCpltCallback will release semaphore when DMA done
This commit is contained in:
2026-06-16 21:24:58 +02:00
parent 79f317cec5
commit 3691918196
+16 -1
View File
@@ -94,7 +94,7 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
*/ */
void vUARTLogger(void *argument) void vUARTLogger(void *argument)
{ {
CanMessage_t msg; CanMessage_t message;
char tx_buffer[45]; // converted extended frame char tx_buffer[45]; // converted extended frame
bool queues_empty; bool queues_empty;
@@ -102,6 +102,21 @@ void vUARTLogger(void *argument)
{ {
osEventFlagsWait(xCanEventFlags, 0x03, osFlagsWaitAny, osWaitForever); osEventFlagsWait(xCanEventFlags, 0x03, osFlagsWaitAny, osWaitForever);
do
{
queues_empty = true;
if (osMessageQueueGet(xCAN1RxQueue, &message, NULL, 0U) == osOK)
{
format_can_message(tx_buffer, 1, &message);
HAL_UART_Transmit_DMA(&huart1, (uint8_t*)tx_buffer, 44);
osSemaphoreAcquire(xUartDmaSem, osWaitForever);
quesues_empty = false;
}
}
while (!queues_empty);
} }
} }
/* END vUARTLoggerListen */ /* END vUARTLoggerListen */