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 <richardcochran@gmail.com>
master
Richard Cochran 2020-07-22 14:56:36 -07:00
parent 70c32043a5
commit 1335db3bde
1 changed files with 10 additions and 3 deletions

View File

@ -7,6 +7,7 @@
#include <errno.h> #include <errno.h>
#include <linux/ptp_clock.h> #include <linux/ptp_clock.h>
#include <poll.h> #include <poll.h>
#include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
@ -50,7 +51,7 @@ struct ts2phc_slave_array {
struct ts2phc_source_timestamp { struct ts2phc_source_timestamp {
struct timespec ts; struct timespec ts;
int valid; bool valid;
}; };
enum extts_result { enum extts_result {
@ -269,6 +270,11 @@ static int ts2phc_slave_event(struct ts2phc_slave *slave,
return 0; 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, adj = servo_sample(slave->servo, offset, extts_ts,
SAMPLE_WEIGHT, &slave->state); SAMPLE_WEIGHT, &slave->state);
@ -398,7 +404,7 @@ int ts2phc_slave_poll(struct ts2phc_master *master)
{ {
struct ts2phc_source_timestamp source_ts; struct ts2phc_source_timestamp source_ts;
unsigned int i; unsigned int i;
int cnt; int cnt, err;
if (ts2phc_slave_array_create()) { if (ts2phc_slave_array_create()) {
return -1; return -1;
@ -416,7 +422,8 @@ int ts2phc_slave_poll(struct ts2phc_master *master)
return 0; 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++) { for (i = 0; i < ts2phc_n_slaves; i++) {
if (polling_array.pfd[i].revents & (POLLIN|POLLPRI)) { if (polling_array.pfd[i].revents & (POLLIN|POLLPRI)) {