Revert ticks implementation for unix build.

This commit is contained in:
Tsutomu IKEGAMI 2022-02-22 17:49:23 +09:00
parent 6b7ad72f8f
commit bccb09b0ea
1 changed files with 17 additions and 2 deletions

View File

@ -29,8 +29,9 @@
#include "py/pairheap.h"
#include "py/mphal.h"
// Unix build does not have shared-bindings/supervisor/__init__.h
extern mp_obj_t supervisor_ticks_ms(void);
#ifndef __unix__
#include "shared-bindings/supervisor/__init__.h"
#endif
#if MICROPY_PY_UASYNCIO
@ -66,6 +67,19 @@ 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
#ifdef __unix__
STATIC mp_obj_t ticks(void) {
return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1));
}
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;
return diff;
}
#else
#define _TICKS_PERIOD (1lu << 29)
#define _TICKS_MAX (_TICKS_PERIOD - 1)
#define _TICKS_HALFPERIOD (_TICKS_PERIOD >> 1)
@ -78,6 +92,7 @@ STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) {
mp_int_t diff = ((t1 - t0 + _TICKS_HALFPERIOD) & _TICKS_MAX) - _TICKS_HALFPERIOD;
return diff;
}
#endif
STATIC int task_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) {
mp_obj_task_t *t1 = (mp_obj_task_t *)n1;