micaz port now extends AbstractWakeupMote and schedules itself to execute every millisecond.

still no memory access, so simulation of micaz motes remains limited
This commit is contained in:
fros4943 2009-10-30 09:42:50 +00:00
parent d3131e1811
commit 36eae6fcdf
3 changed files with 48 additions and 48 deletions

View file

@ -26,14 +26,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: MicaZMote.java,v 1.8 2009/09/17 13:19:08 fros4943 Exp $
* $Id: MicaZMote.java,v 1.9 2009/10/30 09:42:50 fros4943 Exp $
*/
package se.sics.cooja.avrmote;
import java.io.File;
import java.util.Collection;
import java.util.Random;
import java.util.Vector;
import org.apache.log4j.Logger;
@ -45,12 +44,7 @@ import se.sics.cooja.MoteInterfaceHandler;
import se.sics.cooja.MoteMemory;
import se.sics.cooja.MoteType;
import se.sics.cooja.Simulation;
import se.sics.cooja.avrmote.interfaces.MicaClock;
import se.sics.cooja.avrmote.interfaces.MicaSerial;
import se.sics.cooja.avrmote.interfaces.MicaZLED;
import se.sics.cooja.avrmote.interfaces.MicaZRadio;
import se.sics.cooja.interfaces.MoteID;
import se.sics.cooja.interfaces.Position;
import se.sics.cooja.motes.AbstractEmulatedMote;
import avrora.core.LoadableProgram;
import avrora.sim.Interpreter;
import avrora.sim.Simulator;
@ -62,16 +56,12 @@ import avrora.sim.platform.PlatformFactory;
/**
* @author Joakim Eriksson, Fredrik Osterlind
*/
public class MicaZMote implements Mote {
public class MicaZMote extends AbstractEmulatedMote implements Mote {
private static Logger logger = Logger.getLogger(MicaZMote.class);
/* 8 MHz according to Contiki config */
public static long NR_CYCLES_PER_MSEC = 8000;
/* Cycle counter */
public long cycleCounter = 0;
public long usDrift = 0; /* us */
private Simulation mySimulation = null;
private MoteInterfaceHandler myMoteInterfaceHandler;
private Microcontroller myCpu = null;
@ -84,7 +74,6 @@ public class MicaZMote implements Mote {
/* Stack monitoring variables */
private boolean stopNextInstruction = false;
public MicaZMote() {
myMoteType = null;
mySimulation = null;
@ -96,6 +85,9 @@ public class MicaZMote implements Mote {
public MicaZMote(Simulation simulation, MicaZMoteType type) {
mySimulation = simulation;
myMoteType = type;
/* Schedule us immediately */
requestImmediateWakeup();
}
protected boolean initEmulator(File fileELF) {
@ -184,35 +176,37 @@ public class MicaZMote implements Mote {
myMoteInterfaceHandler = moteInterfaceHandler;
}
/* return false when done - e.g. true means more work to do before finished with this tick */
private long cyclesExecuted = 0;
public boolean tick(long simTime) {
throw new RuntimeException("Obsolete method");
}
private long cyclesExecuted = 0;
private long cyclesUntil = 0;
public void execute(long t) {
/* Wait until mote boots */
if (myMoteInterfaceHandler.getClock().getTime() < 0) {
scheduleNextWakeup(t - myMoteInterfaceHandler.getClock().getTime());
return;
}
if (stopNextInstruction) {
stopNextInstruction = false;
throw new RuntimeException("Avrora requested simulation stop");
}
if (simTime + usDrift < 0) {
return false;
}
long maxSimTimeCycles = (long)(NR_CYCLES_PER_MSEC * ((simTime+usDrift+Simulation.MILLISECOND)/(double)Simulation.MILLISECOND));
if (maxSimTimeCycles <= cycleCounter) {
return false;
}
// Leave control to emulated CPU
cycleCounter += 1;
if (cyclesExecuted > cycleCounter) {
/* CPU already ticked too far - just wait it out */
return true;
}
myMoteInterfaceHandler.doActiveActionsBeforeTick();
/* TODO Poll mote interfaces? */
/* Execute one millisecond */
cyclesUntil += NR_CYCLES_PER_MSEC;
while (cyclesExecuted < cyclesUntil) {
cyclesExecuted += interpreter.step();
}
return true;
/* TODO Poll mote interfaces? */
/* Schedule wakeup every millisecond */
/* TODO Optimize next wakeup time */
scheduleNextWakeup(t + Simulation.MILLISECOND);
}
public boolean setConfigXML(Simulation simulation, Collection<Element> configXML, boolean visAvailable) {
@ -242,6 +236,8 @@ public class MicaZMote implements Mote {
}
}
/* Schedule us immediately */
requestImmediateWakeup();
return true;
}

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: MicaZMoteType.java,v 1.6 2009/09/17 10:45:14 fros4943 Exp $
* $Id: MicaZMoteType.java,v 1.7 2009/10/30 09:42:50 fros4943 Exp $
*/
package se.sics.cooja.avrmote;
@ -290,7 +290,7 @@ public class MicaZMoteType implements MoteType {
} else if (name.equals("firmware")) {
fileFirmware = new File(element.getText());
if (!fileFirmware.exists()) {
fileFirmware = simulation.getGUI().restorePortablePath(fileSource);
fileFirmware = simulation.getGUI().restorePortablePath(fileFirmware);
}
} else if (name.equals("moteinterface")) {
String intfClass = element.getText().trim();

View file

@ -26,21 +26,23 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: MicaClock.java,v 1.5 2009/10/27 10:20:25 fros4943 Exp $
* $Id: MicaClock.java,v 1.6 2009/10/30 09:42:50 fros4943 Exp $
*/
package se.sics.cooja.avrmote.interfaces;
import java.util.Collection;
import javax.swing.JPanel;
import org.apache.log4j.Logger;
import org.jdom.Element;
import se.sics.cooja.*;
import se.sics.cooja.ClassDescription;
import se.sics.cooja.Mote;
import se.sics.cooja.Simulation;
import se.sics.cooja.avrmote.MicaZMote;
import se.sics.cooja.interfaces.Clock;
import se.sics.cooja.mspmote.MspMote;
/**
* @author Fredrik Osterlind, Joakim Eriksson
@ -49,9 +51,13 @@ import se.sics.cooja.mspmote.MspMote;
public class MicaClock extends Clock {
private static Logger logger = Logger.getLogger(MicaClock.class);
private Simulation simulation;
private MicaZMote myMote;
private long timeDrift; /* Microseconds */
public MicaClock(Mote mote) {
simulation = mote.getSimulation();
myMote = (MicaZMote) mote;
}
@ -60,17 +66,15 @@ public class MicaClock extends Clock {
}
public long getTime() {
// long time = (long) ((double)myMote.cycleCounter * Simulation.MILLISECOND / MspMote.NR_CYCLES_PER_MSEC);
// return time > 0 ? time : 0;
return 0;
return simulation.getSimulationTime() + timeDrift;
}
public void setDrift(long drift) {
myMote.usDrift = drift;
timeDrift = drift;
}
public long getDrift() {
return myMote.usDrift;
return timeDrift;
}
public JPanel getInterfaceVisualizer() {