sntp: calibrate to the ntp times rather than the system function.

The system sdk_system_rtc_clock_cali_proc() is rather noisy, so
this patch calibrates the RTC count to the NTP time responses.

An average of many calls to sdk_system_rtc_clock_cali_proc() is used
for initialization.

The system calibration value is used to limit the calibration value
computed via the ntp times, to 1/16 either way.

A 64 bit RTC counter is implemented, and used in the calculations, but
might be of some use on its own.

The ratio of the ntp time differences and the RTC count differences is
filtered a little to keep the changes relatively stable and to filter
the jitter.
This commit is contained in:
iosen 2016-07-02 00:35:59 +10:00
parent 15964efc0f
commit b1f7a0493f
3 changed files with 128 additions and 74 deletions

View file

@ -61,10 +61,9 @@ int sntp_set_servers(char *server_url[], int num_servers);
void sntp_set_update_delay(uint32_t ms);
/*
* Returns the time read from RTC counter, in seconds from Epoch. If
* us is not null, it will be filled with the microseconds.
* Returns the time read from RTC counter, in micro seconds from Epoch.
*/
time_t sntp_get_rtc_time(int32_t *us);
uint64_t sntp_get_rtc_time();
/*
* Update RTC timer. This function is called by the SNTP module each time