You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(21) |
Nov
(12) |
Dec
(41) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(25) |
Feb
(54) |
Mar
(63) |
Apr
(52) |
May
(17) |
Jun
(3) |
Jul
(3) |
Aug
(5) |
Sep
(49) |
Oct
(50) |
Nov
(34) |
Dec
(14) |
2009 |
Jan
(9) |
Feb
(15) |
Mar
(38) |
Apr
(12) |
May
(35) |
Jun
(20) |
Jul
(2) |
Aug
(7) |
Sep
(36) |
Oct
(24) |
Nov
(2) |
Dec
(2) |
2010 |
Jan
(14) |
Feb
(1) |
Mar
(36) |
Apr
(2) |
May
(4) |
Jun
(6) |
Jul
(35) |
Aug
(11) |
Sep
(8) |
Oct
(3) |
Nov
|
Dec
(1) |
2011 |
Jan
(11) |
Feb
(12) |
Mar
(3) |
Apr
(7) |
May
(12) |
Jun
(8) |
Jul
|
Aug
(3) |
Sep
(4) |
Oct
|
Nov
(2) |
Dec
(4) |
2012 |
Jan
(2) |
Feb
(1) |
Mar
(14) |
Apr
(5) |
May
(28) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(21) |
Nov
(4) |
Dec
(1) |
2013 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <jo...@us...> - 2008-09-09 20:58:23
|
Revision: 311 http://mspsim.svn.sourceforge.net/mspsim/?rev=311&view=rev Author: joxe Date: 2008-09-09 20:58:19 +0000 (Tue, 09 Sep 2008) Log Message: ----------- moved a few IOUnits to passive units instead of active Modified Paths: -------------- mspsim/se/sics/mspsim/core/BasicClockModule.java mspsim/se/sics/mspsim/core/IOUnit.java mspsim/se/sics/mspsim/core/MSP430Core.java Modified: mspsim/se/sics/mspsim/core/BasicClockModule.java =================================================================== --- mspsim/se/sics/mspsim/core/BasicClockModule.java 2008-09-08 18:00:44 UTC (rev 310) +++ mspsim/se/sics/mspsim/core/BasicClockModule.java 2008-09-09 20:58:19 UTC (rev 311) @@ -95,11 +95,6 @@ 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]; Modified: mspsim/se/sics/mspsim/core/IOUnit.java =================================================================== --- mspsim/se/sics/mspsim/core/IOUnit.java 2008-09-08 18:00:44 UTC (rev 310) +++ mspsim/se/sics/mspsim/core/IOUnit.java 2008-09-09 20:58:19 UTC (rev 311) @@ -58,7 +58,7 @@ return true; } - // Default implementation assums notify write and read on all + // Default implementation assumes notify write and read on all // addresses (should be optimized for each unit) public boolean needsWrite(int address) { return true; Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2008-09-08 18:00:44 UTC (rev 310) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2008-09-09 20:58:19 UTC (rev 311) @@ -53,7 +53,6 @@ // Try it out with 64 k memory public static final int MAX_MEM = 64*1024; public static final int MAX_MEM_IO = 0x200; - public static final int INTERNAL_IO_SIZE = 3; public static final int PORTS = 6; // 16 registers of which some are "special" - PC, SP, etc. @@ -85,7 +84,7 @@ private long nextIOTickCycles; private int nextIOTickIndex; - private int lastIOUnitPos = INTERNAL_IO_SIZE; + private int lastIOUnitPos = 0; // From the possible interrupt sources - to be able to indicate is serviced. private IOUnit interruptSource[] = new IOUnit[16]; @@ -126,12 +125,12 @@ // Internal Active IOUnits int passIO = 0; int actIO = 0; - ioUnits = new IOUnit[INTERNAL_IO_SIZE + 10]; - ioCycles = new long[INTERNAL_IO_SIZE + 10]; + ioUnits = new IOUnit[10]; + ioCycles = new long[10]; - // Passive IOUnits (no tick) - do we need to remember them??? + // Passive IOUnits (no tick) - should likely be placed in a hashtable? // Maybe for debugging purposes... - passiveIOUnits = new IOUnit[PORTS + 2]; + passiveIOUnits = new IOUnit[PORTS + 4]; Timer ta = new Timer(this, Timer.TIMER_Ax149, memory, 0x160); Timer tb = new Timer(this, Timer.TIMER_Bx149, memory, 0x180); @@ -167,10 +166,6 @@ memIn[i] = mp; } -// ioUnits[0] = ta; -// ioUnits[1] = tb; - ioUnits[actIO++] = bcs; - USART usart0 = new USART(this, memory, 0x70); USART usart1 = new USART(this, memory, 0x78); @@ -184,22 +179,6 @@ memOut[0x78 + i] = usart1; memIn[0x78 + i] = usart1; } - - ADC12 adc12 = new ADC12(this); - ioUnits[actIO++] = adc12; - - for (int i = 0, n = 16; i < n; i++) { - memOut[0x80 + i] = adc12; - memIn[0x80 + i] = adc12; - memOut[0x140 + i] = adc12; - memIn[0x140 + i] = adc12; - memOut[0x150 + i] = adc12; - memIn[0x150 + i] = adc12; - } - for (int i = 0, n = 8; i < n; i++) { - memOut[0x1A0 + i] = adc12; - memIn[0x1A0 + i] = adc12; - } // Add port 1,2 with interrupt capability! @@ -229,10 +208,31 @@ } passIO = 6; + // Basic clock syst. + passiveIOUnits[passIO++] = bcs; + // Add the timers passiveIOUnits[passIO++] = ta; passiveIOUnits[passIO++] = tb; + ADC12 adc12 = new ADC12(this); + passiveIOUnits[passIO++] = adc12; + + for (int i = 0, n = 16; i < n; i++) { + memOut[0x80 + i] = adc12; + memIn[0x80 + i] = adc12; + memOut[0x140 + i] = adc12; + memIn[0x140 + i] = adc12; + memOut[0x150 + i] = adc12; + memIn[0x150 + i] = adc12; + } + for (int i = 0, n = 8; i < n; i++) { + memOut[0x1A0 + i] = adc12; + memIn[0x1A0 + i] = adc12; + } + System.out.println("Number of active: " + actIO); + System.out.println("Number of passive: " + passIO); + lastIOUnitPos = actIO; initIOUnit(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-09-08 18:00:47
|
Revision: 310 http://mspsim.svn.sourceforge.net/mspsim/?rev=310&view=rev Author: joxe Date: 2008-09-08 18:00:44 +0000 (Mon, 08 Sep 2008) Log Message: ----------- added MoteIVNode Added Paths: ----------- mspsim/se/sics/mspsim/platform/sky/MoteIVNode.java Added: mspsim/se/sics/mspsim/platform/sky/MoteIVNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/MoteIVNode.java (rev 0) +++ mspsim/se/sics/mspsim/platform/sky/MoteIVNode.java 2008-09-08 18:00:44 UTC (rev 310) @@ -0,0 +1,99 @@ +package se.sics.mspsim.platform.sky; + +import se.sics.mspsim.chip.CC2420; +import se.sics.mspsim.core.IOPort; +import se.sics.mspsim.core.MSP430; +import se.sics.mspsim.core.PortListener; +import se.sics.mspsim.core.USARTListener; +import se.sics.mspsim.platform.GenericNode; +import se.sics.mspsim.util.ELF; + +public abstract class MoteIVNode extends GenericNode implements PortListener, USARTListener { + + public static final int MODE_LEDS_OFF = 0; + public static final int MODE_LEDS_1 = 1; + public static final int MODE_LEDS_2 = 2; + public static final int MODE_LEDS_3 = 3; + public static final int MODE_MAX = MODE_LEDS_3; + // Port 2. + public static final int BUTTON_PIN = 7; + + /* P1.0 - Input: FIFOP from CC2420 */ + /* P1.3 - Input: FIFO from CC2420 */ + /* P1.4 - Input: CCA from CC2420 */ + public static final int CC2420_FIFOP = 0; + public static final int CC2420_FIFO = 3; + public static final int CC2420_CCA = 4; + + /* P4.1 - Input: SFD from CC2420 */ + /* P4.5 - Output: VREG_EN to CC2420 */ + /* P4.2 - Output: SPI Chip Select (CS_N) */ + public static final int CC2420_SFD = 1; + public static final int CC2420_VREG = (1 << 5); + public static final int CC2420_CHIP_SELECT = 0x04; + + 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; + + protected IOPort port1; + protected IOPort port2; + protected IOPort port4; + protected IOPort port5; + + public CC2420 radio; + + + public SkyGui gui; + + public void setDebug(boolean debug) { + cpu.setDebug(debug); + } + + public MSP430 getCPU() { + return cpu; + } + + public void setButton(boolean hi) { + port2.setPinState(BUTTON_PIN, hi ? IOPort.PIN_HI : IOPort.PIN_LOW); + } + + public boolean getDebug() { + return cpu.getDebug(); + } + + public ELF getElfInfo() { + return elf; + } + + public void portWrite(IOPort source, int data) { + if (source == port5) { + redLed = (data & RED_LED) == 0; + blueLed = (data & BLUE_LED) == 0; + greenLed = (data & GREEN_LED) == 0; + int newMode = (redLed ? 1 : 0) + (greenLed ? 1 : 0) + (blueLed ? 1 : 0); + setMode(newMode); + + if (gui != null) { + gui.repaint(); + } + } else if (source == port4) { + // Chip select = active low... + radio.setChipSelect((data & CC2420_CHIP_SELECT) == 0); + radio.setVRegOn((data & CC2420_VREG) != 0); + //radio.portWrite(source, data); + flashWrite(source, data); + } + } + + public int getModeMax() { + return MODE_MAX; + } + + abstract void flashWrite(IOPort source, int data); + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-09-07 17:50:10
|
Revision: 309 http://mspsim.svn.sourceforge.net/mspsim/?rev=309&view=rev Author: joxe Date: 2008-09-07 17:50:08 +0000 (Sun, 07 Sep 2008) Log Message: ----------- fixed minor bug in telos node Modified Paths: -------------- mspsim/CHANGE_LOG.txt mspsim/se/sics/mspsim/platform/sky/TelosNode.java Modified: mspsim/CHANGE_LOG.txt =================================================================== --- mspsim/CHANGE_LOG.txt 2008-09-07 17:08:42 UTC (rev 308) +++ mspsim/CHANGE_LOG.txt 2008-09-07 17:50:08 UTC (rev 309) @@ -10,7 +10,7 @@ - fixed windows to accept double input and not only int input - corrected cycle count on some instructions - improved CC2420 emulation (thanks to Matt Thompson) -- added Telos platformincluding AT45DB flash memory chip (Matt Thompson) +- added Telos platform including AT45DB flash memory chip (Matt Thompson) 0.91 Modified: mspsim/se/sics/mspsim/platform/sky/TelosNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/TelosNode.java 2008-09-07 17:08:42 UTC (rev 308) +++ mspsim/se/sics/mspsim/platform/sky/TelosNode.java 2008-09-07 17:50:08 UTC (rev 309) @@ -104,7 +104,7 @@ } public String getName() { - return "TelosB"; + return "Telos"; } public void setupNodePorts(boolean loadFlash) { @@ -211,7 +211,7 @@ // A HACK for some "graphs"!!! DataChart dataChart = new DataChart("Duty Cycle", "Duty Cycle"); DataSourceSampler dss = dataChart.setupChipFrame(cpu); - dataChart.addDataSource(dss, "LEDS", stats.getDataSource("Tmote Sky", 0, OperatingModeStatistics.OP_INVERT)); + dataChart.addDataSource(dss, "LEDS", stats.getDataSource("Telos", 0, OperatingModeStatistics.OP_INVERT)); dataChart.addDataSource(dss, "Listen", stats.getDataSource("CC2420", CC2420.MODE_RX_ON)); dataChart.addDataSource(dss, "Transmit", stats.getDataSource("CC2420", CC2420.MODE_TXRX_ON)); dataChart.addDataSource(dss, "CPU", stats.getDataSource("MSP430 Core", MSP430.MODE_ACTIVE)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-09-07 17:08:46
|
Revision: 308 http://mspsim.svn.sourceforge.net/mspsim/?rev=308&view=rev Author: joxe Date: 2008-09-07 17:08:42 +0000 (Sun, 07 Sep 2008) Log Message: ----------- added runtelos in Makefile Modified Paths: -------------- mspsim/Makefile Modified: mspsim/Makefile =================================================================== --- mspsim/Makefile 2008-09-07 16:23:20 UTC (rev 307) +++ mspsim/Makefile 2008-09-07 17:08:42 UTC (rev 308) @@ -108,6 +108,10 @@ runsky: compile $(JAVA) $(JAVAARGS) se.sics.mspsim.platform.sky.SkyNode $(ARGS) $(SKYFIRMWARE) $(MAPFILE) +runtelos: compile + $(JAVA) $(JAVAARGS) se.sics.mspsim.platform.sky.TelosNode $(ARGS) $(SKYFIRMWARE) $(MAPFILE) + + test: cputest cputest: $(CPUTEST) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-09-07 16:23:22
|
Revision: 307 http://mspsim.svn.sourceforge.net/mspsim/?rev=307&view=rev Author: joxe Date: 2008-09-07 16:23:20 +0000 (Sun, 07 Sep 2008) Log Message: ----------- updated change log Modified Paths: -------------- mspsim/CHANGE_LOG.txt Modified: mspsim/CHANGE_LOG.txt =================================================================== --- mspsim/CHANGE_LOG.txt 2008-09-07 16:20:53 UTC (rev 306) +++ mspsim/CHANGE_LOG.txt 2008-09-07 16:23:20 UTC (rev 307) @@ -9,7 +9,10 @@ duty cycle information as double instead of int - fixed windows to accept double input and not only int input - corrected cycle count on some instructions +- improved CC2420 emulation (thanks to Matt Thompson) +- added Telos platformincluding AT45DB flash memory chip (Matt Thompson) + 0.91 Changes: - added window system and support for it in the CLI This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-09-07 16:20:56
|
Revision: 306 http://mspsim.svn.sourceforge.net/mspsim/?rev=306&view=rev Author: joxe Date: 2008-09-07 16:20:53 +0000 (Sun, 07 Sep 2008) Log Message: ----------- added Telos platform - currently sky with other memory Modified Paths: -------------- mspsim/se/sics/mspsim/platform/sky/SkyGui.java mspsim/se/sics/mspsim/platform/sky/SkyNode.java Added Paths: ----------- mspsim/se/sics/mspsim/platform/sky/TelosNode.java Modified: mspsim/se/sics/mspsim/platform/sky/SkyGui.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyGui.java 2008-09-06 20:06:22 UTC (rev 305) +++ mspsim/se/sics/mspsim/platform/sky/SkyGui.java 2008-09-07 16:20:53 UTC (rev 306) @@ -57,6 +57,11 @@ public class SkyGui extends JComponent implements KeyListener { + /** + * + */ + private static final long serialVersionUID = 7753659717805292786L; + public static final int GREEN_Y = 40; public static final int BLUE_Y = 46; public static final int RED_Y = 34; @@ -74,9 +79,9 @@ private ImageIcon skyImage; private JFrame window; - private SkyNode node; + private MoteIVNode node; - public SkyGui(SkyNode node) { + public SkyGui(MoteIVNode node) { this.node = node; setBackground(Color.black); Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-09-06 20:06:22 UTC (rev 305) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-09-07 16:20:53 UTC (rev 306) @@ -43,74 +43,32 @@ import java.io.IOException; import se.sics.mspsim.chip.CC2420; -import se.sics.mspsim.chip.M25P80; import se.sics.mspsim.chip.FileM25P80; +import se.sics.mspsim.chip.M25P80; import se.sics.mspsim.chip.PacketListener; import se.sics.mspsim.chip.RFListener; import se.sics.mspsim.core.IOPort; import se.sics.mspsim.core.IOUnit; import se.sics.mspsim.core.MSP430; -import se.sics.mspsim.core.PortListener; import se.sics.mspsim.core.USART; -import se.sics.mspsim.core.USARTListener; import se.sics.mspsim.extutil.jfreechart.DataChart; import se.sics.mspsim.extutil.jfreechart.DataSourceSampler; -import se.sics.mspsim.platform.GenericNode; import se.sics.mspsim.util.ArgumentManager; -import se.sics.mspsim.util.ELF; import se.sics.mspsim.util.NetworkConnection; import se.sics.mspsim.util.OperatingModeStatistics; /** * Emulation of Sky Mote */ -public class SkyNode extends GenericNode implements PortListener, USARTListener { +public class SkyNode extends MoteIVNode { public static final boolean DEBUG = false; - public static final int MODE_LEDS_OFF = 0; - public static final int MODE_LEDS_1 = 1; - public static final int MODE_LEDS_2 = 2; - public static final int MODE_LEDS_3 = 3; - public static final int MODE_MAX = MODE_LEDS_3; - // Port 2. - public static final int BUTTON_PIN = 7; - - /* P1.0 - Input: FIFOP from CC2420 */ - /* P1.3 - Input: FIFO from CC2420 */ - /* P1.4 - Input: CCA from CC2420 */ - public static final int CC2420_FIFOP = 0; - public static final int CC2420_FIFO = 3; - public static final int CC2420_CCA = 4; - - /* P4.1 - Input: SFD from CC2420 */ - /* P4.5 - Output: VREG_EN to CC2420 */ - /* P4.2 - Output: SPI Chip Select (CS_N) */ - public static final int CC2420_SFD = 1; - public static final int CC2420_VREG = (1 << 5); - public static final int CC2420_CHIP_SELECT = 0x04; - - private IOPort port1; - private IOPort port2; - private IOPort port4; - private IOPort port5; - - public CC2420 radio; public NetworkConnection network; - private M25P80 flash; private String flashFile; - 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; - - public SkyGui gui; /** * Creates a new <code>SkyNode</code> instance. * @@ -119,18 +77,6 @@ setMode(MODE_LEDS_OFF); } - public void setButton(boolean hi) { - port2.setPinState(BUTTON_PIN, hi ? IOPort.PIN_HI : IOPort.PIN_LOW); - } - - public boolean getDebug() { - return cpu.getDebug(); - } - - public ELF getElfInfo() { - return elf; - } - public M25P80 getFlash() { return flash; } @@ -139,44 +85,18 @@ this.flash = flash; } - public void setDebug(boolean debug) { - cpu.setDebug(debug); - } - public MSP430 getCPU() { - return cpu; - } - - public void portWrite(IOPort source, int data) { - if (source == port5) { - redLed = (data & RED_LED) == 0; - blueLed = (data & BLUE_LED) == 0; - greenLed = (data & GREEN_LED) == 0; - int newMode = (redLed ? 1 : 0) + (greenLed ? 1 : 0) + (blueLed ? 1 : 0); - setMode(newMode); - - if (gui != null) { - gui.repaint(); - } - } else if (source == port4) { - // Chip select = active low... - radio.setChipSelect((data & CC2420_CHIP_SELECT) == 0); - radio.setVRegOn((data & CC2420_VREG) != 0); - //radio.portWrite(source, data); - flash.portWrite(source, data); - } - } - // USART Listener public void dataReceived(USART source, int data) { radio.dataReceived(source, data); flash.dataReceived(source, data); } - public int getModeMax() { - return MODE_MAX; + @Override + void flashWrite(IOPort source, int data) { + flash.portWrite(source, data); } - + public String getName() { return "Tmote Sky"; } Added: mspsim/se/sics/mspsim/platform/sky/TelosNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/TelosNode.java (rev 0) +++ mspsim/se/sics/mspsim/platform/sky/TelosNode.java 2008-09-07 16:20:53 UTC (rev 306) @@ -0,0 +1,229 @@ +/** + * 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: SkyNode.java 304 2008-09-06 20:04:45Z joxe $ + * + * ----------------------------------------------------------------- + * + * SkyNode + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2008-09-06 22:04:45 +0200 (Sat, 06 Sep 2008) $ + * $Revision: 304 $ + */ + +package se.sics.mspsim.platform.sky; +import java.io.IOException; + +import se.sics.mspsim.chip.AT45DB; +import se.sics.mspsim.chip.CC2420; +import se.sics.mspsim.chip.FileAT45DB; +import se.sics.mspsim.chip.PacketListener; +import se.sics.mspsim.chip.RFListener; +import se.sics.mspsim.core.IOPort; +import se.sics.mspsim.core.IOUnit; +import se.sics.mspsim.core.MSP430; +import se.sics.mspsim.core.USART; +import se.sics.mspsim.extutil.jfreechart.DataChart; +import se.sics.mspsim.extutil.jfreechart.DataSourceSampler; +import se.sics.mspsim.util.ArgumentManager; +import se.sics.mspsim.util.NetworkConnection; +import se.sics.mspsim.util.OperatingModeStatistics; + +/** + * Emulation of Telos Mote (old version of Sky Node) + * + * TODO: Cleanup the MoteIVNode, SkyNode and TelosNode + */ +public class TelosNode extends MoteIVNode { + public static final boolean DEBUG = false; + + // P4.4 - Output: SPI Flash Chip Select + public static final int FLASH_RESET = (1<<3); + public static final int FLASH_CS = (1<<4); + + public NetworkConnection network; + + + private AT45DB flash; + private String flashFile; + + /** + * Creates a new <code>SkyNode</code> instance. + * + */ + public TelosNode() { + setMode(MODE_LEDS_OFF); + } + + public AT45DB getFlash() { + return flash; + } + + public void setFlash(AT45DB flash) { + this.flash = flash; + } + + @Override + void flashWrite(IOPort source, int data) { + flash.setReset((data & FLASH_RESET) == 0); + flash.setChipSelect((data & FLASH_CS) == 0); + } + + // USART Listener + public void dataReceived(USART source, int data) { + radio.dataReceived(source, data); + flash.dataReceived(source, data); + } + + public String getName() { + return "TelosB"; + } + + public void setupNodePorts(boolean loadFlash) { + IOUnit unit = cpu.getIOUnit("Port 5"); + if (unit instanceof IOPort) { + port5 = (IOPort) unit; + port5.setPortListener(this); + } + + unit = cpu.getIOUnit("Port 1"); + if (unit instanceof IOPort) { + port1 = (IOPort) unit; + } + + unit = cpu.getIOUnit("Port 2"); + if (unit instanceof IOPort) { + port2 = (IOPort) unit; + } + + IOUnit usart0 = cpu.getIOUnit("USART 0"); + if (usart0 instanceof USART) { + radio = new CC2420(cpu); + radio.setCCAPort(port1, CC2420_CCA); + radio.setFIFOPPort(port1, CC2420_FIFOP); + radio.setFIFOPort(port1, CC2420_FIFO); + if (loadFlash) { + flash = new FileAT45DB(cpu, flashFile); + } + ((USART) usart0).setUSARTListener(this); + port4 = (IOPort) cpu.getIOUnit("Port 4"); + if (port4 != null && port4 instanceof IOPort) { + port4.setPortListener(this); + radio.setSFDPort(port4, CC2420_SFD); + } + } + } + + public void setupNode() { + // create a filename for the flash file + // This should be possible to take from a config file later! + String fileName = config.getProperty("flashfile"); + if (fileName == null) { + fileName = firmwareFile; + int ix = fileName.lastIndexOf('.'); + if (ix > 0) { + fileName = fileName.substring(0, ix); + } + fileName = fileName + ".flash"; + } + System.out.println("Using flash file: " + fileName); + + this.flashFile = fileName; + + setupNodePorts(true); + + stats.addMonitor(this); + stats.addMonitor(radio); + stats.addMonitor(cpu); + + network = new NetworkConnection(); + network.addPacketListener(new PacketListener() { + public void transmissionEnded(byte[] receivedData) { + radio.setIncomingPacket(receivedData); + } + public void transmissionStarted() { + } + }); + // TODO: remove this test... + radio.setRFListener(new RFListener() { + int len = 0; + int pos = 0; + byte[] buffer = new byte[128]; + // NOTE: len is not in the packet for now... + public void receivedByte(byte data) { +// System.out.println("*** RF Data :" + data); + if (pos == 5) { +// System.out.println("**** Setting length to:" + data); + len = data; + } + buffer[pos++] = data; + // len + 1 = pos + 5 (preambles) + if (len > 0 && len + 1 == pos - 5) { +// System.out.println("***** SENDING DATA!!!"); + byte[] packet = new byte[len]; + System.arraycopy(buffer, 5, packet, 0, len); + network.dataSent(packet); + pos = 0; + len = 0; + } + } + }); + + // UART0 TXreg = 0x77? +// cpu.setBreakPoint(0x77, new CPUMonitor() { +// public void cpuAction(int type, int adr, int data) { +// System.out.println("Write to USART0 TX: " + data + " at " + +// SkyNode.this.elf.getDebugInfo(SkyNode.this.cpu.readRegister(0))); +// } +// }); + + if (!config.getPropertyAsBoolean("nogui", false)) { + gui = new SkyGui(this); + + // A HACK for some "graphs"!!! + DataChart dataChart = new DataChart("Duty Cycle", "Duty Cycle"); + DataSourceSampler dss = dataChart.setupChipFrame(cpu); + dataChart.addDataSource(dss, "LEDS", stats.getDataSource("Tmote Sky", 0, OperatingModeStatistics.OP_INVERT)); + dataChart.addDataSource(dss, "Listen", stats.getDataSource("CC2420", CC2420.MODE_RX_ON)); + dataChart.addDataSource(dss, "Transmit", stats.getDataSource("CC2420", CC2420.MODE_TXRX_ON)); + dataChart.addDataSource(dss, "CPU", stats.getDataSource("MSP430 Core", MSP430.MODE_ACTIVE)); + } + } + + + public static void main(String[] args) throws IOException { + TelosNode node = new TelosNode(); + ArgumentManager config = new ArgumentManager(); + config.handleArguments(args); + node.setup(config); + node.start(); + } +} Property changes on: mspsim/se/sics/mspsim/platform/sky/TelosNode.java ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-09-06 20:06:24
|
Revision: 305 http://mspsim.svn.sourceforge.net/mspsim/?rev=305&view=rev Author: joxe Date: 2008-09-06 20:06:22 +0000 (Sat, 06 Sep 2008) Log Message: ----------- added RFListener Added Paths: ----------- mspsim/se/sics/mspsim/chip/RFListener.java Added: mspsim/se/sics/mspsim/chip/RFListener.java =================================================================== --- mspsim/se/sics/mspsim/chip/RFListener.java (rev 0) +++ mspsim/se/sics/mspsim/chip/RFListener.java 2008-09-06 20:06:22 UTC (rev 305) @@ -0,0 +1,45 @@ +/** + * 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: RFListener.java 281 2008-05-13 15:18:14Z joxe$ + * + * ----------------------------------------------------------------- + * + * CC2420 + * + * Author : Joakim Eriksson + * Created : Sep 06 22:00:00 2008 + * + */ +package se.sics.mspsim.chip; + +public interface RFListener { + // A byte has been received via the "air" + public void receivedByte(byte data); +} Property changes on: mspsim/se/sics/mspsim/chip/RFListener.java ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-09-06 20:04:49
|
Revision: 304 http://mspsim.svn.sourceforge.net/mspsim/?rev=304&view=rev Author: joxe Date: 2008-09-06 20:04:45 +0000 (Sat, 06 Sep 2008) Log Message: ----------- improvement of CC2420 emulation by Matt Thompson Modified Paths: -------------- mspsim/se/sics/mspsim/chip/CC2420.java mspsim/se/sics/mspsim/platform/sky/SkyNode.java Modified: mspsim/se/sics/mspsim/chip/CC2420.java =================================================================== --- mspsim/se/sics/mspsim/chip/CC2420.java 2008-09-06 20:03:45 UTC (rev 303) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2008-09-06 20:04:45 UTC (rev 304) @@ -1,563 +1,905 @@ -/** - * 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 - * - * Author : Joakim Eriksson - * Created : Sun Oct 21 22:00:00 2007 - * - */ - -package se.sics.mspsim.chip; -import se.sics.mspsim.core.*; -import se.sics.mspsim.util.Utils; - -public class CC2420 extends Chip implements USARTListener { - - public static final boolean DEBUG = false; - - 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 STATUS_XOSC16M_STABLE = 1 << 6; - public static final int STATUS_TX_UNDERFLOW = 1 << 5; - public static final int STATUS_ENC_BUSY = 1 << 4; - public static final int STATUS_TX_ACTIVE = 1 << 3; - public static final int STATUS_LOCK = 1 << 2; - public static final int STATUS_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; - - // The Operation modes of the CC2420 - public static final int MODE_TXRX_OFF = 0x00; - public static final int MODE_RX_ON = 0x01; - public static final int MODE_TXRX_ON = 0x02; - public static final int MODE_MAX = MODE_TXRX_ON; - private static final String[] MODE_NAMES = new String[] { - "off", "listen", "transmit" - }; - - // when reading registers 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 contains - // 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 activeFrequency = 0; - private int activeChannel = 0; - - private int status = STATUS_XOSC16M_STABLE | STATUS_RSSI_VALID; - - 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 IOPort sfdPort = null; - private int sfdPin; - - private boolean rxPacket; - private int rxCursor; - private int rxLen; - private int txCursor; - - private PacketListener packetListener; - - private MSP430Core cpu; - - private TimeEvent transmissionEvent = new TimeEvent(0) { - public void execute(long t) { - if (DEBUG) { - System.out.println(getName() + ": **** Transmitting package to listener (if any)"); - } - status &= ~STATUS_TX_ACTIVE; - updateSFDPin(); - if (getMode() == MODE_TXRX_ON) { - setMode(MODE_RX_ON); - } - if (packetListener != null) { - // First byte is length and is not included in the data buffer (and its length) - int len = memory[RAM_TXFIFO]; - byte[] data = new byte[len + 1]; - for (int i = 0, n = data.length; i < n; i++) { - data[i] = (byte) (memory[RAM_TXFIFO + i] & 0xff); - } - packetListener.transmissionEnded(data); - } - } - }; - - private boolean on; - - public CC2420(MSP430Core cpu) { - registers[REG_SNOP] = 0; - registers[REG_TXCTRL] = 0xa0ff; - this.cpu = cpu; - setModeNames(MODE_NAMES); - setMode(MODE_TXRX_OFF); - } - - public void dataReceived(USART source, int data) { - if (on && chipSelect) { - if (DEBUG) { - System.out.println("CC2420 byte received: " + Utils.hex8(data) + - " (" + ((data >= ' ' && data <= 'Z') ? (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; - if (DEBUG) { - System.out.println("CC2420: wrote to " + Utils.hex8(address) + " = " - + registers[address]); - } - } - pos++; - break; - case READ_REGISTER: - if (pos == 0) { - source.byteReceived(registers[address] >> 8); - } else { - source.byteReceived(registers[address] & 0xff); - if (DEBUG) { - System.out.println("CC2420: read from " + Utils.hex8(address) + " = " - + registers[address]); - } - } - pos++; - 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 WRITE_TXFIFO: -// System.out.println("Writing data: " + data + " to tx: " + txCursor); - memory[RAM_TXFIFO + txCursor++] = data & 0xff; - break; - case RAM_ACCESS: - if (pos == 0) { - address = address | (data << 1) & 0x180; - ramRead = (data & 0x20) != 0; - if (DEBUG) { - System.out.println("CC2420: Address: " + Utils.hex16(address) + - " read: " + ramRead); - } - pos++; - } else { - if (!ramRead) { - memory[address++] = data; - if (DEBUG && 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... - if (DEBUG) { - System.out.println("CC2420: Strobe on: " + Utils.hex8(data)); - } - - switch (data) { - case REG_SNOP: - break; - case REG_SRXON: - updateActiveFrequency(); - - if (DEBUG) { - System.out.println("CC2420: Strobe RX-ON!!!"); - } - setMode(MODE_RX_ON); - break; - case REG_SRFOFF: - if (DEBUG) { - System.out.println("CC2420: Strobe RXTX-OFF!!!"); - } - setMode(MODE_TXRX_OFF); - break; - case REG_STXON: - updateActiveFrequency(); - - if (DEBUG) { - System.out.println("CC2420: Strobe TXON!"); - } - setMode(MODE_TXRX_ON); - transmitPacket(); - break; - case REG_STXONCCA: - updateActiveFrequency(); - - if (DEBUG) { - System.out.println("CC2420: Strobe TXONCCA!"); - } - setMode(MODE_TXRX_ON); - transmitPacket(); - break; - case REG_SFLUSHRX: - flushRX(); - break; - case REG_SFLUSHTX: - flushTX(); - break; - default: - if (DEBUG) { - System.out.println("Unknown strobe command: " + data); - } - break; - } - } - - public void updateActiveFrequency() { - /* INVERTED: f = 5 * (c - 11) + 357 + 0x4000 */ - activeFrequency = registers[REG_FSCTRL] - 357 + 2405 - 0x4000; - activeChannel = (registers[REG_FSCTRL] - 357 - 0x4000)/5 + 11; - } - - public int getActiveFrequency() { - return activeFrequency; - } - - public int getActiveChannel() { - return activeChannel; - } - - public int getOutputPowerIndicator() { - return (registers[REG_TXCTRL] & 0x1f); - } - - private static int RSSI_OFFSET = -45; /* cc2420 datasheet */ - - public void setRSSI(int power) { - if (power < -128) { - power = -128; - } - registers[REG_RSSI] = power - RSSI_OFFSET; - } - - public int getRSSI() { - return registers[REG_RSSI] + RSSI_OFFSET; - } - - public int getOutputPower() { - /* From CC2420 datasheet */ - int indicator = getOutputPowerIndicator(); - if (indicator >= 31) { - return 0; - } else if (indicator >= 27) { - return -1; - } else if (indicator >= 23) { - return -3; - } else if (indicator >= 19) { - return -5; - } else if (indicator >= 15) { - return -7; - } else if (indicator >= 11) { - return -10; - } else if (indicator >= 7) { - return -15; - } else if (indicator >= 3) { - return -25; - } - - /* Unknown */ - return -100; - } - - private void transmitPacket() { - int len = memory[RAM_TXFIFO]; - int kBps = 250000 / 8; - double time = 1.0 * (4 + 1 + 1 + len) / kBps; - if (DEBUG) { - System.out.println(getName() + " Transmitting " + len + " bytes => " + time + " sec"); - } - status |= STATUS_TX_ACTIVE; - cpu.scheduleTimeEventMillis(transmissionEvent, 1000 * time); - updateSFDPin(); - if (packetListener != null) { - packetListener.transmissionStarted(); - memory[RAM_TXFIFO + len - 1] = 1; - memory[RAM_TXFIFO + len - 0] = 2; - } - } - - public void setPacketListener(PacketListener listener) { - packetListener = listener; - } - - public void setVRegOn(boolean on) { - this.on = on; - } - - public void setChipSelect(boolean select) { - chipSelect = select; - if (!chipSelect) { - state = WAITING; - } - if (DEBUG) { - System.out.println("CC2420: setting 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; - } - - public void setSFDPort(IOPort port, int pin) { - sfdPort = port; - sfdPin = 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(byte[] receivedData) { - if (getMode() != MODE_RX_ON) { - if (DEBUG) System.out.println(getName() + ": dropping due to not in listening mode"); - } else if (rxPacket) { - // Already have a waiting packet - if (DEBUG) System.out.println(getName() + ": dropping due to unread packet"); - } else { - int adr = RAM_RXFIFO; - // length of packet is data size + RSSI and CRC/Correlation! - for (byte element: receivedData) { - memory[adr++] = element & 0xff; - } - // Should take a RSSI value as input or use a set-RSSI value... - memory[adr - 2] = (registers[REG_RSSI]) & 0xff; - // Set CRC ok and add a correlation - memory[adr - 1] = 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(); - } - - // TODO: update any pins here? - private void flushTX() { - txCursor = 0; - } - - - private void updateFifopPin() { - fifopPort.setPinState(fifopPin, rxPacket ? 1 : 0); - } - - private void updateSFDPin() { - sfdPort.setPinState(sfdPin, (status & STATUS_TX_ACTIVE) != 0 ? 1 : 0); - } - - public void setCCA(boolean cca) { - ccaPort.setPinState(ccaPin, cca ? 1 : 0); - } - - public String getName() { - return "CC2420"; - } - - public int getModeMax() { - return MODE_MAX; - } - -} // CC2420 +/** + * 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 + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * + */ + +package se.sics.mspsim.chip; +import se.sics.mspsim.core.*; +import se.sics.mspsim.util.Utils; + +public class CC2420 extends Chip implements USARTListener, RFListener { + + public static final boolean DEBUG = false; //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 STATUS_XOSC16M_STABLE = 1 << 6; + public static final int STATUS_TX_UNDERFLOW = 1 << 5; + public static final int STATUS_ENC_BUSY = 1 << 4; + public static final int STATUS_TX_ACTIVE = 1 << 3; + public static final int STATUS_LOCK = 1 << 2; + public static final int STATUS_RSSI_VALID = 1 << 1; + + // IOCFG0 Register Bit masks + public static final int BCN_ACCEPT = (1<<11); + public static final int FIFO_POLARITY = (1<<10); + public static final int FIFOP_POLARITY = (1<<9); + public static final int SFD_POLARITY = (1<<8); + public static final int CCA_POLARITY = (1<<7); + public static final int FIFOP_THR = 0x7F; + + // IOCFG1 Register Bit Masks + public static final int SFDMUX = 0x3E0; + public static final int CCAMUX = 0x1F; + + // CCAMUX values + public static final int CCA_CCA = 0; + public static final int CCA_XOSC16M_STABLE = 24; + + + // 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; + + // The Operation modes of the CC2420 + public static final int MODE_TXRX_OFF = 0x00; + public static final int MODE_RX_ON = 0x01; + public static final int MODE_TXRX_ON = 0x02; + public static final int MODE_POWER_OFF = 0x03; + public static final int MODE_MAX = MODE_POWER_OFF; + private static final String[] MODE_NAMES = new String[] { + "off", "listen", "transmit", "power_off" + }; + + // State Machine - Datasheet Figure 25 page 44 + public static final int STATE_VREG_OFF = -1; + public static final int STATE_POWER_DOWN = 0; + public static final int STATE_IDLE = 1; + public static final int STATE_RX_CALIBRATE = 2; + public static final int STATE_RX_SFD_SEARCH = 3; + public static final int STATE_RX_WAIT = 14; + public static final int STATE_RX_FRAME = 16; + public static final int STATE_RX_OVERFLOW = 17; + public static final int STATE_TX_CALIBRATE = 32; + public static final int STATE_TX_PREAMBLE = 34; + public static final int STATE_TX_FRAME = 37; + public static final int STATE_TX_ACK_CALIBRATE = 48; + public static final int STATE_TX_ACK_PREABLE = 49; + public static final int STATE_TX_ACK = 52; + public static final int STATE_TX_UNDERFLOW = 56; + + // FCF High + public static final int FRAME_TYPE = 0xC0; + public static final int SECURITY_ENABLED = (1<<6); + public static final int FRAME_PENDING = (1<<5); + public static final int ACK_REQUEST = (1<<4); + public static final int INTRA_PAN = (1<<3); + // FCF Low + public static final int DESTINATION_ADDRESS_MODE = 0x30; + public static final int SOURCE_ADDRESS_MODE = 0x3; + + private int stateMachine = STATE_VREG_OFF; + + // 802.15.4 symbol period in ms + public static final double SYMBOL_PERIOD = 0.016; // 16 us + + // when reading registers 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 contains + // 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 int shr_pos; + private int txfifo_pos; + private boolean txfifo_flush; // TXFIFO is automatically flushed on next write + private int rxfifo_write_pos; + private int rxfifo_read_pos; + private int rxfifo_len; + private int rxlen; + private int rxread; + private int zero_symbols; + private boolean ramRead = false; + private boolean fifopState; + private boolean cca; + + private int activeFrequency = 0; + private int activeChannel = 0; + + //private int status = STATUS_XOSC16M_STABLE | STATUS_RSSI_VALID; + private int status = 0; + + private int[] registers = new int[64]; + // More than needed... + private int[] memory = new int[512]; + + // Buffer to hold 5 byte Synchronization header, as it is not written to the TXFIFO + private byte[] SHR = new byte[5]; + + 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 IOPort sfdPort = null; + private int sfdPin; + + private boolean rxPacket = false; + private int rxLen; + private int txCursor; + private RFListener listener; + + + private MSP430Core cpu; + + + private TimeEvent oscillatorEvent = new TimeEvent(0) { + public void execute(long t) { + status |= STATUS_XOSC16M_STABLE; + if(DEBUG) System.out.println("CC2420: Oscillator Stable Event."); + setState(STATE_IDLE); + if( (registers[REG_IOCFG1] & CCAMUX) == CCA_XOSC16M_STABLE) { + setCCA(true); + }else{ + System.out.println("CC2420: CCAMUX != CCA_XOSC16M_STABLE! Not raising CCA"); + } + } + }; + + private TimeEvent vregEvent = new TimeEvent(0) { + public void execute(long t) { + if(DEBUG) System.out.println("CC2420: VREG Started."); + setCCA(false); + on = true; + setState(STATE_POWER_DOWN); + } + }; + + private TimeEvent sendEvent = new TimeEvent(0) { + public void execute(long t) { + txNext(); + } + }; + + private TimeEvent shrEvent = new TimeEvent(0) { + public void execute(long t) { + shrNext(); + } + }; + + private TimeEvent symbolEvent = new TimeEvent(0) { + public void execute(long t) { + switch(stateMachine) { + case STATE_RX_CALIBRATE: + setClear(true); + setState(STATE_RX_SFD_SEARCH); + break; + + case STATE_TX_CALIBRATE: + setState(STATE_TX_PREAMBLE); + break; + + case STATE_RX_WAIT: + setClear(true); + break; + } + } + }; + + private boolean setState(int state) { + //if(DEBUG) System.out.println("CC2420: State Transition from " + stateMachine + " to " + state); + stateMachine = state; + + switch(stateMachine) { + + case STATE_VREG_OFF: + System.out.println("CC2420: VREG Off."); + break; + + case STATE_POWER_DOWN: + rxfifo_read_pos = 0; + rxfifo_write_pos = 0; + break; + + case STATE_RX_CALIBRATE: + setSymbolEvent(12); + break; + + case STATE_RX_SFD_SEARCH: + zero_symbols = 0; + break; + + case STATE_TX_CALIBRATE: + setSymbolEvent(12); + break; + + case STATE_TX_PREAMBLE: + shr_pos = 0; + SHR[0] = 0; + SHR[1] = 0; + SHR[2] = 0; + SHR[3] = 0; + SHR[4] = 0x7A; + shrNext(); + break; + + case STATE_TX_FRAME: + txfifo_pos = 0; + txNext(); + break; + + case STATE_RX_WAIT: + setSymbolEvent(8); + break; + + + } + + return true; + + } + + private boolean on; + + public CC2420(MSP430Core cpu) { + registers[REG_SNOP] = 0; + registers[REG_TXCTRL] = 0xa0ff; + this.cpu = cpu; + setModeNames(MODE_NAMES); + setMode(MODE_POWER_OFF); + rxPacket = false; + rxfifo_read_pos = 0; + rxfifo_write_pos = 0; + cca = false; + } + + public void receivedByte(byte data) { + // Received a byte from the "air" + if(cca) + setClear(false); + if(stateMachine == STATE_RX_SFD_SEARCH) { + // Look for the preamble (4 zero bytes) followed by the SFD byte 0x7A + if(data == 0) { + // Count zero bytes + zero_symbols++; + return; + } + // If the received byte is !zero, we have counted 4 zero bytes prior to this one, + // and the current received byte == 0x7A (SFD), we're in sync. + if(zero_symbols == 4) { + if(data == 0x7A) { + // In RX mode, SFD goes high when the SFD is received + setSFD(true); + System.out.println("CC2420: RX: Preamble/SFD Synchronized."); + rxread = 0; + setState(STATE_RX_FRAME); + }else{ + zero_symbols = 0; + } + } + + }else if(stateMachine == STATE_RX_FRAME) { + if(rxfifo_len == 128) { + setRxOverflow(); + }else{ + memory[RAM_RXFIFO + rxfifo_write_pos++] = data & 0xFF; + rxfifo_len++; + + if(rxfifo_write_pos == 128) { + System.out.println("Wrapped RXFIFO write pos"); + rxfifo_write_pos = 0; + } + + if(rxread == 0) { + rxlen = (int)data; + System.out.println("CC2420: RX: Start frame length " + rxlen); + // FIFO pin goes high after length byte is written to RXFIFO + setFIFO(true); + } + + if(rxread++ == rxlen) { + // In RX mode, FIFOP goes high, if threshold is higher than frame length.... + + // Should take a RSSI value as input or use a set-RSSI value... + memory[RAM_RXFIFO + (rxfifo_write_pos - 2)] = (registers[REG_RSSI]) & 0xff; + // Set CRC ok and add a correlation + memory[RAM_RXFIFO + (rxfifo_write_pos -1 )] = 37 | 0x80; + setFIFOP(true); + setSFD(false); + System.out.println("CC2420: RX: Complete."); + setState(STATE_RX_WAIT); + } + } + + + } + + } + + public void dataReceived(USART source, int data) { + if ( (stateMachine != STATE_VREG_OFF) && chipSelect) { + + /* + if (DEBUG) { + System.out.println("State Machine: " + stateMachine); + System.out.println("CC2420 byte received: " + Utils.hex8(data) + + " (" + ((data >= ' ' && data <= 'Z') ? (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; + /* + if (DEBUG) { + System.out.println("CC2420: wrote to " + Utils.hex8(address) + " = " + + registers[address]); + switch(address) { + case REG_IOCFG0: + System.out.println("CC2420: IOCFG0: " + registers[address]); + break; + case REG_IOCFG1: + System.out.println("CC2420: IOCFG1: SFDMUX " + + ((registers[address] & SFDMUX) >> SFDMUX) + + " CCAMUX: " + (registers[address] & CCAMUX)); + if( (registers[address] & CCAMUX) == CCA_CCA) + setCCA(false); + break; + } + } + */ + } + pos++; + break; + case READ_REGISTER: + if (pos == 0) { + source.byteReceived(registers[address] >> 8); + } else { + source.byteReceived(registers[address] & 0xff); + if (DEBUG) { + System.out.println("CC2420: read from " + Utils.hex8(address) + " = " + + registers[address]); + } + } + pos++; + return; + //break; + case READ_RXFIFO: + if(rxfifo_len == 0) + break; + System.out.println("CC2420: RXFIFO READ " + rxfifo_read_pos + " => " + + (memory[RAM_RXFIFO + rxfifo_read_pos] & 0xFF) ); + source.byteReceived( (memory[RAM_RXFIFO + rxfifo_read_pos] & 0xFF) ); + rxfifo_read_pos++; + setFIFOP(false); + + // Set the FIFO pin low if there are no more bytes available in the RXFIFO. + if(--rxfifo_len == 0) + setFIFO(false); + + // What if wrap cursor??? + if (rxfifo_read_pos >= 128) { + rxfifo_read_pos = 0; + } + // When is this set to "false" - when is interrupt de-triggered? + // TODO: + // -MT FIFOP is lowered when there are less than IOCFG0:FIFOP_THR bytes in the RXFIFO + // If FIFO_THR is greater than the frame length, FIFOP goes low when the first byte is read out. + if (rxPacket) { + rxPacket = false; + setFIFOP(false); + } + return; + case WRITE_TXFIFO: + if(txfifo_flush) { + txCursor = 0; + txfifo_flush = false; + } + if (DEBUG) System.out.println("Writing data: " + data + " to tx: " + txCursor); + + memory[RAM_TXFIFO + txCursor++] = data & 0xff; + break; + case RAM_ACCESS: + if (pos == 0) { + address = address | (data << 1) & 0x180; + ramRead = (data & 0x20) != 0; + if (DEBUG) { + System.out.println("CC2420: Address: " + Utils.hex16(address) + + " read: " + ramRead); + } + pos++; + } else { + if (!ramRead) { + memory[address++] = data; + if (DEBUG && address == RAM_PANID + 2) { + System.out.println("CC2420: Pan ID set to: 0x" + + Utils.hex8(memory[RAM_PANID]) + + Utils.hex8(memory[RAM_PANID + 1])); + } + }else{ + //System.out.println("Read RAM Addr: " + address + " Data: " + memory[address]); + source.byteReceived(memory[address++]); + return; + } + } + break; + } + + source.byteReceived(status); + } + } + + // Needs to get information about when it is possible to write + // next data... + private void strobe(int data) { + // Resets, on/off of different things... + //if (DEBUG) { + // System.out.println("CC2420: Strobe on: " + Utils.hex8(data)); + //} + + if( (stateMachine == STATE_POWER_DOWN) && (data != REG_SXOSCON) ) { + if (DEBUG) System.out.println("CC2420: Got command strobe: " + data + " in STATE_POWER_DOWN. Ignoring."); + return; + } + + switch (data) { + case REG_SNOP: + //System.out.println("CC2420: SNOP"); + break; + case REG_SRXON: + if(stateMachine == STATE_IDLE) { + setState(STATE_RX_CALIBRATE); + //updateActiveFrequency(); + //if (DEBUG) { + // System.out.println("CC2420: Strobe RX-ON!!!"); + //} + //setMode(MODE_RX_ON); + }else{ + System.out.println("CC2420: WARNING: SRXON when not IDLE"); + } + + break; + case REG_SRFOFF: + if (DEBUG) { + System.out.println("CC2420: Strobe RXTX-OFF!!!"); + } + setState(STATE_IDLE); + + setMode(MODE_TXRX_OFF); + break; + case REG_STXON: + // State transition valid from IDLE state or all RX states + if( (stateMachine == STATE_IDLE) || + (stateMachine == STATE_RX_CALIBRATE) || + (stateMachine == STATE_RX_SFD_SEARCH) || + (stateMachine == STATE_RX_FRAME) || + (stateMachine == STATE_RX_OVERFLOW) || + (stateMachine == STATE_RX_WAIT)) { + status |= STATUS_TX_ACTIVE; + setState(STATE_TX_CALIBRATE); + } + break; + case REG_STXONCCA: + // Only valid from all RX states, + // since CCA requires ??(look this up) receive symbol periods to be valid + if( (stateMachine == STATE_RX_CALIBRATE) || + (stateMachine == STATE_RX_SFD_SEARCH) || + (stateMachine == STATE_RX_FRAME) || + (stateMachine == STATE_RX_OVERFLOW) || + (stateMachine == STATE_RX_WAIT)) { + if(cca) { + status |= STATUS_TX_ACTIVE; + setState(STATE_TX_CALIBRATE); + }else{ + System.out.println("CC2420: STXONCCA Ignored, CCA false"); + } + } + break; + case REG_SFLUSHRX: + flushRX(); + break; + case REG_SFLUSHTX: + System.out.println("CC2420: Flushing TXFIFO"); + flushTX(); + break; + case REG_SXOSCON: + //System.out.println("CC2420: Strobe Oscillator On"); + startOscillator(); + break; + case REG_SXOSCOFF: + //System.out.println("CC2420: Strobe Oscillator Off"); + stopOscillator(); + break; + default: + if (DEBUG) { + System.out.println("Unknown strobe command: " + data); + } + break; + } + } + + public void updateActiveFrequency() { + /* INVERTED: f = 5 * (c - 11) + 357 + 0x4000 */ + activeFrequency = registers[REG_FSCTRL] - 357 + 2405 - 0x4000; + activeChannel = (registers[REG_FSCTRL] - 357 - 0x4000)/5 + 11; + } + + public int getActiveFrequency() { + return activeFrequency; + } + + public int getActiveChannel() { + return activeChannel; + } + + public int getOutputPowerIndicator() { + return (registers[REG_TXCTRL] & 0x1f); + } + + private static int RSSI_OFFSET = -45; /* cc2420 datasheet */ + + public void setRSSI(int power) { + if (power < -128) { + power = -128; + } + registers[REG_RSSI] = power - RSSI_OFFSET; + } + + public int getRSSI() { + return registers[REG_RSSI] + RSSI_OFFSET; + } + + public int getOutputPower() { + /* From CC2420 datasheet */ + int indicator = getOutputPowerIndicator(); + if (indicator >= 31) { + return 0; + } else if (indicator >= 27) { + return -1; + } else if (indicator >= 23) { + return -3; + } else if (indicator >= 19) { + return -5; + } else if (indicator >= 15) { + return -7; + } else if (indicator >= 11) { + return -10; + } else if (indicator >= 7) { + return -15; + } else if (indicator >= 3) { + return -25; + } + + /* Unknown */ + return -100; + } + + private void shrNext() { + listener.receivedByte(SHR[shr_pos++]); + if(shr_pos == 5) { + // Set SFD high + setSFD(true); + setState(STATE_TX_FRAME); + }else{ + cpu.scheduleTimeEventMillis(shrEvent, SYMBOL_PERIOD * 2); + } + } + + private void txNext() { + listener.receivedByte((byte)(memory[RAM_TXFIFO + txfifo_pos++] & 0xFF)); + if(txfifo_pos <= memory[RAM_TXFIFO]) { + // Two symbol periods to send a byte.. + cpu.scheduleTimeEventMillis(sendEvent, SYMBOL_PERIOD * 2); + } else { + System.out.println("Completed Transmission."); + status &= ~STATUS_TX_ACTIVE; + setSFD(false); + setState(STATE_RX_CALIBRATE); + txfifo_flush = true; + } + } + + private void setSymbolEvent(int symbols) { + double period = SYMBOL_PERIOD * symbols; + cpu.scheduleTimeEventMillis(symbolEvent, period); + //System.out.println("Set Symbol event: " + period); + } + + private void startOscillator() { + // 1ms crystal startup from datasheet pg12 + cpu.scheduleTimeEventMillis(oscillatorEvent, 1); + } + + private void stopOscillator() { + status &= ~STATUS_XOSC16M_STABLE; + setState(STATE_POWER_DOWN); + + if (DEBUG) System.out.println("CC2420: Oscillator Off."); + setMode(MODE_POWER_OFF); + // Reset state + rxPacket = false; + setFIFOP(false); + } + + public void setRFListener(RFListener rf) { + listener = rf; + } + + public void setVRegOn(boolean on) { + if(this.on == on) return; + + if(on) { + // 0.6ms maximum vreg startup from datasheet pg 13 + cpu.scheduleTimeEventMillis(vregEvent, 0.1); + }else{ + this.on = on; + setState(STATE_VREG_OFF); + } + //this.on = on; + } + + public void setChipSelect(boolean select) { + chipSelect = select; + if (!chipSelect) { + state = WAITING; + } + + //if (DEBUG) { + // System.out.println("CC2420: setting 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; + } + + public void setSFDPort(IOPort port, int pin) { + sfdPort = port; + sfdPin = pin; + } + + + // ------------------------------------------------------------------- + // Methods for accessing and writing to registers, etc from outside + // And for receiveing data + // ------------------------------------------------------------------- + + public int getRegister(int register) { + return registers[register]; + } + + public void setRegister(int register, int data) { + registers[register] = data; + } + + private void flushRX() { + if (DEBUG) { + System.out.println("CC2420: Flushing RX len = " + rxfifo_len); + } + rxPacket = false; + rxfifo_read_pos = 0; + rxfifo_write_pos = 0; + rxfifo_len = 0; + setClear(true); + setSFD(false); + setFIFOP(false); + } + + // TODO: update any pins here? + private void flushTX() { + txCursor = 0; + } + + // For incoming packets... - mostly for backward compatibility... + public void setIncomingPacket(byte[] receivedData) { + for (byte element: receivedData) { + receivedByte((byte)(element & 0xff)); + } + } + + + public void setClear(boolean clear) { + cca = clear; + setCCA(clear); + System.out.println("CC2420: CCA: " + clear); + } + + public void setSFD(boolean sfd) { + System.out.println("SFD: " + sfd); + sfdPort.setPinState(sfdPin, sfd ? 1 : 0); + } + + public void setCCA(boolean cca) { + if( (registers[REG_IOCFG0] & CCA_POLARITY) == CCA_POLARITY) + ccaPort.setPinState(ccaPin, cca ? 0 : 1); + else + ccaPort.setPinState(ccaPin, cca ? 1 : 0); + } + + public void setFIFOP(boolean fifop) { + fifopState = fifop; + if( (registers[REG_IOCFG0] & FIFOP_POLARITY) == FIFOP_POLARITY) { + fifopPort.setPinState(fifopPin, fifop ? 0 : 1); + } else { + fifopPort.setPinState(fifopPin, fifop ? 1 : 0); + } + } + + public void setFIFO(boolean fifo) { + fifoPort.setPinState(fifoPin, fifo ? 1 : 0); + } + + public void setRxOverflow() { + if (DEBUG) System.out.println("CC2420: RXFIFO Overflow! Read Pos: " + rxfifo_read_pos + " Write Pos: " + rxfifo_write_pos); + setFIFOP(true); + setFIFO(false); + } + + public String getName() { + return "CC2420"; + } + + public int getModeMax() { + return MODE_MAX; + } + +} // CC2420 Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-09-06 20:03:45 UTC (rev 303) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-09-06 20:04:45 UTC (rev 304) @@ -46,6 +46,7 @@ import se.sics.mspsim.chip.M25P80; import se.sics.mspsim.chip.FileM25P80; import se.sics.mspsim.chip.PacketListener; +import se.sics.mspsim.chip.RFListener; import se.sics.mspsim.core.IOPort; import se.sics.mspsim.core.IOUnit; import se.sics.mspsim.core.MSP430; @@ -237,16 +238,6 @@ stats.addMonitor(radio); stats.addMonitor(cpu); -// 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); - - network = new NetworkConnection(); network.addPacketListener(new PacketListener() { public void transmissionEnded(byte[] receivedData) { @@ -256,14 +247,28 @@ } }); // TODO: remove this test... - radio.setPacketListener(new PacketListener() { - public void transmissionEnded(byte[] receivedData) { -// System.out.println(getName() + " got packet from radio " + SkyNode.this.cpu.getTimeMillis()); - network.dataSent(receivedData); + radio.setRFListener(new RFListener() { + int len = 0; + int pos = 0; + byte[] buffer = new byte[128]; + // NOTE: len is not in the packet for now... + public void receivedByte(byte data) { +// System.out.println("*** RF Data :" + data); + if (pos == 5) { +// System.out.println("**** Setting length to:" + data); + len = data; + } + buffer[pos++] = data; + // len + 1 = pos + 5 (preambles) + if (len > 0 && len + 1 == pos - 5) { +// System.out.println("***** SENDING DATA!!!"); + byte[] packet = new byte[len]; + System.arraycopy(buffer, 5, packet, 0, len); + network.dataSent(packet); + pos = 0; + len = 0; + } } - public void transmissionStarted() { -// System.out.println(getName() + " got indication on transmission from radio " + SkyNode.this.cpu.getTimeMillis()); - } }); // UART0 TXreg = 0x77? This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-09-06 20:03:47
|
Revision: 303 http://mspsim.svn.sourceforge.net/mspsim/?rev=303&view=rev Author: joxe Date: 2008-09-06 20:03:45 +0000 (Sat, 06 Sep 2008) Log Message: ----------- added ext memory / flash chip Added Paths: ----------- mspsim/se/sics/mspsim/chip/FileAT45DB.java Added: mspsim/se/sics/mspsim/chip/FileAT45DB.java =================================================================== --- mspsim/se/sics/mspsim/chip/FileAT45DB.java (rev 0) +++ mspsim/se/sics/mspsim/chip/FileAT45DB.java 2008-09-06 20:03:45 UTC (rev 303) @@ -0,0 +1,143 @@ +/** + * 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: $ + * + * ----------------------------------------------------------------- + * + * FileAT45DB - File based implementation of external flash. + * + * Author : Joakim Eriksson, Fredrik Osterlind + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2008-05-12 18:10:17 +0000 (Mon, 12 May 2008) $ + * $Revision: 280 $ + */ + +package se.sics.mspsim.chip; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import se.sics.mspsim.core.MSP430Core; + +public class FileAT45DB extends AT45DB { + + private static final boolean DEBUG = true; + + // PAGE_SIZE and NUM_PAGES defined in AT45DB + private static final int FLASH_SIZE = PAGE_SIZE * NUM_PAGES; + + private RandomAccessFile file; + private FileChannel fileChannel; + private FileLock fileLock; + + public FileAT45DB(MSP430Core cpu, String filename) { + super(cpu); + if (filename == null) { + filename = "flash.bin"; + } + + // Open flash file for R/W + if (!openFile(filename)) { + // Failed to open/lock the specified file. Add a counter and try with next filename. + Matcher m = Pattern.compile("(.+?)(\\d*)(\\.[^.]+)").matcher(filename); + if (m.matches()) { + String baseName = m.group(1); + String c = m.group(2); + String extName = m.group(3); + int count = 1; + if (c != null && c.length() > 0) { + count = Integer.parseInt(c) + 1; + } + for (int i = 0; !openFile(baseName + count + extName) && i < 100; i++, count++); + } + } + if (fileLock == null) { + // Failed to open flash file + throw new IllegalStateException("failed to open flash file '" + filename + '\''); + } + // Set size of flash + try { + file.setLength(FLASH_SIZE); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private boolean openFile(String filename) { + // Open flash file for R/W + try { + file = new RandomAccessFile(filename, "rw"); + fileChannel = file.getChannel(); + fileLock = fileChannel.tryLock(); + if (fileLock != null) { + // The file is now locked for use + if (DEBUG) System.out.println("FileAT45DB: using flash file '" + filename + '\''); + return true; + } else { + fileChannel.close(); + return false; + } + } catch (IOException e) { + e.printStackTrace(); + closeFile(); + return false; + } + } + + private void closeFile() { + try { + if (fileLock != null) { + fileLock.release(); + fileLock = null; + } + if (fileChannel != null) { + fileChannel.close(); + fileChannel = null; + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void seek(long pos) throws IOException { + file.seek(pos); + } + + public int read(byte[] b) throws IOException { + return file.read(b); + } + + public void write(byte[] b) throws IOException { + file.write(b); + } + +} // FileAT45DB This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-09-06 20:03:24
|
Revision: 302 http://mspsim.svn.sourceforge.net/mspsim/?rev=302&view=rev Author: joxe Date: 2008-09-06 20:03:22 +0000 (Sat, 06 Sep 2008) Log Message: ----------- added ext memory / flash chip Added Paths: ----------- mspsim/se/sics/mspsim/chip/AT45DB.java Added: mspsim/se/sics/mspsim/chip/AT45DB.java =================================================================== --- mspsim/se/sics/mspsim/chip/AT45DB.java (rev 0) +++ mspsim/se/sics/mspsim/chip/AT45DB.java 2008-09-06 20:03:22 UTC (rev 302) @@ -0,0 +1,373 @@ +/** + * 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: $ + * + * ----------------------------------------------------------------- + * + * AT45DB SPI Flash Simulator + * + * Author : Matt Thompson <mat...@lo...> + * Created : Fri May 30 2008 + * Updated : $Date: $ + * $Revision: $ + */ + +package se.sics.mspsim.chip; +import java.io.IOException; +import se.sics.mspsim.core.*; + +public abstract class AT45DB extends Chip implements USARTListener { + + public static final boolean DEBUG = false; + + public static final int PAGE_SIZE = 264; + public static final int NUM_PAGES = 2048; + public static final int SIZE_BYTES = PAGE_SIZE * NUM_PAGES; + + /** Read Commands - Datasheet Table 15-1 */ + public static final int PAGE_READ = 0xD2; + public static final int CONTINUOUS_ARRAY_READ_LEGACY = 0xE8; + public static final int CONTINUOUS_ARRAY_READ_HF = 0x0B; // 66MHz + public static final int CONTINUOUS_ARRAY_READ_LF = 0x03; // 33MHz + public static final int BUFFER1_READ_LF = 0xD1; + public static final int BUFFER2_READ_LF = 0xD3; + public static final int BUFFER1_READ = 0xD4; + public static final int BUFFER2_READ = 0xD6; + + /** Program and Erase Commands - Datasheet Table 15-2 */ + public static final int BUFFER1_WRITE = 0x84; + public static final int BUFFER2_WRITE = 0x87; + public static final int BUFFER1_TO_PAGE_ERASE = 0x83; + public static final int BUFFER2_TO_PAGE_ERASE = 0x86; + public static final int BUFFER1_TO_PAGE = 0x88; + public static final int BUFFER2_TO_PAGE = 0x89; + public static final int PAGE_ERASE = 0x81; + public static final int BLOCK_ERASE = 0x50; + public static final int SECTOR_ERASE = 0x7C; + // These chip erases opcodes are synonymous + public static final int CHIP_ERASE = 0xC7; + public static final int CHIP_ERASE1 = 0x94; + public static final int CHIP_ERASE2 = 0x80; + public static final int CHIP_ERASE3 = 0x9A; + public static final int PAGE_PROGRAM_THROUGH_BUFFER1 = 0x82; + public static final int PAGE_PROGRAM_THROUGH_BUFFER2 = 0x85; + /** End of Program and Erase Command opcodes */ + + /** Protection and Security Commands - Datasheet Table 15-3 */ + /** Additional Commands - Datasheet Table 15-4 */ + public static final int PAGE_TO_BUFFER1 = 0x53; + public static final int PAGE_TO_BUFFER2 = 0x55; + public static final int PAGE_TO_BUFFER1_COMPARE = 0x60; + public static final int PAGE_TO_BUFFER2_COMPARE = 0x61; + public static final int AUTO_PAGE_REWRITE_BUFFER1 = 0x58; + public static final int AUTO_PAGE_REWRITE_BUFFER2 = 0x59; + public static final int DEEP_POWER_DOWN = 0xB9; + public static final int RESUME_DEEP_POWER_DOWN = 0xAB; + public static final int STATUS_REGISTER_READ = 0xD7; + public static final int READ_DEVICE_ID = 0x9F; + /** Legacy Commands - Datasheet Table 15-5 */ + + // Status register bitmasks + public static final int STATUS_RDY = (1<<7); + public static final int STATUS_COMP = (1<<6); + public static final int STATUS_DENSITY = 0x3C; + public static final int STATUS_PROTECT = (1<<1); + public static final int STATUS_PAGE_SIZE = 1; + + + private static final int STATE_RESET = 0; + private static final int STATE_IDLE = 1; + private static final int READ_ADDRESS = 2; + private int state = STATE_RESET; + private int next_state = STATE_RESET; + + + private boolean Reset; // Reset Pin + private boolean chipSelect; // CS Pin + + private int pos; + + // AT45 Status Register byte + private int status = 0x1C | STATUS_RDY; // AT45DB041 has bits 5-2 set to 0111 - density bits + + private int pageAddress; + private int bufferAddress; + private int dummy=0; // Number of dummy bytes following command + + + + // AT45 has two page sized RAM buffers + private byte[] buffer1 = new byte[PAGE_SIZE]; + private byte[] buffer2 = new byte[PAGE_SIZE]; + + private TimeEvent writeEvent = new TimeEvent(0) { + public void execute(long t) { + setReady(true); + }}; + + private MSP430Core cpu; + + public AT45DB(MSP430Core cpu) { + this.cpu = cpu; + } + + private void setReady(boolean ready) { + if(ready == true) + status |= STATUS_RDY; + else + status &= ~STATUS_RDY; + } + + public void dataReceived(USART source, int data) { + int buf_num = 1; + + if (chipSelect) { + //if (DEBUG) { + // System.out.println("AT45DB: byte received: " + data); + //} + + switch(state) { + + case READ_ADDRESS: + pos++; + if(pos == 1) { + pageAddress = ((data & 0xF) << 7); + }else if (pos == 2) { + pageAddress |= ((data & 0xFE) >> 1); + bufferAddress = ((data & 1) << 9); + }else if (pos == 3) { + bufferAddress |= data; + + if(DEBUG) + System.out.println("AT45DB: Address - PA[10-0]: " + pageAddress + " BA[8-0]: " + bufferAddress); + + if(dummy == 0) { + if(DEBUG) System.out.println("AT45DB: State " + state + " -> " + next_state); + state = next_state; + } + }else{ + if(--dummy == 0) { + if(DEBUG) System.out.println("AT45DB: State " + state + " -> " + next_state); + state = next_state; + } + } + source.byteReceived(0); + break; + + case BUFFER1_READ: + case BUFFER2_READ: + // Return bytes from the RAM buffer + buf_num = (state == BUFFER1_READ ? 1 : 2); + source.byteReceived(readBuffer(buf_num, bufferAddress++)); + if(bufferAddress >= PAGE_SIZE) + System.out.println("AT45DB: ERROR: Buffer Read past buffer size: " + bufferAddress); + break; + + case BUFFER1_WRITE: + case BUFFER2_WRITE: + buf_num = (state == BUFFER1_WRITE ? 1 : 2); + writeBuffer(buf_num, bufferAddress++, data); + if(bufferAddress >= PAGE_SIZE) + System.out.println("AT45DB: ERROR: Buffer Write past buffer size: " + bufferAddress); + source.byteReceived(0); + break; + + case STATUS_REGISTER_READ: + // Chip select false will transition state, as the status register can be + // polled by clocking data on SI until CS is false + source.byteReceived(status); + break; + + case STATE_RESET: + case STATE_IDLE: + // data is a command byte + switch(data) { + + case BUFFER1_TO_PAGE_ERASE: + case BUFFER2_TO_PAGE_ERASE: + if(DEBUG) + System.out.println("AT45DB: Buffer" + (data == BUFFER1_TO_PAGE_ERASE ? "1" : "2") + " to Page with Erase Command"); + pos = 0; + state = READ_ADDRESS; + next_state = data; + dummy = 0; + setReady(false); + source.byteReceived(0); + break; + + case BUFFER1_READ: + case BUFFER2_READ: + if(DEBUG) + System.out.println("AT45DB: Read Buffer Command " + (data == BUFFER1_READ ? "Buffer1" : "Buffer2")); + pos = 0; + state = READ_ADDRESS; + next_state = data; + dummy = 1; + setReady(false); + source.byteReceived(0); + break; + + case BUFFER1_WRITE: + case BUFFER2_WRITE: + if(DEBUG) + System.out.println("AT45DB: Write Buffer Command " + (data == BUFFER1_WRITE ? "Buffer1" : "Buffer2")); + pos = 0; + state = READ_ADDRESS; + next_state = data; + dummy = 0; + setReady(false); + source.byteReceived(0); + break; + + case PAGE_TO_BUFFER1: + case PAGE_TO_BUFFER2: + if(DEBUG) + System.out.println("AT45DB: Page To Buffer " + (data == PAGE_TO_BUFFER1 ? "1" : "2") + " Command"); + pos = 0; + state = READ_ADDRESS; + next_state = data; + dummy = 0; + setReady(false); + source.byteReceived(0); + break; + + case STATUS_REGISTER_READ: + if(DEBUG) System.out.println("AT45DB: Read status register command. status: " + status); + state = STATUS_REGISTER_READ; + source.byteReceived(0); + break; + default: + System.out.println("AT45DB: WARNING: Command not implemented: " + data); + source.byteReceived(0); + break; + } + break; + default: + source.byteReceived(0); + break; + } + } + } + + private int readBuffer(int num, int address) { + //if(DEBUG) { + // System.out.println("AT45DB: Reading RAM Buffer" + num + " Address: " + Integer.toHexString(address)); + //} + if(num == 1) + return buffer1[address & 0x1ff]; + else + return buffer2[address & 0x1ff]; + } + + private void writeBuffer(int num, int address, int data) { + //if(DEBUG) { + // System.out.println("AT45DB: Writing RAM Buffer" + num + " Address: " + Integer.toHexString(address) + " Data: " + data); + //} + if(num == 1) + buffer1[address & 0x1ff] = (byte)data; + else + buffer2[address & 0x1ff] = (byte)data; + } + + public void setReset(boolean reset) { + Reset = reset; + if(Reset == true) + state = STATE_RESET; + if(DEBUG) { + System.out.println("AT45DB: Reset: " + Reset); + } + } + public void setChipSelect(boolean select) { + chipSelect = select; + if(chipSelect == false) { + switch(state) { + + case BUFFER1_TO_PAGE_ERASE: + case BUFFER2_TO_PAGE_ERASE: + bufferToPage((state == BUFFER1_TO_PAGE_ERASE ? 1 : 2)); + setReady(true); + break; + + case PAGE_TO_BUFFER1: + case PAGE_TO_BUFFER2: + pageToBuffer((state == PAGE_TO_BUFFER1 ? 1 : 2)); + setReady(true); + break; + + default: + setReady(true); + break; + } + + state = STATE_IDLE; + } + + if(DEBUG) { + System.out.println("AT45DB: Chip Select: " + chipSelect); + } + } + + private void bufferToPage(int buf) { + try { + seek(pageAddress * PAGE_SIZE); + if(buf == 1) + write(buffer1); + else + write(buffer2); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void pageToBuffer(int buf) { + try { + seek(pageAddress * PAGE_SIZE); + if(buf == 1) + read(buffer1); + else + read(buffer2); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public int getModeMax() { + return 0; + } + + public String getName() { + return "AT45DB: external flash"; + } + + public abstract void seek(long pos) throws IOException; + public abstract int read(byte[] b) throws IOException; + public abstract void write(byte[] b) throws IOException; + +} // AT45DB This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-09-04 21:31:55
|
Revision: 301 http://mspsim.svn.sourceforge.net/mspsim/?rev=301&view=rev Author: joxe Date: 2008-09-04 21:31:52 +0000 (Thu, 04 Sep 2008) Log Message: ----------- added more to changelog Modified Paths: -------------- mspsim/CHANGE_LOG.txt Modified: mspsim/CHANGE_LOG.txt =================================================================== --- mspsim/CHANGE_LOG.txt 2008-09-04 21:25:34 UTC (rev 300) +++ mspsim/CHANGE_LOG.txt 2008-09-04 21:31:52 UTC (rev 301) @@ -4,10 +4,11 @@ - fixed bug which caused array out of bounds on IO-units. - fixed bug in timer causing interrupts when timer was stopped - fixed bug in timer to handle start/stop better -- fixed bug in MSP430 core that caused MOV operand to change status flags +- fixed bug in MSP430 core that caused MOV instruction to change status flags - added getDoubleValue in DataSource and made "duty" command print duty cycle information as double instead of int - fixed windows to accept double input and not only int input +- corrected cycle count on some instructions 0.91 Changes: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-09-04 21:25:39
|
Revision: 300 http://mspsim.svn.sourceforge.net/mspsim/?rev=300&view=rev Author: joxe Date: 2008-09-04 21:25:34 +0000 (Thu, 04 Sep 2008) Log Message: ----------- updated version number and added info in CHANGELOG to prepare for release of 0.92 Modified Paths: -------------- mspsim/CHANGE_LOG.txt mspsim/se/sics/mspsim/core/MSP430Constants.java Modified: mspsim/CHANGE_LOG.txt =================================================================== --- mspsim/CHANGE_LOG.txt 2008-09-04 19:11:51 UTC (rev 299) +++ mspsim/CHANGE_LOG.txt 2008-09-04 21:25:34 UTC (rev 300) @@ -2,6 +2,12 @@ Changes: - fixed bug with a write register which did not handle word/byte - fixed bug which caused array out of bounds on IO-units. +- fixed bug in timer causing interrupts when timer was stopped +- fixed bug in timer to handle start/stop better +- fixed bug in MSP430 core that caused MOV operand to change status flags +- added getDoubleValue in DataSource and made "duty" command print + duty cycle information as double instead of int +- fixed windows to accept double input and not only int input 0.91 Changes: Modified: mspsim/se/sics/mspsim/core/MSP430Constants.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Constants.java 2008-09-04 19:11:51 UTC (rev 299) +++ mspsim/se/sics/mspsim/core/MSP430Constants.java 2008-09-04 21:25:34 UTC (rev 300) @@ -43,7 +43,7 @@ public interface MSP430Constants { - public static final String VERSION = "0.91"; + public static final String VERSION = "0.92"; public static final int RESET_PUC = 0; public static final int RESET_POR = 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-09-04 19:11:55
|
Revision: 299 http://mspsim.svn.sourceforge.net/mspsim/?rev=299&view=rev Author: joxe Date: 2008-09-04 19:11:51 +0000 (Thu, 04 Sep 2008) Log Message: ----------- added getDoubleValue to data source and fixed windows to handle double values Modified Paths: -------------- mspsim/se/sics/mspsim/cli/AbstractWindowDataHandler.java mspsim/se/sics/mspsim/core/Timer.java mspsim/se/sics/mspsim/extutil/jfreechart/LineChart.java mspsim/se/sics/mspsim/extutil/jfreechart/LineSampleChart.java mspsim/se/sics/mspsim/platform/GenericNode.java mspsim/se/sics/mspsim/util/DataSource.java mspsim/se/sics/mspsim/util/MultiDataSource.java mspsim/se/sics/mspsim/util/OperatingModeStatistics.java mspsim/se/sics/mspsim/util/StackMonitor.java mspsim/se/sics/mspsim/util/StatCommands.java Modified: mspsim/se/sics/mspsim/cli/AbstractWindowDataHandler.java =================================================================== --- mspsim/se/sics/mspsim/cli/AbstractWindowDataHandler.java 2008-09-04 14:30:47 UTC (rev 298) +++ mspsim/se/sics/mspsim/cli/AbstractWindowDataHandler.java 2008-09-04 19:11:51 UTC (rev 299) @@ -60,7 +60,7 @@ public abstract void setProperty(int index, String param, String[] args); - public int atoi(String data, int defaultValue) { + public static int atoi(String data, int defaultValue) { try { return Integer.parseInt(data); } catch (NumberFormatException e) { @@ -68,4 +68,11 @@ } } + public static double atod(String data, double defaultValue) { + try { + return Double.parseDouble(data); + } catch (NumberFormatException e) { + return defaultValue; + } + } } Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2008-09-04 14:30:47 UTC (rev 298) +++ mspsim/se/sics/mspsim/core/Timer.java 2008-09-04 19:11:51 UTC (rev 299) @@ -610,9 +610,6 @@ } } -// System.out.println("UpdateCounter: C1: " + counter + " C2:" + ctr); - - if (DEBUG) { System.out.println(getName() + ": Updating counter cycctr: " + cycctr + " divider: " + divider + " mode:" + mode + " => " + counter); } Modified: mspsim/se/sics/mspsim/extutil/jfreechart/LineChart.java =================================================================== --- mspsim/se/sics/mspsim/extutil/jfreechart/LineChart.java 2008-09-04 14:30:47 UTC (rev 298) +++ mspsim/se/sics/mspsim/extutil/jfreechart/LineChart.java 2008-09-04 19:11:51 UTC (rev 299) @@ -126,7 +126,7 @@ addSeries(); } for (int i = 0; i < parts.length; i++) { - dataset.getSeries(i).add(point, atoi(parts[i], 0)); + dataset.getSeries(i).add(point, atod(parts[i], 0)); } point++; panel.repaint(); Modified: mspsim/se/sics/mspsim/extutil/jfreechart/LineSampleChart.java =================================================================== --- mspsim/se/sics/mspsim/extutil/jfreechart/LineSampleChart.java 2008-09-04 14:30:47 UTC (rev 298) +++ mspsim/se/sics/mspsim/extutil/jfreechart/LineSampleChart.java 2008-09-04 19:11:51 UTC (rev 299) @@ -64,7 +64,7 @@ String parts[] = line.trim().split(" "); dataSeries.clear(); for (int i = 0; i < parts.length; i++) { - dataSeries.add(i, atoi(parts[i], 0)); + dataSeries.add(i, atod(parts[i], 0)); } panel.repaint(); } Modified: mspsim/se/sics/mspsim/platform/GenericNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/GenericNode.java 2008-09-04 14:30:47 UTC (rev 298) +++ mspsim/se/sics/mspsim/platform/GenericNode.java 2008-09-04 19:11:51 UTC (rev 299) @@ -103,13 +103,7 @@ IHexReader reader = new IHexReader(); reader.readFile(memory, firmwareFile = args[0]); } else { - elf = ELF.readELF(firmwareFile = args[0]); - elf.loadPrograms(memory); - MapTable map = elf.getMap(); - cpu.getDisAsm().setMap(map); - cpu.setMap(map); - registry.registerComponent("elf", elf); - registry.registerComponent("mapTable", map); + loadFirmware(args[0], memory); } cpu.reset(); @@ -160,6 +154,17 @@ } } + public void loadFirmware(String name, int[] memory) throws IOException { + stop(); + elf = ELF.readELF(firmwareFile = name); + elf.loadPrograms(memory); + MapTable map = elf.getMap(); + cpu.getDisAsm().setMap(map); + cpu.setMap(map); + registry.registerComponent("elf", elf); + registry.registerComponent("mapTable", map); + } + // A step that will break out of breakpoints! public void step(int nr) { if (!cpu.isRunning()) { Modified: mspsim/se/sics/mspsim/util/DataSource.java =================================================================== --- mspsim/se/sics/mspsim/util/DataSource.java 2008-09-04 14:30:47 UTC (rev 298) +++ mspsim/se/sics/mspsim/util/DataSource.java 2008-09-04 19:11:51 UTC (rev 299) @@ -39,5 +39,6 @@ package se.sics.mspsim.util; public interface DataSource { + public double getDoubleValue(); public int getValue(); } Modified: mspsim/se/sics/mspsim/util/MultiDataSource.java =================================================================== --- mspsim/se/sics/mspsim/util/MultiDataSource.java 2008-09-04 14:30:47 UTC (rev 298) +++ mspsim/se/sics/mspsim/util/MultiDataSource.java 2008-09-04 19:11:51 UTC (rev 299) @@ -44,6 +44,7 @@ public int getModeMax(); + public double getDoubleValue(int mode); public int getValue(int mode); } Modified: mspsim/se/sics/mspsim/util/OperatingModeStatistics.java =================================================================== --- mspsim/se/sics/mspsim/util/OperatingModeStatistics.java 2008-09-04 14:30:47 UTC (rev 298) +++ mspsim/se/sics/mspsim/util/OperatingModeStatistics.java 2008-09-04 19:11:51 UTC (rev 299) @@ -137,7 +137,7 @@ } // returns percentage since last call... - public int getValue() { + public double getDoubleValue() { long diff = cpu.cycles - lastCycles; if (diff == 0) return 0; long val = entry.getValue(mode, cpu.cycles); @@ -147,8 +147,12 @@ if (operation == OP_INVERT) { return (int) (100 - 100 * valDiff / diff); } - return (int) (100 * valDiff / diff); + return (100.0 * valDiff / diff); } + + public int getValue() { + return (int) getDoubleValue(); + } } private class StatMultiDataSource implements MultiDataSource { @@ -171,6 +175,10 @@ // returns percentage since last call... public int getValue(int mode) { + return (int) getDoubleValue(mode); + } + + public double getDoubleValue(int mode) { long diff = cpu.cycles - lastCycles[mode]; if (diff == 0) return 0; @@ -178,7 +186,7 @@ long valDiff = (val - lastValue[mode]); lastValue[mode] = val; lastCycles[mode] = cpu.cycles; - return (int) (100 * valDiff / diff); + return (100.0 * valDiff / diff); } } Modified: mspsim/se/sics/mspsim/util/StackMonitor.java =================================================================== --- mspsim/se/sics/mspsim/util/StackMonitor.java 2008-09-04 14:30:47 UTC (rev 298) +++ mspsim/se/sics/mspsim/util/StackMonitor.java 2008-09-04 19:11:51 UTC (rev 299) @@ -20,6 +20,9 @@ stackMax = stack; return tmp; } + public double getDoubleValue() { + return getValue(); + } }; private DataSource minDataSource = new DataSource() { @@ -28,12 +31,18 @@ stackMin = stack; return tmp; } + public double getDoubleValue() { + return getValue(); + } }; private DataSource dataSource = new DataSource() { public int getValue() { return stack; } + public double getDoubleValue() { + return getValue(); + } }; public StackMonitor(MSP430 cpu) { Modified: mspsim/se/sics/mspsim/util/StatCommands.java =================================================================== --- mspsim/se/sics/mspsim/util/StatCommands.java 2008-09-04 14:30:47 UTC (rev 298) +++ mspsim/se/sics/mspsim/util/StatCommands.java 2008-09-04 19:11:51 UTC (rev 299) @@ -139,10 +139,10 @@ MultiDataSource ds = (MultiDataSource) s; for (int k = 0, m = ds.getModeMax(); k <= m; k++) { if (k > 0) out.print(' '); - out.print(ds.getValue(k)); + out.print(((int) (ds.getDoubleValue(k) * 100)) / 100.0); } } else { - out.print(((DataSource)s).getValue()); + out.print(((int)((DataSource)s).getDoubleValue() * 100) / 100.0); } } out.println(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2008-09-04 14:30:50
|
Revision: 298 http://mspsim.svn.sourceforge.net/mspsim/?rev=298&view=rev Author: nifi Date: 2008-09-04 14:30:47 +0000 (Thu, 04 Sep 2008) Log Message: ----------- fixed bug in mov instruction - removed status register update Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430Core.java Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2008-09-03 16:01:38 UTC (rev 297) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2008-09-04 14:30:47 UTC (rev 298) @@ -1073,9 +1073,10 @@ case MOV: // MOV dst = src; write = true; + updateStatus = false; break; // FIX THIS!!! - make SUB a separate operation so that - // it is clear that overflow flag is corretct... + // it is clear that overflow flag is correct... case SUB: // Carry always 1 with SUB tmpAdd = 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-09-03 16:01:45
|
Revision: 297 http://mspsim.svn.sourceforge.net/mspsim/?rev=297&view=rev Author: joxe Date: 2008-09-03 16:01:38 +0000 (Wed, 03 Sep 2008) Log Message: ----------- cleaned up timer code slightly Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430.java mspsim/se/sics/mspsim/core/Timer.java Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2008-08-29 22:09:45 UTC (rev 296) +++ mspsim/se/sics/mspsim/core/MSP430.java 2008-09-03 16:01:38 UTC (rev 297) @@ -280,9 +280,12 @@ } private void printCPUSpeed(int pc) { + // Passed time int td = (int)(System.currentTimeMillis() - time); - int cd = (int) (cycles - lastCycles); - int cpud = (int) (cpuCycles - lastCpuCycles); + // Passed total cycles + long cd = (cycles - lastCycles); + // Passed "active" CPU cycles + long cpud = (cpuCycles - lastCpuCycles); if (td == 0 || cd == 0) { return; @@ -295,7 +298,7 @@ + 1000 * (cpud / td ) + " cyc/s " + (10000 * cpud / cd)/100.0 + "%"); } - lastCPUPercent = (10000 * cpud / cd)/100.0; + lastCPUPercent = (10000 * cpud / cd) / 100.0; time = System.currentTimeMillis(); lastCycles = cycles; lastCpuCycles = cpuCycles; Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2008-08-29 22:09:45 UTC (rev 296) +++ mspsim/se/sics/mspsim/core/Timer.java 2008-09-03 16:01:38 UTC (rev 297) @@ -65,7 +65,7 @@ * * ___---___---___ * - * ==> Reads might be another problem. If a loop is just cheking the + * ==> Reads might be another problem. If a loop is just checking the * counter it will be reading same value for a long time. Needs to "capture" * reads to Timers by some simple means... */ @@ -134,9 +134,18 @@ // useful for setting expected compare and capture times to correct time. // valid for timer A private final int timerOverflow; - private long counterStart = 0; private long nextTimerTrigger = 0; + // this is used to create "tick" since last reset of the timer. + // it will contain the full number of ticks since that reset and + // is used to calculate the real counter value + private long counterStart = 0; + private long counterAcc; + + // Counter stores the current timer counter register (TR) + private int counter = 0; + private int counterPassed = 0; + // Input map for timer A public static final int[] TIMER_Ax149 = new int[] { SRC_PORT + 0x10, SRC_ACLK, SRC_SMCLK, SRC_PORT + 0x21, // Timer @@ -171,13 +180,6 @@ private int clockSource; private int mode; - - private int counter = 0; - private int counterPassed = 0; - // The value of the counter when something changed last time - // (change of divisor, or a start TAR different than 0 when timer - // starts, etc). - private int initialCounter = 0; // The IO registers private int tctl; @@ -263,7 +265,7 @@ counter = 0; counterPassed = 0; counterStart = 0; - initialCounter = 0; + counterAcc = 0; clockSource = 0; cyclesMultiplicator = 1; mode = STOP; @@ -387,8 +389,8 @@ if ((data & TCLR) != 0) { counter = 0; - counterStart = cycles; - // inputDivider = 1; ???? + resetCounter(cycles); + updateCaptures(-1, cycles); } @@ -396,8 +398,8 @@ if (mode == STOP && newMode != STOP) { // Set the initial counter to the value that counter should have after // recalculation - initialCounter = counter; - counterStart = cycles; + resetCounter(cycles); + // Wait until full wrap before setting the IRQ flag! nextTimerTrigger = (long) (cycles + cyclesMultiplicator * ((0xffff - counter) & 0xffff)); if (DEBUG) System.out.println(getName() + " Starting timer!"); @@ -469,6 +471,14 @@ case TCCR6: // update of compare register index = (iAddress - TCCR0) / 2; + if (index == 0) { + // Reset the counter to bring it down to a smaller value... + // Check if up or updwn and reset if counter too high... + if (counter > data && (mode == UPDWN || mode == UP)) { + counter = 0; + } + resetCounter(cycles); + } tccr[index] = data; updateCounter(cycles); @@ -500,10 +510,17 @@ calculateNextEventTime(cycles); } } + + private void resetCounter(long cycles) { + counterStart = cycles; + // set counterACC to the last returned value (which is the same + // as bigCounter except that it is "moduloed" to a smaller value + counterAcc = counter; + } private void setCounter(int newCtr, long cycles) { counter = newCtr; - counterStart = cycles; + resetCounter(cycles); } private void updateCaptures(int index, long cycles) { @@ -566,23 +583,36 @@ divider = 1.0 * core.smclkFrq / core.aclkFrq; } divider = divider * inputDivider; + + // These calculations assume that we have a big counter that counts from + // last reset and upwards (without any roundoff errors). + // tick - represent the counted value since last "reset" of some kind + // counterAcc - represent the value of the counter at the last reset. long cycctr = cycles - counterStart; double tick = cycctr / divider; counterPassed = (int) (divider * (tick - (long) (tick))); + long bigCounter = (long) (tick + counterAcc); + + //System.out.println("BigStart: " + bigCounterStart + " C:" + cycles + " bigCounter: " + bigCounter); + switch (mode) { case CONTIN: - counter = ((int) tick + initialCounter) & 0xffff; + counter = (int) (bigCounter & 0xffff); break; case UP: - counter = ((int) tick + initialCounter) % tccr[0]; + counter = (int) (bigCounter % tccr[0]); break; case UPDWN: - counter = ((int) tick + initialCounter) % (tccr[0] * 2); + counter = (int) (bigCounter % (tccr[0] * 2)); if (counter > tccr[0]) { // Should back down to start again! counter = 2 * tccr[0] - counter; } } + +// System.out.println("UpdateCounter: C1: " + counter + " C2:" + ctr); + + if (DEBUG) { System.out.println(getName() + ": Updating counter cycctr: " + cycctr + " divider: " + divider + " mode:" + mode + " => " + counter); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2008-08-29 22:09:47
|
Revision: 296 http://mspsim.svn.sourceforge.net/mspsim/?rev=296&view=rev Author: nifi Date: 2008-08-29 22:09:45 +0000 (Fri, 29 Aug 2008) Log Message: ----------- Added check that USART is ready before sending serial data Modified Paths: -------------- mspsim/se/sics/mspsim/ui/SerialMon.java Modified: mspsim/se/sics/mspsim/ui/SerialMon.java =================================================================== --- mspsim/se/sics/mspsim/ui/SerialMon.java 2008-08-29 22:05:55 UTC (rev 295) +++ mspsim/se/sics/mspsim/ui/SerialMon.java 2008-08-29 22:09:45 UTC (rev 296) @@ -135,17 +135,33 @@ public void keyTyped(KeyEvent key) { char c = key.getKeyChar(); - // Send it to the usart! - usart.byteReceived(c & 0xff); - // Visualize the input - if (c == '\n') { - statusLabel.setText(PREFIX); - keyBuffer = new StringBuilder(); - keyBuffer.append(PREFIX); + if(!usart.isReceiveFlagCleared()) { + try { + // Wait for at most 2 seconds before giving up + for (int i = 0, n = 20; !usart.isReceiveFlagCleared() && i < n; i++) { + Thread.sleep(100); + } + } catch (InterruptedException e) { + // Ignore + } + } + + // Send it to the usart if possible! + if (usart.isReceiveFlagCleared()) { + usart.byteReceived(c & 0xff); + + // Visualize the input + if (c == '\n') { + statusLabel.setText(PREFIX); + keyBuffer = new StringBuilder(); + keyBuffer.append(PREFIX); + } else { + keyBuffer.append(c); + statusLabel.setText(keyBuffer.toString()); + } } else { - keyBuffer.append(c); - statusLabel.setText(keyBuffer.toString()); + statusLabel.getToolkit().beep(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2008-08-29 22:05:58
|
Revision: 295 http://mspsim.svn.sourceforge.net/mspsim/?rev=295&view=rev Author: nifi Date: 2008-08-29 22:05:55 +0000 (Fri, 29 Aug 2008) Log Message: ----------- Fixed CLI to parse numerical arguments and addresses prefixed with '$','0x','#' as hexadecimal, '0' as octal, and '%' as binary Modified Paths: -------------- mspsim/se/sics/mspsim/cli/CommandContext.java mspsim/se/sics/mspsim/util/Utils.java Modified: mspsim/se/sics/mspsim/cli/CommandContext.java =================================================================== --- mspsim/se/sics/mspsim/cli/CommandContext.java 2008-08-29 21:58:33 UTC (rev 294) +++ mspsim/se/sics/mspsim/cli/CommandContext.java 2008-08-29 22:05:55 UTC (rev 295) @@ -3,6 +3,7 @@ import se.sics.mspsim.core.MSP430Constants; import se.sics.mspsim.util.MapTable; +import se.sics.mspsim.util.Utils; public class CommandContext { @@ -83,19 +84,13 @@ public int getArgumentAsAddress(int index) { String adr = getArgument(index); if (adr == null || adr.length() == 0) return 0; - adr = adr.trim(); - if (adr.charAt(0) == '$') { + char c = adr.charAt(0); + if (!Character.isLetter(c) && c != '_' && c != '.') { try { - return Integer.parseInt(adr.substring(1), 16); + return Utils.decodeInt(adr); } catch (Exception e) { - err.println("Illegal hex number format: " + adr); + err.println("Illegal address 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) { @@ -112,7 +107,7 @@ return i; } } - String reg = symbol.startsWith("R") ? symbol.substring(1) : symbol; + String reg = (symbol.startsWith("R") || symbol.startsWith("r")) ? symbol.substring(1) : symbol; try { int register = Integer.parseInt(reg); if (register >= 0 && register <= 15) { @@ -127,40 +122,56 @@ } public int getArgumentAsInt(int index) { + return getArgumentAsInt(index, 0); + } + + public int getArgumentAsInt(int index, int defaultValue) { try { - return Integer.parseInt(getArgument(index)); + return Utils.decodeInt(getArgument(index)); } catch (Exception e) { err.println("Illegal number format: " + getArgument(index)); + return defaultValue; } - return 0; } public long getArgumentAsLong(int index) { + return getArgumentAsLong(index, 0L); + } + + public long getArgumentAsLong(int index, long defaultValue) { try { - return Long.parseLong(getArgument(index)); + return Utils.decodeLong(getArgument(index)); } catch (Exception e) { err.println("Illegal number format: " + getArgument(index)); + return defaultValue; } - return 0L; } public float getArgumentAsFloat(int index) { + return getArgumentAsFloat(index, 0f); + } + + public float getArgumentAsFloat(int index, float defaultValue) { try { return Float.parseFloat(getArgument(index)); } catch (Exception e) { err.println("Illegal number format: " + getArgument(index)); + return defaultValue; } - return 0f; } public double getArgumentAsDouble(int index) { + return getArgumentAsDouble(index, 0.0); + } + + public double getArgumentAsDouble(int index, double defaultValue) { String arg = getArgument(index); try { return Double.parseDouble(arg); } catch (Exception e) { err.println("Illegal number format: " + getArgument(index)); + return defaultValue; } - return 0.0; } public int executeCommand(String command) { Modified: mspsim/se/sics/mspsim/util/Utils.java =================================================================== --- mspsim/se/sics/mspsim/util/Utils.java 2008-08-29 21:58:33 UTC (rev 294) +++ mspsim/se/sics/mspsim/util/Utils.java 2008-08-29 22:05:55 UTC (rev 295) @@ -108,6 +108,78 @@ return array; } + public static int decodeInt(String value) throws NumberFormatException { + int radix = 10; + int index = 0; + boolean negative = false; + if (value.startsWith("-")) { + index++; + negative = true; + } + + if (value.startsWith("$", index) || value.startsWith("#", index)) { + radix = 16; + index++; + } else if (value.startsWith("0x", index) || value.startsWith("0X", index)) { + radix = 16; + index += 2; + } else if (value.startsWith("0", index) && value.length() > index + 1) { + radix = 8; + index++; + } else if (value.startsWith("%", index)) { + radix = 2; + index++; + } + String intValue = value; + if (radix != 10) { + if (value.startsWith("-", index)) { + throw new NumberFormatException("unexpected negative sign: " + value); + } + if (negative) { + intValue = '-' + value.substring(index); + } else { + intValue = value.substring(index); + } + } + return Integer.parseInt(intValue, radix); + } + + public static long decodeLong(String value) throws NumberFormatException { + int radix = 10; + int index = 0; + boolean negative = false; + if (value.startsWith("-")) { + index++; + negative = true; + } + + if (value.startsWith("$", index) || value.startsWith("#", index)) { + radix = 16; + index++; + } else if (value.startsWith("0x", index) || value.startsWith("0X", index)) { + radix = 16; + index += 2; + } else if (value.startsWith("0", index) && value.length() > index + 1) { + radix = 8; + index++; + } else if (value.startsWith("%", index)) { + radix = 2; + index++; + } + String longValue = value; + if (radix != 10) { + if (value.startsWith("-", index)) { + throw new NumberFormatException("unexpected negative sign: " + value); + } + if (negative) { + longValue = '-' + value.substring(index); + } else { + longValue = value.substring(index); + } + } + return Long.parseLong(longValue, radix); + } + // public static void main(String[] args) { // System.out.println("Hex 47 = " + hex8(47)); // } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-08-29 21:58:35
|
Revision: 294 http://mspsim.svn.sourceforge.net/mspsim/?rev=294&view=rev Author: joxe Date: 2008-08-29 21:58:33 +0000 (Fri, 29 Aug 2008) Log Message: ----------- removed debug printouts Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/se/sics/mspsim/core/Timer.java Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2008-08-29 20:53:13 UTC (rev 293) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2008-08-29 21:58:33 UTC (rev 294) @@ -48,7 +48,7 @@ public class MSP430Core extends Chip implements MSP430Constants { public static final boolean DEBUG = false; - public static final boolean debugInterrupts = true; //false; + public static final boolean debugInterrupts = false; // Try it out with 64 k memory public static final int MAX_MEM = 64*1024; Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2008-08-29 20:53:13 UTC (rev 293) +++ mspsim/se/sics/mspsim/core/Timer.java 2008-08-29 21:58:33 UTC (rev 294) @@ -71,7 +71,7 @@ */ public class Timer extends IOUnit { - public static final boolean DEBUG = true;//false; + public static final boolean DEBUG = false;//true; public static final int TIMER_A = 0; public static final int TIMER_B = 1; private String[] name = new String[] {"A", "B"}; @@ -694,12 +694,12 @@ } if (timerTrigger.scheduledIn == null) { - System.out.println(getName() + " new trigger (nothing sch) ..." + time + " re:" + - smallest + " => " + (smallest > 0 ? expCaptureTime[smallest] + " > " + expCompare[smallest]: - nextTimerTrigger) + " C:"+ cycles); +// 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); +// System.out.println(getName() + " new trigger (new time)..." + time + " C:"+ cycles); core.scheduleCycleEvent(timerTrigger, time); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-08-29 20:53:15
|
Revision: 293 http://mspsim.svn.sourceforge.net/mspsim/?rev=293&view=rev Author: joxe Date: 2008-08-29 20:53:13 +0000 (Fri, 29 Aug 2008) Log Message: ----------- made some constants final Modified Paths: -------------- mspsim/se/sics/mspsim/core/Timer.java Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2008-08-29 20:34:19 UTC (rev 292) +++ mspsim/se/sics/mspsim/core/Timer.java 2008-08-29 20:53:13 UTC (rev 293) @@ -133,7 +133,7 @@ // Number of cycles passed since current counter value was set // useful for setting expected compare and capture times to correct time. // valid for timer A - private int timerOverflow = 0x0a; + private final int timerOverflow; private long counterStart = 0; private long nextTimerTrigger = 0; @@ -185,7 +185,7 @@ private int[] tccr = new int[7]; // Support variables Max 7 compare regs... (timer b) - private int noCompare = 0; + private final int noCompare; private int[] expCompare = new int[7]; private int[] expCapInterval = new int[7]; private long[] expCaptureTime = new long[7]; @@ -199,10 +199,10 @@ private boolean interruptEnable = false; private boolean interruptPending = false; - private int ccr1Vector; - private int ccr0Vector; - private MSP430Core core; + private final int ccr1Vector; + private final int ccr0Vector; + private final MSP430Core core; private TimeEvent timerTrigger = new TimeEvent(0) { public void execute(long t) { @@ -213,7 +213,7 @@ private int lastTIV; - private int[] srcMap; + private final int[] srcMap; /** * Creates a new <code>Timer</code> instance. * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-08-29 20:34:22
|
Revision: 292 http://mspsim.svn.sourceforge.net/mspsim/?rev=292&view=rev Author: joxe Date: 2008-08-29 20:34:19 +0000 (Fri, 29 Aug 2008) Log Message: ----------- fixed some bugs in timer subsystem Modified Paths: -------------- mspsim/se/sics/mspsim/core/Timer.java Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2008-07-08 07:05:20 UTC (rev 291) +++ mspsim/se/sics/mspsim/core/Timer.java 2008-08-29 20:34:19 UTC (rev 292) @@ -71,7 +71,7 @@ */ public class Timer extends IOUnit { - public static final boolean DEBUG = false; + public static final boolean DEBUG = true;//false; public static final int TIMER_A = 0; public static final int TIMER_B = 1; private String[] name = new String[] {"A", "B"}; @@ -174,7 +174,11 @@ private int counter = 0; private int counterPassed = 0; - + // The value of the counter when something changed last time + // (change of divisor, or a start TAR different than 0 when timer + // starts, etc). + private int initialCounter = 0; + // The IO registers private int tctl; private int[] tcctl = new int[7]; @@ -259,6 +263,7 @@ counter = 0; counterPassed = 0; counterStart = 0; + initialCounter = 0; clockSource = 0; cyclesMultiplicator = 1; mode = STOP; @@ -275,7 +280,7 @@ // But this mess the TIV up too early...... // Must DELAY the reset of interrupt flags until next read...? int val = lastTIV; - resetTIV(); + resetTIV(cycles); return val; } int val = 0; @@ -333,14 +338,14 @@ return val & 0xffff; } - private void resetTIV() { + private void resetTIV(long cycles) { if (lastTIV == timerOverflow) { interruptPending = false; lastTIV = 0; if (DEBUG) { System.out.println(getName() + " Clearing TIV - overflow "); } - triggerInterrupts(); + triggerInterrupts(cycles); } if (lastTIV / 2 < noCompare) { if (DEBUG) { @@ -348,7 +353,7 @@ } // Clear interrupt flags! tcctl[lastTIV / 2] &= ~CC_IFG; - triggerInterrupts(); + triggerInterrupts(cycles); // memory[offset + TCCTL0 + lastTIV] &= ~CC_IFG; } } @@ -389,9 +394,14 @@ int newMode = (data >> 4) & 3; if (mode == STOP && newMode != STOP) { - updateCounter(cycles); + // Set the initial counter to the value that counter should have after + // recalculation + initialCounter = counter; + counterStart = cycles; // Wait until full wrap before setting the IRQ flag! nextTimerTrigger = (long) (cycles + cyclesMultiplicator * ((0xffff - counter) & 0xffff)); + if (DEBUG) System.out.println(getName() + " Starting timer!"); + recalculateCompares(cycles); } mode = newMode; @@ -436,7 +446,7 @@ inputSrc[index] = srcMap[4 + index * 4 + inputSel[index]]; capMode[index] = (data >> 14) & 3; - triggerInterrupts(); + triggerInterrupts(cycles); if (DEBUG) { System.out.println(getName() + " Write: CCTL" + @@ -546,6 +556,8 @@ } private int updateCounter(long cycles) { + if (mode == STOP) return counter; + // Needs to be non-integer since smclk Frq can be lower // than aclk double divider = 1; @@ -559,19 +571,18 @@ counterPassed = (int) (divider * (tick - (long) (tick))); switch (mode) { case CONTIN: - counter = ((int) tick) & 0xffff; + counter = ((int) tick + initialCounter) & 0xffff; break; case UP: - counter = ((int) tick) % tccr[0]; + counter = ((int) tick + initialCounter) % tccr[0]; break; case UPDWN: - counter = ((int) tick) % (tccr[0] * 2); + counter = ((int) tick + initialCounter) % (tccr[0] * 2); if (counter > tccr[0]) { // Should back down to start again! counter = 2 * tccr[0] - counter; } } - if (DEBUG) { System.out.println(getName() + ": Updating counter cycctr: " + cycctr + " divider: " + divider + " mode:" + mode + " => " + counter); } @@ -584,7 +595,13 @@ return 100000 + cycles; } + // Only called by the interrupt handler private void updateTimers(long cycles) { + if (mode == STOP) { + System.out.println("No timer running -> no interrupt can be caused -> no scheduling..."); + return; + } + if (cycles >= nextTimerTrigger) { interruptPending = true; // This should be updated whenever clockspeed changes... @@ -598,7 +615,7 @@ for (int i = 0, n = noCompare; i < n; i++) { if (expCaptureTime[i] != -1 && cycles >= expCaptureTime[i]) { if (DEBUG) { - System.out.println(getName() + " CAPTURE: " + i + + System.out.println(getName() + (captureOn[i] ? " CAPTURE: " : " COMPARE: ") + i + " Cycles: " + cycles + " expCap: " + expCaptureTime[i] + " => ExpCR: " + Utils.hex16(expCompare[i]) + @@ -640,14 +657,31 @@ // Trigger interrupts that are up for triggering! - triggerInterrupts(); + triggerInterrupts(cycles); calculateNextEventTime(cycles); } + private void recalculateCompares(long cycles) { + for (int i = 0; i < expCaptureTime.length; i++) { + if (expCaptureTime[i] != 0) { + int diff = tccr[i] - counter; + if (diff < 0) { + // Wrap... + diff += 0x10000; + } + expCaptureTime[i] = cycles + (long) (diff * cyclesMultiplicator); + } + } + } + private void calculateNextEventTime(long cycles) { + if (mode == STOP) { + // If nothing is "running" there is no point scheduling... + return; + } long time = nextTimerTrigger; int smallest = -1; - for (int i = 0; i < expCaptureTime.length; i++) { + for (int i = 0; i < noCompare; i++) { long ct = expCaptureTime[i]; if (ct > 0 && ct < time) { time = ct; @@ -660,18 +694,18 @@ } if (timerTrigger.scheduledIn == null) { -// System.out.println(getName() + " new trigger (nothing sch) ..." + time + " re:" + -// smallest + " => " + (smallest > 0 ? expCaptureTime[smallest] + " > " + expCompare[smallest]: -// nextTimerTrigger) + " C:"+ cycles); - core.scheduleCycleEvent(timerTrigger, time); + 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); + 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() { + public void triggerInterrupts(long cycles) { // First check if any capture register is generating an interrupt... boolean trigger = false; @@ -698,7 +732,7 @@ if (newTrigger) { if (DEBUG) { System.out.println(getName() + " triggering interrupt TIV: " + - (i * 2)); + (i * 2) + " at cycles:" + cycles); } tIndex = i; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-07-08 07:05:23
|
Revision: 291 http://mspsim.svn.sourceforge.net/mspsim/?rev=291&view=rev Author: joxe Date: 2008-07-08 00:05:20 -0700 (Tue, 08 Jul 2008) Log Message: ----------- updated changelog. Modified Paths: -------------- mspsim/CHANGE_LOG.txt Modified: mspsim/CHANGE_LOG.txt =================================================================== --- mspsim/CHANGE_LOG.txt 2008-07-08 07:01:45 UTC (rev 290) +++ mspsim/CHANGE_LOG.txt 2008-07-08 07:05:20 UTC (rev 291) @@ -1,3 +1,8 @@ +0.92 +Changes: +- fixed bug with a write register which did not handle word/byte +- fixed bug which caused array out of bounds on IO-units. + 0.91 Changes: - added window system and support for it in the CLI This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-07-08 07:02:08
|
Revision: 290 http://mspsim.svn.sourceforge.net/mspsim/?rev=290&view=rev Author: joxe Date: 2008-07-08 00:01:45 -0700 (Tue, 08 Jul 2008) Log Message: ----------- fixed bug with word/byte handling of writeRegister after two ops instructions Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430Core.java Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2008-07-04 06:07:31 UTC (rev 289) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2008-07-08 07:01:45 UTC (rev 290) @@ -1177,6 +1177,7 @@ if (write) { if (dstRegMode) { + if (!word) dst &= 0xff; writeRegister(dstRegister, dst); } else { dstAddress &= 0xffff; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-07-04 06:07:50
|
Revision: 289 http://mspsim.svn.sourceforge.net/mspsim/?rev=289&view=rev Author: joxe Date: 2008-07-03 23:07:31 -0700 (Thu, 03 Jul 2008) Log Message: ----------- fixed bug with missed cycles on some instructions Modified Paths: -------------- 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 Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2008-06-11 21:59:07 UTC (rev 288) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2008-07-04 06:07:31 UTC (rev 289) @@ -39,6 +39,8 @@ * $Revision$ */ package se.sics.mspsim.cli; +import javax.swing.MenuSelectionManager; + import se.sics.mspsim.core.CPUMonitor; import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.MSP430Constants; @@ -78,7 +80,7 @@ }); ch.registerCommand("watch", - new BasicAsyncCommand("add a write watch to a given address or symbol", "<address or symbol>") { + new BasicAsyncCommand("add a write/read watch to a given address or symbol", "<address or symbol> [char | break]") { int mode = 0; int address = 0; public int executeCommand(final CommandContext context) { @@ -91,17 +93,28 @@ String modeStr = context.getArgument(1); if ("char".equals(modeStr)) { mode = 1; + } else if ("break".equals(modeStr)) { + mode = 2; } } cpu.setBreakPoint(address = baddr, new CPUMonitor() { public void cpuAction(int type, int adr, int data) { - if (mode == 0) { + if (mode == 0 || mode == 2) { int pc = cpu.readRegister(0); String adrStr = getSymOrAddr(context, adr); String pcStr = getSymOrAddrELF(elf, pc); - context.out.println("*** Write from " + pcStr + + String op = "op"; + if (type == MEMORY_READ) { + op = "Read"; + } else if (type == MEMORY_WRITE){ + op = "Write"; + } + context.out.println("*** " + op + " from " + pcStr + ": " + adrStr + " = " + data); + if (mode == 2) { + cpu.stop(); + } } else { context.out.print((char) data); } @@ -205,9 +218,10 @@ ch.registerCommand("step", new BasicCommand("singlestep the CPU", "[number of instructions]") { 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))); + long cyc = cpu.cycles; + node.step(nr); + context.out.println("CPU stepped to: $" + Utils.hex16(cpu.readRegister(0)) + + " in " + (cpu.cycles - cyc) + " cycles (" + cpu.cycles + ")"); return 0; } }); Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2008-06-11 21:59:07 UTC (rev 288) +++ mspsim/se/sics/mspsim/core/MSP430.java 2008-07-04 06:07:31 UTC (rev 289) @@ -153,6 +153,49 @@ return step(0); } + public long stepInstructions(int count) { + if (isRunning()) { + throw new IllegalStateException("step not possible when CPU is running"); + } + setRunning(true); + // ------------------------------------------------------------------- + // Debug information + // ------------------------------------------------------------------- + + + while (count-- > 0 && isRunning()) { + if (debug) { + if (servicedInterrupt >= 0) { + disAsm.disassemble(reg[PC], memory, reg, servicedInterrupt); + } else { + disAsm.disassemble(reg[PC], memory, reg); + } + } + + boolean emuOP = emulateOP(); + if (emuOP) { + if (execCounter != null) { + execCounter[reg[PC]]++; + } + + if (profiler != null) { + if ((instruction & 0xff80) == CALL) { + /* The profiling should only be made on actual cpuCycles */ + MapEntry function = map.getEntry(reg[PC]); + if (function == null) { + function = getFunction(map, reg[PC]); + } + profiler.profileCall(function, cpuCycles); + } else if (instruction == RETURN) { + profiler.profileReturn(cpuCycles); + } + } + } + } + setRunning(false); + return cycles; + } + public long step(long max_cycles) { if (isRunning()) { throw new IllegalStateException("step not possible when CPU is running"); Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2008-06-11 21:59:07 UTC (rev 288) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2008-07-04 06:07:31 UTC (rev 289) @@ -48,7 +48,7 @@ public class MSP430Core extends Chip implements MSP430Constants { public static final boolean DEBUG = false; - public static final boolean debugInterrupts = false; + public static final boolean debugInterrupts = true; //false; // Try it out with 64 k memory public static final int MAX_MEM = 64*1024; @@ -528,7 +528,11 @@ interruptSource[interrupt] = source; if (debugInterrupts) { - System.out.println("### Interrupt flagged ON by " + source.getName()); + if (source != null) { + System.out.println("### Interrupt flagged ON by " + source.getName()); + } else { + System.out.println("### Interrupt flagged ON by <null>"); + } } // MAX priority is executed first - update max if this is higher! @@ -594,9 +598,6 @@ // Read method that handles read from IO units! public int read(int address, boolean word) { int val = 0; -// if (breakPoints[address] != null) { -// breakPoints[address].call -// } // Only word reads at 0x1fe which is highest address... if (address < 0x1ff && memIn[address] != null) { val = memIn[address].read(address, word, cycles); @@ -607,6 +608,9 @@ val |= (memory[(address + 1) & 0xffff] << 8); } } + if (breakPoints[address] != null) { + breakPoints[address].cpuAction(CPUMonitor.MEMORY_READ, address, val); + } return val; } @@ -693,6 +697,7 @@ /* returns true if any instruction was emulated - false if CpuOff */ public boolean emulateOP() { + //System.out.println("CYCLES BEFORE: " + cycles); int pc = readRegister(PC); long startCycles = cycles; @@ -726,7 +731,7 @@ } // This is quite costly... should probably be made more - // efficiently (maybe in CORE where PC is read anyway?) + // efficiently if (breakPoints[pc] != null) { if (breakpointActive) { breakPoints[pc].cpuAction(CPUMonitor.BREAK, pc, 0); @@ -929,8 +934,8 @@ 2 * jmpOffset : -(2 * (0x200 - (jmpOffset & 0x1ff))); boolean jump = false; - // All jump takes one extra cycle - cycles++; + // All jump takes two cycles + cycles += 2; sr = readRegister(SR); switch(instruction & 0xfc00) { case JNE: @@ -986,7 +991,7 @@ if (!word) { src &= 0xff; } - + cycles += dstRegMode ? 1 : 4; } else { switch(as) { // Operand in register! @@ -996,6 +1001,7 @@ if (!word) { src &= 0xff; } + cycles += dstRegMode ? 1 : 4; break; case AM_INDEX: // Indexed if reg != PC & CG1/CG2 - will PC be incremented? @@ -1188,6 +1194,8 @@ writeRegister(SR, sr); } + //System.out.println("CYCLES AFTER: " + cycles); + cpuCycles += cycles - startCycles; return true; } Modified: mspsim/se/sics/mspsim/platform/GenericNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/GenericNode.java 2008-06-11 21:59:07 UTC (rev 288) +++ mspsim/se/sics/mspsim/platform/GenericNode.java 2008-07-04 06:07:31 UTC (rev 289) @@ -159,4 +159,12 @@ cpu.step(); } } + + // A step that will break out of breakpoints! + public void step(int nr) { + if (!cpu.isRunning()) { + cpu.stepInstructions(nr); + } + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-06-11 21:59:26
|
Revision: 288 http://mspsim.svn.sourceforge.net/mspsim/?rev=288&view=rev Author: joxe Date: 2008-06-11 14:59:07 -0700 (Wed, 11 Jun 2008) Log Message: ----------- fixed index out of bounds bug for IO addresses (< 0x200). Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430Core.java Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2008-06-02 10:44:49 UTC (rev 287) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2008-06-11 21:59:07 UTC (rev 288) @@ -597,7 +597,8 @@ // if (breakPoints[address] != null) { // breakPoints[address].call // } - if (address < 0x200 && memIn[address] != null) { + // Only word reads at 0x1fe which is highest address... + if (address < 0x1ff && memIn[address] != null) { val = memIn[address].read(address, word, cycles); } else { address &= 0xffff; @@ -614,7 +615,8 @@ breakPoints[dstAddress].cpuAction(CPUMonitor.MEMORY_WRITE, dstAddress, dst); } - if (dstAddress <= 0x200 && memOut[dstAddress] != null) { + // Only word writes at 0x1fe which is highest address... + if (dstAddress < 0x1ff && memOut[dstAddress] != null) { if (!word) dst &= 0xff; memOut[dstAddress].write(dstAddress, dst, word, cycles); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-06-02 10:44:52
|
Revision: 287 http://mspsim.svn.sourceforge.net/mspsim/?rev=287&view=rev Author: joxe Date: 2008-06-02 03:44:49 -0700 (Mon, 02 Jun 2008) Log Message: ----------- updated readme file Modified Paths: -------------- mspsim/README.txt Modified: mspsim/README.txt =================================================================== --- mspsim/README.txt 2008-06-02 10:38:12 UTC (rev 286) +++ mspsim/README.txt 2008-06-02 10:44:49 UTC (rev 287) @@ -1,4 +1,4 @@ -* MSPSim version 0.8 +* MSPSim version 0.9x MSPSim is a Java-based instruction level emulator of the MSP430 series microprocessor and emulation of some sensor networking @@ -41,7 +41,10 @@ - Easy to add external components that emulates external HW - Supports monitoring of registers, adding breakpoints, etc. - Built-in profiling of executed code +- Statistics for various components modes (on/off, LPM modes, etc). - Emulates some external hardware such as TR1001 and CC2420. +- Command Line Interface, CLI, for setting up breakpoints and output + to files or windows. * What is emulated of the MSP430 - CPU (instruction level simulation) @@ -49,10 +52,11 @@ - USARTs - Digital I/O - Multiplication unit +- Basic A/D subsystem (not complete) +- Watchdog -* Limitations of the emulation (some of them) on version 0.8 +* Limitations of the emulation (some of them) on version 0.9x - currently the emulator runs as if it can use all memory as RAM (e.g. flash writes, etc not supported) - no DMA implementation -- no ADs implemented (fully) -- timer system not 100% emulated +- timer system not 100% emulated \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |