Input can have "high Z" as its default value

This commit is contained in:
hneemann 2017-06-19 19:34:54 +02:00
parent 513d9bf5f9
commit c705acc033
19 changed files with 259 additions and 94 deletions

View File

@ -3,6 +3,10 @@ Release Notes
planned as v0.13
- In case of oscillations almost all affected components are shown.
- If an error occurs, the name of the affected circuit file is shown.
- An input can have "high z" value as its default value.
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.
v0.12.1, released on 05. Jun 2016
- added a fuse to simulate a PROM or PAL.

View File

@ -213,6 +213,10 @@
<string>Default</string>
<int>1</int>
</entry>
<entry>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="200" y="660"/>
</visualElement>

View File

@ -543,6 +543,10 @@
<string>Default</string>
<int>1</int>
</entry>
<entry>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="200" y="660"/>
</visualElement>

View File

@ -283,6 +283,10 @@
<string>Default</string>
<int>1</int>
</entry>
<entry>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="200" y="660"/>
</visualElement>

View File

@ -44420,8 +44420,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-8260" y="-11300"/>
@ -44477,8 +44477,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-8500" y="-11300"/>
@ -44690,8 +44690,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-8260" y="-11540"/>
@ -44747,8 +44747,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-8500" y="-11540"/>
@ -47612,8 +47612,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-10900" y="-10580"/>
@ -47877,8 +47877,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-10900" y="-10820"/>
@ -49026,8 +49026,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-11380" y="-10820"/>
@ -49343,8 +49343,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-11620" y="-11060"/>
@ -49400,8 +49400,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-11860" y="-11060"/>
@ -50237,8 +50237,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-10900" y="-11780"/>
@ -50502,8 +50502,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-10900" y="-12020"/>
@ -50923,8 +50923,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-11620" y="-11300"/>
@ -50980,8 +50980,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-11860" y="-11300"/>
@ -51193,8 +51193,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-11620" y="-11540"/>
@ -51250,8 +51250,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-11860" y="-11540"/>
@ -51411,8 +51411,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-11380" y="-11780"/>
@ -52560,8 +52560,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-13060" y="-10340"/>
@ -52773,8 +52773,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-12820" y="-10580"/>
@ -52986,8 +52986,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-12580" y="-10820"/>
@ -53043,8 +53043,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-12820" y="-10820"/>
@ -53152,8 +53152,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-13300" y="-10820"/>
@ -53313,8 +53313,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-12820" y="-11060"/>
@ -53474,8 +53474,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-13540" y="-10100"/>
@ -53531,8 +53531,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-13780" y="-10100"/>
@ -53848,8 +53848,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-14020" y="-10340"/>
@ -54165,8 +54165,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-14260" y="-10580"/>
@ -54430,8 +54430,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-14260" y="-10820"/>
@ -54695,8 +54695,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-14260" y="-11060"/>
@ -54960,8 +54960,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-13060" y="-11300"/>
@ -56213,8 +56213,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-14020" y="-11300"/>
@ -56374,8 +56374,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-13540" y="-11540"/>
@ -56431,8 +56431,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-13780" y="-11540"/>
@ -59608,8 +59608,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-16420" y="-10820"/>
@ -59665,8 +59665,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-16660" y="-10820"/>
@ -59878,8 +59878,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-16420" y="-11060"/>
@ -59935,8 +59935,8 @@
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="-16660" y="-11060"/>

View File

