use of de.neemann.digital.core.flipflops.FlipflopD in project Digital by hneemann.
the class ModelAnalyser method replaceMultiBitFlipflops.
private List<FlipflopD> replaceMultiBitFlipflops(List<FlipflopD> flipflops) throws AnalyseException {
ArrayList<FlipflopD> out = new ArrayList<>();
for (FlipflopD ff : flipflops) {
if (ff.getBits() == 1)
out.add(ff);
else {
try {
model.removeNode(ff);
ff.getDInput().removeObserver(ff);
ff.getClock().removeObserver(ff);
Splitter insp = Splitter.createOneToN(ff.getBits());
insp.setInputs(new ObservableValues(ff.getDInput()));
ff.getDInput().fireHasChanged();
Splitter outsp = Splitter.createNToOne(ff.getBits());
ObservableValues.Builder spinput = new ObservableValues.Builder();
String label = ff.getLabel();
if (label.length() == 0)
label = createUniqueName(ff);
for (int i = ff.getBits() - 1; i >= 0; i--) {
ObservableValue qn = new ObservableValue("", 1);
ObservableValue nqn = new ObservableValue("", 1);
FlipflopD newff = new FlipflopD(label + i, qn, nqn);
spinput.addAtTop(qn);
model.add(newff);
newff.setInputs(new ObservableValues(insp.getOutputs().get(i), getClock()));
out.add(newff);
}
outsp.setInputs(spinput.build());
for (ObservableValue v : spinput) v.fireHasChanged();
final ObservableValue qout = ff.getOutputs().get(0);
final ObservableValue nqout = ff.getOutputs().get(1);
ObservableValue spq = outsp.getOutputs().get(0);
spq.addObserver(new NodeWithoutDelay(qout, nqout) {
@Override
public void hasChanged() {
final long value = spq.getValue();
qout.setValue(value);
nqout.setValue(~value);
}
});
spq.fireHasChanged();
} catch (NodeException e) {
throw new AnalyseException(e);
}
}
}
return out;
}
use of de.neemann.digital.core.flipflops.FlipflopD in project Digital by hneemann.
the class ModelAnalyser method replaceJKFF.
private void replaceJKFF() throws NodeException, AnalyseException {
List<FlipflopJK> jkList = model.findNode(FlipflopJK.class);
for (FlipflopJK jk : jkList) {
checkClock(jk);
jk.getClockVal().removeObserver(jk);
jk.getjVal().removeObserver(jk);
jk.getkVal().removeObserver(jk);
// create d ff
ObservableValue q = jk.getOutputs().get(0);
ObservableValue qn = jk.getOutputs().get(1);
FlipflopD d = new FlipflopD(jk.getLabel(), q, qn);
And a1 = new And(new ElementAttributes());
a1.setInputs(new ObservableValues(jk.getjVal(), qn));
And a2 = new And(new ElementAttributes());
Not nk = new Not(new ElementAttributes());
nk.setInputs(jk.getkVal().asList());
a2.setInputs(new ObservableValues(nk.getOutput(), q));
Or or = new Or(new ElementAttributes());
or.setInputs(new ObservableValues(a1.getOutput(), a2.getOutput()));
d.setInputs(new ObservableValues(or.getOutputs().get(0), jk.getClockVal()));
model.add(a1);
model.add(a2);
model.add(nk);
model.add(or);
model.replace(jk, d);
}
}
use of de.neemann.digital.core.flipflops.FlipflopD in project Digital by hneemann.
the class ModelAnalyser method replaceTFF.
private void replaceTFF() throws NodeException, AnalyseException {
List<FlipflopT> tList = model.findNode(FlipflopT.class);
for (FlipflopT tff : tList) {
checkClock(tff);
tff.getClockVal().removeObserver(tff);
ObservableValue q = tff.getOutputs().get(0);
ObservableValue qn = tff.getOutputs().get(1);
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);
}
}
}
Aggregations