Updated MSPSim plugin for new memory model in MSPSim
This commit is contained in:
parent
b79eb23851
commit
28f8467ab1
4 changed files with 75 additions and 95 deletions
|
@ -36,21 +36,17 @@ import org.apache.log4j.Logger;
|
|||
import se.sics.cooja.AddressMemory;
|
||||
import se.sics.cooja.Mote;
|
||||
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.Memory.AccessType;
|
||||
import se.sics.mspsim.util.MapEntry;
|
||||
|
||||
public class MspMoteMemory implements MoteMemory, AddressMemory {
|
||||
private static Logger logger = Logger.getLogger(MspMoteMemory.class);
|
||||
private final ArrayList<MapEntry> mapEntries;
|
||||
|
||||
private MSP430 cpu;
|
||||
private Mote mote;
|
||||
private final MSP430 cpu;
|
||||
|
||||
public MspMoteMemory(Mote mote, MapEntry[] allEntries, MSP430 cpu) {
|
||||
this.mote = mote;
|
||||
this.mapEntries = new ArrayList<MapEntry>();
|
||||
|
||||
for (MapEntry entry: allEntries) {
|
||||
|
@ -191,7 +187,7 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
|
|||
}
|
||||
|
||||
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 int address;
|
||||
public final int size;
|
||||
|
@ -202,22 +198,14 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
|
|||
this.size = size;
|
||||
}
|
||||
|
||||
public void cpuAction(int type, final int adr, int data) {
|
||||
final MemoryEventType t;
|
||||
if (type == CPUMonitor.MEMORY_WRITE) {
|
||||
t = MemoryEventType.WRITE;
|
||||
} else {
|
||||
t = MemoryEventType.READ;
|
||||
}
|
||||
@Override
|
||||
public void notifyReadAfter(int address, int mode, AccessType type) {
|
||||
mm.memoryChanged(MspMoteMemory.this, MemoryEventType.READ, address);
|
||||
}
|
||||
|
||||
/* XXX Workaround to avoid using soon-obsolete data argument.
|
||||
* This causes a delay between memory rw and listener notifications */
|
||||
TimeEvent e = new MoteTimeEvent(mote, 0) {
|
||||
public void execute(long time) {
|
||||
mm.memoryChanged(MspMoteMemory.this, t, adr);
|
||||
}
|
||||
};
|
||||
mote.getSimulation().scheduleEvent(e, mote.getSimulation().getSimulationTime());
|
||||
@Override
|
||||
public void notifyWriteAfter(int dstAddress, int data, int mode) {
|
||||
mm.memoryChanged(MspMoteMemory.this, MemoryEventType.WRITE, dstAddress);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,8 @@ import se.sics.cooja.Mote;
|
|||
import se.sics.cooja.interfaces.Log;
|
||||
import se.sics.cooja.mspmote.MspMote;
|
||||
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.
|
||||
|
@ -67,7 +68,7 @@ public class MspDebugOutput extends Log {
|
|||
private MspMoteMemory mem;
|
||||
|
||||
private String lastLog = null;
|
||||
private CPUMonitor cpuMonitor = null;
|
||||
private MemoryMonitor memoryMonitor = null;
|
||||
|
||||
public MspDebugOutput(Mote mote) {
|
||||
this.mote = (MspMote) mote;
|
||||
|
@ -78,18 +79,15 @@ public class MspDebugOutput extends Log {
|
|||
return;
|
||||
}
|
||||
this.mote.getCPU().addWatchPoint(mem.getVariableAddress(CONTIKI_POINTER),
|
||||
cpuMonitor = new CPUMonitor() {
|
||||
public void cpuAction(int type, int adr, int data) {
|
||||
if (type != MEMORY_WRITE) {
|
||||
return;
|
||||
}
|
||||
|
||||
String msg = extractString(mem, data);
|
||||
if (msg != null && msg.length() > 0) {
|
||||
lastLog = "DEBUG: " + msg;
|
||||
setChanged();
|
||||
notifyObservers(MspDebugOutput.this.mote);
|
||||
}
|
||||
memoryMonitor = new MemoryMonitor.Adapter() {
|
||||
@Override
|
||||
public void notifyWriteAfter(int adr, int data, int mode) {
|
||||
String msg = extractString(mem, data);
|
||||
if (msg != null && msg.length() > 0) {
|
||||
lastLog = "DEBUG: " + msg;
|
||||
setChanged();
|
||||
notifyObservers(MspDebugOutput.this.mote);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -138,8 +136,8 @@ public class MspDebugOutput extends Log {
|
|||
public void removed() {
|
||||
super.removed();
|
||||
|
||||
if (cpuMonitor != null) {
|
||||
mote.getCPU().removeWatchPoint(mem.getVariableAddress(CONTIKI_POINTER), cpuMonitor);
|
||||
if (memoryMonitor != null) {
|
||||
mote.getCPU().removeWatchPoint(mem.getVariableAddress(CONTIKI_POINTER), memoryMonitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,12 +39,10 @@ import javax.swing.JPanel;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
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.mspmote.MspMote;
|
||||
import se.sics.cooja.mspmote.MspMoteMemory;
|
||||
import se.sics.mspsim.core.CPUMonitor;
|
||||
import se.sics.mspsim.core.MemoryMonitor;
|
||||
|
||||
/**
|
||||
* Mote ID.
|
||||
|
@ -60,7 +58,7 @@ public class MspMoteID extends MoteID {
|
|||
private boolean writeFlashHeader = true;
|
||||
private int moteID = -1;
|
||||
|
||||
private CPUMonitor cpuMonitor;
|
||||
private MemoryMonitor memoryMonitor;
|
||||
|
||||
/**
|
||||
* Creates an interface to the mote ID at mote.
|
||||
|
@ -110,41 +108,23 @@ public class MspMoteID extends MoteID {
|
|||
if (moteMem.variableExists("ActiveMessageAddressC$addr")) {
|
||||
moteMem.setIntValueOf("ActiveMessageAddressC$addr", newID);
|
||||
}
|
||||
if (cpuMonitor == null) {
|
||||
final MoteTimeEvent writeIDEvent = new MoteTimeEvent(mote, 0) {
|
||||
public void execute(long t) {
|
||||
setMoteID(moteID);
|
||||
if (memoryMonitor == null) {
|
||||
memoryMonitor = new MemoryMonitor.Adapter() {
|
||||
|
||||
@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() {
|
||||
public void cpuAction(int type, int address, int data) {
|
||||
if (type != MEMORY_WRITE) {
|
||||
return;
|
||||
}
|
||||
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);
|
||||
}
|
||||
addMonitor("node_id", memoryMonitor);
|
||||
addMonitor("TOS_NODE_ID", memoryMonitor);
|
||||
addMonitor("ActiveMessageAddressC__addr", memoryMonitor);
|
||||
addMonitor("ActiveMessageAddressC$addr", memoryMonitor);
|
||||
}
|
||||
|
||||
notifyObservers();
|
||||
|
@ -182,20 +162,32 @@ public class MspMoteID extends MoteID {
|
|||
|
||||
public void removed() {
|
||||
super.removed();
|
||||
if (cpuMonitor != null) {
|
||||
if (moteMem.variableExists("node_id")) {
|
||||
this.mote.getCPU().removeWatchPoint(moteMem.getVariableAddress("node_id"), cpuMonitor);
|
||||
}
|
||||
if (moteMem.variableExists("TOS_NODE_ID")) {
|
||||
this.mote.getCPU().removeWatchPoint(moteMem.getVariableAddress("TOS_NODE_ID"), cpuMonitor);
|
||||
}
|
||||
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;
|
||||
if (memoryMonitor != null) {
|
||||
removeMonitor("node_id", memoryMonitor);
|
||||
removeMonitor("TOS_NODE_ID", memoryMonitor);
|
||||
removeMonitor("ActiveMessageAddressC__addr", memoryMonitor);
|
||||
removeMonitor("ActiveMessageAddressC$addr", memoryMonitor);
|
||||
memoryMonitor = 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,8 @@ import org.jdom.Element;
|
|||
import se.sics.cooja.Watchpoint;
|
||||
import se.sics.cooja.mspmote.MspMote;
|
||||
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.
|
||||
|
@ -59,7 +60,7 @@ public class MspBreakpoint implements Watchpoint {
|
|||
private File codeFile = null; /* Source code, 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;
|
||||
|
||||
|
@ -130,16 +131,17 @@ public class MspBreakpoint implements Watchpoint {
|
|||
}
|
||||
|
||||
private void createMonitor() {
|
||||
cpuMonitor = new CPUMonitor() {
|
||||
public void cpuAction(int type, int adr, int data) {
|
||||
if (type != CPUMonitor.EXECUTE) {
|
||||
memoryMonitor = new MemoryMonitor.Adapter() {
|
||||
@Override
|
||||
public void notifyReadBefore(int addr, int mode, Memory.AccessType type) {
|
||||
if (type != Memory.AccessType.EXECUTE) {
|
||||
return;
|
||||
}
|
||||
|
||||
mspMote.signalBreakpointTrigger(MspBreakpoint.this);
|
||||
}
|
||||
};
|
||||
mspMote.getCPU().addWatchPoint(address, cpuMonitor);
|
||||
mspMote.getCPU().addWatchPoint(address, memoryMonitor);
|
||||
|
||||
|
||||
/* Remember Contiki code, to verify it when reloaded */
|
||||
|
@ -156,7 +158,7 @@ public class MspBreakpoint implements Watchpoint {
|
|||
}
|
||||
|
||||
public void unregisterBreakpoint() {
|
||||
mspMote.getCPU().removeWatchPoint(address, cpuMonitor);
|
||||
mspMote.getCPU().removeWatchPoint(address, memoryMonitor);
|
||||
}
|
||||
|
||||
public Collection<Element> getConfigXML() {
|
||||
|
|
Loading…
Reference in a new issue