mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-26 06:22:48 -04:00
analysis of flipflops without a label is allowed now.
This commit is contained in:
parent
6ed91b59cb
commit
5350361884
@ -33,6 +33,7 @@ public class ModelAnalyser {
|
|||||||
private final ArrayList<Signal> inputs;
|
private final ArrayList<Signal> inputs;
|
||||||
private final ArrayList<Signal> outputs;
|
private final ArrayList<Signal> outputs;
|
||||||
private final int rows;
|
private final int rows;
|
||||||
|
private int uniqueIndex = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance
|
* Creates a new instance
|
||||||
@ -69,7 +70,7 @@ public class ModelAnalyser {
|
|||||||
ff.getDInput().removeObserver(ff); // turn off flipflop
|
ff.getDInput().removeObserver(ff); // turn off flipflop
|
||||||
String label = ff.getLabel();
|
String label = ff.getLabel();
|
||||||
if (label.length() == 0)
|
if (label.length() == 0)
|
||||||
throw new AnalyseException(Lang.get("err_DFlipflopWithoutALabel"));
|
label = createUniqueName(ff);
|
||||||
|
|
||||||
if (!label.endsWith("n"))
|
if (!label.endsWith("n"))
|
||||||
label += "n";
|
label += "n";
|
||||||
@ -95,6 +96,21 @@ public class ModelAnalyser {
|
|||||||
rows = 1 << inputs.size();
|
rows = 1 << inputs.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String createUniqueName(FlipflopD ff) {
|
||||||
|
ObservableValue q = ff.getOutputs().get(0);
|
||||||
|
for (Signal o : outputs) {
|
||||||
|
if (o.getValue() == q)
|
||||||
|
return o.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
String name;
|
||||||
|
do {
|
||||||
|
name = "Z" + uniqueIndex;
|
||||||
|
uniqueIndex++;
|
||||||
|
} while (inputs.contains(new Signal(name, null)));
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
private void checkUnique(ArrayList<Signal> signals) throws AnalyseException {
|
private void checkUnique(ArrayList<Signal> signals) throws AnalyseException {
|
||||||
for (int i = 0; i < signals.size() - 1; i++)
|
for (int i = 0; i < signals.size() - 1; i++)
|
||||||
for (int j = i + 1; j < signals.size(); j++)
|
for (int j = i + 1; j < signals.size(); j++)
|
||||||
@ -127,31 +143,35 @@ public class ModelAnalyser {
|
|||||||
|
|
||||||
Splitter insp = Splitter.createOneToN(ff.getBits());
|
Splitter insp = Splitter.createOneToN(ff.getBits());
|
||||||
insp.setInputs(new ObservableValues(ff.getDInput()));
|
insp.setInputs(new ObservableValues(ff.getDInput()));
|
||||||
|
ff.getDInput().fireHasChanged();
|
||||||
|
|
||||||
Splitter outsp = Splitter.createNToOne(ff.getBits());
|
Splitter outsp = Splitter.createNToOne(ff.getBits());
|
||||||
Splitter noutsp = Splitter.createNToOne(ff.getBits());
|
|
||||||
|
|
||||||
|
|
||||||
ObservableValues.Builder spinput = new ObservableValues.Builder();
|
ObservableValues.Builder spinput = new ObservableValues.Builder();
|
||||||
ObservableValues.Builder spninput = new ObservableValues.Builder();
|
String label = ff.getLabel();
|
||||||
|
if (label.length() == 0)
|
||||||
|
label = createUniqueName(ff);
|
||||||
for (int i = 0; i < ff.getBits(); i++) {
|
for (int i = 0; i < ff.getBits(); i++) {
|
||||||
ObservableValue qn = new ObservableValue("", 1);
|
ObservableValue qn = new ObservableValue("", 1);
|
||||||
ObservableValue nqn = new ObservableValue("", 1);
|
ObservableValue nqn = new ObservableValue("", 1);
|
||||||
FlipflopD newff = new FlipflopD(ff.getLabel() + i, qn, nqn);
|
FlipflopD newff = new FlipflopD(label + i, qn, nqn);
|
||||||
spinput.add(qn);
|
spinput.add(qn);
|
||||||
spninput.add(nqn);
|
|
||||||
newff.setInputs(new ObservableValues(insp.getOutputs().get(i), getClock()));
|
|
||||||
model.add(newff);
|
model.add(newff);
|
||||||
|
newff.setInputs(new ObservableValues(insp.getOutputs().get(i), getClock()));
|
||||||
out.add(newff);
|
out.add(newff);
|
||||||
}
|
}
|
||||||
outsp.setInputs(spinput.build());
|
outsp.setInputs(spinput.build());
|
||||||
noutsp.setInputs(spninput.build());
|
for (ObservableValue v : spinput)
|
||||||
|
v.fireHasChanged();
|
||||||
|
|
||||||
final FlipflopD oldff = ff;
|
final ObservableValue qout = ff.getOutputs().get(0);
|
||||||
|
final ObservableValue nqout = ff.getOutputs().get(1);
|
||||||
ObservableValue spq = outsp.getOutputs().get(0);
|
ObservableValue spq = outsp.getOutputs().get(0);
|
||||||
spq.addObserver(() -> oldff.getOutputs().get(0).setValue(spq.getValue()));
|
spq.addObserver(() -> {
|
||||||
ObservableValue spnq = noutsp.getOutputs().get(0);
|
final long value = spq.getValue();
|
||||||
spnq.addObserver(() -> oldff.getOutputs().get(1).setValue(spnq.getValue()));
|
qout.setValue(value);
|
||||||
|
nqout.setValue(~value);
|
||||||
|
});
|
||||||
|
|
||||||
} catch (NodeException e) {
|
} catch (NodeException e) {
|
||||||
throw new AnalyseException(e);
|
throw new AnalyseException(e);
|
||||||
|
@ -5,6 +5,7 @@ import de.neemann.digital.core.element.ImmutableList;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
@ -14,7 +15,7 @@ public class ObservableValues extends ImmutableList<ObservableValue> {
|
|||||||
/**
|
/**
|
||||||
* Builder for ObservableValues
|
* Builder for ObservableValues
|
||||||
*/
|
*/
|
||||||
public static class Builder {
|
public static class Builder implements Iterable<ObservableValue> {
|
||||||
private ArrayList<ObservableValue> values;
|
private ArrayList<ObservableValue> values;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,6 +53,11 @@ public class ObservableValues extends ImmutableList<ObservableValue> {
|
|||||||
public ObservableValues build() {
|
public ObservableValues build() {
|
||||||
return new ObservableValues(values);
|
return new ObservableValues(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<ObservableValue> iterator() {
|
||||||
|
return values.iterator();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -432,7 +432,6 @@ Die gesammte Speichergröße beträgt damit damit dx*dy*2 Speicherworte.</string
|
|||||||
<string name="elem_TransGate_pin_~S">Steuereingang, invertiert</string>
|
<string name="elem_TransGate_pin_~S">Steuereingang, invertiert</string>
|
||||||
|
|
||||||
<string name="error">Fehler</string>
|
<string name="error">Fehler</string>
|
||||||
<string name="err_DFlipflopWithoutALabel">Flipflop hat keine Bezeichnung!</string>
|
|
||||||
<string name="err_N_isNotInputOrOutput">Pin {0} in Element {1} ist werder Eingang noch Ausgang</string>
|
<string name="err_N_isNotInputOrOutput">Pin {0} in Element {1} ist werder Eingang noch Ausgang</string>
|
||||||
<string name="err_aSingleClockNecessary">Es muss genau ein Taktelement geben. Alle Flipflops müssen an diesem Takt hängen.</string>
|
<string name="err_aSingleClockNecessary">Es muss genau ein Taktelement geben. Alle Flipflops müssen an diesem Takt hängen.</string>
|
||||||
<string name="err_analyseNoInputs">Die Schaltung hat keine benannten Eingänge</string>
|
<string name="err_analyseNoInputs">Die Schaltung hat keine benannten Eingänge</string>
|
||||||
|
@ -422,7 +422,6 @@
|
|||||||
<string name="elem_TransGate_pin_~S">inverted control input</string>
|
<string name="elem_TransGate_pin_~S">inverted control input</string>
|
||||||
|
|
||||||
<string name="error">Error</string>
|
<string name="error">Error</string>
|
||||||
<string name="err_DFlipflopWithoutALabel">D-flip-flop has no label set</string>
|
|
||||||
<string name="err_N_isNotInputOrOutput">Pin {0} in component {1} is not a input or output</string>
|
<string name="err_N_isNotInputOrOutput">Pin {0} in component {1} is not a input or output</string>
|
||||||
<string name="err_aSingleClockNecessary">A single clock component is necessary. All flip-flops must use this clock signal.</string>
|
<string name="err_aSingleClockNecessary">A single clock component is necessary. All flip-flops must use this clock signal.</string>
|
||||||
<string name="err_analyseNoInputs">The circuit has no Inputs</string>
|
<string name="err_analyseNoInputs">The circuit has no Inputs</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user