35.5.3 Timestamp Generation
Default Behavior
For timestamp generation the CAN supplies a 16-bit wrap-around counter. A prescaler TSCC.TCP bit (TSCC <19:16>) can be configured to clock the counter in multiples of CAN bit times (1…16). The counter is readable via TSCV.TSC bit (TSCV <15:8>). A write access to register TSCV resets the counter to zero. When the timestamp counter wraps around interrupt flag IR.TSW bit (TSW <16>) is set.
On start of frame reception / transmission the counter value is captured and stored into the timestamp section of an Rx Buffer / Rx FIFO (RXTS[15:0]) or Tx Event FIFO (TXTS[15:0]) element.
By programming the TSCC.TSS (TSCC <1:0>) bit, a 16-bit external Timestamping Unit (TSU) can be used, instead of the internal 16-bit counter.
Behavior When Enabling the TSU
Overview
The TSU implements the requirements specified in CiA 603. This approach is independent of interrupt response times and thus achieves the best possible accuracy. The TSU may operate on its own internal timebase, or use an external time base, e.g. a reference time base from a timer/counter within the device.
The TSU offers the capability to store up to 16 captured timestamps. The resolution depends on the internal or external counter resolution. Up to 32-bit resolution is available.
To enable the CAN-FD hardware timestamping together with the TSU, the CCCR.UTSU (CCCR <10>) bit must be set to 1. If the bit is cleared, the internal 16-bit timestamp counter will be used by default.
A message timestamping can happen at the start-of-frame (SoF), or end-of-frame (EoF).
The TSU is configured via the TSCFG register, which is writable only when the CCCR.CCE (CCCR <1>) = 1.
With TSCFG.TSUE (TSCFG <0>) the TSU is enabled. Default after reset is disabled. The Timebase Prescaler TSCFG.TBPRE (TSCFG <15:8>) is used to adapt the count rate of the TSU’s internal counter, if enabled, to the requirements of the application.
Either the internal timebase or an external timebase input can be selected for timestamping via TSCFG.TBCS (TSCFG <1>). In case TSCFG.TBCS (TSCFG <1>) = ‘0’, the internal free running timebase counter is used. In case TSCFG.TBCS (TSCFG <1>) = ‘1’, the timestamp value is taken from the Timebase Input tsu_tbin[31:0].
Reception of Timestamped Messages
To configure the M_CAN for reception of timestamped messages, a Standard/Extended Message ID Filter Element has to be set up by configuration of S0.SSYNC = ‘1’ respectively F1.ESYNC = ‘1’. In case the filter element matches the received frame and the received frame is valid, a capture will be performed at the EOF. The value of the Actual Timebase (ATB) is stored into the TSU’s timestamp register selected by the TSS2.TSP (TSS2 <3:0>). The TSP value from the TSU will be written into the R1.RXTSP of the related RX Buffer or RX FIFO element.
Transmission of Timestamped Messages
In case bits T1.TSCE and T1.EFC of a TX Buffer element are set, a successful transmission of that TX Buffer triggers the storage of the value of the TSU’s Actual Timebase ATB to the TSU's timestamp register selected by the Timestamp Pointer TSS2.TSP (TSS2 <3:0>). The Timestamp Pointer value from the TSU is written to the E1.TXTSP of the related TX Event FIFO element.
Capture Point
TSCFG.SCP configures the point in time when a timestamp is captured for Sync messages (0: at EOF, 1: at SOF of the received/transmitted Sync message).
When TSCFG.SCP (TSCFG <2>) = '0', the timestamp is captured directly from the Actual Timebase ATB to the timestamp register TSn, when the message gets valid at EOF. This configuration is intended for AUTOSAR conformant applications.
When TSCFG.SCP (TSCFG <2>) = '1', the Actual Timebase ATB is captured into a temporary buffer at each SOF.
When the message gets valid at EOF the timestamp is copied from the temporary buffer to the timestamp register TSn.
Handling of Timestamps
The timestamps are written from TS0 to TS7 in a cyclic manner. Each timestamp register has assigned two status bits:
- TSS1.TSNn (TSS1 <31:16>) is set whenever a timestamp was stored to the related timestamp register TSn
- TSS1.TSLn (TSS1 <15:0>) is set when a new timestamp was stored to the related timestamp register TSn before the previously store timestamp has been read out
Reading a Timestamp register resets the related TSS1 bits.
Synchronization Process After AUTOSAR
After successful configuration of all participating CAN nodes, the timers of the time slaves can be corrected with a two-step synchronization process. In the first step, the current time T0 is latched in the time master, and the part of T0, which represents the seconds, is sent to the time slaves with the SYNC message. If the EoF (End-Of-Frame) is reached when sending this SYNC message, then timestamps are stored in the TSUs of all nodes, i.e. in the Time Master and all Time Slaves. This is the common point of time reference. In the second step, the time master adds its TSU time stamp to the nanosecond part of T0 and sends it to the time slaves via FollowUp message. From this, the time slaves can derive their own time base.
Saving Time Stamps at SoF (Start-of-Frame)
For non-AUTOSAR applications, the TSU can also be configured to store timestamps at the start of a CAN message (SoF bit).