Let the clock servo know about the expected time stamp quality.

If software time stamping is to be used, then the servo will want to
have appropriate filtering.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2011-12-13 04:57:28 +01:00
parent 01691df47b
commit 87e61f9770
5 changed files with 33 additions and 11 deletions

11
clock.c
View File

@ -158,7 +158,7 @@ UInteger8 clock_class(struct clock *c)
struct clock *clock_create(char *phc, struct interface *iface, int count,
struct defaultDS *ds)
{
int i, max_adj;
int i, max_adj, sw_ts = 0;
struct clock *c = &the_clock;
srandom(time(NULL));
@ -182,7 +182,14 @@ struct clock *clock_create(char *phc, struct interface *iface, int count,
max_adj = 512000;
}
c->servo = servo_create("pi", max_adj);
for (i = 0; i < count; i++) {
if (iface[i].timestamping == TS_SOFTWARE) {
sw_ts = 1;
break;
}
}
c->servo = servo_create("pi", max_adj, sw_ts);
if (!c->servo) {
pr_err("Failed to create clock servo");
return NULL;

23
pi.c
View File

@ -22,8 +22,11 @@
#include "pi.h"
#include "servo_private.h"
#define KP 0.7
#define KI 0.3
#define HWTS_KP 0.7
#define HWTS_KI 0.3
#define SWTS_KP 0.1
#define SWTS_KI 0.001
struct pi_servo {
struct servo servo;
@ -31,6 +34,8 @@ struct pi_servo {
double local[2];
double drift;
double maxppb;
double kp;
double ki;
int count;
};
@ -72,8 +77,8 @@ static double pi_sample(struct servo *servo,
s->count = 4;
break;
case 4:
ki_term = KI * offset;
ppb = KP * offset + s->drift + ki_term;
ki_term = s->ki * offset;
ppb = s->kp * offset + s->drift + ki_term;
if (ppb < -s->maxppb) {
ppb = -s->maxppb;
} else if (ppb > s->maxppb) {
@ -88,7 +93,7 @@ static double pi_sample(struct servo *servo,
return ppb;
}
struct servo *pi_servo_create(int max_ppb)
struct servo *pi_servo_create(int max_ppb, int sw_ts)
{
struct pi_servo *s;
@ -100,5 +105,13 @@ struct servo *pi_servo_create(int max_ppb)
s->servo.sample = pi_sample;
s->maxppb = max_ppb;
if (sw_ts) {
s->kp = SWTS_KP;
s->ki = SWTS_KI;
} else {
s->kp = HWTS_KP;
s->ki = HWTS_KI;
}
return &s->servo;
}

2
pi.h
View File

@ -21,6 +21,6 @@
#include "servo.h"
struct servo *pi_servo_create(int max_ppb);
struct servo *pi_servo_create(int max_ppb, int sw_ts);
#endif

View File

@ -21,10 +21,10 @@
#include "pi.h"
#include "servo_private.h"
struct servo *servo_create(char *name, int max_ppb)
struct servo *servo_create(char *name, int max_ppb, int sw_ts)
{
if (!strncmp(name, "pi", 2)) {
return pi_servo_create(max_ppb);
return pi_servo_create(max_ppb, sw_ts);
}
return NULL;
}

View File

@ -51,9 +51,11 @@ enum servo_state {
* @param max_ppb The absolute maxinum adjustment allowed by the clock
* in parts per billion. The clock servo will clamp its
* output according to this limit.
* @param sw_ts Indicates that software time stamping will be used,
* and the servo should use more aggressive filtering.
* @return A pointer to a new servo on success, NULL otherwise.
*/
struct servo *servo_create(char *name, int max_ppb);
struct servo *servo_create(char *name, int max_ppb, int sw_ts);
/**
* Destroy an instance of a clock servo.