APEX ORIN NX PTP Function#
Explanation#
The Precision Time Protocol (PTP) is a protocol used to synchronize clocks across a computer network. On a local area network, clock accuracy at the nanosecond level can be achieved.

Preparatory work#
Preparation work - Hardware connection#
Prepare two devices: Device A and Device B. Device A is the master device, and Device B is the slave device. Set static IPs for the network interfaces of the two devices, connect them directly with a network cable, and ensure they can ping each other. If a switch or router is used in the network link, the switch or router must also support the PTP protocol.
Preparatory work - software environment#
sudo git clone -b v4.1 git://git.code.sf.net/p/linuxptp/code linuxptp
cd linuxptp
sudo make
sudo make install
Master-slave device configuration#
Configuration process
The master starts the ptp4l service → The master synchronizes its time to the network card clock → The slave synchronizes the master’s time to the network card clock → The slave synchronizes the network card clock to the system clock
Open a terminal and execute the following commands:
sudo ptp4l -i eth1 -m -H --step_threshold 1.0
This command is used to start the ptp4l service. At this time, the information printed on the terminal of the master device should be as shown in the figure below:

Open another terminal and execute the following commands:
sudo phc2sys -m -s CLOCK_REALTIME -c eth1 -w --step_threshold 1.0
This command is used to synchronize the system clock of the master device to the network card hardware clock. At this time, the information printed by this terminal should be as shown in the figure below:

Open the terminal of the device and execute the following commands:
sudo ptp4l -i eth1 -m -H -s --step_threshold 1.0
This command is used to synchronize the master clock to the slave clock. At this time, the information printed by the terminal should be as shown in the figure below:

Among them, the master offset is the time offset between the master and slave devices, with the unit of ns.
Open another terminal and execute the following commands:
sudo phc2sys -m -s eth1 -w --step_threshold 1.0
This command is used to synchronize the network card clock of the slave device to the system clock. At this time, the information printed on this terminal should be as shown in the figure below:

Among them, the phc offset is the time offset of the network card clock and system clock of the slave device.
Function verification#
Test process
Confirm master time → Confirm slave time → Modify master time → Confirm that the slave time is synchronized
View the system time of the master device:
sudo timedatectl

View the system time of the slave device:
sudo timedatectl

Change the system time of the master device
sudo date -s 12:12:12
At this point, you can see that the time of the matser system has been changed, as shown in the figure below:

At the same time, observe the system time on the slave device. Wait for about 30 seconds, and you can see that the time has been adjusted to the master’s system time at this moment.
sudo timedatectl
Observing the system time on the slave device, it can be seen that the time has been adjusted to the system time of the master, as shown in the following figure:

Performance verification#
Open the terminal on the slave device and execute the following commands:
sudo ptp4l -i eth1 -m -H -s --step_threshold 1.0
This command is used to synchronize the master clock to the slave clock. At this time, the information printed by the terminal should be as shown in the figure below:

Among them, the master offset is the time offset between the master and slave devices, with the unit being ns.
Remarks#
Check whether the device supports hardware PTP#
sudo ethtool -T ethX
Just change ethX to the corresponding network card, and the following content will be displayed (take eth1 as an example):

If the following parameters are included, it means the device supports the hardware PTP function: SOF_TIMESTAMPING_SOFTWARE
SOF_TIMESTAMPING_TX_SOFTWARE
SOF_TIMESTAMPING_RX_SOFTWARE
SOF_TIMESTAMPING_RAW_HARDWARE
SOF_TIMESTAMPING_TX_HARDWARE
SOF_TIMESTAMPING_RX_HARDWARE
If only the following parameters are included, it means the device does not support the hardware PTP function.
SOF_TIMESTAMPING_SOFTWARE
SOF_TIMESTAMPING_TX_SOFTWARE
SOF_TIMESTAMPING_RX_SOFTWARE