From 1335db3bded3d424df9ec49919ed355802f6757b Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Wed, 22 Jul 2020 14:56:36 -0700 Subject: [PATCH] ts2phc: Ignore pulses with invalid time stamps. The API to obtain the time stamp of a PPS source indicates the validity of the returned value. However, the current code does not ever test the validity information in any way. This patch lets the clients ignore PPS values that lack a valid time stamp. Signed-off-by: Richard Cochran --- ts2phc_slave.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ts2phc_slave.c b/ts2phc_slave.c index 71077a7..749efe5 100644 --- a/ts2phc_slave.c +++ b/ts2phc_slave.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -50,7 +51,7 @@ struct ts2phc_slave_array { struct ts2phc_source_timestamp { struct timespec ts; - int valid; + bool valid; }; enum extts_result { @@ -269,6 +270,11 @@ static int ts2phc_slave_event(struct ts2phc_slave *slave, return 0; } + if (!source_ts.valid) { + pr_debug("%s ignoring invalid master time stamp", slave->name); + return 0; + } + adj = servo_sample(slave->servo, offset, extts_ts, SAMPLE_WEIGHT, &slave->state); @@ -398,7 +404,7 @@ int ts2phc_slave_poll(struct ts2phc_master *master) { struct ts2phc_source_timestamp source_ts; unsigned int i; - int cnt; + int cnt, err; if (ts2phc_slave_array_create()) { return -1; @@ -416,7 +422,8 @@ int ts2phc_slave_poll(struct ts2phc_master *master) return 0; } - source_ts.valid = ts2phc_master_getppstime(master, &source_ts.ts); + err = ts2phc_master_getppstime(master, &source_ts.ts); + source_ts.valid = err ? false : true; for (i = 0; i < ts2phc_n_slaves; i++) { if (polling_array.pfd[i].revents & (POLLIN|POLLPRI)) {