硬件准备
Xavier 开发套件一套/图为T6xx 系列智盒
GPS 模块一套(自带PPS输出)
硬件接口:3.3V、UART5(J58/H58, ttyTHS4)、PPS_GPIO(B58, GPIO_PA.00)
BSP支持
1、添加PPS 支持
由于Xavier(NX/Nano/TX)不支持专用PPS硬件信号,通过软件将GPIO模拟接收PPS信号,修改如下:
hardware\nvidia\platform\t19x\galen\kernel-dts\common\tegra194-p2888-0000-a00.dtsi
pps {
//here use gpio for the pin in which you want pps signal.
gpios = <&tegra_main_gpio TEGRA194_MAIN_GPIO(A, 0) GPIO_ACTIVE_LOW>;
compatible = "pps-gpio";
assert-falling-edge;
status = "okay";
};
同步修改kernel config文件
CONFIG_PPS=y
CONFIG_PPS_CLIENT_GPIO=y
2、编译并升级dtb文件,待机器重启后,查看如下设备节点:
PPS 设备节点: /dev/pps0
Sysfs文件节点: /sys/class/pps/pps0/
每当GPS的PPS过来后,会在对应的GPIO下降沿时会产生一个中断信号,此时也会产生一个timestamp时间戳,通过如下命令查看:
$cat /sys/class/pps/pps0/assert
1603875932.000014717#2869
如果PPS sysfs和dev 节点未出现则排查软件修改是否正确、DTB升级是否正常。
A pulse per second (PPS or 1PPS) is an electrical signal that has a width of less than one second and a sharply rising or abruptly falling edge that accurately repeats once per second. PPS signals are output by radio beacons, frequency standards, other types of precision oscillators and some GPS receivers.Precision clocks are sometimes manufactured by interfacing a PPS signal generator to processing equipment that aligns the PPS signal to the UTC second and converts it to a useful display. Atomic clocks usually have an external PPS output, although internally they may operate at 9,192,631,770 Hz. PPS signals have an accuracy ranging from a 12 picoseconds to a few microseconds per second, or 2.0 nanoseconds to a few milliseconds per day based on the resolution and accuracy of the device generating the signal.
每秒脉冲(PPS或1PPS)是一种宽度小于一秒的电子信号,其下降沿或上升沿以精确的时间每秒重复一次。PPS信号由无线电信标、频率标准、其他类型的精密振荡器和一些GPS接收机输出。精密时钟有时是通过将PPS信号发生器连接到处理设备来制造的,处理设备将PPS信号校准到UTC秒,并将其转换为有用的显示。原子钟通常有外部PPS输出,但内部可能运行在9192631770赫兹。根据产生信号的设备的分辨率和精度,PPS信号的精度范围在12皮秒到几微秒之间,或者每天2.0纳秒到几毫秒之间。
如何应用
1、安装第三方工具
sudo apt-get install -y setserial gpsd gpsd-clients python-gps pps-tools
2、查看GPS信号
stty -F /dev/ttyTHS4 9600
sudo gpsd /dev/ttyTHS4 -F /var/run/gpsd.sock
gpsd 运行服务: (开机自启动)
sudo systemctl daemon-reload
sudo systemctl enable gpsd
sudo systemctl restart gpsd
释放init进程开启的gpsd进程socket和service
sudo systemctl stop gpsd.socket
sudo systemctl stop gpsd.service
运行gpsmon 即可查看gps 状态如图(经纬度、时间、NMEA等)
3、测试PPS信号 (通过pps-tools 工具测试)
nvidia@Xavier:~$ sudo ppstest /dev/pps*
trying PPS source "/dev/pps0"
found PPS source "/dev/pps0"
ok, found 1 source(s), now start fetching data...
time_pps_fetch() error -1 (Connection timed out)
time_pps_fetch() error -1 (Connection timed out)
前提是GPS 必须有信号,且获取到经纬度和时间信息后,PPS才有输出,以上说明GPS信号有问题,调整天线或排查模块是否有异常
4、如何通过NTP将系统时间同步为GPS时间
步骤1、 安装ntp
sudo apt-get install -y ntp
步骤2、设置ntp conf
$sudo mv /etc/ntp.conf /etc/ntp.conf.bak (备份ntp.conf)
$sudo vi /etc/ntp.conf
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
# Drift file to remember clock rate across restarts
driftfile /var/lib/ntp/ntp.drift
# Server from generic NMEA GPS Receiver
# server: NMEA serial port (/dev/gps0), mode 16 = 9600 baud + 2 = $GPGGA
# fudge: flag 1 for use PPS (/dev/gpspps0), time2 for calibration time offset
server 127.127.20.0 mode 18 minpoll 3 maxpoll 3 prefer
fudge 127.127.20.0 flag1 1 time2 0.000 refid gPPS
重启NTP Service (当前ntp 无法开机自动启动服务,需要每次开机运行 sudo service ntp restart)
nvidia@Xavier:~$ sudo service ntp restart
[sudo] password for nvidia:
nvidia@Xavier:~$ sudo service ntp status
● ntp.service - Network Time Service
Loaded: loaded (/lib/systemd/system/ntp.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-10-29 10:11:45 CST; 3s ago
Docs: man:ntpd(8)
Process: 10001 ExecStart=/usr/lib/ntp/ntp-systemd-wrapper (code=exited, status=0/SUCCESS)
Main PID: 10033 (ntpd)
Tasks: 2 (limit: 4915)
CGroup: /system.slice/ntp.service
└─10033 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 125:131
10月 29 10:11:45 Xavier systemd[1]: Starting Network Time Service...
10月 29 10:11:45 Xavier ntpd[10033]: proto: precision = 0.288 usec (-22)
10月 29 10:11:45 Xavier systemd[1]: Started Network Time Service.
10月 29 10:11:45 Xavier ntpd[10033]: switching logging to file /var/log/ntp.log
通过ntpq -p 查看ntp 状态
nvidia@Xavier:~$ ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*GPS_NMEA(0) .gPPS. 0 l 49 8 100 0.000 0.000 0.000
步骤3、关机等待一段时间(随机),再次开机查看date或ntptime 是否同步更新以此确认ntp时间设置为了GPS 时间
nvidia@Xavier:~$ ntptime
ntp_gettime() returns code 0 (OK)
time e344a3a4.97d50000 Thu, Oct 29 2020 10:12:52.593, (.593094),
maximum error 33516 us, estimated error 16 us, TAI offset 0
ntp_adjtime() returns code 0 (OK)
modes 0x0 (),
offset 0.000 us, frequency 0.000 ppm, interval 1 s,
maximum error 33516 us, estimated error 16 us,
status 0x1 (PLL),
time constant 7, precision 1.000 us, tolerance 500 ppm,
nvidia@Xavier:~$