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)) {