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, write to the Free Software
19 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 ## This script generates test cases for the nrf24l01 protocol decoder.
29 def __init__(self, filename):
30 self._filename = filename
34 self._data.append([1, 0, 0, 0])
35 self._data.append([0, 0, 0, 0])
38 self._data.append([0, 0, 0, 0])
39 self._data.append([1, 0, 0, 0])
41 def add(self, mosi, miso):
43 mo = (mosi & 0x80) >> 7
44 mi = (miso & 0x80) >> 7
47 self._data.append([0, 0, mo, mi])
48 self._data.append([0, 1, mo, mi])
50 self._data.append([0, 0, 0, 0])
53 with tempfile.NamedTemporaryFile() as tf:
54 with open(tf.name, 'w') as tff:
56 w.writerow(['CS', 'CLK', 'MOSI', 'MISO'])
57 w.writerows(self._data)
59 fn = '{}.sr'.format(self._filename)
60 I = 'csv:header=true:samplerate=1000'
61 subprocess.check_call(['sigrok-cli', '-I', I, '-i', tf.name, '-o', fn])
63 spi = SPI('nrf24l01-test-activate')
65 spi.add(0x50, 0x00) # ACTIVATE
66 spi.add(0x73, 0x00) # correct payload
69 spi.add(0x50, 0x00) # ACTIVATE
70 spi.add(0x74, 0x00) # wrong payload
74 spi = SPI('nrf24l01-test-excess-bytes')
76 spi.add(0x00, 0x00) # R_REGISTER, reg = CONFIG
80 spi.add(0x00, 0x00) # R_REGISTER, reg = CONFIG
82 spi.add(0x00, 0x00) # excess
85 spi.add(0x20, 0x00) # W_REGISTER, reg = CONFIG
87 spi.add(0x00, 0x00) # excess
90 spi.add(0x20, 0x00) # W_REGISTER, reg = CONFIG
92 spi.add(0x00, 0x00) # excess
93 spi.add(0x00, 0x00) # excess
96 spi.add(0x2a, 0x00) # W_REGISTER, reg = RX_ADDR_P0
102 spi.add(0x00, 0x00) # excess
105 spi.add(0x2c, 0x00) # W_REGISTER, reg = RX_ADDR_P2
107 spi.add(0x00, 0x00) # excess
110 spi.add(0xa0, 0x00) # W_ACK_PAYLOAD, pipe = 0
112 spi.add(i, 0x00) # write 33 bytes, command only expects 32
116 spi = SPI('nrf24l01-test-missing-bytes')
118 spi.add(0x00, 0x00) # R_REGISTER, reg = CONFIG
121 spi.add(0xb0, 0x00) # W_TX_PAYLOAD_NOACK
125 spi = SPI('nrf24l01-test-no-command')
131 spi.add(0x00, 0x00) # R_REGISTER, reg = CONFIG
137 spi.add(0x00, 0x00) # R_REGISTER, reg = CONFIG
142 spi = SPI('nrf24l01-test-unknown-register')
144 spi.add(0x1f, 0x00) # R_REGISTER, reg = 0x1f
149 spi = SPI('nrf24l01-test-unknown-command')
151 spi.add(0x00, 0x00) # R_REGISTER, reg = CONFIG
155 spi.add(0xf0, 0x00) # wrong command
159 spi.add(0x20, 0x00) # W_REGISTER, reg = CONFIG
164 spi = SPI('nrf24l01-test-misc')
166 spi.add(0xe3, 0x00) # REUSE_TX_PL
169 spi.add(0x60, 0x00) # R_RX_PL_WID
173 spi.add(0x60, 0x00) # R_RX_PL_WID
176 spi.add(0x60, 0x00) # R_RX_PL_WID
178 spi.add(0x00, 0x09) # excess
181 spi.add(0xa9, 0x00) # W_ACK_PAYLOAD, pipe = 1
185 spi.add(ord(c), 0x00)
191 spi = SPI('nrf24l01-test-incomplete-cmd')
192 spi.add(0xff, 0xff) # some bytes from a command
193 spi.add(0xff, 0xff) # that was captured incompletely
196 spi.add(0xe1, 0x00) # FLUSH_TX