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
|
||||
* 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;
|
||||
|
@ -242,21 +242,30 @@ public abstract class MspMote implements Mote {
|
|||
*/
|
||||
protected abstract boolean initEmulator(File ELFFile);
|
||||
|
||||
public void tick(int simTime) {
|
||||
// Let all interfaces act
|
||||
myMoteInterfaceHandler.doPassiveActionsBeforeTick();
|
||||
myMoteInterfaceHandler.doActiveActionsBeforeTick();
|
||||
|
||||
private int currentSimTime = -1;
|
||||
public boolean tick(int simTime) {
|
||||
if (stopNextInstruction) {
|
||||
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
|
||||
MSP430 cpu = getCPU();
|
||||
cycleCounter += NR_CYCLES_PER_MSEC;
|
||||
cycleCounter += 1;
|
||||
|
||||
if (monitorStackUsage) {
|
||||
// CPU loop with stack observer
|
||||
int newStack;
|
||||
while (!stopNextInstruction && cpu.cycles < cycleCounter) {
|
||||
MSP430 cpu = getCPU();
|
||||
cpu.step(cycleCounter);
|
||||
|
||||
/* Check if radio has pending incoming bytes */
|
||||
|
@ -264,7 +273,8 @@ public abstract class MspMote implements Mote {
|
|||
myRadio.tryDeliverNextByte(cpu.cycles);
|
||||
}
|
||||
|
||||
newStack = cpu.reg[MSP430.SP];
|
||||
if (monitorStackUsage) {
|
||||
int newStack = cpu.reg[MSP430.SP];
|
||||
if (newStack < stackPointerLow && newStack > 0) {
|
||||
stackPointerLow = cpu.reg[MSP430.SP];
|
||||
|
||||
|
@ -272,26 +282,12 @@ public abstract class MspMote implements Mote {
|
|||
if (stackPointerLow < heapStartAddress) {
|
||||
stackOverflowObservable.signalStackOverflow();
|
||||
stopNextInstruction = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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);
|
||||
getSimulation().stopSimulation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reset abort flag
|
||||
stopNextInstruction = false;
|
||||
|
||||
// Let all interfaces act after tick
|
||||
myMoteInterfaceHandler.doActiveActionsAfterTick();
|
||||
myMoteInterfaceHandler.doPassiveActionsAfterTick();
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean setConfigXML(Simulation simulation, Collection<Element> configXML, boolean visAvailable) {
|
||||
|
|
Loading…
Reference in a new issue