Can mailboxes & timeout (#110)

* CAN: rotate mailboxes used for TX (workaround for GD32)

To avoid overwrite of not-yet-transmitted message by next one.

* CAN: 100mS timeout
This commit is contained in:
Andrey G 2022-07-14 09:10:58 +03:00 committed by GitHub
parent fa6df58caf
commit 50b1483c1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

@ -2,6 +2,9 @@
#include <cstring>
// manualy rotate mailboxes on GD32
static int can1_mailbox = 1;
CanTxMessage::CanTxMessage(uint32_t eid, uint8_t dlc, bool isExtended) {
m_frame.IDE = isExtended ? CAN_IDE_EXT : CAN_IDE_STD;
m_frame.EID = eid;
@ -12,7 +15,14 @@ CanTxMessage::CanTxMessage(uint32_t eid, uint8_t dlc, bool isExtended) {
CanTxMessage::~CanTxMessage() {
// 100 ms timeout
canTransmitTimeout(&CAND1, CAN_ANY_MAILBOX, &m_frame, TIME_IMMEDIATE);
canTransmitTimeout(&CAND1, can1_mailbox, &m_frame, TIME_MS2I(100));
// GD32 workaround: rotate mailboxes
// Does not affect STM32 devices
can1_mailbox++;
if (can1_mailbox == CAN_TX_MAILBOXES) {
can1_mailbox = 1;
}
}
uint8_t& CanTxMessage::operator[](size_t index) {