From 52784bf5951b6b76cf2c3125a7b78bcfef0553c3 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 4 Oct 2016 21:20:47 +0300 Subject: [PATCH] esp8266/modmachine: idle(): Return number of CPU cycles spent idling. Useful to better understand esp8266 inner workings and compare behavior in different cases. --- esp8266/modmachine.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/esp8266/modmachine.c b/esp8266/modmachine.c index 8a81cba53a..0ab3c122b7 100644 --- a/esp8266/modmachine.c +++ b/esp8266/modmachine.c @@ -86,8 +86,10 @@ STATIC mp_obj_t machine_unique_id(void) { STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id); STATIC mp_obj_t machine_idle(void) { + uint32_t t = mp_hal_ticks_cpu(); asm("waiti 0"); - return mp_const_none; + t = mp_hal_ticks_cpu() - t; + return MP_OBJ_NEW_SMALL_INT(t); } STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle);