Commit d16453c4 authored by Alessandro Rubini's avatar Alessandro Rubini

white-rabbit: change initial jump to correct time for non-wr slave

Commit

	06cb0670 time-wrs: implement time_set()

is changin the seconds leaving the fractional part alone. However, the
servo won't time-set again, but will rather converge, and this takes time.

We now adjust nanoseconds first, so the servo will still notice a
more-than-one-second error and will call our time-set again. Thus,
we jump to proper time in a few seconds instead of slowly converging from
far away.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent e89573a3
......@@ -197,7 +197,7 @@ static int wrs_time_get(struct pp_instance *ppi, TimeInternal *t)
static int32_t wrs_time_set(struct pp_instance *ppi, TimeInternal *t)
{
int64_t offset_sec;
TimeInternal diff;
/*
* This is almost unused in ppsi, only proto-standard/servo.c
* calls it, at initialization time, when the offset is bigger
......@@ -206,16 +206,28 @@ static int32_t wrs_time_set(struct pp_instance *ppi, TimeInternal *t)
*/
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 */
offset_sec = (long long)t->seconds - (long long)ppi->t3.seconds;
pp_diag(ppi, time, 1, "%s: adjusting seconds: %li\n", __func__,
(long)offset_sec);
wrs_adjust_counters(offset_sec, 0);
sub_TimeInternal(&diff, t, &ppi->t3);
/* Set unix time anyways */
/*
* We can adjust nanoseconds or seconds, but not both at the
* same time. When an adjustment is in progress we can't do
* the other. So make nanoseconds first if > 10ms, and the
* servo will call us again later for the seconds part.
*/
if (abs(diff.nanoseconds) > 10 * 1000 * 1000) {
pp_diag(ppi, time, 1, "%s: adjusting nanoseconds: %li\n",
__func__, (long)diff.nanoseconds);
wrs_adjust_counters(0, diff.nanoseconds);
return 0;
}
pp_diag(ppi, time, 1, "%s: adjusting seconds: %li\n",
__func__, (long)diff.seconds);
wrs_adjust_counters(diff.seconds, 0);
/* Finally, set unix time too */
unix_time_ops.set(ppi, t);
return -ENOTSUP;
return 0;
}
static int wrs_time_adjust_offset(struct pp_instance *ppi, long offset_ns)
......
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