From efe9834313f7bafda9f7cb29ecfa5dc1c9c7e6c7 Mon Sep 17 00:00:00 2001 From: yuanjm Date: Tue, 15 Oct 2019 18:48:12 +0800 Subject: [PATCH] feat(newlib): Add macro ESP8266_TIME_SYSCALL_USE_FRC1 to enable clock_gettime function --- components/esp8266/Kconfig | 18 ++++++++++++++++++ components/newlib/newlib/port/time.c | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/components/esp8266/Kconfig b/components/esp8266/Kconfig index 1bb95ae1..b2f2d6ec 100644 --- a/components/esp8266/Kconfig +++ b/components/esp8266/Kconfig @@ -321,6 +321,24 @@ config ESP_ERR_TO_NAME_LOOKUP order to save memory but this comes at the price of sacrificing distinguishable (meaningful) output string representations. + choice ESP8266_TIME_SYSCALL + prompt "Timers used for gettimeofday function" + default ESP8266_TIME_SYSCALL_USE_FRC1 + help + This setting defines which hardware timers are used to + implement 'gettimeofday' and 'time' functions in C library. + + - If high-resolution timer is used, gettimeofday will + provide time at microsecond resolution. + Time will not be preserved when going into deep sleep mode. + - If no timers are used, gettimeofday and time functions + return -1 and set errno to ENOSYS. + + config ESP8266_TIME_SYSCALL_USE_FRC1 + bool "High-resolution timer" + config ESP8266_TIME_SYSCALL_USE_NONE + bool "None" + endchoice endmenu menu Wi-Fi diff --git a/components/newlib/newlib/port/time.c b/components/newlib/newlib/port/time.c index ad0daade..68144925 100644 --- a/components/newlib/newlib/port/time.c +++ b/components/newlib/newlib/port/time.c @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -26,6 +27,12 @@ #include "task.h" #include "driver/soc.h" +#include "sdkconfig.h" + +#ifdef CONFIG_ESP8266_TIME_SYSCALL_USE_FRC1 +#define WITH_FRC 1 +#endif + static uint64_t s_boot_time; static inline void set_boot_time(uint64_t time_us)