Hard Processor System Technical Reference Manual: Agilex™ 5 SoCs

ID 814346
Date 4/01/2024
Public
Document Table of Contents

5.1.6.9.5. System Time Register Module

The 64-bit time is maintained in system time generator module and updated using the input reference clock (emac_ptp_clk). This time is the source for taking snapshots (timestamps) of Ethernet packets being transmitted or received at the GMII interface.

The system time counter can be initialized or corrected using the coarse correction method. In this method, the initial value or the offset value is written to the timestamp update register. For initialization, the system time counter is written with the value in the timestamp update register. For system time correction, the offset value is added to or subtracted from the system time.

In the fine correction method, the frequency drift of a time receiver clock (emac_ptp_clk) with respect to the time transmitter clock (as defined in IEEE 1588) is corrected over a period of time instead of in one clock, as in coarse correction. This helps maintain linear time and does not introduce drastic changes (or a large jitter) in the reference time between PTP sync message intervals. In this method, an accumulator sums up the contents of the addend register, as shown in figure below. The arithmetic carry that the accumulator generates is used as a pulse to increment the system time counter. The accumulator and the addend are 32-bit registers. The accumulator acts as a high-precision frequency multiplier or divider.
Note: You must connect a PTP clock with a frequency higher than the frequency required for the specified accuracy.
Figure 77. System Time Update Using Fine Method

The system time update logic requires a 50 MHz clock frequency to achieve 20 ns accuracy. The frequency division is the ratio of the reference clock frequency to the required clock frequency. For example, if the reference clock (emac_ptp_clk) is 66 MHz, this ratio is calculated as 66 MHz / 50 MHz = 1.32. Therefore, the default value to be set in the register is 232 / 1.32, 0xC1F07C1F.

If the reference clock drifts lower, for example, to 65 MHz, the ratio is 65 / 50, or 1.3 and the value to set in the addend register is 232 / 1.30, or 0xC4EC4EC4. If the clock drifts higher, for example, to 67 MHz, the addend register must be set to 0xBF0B7672. When the clock drift is zero, the default addend value of 0xC1F07C1F (232 / 1.32) must be programmed.

In the figure above, the constant value used to accumulate the sub-second register is decimal 43, which achieves an accuracy of 20 ns in the system time (in other words, it is incremented in 20 ns steps). When external time update is enabled, the optional system time module is not available. Two different methods are used to update the system time register depending on the configuration.

The software must calculate the drift in frequency based on the sync messages and accordingly update the addend register. Initially, the time receiver clock is set with FreqCompensationValue0 in the addend register. This value is as follows:

FreqCompensationValue0 = 232 / FreqDivisionRatio

If MasterToSlaveDelay is initially assumed to be the same for consecutive sync messages, the algorithm given in this section is applicable. After a few sync cycles, frequency lock occurs. The time receiver clock can then determine a precise MasterToSlaveDelay value and synchronize again with the host, using the new value.

The algorithm is as follows:
  • At time MasterSyncTimen the host sends the time receiver clock a sync message. The time receiver receives this message when its local clock is SlaveClockTimen and computes MasterClockTimen as:

    MasterClockTimen = MasterSyncTimen + MasterToSlaveDelayn

  • The time transmitter clock count for current sync cycle, MasterClockCountn is:

    MasterClockCountn = MasterClockTimen MasterClockTimen – 1 (assuming that MasterToSlaveDelay is the same for sync cycles n and n – 1)

  • The time receiver clock count for current Sync cycle, SlaveClockCountn is:

    SlaveClockCountn = SlaveClockTimen SlaveClockTimen – 1

  • The difference between time transmitter and time receiver clock counts for current Sync cycle, ClockDiffCountn is:

    ClockDiffCountn = MasterClockTimen SlaveClockTimen

  • The frequency-scaling factor for ) clock, FreqScaleFactorn is:

    FreqScaleFactorn = (MasterClockCountn + ClockDiffCountn )/ SlaveClockCountn

  • The frequency compensation value for Addend register, FreqCompensationValuen is:

    FreqCompensationValuen = FreqScaleFactorn * FreqCompensationValuen – 1

In theory, this algorithm achieves lock in one sync cycle. However, it might take several cycles, because of changing network propagation delays and operating conditions. This algorithm is self-correcting. If the time receiver clock is initially set to an incorrect value from the host, the algorithm corrects it at the cost of more sync cycles.