Skip to content

Commit cc97e44

Browse files
committed
draft new G4 tx task
1 parent 2242815 commit cc97e44

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

common/can_library/can_common.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,6 @@ bool CAN_library_init() {
227227

228228
#elif defined(STM32G474xx)
229229

230-
// G4/FDCAN implementation - uses TX FIFO (no mailboxes)
231-
// FDCAN has 3 TX FIFO slots handled by hardware, so we use a single software queue per peripheral
232-
233230
#ifndef NUM_CAN_PERIPHERALS
234231
#if defined(USE_FDCAN3)
235232
#define NUM_CAN_PERIPHERALS 3
@@ -274,25 +271,36 @@ void CAN_enqueue_tx(CanMsgTypeDef_t *msg) {
274271
}
275272

276273
void CAN_tx_update() {
277-
CanMsgTypeDef_t tx_msg;
274+
// Block until a notification is received
275+
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
276+
277+
// Feed the peripheral TX FIFOs until all queues are empty or FIFOs are full
278+
bool is_message_sent;
279+
do { // Loop to handle the case where a FIFO slot opens during processing
280+
is_message_sent = false;
281+
CanMsgTypeDef_t tx_msg;
278282

279283
#ifdef USE_FDCAN1
280-
while (PHAL_FDCAN_txFifoFree(FDCAN1) && xQueueReceive(q_tx_can[CAN1_IDX], &tx_msg, 0) == pdPASS) {
281-
PHAL_FDCAN_send(&tx_msg);
282-
}
284+
while (PHAL_FDCAN_txFifoFree(FDCAN1) && xQueueReceive(q_tx_can[CAN1_IDX], &tx_msg, 0) == pdPASS) {
285+
PHAL_FDCAN_send(&tx_msg);
286+
is_message_sent = true;
287+
}
283288
#endif
284289

285290
#ifdef USE_FDCAN2
286-
while (PHAL_FDCAN_txFifoFree(FDCAN2) && xQueueReceive(q_tx_can[CAN2_IDX], &tx_msg, 0) == pdPASS) {
287-
PHAL_FDCAN_send(&tx_msg);
288-
}
291+
while (PHAL_FDCAN_txFifoFree(FDCAN2) && xQueueReceive(q_tx_can[CAN2_IDX], &tx_msg, 0) == pdPASS) {
292+
PHAL_FDCAN_send(&tx_msg);
293+
is_message_sent = true;
294+
}
289295
#endif
290296

291297
#ifdef USE_FDCAN3
292-
while (PHAL_FDCAN_txFifoFree(FDCAN3) && xQueueReceive(q_tx_can[CAN3_IDX], &tx_msg, 0) == pdPASS) {
293-
PHAL_FDCAN_send(&tx_msg);
294-
}
298+
while (PHAL_FDCAN_txFifoFree(FDCAN3) && xQueueReceive(q_tx_can[CAN3_IDX], &tx_msg, 0) == pdPASS) {
299+
PHAL_FDCAN_send(&tx_msg);
300+
is_message_sent = true;
301+
}
295302
#endif
303+
} while (is_message_sent);
296304
}
297305

298306
// FDCAN RX callback - enqueues received messages to the RX queue

common/can_library/can_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void CAN_handle_irq(CAN_TypeDef *bus, uint8_t fifo);
102102

103103
#define DEFINE_CAN_TASKS() \
104104
DEFINE_TASK(CAN_rx_update, 0, osPriorityHigh, STACK_2048); \
105-
DEFINE_TASK(CAN_tx_update, 2, osPriorityNormal, STACK_2048);
105+
DEFINE_TASK(CAN_tx_update, 0, osPriorityHigh, STACK_2048);
106106

107107
#define START_CAN_TASKS() \
108108
START_TASK(CAN_rx_update); \

0 commit comments

Comments
 (0)