2 ## This file is part of the libsigrokdecode project.
4 ## Copyright (C) 2018 Stefan Petersen <spe@ciellt.se>
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.
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.
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/>.
21 import sigrokdecode as srd
24 0x80: ['WRDS', 0, lambda _: ''],
25 0x81: ['STO', 1, lambda _: ''],
26 0x82: ['SLEEP', 2, lambda _: ''],
27 0x83: ['WRITE', 3, lambda v: '0x%x' % v],
28 0x84: ['WREN', 4, lambda _: ''],
29 0x85: ['RCL', 5, lambda _: ''],
30 0x86: ['READ', 6, lambda v: '0x%x' % v],
31 0x87: ['READ', 7, lambda v: '0x%x' % v],
34 class Decoder(srd.Decoder):
38 longname = 'Xicor X2444M/P'
39 desc = 'Xicor X2444M/P nonvolatile static RAM protocol.'
43 tags = ['IC', 'Memory']
45 ('wrds', 'Write disable'),
46 ('sto', 'Store RAM data in EEPROM'),
47 ('sleep', 'Enter sleep mode'),
48 ('write', 'Write data into RAM'),
49 ('wren', 'Write enable'),
50 ('rcl', 'Recall EEPROM data into RAM'),
51 ('read', 'Data read from RAM'),
52 ('read', 'Data read from RAM'),
60 self.cs_asserted = False
64 self.out_ann = self.register(srd.OUTPUT_ANN)
66 def putreadwrite(self, ss, es, reg, idx, addr, value):
67 self.put(ss, es, self.out_ann,
68 [idx, ['%s: %s => 0x%4.4x' % (reg, addr, value),
69 '%s: %s => 0x%4.4x' % (reg[0], addr, value), reg[0]]])
71 def putcmd(self, ss, es, reg, idx):
72 self.put(ss, es, self.out_ann, [idx, [reg, reg[0]]])
74 def decode(self, ss, es, data):
75 ptype, mosi, miso = data
78 if not self.cs_asserted:
81 if self.cmd_digit == 0:
84 elif self.cmd_digit > 0:
85 self.read_value = (self.read_value << 8) + miso
86 self.write_value = (self.write_value << 8) + mosi
88 elif ptype == 'CS-CHANGE':
89 self.cs_asserted = (miso == 1)
90 # When not asserted, CS has just changed from asserted to deasserted.
91 if not self.cs_asserted:
92 # Only one digit, simple command. Else read/write.
93 if self.cmd_digit == 1:
94 name, idx, decoder = registers[self.addr & 0x87]
95 self.putcmd(self.addr_start, es, name, idx)
96 elif self.cmd_digit > 1:
97 name, idx, decoder = registers[self.addr & 0x87]
99 value = self.read_value
100 elif name == 'WRITE':
101 value = self.write_value
104 self.putreadwrite(self.addr_start, es, name, idx,
105 decoder((self.addr >> 3) & 0x0f), value)