int halexp_get_port_state(hexp_port_state_t *state, const char *port_name) { state->valid = 1; #ifdef WRPC_MASTER state->mode = HEXP_PORT_MODE_WR_MASTER; #else state->mode = HEXP_PORT_MODE_WR_SLAVE; #endif ep_get_deltas( &state->delta_tx, &state->delta_rx); read_phase_val(state); state->up = ep_link_up(NULL); state->tx_calibrated = 1; state->rx_calibrated = 1; state->is_locked = spll_check_lock(0); state->lock_priority = 0; spll_get_phase_shift(0, NULL, &state->phase_setpoint); state->clock_period = 8000; state->t2_phase_transition = cal_phase_transition; state->t4_phase_transition = cal_phase_transition; get_mac_addr(state->hw_addr); state->hw_index = 0; state->fiber_fix_alpha = sfp_alpha; return 0; }
int wrc_ptp_set_mode(int mode) { uint32_t start_tics, lock_timeout = 0; ptp_mode = 0; wrc_ptp_stop(); switch (mode) { case WRC_MODE_GM: rtOpts.primarySource = TRUE; rtOpts.wrConfig = WR_M_ONLY; rtOpts.masterOnly = TRUE; spll_init(SPLL_MODE_GRAND_MASTER, 0, 1); lock_timeout = LOCK_TIMEOUT_GM; break; case WRC_MODE_MASTER: rtOpts.primarySource = FALSE; rtOpts.wrConfig = WR_M_ONLY; rtOpts.masterOnly = TRUE; spll_init(SPLL_MODE_FREE_RUNNING_MASTER, 0, 1); lock_timeout = LOCK_TIMEOUT_FM; break; case WRC_MODE_SLAVE: rtOpts.primarySource = FALSE; rtOpts.wrConfig = WR_S_ONLY; rtOpts.masterOnly = FALSE; spll_init(SPLL_MODE_SLAVE, 0, 1); break; } initDataClock(&rtOpts, &ptpClockDS); start_tics = timer_get_tics(); mprintf("Locking PLL"); shw_pps_gen_enable_output(0); while (!spll_check_lock(0) && lock_timeout) { timer_delay_ms(1000); mprintf("."); if (time_after(timer_get_tics(), start_tics + lock_timeout)) { mprintf("\nLock timeout.\n"); return -ETIMEDOUT; } else if (uart_read_byte() == 27) { mprintf("\n"); return -EINTR; } } mprintf("\n"); if (mode == WRC_MODE_MASTER || mode == WRC_MODE_GM) shw_pps_gen_enable_output(1); ptp_mode = mode; return 0; }
/* legacy function for 'calibration force' command */ int measure_t24p(uint32_t *value) { int rv; pp_printf("Waiting for link...\n"); while (!ep_link_up(NULL)) timer_delay_ms(100); spll_init(SPLL_MODE_SLAVE, 0, 1); pp_printf("Locking PLL...\n"); while (!spll_check_lock(0)) timer_delay_ms(100); pp_printf("\n"); pp_printf("Calibrating RX timestamper...\n"); rxts_calibration_start(); while (!(rv = rxts_calibration_update(value))) ; return rv; }
int wrpc_spll_locking_poll(struct pp_instance *ppi, int grandmaster) { int locked; static int t24p_calibrated = 0; locked = spll_check_lock(0); /* both slave and gm mode */ if (grandmaster) return locked ? WR_SPLL_READY : WR_SPLL_ERROR; /* Else, slave: ensure calibration is done */ if(!locked) { t24p_calibrated = 0; } else if(locked && !t24p_calibrated) { /*run t24p calibration if needed*/ calib_t24p(WRC_MODE_SLAVE, &cal_phase_transition); t24p_calibrated = 1; } return locked ? WR_SPLL_READY : WR_SPLL_ERROR; }
int ptpd_netif_locking_poll(int txrx, const char *ifaceName, int priority) { return spll_check_lock(0) ? PTPD_NETIF_READY : PTPD_NETIF_ERROR; }