mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 12:14:32 +02:00
time: Fix gettimeofday for ESP32-S3
This commit is contained in:
committed by
Angus Gratton
parent
a416452657
commit
9386cafbc3
@@ -523,14 +523,17 @@ menu "ESP32-specific"
|
|||||||
|
|
||||||
config ESP32_TIME_SYSCALL_USE_RTC_FRC1
|
config ESP32_TIME_SYSCALL_USE_RTC_FRC1
|
||||||
bool "RTC and high-resolution timer"
|
bool "RTC and high-resolution timer"
|
||||||
select ESP_TIMER_RTC_USE
|
select ESP_TIME_FUNCS_USE_RTC_TIMER
|
||||||
|
select ESP_TIME_FUNCS_USE_ESP_TIMER
|
||||||
config ESP32_TIME_SYSCALL_USE_RTC
|
config ESP32_TIME_SYSCALL_USE_RTC
|
||||||
bool "RTC"
|
bool "RTC"
|
||||||
select ESP_TIMER_RTC_USE
|
select ESP_TIME_FUNCS_USE_RTC_TIMER
|
||||||
config ESP32_TIME_SYSCALL_USE_FRC1
|
config ESP32_TIME_SYSCALL_USE_FRC1
|
||||||
bool "High-resolution timer"
|
bool "High-resolution timer"
|
||||||
|
select ESP_TIME_FUNCS_USE_ESP_TIMER
|
||||||
config ESP32_TIME_SYSCALL_USE_NONE
|
config ESP32_TIME_SYSCALL_USE_NONE
|
||||||
bool "None"
|
bool "None"
|
||||||
|
select ESP_TIME_FUNCS_USE_NONE
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
choice ESP32_RTC_CLK_SRC
|
choice ESP32_RTC_CLK_SRC
|
||||||
|
@@ -392,14 +392,17 @@ menu "ESP32S2-specific"
|
|||||||
|
|
||||||
config ESP32S2_TIME_SYSCALL_USE_RTC_FRC1
|
config ESP32S2_TIME_SYSCALL_USE_RTC_FRC1
|
||||||
bool "RTC and high-resolution timer"
|
bool "RTC and high-resolution timer"
|
||||||
select ESP_TIMER_RTC_USE
|
select ESP_TIME_FUNCS_USE_RTC_TIMER
|
||||||
|
select ESP_TIME_FUNCS_USE_ESP_TIMER
|
||||||
config ESP32S2_TIME_SYSCALL_USE_RTC
|
config ESP32S2_TIME_SYSCALL_USE_RTC
|
||||||
bool "RTC"
|
bool "RTC"
|
||||||
select ESP_TIMER_RTC_USE
|
select ESP_TIME_FUNCS_USE_RTC_TIMER
|
||||||
config ESP32S2_TIME_SYSCALL_USE_FRC1
|
config ESP32S2_TIME_SYSCALL_USE_FRC1
|
||||||
bool "High-resolution timer"
|
bool "High-resolution timer"
|
||||||
|
select ESP_TIME_FUNCS_USE_ESP_TIMER
|
||||||
config ESP32S2_TIME_SYSCALL_USE_NONE
|
config ESP32S2_TIME_SYSCALL_USE_NONE
|
||||||
bool "None"
|
bool "None"
|
||||||
|
select ESP_TIME_FUNCS_USE_NONE
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
choice ESP32S2_RTC_CLK_SRC
|
choice ESP32S2_RTC_CLK_SRC
|
||||||
|
@@ -430,14 +430,17 @@ menu "ESP32S3-Specific"
|
|||||||
|
|
||||||
config ESP32S3_TIME_SYSCALL_USE_RTC_FRC1
|
config ESP32S3_TIME_SYSCALL_USE_RTC_FRC1
|
||||||
bool "RTC and high-resolution timer"
|
bool "RTC and high-resolution timer"
|
||||||
select ESP_TIMER_RTC_USE
|
select ESP_TIME_FUNCS_USE_RTC_TIMER
|
||||||
|
select ESP_TIME_FUNCS_USE_ESP_TIMER
|
||||||
config ESP32S3_TIME_SYSCALL_USE_RTC
|
config ESP32S3_TIME_SYSCALL_USE_RTC
|
||||||
bool "RTC"
|
bool "RTC"
|
||||||
select ESP_TIMER_RTC_USE
|
select ESP_TIME_FUNCS_USE_RTC_TIMER
|
||||||
config ESP32S3_TIME_SYSCALL_USE_FRC1
|
config ESP32S3_TIME_SYSCALL_USE_FRC1
|
||||||
bool "High-resolution timer"
|
bool "High-resolution timer"
|
||||||
|
select ESP_TIME_FUNCS_USE_ESP_TIMER
|
||||||
config ESP32S3_TIME_SYSCALL_USE_NONE
|
config ESP32S3_TIME_SYSCALL_USE_NONE
|
||||||
bool "None"
|
bool "None"
|
||||||
|
select ESP_TIME_FUNCS_USE_NONE
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
choice ESP32S3_RTC_CLK_SRC
|
choice ESP32S3_RTC_CLK_SRC
|
||||||
|
@@ -23,7 +23,7 @@ menu "Power Management"
|
|||||||
|
|
||||||
config PM_USE_RTC_TIMER_REF
|
config PM_USE_RTC_TIMER_REF
|
||||||
bool "Use RTC timer to prevent time drift (EXPERIMENTAL)"
|
bool "Use RTC timer to prevent time drift (EXPERIMENTAL)"
|
||||||
depends on (PM_ENABLE && ESP_TIMER_IMPL_FRC2 && ESP_TIMER_RTC_USE)
|
depends on (PM_ENABLE && ESP_TIMER_IMPL_FRC2 && ESP_TIME_FUNCS_USE_RTC_TIMER)
|
||||||
default n
|
default n
|
||||||
help
|
help
|
||||||
When APB clock frequency changes, high-resolution timer (esp_timer)
|
When APB clock frequency changes, high-resolution timer (esp_timer)
|
||||||
|
@@ -9,7 +9,13 @@ menu "High resolution timer (esp_timer)"
|
|||||||
This option has some effect on timer performance and the amount of memory used for timer
|
This option has some effect on timer performance and the amount of memory used for timer
|
||||||
storage, and should only be used for debugging/testing purposes.
|
storage, and should only be used for debugging/testing purposes.
|
||||||
|
|
||||||
config ESP_TIMER_RTC_USE # [refactor-todo] remove when timekeeping and persistence are separate
|
config ESP_TIME_FUNCS_USE_RTC_TIMER # [refactor-todo] remove when timekeeping and persistence are separate
|
||||||
|
bool
|
||||||
|
|
||||||
|
config ESP_TIME_FUNCS_USE_ESP_TIMER # [refactor-todo] remove when timekeeping and persistence are separate
|
||||||
|
bool
|
||||||
|
|
||||||
|
config ESP_TIME_FUNCS_USE_NONE # [refactor-todo] remove when timekeeping and persistence are separate
|
||||||
bool
|
bool
|
||||||
|
|
||||||
config ESP_TIMER_TASK_STACK_SIZE
|
config ESP_TIMER_TASK_STACK_SIZE
|
||||||
|
@@ -36,17 +36,12 @@
|
|||||||
#include "esp32/rtc.h"
|
#include "esp32/rtc.h"
|
||||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||||
#include "esp32s2/rtc.h"
|
#include "esp32s2/rtc.h"
|
||||||
|
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||||
|
#include "esp32s3/rtc.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
#if defined( CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 ) || \
|
|
||||||
defined( CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 ) || \
|
|
||||||
defined( CONFIG_ESP32S2_TIME_SYSCALL_USE_FRC1 ) || \
|
|
||||||
defined( CONFIG_ESP32S2_TIME_SYSCALL_USE_RTC_FRC1 )
|
|
||||||
#define WITH_FRC 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_ESP_TIMER_PROFILING
|
#ifdef CONFIG_ESP_TIMER_PROFILING
|
||||||
#define WITH_PROFILING 1
|
#define WITH_PROFILING 1
|
||||||
#endif
|
#endif
|
||||||
@@ -396,7 +391,7 @@ esp_err_t esp_timer_init(void)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if WITH_FRC
|
#if CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER
|
||||||
// [refactor-todo] this logic, "esp_rtc_get_time_us() - g_startup_time", is also
|
// [refactor-todo] this logic, "esp_rtc_get_time_us() - g_startup_time", is also
|
||||||
// the weak definition of esp_system_get_time; find a way to remove this duplication.
|
// the weak definition of esp_system_get_time; find a way to remove this duplication.
|
||||||
esp_timer_private_advance(esp_rtc_get_time_us() - g_startup_time);
|
esp_timer_private_advance(esp_rtc_get_time_us() - g_startup_time);
|
||||||
@@ -531,7 +526,7 @@ int64_t IRAM_ATTR esp_timer_get_next_alarm(void)
|
|||||||
|
|
||||||
// Provides strong definition for system time functions relied upon
|
// Provides strong definition for system time functions relied upon
|
||||||
// by core components.
|
// by core components.
|
||||||
#if WITH_FRC
|
#if CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER
|
||||||
int64_t IRAM_ATTR esp_system_get_time(void)
|
int64_t IRAM_ATTR esp_system_get_time(void)
|
||||||
{
|
{
|
||||||
return esp_timer_get_time();
|
return esp_timer_get_time();
|
||||||
|
@@ -296,7 +296,7 @@ menu "mbedTLS"
|
|||||||
|
|
||||||
config MBEDTLS_HAVE_TIME
|
config MBEDTLS_HAVE_TIME
|
||||||
bool "Enable mbedtls time"
|
bool "Enable mbedtls time"
|
||||||
depends on !ESP32_TIME_SYSCALL_USE_NONE
|
depends on !ESP_TIME_FUNCS_USE_NONE
|
||||||
default y
|
default y
|
||||||
help
|
help
|
||||||
System has time.h and time().
|
System has time.h and time().
|
||||||
|
@@ -41,69 +41,55 @@
|
|||||||
#include "esp32s3/rtc.h"
|
#include "esp32s3/rtc.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined( CONFIG_ESP32_TIME_SYSCALL_USE_RTC ) \
|
|
||||||
|| defined( CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 ) \
|
|
||||||
|| defined( CONFIG_ESP32S2_TIME_SYSCALL_USE_RTC ) \
|
|
||||||
|| defined( CONFIG_ESP32S2_TIME_SYSCALL_USE_RTC_FRC1 ) \
|
|
||||||
|| defined( CONFIG_ESP32S3_TIME_SYSCALL_USE_RTC ) \
|
|
||||||
|| defined( CONFIG_ESP32S3_TIME_SYSCALL_USE_RTC_FRC1 )
|
|
||||||
#define WITH_RTC 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined( CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 ) \
|
|
||||||
|| defined( CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 ) \
|
|
||||||
|| defined( CONFIG_ESP32S2_TIME_SYSCALL_USE_FRC1 ) \
|
|
||||||
|| defined( CONFIG_ESP32S2_TIME_SYSCALL_USE_RTC_FRC1 )
|
|
||||||
#define WITH_FRC 1
|
|
||||||
#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_FRC)
|
#if defined(CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER) && defined(CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER)
|
||||||
uint64_t s_microseconds_offset;
|
uint64_t s_microseconds_offset;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WITH_RTC
|
#ifndef CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER
|
||||||
static uint64_t s_boot_time; // when RTC is used to persist time, two RTC_STORE registers are used to store boot time instead
|
static uint64_t s_boot_time; // when RTC is used to persist time, two RTC_STORE registers are used to store boot time instead
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static _lock_t s_boot_time_lock;
|
static _lock_t s_boot_time_lock;
|
||||||
|
|
||||||
#if defined( WITH_FRC ) || defined( WITH_RTC )
|
#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)
|
uint64_t esp_time_impl_get_time_since_boot(void)
|
||||||
{
|
{
|
||||||
uint64_t microseconds = 0;
|
uint64_t microseconds = 0;
|
||||||
|
|
||||||
#ifdef WITH_FRC
|
#ifdef CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER
|
||||||
#ifdef WITH_RTC
|
#ifdef CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER
|
||||||
microseconds = s_microseconds_offset + esp_system_get_time();
|
microseconds = s_microseconds_offset + esp_system_get_time();
|
||||||
#else
|
#else
|
||||||
microseconds = esp_system_get_time();
|
microseconds = esp_system_get_time();
|
||||||
#endif // WITH_RTC
|
#endif // CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER
|
||||||
#elif defined(WITH_RTC)
|
#elif defined(CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER)
|
||||||
microseconds = esp_rtc_get_time_us();
|
microseconds = esp_rtc_get_time_us();
|
||||||
#endif // WITH_FRC
|
#endif // CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER
|
||||||
return microseconds;
|
return microseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t esp_time_impl_get_time(void)
|
uint64_t esp_time_impl_get_time(void)
|
||||||
{
|
{
|
||||||
uint64_t microseconds = 0;
|
uint64_t microseconds = 0;
|
||||||
#if defined( WITH_FRC )
|
#if defined( CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER )
|
||||||
microseconds = esp_system_get_time();
|
microseconds = esp_system_get_time();
|
||||||
#elif defined( WITH_RTC )
|
#elif defined( CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER )
|
||||||
microseconds = esp_rtc_get_time_us();
|
microseconds = esp_rtc_get_time_us();
|
||||||
#endif // WITH_FRC
|
#endif // CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER
|
||||||
return microseconds;
|
return microseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // defined( WITH_FRC ) || defined( WITH_RTC )
|
#endif // defined( CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER ) || defined( CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER )
|
||||||
|
|
||||||
|
|
||||||
void esp_time_impl_set_boot_time(uint64_t time_us)
|
void esp_time_impl_set_boot_time(uint64_t time_us)
|
||||||
{
|
{
|
||||||
_lock_acquire(&s_boot_time_lock);
|
_lock_acquire(&s_boot_time_lock);
|
||||||
#ifdef WITH_RTC
|
#ifdef CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER
|
||||||
REG_WRITE(RTC_BOOT_TIME_LOW_REG, (uint32_t) (time_us & 0xffffffff));
|
REG_WRITE(RTC_BOOT_TIME_LOW_REG, (uint32_t) (time_us & 0xffffffff));
|
||||||
REG_WRITE(RTC_BOOT_TIME_HIGH_REG, (uint32_t) (time_us >> 32));
|
REG_WRITE(RTC_BOOT_TIME_HIGH_REG, (uint32_t) (time_us >> 32));
|
||||||
#else
|
#else
|
||||||
@@ -114,7 +100,7 @@ void esp_time_impl_set_boot_time(uint64_t time_us)
|
|||||||
|
|
||||||
uint64_t esp_clk_rtc_time(void)
|
uint64_t esp_clk_rtc_time(void)
|
||||||
{
|
{
|
||||||
#ifdef WITH_RTC
|
#ifdef CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER
|
||||||
return esp_rtc_get_time_us();
|
return esp_rtc_get_time_us();
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
@@ -125,7 +111,7 @@ uint64_t esp_time_impl_get_boot_time(void)
|
|||||||
{
|
{
|
||||||
uint64_t result;
|
uint64_t result;
|
||||||
_lock_acquire(&s_boot_time_lock);
|
_lock_acquire(&s_boot_time_lock);
|
||||||
#ifdef WITH_RTC
|
#ifdef CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER
|
||||||
result = ((uint64_t) REG_READ(RTC_BOOT_TIME_LOW_REG)) + (((uint64_t) REG_READ(RTC_BOOT_TIME_HIGH_REG)) << 32);
|
result = ((uint64_t) REG_READ(RTC_BOOT_TIME_LOW_REG)) + (((uint64_t) REG_READ(RTC_BOOT_TIME_HIGH_REG)) << 32);
|
||||||
#else
|
#else
|
||||||
result = s_boot_time;
|
result = s_boot_time;
|
||||||
@@ -162,7 +148,7 @@ uint64_t esp_rtc_get_time_us(void)
|
|||||||
|
|
||||||
void esp_clk_slowclk_cal_set(uint32_t new_cal)
|
void esp_clk_slowclk_cal_set(uint32_t new_cal)
|
||||||
{
|
{
|
||||||
#if defined(WITH_RTC)
|
#if defined(CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER)
|
||||||
/* To force monotonic time values even when clock calibration value changes,
|
/* To force monotonic time values even when clock calibration value changes,
|
||||||
* we adjust boot time, given current time and the new calibration value:
|
* we adjust boot time, given current time and the new calibration value:
|
||||||
* T = boot_time_old + cur_cal * ticks / 2^19
|
* T = boot_time_old + cur_cal * ticks / 2^19
|
||||||
@@ -176,21 +162,21 @@ void esp_clk_slowclk_cal_set(uint32_t new_cal)
|
|||||||
int64_t boot_time_diff = ticks * cal_diff / (1LL << RTC_CLK_CAL_FRACT);
|
int64_t boot_time_diff = ticks * cal_diff / (1LL << RTC_CLK_CAL_FRACT);
|
||||||
uint64_t boot_time_adj = esp_time_impl_get_boot_time() + boot_time_diff;
|
uint64_t boot_time_adj = esp_time_impl_get_boot_time() + boot_time_diff;
|
||||||
esp_time_impl_set_boot_time(boot_time_adj);
|
esp_time_impl_set_boot_time(boot_time_adj);
|
||||||
#endif // WITH_RTC
|
#endif // CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER
|
||||||
REG_WRITE(RTC_SLOW_CLK_CAL_REG, new_cal);
|
REG_WRITE(RTC_SLOW_CLK_CAL_REG, new_cal);
|
||||||
}
|
}
|
||||||
|
|
||||||
void esp_set_time_from_rtc(void)
|
void esp_set_time_from_rtc(void)
|
||||||
{
|
{
|
||||||
#if defined( WITH_FRC ) && defined( WITH_RTC )
|
#if defined( CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER ) && defined( CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER )
|
||||||
// initialize time from RTC clock
|
// initialize time from RTC clock
|
||||||
s_microseconds_offset = esp_rtc_get_time_us() - esp_system_get_time();
|
s_microseconds_offset = esp_rtc_get_time_us() - esp_system_get_time();
|
||||||
#endif // WITH_FRC && WITH_RTC
|
#endif // CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER && CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER
|
||||||
}
|
}
|
||||||
|
|
||||||
void esp_sync_counters_rtc_and_frc(void)
|
void esp_sync_counters_rtc_and_frc(void)
|
||||||
{
|
{
|
||||||
#if defined( WITH_FRC ) && defined( WITH_RTC )
|
#if defined( CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER ) && defined( CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER )
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
settimeofday(&tv, NULL);
|
settimeofday(&tv, NULL);
|
||||||
|
@@ -336,25 +336,18 @@ TEST_CASE("test time adjustment happens linearly", "[newlib][timeout=35]")
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined( CONFIG_ESP32_TIME_SYSCALL_USE_RTC ) || defined( CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 ) || defined( CONFIG_ESP32S2_TIME_SYSCALL_USE_RTC ) || defined( CONFIG_ESP32S2_TIME_SYSCALL_USE_RTC_FRC1 )
|
|
||||||
#define WITH_RTC 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined( CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 ) || defined( CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 ) || defined( CONFIG_ESP32S2_TIME_SYSCALL_USE_FRC1 ) || defined( CONFIG_ESP32S2_TIME_SYSCALL_USE_RTC_FRC1 )
|
|
||||||
#define WITH_FRC 1
|
|
||||||
#endif
|
|
||||||
void test_posix_timers_clock (void)
|
void test_posix_timers_clock (void)
|
||||||
{
|
{
|
||||||
#ifndef _POSIX_TIMERS
|
#ifndef _POSIX_TIMERS
|
||||||
TEST_ASSERT_MESSAGE(false, "_POSIX_TIMERS - is not defined");
|
TEST_ASSERT_MESSAGE(false, "_POSIX_TIMERS - is not defined");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined( WITH_FRC )
|
#if defined( CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER )
|
||||||
printf("WITH_FRC ");
|
printf("CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER ");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined( WITH_RTC )
|
#if defined( CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER )
|
||||||
printf("WITH_RTC ");
|
printf("CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER ");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS
|
#ifdef CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS
|
||||||
@@ -371,7 +364,7 @@ void test_posix_timers_clock (void)
|
|||||||
TEST_ASSERT(clock_gettime(CLOCK_MONOTONIC, NULL) == -1);
|
TEST_ASSERT(clock_gettime(CLOCK_MONOTONIC, NULL) == -1);
|
||||||
TEST_ASSERT(clock_getres(CLOCK_MONOTONIC, NULL) == -1);
|
TEST_ASSERT(clock_getres(CLOCK_MONOTONIC, NULL) == -1);
|
||||||
|
|
||||||
#if defined( WITH_FRC ) || defined( WITH_RTC )
|
#if defined( CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER ) || defined( CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER )
|
||||||
struct timeval now = {0};
|
struct timeval now = {0};
|
||||||
now.tv_sec = 10L;
|
now.tv_sec = 10L;
|
||||||
now.tv_usec = 100000L;
|
now.tv_usec = 100000L;
|
||||||
@@ -398,7 +391,7 @@ void test_posix_timers_clock (void)
|
|||||||
TEST_ASSERT(clock_settime(CLOCK_MONOTONIC, &ts) == -1);
|
TEST_ASSERT(clock_settime(CLOCK_MONOTONIC, &ts) == -1);
|
||||||
|
|
||||||
uint64_t delta_monotonic_us = 0;
|
uint64_t delta_monotonic_us = 0;
|
||||||
#if defined( WITH_FRC )
|
#if defined( CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER )
|
||||||
|
|
||||||
TEST_ASSERT(clock_getres(CLOCK_REALTIME, &ts) == 0);
|
TEST_ASSERT(clock_getres(CLOCK_REALTIME, &ts) == 0);
|
||||||
TEST_ASSERT_EQUAL_INT(1000, ts.tv_nsec);
|
TEST_ASSERT_EQUAL_INT(1000, ts.tv_nsec);
|
||||||
@@ -410,7 +403,7 @@ void test_posix_timers_clock (void)
|
|||||||
TEST_ASSERT(delta_monotonic_us > 0 || delta_monotonic_us == 0);
|
TEST_ASSERT(delta_monotonic_us > 0 || delta_monotonic_us == 0);
|
||||||
TEST_ASSERT_INT_WITHIN(5000L, 0, delta_monotonic_us);
|
TEST_ASSERT_INT_WITHIN(5000L, 0, delta_monotonic_us);
|
||||||
|
|
||||||
#elif defined( WITH_RTC )
|
#elif defined( CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER )
|
||||||
|
|
||||||
TEST_ASSERT(clock_getres(CLOCK_REALTIME, &ts) == 0);
|
TEST_ASSERT(clock_getres(CLOCK_REALTIME, &ts) == 0);
|
||||||
TEST_ASSERT_EQUAL_INT(1000000000L / rtc_clk_slow_freq_get_hz(), ts.tv_nsec);
|
TEST_ASSERT_EQUAL_INT(1000000000L / rtc_clk_slow_freq_get_hz(), ts.tv_nsec);
|
||||||
@@ -422,7 +415,7 @@ void test_posix_timers_clock (void)
|
|||||||
TEST_ASSERT(delta_monotonic_us > 0 || delta_monotonic_us == 0);
|
TEST_ASSERT(delta_monotonic_us > 0 || delta_monotonic_us == 0);
|
||||||
TEST_ASSERT_INT_WITHIN(5000L, 0, delta_monotonic_us);
|
TEST_ASSERT_INT_WITHIN(5000L, 0, delta_monotonic_us);
|
||||||
|
|
||||||
#endif // WITH_FRC
|
#endif // CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER
|
||||||
|
|
||||||
#else
|
#else
|
||||||
struct timespec ts = {0};
|
struct timespec ts = {0};
|
||||||
@@ -433,7 +426,7 @@ void test_posix_timers_clock (void)
|
|||||||
TEST_ASSERT(clock_settime(CLOCK_MONOTONIC, &ts) == -1);
|
TEST_ASSERT(clock_settime(CLOCK_MONOTONIC, &ts) == -1);
|
||||||
TEST_ASSERT(clock_gettime(CLOCK_MONOTONIC, &ts) == -1);
|
TEST_ASSERT(clock_gettime(CLOCK_MONOTONIC, &ts) == -1);
|
||||||
TEST_ASSERT(clock_getres(CLOCK_MONOTONIC, &ts) == -1);
|
TEST_ASSERT(clock_getres(CLOCK_MONOTONIC, &ts) == -1);
|
||||||
#endif // defined( WITH_FRC ) || defined( WITH_RTC )
|
#endif // defined( CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER ) || defined( CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER )
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("test posix_timers clock_... functions", "[newlib]")
|
TEST_CASE("test posix_timers clock_... functions", "[newlib]")
|
||||||
|
@@ -42,7 +42,7 @@ _Static_assert(sizeof(time_t) == 8, "The toolchain does not support time_t wide
|
|||||||
_Static_assert(sizeof(time_t) == 4, "The toolchain supports time_t wide 64-bits. Please enable CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS.");
|
_Static_assert(sizeof(time_t) == 4, "The toolchain supports time_t wide 64-bits. Please enable CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS.");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !CONFIG_ESP32_TIME_SYSCALL_USE_NONE && !CONFIG_ESP32S2_TIME_SYSCALL_USE_NONE
|
#if !CONFIG_ESP_TIME_FUNCS_USE_NONE
|
||||||
#define IMPL_NEWLIB_TIME_FUNCS 1
|
#define IMPL_NEWLIB_TIME_FUNCS 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user