From 5bcb6ad8a572e225d18b8fc1d5f2aaf38686819d Mon Sep 17 00:00:00 2001 From: Fredrik Osterlind Date: Thu, 26 Jan 2012 16:09:31 +0100 Subject: [PATCH] updated to mspsims new watchpoint api --- .../mspmote/interfaces/MspDebugOutput.java | 10 ++- .../cooja/mspmote/interfaces/MspMoteID.java | 86 ++++++++----------- .../cooja/mspmote/plugins/MspBreakpoint.java | 4 +- 3 files changed, 47 insertions(+), 53 deletions(-) diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspDebugOutput.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspDebugOutput.java index a8173f8a6..ea189faa4 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspDebugOutput.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspDebugOutput.java @@ -67,6 +67,7 @@ public class MspDebugOutput extends Log { private MspMoteMemory mem; private String lastLog = null; + private CPUMonitor cpuMonitor = null; public MspDebugOutput(Mote mote) { this.mote = (MspMote) mote; @@ -76,8 +77,8 @@ public class MspDebugOutput extends Log { /* Disabled */ return; } - this.mote.getCPU().setBreakPoint(mem.getVariableAddress(CONTIKI_POINTER), - new CPUMonitor() { + 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; @@ -136,6 +137,9 @@ public class MspDebugOutput extends Log { public void removed() { super.removed(); - /* TODO Remove watchpoint */ + + if (cpuMonitor != null) { + mote.getCPU().removeWatchPoint(mem.getVariableAddress(CONTIKI_POINTER), cpuMonitor); + } } } diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspMoteID.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspMoteID.java index 0c8f61ce3..b330ab326 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspMoteID.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspMoteID.java @@ -64,6 +64,8 @@ public class MspMoteID extends MoteID { private boolean writeFlashHeader = true; private int moteID = -1; + private CPUMonitor cpuMonitor; + /** * Creates an interface to the mote ID at mote. * @@ -81,61 +83,33 @@ public class MspMoteID extends MoteID { } }; + cpuMonitor = new CPUMonitor() { + public void cpuAction(int type, int adr, int data) { + if (type != MEMORY_WRITE) { + return; + } + if (data == moteID) { + return; + } + Simulation s = mote.getSimulation(); + if (writeIDEvent.isScheduled()) { + return; + } + s.scheduleEvent(writeIDEvent, s.getSimulationTime()); + } + }; + if (moteMem.variableExists("node_id")) { - this.mote.getCPU().setBreakPoint(moteMem.getVariableAddress("node_id"), new CPUMonitor() { - public void cpuAction(int type, int adr, int data) { - if (type != MEMORY_WRITE) { - return; - } - if (data == moteID) { - return; - } - Simulation s = mote.getSimulation(); - s.scheduleEvent(writeIDEvent, s.getSimulationTime()); - } - }); + this.mote.getCPU().addWatchPoint(moteMem.getVariableAddress("node_id"), cpuMonitor); } if (moteMem.variableExists("TOS_NODE_ID")) { - this.mote.getCPU().setBreakPoint(moteMem.getVariableAddress("TOS_NODE_ID"), new CPUMonitor() { - public void cpuAction(int type, int adr, int data) { - if (type != MEMORY_WRITE) { - return; - } - if (data == moteID) { - return; - } - Simulation s = mote.getSimulation(); - s.scheduleEvent(writeIDEvent, s.getSimulationTime()); - } - }); + this.mote.getCPU().addWatchPoint(moteMem.getVariableAddress("TOS_NODE_ID"), cpuMonitor); } if (moteMem.variableExists("ActiveMessageAddressC__addr")) { - this.mote.getCPU().setBreakPoint(moteMem.getVariableAddress("ActiveMessageAddressC__addr"), new CPUMonitor() { - public void cpuAction(int type, int adr, int data) { - if (type != MEMORY_WRITE) { - return; - } - if (data == moteID) { - return; - } - Simulation s = mote.getSimulation(); - s.scheduleEvent(writeIDEvent, s.getSimulationTime()); - } - }); + this.mote.getCPU().addWatchPoint(moteMem.getVariableAddress("ActiveMessageAddressC__addr"), cpuMonitor); } if (moteMem.variableExists("ActiveMessageAddressC$addr")) { - this.mote.getCPU().setBreakPoint(moteMem.getVariableAddress("ActiveMessageAddressC$addr"), new CPUMonitor() { - public void cpuAction(int type, int adr, int data) { - if (type != MEMORY_WRITE) { - return; - } - if (data == moteID) { - return; - } - Simulation s = mote.getSimulation(); - s.scheduleEvent(writeIDEvent, s.getSimulationTime()); - } - }); + this.mote.getCPU().addWatchPoint(moteMem.getVariableAddress("ActiveMessageAddressC$addr"), cpuMonitor); } } @@ -224,4 +198,20 @@ public class MspMoteID extends MoteID { } } } + + public void removed() { + super.removed(); + 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); + } + } } diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/plugins/MspBreakpoint.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/plugins/MspBreakpoint.java index ad2c909db..7f2c18a81 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/plugins/MspBreakpoint.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/plugins/MspBreakpoint.java @@ -128,11 +128,11 @@ public class MspBreakpoint implements Watchpoint { breakpoints.signalBreakpointTrigger(MspBreakpoint.this); } }; - mspMote.getCPU().setBreakPoint(address, cpuMonitor); + mspMote.getCPU().addWatchPoint(address, cpuMonitor); } public void unregisterBreakpoint() { - mspMote.getCPU().setBreakPoint(address, null); + mspMote.getCPU().removeWatchPoint(address, cpuMonitor); } public Collection getConfigXML() {