Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get NTP working with custom I/O Pin?

Tags:

ntp

I have a motherboard with I/O pins and I have written a C library with functions to set and query the status of these I/O pins. Lets say the name of one of these functions is get_pin(int pin_no), and it returns the logical voltage of that pin. I would like to send a 1 pulse-per-second (PPS) signal to one of my pins and tell Linux's NTPD to calibrate based off this signal.

Is it possible to tell the NTPD to use one of these I/O pins as its PPS? If so, what is the approach to do this? Ie. Is it via config file or does it require modifying NTPD's source code? My early research seems to suggest the latter may be necessary.

Edit: I'm working with the ntpd on Centos

like image 277
DeepDeadpool Avatar asked Feb 13 '17 23:02

DeepDeadpool


1 Answers

Does your kernel have PPS support?

$ grep PPS /boot/config-$(uname -r)
# PPS support
CONFIG_PPS=m
# CONFIG_PPS_DEBUG is not set
# PPS clients support
# CONFIG_PPS_CLIENT_KTIMER is not set
CONFIG_PPS_CLIENT_LDISC=m
CONFIG_PPS_CLIENT_PARPORT=m
CONFIG_PPS_CLIENT_GPIO=m
# PPS generators support

Is ldattach installed?

$ which ldattach
/usr/sbin/ldattach

You may not need ldattach. It was mentioned in the LinuxPPS installation instructions. However, it appears that it is only used for PPS sent over a serial line (e.g. RS-232).

Are the pps-tools installed?

$ which ppstest
/usr/bin/ppstest

Is the pps-gpio.ko module installed?

$ modinfo pps-gpio
filename:       /lib/modules/4.4.0-38-generic/kernel/drivers/pps/clients/pps-gpio.ko
version:        1.0.0
license:        GPL
description:    Use GPIO pin as PPS source
author:         James Nuss <[email protected]>
author:         Ricardo Martins <[email protected]>
srcversion:     D2C22B0A465DA63746EFB59
alias:          of:N*T*Cpps-gpio*
depends:        pps_core
intree:         Y
vermagic:       4.4.0-38-generic SMP mod_unload modversions 

You can tell the kernel that a GPIO pin will be used as a PPS signal by adding something like this to your kernel line in your GRUB config:

dtoverlay=pps-gpio,gpiopin=18

You will need to change "18" to the GPIO pin you are using.

You will need to add a couple of lines like this to your ntp.conf:

server 127.127.22.1            # ATOM(PPS)
fudge 127.127.22.1 flag3 1     # enable PPS API

References:

http://www.ntp.org/ntpfaq/NTP-s-config-adv.htm

http://linuxpps.org/wiki/index.php/Main_Page

http://rdlazaro.info/compu-Raspberry_Pi-RPi-stratum0.html

http://doc.ntp.org/4.1.1/refclock.htm

http://doc.ntp.org/4.1.1/driver22.htm

like image 130
David Cullen Avatar answered Oct 02 '22 13:10

David Cullen