]> sigrok.org Git - libsigrokdecode.git/blame - decoders/aud/pd.py
aud: Convert to PD API version 3.
[libsigrokdecode.git] / decoders / aud / pd.py
CommitLineData
e96593c1 1##
2## This file is part of the libsigrokdecode project.
3##
4## Copyright (C) 2016 fenugrec <fenugrec users.sourceforge.net>
5##
6## This program is free software; you can redistribute it and/or modify
7## it under the terms of the GNU General Public License as published by
8## the Free Software Foundation; either version 2 of the License, or
9## (at your option) any later version.
10##
11## This program is distributed in the hope that it will be useful,
12## but WITHOUT ANY WARRANTY; without even the implied warranty of
13## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14## GNU General Public License for more details.
15##
16## You should have received a copy of the GNU General Public License
17## along with this program; if not, write to the Free Software
18## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19##
20
21# TODO:
22# - Annotations are very crude and could be improved.
23# - Annotate every nibble? Would give insight on interrupted shifts.
24# - Annotate invalid "command" nibbles while SYNC==1?
25
26import sigrokdecode as srd
27
28class Decoder(srd.Decoder):
86e7c29c 29 api_version = 3
e96593c1 30 id = 'aud'
31 name = 'AUD'
32 longname = 'Advanced User Debugger'
33 desc = 'Renesas/Hitachi Advanced User Debugger (AUD) protocol.'
34 license = 'gplv2+'
35 inputs = ['logic']
36 outputs = ['aud']
37 channels = (
38 {'id': 'audck', 'name': 'AUDCK', 'desc': 'AUD clock'},
39 {'id': 'naudsync', 'name': 'nAUDSYNC', 'desc': 'AUD sync'},
40 {'id': 'audata3', 'name': 'AUDATA3', 'desc': 'AUD data line 3'},
41 {'id': 'audata2', 'name': 'AUDATA2', 'desc': 'AUD data line 2'},
42 {'id': 'audata1', 'name': 'AUDATA1', 'desc': 'AUD data line 1'},
43 {'id': 'audata0', 'name': 'AUDATA0', 'desc': 'AUD data line 0'},
44 )
45 annotations = (
46 ('dest', 'Destination address'),
47 )
48
92b7b49f 49 def __init__(self):
e96593c1 50 self.ncnt = 0
51 self.nmax = 0
52 self.addr = 0
53 self.lastaddr = 0
e96593c1 54 self.ss = 0
55
56 def start(self):
57 self.out_ann = self.register(srd.OUTPUT_ANN)
58
59 def putx(self, data):
60 self.put(self.ss, self.samplenum, self.out_ann, data)
61
86e7c29c 62 def handle_clk_edge(self, clk, sync, datapins):
e96593c1 63 # Reconstruct nibble.
64 nib = 0
65 for i in range(4):
66 nib |= datapins[3-i] << i
67
68 # sync == 1: annotate if finished; update cmd.
69 # TODO: Annotate idle level (nibble = 0x03 && SYNC=1).
70 if sync == 1:
71 if (self.ncnt == self.nmax) and (self.nmax != 0):
72 # Done shifting an address: annotate.
73 self.putx([0, ['0x%08X' % self.addr]])
74 self.lastaddr = self.addr
75
76 self.ncnt = 0
77 self.addr = self.lastaddr
78 self.ss = self.samplenum
79 if nib == 0x08:
80 self.nmax = 1
81 elif nib == 0x09:
82 self.nmax = 2
83 elif nib == 0x0a:
84 self.nmax = 4
85 elif nib == 0x0b:
86 self.nmax = 8
87 else:
88 # Undefined or idle.
89 self.nmax = 0
90 else:
91 # sync == 0, valid cmd: start or continue shifting in nibbles.
92 if (self.nmax > 0):
93 # Clear tgt nibble.
94 self.addr &= ~(0x0F << (self.ncnt * 4))
95 # Set nibble.
96 self.addr |= nib << (self.ncnt * 4)
97 self.ncnt += 1
98
86e7c29c
UH
99 def decode(self):
100 while True:
101 pins = self.wait({0: 'r'})
e96593c1 102 clk = pins[0]
103 sync = pins[1]
104 d = pins[2:]
86e7c29c 105 self.handle_clk_edge(clk, sync, d)