create a last sntp update ts function

This commit is contained in:
Rutger Huijgen 2020-05-01 17:01:35 +02:00
parent 3324e61d9f
commit 566b0b6ac2
2 changed files with 13 additions and 0 deletions

View file

@ -67,5 +67,7 @@ void sntp_set_update_delay(uint32_t ms);
*/
void sntp_update_rtc(time_t t, uint32_t us);
time_t sntp_last_update_ts(void);
#endif /* _SNTP_H_ */

View file

@ -35,6 +35,8 @@
// Calibration value
#define cal (RTC.SCRATCH[3])
static time_t _sntp_update_ts = 0;
// To protect access to the above.
static SemaphoreHandle_t sntp_sem = NULL;
@ -113,6 +115,7 @@ void sntp_update_rtc(time_t t, uint32_t us) {
uint32_t tim = TIMER_COUNT;
tim_ref = tim;
sntp_base = sntp_correct;
_sntp_update_ts = t;
#ifndef SKIP_DIAGNOSTICS
// Assume the difference does not overflow in which case
// wrapping of the RTC timer still yields a good difference.
@ -125,3 +128,11 @@ void sntp_update_rtc(time_t t, uint32_t us) {
SNTP_LOGD("SNTP RTC Adjust: drift = %d usec, cal = %d", (int)(sntp_correct - sntp_current), cal);
}
time_t sntp_last_update_ts(void) {
time_t ts;
xSemaphoreTake(sntp_sem, portMAX_DELAY);
ts = _sntp_update_ts;
xSemaphoreGive(sntp_sem);
return ts;
}