Search in sources :

Example 1 with PinException

use of de.neemann.digital.draw.elements.PinException 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 2 with PinException

use of de.neemann.digital.draw.elements.PinException in project Digital by hneemann.

the class ElementLibrary method importElement.

/**
 * Imports the given file
 *
 * @param file the file to load
 * @return the description
 * @throws IOException IOException
 */
ElementTypeDescription importElement(File file) throws IOException {
    try {
        LOGGER.debug("load element " + file);
        Circuit circuit;
        try {
            circuit = Circuit.loadCircuit(file, shapeFactory);
        } catch (FileNotFoundException e) {
            throw new IOException(Lang.get("err_couldNotFindIncludedFile_N0", file));
        }
        ElementTypeDescriptionCustom description = new ElementTypeDescriptionCustom(file, attributes -> new CustomElement(circuit, ElementLibrary.this), circuit);
        description.setShortName(createShortName(file));
        String descriptionText = circuit.getAttributes().get(Keys.DESCRIPTION);
        if (descriptionText != null && descriptionText.length() > 0) {
            description.setDescription(descriptionText);
        }
        return description;
    } catch (PinException e) {
        throw new IOException(Lang.get("msg_errorImportingModel_N0", file), e);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) Circuit(de.neemann.digital.draw.elements.Circuit) IOException(java.io.IOException) PinException(de.neemann.digital.draw.elements.PinException)

Example 3 with PinException

use of de.neemann.digital.draw.elements.PinException 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)

Example 4 with PinException

use of de.neemann.digital.draw.elements.PinException 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

PinException (de.neemann.digital.draw.elements.PinException)4 NodeException (de.neemann.digital.core.NodeException)2 IOException (java.io.IOException)2 ObservableValue (de.neemann.digital.core.ObservableValue)1 ElementTypeDescription (de.neemann.digital.core.element.ElementTypeDescription)1 DataBus (de.neemann.digital.core.wiring.bus.DataBus)1 Circuit (de.neemann.digital.draw.elements.Circuit)1 Pin (de.neemann.digital.draw.elements.Pin)1 Wire (de.neemann.digital.draw.elements.Wire)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 HDLException (de.neemann.digital.hdl.model2.HDLException)1 HDLModel (de.neemann.digital.hdl.model2.HDLModel)1 HDLClockIntegrator (de.neemann.digital.hdl.model2.clock.HDLClockIntegrator)1 BoardInterface (de.neemann.digital.hdl.vhdl2.boards.BoardInterface)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1