monitor.c 3.26 KB
Newer Older
root's avatar
root committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include "board.h"
#include "ptpd_exports.h"
#include "hal_exports.h"

extern ptpdexp_sync_state_t cur_servo_state;

#define C_DIM 0x80                                                                                                    
#define C_WHITE 7

#define C_GREY (C_WHITE | C_DIM)                                                                                      

#define C_RED 1
#define C_GREEN 2                                                                                                     
#define C_BLUE 4 

int64_t abs64(int64_t t)
{
  return t<0?(-t):t;
}

21 22


root's avatar
root committed
23 24 25 26 27 28 29 30 31 32 33 34 35
int wr_mon_debug(void)
{
  static char* slave_states[] = {"Uninitialized", "SYNC_UTC", "SYNC_NSEC", "SYNC_PHASE", "TRACK_PHASE"};
  static uint32_t last = 0;
  hexp_port_state_t ps;
    
  if(timer_get_tics() - last < 1000)
    return 0;

  last = timer_get_tics();

  m_term_clear();

36
  m_pcprintf(1, 1, C_BLUE, "WR PTP Core Sync Monitor v 0.1 **** pre-alpha version ****");
root's avatar
root committed
37 38 39

  /*show_ports*/
  halexp_get_port_state(&ps, NULL);
40
  m_pcprintf(3, 1, C_BLUE, "Link status:");
root's avatar
root committed
41 42 43 44

  m_pcprintf(5, 1, C_WHITE, "%s: ", "wru1");
  if(ps.up)  m_cprintf(C_GREEN, "Link up    "); else  m_cprintf(C_RED, "Link down  ");

45 46
	if(ps.up)
	{
root's avatar
root committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
  m_cprintf(C_GREY, "mode: ");

  switch(ps.mode)
  {   
    case HEXP_PORT_MODE_WR_MASTER:m_cprintf(C_WHITE, "WR Master  ");break;
    case HEXP_PORT_MODE_WR_SLAVE:m_cprintf(C_WHITE, "WR Slave   ");break;
  }   

  if(ps.is_locked) m_cprintf(C_GREEN, "Locked  "); else   m_cprintf(C_RED, "NoLock  ");
  if(ps.rx_calibrated  && ps.tx_calibrated) m_cprintf(C_GREEN, "Calibrated  "); else   m_cprintf(C_RED, "Uncalibrated  ");


  /*show_servo*/
  m_cprintf(C_BLUE, "\n\nSynchronization status:\n\n");

  if(!cur_servo_state.valid)
  {
    m_cprintf(C_RED, "Master mode or sync info not valid\n\n");
    return;
  }   

  m_cprintf(C_GREY, "Servo state:               "); m_cprintf(C_WHITE, "%s\n", cur_servo_state.slave_servo_state);
  m_cprintf(C_GREY, "Phase tracking:            "); if(cur_servo_state.tracking_enabled) m_cprintf(C_GREEN, "ON\n"); else m_cprintf(C_RED,"OFF\n");
  m_cprintf(C_GREY, "Synchronization source:    "); m_cprintf(C_WHITE, "%s\n", cur_servo_state.sync_source);

  m_cprintf(C_BLUE, "\nTiming parameters:\n\n");

74 75 76 77 78 79 80 81 82
  m_cprintf(C_GREY, "Round-trip time (mu):      "); m_cprintf(C_WHITE, "%d ps\n", (int32_t)(cur_servo_state.mu));
  m_cprintf(C_GREY, "Master-slave delay:        "); m_cprintf(C_WHITE, "%d ps\n", (int32_t)(cur_servo_state.delay_ms));
  m_cprintf(C_GREY, "Master PHY delays:         "); m_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);
  m_cprintf(C_GREY, "Slave PHY delays:          "); m_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);
  m_cprintf(C_GREY, "Total link asymmetry:      "); m_cprintf(C_WHITE, "%d ps\n", (int32_t)(cur_servo_state.total_asymmetry));
  m_cprintf(C_GREY, "Clock offset:              "); m_cprintf(C_WHITE, "%d ps\n", (int32_t)(cur_servo_state.cur_offset));
  m_cprintf(C_GREY, "Phase setpoint:            "); m_cprintf(C_WHITE, "%d ps\n", (int32_t)(cur_servo_state.cur_setpoint));
  m_cprintf(C_GREY, "Skew:                      "); m_cprintf(C_WHITE, "%d ps\n", (int32_t)(cur_servo_state.cur_skew));
     }
root's avatar
root committed
83 84 85 86


  return 0;
}