diff --git a/tests/psoc6/timer.py b/tests/psoc6/timer.py index 3e3b31c725a0f..67eb0ab6fb7ee 100644 --- a/tests/psoc6/timer.py +++ b/tests/psoc6/timer.py @@ -1,37 +1,54 @@ from machine import Timer -import uasyncio as asyncio -interrupt_triggered = False # Flag to indicate interrupt triggered - -def call(timer): - global interrupt_triggered - interrupt_triggered = True - -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 - -async def main(): - print("Oneshot Timer Execution") - tim = Timer(0, period=1000, mode=Timer.ONE_SHOT, callback=call) +import time + +oneshot_triggered = False +periodic_triggered = False + + +def call_oneshot(timer): + global oneshot_triggered + oneshot_triggered = True + + +def call_periodic(timer): + global periodic_triggered + periodic_triggered = True + + +def test_oneshot(): + # Periodic timer + global oneshot_triggered + tim_oneshot = Timer(0, period=1000, mode=Timer.ONE_SHOT, callback=call_oneshot) + try: - logger_task = asyncio.create_task(print_message_thread()) - await asyncio.sleep(5) # Wait for 5 seconds - logger_task.cancel() # Cancel the logger task + # Wait for 5 seconds + for i in range(5): + time.sleep(1) + if oneshot_triggered: + print("Oneshot timer triggered") + oneshot_triggered = False finally: - tim.deinit() # Deinitialize the timer - print("Periodic Timer Execution") - tim = Timer(0, period=1000, mode=Timer.PERIODIC, callback=call) + tim_oneshot.deinit() # Deinitialize the periodic timer + + +def test_periodic(): + # Periodic timer + global periodic_triggered + tim_periodic = Timer(0, period=1, mode=Timer.PERIODIC, callback=call_periodic) + try: - logger_task = asyncio.create_task(print_message_thread()) - await asyncio.sleep(5) # Wait for 5 seconds - logger_task.cancel() # Cancel the logger task + # Wait for 15 seconds + for i in range(15): + time.sleep(1) + if periodic_triggered: + print("Periodic timer triggered") + periodic_triggered = False finally: - tim.deinit() # Deinitialize the timer - + tim_periodic.deinit() # Deinitialize the periodic timer + + if __name__ == "__main__": - print("Timer Test") - asyncio.run(main()) \ No newline at end of file + print("*****Oneshot Timer Execution*****") + test_oneshot() + print("*****Periodic Timer Execution*****") + test_periodic() diff --git a/tests/psoc6/timer.py.exp b/tests/psoc6/timer.py.exp index e677f41f5238e..f35489a58832b 100644 --- a/tests/psoc6/timer.py.exp +++ b/tests/psoc6/timer.py.exp @@ -1,8 +1,17 @@ -Timer Test -Oneshot Timer Execution -Interrupt triggered -Periodic Timer Execution -Interrupt triggered -Interrupt triggered -Interrupt triggered -Interrupt triggered \ No newline at end of file +*****Oneshot Timer Execution***** +Oneshot timer triggered +*****Periodic Timer Execution***** +Periodic timer triggered +Periodic timer triggered +Periodic timer triggered +Periodic timer triggered +Periodic timer triggered +Periodic timer triggered +Periodic timer triggered +Periodic timer triggered +Periodic timer triggered +Periodic timer triggered +Periodic timer triggered +Periodic timer triggered +Periodic timer triggered +Periodic timer triggered diff --git a/tools/codeformat.py b/tools/codeformat.py index 8629ab4401642..cf0e4b32ad38c 100755 --- a/tools/codeformat.py +++ b/tools/codeformat.py @@ -61,8 +61,7 @@ "ports/nrf/modules/board/*.[ch]", "ports/nrf/modules/music/*.[ch]", "ports/nrf/modules/ubluepy/*.[ch]", - "ports/nrf/modules/uos/*.[ch]", - "ports/nrf/modules/utime/*.[ch]", + "ports/nrf/modules/os/*.[ch]", # PSoC 3rd party "ports/psoc6/boards/**/*.[ch]", # STM32 USB dev/host code is mostly 3rd party.