]> sigrok.org Git - libsigrokdecode.git/blame_incremental - decoders/uart/pd.py
cjtag: Use an exact copy of the jtag PD as basis for cjtag.
[libsigrokdecode.git] / decoders / uart / pd.py
... / ...
CommitLineData
1##
2## This file is part of the libsigrokdecode project.
3##
4## Copyright (C) 2011-2014 Uwe Hermann <uwe@hermann-uwe.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
17## along with this program; if not, see <http://www.gnu.org/licenses/>.
18##
19
20import sigrokdecode as srd
21from common.srdhelper import bitpack
22from math import floor, ceil
23
24'''
25OUTPUT_PYTHON format:
26
27Packet:
28[<ptype>, <rxtx>, <pdata>]
29
30This is the list of <ptype>s and their respective <pdata> values:
31 - 'STARTBIT': The data is the (integer) value of the start bit (0/1).
32 - 'DATA': This is always a tuple containing two items:
33 - 1st item: the (integer) value of the UART data. Valid values
34 range from 0 to 511 (as the data can be up to 9 bits in size).
35 - 2nd item: the list of individual data bits and their ss/es numbers.
36 - 'PARITYBIT': The data is the (integer) value of the parity bit (0/1).
37 - 'STOPBIT': The data is the (integer) value of the stop bit (0 or 1).
38 - 'INVALID STARTBIT': The data is the (integer) value of the start bit (0/1).
39 - 'INVALID STOPBIT': The data is the (integer) value of the stop bit (0/1).
40 - 'PARITY ERROR': The data is a tuple with two entries. The first one is
41 the expected parity value, the second is the actual parity value.
42 - 'BREAK': The data is always 0.
43 - 'FRAME': The data is always a tuple containing two items: The (integer)
44 value of the UART data, and a boolean which reflects the validity of the
45 UART frame.
46 - 'IDLE': The data is always 0.
47
48The <rxtx> field is 0 for RX packets, 1 for TX packets.
49'''
50
51# Used for differentiating between the two data directions.
52RX = 0
53TX = 1
54
55# Given a parity type to check (odd, even, zero, one), the value of the
56# parity bit, the value of the data, and the length of the data (5-9 bits,
57# usually 8 bits) return True if the parity is correct, False otherwise.
58# 'none' is _not_ allowed as value for 'parity_type'.
59def parity_ok(parity_type, parity_bit, data, data_bits):
60
61 if parity_type == 'ignore':
62 return True
63
64 # Handle easy cases first (parity bit is always 1 or 0).
65 if parity_type == 'zero':
66 return parity_bit == 0
67 elif parity_type == 'one':
68 return parity_bit == 1
69
70 # Count number of 1 (high) bits in the data (and the parity bit itself!).
71 ones = bin(data).count('1') + parity_bit
72
73 # Check for odd/even parity.
74 if parity_type == 'odd':
75 return (ones % 2) == 1
76 elif parity_type == 'even':
77 return (ones % 2) == 0
78
79class SamplerateError(Exception):
80 pass
81
82class ChannelError(Exception):
83 pass
84
85class Ann:
86 RX_DATA, TX_DATA, RX_START, TX_START, RX_PARITY_OK, TX_PARITY_OK, \
87 RX_PARITY_ERR, TX_PARITY_ERR, RX_STOP, TX_STOP, RX_WARN, TX_WARN, \
88 RX_DATA_BIT, TX_DATA_BIT, RX_BREAK, TX_BREAK, RX_PACKET, TX_PACKET = \
89 range(18)
90
91class Bin:
92 RX, TX, RXTX = range(3)
93
94class Decoder(srd.Decoder):
95 api_version = 3
96 id = 'uart'
97 name = 'UART'
98 longname = 'Universal Asynchronous Receiver/Transmitter'
99 desc = 'Asynchronous, serial bus.'
100 license = 'gplv2+'
101 inputs = ['logic']
102 outputs = ['uart']
103 tags = ['Embedded/industrial']
104 optional_channels = (
105 # Allow specifying only one of the signals, e.g. if only one data
106 # direction exists (or is relevant).
107 {'id': 'rx', 'name': 'RX', 'desc': 'UART receive line'},
108 {'id': 'tx', 'name': 'TX', 'desc': 'UART transmit line'},
109 )
110 options = (
111 {'id': 'baudrate', 'desc': 'Baud rate', 'default': 115200},
112 {'id': 'data_bits', 'desc': 'Data bits', 'default': 8,
113 'values': (5, 6, 7, 8, 9)},
114 {'id': 'parity', 'desc': 'Parity', 'default': 'none',
115 'values': ('none', 'odd', 'even', 'zero', 'one', 'ignore')},
116 {'id': 'stop_bits', 'desc': 'Stop bits', 'default': 1.0,
117 'values': (0.0, 0.5, 1.0, 1.5)},
118 {'id': 'bit_order', 'desc': 'Bit order', 'default': 'lsb-first',
119 'values': ('lsb-first', 'msb-first')},
120 {'id': 'format', 'desc': 'Data format', 'default': 'hex',
121 'values': ('ascii', 'dec', 'hex', 'oct', 'bin')},
122 {'id': 'invert_rx', 'desc': 'Invert RX', 'default': 'no',
123 'values': ('yes', 'no')},
124 {'id': 'invert_tx', 'desc': 'Invert TX', 'default': 'no',
125 'values': ('yes', 'no')},
126 {'id': 'sample_point', 'desc': 'Sample point (%)', 'default': 50},
127 {'id': 'rx_packet_delim', 'desc': 'RX packet delimiter (decimal)',
128 'default': -1},
129 {'id': 'tx_packet_delim', 'desc': 'TX packet delimiter (decimal)',
130 'default': -1},
131 {'id': 'rx_packet_len', 'desc': 'RX packet length', 'default': -1},
132 {'id': 'tx_packet_len', 'desc': 'TX packet length', 'default': -1},
133 )
134 annotations = (
135 ('rx-data', 'RX data'),
136 ('tx-data', 'TX data'),
137 ('rx-start', 'RX start bit'),
138 ('tx-start', 'TX start bit'),
139 ('rx-parity-ok', 'RX parity OK bit'),
140 ('tx-parity-ok', 'TX parity OK bit'),
141 ('rx-parity-err', 'RX parity error bit'),
142 ('tx-parity-err', 'TX parity error bit'),
143 ('rx-stop', 'RX stop bit'),
144 ('tx-stop', 'TX stop bit'),
145 ('rx-warning', 'RX warning'),
146 ('tx-warning', 'TX warning'),
147 ('rx-data-bit', 'RX data bit'),
148 ('tx-data-bit', 'TX data bit'),
149 ('rx-break', 'RX break'),
150 ('tx-break', 'TX break'),
151 ('rx-packet', 'RX packet'),
152 ('tx-packet', 'TX packet'),
153 )
154 annotation_rows = (
155 ('rx-data-bits', 'RX bits', (Ann.RX_DATA_BIT,)),
156 ('rx-data-vals', 'RX data', (Ann.RX_DATA, Ann.RX_START, Ann.RX_PARITY_OK, Ann.RX_PARITY_ERR, Ann.RX_STOP)),
157 ('rx-warnings', 'RX warnings', (Ann.RX_WARN,)),
158 ('rx-breaks', 'RX breaks', (Ann.RX_BREAK,)),
159 ('rx-packets', 'RX packets', (Ann.RX_PACKET,)),
160 ('tx-data-bits', 'TX bits', (Ann.TX_DATA_BIT,)),
161 ('tx-data-vals', 'TX data', (Ann.TX_DATA, Ann.TX_START, Ann.TX_PARITY_OK, Ann.TX_PARITY_ERR, Ann.TX_STOP)),
162 ('tx-warnings', 'TX warnings', (Ann.TX_WARN,)),
163 ('tx-breaks', 'TX breaks', (Ann.TX_BREAK,)),
164 ('tx-packets', 'TX packets', (Ann.TX_PACKET,)),
165 )
166 binary = (
167 ('rx', 'RX dump'),
168 ('tx', 'TX dump'),
169 ('rxtx', 'RX/TX dump'),
170 )
171 idle_state = ['WAIT FOR START BIT', 'WAIT FOR START BIT']
172
173 def putx(self, rxtx, data):
174 s, halfbit = self.startsample[rxtx], self.bit_width / 2.0
175 self.put(s - floor(halfbit), self.samplenum + ceil(halfbit), self.out_ann, data)
176
177 def putx_packet(self, rxtx, data):
178 s, halfbit = self.ss_packet[rxtx], self.bit_width / 2.0
179 self.put(s - floor(halfbit), self.samplenum + ceil(halfbit), self.out_ann, data)
180
181 def putpx(self, rxtx, data):
182 s, halfbit = self.startsample[rxtx], self.bit_width / 2.0
183 self.put(s - floor(halfbit), self.samplenum + ceil(halfbit), self.out_python, data)
184
185 def putg(self, data):
186 s, halfbit = self.samplenum, self.bit_width / 2.0
187 self.put(s - floor(halfbit), s + ceil(halfbit), self.out_ann, data)
188
189 def putp(self, data):
190 s, halfbit = self.samplenum, self.bit_width / 2.0
191 self.put(s - floor(halfbit), s + ceil(halfbit), self.out_python, data)
192
193 def putgse(self, ss, es, data):
194 self.put(ss, es, self.out_ann, data)
195
196 def putpse(self, ss, es, data):
197 self.put(ss, es, self.out_python, data)
198
199 def putbin(self, rxtx, data):
200 s, halfbit = self.startsample[rxtx], self.bit_width / 2.0
201 self.put(s - floor(halfbit), self.samplenum + ceil(halfbit), self.out_binary, data)
202
203 def __init__(self):
204 self.reset()
205
206 def reset(self):
207 self.samplerate = None
208 self.frame_start = [-1, -1]
209 self.frame_valid = [None, None]
210 self.startbit = [-1, -1]
211 self.cur_data_bit = [0, 0]
212 self.datavalue = [0, 0]
213 self.paritybit = [-1, -1]
214 self.stopbit1 = [-1, -1]
215 self.startsample = [-1, -1]
216 self.state = ['WAIT FOR START BIT', 'WAIT FOR START BIT']
217 self.databits = [[], []]
218 self.break_start = [None, None]
219 self.packet_cache = [[], []]
220 self.ss_packet, self.es_packet = [None, None], [None, None]
221 self.idle_start = [None, None]
222
223 def start(self):
224 self.out_python = self.register(srd.OUTPUT_PYTHON)
225 self.out_binary = self.register(srd.OUTPUT_BINARY)
226 self.out_ann = self.register(srd.OUTPUT_ANN)
227 self.bw = (self.options['data_bits'] + 7) // 8
228
229 def metadata(self, key, value):
230 if key == srd.SRD_CONF_SAMPLERATE:
231 self.samplerate = value
232 # The width of one UART bit in number of samples.
233 self.bit_width = float(self.samplerate) / float(self.options['baudrate'])
234
235 def get_sample_point(self, rxtx, bitnum):
236 # Determine absolute sample number of a bit slot's sample point.
237 # Counts for UART bits start from 0 (0 = start bit, 1..x = data,
238 # x+1 = parity bit (if used) or the first stop bit, and so on).
239 # Accept a position in the range of 1-99% of the full bit width.
240 # Assume 50% for invalid input specs for backwards compatibility.
241 perc = self.options['sample_point'] or 50
242 if not perc or perc not in range(1, 100):
243 perc = 50
244 perc /= 100.0
245 bitpos = (self.bit_width - 1) * perc
246 bitpos += self.frame_start[rxtx]
247 bitpos += bitnum * self.bit_width
248 return bitpos
249
250 def wait_for_start_bit(self, rxtx, signal):
251 # Save the sample number where the start bit begins.
252 self.frame_start[rxtx] = self.samplenum
253 self.frame_valid[rxtx] = True
254
255 self.state[rxtx] = 'GET START BIT'
256
257 def get_start_bit(self, rxtx, signal):
258 self.startbit[rxtx] = signal
259
260 # The startbit must be 0. If not, we report an error and wait
261 # for the next start bit (assuming this one was spurious).
262 if self.startbit[rxtx] != 0:
263 self.putp(['INVALID STARTBIT', rxtx, self.startbit[rxtx]])
264 self.putg([Ann.RX_WARN + rxtx, ['Frame error', 'Frame err', 'FE']])
265 self.frame_valid[rxtx] = False
266 es = self.samplenum + ceil(self.bit_width / 2.0)
267 self.putpse(self.frame_start[rxtx], es, ['FRAME', rxtx,
268 (self.datavalue[rxtx], self.frame_valid[rxtx])])
269 self.state[rxtx] = 'WAIT FOR START BIT'
270 return
271
272 self.cur_data_bit[rxtx] = 0
273 self.datavalue[rxtx] = 0
274 self.startsample[rxtx] = -1
275
276 self.putp(['STARTBIT', rxtx, self.startbit[rxtx]])
277 self.putg([Ann.RX_START + rxtx, ['Start bit', 'Start', 'S']])
278
279 self.state[rxtx] = 'GET DATA BITS'
280
281 def handle_packet(self, rxtx):
282 d = 'rx' if (rxtx == RX) else 'tx'
283 delim = self.options[d + '_packet_delim']
284 plen = self.options[d + '_packet_len']
285 if delim == -1 and plen == -1:
286 return
287
288 # Cache data values until we see the delimiter and/or the specified
289 # packet length has been reached (whichever happens first).
290 if len(self.packet_cache[rxtx]) == 0:
291 self.ss_packet[rxtx] = self.startsample[rxtx]
292 self.packet_cache[rxtx].append(self.datavalue[rxtx])
293 if self.datavalue[rxtx] == delim or len(self.packet_cache[rxtx]) == plen:
294 self.es_packet[rxtx] = self.samplenum
295 s = ''
296 for b in self.packet_cache[rxtx]:
297 s += self.format_value(b)
298 if self.options['format'] != 'ascii':
299 s += ' '
300 if self.options['format'] != 'ascii' and s[-1] == ' ':
301 s = s[:-1] # Drop trailing space.
302 self.putx_packet(rxtx, [Ann.RX_PACKET + rxtx, [s]])
303 self.packet_cache[rxtx] = []
304
305 def get_data_bits(self, rxtx, signal):
306 # Save the sample number of the middle of the first data bit.
307 if self.startsample[rxtx] == -1:
308 self.startsample[rxtx] = self.samplenum
309
310 self.putg([Ann.RX_DATA_BIT + rxtx, ['%d' % signal]])
311
312 # Store individual data bits and their start/end samplenumbers.
313 s, halfbit = self.samplenum, int(self.bit_width / 2)
314 self.databits[rxtx].append([signal, s - halfbit, s + halfbit])
315
316 # Return here, unless we already received all data bits.
317 self.cur_data_bit[rxtx] += 1
318 if self.cur_data_bit[rxtx] < self.options['data_bits']:
319 return
320
321 # Convert accumulated data bits to a data value.
322 bits = [b[0] for b in self.databits[rxtx]]
323 if self.options['bit_order'] == 'msb-first':
324 bits.reverse()
325 self.datavalue[rxtx] = bitpack(bits)
326 self.putpx(rxtx, ['DATA', rxtx,
327 (self.datavalue[rxtx], self.databits[rxtx])])
328
329 b = self.datavalue[rxtx]
330 formatted = self.format_value(b)
331 if formatted is not None:
332 self.putx(rxtx, [rxtx, [formatted]])
333
334 bdata = b.to_bytes(self.bw, byteorder='big')
335 self.putbin(rxtx, [Bin.RX + rxtx, bdata])
336 self.putbin(rxtx, [Bin.RXTX, bdata])
337
338 self.handle_packet(rxtx)
339
340 self.databits[rxtx] = []
341
342 # Advance to either reception of the parity bit, or reception of
343 # the STOP bits if parity is not applicable.
344 self.state[rxtx] = 'GET PARITY BIT'
345 if self.options['parity'] == 'none':
346 self.state[rxtx] = 'GET STOP BITS'
347
348 def format_value(self, v):
349 # Format value 'v' according to configured options.
350 # Reflects the user selected kind of representation, as well as
351 # the number of data bits in the UART frames.
352
353 fmt, bits = self.options['format'], self.options['data_bits']
354
355 # Assume "is printable" for values from 32 to including 126,
356 # below 32 is "control" and thus not printable, above 127 is
357 # "not ASCII" in its strict sense, 127 (DEL) is not printable,
358 # fall back to hex representation for non-printables.
359 if fmt == 'ascii':
360 if v in range(32, 126 + 1):
361 return chr(v)
362 hexfmt = "[{:02X}]" if bits <= 8 else "[{:03X}]"
363 return hexfmt.format(v)
364
365 # Mere number to text conversion without prefix and padding
366 # for the "decimal" output format.
367 if fmt == 'dec':
368 return "{:d}".format(v)
369
370 # Padding with leading zeroes for hex/oct/bin formats, but
371 # without a prefix for density -- since the format is user
372 # specified, there is no ambiguity.
373 if fmt == 'hex':
374 digits = (bits + 4 - 1) // 4
375 fmtchar = "X"
376 elif fmt == 'oct':
377 digits = (bits + 3 - 1) // 3
378 fmtchar = "o"
379 elif fmt == 'bin':
380 digits = bits
381 fmtchar = "b"
382 else:
383 fmtchar = None
384 if fmtchar is not None:
385 fmt = "{{:0{:d}{:s}}}".format(digits, fmtchar)
386 return fmt.format(v)
387
388 return None
389
390 def get_parity_bit(self, rxtx, signal):
391 self.paritybit[rxtx] = signal
392
393 if parity_ok(self.options['parity'], self.paritybit[rxtx],
394 self.datavalue[rxtx], self.options['data_bits']):
395 self.putp(['PARITYBIT', rxtx, self.paritybit[rxtx]])
396 self.putg([Ann.RX_PARITY_OK + rxtx, ['Parity bit', 'Parity', 'P']])
397 else:
398 # TODO: Return expected/actual parity values.
399 self.putp(['PARITY ERROR', rxtx, (0, 1)]) # FIXME: Dummy tuple...
400 self.putg([Ann.RX_PARITY_ERR + rxtx, ['Parity error', 'Parity err', 'PE']])
401 self.frame_valid[rxtx] = False
402
403 self.state[rxtx] = 'GET STOP BITS'
404
405 # TODO: Currently only supports 1 stop bit.
406 def get_stop_bits(self, rxtx, signal):
407 self.stopbit1[rxtx] = signal
408
409 # Stop bits must be 1. If not, we report an error.
410 if self.stopbit1[rxtx] != 1:
411 self.putp(['INVALID STOPBIT', rxtx, self.stopbit1[rxtx]])
412 self.putg([Ann.RX_WARN + rxtx, ['Frame error', 'Frame err', 'FE']])
413 self.frame_valid[rxtx] = False
414
415 self.putp(['STOPBIT', rxtx, self.stopbit1[rxtx]])
416 self.putg([Ann.RX_STOP + rxtx, ['Stop bit', 'Stop', 'T']])
417
418 # Pass the complete UART frame to upper layers.
419 es = self.samplenum + ceil(self.bit_width / 2.0)
420 self.putpse(self.frame_start[rxtx], es, ['FRAME', rxtx,
421 (self.datavalue[rxtx], self.frame_valid[rxtx])])
422
423 self.state[rxtx] = 'WAIT FOR START BIT'
424 self.idle_start[rxtx] = self.frame_start[rxtx] + self.frame_len_sample_count
425
426 def handle_break(self, rxtx):
427 self.putpse(self.frame_start[rxtx], self.samplenum,
428 ['BREAK', rxtx, 0])
429 self.putgse(self.frame_start[rxtx], self.samplenum,
430 [Ann.RX_BREAK + rxtx, ['Break condition', 'Break', 'Brk', 'B']])
431 self.state[rxtx] = 'WAIT FOR START BIT'
432
433 def get_wait_cond(self, rxtx, inv):
434 # Return condititions that are suitable for Decoder.wait(). Those
435 # conditions either match the falling edge of the START bit, or
436 # the sample point of the next bit time.
437 state = self.state[rxtx]
438 if state == 'WAIT FOR START BIT':
439 return {rxtx: 'r' if inv else 'f'}
440 if state == 'GET START BIT':
441 bitnum = 0
442 elif state == 'GET DATA BITS':
443 bitnum = 1 + self.cur_data_bit[rxtx]
444 elif state == 'GET PARITY BIT':
445 bitnum = 1 + self.options['data_bits']
446 elif state == 'GET STOP BITS':
447 bitnum = 1 + self.options['data_bits']
448 bitnum += 0 if self.options['parity'] == 'none' else 1
449 want_num = ceil(self.get_sample_point(rxtx, bitnum))
450 return {'skip': want_num - self.samplenum}
451
452 def get_idle_cond(self, rxtx, inv):
453 # Return a condition that corresponds to the (expected) end of
454 # the next frame, assuming that it will be an "idle frame"
455 # (constant high input level for the frame's length).
456 if self.idle_start[rxtx] is None:
457 return None
458 end_of_frame = self.idle_start[rxtx] + self.frame_len_sample_count
459 if end_of_frame < self.samplenum:
460 return None
461 return {'skip': end_of_frame - self.samplenum}
462
463 def inspect_sample(self, rxtx, signal, inv):
464 # Inspect a sample returned by .wait() for the specified UART line.
465 if inv:
466 signal = not signal
467
468 state = self.state[rxtx]
469 if state == 'WAIT FOR START BIT':
470 self.wait_for_start_bit(rxtx, signal)
471 elif state == 'GET START BIT':
472 self.get_start_bit(rxtx, signal)
473 elif state == 'GET DATA BITS':
474 self.get_data_bits(rxtx, signal)
475 elif state == 'GET PARITY BIT':
476 self.get_parity_bit(rxtx, signal)
477 elif state == 'GET STOP BITS':
478 self.get_stop_bits(rxtx, signal)
479
480 def inspect_edge(self, rxtx, signal, inv):
481 # Inspect edges, independently from traffic, to detect break conditions.
482 if inv:
483 signal = not signal
484 if not signal:
485 # Signal went low. Start another interval.
486 self.break_start[rxtx] = self.samplenum
487 return
488 # Signal went high. Was there an extended period with low signal?
489 if self.break_start[rxtx] is None:
490 return
491 diff = self.samplenum - self.break_start[rxtx]
492 if diff >= self.break_min_sample_count:
493 self.handle_break(rxtx)
494 self.break_start[rxtx] = None
495
496 def inspect_idle(self, rxtx, signal, inv):
497 # Check each edge and each period of stable input (either level).
498 # Can derive the "idle frame period has passed" condition.
499 if inv:
500 signal = not signal
501 if not signal:
502 # Low input, cease inspection.
503 self.idle_start[rxtx] = None
504 return
505 # High input, either just reached, or still stable.
506 if self.idle_start[rxtx] is None:
507 self.idle_start[rxtx] = self.samplenum
508 diff = self.samplenum - self.idle_start[rxtx]
509 if diff < self.frame_len_sample_count:
510 return
511 ss, es = self.idle_start[rxtx], self.samplenum
512 self.putpse(ss, es, ['IDLE', rxtx, 0])
513 self.idle_start[rxtx] = self.samplenum
514
515 def decode(self):
516 if not self.samplerate:
517 raise SamplerateError('Cannot decode without samplerate.')
518
519 has_pin = [self.has_channel(ch) for ch in (RX, TX)]
520 if not True in has_pin:
521 raise ChannelError('Need at least one of TX or RX pins.')
522
523 opt = self.options
524 inv = [opt['invert_rx'] == 'yes', opt['invert_tx'] == 'yes']
525 cond_data_idx = [None] * len(has_pin)
526
527 # Determine the number of samples for a complete frame's time span.
528 # A period of low signal (at least) that long is a break condition.
529 frame_samples = 1 # START
530 frame_samples += self.options['data_bits']
531 frame_samples += 0 if self.options['parity'] == 'none' else 1
532 frame_samples += self.options['stop_bits']
533 frame_samples *= self.bit_width
534 self.frame_len_sample_count = ceil(frame_samples)
535 self.break_min_sample_count = self.frame_len_sample_count
536 cond_edge_idx = [None] * len(has_pin)
537 cond_idle_idx = [None] * len(has_pin)
538
539 while True:
540 conds = []
541 if has_pin[RX]:
542 cond_data_idx[RX] = len(conds)
543 conds.append(self.get_wait_cond(RX, inv[RX]))
544 cond_edge_idx[RX] = len(conds)
545 conds.append({RX: 'e'})
546 cond_idle_idx[RX] = None
547 idle_cond = self.get_idle_cond(RX, inv[RX])
548 if idle_cond:
549 cond_idle_idx[RX] = len(conds)
550 conds.append(idle_cond)
551 if has_pin[TX]:
552 cond_data_idx[TX] = len(conds)
553 conds.append(self.get_wait_cond(TX, inv[TX]))
554 cond_edge_idx[TX] = len(conds)
555 conds.append({TX: 'e'})
556 cond_idle_idx[TX] = None
557 idle_cond = self.get_idle_cond(TX, inv[TX])
558 if idle_cond:
559 cond_idle_idx[TX] = len(conds)
560 conds.append(idle_cond)
561 (rx, tx) = self.wait(conds)
562 if cond_data_idx[RX] is not None and self.matched[cond_data_idx[RX]]:
563 self.inspect_sample(RX, rx, inv[RX])
564 if cond_edge_idx[RX] is not None and self.matched[cond_edge_idx[RX]]:
565 self.inspect_edge(RX, rx, inv[RX])
566 self.inspect_idle(RX, rx, inv[RX])
567 if cond_idle_idx[RX] is not None and self.matched[cond_idle_idx[RX]]:
568 self.inspect_idle(RX, rx, inv[RX])
569 if cond_data_idx[TX] is not None and self.matched[cond_data_idx[TX]]:
570 self.inspect_sample(TX, tx, inv[TX])
571 if cond_edge_idx[TX] is not None and self.matched[cond_edge_idx[TX]]:
572 self.inspect_edge(TX, tx, inv[TX])
573 self.inspect_idle(TX, tx, inv[TX])
574 if cond_idle_idx[TX] is not None and self.matched[cond_idle_idx[TX]]:
575 self.inspect_idle(TX, tx, inv[TX])