Updated MSPSim plugin for new memory model in MSPSim

This commit is contained in:
Niclas Finne 2012-03-23 02:52:10 +01:00
parent b79eb23851
commit 28f8467ab1
4 changed files with 75 additions and 95 deletions

View file

@ -36,21 +36,17 @@ import org.apache.log4j.Logger;
import se.sics.cooja.AddressMemory; import se.sics.cooja.AddressMemory;
import se.sics.cooja.Mote; import se.sics.cooja.Mote;
import se.sics.cooja.MoteMemory; import se.sics.cooja.MoteMemory;
import se.sics.cooja.MoteTimeEvent;
import se.sics.cooja.TimeEvent;
import se.sics.mspsim.core.CPUMonitor;
import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.MSP430;
import se.sics.mspsim.core.Memory.AccessType;
import se.sics.mspsim.util.MapEntry; import se.sics.mspsim.util.MapEntry;
public class MspMoteMemory implements MoteMemory, AddressMemory { public class MspMoteMemory implements MoteMemory, AddressMemory {
private static Logger logger = Logger.getLogger(MspMoteMemory.class); private static Logger logger = Logger.getLogger(MspMoteMemory.class);
private final ArrayList<MapEntry> mapEntries; private final ArrayList<MapEntry> mapEntries;
private MSP430 cpu; private final MSP430 cpu;
private Mote mote;
public MspMoteMemory(Mote mote, MapEntry[] allEntries, MSP430 cpu) { public MspMoteMemory(Mote mote, MapEntry[] allEntries, MSP430 cpu) {
this.mote = mote;
this.mapEntries = new ArrayList<MapEntry>(); this.mapEntries = new ArrayList<MapEntry>();
for (MapEntry entry: allEntries) { for (MapEntry entry: allEntries) {
@ -191,7 +187,7 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
} }
private ArrayList<MemoryCPUMonitor> cpuMonitorArray = new ArrayList<MemoryCPUMonitor>(); private ArrayList<MemoryCPUMonitor> cpuMonitorArray = new ArrayList<MemoryCPUMonitor>();
class MemoryCPUMonitor implements CPUMonitor { class MemoryCPUMonitor extends se.sics.mspsim.core.MemoryMonitor.Adapter {
public final MemoryMonitor mm; public final MemoryMonitor mm;
public final int address; public final int address;
public final int size; public final int size;
@ -202,22 +198,14 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
this.size = size; this.size = size;
} }
public void cpuAction(int type, final int adr, int data) { @Override
final MemoryEventType t; public void notifyReadAfter(int address, int mode, AccessType type) {
if (type == CPUMonitor.MEMORY_WRITE) { mm.memoryChanged(MspMoteMemory.this, MemoryEventType.READ, address);
t = MemoryEventType.WRITE; }
} else {
t = MemoryEventType.READ;
}
/* XXX Workaround to avoid using soon-obsolete data argument. @Override
* This causes a delay between memory rw and listener notifications */ public void notifyWriteAfter(int dstAddress, int data, int mode) {
TimeEvent e = new MoteTimeEvent(mote, 0) { mm.memoryChanged(MspMoteMemory.this, MemoryEventType.WRITE, dstAddress);
public void execute(long time) {
mm.memoryChanged(MspMoteMemory.this, t, adr);
}
};
mote.getSimulation().scheduleEvent(e, mote.getSimulation().getSimulationTime());
} }
} }

View file

@ -43,7 +43,8 @@ import se.sics.cooja.Mote;
import se.sics.cooja.interfaces.Log; import se.sics.cooja.interfaces.Log;
import se.sics.cooja.mspmote.MspMote; import se.sics.cooja.mspmote.MspMote;
import se.sics.cooja.mspmote.MspMoteMemory; import se.sics.cooja.mspmote.MspMoteMemory;
import se.sics.mspsim.core.CPUMonitor; import se.sics.mspsim.core.Memory;
import se.sics.mspsim.core.MemoryMonitor;
/** /**
* Observes writes to a special (hardcoded) Contiki variable: cooja_debug_ptr. * Observes writes to a special (hardcoded) Contiki variable: cooja_debug_ptr.
@ -67,7 +68,7 @@ public class MspDebugOutput extends Log {
private MspMoteMemory mem; private MspMoteMemory mem;
private String lastLog = null; private String lastLog = null;
private CPUMonitor cpuMonitor = null; private MemoryMonitor memoryMonitor = null;
public MspDebugOutput(Mote mote) { public MspDebugOutput(Mote mote) {
this.mote = (MspMote) mote; this.mote = (MspMote) mote;
@ -78,18 +79,15 @@ public class MspDebugOutput extends Log {
return; return;
} }
this.mote.getCPU().addWatchPoint(mem.getVariableAddress(CONTIKI_POINTER), this.mote.getCPU().addWatchPoint(mem.getVariableAddress(CONTIKI_POINTER),
cpuMonitor = new CPUMonitor() { memoryMonitor = new MemoryMonitor.Adapter() {
public void cpuAction(int type, int adr, int data) { @Override
if (type != MEMORY_WRITE) { public void notifyWriteAfter(int adr, int data, int mode) {
return; String msg = extractString(mem, data);
} if (msg != null && msg.length() > 0) {
lastLog = "DEBUG: " + msg;
String msg = extractString(mem, data); setChanged();
if (msg != null && msg.length() > 0) { notifyObservers(MspDebugOutput.this.mote);
lastLog = "DEBUG: " + msg; }
setChanged();
notifyObservers(MspDebugOutput.this.mote);
}
} }
}); });
} }
@ -138,8 +136,8 @@ public class MspDebugOutput extends Log {
public void removed() { public void removed() {
super.removed(); super.removed();
if (cpuMonitor != null) { if (memoryMonitor != null) {
mote.getCPU().removeWatchPoint(mem.getVariableAddress(CONTIKI_POINTER), cpuMonitor); mote.getCPU().removeWatchPoint(mem.getVariableAddress(CONTIKI_POINTER), memoryMonitor);
} }
} }
} }

View file

@ -39,12 +39,10 @@ import javax.swing.JPanel;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import se.sics.cooja.Mote; import se.sics.cooja.Mote;
import se.sics.cooja.MoteTimeEvent;
import se.sics.cooja.Simulation;
import se.sics.cooja.interfaces.MoteID; import se.sics.cooja.interfaces.MoteID;
import se.sics.cooja.mspmote.MspMote; import se.sics.cooja.mspmote.MspMote;
import se.sics.cooja.mspmote.MspMoteMemory; import se.sics.cooja.mspmote.MspMoteMemory;
import se.sics.mspsim.core.CPUMonitor; import se.sics.mspsim.core.MemoryMonitor;
/** /**
* Mote ID. * Mote ID.
@ -60,7 +58,7 @@ public class MspMoteID extends MoteID {
private boolean writeFlashHeader = true; private boolean writeFlashHeader = true;
private int moteID = -1; private int moteID = -1;
private CPUMonitor cpuMonitor; private MemoryMonitor memoryMonitor;
/** /**
* Creates an interface to the mote ID at mote. * Creates an interface to the mote ID at mote.
@ -110,41 +108,23 @@ public class MspMoteID extends MoteID {
if (moteMem.variableExists("ActiveMessageAddressC$addr")) { if (moteMem.variableExists("ActiveMessageAddressC$addr")) {
moteMem.setIntValueOf("ActiveMessageAddressC$addr", newID); moteMem.setIntValueOf("ActiveMessageAddressC$addr", newID);
} }
if (cpuMonitor == null) { if (memoryMonitor == null) {
final MoteTimeEvent writeIDEvent = new MoteTimeEvent(mote, 0) { memoryMonitor = new MemoryMonitor.Adapter() {
public void execute(long t) {
setMoteID(moteID); @Override
public void notifyWriteAfter(int dstAddress, int data, int mode) {
byte[] id = new byte[2];
id[0] = (byte) (moteID & 0xff);
id[1] = (byte) ((moteID >> 8) & 0xff);
moteMem.setMemorySegment(dstAddress & ~1, id);
} }
}; };
cpuMonitor = new CPUMonitor() { addMonitor("node_id", memoryMonitor);
public void cpuAction(int type, int address, int data) { addMonitor("TOS_NODE_ID", memoryMonitor);
if (type != MEMORY_WRITE) { addMonitor("ActiveMessageAddressC__addr", memoryMonitor);
return; addMonitor("ActiveMessageAddressC$addr", memoryMonitor);
}
if (data == moteID) {
return;
}
if (writeIDEvent.isScheduled()) {
return;
}
Simulation s = mote.getSimulation();
s.scheduleEvent(writeIDEvent, s.getSimulationTime());
}
};
if (moteMem.variableExists("node_id")) {
this.mote.getCPU().addWatchPoint(moteMem.getVariableAddress("node_id"), cpuMonitor);
}
if (moteMem.variableExists("TOS_NODE_ID")) {
this.mote.getCPU().addWatchPoint(moteMem.getVariableAddress("TOS_NODE_ID"), cpuMonitor);
}
if (moteMem.variableExists("ActiveMessageAddressC__addr")) {
this.mote.getCPU().addWatchPoint(moteMem.getVariableAddress("ActiveMessageAddressC__addr"), cpuMonitor);
}
if (moteMem.variableExists("ActiveMessageAddressC$addr")) {
this.mote.getCPU().addWatchPoint(moteMem.getVariableAddress("ActiveMessageAddressC$addr"), cpuMonitor);
}
} }
notifyObservers(); notifyObservers();
@ -182,20 +162,32 @@ public class MspMoteID extends MoteID {
public void removed() { public void removed() {
super.removed(); super.removed();
if (cpuMonitor != null) { if (memoryMonitor != null) {
if (moteMem.variableExists("node_id")) { removeMonitor("node_id", memoryMonitor);
this.mote.getCPU().removeWatchPoint(moteMem.getVariableAddress("node_id"), cpuMonitor); removeMonitor("TOS_NODE_ID", memoryMonitor);
} removeMonitor("ActiveMessageAddressC__addr", memoryMonitor);
if (moteMem.variableExists("TOS_NODE_ID")) { removeMonitor("ActiveMessageAddressC$addr", memoryMonitor);
this.mote.getCPU().removeWatchPoint(moteMem.getVariableAddress("TOS_NODE_ID"), cpuMonitor); memoryMonitor = null;
}
if (moteMem.variableExists("ActiveMessageAddressC__addr")) {
this.mote.getCPU().removeWatchPoint(moteMem.getVariableAddress("ActiveMessageAddressC__addr"), cpuMonitor);
}
if (moteMem.variableExists("ActiveMessageAddressC$addr")) {
this.mote.getCPU().removeWatchPoint(moteMem.getVariableAddress("ActiveMessageAddressC$addr"), cpuMonitor);
}
cpuMonitor = null;
} }
} }
private void addMonitor(String variable, MemoryMonitor monitor) {
if (moteMem.variableExists(variable)) {
int address = moteMem.getVariableAddress(variable);
if ((address & 1) != 0) {
// Variable can not be a word - must be a byte
} else {
mote.getCPU().addWatchPoint(address, monitor);
mote.getCPU().addWatchPoint(address + 1, monitor);
}
}
}
private void removeMonitor(String variable, MemoryMonitor monitor) {
if (moteMem.variableExists(variable)) {
int address = moteMem.getVariableAddress(variable);
mote.getCPU().removeWatchPoint(address, monitor);
mote.getCPU().removeWatchPoint(address + 1, monitor);
}
}
} }

View file

@ -43,7 +43,8 @@ import org.jdom.Element;
import se.sics.cooja.Watchpoint; import se.sics.cooja.Watchpoint;
import se.sics.cooja.mspmote.MspMote; import se.sics.cooja.mspmote.MspMote;
import se.sics.cooja.util.StringUtils; import se.sics.cooja.util.StringUtils;
import se.sics.mspsim.core.CPUMonitor; import se.sics.mspsim.core.Memory;
import se.sics.mspsim.core.MemoryMonitor;
/** /**
* Mspsim watchpoint. * Mspsim watchpoint.
@ -59,7 +60,7 @@ public class MspBreakpoint implements Watchpoint {
private File codeFile = null; /* Source code, may be null*/ private File codeFile = null; /* Source code, may be null*/
private int lineNr = -1; /* Source code line number, may be null */ private int lineNr = -1; /* Source code line number, may be null */
private CPUMonitor cpuMonitor = null; private MemoryMonitor memoryMonitor = null;
private boolean stopsSimulation = true; private boolean stopsSimulation = true;
@ -130,16 +131,17 @@ public class MspBreakpoint implements Watchpoint {
} }
private void createMonitor() { private void createMonitor() {
cpuMonitor = new CPUMonitor() { memoryMonitor = new MemoryMonitor.Adapter() {
public void cpuAction(int type, int adr, int data) { @Override
if (type != CPUMonitor.EXECUTE) { public void notifyReadBefore(int addr, int mode, Memory.AccessType type) {
if (type != Memory.AccessType.EXECUTE) {
return; return;
} }
mspMote.signalBreakpointTrigger(MspBreakpoint.this); mspMote.signalBreakpointTrigger(MspBreakpoint.this);
} }
}; };
mspMote.getCPU().addWatchPoint(address, cpuMonitor); mspMote.getCPU().addWatchPoint(address, memoryMonitor);
/* Remember Contiki code, to verify it when reloaded */ /* Remember Contiki code, to verify it when reloaded */
@ -156,7 +158,7 @@ public class MspBreakpoint implements Watchpoint {
} }
public void unregisterBreakpoint() { public void unregisterBreakpoint() {
mspMote.getCPU().removeWatchPoint(address, cpuMonitor); mspMote.getCPU().removeWatchPoint(address, memoryMonitor);
} }
public Collection<Element> getConfigXML() { public Collection<Element> getConfigXML() {