2 ## This file is part of the libsigrokdecode project.
4 ## Copyright (C) 2017 Marcus Comstedt <marcus@mc.pp.se>
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, see <http://www.gnu.org/licenses/>.
20 import sigrokdecode as srd
22 class Decoder(srd.Decoder):
26 longname = 'Commodore bus'
27 desc = 'Commodore serial IEEE-488 (IEC) bus protocol.'
32 {'id': 'data', 'name': 'DATA', 'desc': 'Data I/O'},
33 {'id': 'clk', 'name': 'CLK', 'desc': 'Clock'},
34 {'id': 'atn', 'name': 'ATN', 'desc': 'Attention'},
37 {'id': 'srq', 'name': 'SRQ', 'desc': 'Service request'},
45 ('bytes', 'Bytes', (0,)),
46 ('gpib', 'DAT/CMD', (1,)),
51 self.saved_ATN = False
52 self.saved_EOI = False
54 self.ss_item = self.es_item = None
60 self.out_ann = self.register(srd.OUTPUT_ANN)
63 self.put(self.ss_item, self.es_item, self.out_ann, data)
65 def handle_bits(self):
66 # Output the saved item.
70 self.es_item = self.samplenum
71 self.putb([0, ['%02X' % dbyte]])
73 # Encode item byte to GPIB convention.
75 if dATN: # ATN, decode commands.
76 # Note: Commands < 0x20 are not used on IEC bus.
77 if dbyte == 0x01: self.strgpib = 'GTL'
78 if dbyte == 0x04: self.strgpib = 'SDC'
79 if dbyte == 0x05: self.strgpib = 'PPC'
80 if dbyte == 0x08: self.strgpib = 'GET'
81 if dbyte == 0x09: self.strgpib = 'TCT'
82 if dbyte == 0x11: self.strgpib = 'LLO'
83 if dbyte == 0x14: self.strgpib = 'DCL'
84 if dbyte == 0x15: self.strgpib = 'PPU'
85 if dbyte == 0x18: self.strgpib = 'SPE'
86 if dbyte == 0x19: self.strgpib = 'SPD'
88 if dbyte == 0x3f: self.strgpib = 'UNL'
89 if dbyte == 0x5f: self.strgpib = 'UNT'
90 if dbyte > 0x1f and dbyte < 0x3f: # Address listener.
91 self.strgpib = 'L' + chr(dbyte + 0x10)
92 if dbyte > 0x3f and dbyte < 0x5f: # Address talker.
93 self.strgpib = 'T' + chr(dbyte - 0x10)
94 if dbyte > 0x5f and dbyte < 0x70: # Channel reopen.
95 self.strgpib = 'R' + chr(dbyte - 0x30)
96 if dbyte > 0xdf and dbyte < 0xf0: # Channel close.
97 self.strgpib = 'C' + chr(dbyte - 0xb0)
98 if dbyte > 0xef: # Channel open.
99 self.strgpib = 'O' + chr(dbyte - 0xc0)
101 if dbyte > 0x1f and dbyte < 0x7f:
102 self.strgpib = chr(dbyte)
108 self.putb([1, [self.strgpib]])
112 self.putb([2, [self.strEOI]])
114 def decode(self, ss, es, data):
115 for (self.samplenum, pins) in data:
117 # Ignore identical samples early on (for performance reasons).
118 if self.oldpins == pins:
121 if pins[2] == 0 and self.oldpins[2] == 1:
122 # Falling edge on ATN, reset step.
126 if pins[0] == 0 and pins[1] == 1:
127 # Rising edge on CLK while DATA is low: Ready to send.
130 if pins[0] == 1 and pins[1] == 1:
131 # Rising edge on DATA while CLK is high: Ready for data.
132 self.ss_item = self.samplenum
133 self.saved_ATN = not pins[2]
134 self.saved_EOI = False
139 # CLK low again, transfer aborted.
142 if pins[0] == 0 and pins[1] == 1:
143 # DATA goes low while CLK is still high, EOI confirmed.
144 self.saved_EOI = True
148 if pins[1] == 1 and self.oldpins[1] == 0:
149 # Rising edge on CLK; latch DATA.
150 self.bits |= pins[0] << self.numbits
151 elif pins[1] == 0 and self.oldpins[1] == 1:
152 # Falling edge on CLK; end of bit.
154 if self.numbits == 8: