mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-13 23:06:22 -04:00
first version of a splitter
This commit is contained in:
parent
ed6a2f6a16
commit
b9c5f6fd35
@ -1,42 +0,0 @@
|
|||||||
package de.neemann.digital.core.wiring;
|
|
||||||
|
|
||||||
import de.neemann.digital.core.BurnException;
|
|
||||||
import de.neemann.digital.core.NodeException;
|
|
||||||
import de.neemann.digital.core.ObservableValue;
|
|
||||||
import de.neemann.digital.core.Value;
|
|
||||||
import de.neemann.digital.core.basic.FanIn;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hneemann
|
|
||||||
*/
|
|
||||||
public class Bus extends FanIn {
|
|
||||||
|
|
||||||
private Value value;
|
|
||||||
|
|
||||||
public Bus(int bits) {
|
|
||||||
super(bits);
|
|
||||||
value = new Value(bits);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readInputs() throws NodeException {
|
|
||||||
ObservableValue found = null;
|
|
||||||
for (ObservableValue in : inputs) {
|
|
||||||
if (!in.isHighZ()) {
|
|
||||||
if (found != null)
|
|
||||||
throw new BurnException(in, found);
|
|
||||||
found = in;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found == null) {
|
|
||||||
value.set(0, true);
|
|
||||||
} else {
|
|
||||||
value.set(found.getValue(), false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeOutputs() throws NodeException {
|
|
||||||
output.set(value);
|
|
||||||
}
|
|
||||||
}
|
|
@ -59,7 +59,7 @@ public class Splitter implements Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Observer createObserverForInput(int i) throws NodeException {
|
private Observer createObserverForInput(int i) throws NodeException {
|
||||||
Observer observer = outPorts.getSimpleTargetObserver(inPorts.getPort(i), inputs, outputs);
|
Observer observer = outPorts.getSingleTargetObserver(inPorts.getPort(i), inputs, outputs);
|
||||||
if (observer == null)
|
if (observer == null)
|
||||||
throw new NodeException("splitterMismatchError");
|
throw new NodeException("splitterMismatchError");
|
||||||
return observer;
|
return observer;
|
||||||
@ -126,7 +126,7 @@ public class Splitter implements Element {
|
|||||||
* @param inputs
|
* @param inputs
|
||||||
* @param outputs
|
* @param outputs
|
||||||
*/
|
*/
|
||||||
public Observer getSimpleTargetObserver(Port inPort, ObservableValue[] inputs, ObservableValue[] outputs) {
|
public Observer getSingleTargetObserver(Port inPort, ObservableValue[] inputs, ObservableValue[] outputs) {
|
||||||
int pos = inPort.getPos();
|
int pos = inPort.getPos();
|
||||||
int bits = inPort.getBits();
|
int bits = inPort.getBits();
|
||||||
|
|
||||||
|
@ -1,50 +0,0 @@
|
|||||||
package de.neemann.digital.core.wiring;
|
|
||||||
|
|
||||||
import de.neemann.digital.TestExecuter;
|
|
||||||
import de.neemann.digital.core.BurnException;
|
|
||||||
import de.neemann.digital.core.Model;
|
|
||||||
import de.neemann.digital.core.ObservableValue;
|
|
||||||
import de.neemann.digital.core.basic.FanIn;
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hneemann
|
|
||||||
*/
|
|
||||||
public class BusTest extends TestCase {
|
|
||||||
|
|
||||||
public void testBus() throws Exception {
|
|
||||||
Model model = new Model();
|
|
||||||
ObservableValue a = new ObservableValue("a", 1, true);
|
|
||||||
ObservableValue b = new ObservableValue("b", 1);
|
|
||||||
FanIn out = model.add(new Bus(1));
|
|
||||||
out.setInputs(a, b);
|
|
||||||
|
|
||||||
|
|
||||||
TestExecuter te = new TestExecuter(model).setInputs(a, b).setOutputs(out.getOutputs());
|
|
||||||
te.check(0, 0, 0);
|
|
||||||
te.check(0, 1, 1);
|
|
||||||
a.setHighZ(false);
|
|
||||||
b.setHighZ(true);
|
|
||||||
te.check(0, 1, 0);
|
|
||||||
te.check(1, 0, 1);
|
|
||||||
a.setHighZ(false);
|
|
||||||
b.setHighZ(false);
|
|
||||||
try {
|
|
||||||
te.check(0, 0, 0);
|
|
||||||
assertTrue(false);
|
|
||||||
} catch (BurnException e) {
|
|
||||||
assertTrue(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBusHighZ() throws Exception {
|
|
||||||
Model model = new Model();
|
|
||||||
ObservableValue a = new ObservableValue("a", 1, true);
|
|
||||||
ObservableValue b = new ObservableValue("b", 1, true);
|
|
||||||
FanIn out = model.add(new Bus(1));
|
|
||||||
out.setInputs(a, b);
|
|
||||||
|
|
||||||
TestExecuter te = new TestExecuter(model).setInputs(a, b).setOutputs(out.getOutputs());
|
|
||||||
assertTrue(out.getOutput().isHighZ());
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user