Search in sources :

Example 1 with DataBus

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);
    }
}
Also used : BurnException(de.neemann.digital.core.BurnException) ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) DataBus(de.neemann.digital.core.wiring.bus.DataBus)

Example 2 with DataBus

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);
}
Also used : Pin(de.neemann.digital.draw.elements.Pin) ArrayList(java.util.ArrayList) ObservableValue(de.neemann.digital.core.ObservableValue) PinException(de.neemann.digital.draw.elements.PinException) DataBus(de.neemann.digital.core.wiring.bus.DataBus) Wire(de.neemann.digital.draw.elements.Wire)

Aggregations

ObservableValue (de.neemann.digital.core.ObservableValue)2 DataBus (de.neemann.digital.core.wiring.bus.DataBus)2 BurnException (de.neemann.digital.core.BurnException)1 Model (de.neemann.digital.core.Model)1 Pin (de.neemann.digital.draw.elements.Pin)1 PinException (de.neemann.digital.draw.elements.PinException)1 Wire (de.neemann.digital.draw.elements.Wire)1 ArrayList (java.util.ArrayList)1