Commit d68c31e7 authored by Alessandro Rubini's avatar Alessandro Rubini

Merge branch 'servo-fixes'

parents 89107dda 6dcafdcf
......@@ -231,7 +231,7 @@ typedef struct DSCurrent { /* page 67 */
/* Dynamic */
UInteger16 stepsRemoved;
TimeInternal offsetFromMaster;
TimeInternal meanPathDelay;
TimeInternal oneWayDelay;
/* White Rabbit extension begin */
UInteger16 primarySlavePortNumber;
/* White Rabbit extension end */
......
......@@ -26,7 +26,6 @@ struct pp_runtime_opts {
/* ethernet_mode:1, -- moved to ppsi, is no more global */
/* e2e_mode:1, -- no more: we only support e2e */
/* gptp_mode:1, -- no more: peer-to-peer unsupported */
ofst_first_updated:1,
no_rst_clk:1;
Integer16 ap, ai;
Integer16 s;
......@@ -72,39 +71,23 @@ struct pp_frgn_master {
* are used in servo.c src, where specific function for time setting of the
* machine are implemented.
*
* pp_ofm_fltr: The FIR filtering of the offset from master input is a simple,
* two-sample average
*
* pp_owd_fltr: It is a variable cutoff/delay low-pass, infinite impulse
* pp_avg_fltr: It is a variable cutoff/delay low-pass, infinite impulse
* response (IIR) filter. The one-way delay filter has the difference equation:
* s*y[n] - (s-1)*y[n-1] = x[n]/2 + x[n-1]/2,
* where increasing the stiffness (s) lowers the cutoff and increases the delay.
*/
struct pp_ofm_fltr {
Integer32 nsec_prev;
Integer32 y;
};
struct pp_owd_fltr {
Integer32 nsec_prev;
struct pp_avg_fltr {
Integer32 m; /* magnitude */
Integer32 y;
Integer32 s_exp;
};
struct pp_servo {
/* TODO check. Which is the difference between m_to_s_dly (which
* comes from ptpd's master_to_slave_delay) and delay_ms (which comes
* from ptpd's delay_MS? Seems like ptpd actually uses only delay_MS.
* The same of course must be checked for their equivalents,
* s_to_m_dly and delay_sm
*/
TimeInternal m_to_s_dly;
TimeInternal s_to_m_dly;
TimeInternal delay_ms;
TimeInternal delay_sm;
Integer32 obs_drift;
struct pp_owd_fltr owd_fltr;
struct pp_ofm_fltr ofm_fltr;
struct pp_avg_fltr owd_fltr;
struct pp_avg_fltr ofm_fltr;
};
/*
......
......@@ -117,7 +117,7 @@ struct pp_ext_hooks {
int (*master_msg)(struct pp_instance *ppi, unsigned char *pkt,
int plen, int msgtype);
int (*new_slave)(struct pp_instance *ppi, unsigned char *pkt, int plen);
int (*update_delay)(struct pp_instance *ppi);
int (*handle_resp)(struct pp_instance *ppi);
void (*s1)(struct pp_instance *ppi, MsgHeader *hdr, MsgAnnounce *ann);
int (*execute_slave)(struct pp_instance *ppi);
void (*handle_announce)(struct pp_instance *ppi);
......@@ -164,6 +164,7 @@ struct pp_time_operations {
int (*adjust)(struct pp_instance *ppi, long offset_ns, long freq_ppm);
int (*adjust_offset)(struct pp_instance *ppi, long offset_ns);
int (*adjust_freq)(struct pp_instance *ppi, long freq_ppm);
int (*init_servo)(struct pp_instance *ppi);
/* calc_timeout cannot return zero */
unsigned long (*calc_timeout)(struct pp_instance *ppi, int millisec);
};
......@@ -257,12 +258,9 @@ extern int pp_parse_cmdline(struct pp_globals *ppg, int argc, char **argv);
extern int pp_parse_conf(struct pp_globals *ppg, char *conf, int len);
/* Servo */
extern void pp_init_clock(struct pp_instance *ppi);
extern void pp_update_delay(struct pp_instance *ppi,
TimeInternal *correction_field);
extern void pp_update_offset(struct pp_instance *ppi,
TimeInternal *correctionField);
extern void pp_update_clock(struct pp_instance *ppi);
extern void pp_servo_init(struct pp_instance *ppi);
extern void pp_servo_got_sync(struct pp_instance *ppi); /* got t1 and t2 */
extern void pp_servo_got_resp(struct pp_instance *ppi); /* got all t1..t4 */
/* bmc.c */
......
......@@ -104,7 +104,7 @@ int pp_parse_cmdline(struct pp_globals *ppg, int argc, char **argv)
cmd_line_print_help();
return -1;
}
if (1) { /* ARub: I don't want to reintent it all now */
if (1) { /* ARub: I don't want to reindent it all */
switch (a[1]) {
case 'V':
pp_diag_verbosity++;
......@@ -120,7 +120,7 @@ int pp_parse_cmdline(struct pp_globals *ppg, int argc, char **argv)
case 'O':
a = argv[++i];
GOPTS(ppg)->max_rst = atoi(a);
if (GOPTS(ppg)->max_rst < PP_NSEC_PER_SEC) {
if (GOPTS(ppg)->max_rst > PP_NSEC_PER_SEC) {
pp_printf("Use -x to prevent jumps of"
" more than one second\n");
return -1;
......@@ -129,7 +129,7 @@ int pp_parse_cmdline(struct pp_globals *ppg, int argc, char **argv)
case 'M':
a = argv[++i];
GOPTS(ppg)->max_dly = atoi(a);
if (GOPTS(ppg)->max_dly < PP_NSEC_PER_SEC) {
if (GOPTS(ppg)->max_dly > PP_NSEC_PER_SEC) {
pp_printf("Use -x to prevent jumps of"
" more than one second\n");
return -1;
......
......@@ -105,7 +105,7 @@ static int wr_new_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
return 0;
}
static int wr_update_delay(struct pp_instance *ppi)
static int wr_handle_resp(struct pp_instance *ppi)
{
MsgHeader *hdr = &ppi->received_ptp_header;
TimeInternal correction_field;
......@@ -115,7 +115,7 @@ static int wr_update_delay(struct pp_instance *ppi)
/* If no WR mode is on, run normal code */
if (!WR_DSPOR(ppi)->wrModeOn) {
pp_update_delay(ppi, &correction_field);
pp_servo_got_resp(ppi);
return 0;
}
wr_servo_got_delay(ppi, hdr->correctionfield.lsb);
......@@ -197,7 +197,7 @@ struct pp_ext_hooks pp_hooks = {
.listening = wr_listening,
.master_msg = wr_master_msg,
.new_slave = wr_new_slave,
.update_delay = wr_update_delay,
.handle_resp = wr_handle_resp,
.s1 = wr_s1,
.execute_slave = wr_execute_slave,
.handle_announce = wr_handle_announce,
......
......@@ -25,7 +25,7 @@ void m1(struct pp_instance *ppi)
/* Current data set update */
DSCUR(ppi)->stepsRemoved = 0;
clear_TimeInternal(&DSCUR(ppi)->offsetFromMaster);
clear_TimeInternal(&DSCUR(ppi)->meanPathDelay);
clear_TimeInternal(&DSCUR(ppi)->oneWayDelay);
/* Parent data set: we are the parent */
memset(parent, 0, sizeof(*parent));
......
......@@ -151,8 +151,7 @@ int st_com_slave_handle_sync(struct pp_instance *ppi, unsigned char *buf,
ppi->waiting_for_follow = FALSE;
to_TimeInternal(&ppi->t1,
&sync.originTimestamp);
pp_update_offset(ppi, &ppi->cField);
pp_update_clock(ppi);
pp_servo_got_sync(ppi);
return 0;
}
......@@ -198,8 +197,7 @@ int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
if (ret < 0)
return ret;
pp_update_offset(ppi, &ppi->cField);
pp_update_clock(ppi);
pp_servo_got_sync(ppi);
return 0;
}
......
......@@ -28,7 +28,6 @@ struct pp_runtime_opts default_rt_opts = {
.ap = PP_DEFAULT_AP,
.ai = PP_DEFAULT_AI,
.s = PP_DEFAULT_DELAY_S,
.ofst_first_updated = 0, /* FIXME: is it a option or a state var? */
.announce_intvl = PP_DEFAULT_ANNOUNCE_INTERVAL,
.sync_intvl = PP_DEFAULT_SYNC_INTERVAL,
.prio1 = PP_DEFAULT_PRIORITY1,
......
This diff is collapsed.
......@@ -57,7 +57,6 @@ int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen)
pp_diag(ppi, time, 1, "%s: can't init timers\n", __func__);
goto failure;
}
pp_init_clock(ppi);
pp_diag(ppi, bmc, 1, "clock class = %d\n",
DSDEF(ppi)->clockQuality.clockClass);
......
......@@ -17,7 +17,7 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
int d1, d2;
if (ppi->is_new_state) {
pp_init_clock(ppi);
pp_servo_init(ppi);
if (pp_hooks.new_slave)
e = pp_hooks.new_slave(ppi, pkt, plen);
......@@ -79,10 +79,10 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
* generating t4, and report back a modified t4
*/
if (pp_hooks.update_delay)
e = pp_hooks.update_delay(ppi);
if (pp_hooks.handle_resp)
e = pp_hooks.handle_resp(ppi);
else
pp_update_delay(ppi, &ppi->cField);
pp_servo_got_resp(ppi);
if (e)
goto out;
......@@ -138,7 +138,7 @@ out:
pp_timeout_clr(ppi, PP_TO_ANN_RECEIPT);
pp_timeout_clr(ppi, PP_TO_DELAYREQ);
pp_init_clock(ppi);
pp_servo_init(ppi);
}
d1 = d2 = pp_ms_to_timeout(ppi, PP_TO_ANN_RECEIPT);
if (ppi->timeouts[PP_TO_DELAYREQ])
......
......@@ -45,6 +45,18 @@ static int32_t unix_time_set(struct pp_instance *ppi, TimeInternal *t)
return 0;
}
static int unix_time_init_servo(struct pp_instance *ppi)
{
struct timex t;
/* We must set MOD_PLL and recover the current frequency value */
t.modes = MOD_STATUS;
t.status = STA_PLL;
if (adjtimex(&t) < 0)
return -1;
return (t.freq >> 16) * 1000; /* positive or negative, not -1 */
}
static int unix_time_adjust(struct pp_instance *ppi, long offset_ns, long freq_ppm)
{
struct timex t;
......@@ -103,5 +115,6 @@ struct pp_time_operations unix_time_ops = {
.adjust = unix_time_adjust,
.adjust_offset = unix_time_adjust_offset,
.adjust_freq = unix_time_adjust_freq,
.init_servo = unix_time_init_servo,
.calc_timeout = unix_calc_timeout,
};
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