diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java index e951e75fd..782cc75a1 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java @@ -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.9 2008/09/17 12:09:20 fros4943 Exp $ + * $Id: MspMote.java,v 1.10 2008/09/17 17:39:37 nifi Exp $ */ package se.sics.cooja.mspmote; @@ -53,6 +53,7 @@ public abstract class MspMote implements Mote { /* Cycle counter */ public long cycleCounter = 0; + public int cycleDrift = 0; private Simulation mySimulation = null; private MSP430 myCpu = null; @@ -276,7 +277,7 @@ public abstract class MspMote implements Mote { } long maxSimTimeCycles = NR_CYCLES_PER_MSEC*(simTime+1); - if (maxSimTimeCycles <= cycleCounter) { + if (maxSimTimeCycles <= cycleCounter - cycleDrift) { return false; } diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspClock.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspClock.java index 348394a30..c2add1eb5 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspClock.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspClock.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: MspClock.java,v 1.1 2008/02/07 14:54:16 fros4943 Exp $ + * $Id: MspClock.java,v 1.2 2008/09/17 17:39:37 nifi Exp $ */ package se.sics.cooja.mspmote.interfaces; @@ -61,11 +61,12 @@ public class MspClock extends Clock { } public int getTime() { - return (int) (cpu.cycles / MspMote.NR_CYCLES_PER_MSEC); + int time = (int) ((cpu.cycles + myMote.cycleDrift) / MspMote.NR_CYCLES_PER_MSEC); + return time > 0 ? time : 0; } public void setDrift(int drift) { - myMote.cycleCounter = -MspMote.NR_CYCLES_PER_MSEC * drift; + myMote.cycleDrift = MspMote.NR_CYCLES_PER_MSEC * drift; } public void doActionsBeforeTick() {