From: <jo...@us...> - 2007-10-24 10:44:57
|
Revision: 4 http://mspsim.svn.sourceforge.net/mspsim/?rev=4&view=rev Author: joxe Date: 2007-10-24 03:44:41 -0700 (Wed, 24 Oct 2007) Log Message: ----------- initial add of mspsim Added Paths: ----------- mspsim/se/ mspsim/se/sics/ mspsim/se/sics/mspsim/ mspsim/se/sics/mspsim/chip/ mspsim/se/sics/mspsim/chip/Beeper.java mspsim/se/sics/mspsim/chip/CC2420.java mspsim/se/sics/mspsim/core/ mspsim/se/sics/mspsim/core/BasicClockModule.java mspsim/se/sics/mspsim/core/CPUMonitor.java mspsim/se/sics/mspsim/core/DbgInstruction.java mspsim/se/sics/mspsim/core/DisAsm.java mspsim/se/sics/mspsim/core/IOPort.java mspsim/se/sics/mspsim/core/IOUnit.java mspsim/se/sics/mspsim/core/MSP430.java mspsim/se/sics/mspsim/core/MSP430Constants.java mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/se/sics/mspsim/core/MapTable.java mspsim/se/sics/mspsim/core/Multiplier.java mspsim/se/sics/mspsim/core/PortListener.java mspsim/se/sics/mspsim/core/SFR.java mspsim/se/sics/mspsim/core/Timer.java mspsim/se/sics/mspsim/core/USART.java mspsim/se/sics/mspsim/core/USARTListener.java mspsim/se/sics/mspsim/platform/ mspsim/se/sics/mspsim/platform/esb/ mspsim/se/sics/mspsim/platform/esb/CVS/ mspsim/se/sics/mspsim/platform/esb/CVS/Entries mspsim/se/sics/mspsim/platform/esb/CVS/Repository mspsim/se/sics/mspsim/platform/esb/CVS/Root mspsim/se/sics/mspsim/platform/esb/ESBGui.java mspsim/se/sics/mspsim/platform/esb/ESBNode.java mspsim/se/sics/mspsim/platform/sky/ mspsim/se/sics/mspsim/platform/sky/CVS/ mspsim/se/sics/mspsim/platform/sky/CVS/Entries mspsim/se/sics/mspsim/platform/sky/CVS/Repository mspsim/se/sics/mspsim/platform/sky/CVS/Root mspsim/se/sics/mspsim/platform/sky/ExtFlash.java mspsim/se/sics/mspsim/platform/sky/SkyGui.java mspsim/se/sics/mspsim/platform/sky/SkyNode.java mspsim/se/sics/mspsim/util/ mspsim/se/sics/mspsim/util/ControlUI.java mspsim/se/sics/mspsim/util/DebugUI.java mspsim/se/sics/mspsim/util/DotDiagram.java mspsim/se/sics/mspsim/util/ELF.java mspsim/se/sics/mspsim/util/ELFProgram.java mspsim/se/sics/mspsim/util/ELFSection.java mspsim/se/sics/mspsim/util/IHexReader.java mspsim/se/sics/mspsim/util/SerialMon.java mspsim/se/sics/mspsim/util/StackUI.java mspsim/se/sics/mspsim/util/Test.java mspsim/se/sics/mspsim/util/Utils.java mspsim/se/sics/mspsim/util/WindowUtils.java Added: mspsim/se/sics/mspsim/chip/Beeper.java =================================================================== --- mspsim/se/sics/mspsim/chip/Beeper.java (rev 0) +++ mspsim/se/sics/mspsim/chip/Beeper.java 2007-10-24 10:44:41 UTC (rev 4) @@ -0,0 +1,148 @@ +/** + * Copyright (c) 2007, 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. + * + * This file is part of MSPSim. + * + * $Id: Beeper.java,v 1.3 2007/10/21 21:17:33 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * Beeper + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 21:17:33 $ + * $Revision: 1.3 $ + */ + +package se.sics.mspsim.chip; +import javax.sound.sampled.*; +import se.sics.mspsim.core.*; + +/** + * Beeper for the esb... + */ +public class Beeper extends IOUnit { + + private SourceDataLine dataLine; + private FloatControl volume; + + public static final int SAMPLE_RATE = 44000; + + public static final int FRQ_1 = 2200; + + public static final int WAVE_LEN = (SAMPLE_RATE / FRQ_1); + + // One second of the sound in buffer + byte[] buffer = new byte[WAVE_LEN]; + byte[] quiet = new byte[WAVE_LEN]; + + int beepCtr = 0; + + public Beeper() { + super(null, 0); + AudioFormat af = new AudioFormat(SAMPLE_RATE, 8, 1, true, false); + DataLine.Info dli = + new DataLine.Info(SourceDataLine.class, af, 16384); + try { + dataLine = (SourceDataLine) AudioSystem.getLine(dli); + if (dataLine == null) { + System.out.println("DataLine: not existing..."); + } else { + dataLine.open(dataLine.getFormat(), 16384); + volume = (FloatControl) dataLine.getControl(FloatControl.Type.MASTER_GAIN); + } + } catch (Exception e) { + System.out.println("Problem while getting data line " + e); + } + double f1 = 0; + for (int i = 0, n = WAVE_LEN; i < n; i++) { + f1 = Math.sin(i * 3.141592 * 2 / WAVE_LEN) * 40; + f1 += Math.sin(i * 3.141592 * 4 / WAVE_LEN) * 30; + buffer[i] = (byte) (f1); + } + + if (dataLine != null) { + dataLine.start(); + } + } + + public void setVolue(int vol) { + volume.setValue(vol); + } + + public void beepOn(boolean beep) { + if (beep) { + beepCtr = 7; + } + } + + public long ioTick(long cycles) { + // Avoid blocking using timer... + if (dataLine != null) { + if (dataLine.available() > WAVE_LEN * 2) { + if (beepCtr > 0) { + dataLine.write(buffer, 0, WAVE_LEN); + beepCtr--; + } else { + dataLine.write(quiet, 0, WAVE_LEN); + } + } + } + return cycles + 1000; + } + + + public int read(int address, boolean word, long cycler) { + return 0; + } + + public void write(int address, int data, boolean word, long cycler) { + } + + public String getName() { + return "Beeper"; + } + + // Nothing for interrupts... + public void interruptServiced() { + } + + public static void main(String[] args) { + Beeper beep = new Beeper(); + while (true) { + beep.beepOn(true); + for (int i = 0, n = 1000; i < n; i++) { + beep.ioTick(0); + } + beep.beepOn(false); + for (int i = 0, n = 10000; i < n; i++) { + beep.ioTick(0); + } + } + } +} Added: mspsim/se/sics/mspsim/chip/CC2420.java =================================================================== --- mspsim/se/sics/mspsim/chip/CC2420.java (rev 0) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2007-10-24 10:44:41 UTC (rev 4) @@ -0,0 +1,345 @@ +/** + * Copyright (c) 2007, 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. + * + * This file is part of MSPSim. + * + * $Id: CC2420.java,v 1.4 2007/10/22 18:03:41 joakime Exp $ + * + * ----------------------------------------------------------------- + * + * CC2420 + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/22 18:03:41 $ + * $Revision: 1.4 $ + */ + +package se.sics.mspsim.chip; +import se.sics.mspsim.core.*; +import se.sics.mspsim.util.Utils; + +public class CC2420 implements USARTListener { + + public static final boolean DEBUG = true; + + public static final int REG_SNOP = 0x00; + public static final int REG_SXOSCON = 0x01; + public static final int REG_STXCAL = 0x02; + public static final int REG_SRXON = 0x03; + public static final int REG_STXON = 0x04; + public static final int REG_STXONCCA = 0x05; + public static final int REG_SRFOFF = 0x06; + public static final int REG_SXOSCOFF = 0x07; + public static final int REG_SFLUSHRX = 0x08; + public static final int REG_SFLUSHTX = 0x09; + public static final int REG_SACK = 0x0A; + public static final int REG_SACKPEND = 0x0B; + public static final int REG_SRXDEC = 0x0C; + public static final int REG_STXENC = 0x0D; + public static final int REG_SAES = 0x0E; + public static final int REG_foo = 0x0F; + public static final int REG_MAIN = 0x10; + public static final int REG_MDMCTRL0 = 0x11; + public static final int REG_MDMCTRL1 = 0x12; + public static final int REG_RSSI = 0x13; + public static final int REG_SYNCWORD = 0x14; + public static final int REG_TXCTRL = 0x15; + public static final int REG_RXCTRL0 = 0x16; + public static final int REG_RXCTRL1 = 0x17; + public static final int REG_FSCTRL = 0x18; + public static final int REG_SECCTRL0 = 0x19; + public static final int REG_SECCTRL1 = 0x1A; + public static final int REG_BATTMON = 0x1B; + public static final int REG_IOCFG0 = 0x1C; + public static final int REG_IOCFG1 = 0x1D; + public static final int REG_MANFIDL = 0x1E; + public static final int REG_MANFIDH = 0x1F; + public static final int REG_FSMTC = 0x20; + public static final int REG_MANAND = 0x21; + public static final int REG_MANOR = 0x22; + public static final int REG_AGCCTRL = 0x23; + public static final int REG_AGCTST0 = 0x24; + public static final int REG_AGCTST1 = 0x25; + public static final int REG_AGCTST2 = 0x26; + public static final int REG_FSTST0 = 0x27; + public static final int REG_FSTST1 = 0x28; + public static final int REG_FSTST2 = 0x29; + public static final int REG_FSTST3 = 0x2A; + public static final int REG_RXBPFTST = 0x2B; + public static final int REG_FSMSTATE = 0x2C; + public static final int REG_ADCTST = 0x2D; + public static final int REG_DACTST = 0x2E; + public static final int REG_TOPTST = 0x2F; + public static final int REG_RESERVED = 0x30; + /* 0x31 - 0x3D not used */ + public static final int REG_TXFIFO = 0x3E; + public static final int REG_RXFIFO = 0x3F; + + public static final int ST_XOSC16M_STABLE = 1 << 6; + public static final int ST_TX_UNDERFLOW = 1 << 5; + public static final int ST_ENC_BUSY = 1 << 4; + public static final int ST_TX_ACTIVE = 1 << 3; + public static final int ST_LOCK = 1 << 2; + public static final int ST_RSSI_VALID = 1 << 1; + + // RAM Addresses + public static final int RAM_TXFIFO = 0x000; + public static final int RAM_RXFIFO = 0x080; + public static final int RAM_KEY0 = 0x100; + public static final int RAM_RXNONCE = 0x110; + public static final int RAM_SABUF = 0x120; + public static final int RAM_KEY1 = 0x130; + public static final int RAM_TXNONCE = 0x140; + public static final int RAM_CBCSTATE = 0x150; + public static final int RAM_IEEEADDR = 0x160; + public static final int RAM_PANID = 0x168; + public static final int RAM_SHORTADDR = 0x16A; + + // when reading registrers this flag is set! + public static final int FLAG_READ = 0x40; + + public static final int FLAG_RAM = 0x80; + // When accessing RAM the second byte of the address comtains + // a flag indicating read/write + public static final int FLAG_RAM_READ = 0x20; + + + public static final int WAITING = 0; + public static final int WRITE_REGISTER = 1; + public static final int READ_REGISTER = 2; + public static final int RAM_ACCESS = 3; + + public static final int READ_RXFIFO = 4; + public static final int WRITE_TXFIFO = 5; + + private int state = WAITING; + private int pos; + private int address; + private boolean ramRead = false; + + private int status = ST_XOSC16M_STABLE; + + private int[] registers = new int[64]; + // More than needed... + private int[] memory = new int[512]; + + private boolean chipSelect; + + private IOPort ccaPort = null; + private int ccaPin; + + private IOPort fifopPort = null; + private int fifopPin; + + private IOPort fifoPort = null; + private int fifoPin; + + private boolean rxPacket; + private int rxCursor; + private int rxLen; + + public CC2420() { + registers[REG_SNOP] = 0; + } + + public void dataReceived(USART source, int data) { + if (chipSelect) { + System.out.println("CC2420 byte received: " + Utils.hex8(data) + + '\'' + (char) data + '\'' + + " CS: " + chipSelect + " state: " + state); + switch(state) { + case WAITING: + state = WRITE_REGISTER; + if ((data & FLAG_READ) != 0) { + state = READ_REGISTER; + } + if ((data & FLAG_RAM) != 0) { + state = RAM_ACCESS; + address = data & 0x7f; + } else { + // The register address + address = data & 0x3f; + + if (address == REG_RXFIFO) { + // check read/write??? + System.out.println("CC2420: Reading RXFIFO!!!"); + state = READ_RXFIFO; + } else if (address == REG_TXFIFO) { + state = WRITE_TXFIFO; + } + } + if (data < 0x0f) { + strobe(data); + } + pos = 0; + // Assuming that the status always is sent back??? + source.byteReceived(status); + break; + case WRITE_REGISTER: + if (pos == 0) { + source.byteReceived(registers[address] >> 8); + // set the high bits + registers[address] = registers[address] & 0xff | (data << 8); + } else { + source.byteReceived(registers[address] & 0xff); + // set the low bits + registers[address] = registers[address] & 0xff00 | data; + System.out.println("CC2420: wrote to " + Utils.hex8(address) + " = " + + registers[address]); + } + break; + case READ_REGISTER: + if (pos == 0) { + source.byteReceived(registers[address] >> 8); + } else { + source.byteReceived(registers[address] & 0xff); + System.out.println("CC2420: read from " + Utils.hex8(address) + " = " + + registers[address]); + } + break; + case READ_RXFIFO: + System.out.println("CC2420: RXFIFO READ => " + + memory[RAM_RXFIFO + rxCursor]); + source.byteReceived(memory[RAM_RXFIFO + rxCursor++]); + // What if wrap cursor??? + if (rxCursor >= 128) rxCursor = 0; + // When is this set to "false" - when is interrupt de-triggered? + if (rxPacket) { + rxPacket = false; + updateFifopPin(); + } + break; + case RAM_ACCESS: + if (pos == 0) { + address = address | (data << 1) & 0x180; + ramRead = (data & 0x20) != 0; + System.out.println("CC2420: Address: " + Utils.hex16(address) + + " read: " + ramRead); + pos++; + } else { + if (!ramRead) { + memory[address++] = data; + if (address == RAM_PANID + 2) { + System.out.println("CC2420: Pan ID set to: 0x" + + Utils.hex8(memory[RAM_PANID]) + + Utils.hex8(memory[RAM_PANID + 1])); + } + } + } + break; + } + } + } + + // Needs to get information about when it is possible to write + // next data... + + private void strobe(int data) { + // Resets, on/off of different things... + System.out.println("CC2420: Strobe on: " + Utils.hex8(data)); + + switch (data) { + case REG_SRXON: + System.out.println("CC2420: Strobe RX-ON!!!"); + break; + case REG_SFLUSHRX: + flushRX(); + break; + } + } + + + public void setChipSelect(boolean select) { + chipSelect = select; + if (!chipSelect) + state = WAITING; + System.out.println("CC2420: chipSelect: " + chipSelect); + } + + public void setCCAPort(IOPort port, int pin) { + ccaPort = port; + ccaPin = pin; + } + + public void setFIFOPPort(IOPort port, int pin) { + fifopPort = port; + fifopPin = pin; + } + + public void setFIFOPort(IOPort port, int pin) { + fifoPort = port; + fifoPin = pin; + } + + + // ------------------------------------------------------------------- + // Methods for accessing and writing to registers, etc from outside + // ------------------------------------------------------------------- + + public int getRegister(int register) { + return registers[register]; + } + + public void setRegister(int register, int data) { + registers[register] = data; + } + + public void setIncomingPacket(int[] packet) { + int adr = RAM_RXFIFO; + memory[adr++] = packet.length + 2; + for (int i = 0, n = packet.length; i < n; i++) { + memory[adr++] = packet[i] & 0xff; + } + // Should take a RSSI value as input or use a set-RSSI value... + memory[adr++] = (202) & 0xff; + // Set CRC ok and add a correlation + memory[adr++] = (37) | 0x80; + rxPacket = true; + rxCursor = 0; + rxLen = adr; + updateFifopPin(); + } + + private void flushRX() { + if (DEBUG) System.out.println("Flushing RX! was: " + rxPacket + " len = " + + rxLen); + rxPacket = false; + rxCursor = 0; + rxLen = 0; + updateFifopPin(); + } + + private void updateFifopPin() { + fifopPort.setPinState(fifopPin, rxPacket ? 1 : 0); + } + + public void setCCA(boolean cca) { + ccaPort.setPinState(ccaPin, cca ? 1 : 0); + } + +} // CC2420 Added: mspsim/se/sics/mspsim/core/BasicClockModule.java =================================================================== --- mspsim/se/sics/mspsim/core/BasicClockModule.java (rev 0) +++ mspsim/se/sics/mspsim/core/BasicClockModule.java 2007-10-24 10:44:41 UTC (rev 4) @@ -0,0 +1,165 @@ +/** + * Copyright (c) 2007, 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. + * + * This file is part of MSPSim. + * + * $Id: BasicClockModule.java,v 1.3 2007/10/21 21:17:34 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * BasicClockModule + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 21:17:34 $ + * $Revision: 1.3 $ + */ + +package se.sics.mspsim.core; +import se.sics.mspsim.util.Utils; + +public class BasicClockModule extends IOUnit { + + public static final int DCOCTL = 0x56; + public static final int BCSCTL1 = 0x57; + public static final int BCSCTL2 = 0x58; + + public static final int ACLK_FRQ = 32768; + // DCO_FRQ what default frq is the DCO running at??? + public static final int DCO_FRQ = 2500000; + // What frequency steps to take for the DCO? + // We have 8 bits + 3 => 11 bits => 2048 combinations... + // => What is lowest frq??? (zero) + // Max speed is 8Mhz (CPU limits it) - is max DCO 8Mhz? + // Based on the scatterweb code it looks like less than + // 5Mhz is more correct... + public static final int MAX_DCO_FRQ = 4915200; + public static final int DCO_FACTOR = MAX_DCO_FRQ / 2048; + + + private MSP430Core core; + + private int dcoFrequency; + private int dcoModulator; + private int resistorSel; + // These will give => + private int calcDCOFrq; + private int divAclk = 1; + private int lfxt1Mode; + private int xt2Off; + private int mclkSel; + private int divMclk = 1; + private int smclSel; + private int divSMclk = 1; + private int dcoResitorSel; + + /** + * Creates a new <code>BasicClockModule</code> instance. + * + */ + public BasicClockModule(MSP430Core core, int[] memory, int offset) { + super(memory, offset); + this.core = core; + init(); + } + + public void init() { + // What should be initial values? + memory[DCOCTL] = 0; + } + + // Should return the cycle it wants the next tick... + public long ioTick(long cycles) { + return cycles + 4711; + } + + // do nothing? + public int read(int address, boolean word, long cycles) { + int val = memory[address]; + if (word) { + val |= memory[(address + 1) & 0xffff] << 8; + } + return val; + } + + public void write(int address, int data, boolean word, long cycles) { + // Currently ignores the word flag... + System.out.println("Write to BasicClockModule: " + + Utils.hex16(address) + " => " + Utils.hex16(data)); + + memory[address] = data & 0xff; + if (word) memory[address + 1] = (data >> 8) & 0xff; + + + switch (address) { + case DCOCTL: + dcoFrequency = (data >> 5) & 0x7; + dcoModulator = data & 0x1f; + System.out.println("Write: BCM DCOCTL0: DCO Frq:" + dcoFrequency + + " dcoMod:" + dcoModulator); + break; + case BCSCTL1: + resistorSel = data & 0x7; + divAclk = 1 << ((data >> 4) & 3); + lfxt1Mode = (data >> 6) & 1; + xt2Off = (data >> 7) & 1; + System.out.println("Write: BCM BCSCTL1: RSel:" + resistorSel + + " DivACLK:" + divAclk + " ACLKFrq: " + + ACLK_FRQ / divAclk); + core.setACLKFrq(ACLK_FRQ / divAclk); + break; + case BCSCTL2: + mclkSel = (data >> 6) & 3; + divMclk = 1 << ((data >> 4) & 3); + smclSel = (data >> 3) & 1; + divSMclk = 1 << ((data >> 2) & 3); + dcoResitorSel = data & 1; + System.out.println("Write: BCM BCSCTL2: SMCLKDIV: " + + divSMclk + " SMCLK_SEL: " + + smclSel + " MCLKSel: " + mclkSel + " divMclk: " + + divMclk + " DCOResitorSel: " + dcoResitorSel); + core.setDCOFrq(calcDCOFrq, calcDCOFrq / divSMclk); + break; + } + + + int newcalcDCOFrq = ((dcoFrequency << 5) + dcoModulator + + (resistorSel << 8)) * DCO_FACTOR; + if (newcalcDCOFrq != calcDCOFrq) { + calcDCOFrq = newcalcDCOFrq; + System.out.println("BCM DCO_Speed: " + calcDCOFrq); + core.setDCOFrq(calcDCOFrq, calcDCOFrq / divSMclk); + } + } + + public String getName() { + return "BasicClockModule"; + } + + public void interruptServiced() { + } +} Added: mspsim/se/sics/mspsim/core/CPUMonitor.java =================================================================== --- mspsim/se/sics/mspsim/core/CPUMonitor.java (rev 0) +++ mspsim/se/sics/mspsim/core/CPUMonitor.java 2007-10-24 10:44:41 UTC (rev 4) @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2007, 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. + * + * This file is part of MSPSim. + * + * $Id: CPUMonitor.java,v 1.3 2007/10/21 21:17:34 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * CPUMonitor + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 21:17:34 $ + * $Revision: 1.3 $ + */ + +package se.sics.mspsim.core; + +public interface CPUMonitor { + + public static final int MEMORY_READ = 1; + public static final int MEMORY_WRITE = 2; + public static final int REGISTER_READ = 3; + public static final int REGISTER_WRITE = 4; + public static final int BREAK = 5; + + public void cpuAction(int type, int adr, int data); + +} Added: mspsim/se/sics/mspsim/core/DbgInstruction.java =================================================================== --- mspsim/se/sics/mspsim/core/DbgInstruction.java (rev 0) +++ mspsim/se/sics/mspsim/core/DbgInstruction.java 2007-10-24 10:44:41 UTC (rev 4) @@ -0,0 +1,106 @@ +/** + * Copyright (c) 2007, 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. + * + * This file is part of MSPSim. + * + * $Id: DbgInstruction.java,v 1.3 2007/10/21 21:17:34 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * DbgInstruction + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 21:17:34 $ + * $Revision: 1.3 $ + */ + +package se.sics.mspsim.core; + +public class DbgInstruction { + + private String asmLine; + private String regs; + private String function; + private int instruction; + private int size; + private int pos; + + public DbgInstruction() { + } + + public void setPos(int p) { + pos = p; + } + + public int getPos() { + return pos; + } + + public void setASMLine(String line) { + asmLine = line; + } + + public void setRegs(String regs) { + this.regs = regs; + } + + public void setInstruction(int instruction, int size) { + this.instruction = instruction; + this.size = size; + } + + public int getSize() { + return size; + } + + public int getInstruction() { + return instruction; + } + + public String getASMLine(boolean showregs) { + if (showregs) return getASMLine(); + return asmLine; + } + + public String getASMLine() { + return asmLine + "\t" + regs; + } + + public void setFunction(String fkn) { + function = fkn; + } + + public String getFunction() { + return function; + } + + public String toString() { + return getASMLine(); + } + +} Added: mspsim/se/sics/mspsim/core/DisAsm.java =================================================================== --- mspsim/se/sics/mspsim/core/DisAsm.java (rev 0) +++ mspsim/se/sics/mspsim/core/DisAsm.java 2007-10-24 10:44:41 UTC (rev 4) @@ -0,0 +1,457 @@ +/** + * Copyright (c) 2007, 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. + * + * This file is part of MSPSim. + * + * $Id: DisAsm.java,v 1.3 2007/10/21 21:17:34 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * DisAsm + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 21:17:34 $ + * $Revision: 1.3 $ + */ + +package se.sics.mspsim.core; +import java.io.BufferedReader; +import java.io.InputStreamReader; + +import se.sics.mspsim.util.Utils; + +public class DisAsm implements MSP430Constants { + + private boolean step = true; //false; + + private MapTable map; + + // Idiots solution to single stepping... + private BufferedReader input = + new BufferedReader(new InputStreamReader(System.in)); + + public void setMap(MapTable m) { + map = m; + } + + public MapTable getMap() { + return map; + } + + public DbgInstruction disassemble(int pc, int[] memory, int[] reg) { + return disassemble(pc, memory, reg, 0); + } + + public DbgInstruction disassemble(int pc, int[] memory, int[] reg, + int interrupt) { + DbgInstruction dbg = disassemble(pc, memory, reg, new DbgInstruction(), + interrupt); + String fkn; + if ((fkn = dbg.getFunction()) != null) { + System.out.println("//// " + fkn); + } + System.out.println(dbg.getASMLine()); + return dbg; + } + + public DbgInstruction getDbgInstruction(int pc, MSP430 cpu) { + return disassemble(pc, cpu.memory, cpu.reg, new DbgInstruction(), + cpu.servicedInterrupt); + } + + public DbgInstruction disassemble(int pc, int[] memory, int[] reg, + DbgInstruction dbg, int interrupt) { + int startPC = pc; + int size = 0; + int instruction = memory[pc] + (memory[pc + 1] << 8); + int op = instruction >> 12; + boolean word = (instruction & 0x40) == 0; + + String output = " "; + if (interrupt > 0) { + output = "I:" + Integer.toString(interrupt) + ' '; + } + + String regs = ""; + + + if (pc < 0x0010) { + output += "000" + Integer.toString(pc, 16); + } else if (pc < 0x0100) { + output += "00" + Integer.toString(pc, 16); + } else if (pc < 0x1000) { + output += "0" + Integer.toString(pc, 16); + } else { + output += Integer.toString(pc, 16); + } + + + output += ":\t"; + + pc += 2; + size += 2; + + switch (op) { + case 1: // Single operand instructions + { + // Register + int register = instruction & 0xf; + // Adress mode of destination... + int ad = (instruction >> 4) & 3; + // Pick up the destination address based on ad more and regs... + int dstAddress = 0; + String adr = ""; + String opstr = ""; + switch(ad) { + // Operand in register! + case AM_REG: + adr = "R" + register; + break; + case AM_INDEX: + dstAddress = memory[pc] + (memory[pc + 1] << 8); + adr = "R" + register + "(" + dstAddress + ")"; + dstAddress = (register == CG1 ? 0 : reg[register]) + dstAddress; + pc += 2; + size += 2; + break; + // Indirect register + case AM_IND_REG: + adr = "@(R" + register + ")"; + dstAddress = reg[register]; + break; + case AM_IND_AUTOINC: + if (register == 0) { + // Can this be PC and be incremented only one byte? + adr = "#" + Utils.hex16(memory[pc] + (memory[pc + 1] << 8)); + size += 2; + } else { + adr = "@(R" + register + "+)"; + dstAddress = reg[register]; + } + break; + } + + switch(instruction & 0xff80) { + case RRC: + opstr = "RRC" + (word ? ".W" : ".B"); + break; + case SWPB: + opstr = "SWPB" + (word ? ".W" : ".B"); + break; + case RRA: + opstr = "RRA" + (word ? ".W" : ".B"); + break; + case SXT: + opstr = "RRA" + (word ? ".W" : ".B"); + break; + case PUSH: + opstr = "PUSH" + (word ? ".W" : ".B"); + break; + case CALL: + opstr = "CALL"; + break; + case RETI: + opstr = "RETI"; + break; + default: + System.out.println("Not implemented instruction: " + instruction); + } + output += dumpMem(startPC, size, memory); + output += opstr + " " + adr; + regs = "R" + register + "=" + Utils.hex16(reg[register]); + regs += " SP=" + Utils.hex16(reg[SP]); + } + break; + // Jump instructions + case 2: + case 3: + // 10 bits for address for these => 0x00fc => remove 2 bits + int jmpOffset = instruction & 0x3ff; + jmpOffset = (jmpOffset & 0x200) == 0 ? + 2 * jmpOffset : -(2 * (0x200 - (jmpOffset & 0x1ff))); + boolean jump = false; + String opstr = ""; + switch(instruction & 0xfc00) { + case JNE: + opstr = "JNE"; + break; + case JEQ: + opstr = "JEQ"; + break; + case JNC: + opstr = "JNC"; + break; + case JC: + opstr = "JC"; + break; + case JN: + opstr = "JN"; + break; + case JGE: + opstr = "JGE"; + break; + case JL: + opstr = "JL"; + break; + case JMP: + opstr = "JMP"; + break; + default: + System.out.println("Not implemented instruction: " + + Utils.binary16(instruction)); + } + output += dumpMem(startPC, size, memory); + output += opstr + " " + Integer.toString(jmpOffset, 16); + regs = "\tSR=" + dumpSR(reg[SR]); + break; + default: + // --------------------------------------------------------------- + // Double operand instructions! + // --------------------------------------------------------------- + int dstRegister = (instruction & 0xf); + int srcRegister = (instruction >> 8) & 0xf; + int as = (instruction >> 4) & 3; + + // AD: 0 => register direct, 1 => register index, e.g. X(Rn) + boolean dstRegMode = ((instruction >> 7) & 1) == 0; + int dstAddress = 0; + int srcAddress = 0; + int src = 0; + int dst = 0; + boolean write = false; + boolean updateStatus = true; + String srcadr = ""; + String dstadr = ""; + switch(as) { + // Operand in register! + case AM_REG: + if (srcRegister == CG2) { + srcadr = "#0"; + } else if (srcRegister == CG1) { + srcadr = "#0"; + } else { + srcadr = getRegName(srcRegister); + } + break; + case AM_INDEX: + // Indexed if reg != PC & CG1/CG2 - will PC be incremented? + if (srcRegister == CG1) { + srcAddress = memory[pc] + (memory[pc + 1] << 8); + srcadr = "&" + Utils.hex16(srcAddress); + size += 2; + } else if (srcRegister == CG2) { + srcadr = "#1"; + } else { + srcAddress = reg[srcRegister] + memory[pc] + (memory[pc + 1] << 8); + srcadr = "(R" + srcRegister + ")"; + } + break; + // Indirect register + case AM_IND_REG: + if (srcRegister == CG2) { + srcadr = "#2"; + } else if (srcRegister == CG1) { + srcadr = "#4"; + } else { + srcadr = "@" + getRegName(srcRegister); + } + break; + case AM_IND_AUTOINC: + if (srcRegister == CG2) { + srcadr = "#$ffff"; + } else if (srcRegister == CG1) { + srcadr = "#8"; + } else if (srcRegister == PC) { + srcadr = "#" + Utils.hex16(memory[pc] + (memory[pc + 1] << 8)); + pc += 2; + size += 2; + } else if (srcRegister == CG2) { + srcadr = "#ffff"; + } else { + srcadr = "@" + getRegName(srcRegister) + "+"; + srcAddress = reg[srcRegister]; + } + break; + } + + if (dstRegMode) { + dstadr = getRegName(dstRegister); + } else { + dstAddress = memory[pc] + (memory[pc + 1] << 8); + if (dstRegister == 2) { + dstadr = "&" + Utils.hex16(dstAddress); + } else { + dstadr = Utils.hex16(dstAddress) + "(R" + dstRegister + ")"; + } + pc += 2; + size += 2; + } + + // If byte mode the source will not contain the full word... + if (!word) { + src = src & 0xff; + dst = dst & 0xff; + } + opstr = ""; + switch (op) { + case MOV: // MOV + if (instruction == 0x3041) { + opstr = "RET /emulated: MOV.W "; + } else { + opstr = "MOV" + (word ? ".W" : ".B"); + } + break; + case ADD: // ADD + opstr = "ADD" + (word ? ".W" : ".B"); + break; + case ADDC: // ADDC + opstr = "ADDC" + (word ? ".W" : ".B"); + break; + case SUBC: // SUBC + opstr = "SUBC" + (word ? ".W" : ".B"); + break; + case SUB: // SUB + opstr = "SUB" + (word ? ".W" : ".B"); + break; + case CMP: // CMP + opstr = "CMP" + (word ? ".W" : ".B"); + break; + case DADD: // DADD + opstr = "DADD" + (word ? ".W" : ".B"); + break; + case BIT: // BIT + opstr = "BIT" + (word ? ".W" : ".B"); + break; + case BIC: // BIC + opstr = "BIC" + (word ? ".W" : ".B"); + break; + case BIS: // BIS + opstr = "BIS" + (word ? ".W" : ".B"); + break; + case XOR: // XOR + opstr = "XOR" + (word ? ".W" : ".B"); + break; + case AND: // AND + opstr = "AND" + (word ? ".W" : ".B"); + break; + default: + System.out.println(output + " DoubleOperand not implemented: " + + op + " instruction: " + + Utils.binary16(instruction) + " = " + + Utils.hex16(instruction)); + } + + + output += dumpMem(startPC, size, memory); + output += opstr + " " + srcadr + ", " + dstadr; + + regs = "R" + dstRegister + "=" + Utils.hex16(reg[dstRegister]) + + " R" + srcRegister + "=" + Utils.hex16(reg[srcRegister]); + regs += " SR=" + dumpSR(reg[SR]); + regs += " SP=" + Utils.hex16(reg[SP]); + regs += "; as = " + as; + srcAddress &= 0xffff; + if (srcAddress != -1) { + srcAddress &= 0xffff; + regs += " sMem:" + Utils.hex16(memory[srcAddress] + + (memory[(srcAddress + 1) % 0xffff] + << 8)); + } + } + + dbg.setASMLine(output); + dbg.setRegs(regs); + dbg.setInstruction(instruction, size); + if (map != null) { + dbg.setFunction(map.getFunction(startPC)); + } + + if (!step) { + String line = ""; + try {line = input.readLine();}catch(Exception e){} + if (line != null && line.length() > 0 && line.charAt(0) == 'r') { + System.out.println("Registers:"); + for (int i = 0, n = 16; i < n; i++) { + System.out.print("R" + i + "=" + Utils.hex16(reg[i]) + " "); + if (i % 7 == 0 && i != 0) System.out.println(); + } + System.out.println(); + } + } + return dbg; + } + + private String getRegName(int index) { + if (index == 0) return "PC"; + if (index == 1) return "SP"; + if (index == 2) return "SR"; + return "R" + index; + } + + public static String getSingleOPStr(int instruction) { + boolean word = (instruction & 0x40) == 0; + switch(instruction & 0xff80) { + case RRC: + return "RRC" + (word ? ".W" : ".B"); + case SWPB: + return "SWPB" + (word ? ".W" : ".B"); + case RRA: + return "RRA" + (word ? ".W" : ".B"); + case SXT: + return "RRA" + (word ? ".W" : ".B"); + case PUSH: + return "PUSH" + (word ? ".W" : ".B"); + case CALL: + return "CALL"; + case RETI: + return "RETI"; + default: + return "-"; + } + } + + private static String dumpSR(int sr) { + return "" + + (((sr & OVERFLOW) != 0) ? 'V' : '-') + + (((sr & NEGATIVE) != 0) ? 'N' : '-') + + (((sr & ZERO) != 0) ? 'Z' : '-') + + (((sr & CARRY) != 0) ? 'C' : '-'); + } + + private static String dumpMem(int pc, int size, int[] memory) { + String output = ""; + for (int i = 0, n = 4; i < n; i++) { + if (size > i) { + output += Utils.hex8(memory[pc + i]) + " "; + } else { + output += " "; + } + } + return output; + } +} Added: mspsim/se/sics/mspsim/core/IOPort.java =================================================================== --- mspsim/se/sics/mspsim/core/IOPort.java (rev 0) +++ mspsim/se/sics/mspsim/core/IOPort.java 2007-10-24 10:44:41 UTC (rev 4) @@ -0,0 +1,199 @@ +/** + * Copyright (c) 2007, 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. + * + * This file is part of MSPSim. + * + * $Id: IOPort.java,v 1.3 2007/10/21 21:17:34 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * IOPort + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 21:17:34 $ + * $Revision: 1.3 $ + */ + +package se.sics.mspsim.core; +import se.sics.mspsim.util.Utils; + +public class IOPort extends IOUnit { + + public static final int PIN_LOW = 0; + public static final int PIN_HI = 1; + + public static final boolean DEBUG = false; + + public static final String[] iNames = { + "P_IN","P_OUT", "P_DIR", "P_IFG", "P_IES", "P_IE", "P_SEL" }; + public static final String[] names = { + "P_IN", "P_OUT", "P_DIR", "P_SEL" }; + + private String name; + private int interrupt; + private int interruptFlag; + private MSP430Core cpu; + + // External pin state! + private int pinState[] = new int[8]; + + public static final int IN = 0; + public static final int OUT = 1; + public static final int DIR = 2; + public static final int SEL = 3; + public static final int IFG = 3; + public static final int IES = 4; + public static final int IE = 5; + public static final int ISEL = 6; + + // One listener per port maximum (now at leat) + private PortListener listener; + + /** + * Creates a new <code>IOPort</code> instance. + * + */ + public IOPort(MSP430Core cpu, String portName, + int interrupt, int[] memory, int offset) { + super(memory, offset); + name = portName; + this.interrupt = interrupt; + this.cpu = cpu; + } + + public void setPortListener(PortListener listener) { + this.listener = listener; + } + + public int read(int address, boolean word, long cycles) { + if (DEBUG) { + System.out.println("Notify read: " + address); + } + + int val = memory[address]; + if (word) { + val |= memory[(address + 1) & 0xffff] << 8; + } + return val; + } + + public void write(int address, int data, boolean word, long cycles) { + memory[address] = data & 0xff; + if (word) memory[address + 1] = (data >> 8) & 0xff; + + // This does not handle word writes yet... + int iAddress = address - offset; + + if (DEBUG) { + try { + System.out.println("Writing to " + getName() + ":" + + (interrupt > 0? iNames[iAddress] : names[iAddress]) + + " " + Utils.hex8(address) + + " => " + Utils.hex8(data) + "=#" + + Utils.binary8(data) + " word: " + word); + } catch (Exception e) { + e.printStackTrace(); + } + } + + switch (iAddress) { + case IN: + break; + case OUT: + if (listener != null) { + listener.portWrite(this, data); + } + break; + case DIR: + break; + // SEL & IFG is the same but behaviour differs between p1,p2 and rest... + case SEL: + // case IFG: + if (interrupt > 0) { + // IFG - writing a zero => clear the flag! + System.out.println(getName() + " Clearing IFlag: " + data); + interruptFlag &= data; + memory[offset + IFG] = interruptFlag; + cpu.flagInterrupt(interrupt, this, interruptFlag > 0); + } else { + // Samel as ISEL!!! + } + break; + case IES: + break; + case IE: + break; + case ISEL: + } + } + + public String getName() { + return "Port " + name; + } + + public void interruptServiced() { + } + + // for HW to set hi/low on the pins... + public void setPinState(int pin, int state) { + if (interrupt > 0) { + if (pinState[pin] != state) { + pinState[pin] = state; + int bit = 1 << pin; + if ((memory[offset + IES] & bit) == 0) { + // LO/HI transition + if (state == PIN_HI) { + interruptFlag |= bit; + System.out.println(getName() + " Flagging interrupt (HI): " + bit); + } + } else { + // HI/LO transition + if (state == PIN_LOW) { + interruptFlag |= bit; + System.out.println(getName() + " Flagging interrupt (LOW): " + + bit); + } + } + } + } + memory[offset + IFG] = interruptFlag; + + // Maybe this is not the only place where we should flag int? + cpu.flagInterrupt(interrupt, this, interruptFlag > 0); + } + + + public void reset() { + for (int i = 0, n = 8; i < n; i++) { + pinState[i] = PIN_LOW; + } + interruptFlag = 0; + cpu.flagInterrupt(interrupt, this, interruptFlag > 0); + } + +} Added: mspsim/se/sics/mspsim/core/IOUnit.java =================================================================== --- mspsim/se/sics/mspsim/core/IOUnit.java (rev 0) +++ mspsim/se/sics/mspsim/core/IOUnit.java 2007-10-24 10:44:41 UTC (rev 4) @@ -0,0 +1,100 @@ +/** + * Copyright (c) 2007, 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. + * + * This file is part of MSPSim. + * + * $Id: IOUnit.java,v 1.3 2007/10/21 21:17:34 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * IOUnit + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 21:17:34 $ + * $Revision: 1.3 $ + */ + +package se.sics.mspsim.core; + +public abstract class IOUnit { + + int[] memory; + int offset; + + public IOUnit(int[] memory, int offset) { + this.memory = memory; + this.offset = offset; + } + + public void reset() { + } + + public boolean needsTick() { + return true; + } + + // Default implementation assums notify write and read on all + // addresses (should be optimized for each unit) + public boolean needsWrite(int address) { + return true; + } + + public boolean needsRead(int address) { + return true; + } + + // Should return the cycle it wants the next tick... + public long ioTick(long cycles) { + return cycles + 1000000; + } + + // write + // write a value to the IO unit + public abstract void write(int address, int value, boolean word, + long cycles); + + // read + // read a value from the IO unit + public abstract int read(int address, boolean word, long cycles); + + public abstract String getName(); + + // We should add "Interrupt serviced..." to indicate that its latest + // Interrupt was serviced... + public abstract void interruptServiced(); + + // Utility function for converting 16 bits data to correct return + // value depending on address alignment and word/byte mode + public static int return16(int address, int data, boolean word) { + if (word) return data; + // First byte => low byte + if ((address & 1) == 0) return data & 0xff; + // Second byte => hi byte + return (data >> 8) & 0xff; + } +} Added: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java (rev 0) +++ mspsim/se/sics/mspsim/core/MSP430.java 2007-10-24 10:44:41 UTC (rev 4) @@ -0,0 +1,281 @@ +/** + * Copyright (c) 2007, 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. + * + * This file is part of MSPSim. + * + * $Id: MSP430.java,v 1.4 2007/10/21 22:02:22 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * MSP430 + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 22:02:22 $ + * $Revision: 1.4 $ + */ + +package se.sics.mspsim.core; +import java.util.Arrays; +import java.util.Hashtable; + +import se.sics.mspsim.util.Utils; + +public class MSP430 extends MSP430Core { + + public static final int RETURN = 0x4130; + + private int[] execCounter; + + private boolean debug = false; + private boolean running = false; + + // Debug time - measure cycles + private long lastCycles = 0; + private long time; + + private long instCtr = 0; + + private DisAsm disAsm; + + private MapTable map; + private Hashtable<String,CallEntry> profileData; + private CallEntry[] callStack; + private int cSP = 0; + + /** + * Creates a new <code>MSP430</code> instance. + * + */ + public MSP430(int type) { + super(type); + disAsm = new DisAsm(); + } + + public DisAsm getDisAsm() { + return disAsm; + } + + public void cpuloop() { + if (running) { + throw new IllegalStateException("already running"); + } + running = true; + // ??? - power-up reset should be executed?! + time = System.currentTimeMillis(); + run(); + } + + private void run() { + while (running) { + // ------------------------------------------------------------------- + // Debug information + // ------------------------------------------------------------------- + if (debug) { + if (servicedInterrupt >= 0) { + disAsm.disassemble(reg[PC], memory, reg, servicedInterrupt); + } else { + disAsm.disassemble(reg[PC], memory, reg); + } + } + + instCtr++; + if ((instCtr % 10000007) == 0 && !debug) { + printCPUSpeed(reg[PC]); + } + + if (execCounter != null) { + execCounter[reg[PC]]++; + } + + emulateOP(); + +// if ((instruction & 0xff80) == CALL) { +// System.out.println("Call to PC = " + reg[PC]); +// } + + if (map != null) { + if ((instruction & 0xff80) == CALL) { + profileCall(map.getFunction(reg[PC]), cycles); + // System.out.println("Call," + map.getFunction(reg[PC]) + "," + + // cycles); + } else if (instruction == RETURN) { + profileReturn(cycles); + //System.out.println("Return," + cycles); + } + } + } + } + + private void profileCall(String function, long cycles) { +// System.out.println("Call at: " + Utils.hex16(reg[PC])); + if (callStack[cSP] == null) { + callStack[cSP] = new CallEntry(); + } + if (function == null) { + function = "fkn at $" + Utils.hex16(reg[PC]); + } + callStack[cSP].function = function; + callStack[cSP++].cycles = cycles; + } + + private void profileReturn(long cycles) { + String fkn = callStack[--cSP].function; +// System.out.println("Profiler: return / call stack: " + cSP + ", " + fkn); + + long elapsed = cycles - callStack[cSP].cycles; + CallEntry ce = profileData.get(fkn); + if (ce == null) { + profileData.put(fkn, ce = new CallEntry()); + ce.function = fkn; + ce.cycles = elapsed; + } else { + ce.cycles += elapsed; + } + } + + public void printProfile() { + CallEntry[] entries = + profileData.values().toArray(new CallEntry[0]); + Arrays.sort(entries); + for (int i = 0, n = entries.length; i < n; i++) { + printFkn(entries[i].function); + System.out.println(" " + entries[i].cycles); + } + } + + public void printFkn(String f) { + System.out.print(f); + int len = f.length(); + if (len < 40) + len = 40 - len; + else + len = 0; + for (int i = 0, n = len; i < n; i++) { + System.out.print(" "); + } + } + + public long step() { + if (running) { + throw new IllegalStateException("step not possible when CPU is running"); + } + + // ------------------------------------------------------------------- + // Debug information + // ------------------------------------------------------------------- + if (debug) { + if (servicedInterrupt >= 0) { + disAsm.disassemble(reg[PC], memory, reg, servicedInterrupt); + } else { + disAsm.disassemble(reg[PC], memory, reg); + } + } + + instCtr++; + if ((instCtr % 10000007) == 0 && !debug) { + printCPUSpeed(reg[PC]); + } + + if (e... [truncated message content] |
From: <jo...@us...> - 2007-10-24 11:26:05
|
Revision: 6 http://mspsim.svn.sourceforge.net/mspsim/?rev=6&view=rev Author: joxe Date: 2007-10-24 04:25:55 -0700 (Wed, 24 Oct 2007) Log Message: ----------- intial add Added Paths: ----------- mspsim/images/ mspsim/images/esb.jpg mspsim/images/sky.jpg Added: mspsim/images/esb.jpg =================================================================== (Binary files differ) Property changes on: mspsim/images/esb.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: mspsim/images/sky.jpg =================================================================== (Binary files differ) Property changes on: mspsim/images/sky.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2007-10-25 10:58:33
|
Revision: 7 http://mspsim.svn.sourceforge.net/mspsim/?rev=7&view=rev Author: joxe Date: 2007-10-25 03:58:19 -0700 (Thu, 25 Oct 2007) Log Message: ----------- added testcases Modified Paths: -------------- mspsim/Makefile Added Paths: ----------- mspsim/firmware/ mspsim/tests/ mspsim/tests/Makefile mspsim/tests/cputest.c mspsim/tests/msp430setup.c mspsim/tests/msp430setup.h Modified: mspsim/Makefile =================================================================== --- mspsim/Makefile 2007-10-24 11:25:55 UTC (rev 6) +++ mspsim/Makefile 2007-10-25 10:58:19 UTC (rev 7) @@ -1,13 +1,11 @@ ############################################################### -# $Revision: 1.11 $ $Date: 2007/10/21 19:47:53 $ +# Makefile for mspsim # # Needed stuff in the PATH: -# java, javac (JDK 1.2 or newer) +# java, javac (JDK 1.5 or newer) # -# Under MS-DOS/Windows 95/NT -# A GNU compatible Make (for example Cygnus GNU-Win 32, -# http://www.cygnus.com/misc/gnu-win32/) -# Note: might need to be called with "make --win32" under Windows!!! +# Under MS-DOS/Windows +# A GNU compatible Make (for example Cygwin's) ############################################################### ############################################################### @@ -37,7 +35,7 @@ # Add "'" around filenames when removing them because UNIX expands "$" APO='#' (last apostrophe to avoid incorrect font-lock) else - # These setting are for MS-DOS/Windows 95/Windows NT + # These setting are for Windows SEPARATOR=; APO= endif @@ -54,7 +52,7 @@ # SERVER OBJECTS ############################################################### -IHEXFILE = blinker2.ihex +FIRMWAREFILE = blinker2.ihex CPUTEST := tests/cputest.ihex CPUTESTMAP := $(CPUTEST:.ihex=.map) @@ -81,13 +79,13 @@ .PHONY: run run: compile - java se.sics.util.IHexReader $(IHEXFILE) $(MAPFILE) + java se.sics.util.IHexReader $(FIRMWAREFILE) $(MAPFILE) runesb: compile - java se.sics.mspsim.platform.esb.ESBNode $(IHEXFILE) $(MAPFILE) + java se.sics.mspsim.platform.esb.ESBNode $(FIRMWAREFILE) $(MAPFILE) runsky: compile - java se.sics.mspsim.platform.sky.SkyNode $(IHEXFILE) $(MAPFILE) + java se.sics.mspsim.platform.sky.SkyNode $(FIRMWAREFILE) $(MAPFILE) .PHONY: cputest test test: cputest Added: mspsim/tests/Makefile =================================================================== --- mspsim/tests/Makefile (rev 0) +++ mspsim/tests/Makefile 2007-10-25 10:58:19 UTC (rev 7) @@ -0,0 +1,50 @@ +### Check if we are running under Windows + +ifndef WINDIR + ifdef OS + ifneq (,$(findstring Windows,$(OS))) + WINDIR := Windows + endif + endif +endif + +.SUFFIXES: + +MCU=msp430x149 + +### Compiler definitions +CC = msp430-gcc +LD = msp430-ld +AS = msp430-as +AR = msp430-ar +OBJCOPY = msp430-objcopy +STRIP = msp430-strip +BSL = msp430-bsl +CFLAGSNO = -I. -DWITH_ASCII \ + -Wall -mmcu=$(MCU) -g +CFLAGS += $(CFLAGSNO) -Os + +SOURCES := msp430setup.c + +OBJECTS := $(SOURCES:.c=.o) + +#all: cputest.ihex +all: cputest.firmware + +%.firmware: %.co $(OBJECTS) + $(CC) -mmcu=$(MCU) -Wl,-Map=$(@:.firmware=.map) $(CFLAGS) -o $@ $^ + +%.ihex: %.firmware + $(OBJCOPY) $^ -O ihex $@ + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +%.co: %.c + $(CC) $(CFLAGS) -DAUTOSTART_ENABLE -c $< -o $@ + +%.u: %.ihex + msp430-jtag -eI $^ + +clean: + rm -f *~ *.lst *.map *.co *.o *.ihex *.firmware Added: mspsim/tests/cputest.c =================================================================== --- mspsim/tests/cputest.c (rev 0) +++ mspsim/tests/cputest.c 2007-10-25 10:58:19 UTC (rev 7) @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2007, 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: cputest.c,v 1.19 2007/10/24 22:17:46 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : 2006-03-07 + * Updated : $Date: 2007/10/24 22:17:46 $ + * $Revision: 1.19 $ + */ + +#include "msp430setup.h" +#include <stdio.h> +#include <string.h> + +/* From Adams test-suite */ +#define TEST(...) if(__VA_ARGS__) { \ + printf("OK: " #__VA_ARGS__ " passed at %s:%d\n", __FILE__,__LINE__); \ + } else { \ + printf("FAIL: " #__VA_ARGS__ " failed at %s:%d\n", __FILE__,__LINE__); \ + } + +#define TEST2(text,...) if(__VA_ARGS__) { \ + printf("OK: " #text " passed at %s:%d\n", __FILE__,__LINE__); \ + } else { \ + printf("FAIL: " #text " failed at %s:%d\n", __FILE__,__LINE__); \ + } + +#define assertTrue(...) TEST(__VA_ARGS__) +#define assertFalse(...) TEST(!(__VA_ARGS__)) + +#define assertTrue2(text,...) TEST2(text,__VA_ARGS__) +#define assertFalse2(text,...) TEST2(text,!(__VA_ARGS__)) + +static int testzero(int hm) +{ + return hm > 0; +} + +static int caseID = 0; + +static void initTest() { + caseID = 0; +} + +static void testCase(char *description) { + caseID++; + printf("-------------\n"); + printf("TEST %d: %s\n", caseID, description); +} + +static void testSimple() { + int a,b,c; + a = 1; b = 2; c = 4; + testCase("Arithmetic Operations"); + + assertTrue((a << b) == 4); + assertTrue((c >> a) == 2); + + assertFalse(0 > 0); + assertFalse(a > b); + + assertFalse(testzero(0)); +} + +static void testIntegers() { + int a,b,c; + int t[3]; + testCase("Integer Operations"); + a = 1; b = 2; c = -42; + t[0] = 1; + t[1] = 2; + t[2] = 3; + assertTrue(a == 1); + assertTrue((b + c) == -40); + assertTrue(t[0] == 1); + assertTrue(t[1] == 2); + assertTrue(t[t[0]] == 2); + assertTrue((a+b) == 3); + assertTrue((b-a) == 1); + assertTrue((a-b) == -1); + assertTrue((a*b) == 2); + assertTrue(a > 0); + assertTrue(b > a); + assertTrue(b != a); + assertTrue((a ^ b) == 3); + assertTrue((a ^ 4) == 5); + assertTrue((a ^ a) == 0); + assertFalse(a > b); + + a = 15; + b = 17; + assertTrue((a & ~b) == 14); +} + +static void testFloats() { + int i; + float f; + i = 2; + f = 0.5; + testCase("Float Operations"); + assertTrue((i * f) == 1); + i++; + assertTrue((i * f) == 1.5); +} + +static void testStrings() { + char buf[10]; + + testCase("String Operations"); + sprintf(buf, "test"); + assertTrue2("test => test", strcmp(buf, "test") == 0); + sprintf(buf, "%c", 'a'); + assertTrue2("buf == 'a'", strcmp(buf, "a") == 0); +} + +/*--------------------------------------------------------------------------*/ + +static int id(int first, ...) +{ + va_list marker; + va_start( marker, first ); + first = va_arg( marker, int); + va_end( marker ); + return first; +} + +static void testFunctions() { + volatile int i; + + testCase("Functions"); + i = 47; + +/* printf("i=%d i+1=%d id(i)=%d\n", i, i + 1, id(0, i)); */ + + assertTrue(i == 47); + assertTrue(id(0,47) == 47); + assertTrue(id(0,i) == 47); +} + +/*--------------------------------------------------------------------------*/ + +static void testModulo() { + int c,i; + c = 1; + testCase("Modulo"); + do { + i = 13; + + i = i % 14; +/* printf("(%d,%d,%d)\n",i, (i % 14), i==1); */ +/* printf("(%d,%d,%d)\n",i, (i % 14), i==1); */ + if (i < 0) printf("%d\n",i); + + + c = c + 1; + } while (c < 3); + +/* if((i % 5) == 0) { */ +/* assertTrue(i != 1); */ +/* } */ +} + +/*--------------------------------------------------------------------------*/ + +/* Bit field tests */ + +static struct { + char green:4, yellow:4, red:4; +} leds; + +static struct { + char green:2, yellow:2, red:2; /* These bit fields should really be + only one bit wide, but that + crashed gcc... */ +} invert; + +#include <io.h> +#ifndef BV +#define BV(n) (1 << (n)) +#endif + +void testBis() { + P4DIR |= BV(2) | BV(5) | BV(6); + assertTrue(P4DIR == 100); +} + +static void testBitFields() { + static int pelle = 0; + + testCase("Bit field Operations"); + + P4DIR = 0; + testBis(); + + leds.green = 1; + leds.yellow = 1; + leds.red = 1; + + assertTrue(leds.green > 0); + assertTrue(leds.yellow > 0); + assertTrue(leds.red > 0); + + leds.green -= 1; + assertTrue(leds.green == 0); + + pelle = 0x4711; + + invert.green = 1; + invert.yellow = 1; + invert.red = 1; + + assertTrue(invert.green > 0); + assertTrue(invert.yellow > 0); + assertTrue(invert.red > 0); + + invert.green ^= 1; + assertTrue(invert.green == 0); + +} + + +/*--------------------------------------------------------------------------*/ + +int +main(void) +{ + msp430_setup(); + + initTest(); + +/* testSimple(); */ +/* testIntegers(); */ +/* testFloats(); */ +/* testStrings(); */ +/* testBitFields(); */ +/* testFunctions(); */ + testModulo(); + + printf("EXIT\n"); + return 0; +} Added: mspsim/tests/msp430setup.c =================================================================== --- mspsim/tests/msp430setup.c (rev 0) +++ mspsim/tests/msp430setup.c 2007-10-25 10:58:19 UTC (rev 7) @@ -0,0 +1,380 @@ +/* + * Copyright (c) 2007, 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: msp430setup.c,v 1.2 2007/01/22 15:45:04 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : 2007-01-22 + * Updated : $Date: 2007/01/22 15:45:04 $ + * $Revision: 1.2 $ + */ + +#include "msp430setup.h" +#include <io.h> +#include <signal.h> +#include <stdio.h> +#include <sys/unistd.h> + + +/*--------------------------------------------------------------------------*/ +/* RS232 Interface */ +/*--------------------------------------------------------------------------*/ + +static int (* input_handler)(unsigned char) = NULL; + +/*---------------------------------------------------------------------------*/ +interrupt(UART1RX_VECTOR) + rs232_rx_usart1(void) +{ + /* Check status register for receive errors. - before reading RXBUF since + it clears the error and interrupt flags */ + if(!(URCTL1 & RXERR) && input_handler != NULL) { + input_handler(RXBUF1); + + } else { + /* Else read out the char to clear the I-flags, etc. */ + RXBUF1; + } +} +/*--------------------------------------------------------------------------*/ +void +rs232_init(void) +{ + + /* RS232 */ + UCTL1 = CHAR; /* 8-bit character */ + UTCTL1 = SSEL1; /* UCLK = MCLK */ + + rs232_set_speed(RS232_57600); + + input_handler = NULL; + + ME2 |= (UTXE1 | URXE1); /* Enable USART1 TXD/RXD */ + IE2 |= URXIE1; /* Enable USART1 RX interrupt */ +} +/*---------------------------------------------------------------------------*/ +void +rs232_send(char c) +{ + /* Loop until the transmission buffer is available. */ + while ((IFG2 & UTXIFG1) == 0); + + /* Transmit the data. */ + TXBUF1 = c; +} +/*---------------------------------------------------------------------------*/ +void +rs232_set_speed(unsigned char speed) +{ + if(speed == RS232_19200) { + /* Set RS232 to 19200 */ + UBR01 = 0x80; /* 2,457MHz/19200 = 128 -> 0x80 */ + UBR11 = 0x00; /* */ + UMCTL1 = 0x00; /* no modulation */ + } else if(speed == RS232_38400) { + /* Set RS232 to 38400 */ + UBR01 = 0x40; /* 2,457MHz/38400 = 64 -> 0x40 */ + UBR11 = 0x00; /* */ + UMCTL1 = 0x00; /* no modulation */ + } else if(speed == RS232_57600) { + UBR01 = 0x2a; /* 2,457MHz/57600 = 42.7 -> 0x2A */ + UBR11 = 0x00; /* */ + UMCTL1 = 0x5b; /* */ + } else if(speed == RS232_115200) { + UBR01 = 0x15; /* 2,457MHz/115200 = 21.4 -> 0x15 */ + UBR11 = 0x00; /* */ + UMCTL1 = 0x4a; /* */ + } else { + rs232_set_speed(RS232_57600); + } +} +/*---------------------------------------------------------------------------*/ +void +rs232_set_input(int (*f)(unsigned char)) +{ + input_handler = f; +} +/*--------------------------------------------------------------------------*/ +int +putchar(int c) +{ + rs232_send(c); + return c; +} +/*--------------------------------------------------------------------------*/ + + + + +/*---------------------------------------------------------------------------*/ +void +esb_sensors_init(void) +{ + P5SEL &= ~(1 << 5); + P5DIR |= (1 << 5); +} +/*---------------------------------------------------------------------------*/ +void +esb_sensors_on(void) +{ + P5OUT &= ~(1 << 5); +} +/*---------------------------------------------------------------------------*/ +void +esb_sensors_off(void) +{ + P5OUT |= (1 << 5); +} +/*---------------------------------------------------------------------------*/ + + + + +/*---------------------------------------------------------------------------*/ +/* CPU INIT */ +/*--------------------------------------------------------------------------*/ + +static void +msp430_init_dco(void) +{ + /* This code taken from the FU Berlin sources and reformatted. */ +#define DELTA 600 + + unsigned int compare, oldcapture = 0; + unsigned int i; + + + BCSCTL1 = 0xa4; /* ACLK is devided by 4. RSEL=6 no division for MCLK + and SSMCLK. XT2 is off. */ + + BCSCTL2 = 0x00; /* Init FLL to desired frequency using the 32762Hz + crystal DCO frquenzy = 2,4576 MHz */ + + WDTCTL = WDTPW + WDTHOLD; /* Stop WDT */ + BCSCTL1 |= DIVA1 + DIVA0; /* ACLK = LFXT1CLK/8 */ + for(i = 0xffff; i > 0; i--); /* Delay for XTAL to settle */ + + CCTL2 = CCIS0 + CM0 + CAP; // Define CCR2, CAP, ACLK + TACTL = TASSEL1 + TACLR + MC1; // SMCLK, continous mode + + + while(1) { + + while((CCTL2 & CCIFG) != CCIFG); /* Wait until capture occured! */ + CCTL2 &= ~CCIFG; /* Capture occured, clear flag */ + compare = CCR2; /* Get current captured SMCLK */ + compare = compare - oldcapture; /* SMCLK difference */ + oldcapture = CCR2; /* Save current captured SMCLK */ + + if(DELTA == compare) { + break; /* if equal, leave "while(1)" */ + } else if(DELTA < compare) { /* DCO is too fast, slow it down */ + DCOCTL--; + if(DCOCTL == 0xFF) { /* Did DCO role under? */ + BCSCTL1--; + } + } else { /* -> Select next lower RSEL */ + DCOCTL++; + if(DCOCTL == 0x00) { /* Did DCO role over? */ + BCSCTL1++; + } + /* -> Select next higher RSEL */ + } + } + + CCTL2 = 0; /* Stop CCR2 function */ + TACTL = 0; /* Stop Timer_A */ + + BCSCTL1 &= ~(DIVA1 + DIVA0); /* remove /8 divisor from ACLK again */ +} +/*---------------------------------------------------------------------------*/ +static void +init_ports(void) +{ + /* Turn everything off, device drivers are supposed to enable what is + * really needed! + */ + + /* All configured for digital I/O */ +#ifdef P1SEL + P1SEL = 0; +#endif +#ifdef P2SEL + P2SEL = 0; +#endif +#ifdef P3SEL + P3SEL = 0; +#endif +#ifdef P4SEL + P4SEL = 0; +#endif +#ifdef P5SEL + P5SEL = 0; +#endif +#ifdef P6SEL + P6SEL = 0; +#endif + + /* All available inputs */ +#ifdef P1DIR + P1DIR = 0; + P1OUT = 0; +#endif +#ifdef P2DIR + P2DIR = 0; + P2OUT = 0; +#endif +#ifdef P3DIR + P3DIR = 0; + P3OUT = 0; +#endif +#ifdef P4DIR + P4DIR = 0; + P4OUT = 0; +#endif + +#ifdef P5DIR + P5DIR = 0; + P5OUT = 0; +#endif + +#ifdef P6DIR + P6DIR = 0; + P6OUT = 0; +#endif + + P1IE = 0; + P2IE = 0; +} +/*---------------------------------------------------------------------------*/ +static void init_ports_toberemoved() { + ////////// Port 1 //// + P1SEL = 0x00; + P1DIR = 0x81; // Outputs: P10=IRSend, P17=RS232RTS + // Inputs: P11=Light, P12=IRRec, P13=PIR, P14=Vibration, + // P15=Clockalarm, P16=RS232CTS + P1OUT = 0x00; + + ////////// Port 2 //// + P2SEL = 0x00; // No Sels + P2DIR = 0x7F; // Outpus: P20..P23=Leds+Beeper, P24..P26=Poti + // Inputs: P27=Taster + P2OUT = 0x77; + + ////////// Port 3 //// + P3SEL = 0xE0; // Sels for P34..P37 to activate UART, + P3DIR = 0x5F; // Inputs: P30..P33=CON4, P35/P37=RXD Transceiver/RS232 + // OutPuts: P36/P38=TXD Transceiver/RS232 + P3OUT = 0xE0; // Output a Zero on P34(TXD Transceiver) and turn SELECT off when receiving!!! + + ////////// Port 4 //// + P4SEL = 0x00; // CON5 Stecker + P4DIR = 0xFF; + P4OUT = 0x00; + + ////////// Port 5 //// + P5SEL = 0x00; // P50/P51= Clock SDA/SCL, P52/P53/P54=EEPROM SDA/SCL/WP + P5DIR = 0xDA; // P56/P57=Transceiver CNTRL0/1 + P5OUT = 0x0F; + + ////////// Port 6 //// + P6SEL = 0x00; // P60=Microphone, P61=PIR digital (same as P13), P62=PIR analog + P6DIR = 0x00; // P63=extern voltage, P64=battery voltage, P65=Receive power + P6OUT = 0x00; +} +/*--------------------------------------------------------------------------*/ +void +msp430_setup(void) +{ + dint(); + init_ports(); + msp430_init_dco(); + eint(); + + init_ports_toberemoved(); + + esb_sensors_init(); + esb_sensors_on(); + + rs232_init(); +} + +#define asmv(arg) __asm__ __volatile__(arg) + +#define STACK_EXTRA 32 +static char *cur_break = (char *)(&__bss_end + 1); + +/* + * Allocate memory from the heap. Check that we don't collide with the + * stack right now (some other routine might later). A watchdog might + * be used to check if cur_break and the stack pointer meet during + * runtime. + */ +void * +sbrk(int incr) +{ + char *stack_pointer; + + asmv("mov r1, %0" : "=r" (stack_pointer)); + stack_pointer -= STACK_EXTRA; + if(incr > (stack_pointer - cur_break)) + return (void *)-1; /* ENOMEM */ + + void *old_break = cur_break; + cur_break += incr; + /* + * If the stack was never here then [old_break .. cur_break] should + * be filled with zeros. + */ + return old_break; +} + +/* + * Mask all interrupts that can be masked. + */ +int +splhigh_(void) +{ + /* Clear the GIE (General Interrupt Enable) flag. */ + int sr; + asmv("mov r2, %0" : "=r" (sr)); + asmv("bic %0, r2" : : "i" (GIE)); + return sr & GIE; /* Ignore other sr bits. */ +} + +/* + * Restore previous interrupt mask. + */ +void +splx_(int sr) +{ + /* If GIE was set, restore it. */ + asmv("bis %0, r2" : : "r" (sr)); +} Added: mspsim/tests/msp430setup.h =================================================================== --- mspsim/tests/msp430setup.h (rev 0) +++ mspsim/tests/msp430setup.h 2007-10-25 10:58:19 UTC (rev 7) @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2007, 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: msp430setup.h,v 1.1 2007/01/22 15:12:27 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : 2007-01-22 + * Updated : $Date: 2007/01/22 15:12:27 $ + * $Revision: 1.1 $ + */ + +#ifndef __MSP430SETUP_H__ +#define __MSP430SETUP_H__ + +void msp430_setup(void); + +#define RS232_19200 1 +#define RS232_38400 2 +#define RS232_57600 3 +#define RS232_115200 4 + +/** + * \brief Set an input handler for incoming RS232 data + * \param f A pointer to a byte input handler + * + * This function sets the input handler for incoming RS232 + * data. The input handler function is called for every + * incoming data byte. The function is called from the + * RS232 interrupt handler, so care must be taken when + * implementing the input handler to avoid race + * conditions. + * + * The return value of the input handler affects the sleep + * mode of the CPU: if the input handler returns non-zero + * (true), the CPU is awakened to let other processing + * take place. If the input handler returns zero, the CPU + * is kept sleeping. + */ +void rs232_set_input(int (* f)(unsigned char)); + +/** + * \brief Configure the speed of the RS232 hardware + * \param speed The speed + * + * This function configures the speed of the RS232 + * hardware. The allowed parameters are RS232_19200, + * RS232_38400, RS232_57600, and RS232_115200. + */ +void rs232_set_speed(unsigned char speed); + +/** + * \brief Print a text string on RS232 + * \param str A pointer to the string that is to be printed + * + * This function prints a string to RS232. The string must + * be terminated by a null byte. The RS232 module must be + * correctly initalized and configured for this function + * to work. + */ +void rs232_print(char *text); + +/** + * \brief Print a character on RS232 + * \param c The character to be printed + * + * This function prints a character to RS232. The RS232 + * module must be correctly initalized and configured for + * this function to work. + */ +void rs232_send(char c); + +#endif /* __MSP430SETUP_H__ */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2007-10-25 11:03:40
|
Revision: 8 http://mspsim.svn.sourceforge.net/mspsim/?rev=8&view=rev Author: joxe Date: 2007-10-25 04:03:36 -0700 (Thu, 25 Oct 2007) Log Message: ----------- fixed so that test cases can be run Modified Paths: -------------- mspsim/Makefile mspsim/se/sics/mspsim/util/Test.java Modified: mspsim/Makefile =================================================================== --- mspsim/Makefile 2007-10-25 10:58:19 UTC (rev 7) +++ mspsim/Makefile 2007-10-25 11:03:36 UTC (rev 8) @@ -54,8 +54,7 @@ FIRMWAREFILE = blinker2.ihex -CPUTEST := tests/cputest.ihex -CPUTESTMAP := $(CPUTEST:.ihex=.map) +CPUTEST := tests/cputest.firmware PACKAGES := ${addprefix se/sics/mspsim/,core platform/esb platform/sky util} @@ -79,7 +78,7 @@ .PHONY: run run: compile - java se.sics.util.IHexReader $(FIRMWAREFILE) $(MAPFILE) + java se.sics.mspsim.util.IHexReader $(FIRMWAREFILE) $(MAPFILE) runesb: compile java se.sics.mspsim.platform.esb.ESBNode $(FIRMWAREFILE) $(MAPFILE) @@ -91,19 +90,19 @@ test: cputest cputest: $(CPUTEST) - java se.sics.util.Test $(CPUTEST) $(CPUTESTMAP) + java se.sics.mspsim.util.Test $(CPUTEST) $(CPUTEST): (cd tests && $(MAKE)) test: cd tests && make - java se.sics.util.Test $(CPUTEST) $(CPUTESTMAP) + java se.sics.mspsim.util.Test $(CPUTEST) .PHONY: mtest mtest: compile $(CPUTEST) @-$(RM) mini-test_cpu.txt - java se.sics.util.Test -debug $(CPUTEST) $(CPUTESTMAP) >mini-test_cpu.txt + java se.sics.util.Test -debug $(CPUTEST) >mini-test_cpu.txt ############################################################### Modified: mspsim/se/sics/mspsim/util/Test.java =================================================================== --- mspsim/se/sics/mspsim/util/Test.java 2007-10-25 10:58:19 UTC (rev 7) +++ mspsim/se/sics/mspsim/util/Test.java 2007-10-25 11:03:36 UTC (rev 8) @@ -40,9 +40,10 @@ */ package se.sics.mspsim.util; import se.sics.mspsim.core.*; +import java.io.IOException; /** - * Test - tests a ihex file and exits when reporting "FAIL:" first + * Test - tests a firmware file and exits when reporting "FAIL:" first * on a line... */ public class Test implements USARTListener { @@ -89,24 +90,21 @@ index++; } - IHexReader reader = new IHexReader(); - String ihexFile = args[index++]; - int[] memory = cpu.getMemory(); - reader.readFile(memory, ihexFile); - cpu.reset(); + try { + int[] memory = cpu.getMemory(); + ELF elf = ELF.readELF(args[index++]); + elf.loadPrograms(memory); + MapTable map = elf.getMap(); + cpu.getDisAsm().setMap(map); + cpu.setMap(map); + cpu.reset(); - if (index < args.length && cpu.getDisAsm() != null) { - try { - MapTable map = new MapTable(args[index++]); - cpu.getDisAsm().setMap(map); - } catch (Exception e) { - e.printStackTrace(); - System.exit(1); - } + // Create the "tester" + new Test(cpu); + cpu.cpuloop(); + } catch (IOException ioe) { + ioe.printStackTrace(); } - // Create the "tester" - new Test(cpu); - cpu.cpuloop(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2007-10-25 11:11:02
|
Revision: 9 http://mspsim.svn.sourceforge.net/mspsim/?rev=9&view=rev Author: joxe Date: 2007-10-25 04:10:47 -0700 (Thu, 25 Oct 2007) Log Message: ----------- fixed elf to not printout all debuginfo Modified Paths: -------------- mspsim/Makefile mspsim/se/sics/mspsim/util/ELF.java Modified: mspsim/Makefile =================================================================== --- mspsim/Makefile 2007-10-25 11:03:36 UTC (rev 8) +++ mspsim/Makefile 2007-10-25 11:10:47 UTC (rev 9) @@ -95,10 +95,6 @@ $(CPUTEST): (cd tests && $(MAKE)) -test: - cd tests && make - java se.sics.mspsim.util.Test $(CPUTEST) - .PHONY: mtest mtest: compile $(CPUTEST) @-$(RM) mini-test_cpu.txt Modified: mspsim/se/sics/mspsim/util/ELF.java =================================================================== --- mspsim/se/sics/mspsim/util/ELF.java 2007-10-25 11:03:36 UTC (rev 8) +++ mspsim/se/sics/mspsim/util/ELF.java 2007-10-25 11:10:47 UTC (rev 9) @@ -106,20 +106,22 @@ shnum = readElf16(); shstrndx = readElf16(); - System.out.println("-- ELF Header --"); - System.out.println("type: " + Integer.toString(type, 16)); - System.out.println("machine: " + Integer.toString(machine, 16)); - System.out.println("version: " + Integer.toString(version, 16)); - System.out.println("entry: " + Integer.toString(entry, 16)); - System.out.println("phoff: " + Integer.toString(phoff, 16)); - System.out.println("shoff: " + Integer.toString(shoff, 16)); - System.out.println("flags: " + Integer.toString(flags, 16)); - System.out.println("ehsize: " + Integer.toString(ehsize, 16)); - System.out.println("phentsize: " + Integer.toString(phentsize, 16)); - System.out.println("phentnum: " + Integer.toString(phnum, 16)); - System.out.println("shentsize: " + Integer.toString(shentsize, 16)); - System.out.println("shentnum: " + Integer.toString(shnum, 16)); - System.out.println("shstrndx: " + Integer.toString(shstrndx, 16)); + if (DEBUG) { + System.out.println("-- ELF Header --"); + System.out.println("type: " + Integer.toString(type, 16)); + System.out.println("machine: " + Integer.toString(machine, 16)); + System.out.println("version: " + Integer.toString(version, 16)); + System.out.println("entry: " + Integer.toString(entry, 16)); + System.out.println("phoff: " + Integer.toString(phoff, 16)); + System.out.println("shoff: " + Integer.toString(shoff, 16)); + System.out.println("flags: " + Integer.toString(flags, 16)); + System.out.println("ehsize: " + Integer.toString(ehsize, 16)); + System.out.println("phentsize: " + Integer.toString(phentsize, 16)); + System.out.println("phentnum: " + Integer.toString(phnum, 16)); + System.out.println("shentsize: " + Integer.toString(shentsize, 16)); + System.out.println("shentnum: " + Integer.toString(shnum, 16)); + System.out.println("shstrndx: " + Integer.toString(shstrndx, 16)); + } } public ELFSection readSectionHeader() { @@ -220,7 +222,9 @@ programs = new ELFProgram[phnum]; for (int i = 0, n = phnum; i < n; i++) { programs[i] = readProgramHeader(); - System.out.println("-- Program header --\n" + programs[i].toString()); + if (DEBUG) { + System.out.println("-- Program header --\n" + programs[i].toString()); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2007-10-25 12:22:00
|
Revision: 10 http://mspsim.svn.sourceforge.net/mspsim/?rev=10&view=rev Author: joxe Date: 2007-10-25 05:21:58 -0700 (Thu, 25 Oct 2007) Log Message: ----------- fixed bug in BIT instruction Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/tests/cputest.c Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2007-10-25 11:10:47 UTC (rev 9) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2007-10-25 12:21:58 UTC (rev 10) @@ -862,11 +862,12 @@ case BIT: // BIT dst = src & dst; sr = readRegister(SR); + // Clear overflow and carry! + sr = sr & ~(CARRY | OVERFLOW); + // Set carry if result is non-zero! if (dst != 0) { sr |= CARRY; } - // Clear overflow! - sr &= ~OVERFLOW; writeRegister(SR, sr); break; case BIC: // BIC Modified: mspsim/tests/cputest.c =================================================================== --- mspsim/tests/cputest.c 2007-10-25 11:10:47 UTC (rev 9) +++ mspsim/tests/cputest.c 2007-10-25 12:21:58 UTC (rev 10) @@ -169,24 +169,16 @@ /*--------------------------------------------------------------------------*/ static void testModulo() { - int c,i; - c = 1; + int c; testCase("Modulo"); - do { - i = 13; - i = i % 14; -/* printf("(%d,%d,%d)\n",i, (i % 14), i==1); */ -/* printf("(%d,%d,%d)\n",i, (i % 14), i==1); */ - if (i < 0) printf("%d\n",i); - - - c = c + 1; - } while (c < 3); - -/* if((i % 5) == 0) { */ -/* assertTrue(i != 1); */ -/* } */ + for(c = 2; c >= 0; c--) { + if((c % 5) == 0) { + assertTrue(c != 1); + } + printf("(%d,%d,%d)\n", c, (c % 5), c==1); + printf("(%d,%d,%d)\n", c, (c % 5), c==1); + } } /*--------------------------------------------------------------------------*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2007-11-19 10:29:38
|
Revision: 25 http://mspsim.svn.sourceforge.net/mspsim/?rev=25&view=rev Author: joxe Date: 2007-11-19 02:29:23 -0800 (Mon, 19 Nov 2007) Log Message: ----------- added very simple sky firmware Modified Paths: -------------- mspsim/Makefile mspsim/se/sics/mspsim/platform/sky/SkyGui.java mspsim/se/sics/mspsim/platform/sky/SkyNode.java Added Paths: ----------- mspsim/firmware/sky/ mspsim/firmware/sky/blink.firmware Modified: mspsim/Makefile =================================================================== --- mspsim/Makefile 2007-11-05 09:35:29 UTC (rev 24) +++ mspsim/Makefile 2007-11-19 10:29:23 UTC (rev 25) @@ -54,7 +54,7 @@ ifndef FIRMWAREFILE ESBFIRMWARE = firmware/esb/sensor-demo.firmware -SKYFIRMWARE = firmware/sky/sensor-demo.firmware +SKYFIRMWARE = firmware/sky/blink.firmware else ESBFIRMWARE = $FIRMWAREFILE SKYFIRMWARE = $FIRMWAREFILE Added: mspsim/firmware/sky/blink.firmware =================================================================== (Binary files differ) Property changes on: mspsim/firmware/sky/blink.firmware ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: mspsim/se/sics/mspsim/platform/sky/SkyGui.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyGui.java 2007-11-05 09:35:29 UTC (rev 24) +++ mspsim/se/sics/mspsim/platform/sky/SkyGui.java 2007-11-19 10:29:23 UTC (rev 25) @@ -58,15 +58,18 @@ public class SkyGui extends JComponent implements KeyListener, MouseMotionListener { - public static final int GREEN_Y = 34; + public static final int GREEN_Y = 39; public static final int BLUE_Y = 47; + public static final int RED_Y = 34; public static final int LED_X = 10; public static final Color BLUE_TRANS = new Color(0x40,0x40,0xff,0xa0); public static final Color GREEN_TRANS = new Color(0x40, 0xf0, 0x40, 0xa0); + public static final Color RED_TRANS = new Color(0xf0, 0x40, 0x40, 0xa0); public static final Color BLUE_C = new Color(0xff8080ff); public static final Color GREEN_C = new Color(0xff60ff60); + public static final Color RED_C = new Color(0xffff8000); private SerialMon serial; private SerialMon radio; @@ -133,6 +136,12 @@ } // Display all active leds + if (node.redLed) { + g.setColor(RED_TRANS); + g.fillOval(LED_X - 2, RED_Y - 1, 9, 5); + g.setColor(RED_C); + g.fillOval(LED_X, RED_Y, 4, 3); + } if (node.greenLed) { g.setColor(GREEN_TRANS); g.fillOval(LED_X - 2, GREEN_Y - 1, 9, 5); Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2007-11-05 09:35:29 UTC (rev 24) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2007-11-19 10:29:23 UTC (rev 25) @@ -65,13 +65,16 @@ private IOPort port1; private IOPort port2; private IOPort port4; + private IOPort port5; private CC2420 radio; private ExtFlash flash; - public static final int BLUE_LED = 0x01; - public static final int GREEN_LED = 0x02; + public static final int BLUE_LED = 0x40; + public static final int GREEN_LED = 0x20; + public static final int RED_LED = 0x10; + public boolean redLed; public boolean blueLed; public boolean greenLed; @@ -82,11 +85,10 @@ */ public SkyNode(MSP430 cpu) { this.cpu = cpu; - IOUnit unit = cpu.getIOUnit("Port 2"); + IOUnit unit = cpu.getIOUnit("Port 5"); if (unit instanceof IOPort) { - port2 = (IOPort) unit; - System.out.println("Found port 2!!!"); - port2.setPortListener(this); + port5 = (IOPort) unit; + port5.setPortListener(this); } unit = cpu.getIOUnit("Port 1"); @@ -124,7 +126,8 @@ public void portWrite(IOPort source, int data) { - if (source == port2) { + if (source == port5) { + redLed = (data & RED_LED) == 0; blueLed = (data & BLUE_LED) == 0; greenLed = (data & GREEN_LED) == 0; if (gui != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2007-12-07 10:15:43
|
Revision: 67 http://mspsim.svn.sourceforge.net/mspsim/?rev=67&view=rev Author: joxe Date: 2007-12-07 02:15:39 -0800 (Fri, 07 Dec 2007) Log Message: ----------- added changelog Modified Paths: -------------- mspsim/Makefile mspsim/se/sics/mspsim/platform/sky/SkyNode.java Added Paths: ----------- mspsim/CHANGE_LOG.txt Added: mspsim/CHANGE_LOG.txt =================================================================== --- mspsim/CHANGE_LOG.txt (rev 0) +++ mspsim/CHANGE_LOG.txt 2007-12-07 10:15:39 UTC (rev 67) @@ -0,0 +1,12 @@ + +0.81 - ELF Stabs, source debugging (2007-12-07) +Changes: +- support for ELF debug information (stab section) +- possible to convert address into linenumber and file +- simple source-level viewer that shows current execution position + (and updates during single stepping) - with highlighting for C. +- support for LPM/CPUOFF which stops instruction emulation when in + LPM modes +- refactored profiling into separate classes + +0.8 - Initial release (2007-11-26) Modified: mspsim/Makefile =================================================================== --- mspsim/Makefile 2007-12-07 08:56:27 UTC (rev 66) +++ mspsim/Makefile 2007-12-07 10:15:39 UTC (rev 67) @@ -62,7 +62,7 @@ CPUTEST := tests/cputest.firmware -BINARY := README.txt license.txt images/*.jpg firmware/*/*.firmware +BINARY := README.txt license.txt CHANGE_LOG.txt images/*.jpg firmware/*/*.firmware PACKAGES := ${addprefix se/sics/mspsim/,core platform/esb platform/sky util chip extutil/highlight} Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2007-12-07 08:56:27 UTC (rev 66) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2007-12-07 10:15:39 UTC (rev 67) @@ -46,6 +46,7 @@ import se.sics.mspsim.core.*; import se.sics.mspsim.extutil.highlight.HighlightSourceViewer; import se.sics.mspsim.util.*; +import java.io.File; /** * Emulation of Sky Mote @@ -190,6 +191,7 @@ node.gui = new SkyGui(node); ControlUI control = new ControlUI(cpu, elf); HighlightSourceViewer sourceViewer = new HighlightSourceViewer(); + sourceViewer.addSearchPath(new File("e:/work/contiki-2.x/examples/sky/")); control.setSourceViewer(sourceViewer); if (args.length > 1) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-02-05 14:38:39
|
Revision: 108 http://mspsim.svn.sourceforge.net/mspsim/?rev=108&view=rev Author: joxe Date: 2008-02-05 06:38:32 -0800 (Tue, 05 Feb 2008) Log Message: ----------- fixed configuration of ext flash Modified Paths: -------------- mspsim/CHANGE_LOG.txt mspsim/se/sics/mspsim/chip/M25P80.java mspsim/se/sics/mspsim/platform/sky/SkyNode.java Modified: mspsim/CHANGE_LOG.txt =================================================================== --- mspsim/CHANGE_LOG.txt 2008-02-05 14:31:14 UTC (rev 107) +++ mspsim/CHANGE_LOG.txt 2008-02-05 14:38:32 UTC (rev 108) @@ -1,3 +1,7 @@ +0.83 +Changes: +- added support for external flash on Sky node (M25P80) + 0.82 - JFreechart, operation mode statistics (2008-02-03) Changes: - added jfreechart diagrams for stack and operation mode statistics Modified: mspsim/se/sics/mspsim/chip/M25P80.java =================================================================== --- mspsim/se/sics/mspsim/chip/M25P80.java 2008-02-05 14:31:14 UTC (rev 107) +++ mspsim/se/sics/mspsim/chip/M25P80.java 2008-02-05 14:38:32 UTC (rev 108) @@ -86,15 +86,18 @@ private RandomAccessFile file; - public M25P80(USART usart) { + public M25P80(USART usart, String filename) { this.usart = usart; + if (filename == null) + filename = "flash.bin"; + // Open flash file for R/W try { - file = new RandomAccessFile("flash.bin", "rw"); + file = new RandomAccessFile(filename, "rw"); } catch (FileNotFoundException e) { e.printStackTrace(); return; } - + // Set size of flash try { file.setLength(1024 * 1024); } catch (IOException e) { Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-02-05 14:31:14 UTC (rev 107) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-02-05 14:38:32 UTC (rev 108) @@ -91,6 +91,7 @@ private CC2420 radio; private M25P80 flash; + private String flashFile; public static final int BLUE_LED = 0x40; public static final int GREEN_LED = 0x20; @@ -108,8 +109,9 @@ * Creates a new <code>SkyNode</code> instance. * */ - public SkyNode(MSP430 cpu) { + public SkyNode(MSP430 cpu, String flashFile) { this.cpu = cpu; + this.flashFile = flashFile; IOUnit unit = cpu.getIOUnit("Port 5"); if (unit instanceof IOPort) { port5 = (IOPort) unit; @@ -132,7 +134,7 @@ radio.setCCAPort(port1, CC2420_CCA); radio.setFIFOPPort(port1, CC2420_FIFOP); radio.setFIFOPort(port1, CC2420_FIFO); - flash = new M25P80((USART)usart0); + flash = new M25P80((USART)usart0, flashFile); ((USART) usart0).setUSARTListener(this); port4 = (IOPort) cpu.getIOUnit("Port 4"); if (port4 != null && port4 instanceof IOPort) { @@ -222,9 +224,19 @@ cpu.getDisAsm().setMap(map); cpu.setMap(map); } - + + // create a filename for the flash file + // This should be possible to take from a config file later! + String fileName = args[0]; + int ix = fileName.lastIndexOf('.'); + if (ix > 0) { + fileName = fileName.substring(0, ix); + } + fileName = fileName + ".flash"; + System.out.println("Using flash file: " + fileName); + cpu.reset(); - SkyNode node = new SkyNode(cpu); + SkyNode node = new SkyNode(cpu, fileName); node.gui = new SkyGui(node); ControlUI control = new ControlUI(cpu, elf); HighlightSourceViewer sourceViewer = new HighlightSourceViewer(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-02-19 19:56:46
|
Revision: 138 http://mspsim.svn.sourceforge.net/mspsim/?rev=138&view=rev Author: joxe Date: 2008-02-19 11:56:31 -0800 (Tue, 19 Feb 2008) Log Message: ----------- updated changelog. Modified Paths: -------------- mspsim/CHANGE_LOG.txt mspsim/se/sics/mspsim/platform/sky/SkyNode.java Modified: mspsim/CHANGE_LOG.txt =================================================================== --- mspsim/CHANGE_LOG.txt 2008-02-19 16:16:06 UTC (rev 137) +++ mspsim/CHANGE_LOG.txt 2008-02-19 19:56:31 UTC (rev 138) @@ -1,3 +1,9 @@ +0.84 +Changes: +- fixed bug in source file handling in ELF symbol loader +- fixed RSSI-ready flag to be set in CC2420 +- refactored code from Sky/ESB into GenericNode + 0.83 Changes: - added support for external flash on Sky node (M25P80) Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-02-19 16:16:06 UTC (rev 137) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-02-19 19:56:31 UTC (rev 138) @@ -152,8 +152,6 @@ mode = newMode; modeChanged(mode); } - // TODO: put this somewhere else!!! - //stats.printStat(); if (gui != null) { gui.repaint(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-03-09 00:52:17
|
Revision: 160 http://mspsim.svn.sourceforge.net/mspsim/?rev=160&view=rev Author: joxe Date: 2008-03-08 16:52:15 -0800 (Sat, 08 Mar 2008) Log Message: ----------- added some more command types to support pipe implementation. Modified Paths: -------------- mspsim/CHANGE_LOG.txt mspsim/se/sics/mspsim/cli/CommandContext.java mspsim/se/sics/mspsim/cli/CommandHandler.java mspsim/se/sics/mspsim/cli/DebugCommands.java mspsim/se/sics/mspsim/core/MSP430.java mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/se/sics/mspsim/platform/GenericNode.java mspsim/se/sics/mspsim/platform/sky/SkyNode.java mspsim/se/sics/mspsim/ui/DebugUI.java Added Paths: ----------- mspsim/se/sics/mspsim/cli/AsyncCommand.java mspsim/se/sics/mspsim/cli/BasicAsyncCommand.java mspsim/se/sics/mspsim/cli/BasicLineCommand.java Removed Paths: ------------- mspsim/se/sics/mspsim/util/BasicCommand.java mspsim/se/sics/mspsim/util/Command.java mspsim/se/sics/mspsim/util/CommandBundle.java mspsim/se/sics/mspsim/util/CommandContext.java mspsim/se/sics/mspsim/util/CommandHandler.java mspsim/se/sics/mspsim/util/CommandParser.java mspsim/se/sics/mspsim/util/DebugCommands.java Modified: mspsim/CHANGE_LOG.txt =================================================================== --- mspsim/CHANGE_LOG.txt 2008-03-08 08:13:09 UTC (rev 159) +++ mspsim/CHANGE_LOG.txt 2008-03-09 00:52:15 UTC (rev 160) @@ -1,6 +1,7 @@ 0.85 Changes: - fixed multiplier to handle the different modes better. +- 0.84 Changes: Added: mspsim/se/sics/mspsim/cli/AsyncCommand.java =================================================================== --- mspsim/se/sics/mspsim/cli/AsyncCommand.java (rev 0) +++ mspsim/se/sics/mspsim/cli/AsyncCommand.java 2008-03-09 00:52:15 UTC (rev 160) @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2007, 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. + * + * This file is part of MSPSim. + * + * $Id: $ + * + * ----------------------------------------------------------------- + * + * AsyncCommand - a command that will continue its execution after it + * returns from the executeCommand method. + * + * Author : Joakim Eriksson + * Created : 9 mar 2008 + * Updated : $Date:$ + * $Revision:$ + */ +package se.sics.mspsim.cli; + +/** + * @author joakim + * + */ +public interface AsyncCommand extends Command { + public void stopCommand(CommandContext context); +} Added: mspsim/se/sics/mspsim/cli/BasicAsyncCommand.java =================================================================== --- mspsim/se/sics/mspsim/cli/BasicAsyncCommand.java (rev 0) +++ mspsim/se/sics/mspsim/cli/BasicAsyncCommand.java 2008-03-09 00:52:15 UTC (rev 160) @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2007, 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. + * + * This file is part of MSPSim. + * + * $Id: $ + * + * ----------------------------------------------------------------- + * + * BasicAsyncCommand + * + * Author : Joakim Eriksson + * Created : 9 mar 2008 + * Updated : $Date:$ + * $Revision:$ + */ +package se.sics.mspsim.cli; + +/** + * @author joakim + * + */ +public abstract class BasicAsyncCommand extends BasicCommand implements + AsyncCommand { + + public BasicAsyncCommand(String cmdHelp, String argHelp) { + super(cmdHelp, argHelp); + } +} Added: mspsim/se/sics/mspsim/cli/BasicLineCommand.java =================================================================== --- mspsim/se/sics/mspsim/cli/BasicLineCommand.java (rev 0) +++ mspsim/se/sics/mspsim/cli/BasicLineCommand.java 2008-03-09 00:52:15 UTC (rev 160) @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2007, 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. + * + * This file is part of MSPSim. + * + * $Id: $ + * + * ----------------------------------------------------------------- + * + * BasicLineCommand + * + * Author : Joakim Eriksson + * Created : 9 mar 2008 + * Updated : $Date:$ + * $Revision:$ + */ +package se.sics.mspsim.cli; + +/** + * @author joakim + * + */ +public abstract class BasicLineCommand extends BasicAsyncCommand implements + LineListener { + + public BasicLineCommand(String cmdHelp, String argHelp) { + super(cmdHelp, argHelp); + } +} Modified: mspsim/se/sics/mspsim/cli/CommandContext.java =================================================================== --- mspsim/se/sics/mspsim/cli/CommandContext.java 2008-03-08 08:13:09 UTC (rev 159) +++ mspsim/se/sics/mspsim/cli/CommandContext.java 2008-03-09 00:52:15 UTC (rev 160) @@ -10,19 +10,27 @@ private String[] args; private MapTable mapTable; + private int pid; + public final PrintStream out; public final PrintStream err; public final InputStream in; + private CommandContext nextCommand; + public CommandContext(MapTable table, String[] args, - InputStream in, PrintStream out, PrintStream err) { + int pid, InputStream in, PrintStream out, PrintStream err) { this.args = args; this.out = out; this.err = err; this.in = in; + this.pid = pid; mapTable = table; } + public int getPID() { + return pid; + } /** * exit needs to be called as soon as the command is completed (or stopped). Modified: mspsim/se/sics/mspsim/cli/CommandHandler.java =================================================================== --- mspsim/se/sics/mspsim/cli/CommandHandler.java 2008-03-08 08:13:09 UTC (rev 159) +++ mspsim/se/sics/mspsim/cli/CommandHandler.java 2008-03-09 00:52:15 UTC (rev 160) @@ -18,60 +18,60 @@ private Hashtable<String, Command> commands = new Hashtable<String, Command>(); private boolean exit; private boolean workaround = false; - + private BufferedReader inReader; private InputStream in; private PrintStream out; private PrintStream err; private MapTable mapTable; private ComponentRegistry registry; - + public CommandHandler() { exit = false; inReader = new BufferedReader(new InputStreamReader(in = System.in)); out = System.out; err = System.err; - + registerCommand("help", new Command() { public int executeCommand(CommandContext context) { if (context.getArgumentCount() == 0) { - context.out.println("Available commands:"); - for(Map.Entry entry: commands.entrySet()) { - String name = (String) entry.getKey(); - Command command = (Command) entry.getValue(); - CommandContext cc = new CommandContext(mapTable, new String[] { - name - }, context.in, context.out, context.err); - String prefix = ' ' + name + ' ' + command.getArgumentHelp(cc); - String helpText = command.getCommandHelp(cc); - int n; - if (helpText != null && (n = helpText.indexOf('\n')) > 0) { - helpText = helpText.substring(0, n); - } - context.out.print(prefix); - if (prefix.length() < 8) { - context.out.print('\t'); - } - if (prefix.length() < 16) { - context.out.print('\t'); - } - context.out.println("\t " + helpText); - } - return 0; - } + context.out.println("Available commands:"); + for(Map.Entry entry: commands.entrySet()) { + String name = (String) entry.getKey(); + Command command = (Command) entry.getValue(); + CommandContext cc = new CommandContext(mapTable, new String[] { + name + }, 0, context.in, context.out, context.err); + String prefix = ' ' + name + ' ' + command.getArgumentHelp(cc); + String helpText = command.getCommandHelp(cc); + int n; + if (helpText != null && (n = helpText.indexOf('\n')) > 0) { + helpText = helpText.substring(0, n); + } + context.out.print(prefix); + if (prefix.length() < 8) { + context.out.print('\t'); + } + if (prefix.length() < 16) { + context.out.print('\t'); + } + context.out.println("\t " + helpText); + } + return 0; + } - String cmd = context.getArgument(0); - Command command = commands.get(cmd); - if (command != null) { - CommandContext cc = new CommandContext(mapTable, new String[] { - cmd - }, context.in, context.out, context.err); - context.out.println(cmd + ' ' + command.getArgumentHelp(cc)); - context.out.println(" " + command.getCommandHelp(cc)); - return 0; - } - context.err.println("Error: unknown command '" + cmd + '\''); - return 1; + String cmd = context.getArgument(0); + Command command = commands.get(cmd); + if (command != null) { + CommandContext cc = new CommandContext(mapTable, new String[] { + cmd + }, 0, context.in, context.out, context.err); + context.out.println(cmd + ' ' + command.getArgumentHelp(cc)); + context.out.println(" " + command.getCommandHelp(cc)); + return 0; + } + context.err.println("Error: unknown command '" + cmd + '\''); + return 1; } public String getArgumentHelp(CommandContext context) { return "<command>"; @@ -87,62 +87,63 @@ } }); } - + // Add it to the hashtable (overwriting anything there) public void registerCommand(String cmd, Command command) { commands.put(cmd, command); } - + private String readLine(BufferedReader inReader2) throws IOException { if (workaround) { - StringBuilder str = new StringBuilder(); - while(true) { - if (inReader2.ready()) { - int c = inReader2.read(); - if (c == '\n') { - return str.toString(); + StringBuilder str = new StringBuilder(); + while(true) { + if (inReader2.ready()) { + int c = inReader2.read(); + if (c == '\n') { + return str.toString(); + } + if (c != '\r') { + str.append((char)c); + } + } else { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + throw new InterruptedIOException(); + } } - if (c != '\r') { - str.append((char)c); - } - } else { - try { - Thread.sleep(500); - } catch (InterruptedException e) { - throw new InterruptedIOException(); - } } - } } else { return inReader2.readLine(); } } - + public void run() { while(!exit) { - try { + try { out.print(">"); out.flush(); String line = readLine(inReader);//.readLine(); if (line != null && line.length() > 0) { - String[][] parts = CommandParser.parseLine(line); - if(parts.length > 0) { - // TODO add support for pipes - String[] args = parts[0]; - Command cmd = commands.get(args[0]); - if (cmd == null) { - out.println("Error: Unknown command " + args[0]); - } else { - CommandContext cc = new CommandContext(mapTable, args, in, out, err); - try { - cmd.executeCommand(cc); - } catch (Exception e) { - err.println("Error: Command failed: " + e.getMessage()); - e.printStackTrace(err); - } - } - } + String[][] parts = CommandParser.parseLine(line); + if(parts.length > 0) { + checkCommands(parts); + // TODO add support for pipes + String[] args = parts[0]; + Command cmd = commands.get(args[0]); + if (cmd == null) { + out.println("Error: Unknown command " + args[0]); + } else { + CommandContext cc = new CommandContext(mapTable, args, 0, in, out, err); + try { + cmd.executeCommand(cc); + } catch (Exception e) { + err.println("Error: Command failed: " + e.getMessage()); + e.printStackTrace(err); + } + } + } } } catch (IOException e) { e.printStackTrace(); @@ -152,6 +153,17 @@ } } + private int checkCommands(String[][] cmds) { + for (int i = 0; i < cmds.length; i++) { + Command command = commands.get(cmds[i][0]); + if (i > 0 && command != null && !(command instanceof LineListener)) { + System.out.println("CLI: Error " + cmds[i][0] + " does not take input"); + return -1; + } + } + return 0; + } + public void setComponentRegistry(ComponentRegistry registry) { this.registry = registry; } @@ -159,14 +171,14 @@ public void setWorkaround(boolean w) { workaround = w; } - + public void start() { mapTable = (MapTable) registry.getComponent(MapTable.class); Object[] commandBundles = registry.getAllComponents(CommandBundle.class); if (commandBundles != null) { for (int i = 0, n = commandBundles.length; i < n; i++) { - ((CommandBundle) commandBundles[i]).setupCommands(registry, this); + ((CommandBundle) commandBundles[i]).setupCommands(registry, this); } } new Thread(this, "cmd").start(); Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2008-03-08 08:13:09 UTC (rev 159) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2008-03-09 00:52:15 UTC (rev 160) @@ -77,8 +77,10 @@ } }); - ch.registerCommand("watch", new Command() { + ch.registerCommand("watch", + new BasicAsyncCommand("adds a write watch to a given address or symbol", "<address or symbol>") { int mode = 0; + int address = 0; public int executeCommand(final CommandContext context) { int baddr = context.getArgumentAsAddress(0); if (baddr == -1) { @@ -91,7 +93,7 @@ mode = 1; } } - cpu.setBreakPoint(baddr, + cpu.setBreakPoint(address = baddr, new CPUMonitor() { public void cpuAction(int type, int adr, int data) { if (mode == 0) { @@ -108,14 +110,10 @@ context.out.println("Watch set at: " + baddr); return 0; } - - public String getArgumentHelp(CommandContext context) { - return "<address or symbol>"; + + public void stopCommand(CommandContext context) { + cpu.clearBreakPoint(address); } - - public String getCommandHelp(CommandContext context) { - return "adds a write watch to a given address or symbol"; - } }); ch.registerCommand("clear", new Command() { @@ -197,6 +195,17 @@ return 0; } }); + // Does nothign yet... TODO!!! + ch.registerCommand("grep", new BasicLineCommand("grep", "regexp") { + public void lineRead(String line) { + } + public void stopCommand(CommandContext context) { + } + public int executeCommand(CommandContext context) { + return 0; + } + + }); } } } Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2008-03-08 08:13:09 UTC (rev 159) +++ mspsim/se/sics/mspsim/core/MSP430.java 2008-03-09 00:52:15 UTC (rev 160) @@ -1,4 +1,4 @@ -/** + /** * Copyright (c) 2007, Swedish Institute of Computer Science. * All rights reserved. * Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2008-03-08 08:13:09 UTC (rev 159) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2008-03-09 00:52:15 UTC (rev 160) @@ -252,9 +252,13 @@ breakPoints[address] = mon; } - public boolean hasBreakpoint(int address) { + public boolean hasBreakPoint(int address) { return breakPoints[address] != null; } + + public void clearBreakPoint(int address) { + breakPoints[address] = null; + } public void setRegisterWriteMonitor(int r, CPUMonitor mon) { regWriteMonitors[r] = mon; Modified: mspsim/se/sics/mspsim/platform/GenericNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/GenericNode.java 2008-03-08 08:13:09 UTC (rev 159) +++ mspsim/se/sics/mspsim/platform/GenericNode.java 2008-03-09 00:52:15 UTC (rev 160) @@ -41,14 +41,14 @@ import java.io.File; import java.io.IOException; +import se.sics.mspsim.cli.CommandHandler; +import se.sics.mspsim.cli.DebugCommands; import se.sics.mspsim.core.Chip; import se.sics.mspsim.core.MSP430; import se.sics.mspsim.extutil.highlight.HighlightSourceViewer; import se.sics.mspsim.extutil.jfreechart.DataChart; import se.sics.mspsim.ui.ControlUI; -import se.sics.mspsim.util.CommandHandler; import se.sics.mspsim.util.ComponentRegistry; -import se.sics.mspsim.util.DebugCommands; import se.sics.mspsim.util.ELF; import se.sics.mspsim.util.IHexReader; import se.sics.mspsim.util.MapTable; Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-03-08 08:13:09 UTC (rev 159) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-03-09 00:52:15 UTC (rev 160) @@ -46,6 +46,8 @@ import se.sics.mspsim.chip.CC2420; import se.sics.mspsim.chip.M25P80; import se.sics.mspsim.chip.PacketListener; +import se.sics.mspsim.cli.CommandHandler; +import se.sics.mspsim.cli.DebugCommands; import se.sics.mspsim.core.CPUMonitor; import se.sics.mspsim.core.Chip; import se.sics.mspsim.core.IOPort; @@ -60,10 +62,8 @@ import se.sics.mspsim.extutil.jfreechart.DataSourceSampler; import se.sics.mspsim.platform.GenericNode; import se.sics.mspsim.ui.ControlUI; -import se.sics.mspsim.util.CommandHandler; import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.DataSource; -import se.sics.mspsim.util.DebugCommands; import se.sics.mspsim.util.ELF; import se.sics.mspsim.util.IHexReader; import se.sics.mspsim.util.MapTable; Modified: mspsim/se/sics/mspsim/ui/DebugUI.java =================================================================== --- mspsim/se/sics/mspsim/ui/DebugUI.java 2008-03-08 08:13:09 UTC (rev 159) +++ mspsim/se/sics/mspsim/ui/DebugUI.java 2008-03-09 00:52:15 UTC (rev 160) @@ -186,7 +186,7 @@ s += "; " + i.getFunction(); } pos = i.getPos(); - if (cpu.hasBreakpoint(pos)) { + if (cpu.hasBreakPoint(pos)) { s = "*B " + s; } else { s = " " + s; Deleted: mspsim/se/sics/mspsim/util/BasicCommand.java =================================================================== --- mspsim/se/sics/mspsim/util/BasicCommand.java 2008-03-08 08:13:09 UTC (rev 159) +++ mspsim/se/sics/mspsim/util/BasicCommand.java 2008-03-09 00:52:15 UTC (rev 160) @@ -1,62 +0,0 @@ -/** - * Copyright (c) 2008, 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. - * - * This file is part of MSPSim. - * - * $Id$ - * - * ----------------------------------------------------------------- - * - * BasicCommand - * - * Author : Joakim Eriksson, Niclas Finne - * Created : Mon Feb 11 21:28:00 2008 - * Updated : $Date: 2007/10/21 21:17:34 $ - * $Revision: 1.3 $ - */ - -package se.sics.mspsim.util; - -public abstract class BasicCommand implements Command { - - private String argumentHelp; - private String commandHelp; - - public BasicCommand(String cmdHelp, String argHelp) { - commandHelp = cmdHelp; - argumentHelp = argHelp; - } - - public String getArgumentHelp(CommandContext context) { - return argumentHelp; - } - - public String getCommandHelp(CommandContext context) { - return commandHelp; - } - -} Deleted: mspsim/se/sics/mspsim/util/Command.java =================================================================== --- mspsim/se/sics/mspsim/util/Command.java 2008-03-08 08:13:09 UTC (rev 159) +++ mspsim/se/sics/mspsim/util/Command.java 2008-03-09 00:52:15 UTC (rev 160) @@ -1,7 +0,0 @@ -package se.sics.mspsim.util; - -public interface Command { - public int executeCommand(CommandContext context); - public String getCommandHelp(CommandContext context); - public String getArgumentHelp(CommandContext context); -} Deleted: mspsim/se/sics/mspsim/util/CommandBundle.java =================================================================== --- mspsim/se/sics/mspsim/util/CommandBundle.java 2008-03-08 08:13:09 UTC (rev 159) +++ mspsim/se/sics/mspsim/util/CommandBundle.java 2008-03-09 00:52:15 UTC (rev 160) @@ -1,48 +0,0 @@ -/** - * Copyright (c) 2008, 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. - * - * This file is part of MSPSim. - * - * $Id$ - * - * ----------------------------------------------------------------- - * - * CommandBundle - * - * Author : Joakim Eriksson, Niclas Finne - * Created : Mon Feb 11 21:28:00 2008 - * Updated : $Date: 2007/10/21 21:17:34 $ - * $Revision: 1.3 $ - */ - -package se.sics.mspsim.util; - -public interface CommandBundle { - - public void setupCommands(ComponentRegistry registry, CommandHandler handler); - -} Deleted: mspsim/se/sics/mspsim/util/CommandContext.java =================================================================== --- mspsim/se/sics/mspsim/util/CommandContext.java 2008-03-08 08:13:09 UTC (rev 159) +++ mspsim/se/sics/mspsim/util/CommandContext.java 2008-03-09 00:52:15 UTC (rev 160) @@ -1,74 +0,0 @@ -package se.sics.mspsim.util; - -import java.io.InputStream; -import java.io.PrintStream; - - -public class CommandContext { - - private String[] args; - private MapTable mapTable; - public final PrintStream out; - public final PrintStream err; - public final InputStream in; - - public CommandContext(MapTable table, String[] args, - InputStream in, PrintStream out, PrintStream err) { - this.args = args; - this.out = out; - this.err = err; - this.in = in; - mapTable = table; - } - - public int getArgumentCount() { - return args.length - 1; - } - - public String getArgument(int index) { - return args[index + 1]; - } - - public MapTable getMapTable() { - return mapTable; - } - - public String getCommand() { - return args[0]; - } - - public int getArgumentAsAddress(int index) { - String adr = getArgument(index); - if (adr == null || adr.length() == 0) return 0; - adr = adr.trim(); - if (adr.charAt(0) == '$') { - try { - return Integer.parseInt(adr.substring(1), 16); - } catch (Exception e) { - err.println("Illegal hex number format: " + adr); - } - } else if (Character.isDigit(adr.charAt(0))) { - try { - return Integer.parseInt(adr); - } catch (Exception e) { - err.println("Illegal number format: " + adr); - } - } else { - // Assume that it is a symbol - if (mapTable != null) { - return mapTable.getFunctionAddress(adr); - } - } - return 0; - } - - public int getArgumentAsInt(int i) { - try { - return Integer.parseInt(getArgument(i)); - } catch (Exception e) { - err.println("Illegal number format: " + getArgument(i)); - } - return 0; - } - -} Deleted: mspsim/se/sics/mspsim/util/CommandHandler.java =================================================================== --- mspsim/se/sics/mspsim/util/CommandHandler.java 2008-03-08 08:13:09 UTC (rev 159) +++ mspsim/se/sics/mspsim/util/CommandHandler.java 2008-03-09 00:52:15 UTC (rev 160) @@ -1,170 +0,0 @@ -package se.sics.mspsim.util; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.InterruptedIOException; -import java.io.PrintStream; -import java.util.Hashtable; -import java.util.Map; - -public class CommandHandler implements ActiveComponent, Runnable { - - private Hashtable<String, Command> commands = new Hashtable<String, Command>(); - private boolean exit; - private boolean workaround = false; - - private BufferedReader inReader; - private InputStream in; - private PrintStream out; - private PrintStream err; - private MapTable mapTable; - private ComponentRegistry registry; - - public CommandHandler() { - exit = false; - inReader = new BufferedReader(new InputStreamReader(in = System.in)); - out = System.out; - err = System.err; - - registerCommand("help", new Command() { - public int executeCommand(CommandContext context) { - if (context.getArgumentCount() == 0) { - context.out.println("Available commands:"); - for(Map.Entry entry: commands.entrySet()) { - String name = (String) entry.getKey(); - Command command = (Command) entry.getValue(); - CommandContext cc = new CommandContext(mapTable, new String[] { - name - }, context.in, context.out, context.err); - String prefix = ' ' + name + ' ' + command.getArgumentHelp(cc); - String helpText = command.getCommandHelp(cc); - int n; - if (helpText != null && (n = helpText.indexOf('\n')) > 0) { - helpText = helpText.substring(0, n); - } - context.out.print(prefix); - if (prefix.length() < 8) { - context.out.print('\t'); - } - if (prefix.length() < 16) { - context.out.print('\t'); - } - context.out.println("\t " + helpText); - } - return 0; - } - - String cmd = context.getArgument(0); - Command command = commands.get(cmd); - if (command != null) { - CommandContext cc = new CommandContext(mapTable, new String[] { - cmd - }, context.in, context.out, context.err); - context.out.println(cmd + ' ' + command.getArgumentHelp(cc)); - context.out.println(" " + command.getCommandHelp(cc)); - return 0; - } - context.err.println("Error: unknown command '" + cmd + '\''); - return 1; - } - public String getArgumentHelp(CommandContext context) { - return "<command>"; - } - public String getCommandHelp(CommandContext context) { - return "shows help for the specified command"; - } - }); - registerCommand("workaround", new BasicCommand("", "") { - public int executeCommand(CommandContext context) { - workaround = true; - return 0; - } - }); - } - - // Add it to the hashtable (overwriting anything there) - public void registerCommand(String cmd, Command command) { - commands.put(cmd, command); - } - - - private String readLine(BufferedReader inReader2) throws IOException { - if (workaround) { - StringBuilder str = new StringBuilder(); - while(true) { - if (inReader2.ready()) { - int c = inReader2.read(); - if (c == '\n') { - return str.toString(); - } - if (c != '\r') { - str.append((char)c); - } - } else { - try { - Thread.sleep(500); - } catch (InterruptedException e) { - throw new InterruptedIOException(); - } - } - } - } else { - return inReader2.readLine(); - } - } - - public void run() { - while(!exit) { - try { - out.print(">"); - out.flush(); - String line = readLine(inReader);//.readLine(); - if (line != null && line.length() > 0) { - String[][] parts = CommandParser.parseLine(line); - if(parts.length > 0) { - // TODO add support for pipes - String[] args = parts[0]; - Command cmd = commands.get(args[0]); - if (cmd == null) { - out.println("Error: Unknown command " + args[0]); - } else { - CommandContext cc = new CommandContext(mapTable, args, in, out, err); - try { - cmd.executeCommand(cc); - } catch (Exception e) { - err.println("Error: Command failed: " + e.getMessage()); - e.printStackTrace(err); - } - } - } - } - } catch (IOException e) { - e.printStackTrace(); - err.println("Command line tool exiting..."); - exit = true; - } - } - } - - public void setComponentRegistry(ComponentRegistry registry) { - this.registry = registry; - } - - public void setWorkaround(boolean w) { - workaround = w; - } - - public void start() { - mapTable = (MapTable) registry.getComponent(MapTable.class); - - Object[] commandBundles = registry.getAllComponents(CommandBundle.class); - if (commandBundles != null) { - for (int i = 0, n = commandBundles.length; i < n; i++) { - ((CommandBundle) commandBundles[i]).setupCommands(registry, this); - } - } - new Thread(this, "cmd").start(); - } -} Deleted: mspsim/se/sics/mspsim/util/CommandParser.java =================================================================== --- mspsim/se/sics/mspsim/util/CommandParser.java 2008-03-08 08:13:09 UTC (rev 159) +++ mspsim/se/sics/mspsim/util/CommandParser.java 2008-03-09 00:52:15 UTC (rev 160) @@ -1,179 +0,0 @@ -/** - * Copyright (c) 2008, 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. - * - * This file is part of MSPSim. - * - * ----------------------------------------------------------------- - * - * CommandParser - * - * Author : Joakim Eriksson, Niclas Finne - * Created : Sun Mar 2 19:41:00 2008 - * Updated : $Date: 2007/10/21 21:17:34 $ - * $Revision: 1.3 $ - */ -package se.sics.mspsim.util; -import java.util.ArrayList; - -public class CommandParser { - - private static final int TEXT = 0; - private static final int ARG = 1; - private static final int QUOTE = 2; - - private CommandParser() { - // Prevent instances of this class - } - - public static String[][] parseLine(String line) { - ArrayList<String[]> list = new ArrayList<String[]>(); - ArrayList<String> args = new ArrayList<String>(); - StringBuilder sb = null; - int state = TEXT; - int index = 0; - char quote = 0; - - for (int i = 0, n = line.length(); i < n; i++) { - char c = line.charAt(i); - if (c <= 32) { - // White space - if (state == ARG) { - if (sb == null) { - args.add(line.substring(index, i)); - } else { - args.add(sb.append(line.substring(index, i)).toString()); - sb = null; - } - state = TEXT; - } - - } else { - switch (c) { - case '\\': - i++; - if (i >= n) { - throw new IllegalArgumentException("unexpected end of line"); - } - if (state == TEXT) { - state = ARG; - } else { - if (sb == null) { - sb = new StringBuilder(); - } - sb.append(line.substring(index, i - 1)); - } - index = i; - break; - case '"': - case '\'': - if (state == QUOTE) { - if (c == quote) { - // End of quote - if (sb == null) { - args.add(line.substring(index, i)); - } else { - args.add(sb.append(line.substring(index, i)).toString()); - sb = null; - } - state = TEXT; - } - } else { - // Start new quote - if (state != TEXT) { - if (sb == null) { - args.add(line.substring(index, i)); - } else { - args.add(sb.append(line.substring(index, i)).toString()); - sb = null; - } - } - index = i + 1; - state = QUOTE; - quote = c; - } - break; - case '|': - if (state != QUOTE) { - // PIPE - if (state == ARG) { - if (sb == null) { - args.add(line.substring(index, i)); - } else { - args.add(sb.append(line.substring(index, i)).toString()); - sb = null; - } - } - state = TEXT; - if (args.size() == 0) { - throw new IllegalArgumentException("empty command"); - } - list.add(args.toArray(new String[args.size()])); - args.clear(); - } - break; - default: - if (state == TEXT) { - index = i; - state = ARG; - } - break; - } - } - } - if (state == QUOTE) { - throw new IllegalArgumentException("unexpected end of line"); - } - if (state == ARG) { - if (sb == null) { - args.add(line.substring(index)); - } else { - args.add(sb.append(line.substring(index)).toString()); - } - } - if (args.size() > 0) { - list.add(args.toArray(new String[args.size()])); - } - return list.toArray(new String[list.size()][]); - } - -// public static void main(String[] args) { -// StringBuilder sb = new StringBuilder(); -// for (int i = 0, n = args.length; i < n; i++) { -// if (i > 0) sb.append(' '); -// sb.append(args[0]); -// } -// String[][] list = parseLine(sb.toString()); -// for (int j = 0, m = list.length; j < m; j++) { -// String[] a = list[j]; -// System.out.println("PARSED LINE:"); -// for (int i = 0, n = a.length; i < n; i++) { -// System.out.println(" ARG " + (i + 1) + ": '" + a[i] + '\''); -// } -// } -// } - -} Deleted: mspsim/se/sics/mspsim/util/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/util/DebugCommands.java 2008-03-08 08:13:09 UTC (rev 159) +++ mspsim/se/sics/mspsim/util/DebugCommands.java 2008-03-09 00:52:15 UTC (rev 160) @@ -1,217 +0,0 @@ -/** - * Copyright (c) 2008, 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. - * - * This file is part of MSPSim. - * - * $Id$ - * - * ----------------------------------------------------------------- - * - * CommandBundle - * - * Author : Joakim Eriksson, Niclas Finne - * Created : Mon Feb 11 2008 - * Updated : $Date: 2007/10/21 21:17:34 $ - * $Revision: 1.3 $ - */ -package se.sics.mspsim.util; -import se.sics.mspsim.core.CPUMonitor; -import se.sics.mspsim.core.MSP430; -import se.sics.mspsim.platform.GenericNode; - -public class DebugCommands implements CommandBundle { - - public void setupCommands(ComponentRegistry registry, CommandHandler ch) { - final MSP430 cpu = (MSP430) registry.getComponent(MSP430.class); - final ELF elf = (ELF) registry.getComponent(ELF.class); - final GenericNode node = (GenericNode) registry.getComponent("node"); - if (cpu != null) { - ch.registerCommand("break", new Command() { - public int executeCommand(final CommandContext context) { - int baddr = context.getArgumentAsAddress(0); - cpu.setBreakPoint(baddr, - new CPUMonitor() { - public void cpuAction(int type, int adr, int data) { - context.out.println("*** Break at " + adr); - } - }); - context.out.println("Breakpoint set at: " + baddr); - return 0; - } - - public String getArgumentHelp(CommandContext context) { - return "<address or symbol>"; - } - - public String getCommandHelp(CommandContext context) { - return "adds a breakpoint to a given address or symbol"; - } - }); - - ch.registerCommand("watch", new Command() { - int mode = 0; - public int executeCommand(final CommandContext context) { - int baddr = context.getArgumentAsAddress(0); - if (baddr == -1) { - context.out.println("Error: unkown symbol:" + context.getArgument(0)); - return -1; - } - if (context.getArgumentCount() > 1) { - String modeStr = context.getArgument(1); - if ("char".equals(modeStr)) { - mode = 1; - } - } - cpu.setBreakPoint(baddr, - new CPUMonitor() { - public void cpuAction(int type, int adr, int data) { - if (mode == 0) { - int pc = cpu.readRegister(0); - String adrStr = getSymOrAddr(context, adr); - String pcStr = getSymOrAddrELF(elf, pc); - context.out.println("*** Write from " + pcStr + - ": " + adrStr + " = " + data); - } else { - context.out.print((char) data); - } - } - }); - context.out.println("Watch set at: " + baddr); - return 0; - } - - public String getArgumentHelp(CommandContext context) { - return "<address or symbol>"; - } - - public String getCommandHelp(CommandContext context) { - return "adds a write watch to a given address or symbol"; - } - }); - - ch.registerCommand("clear", new Command() { - public int executeCommand(final CommandContext context) { - int baddr = context.getArgumentAsAddress(0); - cpu.setBreakPoint(baddr, null); - return 0; - } - - public String getArgumentHelp(CommandContext context) { - return "<address or symbol>"; - } - - public String getCommandHelp(CommandContext context) { - return "clears a breakpoint or watch from a given address or symbol"; - } - }); - - - - ch.registerCommand("symbol", new BasicCommand("lists matching symbold", "<regexp>") { - public int executeCommand(final CommandContext context) { - String regExp = context.getArgument(0); - MapEntry[] entries = context.getMapTable().getEntries(regExp); - for (int i = 0; i < entries.length; i++) { - MapEntry mapEntry = entries[i]; - context.out.println(" " + mapEntry.getName() + " at " + - Utils.hex16(mapEntry.getAddress())); - } - return 0; - } - }); - - if (node != null) { - ch.registerCommand("stop", new BasicCommand("stops mspsim", "") { - public int executeCommand(CommandContext context) { - node.stop(); - context.out.println("CPU stopped at: " + Utils.hex16(cpu.readRegister(0))); - return 0; - } - }); - ch.registerCommand("start", new BasicCommand("starts mspsim", "") { - public int executeCommand(CommandContext context) { - node.start(); - return 0; - } - }); - ch.registerCommand("step", new BasicCommand("singlesteps mspsim", "<number of lines>") { - public int executeCommand(CommandContext context) { - int nr = context.getArgumentCount() > 0 ? context.getArgumentAsInt(0) : 1; - while(nr-- > 0) - node.step(); - context.out.println("CPU stepped to: " + Utils.hex16(cpu.readRegister(0))); - return 0; - } - }); - ch.registerCommand("print", new BasicCommand("prints value of an address or symbol", "<address or symbol>") { - public int executeCommand(CommandContext context) { - int adr = context.getArgumentAsAddress(0); - if (adr != -1) { - context.out.println("" + context.getArgument(0) + " = " + Utils.hex16(cpu.read(adr, adr >= 0x100))); - } else { - context.out.println("unkown symbol"); - } - return 0; - } - }); - ch.registerCommand("printreg", new BasicCommand("prints value of an register", "<register>") { - public int executeCommand(CommandContext context) { - int adr = context.getArgumentAsInt(0); - context.out.println("" + context.getArgument(0) + " = " + Utils.hex16(cpu.readRegister(adr))); - return 0; - } - }); - ch.registerCommand("time", new BasicCommand("prints the elapse time and cycles", "") { - public int executeCommand(CommandContext context) { - long time = ((long)(cpu.getTimeMillis())); - context.out.println("Emulated time elapsed:" + time + "(ms) cycles: " + cpu.cycles); - return 0; - } - }); - } - } - } - - private static String getSymOrAddr(CommandContext context, int adr) { - MapEntry me = context.getMapTable().getEntry(adr); - if (me != null) { - return me.getName(); - } else { - return Utils.hex16(adr); - } - } - - private static String getSymOrAddrELF(ELF elf, int adr) { - DebugInfo me = elf.getDebugInfo(adr); - if (me != null) { - return me.toString(); - } else { - return Utils.hex16(adr); - } - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-03-11 23:54:25
|
Revision: 179 http://mspsim.svn.sourceforge.net/mspsim/?rev=179&view=rev Author: joxe Date: 2008-03-11 16:54:12 -0700 (Tue, 11 Mar 2008) Log Message: ----------- minor refactoring - IOUnit is no longer a Chip - removed dead code. Modified Paths: -------------- mspsim/CHANGE_LOG.txt mspsim/se/sics/mspsim/chip/Beeper.java mspsim/se/sics/mspsim/core/ADC12.java mspsim/se/sics/mspsim/core/BasicClockModule.java mspsim/se/sics/mspsim/core/IOPort.java mspsim/se/sics/mspsim/core/IOUnit.java mspsim/se/sics/mspsim/core/Multiplier.java mspsim/se/sics/mspsim/core/SFR.java mspsim/se/sics/mspsim/core/USART.java Modified: mspsim/CHANGE_LOG.txt =================================================================== --- mspsim/CHANGE_LOG.txt 2008-03-11 23:41:17 UTC (rev 178) +++ mspsim/CHANGE_LOG.txt 2008-03-11 23:54:12 UTC (rev 179) @@ -1,7 +1,9 @@ 0.85 Changes: - fixed multiplier to handle the different modes better. -- +- refactored so that IOUnit is no longer a Chip +- added statistics commands to the CLI +- implemented better support for statistics (operating mode) 0.84 Changes: Modified: mspsim/se/sics/mspsim/chip/Beeper.java =================================================================== --- mspsim/se/sics/mspsim/chip/Beeper.java 2008-03-11 23:41:17 UTC (rev 178) +++ mspsim/se/sics/mspsim/chip/Beeper.java 2008-03-11 23:54:12 UTC (rev 179) @@ -145,8 +145,4 @@ } } } - - public int getModeMax() { - return 0; - } } Modified: mspsim/se/sics/mspsim/core/ADC12.java =================================================================== --- mspsim/se/sics/mspsim/core/ADC12.java 2008-03-11 23:41:17 UTC (rev 178) +++ mspsim/se/sics/mspsim/core/ADC12.java 2008-03-11 23:54:12 UTC (rev 179) @@ -122,7 +122,7 @@ } public String getName() { - return "AD12"; + return "ADC12"; } public void interruptServiced(int vector) { @@ -131,8 +131,4 @@ public long ioTick(long cycles) { return cycles + 1000000; } - - public int getModeMax() { - return 0; - } } Modified: mspsim/se/sics/mspsim/core/BasicClockModule.java =================================================================== --- mspsim/se/sics/mspsim/core/BasicClockModule.java 2008-03-11 23:41:17 UTC (rev 178) +++ mspsim/se/sics/mspsim/core/BasicClockModule.java 2008-03-11 23:54:12 UTC (rev 179) @@ -163,8 +163,4 @@ public void interruptServiced(int vector) { } - - public int getModeMax() { - return 0; - } } Modified: mspsim/se/sics/mspsim/core/IOPort.java =================================================================== --- mspsim/se/sics/mspsim/core/IOPort.java 2008-03-11 23:41:17 UTC (rev 178) +++ mspsim/se/sics/mspsim/core/IOPort.java 2008-03-11 23:54:12 UTC (rev 179) @@ -202,10 +202,4 @@ interruptFlag = 0; cpu.flagInterrupt(interrupt, this, interruptFlag > 0); } - - // TODO: Should override this - public int getModeMax() { - return 0; - } - } Modified: mspsim/se/sics/mspsim/core/IOUnit.java =================================================================== --- mspsim/se/sics/mspsim/core/IOUnit.java 2008-03-11 23:41:17 UTC (rev 178) +++ mspsim/se/sics/mspsim/core/IOUnit.java 2008-03-11 23:54:12 UTC (rev 179) @@ -41,11 +41,8 @@ package se.sics.mspsim.core; -import java.util.ArrayList; -import java.util.Iterator; +public abstract class IOUnit { -public abstract class IOUnit extends Chip { - int[] memory; int offset; @@ -98,4 +95,6 @@ // Second byte => hi byte return (data >> 8) & 0xff; } + + public abstract String getName(); } Modified: mspsim/se/sics/mspsim/core/Multiplier.java =================================================================== --- mspsim/se/sics/mspsim/core/Multiplier.java 2008-03-11 23:41:17 UTC (rev 178) +++ mspsim/se/sics/mspsim/core/Multiplier.java 2008-03-11 23:54:12 UTC (rev 179) @@ -65,15 +65,12 @@ private int macs; private int sumext; - private int lastWriteOP; - private int currentSum; private int op1; - private boolean signed = false; - MSP430Core core; - private boolean accumulating; + private boolean signed = false; + private boolean accumulating = false; /** * Creates a new <code>Multiplier</code> instance. * @@ -127,28 +124,24 @@ case MPY: op1 = mpy = data; if (DEBUG) System.out.println(getName() + " Write to MPY: " + data); - lastWriteOP = address; signed = false; accumulating = false; break; case MPYS: op1 = mpys = data; if (DEBUG) System.out.println(getName() + " Write to MPYS: " + data); - lastWriteOP = address; signed = true; accumulating = false; break; case MAC: op1 = mac = data; if (DEBUG) System.out.println(getName() + " Write to MAC: " + data); - lastWriteOP = address; signed = false; accumulating = true; break; case MACS: op1 = macs = data; if (DEBUG) System.out.println(getName() + " Write to MACS: " + data); - lastWriteOP = address; signed = true; accumulating = true; break; @@ -199,10 +192,4 @@ public void interruptServiced(int vector) { } - - public int getModeMax() { - return 0; - } - - } Modified: mspsim/se/sics/mspsim/core/SFR.java =================================================================== --- mspsim/se/sics/mspsim/core/SFR.java 2008-03-11 23:41:17 UTC (rev 178) +++ mspsim/se/sics/mspsim/core/SFR.java 2008-03-11 23:54:12 UTC (rev 179) @@ -155,8 +155,4 @@ public String getName() { return "SpecialFunctionRegister, SFR"; } - - public int getModeMax() { - return 0; - } } // SFR Modified: mspsim/se/sics/mspsim/core/USART.java =================================================================== --- mspsim/se/sics/mspsim/core/USART.java 2008-03-11 23:41:17 UTC (rev 178) +++ mspsim/se/sics/mspsim/core/USART.java 2008-03-11 23:54:12 UTC (rev 179) @@ -346,9 +346,4 @@ cpu.flagInterrupt(receiveInterrupt, this, true); } } - - public int getModeMax() { - return 0; - } - } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-03-17 21:12:49
|
Revision: 192 http://mspsim.svn.sourceforge.net/mspsim/?rev=192&view=rev Author: joxe Date: 2008-03-17 14:12:47 -0700 (Mon, 17 Mar 2008) Log Message: ----------- added speed control API Modified Paths: -------------- mspsim/CHANGE_LOG.txt mspsim/se/sics/mspsim/core/MSP430.java Modified: mspsim/CHANGE_LOG.txt =================================================================== --- mspsim/CHANGE_LOG.txt 2008-03-17 21:02:40 UTC (rev 191) +++ mspsim/CHANGE_LOG.txt 2008-03-17 21:12:47 UTC (rev 192) @@ -6,8 +6,11 @@ - implemented better support for statistics (operating mode) - fixed interrupt handling bugs in IOUnit - added API for accessing frequency/channel and output power in CC2420 +- added RSSI support for CC2420 - refactored radio emulation code of ESB platform into a separate TR1001 class - added watch on register, grep, and other commands in CLI +- added redirect to files in CLI +- added speed control API and CLI command (speed) 0.84 Changes: Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2008-03-17 21:02:40 UTC (rev 191) +++ mspsim/se/sics/mspsim/core/MSP430.java 2008-03-17 21:12:47 UTC (rev 192) @@ -50,6 +50,7 @@ private boolean debug = false; private boolean running = false; + private long sleepRate = 50000; // Debug time - measure cycles private long lastCycles = 0; @@ -137,7 +138,9 @@ Thread.sleep(10); } catch (Exception e) { } - nextSleep = cycles + 50000; + // Frequency = 100 * cycles ratio + // Ratio = Frq / 100 + nextSleep = cycles + sleepRate; } // if ((instruction & 0xff80) == CALL) { @@ -285,4 +288,8 @@ public boolean isRunning() { return running; } -} + + public void setSleepRate(long rate) { + sleepRate = rate; + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-03-20 12:49:34
|
Revision: 204 http://mspsim.svn.sourceforge.net/mspsim/?rev=204&view=rev Author: joxe Date: 2008-03-20 05:49:27 -0700 (Thu, 20 Mar 2008) Log Message: ----------- fixed so that timer system performs reset when CPU is reset Modified Paths: -------------- mspsim/CHANGE_LOG.txt mspsim/se/sics/mspsim/cli/DebugCommands.java mspsim/se/sics/mspsim/cli/MiscCommands.java mspsim/se/sics/mspsim/core/MSP430Constants.java mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/se/sics/mspsim/core/Timer.java Modified: mspsim/CHANGE_LOG.txt =================================================================== --- mspsim/CHANGE_LOG.txt 2008-03-20 10:44:01 UTC (rev 203) +++ mspsim/CHANGE_LOG.txt 2008-03-20 12:49:27 UTC (rev 204) @@ -1,4 +1,4 @@ -0.85 +0.90 Changes: - fixed multiplier to handle the different modes better. - refactored so that IOUnit is no longer a Chip @@ -11,6 +11,9 @@ - added watch on register, grep, and other commands in CLI - added redirect to files in CLI - added speed control API and CLI command (speed) +- added event system for cycle based events +- fixed timer (A/B) to be event driven instead of tick driven +- fixed bugs in interrupt handling of timer system 0.84 Changes: Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2008-03-20 10:44:01 UTC (rev 203) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2008-03-20 12:49:27 UTC (rev 204) @@ -50,7 +50,9 @@ import se.sics.mspsim.util.Utils; public class DebugCommands implements CommandBundle { - + private long lastCall = 0; + private long lastWall = 0; + public void setupCommands(ComponentRegistry registry, CommandHandler ch) { final MSP430 cpu = (MSP430) registry.getComponent(MSP430.class); final ELF elf = (ELF) registry.getComponent(ELF.class); @@ -230,14 +232,23 @@ return -1; } }); + ch.registerCommand("reset", new BasicCommand("resets the CPU", "") { + public int executeCommand(CommandContext context) { + cpu.reset(); + return 0; + } + }); + ch.registerCommand("time", new BasicCommand("prints the elapse time and cycles", "") { public int executeCommand(CommandContext context) { long time = ((long)(cpu.getTimeMillis())); - context.out.println("Emulated time elapsed: " + time + "(ms) cycles: " + cpu.cycles); + context.out.println("Emulated time elapsed: " + time + "(ms) since last: " + (time - lastCall) + " ms" + " wallTime: " + + (System.currentTimeMillis() - lastWall) + " ms"); + lastCall = time; + lastWall = System.currentTimeMillis(); return 0; } }); - } } } Modified: mspsim/se/sics/mspsim/cli/MiscCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/MiscCommands.java 2008-03-20 10:44:01 UTC (rev 203) +++ mspsim/se/sics/mspsim/cli/MiscCommands.java 2008-03-20 12:49:27 UTC (rev 204) @@ -143,6 +143,12 @@ } }); + handler.registerCommand("exit", new BasicCommand("exit", "") { + public int executeCommand(CommandContext context) { + System.exit(0); + return 0; + } + }); handler.registerCommand("exec", new ExecCommand()); } Modified: mspsim/se/sics/mspsim/core/MSP430Constants.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Constants.java 2008-03-20 10:44:01 UTC (rev 203) +++ mspsim/se/sics/mspsim/core/MSP430Constants.java 2008-03-20 12:49:27 UTC (rev 204) @@ -43,7 +43,7 @@ public interface MSP430Constants { - public static final String VERSION = "0.85"; + public static final String VERSION = "0.90"; public static final int CLK_ACLK = 1; public static final int CLK_SMCLK = 2; Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2008-03-20 10:44:01 UTC (rev 203) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2008-03-20 12:49:27 UTC (rev 204) @@ -506,6 +506,8 @@ public void reset() { resetIOUnits(); reg[PC] = memory[0xfffe] + (memory[0xffff] << 8); + System.out.println("Reset the CPU: " + reg[PC]); + for (int i = 0, n = 16; i < n; i++) { interruptSource[i] = null; } Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2008-03-20 10:44:01 UTC (rev 203) +++ mspsim/se/sics/mspsim/core/Timer.java 2008-03-20 12:49:27 UTC (rev 204) @@ -243,6 +243,15 @@ expCompare[i] = -1; expCaptureTime[i] = -1; } + for (int i = 0; i < tcctl.length; i++) { + tcctl[i] = 0; + tccr[i] = 0; + } + + interruptEnable = false; + interruptPending = false; + counter = 0; + counterPassed = 0; } // Should handle read of byte also (currently ignores that...) @@ -735,6 +744,7 @@ // Some flags should be cleared (the highest priority flags)? public void interruptServiced(int vector) { if (vector == ccr0Vector) { + // Reset the interrupt trigger in "core". core.flagInterrupt(ccr0Vector, this, false); // Remove the flag also... tcctl[0] &= ~CC_IFG; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2007-10-26 12:43:52
|
Revision: 12 http://mspsim.svn.sourceforge.net/mspsim/?rev=12&view=rev Author: joxe Date: 2007-10-26 05:43:41 -0700 (Fri, 26 Oct 2007) Log Message: ----------- added firmware for esb demo Modified Paths: -------------- mspsim/Makefile mspsim/se/sics/mspsim/core/IOPort.java mspsim/se/sics/mspsim/platform/esb/ESBGui.java Added Paths: ----------- mspsim/firmware/esb/ mspsim/firmware/esb/sensor-demo.firmware Modified: mspsim/Makefile =================================================================== --- mspsim/Makefile 2007-10-25 12:23:33 UTC (rev 11) +++ mspsim/Makefile 2007-10-26 12:43:41 UTC (rev 12) @@ -53,6 +53,8 @@ ############################################################### FIRMWAREFILE = blinker2.ihex +ESBFIRMWARE = firmware/esb/sensor-demo.firmware +SKYFIRMWARE = firmware/sky/sensor-demo.firmware CPUTEST := tests/cputest.firmware @@ -81,10 +83,10 @@ java se.sics.mspsim.util.IHexReader $(FIRMWAREFILE) $(MAPFILE) runesb: compile - java se.sics.mspsim.platform.esb.ESBNode $(FIRMWAREFILE) $(MAPFILE) + java se.sics.mspsim.platform.esb.ESBNode $(ESBFIRMWARE) $(MAPFILE) runsky: compile - java se.sics.mspsim.platform.sky.SkyNode $(FIRMWAREFILE) $(MAPFILE) + java se.sics.mspsim.platform.sky.SkyNode $(SKYFIRMWARE) $(MAPFILE) .PHONY: cputest test test: cputest Added: mspsim/firmware/esb/sensor-demo.firmware =================================================================== (Binary files differ) Property changes on: mspsim/firmware/esb/sensor-demo.firmware ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + application/octet-stream Modified: mspsim/se/sics/mspsim/core/IOPort.java =================================================================== --- mspsim/se/sics/mspsim/core/IOPort.java 2007-10-25 12:23:33 UTC (rev 11) +++ mspsim/se/sics/mspsim/core/IOPort.java 2007-10-26 12:43:41 UTC (rev 12) @@ -136,7 +136,9 @@ // case IFG: if (interrupt > 0) { // IFG - writing a zero => clear the flag! - System.out.println(getName() + " Clearing IFlag: " + data); + if (DEBUG) { + System.out.println(getName() + " Clearing IFlag: " + data); + } interruptFlag &= data; memory[offset + IFG] = interruptFlag; cpu.flagInterrupt(interrupt, this, interruptFlag > 0); @@ -169,14 +171,19 @@ // LO/HI transition if (state == PIN_HI) { interruptFlag |= bit; - System.out.println(getName() + " Flagging interrupt (HI): " + bit); + if (DEBUG) { + System.out.println(getName() + + " Flagging interrupt (HI): " + bit); + } } } else { // HI/LO transition if (state == PIN_LOW) { interruptFlag |= bit; - System.out.println(getName() + " Flagging interrupt (LOW): " + - bit); + if (DEBUG) { + System.out.println(getName() + + " Flagging interrupt (LOW): " + bit); + } } } } Modified: mspsim/se/sics/mspsim/platform/esb/ESBGui.java =================================================================== --- mspsim/se/sics/mspsim/platform/esb/ESBGui.java 2007-10-25 12:23:33 UTC (rev 11) +++ mspsim/se/sics/mspsim/platform/esb/ESBGui.java 2007-10-26 12:43:41 UTC (rev 12) @@ -47,6 +47,7 @@ import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; +import java.awt.event.MouseListener; import javax.swing.ImageIcon; import javax.swing.JComponent; import javax.swing.JFrame; @@ -57,7 +58,8 @@ import se.sics.mspsim.util.WindowUtils; public class ESBGui extends JComponent implements KeyListener, - MouseMotionListener { + MouseMotionListener, + MouseListener { public static final int GREEN_X = 3; public static final int YELLOW_X = 10; @@ -79,6 +81,7 @@ private ImageIcon esbImage; private JFrame window; private ESBNode node; + private boolean buttonDown = false; public ESBGui(ESBNode node) { this.node = node; @@ -103,6 +106,7 @@ window.addKeyListener(this); window.addMouseMotionListener(this); + window.addMouseListener(this); // Add some windows for listening to serial output MSP430 cpu = node.getCPU(); @@ -130,10 +134,27 @@ node.setVIB(x > 60 && x < 100 && y > 180 && y < 200); } - public void mouseDragged(MouseEvent e) { + public void mouseDragged(MouseEvent e) {} + public void mouseClicked(MouseEvent e) {} + public void mouseEntered(MouseEvent e) {} + public void mouseExited(MouseEvent e) {} + + // For the button sensor on the ESB nodes. + public void mousePressed(MouseEvent e) { + int x = e.getX(); + int y = e.getY(); + if (x > 0 && x < 24 && y > 180 && y < 200) { + node.setButton(buttonDown = true); + } } + public void mouseReleased(MouseEvent e) { + if (buttonDown) { + node.setButton(buttonDown = false); + } + } + public void paintComponent(Graphics g) { Color old = g.getColor(); int w = getWidth(), h = getHeight(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2007-10-29 19:03:08
|
Revision: 17 http://mspsim.svn.sourceforge.net/mspsim/?rev=17&view=rev Author: joxe Date: 2007-10-29 11:19:04 -0700 (Mon, 29 Oct 2007) Log Message: ----------- added possibility to profile from unit test framework Modified Paths: -------------- mspsim/se/sics/mspsim/util/Test.java mspsim/tests/cputest.c Modified: mspsim/se/sics/mspsim/util/Test.java =================================================================== --- mspsim/se/sics/mspsim/util/Test.java 2007-10-26 13:26:33 UTC (rev 16) +++ mspsim/se/sics/mspsim/util/Test.java 2007-10-29 18:19:04 UTC (rev 17) @@ -69,6 +69,8 @@ System.exit(0); } else if (line.startsWith("DEBUG")) { cpu.setDebug(true); + } else if (line.startsWith("PROFILE")) { + cpu.printProfile(); } line = ""; } else { Modified: mspsim/tests/cputest.c =================================================================== --- mspsim/tests/cputest.c 2007-10-26 13:26:33 UTC (rev 16) +++ mspsim/tests/cputest.c 2007-10-29 18:19:04 UTC (rev 17) @@ -256,7 +256,7 @@ testBitFields(); testFunctions(); testModulo(); - + /* printf("PROFILE\n"); */ printf("EXIT\n"); return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2007-11-26 15:25:37
|
Revision: 32 http://mspsim.svn.sourceforge.net/mspsim/?rev=32&view=rev Author: joxe Date: 2007-11-26 07:25:22 -0800 (Mon, 26 Nov 2007) Log Message: ----------- added license text Modified Paths: -------------- mspsim/Makefile Added Paths: ----------- mspsim/license.txt Modified: mspsim/Makefile =================================================================== --- mspsim/Makefile 2007-11-26 10:24:34 UTC (rev 31) +++ mspsim/Makefile 2007-11-26 15:25:22 UTC (rev 32) @@ -62,7 +62,7 @@ CPUTEST := tests/cputest.firmware -BINARY := README.txt images/*.jpg firmware/*/*.firmware +BINARY := README.txt license.txt images/*.jpg firmware/*/*.firmware PACKAGES := ${addprefix se/sics/mspsim/,core platform/esb platform/sky util chip} Added: mspsim/license.txt =================================================================== --- mspsim/license.txt (rev 0) +++ mspsim/license.txt 2007-11-26 15:25:22 UTC (rev 32) @@ -0,0 +1,25 @@ +Copyright (c) 2007, 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. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2008-02-01 13:16:07
|
Revision: 100 http://mspsim.svn.sourceforge.net/mspsim/?rev=100&view=rev Author: nifi Date: 2008-02-01 05:15:53 -0800 (Fri, 01 Feb 2008) Log Message: ----------- JFreeChart library (http://www.jfree.org/jfreechart/) Added Paths: ----------- mspsim/lib/ mspsim/lib/jcommon-1.0.12.jar mspsim/lib/jfreechart-1.0.9.jar mspsim/lib/jfreechart-licence-LGPL.txt Added: mspsim/lib/jcommon-1.0.12.jar =================================================================== (Binary files differ) Property changes on: mspsim/lib/jcommon-1.0.12.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: mspsim/lib/jfreechart-1.0.9.jar =================================================================== (Binary files differ) Property changes on: mspsim/lib/jfreechart-1.0.9.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: mspsim/lib/jfreechart-licence-LGPL.txt =================================================================== --- mspsim/lib/jfreechart-licence-LGPL.txt (rev 0) +++ mspsim/lib/jfreechart-licence-LGPL.txt 2008-02-01 13:15:53 UTC (rev 100) @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + <one line to give the library's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + <signature of Ty Coon>, 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-02-03 20:03:56
|
Revision: 102 http://mspsim.svn.sourceforge.net/mspsim/?rev=102&view=rev Author: joxe Date: 2008-02-03 10:45:08 -0800 (Sun, 03 Feb 2008) Log Message: ----------- Fixed Makefile (source) and added event classes as start on reimplementing IO emulation to be event driven. Modified Paths: -------------- mspsim/Makefile Added Paths: ----------- mspsim/se/sics/mspsim/core/AD12.java mspsim/se/sics/mspsim/core/EventQueue.java mspsim/se/sics/mspsim/core/TimeEvent.java Modified: mspsim/Makefile =================================================================== --- mspsim/Makefile 2008-02-02 12:25:41 UTC (rev 101) +++ mspsim/Makefile 2008-02-03 18:45:08 UTC (rev 102) @@ -126,7 +126,7 @@ ############################################################### source: - zip -9 mspsim-source-`date '+%F'`.zip Makefile $(BINARY) *.java $(addsuffix /*.java,$(PACKAGES)) tests/Makefile tests/*.c tests/*.h + zip -9 mspsim-source-`date '+%F'`.zip Makefile $(BINARY) *.java $(addsuffix /*.java,$(PACKAGES)) tests/Makefile tests/*.c tests/*.h lib/*.* ############################################################### Added: mspsim/se/sics/mspsim/core/AD12.java =================================================================== --- mspsim/se/sics/mspsim/core/AD12.java (rev 0) +++ mspsim/se/sics/mspsim/core/AD12.java 2008-02-03 18:45:08 UTC (rev 102) @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2007, 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. + * + * This file is part of MSPSim. + * + * $Id: IOUnit.java,v 1.3 2007/10/21 21:17:34 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * AD12 + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 21:17:34 $ + * $Revision: 1.3 $ + */ + +package se.sics.mspsim.core; + +public class AD12 extends IOUnit { + + public AD12() { + super(null, 0); + } + + // write a value to the IO unit + public void write(int address, int value, boolean word, + long cycles) { + } + + // read a value from the IO unit + public int read(int address, boolean word, long cycles) { + return 0; + } + + public String getName() { + return "AD12"; + } + + public void interruptServiced() { + } + + public long ioTick(long cycles) { + return cycles + 1000000; + } + + public int getModeMax() { + return 0; + } +} Added: mspsim/se/sics/mspsim/core/EventQueue.java =================================================================== --- mspsim/se/sics/mspsim/core/EventQueue.java (rev 0) +++ mspsim/se/sics/mspsim/core/EventQueue.java 2008-02-03 18:45:08 UTC (rev 102) @@ -0,0 +1,149 @@ +/** + * Copyright (c) 2007, 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. + * + * This file is part of MSPSim. + * + * $Id: $ + * + * ----------------------------------------------------------------- + * + * EventQueue + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 21:17:34 $ + * $Revision: 1.3 $ + */ + +package se.sics.mspsim.core; + +public class EventQueue { + + private TimeEvent first; + public long nextTime; + + public EventQueue() { + } + + public void addEvent(TimeEvent event, long time) { + event.time = time; + addEvent(event); + } + + public void addEvent(TimeEvent event) { + if (event.scheduled) { + removeEvent(event); + } + if (first == null) { + first = event; + } else { + TimeEvent pos = first; + TimeEvent lastPos = first; + while (pos != null && pos.time < event.time) { + lastPos = pos; + pos = pos.nextEvent; + } + // Here pos will be the first TE after event + // and lastPos the first before + if (pos == first) { + // Before all other + event.nextEvent = pos; + first = event; + } else { + event.nextEvent = pos; + lastPos.nextEvent = event; + } + } + if (first != null) { + nextTime = first.time; + } else { + nextTime = 0; + } + event.scheduled = true; + } + + // Not yet impl. + public boolean removeEvent(TimeEvent event) { + TimeEvent pos = first; + TimeEvent lastPos = first; +// System.out.println("Removing: " + event.getShort() + " Before remove: "); +// print(); + while (pos != null && pos != event) { + lastPos = pos; + pos = pos.nextEvent; + } + if (pos == null) return false; + // pos == event! + if (pos == first) { + // remove it from first pos. + first = pos.nextEvent; + } else { + // else link prev to next... + lastPos.nextEvent = pos.nextEvent; + } + // unlink + pos.nextEvent = null; + + if (first != null) { + nextTime = first.time; + } else { + nextTime = 0; + } +// System.out.println("Removed =>"); +// print(); + event.scheduled = false; + return true; + } + + public TimeEvent popFirst() { + TimeEvent tmp = first; + if (tmp != null) { + first = tmp.nextEvent; + // Unlink. + tmp.nextEvent = null; + } + + if (first != null) { + nextTime = first.time; + } else { + nextTime = 0; + } + tmp.scheduled = false; + return tmp; + } + + public void print() { + TimeEvent t = first; + System.out.print("nxt: " + nextTime + " ["); + while(t != null) { + System.out.print(t.getShort()); + t = t.nextEvent; + if (t != null) System.out.print(", "); + } + System.out.println("]"); + } +} // LLEventQueue Added: mspsim/se/sics/mspsim/core/TimeEvent.java =================================================================== --- mspsim/se/sics/mspsim/core/TimeEvent.java (rev 0) +++ mspsim/se/sics/mspsim/core/TimeEvent.java 2008-02-03 18:45:08 UTC (rev 102) @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2007, 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. + * + * This file is part of MSPSim. + * + * $Id: BasicClockModule.java,v 1.3 2007/10/21 21:17:34 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * TimeEvent + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 21:17:34 $ + * $Revision: 1.3 $ + */ + +package se.sics.mspsim.core; + +public abstract class TimeEvent { + // For linking events... + TimeEvent nextEvent; + TimeEvent prevEvent; + boolean scheduled = false; + String name; + + protected long time; + + public TimeEvent(long time) { + this.time = time; + } + + public TimeEvent(long time, String name) { + this.time = time; + this.name = name; + } + + public final long getTime() { + return time; + } + + public abstract void execute(long t); + + public String getShort() { + return "" + time + (name != null ? ": " + name : ""); + } + +} // TimeEvent This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-02-16 10:11:07
|
Revision: 133 http://mspsim.svn.sourceforge.net/mspsim/?rev=133&view=rev Author: joxe Date: 2008-02-16 02:10:53 -0800 (Sat, 16 Feb 2008) Log Message: ----------- added erase and programpage write timing for ext flash. Modified Paths: -------------- mspsim/CHANGE_LOG.txt mspsim/se/sics/mspsim/chip/M25P80.java mspsim/se/sics/mspsim/platform/sky/SkyNode.java Modified: mspsim/CHANGE_LOG.txt =================================================================== --- mspsim/CHANGE_LOG.txt 2008-02-13 19:59:32 UTC (rev 132) +++ mspsim/CHANGE_LOG.txt 2008-02-16 10:10:53 UTC (rev 133) @@ -6,6 +6,8 @@ - implemented virtual time and event system based on that time. - improved emulation of CC2420 - implemented writer monitors (CPUMonitor - monitor of writes on any address) +- added commands and command (line) handler +- added plug-in system 0.82 - JFreechart, operation mode statistics (2008-02-03) Changes: Modified: mspsim/se/sics/mspsim/chip/M25P80.java =================================================================== --- mspsim/se/sics/mspsim/chip/M25P80.java 2008-02-13 19:59:32 UTC (rev 132) +++ mspsim/se/sics/mspsim/chip/M25P80.java 2008-02-16 10:10:53 UTC (rev 133) @@ -67,11 +67,11 @@ public static final int CHIP_SELECT = 0x10; private boolean chipSelect; - private USART usart; private int pos; private int status = 0; private boolean writeEnable = false; + private boolean writing = false; private int[] identity = new int[] { 0x20,0x20,0x14,0x10, @@ -86,8 +86,15 @@ private RandomAccessFile file; - public M25P80(USART usart, String filename) { - this.usart = usart; + private TimeEvent writeEvent = new TimeEvent(0) { + public void execute(long t) { + writing = false; + }}; + + private MSP430Core cpu; + + public M25P80(MSP430Core cpu, String filename) { + this.cpu = cpu; if (filename == null) filename = "flash.bin"; // Open flash file for R/W @@ -188,7 +195,8 @@ source.byteReceived(identity[pos++]); return; case READ_STATUS: - status = (status & (0xff - 1 - 2)) | (writeEnable ? 0x02 : 0x00); + status = (status & (0xff - 1 - 2)) | (writeEnable ? 0x02 : 0x00) | + (writing ? 0x01 : 0x00); source.byteReceived(status); if (DEBUG) System.out.println("M25P80: Read status => " + status); @@ -265,7 +273,13 @@ state = 0; } + private void writeStatus(double time) { + writing = true; + cpu.scheduleTimeEventMillis(writeEvent, time); + } + private void programPage() { + writeStatus(0.64); ensureLoaded(blockWriteAddress); for (int i = 0; i < readMemory.length; i++) { readMemory[i] &= buffer[i]; @@ -274,6 +288,7 @@ } private void sectorErase(int address) { + writeStatus(600); int sectorAddress = address & 0xf0000; loadedAddress = -1; for (int i = 0; i < buffer.length; i++) { Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-02-13 19:59:32 UTC (rev 132) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-02-16 10:10:53 UTC (rev 133) @@ -145,7 +145,7 @@ radio.setCCAPort(port1, CC2420_CCA); radio.setFIFOPPort(port1, CC2420_FIFOP); radio.setFIFOPort(port1, CC2420_FIFO); - flash = new M25P80((USART)usart0, flashFile); + flash = new M25P80(cpu, flashFile); ((USART) usart0).setUSARTListener(this); port4 = (IOPort) cpu.getIOUnit("Port 4"); if (port4 != null && port4 instanceof IOPort) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-02-27 14:33:25
|
Revision: 148 http://mspsim.svn.sourceforge.net/mspsim/?rev=148&view=rev Author: joxe Date: 2008-02-27 06:33:11 -0800 (Wed, 27 Feb 2008) Log Message: ----------- fixed USART interrupt handling Modified Paths: -------------- mspsim/CHANGE_LOG.txt mspsim/se/sics/mspsim/chip/Beeper.java mspsim/se/sics/mspsim/core/ADC12.java mspsim/se/sics/mspsim/core/BasicClockModule.java mspsim/se/sics/mspsim/core/IOPort.java mspsim/se/sics/mspsim/core/IOUnit.java mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/se/sics/mspsim/core/Multiplier.java mspsim/se/sics/mspsim/core/SFR.java mspsim/se/sics/mspsim/core/Timer.java mspsim/se/sics/mspsim/core/USART.java Modified: mspsim/CHANGE_LOG.txt =================================================================== --- mspsim/CHANGE_LOG.txt 2008-02-27 01:12:20 UTC (rev 147) +++ mspsim/CHANGE_LOG.txt 2008-02-27 14:33:11 UTC (rev 148) @@ -4,7 +4,7 @@ - fixed RSSI-ready flag to be set in CC2420 - refactored code from Sky/ESB into GenericNode - fixed workaround for AWT/IO read line hang bug. (works but not nice in - cygwin) + cygwin). Workaround is off by default by can be configured in CLI. - added several new commands (start, stop, step, print, printreg, etc). 0.83 Modified: mspsim/se/sics/mspsim/chip/Beeper.java =================================================================== --- mspsim/se/sics/mspsim/chip/Beeper.java 2008-02-27 01:12:20 UTC (rev 147) +++ mspsim/se/sics/mspsim/chip/Beeper.java 2008-02-27 14:33:11 UTC (rev 148) @@ -129,7 +129,7 @@ } // Nothing for interrupts... - public void interruptServiced() { + public void interruptServiced(int vector) { } public static void main(String[] args) { Modified: mspsim/se/sics/mspsim/core/ADC12.java =================================================================== --- mspsim/se/sics/mspsim/core/ADC12.java 2008-02-27 01:12:20 UTC (rev 147) +++ mspsim/se/sics/mspsim/core/ADC12.java 2008-02-27 14:33:11 UTC (rev 148) @@ -125,7 +125,7 @@ return "AD12"; } - public void interruptServiced() { + public void interruptServiced(int vector) { } public long ioTick(long cycles) { Modified: mspsim/se/sics/mspsim/core/BasicClockModule.java =================================================================== --- mspsim/se/sics/mspsim/core/BasicClockModule.java 2008-02-27 01:12:20 UTC (rev 147) +++ mspsim/se/sics/mspsim/core/BasicClockModule.java 2008-02-27 14:33:11 UTC (rev 148) @@ -161,7 +161,7 @@ return "BasicClockModule"; } - public void interruptServiced() { + public void interruptServiced(int vector) { } public int getModeMax() { Modified: mspsim/se/sics/mspsim/core/IOPort.java =================================================================== --- mspsim/se/sics/mspsim/core/IOPort.java 2008-02-27 01:12:20 UTC (rev 147) +++ mspsim/se/sics/mspsim/core/IOPort.java 2008-02-27 14:33:11 UTC (rev 148) @@ -158,7 +158,7 @@ return "Port " + name; } - public void interruptServiced() { + public void interruptServiced(int vector) { } // for HW to set hi/low on the pins... Modified: mspsim/se/sics/mspsim/core/IOUnit.java =================================================================== --- mspsim/se/sics/mspsim/core/IOUnit.java 2008-02-27 01:12:20 UTC (rev 147) +++ mspsim/se/sics/mspsim/core/IOUnit.java 2008-02-27 14:33:11 UTC (rev 148) @@ -87,7 +87,7 @@ // We should add "Interrupt serviced..." to indicate that its latest // Interrupt was serviced... - public abstract void interruptServiced(); + public abstract void interruptServiced(int vector); // Utility function for converting 16 bits data to correct return // value depending on address alignment and word/byte mode Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2008-02-27 01:12:20 UTC (rev 147) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2008-02-27 14:33:11 UTC (rev 148) @@ -512,9 +512,10 @@ System.out.println("### Calling serviced interrupt on: " + servicedInterruptUnit.getName()); } - servicedInterruptUnit.interruptServiced(); + servicedInterruptUnit.interruptServiced(servicedInterrupt); } + // Find next pending interrupt for (int i = 0, n = 16; i < n; i++) { if (interruptSource[i] != null) interruptMax = i; Modified: mspsim/se/sics/mspsim/core/Multiplier.java =================================================================== --- mspsim/se/sics/mspsim/core/Multiplier.java 2008-02-27 01:12:20 UTC (rev 147) +++ mspsim/se/sics/mspsim/core/Multiplier.java 2008-02-27 14:33:11 UTC (rev 148) @@ -113,7 +113,7 @@ return "Hardware Multiplier"; } - public void interruptServiced() { + public void interruptServiced(int vector) { } public int getModeMax() { Modified: mspsim/se/sics/mspsim/core/SFR.java =================================================================== --- mspsim/se/sics/mspsim/core/SFR.java 2008-02-27 01:12:20 UTC (rev 147) +++ mspsim/se/sics/mspsim/core/SFR.java 2008-02-27 14:33:11 UTC (rev 148) @@ -62,7 +62,7 @@ private int[] memory; private MSP430Core cpu; - private boolean DEBUG = false; + private boolean DEBUG = true; public SFR(MSP430Core cpu, int[] memory) { super(memory, 0); @@ -148,7 +148,7 @@ else return ifg2; } - public void interruptServiced() { + public void interruptServiced(int vector) { } public String getName() { Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2008-02-27 01:12:20 UTC (rev 147) +++ mspsim/se/sics/mspsim/core/Timer.java 2008-02-27 14:33:11 UTC (rev 148) @@ -680,7 +680,7 @@ // The interrupt have been serviced... // Some flags should be cleared (the highest priority flags)? - public void interruptServiced() { + public void interruptServiced(int vector) { if (MSP430Core.debugInterrupts) { System.out.println("interrupt Serviced..."); } Modified: mspsim/se/sics/mspsim/core/USART.java =================================================================== --- mspsim/se/sics/mspsim/core/USART.java 2008-02-27 01:12:20 UTC (rev 147) +++ mspsim/se/sics/mspsim/core/USART.java 2008-02-27 14:33:11 UTC (rev 148) @@ -82,9 +82,6 @@ private int receiveInterrupt = 0; private int transmitInterrupt = 0; - private boolean rxIntEnabled = false; - private boolean txIntEnabled = false; - private int utxifg; private int urxifg; @@ -106,6 +103,8 @@ private int utxbuf; + private boolean txInterruptPending = false; + /** * Creates a new <code>USART</code> instance. * @@ -294,10 +293,19 @@ // We should add "Interrupt serviced..." to indicate that its latest // Interrupt was serviced... - public void interruptServiced() { + public void interruptServiced(int vector) { // Another byte was received while the last interrupt was processed... - cpu.flagInterrupt(receiveInterrupt, this, - isIEBitsSet(urxifg) && ((getIFG() & urxifg) != 0)); + if (vector == receiveInterrupt) { + cpu.flagInterrupt(receiveInterrupt, this, + isIEBitsSet(urxifg) && ((getIFG() & urxifg) != 0)); + } else { + // Should we immediately make this empty again??? + if (!txInterruptPending) { + cpu.flagInterrupt(transmitInterrupt, this, false); + } else { + txInterruptPending = false; + } + } } @@ -310,7 +318,8 @@ setBitIFG(utxifg); utctl |= UTCTL_TXEMPTY; cpu.flagInterrupt(transmitInterrupt, this, isIEBitsSet(utxifg)); - + txInterruptPending = true; + if (DEBUG) { if (isIEBitsSet(utxifg)) { System.out.println(getName() + " flagging on transmit interrupt"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-03-07 01:02:54
|
Revision: 156 http://mspsim.svn.sourceforge.net/mspsim/?rev=156&view=rev Author: joxe Date: 2008-03-06 16:12:57 -0800 (Thu, 06 Mar 2008) Log Message: ----------- added modes in multiplier Modified Paths: -------------- mspsim/CHANGE_LOG.txt mspsim/se/sics/mspsim/chip/M25P80.java mspsim/se/sics/mspsim/core/MSP430Constants.java mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/se/sics/mspsim/core/Multiplier.java Modified: mspsim/CHANGE_LOG.txt =================================================================== --- mspsim/CHANGE_LOG.txt 2008-03-03 12:35:58 UTC (rev 155) +++ mspsim/CHANGE_LOG.txt 2008-03-07 00:12:57 UTC (rev 156) @@ -1,3 +1,7 @@ +0.85 +Changes: +- fixed multiplier to handle the different modes better. + 0.84 Changes: - fixed bug in source file handling in ELF symbol loader Modified: mspsim/se/sics/mspsim/chip/M25P80.java =================================================================== --- mspsim/se/sics/mspsim/chip/M25P80.java 2008-03-03 12:35:58 UTC (rev 155) +++ mspsim/se/sics/mspsim/chip/M25P80.java 2008-03-07 00:12:57 UTC (rev 156) @@ -224,6 +224,9 @@ state = SECTOR_ERASE; pos = 0; break; + case BULK_ERASE: + System.out.println("M25P80: Bulk Erase"); + break; } source.byteReceived(0); } Modified: mspsim/se/sics/mspsim/core/MSP430Constants.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Constants.java 2008-03-03 12:35:58 UTC (rev 155) +++ mspsim/se/sics/mspsim/core/MSP430Constants.java 2008-03-07 00:12:57 UTC (rev 156) @@ -43,7 +43,7 @@ public interface MSP430Constants { - public static final String VERSION = "0.83"; + public static final String VERSION = "0.85 jag ha"; public static final int CLK_ACLK = 1; public static final int CLK_SMCLK = 2; Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2008-03-03 12:35:58 UTC (rev 155) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2008-03-07 00:12:57 UTC (rev 156) @@ -162,6 +162,7 @@ // Only cares of writes! for (int i = 0x130, n = 0x13f; i < n; i++) { memOut[i] = mp; + memIn[i] = mp; } ioUnits[0] = ta; Modified: mspsim/se/sics/mspsim/core/Multiplier.java =================================================================== --- mspsim/se/sics/mspsim/core/Multiplier.java 2008-03-03 12:35:58 UTC (rev 155) +++ mspsim/se/sics/mspsim/core/Multiplier.java 2008-03-07 00:12:57 UTC (rev 156) @@ -55,6 +55,19 @@ public static final int RESHI = 0x13c; public static final int SUMEXT = 0x13e; + private int mpy; + private int mpys; + private int op2; + + private int resLo; + private int resHi; + private int mac; + private int macs; + private int sumext; + + private int lastWriteOP; + private int currentSum; + MSP430Core core; /** * Creates a new <code>Multiplier</code> instance. @@ -70,11 +83,29 @@ } public int read(int address, boolean word, long cycles) { - int val = memory[address]; - if (word) { - val |= memory[(address + 1) & 0xffff] << 8; + switch (address) { + case MPY: + return mpy; + case MPYS: + return mpys; + case MAC: + return mac; + case MACS: + return macs; + case OP2: + return op2; + case RESHI: + if (DEBUG) System.out.println(getName() + " read res hi: " + resHi ); + return resHi; + case RESLO: + if (DEBUG) System.out.println(getName() + " read res lo: " + resLo ); + return resLo; + case SUMEXT: + if (DEBUG) System.out.println(getName() + " read sumext: " + sumext); + return sumext; } - return val; + System.out.println(getName() + " read other address:" + address); + return 0; } public void write(int address, int data, boolean word, long cycles) { @@ -82,11 +113,6 @@ System.out.println("Multiplier: write to: " + Utils.hex16(address) + " data = " + data + " word = " + word); } - memory[address] = data & 0xff; - if (word) { - memory[address + 1] = (data >> 8) & 0xff; - } - if (MSP430Constants.DEBUGGING_LEVEL > 0) { System.out.println("Write to HW Multiplier: " + Integer.toString(address, 16) + @@ -94,17 +120,63 @@ } switch(address) { + case MPY: + mpy = data; + if (DEBUG) System.out.println(getName() + " Write to MPY: " + data); + lastWriteOP = address; + break; + case MPYS: + mpys = data; + if (DEBUG) System.out.println(getName() + " Write to MPYS: " + data); + lastWriteOP = address; + break; + case MAC: + mac = data; + currentSum = 0; + if (DEBUG) System.out.println(getName() + " Write to MAC: " + data); + lastWriteOP = address; + break; + case MACS: + macs = data; + currentSum = 0; + if (DEBUG) System.out.println(getName() + " Write to MACS: " + data); + lastWriteOP = address; + break; case OP2: - int o2 = memory[OP2] + (memory[OP2 + 1] << 8); + if (DEBUG) System.out.println(getName() + " Write to OP2: " + data); + sumext = 0; + op2 = data; // This should be picked based on which op was written previously!!! - int o1 = memory[MPYS] + (memory[MPYS + 1] << 8); - int res = o1 * o2; - int hiRes = (res >> 16) & 0xffff; - int loRes = res & 0xffff; - memory[RESHI] = hiRes & 0xff; - memory[RESHI + 1] = (hiRes >> 8) & 0xff; - memory[RESLO] = loRes & 0xff; - memory[RESLO + 1] = (loRes >> 8) & 0xff; + int o1 = mpy; + boolean signMode = false; + boolean sum = false; + if (lastWriteOP == MPYS) { + o1 = MPYS; + signMode = true; + } else if (lastWriteOP == MAC) { + o1 = mac; + sum = true; + } else if (lastWriteOP == MACS) { + o1 = macs; + signMode = true; + sum = true; + } + + if (signMode) { + // Assume two 16 bit mults. + if (((o1 ^ op2) & 0x8000) > 0) { + sumext = 0xffff; + } + } + int res = o1 * op2; + + if (sum) { + currentSum += res; + res = currentSum; + } + resHi = (res >> 16) & 0xffff; + resLo = res & 0xffff; + if(DEBUG) System.out.println(" ===> result = " + res); break; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-03-18 10:47:12
|
Revision: 194 http://mspsim.svn.sourceforge.net/mspsim/?rev=194&view=rev Author: joxe Date: 2008-03-18 03:47:10 -0700 (Tue, 18 Mar 2008) Log Message: ----------- added cycle-based eventqueue. Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/se/sics/mspsim/core/Timer.java mspsim/se/sics/mspsim/platform/sky/SkyNode.java mspsim/tests/Makefile mspsim/tests/cputest.c Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2008-03-17 22:54:11 UTC (rev 193) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2008-03-18 10:47:10 UTC (rev 194) @@ -124,6 +124,9 @@ private EventQueue vTimeEventQueue = new EventQueue(); private long nextVTimeEventCycles; + private EventQueue cycleEventQueue = new EventQueue(); + private long nextCycleEventCycles; + public MSP430Core(int type) { // Ignore type for now... @@ -376,25 +379,55 @@ private void executeEvents() { if (cycles >= nextVTimeEventCycles) { if (vTimeEventQueue.nextTime == 0) { - nextEventCycles = cycles + 1000; - return; + nextVTimeEventCycles = cycles + 1000; + } else { + TimeEvent te = vTimeEventQueue.popFirst(); + long now = getTime(); + te.execute(now); + if (vTimeEventQueue.nextTime > 0) { + nextVTimeEventCycles = convertVTime(vTimeEventQueue.nextTime); + } else { + nextVTimeEventCycles = cycles + 1000; + } } - TimeEvent te = vTimeEventQueue.popFirst(); - long now = getTime(); - te.execute(now); - if (vTimeEventQueue.nextTime > 0) { - nextVTimeEventCycles = convertVTime(vTimeEventQueue.nextTime); - nextEventCycles = nextVTimeEventCycles; + } + + if (cycles >= nextCycleEventCycles) { + if (cycleEventQueue.nextTime == 0) { + nextCycleEventCycles = cycles + 1000; + } else { + TimeEvent te = cycleEventQueue.popFirst(); + te.execute(cycles); + if (cycleEventQueue.nextTime > 0) { + nextEventCycles = cycleEventQueue.nextTime; + } else { + nextCycleEventCycles = cycles + 1000; + } } - } else { - // Allow 1000 cycles to pass if nothing to do... - nextEventCycles = cycles + 1000; } + + // Pick the one with shortest time in the future. + nextEventCycles = nextCycleEventCycles < nextVTimeEventCycles ? + nextCycleEventCycles : nextVTimeEventCycles; } -// public void scheduleCycleEvent(long cycles, TimeEvent event) { -// } + /** + * Schedules a new Time event using the cycles counter + * @param event + * @param time + */ + public void scheduleCycleEvent(TimeEvent event, long cycles) { + long currentNext = vTimeEventQueue.nextTime; + cycleEventQueue.addEvent(event, cycles); + if (currentNext != cycleEventQueue.nextTime) { + nextCycleEventCycles = cycleEventQueue.nextTime; + if (nextEventCycles > nextCycleEventCycles) { + nextEventCycles = nextCycleEventCycles; + } + } + } + /** * Schedules a new Time event using the virtual time clock @@ -407,8 +440,10 @@ if (currentNext != vTimeEventQueue.nextTime) { // This is only valid when not having a cycle event queue also... // if we have it needs to be checked also! - nextVTimeEventCycles = nextEventCycles = - convertVTime(vTimeEventQueue.nextTime); + nextVTimeEventCycles = convertVTime(vTimeEventQueue.nextTime); + if (nextEventCycles > nextVTimeEventCycles) { + nextEventCycles = nextVTimeEventCycles; + } } } Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2008-03-17 22:54:11 UTC (rev 193) +++ mspsim/se/sics/mspsim/core/Timer.java 2008-03-18 10:47:10 UTC (rev 194) @@ -599,8 +599,6 @@ // Trigger interrupts that are up for triggering! triggerInterrupts(); - -// System.out.println("Writer: timer ctr = " + Utils.hex16(counter)); return 1000 + cycles; } Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-03-17 22:54:11 UTC (rev 193) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-03-18 10:47:10 UTC (rev 194) @@ -49,6 +49,7 @@ import se.sics.mspsim.core.IOUnit; import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.PortListener; +import se.sics.mspsim.core.TimeEvent; import se.sics.mspsim.core.USART; import se.sics.mspsim.core.USARTListener; import se.sics.mspsim.extutil.jfreechart.DataChart; @@ -223,12 +224,14 @@ stats.addMonitor(radio); stats.addMonitor(cpu); -// cpu.scheduleTimeEventMillis(new TimeEvent(0) { -// public void execute(long t) { -// System.out.println("SkyNode: a second elapsed (wall time): " + t + " millis: " + SkyNode.this.cpu.getTimeMillis()); -// SkyNode.this.cpu.scheduleTimeEventMillis(this, 1000.0); -// } -// }, 1000.0); + cpu.scheduleCycleEvent(new TimeEvent(0) { + public void execute(long t) { + System.out.println("SkyNode: 1000000 cycles elapsed: " + t + " " + + SkyNode.this.cpu.getTimeMillis()); + // schedule at planned time + 1000000 + SkyNode.this.cpu.scheduleCycleEvent(this, time + 1000000); + } + }, 1000000); // TODO: remove this test... radio.setPacketListener(new PacketListener() { Modified: mspsim/tests/Makefile =================================================================== --- mspsim/tests/Makefile 2008-03-17 22:54:11 UTC (rev 193) +++ mspsim/tests/Makefile 2008-03-18 10:47:10 UTC (rev 194) @@ -10,7 +10,8 @@ .SUFFIXES: -MCU=msp430x149 +#MCU=msp430x149 +MCU=msp430x1611 ### Compiler definitions CC = msp430-gcc Modified: mspsim/tests/cputest.c =================================================================== --- mspsim/tests/cputest.c 2008-03-17 22:54:11 UTC (rev 193) +++ mspsim/tests/cputest.c 2008-03-18 10:47:10 UTC (rev 194) @@ -41,6 +41,7 @@ #include <signal.h> #include <stdio.h> #include <string.h> +#include <io.h> /* From Adams test-suite */ #define TEST(...) if(__VA_ARGS__) { \ @@ -68,6 +69,20 @@ static int caseID = 0; +/*---------------------------------------------------------------------------*/ +static int pos = 0; +static unsigned int times[10]; +interrupt(TIMERB1_VECTOR) timerb1 (void) { + if(TBIV == 2) { + if (pos < 10) { + times[pos] = TBR; + pos++; + TBCCR1 = TBCCR1 + 100; + } + } +} +/*---------------------------------------------------------------------------*/ + static void initTest() { caseID = 0; } @@ -267,6 +282,37 @@ printf("output finished...\n"); } +static void testTimer() { + int i; + pos = 0; + dint(); + /* Select SMCLK (2.4576MHz), clear TAR; This makes the rtimer count + the number of processor cycles executed by the CPU. */ + //TBCTL = TBSSEL1 | TBCLR; + /* Select ACLK 32768Hz clock, divide by 1 (was ID_8 previously) */ + TBCTL = TBSSEL0 | TBCLR | ID_0; + + /* CCR1 interrupt enabled, interrupt occurs when timer equals CCR1. */ + TBCCTL1 = CCIE; + + /* Start Timer_B in continuous mode. */ + TBCTL |= MC1; + + TBR = 0; + TBCCR1 = 100; + + /* Enable interrupts. */ + eint(); + + while (pos < 10) { + printf("waiting for timer...%d\n", pos); + } + + for (i = 0; i < pos; i++) { + printf("Trigg time %d => %d\n", i + 1, times[i]); + } +} + /*--------------------------------------------------------------------------*/ int @@ -284,6 +330,7 @@ testFunctions(); testModulo(); testUSART(); + testTimer(); /* printf("PROFILE\n"); */ printf("EXIT\n"); return 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-03-18 13:38:04
|
Revision: 195 http://mspsim.svn.sourceforge.net/mspsim/?rev=195&view=rev Author: joxe Date: 2008-03-18 06:37:58 -0700 (Tue, 18 Mar 2008) Log Message: ----------- Rewrote scheduling of timer system to be eventbased instead of "tick" based. Modified Paths: -------------- mspsim/se/sics/mspsim/core/EventQueue.java mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/se/sics/mspsim/core/Timer.java mspsim/tests/cputest.c Modified: mspsim/se/sics/mspsim/core/EventQueue.java =================================================================== --- mspsim/se/sics/mspsim/core/EventQueue.java 2008-03-18 10:47:10 UTC (rev 194) +++ mspsim/se/sics/mspsim/core/EventQueue.java 2008-03-18 13:37:58 UTC (rev 195) @@ -45,6 +45,7 @@ private TimeEvent first; public long nextTime; + public int eventCount = 0; public EventQueue() { } @@ -58,6 +59,7 @@ if (event.scheduled) { removeEvent(event); } + eventCount++; if (first == null) { first = event; } else { @@ -116,6 +118,7 @@ // System.out.println("Removed =>"); // print(); event.scheduled = false; + eventCount--; return true; } Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2008-03-18 10:47:10 UTC (rev 194) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2008-03-18 13:37:58 UTC (rev 195) @@ -52,7 +52,7 @@ // Try it out with 64 k memory public static final int MAX_MEM = 64*1024; - public static final int INTERNAL_IO_SIZE = 5; + public static final int INTERNAL_IO_SIZE = 3; public static final int PORTS = 6; public static final int MODE_ACTIVE = 0; @@ -131,12 +131,14 @@ // Ignore type for now... // Internal Active IOUnits + int passIO = 0; + int actIO = 0; ioUnits = new IOUnit[INTERNAL_IO_SIZE + 10]; ioCycles = new long[INTERNAL_IO_SIZE + 10]; // Passive IOUnits (no tick) - do we need to remember them??? // Maybe for debugging purposes... - passiveIOUnits = new IOUnit[PORTS]; + passiveIOUnits = new IOUnit[PORTS + 2]; Timer ta = new Timer(this, Timer.TIMER_Ax149, memory, 0x160); Timer tb = new Timer(this, Timer.TIMER_Bx149, memory, 0x180); @@ -168,15 +170,15 @@ memIn[i] = mp; } - ioUnits[0] = ta; - ioUnits[1] = tb; - ioUnits[2] = bcs; +// ioUnits[0] = ta; +// ioUnits[1] = tb; + ioUnits[actIO++] = bcs; USART usart0 = new USART(this, memory, 0x70); USART usart1 = new USART(this, memory, 0x78); - ioUnits[3] = usart0; - ioUnits[4] = usart1; + ioUnits[actIO++] = usart0; + ioUnits[actIO++] = usart1; for (int i = 0, n = 8; i < n; i++) { memOut[0x70 + i] = usart0; @@ -187,7 +189,7 @@ } ADC12 adc12 = new ADC12(this); - ioUnits[5] = adc12; + ioUnits[actIO++] = adc12; for (int i = 0, n = 16; i < n; i++) { memOut[0x80 + i] = adc12; @@ -228,6 +230,11 @@ memOut[0x32 + i * 4] = passiveIOUnits[i + 4]; memOut[0x33 + i * 4] = passiveIOUnits[i + 4]; } + passIO = 6; + + // Add the timers + passiveIOUnits[passIO++] = ta; + passiveIOUnits[passIO++] = tb; initIOUnit(); } @@ -378,30 +385,30 @@ private void executeEvents() { if (cycles >= nextVTimeEventCycles) { - if (vTimeEventQueue.nextTime == 0) { - nextVTimeEventCycles = cycles + 1000; + if (vTimeEventQueue.eventCount == 0) { + nextVTimeEventCycles = cycles + 10000; } else { TimeEvent te = vTimeEventQueue.popFirst(); long now = getTime(); te.execute(now); - if (vTimeEventQueue.nextTime > 0) { + if (vTimeEventQueue.eventCount > 0) { nextVTimeEventCycles = convertVTime(vTimeEventQueue.nextTime); } else { - nextVTimeEventCycles = cycles + 1000; + nextVTimeEventCycles = cycles + 10000; } } } if (cycles >= nextCycleEventCycles) { - if (cycleEventQueue.nextTime == 0) { - nextCycleEventCycles = cycles + 1000; + if (cycleEventQueue.eventCount == 0) { + nextCycleEventCycles = cycles + 10000; } else { TimeEvent te = cycleEventQueue.popFirst(); te.execute(cycles); - if (cycleEventQueue.nextTime > 0) { - nextEventCycles = cycleEventQueue.nextTime; + if (cycleEventQueue.eventCount > 0) { + nextCycleEventCycles = cycleEventQueue.nextTime; } else { - nextCycleEventCycles = cycles + 1000; + nextCycleEventCycles = cycles + 10000; } } } @@ -417,7 +424,7 @@ * @param time */ public void scheduleCycleEvent(TimeEvent event, long cycles) { - long currentNext = vTimeEventQueue.nextTime; + long currentNext = cycleEventQueue.nextTime; cycleEventQueue.addEvent(event, cycles); if (currentNext != cycleEventQueue.nextTime) { nextCycleEventCycles = cycleEventQueue.nextTime; @@ -425,7 +432,6 @@ nextEventCycles = nextCycleEventCycles; } } - } Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2008-03-18 10:47:10 UTC (rev 194) +++ mspsim/se/sics/mspsim/core/Timer.java 2008-03-18 13:37:58 UTC (rev 195) @@ -197,7 +197,13 @@ private boolean interruptEnable = false; private boolean interruptPending = false; - + private TimeEvent timerTrigger = new TimeEvent(0) { + public void execute(long t) { +// System.out.println(getName() + " executing update timers at " + t); + updateTimers(t); + } + }; + private MSP430Core core; private int lastTIV; @@ -389,6 +395,7 @@ } updateCaptures(-1, cycles); + break; case TCCTL0: case TCCTL1: @@ -448,8 +455,10 @@ if (DEBUG) { System.out.println(getName() + " Cycles: " + cycles + " expCap[" + index + "]: " + expCaptureTime[index] + " ctr:" + counter + " data: " + data + " ~" + - (100 * (cyclesMultiplicator * diff * 1L) / 2500000) / 100.0 + " sec"); + (100 * (cyclesMultiplicator * diff * 1L) / 2500000) / 100.0 + " sec" + + "at cycles: " + expCaptureTime[index]); } + calculateNextEventTime(cycles); } } @@ -459,10 +468,8 @@ } private void updateCaptures(int index, long cycles) { - int low = 0; int hi = noCompare; if (index != -1) { - low = index; hi = index + 1; } @@ -476,12 +483,12 @@ } else if (clockSource == SRC_ACLK) { frqClk = core.aclkFrq / inputDivider; } - + // Handle the captures... if (captureOn[i]) { - if (inputSrc[i] == SRC_ACLK) { - divisor = core.aclkFrq; - } + if (inputSrc[i] == SRC_ACLK) { + divisor = core.aclkFrq; + } if (DEBUG) { System.out.println(getName() + " expCapInterval[" + i + "] frq = " + @@ -506,6 +513,7 @@ } } } + calculateNextEventTime(cycles); } private int updateCounter(long cycles) { @@ -539,10 +547,15 @@ return counter; } - // Simplest possible - just a call each 1000 cycles (which is wrong...) + // Simplest possible - just a call each 1000 cycles (which is wrong...) public long ioTick(long cycles) { + System.out.println(getName() + " UNEXPECTED CALL TO IOTICK ****"); + return 100000 + cycles; + } - if (cycles > nextTimerTrigger) { + private void updateTimers(long cycles) { + + if (cycles >= nextTimerTrigger) { interruptPending = true; // This should be updated whenever clockspeed changes... nextTimerTrigger = (long) (nextTimerTrigger + 0x10000 * cyclesMultiplicator); @@ -551,57 +564,83 @@ // This will not work very good... // But the timer does not need to be updated this often... // Do we need to update the counter here??? - // System.out.println("Checking capture register [ioTick]: " + cycles); + // System.out.println("Checking capture register [ioTick]: " + cycles); for (int i = 0, n = noCompare; i < n; i++) { // System.out.println("Checking: " + i); - if (expCaptureTime[i] != -1 && cycles > expCaptureTime[i]) { - if (DEBUG) { - System.out.println(getName() + " CAPTURE: " + i + - " Cycles: " + cycles + " expCap: " + - expCaptureTime[i] + - " => ExpCR: " + Utils.hex16(expCompare[i]) + - " TR: " + Utils.hex16(updateCounter(cycles))); - } - // Set the interrupt flag... - tcctl[i] |= CC_IFG; + if (expCaptureTime[i] != -1 && cycles >= expCaptureTime[i]) { + if (DEBUG) { + System.out.println(getName() + " CAPTURE: " + i + + " Cycles: " + cycles + " expCap: " + + expCaptureTime[i] + + " => ExpCR: " + Utils.hex16(expCompare[i]) + + " TR: " + Utils.hex16(updateCounter(cycles))); + } + // Set the interrupt flag... + tcctl[i] |= CC_IFG; - if (captureOn[i]) { - // Write the expected capture time to the register (counter could - // differ slightly) - tccr[i] = expCompare[i]; - // Update capture times... for next capture - expCompare[i] = (expCompare[i] + expCapInterval[i]) & 0xffff; - expCaptureTime[i] += expCapInterval[i] * cyclesMultiplicator; - if (DEBUG) { - System.out.println(getName() + - " setting expCaptureTime to next capture: " + - expCaptureTime[i]); - } - } else { - // Update expected compare time for this compare/cap reg. - // 0x10000 cycles... e.g. a full 16 bits wrap of the timer - expCaptureTime[i] = expCaptureTime[i] + - (long) (0x10000 * cyclesMultiplicator); - if (DEBUG) { - System.out.println(getName() + - " setting expCaptureTime to full wrap: " + - expCaptureTime[i]); - } - } + if (captureOn[i]) { + // Write the expected capture time to the register (counter could + // differ slightly) + tccr[i] = expCompare[i]; + // Update capture times... for next capture + expCompare[i] = (expCompare[i] + expCapInterval[i]) & 0xffff; + expCaptureTime[i] += expCapInterval[i] * cyclesMultiplicator; + if (DEBUG) { + System.out.println(getName() + + " setting expCaptureTime to next capture: " + + expCaptureTime[i]); + } + } else { + // Update expected compare time for this compare/cap reg. + // 0x10000 cycles... e.g. a full 16 bits wrap of the timer + expCaptureTime[i] = expCaptureTime[i] + + (long) (0x10000 * cyclesMultiplicator); + if (DEBUG) { + System.out.println(getName() + + " setting expCaptureTime to full wrap: " + + expCaptureTime[i]); + } + } - if (DEBUG) { - System.out.println("Wrote to: " + - Utils.hex16(offset + TCCTL0 + i * 2 + 1)); - } + if (DEBUG) { + System.out.println("Wrote to: " + + Utils.hex16(offset + TCCTL0 + i * 2 + 1)); + } } } + // Trigger interrupts that are up for triggering! triggerInterrupts(); - - return 1000 + cycles; + calculateNextEventTime(cycles); } - + + private void calculateNextEventTime(long cycles) { + long time = nextTimerTrigger; +// int smallest = -1; + for (int i = 0; i < expCaptureTime.length; i++) { + long ct = expCaptureTime[i]; + if (ct > 0 && ct < time) { + time = ct; +// smallest = i; + } + } + + if (time == 0) { + time = cycles + 1000; + } + + if (!timerTrigger.scheduled) { +// System.out.println(getName() + " new trigger (nothing sch) ..." + time + " re:" + +// smallest + " => " + (smallest > 0 ? expCaptureTime[smallest] + " > " + expCompare[smallest]: +// nextTimerTrigger) + " C:"+ cycles); + core.scheduleCycleEvent(timerTrigger, time); + } else if (timerTrigger.time > time) { +// System.out.println(getName() + " new trigger (new time)..." + time + " C:"+ cycles); + core.scheduleCycleEvent(timerTrigger, time); + } + } + // Can be called to generate any interrupt... public void triggerInterrupts() { // First check if any capture register is generating an interrupt... Modified: mspsim/tests/cputest.c =================================================================== --- mspsim/tests/cputest.c 2008-03-18 10:47:10 UTC (rev 194) +++ mspsim/tests/cputest.c 2008-03-18 13:37:58 UTC (rev 195) @@ -73,7 +73,7 @@ static int pos = 0; static unsigned int times[10]; interrupt(TIMERB1_VECTOR) timerb1 (void) { - if(TBIV == 2) { + if (TBIV == 2) { if (pos < 10) { times[pos] = TBR; pos++; @@ -309,7 +309,7 @@ } for (i = 0; i < pos; i++) { - printf("Trigg time %d => %d\n", i + 1, times[i]); + printf("Trigg time %d => %ud\n", i + 1, times[i]); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-03-18 15:29:03
|
Revision: 197 http://mspsim.svn.sourceforge.net/mspsim/?rev=197&view=rev Author: joxe Date: 2008-03-18 08:28:58 -0700 (Tue, 18 Mar 2008) Log Message: ----------- Added compensation for timer counter system for less drift. Modified Paths: -------------- mspsim/se/sics/mspsim/core/Timer.java mspsim/tests/cputest.c Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2008-03-18 14:48:54 UTC (rev 196) +++ mspsim/se/sics/mspsim/core/Timer.java 2008-03-18 15:28:58 UTC (rev 197) @@ -134,6 +134,9 @@ private long lastCycles = 0; private long counterStart = 0; private long nextTimerTrigger = 0; + // Number of cycles passed since current counter value was set + // useful for setting timeEvents to correct time. + private int counterPassed = 0; // valid for timer A private int timerOverflow = 0x0a; @@ -451,7 +454,9 @@ Utils.hex16(data) + " TR: " + Utils.hex16(counter) + " diff: " + Utils.hex16(diff)); } - expCaptureTime[index] = cycles + (long)(cyclesMultiplicator * diff); + // Use the counterPassed information to compensate the expected capture/compare time!!! + expCaptureTime[index] = cycles + (long)(cyclesMultiplicator * diff) - counterPassed; + counterPassed = 0; if (DEBUG) { System.out.println(getName() + " Cycles: " + cycles + " expCap[" + index + "]: " + expCaptureTime[index] + " ctr:" + counter + " data: " + data + " ~" + @@ -526,15 +531,17 @@ } divider = divider * inputDivider; long cycctr = cycles - counterStart; + double tick = cycctr / divider; + counterPassed = (int) (divider * (tick - (long) (tick))); switch (mode) { case CONTIN: - counter = ((int) (cycctr / divider)) & 0xffff; + counter = ((int) tick) & 0xffff; break; case UP: - counter = ((int) (cycctr / divider)) % tccr[0]; + counter = ((int) tick) % tccr[0]; break; case UPDWN: - counter = ((int) (cycctr / divider)) % (tccr[0] * 2); + counter = ((int) tick) % (tccr[0] * 2); if (counter > tccr[0]) { // Should back down to start again! counter = 2 * tccr[0] - counter; Modified: mspsim/tests/cputest.c =================================================================== --- mspsim/tests/cputest.c 2008-03-18 14:48:54 UTC (rev 196) +++ mspsim/tests/cputest.c 2008-03-18 15:28:58 UTC (rev 197) @@ -311,7 +311,7 @@ for (i = 0; i < pos; i++) { unsigned int t = 100 + i * 100; -/* printf("Trigg time %d => %u\n", i + 1, times[i]); */ + printf("Trigg time %d => %u\n", i + 1, times[i]); assertTrue(times[i] >= t && times[i] < t + 2); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |