summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
authorStephan Thiele <stephan.thiele@mailbox.org>2019-11-13 23:24:31 +0100
committerUwe Hermann <uwe@hermann-uwe.de>2019-11-29 20:33:48 +0100
commit8abd7aa36c1a8c2d83777fedba499f6fb7f38e06 (patch)
tree8690d1d2d1c6ec40dfbdc48399501b8ffbfd3f53 /decoders
parent9a76aa18ecd429adda8a45258f43a2a93cc6def3 (diff)
downloadlibsigrokdecode-8abd7aa36c1a8c2d83777fedba499f6fb7f38e06.tar.gz
libsigrokdecode-8abd7aa36c1a8c2d83777fedba499f6fb7f38e06.zip
can: implement bit rate switch support for CAN-FD frames
Diffstat (limited to 'decoders')
-rw-r--r--decoders/can/pd.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/decoders/can/pd.py b/decoders/can/pd.py
index faed45e..3ab82b0 100644
--- a/decoders/can/pd.py
+++ b/decoders/can/pd.py
@@ -80,6 +80,16 @@ class Decoder(srd.Decoder):
def start(self):
self.out_ann = self.register(srd.OUTPUT_ANN)
+ def set_bit_rate(self, bitrate):
+ self.bit_width = float(self.samplerate) / float(bitrate)
+ self.sample_point = (self.bit_width / 100.0) * self.options['sample_point']
+
+ def set_nominal_bitrate(self):
+ self.set_bit_rate(self.options['nominal_bitrate'])
+
+ def set_fast_bitrate(self):
+ self.set_bit_rate(self.options['fast_bitrate'])
+
def metadata(self, key, value):
if key == srd.SRD_CONF_SAMPLERATE:
self.samplerate = value
@@ -205,6 +215,9 @@ class Decoder(srd.Decoder):
if can_rx != 1:
self.putx([16, ['CRC delimiter must be a recessive bit']])
+ if self.fd:
+ self.set_nominal_bitrate()
+
# ACK slot bit (dominant: ACK, recessive: NACK)
elif bitnum == (self.last_databit + self.crc_len + 2):
ack = 'ACK' if can_rx == 0 else 'NACK'
@@ -408,6 +421,12 @@ class Decoder(srd.Decoder):
# Get the index of the current CAN frame bit (without stuff bits).
bitnum = len(self.bits) - 1
+ if self.fd and can_rx:
+ if bitnum == 16 and self.frame_type == 'standard' \
+ or bitnum == 35 and self.frame_type == 'extended':
+ self.dom_edge_seen(force=True)
+ self.set_fast_bitrate()
+
# If this is a stuff bit, remove it from self.bits and ignore it.
if self.is_stuff_bit():
self.putx([15, [str(can_rx)]])