[cooja] Implementation of former MspMoteMemory dummy functions

This commit is contained in:
Enrico Joerns 2014-07-23 11:30:44 +02:00
parent e5a35821c3
commit 434c4db1a2
2 changed files with 90 additions and 28 deletions

View File

@ -34,7 +34,6 @@ import java.awt.Component;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.nio.ByteOrder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Hashtable; import java.util.Hashtable;
@ -52,7 +51,6 @@ import org.contikios.cooja.Watchpoint;
import org.contikios.cooja.WatchpointMote; import org.contikios.cooja.WatchpointMote;
import org.contikios.cooja.interfaces.IPAddress; import org.contikios.cooja.interfaces.IPAddress;
import org.contikios.cooja.mote.memory.MemoryInterface; import org.contikios.cooja.mote.memory.MemoryInterface;
import org.contikios.cooja.mote.memory.MemoryLayout;
import org.contikios.cooja.motes.AbstractEmulatedMote; import org.contikios.cooja.motes.AbstractEmulatedMote;
import org.contikios.cooja.mspmote.interfaces.Msp802154Radio; import org.contikios.cooja.mspmote.interfaces.Msp802154Radio;
import org.contikios.cooja.mspmote.interfaces.MspSerial; import org.contikios.cooja.mspmote.interfaces.MspSerial;
@ -107,7 +105,6 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
public MspMote(MspMoteType moteType, Simulation simulation) { public MspMote(MspMoteType moteType, Simulation simulation) {
this.simulation = simulation; this.simulation = simulation;
myMoteType = moteType; myMoteType = moteType;
new MemoryLayout(ByteOrder.LITTLE_ENDIAN, MemoryLayout.ARCH_16BIT, 2);
/* Schedule us immediately */ /* Schedule us immediately */
requestImmediateWakeup(); requestImmediateWakeup();

View File

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2014, TU Braunschweig. All rights reserved.
* Copyright (c) 2007, Swedish Institute of Computer Science. All rights * Copyright (c) 2007, Swedish Institute of Computer Science. All rights
* reserved. * reserved.
* *
@ -28,20 +29,27 @@
package org.contikios.cooja.mspmote; package org.contikios.cooja.mspmote;
import java.nio.ByteOrder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.contikios.cooja.Mote; import org.contikios.cooja.Mote;
import org.contikios.cooja.mote.memory.MemoryInterface; import org.contikios.cooja.mote.memory.MemoryInterface;
import org.contikios.cooja.mote.memory.MemoryInterface.SegmentMonitor.EventType;
import org.contikios.cooja.mote.memory.MemoryLayout; import org.contikios.cooja.mote.memory.MemoryLayout;
import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.MSP430;
import se.sics.mspsim.core.Memory.AccessMode;
import se.sics.mspsim.core.Memory.AccessType;
import se.sics.mspsim.util.MapEntry; import se.sics.mspsim.util.MapEntry;
public class MspMoteMemory implements MemoryInterface { public class MspMoteMemory implements MemoryInterface {
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 final MemoryLayout memLayout;
private final MSP430 cpu; private final MSP430 cpu;
@ -55,6 +63,7 @@ public class MspMoteMemory implements MemoryInterface {
} }
this.cpu = cpu; this.cpu = cpu;
memLayout = new MemoryLayout(ByteOrder.LITTLE_ENDIAN, MemoryLayout.ARCH_16BIT, 2);
} }
@Override @Override
@ -68,55 +77,111 @@ public class MspMoteMemory implements MemoryInterface {
} }
@Override @Override
public byte[] getMemorySegment(long addr, int size) throws MoteMemoryException { public byte[] getMemorySegment(long address, int size) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. int[] memInts = new int[size];
System.arraycopy(cpu.memory, (int) address, memInts, 0, size);
/* Convert to byte array */
byte[] memBytes = new byte[size];
for (int i = 0; i < size; i++) {
memBytes[i] = (byte) memInts[i];
}
return memBytes;
} }
@Override @Override
public void setMemorySegment(long addr, byte[] data) throws MoteMemoryException { public void setMemorySegment(long address, byte[] data) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. /* Convert to int array */
int[] memInts = new int[data.length];
for (int i = 0; i < data.length; i++) {
memInts[i] = data[i];
}
System.arraycopy(memInts, 0, cpu.memory, (int) address, data.length);
} }
@Override @Override
public void clearMemory() { public void clearMemory() {
throw new UnsupportedOperationException("Not supported yet."); Arrays.fill(cpu.memory, 0);
} }
@Override @Override
public long getStartAddr() { public long getStartAddr() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. return 0;// XXXX
} }
@Override @Override
public Map<String, Symbol> getSymbolMap() { public Map<String, Symbol> getSymbolMap() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. Map<String, Symbol> vars = new HashMap<>();
for (MapEntry entry : mapEntries) {
if (entry.getType() != MapEntry.TYPE.variable) {
continue;
}
vars.put(entry.getName(), new Symbol(
Symbol.Type.VARIABLE,
entry.getName(),
entry.getAddress(),
entry.getSize()));
}
return vars;
} }
@Override @Override
public MemoryLayout getLayout() { public MemoryLayout getLayout() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. return memLayout;
}
private final ArrayList<MemoryCPUMonitor> cpuMonitorArray = new ArrayList<>();
class MemoryCPUMonitor extends se.sics.mspsim.core.MemoryMonitor.Adapter {
public final SegmentMonitor mm;
public final int address;
public final int size;
public MemoryCPUMonitor(SegmentMonitor mm, int address, int size) {
this.mm = mm;
this.address = address;
this.size = size;
} }
@Override @Override
public boolean addSegmentMonitor(SegmentMonitor.EventType flag, long address, int size, SegmentMonitor monitor) { public void notifyReadAfter(int address, AccessMode mode, AccessType type) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. mm.memoryChanged(MspMoteMemory.this, EventType.READ, address);
} }
@Override @Override
public boolean removeSegmentMonitor(long address, int size, SegmentMonitor monitor) { public void notifyWriteAfter(int dstAddress, int data, AccessMode mode) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. mm.memoryChanged(MspMoteMemory.this, EventType.WRITE, dstAddress);
}
} }
public int parseInt(byte[] memorySegment) { @Override
if (memorySegment.length < 2) { public boolean addSegmentMonitor(EventType type, long address, int size, SegmentMonitor mm) {
return -1; MemoryCPUMonitor t = new MemoryCPUMonitor(mm, (int) address, size);
cpuMonitorArray.add(t);
for (int a = (int) address; a < address + size; a++) {
cpu.addWatchPoint(a, t);
} }
int retVal = 0; return true;
int pos = 0; }
retVal += ((memorySegment[pos++] & 0xFF)) << 8;
retVal += ((memorySegment[pos++] & 0xFF)) << 0;
return Integer.reverseBytes(retVal) >> 16; @Override
public boolean removeSegmentMonitor(long address, int size, SegmentMonitor mm) {
for (MemoryCPUMonitor mcm : cpuMonitorArray) {
if (mcm.mm != mm || mcm.address != address || mcm.size != size) {
continue;
}
for (int a = (int) address; a < (int) address + size; a++) {
cpu.removeWatchPoint(a, mcm);
}
cpuMonitorArray.remove(mcm);
return true;
}
return false;
} }
} }