3 ## This file is part of the sigrok-dumps project.
5 ## Copyright (C) 2014 Jens Steinhauser <jens.steinhauser@gmail.com>
7 ## This program is free software; you can redistribute it and/or modify
8 ## it under the terms of the GNU General Public License as published by
9 ## the Free Software Foundation; either version 2 of the License, or
10 ## (at your option) any later version.
12 ## This program is distributed in the hope that it will be useful,
13 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ## GNU General Public License for more details.
17 ## You should have received a copy of the GNU General Public License
18 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
21 ## This script generates test cases for the nrf24l01 protocol decoder.
28 def __init__(self, filename):
29 self._filename = filename
33 self._data.append([1, 0, 0, 0])
34 self._data.append([0, 0, 0, 0])
37 self._data.append([0, 0, 0, 0])
38 self._data.append([1, 0, 0, 0])
40 def add(self, mosi, miso):
42 mo = (mosi & 0x80) >> 7
43 mi = (miso & 0x80) >> 7
46 self._data.append([0, 0, mo, mi])
47 self._data.append([0, 1, mo, mi])
49 self._data.append([0, 0, 0, 0])
52 with tempfile.NamedTemporaryFile() as tf:
53 with open(tf.name, 'w') as tff:
55 w.writerow(['CS', 'CLK', 'MOSI', 'MISO'])
56 w.writerows(self._data)
58 fn = '{}.sr'.format(self._filename)
59 I = 'csv:header=true:samplerate=1000'
60 subprocess.check_call(['sigrok-cli', '-I', I, '-i', tf.name, '-o', fn])
62 spi = SPI('nrf24l01-test-activate')
64 spi.add(0x50, 0x00) # ACTIVATE
65 spi.add(0x73, 0x00) # correct payload
68 spi.add(0x50, 0x00) # ACTIVATE
69 spi.add(0x74, 0x00) # wrong payload
73 spi = SPI('nrf24l01-test-excess-bytes')
75 spi.add(0x00, 0x00) # R_REGISTER, reg = CONFIG
79 spi.add(0x00, 0x00) # R_REGISTER, reg = CONFIG
81 spi.add(0x00, 0x00) # excess
84 spi.add(0x20, 0x00) # W_REGISTER, reg = CONFIG
86 spi.add(0x00, 0x00) # excess
89 spi.add(0x20, 0x00) # W_REGISTER, reg = CONFIG
91 spi.add(0x00, 0x00) # excess
92 spi.add(0x00, 0x00) # excess
95 spi.add(0x2a, 0x00) # W_REGISTER, reg = RX_ADDR_P0
101 spi.add(0x00, 0x00) # excess
104 spi.add(0x2c, 0x00) # W_REGISTER, reg = RX_ADDR_P2
106 spi.add(0x00, 0x00) # excess
109 spi.add(0xa0, 0x00) # W_ACK_PAYLOAD, pipe = 0
111 spi.add(i, 0x00) # write 33 bytes, command only expects 32
115 spi = SPI('nrf24l01-test-missing-bytes')
117 spi.add(0x00, 0x00) # R_REGISTER, reg = CONFIG
120 spi.add(0xb0, 0x00) # W_TX_PAYLOAD_NOACK
124 spi = SPI('nrf24l01-test-no-command')
130 spi.add(0x00, 0x00) # R_REGISTER, reg = CONFIG
136 spi.add(0x00, 0x00) # R_REGISTER, reg = CONFIG
141 spi = SPI('nrf24l01-test-unknown-register')
143 spi.add(0x1f, 0x00) # R_REGISTER, reg = 0x1f
148 spi = SPI('nrf24l01-test-unknown-command')
150 spi.add(0x00, 0x00) # R_REGISTER, reg = CONFIG
154 spi.add(0xf0, 0x00) # wrong command
158 spi.add(0x20, 0x00) # W_REGISTER, reg = CONFIG
163 spi = SPI('nrf24l01-test-misc')
165 spi.add(0xe3, 0x00) # REUSE_TX_PL
168 spi.add(0x60, 0x00) # R_RX_PL_WID
172 spi.add(0x60, 0x00) # R_RX_PL_WID
175 spi.add(0x60, 0x00) # R_RX_PL_WID
177 spi.add(0x00, 0x09) # excess
180 spi.add(0xa9, 0x00) # W_ACK_PAYLOAD, pipe = 1
184 spi.add(ord(c), 0x00)
190 spi = SPI('nrf24l01-test-incomplete-cmd')
191 spi.add(0xff, 0xff) # some bytes from a command
192 spi.add(0xff, 0xff) # that was captured incompletely
195 spi.add(0xe1, 0x00) # FLUSH_TX