Commit 4dbc6b0b authored by Alessandro Rubini's avatar Alessandro Rubini

time-wrs: fix for a mishap when WR time starts at 0.

System time is used for log messages and nothing critical, so we'd
better have it different from WR time, when WR time is clearly wrong.
This commit avoids setting Unix time from WR time when WR time is
clearly wrong (i.e. earlier than today).

This, among other things, fixes a "fatal error" startup failure when
two free-running WRS devices are turned one at the same time
(noted by Adam Wujek).

This is because the master was counting from zero and the slave,
was setting system time accordingly; but the slave's boot procedure
already used wr_date to set the utc/tai offset, and system time
as a result  was being set to a negative value -- tai's being small,
"tai - 35" was negative.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 12bd4376
......@@ -198,6 +198,13 @@ static int wrs_time_set(struct pp_instance *ppi, TimeInternal *t)
if (!t) /* ... when the utc/tai offset changes, if t is NULL */
return unix_time_ops.set(ppi, t);
/*
* We say "weird" because we are not expected to set time here;
* rather, time setting goes usually from the WR servo, straight
* to the HAL process, where a difference is injected into the fpga;
* rather then "setting" an absolute time, which we can't do
* and thus T3 is referenced below, to get some approximate value...
*/
pp_diag(ppi, time, 1, "%s: (weird) %9li.%09li\n", __func__,
(long)t->seconds, (long)t->nanoseconds);
/* We have no way to get the WR time, currently. So use our T3 */
......@@ -220,6 +227,11 @@ static int wrs_time_set(struct pp_instance *ppi, TimeInternal *t)
}
wrs_adjust_counters(diff.seconds, diff.nanoseconds);
/* If WR time is unrelated to real-world time, we are done. */
if (t->seconds < 1420730822 /* "now" as I write this */)
return 0;
/*
* Finally, set unix time too, but count the UTC/TAI difference
* assuming somebody has set up up for us
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment