LinuxPPS NTPD support

From LinuxPPS
Jump to: navigation, search

Currently you may have to patch ntpd in order for LinuxPPS to work.
We are working on getting these patches merged into the upstream ntpd source.
See this for how to set up your environment for compiling ntpd.

The following are the reference clocks that are known to be working with LinuxPPS.

Generic NMEA GPS Receiver (refclock_nmea - driver 20)

This driver implements reference clock support for NTPD package that can read time data from a Generic NMEA GPS receiver and optionally its PPS signal.

General Information

Installation

If you are using ntpd before 4.2.6p1, you will need to patch the refclock_nmea.c with the supplied patch file, and then configure and compile ntpd. You can follow the instructions below, which will disable reference clocks which are known to be buggy when used with LinuxPPS. Please refer to the NTPD documentation for any other compilation options you may need.

$ cd my-ntpd-source
$ patch -p1 < nmea.patch
$ ./configure --disable-all-clocks --disable-parse-clocks \
              --enable-NMEA --enable-LOCAL-CLOCK
$ make

When this completes, you will have an NTP daemon which works with LinuxPPS. You can install it if you would like, using make install.

Part of Udo's ntp.conf is shown below.

server 127.127.20.0 prefer minpoll 4
fudge 127.127.20.0 flag3 1 flag2 0 time1 0.0

You can use this info in /etc/udev/rules.d/09.pps.rules

KERNEL=="ttyS0", SYMLINK+="gps0"
KERNEL=="pps0", OWNER="root", GROUP="tty", MODE="0660", SYMLINK+="gpspps0"
KERNEL=="ttyS0", RUN+="/bin/setserial -v /dev/%k low_latency irq 4"

so that the driver can find the necessary device files when ldattach opens the /dev/ttyS0 file using this service file in /usr/lib/systemd/system:

# cat ldattach@.service 
[Unit]
Description=Line Discipline for GPS Timekeeping for %i
Before=ntpd.service

[Service]
ExecStart=/sbin/ldattach 18 /dev/%i
Type=forking

[Install]
WantedBy=multi-user.target 

Then enable the service file:

# systemctl enable ldattach@ttyS0.service
ln -s '/usr/lib/systemd/system/ldattach@.service' '/etc/systemd/system/multi-user.target.wants/ldattach@ttyS0.service'
#

On reboot this will start ldattach before ntpd. Please adapt service file name in enable command to your serial port situation.

Notes

For further information on this reference clock, please view the NTPD documentation. See above for a link.

The Generic NMEA GPS Receiver code was successfully tested with a Garmin GPS 18 LVC and NTP ntp-4.2.4p2.

You can find a very useful email with instructions on using NTPD with the NMEA patch in our mailing list archives.

flag3 was set to 1 to use the kernel consumer. Please refer to Alexander Gordeev's hardpps patch.

Atom PPS Clock Discipline (refclock_atom - driver 22)

This driver implements reference clock support for NTPD package that can read time data from a Atom PPS Clock Discipline.

General Information

Installation

As mentioned in the NTPD documentation, this is a secondary PPS input driver that can be used with any other time source, either a local reference clock or a network peer.

Because a PPS signal does not give a complete time, it must be attached to another time source which can disambiguate the seconds. If that time source is valid and within ±0.4 seconds of the PPS edge, the PPS clock will "take over" and provide the time measurements that NTPD uses.

Note that it is entirely normal for the PPS time source to use the same serial port as a serial time code. For serial ports, the PPS time source uses the edges of the DCD input signal.

The disambiguating time source is marked with the keyword prefer on its server or peer line. The PPS clock will not begin sampling until this clock is detected, so do not worry about not seeing events detected immediately.

An example ntp.conf using the PPS clock configuration follows. The prefix 127.127.22 specifies the ATOM driver (driver 22). The last number, 1 in this case, specifies PPS source number 1. This means /dev/pps1.

