From 241958087539b7cebc4a6f5516874568e59b6e33 Mon Sep 17 00:00:00 2001 From: hneemann Date: Wed, 6 Sep 2017 15:56:33 +0200 Subject: [PATCH] Added an EEPROM --- .../neemann/digital/core/memory/EEPROM.java | 104 ++++++++++ .../digital/draw/library/ElementLibrary.java | 1 + src/main/resources/lang/lang_de.xml | 9 + src/main/resources/lang/lang_en.xml | 9 + .../digital/integration/TestExamples.java | 4 +- src/test/resources/dig/test/eeprom.dig | 194 ++++++++++++++++++ 6 files changed, 319 insertions(+), 2 deletions(-) create mode 100644 src/main/java/de/neemann/digital/core/memory/EEPROM.java create mode 100644 src/test/resources/dig/test/eeprom.dig diff --git a/src/main/java/de/neemann/digital/core/memory/EEPROM.java b/src/main/java/de/neemann/digital/core/memory/EEPROM.java new file mode 100644 index 000000000..a784426df --- /dev/null +++ b/src/main/java/de/neemann/digital/core/memory/EEPROM.java @@ -0,0 +1,104 @@ +package de.neemann.digital.core.memory; + +import de.neemann.digital.core.Node; +import de.neemann.digital.core.NodeException; +import de.neemann.digital.core.ObservableValue; +import de.neemann.digital.core.ObservableValues; +import de.neemann.digital.core.element.Element; +import de.neemann.digital.core.element.ElementAttributes; +import de.neemann.digital.core.element.ElementTypeDescription; +import de.neemann.digital.core.element.Keys; + +import static de.neemann.digital.core.element.PinInfo.input; + +/** + * A EEPROM module. + * + * @author hneemann + */ +public class EEPROM extends Node implements Element { + + /** + * The EEPROMs {@link ElementTypeDescription} + */ + public static final ElementTypeDescription DESCRIPTION = new ElementTypeDescription(EEPROM.class, + input("A"), + input("CS"), + input("WE"), + input("OE")) + .addAttribute(Keys.ROTATE) + .addAttribute(Keys.BITS) + .addAttribute(Keys.ADDR_BITS) + .addAttribute(Keys.LABEL) + .addAttribute(Keys.DATA); + + private final int bits; + private final int addrBits; + private final DataField memory; + private final ObservableValue dataOut; + + private ObservableValue addrIn; + private ObservableValue csIn; + private ObservableValue weIn; + private ObservableValue oeIn; + private ObservableValue dataIn; + private int addr; + private boolean cs; + private boolean oe; + + /** + * Creates a new instance + * + * @param attr the elements attributes + */ + public EEPROM(ElementAttributes attr) { + super(true); + bits = attr.get(Keys.BITS); + addrBits = attr.get(Keys.ADDR_BITS); + int size = 1 << addrBits; + DataField memory = attr.get(Keys.DATA); + if (memory.size() < size) { + memory = new DataField(memory, size); + attr.set(Keys.DATA, memory); + } + this.memory = memory; + dataOut = new ObservableValue("D", bits, true).setPinDescription(DESCRIPTION).setBidirectional(); + } + + @Override + public void setInputs(ObservableValues inputs) throws NodeException { + addrIn = inputs.get(0).checkBits(addrBits, this).addObserverToValue(this); + csIn = inputs.get(1).checkBits(1, this).addObserverToValue(this); + weIn = inputs.get(2).checkBits(1, this).addObserverToValue(this); + oeIn = inputs.get(3).checkBits(1, this).addObserverToValue(this); + dataIn = inputs.get(4).checkBits(bits, this).addObserverToValue(this); + } + + @Override + public void readInputs() throws NodeException { + cs = csIn.getBool(); + if (cs) { + addr = (int) addrIn.getValue(); + oe = oeIn.getBool(); + if (weIn.getBool()) { + long data = dataIn.getValue(); + memory.setData(addr, data); + } + } + } + + @Override + public void writeOutputs() throws NodeException { + if (cs && oe) { + dataOut.set(memory.getDataWord(addr), false); + } else { + dataOut.set(0, true); + } + } + + @Override + public ObservableValues getOutputs() { + return dataOut.asList(); + } + +} diff --git a/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java b/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java index a090e08e1..fd26fd51e 100644 --- a/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java +++ b/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java @@ -135,6 +135,7 @@ public class ElementLibrary implements Iterable .add(RAMDualPort.DESCRIPTION) .add(RAMSinglePort.DESCRIPTION) .add(RAMSinglePortSel.DESCRIPTION) + .add(EEPROM.DESCRIPTION) .add(GraphicCard.DESCRIPTION) .add(Counter.DESCRIPTION)) .add(new LibraryNode(Lang.get("lib_arithmetic")) diff --git a/src/main/resources/lang/lang_de.xml b/src/main/resources/lang/lang_de.xml index 475410f68..e362c16d0 100644 --- a/src/main/resources/lang/lang_de.xml +++ b/src/main/resources/lang/lang_de.xml @@ -272,6 +272,15 @@ Es können sowohl komplette Takte als auch einzelne Gatter-Veränderungen angeze Ein RAM-Baustein mit einem bidirektionellem Anschluss für das Lesen und Schreiben von Daten. Es gibt einen CS-Eingang. Mit diesem können mehrere solcher Bausteine mit einem Adressdekoder zu einem größeren RAM zusammengeschaltet werden. + EEPROM + Die Adresse, an der gelesen und geschrieben wird. + Bei einer 1 werden die Daten in das EEPROM geschrieben. + Der bidirektionale Datenanschluß. + Ist dieser Eingang 1 ist der Baustein aktiv. + Ist dieser Eingang 1 wird das Datenwort ausgegeben. + Ein EEPROM-Baustein mit einem bidirektionellem Anschluss für das Lesen und Schreiben von Daten. + Es gibt einen CS-Eingang. Mit diesem können mehrere solcher Bausteine mit einem Adressdekoder zu einem größeren EEPROM zusammengeschaltet werden. + Grafik-RAM Wird verwendet um Bitmap Grafiken anzuzeigen. Der Baustein verhält sich wie ein RAM-Baustein mit dem Unterschied, dass der RAM-Inhalt als Grafik angezeigt wird. Jede Speicherstelle definiert die Farbe diff --git a/src/main/resources/lang/lang_en.xml b/src/main/resources/lang/lang_en.xml index 607b79074..60db2d1d4 100644 --- a/src/main/resources/lang/lang_en.xml +++ b/src/main/resources/lang/lang_en.xml @@ -268,6 +268,15 @@ A RAM module with a bidirectional connection for reading and writing the data. The CS input allows to build a larger RAM from some smaller RAMs and a address decoder. + EEPROM + The address to read and write. + If set to high the data is written to the EEPROM. + The bidirectional data connection. + If this input is high, this EEPROM is enabled. Otherwise the output is always in high Z state. + If this input is high, the stored value is output. + A EEPROM module with a bidirectional connection for reading and writing the data. + The CS input allows to build a larger EEPROM from some smaller EEPROMs and a address decoder. + Graphic RAM Used to show a bitmap graphic. This element works similar to a RAM. In addition it shows its content on a graphic screen. Every pixel is represented by a memory address. There are to screens supported diff --git a/src/test/java/de/neemann/digital/integration/TestExamples.java b/src/test/java/de/neemann/digital/integration/TestExamples.java index 45b05ca45..de3f67a5e 100644 --- a/src/test/java/de/neemann/digital/integration/TestExamples.java +++ b/src/test/java/de/neemann/digital/integration/TestExamples.java @@ -40,8 +40,8 @@ public class TestExamples extends TestCase { */ public void testTestExamples() throws Exception { File examples = new File(Resources.getRoot(), "/dig/test"); - assertEquals(100, new FileScanner(this::check).scan(examples)); - assertEquals(91, testCasesInFiles); + assertEquals(101, new FileScanner(this::check).scan(examples)); + assertEquals(93, testCasesInFiles); } diff --git a/src/test/resources/dig/test/eeprom.dig b/src/test/resources/dig/test/eeprom.dig new file mode 100644 index 000000000..536813c61 --- /dev/null +++ b/src/test/resources/dig/test/eeprom.dig @@ -0,0 +1,194 @@ + + + 1 + + + + EEPROM + + + AddrBits + 8 + + + Bits + 8 + + + Data + + + + lastDataFile + /home/hneemann/temp/z/z.hex + + + + + + In + + + Label + A + + + Bits + 8 + + + + + + In + + + Label + CS + + + + + + In + + + Label + OE + + + + + + In + + + Label + WE + + + + + + Out + + + Label + D_out + + + Bits + 8 + + + + + + In + + + Label + D_in + + + Bits + 8 + + + isHighZ + true + + + + + + Testcase + + + Label + first + + + Testdata + + A CS OE WE D_in D_out +0 0 0 0 Z Z + +# write to EEPROM +loop(n,30) +(n) 1 0 0 (n) (n) +(n) 1 0 1 (n) (n) +end loop + +# read from EEPROM +loop(n,30) +(n) 1 1 0 Z (n) +end loop + + + + + + + + Testcase + + + Label + second + + + Testdata + + A CS OE WE D_in D_out +0 0 0 0 Z Z + +# Data written by the first test case +# is still present in the EEPROM. + +# read from EEPROM +loop(n,30) +(n) 1 1 0 Z (n) +end loop + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file