improved support for MicaZ emulation - added variable watcher functionality

This commit is contained in:
joxe 2009-11-12 12:49:34 +00:00
parent b909a62265
commit be313dd97d
2 changed files with 158 additions and 7 deletions

View file

@ -0,0 +1,146 @@
/*
* Copyright (c) 2009, 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.
*
* $Id: AvrMoteMemory.java,v 1.1 2009/11/12 12:49:34 joxe Exp $
*/
package se.sics.cooja.avrmote;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.log4j.Logger;
import se.sics.cooja.AddressMemory;
import se.sics.cooja.MoteMemory;
import avrora.arch.avr.AVRProperties;
import avrora.core.SourceMapping;
import avrora.core.SourceMapping.Location;
import avrora.sim.AtmelInterpreter;
/**
* @author Joakim Eriksson
*/
public class AvrMoteMemory implements MoteMemory, AddressMemory {
private static Logger logger = Logger.getLogger(AvrMoteMemory.class);
private SourceMapping memoryMap;
private AtmelInterpreter interpreter;
private AVRProperties avrProperties;
public AvrMoteMemory(SourceMapping map, AVRProperties avrProperties, AtmelInterpreter interpreter) {
memoryMap = map;
this.interpreter = interpreter;
this.avrProperties = avrProperties;
}
public void clearMemory() {
logger.fatal("not implemented");
}
public byte[] getMemorySegment(int address, int size) {
logger.fatal("getMemorySegment is not implemented");
return null;
}
public int getTotalSize() {
return 0;
}
public void setMemorySegment(int address, byte[] data) {
logger.fatal("setMemorySegment is not implemented");
}
public byte[] getByteArray(String varName, int length)
throws UnknownVariableException {
return null;
}
public byte getByteValueOf(String varName) throws UnknownVariableException {
return (byte) getValueOf(varName, 1);
}
private int getValueOf(String varName, int len) throws UnknownVariableException {
Location mem = memoryMap.getLocation(varName);
if (mem == null) throw new UnknownVariableException("Variable does not exist: " + varName);
System.out.println("Variable:" + varName + " in section: " + mem.section);
System.out.println("LMA: " + Integer.toHexString(mem.lma_addr));
System.out.println("VMA: " + Integer.toHexString(mem.vma_addr));
System.out.println("Data: " + interpreter.getDataByte(mem.lma_addr & 0xfffff));
System.out.println("Flash: " + interpreter.getFlashByte(mem.lma_addr & 0xfffff));
int data = 0;
if (mem.vma_addr > 0xfffff) {
for (int i = 0; i < len; i++) {
data = (data << 8) + (interpreter.getDataByte((mem.vma_addr & 0xfffff) + i) & 0xff);
System.out.println("Read byte: " + interpreter.getDataByte((mem.vma_addr & 0xfffff) + i) +
" => " + data);
}
} else {
for (int i = 0; i < len; i++) {
data = (data << 8) + interpreter.getFlashByte(mem.vma_addr + i) & 0xff;
}
}
return data;
}
public int getIntValueOf(String varName) throws UnknownVariableException {
return getValueOf(varName, 2);
}
public int getIntegerLength() {
return 2;
}
public int getVariableAddress(String varName)
throws UnknownVariableException {
return 0;
}
public String[] getVariableNames() {
ArrayList<String> symbols = new ArrayList<String>();
for (Iterator i = memoryMap.getIterator(); i.hasNext();) {
symbols.add(((Location) i.next()).name);
}
return symbols.toArray(new String[0]);
}
public void setByteArray(String varName, byte[] data)
throws UnknownVariableException {
}
public void setByteValueOf(String varName, byte newVal)
throws UnknownVariableException {
}
public void setIntValueOf(String varName, int newVal)
throws UnknownVariableException {
}
public boolean variableExists(String varName) {
return false;
}
}

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: MicaZMote.java,v 1.9 2009/10/30 09:42:50 fros4943 Exp $
* $Id: MicaZMote.java,v 1.10 2009/11/12 12:49:34 joxe Exp $
*/
package se.sics.cooja.avrmote;
@ -45,7 +45,10 @@ import se.sics.cooja.MoteMemory;
import se.sics.cooja.MoteType;
import se.sics.cooja.Simulation;
import se.sics.cooja.motes.AbstractEmulatedMote;
import se.sics.cooja.mspmote.MspMoteMemory;
import avrora.arch.avr.AVRProperties;
import avrora.core.LoadableProgram;
import avrora.sim.AtmelInterpreter;
import avrora.sim.Interpreter;
import avrora.sim.Simulator;
import avrora.sim.State;
@ -67,8 +70,9 @@ public class MicaZMote extends AbstractEmulatedMote implements Mote {
private Microcontroller myCpu = null;
private MicaZ micaZ = null;
private LoadableProgram program = null;
private Interpreter interpreter = null;
private AtmelInterpreter interpreter = null;
private AvrMoteMemory myMemory = null;
private AVRProperties avrProperties = null;
private MicaZMoteType myMoteType = null;
/* Stack monitoring variables */
@ -144,9 +148,11 @@ public class MicaZMote extends AbstractEmulatedMote implements Mote {
PlatformFactory factory = new MicaZ.Factory();
micaZ = (MicaZ) factory.newPlatform(1, program.getProgram());
myCpu = micaZ.getMicrocontroller();
avrProperties = (AVRProperties) myCpu.getProperties();
Simulator sim = myCpu.getSimulator();
interpreter = sim.getInterpreter();
interpreter = (AtmelInterpreter) sim.getInterpreter();
// State state = interpreter.getState();
myMemory = new AvrMoteMemory(program.getProgram().getSourceMapping(), avrProperties, interpreter);
}
public void setState(State newState) {
@ -267,12 +273,11 @@ public class MicaZMote extends AbstractEmulatedMote implements Mote {
}
public MoteMemory getMemory() {
/* TODO Implement */
return null;
return myMemory;
}
public void setMemory(MoteMemory memory) {
/* TODO Implement */
myMemory = (AvrMoteMemory) memory;
}
public String toString() {