Skip to content

Commit

Permalink
tests/psoc6/rtc.py: Capitalize constants.
Browse files Browse the repository at this point in the history
Signed-off-by: NikhitaR-IFX <Nikhita.Rajasekhar@infineon.com>
  • Loading branch information
NikhitaR-IFX authored and actions-user committed Jun 7, 2024
1 parent 009c00f commit a9a85a5
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions tests/psoc6/rtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
from machine import RTC
import time

irq_counter = 0
one_shot_alarm = 0
periodic_alarm = 1
IRQ_COUNTER = 0
ONE_SHOT_ALARM = 0
PERIODIC_ALARM = 1

# Tuple format: Year, Month, Sec, WDay*, Hour, Min, Sec, Subsec=0
# *Note: User cannot set a wrong week day value here. PSoC always calculates the right weekday using rest of the fields.
initial_dtime = (2023, 1, 1, 0, 0, 0, 0, 0)


def cback(event):
global irq_counter
irq_counter += 1
global IRQ_COUNTER
IRQ_COUNTER += 1


def check_rtc_mem_write():
Expand All @@ -40,9 +40,9 @@ def set_alarm_datetime(rtc, alarm_type, datetime):


def wait_for_cback(timeout, exp_counter):
global irq_counter
global IRQ_COUNTER
start = time.ticks_ms()
while irq_counter < exp_counter:
while IRQ_COUNTER < exp_counter:
time.sleep_ms(5)
if time.ticks_diff(time.ticks_ms(), start) > cback_call_wait_time:
break
Expand All @@ -63,43 +63,43 @@ def wait_for_cback(timeout, exp_counter):
print("\n1. Setting periodic short alarm to be triggered repeatedly in few ms in future")
timeout = 1000
cback_call_wait_time = timeout + 200
set_alarm_ms(rtc, periodic_alarm, timeout)
set_alarm_ms(rtc, PERIODIC_ALARM, timeout)
print("Alarm period set to (ms): ", rtc.alarm_left())
wait_for_cback(cback_call_wait_time, 1)
print("Alarm expired : ", irq_counter == 1)
print("Alarm expired : ", IRQ_COUNTER == 1)
print("Alarm set again...")
wait_for_cback(cback_call_wait_time, 2)
print("Alarm expired : ", irq_counter == 2)
print("Alarm expired : ", IRQ_COUNTER == 2)
rtc.cancel()
wait_for_cback(cback_call_wait_time, 2)
print("Alarm cancelled successfully : ", irq_counter == 2)
irq_counter = 0
print("Alarm cancelled successfully : ", IRQ_COUNTER == 2)
IRQ_COUNTER = 0

print("\n2. Setting one-shot short alarm to be triggered in few ms in future")
timeout = 1000
cback_call_wait_time = timeout + 500
set_alarm_ms(rtc, one_shot_alarm, timeout)
set_alarm_ms(rtc, ONE_SHOT_ALARM, timeout)
wait_for_cback(cback_call_wait_time, 1)
print("Alarm expired : ", 0 == rtc.alarm_left())
print("Entered Cback :", irq_counter == 1)
irq_counter = 0
print("Entered Cback :", IRQ_COUNTER == 1)
IRQ_COUNTER = 0

print("\n3. Setting one-shot alarm to be triggered at specified date-time")
timeout = 1
cback_call_wait_time = timeout * 1000 + 500
set_alarm_datetime(rtc, one_shot_alarm, (2023, 1, 1, 0, 0, timeout, 0, 0))
set_alarm_datetime(rtc, ONE_SHOT_ALARM, (2023, 1, 1, 0, 0, timeout, 0, 0))
wait_for_cback(cback_call_wait_time, 1)
print("Alarm expired : ", 0 == rtc.alarm_left())
print("Entered Cback :", irq_counter == 1)
irq_counter = 0
print("Entered Cback :", IRQ_COUNTER == 1)
IRQ_COUNTER = 0

print("\n4. Setting periodic alarm to be triggered at specified date-time should fail")
try:
set_alarm_datetime(rtc, periodic_alarm, (2023, 1, 1, 0, 0, 0, 1, 0)) # Should fail
set_alarm_datetime(rtc, PERIODIC_ALARM, (2023, 1, 1, 0, 0, 0, 1, 0)) # Should fail
except ValueError as e:
print(e)

irq_counter = 0
IRQ_COUNTER = 0

rtc1 = RTC()
print("\n5.RTC constructor return singleton: ", rtc1 == rtc)
Expand Down

0 comments on commit a9a85a5

Please sign in to comment.