Search in sources :

Example 1 with Clock

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

the class Main method doSingleStep.

@Override
public String doSingleStep() throws RemoteException {
    if (model != null && !realTimeClockRunning) {
        try {
            AddressPicker addressPicker = new AddressPicker();
            SwingUtilities.invokeAndWait(() -> {
                ArrayList<Clock> cl = model.getClocks();
                if (cl.size() == 1) {
                    ObservableValue clkVal = cl.get(0).getClockOutput();
                    clkVal.setBool(!clkVal.getBool());
                    try {
                        model.doStep();
                        if (clkVal.getBool()) {
                            clkVal.setBool(!clkVal.getBool());
                            model.doStep();
                        }
                        circuitComponent.repaintNeeded();
                        addressPicker.getProgramROMAddress(model);
                    } catch (NodeException | RuntimeException e) {
                        showErrorAndStopModel(Lang.get("err_remoteExecution"), e);
                    }
                }
            });
            return addressPicker.getAddressString();
        } catch (InterruptedException | InvocationTargetException e) {
            throw new RemoteException("error performing a single step " + e.getMessage());
        }
    }
    return null;
}
Also used : RealTimeClock(de.neemann.digital.draw.model.RealTimeClock) Clock(de.neemann.digital.core.wiring.Clock) RemoteException(de.neemann.digital.gui.remote.RemoteException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with Clock

use of de.neemann.digital.core.wiring.Clock 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 3 with Clock

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

the class Main method createAndStartModel.

private boolean createAndStartModel(boolean globalRunClock, ModelEvent updateEvent, ModelModifier modelModifier) {
    try {
        circuitComponent.removeHighLighted();
        long time = System.currentTimeMillis();
        modelCreator = new ModelCreator(circuitComponent.getCircuit(), library);
        if (model != null) {
            modelSync.access(() -> model.close());
            circuitComponent.getCircuit().clearState();
            model = null;
        }
        model = modelCreator.createModel(true);
        time = System.currentTimeMillis() - time;
        LOGGER.debug("model creation: " + time + " ms");
        model.setWindowPosManager(windowPosManager);
        statusLabel.setText(Lang.get("msg_N_nodes", model.size()));
        realTimeClockRunning = false;
        modelSync = null;
        if (globalRunClock) {
            int threadRunnerCount = 0;
            for (Clock c : model.getClocks()) if (c.getFrequency() > 0) {
                if (modelSync == null)
                    modelSync = new LockSync();
                final RealTimeClock realTimeClock = new RealTimeClock(model, c, timerExecutor, this, modelSync, this);
                model.addObserver(realTimeClock);
                if (realTimeClock.isThreadRunner())
                    threadRunnerCount++;
                realTimeClockRunning = true;
            }
            if (threadRunnerCount > 1)
                throw new RuntimeException(Lang.get("err_moreThanOneFastClock"));
        }
        if (modelSync == null)
            modelSync = NoSync.INST;
        circuitComponent.setModeAndReset(true, modelSync);
        if (realTimeClockRunning) {
            // if clock is running, enable automatic update of gui
            GuiModelObserver gmo = new GuiModelObserver(circuitComponent, updateEvent);
            modelCreator.connectToGui(gmo);
            model.addObserver(gmo);
        } else
            // all repainting is initiated by user actions!
            modelCreator.connectToGui(null);
        doStep.setEnabled(false);
        runToBreakAction.setEnabled(!realTimeClockRunning && model.isFastRunModel());
        ElementAttributes settings = circuitComponent.getCircuit().getAttributes();
        if (settings.get(Keys.SHOW_DATA_TABLE) || windowPosManager.isVisible("probe"))
            showMeasurementDialog(updateEvent);
        if (settings.get(Keys.SHOW_DATA_GRAPH) || windowPosManager.isVisible("dataSet"))
            showMeasurementGraph(updateEvent);
        if (settings.get(Keys.SHOW_DATA_GRAPH_MICRO))
            showMeasurementGraph(ModelEvent.MICROSTEP);
        if (modelModifier != null)
            modelModifier.preInit(model);
        model.init();
        return true;
    } catch (NodeException | PinException | RuntimeException | ElementNotFoundException e) {
        if (model != null)
            showErrorAndStopModel(Lang.get("msg_errorCreatingModel"), e);
        else
            showErrorWithoutARunningModel(Lang.get("msg_errorCreatingModel"), e);
    }
    return false;
}
Also used : RealTimeClock(de.neemann.digital.draw.model.RealTimeClock) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) ElementNotFoundException(de.neemann.digital.draw.library.ElementNotFoundException) RealTimeClock(de.neemann.digital.draw.model.RealTimeClock) Clock(de.neemann.digital.core.wiring.Clock) ModelCreator(de.neemann.digital.draw.model.ModelCreator) LockSync(de.neemann.digital.gui.sync.LockSync)

Example 4 with Clock

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

the class TestExecutor method create.

/**
 * Creates the result by comparing the testing vector with the given model-
 *
 * @param model the model to check
 * @return this for chained calls
 * @throws TestingDataException DataException
 * @throws NodeException        NodeException
 */
