I need to use utime.ticks_diff()
in a ISR code. Do you think it is ISR-safe ? They say that in a ISR you should not use floating point. The code of ticks_diff()
is this:
def ticks_diff(a, b):
return ((a - b + MICROPY_PY_UTIME_TICKS_PERIOD // 2) & (MICROPY_PY_UTIME_TICKS_PERIOD - 1)) - MICROPY_PY_UTIME_TICKS_PERIOD // 2
It has some divisions, but I'm not sure if floating point is used...
MicroPython "implements Python 3.4 and some select features of Python 3.5 and above".
The //
operator is 'floor division' (Python 3.4 docs), and from there
floor division of integers results in an integer
The list of MicroPython differences from CPython doesn't say that //
works any differently in MicroPython than in CPython.
So you should be safe to use this method - but why not try it?