Commit 55ef8b55 authored by Alessandro Rubini's avatar Alessandro Rubini

fix: the heuristics for wrs no-wr slave were not ok

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 289371e7
...@@ -217,9 +217,10 @@ static int wrs_time_get(struct pp_instance *ppi, TimeInternal *t) ...@@ -217,9 +217,10 @@ static int wrs_time_get(struct pp_instance *ppi, TimeInternal *t)
static int wrs_time_set(struct pp_instance *ppi, TimeInternal *t) static int wrs_time_set(struct pp_instance *ppi, TimeInternal *t)
{ {
TimeInternal diff; TimeInternal diff, now;
struct timex tx; struct timex tx;
int tai_offset = 0; int tai_offset = 0;
int msec;
/* /*
* This is almost unused in ppsi, only proto-standard/servo.c * This is almost unused in ppsi, only proto-standard/servo.c
...@@ -232,29 +233,40 @@ static int wrs_time_set(struct pp_instance *ppi, TimeInternal *t) ...@@ -232,29 +233,40 @@ static int wrs_time_set(struct pp_instance *ppi, TimeInternal *t)
/* /*
* We say "weird" because we are not expected to set time here; * We say "weird" because we are not expected to set time here;
* rather, time setting goes usually from the WR servo, straight * rather, time setting goes usually from the WR servo, straight
* to the HAL process, where a difference is injected into the fpga; * to the HAL process, where a difference is injected into the fpga.
* rather then "setting" an absolute time, which we can't do * We are only asked to set a time when slave of non-wr (and
* and thus T3 is referenced below, to get some approximate value... * normal servo drives us). So get time to calc a rough difference.
*/ */
pp_diag(ppi, time, 1, "%s: (weird) %9li.%09li\n", __func__, wrdate_get(&now);
(long)t->seconds, (long)t->nanoseconds); sub_TimeInternal(&diff, t, &now);
/* We have no way to get the WR time, currently. So use our T3 */ pp_diag(ppi, time, 1, "%s: (weird) %9li.%09li - delta %9li.%09li\n",
sub_TimeInternal(&diff, t, &ppi->t3); __func__,
(long)t->seconds, (long)t->nanoseconds,
(long)diff.seconds, (long)diff.nanoseconds);
/* /*
* We can adjust nanoseconds or seconds, but not both at the * We can adjust nanoseconds or seconds, but not both at the
* same time. When an adjustment is in progress we can't do * same time. When an adjustment is in progress we can't do
* the other. So make nanoseconds first if > 10ms, and the * the other. So make nanoseconds first if > 20ms, and the
* servo will call us again later for the seconds part. * servo will call us again later for the seconds part.
* Thus, we fall near, and can then trim frequency (hopefully).
*/ */
if (abs(diff.nanoseconds) > 10 * 1000 * 1000) { msec = diff.nanoseconds / 1000 / 1000;;
#define THRESHOLD_MS 20
if ((msec > THRESHOLD_MS && msec < (1000 - THRESHOLD_MS))
|| (msec < -THRESHOLD_MS && msec > (-1000 + THRESHOLD_MS))) {
pp_diag(ppi, time, 1, "%s: adjusting nanoseconds: %li\n", pp_diag(ppi, time, 1, "%s: adjusting nanoseconds: %li\n",
__func__, (long)diff.nanoseconds); __func__, (long)diff.nanoseconds);
diff.seconds = 0; diff.seconds = 0;
} else { } else {
diff.nanoseconds = 0;
if (msec > 500)
diff.seconds++;
if (msec < -500)
diff.seconds--;
pp_diag(ppi, time, 1, "%s: adjusting seconds: %li\n", pp_diag(ppi, time, 1, "%s: adjusting seconds: %li\n",
__func__, (long)diff.seconds); __func__, (long)diff.seconds);
diff.nanoseconds = 0;
} }
wrs_adjust_counters(diff.seconds, diff.nanoseconds); wrs_adjust_counters(diff.seconds, diff.nanoseconds);
......
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