Skip to content

Commit e970aea

Browse files
authored
Replace millisecond timer with microsecond one for cpuload calculation (#19)
1 parent 1382e85 commit e970aea

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

.github/memsize.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
text data bss dec hex filename
2-
193480 57252 507021 757753 b8ff9 build/template.elf
2+
193528 57252 507029 757809 b9031 build/template.elf

ports/esp-idf/cpuload.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
* SPDX-License-Identifier: MIT
55
*/
66

7-
#include "libmcu/board.h"
8-
7+
#include "esp_timer.h"
98
#include "freertos/FreeRTOS.h"
109
#include "freertos/task.h"
1110

@@ -20,15 +19,15 @@ static struct cpuload {
2019

2120
void on_task_switch_in(void)
2221
{
23-
static uint32_t t0;
24-
static uint32_t sum_elapsed;
22+
static uint64_t t0;
23+
static uint64_t sum_elapsed;
2524

26-
uint32_t t1 = board_get_time_since_boot_ms();
25+
uint64_t t1 = esp_timer_get_time(); /* in microseconds */
2726
uint32_t elapsed = t1 - t0;
2827

2928
/* NOTE: count at least 1 even if the task has run for much shorter time
30-
* as millisecond unit timer used here. For fine granularity, introduce
31-
* high-resolution timer. */
29+
* as microsecond unit timer used here. For fine granularity, introduce
30+
* more high-resolution timer. */
3231
if (elapsed == 0) {
3332
elapsed = 1;
3433
}

0 commit comments

Comments
 (0)