2020-03-23 02:26:08 +00:00
|
|
|
"""
|
2015-09-22 22:20:29 +01:00
|
|
|
RTC IRQ test for the CC3200 based boards.
|
2020-03-23 02:26:08 +00:00
|
|
|
"""
|
2015-09-22 22:20:29 +01:00
|
|
|
|
2015-09-27 12:45:48 +01:00
|
|
|
from machine import RTC
|
|
|
|
import machine
|
2015-09-22 22:20:29 +01:00
|
|
|
import os
|
|
|
|
import time
|
|
|
|
|
2015-09-27 12:45:48 +01:00
|
|
|
mch = os.uname().machine
|
|
|
|
if not "LaunchPad" in mch and not "WiPy" in mch:
|
2015-09-22 22:20:29 +01:00
|
|
|
raise Exception("Board not supported!")
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2015-09-22 22:20:29 +01:00
|
|
|
|
|
|
|
def rtc_ticks_ms(rtc):
|
|
|
|
timedate = rtc.now()
|
|
|
|
return (timedate[5] * 1000) + (timedate[6] // 1000)
|
|
|
|
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2015-09-22 22:20:29 +01:00
|
|
|
rtc_irq_count = 0
|
|
|
|
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2015-09-22 22:20:29 +01:00
|
|
|
def alarm_handler(rtc_o):
|
|
|
|
global rtc_irq
|
|
|
|
global rtc_irq_count
|
|
|
|
if rtc_irq.flags() & RTC.ALARM0:
|
|
|
|
rtc_irq_count += 1
|
|
|
|
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2015-09-22 22:20:29 +01:00
|
|
|
rtc = RTC()
|
|
|
|
rtc.alarm(time=500, repeat=True)
|
|
|
|
rtc_irq = rtc.irq(trigger=RTC.ALARM0, handler=alarm_handler)
|
|
|
|
|
|
|
|
# active mode
|
|
|
|
time.sleep_ms(1000)
|
|
|
|
rtc.alarm_cancel()
|
|
|
|
print(rtc_irq_count == 2)
|
|
|
|
rtc_irq_count = 0
|
|
|
|
rtc.alarm(time=200, repeat=True)
|
|
|
|
time.sleep_ms(1000)
|
|
|
|
rtc.alarm_cancel()
|
|
|
|
print(rtc_irq_count == 5)
|
|
|
|
|
|
|
|
rtc_irq_count = 0
|
|
|
|
rtc.alarm(time=100, repeat=True)
|
|
|
|
time.sleep_ms(1000)
|
|
|
|
rtc.alarm_cancel()
|
|
|
|
print(rtc_irq_count == 10)
|
|
|
|
|
|
|
|
# deep sleep mode
|
|
|
|
rtc.alarm_cancel()
|
|
|
|
rtc_irq_count = 0
|
|
|
|
rtc.alarm(time=50, repeat=True)
|
2015-09-27 12:45:48 +01:00
|
|
|
rtc_irq.init(trigger=RTC.ALARM0, handler=alarm_handler, wake=machine.SLEEP | machine.IDLE)
|
2015-09-22 22:20:29 +01:00
|
|
|
while rtc_irq_count < 3:
|
2015-09-27 12:45:48 +01:00
|
|
|
machine.sleep()
|
2015-09-22 22:20:29 +01:00
|
|
|
print(rtc_irq_count == 3)
|
|
|
|
|
|
|
|
# no repetition
|
|
|
|
rtc.alarm_cancel()
|
|
|
|
rtc_irq_count = 0
|
|
|
|
rtc.alarm(time=100, repeat=False)
|
|
|
|
time.sleep_ms(250)
|
|
|
|
print(rtc_irq_count == 1)
|
|
|
|
|
|
|
|
rtc.alarm_cancel()
|
|
|
|
t0 = rtc_ticks_ms(rtc)
|
|
|
|
rtc.alarm(time=500, repeat=False)
|
2015-09-27 12:45:48 +01:00
|
|
|
machine.sleep()
|
2015-09-22 22:20:29 +01:00
|
|
|
t1 = rtc_ticks_ms(rtc)
|
|
|
|
print(abs(t1 - t0 - 500) < 20)
|
|
|
|
|
|
|
|
# deep sleep repeated mode
|
|
|
|
rtc.alarm_cancel()
|
|
|
|
rtc_irq_count = 0
|
2015-09-27 12:18:12 +01:00
|
|
|
rtc.alarm(time=500, repeat=True)
|
2015-09-22 22:20:29 +01:00
|
|
|
t0 = rtc_ticks_ms(rtc)
|
2015-09-27 12:45:48 +01:00
|
|
|
rtc_irq = rtc.irq(trigger=RTC.ALARM0, handler=alarm_handler, wake=machine.SLEEP)
|
2015-09-27 12:18:12 +01:00
|
|
|
while rtc_irq_count < 3:
|
2015-09-27 12:45:48 +01:00
|
|
|
machine.sleep()
|
2015-09-22 22:20:29 +01:00
|
|
|
t1 = rtc_ticks_ms(rtc)
|
2015-09-27 12:18:12 +01:00
|
|
|
print(abs(t1 - t0 - (500 * rtc_irq_count)) < 25)
|
2015-09-22 22:20:29 +01:00
|
|
|
|
|
|
|
# next ones must raise
|
|
|
|
try:
|
|
|
|
rtc_irq = rtc.irq(trigger=10, handler=alarm_handler)
|
|
|
|
except:
|
|
|
|
print("Exception")
|
|
|
|
|
|
|
|
try:
|
|
|
|
rtc_irq = rtc.irq(trigger=RTC.ALARM0, wake=1789456)
|
|
|
|
except:
|
|
|
|
print("Exception")
|