Skip to content

Commit

Permalink
STM32 FDCAN: Get all messages from FIFO in RX ISR
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Pluzhnikov committed May 9, 2023
1 parent bfafcd3 commit e7021c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/modm/platform/can/stm32-fdcan/can.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -237,25 +237,31 @@ MODM_ISR({{ reg }}_IT0)
MODM_ISR({{ reg }}_IT1)
{
%% if options["buffer.rx"] > 0
int_fast16_t msgRetrieveLimit = rxQueue.getMaxSize() - rxQueue.getSize();

if (msgRetrieveLimit == 0) {
modm_assert_continue_ignore(false, "fdcan.rx.buffer",
"CAN receive software buffer full, not reading new message(s)!");
// acknowledge interrupt flags
{{ reg }}->IR = FDCAN_IR_RF0N | FDCAN_IR_RF1N;
return;
}

RxMessage rxMessage;

if (rxFifo0HasMessage()) {
while (rxFifo0HasMessage() && (msgRetrieveLimit > 0)) {
readMsg(rxMessage.message, 0, &rxMessage.filter_id, &rxMessage.timestamp);
// acknowledge interrupt flag
{{ reg }}->IR = FDCAN_IR_RF0N;

modm_assert_continue_ignore(rxQueue.push(rxMessage), "fdcan.rx.buffer",
"CAN receive software buffer overflowed!", {{ id }});
rxQueue.push(rxMessage);
msgRetrieveLimit--;
}
{{ reg }}->IR = FDCAN_IR_RF0N; // acknowledge interrupt flag

if (rxFifo1HasMessage()) {
while (rxFifo1HasMessage() && (msgRetrieveLimit > 0)) {
readMsg(rxMessage.message, 1, &rxMessage.filter_id, &rxMessage.timestamp);
// acknowledge interrupt flag
{{ reg }}->IR = FDCAN_IR_RF1N;

modm_assert_continue_ignore(rxQueue.push(rxMessage), "fdcan.rx.buffer",
"CAN receive software buffer overflowed!", {{ id }});
rxQueue.push(rxMessage);
msgRetrieveLimit--;
}
{{ reg }}->IR = FDCAN_IR_RF1N; // acknowledge interrupt flag
%% endif
}

Expand Down
2 changes: 2 additions & 0 deletions src/modm/platform/can/stm32-fdcan/can.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#ifndef MODM_STM32_FDCAN{{ id }}_HPP
#define MODM_STM32_FDCAN{{ id }}_HPP

#include <optional>

#include <modm/architecture/interface/can.hpp>
#include <modm/architecture/interface/can_filter.hpp>
#include <modm/platform/gpio/connector.hpp>
Expand Down

0 comments on commit e7021c9

Please sign in to comment.