diff --git a/userspace/tools/wr_mon.c b/userspace/tools/wr_mon.c index 44c6b983d8a34ab82574f53137578dd7a1108ba2..e64dd2ec8ddc1cb66a314db0d2d8ca792f9de462 100644 --- a/userspace/tools/wr_mon.c +++ b/userspace/tools/wr_mon.c @@ -12,6 +12,7 @@ #include #include #include +#include "../../kernel/wbgen-regs/ppsg-regs.h" #include #include #include @@ -536,7 +537,8 @@ static struct desired_state_t{ void show_ports(int hal_alive, int ppsi_alive) { int i, j; - time_t t; + uint32_t tai_l,tmp2,nsec; + struct timeval sw, hw; struct timex timex_val; struct tm *tm; char datestr[32]; @@ -545,6 +547,8 @@ void show_ports(int hal_alive, int ppsi_alive) int nvlans; int *p; + struct PPSG_WB *pps=(struct PPSG_WB *)(_fpga_base_virt+FPGA_BASE_PPS_GEN); + if (!hal_alive) { if (mode == SHOW_GUI) term_cprintf(C_RED, "HAL is dead!\n"); @@ -554,17 +558,26 @@ void show_ports(int hal_alive, int ppsi_alive) } if (mode == SHOW_GUI) { - t = (time_t)_fpga_readl(FPGA_BASE_PPS_GEN + 8 /* UTC_LO */); - tm = localtime(&t); + //First get all the times at the "same instant" + do { + tai_l = pps->CNTR_UTCLO; + nsec = pps->CNTR_NSEC * 16; /* we count a 16.5MHz */ + tmp2 = pps->CNTR_UTCLO; + } while((tmp2 != tai_l)); + gettimeofday(&sw, NULL); + + hw.tv_usec = nsec/1000; + hw.tv_sec = (time_t)(tai_l); + + tm = gmtime(&(hw.tv_sec)); strftime(datestr, sizeof(datestr), "%Y-%m-%d %H:%M:%S", tm); term_cprintf(C_BLUE, "WR time (TAI): "); - term_cprintf(C_WHITE, "%s\n", datestr); + term_cprintf(C_WHITE, "%s.%06li\n", datestr,hw.tv_usec); - time(&t); - tm = localtime(&t); + tm = gmtime(&(sw.tv_sec)); strftime(datestr, sizeof(datestr), "%Y-%m-%d %H:%M:%S", tm); term_cprintf(C_BLUE, "Switch time (UTC): "); - term_cprintf(C_WHITE, "%s", datestr); + term_cprintf(C_WHITE, "%s.%06li", datestr,sw.tv_usec); term_cprintf(C_BLUE, " Leap seconds: "); if (adjtimex(&timex_val) < 0) {