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); ...@@ -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 sub_TimeInternal(TimeInternal *r, TimeInternal *x, TimeInternal *y);
extern void set_TimeInternal(TimeInternal *t, Integer32 s, Integer32 ns); extern void set_TimeInternal(TimeInternal *t, Integer32 s, Integer32 ns);
extern void display_TimeInternal(const char *label, TimeInternal *t); extern void display_TimeInternal(const char *label, TimeInternal *t);
extern void div2_TimeInternal(TimeInternal *r);
/* Get and Set system timestamp */ /* Get and Set system timestamp */
extern void pp_get_tstamp(TimeInternal *t); extern void pp_get_tstamp(TimeInternal *t);
......
...@@ -91,6 +91,15 @@ void sub_TimeInternal(TimeInternal *r, TimeInternal *x, TimeInternal *y) ...@@ -91,6 +91,15 @@ void sub_TimeInternal(TimeInternal *r, TimeInternal *x, TimeInternal *y)
normalize_TimeInternal(r); 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) void set_TimeInternal(TimeInternal *t, Integer32 s, Integer32 ns)
{ {
t->seconds = s; t->seconds = s;
......
...@@ -66,8 +66,7 @@ void pp_update_delay(struct pp_instance *ppi, TimeInternal *correction_field) ...@@ -66,8 +66,7 @@ void pp_update_delay(struct pp_instance *ppi, TimeInternal *correction_field)
&DSCUR(ppi)->meanPathDelay, correction_field); &DSCUR(ppi)->meanPathDelay, correction_field);
/* Compute one-way delay */ /* Compute one-way delay */
DSCUR(ppi)->meanPathDelay.seconds /= 2; div2_TimeInternal(&DSCUR(ppi)->meanPathDelay);
DSCUR(ppi)->meanPathDelay.nanoseconds /= 2;
if (DSCUR(ppi)->meanPathDelay.seconds) { if (DSCUR(ppi)->meanPathDelay.seconds) {
...@@ -131,8 +130,7 @@ void pp_update_peer_delay(struct pp_instance *ppi, ...@@ -131,8 +130,7 @@ void pp_update_peer_delay(struct pp_instance *ppi,
&DSPOR(ppi)->peerMeanPathDelay, correction_field); &DSPOR(ppi)->peerMeanPathDelay, correction_field);
/* Compute one-way delay */ /* Compute one-way delay */
DSPOR(ppi)->peerMeanPathDelay.seconds /= 2; div2_TimeInternal(&DSPOR(ppi)->peerMeanPathDelay);
DSPOR(ppi)->peerMeanPathDelay.nanoseconds /= 2;
} else { } else {
/* One step clock */ /* One step clock */
...@@ -145,8 +143,7 @@ void pp_update_peer_delay(struct pp_instance *ppi, ...@@ -145,8 +143,7 @@ void pp_update_peer_delay(struct pp_instance *ppi,
&DSPOR(ppi)->peerMeanPathDelay, correction_field); &DSPOR(ppi)->peerMeanPathDelay, correction_field);
/* Compute one-way delay */ /* Compute one-way delay */
DSPOR(ppi)->peerMeanPathDelay.seconds /= 2; div2_TimeInternal(&DSPOR(ppi)->peerMeanPathDelay);
DSPOR(ppi)->peerMeanPathDelay.nanoseconds /= 2;
} }
if (DSPOR(ppi)->peerMeanPathDelay.seconds) { 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