Commit c2320d6a authored by Aurelio Colosimo's avatar Aurelio Colosimo

proto-standard/arith.c: fix a div2 division in TimeInternal

There was a bug in ptpd-2.1, fixed in ptpd-2.2. This patch solves
the bug in ppsi.
parent 85930527
......@@ -336,6 +336,7 @@ extern void add_TimeInternal(TimeInternal *r, TimeInternal *x, TimeInternal *y);
extern void sub_TimeInternal(TimeInternal *r, TimeInternal *x, TimeInternal *y);
extern void set_TimeInternal(TimeInternal *t, Integer32 s, Integer32 ns);
extern void display_TimeInternal(const char *label, TimeInternal *t);
extern void div2_TimeInternal(TimeInternal *r);
/* Get and Set system timestamp */
extern void pp_get_tstamp(TimeInternal *t);
......
......@@ -91,6 +91,15 @@ void sub_TimeInternal(TimeInternal *r, TimeInternal *x, TimeInternal *y)
normalize_TimeInternal(r);
}
void div2_TimeInternal(TimeInternal *r)
{
r->nanoseconds += r->seconds % 2 * 1000000000;
r->seconds /= 2;
r->nanoseconds /= 2;
normalize_TimeInternal(r);
}
void set_TimeInternal(TimeInternal *t, Integer32 s, Integer32 ns)
{
t->seconds = s;
......
......@@ -66,8 +66,7 @@ void pp_update_delay(struct pp_instance *ppi, TimeInternal *correction_field)
&DSCUR(ppi)->meanPathDelay, correction_field);
/* Compute one-way delay */
DSCUR(ppi)->meanPathDelay.seconds /= 2;
DSCUR(ppi)->meanPathDelay.nanoseconds /= 2;
div2_TimeInternal(&DSCUR(ppi)->meanPathDelay);
if (DSCUR(ppi)->meanPathDelay.seconds) {
......@@ -131,8 +130,7 @@ void pp_update_peer_delay(struct pp_instance *ppi,
&DSPOR(ppi)->peerMeanPathDelay, correction_field);
/* Compute one-way delay */
DSPOR(ppi)->peerMeanPathDelay.seconds /= 2;
DSPOR(ppi)->peerMeanPathDelay.nanoseconds /= 2;
div2_TimeInternal(&DSPOR(ppi)->peerMeanPathDelay);
} else {
/* One step clock */
......@@ -145,8 +143,7 @@ void pp_update_peer_delay(struct pp_instance *ppi,
&DSPOR(ppi)->peerMeanPathDelay, correction_field);
/* Compute one-way delay */
DSPOR(ppi)->peerMeanPathDelay.seconds /= 2;
DSPOR(ppi)->peerMeanPathDelay.nanoseconds /= 2;
div2_TimeInternal(&DSPOR(ppi)->peerMeanPathDelay);
}
if (DSPOR(ppi)->peerMeanPathDelay.seconds) {
......
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