From 7ae7adf16ad62b2042256319b4999ca756dfafb0 Mon Sep 17 00:00:00 2001 From: KonstantinKondrashov Date: Wed, 7 Oct 2020 17:39:11 +0800 Subject: [PATCH] newlib: Fix clock_getres() improves accuracy Returns not rounded value of resolution for WITH_RTC and !WITH_FRC --- components/esp_common/include/esp_private/system_internal.h | 2 +- components/esp_system/system_time.c | 2 +- components/esp_timer/src/esp_timer.c | 2 +- components/newlib/time.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/esp_common/include/esp_private/system_internal.h b/components/esp_common/include/esp_private/system_internal.h index 4f5c90e817..12d7c2db88 100644 --- a/components/esp_common/include/esp_private/system_internal.h +++ b/components/esp_common/include/esp_private/system_internal.h @@ -72,7 +72,7 @@ int64_t esp_system_get_time(void); /** * @brief Get the resolution of the time returned by `esp_system_get_time`. * - * @returns the resolution in microseconds + * @returns the resolution in nanoseconds */ uint32_t esp_system_get_time_resolution(void); diff --git a/components/esp_system/system_time.c b/components/esp_system/system_time.c index 8fae106ce8..9c1f76a855 100644 --- a/components/esp_system/system_time.c +++ b/components/esp_system/system_time.c @@ -42,5 +42,5 @@ int64_t IRAM_ATTR __attribute__((weak)) esp_system_get_time(void) uint32_t IRAM_ATTR __attribute__((weak)) esp_system_get_time_resolution(void) { - return 1000000L / rtc_clk_slow_freq_get_hz(); + return 1000000000L / rtc_clk_slow_freq_get_hz(); } \ No newline at end of file diff --git a/components/esp_timer/src/esp_timer.c b/components/esp_timer/src/esp_timer.c index c645886ecd..323cce8bc6 100644 --- a/components/esp_timer/src/esp_timer.c +++ b/components/esp_timer/src/esp_timer.c @@ -539,6 +539,6 @@ int64_t IRAM_ATTR esp_system_get_time(void) uint32_t IRAM_ATTR esp_system_get_time_resolution(void) { - return 1; + return 1000; } #endif \ No newline at end of file diff --git a/components/newlib/time.c b/components/newlib/time.c index e4f0eda085..e6b4ce9e0e 100644 --- a/components/newlib/time.c +++ b/components/newlib/time.c @@ -287,7 +287,7 @@ int clock_getres (clockid_t clock_id, struct timespec *res) } res->tv_sec = 0; - res->tv_nsec = esp_system_get_time_resolution() * 1000; + res->tv_nsec = esp_system_get_time_resolution(); return 0; #else