XilinxProcessorIPLib/drivers/rtcpsu/examples/xrtcpsu_set_calibration_example.c
int RtcPsuSetCalibrationExample(u16 DeviceId)
{
	int Status;
	u32 NetworkTime;
	XRtcPsu_DT dt1;
	u32 OscillatorFreq;

	/*
	 * Initialize the RTC driver so that it's ready to use.
	 * Look up the configuration in the config table, then initialize it.
	 */
	Config = XRtcPsu_LookupConfig(DeviceId);
	if (NULL == Config) {
		return XST_FAILURE;
	}

	Status = XRtcPsu_CfgInitialize(&Rtc_Psu, Config, Config->BaseAddr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/* Check hardware build. */
	Status = XRtcPsu_SelfTest(&Rtc_Psu);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	xil_printf("Enter Crystal oscillator frequency : ");
#if defined(__aarch64__)
	scanf("%d", &OscillatorFreq);
#else
	scanf("%ld", &OscillatorFreq);
#endif

	xil_printf("\n\rEnter Internet / Network Time YEAR:MM:DD HR:MM:SS : ");
#if defined(__aarch64__)
	scanf("%d %d %d %d %d %d", &dt1.Year, &dt1.Month, &dt1.Day,
			&dt1.Hour, &dt1.Min, &dt1.Sec);
#else
	scanf("%ld %ld %ld %ld %ld %ld", &dt1.Year, &dt1.Month, &dt1.Day,
			&dt1.Hour, &dt1.Min, &dt1.Sec);
#endif
	xil_printf("%d %d %d %d %d %d\n\r",dt1.Year,dt1.Month,dt1.Day,dt1.Hour,dt1.Min,dt1.Sec);

	NetworkTime = XRtcPsu_DateTimeToSec(&dt1);

	xil_printf("\n\rOld Calibration value : %08x\tCrystal Frequency : %08x\n\r",
			Rtc_Psu.CalibrationValue,Rtc_Psu.OscillatorFreq);

	/* Set RTC time to user input time */
	XRtcPsu_SetTime(&Rtc_Psu,NetworkTime);

	/*
	 * For time accuracy RTC module need to be calibrated at regular interval,
	 * new calibration value calculation requires rtc set time, rtc current time
	 * and system/network time. For reference 10Sec system/network time interval
	 * used for finding new calibration values.
	 */
	sleep(10);
	NetworkTime = NetworkTime+10;

	XRtcPsu_CalculateCalibration(&Rtc_Psu,NetworkTime,OscillatorFreq);

	Status = XRtcPsu_CfgInitialize(&Rtc_Psu, Config, Config->BaseAddr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	xil_printf("New Calibration value : %08x\tCrystal Frequency : %08x\n\r",
			Rtc_Psu.CalibrationValue,Rtc_Psu.OscillatorFreq);

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* This function does a minimal set Calibration test on the XRtcPsu device.
*
* This function updates the Calibration register value.
*
* @param	DeviceId is the unique device id from hardware build.
*
* @return	XST_SUCCESS if successful, XST_FAILURE if unsuccessful
*
* @note		None.
*
****************************************************************************/
This function does a minimal set Calibration test on the XRtcPsu device.
This function updates the Calibration register value.
This function does a minimal set Calibration test on the XRtcPsu device . This function updates the Calibration register value .
int RtcPsuSetCalibrationExample(u16 DeviceId)
{
	int Status;
	u32 NetworkTime;
	XRtcPsu_DT dt1;
	u32 OscillatorFreq;
	Config = XRtcPsu_LookupConfig(DeviceId);
	if (NULL == Config) {
		return XST_FAILURE;
	}
	Status = XRtcPsu_CfgInitialize(&Rtc_Psu, Config, Config->BaseAddr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = XRtcPsu_SelfTest(&Rtc_Psu);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	xil_printf("Enter Crystal oscillator frequency : ");
#if defined(__aarch64__)
	scanf("%d", &OscillatorFreq);
#else
	scanf("%ld", &OscillatorFreq);
#endif
	xil_printf("\n\rEnter Internet / Network Time YEAR:MM:DD HR:MM:SS : ");
#if defined(__aarch64__)
	scanf("%d %d %d %d %d %d", &dt1.Year, &dt1.Month, &dt1.Day,
			&dt1.Hour, &dt1.Min, &dt1.Sec);
#else
	scanf("%ld %ld %ld %ld %ld %ld", &dt1.Year, &dt1.Month, &dt1.Day,
			&dt1.Hour, &dt1.Min, &dt1.Sec);
#endif
	xil_printf("%d %d %d %d %d %d\n\r",dt1.Year,dt1.Month,dt1.Day,dt1.Hour,dt1.Min,dt1.Sec);
	NetworkTime = XRtcPsu_DateTimeToSec(&dt1);
	xil_printf("\n\rOld Calibration value : %08x\tCrystal Frequency : %08x\n\r",
			Rtc_Psu.CalibrationValue,Rtc_Psu.OscillatorFreq);
	XRtcPsu_SetTime(&Rtc_Psu,NetworkTime);
	sleep(10);
	NetworkTime = NetworkTime+10;
	XRtcPsu_CalculateCalibration(&Rtc_Psu,NetworkTime,OscillatorFreq);
	Status = XRtcPsu_CfgInitialize(&Rtc_Psu, Config, Config->BaseAddr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	xil_printf("New Calibration value : %08x\tCrystal Frequency : %08x\n\r",
			Rtc_Psu.CalibrationValue,Rtc_Psu.OscillatorFreq);
	return XST_SUCCESS;
}
int RtcPsuSetCalibrationExample ( u16 DeviceId ) { int Status ; u32 NetworkTime ; XRtcPsu_DT dt1 ; u32 OscillatorFreq ; Config = XRtcPsu_LookupConfig ( DeviceId ) ; if ( NULL == Config ) { return XST_FAILURE ; } Status = XRtcPsu_CfgInitialize ( & Rtc_Psu , Config , Config -> BaseAddr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = XRtcPsu_SelfTest ( & Rtc_Psu ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } xil_printf ( " " ) ; #if defined ( __aarch64__ ) scanf ( " " , & OscillatorFreq ) ; #else scanf ( " " , & OscillatorFreq ) ; #endif xil_printf ( " \n \r " ) ; #if defined ( __aarch64__ ) scanf ( " " , & dt1 . Year , & dt1 . Month , & dt1 . Day , & dt1 . Hour , & dt1 . Min , & dt1 . Sec ) ; #else scanf ( " " , & dt1 . Year , & dt1 . Month , & dt1 . Day , & dt1 . Hour , & dt1 . Min , & dt1 . Sec ) ; #endif xil_printf ( " \n \r " , dt1 . Year , dt1 . Month , dt1 . Day , dt1 . Hour , dt1 . Min , dt1 . Sec ) ; NetworkTime = XRtcPsu_DateTimeToSec ( & dt1 ) ; xil_printf ( " \n \r \t \n \r " , Rtc_Psu . CalibrationValue , Rtc_Psu . OscillatorFreq ) ; XRtcPsu_SetTime ( & Rtc_Psu , NetworkTime ) ; sleep ( 10 ) ; NetworkTime = NetworkTime + 10 ; XRtcPsu_CalculateCalibration ( & Rtc_Psu , NetworkTime , OscillatorFreq ) ; Status = XRtcPsu_CfgInitialize ( & Rtc_Psu , Config , Config -> BaseAddr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } xil_printf ( " \t \n \r " , Rtc_Psu . CalibrationValue , Rtc_Psu . OscillatorFreq ) ; return XST_SUCCESS ; }
This function does a minimal set Calibration test on the XRtcPsu device.
This function does a minimal set Calibration test on the XRtcPsu device .
/*
	 * Initialize the RTC driver so that it's ready to use.
	 * Look up the configuration in the config table, then initialize it.
	 */ /* Check hardware build. */ /* Set RTC time to user input time */ /*
	 * For time accuracy RTC module need to be calibrated at regular interval,
	 * new calibration value calculation requires rtc set time, rtc current time
	 * and system/network time. For reference 10Sec system/network time interval
	 * used for finding new calibration values.
	 */