硬件準(zhǔn)備
Xavier 開發(fā)套件一套/圖為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文件屎暇,待機器重啟后承桥,查看如下設(shè)備節(jié)點:
PPS 設(shè)備節(jié)點: /dev/pps0
Sysfs文件節(jié)點: /sys/class/pps/pps0/
每當(dāng)GPS的PPS過來后,會在對應(yīng)的GPIO下降沿時會產(chǎn)生一個中斷信號根悼,此時也會產(chǎn)生一個timestamp時間戳凶异,通過如下命令查看:
$cat /sys/class/pps/pps0/assert
1603875932.000014717#2869
如果PPS sysfs和dev 節(jié)點未出現(xiàn)則排查軟件修改是否正確、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)是一種寬度小于一秒的電子信號剩彬,其下降沿或上升沿以精確的時間每秒重復(fù)一次。PPS信號由無線電信標(biāo)矿卑、頻率標(biāo)準(zhǔn)喉恋、其他類型的精密振蕩器和一些GPS接收機輸出。精密時鐘有時是通過將PPS信號發(fā)生器連接到處理設(shè)備來制造的母廷,處理設(shè)備將PPS信號校準(zhǔn)到UTC秒轻黑,并將其轉(zhuǎn)換為有用的顯示。原子鐘通常有外部PPS輸出徘意,但內(nèi)部可能運行在9192631770赫茲苔悦。根據(jù)產(chǎn)生信號的設(shè)備的分辨率和精度,PPS信號的精度范圍在12皮秒到幾微秒之間椎咧,或者每天2.0納秒到幾毫秒之間玖详。
如何應(yīng)用
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 運行服務(wù): (開機自啟動)
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
運行g(shù)psmon 即可查看gps 狀態(tài)如圖(經(jīng)緯度蟋座、時間拗踢、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 必須有信號向臀,且獲取到經(jīng)緯度和時間信息后巢墅,PPS才有輸出,以上說明GPS信號有問題券膀,調(diào)整天線或排查模塊是否有異常
4君纫、如何通過NTP將系統(tǒng)時間同步為GPS時間
步驟1、 安裝ntp
sudo apt-get install -y ntp
步驟2芹彬、設(shè)置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 (當(dāng)前ntp 無法開機自動啟動服務(wù)蓄髓,需要每次開機運行 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 狀態(tài)
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、關(guān)機等待一段時間(隨機)舒帮,再次開機查看date或ntptime 是否同步更新以此確認ntp時間設(shè)置為了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:~$