forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ports/psoc6: Timer Module fix with tests.
Signed-off-by: IFX-Anusha <Anusha.TR@infineon.com>
- Loading branch information
1 parent
09a6c26
commit 67cb65b
Showing
3 changed files
with
65 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,37 @@ | ||
import time | ||
from machine import Timer | ||
import os | ||
import uasyncio as asyncio | ||
interrupt_triggered = False # Flag to indicate interrupt triggered | ||
|
||
# machine = os.uname().machine | ||
# if "CY8CPROTO-063-BLE" in machine: | ||
# TODO: Not working correctly. Neither the timer timing is correct. | ||
# TODO: Review test and module. | ||
print("SKIP") | ||
raise SystemExit | ||
def call(timer): | ||
global interrupt_triggered | ||
interrupt_triggered = True | ||
|
||
t = Timer(0) | ||
t.init(period=2000, mode=Timer.ONE_SHOT, callback=lambda t: print("Oneshot Timer")) | ||
time.sleep(30) | ||
t.deinit() | ||
async def print_message_thread(): | ||
global interrupt_triggered | ||
while True: | ||
if interrupt_triggered: | ||
print("Interrupt triggered") | ||
interrupt_triggered = False # Reset the flag | ||
await asyncio.sleep(0.1) # Use asyncio.sleep instead of time.sleep | ||
|
||
|
||
def blocking_delay_ms(delay_ms): | ||
start = time.ticks_ms() | ||
while time.ticks_diff(time.ticks_ms(), start) < delay_ms: | ||
pass | ||
|
||
|
||
t1 = Timer(0) | ||
t1.init(period=2000, mode=Timer.PERIODIC, callback=lambda t: print("Periodic Timer")) | ||
blocking_delay_ms(2000) | ||
t.deinit() | ||
async def main(): | ||
print("Oneshot Timer Execution") | ||
tim = Timer(0, period=1000, mode=Timer.ONE_SHOT, callback=call) | ||
try: | ||
logger_task = asyncio.create_task(print_message_thread()) | ||
await asyncio.sleep(5) # Wait for 5 seconds | ||
logger_task.cancel() # Cancel the logger task | ||
finally: | ||
tim.deinit() # Deinitialize the timer | ||
print("Periodic Timer Execution") | ||
tim = Timer(0, period=1000, mode=Timer.PERIODIC, callback=call) | ||
try: | ||
logger_task = asyncio.create_task(print_message_thread()) | ||
await asyncio.sleep(5) # Wait for 5 seconds | ||
logger_task.cancel() # Cancel the logger task | ||
finally: | ||
tim.deinit() # Deinitialize the timer | ||
|
||
if __name__ == "__main__": | ||
print("Timer Test") | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
Oneshot Timer | ||
Periodic Timer | ||
Periodic Timer | ||
Periodic Timer | ||
Periodic Timer | ||
Periodic Timer | ||
Periodic Timer | ||
Periodic Timer | ||
Periodic Timer | ||
Periodic Timer | ||
Timer Test | ||
Oneshot Timer Execution | ||
Interrupt triggered | ||
Periodic Timer Execution | ||
Interrupt triggered | ||
Interrupt triggered | ||
Interrupt triggered | ||
Interrupt triggered |