Skip to content

Commit

Permalink
esp_hw_support: Fix time jump after reboot
Browse files Browse the repository at this point in the history
Closes #9448
  • Loading branch information
KonstantinKondrashov committed Nov 2, 2022
1 parent 91c60b9 commit 2c3f303
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion components/newlib/port/esp_time_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static uint64_t s_boot_time; // when RTC is used to persist time, two RTC_STORE
static _lock_t s_boot_time_lock;

static _lock_t s_esp_rtc_time_lock;
static RTC_DATA_ATTR uint64_t s_esp_rtc_time_us = 0, s_rtc_last_ticks = 0;
static RTC_NOINIT_ATTR uint64_t s_esp_rtc_time_us, s_rtc_last_ticks;

#if defined( CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER ) || defined( CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER )
uint64_t esp_time_impl_get_time_since_boot(void)
Expand Down Expand Up @@ -137,6 +137,10 @@ uint64_t esp_rtc_get_time_us(void)
{
_lock_acquire(&s_esp_rtc_time_lock);
const uint32_t cal = esp_clk_slowclk_cal_get();
if (cal == 0) {
s_esp_rtc_time_us = 0;
s_rtc_last_ticks = 0;
}
const uint64_t rtc_this_ticks = rtc_time_get();
const uint64_t ticks = rtc_this_ticks - s_rtc_last_ticks;
/* RTC counter result is up to 2^48, calibration factor is up to 2^24,
Expand Down

0 comments on commit 2c3f303

Please sign in to comment.