The flag2 1 specifies that the clear transition of the PPS signal is to be used. This means that /sys/class/pps/pps1/clear will be used as the time source. The default, when flag2 is not specified, is to use the assert signal.

# PPS source /dev/pps1 using the clear edge
server 127.127.22.1 minpoll 4 maxpoll 4
fudge 127.127.22.1 flag2 1

# Network clock for disambiguation
server my.network.clock prefer

PPS pulses are usually short, and the leading edge is the on-time mark, so by looking at the time of two adjacent edges with cat /sys/class/pps/pps1/{assert,clear}, you can see which one leads the other.

Notes

If you do not have a local reference clock, one possible rude hack is to mark the PPS source as prefer as well as the network clock. This will make the network clock required for NTPD to start. However, once NTPD has started, it can keep time by itself as long as it does not lose the PPS signal.

WARNING: this can result in the NTP server claiming to have good time when it is off by several seconds. It is NOT RECOMMENDED!

Motorola Oncore GPS receiver (refclock_oncore - driver 30)

This driver implements reference clock support for NTPD package that reads time data and PPS signals from a Motorola Oncore GPS receiver.

General Information

Rockwell Jupiter GPS receiver (refclock_jupiter - driver 31)

This driver implements reference clock support for NTPD package that can read time data and PPS signal from a Rockwell Jupiter GPS receiver.

General Information

Installation

You will need to patch the refclock_jupiter.c with the supplied patch file, and then configure and compile ntpd. You can follow the instructions below, which will disable reference clocks which are known to be buggy when used with LinuxPPS. Please refer to the NTPD documentation for any other compilation options you may need.

$ cd my-ntpd-source
$ patch -p1 < jupiter.patch
$ ./configure --disable-all-clocks --disable-parse-clocks --enable-JUPITER \
            --enable-LOCAL-CLOCK --enable-HAVE_PPSAPI --enable-HAVE_TIMEPPS_H
$ make

When this completes, you will have an NTP daemon which works with LinuxPPS. You can install it if you would like, using make install.

You will need to create a /dev/gps0 file, which should be a symlink to /dev/ttySX.

An example ntp.conf follows:

server 127.127.31.0

Notes

The Rockwell Jupiter receiver was tested with a Jupiter12 and ntp-4.2.4p4.

RIPE NCC interface for Trimble Palisade (refclock_ripencc - driver 43)

This driver implements reference clock support for NTPD package that can read time data from a RIPE NCC interface for Trimble Palisade.

General Information

Installation

There is an article at ripe.net which explains how to make this clock work.
Below are the instructions for the older patch.

You will need to patch the refclock_ripencc.c with the supplied patch file, and then configure and compile ntpd. You can follow the instructions below, which will disable reference clocks which are known to be buggy when used with LinuxPPS. Please refer to the NTPD documentation for any other compilation options you may need.

$ cd my-ntpd-source
$ patch -p1 < patch.ntp-4.2.6-refclock_ripencc.c
$ ./configure --disable-all-clocks --disable-parse-clocks \
              --enable-RIPENCC --enable-LOCAL-CLOCK
$ make

When this completes, you will have an NTP daemon which works with LinuxPPS. You can install it if you would like, using make install.

Part of Kiss Gabor's ntp.conf is shown below.

server 127.127.43.0     # RIPENCC
# fudge 127.127.43.0 time1 0.0002  # if needed
# fudge 127.127.43.0 stratum 13    # just for testing purpuses

You can use this info in /etc/udev/rules.d/09.pps.rules

KERNEL=="ttyS0", SYMLINK+="gps0"
KERNEL=="pps0", OWNER="root", GROUP="tty", MODE="0660", SYMLINK+="gpspps0"
KERNEL=="ttyS0", RUN+="/bin/setserial -v /dev/%k low_latency irq 4"

so that the driver can find the necessary device files when ldattach opens the /dev/ttyS0 file.

Notes

For further information on this reference clock, please view the NTPD documentation. See above for a link.