public TestExecutor create(Model model) throws TestingDataException, NodeException {
    allPassed = true;
    HashSet<String> usedSignals = new HashSet<>();
    inputs = new ArrayList<>();
    outputs = new ArrayList<>();
    for (Signal s : model.getInputs()) {
        final int index = getIndexOf(s.getName());
        if (index >= 0) {
            inputs.add(new TestSignal(index, s.getValue()));
            addTo(usedSignals, s.getName());
        }
        ObservableValue outValue = s.getBidirectionalReader();
        if (outValue != null) {
            final String outName = s.getName() + "_out";
            final int inIndex = getIndexOf(outName);
            if (inIndex >= 0) {
                outputs.add(new TestSignal(inIndex, outValue));
                addTo(usedSignals, outName);
            }
        }
    }
    for (Clock c : model.getClocks()) {
        final int index = getIndexOf(c.getLabel());
        if (index >= 0) {
            inputs.add(new TestSignal(index, c.getClockOutput()));
            addTo(usedSignals, c.getLabel());
        }
    }
    for (Signal s : model.getOutputs()) {
        final int index = getIndexOf(s.getName());
        if (index >= 0) {
            outputs.add(new TestSignal(index, s.getValue()));
            addTo(usedSignals, s.getName());
        }
    }
    for (String name : names) if (!usedSignals.contains(name))
        throw new TestingDataException(Lang.get("err_testSignal_N_notFound", name));
    if (inputs.size() == 0)
        throw new TestingDataException(Lang.get("err_noTestInputSignalsDefined"));
    if (outputs.size() == 0)
        throw new TestingDataException(Lang.get("err_noTestOutputSignalsDefined"));
    model.init();
    try {
        lines.emitLines(new LineListenerResolveDontCare(values -> checkRow(model, values), inputs), new Context());
    } catch (ParserException e) {
        throw new TestingDataException(Lang.get("err_errorParsingTestdata"), e);
    } catch (RuntimeException e) {
        if (allPassed) {
            allPassed = false;
            exception = e;
        }
    }
    return this;
}
Also used : Clock(de.neemann.digital.core.wiring.Clock) LineEmitter(de.neemann.digital.testing.parser.LineEmitter) Signal(de.neemann.digital.core.Signal) ParserException(de.neemann.digital.testing.parser.ParserException) ObservableValue(de.neemann.digital.core.ObservableValue) Lang(de.neemann.digital.lang.Lang) ValueTable(de.neemann.digital.data.ValueTable) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Model(de.neemann.digital.core.Model) Value(de.neemann.digital.data.Value) Context(de.neemann.digital.testing.parser.Context) NodeException(de.neemann.digital.core.NodeException) Context(de.neemann.digital.testing.parser.Context) ParserException(de.neemann.digital.testing.parser.ParserException) ObservableValue(de.neemann.digital.core.ObservableValue) Clock(de.neemann.digital.core.wiring.Clock) Signal(de.neemann.digital.core.Signal) HashSet(java.util.HashSet)

Example 5 with Clock

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

the class SpeedTest method calculate.

/**
 * Calculates and returns the maximal frequency in Hz
 *
 * @return the maximal frequency in Hz
 * @throws NodeException NodeException
 */
public double calculate() throws NodeException {
    ArrayList<Clock> clocks = model.getClocks();
    if (clocks.isEmpty())
        throw new NodeException(Lang.get("err_noClockFound"));
    else if (clocks.size() > 1)
        throw new NodeException(Lang.get("err_moreThenOneClocksFound"));
    Clock clock = clocks.get(0);
    model.init();
    ObservableValue clockValue = clock.getOutputs().get(0);
    int state = (int) clockValue.getValue();
    long aktTime;
    long starTime = System.currentTimeMillis();
    int loops = 0;
    do {
        for (int i = 0; i < LOOPCOUNTER; i++) {
            state = 1 - state;
            clockValue.setValue(state);
            model.doStep();
        }
        loops++;
        aktTime = System.currentTimeMillis();
    } while (aktTime - starTime < 1000);
    long cycles = ((long) loops) * LOOPCOUNTER / 2;
    double time = (aktTime - starTime) / 1000.0;
    double frequency = cycles / time;
    System.out.println("cycles: " + cycles);
    System.out.println("time  : " + time + "s");
    System.out.println("freq  :" + frequency);
    return frequency;
}
Also used : Clock(de.neemann.digital.core.wiring.Clock)

Aggregations

Clock (de.neemann.digital.core.wiring.Clock)5 NodeException (de.neemann.digital.core.NodeException)2 ObservableValue (de.neemann.digital.core.ObservableValue)2 RealTimeClock (de.neemann.digital.draw.model.RealTimeClock)2 Model (de.neemann.digital.core.Model)1 Signal (de.neemann.digital.core.Signal)1 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)1 Value (de.neemann.digital.data.Value)1 ValueTable (de.neemann.digital.data.ValueTable)1 ElementNotFoundException (de.neemann.digital.draw.library.ElementNotFoundException)1 ModelCreator (de.neemann.digital.draw.model.ModelCreator)1 RemoteException (de.neemann.digital.gui.remote.RemoteException)1 LockSync (de.neemann.digital.gui.sync.LockSync)1 Lang (de.neemann.digital.lang.Lang)1 Context (de.neemann.digital.testing.parser.Context)1 LineEmitter (de.neemann.digital.testing.parser.LineEmitter)1 ParserException (de.neemann.digital.testing.parser.ParserException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1