]>
Commit | Line | Data |
---|---|---|
ffd58b68 RR |
1 | ## |
2 | ## This file is part of the libsigrokdecode project. | |
3 | ## | |
4 | ## Copyright (C) 2016 Rudolf Reuter <reuterru@arcor.de> | |
5 | ## | |
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. | |
10 | ## | |
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. | |
15 | ## | |
16 | ## You should have received a copy of the GNU General Public License | |
4539e9ca | 17 | ## along with this program; if not, see <http://www.gnu.org/licenses/>. |
ffd58b68 RR |
18 | ## |
19 | ||
20 | import sigrokdecode as srd | |
21 | ||
22 | class Decoder(srd.Decoder): | |
3b5b9ad2 | 23 | api_version = 3 |
ffd58b68 RR |
24 | id = 'gpib' |
25 | name = 'GPIB' | |
26 | longname = 'General Purpose Interface Bus' | |
2787cf2a | 27 | desc = 'IEEE-488 General Purpose Interface Bus (GPIB / HPIB).' |
ffd58b68 RR |
28 | license = 'gplv2+' |
29 | inputs = ['logic'] | |
6cbba91f | 30 | outputs = [] |
d6d8a8a4 | 31 | tags = ['PC'] |
ffd58b68 RR |
32 | channels = ( |
33 | {'id': 'dio1' , 'name': 'DIO1', 'desc': 'Data I/O bit 1'}, | |
34 | {'id': 'dio2' , 'name': 'DIO2', 'desc': 'Data I/O bit 2'}, | |
35 | {'id': 'dio3' , 'name': 'DIO3', 'desc': 'Data I/O bit 3'}, | |
36 | {'id': 'dio4' , 'name': 'DIO4', 'desc': 'Data I/O bit 4'}, | |
37 | {'id': 'dio5' , 'name': 'DIO5', 'desc': 'Data I/O bit 5'}, | |
38 | {'id': 'dio6' , 'name': 'DIO6', 'desc': 'Data I/O bit 6'}, | |
39 | {'id': 'dio7' , 'name': 'DIO7', 'desc': 'Data I/O bit 7'}, | |
40 | {'id': 'dio8' , 'name': 'DIO8', 'desc': 'Data I/O bit 8'}, | |
41 | {'id': 'eoi', 'name': 'EOI', 'desc': 'End or identify'}, | |
42 | {'id': 'dav', 'name': 'DAV', 'desc': 'Data valid'}, | |
43 | {'id': 'nrfd', 'name': 'NRFD', 'desc': 'Not ready for data'}, | |
44 | {'id': 'ndac', 'name': 'NDAC', 'desc': 'Not data accepted'}, | |
45 | {'id': 'ifc', 'name': 'IFC', 'desc': 'Interface clear'}, | |
46 | {'id': 'srq', 'name': 'SRQ', 'desc': 'Service request'}, | |
47 | {'id': 'atn', 'name': 'ATN', 'desc': 'Attention'}, | |
48 | {'id': 'ren', 'name': 'REN', 'desc': 'Remote enable'}, | |
49 | ) | |
ffd58b68 RR |
50 | annotations = ( |
51 | ('items', 'Items'), | |
52 | ('gpib', 'DAT/CMD'), | |
53 | ('eoi', 'EOI'), | |
54 | ) | |
55 | annotation_rows = ( | |
56 | ('bytes', 'Bytes', (0,)), | |
57 | ('gpib', 'DAT/CMD', (1,)), | |
58 | ('eoi', 'EOI', (2,)), | |
59 | ) | |
60 | ||
61 | def __init__(self): | |
10aeb8ea GS |
62 | self.reset() |
63 | ||
64 | def reset(self): | |
ffd58b68 RR |
65 | self.items = [] |
66 | self.itemcount = 0 | |
67 | self.saved_item = None | |
68 | self.saved_ATN = False | |
69 | self.saved_EOI = False | |
70 | self.samplenum = 0 | |
ffd58b68 RR |
71 | self.ss_item = self.es_item = None |
72 | self.first = True | |
73 | ||
74 | def start(self): | |
75 | self.out_ann = self.register(srd.OUTPUT_ANN) | |
76 | ||
77 | def putb(self, data): | |
78 | self.put(self.ss_item, self.es_item, self.out_ann, data) | |
79 | ||
80 | def handle_bits(self, datapins): | |
81 | dbyte = 0x20 | |
82 | dATN = False | |
83 | item2 = False | |
84 | dEOI = False | |
85 | item3 = False | |
86 | # If this is the first item in a word, save its sample number. | |
87 | if self.itemcount == 0: | |
88 | self.ss_word = self.samplenum | |
89 | ||
90 | # Get the bits for this item. | |
91 | item = 0 | |
92 | for i in range(8): | |
93 | item |= datapins[i] << i | |
94 | ||
95 | item = item ^ 0xff # Invert data byte. | |
96 | self.items.append(item) | |
97 | self.itemcount += 1 | |
98 | ||
99 | if datapins[14] == 0: | |
100 | item2 = True | |
101 | if datapins[8] == 0: | |
102 | item3 = True | |
103 | ||
104 | if self.first: | |
105 | # Save the start sample and item for later (no output yet). | |
106 | self.ss_item = self.samplenum | |
107 | self.first = False | |
108 | self.saved_item = item | |
109 | self.saved_ATN = item2 | |
110 | self.saved_EOI = item3 | |
111 | else: | |
112 | # Output the saved item. | |
113 | dbyte = self.saved_item | |
114 | dATN = self.saved_ATN | |
115 | dEOI = self.saved_EOI | |
116 | self.es_item = self.samplenum | |
117 | self.putb([0, ['%02X' % self.saved_item]]) | |
118 | ||
119 | # Encode item byte to GPIB convention. | |
120 | self.strgpib = ' ' | |
121 | if dATN: # ATN, decode commands. | |
122 | if dbyte == 0x01: self.strgpib = 'GTL' | |
123 | if dbyte == 0x04: self.strgpib = 'SDC' | |
124 | if dbyte == 0x05: self.strgpib = 'PPC' | |
125 | if dbyte == 0x08: self.strgpib = 'GET' | |
126 | if dbyte == 0x09: self.strgpib = 'TCT' | |
127 | if dbyte == 0x11: self.strgpib = 'LLO' | |
128 | if dbyte == 0x14: self.strgpib = 'DCL' | |
129 | if dbyte == 0x15: self.strgpib = 'PPU' | |
130 | if dbyte == 0x18: self.strgpib = 'SPE' | |
131 | if dbyte == 0x19: self.strgpib = 'SPD' | |
132 | if dbyte == 0x3f: self.strgpib = 'UNL' | |
133 | if dbyte == 0x5f: self.strgpib = 'UNT' | |
134 | if dbyte > 0x1f and dbyte < 0x3f: # Address Listener. | |
135 | self.strgpib = 'L' + chr(dbyte + 0x10) | |
136 | if dbyte > 0x3f and dbyte < 0x5f: # Address Talker | |
137 | self.strgpib = 'T' + chr(dbyte - 0x10) | |
138 | else: | |
139 | if dbyte > 0x1f and dbyte < 0x7f: | |
140 | self.strgpib = chr(dbyte) | |
141 | if dbyte == 0x0a: | |
142 | self.strgpib = 'LF' | |
143 | if dbyte == 0x0d: | |
144 | self.strgpib = 'CR' | |
145 | ||
146 | self.putb([1, [self.strgpib]]) | |
147 | self.strEOI = ' ' | |
148 | if dEOI: | |
149 | self.strEOI = 'EOI' | |
150 | self.putb([2, [self.strEOI]]) | |
151 | ||
152 | self.ss_item = self.samplenum | |
153 | self.saved_item = item | |
154 | self.saved_ATN = item2 | |
155 | self.saved_EOI = item3 | |
156 | ||
157 | if self.itemcount < 16: | |
158 | return | |
159 | ||
160 | self.itemcount, self.items = 0, [] | |
161 | ||
3b5b9ad2 | 162 | def decode(self): |
ffd58b68 | 163 | |
3b5b9ad2 GS |
164 | # Inspect samples at falling edge of DAV. But make sure to also |
165 | # start inspection when the capture happens to start with low | |
d21d2b79 | 166 | # DAV level. |
3b5b9ad2 | 167 | waitcond = [{9: 'l'}] |
3b5b9ad2 | 168 | while True: |
3b5b9ad2 GS |
169 | pins = self.wait(waitcond) |
170 | self.handle_bits(pins) | |
171 | waitcond[0][9] = 'f' |