From 3521271f09156cba31885ba686d65cdb35b8c815 Mon Sep 17 00:00:00 2001 From: Dong Heng Date: Wed, 8 Aug 2018 13:13:59 +0800 Subject: [PATCH] feat(log): Modify log time unit from "s" to "ms" --- components/log/log.c | 16 ++++++---------- components/newlib/Makefile.projbuild | 1 + components/newlib/newlib/port/time.c | 12 ++++++++++++ 3 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 components/newlib/Makefile.projbuild diff --git a/components/log/log.c b/components/log/log.c index 66bff024..d1842192 100644 --- a/components/log/log.c +++ b/components/log/log.c @@ -49,6 +49,11 @@ static const char s_log_prefix[ESP_LOG_MAX] = { 'V', // ESP_LOG_VERBOSE }; +static uint32_t IRAM_ATTR esp_log_early_timestamp() +{ + return xthal_get_ccount() / (80 * 1000); +} + #ifndef BOOTLOADER_BUILD static _lock_t s_lock; static putchar_like_t s_putchar_func = &putchar; @@ -66,19 +71,10 @@ static int esp_log_write_str(const char *s) static uint32_t esp_log_timestamp() { - time_t t; - - t = time(NULL); - - return t; + return clock() * (1000 / CLOCKS_PER_SEC) + esp_log_early_timestamp() % (1000 / CLOCKS_PER_SEC); } #endif -static uint32_t IRAM_ATTR esp_log_early_timestamp() -{ - return xthal_get_ccount() / (80 * 1000); -} - /** * @brief Write message into the log at system startup or critical state */ diff --git a/components/newlib/Makefile.projbuild b/components/newlib/Makefile.projbuild new file mode 100644 index 00000000..733676d0 --- /dev/null +++ b/components/newlib/Makefile.projbuild @@ -0,0 +1 @@ +CFLAGS += -D_CLOCKS_PER_SEC_=CONFIG_FREERTOS_HZ diff --git a/components/newlib/newlib/port/time.c b/components/newlib/newlib/port/time.c index 7a8169b7..fc65f33c 100644 --- a/components/newlib/newlib/port/time.c +++ b/components/newlib/newlib/port/time.c @@ -14,12 +14,14 @@ #include #include +#include #include #include "esp_system.h" #include "esp_timer.h" #include "FreeRTOS.h" +#include "task.h" extern uint32_t esp_get_time(); @@ -129,3 +131,13 @@ int settimeofday(const struct timeval* tv, const struct timezone* tz) return 0; } + +clock_t _times_r(struct _reent *r, struct tms *tms) +{ + tms->tms_utime = xTaskGetTickCount(); + tms->tms_stime = 0; + tms->tms_cutime = 0; + tms->tms_cstime = 0; + + return 0; +}