美文网首页NVIDIA Jetson working
Xavier + GPS/PPS + NTP时间设置

Xavier + GPS/PPS + NTP时间设置

作者: 童年雅趣 | 来源:发表于2020-10-29 12:08 被阅读0次
硬件准备

Xavier 开发套件一套
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升级是否正常。

如何应用

1、安装第三方工具
sudo apt-get install -y setserial gpsd gpsd-clients python-gps pps-tools

2、测试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 无信号,调整天线或排查模块是否有异常

3、查看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等)

gpsmon.png

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:~$ 

相关文章

网友评论

    本文标题:Xavier + GPS/PPS + NTP时间设置

    本文链接:https://www.haomeiwen.com/subject/milcvktx.html