Commit 7b6e9e7a authored by baujc's avatar baujc

Update SFP parameters when link is going up

This is a temporary implementation that will be reviewed when the PPSi
live configuration will be implemented.
parent 22afef58
......@@ -45,8 +45,12 @@ extern void wrs_main_loop(struct pp_globals *ppg);
extern void wrs_init_ipcserver(struct minipc_ch *ppsi_ch);
/* wrs-calibration.c */
int wrs_read_calibration_data(struct pp_instance *ppi, int32_t *clock_period,
uint32_t *bit_slide_ps);
int wrs_read_calibration_data(struct pp_instance *ppi,int32_t *clock_period, TimeInterval *scaledBitSlide,
RelativeDifference *scaledDelayCoefficient,
TimeInterval *scaledSfpDeltaTx, TimeInterval *scaledSfpDeltaRx);
/* wrs-startup.c */
void enable_asymmetryCorrection(struct pp_instance *ppi, Boolean enable );
/* wrs-time.c (some should moce to wrs-spll.c) */
int wrs_locking_enable(struct pp_instance *ppi);
......
......@@ -52,15 +52,31 @@ static unsigned int run_all_state_machines(struct pp_globals *ppg)
ppi->iface_name, ppi->link_up ? "up":"down");
if (ppi->link_up) {
uint32_t bit_slide_ps;
TimeInterval scaledBitSlide;
RelativeDifference scaledDelayCoefficient;
TimeInterval scaledSfpDeltaTx;
TimeInterval scaledSfpDeltaRx;
ppi->state = PPS_INITIALIZING;
if ( wrs_read_calibration_data(ppi,NULL,&bit_slide_ps)!= WRH_HW_CALIB_OK ) {
if ( wrs_read_calibration_data(ppi,NULL,
&scaledBitSlide,
&scaledDelayCoefficient,
&scaledSfpDeltaTx,
&scaledSfpDeltaRx)!= WRH_HW_CALIB_OK ) {
pp_diag(ppi, fsm, 1, "Cannot read bit_slide value values\n");
bit_slide_ps=0;
scaledBitSlide=0;
}
pp_diag(ppi, fsm, 1, "semistaticLatency(bit-slide)=%u [ps]\n",(unsigned int)bit_slide_ps);
ppi->timestampCorrectionPortDS.semistaticLatency= picos_to_interval(bit_slide_ps);
ppi->timestampCorrectionPortDS.semistaticLatency= scaledBitSlide;
if (scaledDelayCoefficient>=PP_MIN_DCOEFF_AS_RELATIVE_DIFF &&
scaledDelayCoefficient<=PP_MAX_DCOEFF_AS_RELATIVE_DIFF ) {
/* Scaled delay coefficient is valid then delta tx and rx also */
if ( ppi->asymmetryCorrectionPortDS.enable ) {
ppi->cfg.scaledDelayCoefficient=scaledDelayCoefficient;
enable_asymmetryCorrection(ppi,TRUE);
}
ppi->timestampCorrectionPortDS.egressLatency=picos_to_interval(ppi->cfg.egressLatency_ps)+scaledSfpDeltaTx;
ppi->timestampCorrectionPortDS.ingressLatency=picos_to_interval(ppi->cfg.ingressLatency_ps)+scaledSfpDeltaRx;
}
}
else {
ppi->next_state = PPS_DISABLED;
......
......@@ -13,7 +13,9 @@
#include <hal_exports.h>
int wrs_read_calibration_data(struct pp_instance *ppi,int32_t *clock_period, uint32_t *bit_slide_ps)
int wrs_read_calibration_data(struct pp_instance *ppi,int32_t *clock_period, TimeInterval *scaledBitSlide,
RelativeDifference *scaledDelayCoefficient,
TimeInterval *scaledSfpDeltaTx, TimeInterval *scaledSfpDeltaRx)
{
struct hal_port_state *p;
......@@ -21,12 +23,15 @@ int wrs_read_calibration_data(struct pp_instance *ppi,int32_t *clock_period, uin
if (!p)
return WRH_HW_CALIB_NOT_FOUND;
if(!p->calib.tx_calibrated || !p->calib.rx_calibrated)
return WRH_HW_CALIB_NOT_FOUND;
if ( bit_slide_ps )
*bit_slide_ps=p->calib.bitslide_ps;
if ( scaledBitSlide )
*scaledBitSlide=picos_to_interval( (int64_t) p->calib.bitslide_ps);
if(clock_period)
*clock_period = 16000; /* REF_CLOCK_PERIOD_PS */
if ( scaledDelayCoefficient )
*scaledDelayCoefficient=(RelativeDifference)(p->calib.sfp.alpha * REL_DIFF_TWO_POW_FRACBITS);
if ( scaledSfpDeltaTx )
*scaledSfpDeltaTx= picos_to_interval( (int64_t) p->calib.sfp.delta_tx_ps);
if ( scaledSfpDeltaRx )
*scaledSfpDeltaRx= picos_to_interval( (int64_t) p->calib.sfp.delta_rx_ps);
return WRH_HW_CALIB_OK;
}
......@@ -97,7 +97,7 @@ static __inline__ double calculateDelayAsymCoefficient(double delayCoefficient
/**
* Enable/disable asymmetry correction
*/
static void enable_asymmetryCorrection(struct pp_instance *ppi, Boolean enable ) {
void enable_asymmetryCorrection(struct pp_instance *ppi, Boolean enable ) {
if ( (ppi->asymmetryCorrectionPortDS.enable=enable)==TRUE ) {
/* Enabled: The delay asymmetry will be calculated */
double delayCoefficient;
......
......@@ -56,7 +56,9 @@ struct wrh_operations {
int (*adjust_counters)(int64_t adjust_sec, int32_t adjust_nsec);
int (*adjust_phase)(int32_t phase_ps);
int (*read_calib_data)(struct pp_instance *ppi,int32_t *clock_period, uint32_t *bit_slide_ps);
int (*read_calib_data)(struct pp_instance *ppi,int32_t *clock_period, TimeInterval *scaledBitSlide,
RelativeDifference *scaledDelayCoefficient,
TimeInterval *scaledSfpDeltaTx, TimeInterval *scaledSfpDeltaRx);
int (*enable_timing_output)(struct pp_globals *,int enable);
timing_mode_t (*get_timing_mode)(struct pp_globals *);
timing_mode_state_t (*get_timing_mode_state)(struct pp_globals *);
......
......@@ -50,7 +50,7 @@ int wrh_update_correction_values(struct pp_instance *ppi)
/* read the interesting values from HW (i.e. HAL)*/
if ( WRH_OPER()->read_calib_data(ppi,&s->clock_period_ps,NULL) != WRH_HW_CALIB_OK){
if ( WRH_OPER()->read_calib_data(ppi,&s->clock_period_ps,NULL,NULL,NULL,NULL) != WRH_HW_CALIB_OK){
pp_diag(ppi, ext, 2, "hook: %s -- cannot read calib values\n",
__func__);
return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment