diff --git a/extmod/moduasyncio.c b/extmod/moduasyncio.c index 1f5cc618d0..185f76a3fe 100644 --- a/extmod/moduasyncio.c +++ b/extmod/moduasyncio.c @@ -28,6 +28,7 @@ #include "py/smallint.h" #include "py/pairheap.h" #include "py/mphal.h" +#include "shared-bindings/supervisor/__init__.h" #if MICROPY_PY_UASYNCIO @@ -63,15 +64,16 @@ STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, si /******************************************************************************/ // Ticks for task ordering in pairing heap -STATIC mp_obj_t ticks(void) { - return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1)); -} +#define _TICKS_PERIOD (1lu << 29) +#define _TICKS_MAX (_TICKS_PERIOD - 1) +#define _TICKS_HALFPERIOD (_TICKS_PERIOD >> 1) + +#define ticks() supervisor_ticks_ms() STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) { mp_uint_t t0 = MP_OBJ_SMALL_INT_VALUE(t0_in); mp_uint_t t1 = MP_OBJ_SMALL_INT_VALUE(t1_in); - mp_int_t diff = ((t1 - t0 + MICROPY_PY_UTIME_TICKS_PERIOD / 2) & (MICROPY_PY_UTIME_TICKS_PERIOD - 1)) - - MICROPY_PY_UTIME_TICKS_PERIOD / 2; + mp_int_t diff = ((t1 - t0 + _TICKS_HALFPERIOD) & _TICKS_MAX) - _TICKS_HALFPERIOD; return diff; } diff --git a/py/objmodule.c b/py/objmodule.c index 238b24be4b..6b365ec91d 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -196,6 +196,9 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = { // extmod modules + #if MICROPY_PY_UASYNCIO + { MP_ROM_QSTR(MP_QSTR__uasyncio), MP_ROM_PTR(&mp_module_uasyncio) }, + #endif #if MICROPY_PY_UERRNO #if CIRCUITPY // CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here.