aboutsummaryrefslogtreecommitdiff
path: root/extmod/utime_mphal.c
AgeCommit message (Collapse)Author
2020-10-01extmod/utime_mphal: Add generic utime.time_ns() function.Damien George
It requires mp_hal_time_ns() to be provided by a port. This function allows very accurate absolute timestamps. Enabled on unix, windows, stm32, esp8266 and esp32. Signed-off-by: Damien George <damien@micropython.org>
2020-02-28all: Reformat C and Python source code with tools/codeformat.py.Damien George
This is run with uncrustify 0.70.1, and black 19.10b0.
2017-07-07py,extmod: Some casts and minor refactors to quiet compiler warnings.Tom Collins
2017-03-22extmod/utime_mphal: Don't exit/enter the GIL in generic sleep functions.Damien George
GIL behaviour should be handled by the port. And ports probably want to define sleep_us so that it doesn't release the GIL, to improve timing accuracy.
2016-11-03extmod/utime_mphal: ticks_diff/ticks_add: Don't hardcode 32-bit types.Paul Sokolovsky
Use normal mp_int_t/mp_uint_t types, algorithms (hm, formulas) can work with any type width.
2016-11-02extmod/utime_mphal: ticks_diff(): Optimize to avoid if conditions.Paul Sokolovsky
2016-10-30extmod/utime_mphal: Fix implementation of new semantics of ticks_diff().Paul Sokolovsky
Now the function properly uses ring arithmetic to return signed value in range (inclusive): [-MICROPY_PY_UTIME_TICKS_PERIOD/2, MICROPY_PY_UTIME_TICKS_PERIOD/2-1]. That means that function can properly process 2 time values away from each other within MICROPY_PY_UTIME_TICKS_PERIOD/2 ticks, but away in both directions. For example, if tick value 'a' predates tick value 'b', ticks_diff(a, b) will return negative value, and positive value otherwise. But at positive value of MICROPY_PY_UTIME_TICKS_PERIOD/2-1, the result of the function will wrap around to negative -MICROPY_PY_UTIME_TICKS_PERIOD/2, in other words, if a follows b in more than MICROPY_PY_UTIME_TICKS_PERIOD/2 - 1 ticks, the function will "consider" a to actually predate b.
2016-10-30extmod/utime_mphal: Allow ticks functions period be configurable by a port.Paul Sokolovsky
Using MICROPY_PY_UTIME_TICKS_PERIOD config var.
2016-10-29extmod/utime_mphal: Implement ticks_add(), add to all maintained ports.Paul Sokolovsky
2016-10-29extmod/utime_mphal: Add MP_THREAD_GIL_EXIT/ENTER warppers for sleep functions.Paul Sokolovsky
Ported from unix port.
2016-10-29extmod/utime_mphal: ticks_diff(): switch arg order, return signed value.Paul Sokolovsky
Based on the earlier discussed RFC. Practice showed that the most natural order for arguments corresponds to mathematical subtraction: ticks_diff(x, y) <=> x - y Also, practice showed that in real life, it's hard to order events by time of occurance a priori, events tend to miss deadlines, etc. and the expected order breaks. And then there's a need to detect such cases. And ticks_diff can be used exactly for this purpose, if it returns a signed, instead of unsigned, value. E.g. if x is scheduled time for event, and y is the current time, then if ticks_diff(x, y) < 0 then event has missed a deadline (and e.g. needs to executed ASAP or skipped). Returning in this case a large unsigned number (like ticks_diff behaved previously) doesn't make sense, and such "large unsigned number" can't be reliably detected per our definition of ticks_* function (we don't expose to user level maximum value, it can be anything, relatively small or relatively large).
2016-10-14extmod/utime_mphal: sleep_us/ms(): Don't wait on negative argument.Paul Sokolovsky
2016-10-14extmod/utime_mphal: Factor out implementations in terms of mp_hal_* for reuse.Paul Sokolovsky
As long as a port implement mp_hal_sleep_ms(), mp_hal_ticks_ms(), etc. functions, it can just use standard implementations of utime.sleel_ms(), utime.ticks_ms(), etc. Python-level functions.