Skip to content

Commit e590d27

Browse files
committed
Use CircuitPython _TICKS_PERIOD
.. since Adafruit_CircuitPython_asyncio is hard-coded to this _TICKS_PERIOD not the one that would otherwise be used on Unix This fixes all the uasyncio test failures on Unix
1 parent 6a8bc73 commit e590d27

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

extmod/moduasyncio.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,32 +70,20 @@ STATIC mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf);
7070
/******************************************************************************/
7171
// Ticks for task ordering in pairing heap
7272

73-
#if !CIRCUITPY || (defined(__unix__) || defined(__APPLE__))
74-
STATIC mp_obj_t ticks(void) {
75-
return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1));
76-
}
77-
78-
STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) {
79-
mp_uint_t t0 = MP_OBJ_SMALL_INT_VALUE(t0_in);
80-
mp_uint_t t1 = MP_OBJ_SMALL_INT_VALUE(t1_in);
81-
mp_int_t diff = ((t1 - t0 + MICROPY_PY_UTIME_TICKS_PERIOD / 2) & (MICROPY_PY_UTIME_TICKS_PERIOD - 1))
82-
- MICROPY_PY_UTIME_TICKS_PERIOD / 2;
83-
return diff;
84-
}
85-
#else
8673
#define _TICKS_PERIOD (1lu << 29)
8774
#define _TICKS_MAX (_TICKS_PERIOD - 1)
8875
#define _TICKS_HALFPERIOD (_TICKS_PERIOD >> 1)
8976

90-
#define ticks() supervisor_ticks_ms()
77+
STATIC mp_obj_t ticks(void) {
78+
return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & _TICKS_MAX);
79+
}
9180

9281
STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) {
9382
mp_uint_t t0 = MP_OBJ_SMALL_INT_VALUE(t0_in);
9483
mp_uint_t t1 = MP_OBJ_SMALL_INT_VALUE(t1_in);
9584
mp_int_t diff = ((t1 - t0 + _TICKS_HALFPERIOD) & _TICKS_MAX) - _TICKS_HALFPERIOD;
9685
return diff;
9786
}
98-
#endif
9987

10088
STATIC int task_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) {
10189
mp_obj_task_t *t1 = (mp_obj_task_t *)n1;

0 commit comments

Comments
 (0)