Search in sources :

Example 1 with NodeException

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

the class Monoflop method init.

@Override
public void init(Model model) throws NodeException {
    ArrayList<Clock> clockList = model.getClocks();
    if (clockList.size() != 1)
        throw new NodeException(Lang.get("err_monoflopRequiresOneClock"));
    final ObservableValue clock = clockList.get(0).getClockOutput();
    clock.addObserver(() -> {
        if (clock.getBool()) {
            if (counter > 0) {
                counter--;
                if (counter == 0) {
                    setOut(false);
                    Monoflop.this.hasChanged();
                }
            }
        }
    });
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) NodeException(de.neemann.digital.core.NodeException) Clock(de.neemann.digital.core.wiring.Clock)

Example 2 with NodeException

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

the class HDLModel method createNode.

/**
 * Creates a isolated node
 *
 * @param v      the VisualElement of the node
 * @param parent the parrents circuit
 * @return the node
 * @throws HDLException HDLException
 */
public HDLNode createNode(VisualElement v, HDLCircuit parent) throws HDLException {
    try {
        ElementTypeDescription td = elementLibrary.getElementType(v.getElementName());
        if (td instanceof ElementLibrary.ElementTypeDescriptionCustom) {
            ElementLibrary.ElementTypeDescriptionCustom tdc = (ElementLibrary.ElementTypeDescriptionCustom) td;
            HDLCircuit c = circuitMap.get(tdc.getCircuit());
            if (c == null) {
                c = new HDLCircuit(tdc.getCircuit(), v.getElementName(), this);
                circuitMap.put(tdc.getCircuit(), c);
            }
            return addInputsOutputs(new HDLNodeCustom(v.getElementName(), v.getElementAttributes(), c), v, parent).createExpressions();
        } else if (v.equalsDescription(Const.DESCRIPTION)) {
            final HDLNodeAssignment node = createExpression(v, parent, td);
            node.setExpression(new ExprConstant(node.getElementAttributes().get(Keys.VALUE), node.getOutput().getBits()));
            return node;
        } else if (v.equalsDescription(DipSwitch.DESCRIPTION)) {
            final HDLNodeAssignment node = createExpression(v, parent, td);
            node.setExpression(new ExprConstant(node.getElementAttributes().get(Keys.DIP_DEFAULT) ? 1 : 0, node.getOutput().getBits()));
            return node;
        } else if (v.equalsDescription(Ground.DESCRIPTION)) {
            final HDLNodeAssignment node = createExpression(v, parent, td);
            node.setExpression(new ExprConstant(0, node.getOutput().getBits()));
            return node;
        } else if (v.equalsDescription(VDD.DESCRIPTION)) {
            final HDLNodeAssignment node = createExpression(v, parent, td);
            node.setExpression(new ExprConstant(-1, node.getOutput().getBits()));
            return node;
        } else if (v.equalsDescription(Not.DESCRIPTION)) {
            final HDLNodeAssignment node = createExpression(v, parent, td);
            node.setExpression(new ExprNot(new ExprVar(node.getInputs().get(0).getNet())));
            return node;
        } else if (v.equalsDescription(Or.DESCRIPTION)) {
            final HDLNodeAssignment node = createExpression(v, parent, td);
            node.setExpression(createOperation(node.getInputs(), ExprOperate.Operation.OR));
            return node;
        } else if (v.equalsDescription(And.DESCRIPTION)) {
            final HDLNodeAssignment node = createExpression(v, parent, td);
            node.setExpression(createOperation(node.getInputs(), ExprOperate.Operation.AND));
            return node;
        } else if (v.equalsDescription(XOr.DESCRIPTION)) {
            final HDLNodeAssignment node = createExpression(v, parent, td);
            node.setExpression(createOperation(node.getInputs(), ExprOperate.Operation.XOR));
            return node;
        } else if (v.equalsDescription(NOr.DESCRIPTION)) {
            final HDLNodeAssignment node = createExpression(v, parent, td);
            node.setExpression(new ExprNot(createOperation(node.getInputs(), ExprOperate.Operation.OR)));
            return node;
        } else if (v.equalsDescription(NAnd.DESCRIPTION)) {
            final HDLNodeAssignment node = createExpression(v, parent, td);
            node.setExpression(new ExprNot(createOperation(node.getInputs(), ExprOperate.Operation.AND)));
            return node;
        } else if (v.equalsDescription(XNOr.DESCRIPTION)) {
            final HDLNodeAssignment node = createExpression(v, parent, td);
            node.setExpression(new ExprNot(createOperation(node.getInputs(), ExprOperate.Operation.XOR)));
            return node;
        } else
            return addInputsOutputs(new HDLNodeBuildIn(v.getElementName(), v.getElementAttributes(), new ObservableValuesBitsProvider(td.createElement(v.getElementAttributes()).getOutputs())), v, parent).createExpressions();
    } catch (ElementNotFoundException | PinException | NodeException e) {
        throw new HDLException("error creating node", e);
    }
}
Also used : NodeException(de.neemann.digital.core.NodeException) ElementNotFoundException(de.neemann.digital.draw.library.ElementNotFoundException) ElementTypeDescription(de.neemann.digital.core.element.ElementTypeDescription) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) PinException(de.neemann.digital.draw.elements.PinException)

