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:
parent
d3131e1811
commit
36eae6fcdf
|
@ -26,14 +26,13 @@
|
||||||
* 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: 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;
|
package se.sics.cooja.avrmote;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
@ -45,12 +44,7 @@ import se.sics.cooja.MoteInterfaceHandler;
|
||||||
import se.sics.cooja.MoteMemory;
|
import se.sics.cooja.MoteMemory;
|
||||||
import se.sics.cooja.MoteType;
|
import se.sics.cooja.MoteType;
|
||||||
import se.sics.cooja.Simulation;
|
import se.sics.cooja.Simulation;
|
||||||
import se.sics.cooja.avrmote.interfaces.MicaClock;
|
import se.sics.cooja.motes.AbstractEmulatedMote;
|
||||||
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 avrora.core.LoadableProgram;
|
import avrora.core.LoadableProgram;
|
||||||
import avrora.sim.Interpreter;
|
import avrora.sim.Interpreter;
|
||||||
import avrora.sim.Simulator;
|
import avrora.sim.Simulator;
|
||||||
|
@ -62,16 +56,12 @@ import avrora.sim.platform.PlatformFactory;
|
||||||
/**
|
/**
|
||||||
* @author Joakim Eriksson, Fredrik Osterlind
|
* @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);
|
private static Logger logger = Logger.getLogger(MicaZMote.class);
|
||||||
|
|
||||||
/* 8 MHz according to Contiki config */
|
/* 8 MHz according to Contiki config */
|
||||||
public static long NR_CYCLES_PER_MSEC = 8000;
|
public static long NR_CYCLES_PER_MSEC = 8000;
|
||||||
|
|
||||||
/* Cycle counter */
|
|
||||||
public long cycleCounter = 0;
|
|
||||||
public long usDrift = 0; /* us */
|
|
||||||
|
|
||||||
private Simulation mySimulation = null;
|
private Simulation mySimulation = null;
|
||||||
private MoteInterfaceHandler myMoteInterfaceHandler;
|
private MoteInterfaceHandler myMoteInterfaceHandler;
|
||||||
private Microcontroller myCpu = null;
|
private Microcontroller myCpu = null;
|
||||||
|
@ -84,7 +74,6 @@ public class MicaZMote implements Mote {
|
||||||
/* Stack monitoring variables */
|
/* Stack monitoring variables */
|
||||||
private boolean stopNextInstruction = false;
|
private boolean stopNextInstruction = false;
|
||||||
|
|
||||||
|
|
||||||
public MicaZMote() {
|
public MicaZMote() {
|
||||||
myMoteType = null;
|
myMoteType = null;
|
||||||
mySimulation = null;
|
mySimulation = null;
|
||||||
|
@ -96,6 +85,9 @@ public class MicaZMote implements Mote {
|
||||||
public MicaZMote(Simulation simulation, MicaZMoteType type) {
|
public MicaZMote(Simulation simulation, MicaZMoteType type) {
|
||||||
mySimulation = simulation;
|
mySimulation = simulation;
|
||||||
myMoteType = type;
|
myMoteType = type;
|
||||||
|
|
||||||
|
/* Schedule us immediately */
|
||||||
|
requestImmediateWakeup();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean initEmulator(File fileELF) {
|
protected boolean initEmulator(File fileELF) {
|
||||||
|
@ -184,35 +176,37 @@ public class MicaZMote implements Mote {
|
||||||
myMoteInterfaceHandler = moteInterfaceHandler;
|
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) {
|
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) {
|
if (stopNextInstruction) {
|
||||||
stopNextInstruction = false;
|
stopNextInstruction = false;
|
||||||
throw new RuntimeException("Avrora requested simulation stop");
|
throw new RuntimeException("Avrora requested simulation stop");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (simTime + usDrift < 0) {
|
/* TODO Poll mote interfaces? */
|
||||||
return false;
|
|
||||||
|
/* Execute one millisecond */
|
||||||
|
cyclesUntil += NR_CYCLES_PER_MSEC;
|
||||||
|
while (cyclesExecuted < cyclesUntil) {
|
||||||
|
cyclesExecuted += interpreter.step();
|
||||||
}
|
}
|
||||||
|
|
||||||
long maxSimTimeCycles = (long)(NR_CYCLES_PER_MSEC * ((simTime+usDrift+Simulation.MILLISECOND)/(double)Simulation.MILLISECOND));
|
/* TODO Poll mote interfaces? */
|
||||||
if (maxSimTimeCycles <= cycleCounter) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Leave control to emulated CPU
|
/* Schedule wakeup every millisecond */
|
||||||
cycleCounter += 1;
|
/* TODO Optimize next wakeup time */
|
||||||
|
scheduleNextWakeup(t + Simulation.MILLISECOND);
|
||||||
if (cyclesExecuted > cycleCounter) {
|
|
||||||
/* CPU already ticked too far - just wait it out */
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
myMoteInterfaceHandler.doActiveActionsBeforeTick();
|
|
||||||
|
|
||||||
cyclesExecuted += interpreter.step();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setConfigXML(Simulation simulation, Collection<Element> configXML, boolean visAvailable) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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: 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;
|
package se.sics.cooja.avrmote;
|
||||||
|
@ -290,7 +290,7 @@ public class MicaZMoteType implements MoteType {
|
||||||
} else if (name.equals("firmware")) {
|
} else if (name.equals("firmware")) {
|
||||||
fileFirmware = new File(element.getText());
|
fileFirmware = new File(element.getText());
|
||||||
if (!fileFirmware.exists()) {
|
if (!fileFirmware.exists()) {
|
||||||
fileFirmware = simulation.getGUI().restorePortablePath(fileSource);
|
fileFirmware = simulation.getGUI().restorePortablePath(fileFirmware);
|
||||||
}
|
}
|
||||||
} else if (name.equals("moteinterface")) {
|
} else if (name.equals("moteinterface")) {
|
||||||
String intfClass = element.getText().trim();
|
String intfClass = element.getText().trim();
|
||||||
|
|
|
@ -26,21 +26,23 @@
|
||||||
* 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: 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;
|
package se.sics.cooja.avrmote.interfaces;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.jdom.Element;
|
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.avrmote.MicaZMote;
|
||||||
import se.sics.cooja.interfaces.Clock;
|
import se.sics.cooja.interfaces.Clock;
|
||||||
import se.sics.cooja.mspmote.MspMote;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Fredrik Osterlind, Joakim Eriksson
|
* @author Fredrik Osterlind, Joakim Eriksson
|
||||||
|
@ -49,9 +51,13 @@ import se.sics.cooja.mspmote.MspMote;
|
||||||
public class MicaClock extends Clock {
|
public class MicaClock extends Clock {
|
||||||
private static Logger logger = Logger.getLogger(MicaClock.class);
|
private static Logger logger = Logger.getLogger(MicaClock.class);
|
||||||
|
|
||||||
|
private Simulation simulation;
|
||||||
private MicaZMote myMote;
|
private MicaZMote myMote;
|
||||||
|
|
||||||
|
private long timeDrift; /* Microseconds */
|
||||||
|
|
||||||
public MicaClock(Mote mote) {
|
public MicaClock(Mote mote) {
|
||||||
|
simulation = mote.getSimulation();
|
||||||
myMote = (MicaZMote) mote;
|
myMote = (MicaZMote) mote;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,17 +66,15 @@ public class MicaClock extends Clock {
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTime() {
|
public long getTime() {
|
||||||
// long time = (long) ((double)myMote.cycleCounter * Simulation.MILLISECOND / MspMote.NR_CYCLES_PER_MSEC);
|
return simulation.getSimulationTime() + timeDrift;
|
||||||
// return time > 0 ? time : 0;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDrift(long drift) {
|
public void setDrift(long drift) {
|
||||||
myMote.usDrift = drift;
|
timeDrift = drift;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getDrift() {
|
public long getDrift() {
|
||||||
return myMote.usDrift;
|
return timeDrift;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getInterfaceVisualizer() {
|
public JPanel getInterfaceVisualizer() {
|
||||||
|
|
Loading…
Reference in a new issue