2 ## This file is part of the libsigrokdecode project.
4 ## Copyright (C) 2016 Rudolf Reuter <reuterru@arcor.de>
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 = 'General Purpose Interface Bus'
27 desc = 'IEEE-488 GPIB / HPIB protocol.'
32 {'id': 'dio1' , 'name': 'DIO1', 'desc': 'Data I/O bit 1'},
33 {'id': 'dio2' , 'name': 'DIO2', 'desc': 'Data I/O bit 2'},
34 {'id': 'dio3' , 'name': 'DIO3', 'desc': 'Data I/O bit 3'},
35 {'id': 'dio4' , 'name': 'DIO4', 'desc': 'Data I/O bit 4'},
36 {'id': 'dio5' , 'name': 'DIO5', 'desc': 'Data I/O bit 5'},
37 {'id': 'dio6' , 'name': 'DIO6', 'desc': 'Data I/O bit 6'},
38 {'id': 'dio7' , 'name': 'DIO7', 'desc': 'Data I/O bit 7'},
39 {'id': 'dio8' , 'name': 'DIO8', 'desc': 'Data I/O bit 8'},
40 {'id': 'eoi', 'name': 'EOI', 'desc': 'End or identify'},
41 {'id': 'dav', 'name': 'DAV', 'desc': 'Data valid'},
42 {'id': 'nrfd', 'name': 'NRFD', 'desc': 'Not ready for data'},
43 {'id': 'ndac', 'name': 'NDAC', 'desc': 'Not data accepted'},
44 {'id': 'ifc', 'name': 'IFC', 'desc': 'Interface clear'},
45 {'id': 'srq', 'name': 'SRQ', 'desc': 'Service request'},
46 {'id': 'atn', 'name': 'ATN', 'desc': 'Attention'},
47 {'id': 'ren', 'name': 'REN', 'desc': 'Remote enable'},
50 {'id': 'sample_total', 'desc': 'Total number of samples', 'default': 0},
58 ('bytes', 'Bytes', (0,)),
59 ('gpib', 'DAT/CMD', (1,)),
66 self.saved_item = None
67 self.saved_ATN = False
68 self.saved_EOI = False
70 self.ss_item = self.es_item = None
74 self.out_ann = self.register(srd.OUTPUT_ANN)
77 self.put(self.ss_item, self.es_item, self.out_ann, data)
79 def handle_bits(self, datapins):
85 # If this is the first item in a word, save its sample number.
86 if self.itemcount == 0:
87 self.ss_word = self.samplenum
89 # Get the bits for this item.
92 item |= datapins[i] << i
94 item = item ^ 0xff # Invert data byte.
95 self.items.append(item)
104 # Save the start sample and item for later (no output yet).
105 self.ss_item = self.samplenum
107 self.saved_item = item
108 self.saved_ATN = item2
109 self.saved_EOI = item3
111 # Output the saved item.
112 dbyte = self.saved_item
113 dATN = self.saved_ATN
114 dEOI = self.saved_EOI
115 self.es_item = self.samplenum
116 self.putb([0, ['%02X' % self.saved_item]])
118 # Encode item byte to GPIB convention.
120 if dATN: # ATN, decode commands.
121 if dbyte == 0x01: self.strgpib = 'GTL'
122 if dbyte == 0x04: self.strgpib = 'SDC'
123 if dbyte == 0x05: self.strgpib = 'PPC'
124 if dbyte == 0x08: self.strgpib = 'GET'
125 if dbyte == 0x09: self.strgpib = 'TCT'
126 if dbyte == 0x11: self.strgpib = 'LLO'
127 if dbyte == 0x14: self.strgpib = 'DCL'
128 if dbyte == 0x15: self.strgpib = 'PPU'
129 if dbyte == 0x18: self.strgpib = 'SPE'
130 if dbyte == 0x19: self.strgpib = 'SPD'
131 if dbyte == 0x3f: self.strgpib = 'UNL'
132 if dbyte == 0x5f: self.strgpib = 'UNT'
133 if dbyte > 0x1f and dbyte < 0x3f: # Address Listener.
134 self.strgpib = 'L' + chr(dbyte + 0x10)
135 if dbyte > 0x3f and dbyte < 0x5f: # Address Talker
136 self.strgpib = 'T' + chr(dbyte - 0x10)
138 if dbyte > 0x1f and dbyte < 0x7f:
139 self.strgpib = chr(dbyte)
145 self.putb([1, [self.strgpib]])
149 self.putb([2, [self.strEOI]])
151 self.ss_item = self.samplenum
152 self.saved_item = item
153 self.saved_ATN = item2
154 self.saved_EOI = item3
156 if self.itemcount < 16:
159 self.itemcount, self.items = 0, []
163 # Inspect samples at falling edge of DAV. But make sure to also
164 # start inspection when the capture happens to start with low
165 # DAV level. Optionally enforce processing when a user specified
166 # sample number was reached.
167 waitcond = [{9: 'l'}]
168 lsn = self.options['sample_total']
170 waitcond.append({'skip': lsn})
173 waitcond[1]['skip'] = lsn - self.samplenum - 1
174 pins = self.wait(waitcond)
175 self.handle_bits(pins)