Skip to content

Commit 52784bf

Browse files
committed
esp8266/modmachine: idle(): Return number of CPU cycles spent idling.
Useful to better understand esp8266 inner workings and compare behavior in different cases.
1 parent addd1d3 commit 52784bf

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

esp8266/modmachine.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ STATIC mp_obj_t machine_unique_id(void) {
8686
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id);
8787

8888
STATIC mp_obj_t machine_idle(void) {
89+
uint32_t t = mp_hal_ticks_cpu();
8990
asm("waiti 0");
90-
return mp_const_none;
91+
t = mp_hal_ticks_cpu() - t;
92+
return MP_OBJ_NEW_SMALL_INT(t);
9193
}
9294
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle);
9395

0 commit comments

Comments
 (0)