50.7.3 Time Management Unit
The CAN controller integrates a free-running 16-bit internal timer. The counter is driven by the bit clock of the CAN bus line. It is enabled when the CAN controller is enabled (CANEN set in the Mode register CAN_MR). It is automatically cleared in the following cases:
- After a reset
- When the CAN controller Low-power mode is enabled (LPM bit set in CAN_MR and SLEEP bit set in Status register CAN_SR)
- After a reset of the CAN controller (CAN_MR.CANEN)
- In Time-triggered mode, when a message is accepted by the last mailbox (rising edge of the MRDY signal in the Message Status register CAN_MSRlast_mailbox_number).
The application can also reset the internal timer by setting TIMRST in the Transfer Command register (CAN_TCR). The current value of the internal timer is always accessible by reading the Timer register (CAN_TIM).
When the timer rolls over from FFFFh to 0000h, the TOVF (Timer Overflow) signal in CAN_SR is set. The CAN_SR.TOVF bit is cleared by reading CAN_SR. Depending on the corresponding interrupt mask in the Interrupt Mask register (CAN_IMR), an interrupt is generated while TOVF is set.
In a CAN network, some CAN devices may have a larger counter. In this case, the application can also decide to freeze the internal counter when the timer reaches FFFFh and to wait for a restart condition from another device. This feature is enabled by setting the CAN_MR.TIMFRZ bit. CAN_TIM is frozen to the FFFFh value. A clear condition described above restarts the timer. A timer overflow (TOVF) interrupt is triggered.
To monitor the CAN bus activity, CAN_TIM is copied to the Timestamp register (CAN _TIMESTP) after each start of frame or end of frame and a TSTP interrupt is triggered. If the CAN_MR.TEOF bit is set, the value is captured at each End Of Frame, else it is captured at each Start Of Frame. Depending on the corresponding mask in CAN_IMR, an interrupt is generated while the CAN_SR.TSTP bit is set. TSTP is cleared by reading CAN_SR.
The time management unit can operate in one of the following two modes:
- Timestamping: the value of the internal timer is captured at each Start Of Frame or each End Of Frame
- Time-triggered: a mailbox transfer operation is triggered when the internal timer reaches the mailbox trigger.
Timestamping mode is enabled by clearing the CAN_MR.TTM field. To enable the Time-triggered mode, set TTM.