mirror of
https://github.com/micropython/micropython.git
synced 2026-01-08 05:00:26 +01:00
extmod/utime_mphal: Add generic utime.time_ns() function.
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>
This commit is contained in:
24
tests/extmod/utime_time_ns.py
Normal file
24
tests/extmod/utime_time_ns.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# test utime.time_ns()
|
||||
|
||||
try:
|
||||
import utime
|
||||
|
||||
utime.sleep_us
|
||||
utime.time_ns
|
||||
except (ImportError, AttributeError):
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
t0 = utime.time_ns()
|
||||
utime.sleep_us(1000)
|
||||
t1 = utime.time_ns()
|
||||
|
||||
# Check that time_ns increases.
|
||||
print(t0 < t1)
|
||||
|
||||
# Check that time_ns counts correctly, but be very lenient with the upper bound (50ms).
|
||||
if 950000 < t1 - t0 < 50000000:
|
||||
print(True)
|
||||
else:
|
||||
print(t0, t1, t1 - t0)
|
||||
2
tests/extmod/utime_time_ns.py.exp
Normal file
2
tests/extmod/utime_time_ns.py.exp
Normal file
@@ -0,0 +1,2 @@
|
||||
True
|
||||
True
|
||||
Reference in New Issue
Block a user