[cooja] memory: Removed MoteMemory class including all references

This commit is contained in:
Enrico Joerns 2014-07-23 10:12:19 +02:00
parent 9dd29d56c9
commit 482dab5d16
10 changed files with 127 additions and 257 deletions

View file

@ -34,7 +34,6 @@ import java.util.Iterator;
import org.apache.log4j.Logger;
import org.contikios.cooja.AddressMemory;
import org.contikios.cooja.MoteMemory;
import avrora.arch.avr.AVRProperties;
import avrora.core.SourceMapping;
import avrora.core.SourceMapping.Location;
@ -46,7 +45,7 @@ import org.contikios.cooja.mote.memory.MemoryLayout;
/**
* @author Joakim Eriksson
*/
public class AvrMoteMemory implements MemoryInterface, MoteMemory, AddressMemory {
public class AvrMoteMemory implements MemoryInterface, AddressMemory {
private static Logger logger = Logger.getLogger(AvrMoteMemory.class);
private SourceMapping memoryMap;
@ -63,22 +62,11 @@ public class AvrMoteMemory implements MemoryInterface, MoteMemory, AddressMemory
interpreter.getSimulator().insertWatch(w, address);
}
@Override
public byte[] getMemorySegment(int address, int size) {
logger.fatal("getMemorySegment is not implemented");
return null;
}
@Override
public int getTotalSize() {
return 0;
}
@Override
public void setMemorySegment(int address, byte[] data) {
logger.fatal("setMemorySegment is not implemented");
}
@Override
public byte[] getByteArray(String varName, int length)
throws UnknownVariableException {
@ -182,22 +170,6 @@ public class AvrMoteMemory implements MemoryInterface, MoteMemory, AddressMemory
return memoryMap.getLocation(varName) != null;
}
@Override
public boolean addMemoryMonitor(int address, int size, MemoryMonitor mm) {
logger.warn("Not implemented");
return false;
}
@Override
public void removeMemoryMonitor(int address, int size, MemoryMonitor mm) {
}
@Override
public int parseInt(byte[] memorySegment) {
logger.warn("Not implemented");
return 0;
}
@Override
public byte[] getMemory() throws MoteMemoryException {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

View file

@ -40,7 +40,6 @@ import org.jdom.Element;
import org.contikios.cooja.Mote;
import org.contikios.cooja.MoteInterface;
import org.contikios.cooja.MoteInterfaceHandler;
import org.contikios.cooja.MoteMemory;
import org.contikios.cooja.MoteType;
import org.contikios.cooja.Simulation;
import org.contikios.cooja.mote.memory.MemoryInterface;
@ -273,7 +272,7 @@ public class MicaZMote extends AbstractEmulatedMote implements Mote {
return myMemory;
}
public void setMemory(MoteMemory memory) {
public void setMemory(AvrMoteMemory memory) {
myMemory = (AvrMoteMemory) memory;
}

View file

@ -46,7 +46,6 @@ import org.contikios.cooja.Cooja;
import org.contikios.cooja.Mote;
import org.contikios.cooja.MoteInterface;
import org.contikios.cooja.MoteInterfaceHandler;
import org.contikios.cooja.MoteMemory;
import org.contikios.cooja.MoteType;
import org.contikios.cooja.Simulation;
import org.contikios.cooja.Watchpoint;
@ -194,8 +193,8 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
return myMemory;
}
public void setMemory(MoteMemory memory) {
myMemory = (MspMoteMemory) memory;
public void setMemory(MspMoteMemory memory) {
myMemory = memory;
}
/**

View file

@ -35,15 +35,12 @@ import org.apache.log4j.Logger;
import org.contikios.cooja.AddressMemory;
import org.contikios.cooja.Mote;
import org.contikios.cooja.MoteMemory;
import org.contikios.cooja.mote.memory.MemoryInterface;
import org.contikios.cooja.mote.memory.MemoryLayout;
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;
public class MspMoteMemory implements MemoryInterface, MoteMemory, AddressMemory {
public class MspMoteMemory implements MemoryInterface, AddressMemory {
private static Logger logger = Logger.getLogger(MspMoteMemory.class);
private final ArrayList<MapEntry> mapEntries;
@ -90,31 +87,31 @@ public class MspMoteMemory implements MemoryInterface, MoteMemory, AddressMemory
return 2;
}
@Override
public byte[] getMemorySegment(int address, int size) {
int[] memInts = new int[size];
System.arraycopy(cpu.memory, 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
public void setMemorySegment(int address, byte[] data) {
/* 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, address, data.length);
}
// @Override
// public byte[] getMemorySegment(int address, int size) {
// int[] memInts = new int[size];
//
// System.arraycopy(cpu.memory, 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
// public void setMemorySegment(int address, byte[] data) {
// /* 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, address, data.length);
// }
@Override
public int getTotalSize() {
@ -198,7 +195,7 @@ public class MspMoteMemory implements MemoryInterface, MoteMemory, AddressMemory
setMemorySegment(varAddr, data);
}
private ArrayList<MemoryCPUMonitor> cpuMonitorArray = new ArrayList<MemoryCPUMonitor>();
// private ArrayList<MemoryCPUMonitor> cpuMonitorArray = new ArrayList<MemoryCPUMonitor>();
@Override
public byte[] getMemory() throws MoteMemoryException {
@ -245,55 +242,6 @@ public class MspMoteMemory implements MemoryInterface, MoteMemory, AddressMemory
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
class MemoryCPUMonitor extends se.sics.mspsim.core.MemoryMonitor.Adapter {
public final MemoryMonitor mm;
public final int address;
public final int size;
public MemoryCPUMonitor(MemoryMonitor mm, int address, int size) {
this.mm = mm;
this.address = address;
this.size = size;
}
@Override
public void notifyReadAfter(int address, AccessMode mode, AccessType type) {
mm.memoryChanged(MspMoteMemory.this, MemoryEventType.READ, address);
}
@Override
public void notifyWriteAfter(int dstAddress, int data, AccessMode mode) {
mm.memoryChanged(MspMoteMemory.this, MemoryEventType.WRITE, dstAddress);
}
}
@Override
public boolean addMemoryMonitor(int address, int size, MemoryMonitor mm) {
MemoryCPUMonitor t = new MemoryCPUMonitor(mm, address, size);
cpuMonitorArray.add(t);
for (int a = address; a < address+size; a++) {
cpu.addWatchPoint(a, t);
}
return true;
}
@Override
public void removeMemoryMonitor(int address, int size, MemoryMonitor mm) {
for (MemoryCPUMonitor mcm: cpuMonitorArray) {
if (mcm.mm != mm || mcm.address != address || mcm.size != size) {
continue;
}
for (int a = address; a < address+size; a++) {
cpu.removeWatchPoint(a, mcm);
}
cpuMonitorArray.remove(mcm);
break;
}
}
@Override
public int parseInt(byte[] memorySegment) {
if (memorySegment.length < 2) {
return -1;

View file

@ -1,90 +0,0 @@
/*
* Copyright (c) 2006, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
package org.contikios.cooja;
/**
* This interface represents a mote memory.
*
* Mote memory is represented by byte arrays and this
* interface provides a few of basic operations.
*
* Note that this memory internally may consist of several
* different memory sections, not covering the entire range
* between the start address and the end address of this memory.
*
* @see org.contikios.cooja.SectionMoteMemory
* @author Fredrik Osterlind
*/
public interface MoteMemory extends AddressMemory {
/**
* Clears the entire memory.
*/
public void clearMemory();
/**
* Returns a memory segment.
*
* @param address Start address of memory segment
* @param size Size of memory segment
* @return Memory segment or null if segment not available
*/
public byte[] getMemorySegment(int address, int size);
/**
* Sets a memory segment.
*
* @param address Start address of memory segment
* @param data Data
*/
public void setMemorySegment(int address, byte[] data);
/**
* Returns the sum of all byte array sizes in this memory.
* This is not neccessarily the the same as the total memory range,
* since the entire memory range may not be handled by this memory.
*
* @return Total size
*/
public int getTotalSize();
public abstract int parseInt(byte[] memorySegment);
public enum MemoryEventType { READ, WRITE };
public interface MemoryMonitor {
public void memoryChanged(MoteMemory memory, MemoryEventType type, int address);
}
public boolean addMemoryMonitor(int address, int size, MemoryMonitor mm);
public void removeMemoryMonitor(int address, int size, MemoryMonitor mm);
}

View file

@ -46,7 +46,7 @@ import org.contikios.cooja.mote.memory.MemoryLayout;
*
* @author Fredrik Osterlind
*/
public class SectionMoteMemory implements MemoryInterface, MoteMemory, AddressMemory {
public class SectionMoteMemory implements MemoryInterface, AddressMemory {
private static Logger logger = Logger.getLogger(SectionMoteMemory.class);
private ArrayList<MoteMemorySection> sections = new ArrayList<MoteMemorySection>();
@ -94,48 +94,48 @@ public class SectionMoteMemory implements MemoryInterface, MoteMemory, AddressMe
sections.clear();
}
@Override
public byte[] getMemorySegment(int address, int size) {
/* Cooja address space */
address -= offset;
for (MoteMemorySection section : sections) {
if (section.includesAddr(address)
&& section.includesAddr(address + size - 1)) {
return section.getMemorySegment(address, size);
}
}
/* Check if in readonly section */
for (MoteMemorySection section : readonlySections) {
if (section.includesAddr(address)
&& section.includesAddr(address + size - 1)) {
return section.getMemorySegment(address, size);
}
}
return null;
}
// @Override
// public byte[] getMemorySegment(int address, int size) {
// /* Cooja address space */
// address -= offset;
//
// for (MoteMemorySection section : sections) {
// if (section.includesAddr(address)
// && section.includesAddr(address + size - 1)) {
// return section.getMemorySegment(address, size);
// }
// }
//
// /* Check if in readonly section */
// for (MoteMemorySection section : readonlySections) {
// if (section.includesAddr(address)
// && section.includesAddr(address + size - 1)) {
// return section.getMemorySegment(address, size);
// }
// }
//
// return null;
// }
public void setMemorySegmentNative(int address, byte[] data) {
setMemorySegment(address+offset, data);
}
@Override
public void setMemorySegment(int address, byte[] data) {
/* Cooja address space */
address -= offset;
/* TODO XXX Sections may overlap */
for (MoteMemorySection section : sections) {
if (section.includesAddr(address)
&& section.includesAddr(address + data.length - 1)) {
section.setMemorySegment(address, data);
return;
}
}
sections.add(new MoteMemorySection(address, data));
}
// @Override
// public void setMemorySegment(int address, byte[] data) {
// /* Cooja address space */
// address -= offset;
//
// /* TODO XXX Sections may overlap */
// for (MoteMemorySection section : sections) {
// if (section.includesAddr(address)
// && section.includesAddr(address + data.length - 1)) {
// section.setMemorySegment(address, data);
// return;
// }
// }
// sections.add(new MoteMemorySection(address, data));
// }
public void setReadonlyMemorySegment(int address, byte[] data) {
/* Cooja address space */
@ -271,6 +271,11 @@ public class SectionMoteMemory implements MemoryInterface, MoteMemory, AddressMe
setMemorySegment(varAddr, data);
}
@Override
public byte[] getMemory() throws MoteMemoryException {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public byte[] getMemorySegment(long addr, int size) throws MoteMemoryException {
throw new UnsupportedOperationException("Not supported yet.");
@ -430,12 +435,12 @@ public class SectionMoteMemory implements MemoryInterface, MoteMemory, AddressMe
}
private class PolledMemorySegments {
public final MemoryMonitor mm;
public final SegmentMonitor mm;
public final int address;
public final int size;
private byte[] oldMem;
public PolledMemorySegments(MemoryMonitor mm, int address, int size) {
public PolledMemorySegments(SegmentMonitor mm, int address, int size) {
this.mm = mm;
this.address = address;
this.size = size;
@ -449,20 +454,20 @@ public class SectionMoteMemory implements MemoryInterface, MoteMemory, AddressMe
return;
}
mm.memoryChanged(SectionMoteMemory.this, MemoryEventType.WRITE, address);
mm.memoryChanged(SectionMoteMemory.this, SegmentMonitor.EventType.WRITE, address);
oldMem = newMem;
}
}
@Override
public boolean addMemoryMonitor(int address, int size, MemoryMonitor mm) {
// @Override
public boolean addMemoryMonitor(int address, int size, SegmentMonitor mm) {
PolledMemorySegments t = new PolledMemorySegments(mm, address, size);
polledMemories.add(t);
return true;
}
@Override
public void removeMemoryMonitor(int address, int size, MemoryMonitor mm) {
// @Override
public void removeMemoryMonitor(int address, int size, SegmentMonitor mm) {
for (PolledMemorySegments mcm: polledMemories) {
if (mcm.mm != mm || mcm.address != address || mcm.size != size) {
continue;
@ -472,7 +477,7 @@ public class SectionMoteMemory implements MemoryInterface, MoteMemory, AddressMe
}
}
@Override
// @Override
public int parseInt(byte[] memorySegment) {
int retVal = 0;
int pos = 0;

View file

@ -38,7 +38,6 @@ import org.jdom.Element;
import org.contikios.cooja.Mote;
import org.contikios.cooja.MoteInterface;
import org.contikios.cooja.MoteInterfaceHandler;
import org.contikios.cooja.MoteMemory;
import org.contikios.cooja.MoteType;
import org.contikios.cooja.SectionMoteMemory;
import org.contikios.cooja.Simulation;
@ -103,8 +102,8 @@ public class ContikiMote extends AbstractWakeupMote implements Mote {
return myMemory;
}
public void setMemory(MoteMemory memory) {
myMemory = (SectionMoteMemory) memory;
public void setMemory(SectionMoteMemory memory) {
myMemory = memory;
}
@Override

View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 2013, Enrico Joerns
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
package org.contikios.cooja.mote.memory;
/**
* Unknown variable name exception.
*/
public class UnknownVariableException extends RuntimeException {
public UnknownVariableException(String varName) {
super("Unknown variable name: " + varName);
}
}

View file

@ -39,7 +39,6 @@ import org.jdom.Element;
import org.contikios.cooja.Mote;
import org.contikios.cooja.MoteInterface;
import org.contikios.cooja.MoteInterfaceHandler;
import org.contikios.cooja.MoteMemory;
import org.contikios.cooja.MoteType;
import org.contikios.cooja.RadioPacket;
import org.contikios.cooja.SectionMoteMemory;
@ -116,7 +115,7 @@ public abstract class AbstractApplicationMote extends AbstractWakeupMote impleme
return memory;
}
public void setMemory(MoteMemory memory) {
public void setMemory(SectionMoteMemory memory) {
this.memory = (SectionMoteMemory) memory;
}

View file

@ -89,8 +89,6 @@ import org.jdom.Element;
import org.contikios.cooja.ClassDescription;
import org.contikios.cooja.Cooja;
import org.contikios.cooja.Mote;
import org.contikios.cooja.MoteMemory;
import org.contikios.cooja.MoteMemory.MemoryEventType;
import org.contikios.cooja.Plugin;
import org.contikios.cooja.PluginType;
import org.contikios.cooja.SimEventCentral.MoteCountListener;