void rxts_calibration_start() { cal_cur_phase = 0; det_rising.prev_val = det_falling.prev_val = -1; det_rising.state = det_falling.state = TD_WAIT_INACTIVE; spll_set_phase_shift(0, 0); }
/* Updates RX timestamper state machine. Non-zero return value means that calibration is done. */ int rxts_calibration_update(uint32_t *t24p_value) { int32_t ttrans = 0; if (spll_shifter_busy(0)) return 0; /* generate a fake RX timestamp and check if falling edge counter is ahead of rising edge counter */ int flip = ep_timestamper_cal_pulse(); /* look for transitions (with deglitching) */ lookup_transition(&det_rising, flip, cal_cur_phase, 1); lookup_transition(&det_falling, flip, cal_cur_phase, 0); if (cal_cur_phase >= CAL_SCAN_RANGE) { if (det_rising.state != TD_DONE || det_falling.state != TD_DONE) { TRACE_DEV("RXTS calibration error.\n"); return -1; } /* normalize */ while (det_falling.trans_phase >= REF_CLOCK_PERIOD_PS) det_falling.trans_phase -= REF_CLOCK_PERIOD_PS; while (det_rising.trans_phase >= REF_CLOCK_PERIOD_PS) det_rising.trans_phase -= REF_CLOCK_PERIOD_PS; /* Use falling edge as second sample of rising edge */ if (det_falling.trans_phase > det_rising.trans_phase) ttrans = det_falling.trans_phase - REF_CLOCK_PERIOD_PS/2; else if(det_falling.trans_phase < det_rising.trans_phase) ttrans = det_falling.trans_phase + REF_CLOCK_PERIOD_PS/2; ttrans += det_rising.trans_phase; ttrans /= 2; /*normalize ttrans*/ if(ttrans < 0) ttrans += REF_CLOCK_PERIOD_PS; if(ttrans >= REF_CLOCK_PERIOD_PS) ttrans -= REF_CLOCK_PERIOD_PS; TRACE_DEV("RXTS calibration: R@%dps, F@%dps, transition@%dps\n", det_rising.trans_phase, det_falling.trans_phase, ttrans); *t24p_value = (uint32_t)ttrans; return 1; } cal_cur_phase += CAL_SCAN_STEP; spll_set_phase_shift(0, cal_cur_phase); return 0; }
int ptpd_netif_adjust_phase(int32_t phase_ps) { spll_set_phase_shift(SPLL_ALL_CHANNELS, phase_ps); }
int wrpc_adjust_phase(int32_t phase_ps) { spll_set_phase_shift(SPLL_ALL_CHANNELS, phase_ps); return WR_SPLL_OK; }