Commit 279f2c6b authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

call t24p calibration every time PTP is set to Slave mode, or read the value…

call t24p calibration every time PTP is set to Slave mode, or read the value from EEPROM when Master mode
parent c615ef5d
......@@ -16,6 +16,7 @@
#include "syscon.h"
#include "endpoint.h"
#include "softpll_ng.h"
#include "wrc_ptp.h"
/* New calibrator for the transition phase value. A major pain in the ass for the folks who frequently rebuild
their gatewares. The idea is described below:
......@@ -176,3 +177,47 @@ int measure_t24p(int *value)
while (!(rv = rxts_calibration_update(value))) ;
return rv;
}
/*SoftPLL must be locked prior calling this function*/
static int calib_t24p_slave(int *value)
{
int rv;
rxts_calibration_start();
while (!(rv = rxts_calibration_update(value))) ;
if (rv < 0) {
printf("Could not calibrate t24p, trying to read from EEPROM\n");
if(eeprom_phtrans(WRPC_FMC_I2C, FMC_EEPROM_ADR, value, 0) < 0) {
printf("Something went wrong while writing EEPROM\n");
return -1;
}
}
else {
printf("t24p value is %d ps, storing to EEPROM\n", *value);
if(eeprom_phtrans(WRPC_FMC_I2C, FMC_EEPROM_ADR, value, 1) < 0) {
printf("Something went wrong while writing EEPROM\n");
return -1;
}
}
return 0;
}
static int calib_t24p_master(int *value)
{
int rv;
rv = eeprom_phtrans(WRPC_FMC_I2C, FMC_EEPROM_ADR, value, 0);
printf("t24p read from EEPROM: %d ps\n", *value);
return rv;
}
int calib_t24p(int mode, int *value)
{
if (mode == WRC_MODE_SLAVE)
return calib_t24p_slave(value);
else
return calib_t24p_master(value);
}
......@@ -13,5 +13,6 @@
void rxts_calibration_start();
int rxts_calibration_update(int *t24p_value);
int measure_t24p(int *value);
int calib_t24p(int mode, int *value);
#endif
......@@ -18,6 +18,9 @@
#include "wrc_ptp.h"
#include "pps_gen.h"
#include "uart.h"
#include "rxts_calibrator.h"
extern int32_t cal_phase_transition;
static RunTimeOpts rtOpts = {
.ifaceName = {"wr1"},
......@@ -136,11 +139,14 @@ int wrc_ptp_set_mode(int mode)
return -EINTR;
}
}
mprintf("\n");
/*t24p calibration here*/
calib_t24p(mode, &cal_phase_transition);
if (mode == WRC_MODE_MASTER || mode == WRC_MODE_GM)
shw_pps_gen_enable_output(1);
mprintf("\n");
ptp_mode = mode;
return 0;
}
......
......@@ -22,6 +22,9 @@
#include "wrc_ptp.h"
#include "pps_gen.h"
#include "uart.h"
#include "rxts_calibrator.h"
extern int32_t cal_phase_transition;
int ptp_mode = WRC_MODE_UNKNOWN;
static int ptp_enabled = 0, ptp_forced_stop = 0;
......@@ -125,11 +128,14 @@ int wrc_ptp_set_mode(int mode)
return -EINTR;
}
}
pp_printf("\n");
/*t24p calibration here*/
calib_t24p(mode, &cal_phase_transition);
if (mode == WRC_MODE_MASTER || mode == WRC_MODE_GM)
shw_pps_gen_enable_output(1);
pp_printf("\n");
ptp_mode = mode;
return 0;
}
......
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