From: Uwe Hermann Date: Tue, 6 Jun 2017 10:46:08 +0000 (+0200) Subject: Rename eeprom93cxx decoder to eeprom93xx. X-Git-Tag: libsigrokdecode-0.5.0~10 X-Git-Url: http://sigrok.org/gitweb/?p=libsigrokdecode.git;a=commitdiff_plain;h=e1eacaabe27095eb4688b4b1e50523d2d3527f22 Rename eeprom93cxx decoder to eeprom93xx. Not all EEPROMs of this series have (just) a 'c' in the name. --- diff --git a/decoders/eeprom93cxx/__init__.py b/decoders/eeprom93cxx/__init__.py deleted file mode 100644 index 036f1f7..0000000 --- a/decoders/eeprom93cxx/__init__.py +++ /dev/null @@ -1,32 +0,0 @@ -## -## This file is part of the libsigrokdecode project. -## -## Copyright (C) 2017 Kevin Redon -## -## 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 -## along with this program; if not, see . -## - -''' -This decoder stacks on top of the 'microwire' PD and decodes the 93Cxx EEPROM -specific instructions. - -The implemented instructions come from the STMicroelectronics M93Cx6 EEPROM -datasheet. They are compatible with the Atmel AT93Cxx EEPROM with slightly -different names. - -Warning: Other EEPROMs using Microwire might have different operation codes -and instructions. -''' - -from .pd import Decoder diff --git a/decoders/eeprom93cxx/pd.py b/decoders/eeprom93cxx/pd.py deleted file mode 100644 index cd54b47..0000000 --- a/decoders/eeprom93cxx/pd.py +++ /dev/null @@ -1,137 +0,0 @@ -## -## This file is part of the libsigrokdecode project. -## -## Copyright (C) 2017 Kevin Redon -## -## 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 -## along with this program; if not, see . -## - -import sigrokdecode as srd - -class Decoder(srd.Decoder): - api_version = 2 - id = 'eeprom93cxx' - name = '93Cxx EEPROM' - longname = '93Cxx Microwire EEPROM' - desc = '93Cxx series Microwire EEPROM protocol.' - license = 'gplv2+' - inputs = ['microwire'] - outputs = ['eeprom93cxx'] - options = ( - {'id': 'addresssize', 'desc': 'Address size', 'default': 8}, - {'id': 'wordsize', 'desc': 'Word size', 'default': 16}, - ) - annotations = ( - ('si-data', 'SI data'), - ('so-data', 'SO data'), - ('warning', 'Warning'), - ) - annotation_rows = ( - ('data', 'Data', (0, 1)), - ('warnings', 'Warnings', (2,)), - ) - - def __init__(self): - self.frame = [] - - def start(self): - self.out_ann = self.register(srd.OUTPUT_ANN) - self.addresssize = self.options['addresssize'] - self.wordsize = self.options['wordsize'] - - def put_address(self, data): - # Get address (MSb first). - a = 0 - for b in range(len(data)): - a += (data[b].si << (len(data) - b - 1)) - self.put(data[0].ss, data[-1].es, self.out_ann, - [0, ['Address: 0x%x' % a, 'Addr: 0x%x' % a, '0x%x' % a]]) - - def put_word(self, si, data): - # Decode word (MSb first). - word = 0 - for b in range(len(data)): - d = data[b].si if si else data[b].so - word += (d << (len(data) - b - 1)) - idx = 0 if si else 1 - self.put(data[0].ss, data[-1].es, - self.out_ann, [idx, ['Data: 0x%x' % word, '0x%x' % word]]) - - def decode(self, ss, es, data): - if len(data) < (2 + self.addresssize): - self.put(ss, es, self.out_ann, [2, ['Not enough packet bits']]) - return - - opcode = (data[0].si << 1) + (data[1].si << 0) - - if opcode == 2: - # READ instruction. - self.put(data[0].ss, data[1].es, - self.out_ann, [0, ['Read word', 'READ']]) - self.put_address(data[2:2 + self.addresssize]) - - # Get all words. - word_start = 2 + self.addresssize - while len(data) - word_start > 0: - # Check if there are enough bits for a word. - if len(data) - word_start < self.wordsize: - self.put(data[word_start].ss, data[len(data) - 1].es, - self.out_ann, [2, ['Not enough word bits']]) - break - self.put_word(False, data[word_start:word_start + self.wordsize]) - # Go to next word. - word_start += self.wordsize - elif opcode == 1: - # WRITE instruction. - self.put(data[0].ss, data[1].es, - self.out_ann, [0, ['Write word', 'WRITE']]) - self.put_address(data[2:2 + self.addresssize]) - # Get word. - if len(data) < 2 + self.addresssize + self.wordsize: - self.put(data[2 + self.addresssize].ss, - data[len(data) - 1].ss, - self.out_ann, [2, ['Not enough word bits']]) - else: - self.put_word(True, data[2 + self.addresssize:2 + self.addresssize + self.wordsize]) - elif opcode == 3: - # ERASE instruction. - self.put(data[0].ss, data[1].es, - self.out_ann, [0, ['Erase word', 'ERASE']]) - self.put_address(data[2:2 + self.addresssize]) - elif opcode == 0: - if data[2].si == 1 and data[3].si == 1: - # WEN instruction. - self.put(data[0].ss, data[2 + self.addresssize - 1].es, - self.out_ann, [0, ['Write enable', 'WEN']]) - elif data[2].si == 0 and data[3].si == 0: - # WDS instruction. - self.put(data[0].ss, data[2 + self.addresssize - 1].es, - self.out_ann, [0, ['Write disable', 'WDS']]) - elif data[2].si == 1 and data[3].si == 0: - # ERAL instruction. - self.put(data[0].ss, data[2 + self.addresssize - 1].es, - self.out_ann, [0, ['Erase all memory', - 'Erase all', 'ERAL']]) - elif data[2].si == 0 and data[3].si == 1: - # WRAL instruction. - self.put(data[0].ss, data[2 + self.addresssize - 1].es, - self.out_ann, [0, ['Write all memory', - 'Write all', 'WRAL']]) - # Get word. - if len(data) < 2 + self.addresssize + self.wordsize: - self.put(data[2 + self.addresssize].ss, - data[len(data) - 1].ss, - self.out_ann, [2, ['Not enough word bits']]) - else: - self.put_word(True, data[2 + self.addresssize:2 + self.addresssize + self.wordsize]) diff --git a/decoders/eeprom93xx/__init__.py b/decoders/eeprom93xx/__init__.py new file mode 100644 index 0000000..c8eaf7a --- /dev/null +++ b/decoders/eeprom93xx/__init__.py @@ -0,0 +1,32 @@ +## +## This file is part of the libsigrokdecode project. +## +## Copyright (C) 2017 Kevin Redon +## +## 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 +## along with this program; if not, see . +## + +''' +This decoder stacks on top of the 'microwire' PD and decodes the 93xx EEPROM +specific instructions. + +The implemented instructions come from the STMicroelectronics M93Cx6 EEPROM +datasheet. They are compatible with the Atmel AT93Cxx EEPROM with slightly +different names. + +Warning: Other EEPROMs using Microwire might have different operation codes +and instructions. +''' + +from .pd import Decoder diff --git a/decoders/eeprom93xx/pd.py b/decoders/eeprom93xx/pd.py new file mode 100644 index 0000000..5ae789f --- /dev/null +++ b/decoders/eeprom93xx/pd.py @@ -0,0 +1,137 @@ +## +## This file is part of the libsigrokdecode project. +## +## Copyright (C) 2017 Kevin Redon +## +## 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 +## along with this program; if not, see . +## + +import sigrokdecode as srd + +class Decoder(srd.Decoder): + api_version = 2 + id = 'eeprom93xx' + name = '93xx EEPROM' + longname = '93xx Microwire EEPROM' + desc = '93xx series Microwire EEPROM protocol.' + license = 'gplv2+' + inputs = ['microwire'] + outputs = ['eeprom93xx'] + options = ( + {'id': 'addresssize', 'desc': 'Address size', 'default': 8}, + {'id': 'wordsize', 'desc': 'Word size', 'default': 16}, + ) + annotations = ( + ('si-data', 'SI data'), + ('so-data', 'SO data'), + ('warning', 'Warning'), + ) + annotation_rows = ( + ('data', 'Data', (0, 1)), + ('warnings', 'Warnings', (2,)), + ) + + def __init__(self): + self.frame = [] + + def start(self): + self.out_ann = self.register(srd.OUTPUT_ANN) + self.addresssize = self.options['addresssize'] + self.wordsize = self.options['wordsize'] + + def put_address(self, data): + # Get address (MSb first). + a = 0 + for b in range(len(data)): + a += (data[b].si << (len(data) - b - 1)) + self.put(data[0].ss, data[-1].es, self.out_ann, + [0, ['Address: 0x%x' % a, 'Addr: 0x%x' % a, '0x%x' % a]]) + + def put_word(self, si, data): + # Decode word (MSb first). + word = 0 + for b in range(len(data)): + d = data[b].si if si else data[b].so + word += (d << (len(data) - b - 1)) + idx = 0 if si else 1 + self.put(data[0].ss, data[-1].es, + self.out_ann, [idx, ['Data: 0x%x' % word, '0x%x' % word]]) + + def decode(self, ss, es, data): + if len(data) < (2 + self.addresssize): + self.put(ss, es, self.out_ann, [2, ['Not enough packet bits']]) + return + + opcode = (data[0].si << 1) + (data[1].si << 0) + + if opcode == 2: + # READ instruction. + self.put(data[0].ss, data[1].es, + self.out_ann, [0, ['Read word', 'READ']]) + self.put_address(data[2:2 + self.addresssize]) + + # Get all words. + word_start = 2 + self.addresssize + while len(data) - word_start > 0: + # Check if there are enough bits for a word. + if len(data) - word_start < self.wordsize: + self.put(data[word_start].ss, data[len(data) - 1].es, + self.out_ann, [2, ['Not enough word bits']]) + break + self.put_word(False, data[word_start:word_start + self.wordsize]) + # Go to next word. + word_start += self.wordsize + elif opcode == 1: + # WRITE instruction. + self.put(data[0].ss, data[1].es, + self.out_ann, [0, ['Write word', 'WRITE']]) + self.put_address(data[2:2 + self.addresssize]) + # Get word. + if len(data) < 2 + self.addresssize + self.wordsize: + self.put(data[2 + self.addresssize].ss, + data[len(data) - 1].ss, + self.out_ann, [2, ['Not enough word bits']]) + else: + self.put_word(True, data[2 + self.addresssize:2 + self.addresssize + self.wordsize]) + elif opcode == 3: + # ERASE instruction. + self.put(data[0].ss, data[1].es, + self.out_ann, [0, ['Erase word', 'ERASE']]) + self.put_address(data[2:2 + self.addresssize]) + elif opcode == 0: + if data[2].si == 1 and data[3].si == 1: + # WEN instruction. + self.put(data[0].ss, data[2 + self.addresssize - 1].es, + self.out_ann, [0, ['Write enable', 'WEN']]) + elif data[2].si == 0 and data[3].si == 0: + # WDS instruction. + self.put(data[0].ss, data[2 + self.addresssize - 1].es, + self.out_ann, [0, ['Write disable', 'WDS']]) + elif data[2].si == 1 and data[3].si == 0: + # ERAL instruction. + self.put(data[0].ss, data[2 + self.addresssize - 1].es, + self.out_ann, [0, ['Erase all memory', + 'Erase all', 'ERAL']]) + elif data[2].si == 0 and data[3].si == 1: + # WRAL instruction. + self.put(data[0].ss, data[2 + self.addresssize - 1].es, + self.out_ann, [0, ['Write all memory', + 'Write all', 'WRAL']]) + # Get word. + if len(data) < 2 + self.addresssize + self.wordsize: + self.put(data[2 + self.addresssize].ss, + data[len(data) - 1].ss, + self.out_ann, [2, ['Not enough word bits']]) + else: + self.put_word(True, data[2 + self.addresssize:2 + self.addresssize + self.wordsize])