enable running asyncio

This commit is contained in:
Dan Halbert 2021-11-01 16:02:11 -04:00
parent a69496b0e7
commit b01e2d6674
3 changed files with 30 additions and 4 deletions

View File

@ -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

View File

@ -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.

View File

@ -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)