use of de.neemann.digital.core.wiring.bus.DataBus in project Digital by hneemann.
the class DataBusTest method testSimple.
public void testSimple() throws PinException, NodeException {
ObservableValue a = new ObservableValue("a", 4).setToHighZ();
ObservableValue b = new ObservableValue("b", 4).setToHighZ();
Model m = new Model();
ObservableValue out = new DataBus(null, m, a, b).getReadableOutput();
a.setValue(1);
assertEquals(1, out.getValue());
a.setToHighZ();
b.setValue(2);
assertEquals(2, out.getValue());
b.setToHighZ();
// try { ToDo HighZ
// out.getValue();
// assertTrue(false);
// } catch (HighZException e) {
// assertTrue(true);
// }
a.setValue(1);
b.setValue(1);
m.doStep();
a.setValue(0);
b.setValue(0);
m.doStep();
a.setValue(1);
b.setValue(0);
try {
m.doStep();
assertTrue(true);
} catch (BurnException e) {
assertTrue(true);
}
}
use of de.neemann.digital.core.wiring.bus.DataBus in project Digital by hneemann.
the class Net method interconnect.
/**
* Do the interconnection.
* All inputs and outputs in the net are connected together.
* If there is no output an exception is thrown.
* If there is one single output, all input {@link ObservableValue}s are set to this output
* If there are more then one output a {@link DataBus} is created.
* <p>
* At the end all wires get a reference to the {@link ObservableValue} the represent
*
* @param m the model is needed to create the {@link DataBus}
* @param attachWires if true, the values are attached to the wires
* @throws PinException PinException
*/
public void interconnect(Model m, boolean attachWires) throws PinException {
ArrayList<Pin> inputs = new ArrayList<>();
ArrayList<Pin> outputs = new ArrayList<>();
for (Pin p : pins) {
if (p.getDirection() == Pin.Direction.input)
inputs.add(p);
else
outputs.add(p);
}
if (outputs.size() == 0)
throw new PinException(Lang.get("err_noOutConnectedToWire", this.toString()), this);
ObservableValue value = null;
if (outputs.size() == 1 && outputs.get(0).getPullResistor() == PinDescription.PullResistor.none) {
value = outputs.get(0).getValue();
} else {
value = new DataBus(this, m, outputs).getReadableOutput();
}
if (value == null)
throw new PinException(Lang.get("err_output_N_notDefined", outputs.get(0)), this);
for (Pin i : inputs) i.setValue(value);
for (// set also the reader for bidirectional pins
Pin o : // set also the reader for bidirectional pins
outputs) o.setReaderValue(value);
if (wires != null && attachWires)
for (Wire w : wires) w.setValue(value);
}
Aggregations