From 2cbf90d9fe2a0c8495f18858a0cf1e47f14a783c Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Wed, 19 Feb 2020 10:27:21 +0100 Subject: [PATCH] cpu/esp32: small fix of rtc_init for light sleep `rtc_init` is used after light sleep to update the system time from RTC timer. The fix corrects a small difference of about 230 ms which would sum up with each wakeup from light sleep. --- cpu/esp32/periph/rtc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cpu/esp32/periph/rtc.c b/cpu/esp32/periph/rtc.c index e4dbff7b85..a76f9c8ac1 100644 --- a/cpu/esp32/periph/rtc.c +++ b/cpu/esp32/periph/rtc.c @@ -101,21 +101,19 @@ static void IRAM_ATTR _rtc_timer_handler(void* arg); void rtc_init(void) { - uint64_t _rtc_time_us = _rtc_time_to_us(_rtc_get_time_raw()); + uint64_t _rtc_time = _rtc_get_time_raw(); + uint64_t _rtc_time_us = _rtc_time_to_us(_rtc_time); if (_rtc_time_init == 0 && _rtc_time_init_us == 0) { /* only set it new, if it was not set before */ - _rtc_time_init = _rtc_get_time_raw(); + _rtc_time_init = _rtc_time; _rtc_time_init_us = _rtc_time_us; - _sys_time_off_us = 0; DEBUG("%s saved rtc_init=%lld rtc_init_us=%lld\n", __func__, _rtc_time_init, _rtc_time_init_us); } - else { - _sys_time_off_us = _rtc_time_us - _rtc_time_set_us; - } + _sys_time_off_us = _rtc_time_us - _rtc_time_set_us - system_get_time_64(); _sys_time_set_us = 0; }