@ -261,7 +261,7 @@ public class ObservableValue extends Observable implements PinDescription {
*
* @return the actual value.
*/
public long getValueIgnoreBurn() {
public long getValueIgnoreHighZ() {
return value;
}

View File

@ -1,6 +1,7 @@
package de.neemann.digital.core.element;
import de.neemann.digital.analyse.expression.format.FormatToExpression;
import de.neemann.digital.core.io.InValue;
import de.neemann.digital.core.io.IntFormat;
import de.neemann.digital.core.memory.DataField;
import de.neemann.digital.draw.model.InverterConfig;
@ -56,11 +57,17 @@ public final class Keys {
= new Key<>("Value", 1);
/**
* The default value of inputs
* The default value of elements
*/
public static final Key<Integer> DEFAULT
= new Key<>("Default", 0);
/**
* The default value of inputs
*/
public static final Key<InValue> INPUT_DEFAULT
= new Key<>("InDefault", new InValue(0));
/**
* Color of LEDs
*/

View File

@ -21,17 +21,17 @@ public class In implements Element {
@Override
public String getDescription(ElementAttributes elementAttributes) {
String d = elementAttributes.get(Keys.DESCRIPTION);
if (d.length()>0)
if (d.length() > 0)
return d;
else
return super.getDescription(elementAttributes);
}
}
.addAttribute(Keys.ROTATE)
.addAttribute(Keys.IS_HIGH_Z)
.addAttribute(Keys.BITS)
.addAttribute(Keys.LABEL)
.addAttribute(Keys.DEFAULT)
.addAttribute(Keys.INPUT_DEFAULT)
.addAttribute(Keys.IS_HIGH_Z)
.addAttribute(Keys.DESCRIPTION)
.addAttribute(Keys.PINNUMBER);
@ -45,10 +45,11 @@ public class In implements Element {
* @param attributes the inputs attributes
*/
public In(ElementAttributes attributes) {
boolean highZ = attributes.get(Keys.IS_HIGH_Z);
InValue value = attributes.get(Keys.INPUT_DEFAULT);
boolean highZ = attributes.get(Keys.IS_HIGH_Z) || value.isHighZ();
pinNumber = attributes.get(Keys.PINNUMBER);
output = new ObservableValue("out", attributes.get(Keys.BITS), highZ).setPinDescription(DESCRIPTION).setPinNumber(pinNumber);
output.setValue(attributes.get(Keys.DEFAULT));
output.set(value.getValue(), value.isHighZ());
label = attributes.getCleanLabel();
}

View File

@ -0,0 +1,106 @@
package de.neemann.digital.core.io;
import de.neemann.digital.core.ObservableValue;
/**
* A simple value.
* <p>
* Created by hneemann on 19.06.17.
*/
public class InValue {
private final long value;
private final boolean highZ;
/**
* Creates a new value
*
* @param value the value
*/
public InValue(long value) {
this.value = value;
this.highZ = false;
}
/**
* Creates a new value
*
* @param highZ ht ehigh z state
*/
public InValue(boolean highZ) {
this.value = 0;
this.highZ = true;
}
/**
* Creates a new value
*
* @param value the value
*/
public InValue(ObservableValue value) {
if (value.isHighZ()) {
this.highZ = true;
this.value = 0;
} else {
this.highZ = false;
this.value = value.getValueIgnoreHighZ();
}
}
/**
* Creates a new instance
*
* @param value the value a "Z" means "high z"
* @throws NumberFormatException NumberFormatException
*/
public InValue(String value) {
if (value.toLowerCase().trim().equalsIgnoreCase("z")) {
this.highZ = true;
this.value = 0;
} else {
this.highZ = false;
this.value = Long.decode(value.trim());
}
}
/**
* @return the value
*/
public long getValue() {
return value;
}
/**
* @return High Z State
*/
public boolean isHighZ() {
return highZ;
}
@Override
public String toString() {
if (highZ)
return "Z";
else
return Long.toString(value);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
InValue inValue = (InValue) o;
if (value != inValue.value) return false;
return highZ == inValue.highZ;
}
@Override
public int hashCode() {
int result = (int) (value ^ (value >>> 32));
result = 31 * result + (highZ ? 1 : 0);
return result;
}
}

View File

@ -11,6 +11,7 @@ import de.neemann.digital.core.element.Keys;
import de.neemann.digital.core.element.PinDescription;
import de.neemann.digital.core.element.Rotation;
import de.neemann.digital.core.io.In;
import de.neemann.digital.core.io.InValue;
import de.neemann.digital.core.io.IntFormat;
import de.neemann.digital.core.io.Out;
import de.neemann.digital.core.memory.DataField;
@ -74,6 +75,9 @@ public class Circuit {
xStream.alias("vector", Vector.class);
xStream.aliasAttribute(Vector.class, "x", "x");
xStream.aliasAttribute(Vector.class, "y", "y");
xStream.alias("value", InValue.class);
xStream.aliasAttribute(InValue.class, "value", "v");
xStream.aliasAttribute(InValue.class, "highZ", "z");
xStream.addImplicitCollection(ElementAttributes.class, "attributes");
xStream.alias("data", DataField.class);
xStream.registerConverter(new DataFieldConverter());

View File

@ -186,10 +186,10 @@ public class Style {
*/
public static Style getWireStyle(ObservableValue value) {
if (value == null) return WIRE;
if (value.getBits() > 1) return WIRE_BUS;
if (value.isHighZ()) return WIRE_HIGHZ;
if (value.getBits() > 1) return WIRE_BUS;
if (value.getValueIgnoreBurn() == 1) return WIRE_HIGH;
if (value.getValueIgnoreHighZ() == 1) return WIRE_HIGH;
else return WIRE_LOW;
}

View File

@ -43,7 +43,7 @@ public class SevenSegHexShape extends SevenShape {
if (i == 7) {
return dp.getBool();
} else {
int v = (int) input.getValueIgnoreBurn() & 0xf;
int v = (int) input.getValueIgnoreHighZ() & 0xf;
v = TABLE[v];
return (v & (1 << i)) != 0;
}

View File

@ -89,13 +89,13 @@ public class SevenSegShape extends SevenShape {
if (persistence && commonCatode) {
if (!ccin.isHighZ() && !ccin.getBool())
data[i] = inputs.get(i).getValueIgnoreBurn() > 0;
data[i] = inputs.get(i).getValueIgnoreHighZ() > 0;
return data[i];
} else {
if (commonCatode && (ccin.isHighZ() || ccin.getBool()))
return false;
return inputs.get(i).getValueIgnoreBurn() > 0;
return inputs.get(i).getValueIgnoreHighZ() > 0;
}
}

View File

@ -5,6 +5,7 @@ import de.neemann.digital.core.ObservableValue;
import de.neemann.digital.core.Observer;
import de.neemann.digital.core.element.*;
import de.neemann.digital.core.io.In;
import de.neemann.digital.core.io.InValue;
import de.neemann.digital.draw.elements.*;
import de.neemann.digital.draw.shapes.InputShape;
import de.neemann.digital.gui.components.modification.*;
@ -911,10 +912,10 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
if (ve.equalsDescription(In.DESCRIPTION)) {
ObservableValue ov = ((InputShape) ve.getShape()).getObservableValue();
if (ov != null) {
int newValue = (int) ov.getValue();
int oldValue = ve.getElementAttributes().get(Keys.DEFAULT);
if (newValue != oldValue)
builder.add(new ModifyAttribute<>(ve, Keys.DEFAULT, newValue));
InValue newValue = new InValue(ov);
InValue oldValue = ve.getElementAttributes().get(Keys.INPUT_DEFAULT);
if (!newValue.equals(oldValue))
builder.add(new ModifyAttribute<>(ve, Keys.INPUT_DEFAULT, newValue));
}
}
modify(builder.build());

View File

@ -3,6 +3,7 @@ package de.neemann.digital.gui.components;
import de.neemann.digital.analyse.expression.format.FormatToExpression;
import de.neemann.digital.core.NodeException;
import de.neemann.digital.core.element.*;
import de.neemann.digital.core.io.InValue;
import de.neemann.digital.core.io.IntFormat;
import de.neemann.digital.core.memory.DataField;
import de.neemann.digital.core.memory.ROM;
@ -44,6 +45,7 @@ public final class EditorFactory {
private EditorFactory() {
add(String.class, StringEditor.class);
add(Integer.class, IntegerEditor.class);
add(InValue.class, InValueEditor.class);
add(File.class, FileEditor.class);
add(Color.class, ColorEditor.class);
add(Boolean.class, BooleanEditor.class);
@ -209,6 +211,28 @@ public final class EditorFactory {
}
}
private final static class InValueEditor extends LabelEditor<InValue> {
private static final String[] DEFAULTS = {"Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"};
private final JComboBox<String> comboBox;
public InValueEditor(InValue value, Key<Integer> key) {
comboBox = new JComboBox<>(DEFAULTS);
comboBox.setEditable(true);
comboBox.setSelectedItem(value.toString());
}
@Override
public JComponent getComponent(ElementAttributes attr) {
return comboBox;
}
@Override
public InValue getValue() {
Object item = comboBox.getSelectedItem();
return new InValue(item.toString());
}
}
private final static class BooleanEditor implements Editor<Boolean> {
private final JCheckBox bool;

View File

@ -73,7 +73,7 @@ public class DataSample {
*/
public DataSample fillWith(ArrayList<Signal> signals) {
for (int i = 0; i < signals.size(); i++)
values[i] = signals.get(i).getValue().getValueIgnoreBurn();
values[i] = signals.get(i).getValue().getValueIgnoreHighZ();
return this;
}

View File

@ -555,6 +555,11 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
<string name="key_Data_tt">Die Daten, welche in diesem Element gespeichert sind.</string>
<string name="key_Default">Vorgabe</string>
<string name="key_Default_tt">Dieser Wert wird beim Schaltungsstart gesetzt</string>
<string name="key_InDefault">Vorgabe</string>
<string name="key_InDefault_tt">Dieser Wert wird beim Schaltungsstart gesetzt. Ein "Z" steht für "hochohmig".</string>
<string name="key_isHighZ">Eingang kann hochohmig sein</string>
<string name="key_isHighZ_tt">Wenn gesetzt ist ein hochohmiger Eingang erlaubt. Ein hochohmiger Eingang ist auch
erlaubt, wenn der Vorgabewert auf hochohmig ("Z") gesetzt wird.</string>
<string name="key_Description">Beschreibung</string>
<string name="key_Description_tt">Eine kurze Beschreibung des Elementes.</string>
<string name="key_Frequency">Frequenz/Hz</string>
@ -601,8 +606,6 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
<string name="key_intFormat_dec">Dezimal</string>
<string name="key_intFormat_def">Vorgabe</string>
<string name="key_intFormat_hex">Hexadezimal</string>
<string name="key_isHighZ">Eingang kann hochohmig sein</string>
<string name="key_isHighZ_tt">Wenn gesetzt ist ein hochohmiger Eingang erlaubt.</string>
<string name="key_maxStepCount">Maximale Messpunktezahl</string>
<string name="key_maxStepCount_tt">Die maximale Anzahl an Messpunkten die gespeichert werden, bevor die ältesten Messungen verworfen werden.</string>
<string name="key_microStep">Zeige Einzelgatterschritte</string>

View File

@ -545,6 +545,11 @@ The names of the variables may not be unique.</string>
<string name="key_Data_tt">The values stored in this element.</string>
<string name="key_Default">Default</string>
<string name="key_Default_tt">This value is set if the circuit is started</string>
<string name="key_InDefault">Default</string>
<string name="key_InDefault_tt">This value is set if the circuit is started. A "Z" means high-z state.</string>
<string name="key_isHighZ">Is three-state input</string>
<string name="key_isHighZ_tt">If set the input is allowed to be in high-z state. This is also allowed
if high-z ("Z") is set as the default value.</string>
<string name="key_Description">Description</string>
<string name="key_Description_tt">A short description of this element and its usage.</string>
<string name="key_Frequency">Frequency/Hz</string>
@ -591,8 +596,6 @@ The names of the variables may not be unique.</string>
<string name="key_intFormat_dec">decimal</string>
<string name="key_intFormat_def">default</string>
<string name="key_intFormat_hex">hex</string>
<string name="key_isHighZ">Is three-state input</string>
<string name="key_isHighZ_tt">If set the input is allowed to be in high-z state.</string>
<string name="key_maxStepCount">Max number of steps to show</string>
<string name="key_maxStepCount_tt">The maximal number of values stored. If the maximum number is reached, the oldest values are discarded.</string>
<string name="key_microStep">Show single gate steps</string>

View File

@ -23,7 +23,7 @@ public class FileScanner {
if (errors.isEmpty())
return count;
System.out.println("errors:");
System.err.println("errors:");
for (Error e : errors) {
System.err.println("----> error in: " + e.f);
e.e.printStackTrace();