]> sigrok.org Git - libsigrokdecode.git/blob - decoders/aud/pd.py
license: remove FSF postal address from boiler plate license text
[libsigrokdecode.git] / decoders / aud / pd.py
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, see <http://www.gnu.org/licenses/>.
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):
28     api_version = 3
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']
35     outputs = ['aud']
36     channels = (
37         {'id': 'audck', 'name': 'AUDCK', 'desc': 'AUD clock'},
38         {'id': 'naudsync', 'name': 'nAUDSYNC', 'desc': 'AUD sync'},
39         {'id': 'audata3', 'name': 'AUDATA3', 'desc': 'AUD data line 3'},
40         {'id': 'audata2', 'name': 'AUDATA2', 'desc': 'AUD data line 2'},
41         {'id': 'audata1', 'name': 'AUDATA1', 'desc': 'AUD data line 1'},
42         {'id': 'audata0', 'name': 'AUDATA0', 'desc': 'AUD data line 0'},
43     )
44     annotations = (
45         ('dest', 'Destination address'),
46     )
47
48     def __init__(self):
49         self.ncnt = 0
50         self.nmax = 0
51         self.addr = 0
52         self.lastaddr = 0
53         self.ss = 0
54
55     def start(self):
56         self.out_ann = self.register(srd.OUTPUT_ANN)
57
58     def putx(self, data):
59         self.put(self.ss, self.samplenum, self.out_ann, data)
60
61     def handle_clk_edge(self, clk, sync, datapins):
62         # Reconstruct nibble.
63         nib = 0
64         for i in range(4):
65             nib |= datapins[3-i] << i
66
67         # sync == 1: annotate if finished; update cmd.
68         # TODO: Annotate idle level (nibble = 0x03 && SYNC=1).
69         if sync == 1:
70             if (self.ncnt == self.nmax) and (self.nmax != 0):
71                 # Done shifting an address: annotate.
72                 self.putx([0, ['0x%08X' % self.addr]])
73                 self.lastaddr = self.addr
74
75             self.ncnt = 0
76             self.addr = self.lastaddr
77             self.ss = self.samplenum
78             if nib == 0x08:
79                 self.nmax = 1
80             elif nib == 0x09:
81                 self.nmax = 2
82             elif nib == 0x0a:
83                 self.nmax = 4
84             elif nib == 0x0b:
85                 self.nmax = 8
86             else:
87                 # Undefined or idle.
88                 self.nmax = 0
89         else:
90             # sync == 0, valid cmd: start or continue shifting in nibbles.
91             if (self.nmax > 0):
92                 # Clear tgt nibble.
93                 self.addr &= ~(0x0F << (self.ncnt * 4))
94                 # Set nibble.
95                 self.addr |= nib << (self.ncnt * 4)
96                 self.ncnt += 1
97
98     def decode(self):
99         while True:
100             pins = self.wait({0: 'r'})
101             clk = pins[0]
102             sync = pins[1]
103             d = pins[2:]
104             self.handle_clk_edge(clk, sync, d)