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
23 [{2: 'f'}, {0: 'l', 1: 'h'}],
24 [{2: 'f'}, {0: 'h', 1: 'h'}, {1: 'l'}],
25 [{2: 'f'}, {0: 'f'}, {1: 'l'}],
29 class Decoder(srd.Decoder):
33 longname = 'Commodore bus'
34 desc = 'Commodore serial IEEE-488 (IEC) bus protocol.'
39 {'id': 'data', 'name': 'DATA', 'desc': 'Data I/O'},
40 {'id': 'clk', 'name': 'CLK', 'desc': 'Clock'},
41 {'id': 'atn', 'name': 'ATN', 'desc': 'Attention'},
44 {'id': 'srq', 'name': 'SRQ', 'desc': 'Service request'},
52 ('bytes', 'Bytes', (0,)),
53 ('gpib', 'DAT/CMD', (1,)),
58 self.saved_ATN = False
59 self.saved_EOI = False
60 self.ss_item = self.es_item = None
66 self.out_ann = self.register(srd.OUTPUT_ANN)
69 self.put(self.ss_item, self.es_item, self.out_ann, data)
71 def handle_bits(self):
72 # Output the saved item.
76 self.es_item = self.samplenum
77 self.putb([0, ['%02X' % dbyte]])
79 # Encode item byte to GPIB convention.
81 if dATN: # ATN, decode commands.
82 # Note: Commands < 0x20 are not used on IEC bus.
83 if dbyte == 0x01: self.strgpib = 'GTL'
84 if dbyte == 0x04: self.strgpib = 'SDC'
85 if dbyte == 0x05: self.strgpib = 'PPC'
86 if dbyte == 0x08: self.strgpib = 'GET'
87 if dbyte == 0x09: self.strgpib = 'TCT'
88 if dbyte == 0x11: self.strgpib = 'LLO'
89 if dbyte == 0x14: self.strgpib = 'DCL'
90 if dbyte == 0x15: self.strgpib = 'PPU'
91 if dbyte == 0x18: self.strgpib = 'SPE'
92 if dbyte == 0x19: self.strgpib = 'SPD'
94 if dbyte == 0x3f: self.strgpib = 'UNL'
95 if dbyte == 0x5f: self.strgpib = 'UNT'
96 if dbyte > 0x1f and dbyte < 0x3f: # Address listener.
97 self.strgpib = 'L' + chr(dbyte + 0x10)
98 if dbyte > 0x3f and dbyte < 0x5f: # Address talker.
99 self.strgpib = 'T' + chr(dbyte - 0x10)
100 if dbyte > 0x5f and dbyte < 0x70: # Channel reopen.
101 self.strgpib = 'R' + chr(dbyte - 0x30)
102 if dbyte > 0xdf and dbyte < 0xf0: # Channel close.
103 self.strgpib = 'C' + chr(dbyte - 0xb0)
104 if dbyte > 0xef: # Channel open.
105 self.strgpib = 'O' + chr(dbyte - 0xc0)
107 if dbyte > 0x1f and dbyte < 0x7f:
108 self.strgpib = chr(dbyte)
114 self.putb([1, [self.strgpib]])
118 self.putb([2, [self.strEOI]])
123 data, clk, atn, srq = self.wait(step_wait_conds[self.step])
126 # Falling edge on ATN, reset step.
130 # Don't use self.matched[1] here since we might come from
131 # a step with different conds due to the code above.
132 if data == 0 and clk == 1:
133 # Rising edge on CLK while DATA is low: Ready to send.
136 if data == 1 and clk == 1:
137 # Rising edge on DATA while CLK is high: Ready for data.
138 self.ss_item = self.samplenum
139 self.saved_ATN = not atn
140 self.saved_EOI = False
145 # CLK low again, transfer aborted.
148 if data == 0 and clk == 1:
149 # DATA goes low while CLK is still high, EOI confirmed.
150 self.saved_EOI = True
156 # Rising edge on CLK; latch DATA.
157 self.bits |= data << self.numbits
159 # Falling edge on CLK; end of bit.
161 if self.numbits == 8: