]> sigrok.org Git - libsigrokdecode.git/blame - decoders/ssi32/pd.py
ssi32: Slightly more descriptive naming.
[libsigrokdecode.git] / decoders / ssi32 / pd.py
CommitLineData
268d62bf
OR
1##
2## This file is part of the libsigrokdecode project.
3##
4## Copyright (C) 2016 Robert Bosch Car Multimedia GmbH
5## Authors: Oleksij Rempel
6## <fixed-term.Oleksij.Rempel@de.bosch.com>
7## <linux@rempel-privat.de>
8##
9## This program is free software; you can redistribute it and/or modify
10## it under the terms of the GNU General Public License as published by
11## the Free Software Foundation; either version 2 of the License, or
12## (at your option) any later version.
13##
d66d47ed
UH
14## This program is distributed in the hope that it will be useful,
15## but WITHOUT ANY WARRANTY; without even the implied warranty of
16## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17## GNU General Public License for more details.
18##
19## You should have received a copy of the GNU General Public License
20## along with this program; if not, write to the Free Software
21## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22##
268d62bf
OR
23
24import sigrokdecode as srd
268d62bf
OR
25
26class Decoder(srd.Decoder):
27 api_version = 2
28 id = 'ssi32'
29 name = 'SSI32'
e1fefac5
UH
30 longname = 'Synchronous Serial Interface (32bit)'
31 desc = 'Synchronous Serial Interface (32bit) protocol.'
268d62bf
OR
32 license = 'gplv2+'
33 inputs = ['spi']
34 outputs = ['ssi32']
35 options = (
36 {'id': 'msgsize', 'desc': 'Message size', 'default': 64},
37 )
38 annotations = (
39 ('ctrl-tx', 'CTRL TX'),
40 ('ack-tx', 'ACK TX'),
41 ('ctrl-rx', 'CTRL RX'),
d66d47ed 42 ('ack-rx', 'ACK RX'),
268d62bf
OR
43 )
44 annotation_rows = (
d66d47ed
UH
45 ('tx', 'TX', (0, 1)),
46 ('rx', 'RX', (2, 3)),
268d62bf
OR
47 )
48
49 def __init__(self):
50 self.ss_cmd, self.es_cmd = 0, 0
51 self.mosi_bytes = []
52 self.miso_bytes = []
53 self.es_array = []
54 self.rx_size = 0
55 self.tx_size = 0
56
57 def start(self):
58 self.out_ann = self.register(srd.OUTPUT_ANN)
59
60 def putx(self, data):
61 self.put(self.ss_cmd, self.es_cmd, self.out_ann, data)
62
63 def reset(self):
64 self.mosi_bytes = []
65 self.miso_bytes = []
66 self.es_array = []
67
68 def handle_ack(self):
d66d47ed 69 # Only first byte should have ACK data, other 3 bytes are reserved.
268d62bf
OR
70 self.es_cmd = self.es_array[0]
71 self.putx([1, ['> ACK:0x%02x' % (self.mosi_bytes[0])]])
72 self.putx([3, ['< ACK:0x%02x' % (self.miso_bytes[0])]])
73
74 def handle_ctrl(self):
75 mosi = miso = ''
76 self.tx_size = self.mosi_bytes[2]
77 self.rx_size = self.miso_bytes[2]
78
79 if self.tx_size > 0:
80 mosi = ', DATA:0x' + ''.join(format(x, '02x') for x in self.mosi_bytes[4:self.tx_size + 4])
81 if self.rx_size > 0:
82 miso = ', DATA:0x' + ''.join(format(x, '02x') for x in self.miso_bytes[4:self.rx_size + 4])
83
84 self.es_cmd = self.es_array[self.tx_size + 3]
d66d47ed 85 self.putx([0, ['> CTRL:0x%02x, LUN:0x%02x, SIZE:0x%02x, CRC:0x%02x%s'
268d62bf
OR
86 % (self.mosi_bytes[0], self.mosi_bytes[1],
87 self.mosi_bytes[2], self.mosi_bytes[3], mosi)]])
88
89 self.es_cmd = self.es_array[self.rx_size + 3]
d66d47ed 90 self.putx([2, ['< CTRL:0x%02x, LUN:0x%02x, SIZE:0x%02x, CRC:0x%02x%s'
268d62bf
OR
91 % (self.miso_bytes[0], self.miso_bytes[1],
92 self.miso_bytes[2], self.miso_bytes[3], miso)]])
93
94 def decode(self, ss, es, data):
95 ptype = data[0]
96 if ptype == 'CS-CHANGE':
97 self.reset()
98 return
99
100 # Don't care about anything else.
101 if ptype != 'DATA':
102 return
103 mosi, miso = data[1:]
104
105 self.ss, self.es = ss, es
106
107 if len(self.mosi_bytes) == 0:
108 self.ss_cmd = ss
109 self.mosi_bytes.append(mosi)
110 self.miso_bytes.append(miso)
111 self.es_array.append(es)
112
113 if self.mosi_bytes[0] & 0x80:
114 if len(self.mosi_bytes) < 4:
115 return
116
117 self.handle_ack()
118 self.reset()
119 else:
120 if len(self.mosi_bytes) < self.options['msgsize']:
121 return
122
123 self.handle_ctrl()
124 self.reset()