Ok...
What I did and what I understand:
Code: Select all
#include "soc/rtc_cntl_reg.h"
LVGL_Timer = xTimerCreate("LVGL_Timer", pdMS_TO_TICKS(128000), pdTRUE, (void *)0, LVGL_Timer_Callback);
extern uint32_t last_read;
SET_PERI_REG_MASK(RTC_CNTL_TIME_UPDATE_REG, RTC_CNTL_TIME_UPDATE);
last_read = READ_PERI_REG(RTC_CNTL_TIME0_REG);
xTimerStart(LVGL_Timer, 0);
Code: Select all
uint32_t last_read = 0;
//===================================================================================================================
void LVGL_Timer_Callback(TimerHandle_t xTimer)
{
//---
SET_PERI_REG_MASK(RTC_CNTL_TIME_UPDATE_REG, RTC_CNTL_TIME_UPDATE);
uint32_t rtc_timestamp_low = READ_PERI_REG(RTC_CNTL_TIME0_REG);
uint32_t rtc_timestamp_high = READ_PERI_REG(RTC_CNTL_TIME1_REG);
time_t rtc_epoch;
time(&rtc_epoch);
Serial.printf("\n==========================================================\n");
Serial.printf("rtc_timestamp_low = %d\n", rtc_timestamp_low);
Serial.printf("rtc_timestamp_high = %d\n", rtc_timestamp_high);
Serial.printf("RTC value of time_t rtc_epoch = %d\n", rtc_epoch);
Serial.printf("Ticks per seconds = %d\n", ((rtc_timestamp_low - last_read) >> 7));
Serial.printf("==========================================================\n");
last_read = rtc_timestamp_low;
//---
}
//---
Output terminal:
==========================================================
rtc_timestamp_low = 1084964449
rtc_timestamp_high = 0
RTC value of time_t rtc_epoch = 1021133799
Ticks per seconds = 130399
==========================================================
==========================================================
rtc_timestamp_low = 1101659100
rtc_timestamp_high = 0
RTC value of time_t rtc_epoch = 1021133927
Ticks per seconds = 130426
==========================================================
==========================================================
rtc_timestamp_low = 1118352170
rtc_timestamp_high = 0
RTC value of time_t rtc_epoch = 1021134055
Ticks per seconds = 130414
==========================================================
In the ESP32 doesn't exist physically RTC register. Here exist 48bit counter of low speed clk which after reset is choosed internal low speed clk:
Code: Select all
// On esp32s3, RC_SLOW_CLK has a freq of ~136kHz
#define SOC_CLK_RC_SLOW_FREQ_APPROX 136000
// '150K' does not mean the actual freq, it represents the clock source is RC_SLOW_CLK. RC_SLOW_CLK has a freq of ~150kHz only on esp32.
#define RTC_SLOW_CLK_FREQ_150K SOC_CLK_RC_SLOW_FREQ_APPROX
And in the ROM is created programmatically RTC and all POSIX functions like time(), mktime(), settimeofday() and so on... these functions are build and working with this programming make RTC.
High 16bits of low speed clk timer will increase after arround 9,15hours.
Completly another way and subject it's put the epoch time in the (virtual) RTC registers or update (increase) it after every one second all the time, what is doing by procedures implemented in ROM.
After reset these two rtc low speed clock registers are set as "0". These two registers only counting jitter low speed RTC clock. They are not directly RTC.