Fix ticks in moduasyncio.c to work with adafruit version of asyncio, and enable _uasyncio module.

This commit is contained in:
Tsutomu IKEGAMI 2022-02-16 19:22:18 +09:00
parent c4ae8c8320
commit b0b3c7817f
2 changed files with 10 additions and 5 deletions

View File

@ -28,6 +28,7 @@
#include "py/smallint.h" #include "py/smallint.h"
#include "py/pairheap.h" #include "py/pairheap.h"
#include "py/mphal.h" #include "py/mphal.h"
#include "shared-bindings/supervisor/__init__.h"
#if MICROPY_PY_UASYNCIO #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 // Ticks for task ordering in pairing heap
STATIC mp_obj_t ticks(void) { #define _TICKS_PERIOD (1lu << 29)
return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1)); #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) { 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 t0 = MP_OBJ_SMALL_INT_VALUE(t0_in);
mp_uint_t t1 = MP_OBJ_SMALL_INT_VALUE(t1_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)) mp_int_t diff = ((t1 - t0 + _TICKS_HALFPERIOD) & _TICKS_MAX) - _TICKS_HALFPERIOD;
- MICROPY_PY_UTIME_TICKS_PERIOD / 2;
return diff; return diff;
} }

View File

@ -196,6 +196,9 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = {
// extmod modules // extmod modules
#if MICROPY_PY_UASYNCIO
{ MP_ROM_QSTR(MP_QSTR__uasyncio), MP_ROM_PTR(&mp_module_uasyncio) },
#endif
#if MICROPY_PY_UERRNO #if MICROPY_PY_UERRNO
#if CIRCUITPY #if CIRCUITPY
// CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here. // CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here.