Merge pull request #792 from yunyaobaihong/master

Decoder Update : cjtag , onewire_link and sbus
This commit is contained in:
dreamsourcelabTAI 2024-08-20 09:05:53 +08:00 committed by GitHub
commit 0957a05d1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 59 additions and 9 deletions

View File

@ -4,6 +4,7 @@
## Copyright (C) 2012-2020 Uwe Hermann <uwe@hermann-uwe.de>
## Copyright (C) 2019 Zhiyuan Wan <dv.xw@qq.com>
## Copyright (C) 2019 Kongou Hikari <hikari@iloli.bid>
## Copyright (C) 2024 DreamSourceLab <support@dreamsourcelab.com>
##
## 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
@ -19,6 +20,11 @@
## along with this program; if not, see <http://www.gnu.org/licenses/>.
##
##
## 2024/8/7 DreamSourceLab : Display data when zooming out
## 2024/8/16 DreamSourceLab : Added a filter to remove non-binary data
##
import sigrokdecode as srd
from common.srdhelper import SrdStrEnum
@ -257,6 +263,7 @@ class Decoder(srd.Decoder):
t = self.state.value[-2:] + ' TDI'
b = ''.join(map(str, self.bits_tdi[1:]))
b = ''.join(filter(lambda x: x in '01', b))
h = ' (0x%x' % int('0b0' + b, 2) + ')'
s = t + ': ' + b + h + ', ' + str(len(self.bits_tdi[1:])) + ' bits'
self.putx_bs([30, [s]])
@ -266,6 +273,7 @@ class Decoder(srd.Decoder):
t = self.state.value[-2:] + ' TDO'
b = ''.join(map(str, self.bits_tdo[1:]))
b = ''.join(filter(lambda x: x in '01', b))
h = ' (0x%x' % int('0b0' + b, 2) + ')'
s = t + ': ' + b + h + ', ' + str(len(self.bits_tdo[1:])) + ' bits'
self.putx_bs([31, [s]])

View File

@ -17,6 +17,10 @@
## along with this program; if not, see <http://www.gnu.org/licenses/>.
##
##
## 2024/7/30 DreamSourceLab : Allow adjustment of data structure and pulse width timing for high and low levels
##
import sigrokdecode as srd
class SamplerateError(Exception):
@ -60,11 +64,14 @@ timing = {
True: 24.0,
},
},
#Frame
'SLOT': {
#Frame End
'min': {
False: 60.0,
True: 6.0,
},
#Frame Mid
'max': {
False: 120.0,
True: 16.0,
@ -77,10 +84,12 @@ timing = {
},
},
'LOWR': {
# if time < min , is too short
'min': {
False: 1.0,
True: 1.0,
},
# if time > max , bit = 1, else bit = 0
'max': {
False: 15.0,
True: 2.0,
@ -104,6 +113,12 @@ class Decoder(srd.Decoder):
options = (
{'id': 'overdrive', 'desc': 'Start in overdrive speed',
'default': 'no', 'values': ('yes', 'no'), 'idn':'dec_onewire_link_opt_overdrive'},
{'id': 'min height level pulse time', 'desc': 'min height level pulse time(us)',
'default': 2.0, 'idn':'dec_onewire_link_opt_min_height_level_pulse_time'},
{'id': 'min overdrive height level pulse time', 'desc': 'min overdrive height level pulse time(us)',
'default': 15.0, 'idn':'dec_onewire_link_opt_min_overdrive_height_level_pulse_time'},
{'id': 'data order', 'desc': 'data order',
'default': 'bit first', 'values': ('bit first', 'space first'),'idn':'dec_can_opt_data_order'},
)
annotations = (
('bit', 'Bit'),
@ -129,6 +144,7 @@ class Decoder(srd.Decoder):
self.bit_count = -1
self.command = 0
self.overdrive = False
self.bit_first = True
self.fall = 0
self.rise = 0
@ -136,6 +152,10 @@ class Decoder(srd.Decoder):
self.out_python = self.register(srd.OUTPUT_PYTHON)
self.out_ann = self.register(srd.OUTPUT_ANN)
self.overdrive = (self.options['overdrive'] == 'yes')
self.bit_first = (self.options['data order'] == 'bit first')
timing['LOWR']['max'][False] = float(self.options['min height level pulse time'])
timing['LOWR']['max'][True] = float(self.options['min overdrive height level pulse time'])
self.fall = 0
self.rise = 0
self.bit_count = -1
@ -188,6 +208,19 @@ class Decoder(srd.Decoder):
samples_to_skip = samples_to_skip if (samples_to_skip > 0) else 0
return self.wait([{0: 'f'}, {'skip': samples_to_skip}])
def MinBitTimeOutput(self, time):
if time < timing['LOWR']['min'][self.overdrive]:
self.putfr([1, ['Low signal not long enough',
'Low too short',
'LOW < ' + str(timing['LOWR']['min'][self.overdrive])]])
def GetBitValue(self, time):
if time > timing['LOWR']['max'][self.overdrive]:
self.bit = 1 #Long pulse is a 1 bit.
else:
self.bit = 0 #Short pulse is a 0 bit.
def decode(self):
if not self.samplerate:
raise SamplerateError('Cannot decode without samplerate.')
@ -237,16 +270,13 @@ class Decoder(srd.Decoder):
# Overdrive reset pulse.
self.putfr([2, ['Reset', 'Rst', 'R']])
self.state = 'PRESENCE DETECT HIGH'
#Frame
elif time < timing['SLOT']['max'][self.overdrive]:
# Read/write time slot.
if time < timing['LOWR']['min'][self.overdrive]:
self.putfr([1, ['Low signal not long enough',
'Low too short',
'LOW < ' + str(timing['LOWR']['min'][self.overdrive])]])
if time < timing['LOWR']['max'][self.overdrive]:
self.bit = 1 # Short pulse is a 1 bit.
else:
self.bit = 0 # Long pulse is a 0 bit.
if self.bit_first == True:
# Read/write time slot.
self.MinBitTimeOutput(time)
self.GetBitValue(time)
# Wait for end of slot.
self.state = 'SLOT'
else:
@ -305,6 +335,12 @@ class Decoder(srd.Decoder):
self.state = 'LOW'
else: # End of time slot.
# Output bit.
if self.bit_first == False:
time = ((self.samplenum - self.rise) / self.samplerate) * 1000000.0
# Read/write time slot.
self.MinBitTimeOutput(time)
self.GetBitValue(time)
self.putfs([0, ['Bit: %d' % self.bit, '%d' % self.bit]])
self.putpfs(['BIT', self.bit])
# Save command bits.

View File

@ -2,6 +2,7 @@
## This file is part of the libsigrokdecode project.
##
## Copyright (C) 2022 Gerhard Sittig <gerhard.sittig@gmx.net>
## Copyright (C) 2024 DreamSourceLab <support@dreamsourcelab.com>
##
## 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
@ -17,6 +18,10 @@
## along with this program; if not, see <http://www.gnu.org/licenses/>.
##
##
## 2024/7/5 DreamSourceLab : Fixing the issue of decoding only the first frame
##
"""
OUTPUT_PYTHON format:
@ -223,6 +228,7 @@ class Decoder(srd.Decoder):
# spans all unprocessed data, and improves perception.
if self.sent_fields >= upto:
self.msg_complete = True
self.sent_fields = 0
if self.msg_complete and self.bits_accum:
self.failed = ['Excess data bits', 'Excess']