diff options
author | Daniel Campora <daniel@wipy.io> | 2015-09-22 23:20:29 +0200 |
---|---|---|
committer | Daniel Campora <daniel@wipy.io> | 2015-09-27 01:48:20 +0200 |
commit | dbdcb58d6413a907e5f4aed25eee85073ff7e575 (patch) | |
tree | 0ecc90d3a3a947639549afde2b94c3d35b13fc2a /tests/wipy/uart_irq.py | |
parent | 81d64ab939ff45e74b0154e4ce2d9c5d2cfe6328 (diff) | |
download | micropython-dbdcb58d6413a907e5f4aed25eee85073ff7e575.tar.gz micropython-dbdcb58d6413a907e5f4aed25eee85073ff7e575.zip |
cc3200: New irq API, affects all classes that provide the irq method.
Diffstat (limited to 'tests/wipy/uart_irq.py')
-rw-r--r-- | tests/wipy/uart_irq.py | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/tests/wipy/uart_irq.py b/tests/wipy/uart_irq.py new file mode 100644 index 0000000000..3f1084cce3 --- /dev/null +++ b/tests/wipy/uart_irq.py @@ -0,0 +1,149 @@ +''' +UART IRQ test for the CC3200 based boards. +''' + +from pyb import UART +import os +import pyb +import time + +machine = os.uname().machine +if 'LaunchPad' in machine: + uart_pins = [[('GP12', 'GP13'), ('GP12', 'GP13', 'GP7', 'GP6')], [('GP16', 'GP17'), ('GP16', 'GP17', 'GP7', 'GP6')]] +elif 'WiPy' in machine: + uart_pins = [[('GP12', 'GP13'), ('GP12', 'GP13', 'GP7', 'GP6')], [('GP16', 'GP17'), ('GP16', 'GP17', 'GP7', 'GP6')]] +else: + raise Exception('Board not supported!') + +# just in case we have stdio duplicated on any of the uarts +pyb.repl_uart(None) + +uart0 = UART(0, 1000000, pins=uart_pins[0][0]) +uart1 = UART(1, 1000000, pins=uart_pins[1][0]) + +uart0_int_count = 0 +uart1_int_count = 0 + +def uart0_handler (uart_o): + global uart0_irq + global uart0_int_count + if (uart0_irq.flags() & UART.RX_ANY): + uart0_int_count += 1 + +def uart1_handler (uart_o): + global uart1_irq + global uart1_int_count + if (uart1_irq.flags() & UART.RX_ANY): + uart1_int_count += 1 + +uart0_irq = uart0.irq(trigger=UART.RX_ANY, handler=uart0_handler) +uart1_irq = uart1.irq(trigger=UART.RX_ANY, handler=uart1_handler) + +uart0.write(b'123') +# wait for the characters to be received +while not uart1.any(): + pass + +time.sleep_us(100) +print(uart1.any() == 3) +print(uart1_int_count > 0) +print(uart1_irq.flags() == 0) +print(uart0_irq.flags() == 0) +print(uart1.read() == b'123') + +uart1.write(b'12345') +# wait for the characters to be received +while not uart0.any(): + pass + +time.sleep_us(100) +print(uart0.any() == 5) +print(uart0_int_count > 0) +print(uart0_irq.flags() == 0) +print(uart1_irq.flags() == 0) +print(uart0.read() == b'12345') + +# do it again +uart1_int_count = 0 +uart0.write(b'123') +# wait for the characters to be received +while not uart1.any(): + pass + +time.sleep_us(100) +print(uart1.any() == 3) +print(uart1_int_count > 0) +print(uart1_irq.flags() == 0) +print(uart0_irq.flags() == 0) +print(uart1.read() == b'123') + +# disable the interrupt +uart1_irq.disable() +# do it again +uart1_int_count = 0 +uart0.write(b'123') +# wait for the characters to be received +while not uart1.any(): + pass + +time.sleep_us(100) +print(uart1.any() == 3) +print(uart1_int_count == 0) # no interrupt triggered this time +print(uart1_irq.flags() == 0) +print(uart0_irq.flags() == 0) +print(uart1.read() == b'123') + +# enable the interrupt +uart1_irq.enable() +# do it again +uart1_int_count = 0 +uart0.write(b'123') +# wait for the characters to be received +while not uart1.any(): + pass + +time.sleep_us(100) +print(uart1.any() == 3) +print(uart1_int_count > 0) +print(uart1_irq.flags() == 0) +print(uart0_irq.flags() == 0) +print(uart1.read() == b'123') + +uart1_irq.init(trigger=UART.RX_ANY, handler=None) # No handler +# do it again +uart1_int_count = 0 +uart0.write(b'123') +# wait for the characters to be received +while not uart1.any(): + pass + +time.sleep_us(100) +print(uart1.any() == 3) +print(uart1_int_count == 0) # no interrupt handler called +print(uart1_irq.flags() == 0) +print(uart0_irq.flags() == 0) +print(uart1.read() == b'123') + +# check for memory leaks +for i in range(0, 1000): + uart0_irq = uart0.irq(trigger=UART.RX_ANY, handler=uart0_handler) + uart1_irq = uart1.irq(trigger=UART.RX_ANY, handler=uart1_handler) + +# next ones must raise +try: + uart0_irq = uart0.irq(trigger=100, handler=uart0_handler) +except: + print('Exception') + +try: + uart0_irq = uart0.irq(trigger=0) +except: + print('Exception') + +try: + uart0_irq = uart0.irq(trigger=UART.RX_ANY, wake=Sleep.SUSPENDED) +except: + print('Exception') + +uart0_irq.disable() +uart1_irq.disable() |