From 6521366026cee146605d4ce013954d27645cf0da Mon Sep 17 00:00:00 2001 From: eastboy007 <369614718@qq.com> Date: Tue, 10 Jan 2017 22:19:01 +0800 Subject: [PATCH 1/2] JTAG TDI/TDO decode bug fixed --- libsigrokdecode4DSL/decoders/jtag/pd.py | 121 ++++++++++++++++-------- 1 file changed, 80 insertions(+), 41 deletions(-) diff --git a/libsigrokdecode4DSL/decoders/jtag/pd.py b/libsigrokdecode4DSL/decoders/jtag/pd.py index 74e63294..44b64cf5 100755 --- a/libsigrokdecode4DSL/decoders/jtag/pd.py +++ b/libsigrokdecode4DSL/decoders/jtag/pd.py @@ -3,6 +3,12 @@ ## ## Copyright (C) 2012-2015 Uwe Hermann ## +## Version: +## Modified by Shiqiu Nie(369614718@qq.com) +## Date: 2017-01-10 +## Descript: Fixed TDI/TDO data decode, when JTAG TAP run into SHIFT-IR/SHIFT-DR status, +## the first bit is not a valid bit. +## ## 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 ## the Free Software Foundation; either version 2 of the License, or @@ -104,6 +110,8 @@ class Decoder(srd.Decoder): self.saved_item = None self.first = True self.first_bit = True + self.bits_cnt = 0 + self.data_ready = False def start(self): self.out_python = self.register(srd.OUTPUT_PYTHON) @@ -179,55 +187,86 @@ class Decoder(srd.Decoder): # Upon SHIFT-IR/SHIFT-DR collect the current TDI/TDO values. if self.state.startswith('SHIFT-'): - if self.first_bit: - self.ss_bitstring = self.samplenum - self.first_bit = False - else: - self.putx([16, [str(self.bits_tdi[0])]]) - self.putx([17, [str(self.bits_tdo[0])]]) - # Use self.samplenum as ES of the previous bit. - self.bits_samplenums_tdi[0][1] = self.samplenum - self.bits_samplenums_tdo[0][1] = self.samplenum + #if self.first_bit: + #self.ss_bitstring = self.samplenum + # self.first_bit = False + + #else: + if self.bits_cnt > 0: + if self.bits_cnt == 1: + self.ss_bitstring = self.samplenum - self.bits_tdi.insert(0, tdi) - self.bits_tdo.insert(0, tdo) - - # Use self.samplenum as SS of the current bit. - self.bits_samplenums_tdi.insert(0, [self.samplenum, -1]) - self.bits_samplenums_tdo.insert(0, [self.samplenum, -1]) + if self.bits_cnt > 1: + self.putx([16, [str(self.bits_tdi[0])]]) + self.putx([17, [str(self.bits_tdo[0])]]) + # Use self.samplenum as ES of the previous bit. + self.bits_samplenums_tdi[0][1] = self.samplenum + self.bits_samplenums_tdo[0][1] = self.samplenum + + self.bits_tdi.insert(0, tdi) + self.bits_tdo.insert(0, tdo) + + # Use self.samplenum as SS of the current bit. + self.bits_samplenums_tdi.insert(0, [self.samplenum, -1]) + self.bits_samplenums_tdo.insert(0, [self.samplenum, -1]) + + self.bits_cnt = self.bits_cnt + 1 # Output all TDI/TDO bits if we just switched from SHIFT-* to EXIT1-*. if self.oldstate.startswith('SHIFT-') and \ self.state.startswith('EXIT1-'): - - self.es_bitstring = self.samplenum - - t = self.state[-2:] + ' TDI' - b = ''.join(map(str, self.bits_tdi)) - h = ' (0x%x' % int('0b' + b, 2) + ')' - s = t + ': ' + b + h + ', ' + str(len(self.bits_tdi)) + ' bits' - self.putx_bs([18, [s]]) - self.bits_samplenums_tdi[0][1] = self.samplenum # ES of last bit. - self.putp_bs([t, [b, self.bits_samplenums_tdi]]) - self.putx([16, [str(self.bits_tdi[0])]]) # Last bit. - self.bits_tdi = [] - self.bits_samplenums_tdi = [] - - t = self.state[-2:] + ' TDO' - b = ''.join(map(str, self.bits_tdo)) - h = ' (0x%x' % int('0b' + b, 2) + ')' - s = t + ': ' + b + h + ', ' + str(len(self.bits_tdo)) + ' bits' - self.putx_bs([19, [s]]) - self.bits_samplenums_tdo[0][1] = self.samplenum # ES of last bit. - self.putp_bs([t, [b, self.bits_samplenums_tdo]]) - self.putx([17, [str(self.bits_tdo[0])]]) # Last bit. - self.bits_tdo = [] - self.bits_samplenums_tdo = [] - + + #self.es_bitstring = self.samplenum + if self.bits_cnt > 1: + ### ---------------------------------------------------------------- + self.putx([16, [str(self.bits_tdi[0])]]) + self.putx([17, [str(self.bits_tdo[0])]]) + ### Use self.samplenum as ES of the previous bit. + self.bits_samplenums_tdi[0][1] = self.samplenum + self.bits_samplenums_tdo[0][1] = self.samplenum + + self.bits_tdi.insert(0, tdi) + self.bits_tdo.insert(0, tdo) + + ## Use self.samplenum as SS of the current bit. + self.bits_samplenums_tdi.insert(0, [self.samplenum, -1]) + self.bits_samplenums_tdo.insert(0, [self.samplenum, -1]) + ## ---------------------------------------------------------------- + self.data_ready = True self.first_bit = True + self.bits_cnt = 0 + if self.oldstate.startswith('EXIT'):# and \ + #self.state.startswith('PAUSE-'): + if self.data_ready: + self.data_ready = False + self.es_bitstring = self.samplenum + t = self.state[-2:] + ' TDI' + b = ''.join(map(str, self.bits_tdi)) + h = ' (0x%X' % int('0b' + b, 2) + ')' + s = t + ': ' + b + h + ', ' + str(len(self.bits_tdi)) + ' bits' + self.putx_bs([18, [s]]) + self.bits_samplenums_tdi[0][1] = self.samplenum # ES of last bit. + self.putp_bs([t, [b, self.bits_samplenums_tdi]]) + self.putx([16, [str(self.bits_tdi[0])]]) # Last bit. + self.bits_tdi = [] + self.bits_samplenums_tdi = [] - self.ss_bitstring = self.samplenum + t = self.state[-2:] + ' TDO' + b = ''.join(map(str, self.bits_tdo)) + h = ' (0x%X' % int('0b' + b, 2) + ')' + s = t + ': ' + b + h + ', ' + str(len(self.bits_tdo)) + ' bits' + self.putx_bs([19, [s]]) + self.bits_samplenums_tdo[0][1] = self.samplenum # ES of last bit. + self.putp_bs([t, [b, self.bits_samplenums_tdo]]) + self.putx([17, [str(self.bits_tdo[0])]]) # Last bit. + self.bits_tdo = [] + self.bits_samplenums_tdo = [] + #self.first_bit = True + #self.bits_cnt = 0 + + #self.ss_bitstring = self.samplenum + self.ss_item = self.samplenum def decode(self, ss, es, data): From b42c81fdb449568adbc3bc10fff0faf6a5511d6f Mon Sep 17 00:00:00 2001 From: eastboy007 <369614718@qq.com> Date: Wed, 11 Jan 2017 16:04:29 +0800 Subject: [PATCH 2/2] Fixed decode when shift one bit --- libsigrokdecode4DSL/decoders/jtag/pd.py | 56 +++++++++++++++---------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/libsigrokdecode4DSL/decoders/jtag/pd.py b/libsigrokdecode4DSL/decoders/jtag/pd.py index 44b64cf5..98919509 100755 --- a/libsigrokdecode4DSL/decoders/jtag/pd.py +++ b/libsigrokdecode4DSL/decoders/jtag/pd.py @@ -5,9 +5,11 @@ ## ## Version: ## Modified by Shiqiu Nie(369614718@qq.com) -## Date: 2017-01-10 -## Descript: Fixed TDI/TDO data decode, when JTAG TAP run into SHIFT-IR/SHIFT-DR status, -## the first bit is not a valid bit. +## Date: 2017-01-11 +## Descript: +## 1. 2017-01-10 Fixed TDI/TDO data decode, when JTAG TAP run into +## SHIFT-IR/SHIFT-DR status,the first bit is not a valid bit. +## 2. 2017-01-11 Fixed decode when shift only one bit. ## ## 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 @@ -206,9 +208,9 @@ class Decoder(srd.Decoder): self.bits_tdi.insert(0, tdi) self.bits_tdo.insert(0, tdo) - # Use self.samplenum as SS of the current bit. - self.bits_samplenums_tdi.insert(0, [self.samplenum, -1]) - self.bits_samplenums_tdo.insert(0, [self.samplenum, -1]) + # Use self.samplenum as SS of the current bit. + self.bits_samplenums_tdi.insert(0, [self.samplenum, -1]) + self.bits_samplenums_tdo.insert(0, [self.samplenum, -1]) self.bits_cnt = self.bits_cnt + 1 @@ -217,22 +219,32 @@ class Decoder(srd.Decoder): self.state.startswith('EXIT1-'): #self.es_bitstring = self.samplenum - if self.bits_cnt > 1: - ### ---------------------------------------------------------------- - self.putx([16, [str(self.bits_tdi[0])]]) - self.putx([17, [str(self.bits_tdo[0])]]) - ### Use self.samplenum as ES of the previous bit. - self.bits_samplenums_tdi[0][1] = self.samplenum - self.bits_samplenums_tdo[0][1] = self.samplenum + if self.bits_cnt > 0: + if self.bits_cnt == 1: # Only shift one bit + self.ss_bitstring = self.samplenum + self.bits_tdi.insert(0, tdi) + self.bits_tdo.insert(0, tdo) + ## Use self.samplenum as SS of the current bit. + self.bits_samplenums_tdi.insert(0, [self.samplenum, -1]) + self.bits_samplenums_tdo.insert(0, [self.samplenum, -1]) + else: + ### ---------------------------------------------------------------- + self.putx([16, [str(self.bits_tdi[0])]]) + self.putx([17, [str(self.bits_tdo[0])]]) + ### Use self.samplenum as ES of the previous bit. + self.bits_samplenums_tdi[0][1] = self.samplenum + self.bits_samplenums_tdo[0][1] = self.samplenum + + self.bits_tdi.insert(0, tdi) + self.bits_tdo.insert(0, tdo) + + ## Use self.samplenum as SS of the current bit. + self.bits_samplenums_tdi.insert(0, [self.samplenum, -1]) + self.bits_samplenums_tdo.insert(0, [self.samplenum, -1]) + ## ---------------------------------------------------------------- - self.bits_tdi.insert(0, tdi) - self.bits_tdo.insert(0, tdo) - - ## Use self.samplenum as SS of the current bit. - self.bits_samplenums_tdi.insert(0, [self.samplenum, -1]) - self.bits_samplenums_tdo.insert(0, [self.samplenum, -1]) - ## ---------------------------------------------------------------- self.data_ready = True + self.first_bit = True self.bits_cnt = 0 if self.oldstate.startswith('EXIT'):# and \ @@ -243,7 +255,7 @@ class Decoder(srd.Decoder): t = self.state[-2:] + ' TDI' b = ''.join(map(str, self.bits_tdi)) h = ' (0x%X' % int('0b' + b, 2) + ')' - s = t + ': ' + b + h + ', ' + str(len(self.bits_tdi)) + ' bits' + s = t + ': ' + h + ', ' + str(len(self.bits_tdi)) + ' bits' #b + self.putx_bs([18, [s]]) self.bits_samplenums_tdi[0][1] = self.samplenum # ES of last bit. self.putp_bs([t, [b, self.bits_samplenums_tdi]]) @@ -254,7 +266,7 @@ class Decoder(srd.Decoder): t = self.state[-2:] + ' TDO' b = ''.join(map(str, self.bits_tdo)) h = ' (0x%X' % int('0b' + b, 2) + ')' - s = t + ': ' + b + h + ', ' + str(len(self.bits_tdo)) + ' bits' + s = t + ': ' + h + ', ' + str(len(self.bits_tdo)) + ' bits' #+ b self.putx_bs([19, [s]]) self.bits_samplenums_tdo[0][1] = self.samplenum # ES of last bit. self.putp_bs([t, [b, self.bits_samplenums_tdo]])