time deviation for MSP based nodes

This commit is contained in:
Andreas Löscher 2015-02-26 16:40:48 +01:00
parent 1c4a6f701e
commit 97da226255
2 changed files with 34 additions and 3 deletions

View file

@ -78,6 +78,8 @@ import se.sics.mspsim.util.MapEntry;
import se.sics.mspsim.util.MapTable; import se.sics.mspsim.util.MapTable;
import se.sics.mspsim.profiler.SimpleProfiler; import se.sics.mspsim.profiler.SimpleProfiler;
import org.contikios.cooja.mspmote.interfaces.MspClock;
/** /**
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
@ -313,9 +315,24 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
throw new RuntimeException("Bad event ordering: " + lastExecute + " < " + t); throw new RuntimeException("Bad event ordering: " + lastExecute + " < " + t);
} }
/* time deviation skip if ahead*/
double rtime = ((MspClock) (myMoteInterfaceHandler.getClock()))
.getReferenceTime();
double deviation = ((MspClock) myMoteInterfaceHandler.getClock())
.getDeviation();
long drift = myMoteInterfaceHandler.getClock().getDrift();
if (Math.round(rtime) < (t + drift)) {
lastExecute = t;
nextExecute = t + duration;
((MspClock) (myMoteInterfaceHandler.getClock())).setReferenceTime(rtime
+ duration + (deviation * duration));
scheduleNextWakeup(nextExecute);
return;
}
/* Execute MSPSim-based mote */ /* Execute MSPSim-based mote */
/* TODO Try-catch overhead */ /* TODO Try-catch overhead */
try { try {
nextExecute = nextExecute =
t + duration + t + duration +
myCpu.stepMicros(t - lastExecute, duration); myCpu.stepMicros(t - lastExecute, duration);
@ -333,6 +350,10 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
/*logger.debug(t + ": Schedule next wakeup at " + nextExecute);*/ /*logger.debug(t + ": Schedule next wakeup at " + nextExecute);*/
scheduleNextWakeup(nextExecute); scheduleNextWakeup(nextExecute);
/* time deviation book keeping */
((MspClock) (myMoteInterfaceHandler.getClock())).setReferenceTime(rtime
+ deviation * (nextExecute - lastExecute));
if (stopNextInstruction) { if (stopNextInstruction) {
stopNextInstruction = false; stopNextInstruction = false;
throw new RuntimeException("MSPSim requested simulation stop"); throw new RuntimeException("MSPSim requested simulation stop");

View file

@ -52,11 +52,13 @@ public class MspClock extends Clock {
private Simulation simulation; private Simulation simulation;
private long timeDrift; /* Microseconds */ private long timeDrift; /* Microseconds */
private double referenceTime; /* Microseconds */
private double deviation; private double deviation;
public MspClock(Mote mote) { public MspClock(Mote mote) {
simulation = mote.getSimulation(); simulation = mote.getSimulation();
deviation = 1.0; referenceTime = 0.0;
deviation = 0.999;
} }
public void setTime(long newTime) { public void setTime(long newTime) {
@ -75,8 +77,16 @@ public class MspClock extends Clock {
return timeDrift; return timeDrift;
} }
public void setReferenceTime(double referenceTime) {
this.referenceTime = referenceTime;
}
public double getReferenceTime() {
return referenceTime;
}
public void setDeviation(double deviation) { public void setDeviation(double deviation) {
assert deviation>0.0; assert (deviation>0.0) && (deviation<=1.0);
this.deviation = deviation; this.deviation = deviation;
} }