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,)),
61 self.saved_ATN = False
62 self.saved_EOI = False
63 self.ss_item = self.es_item = None
69 self.out_ann = self.register(srd.OUTPUT_ANN)
72 self.put(self.ss_item, self.es_item, self.out_ann, data)
74 def handle_bits(self):
75 # Output the saved item.
79 self.es_item = self.samplenum
80 self.putb([0, ['%02X' % dbyte]])
82 # Encode item byte to GPIB convention.
84 if dATN: # ATN, decode commands.
85 # Note: Commands < 0x20 are not used on IEC bus.
86 if dbyte == 0x01: self.strgpib = 'GTL'
87 if dbyte == 0x04: self.strgpib = 'SDC'
88 if dbyte == 0x05: self.strgpib = 'PPC'
89 if dbyte == 0x08: self.strgpib = 'GET'
90 if dbyte == 0x09: self.strgpib = 'TCT'
91 if dbyte == 0x11: self.strgpib = 'LLO'
92 if dbyte == 0x14: self.strgpib = 'DCL'
93 if dbyte == 0x15: self.strgpib = 'PPU'
94 if dbyte == 0x18: self.strgpib = 'SPE'
95 if dbyte == 0x19: self.strgpib = 'SPD'
97 if dbyte == 0x3f: self.strgpib = 'UNL'
98 if dbyte == 0x5f: self.strgpib = 'UNT'
99 if dbyte > 0x1f and dbyte < 0x3f: # Address listener.
100 self.strgpib = 'L' + chr(dbyte + 0x10)
101 if dbyte > 0x3f and dbyte < 0x5f: # Address talker.
102 self.strgpib = 'T' + chr(dbyte - 0x10)
103 if dbyte > 0x5f and dbyte < 0x70: # Channel reopen.
104 self.strgpib = 'R' + chr(dbyte - 0x30)
105 if dbyte > 0xdf and dbyte < 0xf0: # Channel close.
106 self.strgpib = 'C' + chr(dbyte - 0xb0)
107 if dbyte > 0xef: # Channel open.
108 self.strgpib = 'O' + chr(dbyte - 0xc0)
110 if dbyte > 0x1f and dbyte < 0x7f:
111 self.strgpib = chr(dbyte)
117 self.putb([1, [self.strgpib]])
121 self.putb([2, [self.strEOI]])
126 data, clk, atn, srq = self.wait(step_wait_conds[self.step])
129 # Falling edge on ATN, reset step.
133 # Don't use self.matched[1] here since we might come from
134 # a step with different conds due to the code above.
135 if data == 0 and clk == 1:
136 # Rising edge on CLK while DATA is low: Ready to send.
139 if data == 1 and clk == 1:
140 # Rising edge on DATA while CLK is high: Ready for data.
141 self.ss_item = self.samplenum
142 self.saved_ATN = not atn
143 self.saved_EOI = False
148 # CLK low again, transfer aborted.
151 if data == 0 and clk == 1:
152 # DATA goes low while CLK is still high, EOI confirmed.
153 self.saved_EOI = True
159 # Rising edge on CLK; latch DATA.
160 self.bits |= data << self.numbits
162 # Falling edge on CLK; end of bit.
164 if self.numbits == 8: