monitor.c 6.16 KB
Newer Older
1 2 3
#include <stdio.h>
#include <time.h>

root's avatar
root committed
4 5 6
#include "board.h"
#include "ptpd_exports.h"
#include "hal_exports.h"
7
#include "softpll_ng.h"
8
#include "pps_gen.h"
9 10
#include "util.h"
#include "timer.h"
11
#include "onewire.h"
12 13

#define UI_REFRESH_PERIOD TICS_PER_SECOND /* 1 sec */
root's avatar
root committed
14 15

extern ptpdexp_sync_state_t cur_servo_state;
16
extern int wrc_man_phase;
root's avatar
root committed
17

18
int wrc_mon_gui(void)
root's avatar
root committed
19
{
20
  static char* slave_states[] = {"Uninitialized", "SYNC_SEC", "SYNC_NSEC", "SYNC_PHASE", "TRACK_PHASE"};
root's avatar
root committed
21 22
  static uint32_t last = 0;
  hexp_port_state_t ps;
23
  int tx, rx;
24
  int aux_stat;
25 26
  uint64_t sec;
  uint32_t nsec;
root's avatar
root committed
27
    
28
  if(timer_get_tics() - last < UI_REFRESH_PERIOD)
root's avatar
root committed
29 30 31 32
    return 0;

  last = timer_get_tics();

33
  term_clear();
root's avatar
root committed
34

35 36
  pcprintf(1, 1, C_BLUE, "WR PTP Core Sync Monitor v 1.0");
  pcprintf(2, 1, C_GREY, "Esc = exit");
37

38
  pps_gen_get_time(&sec, &nsec);
39

40 41
  cprintf(C_BLUE, "\n\nTAI Time:                  ");
  cprintf(C_WHITE, "%s", format_time(sec));
root's avatar
root committed
42 43 44

  /*show_ports*/
  halexp_get_port_state(&ps, NULL);
45
  pcprintf(4, 1, C_BLUE, "\n\nLink status:");
root's avatar
root committed
46

47 48
  pcprintf(6, 1, C_WHITE, "%s: ", "wru1");
  if(ps.up)  cprintf(C_GREEN, "Link up   "); else  cprintf(C_RED, "Link down ");
root's avatar
root committed
49

50 51 52
  if(ps.up)
    {
      minic_get_stats(&tx, &rx);
53
      cprintf(C_GREY, "(RX: %d, TX: %d), mode: ", rx, tx);
54 55 56

      switch(ps.mode)
        {   
57 58
        case HEXP_PORT_MODE_WR_MASTER:cprintf(C_WHITE, "WR Master  ");break;
        case HEXP_PORT_MODE_WR_SLAVE:cprintf(C_WHITE, "WR Slave   ");break;
59
        }   
root's avatar
root committed
60

61 62
      if(ps.is_locked) cprintf(C_GREEN, "Locked  "); else   cprintf(C_RED, "NoLock  ");
      if(ps.rx_calibrated  && ps.tx_calibrated) cprintf(C_GREEN, "Calibrated  "); else   cprintf(C_RED, "Uncalibrated  ");
root's avatar
root committed
63

64
      
root's avatar
root committed
65 66


67 68
      
      /* show_servo */
69
      cprintf(C_BLUE, "\n\nSynchronization status:\n\n");
root's avatar
root committed
70

71 72
      if(!cur_servo_state.valid)
        {
73
          cprintf(C_RED, "Master mode or sync info not valid\n\n");
74 75
          return;
        }   
root's avatar
root committed
76

77 78 79
      cprintf(C_GREY, "Servo state:               "); cprintf(C_WHITE, "%s\n", cur_servo_state.slave_servo_state);
      cprintf(C_GREY, "Phase tracking:            "); if(cur_servo_state.tracking_enabled) cprintf(C_GREEN, "ON\n"); else cprintf(C_RED,"OFF\n");
      cprintf(C_GREY, "Synchronization source:    "); cprintf(C_WHITE, "%s\n", cur_servo_state.sync_source);
root's avatar
root committed
80

81
      cprintf(C_GREY, "Aux clock status:          "); 
82

83
      aux_stat = spll_get_aux_status(0);
84

85
      if(aux_stat & SPLL_AUX_ENABLED)
86
  			cprintf(C_GREEN,"enabled");
87

88
      if(aux_stat & SPLL_AUX_LOCKED)
89
  			cprintf(C_GREEN,", locked");
90 91
      mprintf("\n");

92
      cprintf(C_BLUE, "\nTiming parameters:\n\n");
93

94 95 96 97 98 99
      cprintf(C_GREY, "Round-trip time (mu):      "); cprintf(C_WHITE, "%d ps\n", (int32_t)(cur_servo_state.mu));
      cprintf(C_GREY, "Master-slave delay:        "); cprintf(C_WHITE, "%d ps\n", (int32_t)(cur_servo_state.delay_ms));
      cprintf(C_GREY, "Master PHY delays:         "); cprintf(C_WHITE, "TX: %d ps, RX: %d ps\n", (int32_t)cur_servo_state.delta_tx_m, (int32_t)cur_servo_state.delta_rx_m);
      cprintf(C_GREY, "Slave PHY delays:          "); cprintf(C_WHITE, "TX: %d ps, RX: %d ps\n", (int32_t)cur_servo_state.delta_tx_s, (int32_t)cur_servo_state.delta_rx_s);
      cprintf(C_GREY, "Total link asymmetry:      "); cprintf(C_WHITE, "%d ps\n", (int32_t)(cur_servo_state.total_asymmetry));
      cprintf(C_GREY, "Cable rtt delay:           "); cprintf(C_WHITE, "%d ps\n", 
100 101
                                                                  (int32_t)(cur_servo_state.mu) - (int32_t)cur_servo_state.delta_tx_m - (int32_t)cur_servo_state.delta_rx_m - 
                                                                  (int32_t)cur_servo_state.delta_tx_s - (int32_t)cur_servo_state.delta_rx_s);
102 103 104 105
      cprintf(C_GREY, "Clock offset:              "); cprintf(C_WHITE, "%d ps\n", (int32_t)(cur_servo_state.cur_offset));
      cprintf(C_GREY, "Phase setpoint:            "); cprintf(C_WHITE, "%d ps\n", (int32_t)(cur_servo_state.cur_setpoint));
      cprintf(C_GREY, "Skew:                      "); cprintf(C_WHITE, "%d ps\n", (int32_t)(cur_servo_state.cur_skew));
      cprintf(C_GREY, "Manual phase adjustment:   "); cprintf(C_WHITE, "%d ps\n", (int32_t)(wrc_man_phase));
root's avatar
root committed
106

107
      cprintf(C_GREY, "Update counter:            "); cprintf(C_WHITE, "%d \n", (int32_t)(cur_servo_state.update_count));
108 109 110


    }
root's avatar
root committed
111

112
  cprintf(C_GREY, "--");
root's avatar
root committed
113 114 115

  return 0;
}
116

