2016-07-20 08:59:39 +08:00
|
|
|
##
|
|
|
|
## This file is part of the libsigrokdecode project.
|
|
|
|
##
|
|
|
|
## Copyright (C) 2016 fenugrec <fenugrec users.sourceforge.net>
|
2019-09-09 00:07:19 -07:00
|
|
|
## Copyright (C) 2019 DreamSourceLab <support@dreamsourcelab.com>
|
2016-07-20 08:59:39 +08:00
|
|
|
##
|
|
|
|
## 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
|
|
|
|
## (at your option) any later version.
|
|
|
|
##
|
|
|
|
## This program is distributed in the hope that it will be useful,
|
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
|
|
|
## You should have received a copy of the GNU General Public License
|
2019-09-09 00:07:19 -07:00
|
|
|
## along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2016-07-20 08:59:39 +08:00
|
|
|
##
|
|
|
|
|
|
|
|
# TODO:
|
|
|
|
# - Annotations are very crude and could be improved.
|
|
|
|
# - Annotate every nibble? Would give insight on interrupted shifts.
|
|
|
|
# - Annotate invalid "command" nibbles while SYNC==1?
|
|
|
|
|
|
|
|
import sigrokdecode as srd
|
|
|
|
|
|
|
|
class Decoder(srd.Decoder):
|
2019-09-09 00:07:19 -07:00
|
|
|
api_version = 3
|
2016-07-20 08:59:39 +08:00
|
|
|
id = 'aud'
|
|
|
|
name = 'AUD'
|
|
|
|
longname = 'Advanced User Debugger'
|
|
|
|
desc = 'Renesas/Hitachi Advanced User Debugger (AUD) protocol.'
|
|
|
|
license = 'gplv2+'
|
|
|
|
inputs = ['logic']
|
2019-09-09 00:07:19 -07:00
|
|
|
outputs = []
|
|
|
|
tags = ['Debug/trace']
|
2016-07-20 08:59:39 +08:00
|
|
|
channels = (
|
2022-10-21 11:10:28 +08:00
|
|
|
{'id': 'audck', 'name': 'AUDCK', 'desc': 'AUD clock', 'idn':'dec_aud_chan_audck'},
|
|
|
|
{'id': 'naudsync', 'name': 'nAUDSYNC', 'desc': 'AUD sync', 'idn':'dec_aud_chan_naudsync'},
|
|
|
|
{'id': 'audata3', 'name': 'AUDATA3', 'desc': 'AUD data line 3', 'idn':'dec_aud_chan_audata3'},
|
|
|
|
{'id': 'audata2', 'name': 'AUDATA2', 'desc': 'AUD data line 2', 'idn':'dec_aud_chan_audata2'},
|
|
|
|
{'id': 'audata1', 'name': 'AUDATA1', 'desc': 'AUD data line 1', 'idn':'dec_aud_chan_audata1'},
|
|
|
|
{'id': 'audata0', 'name': 'AUDATA0', 'desc': 'AUD data line 0', 'idn':'dec_aud_chan_audata0'},
|
2016-07-20 08:59:39 +08:00
|
|
|
)
|
|
|
|
annotations = (
|
|
|
|
('dest', 'Destination address'),
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self):
|
2019-09-09 00:07:19 -07:00
|
|
|
self.reset()
|
|
|
|
|
|
|
|
def reset(self):
|
2016-07-20 08:59:39 +08:00
|
|
|
self.ncnt = 0
|
|
|
|
self.nmax = 0
|
|
|
|
self.addr = 0
|
|
|
|
self.lastaddr = 0
|
|
|
|
self.ss = 0
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
self.out_ann = self.register(srd.OUTPUT_ANN)
|
|
|
|
|
|
|
|
def putx(self, data):
|
|
|
|
self.put(self.ss, self.samplenum, self.out_ann, data)
|
|
|
|
|
2019-09-09 00:07:19 -07:00
|
|
|
def handle_clk_edge(self, clk, sync, datapins):
|
2016-07-20 08:59:39 +08:00
|
|
|
# Reconstruct nibble.
|
|
|
|
nib = 0
|
|
|
|
for i in range(4):
|
|
|
|
nib |= datapins[3-i] << i
|
|
|
|
|
|
|
|
# sync == 1: annotate if finished; update cmd.
|
|
|
|
# TODO: Annotate idle level (nibble = 0x03 && SYNC=1).
|
|
|
|
if sync == 1:
|
|
|
|
if (self.ncnt == self.nmax) and (self.nmax != 0):
|
|
|
|
# Done shifting an address: annotate.
|
|
|
|
self.putx([0, ['0x%08X' % self.addr]])
|
|
|
|
self.lastaddr = self.addr
|
|
|
|
|
|
|
|
self.ncnt = 0
|
|
|
|
self.addr = self.lastaddr
|
|
|
|
self.ss = self.samplenum
|
|
|
|
if nib == 0x08:
|
|
|
|
self.nmax = 1
|
|
|
|
elif nib == 0x09:
|
|
|
|
self.nmax = 2
|
|
|
|
elif nib == 0x0a:
|
|
|
|
self.nmax = 4
|
|
|
|
elif nib == 0x0b:
|
|
|
|
self.nmax = 8
|
|
|
|
else:
|
|
|
|
# Undefined or idle.
|
|
|
|
self.nmax = 0
|
|
|
|
else:
|
|
|
|
# sync == 0, valid cmd: start or continue shifting in nibbles.
|
|
|
|
if (self.nmax > 0):
|
|
|
|
# Clear tgt nibble.
|
|
|
|
self.addr &= ~(0x0F << (self.ncnt * 4))
|
|
|
|
# Set nibble.
|
|
|
|
self.addr |= nib << (self.ncnt * 4)
|
|
|
|
self.ncnt += 1
|
|
|
|
|
2019-09-09 00:07:19 -07:00
|
|
|
def decode(self):
|
|
|
|
while True:
|
|
|
|
(clk, sync, d3, d2, d1, d0) = self.wait({0: 'r'})
|
|
|
|
d = (d3, d2, d1, d0)
|
|
|
|
self.handle_clk_edge(clk, sync, d)
|