2 ## This file is part of the libsigrokdecode project.
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>
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.
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.
19 ## You should have received a copy of the GNU General Public License
20 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
23 import sigrokdecode as srd
25 class Decoder(srd.Decoder):
29 longname = 'Synchronous Serial Interface (32bit)'
30 desc = 'Synchronous Serial Interface (32bit) protocol.'
35 {'id': 'msgsize', 'desc': 'Message size', 'default': 64},
38 ('ctrl-tx', 'CTRL TX'),
40 ('ctrl-rx', 'CTRL RX'),
49 self.ss_cmd, self.es_cmd = 0, 0
57 self.out_ann = self.register(srd.OUTPUT_ANN)
60 self.put(self.ss_cmd, self.es_cmd, self.out_ann, data)
68 # Only first byte should have ACK data, other 3 bytes are reserved.
69 self.es_cmd = self.es_array[0]
70 self.putx([1, ['> ACK:0x%02x' % (self.mosi_bytes[0])]])
71 self.putx([3, ['< ACK:0x%02x' % (self.miso_bytes[0])]])
73 def handle_ctrl(self):
75 self.tx_size = self.mosi_bytes[2]
76 self.rx_size = self.miso_bytes[2]
79 mosi = ', DATA:0x' + ''.join(format(x, '02x') for x in self.mosi_bytes[4:self.tx_size + 4])
81 miso = ', DATA:0x' + ''.join(format(x, '02x') for x in self.miso_bytes[4:self.rx_size + 4])
83 self.es_cmd = self.es_array[self.tx_size + 3]
84 self.putx([0, ['> CTRL:0x%02x, LUN:0x%02x, SIZE:0x%02x, CRC:0x%02x%s'
85 % (self.mosi_bytes[0], self.mosi_bytes[1],
86 self.mosi_bytes[2], self.mosi_bytes[3], mosi)]])
88 self.es_cmd = self.es_array[self.rx_size + 3]
89 self.putx([2, ['< CTRL:0x%02x, LUN:0x%02x, SIZE:0x%02x, CRC:0x%02x%s'
90 % (self.miso_bytes[0], self.miso_bytes[1],
91 self.miso_bytes[2], self.miso_bytes[3], miso)]])
93 def decode(self, ss, es, data):
95 if ptype == 'CS-CHANGE':
99 # Don't care about anything else.
102 mosi, miso = data[1:]
104 self.ss, self.es = ss, es
106 if len(self.mosi_bytes) == 0:
108 self.mosi_bytes.append(mosi)
109 self.miso_bytes.append(miso)
110 self.es_array.append(es)
112 if self.mosi_bytes[0] & 0x80:
113 if len(self.mosi_bytes) < 4:
119 if len(self.mosi_bytes) < self.options['msgsize']: