Richard Cochran
2013-05-17 05:39:49 UTC
As it now stands, the frequency offset from the master clock is guessed
by using one sync interval. When the interval is shorter than one second,
this does not work any more when using hardware time stamping, and
software time stamping requires an even longer interval. This patch
fixes the issue by always using an interval at least one second long
(and 16 seconds in the case of SW time stamping).
Signed-off-by: Richard Cochran <***@gmail.com>
---
pi.c | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/pi.c b/pi.c
index 427cb3e..4671b11 100644
--- a/pi.c
+++ b/pi.c
@@ -47,6 +47,7 @@ struct pi_servo {
double ki;
double max_offset;
int count;
+ int hwts;
};
static void pi_destroy(struct servo *servo)
@@ -60,7 +61,7 @@ static double pi_sample(struct servo *servo,
uint64_t local_ts,
enum servo_state *state)
{
- double ki_term, ppb = 0.0;
+ double fest_interval, ki_term, ppb = 0.0;
struct pi_servo *s = container_of(servo, struct pi_servo, servo);
switch (s->count) {
@@ -79,6 +80,11 @@ static double pi_sample(struct servo *servo,
s->count = 0;
break;
}
+ /* Wait long enough before estimating the frequency offset. */
+ fest_interval = s->hwts ? 1.0 : 16.0;
+ if ((s->local[1] - s->local[0]) / 1e9 - fest_interval > 0.001) {
+ break;
+ }
s->drift += (s->offset[1] - s->offset[0]) * 1e9 /
(s->local[1] - s->local[0]);
@@ -133,6 +139,7 @@ struct servo *pi_servo_create(int fadj, int max_ppb, int sw_ts)
s->servo.sample = pi_sample;
s->drift = fadj;
s->maxppb = max_ppb;
+ s->hwts = sw_ts ? 0 : 1;
if (configured_pi_kp && configured_pi_ki) {
s->kp = configured_pi_kp;
by using one sync interval. When the interval is shorter than one second,
this does not work any more when using hardware time stamping, and
software time stamping requires an even longer interval. This patch
fixes the issue by always using an interval at least one second long
(and 16 seconds in the case of SW time stamping).
Signed-off-by: Richard Cochran <***@gmail.com>
---
pi.c | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/pi.c b/pi.c
index 427cb3e..4671b11 100644
--- a/pi.c
+++ b/pi.c
@@ -47,6 +47,7 @@ struct pi_servo {
double ki;
double max_offset;
int count;
+ int hwts;
};
static void pi_destroy(struct servo *servo)
@@ -60,7 +61,7 @@ static double pi_sample(struct servo *servo,
uint64_t local_ts,
enum servo_state *state)
{
- double ki_term, ppb = 0.0;
+ double fest_interval, ki_term, ppb = 0.0;
struct pi_servo *s = container_of(servo, struct pi_servo, servo);
switch (s->count) {
@@ -79,6 +80,11 @@ static double pi_sample(struct servo *servo,
s->count = 0;
break;
}
+ /* Wait long enough before estimating the frequency offset. */
+ fest_interval = s->hwts ? 1.0 : 16.0;
+ if ((s->local[1] - s->local[0]) / 1e9 - fest_interval > 0.001) {
+ break;
+ }
s->drift += (s->offset[1] - s->offset[0]) * 1e9 /
(s->local[1] - s->local[0]);
@@ -133,6 +139,7 @@ struct servo *pi_servo_create(int fadj, int max_ppb, int sw_ts)
s->servo.sample = pi_sample;
s->drift = fadj;
s->maxppb = max_ppb;
+ s->hwts = sw_ts ? 0 : 1;
if (configured_pi_kp && configured_pi_ki) {
s->kp = configured_pi_kp;
--
1.7.2.5
1.7.2.5