Commit 74b72170 authored by Jean-Claude BAU's avatar Jean-Claude BAU Committed by Adam Wujek

Change conversion of RelativeDifference to human readable format.

These modifications increase the precision of the displayed fraction
part of a RelativeDifference type.
parent 10cc05bf
...@@ -215,13 +215,23 @@ static double interval_to_double (TimeInterval interval) { ...@@ -215,13 +215,23 @@ static double interval_to_double (TimeInterval interval) {
return neg ? -f : f; return neg ? -f : f;
} }
static double relDiff_to_double(RelativeDifference relDiff) { #define REL_DIFF_FRACBITS 62
double f ; #define REL_DIFF_FRACMASK 0x3fffffffffffffff
int neg = relDiff<0;
/* We cannot use double for calculation as it is less precise than the RelativeDifference type */
if(neg) relDiff= ~relDiff+1; void decode_relative_difference(RelativeDifference rd, int32_t *nsecs, uint64_t *sub_yocto) {
f= (double)relDiff/(double)(1LL<<REL_DIFF_FRACBITS); int64_t fraction;
return neg ? -f : f; uint64_t bitWeight=500000000000000000;
uint64_t mask;
*sub_yocto=0;
*nsecs = (int32_t)(rd >> REL_DIFF_FRACBITS);
fraction=(int64_t)rd & REL_DIFF_FRACMASK;
for (mask=(uint64_t) 1<< (REL_DIFF_FRACBITS-1);mask!=0; mask>>=1 ) {
if ( mask & fraction )
*sub_yocto+=bitWeight;
bitWeight/=2;
}
} }
static double alpha_to_double(int32_t alpha) { static double alpha_to_double(int32_t alpha) {
...@@ -743,6 +753,8 @@ void show_servo(struct inst_servo_t *servo, int alive) ...@@ -743,6 +753,8 @@ void show_servo(struct inst_servo_t *servo, int alive)
{ {
struct wr_servo_state * wr_servo; struct wr_servo_state * wr_servo;
int32_t nsecs;
uint64_t sub_yocto;
struct l1e_servo_state * l1e_servo; struct l1e_servo_state * l1e_servo;
int proto_extension=servo->ppi->protocol_extension; int proto_extension=servo->ppi->protocol_extension;
struct proto_ext_info_t *pe_info= IS_PROTO_EXT_INFO_AVAILABLE(proto_extension) ? &proto_ext_info[proto_extension] : &proto_ext_info[0] ; struct proto_ext_info_t *pe_info= IS_PROTO_EXT_INFO_AVAILABLE(proto_extension) ? &proto_ext_info[proto_extension] : &proto_ext_info[0] ;
...@@ -807,7 +819,8 @@ void show_servo(struct inst_servo_t *servo, int alive) ...@@ -807,7 +819,8 @@ void show_servo(struct inst_servo_t *servo, int alive)
term_cprintf(C_CYAN," | ");term_cprintf(C_BLUE, "delayAsymmetry : "); term_cprintf(C_CYAN," | ");term_cprintf(C_BLUE, "delayAsymmetry : ");
term_cprintf(C_WHITE, "%15.3f nsec\n", interval_to_double(servo->delayAsymmetry)); term_cprintf(C_WHITE, "%15.3f nsec\n", interval_to_double(servo->delayAsymmetry));
term_cprintf(C_CYAN," | ");term_cprintf(C_BLUE, "scaledDelayCoef : "); term_cprintf(C_CYAN," | ");term_cprintf(C_BLUE, "scaledDelayCoef : ");
term_cprintf(C_WHITE, "%.9f fpa(%" PRId64 ")", relDiff_to_double(servo->scaledDelayCoefficient), (int64_t)servo->scaledDelayCoefficient); decode_relative_difference(servo->scaledDelayCoefficient, &nsecs, &sub_yocto);
term_cprintf(C_WHITE, "%"PRId32".%018"PRIu64" fpa(%" PRIu64 ")", nsecs, sub_yocto, (uint64_t)servo->scaledDelayCoefficient);
if ( wr_servo ) { if ( wr_servo ) {
term_cprintf(C_BLUE, " Fixed Alpha : "); term_cprintf(C_BLUE, " Fixed Alpha : ");
term_cprintf(C_WHITE, "%.9f fpa(%d)", alpha_to_double(wr_servo->fiber_fix_alpha), wr_servo->fiber_fix_alpha); term_cprintf(C_WHITE, "%.9f fpa(%d)", alpha_to_double(wr_servo->fiber_fix_alpha), wr_servo->fiber_fix_alpha);
......
...@@ -79,6 +79,24 @@ static int dump_all_rtu_entries = 0; /* rtu exports 4096 vlans and 2048 htab ...@@ -79,6 +79,24 @@ static int dump_all_rtu_entries = 0; /* rtu exports 4096 vlans and 2048 htab
entries */ entries */
#define REL_DIFF_FRACBITS 62
#define REL_DIFF_FRACMASK 0x3fffffffffffffff
void decode_relative_difference(RelativeDifference rd, int32_t *nsecs, uint64_t *sub_yocto) {
int64_t fraction;
uint64_t bitWeight=500000000000000000;
uint64_t mask;
*sub_yocto=0;
*nsecs = (int32_t)(rd >> REL_DIFF_FRACBITS);
fraction=(int64_t)rd & REL_DIFF_FRACMASK;
for (mask=(uint64_t) 1<< (REL_DIFF_FRACBITS-1);mask!=0; mask>>=1 ) {
if ( mask & fraction )
*sub_yocto+=bitWeight;
bitWeight/=2;
}
}
void dump_one_field(void *addr, struct dump_info *info) void dump_one_field(void *addr, struct dump_info *info)
{ {
void *p = addr + info->offset; void *p = addr + info->offset;
...@@ -89,7 +107,7 @@ void dump_one_field(void *addr, struct dump_info *info) ...@@ -89,7 +107,7 @@ void dump_one_field(void *addr, struct dump_info *info)
struct PortIdentity *pi = p; struct PortIdentity *pi = p;
struct ClockQuality *cq = p; struct ClockQuality *cq = p;
char format[16]; char format[16];
uint64_t sec, nano, pico, femto; uint64_t sec, nano, pico;
int i; int i;
printf(" %-30s ", info->name); /* name includes trailing ':' */ printf(" %-30s ", info->name); /* name includes trailing ':' */
...@@ -170,7 +188,6 @@ void dump_one_field(void *addr, struct dump_info *info) ...@@ -170,7 +188,6 @@ void dump_one_field(void *addr, struct dump_info *info)
int64_t scaled_nsecs=t->scaled_nsecs; int64_t scaled_nsecs=t->scaled_nsecs;
if ( scaled_nsecs < 0) { if ( scaled_nsecs < 0) {
scaled_nsecs =-scaled_nsecs;
sign='-'; sign='-';
} }
nano = scaled_nsecs >> TIME_FRACBITS; nano = scaled_nsecs >> TIME_FRACBITS;
...@@ -192,36 +209,22 @@ void dump_one_field(void *addr, struct dump_info *info) ...@@ -192,36 +209,22 @@ void dump_one_field(void *addr, struct dump_info *info)
case dump_type_TimeInterval: case dump_type_TimeInterval:
{ {
char sign='+';
int64_t scaled_nsecs=*ti; int64_t scaled_nsecs=*ti;
if ( scaled_nsecs < 0) {
scaled_nsecs =-scaled_nsecs;
sign='-';
}
nano = scaled_nsecs >> TIME_INTERVAL_FRACBITS; nano = scaled_nsecs >> TIME_INTERVAL_FRACBITS;
pico = scaled_nsecs & TIME_INTERVAL_FRACMASK; pico = scaled_nsecs & TIME_INTERVAL_FRACMASK;
pico = (pico * 1000) >> TIME_INTERVAL_FRACBITS; pico = (pico * 1000) >> TIME_INTERVAL_FRACBITS;
printf("%c%09"PRIu64".%03"PRIu64"\n", sign,nano,pico); printf("%10"PRId64".%03"PRIu64"\n", nano,pico);
} }
break; break;
#define REL_DIFF_FRACBITS 62
#define REL_DIFF_FRACMASK 0x3fffffffffffffff
case dump_type_RelativeDifference: case dump_type_RelativeDifference:
{ {
char sign='+'; int32_t nsecs;
int64_t scaled_nsecs=*rd; uint64_t sub_yocto;
if (scaled_nsecs<0) { decode_relative_difference(*rd, &nsecs, &sub_yocto);
scaled_nsecs =-scaled_nsecs; printf("%"PRId32".%018"PRIu64"\n", nsecs, sub_yocto);
sign='-';
}
nano = scaled_nsecs >> REL_DIFF_FRACBITS;
femto= (scaled_nsecs & REL_DIFF_FRACMASK)>>32;
femto = (femto * 1000000L) >> (REL_DIFF_FRACBITS-32);
printf("%c%01"PRIu64".%06"PRIu64" \n", sign, nano,femto);
} }
break; break;
case dump_type_ip_address: case dump_type_ip_address:
......
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