time: rename time source option from FRC to "high-resolution timer"
libc time function now rely on esp_timer_get_time as the source of high-resolution time, rather than FRC1 timer. Internally, on the ESP32 esp_timer implementation uses FRC2 timer. - Change help text and labels in Kconfig to use "high-resolution timer" instead of FRC1. Keep existing Kconfig option name to be backwards compatible. - Change references to "FRC1" in the source code to "FRC".
This commit is contained in:
parent
50b710d267
commit
e8fbd6e288
2 changed files with 29 additions and 25 deletions
|
@ -631,6 +631,10 @@ config BROWNOUT_DET_LVL
|
||||||
default 7 if BROWNOUT_DET_LVL_SEL_7
|
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
|
choice ESP32_TIME_SYSCALL
|
||||||
prompt "Timers used for gettimeofday function"
|
prompt "Timers used for gettimeofday function"
|
||||||
default ESP32_TIME_SYSCALL_USE_RTC_FRC1
|
default ESP32_TIME_SYSCALL_USE_RTC_FRC1
|
||||||
|
@ -638,12 +642,12 @@ choice ESP32_TIME_SYSCALL
|
||||||
This setting defines which hardware timers are used to
|
This setting defines which hardware timers are used to
|
||||||
implement 'gettimeofday' and 'time' functions in C library.
|
implement 'gettimeofday' and 'time' functions in C library.
|
||||||
|
|
||||||
- If only FRC1 timer is used, gettimeofday will provide time at
|
- If both high-resolution and RTC timers are used, timekeeping will
|
||||||
microsecond resolution. Time will not be preserved when going
|
|
||||||
into deep sleep mode.
|
|
||||||
- If both FRC1 and RTC timers are used, timekeeping will
|
|
||||||
continue in deep sleep. Time will be reported at 1 microsecond
|
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
|
- If only RTC timer is used, timekeeping will continue in
|
||||||
deep sleep, but time will be measured at 6.(6) microsecond
|
deep sleep, but time will be measured at 6.(6) microsecond
|
||||||
resolution. Also the gettimeofday function itself may take
|
resolution. Also the gettimeofday function itself may take
|
||||||
|
@ -653,12 +657,12 @@ choice ESP32_TIME_SYSCALL
|
||||||
- When RTC is used for timekeeping, two RTC_STORE registers are
|
- When RTC is used for timekeeping, two RTC_STORE registers are
|
||||||
used to keep time in deep sleep mode.
|
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
|
config ESP32_TIME_SYSCALL_USE_RTC
|
||||||
bool "RTC"
|
bool "RTC"
|
||||||
config ESP32_TIME_SYSCALL_USE_RTC_FRC1
|
|
||||||
bool "RTC and FRC1"
|
|
||||||
config ESP32_TIME_SYSCALL_USE_FRC1
|
config ESP32_TIME_SYSCALL_USE_FRC1
|
||||||
bool "FRC1"
|
bool "High-resolution timer"
|
||||||
config ESP32_TIME_SYSCALL_USE_NONE
|
config ESP32_TIME_SYSCALL_USE_NONE
|
||||||
bool "None"
|
bool "None"
|
||||||
endchoice
|
endchoice
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined( CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 ) || defined( CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 )
|
#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
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_RTC
|
#ifdef WITH_RTC
|
||||||
|
@ -72,21 +72,21 @@ static uint64_t get_rtc_time_us()
|
||||||
// s_boot_time: time from Epoch to the first boot time
|
// s_boot_time: time from Epoch to the first boot time
|
||||||
#ifdef WITH_RTC
|
#ifdef WITH_RTC
|
||||||
// when RTC is used to persist time, two RTC_STORE registers are used to store boot time
|
// 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;
|
static uint64_t s_boot_time;
|
||||||
#endif // WITH_RTC
|
#endif // WITH_RTC
|
||||||
|
|
||||||
#if defined(WITH_RTC) || defined(WITH_FRC1)
|
#if defined(WITH_RTC) || defined(WITH_FRC)
|
||||||
static _lock_t s_boot_time_lock;
|
static _lock_t s_boot_time_lock;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Offset between FRC timer and the RTC.
|
// Offset between FRC timer and the RTC.
|
||||||
// Initialized after reset or light sleep.
|
// 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;
|
uint64_t s_microseconds_offset;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WITH_RTC) || defined(WITH_FRC1)
|
#if defined(WITH_RTC) || defined(WITH_FRC)
|
||||||
static void set_boot_time(uint64_t time_us)
|
static void set_boot_time(uint64_t time_us)
|
||||||
{
|
{
|
||||||
_lock_acquire(&s_boot_time_lock);
|
_lock_acquire(&s_boot_time_lock);
|
||||||
|
@ -111,7 +111,7 @@ static uint64_t get_boot_time()
|
||||||
_lock_release(&s_boot_time_lock);
|
_lock_release(&s_boot_time_lock);
|
||||||
return result;
|
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_clk_slowclk_cal_set(uint32_t new_cal)
|
||||||
|
@ -141,10 +141,10 @@ uint32_t esp_clk_slowclk_cal_get()
|
||||||
|
|
||||||
void esp_set_time_from_rtc()
|
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
|
// initialize time from RTC clock
|
||||||
s_microseconds_offset = get_rtc_time_us() - esp_timer_get_time();
|
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)
|
uint64_t esp_clk_rtc_time(void)
|
||||||
|
@ -168,11 +168,11 @@ clock_t IRAM_ATTR _times_r(struct _reent *r, struct tms *ptms)
|
||||||
return (clock_t) tv.tv_sec;
|
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()
|
static uint64_t get_time_since_boot()
|
||||||
{
|
{
|
||||||
uint64_t microseconds = 0;
|
uint64_t microseconds = 0;
|
||||||
#ifdef WITH_FRC1
|
#ifdef WITH_FRC
|
||||||
#ifdef WITH_RTC
|
#ifdef WITH_RTC
|
||||||
microseconds = s_microseconds_offset + esp_timer_get_time();
|
microseconds = s_microseconds_offset + esp_timer_get_time();
|
||||||
#else
|
#else
|
||||||
|
@ -180,15 +180,15 @@ static uint64_t get_time_since_boot()
|
||||||
#endif // WITH_RTC
|
#endif // WITH_RTC
|
||||||
#elif defined(WITH_RTC)
|
#elif defined(WITH_RTC)
|
||||||
microseconds = get_rtc_time_us();
|
microseconds = get_rtc_time_us();
|
||||||
#endif // WITH_FRC1
|
#endif // WITH_FRC
|
||||||
return microseconds;
|
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)
|
int IRAM_ATTR _gettimeofday_r(struct _reent *r, struct timeval *tv, void *tz)
|
||||||
{
|
{
|
||||||
(void) tz;
|
(void) tz;
|
||||||
#if defined( WITH_FRC1 ) || defined( WITH_RTC )
|
#if defined( WITH_FRC ) || defined( WITH_RTC )
|
||||||
if (tv) {
|
if (tv) {
|
||||||
uint64_t microseconds = get_boot_time() + get_time_since_boot();
|
uint64_t microseconds = get_boot_time() + get_time_since_boot();
|
||||||
tv->tv_sec = microseconds / 1000000;
|
tv->tv_sec = microseconds / 1000000;
|
||||||
|
@ -198,13 +198,13 @@ int IRAM_ATTR _gettimeofday_r(struct _reent *r, struct timeval *tv, void *tz)
|
||||||
#else
|
#else
|
||||||
__errno_r(r) = ENOSYS;
|
__errno_r(r) = ENOSYS;
|
||||||
return -1;
|
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)
|
int settimeofday(const struct timeval *tv, const struct timezone *tz)
|
||||||
{
|
{
|
||||||
(void) tz;
|
(void) tz;
|
||||||
#if defined( WITH_FRC1 ) || defined( WITH_RTC )
|
#if defined( WITH_FRC ) || defined( WITH_RTC )
|
||||||
if (tv) {
|
if (tv) {
|
||||||
uint64_t now = ((uint64_t) tv->tv_sec) * 1000000LL + tv->tv_usec;
|
uint64_t now = ((uint64_t) tv->tv_sec) * 1000000LL + tv->tv_usec;
|
||||||
uint64_t since_boot = get_time_since_boot();
|
uint64_t since_boot = get_time_since_boot();
|
||||||
|
@ -239,7 +239,7 @@ unsigned int sleep(unsigned int seconds)
|
||||||
|
|
||||||
uint32_t system_get_time(void)
|
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();
|
return get_time_since_boot();
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -250,7 +250,7 @@ uint32_t system_get_current_time(void) __attribute__((alias("system_get_time")))
|
||||||
|
|
||||||
uint32_t system_relative_time(uint32_t current_time)
|
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;
|
return get_time_since_boot() - current_time;
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue