2 ## This file is part of the libsigrokdecode project.
4 ## Copyright (C) 2015 Karl Palsson <karlp@tweak.net.au>
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 2 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, write to the Free Software
18 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 import sigrokdecode as srd
151 0x23C: 'Unimplemented',
152 0x23D: 'Unimplemented',
153 0x23E: 'Unimplemented',
154 0x23F: 'Unimplemented',
170 class Decoder(srd.Decoder):
174 longname = 'Microchip MRF24J40'
175 desc = 'IEEE 802.15.4 2.4 GHz RF tranceiver chip.'
178 outputs = ['mrf24j40']
180 ('sread', 'Short register read commands'),
181 ('swrite', 'Short register write commands'),
182 ('lread', 'Long register read commands'),
183 ('lwrite', 'Long register write commands'),
184 ('warning', 'Warnings'),
187 ('read', 'Read', (0, 2)),
188 ('write', 'Write', (1, 3)),
189 ('warnings', 'Warnings', (4,)),
192 def __init__(self, **kwargs):
193 self.ss_cmd, self.es_cmd = 0, 0
198 self.out_ann = self.register(srd.OUTPUT_ANN)
200 def putx(self, data):
201 self.put(self.ss_cmd, self.es_cmd, self.out_ann, data)
203 def putw(self, pos, msg):
204 self.put(pos[0], pos[1], self.out_ann, [4, [msg]])
210 def handle_short(self):
211 write = self.mosi_bytes[0] & 0x1
212 reg = (self.mosi_bytes[0] >> 1) & 0x3f
213 reg_desc = sregs.get(reg, 'illegal')
215 self.putx([1, ['%s: %#x' % (reg_desc, self.mosi_bytes[1])]])
217 self.putx([0, ['%s: %#x' % (reg_desc, self.miso_bytes[1])]])
219 def handle_long(self):
220 dword = self.mosi_bytes[0] << 8 | self.mosi_bytes[1]
221 write = dword & (0x1 << 4)
222 reg = dword >> 5 & 0x3ff
224 reg_desc = 'TX:%#x' % reg
226 reg_desc = 'TX beacon:%#x' % reg
228 reg_desc = 'TX GTS1:%#x' % reg
230 reg_desc = 'TX GTS2:%#x' % reg
232 reg_desc = lregs.get(reg, 'illegal')
234 reg_desc = 'Security keys:%#x' % reg
236 reg_desc = 'Reserved:%#x' % reg
238 reg_desc = 'RX:%#x' % reg
241 self.putx([3, ['%s: %#x' % (reg_desc, self.mosi_bytes[2])]])
243 self.putx([2, ['%s: %#x' % (reg_desc, self.miso_bytes[2])]])
245 def decode(self, ss, es, data):
247 if ptype == 'CS-CHANGE':
248 # If we transition high mid-stream, toss out our data and restart.
249 cs_old, cs_new = data[1:]
250 if cs_old is not None and cs_old == 0 and cs_new == 1:
251 if len(self.mosi_bytes) not in (0, 2, 3):
252 self.putw([self.ss_cmd, es], 'Misplaced CS!')
256 # Don't care about anything else.
259 mosi, miso = data[1:]
261 self.ss, self.es = ss, es
263 if len(self.mosi_bytes) == 0:
265 self.mosi_bytes.append(mosi)
266 self.miso_bytes.append(miso)
268 # Everything is either 2 bytes or 3 bytes.
269 if len(self.mosi_bytes) < 2:
272 if self.mosi_bytes[0] & 0x80:
273 if len(self.mosi_bytes) == 3: