Skip to content

Commit d71e8ec

Browse files
Fix #27 (#29)
The assertion check was placed incorrectly because tx_mailbox may be 0xFF if there are no free mailboxes available. This is not a fault condition.
1 parent 1513fe7 commit d71e8ec

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

stm32/libcanard/bxcan/src/bxcan.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ bool bxCANPush(const uint8_t iface_index, //
578578
{
579579
// All TX mailboxes are busy (this is highly unlikely); at the same time we know that there is no
580580
// higher or equal priority frame that is currently pending. Therefore, priority inversion has just
581-
// happend (sic!), because we can't enqueue the higher priority frame due to all TX mailboxes being
581+
// happened (sic!), because we can't enqueue the higher priority frame due to all TX mailboxes being
582582
// busy. This scenario is extremely unlikely, because in order for it to happen, the application would
583583
// need to transmit 4 (four) or more CAN frames with different CAN ID ordered from high ID to low ID
584584
// nearly at the same time. For example:
@@ -600,16 +600,13 @@ bool bxCANPush(const uint8_t iface_index, //
600600
{
601601
tx_mailbox = 0U;
602602
}
603-
604-
BXCAN_ASSERT(tx_mailbox < 3U); // Index check - the value must be correct here
605603
}
606604

607605
// By this time we've proven that:
608606
// - The input is valid. (input_ok == true)
609607
// - There are no mailboxes with priority >= the priority of the new frame. (prio_higher == false)
610608
// - A priority inversion would not occur. (tx_mailbox != 0xFF)
611-
// - A free TX mailbox is available. (tx_mailbox < 3U)
612-
// Therefore it is safe to enqueue the frame now.
609+
// Therefore it is safe to enqueue the frame now if a free mailbox is available.
613610
if (input_ok && !prio_higher && (tx_mailbox < 3U))
614611
{
615612
volatile BxCANTxMailboxType* const mb = &bxcan_base->TxMailbox[tx_mailbox];

0 commit comments

Comments
 (0)