From d174b38ac092673dd4e1a4a13adcea5cdb270526 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 1 Nov 2021 16:02:11 -0400 Subject: [PATCH] enable running asyncio --- extmod/moduselect.c | 13 +++++++++---- py/circuitpy_mpconfig.h | 7 +++++++ py/circuitpy_mpconfig.mk | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/extmod/moduselect.c b/extmod/moduselect.c index 1b9617fca9..c8f5e57363 100644 --- a/extmod/moduselect.c +++ b/extmod/moduselect.c @@ -150,7 +150,7 @@ STATIC mp_obj_t select_select(size_t n_args, const mp_obj_t *args) { mp_map_deinit(&poll_map); return mp_obj_new_tuple(3, list_array); } - MICROPY_EVENT_POLL_HOOK + RUN_BACKGROUND_TASKS; } } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_select_select_obj, 3, 4, select_select); @@ -229,7 +229,7 @@ STATIC mp_uint_t poll_poll_internal(uint n_args, const mp_obj_t *args) { if (n_ready > 0 || (timeout != (mp_uint_t)-1 && mp_hal_ticks_ms() - start_tick >= timeout)) { break; } - MICROPY_EVENT_POLL_HOOK + RUN_BACKGROUND_TASKS; } return n_ready; @@ -318,10 +318,13 @@ STATIC MP_DEFINE_CONST_DICT(poll_locals_dict, poll_locals_dict_table); STATIC const mp_obj_type_t mp_type_poll = { { &mp_type_type }, + .flags = MP_TYPE_FLAG_EXTENDED, .name = MP_QSTR_poll, - .getiter = mp_identity_getiter, - .iternext = poll_iternext, .locals_dict = (void *)&poll_locals_dict, + MP_TYPE_EXTENDED_FIELDS( + .getiter = mp_identity_getiter, + .iternext = poll_iternext, + ), }; // poll() @@ -354,4 +357,6 @@ const mp_obj_module_t mp_module_uselect = { .globals = (mp_obj_dict_t *)&mp_module_select_globals, }; +MP_REGISTER_MODULE(MP_QSTR_select, mp_module_uselect, MICROPY_PY_USELECT); + #endif // MICROPY_PY_USELECT diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 3c6d5c6110..ad5797b4d8 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -45,6 +45,13 @@ // free bytes. // #define MICROPY_ALLOC_PARSE_RULE_INIT (64) +// These critical-section macros are used only a few places in MicroPython, but +// we need to provide actual implementations. +extern void common_hal_mcu_disable_interrupts(void); +extern void common_hal_mcu_enable_interrupts(void); +#define MICROPY_BEGIN_ATOMIC_SECTION() (common_hal_mcu_disable_interrupts(), 0) +#define MICROPY_END_ATOMIC_SECTION(state) ((void)state, common_hal_mcu_enable_interrupts()) + // Sorted alphabetically for easy finding. // // default is 128; consider raising to reduce fragmentation. diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 04f0778290..ccb9daf5eb 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -36,6 +36,20 @@ CFLAGS += -DCIRCUITPY_FULL_BUILD=$(CIRCUITPY_FULL_BUILD) MICROPY_PY_ASYNC_AWAIT ?= $(CIRCUITPY_FULL_BUILD) CFLAGS += -DMICROPY_PY_ASYNC_AWAIT=$(MICROPY_PY_ASYNC_AWAIT) +# uasyncio +# By default, include uasyncio if async/await are available. +MICROPY_PY_UASYNCIO ?= $(MICROPY_PY_ASYNC_AWAIT) +CFLAGS += -DMICROPY_PY_UASYNCIO=$(MICROPY_PY_UASYNCIO) + +# uasyncio normally needs select +MICROPY_PY_USELECT ?= $(MICROPY_PY_UASYNCIO) +CFLAGS += -DMICROPY_PY_USELECT=$(MICROPY_PY_USELECT) + +# enable select.select if select is enabled. +MICROPY_PY_USELECT_SELECT ?= $(MICROPY_PY_USELECT) +CFLAGS += -DMICROPY_PY_USELECT_SELECT=$(MICROPY_PY_USELECT_SELECT) + + CIRCUITPY_AESIO ?= $(CIRCUITPY_FULL_BUILD) CFLAGS += -DCIRCUITPY_AESIO=$(CIRCUITPY_AESIO)