Example 3 with NodeException

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

the class BitExtenderTest method testSignExtendError2.

public void testSignExtendError2() throws Exception {
    try {
        ObservableValue in = new ObservableValue("in", 5);
        new BitExtender(new ElementAttributes().set(Keys.OUTPUT_BITS, 4)).setInputs(in.asList());
        fail();
    } catch (NodeException e) {
    }
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) NodeException(de.neemann.digital.core.NodeException) ElementAttributes(de.neemann.digital.core.element.ElementAttributes)

Example 4 with NodeException

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

the class RomLoader method preInit.

@Override
public void preInit(Model model) throws NodeException {
    List<ROM> roms = model.findNode(ROM.class, ROM::isProgramMemory);
    if (roms.isEmpty())
        throw new NodeException(Lang.get("msg_noRomFound"));
    if (roms.size() > 1)
        throw new NodeException(Lang.get("msg_moreThenOneRomFound"));
    try {
        roms.get(0).setData(new DataField(romHex));
        roms.get(0).provideRomAdress(model);
    } catch (IOException e) {
        throw new NodeException(e.getMessage());
    }
}
Also used : ROM(de.neemann.digital.core.memory.ROM) DataField(de.neemann.digital.core.memory.DataField) NodeException(de.neemann.digital.core.NodeException) IOException(java.io.IOException)

Example 5 with NodeException

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

the class VHDLGenerator method export.

/**
 * Exports the given circuit
 *
 * @param circuit the circuit to export
 * @return this for chained calls
 * @throws IOException IOException
 */
public VHDLGenerator export(Circuit circuit) throws IOException {
    try {
        if (!circuit.getAttributes().get(Keys.ROMMANAGER).isEmpty())
            throw new HDLException(Lang.get("err_centralDefinedRomsAreNotSupported"));
        BoardInterface board = BoardProvider.getInstance().getBoard(circuit);
        HDLClockIntegrator clockIntegrator = null;
        if (board != null && useClockIntegration)
            clockIntegrator = board.getClockIntegrator();
        HDLModel model = new HDLModel(library).create(circuit, clockIntegrator);
        for (HDLCircuit hdlCircuit : model) hdlCircuit.applyDefaultOptimizations();
        model.renameLabels(new VHDLRenaming());
        out.println("-- generated by Digital. Don't modify this file!");
        out.println("-- Any changes will be lost if this file is regenerated.");
        new VHDLCreator(out).printHDLCircuit(model.getMain());
        File outFile = out.getFile();
        if (outFile != null) {
            testBenches = new VHDLTestBenchCreator(circuit, model).write(outFile).getTestFileWritten();
            if (board != null)
                board.writeFiles(outFile, model);
        }
        return this;
    } catch (PinException | NodeException | HDLException | HGSEvalException e) {
        throw new IOException(Lang.get("err_vhdlExporting"), e);
    }
}
Also used : HDLModel(de.neemann.digital.hdl.model2.HDLModel) NodeException(de.neemann.digital.core.NodeException) HDLCircuit(de.neemann.digital.hdl.model2.HDLCircuit) IOException(java.io.IOException) HDLClockIntegrator(de.neemann.digital.hdl.model2.clock.HDLClockIntegrator) BoardInterface(de.neemann.digital.hdl.vhdl2.boards.BoardInterface) HDLException(de.neemann.digital.hdl.model2.HDLException) PinException(de.neemann.digital.draw.elements.PinException) File(java.io.File) HGSEvalException(de.neemann.digital.hdl.hgs.HGSEvalException)

Aggregations

NodeException (de.neemann.digital.core.NodeException)8 ObservableValue (de.neemann.digital.core.ObservableValue)5 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)2 Clock (de.neemann.digital.core.wiring.Clock)2 PinException (de.neemann.digital.draw.elements.PinException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Model (de.neemann.digital.core.Model)1 ObservableValues (de.neemann.digital.core.ObservableValues)1 Signal (de.neemann.digital.core.Signal)1 ElementTypeDescription (de.neemann.digital.core.element.ElementTypeDescription)1 PinDescription (de.neemann.digital.core.element.PinDescription)1 DataField (de.neemann.digital.core.memory.DataField)1 ROM (de.neemann.digital.core.memory.ROM)1 Value (de.neemann.digital.data.Value)1 ValueTable (de.neemann.digital.data.ValueTable)1 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)1 ElementNotFoundException (de.neemann.digital.draw.library.ElementNotFoundException)1 HGSEvalException (de.neemann.digital.hdl.hgs.HGSEvalException)1 HDLCircuit (de.neemann.digital.hdl.model2.HDLCircuit)1