mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 11:40:18 +01:00
tests: Test hardware timers as well as software timers.
On platforms where hardware timers are available, test these in each combination of hard/soft and one-shot/periodic in the same way as for software timers. Where a platform supports both software (id = -1) and hardware (id >= 0) timers, the behaviour of both is now checked. For now, esp8266 is the only platform that supports hardware timers and both hard and soft callbacks. Signed-off-by: Chris Webb <chris@arachsys.com>
This commit is contained in:
committed by
Damien George
parent
ccc954256f
commit
ec6cdf3718
45
tests/extmod/machine_hard_timer.py
Normal file
45
tests/extmod/machine_hard_timer.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import sys
|
||||
|
||||
try:
|
||||
from machine import Timer
|
||||
from time import sleep_ms
|
||||
except:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
if sys.platform == "esp8266":
|
||||
timer = Timer(0)
|
||||
else:
|
||||
# Hardware timers are not implemented.
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
# Test both hard and soft IRQ handlers and both one-shot and periodic
|
||||
# timers. We adjust period in tests/extmod/machine_soft_timer.py, so try
|
||||
# adjusting freq here instead. The heap should be locked in hard callbacks
|
||||
# and unlocked in soft callbacks.
|
||||
|
||||
|
||||
def callback(t):
|
||||
print("callback", mode[1], kind[1], freq, end=" ")
|
||||
try:
|
||||
allocate = bytearray(1)
|
||||
print("unlocked")
|
||||
except MemoryError:
|
||||
print("locked")
|
||||
|
||||
|
||||
modes = [(Timer.ONE_SHOT, "one-shot"), (Timer.PERIODIC, "periodic")]
|
||||
kinds = [(False, "soft"), (True, "hard")]
|
||||
|
||||
for mode in modes:
|
||||
for kind in kinds:
|
||||
for freq in 50, 25:
|
||||
timer.init(
|
||||
mode=mode[0],
|
||||
freq=freq,
|
||||
hard=kind[0],
|
||||
callback=callback,
|
||||
)
|
||||
sleep_ms(90)
|
||||
timer.deinit()
|
||||
16
tests/extmod/machine_hard_timer.py.exp
Normal file
16
tests/extmod/machine_hard_timer.py.exp
Normal file
@@ -0,0 +1,16 @@
|
||||
callback one-shot soft 50 unlocked
|
||||
callback one-shot soft 25 unlocked
|
||||
callback one-shot hard 50 locked
|
||||
callback one-shot hard 25 locked
|
||||
callback periodic soft 50 unlocked
|
||||
callback periodic soft 50 unlocked
|
||||
callback periodic soft 50 unlocked
|
||||
callback periodic soft 50 unlocked
|
||||
callback periodic soft 25 unlocked
|
||||
callback periodic soft 25 unlocked
|
||||
callback periodic hard 50 locked
|
||||
callback periodic hard 50 locked
|
||||
callback periodic hard 50 locked
|
||||
callback periodic hard 50 locked
|
||||
callback periodic hard 25 locked
|
||||
callback periodic hard 25 locked
|
||||
Reference in New Issue
Block a user