default 7 if BROWNOUT_DET_LVL_SEL_7
+# Note about the use of "FRC1" name: currently FRC1 timer is not used for
+# high resolution timekeeping anymore. Instead the esp_timer API, implemented
+# using FRC2 timer, is used.
+# FRC1 name in the option name is kept for compatibility.
choice ESP32_TIME_SYSCALL
prompt "Timers used for gettimeofday function"
default ESP32_TIME_SYSCALL_USE_RTC_FRC1
This setting defines which hardware timers are used to
implement 'gettimeofday' and 'time' functions in C library.
- - If only FRC1 timer is used, gettimeofday will provide time at
- microsecond resolution. Time will not be preserved when going
- into deep sleep mode.
- - If both FRC1 and RTC timers are used, timekeeping will
+ - If both high-resolution and RTC timers are used, timekeeping will
continue in deep sleep. Time will be reported at 1 microsecond
- resolution.
+ resolution. This is the default, and the recommended option.
+ - If only high-resolution timer is used, gettimeofday will
+ provide time at microsecond resolution.
+ Time will not be preserved when going into deep sleep mode.
- If only RTC timer is used, timekeeping will continue in
deep sleep, but time will be measured at 6.(6) microsecond
resolution. Also the gettimeofday function itself may take
- When RTC is used for timekeeping, two RTC_STORE registers are
used to keep time in deep sleep mode.
+config ESP32_TIME_SYSCALL_USE_RTC_FRC1
+ bool "RTC and high-resolution timer"
config ESP32_TIME_SYSCALL_USE_RTC
bool "RTC"
-config ESP32_TIME_SYSCALL_USE_RTC_FRC1
- bool "RTC and FRC1"
config ESP32_TIME_SYSCALL_USE_FRC1
- bool "FRC1"
+ bool "High-resolution timer"
config ESP32_TIME_SYSCALL_USE_NONE
bool "None"
endchoice
#endif
#if defined( CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 ) || defined( CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 )
-#define WITH_FRC1 1
+#define WITH_FRC 1
#endif
#ifdef WITH_RTC
// s_boot_time: time from Epoch to the first boot time
#ifdef WITH_RTC
// when RTC is used to persist time, two RTC_STORE registers are used to store boot time
-#elif defined(WITH_FRC1)
+#elif defined(WITH_FRC)
static uint64_t s_boot_time;
#endif // WITH_RTC
-#if defined(WITH_RTC) || defined(WITH_FRC1)
+#if defined(WITH_RTC) || defined(WITH_FRC)
static _lock_t s_boot_time_lock;
#endif
// Offset between FRC timer and the RTC.
// Initialized after reset or light sleep.
-#if defined(WITH_RTC) && defined(WITH_FRC1)
+#if defined(WITH_RTC) && defined(WITH_FRC)
uint64_t s_microseconds_offset;
#endif
-#if defined(WITH_RTC) || defined(WITH_FRC1)
+#if defined(WITH_RTC) || defined(WITH_FRC)
static void set_boot_time(uint64_t time_us)
{
_lock_acquire(&s_boot_time_lock);
_lock_release(&s_boot_time_lock);
return result;
}
-#endif //defined(WITH_RTC) || defined(WITH_FRC1)
+#endif //defined(WITH_RTC) || defined(WITH_FRC)
void esp_clk_slowclk_cal_set(uint32_t new_cal)
void esp_set_time_from_rtc()
{
-#if defined( WITH_FRC1 ) && defined( WITH_RTC )
+#if defined( WITH_FRC ) && defined( WITH_RTC )
// initialize time from RTC clock
s_microseconds_offset = get_rtc_time_us() - esp_timer_get_time();
-#endif // WITH_FRC1 && WITH_RTC
+#endif // WITH_FRC && WITH_RTC
}
uint64_t esp_clk_rtc_time(void)
return (clock_t) tv.tv_sec;
}
-#if defined( WITH_FRC1 ) || defined( WITH_RTC )
+#if defined( WITH_FRC ) || defined( WITH_RTC )
static uint64_t get_time_since_boot()
{
uint64_t microseconds = 0;
-#ifdef WITH_FRC1
+#ifdef WITH_FRC
#ifdef WITH_RTC
microseconds = s_microseconds_offset + esp_timer_get_time();
#else
#endif // WITH_RTC
#elif defined(WITH_RTC)
microseconds = get_rtc_time_us();
-#endif // WITH_FRC1
+#endif // WITH_FRC
return microseconds;
}
-#endif // defined( WITH_FRC1 ) || defined( WITH_RTC )
+#endif // defined( WITH_FRC ) || defined( WITH_RTC )
int IRAM_ATTR _gettimeofday_r(struct _reent *r, struct timeval *tv, void *tz)
{
(void) tz;
-#if defined( WITH_FRC1 ) || defined( WITH_RTC )
+#if defined( WITH_FRC ) || defined( WITH_RTC )
if (tv) {
uint64_t microseconds = get_boot_time() + get_time_since_boot();
tv->tv_sec = microseconds / 1000000;
#else
__errno_r(r) = ENOSYS;
return -1;
-#endif // defined( WITH_FRC1 ) || defined( WITH_RTC )
+#endif // defined( WITH_FRC ) || defined( WITH_RTC )
}
int settimeofday(const struct timeval *tv, const struct timezone *tz)
{
(void) tz;
-#if defined( WITH_FRC1 ) || defined( WITH_RTC )
+#if defined( WITH_FRC ) || defined( WITH_RTC )
if (tv) {
uint64_t now = ((uint64_t) tv->tv_sec) * 1000000LL + tv->tv_usec;
uint64_t since_boot = get_time_since_boot();
uint32_t system_get_time(void)
{
-#if defined( WITH_FRC1 ) || defined( WITH_RTC )
+#if defined( WITH_FRC ) || defined( WITH_RTC )
return get_time_since_boot();
#else
return 0;
uint32_t system_relative_time(uint32_t current_time)
{
-#if defined( WITH_FRC1 ) || defined( WITH_RTC )
+#if defined( WITH_FRC ) || defined( WITH_RTC )
return get_time_since_boot() - current_time;
#else
return 0;