]>
Commit | Line | Data |
---|---|---|
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 | |
4539e9ca | 17 | ## along with this program; if not, see <http://www.gnu.org/licenses/>. |
e96593c1 | 18 | ## |
19 | ||
20 | # TODO: | |
21 | # - Annotations are very crude and could be improved. | |
22 | # - Annotate every nibble? Would give insight on interrupted shifts. | |
23 | # - Annotate invalid "command" nibbles while SYNC==1? | |
24 | ||
25 | import sigrokdecode as srd | |
26 | ||
27 | class Decoder(srd.Decoder): | |
86e7c29c | 28 | api_version = 3 |
e96593c1 | 29 | id = 'aud' |
30 | name = 'AUD' | |
31 | longname = 'Advanced User Debugger' | |
32 | desc = 'Renesas/Hitachi Advanced User Debugger (AUD) protocol.' | |
33 | license = 'gplv2+' | |
34 | inputs = ['logic'] | |
6cbba91f | 35 | outputs = [] |
d6d8a8a4 | 36 | tags = ['Debug/trace'] |
e96593c1 | 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): |
10aeb8ea GS |
50 | self.reset() |
51 | ||
52 | def reset(self): | |
e96593c1 | 53 | self.ncnt = 0 |
54 | self.nmax = 0 | |
55 | self.addr = 0 | |
56 | self.lastaddr = 0 | |
e96593c1 | 57 | self.ss = 0 |
58 | ||
59 | def start(self): | |
60 | self.out_ann = self.register(srd.OUTPUT_ANN) | |
61 | ||
62 | def putx(self, data): | |
63 | self.put(self.ss, self.samplenum, self.out_ann, data) | |
64 | ||
86e7c29c | 65 | def handle_clk_edge(self, clk, sync, datapins): |
e96593c1 | 66 | # Reconstruct nibble. |
67 | nib = 0 | |
68 | for i in range(4): | |
69 | nib |= datapins[3-i] << i | |
70 | ||
71 | # sync == 1: annotate if finished; update cmd. | |
72 | # TODO: Annotate idle level (nibble = 0x03 && SYNC=1). | |
73 | if sync == 1: | |
74 | if (self.ncnt == self.nmax) and (self.nmax != 0): | |
75 | # Done shifting an address: annotate. | |
76 | self.putx([0, ['0x%08X' % self.addr]]) | |
77 | self.lastaddr = self.addr | |
78 | ||
79 | self.ncnt = 0 | |
80 | self.addr = self.lastaddr | |
81 | self.ss = self.samplenum | |
82 | if nib == 0x08: | |
83 | self.nmax = 1 | |
84 | elif nib == 0x09: | |
85 | self.nmax = 2 | |
86 | elif nib == 0x0a: | |
87 | self.nmax = 4 | |
88 | elif nib == 0x0b: | |
89 | self.nmax = 8 | |
90 | else: | |
91 | # Undefined or idle. | |
92 | self.nmax = 0 | |
93 | else: | |
94 | # sync == 0, valid cmd: start or continue shifting in nibbles. | |
95 | if (self.nmax > 0): | |
96 | # Clear tgt nibble. | |
97 | self.addr &= ~(0x0F << (self.ncnt * 4)) | |
98 | # Set nibble. | |
99 | self.addr |= nib << (self.ncnt * 4) | |
100 | self.ncnt += 1 | |
101 | ||
86e7c29c UH |
102 | def decode(self): |
103 | while True: | |
104 | pins = self.wait({0: 'r'}) | |
e96593c1 | 105 | clk = pins[0] |
106 | sync = pins[1] | |
107 | d = pins[2:] | |
86e7c29c | 108 | self.handle_clk_edge(clk, sync, d) |