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;
}
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();
}
}
}
});
}
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;
}
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;
}
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;
}
Aggregations