##
-## This file is part of the sigrok project.
+## This file is part of the libsigrokdecode project.
##
## Copyright (C) 2011 Gareth McMullin <gareth@blacksphere.co.nz>
-## Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de>
+## Copyright (C) 2012-2013 Uwe Hermann <uwe@hermann-uwe.de>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
(1, 1): 'SE1',
}
+bitrates = {
+ 'low-speed': 1500000, # 1.5Mb/s (+/- 1.5%)
+ 'full-speed': 12000000, # 12Mb/s (+/- 0.25%)
+}
+
class Decoder(srd.Decoder):
api_version = 1
id = 'usb_signalling'
self.scount = 0
self.packet = ''
self.syms = []
+ self.bitrate = None
+ self.bitwidth = None
self.oldpins = None
def start(self, metadata):
- self.samplerate = metadata['samplerate']
self.out_proto = self.add(srd.OUTPUT_PROTO, 'usb_signalling')
self.out_ann = self.add(srd.OUTPUT_ANN, 'usb_signalling')
+ self.bitrate = bitrates[self.options['signalling']]
+ self.bitwidth = float(metadata['samplerate']) / float(self.bitrate)
def report(self):
pass
+ def putp(self, data):
+ self.put(self.samplenum, self.samplenum, self.out_proto, data)
+
+ def putx(self, data):
+ self.put(self.samplenum, self.samplenum, self.out_ann, data)
+
def decode(self, ss, es, data):
for (self.samplenum, pins) in data:
elif self.options['signalling'] == 'full-speed':
sym = symbols_fs[dp, dm]
- self.put(0, 0, self.out_ann, [0, [sym]])
- self.put(0, 0, self.out_proto, ['SYM', sym])
+ self.putx([0, [sym]])
+ self.putp(['SYM', sym])
# Wait for a symbol change (i.e., change in D+/D- lines).
if sym == self.sym:
## # Debug code:
## self.syms.append(sym + ' ')
## if len(self.syms) == 16:
- ## self.put(0, 0, self.out_ann, [0, [''.join(self.syms)]])
+ ## self.putx([0, [''.join(self.syms)]])
## self.syms = []
# continue
# How many bits since the last transition?
if self.packet != '' or self.sym != 'J':
- if self.options['signalling'] == 'low-speed':
- bitrate = 1500000 # 1.5Mb/s (+/- 1.5%)
- elif self.options['signalling'] == 'full-speed':
- bitrate = 12000000 # 12Mb/s (+/- 0.25%)
- bitcount = int((self.scount - 1) * bitrate / self.samplerate)
+ bitcount = int((self.scount - 1) / self.bitwidth)
else:
bitcount = 0
if self.sym == 'SE0':
if bitcount == 1:
# End-Of-Packet (EOP)
- # self.put(0, 0, self.out_ann,
- # [0, [packet_decode(self.packet), self.packet]])
+ # self.putx([0, [packet_decode(self.packet), self.packet]])
if self.packet != '': # FIXME?
- self.put(0, 0, self.out_ann, [0, ['PACKET: %s' % self.packet]])
- self.put(0, 0, self.out_proto, ['PACKET', self.packet])
+ self.putx([0, ['PACKET: %s' % self.packet]])
+ self.putp(['PACKET', self.packet])
else:
# Longer than EOP, assume reset.
- self.put(0, 0, self.out_ann, [0, ['RESET']])
- self.put(0, 0, self.out_proto, ['RESET', None])
- # self.put(0, 0, self.out_ann, [0, [self.packet]])
+ self.putx([0, ['RESET']])
+ self.putp(['RESET', None])
+ # self.putx([0, [self.packet]])
self.scount = 0
self.sym = sym
self.packet = ''
if bitcount < 6 and sym != 'SE0':
self.packet += '0'
elif bitcount > 6:
- self.put(0, 0, self.out_ann, [0, ['BIT STUFF ERROR']])
- self.put(0, 0, self.out_proto, ['BIT STUFF ERROR', None])
+ self.putx([0, ['BIT STUFF ERROR']])
+ self.putp(['BIT STUFF ERROR', None])
self.scount = 0
self.sym = sym