single instruction ticks instead of entire milliseconds
need optimizing
This commit is contained in:
parent
af2fcbca50
commit
bc4c80f7c7
|
@ -26,7 +26,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: MspMote.java,v 1.5 2008/03/19 17:23:47 fros4943 Exp $
|
* $Id: MspMote.java,v 1.6 2008/04/01 08:08:58 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.mspmote;
|
package se.sics.cooja.mspmote;
|
||||||
|
@ -242,21 +242,30 @@ public abstract class MspMote implements Mote {
|
||||||
*/
|
*/
|
||||||
protected abstract boolean initEmulator(File ELFFile);
|
protected abstract boolean initEmulator(File ELFFile);
|
||||||
|
|
||||||
public void tick(int simTime) {
|
private int currentSimTime = -1;
|
||||||
// Let all interfaces act
|
public boolean tick(int simTime) {
|
||||||
myMoteInterfaceHandler.doPassiveActionsBeforeTick();
|
if (stopNextInstruction) {
|
||||||
myMoteInterfaceHandler.doActiveActionsBeforeTick();
|
|
||||||
|
|
||||||
stopNextInstruction = false;
|
stopNextInstruction = false;
|
||||||
|
throw new RuntimeException("Request simulation stop");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentSimTime < 0) {
|
||||||
|
currentSimTime = simTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentSimTime != simTime) {
|
||||||
|
currentSimTime = simTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
long maxSimTimeCycles = NR_CYCLES_PER_MSEC*(simTime+1);
|
||||||
|
if (maxSimTimeCycles <= cycleCounter) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Leave control to emulated CPU
|
// Leave control to emulated CPU
|
||||||
MSP430 cpu = getCPU();
|
cycleCounter += 1;
|
||||||
cycleCounter += NR_CYCLES_PER_MSEC;
|
|
||||||
|
|
||||||
if (monitorStackUsage) {
|
MSP430 cpu = getCPU();
|
||||||
// CPU loop with stack observer
|
|
||||||
int newStack;
|
|
||||||
while (!stopNextInstruction && cpu.cycles < cycleCounter) {
|
|
||||||
cpu.step(cycleCounter);
|
cpu.step(cycleCounter);
|
||||||
|
|
||||||
/* Check if radio has pending incoming bytes */
|
/* Check if radio has pending incoming bytes */
|
||||||
|
@ -264,7 +273,8 @@ public abstract class MspMote implements Mote {
|
||||||
myRadio.tryDeliverNextByte(cpu.cycles);
|
myRadio.tryDeliverNextByte(cpu.cycles);
|
||||||
}
|
}
|
||||||
|
|
||||||
newStack = cpu.reg[MSP430.SP];
|
if (monitorStackUsage) {
|
||||||
|
int newStack = cpu.reg[MSP430.SP];
|
||||||
if (newStack < stackPointerLow && newStack > 0) {
|
if (newStack < stackPointerLow && newStack > 0) {
|
||||||
stackPointerLow = cpu.reg[MSP430.SP];
|
stackPointerLow = cpu.reg[MSP430.SP];
|
||||||
|
|
||||||
|
@ -272,26 +282,12 @@ public abstract class MspMote implements Mote {
|
||||||
if (stackPointerLow < heapStartAddress) {
|
if (stackPointerLow < heapStartAddress) {
|
||||||
stackOverflowObservable.signalStackOverflow();
|
stackOverflowObservable.signalStackOverflow();
|
||||||
stopNextInstruction = true;
|
stopNextInstruction = true;
|
||||||
}
|
getSimulation().stopSimulation();
|
||||||
}
|
|
||||||
}
|
|
||||||
} else { /* Fast CPU loop */
|
|
||||||
while (!stopNextInstruction && cpu.cycles < cycleCounter) {
|
|
||||||
cpu.step(cycleCounter);
|
|
||||||
|
|
||||||
/* Check if radio has pending incoming bytes */
|
|
||||||
if (myRadio != null && myRadio.hasPendingBytes()) {
|
|
||||||
myRadio.tryDeliverNextByte(cpu.cycles);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset abort flag
|
return true;
|
||||||
stopNextInstruction = false;
|
|
||||||
|
|
||||||
// Let all interfaces act after tick
|
|
||||||
myMoteInterfaceHandler.doActiveActionsAfterTick();
|
|
||||||
myMoteInterfaceHandler.doPassiveActionsAfterTick();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setConfigXML(Simulation simulation, Collection<Element> configXML, boolean visAvailable) {
|
public boolean setConfigXML(Simulation simulation, Collection<Element> configXML, boolean visAvailable) {
|
||||||
|
|
Loading…
Reference in a new issue