GD32A50x User Manual
617
2.
Poll the the corresponding MSx bit in CAN_STAT register to be set, or by the interrupt
when MIEx bit in CAN_INTEN register is set.
3.
Read back the CODE field to make sure that the mailbox is aborted, or transmitted.
4.
Clear the corresponding flag MSx in the CAN_STAT register.
5.
Write the mailbox ID field of MDES1 word, and write IDE, RTR field of MDES0 word if
needed.
6.
Write the EMPTY (0b0100) to the CODE field of MDES0 word to activate the mailbox.
Upon a successful reception, all bits of the mailbox descriptor (DATA, ID, TIMESTAMP, SRR,
IDE, RTR, FDF, BRS, ESI, DLC, CODE) are stored with the received data field or
automatically updated, and the corresponding flag MSx in the CAN_STAT register is set, if
the interrupt enable bit MIEx in CAN_INTEN register is set, an interrupt will be generated.
The TIMESTAMP field is automatically updated with the value of the free running counter at
the time of the second bit of frame’s ID field.
To service (read) a Rx mailbox, the recommended steps are shown as below:
1.
Poll the corresponding flag MSx in the CAN_STAT register to be set, or by the interrupt
when MIEx bit in CAN_INTEN register is set.
2.
Read the mailbox MDES0 word, and poll until the BUSY bit (in CODE field) is 0. When
the BUSY bit is 0, the read operation of the mailbox will lock the mailbox, so that to
prevent the mailbox being overwritten.
3.
Read the contents of the mailbox.
4.
Clear the corresponding flag MSx in the CAN_STAT register.
5.
Read CAN_TIMER register to unlock the mailbox.
Rx mailbox locking
A locking mechanism is only applied for Rx mailbox: For CODE field with Rx FULL or Rx
OVERRUN, a CPU read to the mailbox MDES0 word will lock the mailbox, thus the locking
will prevent a new matching frame overwriting it.
The locking will be released when reading the CAN_TIMER register (global unlocking
operation), or when MDES0 word of any other mailbox is read. When unlocked, a shift-in
process will start with the pending message (the same in Inactive mode, while when LPS bit
in CAN_CTL0 register is 1, the shift-in process will be delayed until LPS bit changes to 0).
If the mailbox is not unlocked in time, while a new matching frame is coming, then the new
frame will overwrite the Rx shift buffer without a notification of a lost message, and no error
is recorded.
Note:
Mailbox inactivation (write CODE with Rx INACTIVE, or Tx ABORT) has higher priority
than locking.
Rx mailbox inactivation
The way to inactivate a Rx mailbox:
Write the CODE field of the Rx mailbox MDES0 with INACTIVE (Tx INACTIVE or Rx