From f56946feaffd1cff39cbbea8c9368a829e6fc80b Mon Sep 17 00:00:00 2001 From: hneemann Date: Thu, 22 Jun 2017 10:18:31 +0200 Subject: [PATCH] model analyser supports enable input of T-FF. --- distribution/ReleaseNotes.txt | 6 +- .../digital/analyse/ModelAnalyser.java | 34 ++-- .../java/de/neemann/digital/core/Model.java | 16 ++ .../digital/core/flipflops/FlipflopJK.java | 19 +- .../digital/core/flipflops/FlipflopT.java | 7 + .../digital/analyse/ModelAnalyserTest.java | 6 + .../resources/dig/analyze/analyzeTestTFF.dig | 164 +++++++++--------- .../dig/analyze/analyzeTestTFFEnable.dig | 83 +++++++++ 8 files changed, 236 insertions(+), 99 deletions(-) create mode 100644 src/test/resources/dig/analyze/analyzeTestTFFEnable.dig diff --git a/distribution/ReleaseNotes.txt b/distribution/ReleaseNotes.txt index c7292b731..86dfa88f6 100644 --- a/distribution/ReleaseNotes.txt +++ b/distribution/ReleaseNotes.txt @@ -7,8 +7,12 @@ planned as v0.13 CAUTION: All default values are lost! If you have built a circuit that contains test cases that depend on a non-null default value, this tests will fail. To resolve this issue, reset the default value. +- added an enable input to the T flip-flop + CAUTION: By default this input is activated now. In circuits which used the T flip-flop + in the past, the new input needs to be disabled. - A warning message shows up if a circuit with unnamed inputs/outputs is analysed. -- A warning message shows up if a circuit with missing pin numbers is exported to a hardware-related file. +- A warning message shows up if a circuit with missing pin numbers is exported to a + hardware-related file. - Comments are allowed in hex files. v0.12.1, released on 05. Jun 2016 diff --git a/src/main/java/de/neemann/digital/analyse/ModelAnalyser.java b/src/main/java/de/neemann/digital/analyse/ModelAnalyser.java index bf88f8434..ba9db948a 100644 --- a/src/main/java/de/neemann/digital/analyse/ModelAnalyser.java +++ b/src/main/java/de/neemann/digital/analyse/ModelAnalyser.java @@ -254,8 +254,8 @@ public class ModelAnalyser { * Analyses the circuit * * @return the generated truth table - * @throws NodeException NodeException - * @throws PinException PinException + * @throws NodeException NodeException + * @throws PinException PinException * @throws BacktrackException BacktrackException */ public TruthTable analyse() throws NodeException, PinException, BacktrackException { @@ -303,8 +303,6 @@ public class ModelAnalyser { for (FlipflopJK jk : jkList) { checkClock(jk); - // remove JK-ff from model - model.removeNode(jk); jk.getClockVal().removeObserver(jk); jk.getjVal().removeObserver(jk); jk.getkVal().removeObserver(jk); @@ -330,28 +328,32 @@ public class ModelAnalyser { model.add(a2); model.add(nk); model.add(or); - model.add(d); + model.replace(jk, d); } } private void replaceTFF() throws NodeException, AnalyseException { - List jkList = model.findNode(FlipflopT.class); + List tList = model.findNode(FlipflopT.class); - for (FlipflopT tff : jkList) { + for (FlipflopT tff : tList) { checkClock(tff); - - // remove T-ff from model - model.removeNode(tff); tff.getClockVal().removeObserver(tff); - - // create d ff ObservableValue q = tff.getOutputs().get(0); ObservableValue qn = tff.getOutputs().get(1); - FlipflopD d = new FlipflopD(tff.getLabel(), q, qn); - d.setInputs(new ObservableValues(qn, getClock())); - - model.add(d); + ObservableValue enable = tff.getEnableVal(); + if (enable == null) { + // create d ff + FlipflopD d = new FlipflopD(tff.getLabel(), q, qn); + d.setInputs(new ObservableValues(qn, getClock())); + model.replace(tff, d); + } else { + // create jk ff + enable.removeObserver(tff); + FlipflopJK jk = new FlipflopJK(tff.getLabel(), q, qn); + jk.setInputs(new ObservableValues(enable, getClock(), enable)); + model.replace(tff, jk); + } } } diff --git a/src/main/java/de/neemann/digital/core/Model.java b/src/main/java/de/neemann/digital/core/Model.java index 4dd710656..c181363b6 100644 --- a/src/main/java/de/neemann/digital/core/Model.java +++ b/src/main/java/de/neemann/digital/core/Model.java @@ -546,6 +546,7 @@ public class Model implements Iterable { return sigWithoutPinNumber; } + /** * A filter for nodes. * @@ -575,6 +576,21 @@ public class Model implements Iterable { nodes.remove(node); } + /** + * replaces a node by an other node + * + * @param oldNode old node + * @param newNode new node + * @throws NodeException NodeException + */ + public void replace(Node oldNode, Node newNode) throws NodeException { + int i = nodes.indexOf(oldNode); + if (i < 0) + throw new NodeException("node not found", oldNode, -1, null); + nodes.set(i, newNode); + } + + /** * Returns the input with the given name. * diff --git a/src/main/java/de/neemann/digital/core/flipflops/FlipflopJK.java b/src/main/java/de/neemann/digital/core/flipflops/FlipflopJK.java index a8d88854e..3b1997c03 100644 --- a/src/main/java/de/neemann/digital/core/flipflops/FlipflopJK.java +++ b/src/main/java/de/neemann/digital/core/flipflops/FlipflopJK.java @@ -27,7 +27,7 @@ public class FlipflopJK extends Node implements Element { .addAttribute(Keys.INVERTER_CONFIG) .addAttribute(Keys.VALUE_IS_PROBE); - private final Boolean isProbe; + private final boolean isProbe; private final String label; private ObservableValue jVal; private ObservableValue kVal; @@ -55,6 +55,23 @@ public class FlipflopJK extends Node implements Element { qn.setBool(!out); } + /** + * Creates a new instance + * + * @param label the label + * @param q the output + * @param qn the inverted output + */ + public FlipflopJK(String label, ObservableValue q, ObservableValue qn) { + super(true); + this.q = q; + this.qn = qn; + isProbe = false; + this.label = label; + q.setBool(false); + qn.setBool(true); + } + @Override public void readInputs() throws NodeException { boolean clock = clockVal.getBool(); diff --git a/src/main/java/de/neemann/digital/core/flipflops/FlipflopT.java b/src/main/java/de/neemann/digital/core/flipflops/FlipflopT.java index 1e18b466b..38b2e0e1e 100644 --- a/src/main/java/de/neemann/digital/core/flipflops/FlipflopT.java +++ b/src/main/java/de/neemann/digital/core/flipflops/FlipflopT.java @@ -111,6 +111,13 @@ public class FlipflopT extends Node implements Element { return clockVal; } + /** + * @return enable value or null if not available + */ + public ObservableValue getEnableVal() { + return enable; + } + /** * @return the label */ diff --git a/src/test/java/de/neemann/digital/analyse/ModelAnalyserTest.java b/src/test/java/de/neemann/digital/analyse/ModelAnalyserTest.java index 922586443..66977a02f 100644 --- a/src/test/java/de/neemann/digital/analyse/ModelAnalyserTest.java +++ b/src/test/java/de/neemann/digital/analyse/ModelAnalyserTest.java @@ -51,6 +51,12 @@ public class ModelAnalyserTest extends TestCase { check2BitCounter(tt); } + public void testAnalyzerTFFEnable() throws Exception { + Model model = new ToBreakRunner("dig/analyze/analyzeTestTFFEnable.dig", false).getModel(); + TruthTable tt = new ModelAnalyser(model).analyse(); + check2BitCounter(tt); + } + private void check2BitCounter(TruthTable tt) { assertEquals(4, tt.getRows()); assertEquals(4, tt.getCols()); diff --git a/src/test/resources/dig/analyze/analyzeTestTFF.dig b/src/test/resources/dig/analyze/analyzeTestTFF.dig index 3173d2a36..6339e4d6a 100644 --- a/src/test/resources/dig/analyze/analyzeTestTFF.dig +++ b/src/test/resources/dig/analyze/analyzeTestTFF.dig @@ -1,84 +1,86 @@ - 1 - - - JK_FF - - - Label - Q_1n - - - - 0 - - - Clock - - - 0 - - - T_FF - - - Label - Q_0n - - - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 1 + + + + JK_FF + + + Label + Q_1n + + + + + + Clock + + + + + T_FF + + + withEnable + false + + + Label + Q_0n + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/dig/analyze/analyzeTestTFFEnable.dig b/src/test/resources/dig/analyze/analyzeTestTFFEnable.dig new file mode 100644 index 000000000..294077f3d --- /dev/null +++ b/src/test/resources/dig/analyze/analyzeTestTFFEnable.dig @@ -0,0 +1,83 @@ + + + 1 + + + + Clock + + + + + T_FF + + + Label + Q_1n + + + + + + T_FF + + + Label + Q_0n + + + + + + VDD + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file