summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Brüns <stefan.bruens@rwth-aachen.de>2015-11-13 04:11:37 +0100
committerStefan Brüns <stefan.bruens@rwth-aachen.de>2015-11-30 00:03:01 +0100
commit033d6221f3d0cd607bb11031a2764a293bf4bff1 (patch)
tree0eaab25a1c66e2bc7550d48c5602a2ff081637bc
parent56cc44ff1106e8e28d9242b6232552c501090ed4 (diff)
downloadlibsigrokdecode-033d6221f3d0cd607bb11031a2764a293bf4bff1.tar.gz
libsigrokdecode-033d6221f3d0cd607bb11031a2764a293bf4bff1.zip
usb_signalling: detect bit stuffing errors
More than six consecutive 1's are an error
-rw-r--r--decoders/usb_signalling/pd.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/decoders/usb_signalling/pd.py b/decoders/usb_signalling/pd.py
index 4af2eff..8e9723e 100644
--- a/decoders/usb_signalling/pd.py
+++ b/decoders/usb_signalling/pd.py
@@ -33,12 +33,13 @@ Packet:
- 'BIT', <bit>
- 'STUFF BIT', None
- 'EOP', None
+ - 'ERR', None
<sym>:
- 'J', 'K', 'SE0', or 'SE1'
<bit>:
- - 0 or 1
+ - '0' or '1'
- Note: Symbols like SE0, SE1, and the J that's part of EOP don't yield 'BIT'.
'''
@@ -102,9 +103,10 @@ class Decoder(srd.Decoder):
('eop', 'End of packet (EOP)'),
('bit', 'Bit'),
('stuffbit', 'Stuff bit'),
+ ('error', 'Error'),
)
annotation_rows = (
- ('bits', 'Bits', (4, 5, 6, 7)),
+ ('bits', 'Bits', (4, 5, 6, 7, 8)),
('symbols', 'Symbols', (0, 1, 2, 3)),
)
@@ -168,6 +170,7 @@ class Decoder(srd.Decoder):
if sym != 'K':
self.oldsym = sym
return
+ self.consecutive_ones = 0
self.ss_sop = self.samplenum
self.samplepos = self.ss_sop - (self.bitwidth / 2) + 0.5
self.set_new_target_samplenum()
@@ -176,11 +179,16 @@ class Decoder(srd.Decoder):
self.state = 'GET BIT'
def handle_bit(self, sym, b):
- if self.consecutive_ones == 6 and b == '0':
- # Stuff bit.
- self.putpb(['STUFF BIT', None])
- self.putb([7, ['Stuff bit: %s' % b, 'SB: %s' % b, '%s' % b]])
- self.consecutive_ones = 0
+ if self.consecutive_ones == 6:
+ if b == '0':
+ # Stuff bit.
+ self.putpb(['STUFF BIT', None])
+ self.putb([7, ['Stuff bit: 0', 'SB: 0', '0']])
+ self.consecutive_ones = 0
+ else:
+ self.putpb(['ERR', None])
+ self.putb([8, ['Bit stuff error', 'BS ERR', 'B']])
+ self.state = 'IDLE'
else:
# Normal bit (not a stuff bit).
self.putpb(['BIT', b])
@@ -202,7 +210,6 @@ class Decoder(srd.Decoder):
self.putpm(['EOP', None])
self.putm([5, ['EOP', 'E']])
self.syms, self.state = [], 'IDLE'
- self.consecutive_ones = 0
self.bitwidth = float(self.samplerate) / float(self.bitrate)
def get_bit(self, sym):