diff --git a/extras/sntp/sntp.h b/extras/sntp/sntp.h index 4e20f0c..3863c1c 100644 --- a/extras/sntp/sntp.h +++ b/extras/sntp/sntp.h @@ -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_ */ diff --git a/extras/sntp/sntp_fun.c b/extras/sntp/sntp_fun.c index 60a749b..9b952d7 100644 --- a/extras/sntp/sntp_fun.c +++ b/extras/sntp/sntp_fun.c @@ -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; +}