一、GPTP简介

       GPTP(IEEE 802.1AS)本质上是PTP1588在时间敏感网络(TSN)框架下的车载定制化版本,专为车载以太网的确定性传输、强电磁干扰、固定拓扑等特性优化,是智能驾驶时代的核心时间同步技术。与PTP1588相比,GPTP的核心特点体现在三个方面:一是强制硬件时间戳,通过MAC层硬件采样时间戳,规避软件实现的延迟波动,确保亚微秒级同步精度,满足激光雷达、摄像头等多传感器融合的数据时序一致性要求;二是简化配置与自动协商,采用优化的最佳主时钟算法(BMCA),无需手动配置主从时钟,系统上电后自动选举最优主时钟,适配车载场景的量产落地需求;三是强抗干扰与确定性,仅支持P2P延时测量机制,逐跳补偿中间设备的驻留时间误差,避免链路拥堵、电磁干扰对同步精度的影响。

二、LinuxPTP简介

        在车载场景适配方面,linuxptp项目具备显著优势,极大降低了GPTP协议的工程化落地成本。项目自带automotive-master.cfg与automotive-slave.cfg两款车载专用配置文件,预设了符合IEEE 802.1AS标准的关键参数,如传输标识、目标MAC地址等,无需开发人员从零调试参数。在实际部署中,主时钟(通常部署于域控制器或中央网关)可通过“sudo ptp4l -i eth0 -f automotive-master.cfg -m”命令快速启动,强制为主模式并采用P2P延迟机制,避免角色切换带来的同步波动;从时钟(传感器、执行器等终端设备)则通过对应从配置文件启动,自动同步主时钟时间。此外,该项目支持硬件级时间戳捕获,可适配车载以太网网卡的时间敏感特性,抵消电磁干扰对同步精度的影响,完美匹配GPTP强制硬件时间戳的核心要求。

       下面贴出Master的配置文件:

# Automotive Profile example configuration for master containing those
# attributes which differ from the defaults.  See the file, default.cfg, for
# the complete list of available options.
#
[global]
# Options carried over from gPTP.
gmCapable               1
priority1               248
priority2               248
logSyncInterval         -3
syncReceiptTimeout      3
neighborPropDelayThresh 800
min_neighbor_prop_delay -20000000
assume_two_step         1
path_trace_enabled      1
follow_up_info          1
transportSpecific       0x1
ptp_dst_mac             01:80:C2:00:00:0E
network_transport       L2
delay_mechanism         P2P
#
# Automotive Profile specific options
#
BMCA                    noop
masterOnly              1
inhibit_announce        1
asCapable               true
inhibit_delay_req       1

Slave的配置文件:

#
# Automotive Profile example configuration for slaves containing those
# attributes which differ from the defaults.  See the file, default.cfg, for
# the complete list of available options.
#
[global]
#
# Options carried over from gPTP.
#
gmCapable               1
priority1               248
priority2               248
logSyncInterval         0
syncReceiptTimeout      3
neighborPropDelayThresh 800
min_neighbor_prop_delay -20000000
assume_two_step         1
path_trace_enabled      1
follow_up_info          1
transportSpecific       0x1
ptp_dst_mac             01:80:C2:00:00:0E
network_transport       L2
delay_mechanism         P2P
#
# Automotive Profile specific options
#
BMCA                    noop
slaveOnly               1
inhibit_announce        1
asCapable               true
ignore_source_id        1
# Required to quickly correct Time Jumps in master
step_threshold          1
operLogSyncInterval     0
operLogPdelayReqInterval 2
msg_interval_request     1
servo_offset_threshold   30
servo_num_offset_values  10
#domainNumber             2

三、基于gPTP实现Linux系统时间同步

        试验采用本公司自主开发的U20时间服务器,实现Linux系统在GPTP协议框架下的时间同步功能。首先对U20进行相关的web端配置:

        设置为主模式后,使能802.1AS后,服务器自动选择GPTP配置。

        下面打开Linux操作系统,安装好Linuxptp,笔者的版本为:

cailiang@cailiang-VMware-Virtual-Platform:~/桌面$ ptp4l -v
3.1.1

        等待U20服务器锁定之后,输入以下命令:

sudo ptp4l -i ens33 -m -S  -f /home/cailiang/文档/automotive_Slave.conf

        此时ptp4l开始同步:

ptp4l[245.895]: port 1: new foreign master 000a35.fffe.000102-1
ptp4l[247.520]: rms 46670831966 max 46673075536 freq     +0 +/-   0 delay 351092 +/-   0
ptp4l[247.895]: selected best master clock 000a35.fffe.000102
ptp4l[247.895]: foreign master not using PTP timescale
ptp4l[247.895]: running in a temporal vortex
ptp4l[249.270]: rms 46678343189 max 46682599347 freq     +0 +/-   0 delay 347532 +/- 432
ptp4l[250.271]: rms 46684931304 max 46689146459 freq     +0 +/-   0 delay 349528 +/-   0
ptp4l[251.270]: rms 46689875629 max 46693019475 freq     +0 +/-   0 delay 351092 +/-   0
ptp4l[252.270]: rms 46694986863 max 46698008857 freq     +0 +/-   0 delay 372058 +/-   0
ptp4l[253.270]: rms 46700074415 max 46703195929 freq     +0 +/-   0 delay 388425 +/-   0
ptp4l[254.270]: rms 46705113616 max 46708075844 freq     +0 +/-   0 delay 390724 +/-   0
ptp4l[255.270]: rms 46710148262 max 46713206512 freq     +0 +/-   0 delay 388425 +/-   0
ptp4l[256.270]: rms 46715316145 max 46718518325 freq     +0 +/-   0 delay 369758 +/-   0
ptp4l[257.270]: rms 46720447457 max 46723507217 freq     +0 +/-   0 delay 368195 +/-   0

        可以看到,LinuxPTP已经开始和服务器之间通过gPTP协议实现时间同步了。

        通过Wireshark监控可以看到,所有协议均运行在物理层:

        以上就是基于Linux系统实现GPTP时间同步的相关操作与配置,后面笔者继续跟大家分享更多的时间同步方面的内容。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