Skip to content

Commit b0b3c78

Browse files
committed
Fix ticks in moduasyncio.c to work with adafruit version of asyncio, and enable _uasyncio module.
1 parent c4ae8c8 commit b0b3c78

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

extmod/moduasyncio.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "py/smallint.h"
2929
#include "py/pairheap.h"
3030
#include "py/mphal.h"
31+
#include "shared-bindings/supervisor/__init__.h"
3132

3233
#if MICROPY_PY_UASYNCIO
3334

@@ -63,15 +64,16 @@ STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, si
6364
/******************************************************************************/
6465
// Ticks for task ordering in pairing heap
6566

66-
STATIC mp_obj_t ticks(void) {
67-
return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1));
68-
}
67+
#define _TICKS_PERIOD (1lu << 29)
68+
#define _TICKS_MAX (_TICKS_PERIOD - 1)
69+
#define _TICKS_HALFPERIOD (_TICKS_PERIOD >> 1)
70+
71+
#define ticks() supervisor_ticks_ms()
6972

7073
STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) {
7174
mp_uint_t t0 = MP_OBJ_SMALL_INT_VALUE(t0_in);
7275
mp_uint_t t1 = MP_OBJ_SMALL_INT_VALUE(t1_in);
73-
mp_int_t diff = ((t1 - t0 + MICROPY_PY_UTIME_TICKS_PERIOD / 2) & (MICROPY_PY_UTIME_TICKS_PERIOD - 1))
74-
- MICROPY_PY_UTIME_TICKS_PERIOD / 2;
76+
mp_int_t diff = ((t1 - t0 + _TICKS_HALFPERIOD) & _TICKS_MAX) - _TICKS_HALFPERIOD;
7577
return diff;
7678
}
7779

py/objmodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = {
196196

197197
// extmod modules
198198

199+
#if MICROPY_PY_UASYNCIO
200+
{ MP_ROM_QSTR(MP_QSTR__uasyncio), MP_ROM_PTR(&mp_module_uasyncio) },
201+
#endif
199202
#if MICROPY_PY_UERRNO
200203
#if CIRCUITPY
201204
// CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here.

0 commit comments

Comments
 (0)