9

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

DeepDeadpool
  • 1,441
  • 12
  • 36

3 Answers3

3

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 <jamesnuss@nanometrics.ca>
author:         Ricardo Martins <rasm@fe.up.pt>
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

  • From your answer I'm inferring that my code is unnecessary and that this is handled entirely through the OS and conf files. What's ldattach used for? – DeepDeadpool Mar 02 '17 at 18:15
  • I updated my answer with a note that `ldattach` might not be necessary. –  Mar 02 '17 at 18:21
0

One pulse per second calibration signal will also require reading input pin exactly at 1 second for calibration. Polling will not serve as timer execution may be differed by OS on high priority work.

Same way using interrupt on change* for this pin hooked with calibrate function will also not grantee 1 PPS execution of calibration method due to interrupt processing delays like say when a higher priority interrupt occurs.

SACn
  • 1,862
  • 1
  • 14
  • 29
  • This isn't really the answer I'm looking for. I need an answer that tells me how to tell NTP to use a particular pin as its pps while using my functions. My question boiled down is "I have a function to read the logical voltage of this pin, what is the approach to tell the ntpd to use this pin as its pps?". – DeepDeadpool Mar 02 '17 at 16:37
0

If I understood question correctly, you are using something like Raspberry and wish to syncronize your system by another controller by receiving some sequence of logical 1s that will mean, for instance, time teac for your board?
The only one thing I do not understand is why do you need ntp daemon for that. Isn't it better to create a static time_t variable that will increment upon each teac receipt?
If you wish to syncronize some external devices later and the board acts as a time server - just adjust system date each time when the difference between your static variable and time(0) value will be greater than defined value.

ETech
  • 1,613
  • 16
  • 17