summaryrefslogtreecommitdiffstatshomepage
path: root/tests/wipy/rtc_irq.py
diff options
context:
space:
mode:
authorDaniel Campora <daniel@wipy.io>2015-09-22 23:20:29 +0200
committerDaniel Campora <daniel@wipy.io>2015-09-27 01:48:20 +0200
commitdbdcb58d6413a907e5f4aed25eee85073ff7e575 (patch)
tree0ecc90d3a3a947639549afde2b94c3d35b13fc2a /tests/wipy/rtc_irq.py
parent81d64ab939ff45e74b0154e4ce2d9c5d2cfe6328 (diff)
downloadmicropython-dbdcb58d6413a907e5f4aed25eee85073ff7e575.tar.gz
micropython-dbdcb58d6413a907e5f4aed25eee85073ff7e575.zip
cc3200: New irq API, affects all classes that provide the irq method.
Diffstat (limited to 'tests/wipy/rtc_irq.py')
-rw-r--r--tests/wipy/rtc_irq.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/wipy/rtc_irq.py b/tests/wipy/rtc_irq.py
new file mode 100644
index 0000000000..1c9ea93f1d
--- /dev/null
+++ b/tests/wipy/rtc_irq.py
@@ -0,0 +1,89 @@
+'''
+RTC IRQ test for the CC3200 based boards.
+'''
+
+from pyb import RTC
+from pyb import Sleep
+import os
+import time
+
+machine = os.uname().machine
+if not 'LaunchPad' in machine and not 'WiPy' in machine:
+ raise Exception('Board not supported!')
+
+def rtc_ticks_ms(rtc):
+ timedate = rtc.now()
+ return (timedate[5] * 1000) + (timedate[6] // 1000)
+
+rtc_irq_count = 0
+
+def alarm_handler (rtc_o):
+ global rtc_irq
+ global rtc_irq_count
+ if rtc_irq.flags() & RTC.ALARM0:
+ rtc_irq_count += 1
+
+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)
+rtc_irq.init(trigger=RTC.ALARM0, handler=alarm_handler, wake=Sleep.SUSPENDED | Sleep.ACTIVE)
+while rtc_irq_count < 3:
+ Sleep.suspend()
+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)
+Sleep.suspend()
+t1 = rtc_ticks_ms(rtc)
+print(abs(t1 - t0 - 500) < 20)
+
+# deep sleep repeated mode
+rtc.alarm_cancel()
+rtc_irq_count = 0
+rtc.alarm(time=250, repeat=True)
+t0 = rtc_ticks_ms(rtc)
+rtc_irq = rtc.irq(trigger=RTC.ALARM0, handler=alarm_handler, wake=Sleep.SUSPENDED)
+while rtc_irq_count < 10:
+ Sleep.suspend()
+ t1 = rtc_ticks_ms(rtc)
+ print(abs(t1 - t0 - (250 * rtc_irq_count)) < 25)
+
+# 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')