msp mote memory now contains map entries instead of name->address hash
This commit is contained in:
parent
2beb497c35
commit
36f70eff7c
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: MspMote.java,v 1.1 2008/02/07 14:53:29 fros4943 Exp $
|
||||
* $Id: MspMote.java,v 1.2 2008/02/11 14:07:38 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.mspmote;
|
||||
|
@ -39,8 +39,9 @@ import org.jdom.Element;
|
|||
import se.sics.cooja.*;
|
||||
import se.sics.cooja.mspmote.interfaces.TR1001Radio;
|
||||
import se.sics.mspsim.core.MSP430;
|
||||
import se.sics.mspsim.core.MapTable;
|
||||
import se.sics.mspsim.util.ELF;
|
||||
import se.sics.mspsim.util.MapEntry;
|
||||
import se.sics.mspsim.util.MapTable;
|
||||
|
||||
/**
|
||||
* @author Fredrik Osterlind
|
||||
|
@ -179,13 +180,8 @@ public abstract class MspMote implements Mote {
|
|||
/* TODO Need new memory type including size and type as well */
|
||||
|
||||
/* Create mote address memory */
|
||||
Properties varAddresses = new Properties();
|
||||
for (int i=0; i < map.functionNames.length; i++) {
|
||||
if (map.functionNames[i] != null) {
|
||||
varAddresses.put(map.functionNames[i], new Integer(i));
|
||||
}
|
||||
}
|
||||
myMemory = new MspMoteMemory(varAddresses, myCpu);
|
||||
ArrayList<MapEntry> allEntries = map.getAllEntries();
|
||||
myMemory = new MspMoteMemory(allEntries, myCpu);
|
||||
|
||||
myCpu.reset();
|
||||
}
|
||||
|
@ -249,7 +245,9 @@ public abstract class MspMote implements Mote {
|
|||
if (monitorStackUsage) {
|
||||
// CPU loop with stack observer
|
||||
int newStack;
|
||||
while (!stopNextInstruction && cpu.step() < cycleCounter) {
|
||||
while (!stopNextInstruction && cpu.cycles < cycleCounter) {
|
||||
cpu.step(cycleCounter);
|
||||
|
||||
/* Check if radio has pending incoming bytes */
|
||||
if (myRadio != null && myRadio.hasPendingBytes()) {
|
||||
myRadio.tryDeliverNextByte(cpu.cycles);
|
||||
|
@ -267,12 +265,14 @@ public abstract class MspMote implements Mote {
|
|||
}
|
||||
}
|
||||
} else { /* Fast CPU loop */
|
||||
do {
|
||||
while (!stopNextInstruction && cpu.cycles < cycleCounter) {
|
||||
cpu.step(cycleCounter);
|
||||
|
||||
/* Check if radio has pending incoming bytes */
|
||||
if (myRadio != null && myRadio.hasPendingBytes()) {
|
||||
myRadio.tryDeliverNextByte(cpu.cycles);
|
||||
}
|
||||
} while (!stopNextInstruction && (cpu.step() < cycleCounter) );
|
||||
}
|
||||
}
|
||||
|
||||
// Reset abort flag
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id: MspMoteMemory.java,v 1.1 2008/02/07 14:53:29 fros4943 Exp $
|
||||
* $Id: MspMoteMemory.java,v 1.2 2008/02/11 14:07:38 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.mspmote;
|
||||
|
@ -35,35 +35,50 @@ import org.apache.log4j.Logger;
|
|||
import se.sics.cooja.AddressMemory;
|
||||
import se.sics.cooja.MoteMemory;
|
||||
import se.sics.mspsim.core.MSP430;
|
||||
import se.sics.mspsim.util.MapEntry;
|
||||
|
||||
public class MspMoteMemory implements MoteMemory, AddressMemory {
|
||||
private static Logger logger = Logger.getLogger(MspMoteMemory.class);
|
||||
private final Properties variableAddresses;
|
||||
private final ArrayList<MapEntry> mapEntries;
|
||||
|
||||
private int TEMP_MEM_START;
|
||||
private MSP430 cpu;
|
||||
|
||||
public MspMoteMemory(Properties variableAddresses, MSP430 cpu) {
|
||||
this.variableAddresses = variableAddresses;
|
||||
public MspMoteMemory(ArrayList<MapEntry> allEntries, MSP430 cpu) {
|
||||
this.mapEntries = new ArrayList<MapEntry>();
|
||||
|
||||
for (MapEntry entry: allEntries) {
|
||||
if (entry.getType() == MapEntry.TYPE.variable) {
|
||||
mapEntries.add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
this.cpu = cpu;
|
||||
TEMP_MEM_START = 0;
|
||||
}
|
||||
|
||||
public String[] getVariableNames() {
|
||||
String[] names = new String[variableAddresses.size()];
|
||||
Enumeration nameEnum = variableAddresses.keys();
|
||||
for (int i = 0; i < variableAddresses.size(); i++) {
|
||||
names[i] = (String) nameEnum.nextElement();
|
||||
String[] names = new String[mapEntries.size()];
|
||||
for (int i = 0; i < mapEntries.size(); i++) {
|
||||
names[i] = mapEntries.get(i).getName();
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
public int getVariableAddress(String varName) {
|
||||
if (!variableAddresses.containsKey(varName)) {
|
||||
return -1;
|
||||
private MapEntry getMapEntry(String varName) throws UnknownVariableException {
|
||||
for (MapEntry entry: mapEntries) {
|
||||
if (entry.getName().equals(varName)) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
return ((Integer) variableAddresses.get(varName)).intValue();
|
||||
throw new UnknownVariableException(varName);
|
||||
}
|
||||
|
||||
public int getVariableAddress(String varName) throws UnknownVariableException {
|
||||
MapEntry entry = getMapEntry(varName);
|
||||
return entry.getAddress();
|
||||
}
|
||||
|
||||
public int getIntegerLength() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public void clearMemory() {
|
||||
|
@ -71,27 +86,27 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
|
|||
}
|
||||
|
||||
public byte[] getMemorySegment(int address, int size) {
|
||||
int[] ret = new int[size];
|
||||
int[] memInts = new int[size];
|
||||
|
||||
System.arraycopy(cpu.memory, address - TEMP_MEM_START, ret, 0, size);
|
||||
System.arraycopy(cpu.memory, address, memInts, 0, size);
|
||||
|
||||
// TODO XXX Slow method
|
||||
byte[] ret2 = new byte[size];
|
||||
/* Convert to byte array */
|
||||
byte[] memBytes = new byte[size];
|
||||
for (int i=0; i < size; i++) {
|
||||
ret2[i] = (byte) ret[i];
|
||||
memBytes[i] = (byte) memInts[i];
|
||||
}
|
||||
|
||||
return ret2;
|
||||
return memBytes;
|
||||
}
|
||||
|
||||
public void setMemorySegment(int address, byte[] data) {
|
||||
// TODO XXX Slow method
|
||||
int[] intArr = new int[data.length];
|
||||
/* Convert to int array */
|
||||
int[] memInts = new int[data.length];
|
||||
for (int i=0; i < data.length; i++) {
|
||||
intArr[i] = data[i];
|
||||
memInts[i] = data[i];
|
||||
}
|
||||
|
||||
System.arraycopy(intArr, 0, cpu.memory, address - TEMP_MEM_START, data.length);
|
||||
System.arraycopy(memInts, 0, cpu.memory, address, data.length);
|
||||
}
|
||||
|
||||
public int getTotalSize() {
|
||||
|
@ -99,16 +114,21 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
|
|||
}
|
||||
|
||||
public boolean variableExists(String varName) {
|
||||
return variableAddresses.containsKey(varName);
|
||||
for (MapEntry entry: mapEntries) {
|
||||
if (entry.getName().equals(varName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getIntValueOf(String varName) {
|
||||
// Get start address of variable
|
||||
if (!variableAddresses.containsKey(varName)) {
|
||||
return -1;
|
||||
}
|
||||
int varAddr = ((Integer) variableAddresses.get(varName)).intValue();
|
||||
/* TODO Check correct variable size in below methods */
|
||||
|
||||
public int getIntValueOf(String varName) throws UnknownVariableException {
|
||||
MapEntry entry = getMapEntry(varName);
|
||||
|
||||
int varAddr = entry.getAddress();
|
||||
byte[] varData = getMemorySegment(varAddr, 2);
|
||||
|
||||
int retVal = 0;
|
||||
|
@ -119,46 +139,34 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
|
|||
return Integer.reverseBytes(retVal) >> 16; // Crop two bytes
|
||||
}
|
||||
|
||||
public void setIntValueOf(String varName, int newVal) {
|
||||
// Get start address of variable
|
||||
if (!variableAddresses.containsKey(varName)) {
|
||||
return;
|
||||
}
|
||||
int varAddr = ((Integer) variableAddresses.get(varName)).intValue();
|
||||
public void setIntValueOf(String varName, int newVal) throws UnknownVariableException {
|
||||
MapEntry entry = getMapEntry(varName);
|
||||
int varAddr = entry.getAddress();
|
||||
|
||||
// TODO Check if small/big-endian when coming from JNI?
|
||||
int newValToSet = Integer.reverseBytes(newVal);
|
||||
|
||||
// Create byte array
|
||||
int pos = 0;
|
||||
|
||||
byte[] varData = new byte[4];
|
||||
byte[] varData = new byte[2];
|
||||
varData[pos++] = (byte) ((newValToSet & 0xFF000000) >> 24);
|
||||
varData[pos++] = (byte) ((newValToSet & 0xFF0000) >> 16);
|
||||
varData[pos++] = (byte) ((newValToSet & 0xFF00) >> 8);
|
||||
varData[pos++] = (byte) ((newValToSet & 0xFF) >> 0);
|
||||
|
||||
setMemorySegment(varAddr, varData);
|
||||
}
|
||||
|
||||
public byte getByteValueOf(String varName) {
|
||||
// Get start address of variable
|
||||
if (!variableAddresses.containsKey(varName)) {
|
||||
return -1;
|
||||
}
|
||||
int varAddr = ((Integer) variableAddresses.get(varName)).intValue();
|
||||
public byte getByteValueOf(String varName) throws UnknownVariableException {
|
||||
MapEntry entry = getMapEntry(varName);
|
||||
int varAddr = entry.getAddress();
|
||||
|
||||
byte[] varData = getMemorySegment(varAddr, 1);
|
||||
|
||||
return varData[0];
|
||||
}
|
||||
|
||||
public void setByteValueOf(String varName, byte newVal) {
|
||||
// Get start address of variable
|
||||
if (!variableAddresses.containsKey(varName)) {
|
||||
return;
|
||||
}
|
||||
int varAddr = ((Integer) variableAddresses.get(varName)).intValue();
|
||||
public void setByteValueOf(String varName, byte newVal) throws UnknownVariableException {
|
||||
MapEntry entry = getMapEntry(varName);
|
||||
int varAddr = entry.getAddress();
|
||||
|
||||
byte[] varData = new byte[1];
|
||||
|
||||
|
@ -167,23 +175,17 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
|
|||
setMemorySegment(varAddr, varData);
|
||||
}
|
||||
|
||||
public byte[] getByteArray(String varName, int length) {
|
||||
// Get start address of variable
|
||||
if (!variableAddresses.containsKey(varName)) {
|
||||
return null;
|
||||
}
|
||||
int varAddr = ((Integer) variableAddresses.get(varName)).intValue();
|
||||
public byte[] getByteArray(String varName, int length) throws UnknownVariableException {
|
||||
MapEntry entry = getMapEntry(varName);
|
||||
int varAddr = entry.getAddress();
|
||||
|
||||
// TODO Check if small/big-endian when coming from JNI?
|
||||
return getMemorySegment(varAddr, length);
|
||||
}
|
||||
|
||||
public void setByteArray(String varName, byte[] data) {
|
||||
// Get start address of variable
|
||||
if (!variableAddresses.containsKey(varName)) {
|
||||
return;
|
||||
}
|
||||
int varAddr = ((Integer) variableAddresses.get(varName)).intValue();
|
||||
public void setByteArray(String varName, byte[] data) throws UnknownVariableException {
|
||||
MapEntry entry = getMapEntry(varName);
|
||||
int varAddr = entry.getAddress();
|
||||
|
||||
// TODO Check if small/big-endian when coming from JNI?
|
||||
setMemorySegment(varAddr, data);
|
||||
|
|
Loading…
Reference in a new issue