117
int wrc_log_stats(uint8_t onetime)
118
{
119
  static char* slave_states[] = {"Uninitialized", "SYNC_SEC", "SYNC_NSEC", "SYNC_PHASE", "TRACK_PHASE"};
120 121 122 123
  static uint32_t last = 0;
  hexp_port_state_t ps;
  int tx, rx;
  int aux_stat;
124 125
  uint64_t sec;
  uint32_t nsec;
126 127
  int16_t brd_temp = 0;
  int16_t brd_temp_frac = 0;
128
    
129 130 131 132 133
  if(!onetime && timer_get_tics() - last < UI_REFRESH_PERIOD)
      return 0;

  last = timer_get_tics();

134
	pps_gen_get_time(&sec, &nsec);
135 136
  halexp_get_port_state(&ps, NULL);
  minic_get_stats(&tx, &rx);
137 138 139 140
  mprintf("lnk:%d rx:%d tx:%d ", ps.up, rx, tx);
  mprintf("lock:%d ", ps.is_locked?1:0);
  mprintf("sv:%d ", cur_servo_state.valid?1:0);
  mprintf("ss:'%s' ", cur_servo_state.slave_servo_state);
141 142
  aux_stat = spll_get_aux_status(0);
  mprintf("aux:%x ", aux_stat);
143
  mprintf("sec:%d nsec:%d ", (uint32_t) sec, nsec); /* fixme: clock is not always 125 MHz */
144 145
  mprintf("mu:%d ", (int32_t)cur_servo_state.mu);
  mprintf("dms:%d ", (int32_t)cur_servo_state.delay_ms);
146 147 148
  mprintf("dtxm:%d drxm:%d ", (int32_t)cur_servo_state.delta_tx_m, (int32_t)cur_servo_state.delta_rx_m);
  mprintf("dtxs:%d drxs:%d ", (int32_t)cur_servo_state.delta_tx_s, (int32_t)cur_servo_state.delta_rx_s);
  mprintf("asym:%d ", (int32_t)(cur_servo_state.total_asymmetry));
149 150 151 152 153 154 155 156 157 158 159 160
  mprintf("crtt:%d ", 
          (int32_t)(cur_servo_state.mu) - (int32_t)cur_servo_state.delta_tx_m - (int32_t)cur_servo_state.delta_rx_m - 
          (int32_t)cur_servo_state.delta_tx_s - (int32_t)cur_servo_state.delta_rx_s);
  mprintf("cko:%d ", (int32_t)(cur_servo_state.cur_offset));
  mprintf("setp:%d ", (int32_t)(cur_servo_state.cur_setpoint));
  mprintf("hd:%d md:%d ad:%d ",
          spll_get_dac(-1),
          spll_get_dac(0),
          spll_get_dac(1)
          );
  mprintf("ucnt:%d ", (int32_t)cur_servo_state.update_count);

161 162 163
  own_readtemp(ONEWIRE_PORT, &brd_temp, &brd_temp_frac);
  mprintf("temp:%d.%02d C", brd_temp, brd_temp_frac);

164
  mprintf("\n");
165 166
  return 0;
}