2021-09-17 08:40:20 -07:00
|
|
|
from micropython import const
|
2018-10-16 22:43:47 -07:00
|
|
|
|
2021-09-13 08:18:01 -07:00
|
|
|
_TICKS_PERIOD = const(1 << 29)
|
|
|
|
_TICKS_MAX = const(_TICKS_PERIOD - 1)
|
|
|
|
_TICKS_HALFPERIOD = const(_TICKS_PERIOD // 2)
|
2018-10-07 00:44:04 -07:00
|
|
|
|
2018-09-28 14:35:52 -07:00
|
|
|
|
2021-09-13 08:18:01 -07:00
|
|
|
def ticks_diff(new, start):
|
|
|
|
diff = (new - start) & _TICKS_MAX
|
|
|
|
diff = ((diff + _TICKS_HALFPERIOD) & _TICKS_MAX) - _TICKS_HALFPERIOD
|
|
|
|
return diff
|
2018-09-28 14:35:52 -07:00
|
|
|
|
|
|
|
|
2021-09-13 08:18:01 -07:00
|
|
|
def check_deadline(new, start, ms):
|
|
|
|
return ticks_diff(new, start) < ms
|