kdb349: GPS Time Synchronization in Linux

Introduction

This document entails the use of the Connect Tech MPG20X GPS mPCIe or m.2 device as a time source for the system clock.

Requirements

To communicate with your GPS device(s), you will require the use of the GPS daemon gpsd. This software allows Linux to interpret the native GPS signal over the connected serial interface on the MPG20X devices.

To provide the OS (Operating System) with time data from the MPG20X you will require NTP to be installed, a network time protocol that allows the system time to synchronise with a networked source. In this case the source will be the GPS module.

(Optional)

For additional accuracy and precision time you will require the use of the PPS pin located on the MPG20X device header PIN2. Further information can be found in the manual. To use the PPS you will need pps-tools installed.

Setup

PPS

Prior to setting up the hardware device you will need to ensure your kernel has pps enabled and that it is supported. Navigate to your boot config file and set your kernel PPS params to y from m. You may find these commands in /boot/config-XXX, they are as follows:

CONFIG_PPS=y
CONFIG_PPS_CLIENT_LDISC=y
CONFIG_PPS_CLIENT_GPIO=y
CONFIG_GPIO_SYSFS=y

*Reboot, as we have edited the boot params.

This signal must be connected to a digital GPIO device (GPIO setup is device dependent and is not covered by the KDB), and can be set as a pps device using the ldattach command to the corresponding GPIO dev/ address such as:

ldattach 18 /dev/deviceNAME

There should now be a new device located at dev/pps0

Now add the following lines to /etc/ntp.conf:

# GPS PPS reference
Server 127.127.28.1 minpoll 4 maxpoll 4
Fudge 127.127.28.1 refid PPS

Proceed to the setup without pps in the next section

GPS

The GPS module MPG20X can be started using gpsd, you may also use it to test/debug your gps device. GPSD can be started using the following command:

gpsd –n /dev/ttyACM0

(Your device may be at a different address depending on how it was installed and which version of linux)

When the GPS has started you can check cgps to see if the device is receiving data/signal from satellites.

cgps

When the device is ready and receiving, it is now possible to proceed with NTP, which must be permitted by the firewall.

firewall-cmd --add-service=ntp --permanent
firewall-cmd –reload

Add the following lines to ntp.conf

# GPS Serial Data reference
server 127.127.28.0 minpoll 4 maxpoll 4
fudge 127.127.28.0 time1 0.0 refid GPS

Now start NTP, using the following commands (This was done using Centos 7.1 and as such you may require a different system command):


systemctl start ntpd
systemctl enable ntpd

Check to see if NTP services is running


systemctl status ntpd
ntpq -p

You should now have time synchronization using the GPS module. Please keep in mind that NTP does not instantly update the system time. The NTP will slowly synchronize with the connected source device as to not cause sporadic time skips when using a potentially unstable time source. As such, you will not witness the results of gps time sync until the system has stabilized.

Reference

https://www.lammertbies.nl/comm/info/GPS-time.html

https://blog.logentries.com/2015/07/adding-a-gps-time-source-to-ntpd/

http://www.catb.org/gpsd/

http://www.tldp.org/LDP/sag/html/basic-ntp-config.html

Appendix

TIMEPULSE

The TIMEPULSE output is a buffered and ESD protected signal from the GPS receiver. This signal connects to pin 2 of the External I/O Connector. It also drives the TIMEPULSE LED. By default, when satellites are not fixed this signal is High (3.3V). When satellites are fixed, this signal pulses at 1 pulse-per-second (1Hz) with a 20% duty cycle (200ms High, 800ms Low). For more information see the Receiver Description Including Protocol Specification document for your GPS receiver found in the Software Support section of this document.

Go to Top