diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/pyb/can.py | 72 | ||||
-rw-r--r-- | tests/pyb/can.py.exp | 24 |
2 files changed, 96 insertions, 0 deletions
diff --git a/tests/pyb/can.py b/tests/pyb/can.py index f1cad860b9..132da23069 100644 --- a/tests/pyb/can.py +++ b/tests/pyb/can.py @@ -48,3 +48,75 @@ else: print('passed') else: print('failed, wrong data received') + +del can + +# Test RxCallbacks +can = CAN(1, CAN.LOOPBACK) +can.setfilter(0, CAN.LIST16, 0, (1, 2, 3, 4)) +can.setfilter(1, CAN.LIST16, 1, (5, 6, 7, 8)) +def cb0(bus, reason): + print('cb0') + if reason == 0: + print('pending') + if reason == 1: + print('full') + if reason == 2: + print('overflow') + +def cb1(bus, reason): + print('cb1') + if reason == 0: + print('pending') + if reason == 1: + print('full') + if reason == 2: + print('overflow') + +def cb0a(bus, reason): + print('cb0a') + if reason == 0: + print('pending') + if reason == 1: + print('full') + if reason == 2: + print('overflow') + +def cb1a(bus, reason): + print('cb1a') + if reason == 0: + print('pending') + if reason == 1: + print('full') + if reason == 2: + print('overflow') + + +can.rxcallback(0, cb0) +can.rxcallback(1, cb1) + +can.send('11111111',1) +can.send('22222222',2) +can.send('33333333',3) +can.rxcallback(0, cb0a) +can.send('44444444',4) + +can.send('55555555',5) +can.send('66666666',6) +can.send('77777777',7) +can.rxcallback(1, cb1a) +can.send('88888888',8) + +print(can.recv(0)) +print(can.recv(0)) +print(can.recv(0)) +print(can.recv(1)) +print(can.recv(1)) +print(can.recv(1)) + +can.send('11111111',1) +can.send('55555555',5) + +print(can.recv(0)) +print(can.recv(1)) + diff --git a/tests/pyb/can.py.exp b/tests/pyb/can.py.exp index 4058202046..b0ede7b9f4 100644 --- a/tests/pyb/can.py.exp +++ b/tests/pyb/can.py.exp @@ -8,3 +8,27 @@ True passed CAN(1, CAN.LOOPBACK, extframe=True) passed +cb0 +pending +cb0 +full +cb0a +overflow +cb1 +pending +cb1 +full +cb1a +overflow +(1, 0, 0, b'11111111') +(2, 0, 1, b'22222222') +(4, 0, 3, b'44444444') +(5, 0, 0, b'55555555') +(6, 0, 1, b'66666666') +(8, 0, 3, b'88888888') +cb0a +pending +cb1a +pending +(1, 0, 0, b'11111111') +(5, 0, 0, b'55555555') |