Commit cba60cfd authored by Aurelio Colosimo's avatar Aurelio Colosimo

arith.c: TimeInternal handling function minor fixes

to_TimeInternal and from_TimeInternal now return int (0 if no errors, -1 in
case of error
normalize_TimeInternal is now declared as static (was not used externally of
arith.c file)
parent 8b53de8e
...@@ -241,9 +241,8 @@ extern void msg_unpack_pdelay_resp_followup(void *buf, ...@@ -241,9 +241,8 @@ extern void msg_unpack_pdelay_resp_followup(void *buf,
/* arith.c */ /* arith.c */
/* FIXME: add prefix in function name? */ /* FIXME: add prefix in function name? */
extern void int64_to_TimeInternal(Integer64 bigint, TimeInternal *internal); extern void int64_to_TimeInternal(Integer64 bigint, TimeInternal *internal);
extern void from_TimeInternal(TimeInternal *internal, Timestamp *external); extern int from_TimeInternal(TimeInternal *internal, Timestamp *external);
extern void to_TimeInternal(TimeInternal *internal, Timestamp *external); extern int to_TimeInternal(TimeInternal *internal, Timestamp *external);
extern void normalize_TimeInternal(TimeInternal *r);
extern void add_TimeInternal(TimeInternal *r, TimeInternal *x, TimeInternal *y); 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);
......
...@@ -21,7 +21,7 @@ void int64_to_TimeInternal(Integer64 bigint, TimeInternal *internal) ...@@ -21,7 +21,7 @@ void int64_to_TimeInternal(Integer64 bigint, TimeInternal *internal)
internal->seconds = bigint_val; internal->seconds = bigint_val;
} }
void from_TimeInternal(TimeInternal *internal, Timestamp *external) int from_TimeInternal(TimeInternal *internal, Timestamp *external)
{ {
/* /*
* fromInternalTime is only used to convert time given by the system * fromInternalTime is only used to convert time given by the system
...@@ -38,30 +38,32 @@ void from_TimeInternal(TimeInternal *internal, Timestamp *external) ...@@ -38,30 +38,32 @@ void from_TimeInternal(TimeInternal *internal, Timestamp *external)
/* FIXME diag /* FIXME diag
* DBG("Negative value cannot be converted into timestamp \n"); * DBG("Negative value cannot be converted into timestamp \n");
*/ */
return; return -1;
} else { } else {
external->secondsField.lsb = internal->seconds; external->secondsField.lsb = internal->seconds;
external->nanosecondsField = internal->nanoseconds; external->nanosecondsField = internal->nanoseconds;
external->secondsField.msb = 0; external->secondsField.msb = 0;
} }
return 0;
} }
void to_TimeInternal(TimeInternal *internal, Timestamp *external) int to_TimeInternal(TimeInternal *internal, Timestamp *external)
{ {
/* Program will not run after 2038... */ /* Program will not run after 2038... */
if (external->secondsField.lsb < INT_MAX) { if (external->secondsField.lsb < INT_MAX) {
internal->seconds = external->secondsField.lsb; internal->seconds = external->secondsField.lsb;
internal->nanoseconds = external->nanosecondsField; internal->nanoseconds = external->nanosecondsField;
return 0;
} else { } else {
/* FIXME diag /* FIXME diag
DBG("Clock servo canno't be executed : " DBG("Clock servo canno't be executed : "
"seconds field is higher than signed integer (32bits) \n"); "seconds field is higher than signed integer (32bits) \n");
*/ */
return; return -1;
} }
} }
void normalize_TimeInternal(TimeInternal *r) static void normalize_TimeInternal(TimeInternal *r)
{ {
r->seconds += r->nanoseconds / PP_NSEC_PER_SEC; r->seconds += r->nanoseconds / PP_NSEC_PER_SEC;
r->nanoseconds -= r->nanoseconds / PP_NSEC_PER_SEC * PP_NSEC_PER_SEC; r->nanoseconds -= r->nanoseconds / PP_NSEC_PER_SEC * PP_NSEC_PER_SEC;
......
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