Please ignore/delete my previous email with identical subject, line wrapping ruined the formatting.
Purpose of this patch: * A new pps-source named 'extpps' is added with similar function as the 'generic' interface. Whereas the 'generic' interface is dependent on that no other process (like, e.g. an NTP server) fiddles with the system clock too much and that the system clock and the PHC stays in a fixed phase relationship, the extpps pulse restricts its action strictly to the documented program purpose "Synchronizes one or more PTP Hardware Clocks using external time stamps" irrespective of what the system clock does (i.e. it will still keep working even with jumps, leapsmear, and drifts between CLOCK_REALTIME and the source PHC). Signed-off-by: Jürgen Appel <j...@dfm.dk> --- makefile | 5 ++-- ts2phc.c | 16 ++++++++++-- ts2phc_extpps_pps_source.c | 51 ++++++++++++++++++++++++++++++++++++++ ts2phc_extpps_pps_source.h | 15 +++++++++++ ts2phc_pps_source.c | 4 +++ ts2phc_pps_source.h | 1 + 6 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 ts2phc_extpps_pps_source.c create mode 100644 ts2phc_extpps_pps_source.h diff --git a/makefile b/makefile index 3e3b8b3..5192a0f 100644 --- a/makefile +++ b/makefile @@ -26,8 +26,9 @@ PRG = ptp4l hwstamp_ctl nsm phc2sys phc_ctl pmc timemaster ts2phc tz2alt FILTERS = filter.o mave.o mmedian.o SERVOS = linreg.o ntpshm.o nullf.o pi.o refclock_sock.o servo.o TRANSP = raw.o transport.o udp.o udp6.o uds.o -TS2PHC = ts2phc.o lstab.o nmea.o serial.o sock.o ts2phc_generic_pps_source.o \ - ts2phc_nmea_pps_source.o ts2phc_phc_pps_source.o ts2phc_pps_sink.o ts2phc_pps_source.o +TS2PHC = ts2phc.o lstab.o nmea.o serial.o sock.o ts2phc_extpps_pps_source.o \ + ts2phc_generic_pps_source.o ts2phc_nmea_pps_source.o ts2phc_phc_pps_source.o \ + ts2phc_pps_sink.o ts2phc_pps_source.o OBJ = bmc.o clock.o clockadj.o clockcheck.o config.o designated_fsm.o \ e2e_tc.o fault.o $(FILTERS) fsm.o hash.o interface.o monitor.o msg.o phc.o \ port.o port_signaling.o pqueue.o print.o ptp4l.o p2p_tc.o rtnl.o $(SERVOS) \ diff --git a/ts2phc.c b/ts2phc.c index 4393059..6a8cad9 100644 --- a/ts2phc.c +++ b/ts2phc.c @@ -467,7 +467,14 @@ static void ts2phc_synchronize_clocks(struct ts2phc_private *priv, int autocfg) continue; } - offset = tmv_to_nanoseconds(tmv_sub(ts, source_tmv)); + if (source_tmv.ns) + offset = tmv_to_nanoseconds(tmv_sub(ts, source_tmv)); + else { + /* no source timestamp => lock ts.ns to nearest whole second */ + offset = tmv_to_nanoseconds(ts) % NS_PER_SEC; + if (offset > NS_PER_SEC/2) + offset -= NS_PER_SEC; + }; if (c->no_adj) { pr_info("%s offset %10" PRId64, c->name, @@ -547,7 +554,10 @@ static void usage(char *progname) " -q do not print messages to the syslog\n" " -s [dev|name] source of the PPS signal\n" " may take any of the following forms:\n" - " generic - an external 1-PPS without ToD information\n" + " generic - an external 1-PPS without ToD information,\n" + " ToD information taken from CLOCK_REALTIME\n" + " extpps - an external 1-PPS without ToD information,\n" + " lock PHCs towards nearest whole second." " /dev/ptp0 - a local PTP Hardware Clock (PHC)\n" " eth0 - a local PTP Hardware Clock (PHC)\n" " nmea - a gps device connected by serial port or network\n" @@ -731,6 +741,8 @@ int main(int argc, char *argv[]) if (!strcasecmp(tod_source, "generic")) { pps_type = TS2PHC_PPS_SOURCE_GENERIC; + } else if (!strcasecmp(tod_source, "extpps")) { + pps_type = TS2PHC_PPS_SOURCE_EXTPPS; } else if (!strcasecmp(tod_source, "nmea")) { pps_type = TS2PHC_PPS_SOURCE_NMEA; } else { diff --git a/ts2phc_extpps_pps_source.c b/ts2phc_extpps_pps_source.c new file mode 100644 index 0000000..4e1f26d --- /dev/null +++ b/ts2phc_extpps_pps_source.c @@ -0,0 +1,51 @@ +/** + * @file ts2phc_extpps_pps_source.c + * @note Copyright (C) 2019 Richard Cochran <richardcoch...@gmail.com> + * @note SPDX-License-Identifier: GPL-2.0+ + */ +#include <stdlib.h> +#include <time.h> + +#include "ts2phc_extpps_pps_source.h" +#include "ts2phc_pps_source_private.h" + +struct ts2phc_extpps_pps_source { + struct ts2phc_pps_source pps_source; +}; + +static void ts2phc_extpps_pps_source_destroy(struct ts2phc_pps_source *src) +{ + struct ts2phc_extpps_pps_source *s = + container_of(src, struct ts2phc_extpps_pps_source, pps_source); + + free(s); +} + +static int ts2phc_extpps_pps_source_getppstime(struct ts2phc_pps_source *src, + struct timespec *ts) +{ + ts->tv_sec = 0; + ts->tv_nsec = 0; + return 0; +} + +struct ts2phc_clock *ts2phc_extpps_pps_source_get_clock(struct ts2phc_pps_source *src) +{ + return NULL; +} + + +struct ts2phc_pps_source *ts2phc_extpps_pps_source_create(struct ts2phc_private *priv, + const char *dev) +{ + struct ts2phc_extpps_pps_source *s; + + s = calloc(1, sizeof(*s)); + if (!s) { + return NULL; + } + s->pps_source.destroy = ts2phc_extpps_pps_source_destroy; + s->pps_source.getppstime = ts2phc_extpps_pps_source_getppstime; + + return &s->pps_source; +} diff --git a/ts2phc_extpps_pps_source.h b/ts2phc_extpps_pps_source.h new file mode 100644 index 0000000..1a57cd6 --- /dev/null +++ b/ts2phc_extpps_pps_source.h @@ -0,0 +1,15 @@ +/** + * @file ts2phc_extpps_pps_source.h + * @note Copyright (C) 2019 Richard Cochran <richardcoch...@gmail.com> + * @note SPDX-License-Identifier: GPL-2.0+ + */ +#ifndef HAVE_TS2PHC_EXTPPS_PPS_SOURCE_H +#define HAVE_TS2PHC_EXTPPS_PPS_SOURCE_H + +#include "ts2phc.h" +#include "ts2phc_pps_source.h" + +struct ts2phc_pps_source *ts2phc_extpps_pps_source_create(struct ts2phc_private *priv, + const char *dev); + +#endif diff --git a/ts2phc_pps_source.c b/ts2phc_pps_source.c index c333f65..be98567 100644 --- a/ts2phc_pps_source.c +++ b/ts2phc_pps_source.c @@ -5,6 +5,7 @@ */ #include "ts2phc.h" #include "ts2phc_generic_pps_source.h" +#include "ts2phc_extpps_pps_source.h" #include "ts2phc_nmea_pps_source.h" #include "ts2phc_phc_pps_source.h" #include "ts2phc_pps_source_private.h" @@ -19,6 +20,9 @@ struct ts2phc_pps_source *ts2phc_pps_source_create(struct ts2phc_private *priv, case TS2PHC_PPS_SOURCE_GENERIC: src = ts2phc_generic_pps_source_create(priv, dev); break; + case TS2PHC_PPS_SOURCE_EXTPPS: + src = ts2phc_extpps_pps_source_create(priv, dev); + break; case TS2PHC_PPS_SOURCE_NMEA: src = ts2phc_nmea_pps_source_create(priv, dev); break; diff --git a/ts2phc_pps_source.h b/ts2phc_pps_source.h index 293c693..519fc02 100644 --- a/ts2phc_pps_source.h +++ b/ts2phc_pps_source.h @@ -21,6 +21,7 @@ struct ts2phc_pps_source; */ enum ts2phc_pps_source_type { TS2PHC_PPS_SOURCE_GENERIC, + TS2PHC_PPS_SOURCE_EXTPPS, TS2PHC_PPS_SOURCE_NMEA, TS2PHC_PPS_SOURCE_PHC, }; -- 2.34.1 _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel