Skip to content

Commit 2e56dda

Browse files
committed
Merge branch 'feature/modify_log_time_unit' into 'master'
Modify log time unit from "s" to "ms" See merge request sdk/ESP8266_RTOS_SDK!367
2 parents dd54592 + 3521271 commit 2e56dda

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

components/log/log.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ static const char s_log_prefix[ESP_LOG_MAX] = {
4949
'V', // ESP_LOG_VERBOSE
5050
};
5151

52+
static uint32_t IRAM_ATTR esp_log_early_timestamp()
53+
{
54+
return xthal_get_ccount() / (80 * 1000);
55+
}
56+
5257
#ifndef BOOTLOADER_BUILD
5358
static _lock_t s_lock;
5459
static putchar_like_t s_putchar_func = &putchar;
@@ -66,19 +71,10 @@ static int esp_log_write_str(const char *s)
6671

6772
static uint32_t esp_log_timestamp()
6873
{
69-
time_t t;
70-
71-
t = time(NULL);
72-
73-
return t;
74+
return clock() * (1000 / CLOCKS_PER_SEC) + esp_log_early_timestamp() % (1000 / CLOCKS_PER_SEC);
7475
}
7576
#endif
7677

77-
static uint32_t IRAM_ATTR esp_log_early_timestamp()
78-
{
79-
return xthal_get_ccount() / (80 * 1000);
80-
}
81-
8278
/**
8379
* @brief Write message into the log at system startup or critical state
8480
*/

components/newlib/Makefile.projbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CFLAGS += -D_CLOCKS_PER_SEC_=CONFIG_FREERTOS_HZ

components/newlib/newlib/port/time.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414

1515
#include <stdint.h>
1616
#include <reent.h>
17+
#include <sys/times.h>
1718
#include <sys/time.h>
1819

1920
#include "esp_system.h"
2021
#include "esp_timer.h"
2122

2223
#include "FreeRTOS.h"
24+
#include "task.h"
2325

2426
extern uint32_t esp_get_time();
2527

@@ -129,3 +131,13 @@ int settimeofday(const struct timeval* tv, const struct timezone* tz)
129131

130132
return 0;
131133
}
134+
135+
clock_t _times_r(struct _reent *r, struct tms *tms)
136+
{
137+
tms->tms_utime = xTaskGetTickCount();
138+
tms->tms_stime = 0;
139+
tms->tms_cutime = 0;
140+
tms->tms_cstime = 0;
141+
142+
return 0;
143+
}

0 commit comments

Comments
 (0)