diff options
| author | Jim Mussared | 2020-04-07 14:42:36 +1000 |
|---|---|---|
| committer | Damien George | 2020-04-29 16:37:46 +1000 |
| commit | cb5994d96e45f26fab4abf5b52ea0f419a060641 (patch) | |
| tree | 817c5d0c012dbee80a3c6c4b1f7d0cafbc0ac4ed | |
| parent | 4fa6d939d653b257341ace6ac8c168564549e4ac (diff) | |
unix/modmachine: Add machine.idle(), implemented using sched_yield.
Also add a definition of MICROPY_EVENT_POLL_HOOK so the unix port can build
against modules that require this.
| -rw-r--r-- | ports/unix/modmachine.c | 12 | ||||
| -rw-r--r-- | ports/unix/mpconfigport.h | 5 |
2 files changed, 17 insertions, 0 deletions
diff --git a/ports/unix/modmachine.c b/ports/unix/modmachine.c index d9952c540..a6eb8c01e 100644 --- a/ports/unix/modmachine.c +++ b/ports/unix/modmachine.c @@ -77,6 +77,14 @@ uintptr_t mod_machine_mem_get_addr(mp_obj_t addr_o, uint align) { return addr; } +#ifdef MICROPY_UNIX_MACHINE_IDLE +STATIC mp_obj_t machine_idle(void) { + MICROPY_UNIX_MACHINE_IDLE + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle); +#endif + STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) }, @@ -84,6 +92,10 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_mem16), MP_ROM_PTR(&machine_mem16_obj) }, { MP_ROM_QSTR(MP_QSTR_mem32), MP_ROM_PTR(&machine_mem32_obj) }, + #ifdef MICROPY_UNIX_MACHINE_IDLE + { MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&machine_idle_obj) }, + #endif + { MP_ROM_QSTR(MP_QSTR_PinBase), MP_ROM_PTR(&machine_pinbase_type) }, { MP_ROM_QSTR(MP_QSTR_Signal), MP_ROM_PTR(&machine_signal_type) }, #if MICROPY_PY_MACHINE_PULSE diff --git a/ports/unix/mpconfigport.h b/ports/unix/mpconfigport.h index 301917a61..b23b6ce47 100644 --- a/ports/unix/mpconfigport.h +++ b/ports/unix/mpconfigport.h @@ -349,4 +349,9 @@ void mp_unix_mark_exec(void); #define MICROPY_END_ATOMIC_SECTION(x) (void)x; mp_thread_unix_end_atomic_section() #endif +#define MICROPY_EVENT_POLL_HOOK mp_hal_delay_us(500); + +#include <sched.h> +#define MICROPY_UNIX_MACHINE_IDLE sched_yield(); + #endif // MICROPY_UNIX_MINIMAL |
