public void execute(long t, int duration) { /* Wait until mote boots */ if (myMoteInterfaceHandler.getClock().getTime() < 0) { scheduleNextWakeup(t - myMoteInterfaceHandler.getClock().getTime()); return; } if (stopNextInstruction) { stopNextInstruction = false; /*sendCLICommandAndPrint("trace 1000");*/ /* TODO Enable */ scheduleNextWakeup(t); throw new RuntimeException("MSPSim requested simulation stop"); } if (lastExecute < 0) { /* Always execute one microsecond the first time */ lastExecute = t; } if (t < lastExecute) { throw new RuntimeException("Bad event ordering: " + lastExecute + " < " + t); } /* Execute MSPSim-based mote */ /* TODO Try-catch overhead */ try { nextExecute = t + duration + myCpu.stepMicros(t - lastExecute, duration); lastExecute = t; } catch (EmulationException e) { String stackTraceOutput = sendCLICommandAndPrint("stacktrace"); throw (ContikiError) new ContikiError(stackTraceOutput).initCause(e); } /* Schedule wakeup */ if (nextExecute < t) { throw new RuntimeException(t + ": MSPSim requested early wakeup: " + nextExecute); } /*logger.debug(t + ": Schedule next wakeup at " + nextExecute);*/ scheduleNextWakeup(nextExecute); /* XXX TODO Reimplement stack monitoring using MSPSim internals */ /*if (monitorStackUsage) { int newStack = cpu.reg[MSP430.SP]; if (newStack < stackPointerLow && newStack > 0) { stackPointerLow = cpu.reg[MSP430.SP]; // Check if stack is writing in memory if (stackPointerLow < heapStartAddress) { stackOverflowObservable.signalStackOverflow(); stopNextInstruction = true; getSimulation().stopSimulation(); } } }*/ }