Search in sources :

Example 16 with Model

use of de.neemann.digital.core.Model in project Digital by hneemann.

the class LUTTest method testLut.

public void testLut() throws Exception {
    ObservableValue a = new ObservableValue("a", 1);
    ObservableValue b = new ObservableValue("b", 1);
    ObservableValue c = new ObservableValue("c", 1);
    Model model = new Model();
    DataField data = new DataField(8);
    data.setData(3, 1);
    data.setData(7, 1);
    LookUpTable out = model.add(new LookUpTable(new ElementAttributes().setBits(1).set(Keys.DATA, data)));
    out.setInputs(ovs(a, b));
    TestExecuter sc = new TestExecuter(model).setInputs(a, b, c).setOutputs(out.getOutputs());
    sc.check(0, 0, 0, 0);
    sc.check(1, 0, 0, 0);
    sc.check(0, 1, 0, 0);
    sc.check(1, 1, 0, 1);
    sc.check(0, 0, 1, 0);
    sc.check(1, 0, 1, 0);
    sc.check(0, 1, 1, 0);
    sc.check(1, 1, 1, 1);
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 17 with Model

use of de.neemann.digital.core.Model in project Digital by hneemann.

the class ROMTest method testROM.

public void testROM() throws Exception {
    ObservableValue addr = new ObservableValue("addr", 3);
    ObservableValue sel = new ObservableValue("sel", 1);
    Model model = new Model();
    DataField data = new DataField(8);
    data.setData(3, 17);
    data.setData(7, 200);
    ROM out = model.add(new ROM(new ElementAttributes().setBits(8).set(Keys.ADDR_BITS, 3).set(Keys.DATA, data)));
    out.setInputs(ovs(addr, sel));
    TestExecuter sc = new TestExecuter(model).setInputs(addr, sel).setOutputs(out.getOutputs());
    sc.check(0, 1, 0);
    sc.check(1, 1, 0);
    sc.check(2, 1, 0);
    sc.check(3, 1, 17);
    sc.check(4, 1, 0);
    sc.check(5, 1, 0);
    sc.check(6, 1, 0);
// try {  ToDo HighZ
// sc.check(6, 0, 0);
// assertTrue(false);
// } catch (HighZException e) {
// assertTrue(true);
// }
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 18 with Model

use of de.neemann.digital.core.Model in project Digital by hneemann.

the class RegisterFileTest method testRegisterFile.

public void testRegisterFile() throws Exception {
    ObservableValue ra = new ObservableValue("ra", 2);
    ObservableValue rb = new ObservableValue("rb", 2);
    ObservableValue rw = new ObservableValue("rw", 2);
    ObservableValue in = new ObservableValue("in", 4);
    ObservableValue we = new ObservableValue("we", 1);
    ObservableValue clk = new ObservableValue("clk", 1);
    Model model = new Model();
    RegisterFile out = model.add(new RegisterFile(new ElementAttributes().set(Keys.ADDR_BITS, 2).setBits(4)));
    out.setInputs(ovs(in, we, rw, clk, ra, rb));
    TestExecuter sc = new TestExecuter(model).setInputs(clk, in, we, rw, ra, rb).setOutputs(out.getOutputs());
    // c  in we rw ra rb da db
    sc.check(0, 0, 0, 0, 0, 0, 0, 0);
    sc.check(1, 7, 1, 1, 0, 0, 0, 0);
    sc.check(0, 0, 0, 0, 1, 1, 7, 7);
    sc.check(1, 5, 1, 2, 1, 1, 7, 7);
    sc.check(0, 0, 0, 0, 1, 2, 7, 5);
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 19 with Model

use of de.neemann.digital.core.Model in project Digital by hneemann.

the class BitSelectorTest method testBitSel.

public void testBitSel() throws Exception {
    Model model = new Model();
    ObservableValue d = new ObservableValue("d", 4);
    ObservableValue sel = new ObservableValue("sel", 2);
    BitSelector out = model.add(new BitSelector(new ElementAttributes().set(Keys.SELECTOR_BITS, 2)));
    out.setInputs(ovs(d, sel));
    TestExecuter te = new TestExecuter(model).setInputs(d, sel).setOutputs(out.getOutputs());
    te.check(5, 0, 1);
    te.check(5, 1, 0);
    te.check(5, 2, 1);
    te.check(5, 3, 0);
    te.check(10, 0, 0);
    te.check(10, 1, 1);
    te.check(10, 2, 0);
    te.check(10, 3, 1);
}
Also used : Model(de.neemann.digital.core.Model) ObservableValue(de.neemann.digital.core.ObservableValue) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 20 with Model

use of de.neemann.digital.core.Model 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)

Aggregations

Model (de.neemann.digital.core.Model)85 ObservableValue (de.neemann.digital.core.ObservableValue)56 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)52 TestExecuter (de.neemann.digital.TestExecuter)49 ToBreakRunner (de.neemann.digital.integration.ToBreakRunner)16 ValueTable (de.neemann.digital.data.ValueTable)6 Signal (de.neemann.digital.core.Signal)4 ModelCreator (de.neemann.digital.draw.model.ModelCreator)4 ObservableValues (de.neemann.digital.core.ObservableValues)3 Expression (de.neemann.digital.analyse.expression.Expression)2 BoolTable (de.neemann.digital.analyse.quinemc.BoolTable)2 Node (de.neemann.digital.core.Node)2 Delay (de.neemann.digital.core.wiring.Delay)2 Circuit (de.neemann.digital.draw.elements.Circuit)2 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)2 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Variable (de.neemann.digital.analyse.expression.Variable)1 Parser (de.neemann.digital.analyse.parser.Parser)1