From: <jo...@us...> - 2007-12-01 00:05:00
|
Revision: 34 http://mspsim.svn.sourceforge.net/mspsim/?rev=34&view=rev Author: joxe Date: 2007-11-30 16:04:48 -0800 (Fri, 30 Nov 2007) Log Message: ----------- some minor fixes Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430.java mspsim/se/sics/mspsim/core/MSP430Constants.java mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/se/sics/mspsim/util/StackUI.java Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2007-11-30 23:09:51 UTC (rev 33) +++ mspsim/se/sics/mspsim/core/MSP430.java 2007-12-01 00:04:48 UTC (rev 34) @@ -56,7 +56,10 @@ // Debug time - measure cycles private long lastCycles = 0; + private long lastCpuCycles = 0; private long time; + private long nextSleep = 0; + private long nextOut = 0; private long instCtr = 0; @@ -103,11 +106,13 @@ } } + if (cycles > nextOut && !debug) { + printCPUSpeed(reg[PC]); + nextOut = cycles + 10000007; + } + if (emulateOP()) { instCtr++; - if ((instCtr % 1000007) == 0 && !debug) { - printCPUSpeed(reg[PC]); - } if (execCounter != null) { execCounter[reg[PC]]++; @@ -126,6 +131,15 @@ } } + /* Just a test to see if it gets down to a reasonable speed */ + if (cycles > nextSleep) { + try { + Thread.sleep(10); + } catch (Exception e) { + } + nextSleep = cycles + 50000; + } + // if ((instruction & 0xff80) == CALL) { // System.out.println("Call to PC = " + reg[PC]); // } @@ -260,14 +274,20 @@ private void printCPUSpeed(int pc) { int td = (int)(System.currentTimeMillis() - time); int cd = (int) (cycles - lastCycles); + int cpud = (int) (cpuCycles - lastCpuCycles); + if (td == 0 || cd == 0) return; + if (DEBUGGING_LEVEL > 0) { - System.out.println("Time elapsed: " + td - + " cycDiff: " + cd - + " => " + 1000 * (cd / td ) + " cycles / s"); + System.out.println("Elapsed: " + td + + " cycDiff: " + cd + " => " + 1000 * (cd / td ) + + " cyc/s cpuDiff:" + cpud + " => " + + 1000 * (cpud / td ) + " cyc/s " + + (10000 * cpud / cd)/100.0 + "%"); } time = System.currentTimeMillis(); lastCycles = cycles; + lastCpuCycles = cpuCycles; disAsm.disassemble(pc, memory, reg); } Modified: mspsim/se/sics/mspsim/core/MSP430Constants.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Constants.java 2007-11-30 23:09:51 UTC (rev 33) +++ mspsim/se/sics/mspsim/core/MSP430Constants.java 2007-12-01 00:04:48 UTC (rev 34) @@ -136,5 +136,5 @@ public static final int CLKCAPTURE_BOTH = 3; - public static final int DEBUGGING_LEVEL = 0; + public static final int DEBUGGING_LEVEL = 1; } Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2007-11-30 23:09:51 UTC (rev 33) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2007-12-01 00:04:48 UTC (rev 34) @@ -337,7 +337,7 @@ servicedInterruptUnit = null; servicedInterrupt = -1; interruptMax = -1; - cpuOff = false; + writeRegister(SR, 0); } // Indicate that we have an interrupt now! Modified: mspsim/se/sics/mspsim/util/StackUI.java =================================================================== --- mspsim/se/sics/mspsim/util/StackUI.java 2007-11-30 23:09:51 UTC (rev 33) +++ mspsim/se/sics/mspsim/util/StackUI.java 2007-12-01 00:04:48 UTC (rev 34) @@ -49,7 +49,7 @@ public class StackUI extends JPanel implements CPUMonitor { - private static final int STACK_FRAME = 2048; + private static final int STACK_FRAME = 1024; private int updateCyclePeriod = 2500; private MSP430 cpu; @@ -106,8 +106,8 @@ if (this.maxData[pos] < size) { this.maxData[pos] = size; } - if (cpu.cycles - lastCycles > updateCyclePeriod) { - lastCycles = cpu.cycles; + if (cpu.cpuCycles - lastCycles > updateCyclePeriod) { + lastCycles = cpu.cpuCycles; //System.out.println("STACK UPDATE: " + type + "," + adr + "," + data); pos = (pos + 1) % this.minData.length; this.minData[pos] = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2007-12-01 12:06:32
|
Revision: 35 http://mspsim.svn.sourceforge.net/mspsim/?rev=35&view=rev Author: joxe Date: 2007-12-01 04:06:29 -0800 (Sat, 01 Dec 2007) Log Message: ----------- refactored profiling to separate class Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430.java mspsim/se/sics/mspsim/util/ControlUI.java mspsim/se/sics/mspsim/util/Test.java Added Paths: ----------- mspsim/se/sics/mspsim/core/Profiler.java mspsim/se/sics/mspsim/util/SimpleProfiler.java Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2007-12-01 00:04:48 UTC (rev 34) +++ mspsim/se/sics/mspsim/core/MSP430.java 2007-12-01 12:06:29 UTC (rev 35) @@ -40,11 +40,8 @@ */ package se.sics.mspsim.core; -import java.util.Arrays; -import java.util.Hashtable; +import se.sics.mspsim.util.*; -import se.sics.mspsim.util.Utils; - public class MSP430 extends MSP430Core { public static final int RETURN = 0x4130; @@ -61,14 +58,12 @@ private long nextSleep = 0; private long nextOut = 0; - private long instCtr = 0; + private double lastCPUPercent = 0d; + private long instCtr = 0; private DisAsm disAsm; - private MapTable map; - private Hashtable<String,CallEntry> profileData; - private CallEntry[] callStack; - private int cSP = 0; + private Profiler profiler; /** * Creates a new <code>MSP430</code> instance. @@ -79,6 +74,10 @@ disAsm = new DisAsm(); } + public double getCPUPercent() { + return lastCPUPercent; + } + public DisAsm getDisAsm() { return disAsm; } @@ -108,7 +107,7 @@ if (cycles > nextOut && !debug) { printCPUSpeed(reg[PC]); - nextOut = cycles + 10000007; + nextOut = cycles + 20000007; } if (emulateOP()) { @@ -118,15 +117,16 @@ execCounter[reg[PC]]++; } - if (map != null) { + if (profiler != null) { if ((instruction & 0xff80) == CALL) { /* The profiling should only be made on actual cpuCycles */ - profileCall(map.getFunction(reg[PC]), cpuCycles); - // System.out.println("Call," + map.getFunction(reg[PC]) + "," + - // cycles); + String function = map.getFunction(reg[PC]); + if (function == null) { + function = "fkn at $" + Utils.hex16(reg[PC]); + } + profiler.profileCall(function, cpuCycles); } else if (instruction == RETURN) { - profileReturn(cpuCycles); - //System.out.println("Return," + cycles); + profiler.profileReturn(cpuCycles); } } } @@ -146,81 +146,6 @@ } } - private void profileCall(String function, long cycles) { -// System.out.println("Call at: " + Utils.hex16(reg[PC])); - if (callStack[cSP] == null) { - callStack[cSP] = new CallEntry(); - } - if (function == null) { - function = "fkn at $" + Utils.hex16(reg[PC]); - } - callStack[cSP].function = function; - callStack[cSP].calls = 0; - callStack[cSP++].cycles = cycles; - } - - private void profileReturn(long cycles) { - String fkn = callStack[--cSP].function; -// System.out.println("Profiler: return / call stack: " + cSP + ", " + fkn); - - long elapsed = cycles - callStack[cSP].cycles; - if (callStack[cSP].calls >= 0) { - CallEntry ce = profileData.get(fkn); - if (ce == null) { - profileData.put(fkn, ce = new CallEntry()); - ce.function = fkn; - } - ce.cycles += elapsed; - ce.calls++; - } - } - - public void clearProfile() { - if (profileData != null) { - CallEntry[] entries = - profileData.values().toArray(new CallEntry[0]); - for (int i = 0, n = entries.length; i < n; i++) { - entries[i].cycles = 0; - entries[i].calls = 0; - } - for (int i = 0, n = callStack.length; i < n; i++) { - CallEntry e = callStack[i]; - if (e != null) { - e.calls = -1; - } - } - } - } - - public void printProfile() { - CallEntry[] entries = - profileData.values().toArray(new CallEntry[0]); - Arrays.sort(entries); - for (int i = 0, n = entries.length; i < n; i++) { - int c = entries[i].calls; - if (c > 0) { - String cyclesS = "" + entries[i].cycles; - String callS = "" + c; - String avgS = "" + (c > 0 ? (entries[i].cycles / c) : 0); - System.out.print(entries[i].function); - printSpace(56 - entries[i].function.length() - avgS.length()); - System.out.print(avgS); - System.out.print(' '); - printSpace(8 - callS.length()); - System.out.print(callS); - System.out.print(' '); - printSpace(10 - cyclesS.length()); - System.out.println(cyclesS); - } - } - } - - private void printSpace(int len) { - for (int i = 0; i < len; i++) { - System.out.print(' '); - } - } - public long step() { if (running) { throw new IllegalStateException("step not possible when CPU is running"); @@ -285,6 +210,7 @@ + 1000 * (cpud / td ) + " cyc/s " + (10000 * cpud / cd)/100.0 + "%"); } + lastCPUPercent = (10000 * cpud / cd)/100.0; time = System.currentTimeMillis(); lastCycles = cycles; lastCpuCycles = cpuCycles; @@ -299,27 +225,15 @@ debug = db; } - public void setMap(MapTable map) { - if (profileData == null) { - profileData = new Hashtable<String,CallEntry>(); - callStack = new CallEntry[2048]; - } - this.map = map; + public Profiler getProfiler() { + return profiler; } - private static class CallEntry implements Comparable { - String function; - long cycles; - int calls; - - public int compareTo(Object o) { - if (o instanceof CallEntry) { - long diff = ((CallEntry)o).cycles - cycles; - if (diff > 0) return 1; - if (diff < 0) return -1; - } - return 0; + public void setMap(MapTable map) { + this.map = map; + /* When we got the map table we can also profile! */ + if (profiler == null) { + this.profiler = new SimpleProfiler(); } } - } Added: mspsim/se/sics/mspsim/core/Profiler.java =================================================================== --- mspsim/se/sics/mspsim/core/Profiler.java (rev 0) +++ mspsim/se/sics/mspsim/core/Profiler.java 2007-12-01 12:06:29 UTC (rev 35) @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2007, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * $Id: MSP430.java,v 1.4 2007/10/21 22:02:22 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * MSP430 + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 22:02:22 $ + * $Revision: 1.4 $ + */ + +package se.sics.mspsim.core; +import java.util.Arrays; +import java.util.Hashtable; + +import se.sics.mspsim.util.Utils; + +public interface Profiler { + + public void profileCall(String function, long cycles); + public void profileReturn(long cycles); + + public void clearProfile(); + + public void printProfile(); + +} Modified: mspsim/se/sics/mspsim/util/ControlUI.java =================================================================== --- mspsim/se/sics/mspsim/util/ControlUI.java 2007-12-01 00:04:48 UTC (rev 34) +++ mspsim/se/sics/mspsim/util/ControlUI.java 2007-12-01 12:06:29 UTC (rev 35) @@ -57,6 +57,8 @@ public class ControlUI extends JPanel implements ActionListener { + private static final String TITLE = "MSPSim monitor"; + private JFrame window; private MSP430 cpu; private DebugUI dui; @@ -76,7 +78,7 @@ WindowUtils.addSaveOnShutdown("StackUI", stackWindow); stackWindow.setVisible(true); - window = new JFrame("MSPSim monitor"); + window = new JFrame(TITLE); // window.setSize(320,240); window.setLayout(new BorderLayout()); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -121,8 +123,13 @@ return jb; } + private void updateCPUPercent() { + window.setTitle(TITLE + " CPU On: " + cpu.getCPUPercent() + "%"); + } + public void actionPerformed(ActionEvent ae) { String cmd = ae.getActionCommand(); + updateCPUPercent(); if ("Debug On".equals(cmd)) { cpu.setDebug(true); ((JButton) ae.getSource()).setText("Debug Off"); @@ -145,9 +152,13 @@ stepAction.setEnabled(true); } else if ("Profile Dump".equals(cmd)) { - cpu.printProfile(); - // } else if ("Single Step".equals(cmd)) { -// cpu.step(); + if (cpu.getProfiler() != null) { + cpu.getProfiler().printProfile(); + } else { + System.out.println("*** No profiler available"); + } + // } else if ("Single Step".equals(cmd)) { + // cpu.step(); // dui.repaint(); } dui.updateRegs(); Added: mspsim/se/sics/mspsim/util/SimpleProfiler.java =================================================================== --- mspsim/se/sics/mspsim/util/SimpleProfiler.java (rev 0) +++ mspsim/se/sics/mspsim/util/SimpleProfiler.java 2007-12-01 12:06:29 UTC (rev 35) @@ -0,0 +1,150 @@ +/** + * Copyright (c) 2007, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * $Id: MSP430.java,v 1.4 2007/10/21 22:02:22 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * MSP430 + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 22:02:22 $ + * $Revision: 1.4 $ + */ + +package se.sics.mspsim.util; +import se.sics.mspsim.core.Profiler; +import java.util.Arrays; +import java.util.Hashtable; + + +public class SimpleProfiler implements Profiler { + + private Hashtable<String,CallEntry> profileData; + private CallEntry[] callStack; + private int cSP = 0; + + public SimpleProfiler() { + profileData = new Hashtable<String,CallEntry>(); + callStack = new CallEntry[2048]; + } + + public void profileCall(String function, long cycles) { +// System.out.println("Call at: " + Utils.hex16(reg[PC])); + if (callStack[cSP] == null) { + callStack[cSP] = new CallEntry(); + } + callStack[cSP].function = function; + callStack[cSP].calls = 0; + callStack[cSP++].cycles = cycles; + } + + public void profileReturn(long cycles) { + String fkn = callStack[--cSP].function; +// System.out.println("Profiler: return / call stack: " + cSP + ", " + fkn); + + long elapsed = cycles - callStack[cSP].cycles; + if (callStack[cSP].calls >= 0) { + CallEntry ce = profileData.get(fkn); + if (ce == null) { + profileData.put(fkn, ce = new CallEntry()); + ce.function = fkn; + } + ce.cycles += elapsed; + ce.calls++; + } + } + + public void clearProfile() { + if (profileData != null) { + CallEntry[] entries = + profileData.values().toArray(new CallEntry[0]); + for (int i = 0, n = entries.length; i < n; i++) { + entries[i].cycles = 0; + entries[i].calls = 0; + } + for (int i = 0, n = callStack.length; i < n; i++) { + CallEntry e = callStack[i]; + if (e != null) { + e.calls = -1; + } + } + } + } + + public void printProfile() { + CallEntry[] entries = + profileData.values().toArray(new CallEntry[0]); + Arrays.sort(entries); + + System.out.println("************************* Profile Data **************************************"); + System.out.println("Function Average Calls Tot.Cycles"); + + + for (int i = 0, n = entries.length; i < n; i++) { + int c = entries[i].calls; + if (c > 0) { + String cyclesS = "" + entries[i].cycles; + String callS = "" + c; + String avgS = "" + (c > 0 ? (entries[i].cycles / c) : 0); + System.out.print(entries[i].function); + printSpace(56 - entries[i].function.length() - avgS.length()); + System.out.print(avgS); + System.out.print(' '); + printSpace(8 - callS.length()); + System.out.print(callS); + System.out.print(' '); + printSpace(10 - cyclesS.length()); + System.out.println(cyclesS); + } + } + } + + private void printSpace(int len) { + for (int i = 0; i < len; i++) { + System.out.print(' '); + } + } + + private static class CallEntry implements Comparable { + String function; + long cycles; + int calls; + + public int compareTo(Object o) { + if (o instanceof CallEntry) { + long diff = ((CallEntry)o).cycles - cycles; + if (diff > 0) return 1; + if (diff < 0) return -1; + } + return 0; + } + } +} Modified: mspsim/se/sics/mspsim/util/Test.java =================================================================== --- mspsim/se/sics/mspsim/util/Test.java 2007-12-01 00:04:48 UTC (rev 34) +++ mspsim/se/sics/mspsim/util/Test.java 2007-12-01 12:06:29 UTC (rev 35) @@ -73,9 +73,9 @@ } else if (line.startsWith("DEBUG")) { cpu.setDebug(true); } else if (line.startsWith("PROFILE")) { - cpu.printProfile(); + cpu.getProfiler().printProfile(); } else if (line.startsWith("CLEARPROFILE")) { - cpu.clearProfile(); + cpu.getProfiler().clearProfile(); } } else { lineBuffer.append((char) data); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2007-12-06 15:11:35
|
Revision: 38 http://mspsim.svn.sourceforge.net/mspsim/?rev=38&view=rev Author: joxe Date: 2007-12-06 07:11:27 -0800 (Thu, 06 Dec 2007) Log Message: ----------- fixed minor bugs related to source view Modified Paths: -------------- mspsim/se/sics/mspsim/platform/sky/SkyNode.java mspsim/se/sics/mspsim/util/ControlUI.java Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2007-12-06 14:24:30 UTC (rev 37) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2007-12-06 15:11:27 UTC (rev 38) @@ -169,7 +169,7 @@ // Monitor execution cpu.setMonitorExec(true); //cpu.setDebug(true); - + ELF elf = null; int[] memory = cpu.getMemory(); if (args[0].endsWith("ihex")) { @@ -177,7 +177,7 @@ IHexReader reader = new IHexReader(); reader.readFile(memory, args[0]); } else { - ELF elf = ELF.readELF(args[0]); + elf = ELF.readELF(args[0]); elf.loadPrograms(memory); MapTable map = elf.getMap(); cpu.getDisAsm().setMap(map); @@ -187,7 +187,7 @@ cpu.reset(); SkyNode node = new SkyNode(cpu); node.gui = new SkyGui(node); - ControlUI control = new ControlUI(cpu); + ControlUI control = new ControlUI(cpu, elf); if (args.length > 1) { MapTable map = new MapTable(args[1]); Modified: mspsim/se/sics/mspsim/util/ControlUI.java =================================================================== --- mspsim/se/sics/mspsim/util/ControlUI.java 2007-12-06 14:24:30 UTC (rev 37) +++ mspsim/se/sics/mspsim/util/ControlUI.java 2007-12-06 15:11:27 UTC (rev 38) @@ -176,9 +176,9 @@ // } else if ("Single Step".equals(cmd)) { // cpu.step(); // dui.repaint(); - } else if ("View Source".equals(cmd)) { + } else if ("Show Source".equals(cmd)) { int pc = cpu.readRegister(cpu.PC); - if (sourceViewer != null) { + if (elfData != null) { DebugInfo dbg = elfData.getDebugInfo(pc); if (dbg != null) { if (sourceViewer != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 16:40:36
|
Revision: 39 http://mspsim.svn.sourceforge.net/mspsim/?rev=39&view=rev Author: nifi Date: 2007-12-06 08:40:33 -0800 (Thu, 06 Dec 2007) Log Message: ----------- highlighting c source viewer Added Paths: ----------- mspsim/se/sics/mspsim/extutil/ mspsim/se/sics/mspsim/extutil/highlight/ mspsim/se/sics/mspsim/extutil/highlight/CScanner.java mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java mspsim/se/sics/mspsim/extutil/highlight/JavaScanner.java mspsim/se/sics/mspsim/extutil/highlight/LineNumberedBorder.java mspsim/se/sics/mspsim/extutil/highlight/Scan.java mspsim/se/sics/mspsim/extutil/highlight/Scanner.java mspsim/se/sics/mspsim/extutil/highlight/Symbol.java mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java mspsim/se/sics/mspsim/extutil/highlight/TextScanner.java mspsim/se/sics/mspsim/extutil/highlight/Token.java mspsim/se/sics/mspsim/extutil/highlight/TokenTypes.java Added: mspsim/se/sics/mspsim/extutil/highlight/CScanner.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/CScanner.java (rev 0) +++ mspsim/se/sics/mspsim/extutil/highlight/CScanner.java 2007-12-06 16:40:33 UTC (rev 39) @@ -0,0 +1,944 @@ +package se.sics.mspsim.extutil.highlight; +// Public domain, no restrictions, Ian Holyer, University of Bristol. + +/** + * <p> + * Provide a hand-written scanner for the Java language. + */ + +public class CScanner extends Scanner { + + private boolean debug = false; + + /** Create a Java scanner, for Java version 1.5 by default. */ + public CScanner() { + super(); + initKind(); + initUniKind(); + } + + /** Create a Java scanner, for a given version between "1.1" and "1.5". */ + public CScanner(String version) { + super(); + initKind(); + initUniKind(); + } + + /** Override the read method from the Scanner class. */ + protected int read() { + int type, saveStart = 0; + if (debug) + saveStart = start; + + if (start >= end) + return WHITESPACE; + + switch (state) { + case MID_COMMENT: + case END_COMMENT: + type = readComment(MID_COMMENT); + if (type == END_COMMENT) + state = WHITESPACE; + else + state = MID_COMMENT; + return type; + default: + char c = buffer[start]; + if (c == '\\') + c = next(); + if (c < 128) + type = kind[c]; + else + type = unikind[Character.getType(c)]; + switch (type) { + case WHITESPACE: + start = start + charlength; + charlength = 1; + while (start < end) { + c = buffer[start]; + if (c == '\\') + c = next(); + int k; + if (c < 128) + k = kind[c]; + else + k = unikind[Character.getType(c)]; + if (k != WHITESPACE) + break; + start = start + charlength; + charlength = 1; + } + break; + case UNRECOGNIZED: + case BRACKET: + case SEPARATOR: + start = start + charlength; + charlength = 1; + break; + case OPERATOR: + start = start + charlength; + charlength = 1; + type = readOperator(c); + break; + case CHARACTER: + start = start + charlength; + charlength = 1; + type = readCharLiteral(); + break; + case STRING: + start = start + charlength; + charlength = 1; + type = readStringLiteral(); + break; + case IDENTIFIER: + start = start + charlength; + charlength = 1; + while (start < end) { + c = buffer[start]; + if (c == '\\') + c = next(); + int k; + if (c < 128) + k = kind[c]; + else + k = unikind[Character.getType(c)]; + if (k != IDENTIFIER && k != NUMBER) + break; + start = start + charlength; + charlength = 1; + } + break; + case NUMBER: + start = start + charlength; + charlength = 1; + type = readNumber(c); + break; + case PUNCTUATION: + start = start + charlength; + charlength = 1; + type = readDot(); + break; + case COMMENT: + start = start + charlength; + charlength = 1; + type = readSlash(); + if (type == START_COMMENT) + state = MID_COMMENT; + break; + } + } + if (debug) { + System.out.print(TokenTypes.typeNames[type]); + System.out.println(" " + saveStart + "," + end + "(" + + (start - saveStart) + ")"); + } + return type; + } + + private int readOperator(char c) { + if (start >= end) + return OPERATOR; + char c2; + + switch (c) { + case '~': + case '?': + case ':': + break; + case '+': + case '-': + case '&': + case '|': + c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + if (c2 != c && c2 != '=') + break; + start = start + charlength; + charlength = 1; + break; + case '=': + case '*': + case '!': + case '^': + case '%': + case '/': + c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + if (c2 != '=') + break; + start = start + charlength; + charlength = 1; + break; + case '<': + case '>': + c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + if (c2 == '=') { + start = start + charlength; + charlength = 1; + } else if (c2 == c) { + start = start + charlength; + charlength = 1; + if (start >= end) + break; + char c3 = buffer[start]; + if (c3 == '\\') + c3 = next(); + if (c3 == '=') { + start = start + charlength; + charlength = 1; + } else if (c == '>' && c3 == '>') // >>> + { + start = start + charlength; + charlength = 1; + if (start >= end) + break; + char c4 = buffer[start]; + if (c4 == '\\') + c4 = next(); + if (c4 != '=') + break; + start = start + charlength; + charlength = 1; + } + } + break; + } + return OPERATOR; + } + + private int readCharLiteral() { + if (start >= end) + return bad(CHARACTER); + char c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + + switch (c2) { + case '\\': + start = start + charlength; + charlength = 1; + boolean ok = readEscapeSequence(); + if (!ok) + return bad(CHARACTER); + break; + case '\'': + case '\n': + return bad(CHARACTER); + default: + start = start + charlength; + charlength = 1; + break; + } + if (start >= end) + return bad(CHARACTER); + char c3 = buffer[start]; + if (c3 == '\\') + c3 = next(); + if (c3 != '\'') + return bad(CHARACTER); + start = start + charlength; + charlength = 1; + return CHARACTER; + } + + private int readStringLiteral() { + if (start >= end) + return bad(STRING); + char c = buffer[start]; + if (c == '\\') + c = next(); + + while (c != '"') { + switch (c) { + case '\\': + start = start + charlength; + charlength = 1; + boolean ok = readEscapeSequence(); + if (!ok) + return bad(STRING); + break; + case '\n': + return bad(STRING); + default: + start = start + charlength; + charlength = 1; + if (start >= end) + return bad(STRING); + break; + } + c = buffer[start]; + if (c == '\\') + c = next(); + } + if (c != '"') + return bad(STRING); + start = start + charlength; + charlength = 1; + return STRING; + } + + private int readSlash() { + if (start >= end) + return OPERATOR; + char c = buffer[start]; + if (c == '\\') + c = next(); + if (c == '/') { + while (c != '\n') { + start = start + charlength; + charlength = 1; + if (start >= end) + return COMMENT; + c = buffer[start]; + if (c == '\\') + c = next(); + } + start = start + charlength; + charlength = 1; + return COMMENT; + } else if (c == '*') { + start = start + charlength; + charlength = 1; + return readComment(START_COMMENT); + } + return readOperator('/'); + } + + // Read one line of a /*...*/ comment, given the expected type + int readComment(int type) { + if (start >= end) + return type; + char c = buffer[start]; + if (c == '\\') + c = next(); + + while (true) { + while (c != '*' && c != '\n') { + start = start + charlength; + charlength = 1; + if (start >= end) + return type; + c = buffer[start]; + if (c == '\\') + c = next(); + } + start = start + charlength; + charlength = 1; + if (c == '\n') + return type; + if (start >= end) + return type; + c = buffer[start]; + if (c == '\\') + c = next(); + if (c == '/') { + start = start + charlength; + charlength = 1; + if (type == START_COMMENT) { + return COMMENT; + } + return END_COMMENT; + } + } + } + + // Read a number, without checking whether it is out of range + // Doesn't deal with e.g. 0777.9 or 07779f + private int readNumber(char c) { + if (c == '0') { + int saveStart = start, saveLength = charlength; + start = start + charlength; + charlength = 1; + if (start >= end) + return NUMBER; + char c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + switch (c2) { + case 'x': + case 'X': + start = start + charlength; + charlength = 1; + boolean ok = readDigits(16); + if (!ok) + return bad(NUMBER); + readSuffix(); + return NUMBER; + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + readDigits(8); + readSuffix(); + return NUMBER; + case '.': + case 'e': + case 'E': + start = saveStart; + charlength = saveLength; + break; + case 'f': + case 'F': + case 'd': + case 'D': + start = start + charlength; + charlength = 1; + return NUMBER; + case 'l': + case 'L': + start = start + charlength; + charlength = 1; + return NUMBER; + } + } + boolean hasDigits = false; + if ('0' <= c && c <= '9') { + hasDigits = true; + readDigits(10); + if (start >= end) + return NUMBER; + c = buffer[start]; + if (c == '\\') + c = next(); + if (c == 'l' || c == 'L') { + start = start + charlength; + charlength = 1; + return NUMBER; + } + } + if (c == '.') { + start = start + charlength; + charlength = 1; + if (start >= end) + return NUMBER; + c = buffer[start]; + if (c == '\\') + c = next(); + if ('0' <= c && c <= '9') { + hasDigits = true; + readDigits(10); + if (start >= end) + return NUMBER; + c = buffer[start]; + if (c == '\\') + c = next(); + } + } + if (!hasDigits) + return bad(NUMBER); + switch (c) { + case 'e': + case 'E': + start = start + charlength; + charlength = 1; + if (start >= end) + return bad(NUMBER); + c = buffer[start]; + if (c == '\\') + c = next(); + if (c == '+' || c == '-') { + start = start + charlength; + charlength = 1; + if (start >= end) + return bad(NUMBER); + c = buffer[start]; + if (c == '\\') + c = next(); + } + readDigits(10); + break; + case 'f': + case 'F': + case 'd': + case 'D': + start = start + charlength; + charlength = 1; + return NUMBER; + } + return NUMBER; + } + + boolean readDigits(int radix) { + if (start >= end) + return false; + char c = buffer[start]; + if (c == '\\') + c = next(); + if (Character.digit(c, radix) == -1) + return false; + while (Character.digit(c, radix) != -1) { + start = start + charlength; + charlength = 1; + if (start >= end) + return true; + c = buffer[start]; + if (c == '\\') + c = next(); + } + return true; + } + + void readSuffix() { + if (start >= end) + return; + char c = buffer[start]; + if (c == '\\') + c = next(); + switch (c) { + case 'f': + case 'F': + case 'd': + case 'D': + case 'l': + case 'L': + start = start + charlength; + charlength = 1; + } + } + + private int readDot() { + if (start >= end) + return SEPARATOR; + char c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + if (Character.isDigit(c2)) { + return readNumber('.'); + } + if (start + 1 >= end) // || version < 15) + return SEPARATOR; + if (c2 != '.' || buffer[start + 1] != '.') + return SEPARATOR; + start = start + 2; + return SEPARATOR; + } + + private boolean readEscapeSequence() { + if (start >= end) + return false; + char c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + + switch (c2) { + case 'b': + case 't': + case 'n': + case 'f': + case 'r': + case '\"': + case '\'': + case '\\': + start = start + charlength; + charlength = 1; + return true; + case '0': + case '1': + case '2': + case '3': + return readOctal(3); + case '4': + case '5': + case '6': + case '7': + return readOctal(2); + default: + return false; + } + } + + boolean readOctal(int maxlength) { + if (start >= end) + return false; + char c = buffer[start]; + if (c == '\\') + c = next(); + + int i, val = 0; + for (i = 0; i < maxlength; i++) { + if (Character.digit(c, 8) != -1) { + val = 8 * val + Character.digit(c, 8); + start = start + charlength; + charlength = 1; + if (start >= end) + break; + c = buffer[start]; + if (c == '\\') + c = next(); + } else + break; + } + if ((i == 0) || (val > 0xFF)) + return false; + return true; + } + + // A malformed or incomplete token has a negative type + private int bad(int type) { + return -type; + } + + // Look ahead at the next character or unicode escape. + // For efficiency, replace c = next(); with + // c = buffer[start]; if (c == '\\') c = next(); + // To accept the character after looking at it, use: + // start = start + charlength; charlength = 1; + + // Record the number of source code characters used up. To deal with an odd + // or even number of backslashes preceding a unicode escape, whenever a + // second backslash is coming up, mark its position as a pair. + + private int charlength = 1; + + private int pair = 0; + + private char next() { + if (start >= end) + return 26; // EOF + char c = buffer[start]; + if (c != '\\') + return c; + if (start == pair) { + pair = 0; + return '\\'; + } + if (start + 1 >= end) + return '\\'; + + c = buffer[start + 1]; + if (c == '\\') + pair = start + 1; + if (c != 'u') + return '\\'; + + int pos = start + 2; + while (pos < end && buffer[pos] == 'u') + pos++; + if (pos + 4 > end) { + charlength = end - start; + return '\0'; + } + + c = 0; + for (int j = 0; j < 4; j++) { + int d = Character.digit(buffer[pos + j], 16); + if (d < 0) { + charlength = pos + j - start; + return '\0'; + } + c = (char) (c * 16 + d); + } + charlength = pos + 4 - start; + return c; + } + + // Override initSymbolTable + + protected void initSymbolTable() { + lookup(KEYWORD, "abstract"); + lookup(KEYWORD, "assert"); + lookup(KEYWORD, "boolean"); + lookup(KEYWORD, "break"); + lookup(KEYWORD, "byte"); + lookup(KEYWORD, "case"); + lookup(KEYWORD, "catch"); + lookup(KEYWORD, "char"); + lookup(KEYWORD, "class"); + lookup(KEYWORD, "const"); + lookup(KEYWORD, "continue"); + lookup(KEYWORD, "default"); + lookup(KEYWORD, "do"); + lookup(KEYWORD, "double"); + lookup(KEYWORD, "else"); + lookup(KEYWORD, "enum"); + lookup(KEYWORD, "extends"); + lookup(KEYWORD, "float"); + lookup(KEYWORD, "for"); + lookup(KEYWORD, "goto"); + lookup(KEYWORD, "if"); + lookup(KEYWORD, "int"); + lookup(KEYWORD, "long"); + lookup(KEYWORD, "new"); + lookup(KEYWORD, "private"); + lookup(KEYWORD, "protected"); + lookup(KEYWORD, "public"); + lookup(KEYWORD, "return"); + lookup(KEYWORD, "short"); + lookup(KEYWORD, "static"); + lookup(KEYWORD, "super"); + lookup(KEYWORD, "switch"); + lookup(KEYWORD, "synchronized"); + lookup(KEYWORD, "this"); + lookup(KEYWORD, "throw"); + lookup(KEYWORD, "throws"); + lookup(KEYWORD, "transient"); + lookup(KEYWORD, "try"); + lookup(KEYWORD, "void"); + lookup(KEYWORD, "volatile"); + lookup(KEYWORD, "while"); + + lookup(LITERAL, "TRUE"); + lookup(LITERAL, "FALSE"); + lookup(LITERAL, "NULL"); + lookup(LITERAL, "int8_t"); + lookup(LITERAL, "int16_t"); + lookup(LITERAL, "int32_t"); + lookup(LITERAL, "uint8_t"); + lookup(LITERAL, "uint16_t"); + lookup(LITERAL, "uint32_t"); + lookup(LITERAL, "u8_t"); + lookup(LITERAL, "u16_t"); + lookup(LITERAL, "u32_t"); + } + + // *** Override lookup, but what about unicode escape translation? + + private Symbol temp = new Symbol(0, null); + + protected Symbol lookup(int type, String name) { + if (type != IDENTIFIER) + return super.lookup(type, name); + temp.type = KEYWORD; + temp.name = name; + Symbol sym = symbolTable.get(temp); + if (sym != null) + return sym; + temp.type = LITERAL; + sym = symbolTable.get(temp); + if (sym != null) + return sym; + return super.lookup(type, name); + } + + // Classify the ascii characters using an array of kinds, and classify all + // other unicode characters using an array indexed by unicode category. + // See the source file java/lang/Character.java for the categories. + // To find the classification of a character, use: + // if (c < 128) k = kind[c]; else k = unikind[Character.getType(c)]; + + private static final byte[] kind = new byte[128]; + + private static final byte[] unikind = new byte[31]; + + // Initialise the two classification arrays using static initializer code. + // Token types from the TokenTypes class are used to classify characters. + + private void initKind() { + for (char c = 0; c < 128; c++) + kind[c] = -1; + for (char c = 0; c < 128; c++) + switch (c) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 11: + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: + case 19: + case 20: + case 21: + case 22: + case 23: + case 24: + case 25: + case 27: + case 28: + case 29: + case 30: + case 31: + case 127: + case '#': + case '@': + case '`': + case '\\': + kind[c] = UNRECOGNIZED; + break; + case '\t': + case '\n': + case ' ': + case '\f': + case 26: + kind[c] = WHITESPACE; + break; + case '!': + case '%': + case '&': + case '*': + case '+': + case '-': + case ':': + case '<': + case '=': + case '>': + case '?': + case '^': + case '|': + case '~': + kind[c] = OPERATOR; + break; + case '"': + kind[c] = STRING; + break; + case '\'': + kind[c] = CHARACTER; + break; + case '.': + kind[c] = PUNCTUATION; + break; + case '/': + kind[c] = COMMENT; + break; + case '$': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': + kind[c] = IDENTIFIER; + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + kind[c] = NUMBER; + break; + case '(': + case ')': + case '[': + case ']': + case '{': + case '}': + kind[c] = BRACKET; + break; + case ',': + case ';': + kind[c] = SEPARATOR; + break; + } + for (char c = 0; c < 128; c++) + if (kind[c] == -1) + System.out.println("Char " + ((int) c) + " hasn't been classified"); + } + + private void initUniKind() { + for (byte b = 0; b < 31; b++) + unikind[b] = -1; + for (byte b = 0; b < 31; b++) + switch (b) { + case Character.UNASSIGNED: + case Character.ENCLOSING_MARK: + case Character.OTHER_NUMBER: + case Character.SPACE_SEPARATOR: + case Character.LINE_SEPARATOR: + case Character.PARAGRAPH_SEPARATOR: + case Character.CONTROL: + case 17: // category 17 is unused + case Character.PRIVATE_USE: + case Character.SURROGATE: + case Character.DASH_PUNCTUATION: + case Character.START_PUNCTUATION: + case Character.END_PUNCTUATION: + case Character.OTHER_PUNCTUATION: + case Character.MATH_SYMBOL: + case Character.MODIFIER_SYMBOL: + case Character.OTHER_SYMBOL: + case Character.INITIAL_QUOTE_PUNCTUATION: + case Character.FINAL_QUOTE_PUNCTUATION: + unikind[b] = UNRECOGNIZED; + break; + case Character.UPPERCASE_LETTER: + case Character.LOWERCASE_LETTER: + case Character.TITLECASE_LETTER: + case Character.MODIFIER_LETTER: + case Character.OTHER_LETTER: + case Character.LETTER_NUMBER: + case Character.CONNECTOR_PUNCTUATION: // maybe NUMBER + case Character.CURRENCY_SYMBOL: + // Characters where Other_ID_Start is true + unikind[b] = IDENTIFIER; + break; + case Character.NON_SPACING_MARK: + case Character.COMBINING_SPACING_MARK: + case Character.DECIMAL_DIGIT_NUMBER: + case Character.FORMAT: + unikind[b] = NUMBER; + break; + } + for (byte b = 0; b < 31; b++) + if (unikind[b] == -1) + System.out.println("Unicode cat " + b + " hasn't been classified"); + } + +} Added: mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java (rev 0) +++ mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 16:40:33 UTC (rev 39) @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2007, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: $ + * + * ----------------------------------------------------------------- + * + * HighlightSourceViewer + * + * Authors : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : 6 dec 2007 + * Updated : $Date: 6 dec 2007 $ + * $Revision: 1.0 $ + */ + +package se.sics.mspsim.extutil.highlight; + +import java.awt.Container; +import java.io.FileReader; +import java.io.IOException; + +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; + +import se.sics.mspsim.util.SourceViewer; + +/** + * + */ +public class HighlightSourceViewer implements SourceViewer { + + private JFrame window; + private SyntaxHighlighter highlighter; + + public HighlightSourceViewer() { + // + } + + private void setup() { + if (window == null) { + window = new JFrame("Source Viewer"); + window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + Scanner scanner = new CScanner(); + highlighter = new SyntaxHighlighter(24, 80, scanner); + highlighter.setBorder(new LineNumberedBorder(LineNumberedBorder.LEFT_SIDE, LineNumberedBorder.RIGHT_JUSTIFY)); + JScrollPane scroller = new JScrollPane(highlighter); + scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + Container pane = window.getContentPane(); + pane.add(scroller); + window.pack(); + } + } + + public boolean isVisible() { + return window != null && window.isVisible(); + } + + public void setVisible(boolean isVisible) { + setup(); + window.setVisible(isVisible); + } + + public void viewFile(final String file) { + setup(); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + try { + FileReader reader = new FileReader(file); + try { + highlighter.read(reader, null); + // Workaround for bug 4782232 in Java 1.4 + highlighter.setCaretPosition(1); + highlighter.setCaretPosition(0); + } finally { + reader.close(); + } + } catch (IOException err) { + err.printStackTrace(); + JOptionPane.showMessageDialog(window, "Failed to read the file '" + file + '\'', "Could not read file", JOptionPane.ERROR_MESSAGE); + } + } + }); + } + + public void viewLine(final int line) { + if (highlighter != null) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + if (line >= 0 && line < highlighter.getLineCount()) { + highlighter.setCaretPosition(highlighter.getLineStartOffset(line)); + } + } + }); + } + } + + public static void main(String[] args) { + HighlightSourceViewer sv = new HighlightSourceViewer(); + sv.setVisible(true); + sv.viewFile(args[0]); + } +} Added: mspsim/se/sics/mspsim/extutil/highlight/JavaScanner.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/JavaScanner.java (rev 0) +++ mspsim/se/sics/mspsim/extutil/highlight/JavaScanner.java 2007-12-06 16:40:33 UTC (rev 39) @@ -0,0 +1,962 @@ +package se.sics.mspsim.extutil.highlight; +// Public domain, no restrictions, Ian Holyer, University of Bristol. + +/** + * <p> + * Provide a hand-written scanner for the Java language. + */ + +public class JavaScanner extends Scanner { + + // The version of Java supported. + private int version = 15; + + private boolean debug = false; + + /** Create a Java scanner, for Java version 1.5 by default. */ + public JavaScanner() { + super(); + initKind(); + initUniKind(); + } + + /** Create a Java scanner, for a given version between "1.1" and "1.5". */ + public JavaScanner(String version) { + super(); + initKind(); + initUniKind(); + if (version.equals("1.1")) + this.version = 11; + else if (version.equals("1.2")) + this.version = 12; + else if (version.equals("1.3")) + this.version = 13; + else if (version.equals("1.4")) + this.version = 14; + else if (version.equals("1.5")) + this.version = 15; + else + throw new Error("Unknown version of Java: " + version); + } + + /** Override the read method from the Scanner class. */ + protected int read() { + int type, saveStart = 0; + if (debug) + saveStart = start; + + if (start >= end) + return WHITESPACE; + + switch (state) { + case MID_COMMENT: + case END_COMMENT: + type = readComment(MID_COMMENT); + if (type == END_COMMENT) + state = WHITESPACE; + else + state = MID_COMMENT; + return type; + default: + char c = buffer[start]; + if (c == '\\') + c = next(); + if (c < 128) + type = kind[c]; + else + type = unikind[Character.getType(c)]; + switch (type) { + case WHITESPACE: + start = start + charlength; + charlength = 1; + while (start < end) { + c = buffer[start]; + if (c == '\\') + c = next(); + int k; + if (c < 128) + k = kind[c]; + else + k = unikind[Character.getType(c)]; + if (k != WHITESPACE) + break; + start = start + charlength; + charlength = 1; + } + break; + case UNRECOGNIZED: + case BRACKET: + case SEPARATOR: + start = start + charlength; + charlength = 1; + break; + case OPERATOR: + start = start + charlength; + charlength = 1; + type = readOperator(c); + break; + case CHARACTER: + start = start + charlength; + charlength = 1; + type = readCharLiteral(); + break; + case STRING: + start = start + charlength; + charlength = 1; + type = readStringLiteral(); + break; + case IDENTIFIER: + start = start + charlength; + charlength = 1; + while (start < end) { + c = buffer[start]; + if (c == '\\') + c = next(); + int k; + if (c < 128) + k = kind[c]; + else + k = unikind[Character.getType(c)]; + if (k != IDENTIFIER && k != NUMBER) + break; + start = start + charlength; + charlength = 1; + } + break; + case NUMBER: + start = start + charlength; + charlength = 1; + type = readNumber(c); + break; + case PUNCTUATION: + start = start + charlength; + charlength = 1; + type = readDot(); + break; + case COMMENT: + start = start + charlength; + charlength = 1; + type = readSlash(); + if (type == START_COMMENT) + state = MID_COMMENT; + break; + } + } + if (debug) { + System.out.print(TokenTypes.typeNames[type]); + System.out.println(" " + saveStart + "," + end + "(" + + (start - saveStart) + ")"); + } + return type; + } + + private int readOperator(char c) { + if (start >= end) + return OPERATOR; + char c2; + + switch (c) { + case '~': + case '?': + case ':': + break; + case '+': + case '-': + case '&': + case '|': + c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + if (c2 != c && c2 != '=') + break; + start = start + charlength; + charlength = 1; + break; + case '=': + case '*': + case '!': + case '^': + case '%': + case '/': + c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + if (c2 != '=') + break; + start = start + charlength; + charlength = 1; + break; + case '<': + case '>': + c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + if (c2 == '=') { + start = start + charlength; + charlength = 1; + } else if (c2 == c) { + start = start + charlength; + charlength = 1; + if (start >= end) + break; + char c3 = buffer[start]; + if (c3 == '\\') + c3 = next(); + if (c3 == '=') { + start = start + charlength; + charlength = 1; + } else if (c == '>' && c3 == '>') // >>> + { + start = start + charlength; + charlength = 1; + if (start >= end) + break; + char c4 = buffer[start]; + if (c4 == '\\') + c4 = next(); + if (c4 != '=') + break; + start = start + charlength; + charlength = 1; + } + } + break; + } + return OPERATOR; + } + + private int readCharLiteral() { + if (start >= end) + return bad(CHARACTER); + char c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + + switch (c2) { + case '\\': + start = start + charlength; + charlength = 1; + boolean ok = readEscapeSequence(); + if (!ok) + return bad(CHARACTER); + break; + case '\'': + case '\n': + return bad(CHARACTER); + default: + start = start + charlength; + charlength = 1; + break; + } + if (start >= end) + return bad(CHARACTER); + char c3 = buffer[start]; + if (c3 == '\\') + c3 = next(); + if (c3 != '\'') + return bad(CHARACTER); + start = start + charlength; + charlength = 1; + return CHARACTER; + } + + private int readStringLiteral() { + if (start >= end) + return bad(STRING); + char c = buffer[start]; + if (c == '\\') + c = next(); + + while (c != '"') { + switch (c) { + case '\\': + start = start + charlength; + charlength = 1; + boolean ok = readEscapeSequence(); + if (!ok) + return bad(STRING); + break; + case '\n': + return bad(STRING); + default: + start = start + charlength; + charlength = 1; + if (start >= end) + return bad(STRING); + break; + } + c = buffer[start]; + if (c == '\\') + c = next(); + } + if (c != '"') + return bad(STRING); + start = start + charlength; + charlength = 1; + return STRING; + } + + private int readSlash() { + if (start >= end) + return OPERATOR; + char c = buffer[start]; + if (c == '\\') + c = next(); + if (c == '/') { + while (c != '\n') { + start = start + charlength; + charlength = 1; + if (start >= end) + return COMMENT; + c = buffer[start]; + if (c == '\\') + c = next(); + } + start = start + charlength; + charlength = 1; + return COMMENT; + } else if (c == '*') { + start = start + charlength; + charlength = 1; + return readComment(START_COMMENT); + } + return readOperator('/'); + } + + // Read one line of a /*...*/ comment, given the expected type + int readComment(int type) { + if (start >= end) + return type; + char c = buffer[start]; + if (c == '\\') + c = next(); + + while (true) { + while (c != '*' && c != '\n') { + start = start + charlength; + charlength = 1; + if (start >= end) + return type; + c = buffer[start]; + if (c == '\\') + c = next(); + } + start = start + charlength; + charlength = 1; + if (c == '\n') + return type; + if (start >= end) + return type; + c = buffer[start]; + if (c == '\\') + c = next(); + if (c == '/') { + start = start + charlength; + charlength = 1; + if (type == START_COMMENT) { + return COMMENT; + } + return END_COMMENT; + } + } + } + + // Read a number, without checking whether it is out of range + // Doesn't deal with e.g. 0777.9 or 07779f + private int readNumber(char c) { + if (c == '0') { + int saveStart = start, saveLength = charlength; + start = start + charlength; + charlength = 1; + if (start >= end) + return NUMBER; + char c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + switch (c2) { + case 'x': + case 'X': + start = start + charlength; + charlength = 1; + boolean ok = readDigits(16); + if (!ok) + return bad(NUMBER); + readSuffix(); + return NUMBER; + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + readDigits(8); + readSuffix(); + return NUMBER; + case '.': + case 'e': + case 'E': + start = saveStart; + charlength = saveLength; + break; + case 'f': + case 'F': + case 'd': + case 'D': + start = start + charlength; + charlength = 1; + return NUMBER; + case 'l': + case 'L': + start = start + charlength; + charlength = 1; + return NUMBER; + } + } + boolean hasDigits = false; + if ('0' <= c && c <= '9') { + hasDigits = true; + readDigits(10); + if (start >= end) + return NUMBER; + c = buffer[start]; + if (c == '\\') + c = next(); + if (c == 'l' || c == 'L') { + start = start + charlength; + charlength = 1; + return NUMBER; + } + } + if (c == '.') { + start = start + charlength; + charlength = 1; + if (start >= end) + return NUMBER; + c = buffer[start]; + if (c == '\\') + c = next(); + if ('0' <= c && c <= '9') { + hasDigits = true; + readDigits(10); + if (start >= end) + return NUMBER; + c = buffer[start]; + if (c == '\\') + c = next(); + } + } + if (!hasDigits) + return bad(NUMBER); + switch (c) { + case 'e': + case 'E': + start = start + charlength; + charlength = 1; + if (start >= end) + return bad(NUMBER); + c = buffer[start]; + if (c == '\\') + c = next(); + if (c == '+' || c == '-') { + start = start + charlength; + charlength = 1; + if (start >= end) + return bad(NUMBER); + c = buffer[start]; + if (c == '\\') + c = next(); + } + readDigits(10); + break; + case 'f': + case 'F': + case 'd': + case 'D': + start = start + charlength; + charlength = 1; + return NUMBER; + } + return NUMBER; + } + + boolean readDigits(int radix) { + if (start >= end) + return false; + char c = buffer[start]; + if (c == '\\') + c = next(); + if (Character.digit(c, radix) == -1) + return false; + while (Character.digit(c, radix) != -1) { + start = start + charlength; + charlength = 1; + if (start >= end) + return true; + c = buffer[start]; + if (c == '\\') + c = next(); + } + return true; + } + + void readSuffix() { + if (start >= end) + return; + char c = buffer[start]; + if (c == '\\') + c = next(); + switch (c) { + case 'f': + case 'F': + case 'd': + case 'D': + case 'l': + case 'L': + start = start + charlength; + charlength = 1; + } + } + + private int readDot() { + if (start >= end) + return SEPARATOR; + char c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + if (Character.isDigit(c2)) { + return readNumber('.'); + } + if (start + 1 >= end || version < 15) + return SEPARATOR; + if (c2 != '.' || buffer[start + 1] != '.') + return SEPARATOR; + start = start + 2; + return SEPARATOR; + } + + private boolean readEscapeSequence() { + if (start >= end) + return false; + char c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + + switch (c2) { + case 'b': + case 't': + case 'n': + case 'f': + case 'r': + case '\"': + case '\'': + case '\\': + start = start + charlength; + charlength = 1; + return true; + case '0': + case '1': + case '2': + case '3': + return readOctal(3); + case '4': + case '5': + case '6': + case '7': + return readOctal(2); + default: + return false; + } + } + + boolean readOctal(int maxlength) { + if (start >= end) + return false; + char c = buffer[start]; + if (c == '\\') + c = next(); + + int i, val = 0; + for (i = 0; i < maxlength; i++) { + if (Character.digit(c, 8) != -1) { + val = 8 * val + Character.digit(c, 8); + start = start + charlength; + charlength = 1; + if (start >= end) + break; + c = buffer[start]; + if (c == '\\') + c = next(); + } else + break; + } + if ((i == 0) || (val > 0xFF)) + return false; + return true; + } + + // A malformed or incomplete token has a negative type + private int bad(int type) { + return -type; + } + + // Look ahead at the next character or unicode escape. + // For efficiency, replace c = next(); with + // c = buffer[start]; if (c == '\\') c = next(); + // To accept the character after looking at it, use: + // start = start + charlength; charlength = 1; + + // Record the number of source code characters used up. To deal with an odd + // or even number of backslashes preceding a unicode escape, whenever a + // second backslash is coming up, mark its position as a pair. + + private int charlength = 1; + + private int pair = 0; + + private char next() { + if (start >= end) + return 26; // EOF + char c = buffer[start]; + if (c != '\\') + return c; + if (start == pair) { + pair = 0; + return '\\'; + } + if (start + 1 >= end) + return '\\'; + + c = buffer[start + 1]; + if (c == '\\') + pair = start + 1; + if (c != 'u') + return '\\'; + + int pos = start + 2; + while (pos < end && buffer[pos] == 'u') + pos++; + if (pos + 4 > end) { + charlength = end - start; + return '\0'; + } + + c = 0; + for (int j = 0; j < 4; j++) { + int d = Character.digit(buffer[pos + j], 16); + if (d < 0) { + charlength = pos + j - start; + return '\0'; + } + c = (char) (c * 16 + d); + } + charlength = pos + 4 - start; + return c; + } + + // Override initSymbolTable + + protected void initSymbolTable() { + lookup(KEYWORD, "abstract"); + if (version >= 14) + lookup(KEYWORD, "assert"); + lookup(KEYWORD, "boolean"); + lookup(KEYWORD, "break"); + lookup(KEYWORD, "byte"); + lookup(KEYWORD, "case"); + lookup(KEYWORD, "catch"); + lookup(KEYWORD, "char"); + lookup(KEYWORD, "class"); + lookup(KEYWORD, "const"); + lookup(KEYWORD, "continue"); + lookup(KEYWORD, "default"); + lookup(KEYWORD, "do"); + lookup(KEYWORD, "double"); + lookup(KEYWORD, "else"); + if (version >= 15) + lookup(KEYWORD, "enum"); + lookup(KEYWORD, "extends"); + lookup(KEYWORD, "final"); + lookup(KEYWORD, "finally"); + lookup(KEYWORD, "float"); + lookup(KEYWORD, "for"); + lookup(KEYWORD, "goto"); + lookup(KEYWORD, "if"); + lookup(KEYWORD, "implements"); + lookup(KEYWORD, "import"); + lookup(KEYWORD, "instanceof"); + lookup(KEYWORD, "int"); + lookup(KEYWORD, "interface"); + lookup(KEYWORD, "long"); + lookup(KEYWORD, "native"); + lookup(KEYWORD, "new"); + lookup(KEYWORD, "package"); + lookup(KEYWORD, "private"); + lookup(KEYWORD, "protected"); + lookup(KEYWORD, "public"); + lookup(KEYWORD, "return"); + lookup(KEYWORD, "short"); + lookup(KEYWORD, "static"); + if (version >= 12) + lookup(KEYWORD, "strictfp"); + lookup(KEYWORD, "super"); + lookup(KEYWORD, "switch"); + lookup(KEYWORD, "synchronized"); + lookup(KEYWORD, "this"); + lookup(KEYWORD, "throw"); + lookup(KEYWORD, "throws"); + lookup(KEYWORD, "transient"); + lookup(KEYWORD, "try"); + lookup(KEYWORD, "void"); + lookup(KEYWORD, "volatile"); + lookup(KEYWORD, "while"); + + lookup(LITERAL, "true"); + lookup(LITERAL, "false"); + lookup(LITERAL, "null"); + } + + // *** Override lookup, but what about unicode escape translation? + + private Symbol temp = new Symbol(0, null); + + protected Symbol lookup(int type, String name) { + if (type != IDENTIFIER) + return super.lookup(type, name); + temp.type = KEYWORD; + temp.name = name; + Symbol sym = symbolTable.get(temp); + if (sym != null) + return sym; + temp.type = LITERAL; + sym = symbolTable.get(temp); + if (sym != null) + return sym; + return super.lookup(type, name); + } + + // Classify the ascii characters using an array of kinds, and classify all + // other unicode characters using an array indexed by unicode category. + // See the source file java/lang/Character.java for the categories. + // To find the classification of a character, use: + // if (c < 128) k = kind[c]; else k = unikind[Character.getType(c)]; + + private static final byte[] kind = new byte[128]; + + private static final byte[] unikind = new byte[31]; + + // Initialise the two classification arrays using static initializer code. + // Token types from the TokenTypes class are used to classify characters. + + private void initKind() { + for (char c = 0; c < 128; c++) + kind[c] = -1; + for (char c = 0; c < 128; c++) + switch (c) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 11: + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: + case 19: + case 20: + case 21: + case 22: + case 23: + case 24: + case 25: + case 27: + case 28: + case 29: + case 30: + case 31: + case 127: + case '#': + case '@': + case '`': + case '\\': + kind[c] = UNRECOGNIZED; + break; + case '\t': + case '\n': + case ' ': + case '\f': + case 26: + kind[c] = WHITESPACE; + break; + case '!': + case '%': + case '&': + case '*': + case '+': + case '-': + case ':': + case '<': + case '=': + case '>': + case '?': + case '^': + case '|': + case '~': + kind[c] = OPERATOR; + break; + case '"': + kind[c] = STRING; + break; + case '\'': + kind[c] = CHARACTER; + break; + case '.': + kind[c] = PUNCTUATION; + break; + case '/': + kind[c] = COMMENT; + break; + case '$': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': + kind[c] = IDENTIFIER; + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + kind[c] = NUMBER; + break; + case '(': + case ')': + case '[': + case ']': + case '{': + case '}': + kind[c] = BRACKET; + break; + case ',': + case ';': + kind[c] = SEPARATOR; + break; + } + for (char c = 0; c < 128; c++) + if (kind[c] == -1) + System.out.println("Char " + ((int) c) + " hasn't been classified"); + } + + private void initUniKind() { + for (byte b = 0; b < 31; b++) + unikind[b] = -1; + for (byte b = 0; b < 31; b++) + switch (b) { + case Character.UNASSIGNED: + case Character.ENCLOSING_MARK: + case Character.OTHER_NUMBER: + case Character.SPACE_SEPARATOR: + case Character.LINE_SEPARATOR: + case Character.PARAGRAPH_SEPARATOR: + case Character.CONTROL: + case 17: // category 17 is unused + case Character.PRIVATE_USE: + case Character.SURROGATE: + case Character.DASH_PUNCTUATION: + case Character.START_PUNCTUATION: + case Character.END_PUNCTUATION: + case Character.OTHER_PUNCTUATION: + case Character.MATH_SYMBOL: + case Character.MODIFIER_SYMBOL: + case Character.OTHER_SYMBOL: + case Character.INITIAL_QUOTE_PUNCTUATION: + case Character.FINAL_QUOTE_PUNCTUATION: + unikind[b] = UNRECOGNIZED; + break; + case Character.UPPERCASE_LETTER: + case Character.LOWERCASE_LETTER: + case Character.TITLECASE_LETTER: + case Character.MODIFIER_LETTER: + case Character.OTHER_LETTER: + case Character.LETTER_NUMBER: + case Character.CONNECTOR_PUNCTUATION: // maybe NUMBER + case Character.CURRENCY_SYMBOL: + // Characters where Other_ID_Start is true + unikind[b] = IDENTIFIER; + break; + case Character.NON_SPACING_MARK: + case Character.COMBINING_SPACING_MARK: + case Character.DECIMAL_DIGIT_NUMBER: + case Character.FORMAT: + unikind[b] = NUMBER; + break; + } + for (byte b = 0; b < 31; b++) + if (unikind[b] == -1) + System.out.println("Unicode cat " + b + " hasn't been classified"); + } + +} Added: mspsim/se/sics/mspsim/extutil/highlight/LineNumberedBorder.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/LineNumberedBorder.java (rev 0) +++ mspsim/se/sics/mspsim/extutil/highlight/LineNumberedBorder.java 2007-12-06 16:40:33 UTC (rev 39) @@ -0,0 +1,258 @@ +package se.sics.mspsim.extutil.highlight; +import java.awt.Component; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Insets; + +import javax.swing.border.AbstractBorder; + +/** + * Draws line numbers next to each line, in the same font as the text. + * Currently, this can only be used with a <tt>SyntaxHighlighter</tt> , since it + * relies on the <tt>getRows()</tt> and <tt>getLineCount()</tt> methods. A + * possible extension, create an interface to return this rows/linecount. + * + * @author Paul Durbin (Mc...@ya...) + * @created January 29, 2002 + */ +public class LineNumberedBorder extends AbstractBorder { + + private static final long serialVersionUID = -3812536735962506061L; + + /** + * The line numbers should be drawn on the left side of the component. + */ + public static int LEFT_SIDE = -2; + + /** + * The line numbers should be drawn on the right side of the component. + */ + public static int RIGHT_SIDE = -1; + + /** + * The line number should be right justified. + */ + public static int RIGHT_JUSTIFY = 0; + + /** + * The line number should be left justified. + */ + public static int LEFT_JUSTIFY = 1; + + /** + * Indicates the justification of the text of the line number. + */ + private int lineNumberJustification = RIGHT_JUSTIFY; + + /** + * Indicates the location of the line numbers, w.r.t. the component. + */ + private int location = LEFT_SIDE; + + public LineNumberedBorder(int location, int justify) { + setLocation(location); + setLineNumberJustification(justify); + } + + public Insets getBorderInsets(Component c) { + return getBorderInsets(c, new Insets(0, 0, 0, 0)); + } + + /** + * This modifies the insets, by adding space for the line number on the left. + * Should be modified to add space on the right, depending upon Locale. + * + * @param c + * Description of the Parameter + * @param insets + * Description of the Parameter + * @return The borderInsets value + */ + public Insets getBorderInsets(Component c, Insets insets) { + // if c is not a SyntaxHighlighter...nothing is done... + if (c instanceof SyntaxHighlighter) { + int width = lineNumberWidth((SyntaxHighlighter) c); + if (location == LEFT_SIDE) { + insets.left = width; + } else { + insets.right = width; + } + } + return insets; + } + + public int getLineNumberJustification() { + return lineNumberJustification; + } + + public void setLineNumberJustification(int justify) { + if (justify == RIGHT_JUSTIFY || justify == LEFT_JUSTIFY) { + lineNumberJustification = justify; + } + } + + public int getLocation() { + return location; + } + + public void setLocation(int loc) { + if (loc == RIGHT_SIDE || loc == LEFT_SIDE) { + location = loc; + } + } + + /** + * Returns the width, in pixels, of the maximum line number, plus a trailing + * space. + * + * @param textArea + * Description of the Parameter + * @return Description of the Return Value + */ + private int lineNumberWidth(SyntaxHighlighter textArea) { + // + // note: should this be changed to use all nines for the lineCount? + // for example, if the number of rows is 111...999 could be wider + // (in pixels) in a proportionally spaced font... + // + int lineCount = Math.max(textArea.getRows(), textArea.getLineCount() + 1); + return textArea.getFontMetrics(textArea.getFont()).stringWidth( + lineCount + " "); + } + + // + // NOTE: This method is called every time the cursor blinks... + // so...optimize (later and if possible) for speed... + // + public void paintBorder(Component c, Graphics g, int x, int y, int width, + int height) { + + java.awt.Rectangle clip = g.getClipBounds(); + + FontMetrics fm = g.getFontMetrics(); + int fontHeight = fm.getHeight(); + + // starting location at the "top" of the page... + // y is the starting baseline for the font... + // should "font leading" be applied? + int ybaseline = y + fm.getAscent(); + + // + // now determine if it is the "top" of the page...or somewhere else + // + int startingLineNumber = (clip.y / fontHeight) + 1; + + // + // use any one of the following if's: + // + // if (startingLineNumber != 1) + if (ybaseline < clip.y) { + // + // not within the clip rectangle...move it... + // determine how many fontHeight's there are between + // y and clip.y...then add that many fontHeights + // + ybaseline = + y + startingLineNumber * fontHeight - (fontHeight - fm.getAscent()); + } + + // + // options: + // . write the number rows in the document (current) + // . write the number of existing lines in the document (to do) + // see getLineCount() + // + + // determine which the "drawing" should end... + // add fontHeight: make sure...part of the line number is drawn + // + // could also do this by determining what the last line + // number to draw. + // then the "while" loop whould change accordingly. + // + // int yend = y + clip.height + fontHeight; + // int yend = ybaseline + height + fontHeight; // original + int yend = ybaseline + height; + if (yend > (y + height)) { + yend = y + height; + } + + SyntaxHighlighter jta = (SyntaxHighlighter) c; + int lineWidth = lineNumberWidth(jta); + + // base x position of the line number + int lnxstart = x; + if (location == LEFT_SIDE) { + // x (LEFT) or (x + lineWidth) (RIGHT) + // (depends upon justification) + if (lineNumberJustification == LEFT_JUSTIFY) { + lnxstart = x; + } else { + // RIGHT JUSTIFY + lnxstart = x + lineWidth; + } + } else { + // RIGHT SIDE + // (y + width) - lineWidth (LEFT) or (y + width) (RIGHT) + // (depends upon justification) + if (lineNumberJustification == LEFT_JUSTIFY) { + lnxstart = (y + width) - lineWidth; + } else { + // RIGHT JUSTIFY + lnxstart = (y + width); + } + } + + g.setColor(c.getForeground()); + // + // loop until out of the "visible" region... + // + int length = + ("" + Math.max(jta.getRows(), jta.getLineCount() + 1)).length(); + while (ybaseline < yend) { + // + // options: + // . left justify the line numbers + // . right justify the line numbers + // + + if (lineNumberJustification == LEFT_JUSTIFY) { + g.drawString(startingLineNumber + " ", lnxstart, ybaseline); + } else { + // right justify + String label = padLabel(startingLineNumber, length, true); + g.drawString(label, lnxstart - fm.stringWidth(label), ybaseline); + } + + ybaseline += fontHeight; + startingLineNumber++; + } + } + + // paintComponent + + /** + * Create the string for the line number. NOTE: The <tt>length</tt> param + * does not include the <em>optional</em> space added after the line number. + * + * @param lineNumber + * to stringize + * @param length + * the length desired of the string + * @param addSpace + * Description of the Parameter + * @return the line number for drawing + */ + private static String padLabel(int lineNumber, int length, boolean addSpace) { + StringBuffer buffer = new StringBuffer(); + buffer.append(lineNumber); + for (int count = (length - buffer.length()); count > 0; count--) { + buffer.insert(0, ' '); + } + if (addSpace) { + buffer.append(' '); + } + return buffer.toString(); + } +} +// LineNumberedBorder Added: mspsim/se/sics/mspsim/extutil/highlight/Scan.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/Scan.java (rev 0) +++ mspsim/se/sics/mspsim/extutil/highlight/Scan.java 2007-12-06 16:40:33 UTC (rev 39) @@ -0,0 +1,38 @@ +package se.sics.mspsim.extutil.highlight; +// Illustrate the use of the scanner by reading in a file and displaying its +// tokens. Public domain, no restrictions, Ian Holyer, University of Bristol. + +import java.io.*; + +public class Scan { + // Get the filename from the command line + public static void main(String[] args) throws IOException { + Scan program = ne... [truncated message content] |
From: <jo...@us...> - 2007-12-06 18:18:24
|
Revision: 47 http://mspsim.svn.sourceforge.net/mspsim/?rev=47&view=rev Author: joxe Date: 2007-12-06 10:18:23 -0800 (Thu, 06 Dec 2007) Log Message: ----------- added path argument to SourceViewer Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java mspsim/se/sics/mspsim/util/ControlUI.java mspsim/se/sics/mspsim/util/SourceViewer.java Modified: mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 17:44:44 UTC (rev 46) +++ mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 18:18:23 UTC (rev 47) @@ -63,7 +63,7 @@ private SyntaxHighlighter highlighter; private ArrayList<File> path = null; private JFileChooser fileChooser; - + public HighlightSourceViewer() { // } @@ -94,7 +94,7 @@ window.setVisible(isVisible); } - public void viewFile(final String filename) { + public void viewFile(final String path, final String filename) { setup(); SwingUtilities.invokeLater(new Runnable() { public void run() { @@ -182,6 +182,6 @@ public static void main(String[] args) { HighlightSourceViewer sv = new HighlightSourceViewer(); sv.setVisible(true); - sv.viewFile(args[0]); + sv.viewFile(".", args[0]); } } Modified: mspsim/se/sics/mspsim/util/ControlUI.java =================================================================== --- mspsim/se/sics/mspsim/util/ControlUI.java 2007-12-06 17:44:44 UTC (rev 46) +++ mspsim/se/sics/mspsim/util/ControlUI.java 2007-12-06 18:18:23 UTC (rev 47) @@ -182,7 +182,7 @@ DebugInfo dbg = elfData.getDebugInfo(pc); if (dbg != null) { if (sourceViewer != null) { - sourceViewer.viewFile(dbg.getFile()); + sourceViewer.viewFile(dbg.getPath(), dbg.getFile()); sourceViewer.viewLine(dbg.getLine()); } else { System.out.println("File: " + dbg.getFile()); Modified: mspsim/se/sics/mspsim/util/SourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/util/SourceViewer.java 2007-12-06 17:44:44 UTC (rev 46) +++ mspsim/se/sics/mspsim/util/SourceViewer.java 2007-12-06 18:18:23 UTC (rev 47) @@ -43,7 +43,7 @@ public interface SourceViewer { - public void viewFile(String file); + public void viewFile(String path, String file); public void viewLine(int line); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2007-12-06 23:25:10
|
Revision: 62 http://mspsim.svn.sourceforge.net/mspsim/?rev=62&view=rev Author: joxe Date: 2007-12-06 15:25:03 -0800 (Thu, 06 Dec 2007) Log Message: ----------- fixed single stepping and assembly output Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430.java mspsim/se/sics/mspsim/util/DebugUI.java Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2007-12-06 23:20:49 UTC (rev 61) +++ mspsim/se/sics/mspsim/core/MSP430.java 2007-12-06 23:25:03 UTC (rev 62) @@ -162,7 +162,12 @@ } } - instCtr++; + + int ctr = 0; + while (!emulateOP() && ctr++ < 10000) { + /* Stuck in LPM - hopefully not more than 10000 times*/ + } + if ((instCtr % 10000007) == 0 && !debug) { printCPUSpeed(reg[PC]); } @@ -171,7 +176,6 @@ execCounter[reg[PC]]++; } - emulateOP(); return cycles; } Modified: mspsim/se/sics/mspsim/util/DebugUI.java =================================================================== --- mspsim/se/sics/mspsim/util/DebugUI.java 2007-12-06 23:20:49 UTC (rev 61) +++ mspsim/se/sics/mspsim/util/DebugUI.java 2007-12-06 23:25:03 UTC (rev 62) @@ -130,7 +130,7 @@ int currentPos = pc; DbgInstruction inst; for (int i = 0, n = size; i < n; i++) { - if (cpu.getExecCount(currentPos) != 0) { + if (cpu.getExecCount(currentPos) != 0 || true) { inst = disAsm.getDbgInstruction(currentPos, cpu); inst.setPos(currentPos); currentPos += inst.getSize(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-01-14 15:03:07
|
Revision: 76 http://mspsim.svn.sourceforge.net/mspsim/?rev=76&view=rev Author: joxe Date: 2008-01-14 05:51:08 -0800 (Mon, 14 Jan 2008) Log Message: ----------- Added MapTable/MapEntry for better symbol information and changed profile API to use MapEntry instead of function names Modified Paths: -------------- mspsim/se/sics/mspsim/core/DisAsm.java mspsim/se/sics/mspsim/core/MSP430.java mspsim/se/sics/mspsim/core/Profiler.java mspsim/se/sics/mspsim/util/ControlUI.java mspsim/se/sics/mspsim/util/ELF.java mspsim/se/sics/mspsim/util/SimpleProfiler.java Added Paths: ----------- mspsim/se/sics/mspsim/util/MapEntry.java mspsim/se/sics/mspsim/util/MapTable.java Modified: mspsim/se/sics/mspsim/core/DisAsm.java =================================================================== --- mspsim/se/sics/mspsim/core/DisAsm.java 2008-01-14 13:41:29 UTC (rev 75) +++ mspsim/se/sics/mspsim/core/DisAsm.java 2008-01-14 13:51:08 UTC (rev 76) @@ -43,6 +43,7 @@ import java.io.BufferedReader; import java.io.InputStreamReader; +import se.sics.mspsim.util.MapTable; import se.sics.mspsim.util.Utils; public class DisAsm implements MSP430Constants { @@ -388,7 +389,7 @@ dbg.setRegs(regs); dbg.setInstruction(instruction, size); if (map != null) { - dbg.setFunction(map.getFunction(startPC)); + dbg.setFunction(map.getFunctionName(startPC)); } if (!step) { Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2008-01-14 13:41:29 UTC (rev 75) +++ mspsim/se/sics/mspsim/core/MSP430.java 2008-01-14 13:51:08 UTC (rev 76) @@ -120,9 +120,9 @@ if (profiler != null) { if ((instruction & 0xff80) == CALL) { /* The profiling should only be made on actual cpuCycles */ - String function = map.getFunction(reg[PC]); + MapEntry function = map.getEntry(reg[PC]); if (function == null) { - function = "fkn at $" + Utils.hex16(reg[PC]); + function = getFunction(map, reg[PC]); } profiler.profileCall(function, cpuCycles); } else if (instruction == RETURN) { @@ -181,9 +181,9 @@ if (profiler != null) { if ((instruction & 0xff80) == CALL) { /* The profiling should only be made on actual cpuCycles */ - String function = map.getFunction(reg[PC]); + MapEntry function = map.getEntry(reg[PC]); if (function == null) { - function = "fkn at $" + Utils.hex16(reg[PC]); + function = getFunction(map, reg[PC]); } profiler.profileCall(function, cpuCycles); } else if (instruction == RETURN) { @@ -193,8 +193,15 @@ } return cycles; +} + + private MapEntry getFunction(MapTable map, int address) { + MapEntry function = new MapEntry(MapEntry.TYPE.function, address, + "fkn at $" + Utils.hex16(address), null, true); + map.setEntry(function); + return function; } - + public void stop() { running = false; } Modified: mspsim/se/sics/mspsim/core/Profiler.java =================================================================== --- mspsim/se/sics/mspsim/core/Profiler.java 2008-01-14 13:41:29 UTC (rev 75) +++ mspsim/se/sics/mspsim/core/Profiler.java 2008-01-14 13:51:08 UTC (rev 76) @@ -40,18 +40,19 @@ */ package se.sics.mspsim.core; -import java.util.Arrays; -import java.util.Hashtable; +import se.sics.mspsim.util.MapEntry; -import se.sics.mspsim.util.Utils; - public interface Profiler { - public void profileCall(String function, long cycles); + public void setCPU(MSP430Core cpu); + + public void profileCall(MapEntry entry, long cycles); public void profileReturn(long cycles); public void clearProfile(); public void printProfile(); + public void printStackTrace(); + } Modified: mspsim/se/sics/mspsim/util/ControlUI.java =================================================================== --- mspsim/se/sics/mspsim/util/ControlUI.java 2008-01-14 13:41:29 UTC (rev 75) +++ mspsim/se/sics/mspsim/util/ControlUI.java 2008-01-14 13:51:08 UTC (rev 76) @@ -95,7 +95,6 @@ createButton("Debug On"); createButton("Stop"); - stepAction = new AbstractAction("Single Step") { public void actionPerformed(ActionEvent e) { ControlUI.this.cpu.step(); @@ -123,6 +122,7 @@ JButton stepButton = new JButton(stepAction); add(stepButton); + createButton("Stack Trace"); if (elf != null) { createButton("Show Source"); @@ -208,6 +208,8 @@ } } } + } else if ("Stack Trace".equals(cmd)) { + cpu.getProfiler().printStackTrace(); } dui.updateRegs(); } Modified: mspsim/se/sics/mspsim/util/ELF.java =================================================================== --- mspsim/se/sics/mspsim/util/ELF.java 2008-01-14 13:41:29 UTC (rev 75) +++ mspsim/se/sics/mspsim/util/ELF.java 2008-01-14 13:51:08 UTC (rev 76) @@ -309,16 +309,17 @@ if (sAddr > 0 && sAddr < 0x10000) { String symbolName = sn; - if (bind == ELFSection.SYMBIND_LOCAL) { - symbolName += " (" + currentFile + ')'; - } +// if (bind == ELFSection.SYMBIND_LOCAL) { +// symbolName += " (" + currentFile + ')'; +// } if ("_end".equals(symbolName)) { map.setHeapStart(sAddr); } else if ("__stack".equals(symbolName)){ map.setStackStart(sAddr); } - map.setFunctionName(sAddr, symbolName); + map.setEntry(new MapEntry(MapEntry.TYPE.function, sAddr, symbolName, currentFile, + bind == ELFSection.SYMBIND_LOCAL)); } addr += symTable.entSize; } Added: mspsim/se/sics/mspsim/util/MapEntry.java =================================================================== --- mspsim/se/sics/mspsim/util/MapEntry.java (rev 0) +++ mspsim/se/sics/mspsim/util/MapEntry.java 2008-01-14 13:51:08 UTC (rev 76) @@ -0,0 +1,107 @@ +/** + * 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 $ + * + * ----------------------------------------------------------------- + * + * MapEntry + * + * Author : Joakim Eriksson + * Created : Jan 14 2008 + * Updated : $Date: 2007/10/21 21:17:34 $ + * $Revision: 1.3 $ + */ + +package se.sics.mspsim.util; + +public class MapEntry { + + public static enum TYPE {function, variable} + + private TYPE type; + private int address; + private String name; + private String file; + private boolean isLocal; + + public MapEntry(TYPE type, int address, String name, String file, boolean isLocal) { + this.type = type; + this.address = address; + this.name = name; + this.file = file; + this.isLocal = isLocal; + } + + public TYPE getType() { + return type; + } + + public int getAddress() { + return address; + } + + public String getName() { + return name; + } + + public String getFile() { + return file; + } + + public boolean isLocal() { + return isLocal; + } + + public String getInfo() { + StringBuilder sb = new StringBuilder(); + sb.append(name); + if (file != null) { + sb.append(" ("); + if (isLocal) sb.append("local in "); + sb.append(file).append(')'); + } else if (isLocal) { + sb.append(" (local)"); + } + return sb.toString(); + } + + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append('$').append(Utils.hex16(address)).append(' ').append(type).append(' ').append(name); + if (file != null) { + sb.append(" ("); + if (isLocal) sb.append("local in "); + sb.append(file).append(')'); + } else if (isLocal) { + sb.append(" (local)"); + } + return sb.toString(); + } +} Property changes on: mspsim/se/sics/mspsim/util/MapEntry.java ___________________________________________________________________ Name: svn:executable + * Added: mspsim/se/sics/mspsim/util/MapTable.java =================================================================== --- mspsim/se/sics/mspsim/util/MapTable.java (rev 0) +++ mspsim/se/sics/mspsim/util/MapTable.java 2008-01-14 13:51:08 UTC (rev 76) @@ -0,0 +1,174 @@ +/** + * 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: MapTable.java,v 1.3 2007/10/21 21:17:34 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * MapTable + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 21:17:34 $ + * $Revision: 1.3 $ + */ + +package se.sics.mspsim.util; +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; + + +/** + * The map reader reads the map file with memory map and + * other information about the binary/firmware to load into the + * node. + * + * Format of the map file must be: + * .text WS Adress WS Size WS file + * WS Adress WS function_name + * WS Adress WS function_name + * ... + */ +public class MapTable { + + private enum Mode {NONE,CODE,DATA,BSS}; + private Mode mode; + + public int heapStartAddress = -1; + public int stackStartAddress = -1; + + private MapEntry[] entries; + + public MapTable() { + } + + public MapTable(String file) throws IOException { + loadMap(file); + } + + /** + * <code>parseMapLine</code> + * parses a line of a map file! + * @param line a <code>String</code> value + */ + public void parseMapLine(String line) { + String parts[] = line.split("\\s+"); + if (line.startsWith(".text")) { + mode = Mode.CODE; + System.out.println("CODE Mode"); + } else if (line.startsWith(".bss")) { + mode = Mode.BSS; + System.out.println("BSS Mode!"); + } else if (line.startsWith(".data")) { + mode = Mode.DATA; + System.out.println("Data Mode!"); + } else if (line.startsWith(" .text")) { + if (parts.length > 3) { + // System.out.println("Code " + parts[2] + " Name:" + parts[4]); + } + } else if (mode == Mode.CODE && line.startsWith(" ")) { + if (parts.length > 2) { + // Scrap 0x and parse as hex! + int val = Integer.parseInt(parts[1].substring(2), 16); + System.out.println("Function: " + parts[2] + " at " + + Utils.hex16(val)); + // Add the file part later some time... + // After the demo... + setEntry(new MapEntry(MapEntry.TYPE.function, val, parts[2], null, false)); + } + + } else if (line.contains(" _end = .") && parts.length > 2) { + heapStartAddress = Integer.parseInt(parts[1].substring(2), 16); + + } else if (line.contains("PROVIDE (__stack") && parts.length > 2) { + stackStartAddress = Integer.parseInt(parts[1].substring(2), 16); + } + } + + public void loadMap(String file) throws IOException { + FileInputStream fInput = new FileInputStream(file); + BufferedReader bInput = new BufferedReader(new InputStreamReader(fInput)); + String line; + while ((line = bInput.readLine()) != null) { + parseMapLine(line); + } + bInput.close(); + fInput.close(); + } + + public String getFunctionName(int address) { + if (entries != null && entries[address] != null) { + return entries[address].getName(); + } else { + return null; + } + } + + public MapEntry getEntry(int address) { + if (entries != null) + return entries[address]; + return null; + } + + // Should be any symbol... not just function... + public void setFunctionName(int address, String name) { + setEntry(new MapEntry(MapEntry.TYPE.function, address, name, null, false)); + } + + public void setEntry(MapEntry entry) { + if (entries == null) + entries = new MapEntry[0x10000]; + entries[entry.getAddress()] = entry; + } + + // Really slow way to find a specific function address!!!! + // Either reimplement this or cache in hashtable... + public int getFunctionAddress(String function) { + for (int i = 0, n = entries.length; i < n; i++) { + if (function.equals(entries[i])) { + return i; + } + } + return -1; + } + + public void setStackStart(int start) { + stackStartAddress = start; + } + + public void setHeapStart(int start) { + heapStartAddress = start; + } + + public static void main(String[] args) throws IOException { + new MapTable(args[0]); + } +} Modified: mspsim/se/sics/mspsim/util/SimpleProfiler.java =================================================================== --- mspsim/se/sics/mspsim/util/SimpleProfiler.java 2008-01-14 13:41:29 UTC (rev 75) +++ mspsim/se/sics/mspsim/util/SimpleProfiler.java 2008-01-14 13:51:08 UTC (rev 76) @@ -40,6 +40,7 @@ */ package se.sics.mspsim.util; +import se.sics.mspsim.core.MSP430Core; import se.sics.mspsim.core.Profiler; import java.util.Arrays; import java.util.Hashtable; @@ -47,27 +48,32 @@ public class SimpleProfiler implements Profiler { - private Hashtable<String,CallEntry> profileData; + private Hashtable<MapEntry,CallEntry> profileData; private CallEntry[] callStack; private int cSP = 0; + private MSP430Core cpu; public SimpleProfiler() { - profileData = new Hashtable<String,CallEntry>(); + profileData = new Hashtable<MapEntry, CallEntry>(); callStack = new CallEntry[2048]; } - public void profileCall(String function, long cycles) { -// System.out.println("Call at: " + Utils.hex16(reg[PC])); + public void setCPU(MSP430Core cpu) { + this.cpu = cpu; + } + + public void profileCall(MapEntry entry, long cycles) { +// System.out.println("Call at: " + Utils.hex16(reg[PC])); if (callStack[cSP] == null) { callStack[cSP] = new CallEntry(); } - callStack[cSP].function = function; + callStack[cSP].function = entry; callStack[cSP].calls = 0; callStack[cSP++].cycles = cycles; } public void profileReturn(long cycles) { - String fkn = callStack[--cSP].function; + MapEntry fkn = callStack[--cSP].function; // System.out.println("Profiler: return / call stack: " + cSP + ", " + fkn); long elapsed = cycles - callStack[cSP].cycles; @@ -114,8 +120,8 @@ String cyclesS = "" + entries[i].cycles; String callS = "" + c; String avgS = "" + (c > 0 ? (entries[i].cycles / c) : 0); - System.out.print(entries[i].function); - printSpace(56 - entries[i].function.length() - avgS.length()); + System.out.print(entries[i].function.getName()); + printSpace(56 - entries[i].function.getName().length() - avgS.length()); System.out.print(avgS); System.out.print(' '); printSpace(8 - callS.length()); @@ -133,17 +139,22 @@ } } - private static class CallEntry implements Comparable { - String function; + public void printStackTrace() { + System.out.println("Stack Trace: number of calls: " + cSP); + for (int i = 0; i < cSP; i++) { + System.out.println(" " + callStack[cSP - i - 1].function.getInfo()); + } + } + + private static class CallEntry implements Comparable<CallEntry> { + MapEntry function; long cycles; int calls; - public int compareTo(Object o) { - if (o instanceof CallEntry) { - long diff = ((CallEntry)o).cycles - cycles; - if (diff > 0) return 1; - if (diff < 0) return -1; - } + public int compareTo(CallEntry o) { + long diff = o.cycles - cycles; + if (diff > 0) return 1; + if (diff < 0) return -1; return 0; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-01-24 13:15:20
|
Revision: 78 http://mspsim.svn.sourceforge.net/mspsim/?rev=78&view=rev Author: joxe Date: 2008-01-24 05:12:18 -0800 (Thu, 24 Jan 2008) Log Message: ----------- Moved UI related files into package ui. Modified Paths: -------------- mspsim/se/sics/mspsim/platform/esb/ESBNode.java mspsim/se/sics/mspsim/platform/sky/SkyNode.java Added Paths: ----------- mspsim/se/sics/mspsim/ui/ mspsim/se/sics/mspsim/ui/ControlUI.java mspsim/se/sics/mspsim/ui/DebugUI.java Removed Paths: ------------- mspsim/se/sics/mspsim/util/ControlUI.java mspsim/se/sics/mspsim/util/DebugUI.java Modified: mspsim/se/sics/mspsim/platform/esb/ESBNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/esb/ESBNode.java 2008-01-14 14:06:28 UTC (rev 77) +++ mspsim/se/sics/mspsim/platform/esb/ESBNode.java 2008-01-24 13:12:18 UTC (rev 78) @@ -43,6 +43,7 @@ import java.io.IOException; import se.sics.mspsim.core.*; +import se.sics.mspsim.ui.ControlUI; import se.sics.mspsim.util.*; import se.sics.mspsim.extutil.highlight.HighlightSourceViewer; public class ESBNode implements PortListener { Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-01-14 14:06:28 UTC (rev 77) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-01-24 13:12:18 UTC (rev 78) @@ -50,7 +50,7 @@ import se.sics.mspsim.core.USART; import se.sics.mspsim.core.USARTListener; import se.sics.mspsim.extutil.highlight.HighlightSourceViewer; -import se.sics.mspsim.util.ControlUI; +import se.sics.mspsim.ui.ControlUI; import se.sics.mspsim.util.ELF; import se.sics.mspsim.util.IHexReader; import se.sics.mspsim.util.MapTable; Copied: mspsim/se/sics/mspsim/ui/ControlUI.java (from rev 76, mspsim/se/sics/mspsim/util/ControlUI.java) =================================================================== --- mspsim/se/sics/mspsim/ui/ControlUI.java (rev 0) +++ mspsim/se/sics/mspsim/ui/ControlUI.java 2008-01-24 13:12:18 UTC (rev 78) @@ -0,0 +1,222 @@ +/** + * 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: ControlUI.java,v 1.4 2007/10/21 22:19:07 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * ControlUI + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 22:19:07 $ + * $Revision: 1.4 $ + */ + +package se.sics.mspsim.ui; +import java.awt.BorderLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.KeyStroke; + +import se.sics.mspsim.core.*; +import se.sics.mspsim.util.DebugInfo; +import se.sics.mspsim.util.ELF; +import se.sics.mspsim.util.SourceViewer; +import se.sics.mspsim.util.StackUI; +import se.sics.mspsim.util.WindowUtils; + +public class ControlUI extends JPanel implements ActionListener { + + private static final String TITLE = "MSPSim monitor"; + + private JFrame window; + private MSP430 cpu; + private DebugUI dui; + private JFrame stackWindow; + private StackUI stackUI; + + private ELF elfData; + private SourceViewer sourceViewer; + + private Action stepAction; + + public ControlUI(MSP430 cpu) { + this(cpu, null); + } + + public ControlUI(MSP430 cpu, ELF elf) { + super(new GridLayout(0, 1)); + this.cpu = cpu; + + this.stackUI = new StackUI(cpu); + stackWindow = new JFrame("Stack"); + stackWindow.add(this.stackUI); + WindowUtils.restoreWindowBounds("StackUI", stackWindow); + WindowUtils.addSaveOnShutdown("StackUI", stackWindow); + stackWindow.setVisible(true); + + window = new JFrame(TITLE); +// window.setSize(320,240); + window.setLayout(new BorderLayout()); + window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + window.add(this, BorderLayout.WEST); + window.add(dui = new DebugUI(cpu), BorderLayout.CENTER); + + createButton("Debug On"); + createButton("Stop"); + stepAction = new AbstractAction("Single Step") { + public void actionPerformed(ActionEvent e) { + ControlUI.this.cpu.step(); + dui.updateRegs(); + dui.repaint(); + if (elfData != null && sourceViewer != null + && sourceViewer.isVisible()) { + int pc = ControlUI.this.cpu.readRegister(MSP430Constants.PC); + DebugInfo dbg = elfData.getDebugInfo(pc); + if (dbg != null) { + if (ControlUI.this.cpu.getDebug()) { + System.out.println("looking up $" + Integer.toString(pc, 16) + + " => " + dbg.getFile() + ':' + + dbg.getLine()); + } + sourceViewer.viewFile(dbg.getPath(), dbg.getFile()); + sourceViewer.viewLine(dbg.getLine()); + } + } + } + }; + stepAction.putValue(Action.MNEMONIC_KEY, + new Integer(KeyEvent.VK_S)); + stepAction.setEnabled(false); + + JButton stepButton = new JButton(stepAction); + add(stepButton); + createButton("Stack Trace"); + + if (elf != null) { + createButton("Show Source"); + } + createButton("Profile Dump"); + + // Setup standard actions + stepButton.getInputMap(WHEN_IN_FOCUSED_WINDOW) + .put(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK), + "cpuStep"); + stepButton.getActionMap().put("cpuStep", stepAction); + + WindowUtils.restoreWindowBounds("ControlUI", window); + WindowUtils.addSaveOnShutdown("ControlUI", window); + window.setVisible(true); + elfData = elf; + } + + public void setSourceViewer(SourceViewer viewer) { + sourceViewer = viewer; + } + + + private JButton createButton(String text) { + JButton jb = new JButton(text); + jb.addActionListener(this); + add(jb); + return jb; + } + + private void updateCPUPercent() { + window.setTitle(TITLE + " CPU On: " + cpu.getCPUPercent() + "%"); + } + + public void actionPerformed(ActionEvent ae) { + String cmd = ae.getActionCommand(); + updateCPUPercent(); + if ("Debug On".equals(cmd)) { + cpu.setDebug(true); + ((JButton) ae.getSource()).setText("Debug Off"); + + } else if ("Debug Off".equals(cmd)) { + cpu.setDebug(false); + ((JButton) ae.getSource()).setText("Debug On"); + + } else if ("Run".equals(cmd)) { + new Thread(new Runnable() { + public void run() { + cpu.cpuloop(); + }}).start(); + ((JButton) ae.getSource()).setText("Stop"); + stepAction.setEnabled(false); + + } else if ("Stop".equals(cmd)) { + cpu.stop(); + ((JButton) ae.getSource()).setText("Run"); + stepAction.setEnabled(true); + + } else if ("Profile Dump".equals(cmd)) { + if (cpu.getProfiler() != null) { + cpu.getProfiler().printProfile(); + } else { + System.out.println("*** No profiler available"); + } + // } else if ("Single Step".equals(cmd)) { + // cpu.step(); +// dui.repaint(); + } else if ("Show Source".equals(cmd)) { + int pc = cpu.readRegister(cpu.PC); + if (elfData != null) { + DebugInfo dbg = elfData.getDebugInfo(pc); + if (dbg != null) { + if (cpu.getDebug()) { + System.out.println("looking up $" + Integer.toString(pc, 16) + + " => " + dbg.getFile() + ':' + dbg.getLine()); + } + if (sourceViewer != null) { + sourceViewer.viewFile(dbg.getPath(), dbg.getFile()); + sourceViewer.viewLine(dbg.getLine()); + } else { + System.out.println("File: " + dbg.getFile()); + System.out.println("LineNr: " + dbg.getLine()); + } + } + } + } else if ("Stack Trace".equals(cmd)) { + cpu.getProfiler().printStackTrace(); + } + dui.updateRegs(); + } + +} Copied: mspsim/se/sics/mspsim/ui/DebugUI.java (from rev 74, mspsim/se/sics/mspsim/util/DebugUI.java) =================================================================== --- mspsim/se/sics/mspsim/ui/DebugUI.java (rev 0) +++ mspsim/se/sics/mspsim/ui/DebugUI.java 2008-01-24 13:12:18 UTC (rev 78) @@ -0,0 +1,215 @@ +/** + * 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: DebugUI.java,v 1.3 2007/10/21 21:17:34 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * DebugUI + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 21:17:34 $ + * $Revision: 1.3 $ + */ + +package se.sics.mspsim.ui; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Font; +import java.awt.GridLayout; +import javax.swing.AbstractListModel; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.ListCellRenderer; + +import se.sics.mspsim.core.*; +import se.sics.mspsim.util.Utils; + +public class DebugUI extends JPanel { + + private JList disList; + private JLabel[] regsLabel; + private MSP430 cpu; + private DbgListModel listModel; + private int currentAddress = 0; + + private DisAsm disAsm; + + /** + * Creates a new <code>DebugUI</code> instance. + * + */ + public DebugUI(MSP430 cpu) { + this(cpu, true); + } + + public DebugUI(MSP430 cpu, boolean showRegs) { + super(new BorderLayout()); + this.cpu = cpu; + disAsm = cpu.getDisAsm(); + + disList = new JList(listModel = new DbgListModel()); + disList.setFont(new Font("courier", 0, 12)); + disList.setCellRenderer(new MyCellRenderer()); + add(disList, BorderLayout.CENTER); + + if (showRegs) { + JPanel regs = new JPanel(new GridLayout(2,8,4,0)); + regsLabel = new JLabel[16]; + for (int i = 0, n = 16; i < n; i++) { + regs.add(regsLabel[i] = new JLabel("$0000")); + } + add(regs, BorderLayout.SOUTH); + updateRegs(); + } + } + + public void updateRegs() { + if (regsLabel != null) { + for (int i = 0, n = 16; i < n; i++) { + regsLabel[i].setText("$" + Utils.hex16(cpu.reg[i])); + } + } + repaint(); + } + + private class DbgListModel extends AbstractListModel { + int startPos = -1; + int endPos = -1; + final int size = 21; + + DbgInstruction[] instructions = new DbgInstruction[size]; + + // 64K Dbg instructions... + private DbgInstruction[] instrs = new DbgInstruction[0x10000]; + + public void setCurrentAddress(int address) { + startPos = address; + } + + // ------------------------------------------------------------------- + // ListAPI + // ------------------------------------------------------------------- + + public int getSize() { + return size; + } + + private void checkPC() { + int pc = cpu.reg[cpu.PC]; + if (pc < startPos || pc > endPos) { + startPos = pc; + // recalulate index!!! with PC at the top of the "page" + int currentPos = pc; + DbgInstruction inst; + for (int i = 0, n = size; i < n; i++) { + if (cpu.getExecCount(currentPos) != 0 || true) { + inst = disAsm.getDbgInstruction(currentPos, cpu); + inst.setPos(currentPos); + currentPos += inst.getSize(); + } else { + inst = new DbgInstruction(); + inst.setASMLine(" " + Utils.hex16(currentPos) + " " + + Utils.hex8(cpu.memory[currentPos]) + " " + + Utils.hex8(cpu.memory[currentPos + 1]) + + " .word " + Utils.hex8(cpu.memory[currentPos]) + + Utils.hex8(cpu.memory[currentPos + 1])); + inst.setPos(currentPos); + currentPos += 2; + } + instructions[i] = inst; + } + endPos = currentPos; + } + } + + // Should cache the current 20 (or size) instructions to get a faster + // version of this... + // And have a call to "update" instead... + public Object getElementAt(int index) { + checkPC(); + return instructions[index]; + } + } + + class MyCellRenderer extends JLabel implements ListCellRenderer { + + public MyCellRenderer() { + setOpaque(true); + } + + public Component getListCellRendererComponent( + JList list, + Object value, // value to display + int index, // cell index + boolean isSelected, // is the cell selected + boolean cellHasFocus) // the list and the cell have the focus + { + String s; + int pos = 0; + if (value == null) { + s = "---"; + } else { + if (value instanceof DbgInstruction) { + DbgInstruction i = (DbgInstruction) value; + s = i.getASMLine(false); + if (i.getFunction() != null) { + s += "; " + i.getFunction(); + } + pos = i.getPos(); + if (cpu.hasBreakpoint(pos)) { + s = "*B " + s; + } else { + s = " " + s; + } + } else { + s = value.toString(); + } + } + setText(s); + if (pos == cpu.reg[cpu.PC]) { + setBackground(Color.green); + } else { + if (isSelected) { + setBackground(list.getSelectionBackground()); + setForeground(list.getSelectionForeground()); + } else { + setBackground(list.getBackground()); + setForeground(list.getForeground()); + } + } + setEnabled(list.isEnabled()); + setFont(list.getFont()); + return this; + } + } +} Deleted: mspsim/se/sics/mspsim/util/ControlUI.java =================================================================== --- mspsim/se/sics/mspsim/util/ControlUI.java 2008-01-14 14:06:28 UTC (rev 77) +++ mspsim/se/sics/mspsim/util/ControlUI.java 2008-01-24 13:12:18 UTC (rev 78) @@ -1,217 +0,0 @@ -/** - * 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: ControlUI.java,v 1.4 2007/10/21 22:19:07 nfi Exp $ - * - * ----------------------------------------------------------------- - * - * ControlUI - * - * Author : Joakim Eriksson - * Created : Sun Oct 21 22:00:00 2007 - * Updated : $Date: 2007/10/21 22:19:07 $ - * $Revision: 1.4 $ - */ - -package se.sics.mspsim.util; -import java.awt.BorderLayout; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.KeyStroke; - -import se.sics.mspsim.core.*; - -public class ControlUI extends JPanel implements ActionListener { - - private static final String TITLE = "MSPSim monitor"; - - private JFrame window; - private MSP430 cpu; - private DebugUI dui; - private JFrame stackWindow; - private StackUI stackUI; - - private ELF elfData; - private SourceViewer sourceViewer; - - private Action stepAction; - - public ControlUI(MSP430 cpu) { - this(cpu, null); - } - - public ControlUI(MSP430 cpu, ELF elf) { - super(new GridLayout(0, 1)); - this.cpu = cpu; - - this.stackUI = new StackUI(cpu); - stackWindow = new JFrame("Stack"); - stackWindow.add(this.stackUI); - WindowUtils.restoreWindowBounds("StackUI", stackWindow); - WindowUtils.addSaveOnShutdown("StackUI", stackWindow); - stackWindow.setVisible(true); - - window = new JFrame(TITLE); -// window.setSize(320,240); - window.setLayout(new BorderLayout()); - window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - window.add(this, BorderLayout.WEST); - window.add(dui = new DebugUI(cpu), BorderLayout.CENTER); - - createButton("Debug On"); - createButton("Stop"); - stepAction = new AbstractAction("Single Step") { - public void actionPerformed(ActionEvent e) { - ControlUI.this.cpu.step(); - dui.updateRegs(); - dui.repaint(); - if (elfData != null && sourceViewer != null - && sourceViewer.isVisible()) { - int pc = ControlUI.this.cpu.readRegister(MSP430Constants.PC); - DebugInfo dbg = elfData.getDebugInfo(pc); - if (dbg != null) { - if (ControlUI.this.cpu.getDebug()) { - System.out.println("looking up $" + Integer.toString(pc, 16) + - " => " + dbg.getFile() + ':' + - dbg.getLine()); - } - sourceViewer.viewFile(dbg.getPath(), dbg.getFile()); - sourceViewer.viewLine(dbg.getLine()); - } - } - } - }; - stepAction.putValue(Action.MNEMONIC_KEY, - new Integer(KeyEvent.VK_S)); - stepAction.setEnabled(false); - - JButton stepButton = new JButton(stepAction); - add(stepButton); - createButton("Stack Trace"); - - if (elf != null) { - createButton("Show Source"); - } - createButton("Profile Dump"); - - // Setup standard actions - stepButton.getInputMap(WHEN_IN_FOCUSED_WINDOW) - .put(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK), - "cpuStep"); - stepButton.getActionMap().put("cpuStep", stepAction); - - WindowUtils.restoreWindowBounds("ControlUI", window); - WindowUtils.addSaveOnShutdown("ControlUI", window); - window.setVisible(true); - elfData = elf; - } - - public void setSourceViewer(SourceViewer viewer) { - sourceViewer = viewer; - } - - - private JButton createButton(String text) { - JButton jb = new JButton(text); - jb.addActionListener(this); - add(jb); - return jb; - } - - private void updateCPUPercent() { - window.setTitle(TITLE + " CPU On: " + cpu.getCPUPercent() + "%"); - } - - public void actionPerformed(ActionEvent ae) { - String cmd = ae.getActionCommand(); - updateCPUPercent(); - if ("Debug On".equals(cmd)) { - cpu.setDebug(true); - ((JButton) ae.getSource()).setText("Debug Off"); - - } else if ("Debug Off".equals(cmd)) { - cpu.setDebug(false); - ((JButton) ae.getSource()).setText("Debug On"); - - } else if ("Run".equals(cmd)) { - new Thread(new Runnable() { - public void run() { - cpu.cpuloop(); - }}).start(); - ((JButton) ae.getSource()).setText("Stop"); - stepAction.setEnabled(false); - - } else if ("Stop".equals(cmd)) { - cpu.stop(); - ((JButton) ae.getSource()).setText("Run"); - stepAction.setEnabled(true); - - } else if ("Profile Dump".equals(cmd)) { - if (cpu.getProfiler() != null) { - cpu.getProfiler().printProfile(); - } else { - System.out.println("*** No profiler available"); - } - // } else if ("Single Step".equals(cmd)) { - // cpu.step(); -// dui.repaint(); - } else if ("Show Source".equals(cmd)) { - int pc = cpu.readRegister(cpu.PC); - if (elfData != null) { - DebugInfo dbg = elfData.getDebugInfo(pc); - if (dbg != null) { - if (cpu.getDebug()) { - System.out.println("looking up $" + Integer.toString(pc, 16) + - " => " + dbg.getFile() + ':' + dbg.getLine()); - } - if (sourceViewer != null) { - sourceViewer.viewFile(dbg.getPath(), dbg.getFile()); - sourceViewer.viewLine(dbg.getLine()); - } else { - System.out.println("File: " + dbg.getFile()); - System.out.println("LineNr: " + dbg.getLine()); - } - } - } - } else if ("Stack Trace".equals(cmd)) { - cpu.getProfiler().printStackTrace(); - } - dui.updateRegs(); - } - -} Deleted: mspsim/se/sics/mspsim/util/DebugUI.java =================================================================== --- mspsim/se/sics/mspsim/util/DebugUI.java 2008-01-14 14:06:28 UTC (rev 77) +++ mspsim/se/sics/mspsim/util/DebugUI.java 2008-01-24 13:12:18 UTC (rev 78) @@ -1,214 +0,0 @@ -/** - * 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: DebugUI.java,v 1.3 2007/10/21 21:17:34 nfi Exp $ - * - * ----------------------------------------------------------------- - * - * DebugUI - * - * Author : Joakim Eriksson - * Created : Sun Oct 21 22:00:00 2007 - * Updated : $Date: 2007/10/21 21:17:34 $ - * $Revision: 1.3 $ - */ - -package se.sics.mspsim.util; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Font; -import java.awt.GridLayout; -import javax.swing.AbstractListModel; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.ListCellRenderer; - -import se.sics.mspsim.core.*; - -public class DebugUI extends JPanel { - - private JList disList; - private JLabel[] regsLabel; - private MSP430 cpu; - private DbgListModel listModel; - private int currentAddress = 0; - - private DisAsm disAsm; - - /** - * Creates a new <code>DebugUI</code> instance. - * - */ - public DebugUI(MSP430 cpu) { - this(cpu, true); - } - - public DebugUI(MSP430 cpu, boolean showRegs) { - super(new BorderLayout()); - this.cpu = cpu; - disAsm = cpu.getDisAsm(); - - disList = new JList(listModel = new DbgListModel()); - disList.setFont(new Font("courier", 0, 12)); - disList.setCellRenderer(new MyCellRenderer()); - add(disList, BorderLayout.CENTER); - - if (showRegs) { - JPanel regs = new JPanel(new GridLayout(2,8,4,0)); - regsLabel = new JLabel[16]; - for (int i = 0, n = 16; i < n; i++) { - regs.add(regsLabel[i] = new JLabel("$0000")); - } - add(regs, BorderLayout.SOUTH); - updateRegs(); - } - } - - public void updateRegs() { - if (regsLabel != null) { - for (int i = 0, n = 16; i < n; i++) { - regsLabel[i].setText("$" + Utils.hex16(cpu.reg[i])); - } - } - repaint(); - } - - private class DbgListModel extends AbstractListModel { - int startPos = -1; - int endPos = -1; - final int size = 21; - - DbgInstruction[] instructions = new DbgInstruction[size]; - - // 64K Dbg instructions... - private DbgInstruction[] instrs = new DbgInstruction[0x10000]; - - public void setCurrentAddress(int address) { - startPos = address; - } - - // ------------------------------------------------------------------- - // ListAPI - // ------------------------------------------------------------------- - - public int getSize() { - return size; - } - - private void checkPC() { - int pc = cpu.reg[cpu.PC]; - if (pc < startPos || pc > endPos) { - startPos = pc; - // recalulate index!!! with PC at the top of the "page" - int currentPos = pc; - DbgInstruction inst; - for (int i = 0, n = size; i < n; i++) { - if (cpu.getExecCount(currentPos) != 0 || true) { - inst = disAsm.getDbgInstruction(currentPos, cpu); - inst.setPos(currentPos); - currentPos += inst.getSize(); - } else { - inst = new DbgInstruction(); - inst.setASMLine(" " + Utils.hex16(currentPos) + " " + - Utils.hex8(cpu.memory[currentPos]) + " " + - Utils.hex8(cpu.memory[currentPos + 1]) + - " .word " + Utils.hex8(cpu.memory[currentPos]) + - Utils.hex8(cpu.memory[currentPos + 1])); - inst.setPos(currentPos); - currentPos += 2; - } - instructions[i] = inst; - } - endPos = currentPos; - } - } - - // Should cache the current 20 (or size) instructions to get a faster - // version of this... - // And have a call to "update" instead... - public Object getElementAt(int index) { - checkPC(); - return instructions[index]; - } - } - - class MyCellRenderer extends JLabel implements ListCellRenderer { - - public MyCellRenderer() { - setOpaque(true); - } - - public Component getListCellRendererComponent( - JList list, - Object value, // value to display - int index, // cell index - boolean isSelected, // is the cell selected - boolean cellHasFocus) // the list and the cell have the focus - { - String s; - int pos = 0; - if (value == null) { - s = "---"; - } else { - if (value instanceof DbgInstruction) { - DbgInstruction i = (DbgInstruction) value; - s = i.getASMLine(false); - if (i.getFunction() != null) { - s += "; " + i.getFunction(); - } - pos = i.getPos(); - if (cpu.hasBreakpoint(pos)) { - s = "*B " + s; - } else { - s = " " + s; - } - } else { - s = value.toString(); - } - } - setText(s); - if (pos == cpu.reg[cpu.PC]) { - setBackground(Color.green); - } else { - if (isSelected) { - setBackground(list.getSelectionBackground()); - setForeground(list.getSelectionForeground()); - } else { - setBackground(list.getBackground()); - setForeground(list.getForeground()); - } - } - setEnabled(list.isEnabled()); - setFont(list.getFont()); - return this; - } - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-01-24 13:43:39
|
Revision: 79 http://mspsim.svn.sourceforge.net/mspsim/?rev=79&view=rev Author: joxe Date: 2008-01-24 05:40:29 -0800 (Thu, 24 Jan 2008) Log Message: ----------- moved some more UI related files into the ui package. Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java mspsim/se/sics/mspsim/platform/esb/ESBGui.java mspsim/se/sics/mspsim/platform/sky/SkyGui.java mspsim/se/sics/mspsim/ui/ControlUI.java Added Paths: ----------- mspsim/se/sics/mspsim/ui/SerialMon.java mspsim/se/sics/mspsim/ui/SourceViewer.java mspsim/se/sics/mspsim/ui/WindowUtils.java Removed Paths: ------------- mspsim/se/sics/mspsim/util/SerialMon.java mspsim/se/sics/mspsim/util/SourceViewer.java mspsim/se/sics/mspsim/util/WindowUtils.java Modified: mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2008-01-24 13:12:18 UTC (rev 78) +++ mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2008-01-24 13:40:29 UTC (rev 79) @@ -52,8 +52,8 @@ import javax.swing.JScrollPane; import javax.swing.SwingUtilities; -import se.sics.mspsim.util.SourceViewer; -import se.sics.mspsim.util.WindowUtils; +import se.sics.mspsim.ui.SourceViewer; +import se.sics.mspsim.ui.WindowUtils; /** * Modified: mspsim/se/sics/mspsim/platform/esb/ESBGui.java =================================================================== --- mspsim/se/sics/mspsim/platform/esb/ESBGui.java 2008-01-24 13:12:18 UTC (rev 78) +++ mspsim/se/sics/mspsim/platform/esb/ESBGui.java 2008-01-24 13:40:29 UTC (rev 79) @@ -54,8 +54,8 @@ import se.sics.mspsim.chip.Beeper; import se.sics.mspsim.core.*; -import se.sics.mspsim.util.SerialMon; -import se.sics.mspsim.util.WindowUtils; +import se.sics.mspsim.ui.SerialMon; +import se.sics.mspsim.ui.WindowUtils; public class ESBGui extends JComponent implements KeyListener, MouseMotionListener, Modified: mspsim/se/sics/mspsim/platform/sky/SkyGui.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyGui.java 2008-01-24 13:12:18 UTC (rev 78) +++ mspsim/se/sics/mspsim/platform/sky/SkyGui.java 2008-01-24 13:40:29 UTC (rev 79) @@ -52,8 +52,8 @@ import javax.swing.JFrame; import se.sics.mspsim.core.*; -import se.sics.mspsim.util.SerialMon; -import se.sics.mspsim.util.WindowUtils; +import se.sics.mspsim.ui.SerialMon; +import se.sics.mspsim.ui.WindowUtils; public class SkyGui extends JComponent implements KeyListener { Modified: mspsim/se/sics/mspsim/ui/ControlUI.java =================================================================== --- mspsim/se/sics/mspsim/ui/ControlUI.java 2008-01-24 13:12:18 UTC (rev 78) +++ mspsim/se/sics/mspsim/ui/ControlUI.java 2008-01-24 13:40:29 UTC (rev 79) @@ -56,9 +56,7 @@ import se.sics.mspsim.core.*; import se.sics.mspsim.util.DebugInfo; import se.sics.mspsim.util.ELF; -import se.sics.mspsim.util.SourceViewer; import se.sics.mspsim.util.StackUI; -import se.sics.mspsim.util.WindowUtils; public class ControlUI extends JPanel implements ActionListener { Copied: mspsim/se/sics/mspsim/ui/SerialMon.java (from rev 74, mspsim/se/sics/mspsim/util/SerialMon.java) =================================================================== --- mspsim/se/sics/mspsim/ui/SerialMon.java (rev 0) +++ mspsim/se/sics/mspsim/ui/SerialMon.java 2008-01-24 13:40:29 UTC (rev 79) @@ -0,0 +1,152 @@ +/** + * 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: SerialMon.java,v 1.4 2007/10/21 22:19:07 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * SerialMon + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 22:19:07 $ + * $Revision: 1.4 $ + */ + +package se.sics.mspsim.ui; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.SwingUtilities; + +import se.sics.mspsim.core.*; + +public class SerialMon implements KeyListener, USARTListener { + + private static final String PREFIX = " > "; + + private String name; + private JFrame window; + private USART usart; + private JTextArea textArea; + private JLabel statusLabel; + private String text = "*** Serial mon for ESB/MSPsim ***\n"; + + private int lines = 1; + private boolean isUpdatePending = false; + private StringBuilder keyBuffer = new StringBuilder(); + + public SerialMon(USART usart, String name) { + this.name = name; + this.usart = usart; + window = new JFrame(name); +// window.setBounds(100, 100, 400,340); + window.add(new JScrollPane(textArea = new JTextArea(20, 40), + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), + BorderLayout.CENTER); + textArea.setText(text); + textArea.setEditable(false); + statusLabel = new JLabel(PREFIX); + keyBuffer.append(PREFIX); + statusLabel.setOpaque(true); + statusLabel.setBackground(Color.lightGray); + window.add(statusLabel, BorderLayout.SOUTH); + String key = "usart." + name; + WindowUtils.restoreWindowBounds(key, window); + WindowUtils.addSaveOnShutdown(key, window); + window.setVisible(true); + + textArea.addKeyListener(this); + } + + public void saveWindowBounds() { + WindowUtils.saveWindowBounds("usart." + name, window); + } + + public void dataReceived(USART source, int data) { + if (data == '\n') { + if (lines >= 60) { + int index = text.indexOf('\n'); + text = text.substring(index + 1); + } else { + lines++; + } + } + text += (char)data; + + // Collapse several immediate updates + if (!isUpdatePending) { + isUpdatePending = true; + SwingUtilities.invokeLater(new Runnable() { + public void run() { + isUpdatePending = false; + + final String newText = text; + textArea.setText(newText); + textArea.setCaretPosition(newText.length()); + textArea.repaint(); + } + }); + } + } + + + // ------------------------------------------------------------------- + // KeyListener + // ------------------------------------------------------------------- + + public void keyPressed(KeyEvent key) { + } + + public void keyReleased(KeyEvent key) { + } + + 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); + } else { + keyBuffer.append(c); + statusLabel.setText(keyBuffer.toString()); + } + } + +} Copied: mspsim/se/sics/mspsim/ui/SourceViewer.java (from rev 74, mspsim/se/sics/mspsim/util/SourceViewer.java) =================================================================== --- mspsim/se/sics/mspsim/ui/SourceViewer.java (rev 0) +++ mspsim/se/sics/mspsim/ui/SourceViewer.java 2008-01-24 13:40:29 UTC (rev 79) @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2007, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * + * ----------------------------------------------------------------- + * + * Source Viewer + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 22:02:22 $ + * $Revision: 1.4 $ + */ + +package se.sics.mspsim.ui; + + +public interface SourceViewer { + + public boolean isVisible(); + public void viewFile(String path, String file); + public void viewLine(int line); + +} Copied: mspsim/se/sics/mspsim/ui/WindowUtils.java (from rev 74, mspsim/se/sics/mspsim/util/WindowUtils.java) =================================================================== --- mspsim/se/sics/mspsim/ui/WindowUtils.java (rev 0) +++ mspsim/se/sics/mspsim/ui/WindowUtils.java 2008-01-24 13:40:29 UTC (rev 79) @@ -0,0 +1,213 @@ +/** + * 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: WindowUtils.java,v 1.2 2007/10/21 20:50:26 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * WindowUtils + * + * Author : Joakim Eriksson, Niclas Finne, Fredrik \xD6sterlind + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 20:50:26 $ + * $Revision: 1.2 $ + */ + +package se.sics.mspsim.ui; +import java.awt.Window; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.prefs.Preferences; + +public class WindowUtils { + + private static Preferences prefs = + Preferences.userNodeForPackage(WindowUtils.class); + + private static Hashtable<Window,CloseListener> closeTable; + private static Hashtable<Window,String> exitTable; + + private WindowUtils() { + } + + public static void saveWindowBounds(String key, Window window) { + putWindowBounds(key, window); + try { + prefs.flush(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static void putWindowBounds(String key, Window window) { + prefs.put("window." + key + ".bounds", getBounds(window)); + } + + public static void restoreWindowBounds(String key, Window window) { + setBounds(window, prefs.get("window." + key + ".bounds", null)); + } + + private static String getBounds(Window window) { + return "" + window.getX() + + ',' + window.getY() + + ',' + window.getWidth() + + ',' + window.getHeight(); + } + + private static void setBounds(Window window, String bounds) { + String[] b; + if ((bounds != null) + && ((b = bounds.split(",")) != null) + && b.length == 4) { + try { + window.setBounds(Integer.parseInt(b[0]), + Integer.parseInt(b[1]), + Integer.parseInt(b[2]), + Integer.parseInt(b[3])); + } catch (Exception e) { + e.printStackTrace(); + window.pack(); + } + } else { + window.pack(); + } + } + + public static void clearState() { + try { + prefs.clear(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public synchronized static void addSaveOnClose(String key, Window window) { + if (closeTable == null) { + closeTable = new Hashtable<Window,CloseListener>(); + } + if (closeTable.get(window) == null) { + CloseListener c = new CloseListener(key); + window.addWindowListener(c); + closeTable.put(window, c); + } + } + + public synchronized static void removeSaveOnClose(Window window) { + if (closeTable != null) { + CloseListener c = closeTable.remove(window); + if (c != null) { + window.removeWindowListener(c); + } + } + } + + public synchronized static void addSaveOnShutdown(String key, Window window) { + if (exitTable == null) { + exitTable = new Hashtable<Window,String>(); + Runtime.getRuntime().addShutdownHook(new ShutdownHandler()); + } + exitTable.put(window, key); + } + + public synchronized static void removeSaveOnShutdown(Window window) { + if (exitTable != null) { + exitTable.remove(window); + } + } + + + + // ------------------------------------------------------------------- + // Main + // ------------------------------------------------------------------- + + public static void main(String[] args) { + if (args.length != 1 || !args[0].equals("-clearState")) { + System.err.println("Usage: WindowUtils -clearState"); + System.exit(1); + } + clearState(); + } + + + // ------------------------------------------------------------------- + // CloseListener + // ------------------------------------------------------------------- + + private static class CloseListener extends WindowAdapter { + + private String key; + + public CloseListener(String key) { + this.key = key; + } + + public void windowClosing(WindowEvent e) { + Window source = (Window) e.getSource(); + saveWindowBounds(key, source); + source.removeWindowListener(this); + closeTable.remove(source); + } + + } + + + // ------------------------------------------------------------------- + // Shutdown handler + // ------------------------------------------------------------------- + + private static class ShutdownHandler extends Thread { + + public ShutdownHandler() { + super("WindowUtils-Shutdown"); + } + + public void run() { + Hashtable<Window,String> table = exitTable; + if (table != null && table.size() > 0) { + exitTable = null; + + Enumeration<Window> e = table.keys(); + while(e.hasMoreElements()) { + Window w = e.nextElement(); + putWindowBounds(table.get(w), w); + } + try { + prefs.flush(); + } catch (Exception e2) { + e2.printStackTrace(); + } + } + } + + } + +} // WindowUtils Deleted: mspsim/se/sics/mspsim/util/SerialMon.java =================================================================== --- mspsim/se/sics/mspsim/util/SerialMon.java 2008-01-24 13:12:18 UTC (rev 78) +++ mspsim/se/sics/mspsim/util/SerialMon.java 2008-01-24 13:40:29 UTC (rev 79) @@ -1,152 +0,0 @@ -/** - * 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: SerialMon.java,v 1.4 2007/10/21 22:19:07 nfi Exp $ - * - * ----------------------------------------------------------------- - * - * SerialMon - * - * Author : Joakim Eriksson - * Created : Sun Oct 21 22:00:00 2007 - * Updated : $Date: 2007/10/21 22:19:07 $ - * $Revision: 1.4 $ - */ - -package se.sics.mspsim.util; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; -import javax.swing.SwingUtilities; - -import se.sics.mspsim.core.*; - -public class SerialMon implements KeyListener, USARTListener { - - private static final String PREFIX = " > "; - - private String name; - private JFrame window; - private USART usart; - private JTextArea textArea; - private JLabel statusLabel; - private String text = "*** Serial mon for ESB/MSPsim ***\n"; - - private int lines = 1; - private boolean isUpdatePending = false; - private StringBuilder keyBuffer = new StringBuilder(); - - public SerialMon(USART usart, String name) { - this.name = name; - this.usart = usart; - window = new JFrame(name); -// window.setBounds(100, 100, 400,340); - window.add(new JScrollPane(textArea = new JTextArea(20, 40), - JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, - JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), - BorderLayout.CENTER); - textArea.setText(text); - textArea.setEditable(false); - statusLabel = new JLabel(PREFIX); - keyBuffer.append(PREFIX); - statusLabel.setOpaque(true); - statusLabel.setBackground(Color.lightGray); - window.add(statusLabel, BorderLayout.SOUTH); - String key = "usart." + name; - WindowUtils.restoreWindowBounds(key, window); - WindowUtils.addSaveOnShutdown(key, window); - window.setVisible(true); - - textArea.addKeyListener(this); - } - - public void saveWindowBounds() { - WindowUtils.saveWindowBounds("usart." + name, window); - } - - public void dataReceived(USART source, int data) { - if (data == '\n') { - if (lines >= 60) { - int index = text.indexOf('\n'); - text = text.substring(index + 1); - } else { - lines++; - } - } - text += (char)data; - - // Collapse several immediate updates - if (!isUpdatePending) { - isUpdatePending = true; - SwingUtilities.invokeLater(new Runnable() { - public void run() { - isUpdatePending = false; - - final String newText = text; - textArea.setText(newText); - textArea.setCaretPosition(newText.length()); - textArea.repaint(); - } - }); - } - } - - - // ------------------------------------------------------------------- - // KeyListener - // ------------------------------------------------------------------- - - public void keyPressed(KeyEvent key) { - } - - public void keyReleased(KeyEvent key) { - } - - 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); - } else { - keyBuffer.append(c); - statusLabel.setText(keyBuffer.toString()); - } - } - -} Deleted: mspsim/se/sics/mspsim/util/SourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/util/SourceViewer.java 2008-01-24 13:12:18 UTC (rev 78) +++ mspsim/se/sics/mspsim/util/SourceViewer.java 2008-01-24 13:40:29 UTC (rev 79) @@ -1,50 +0,0 @@ -/** - * 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. - * - * - * ----------------------------------------------------------------- - * - * Source Viewer - * - * Author : Joakim Eriksson - * Created : Sun Oct 21 22:00:00 2007 - * Updated : $Date: 2007/10/21 22:02:22 $ - * $Revision: 1.4 $ - */ - -package se.sics.mspsim.util; - - -public interface SourceViewer { - - public boolean isVisible(); - public void viewFile(String path, String file); - public void viewLine(int line); - -} Deleted: mspsim/se/sics/mspsim/util/WindowUtils.java =================================================================== --- mspsim/se/sics/mspsim/util/WindowUtils.java 2008-01-24 13:12:18 UTC (rev 78) +++ mspsim/se/sics/mspsim/util/WindowUtils.java 2008-01-24 13:40:29 UTC (rev 79) @@ -1,213 +0,0 @@ -/** - * 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: WindowUtils.java,v 1.2 2007/10/21 20:50:26 nfi Exp $ - * - * ----------------------------------------------------------------- - * - * WindowUtils - * - * Author : Joakim Eriksson, Niclas Finne, Fredrik \xD6sterlind - * Created : Sun Oct 21 22:00:00 2007 - * Updated : $Date: 2007/10/21 20:50:26 $ - * $Revision: 1.2 $ - */ - -package se.sics.mspsim.util; -import java.awt.Window; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.prefs.Preferences; - -public class WindowUtils { - - private static Preferences prefs = - Preferences.userNodeForPackage(WindowUtils.class); - - private static Hashtable<Window,CloseListener> closeTable; - private static Hashtable<Window,String> exitTable; - - private WindowUtils() { - } - - public static void saveWindowBounds(String key, Window window) { - putWindowBounds(key, window); - try { - prefs.flush(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - private static void putWindowBounds(String key, Window window) { - prefs.put("window." + key + ".bounds", getBounds(window)); - } - - public static void restoreWindowBounds(String key, Window window) { - setBounds(window, prefs.get("window." + key + ".bounds", null)); - } - - private static String getBounds(Window window) { - return "" + window.getX() - + ',' + window.getY() - + ',' + window.getWidth() - + ',' + window.getHeight(); - } - - private static void setBounds(Window window, String bounds) { - String[] b; - if ((bounds != null) - && ((b = bounds.split(",")) != null) - && b.length == 4) { - try { - window.setBounds(Integer.parseInt(b[0]), - Integer.parseInt(b[1]), - Integer.parseInt(b[2]), - Integer.parseInt(b[3])); - } catch (Exception e) { - e.printStackTrace(); - window.pack(); - } - } else { - window.pack(); - } - } - - public static void clearState() { - try { - prefs.clear(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public synchronized static void addSaveOnClose(String key, Window window) { - if (closeTable == null) { - closeTable = new Hashtable<Window,CloseListener>(); - } - if (closeTable.get(window) == null) { - CloseListener c = new CloseListener(key); - window.addWindowListener(c); - closeTable.put(window, c); - } - } - - public synchronized static void removeSaveOnClose(Window window) { - if (closeTable != null) { - CloseListener c = closeTable.remove(window); - if (c != null) { - window.removeWindowListener(c); - } - } - } - - public synchronized static void addSaveOnShutdown(String key, Window window) { - if (exitTable == null) { - exitTable = new Hashtable<Window,String>(); - Runtime.getRuntime().addShutdownHook(new ShutdownHandler()); - } - exitTable.put(window, key); - } - - public synchronized static void removeSaveOnShutdown(Window window) { - if (exitTable != null) { - exitTable.remove(window); - } - } - - - - // ------------------------------------------------------------------- - // Main - // ------------------------------------------------------------------- - - public static void main(String[] args) { - if (args.length != 1 || !args[0].equals("-clearState")) { - System.err.println("Usage: WindowUtils -clearState"); - System.exit(1); - } - clearState(); - } - - - // ------------------------------------------------------------------- - // CloseListener - // ------------------------------------------------------------------- - - private static class CloseListener extends WindowAdapter { - - private String key; - - public CloseListener(String key) { - this.key = key; - } - - public void windowClosing(WindowEvent e) { - Window source = (Window) e.getSource(); - saveWindowBounds(key, source); - source.removeWindowListener(this); - closeTable.remove(source); - } - - } - - - // ------------------------------------------------------------------- - // Shutdown handler - // ------------------------------------------------------------------- - - private static class ShutdownHandler extends Thread { - - public ShutdownHandler() { - super("WindowUtils-Shutdown"); - } - - public void run() { - Hashtable<Window,String> table = exitTable; - if (table != null && table.size() > 0) { - exitTable = null; - - Enumeration<Window> e = table.keys(); - while(e.hasMoreElements()) { - Window w = e.nextElement(); - putWindowBounds(table.get(w), w); - } - try { - prefs.flush(); - } catch (Exception e2) { - e2.printStackTrace(); - } - } - } - - } - -} // WindowUtils This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-01-24 18:54:29
|
Revision: 81 http://mspsim.svn.sourceforge.net/mspsim/?rev=81&view=rev Author: joxe Date: 2008-01-24 10:48:06 -0800 (Thu, 24 Jan 2008) Log Message: ----------- added operating mode profiling. Modified Paths: -------------- mspsim/se/sics/mspsim/chip/Beeper.java mspsim/se/sics/mspsim/chip/CC2420.java mspsim/se/sics/mspsim/core/BasicClockModule.java mspsim/se/sics/mspsim/core/IOPort.java mspsim/se/sics/mspsim/core/IOUnit.java mspsim/se/sics/mspsim/core/MSP430.java mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/se/sics/mspsim/core/Multiplier.java mspsim/se/sics/mspsim/core/SFR.java mspsim/se/sics/mspsim/core/Timer.java mspsim/se/sics/mspsim/core/USART.java mspsim/se/sics/mspsim/platform/sky/SkyNode.java mspsim/se/sics/mspsim/util/SimpleProfiler.java Added Paths: ----------- mspsim/se/sics/mspsim/core/Chip.java mspsim/se/sics/mspsim/core/OperatingModeListener.java mspsim/se/sics/mspsim/util/OperatingModeStatistics.java Modified: mspsim/se/sics/mspsim/chip/Beeper.java =================================================================== --- mspsim/se/sics/mspsim/chip/Beeper.java 2008-01-24 17:58:34 UTC (rev 80) +++ mspsim/se/sics/mspsim/chip/Beeper.java 2008-01-24 18:48:06 UTC (rev 81) @@ -145,4 +145,8 @@ } } } + + public int getModeMax() { + return 0; + } } Modified: mspsim/se/sics/mspsim/chip/CC2420.java =================================================================== --- mspsim/se/sics/mspsim/chip/CC2420.java 2008-01-24 17:58:34 UTC (rev 80) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2008-01-24 18:48:06 UTC (rev 81) @@ -43,7 +43,7 @@ import se.sics.mspsim.core.*; import se.sics.mspsim.util.Utils; -public class CC2420 implements USARTListener { +public class CC2420 extends Chip implements USARTListener { public static final boolean DEBUG = true; @@ -120,6 +120,11 @@ public static final int RAM_PANID = 0x168; public static final int RAM_SHORTADDR = 0x16A; + 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; + // when reading registrers this flag is set! public static final int FLAG_READ = 0x40; @@ -144,6 +149,8 @@ private int status = ST_XOSC16M_STABLE; + private int mode = MODE_TXRX_OFF; + private int[] registers = new int[64]; // More than needed... private int[] memory = new int[512]; @@ -169,9 +176,10 @@ public void dataReceived(USART source, int data) { if (chipSelect) { - System.out.println("CC2420 byte received: " + Utils.hex8(data) + - '\'' + (char) data + '\'' + - " CS: " + chipSelect + " state: " + state); + if (DEBUG) + System.out.println("CC2420 byte received: " + Utils.hex8(data) + + '\'' + (char) data + '\'' + + " CS: " + chipSelect + " state: " + state); switch(state) { case WAITING: state = WRITE_REGISTER; @@ -209,8 +217,9 @@ source.byteReceived(registers[address] & 0xff); // set the low bits registers[address] = registers[address] & 0xff00 | data; - System.out.println("CC2420: wrote to " + Utils.hex8(address) + " = " - + registers[address]); + if (DEBUG) + System.out.println("CC2420: wrote to " + Utils.hex8(address) + " = " + + registers[address]); } break; case READ_REGISTER: @@ -218,8 +227,9 @@ source.byteReceived(registers[address] >> 8); } else { source.byteReceived(registers[address] & 0xff); - System.out.println("CC2420: read from " + Utils.hex8(address) + " = " - + registers[address]); + if (DEBUG) + System.out.println("CC2420: read from " + Utils.hex8(address) + " = " + + registers[address]); } break; case READ_RXFIFO: @@ -238,16 +248,17 @@ if (pos == 0) { address = address | (data << 1) & 0x180; ramRead = (data & 0x20) != 0; - System.out.println("CC2420: Address: " + Utils.hex16(address) + - " read: " + ramRead); + if (DEBUG) + System.out.println("CC2420: Address: " + Utils.hex16(address) + + " read: " + ramRead); pos++; } else { if (!ramRead) { memory[address++] = data; - if (address == RAM_PANID + 2) { - System.out.println("CC2420: Pan ID set to: 0x" + - Utils.hex8(memory[RAM_PANID]) + - Utils.hex8(memory[RAM_PANID + 1])); + 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])); } } } @@ -258,20 +269,38 @@ // Needs to get information about when it is possible to write // next data... - private void strobe(int data) { // Resets, on/off of different things... - System.out.println("CC2420: Strobe on: " + Utils.hex8(data)); + if (DEBUG) + System.out.println("CC2420: Strobe on: " + Utils.hex8(data)); switch (data) { case REG_SRXON: System.out.println("CC2420: Strobe RX-ON!!!"); + setMode(MODE_RX_ON); break; + case REG_SRFOFF: + System.out.println("CC2420: Strobe RXTX-OFF!!!"); + setMode(MODE_TXRX_OFF); + break; + case REG_STXON: + System.out.println("CC2420: Strobe TXON!"); + setMode(MODE_TXRX_ON); + break; + case REG_STXONCCA: + System.out.println("CC2420: Strobe TXONCCA!"); + setMode(MODE_TXRX_ON); + break; case REG_SFLUSHRX: flushRX(); break; } } + + private void setMode(int mode) { + this.mode = mode; + modeChanged(mode); + } public void setChipSelect(boolean select) { @@ -310,8 +339,8 @@ } public void setIncomingPacket(int[] packet) { - int adr = RAM_RXFIFO; - memory[adr++] = packet.length + 2; + int adr = RAM_RXFIFO; + memory[adr++] = packet.length + 2; for (int i = 0, n = packet.length; i < n; i++) { memory[adr++] = packet[i] & 0xff; } @@ -326,8 +355,9 @@ } private void flushRX() { - if (DEBUG) System.out.println("Flushing RX! was: " + rxPacket + " len = " + - rxLen); + if (DEBUG) + System.out.println("Flushing RX! was: " + rxPacket + " len = " + + rxLen); rxPacket = false; rxCursor = 0; rxLen = 0; @@ -341,5 +371,14 @@ public void setCCA(boolean cca) { ccaPort.setPinState(ccaPin, cca ? 1 : 0); } + + public String getName() { + return "CC2420"; + } + public int getModeMax() { + return MODE_MAX; + } + + } // CC2420 Modified: mspsim/se/sics/mspsim/core/BasicClockModule.java =================================================================== --- mspsim/se/sics/mspsim/core/BasicClockModule.java 2008-01-24 17:58:34 UTC (rev 80) +++ mspsim/se/sics/mspsim/core/BasicClockModule.java 2008-01-24 18:48:06 UTC (rev 81) @@ -162,4 +162,8 @@ public void interruptServiced() { } + + public int getModeMax() { + return 0; + } } Added: mspsim/se/sics/mspsim/core/Chip.java =================================================================== --- mspsim/se/sics/mspsim/core/Chip.java (rev 0) +++ mspsim/se/sics/mspsim/core/Chip.java 2008-01-24 18:48:06 UTC (rev 81) @@ -0,0 +1,75 @@ +/** + * 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: $ + * + * ----------------------------------------------------------------- + * + * Chip + * + * Author : Joakim Eriksson + * Created : 17 jan 2008 + * Updated : $Date:$ + * $Revision:$ + */ +package se.sics.mspsim.core; +import java.util.ArrayList; +import java.util.Iterator; + +/** + * @author Joakim + * + */ +public abstract class Chip { + + private ArrayList<OperatingModeListener> omListeners; + + public void addOperatingModeListener(OperatingModeListener listener) { + if (omListeners == null) + omListeners = new ArrayList<OperatingModeListener>(); + omListeners.add(listener); + } + + public void removeOperatinModeListener(OperatingModeListener listener) { + if (omListeners != null) + omListeners.remove(listener); + } + + protected void modeChanged(int mode) { + if (omListeners != null) { + for (Iterator<OperatingModeListener> iterator = omListeners.iterator(); iterator.hasNext();) { + OperatingModeListener type = iterator.next(); + type.modeChanged(this, mode); + } + } + } + + public abstract String getName(); + public abstract int getModeMax(); +} Modified: mspsim/se/sics/mspsim/core/IOPort.java =================================================================== --- mspsim/se/sics/mspsim/core/IOPort.java 2008-01-24 17:58:34 UTC (rev 80) +++ mspsim/se/sics/mspsim/core/IOPort.java 2008-01-24 18:48:06 UTC (rev 81) @@ -71,7 +71,7 @@ public static final int IE = 5; public static final int ISEL = 6; - // One listener per port maximum (now at leat) + // One listener per port maximum (now at least) private PortListener listener; /** @@ -203,4 +203,9 @@ cpu.flagInterrupt(interrupt, this, interruptFlag > 0); } + // TODO: Should override this + public int getModeMax() { + return 0; + } + } Modified: mspsim/se/sics/mspsim/core/IOUnit.java =================================================================== --- mspsim/se/sics/mspsim/core/IOUnit.java 2008-01-24 17:58:34 UTC (rev 80) +++ mspsim/se/sics/mspsim/core/IOUnit.java 2008-01-24 18:48:06 UTC (rev 81) @@ -41,8 +41,11 @@ package se.sics.mspsim.core; -public abstract class IOUnit { +import java.util.ArrayList; +import java.util.Iterator; +public abstract class IOUnit extends Chip { + int[] memory; int offset; @@ -53,7 +56,7 @@ public void reset() { } - + public boolean needsTick() { return true; } @@ -82,8 +85,6 @@ // read a value from the IO unit public abstract int read(int address, boolean word, long cycles); - public abstract String getName(); - // We should add "Interrupt serviced..." to indicate that its latest // Interrupt was serviced... public abstract void interruptServiced(); Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2008-01-24 17:58:34 UTC (rev 80) +++ mspsim/se/sics/mspsim/core/MSP430.java 2008-01-24 18:48:06 UTC (rev 81) @@ -64,7 +64,7 @@ private DisAsm disAsm; private MapTable map; private Profiler profiler; - + /** * Creates a new <code>MSP430</code> instance. * Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2008-01-24 17:58:34 UTC (rev 80) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2008-01-24 18:48:06 UTC (rev 81) @@ -45,7 +45,7 @@ /** * The CPU of the MSP430 */ -public class MSP430Core implements MSP430Constants { +public class MSP430Core extends Chip implements MSP430Constants { public static final boolean DEBUG = false; public static final boolean debugInterrupts = false; @@ -54,6 +54,14 @@ public static final int MAX_MEM = 64*1024; public static final int INTERNAL_IO_SIZE = 5; public static final int PORTS = 6; + + public static final int MODE_ACTIVE = 0; + public static final int MODE_LPM0 = 1; + public static final int MODE_LPM1 = 2; + public static final int MODE_LPM2 = 3; + public static final int MODE_LPM3 = 4; + public static final int MODE_LPM4 = 5; + private static final int MODE_MAX = MODE_LPM4; // 16 registers of which some are "special" - PC, SP, etc. public int[] reg = new int[16]; @@ -247,6 +255,24 @@ if (cpuOff != oldCpuOff) { // System.out.println("LPM CPUOff: " + cpuOff + " cycles: " + cycles); } + if (cpuOff) { + boolean scg0 = (value & SCG0) == SCG0; + boolean scg1 = (value & SCG1) == SCG1; + boolean oscoff = (value & OSCOFF) == OSCOFF; + if (oscoff && scg1 && scg0) { + modeChanged(MODE_LPM4); + } else if (scg1 && scg0){ + modeChanged(MODE_LPM3); + } else if (scg1) { + modeChanged(MODE_LPM2); + } else if (scg0) { + modeChanged(MODE_LPM1); + } else { + modeChanged(MODE_LPM0); + } + } else { + modeChanged(MODE_ACTIVE); + } } } @@ -965,4 +991,12 @@ cpuCycles += cycles - startCycles; return true; } + + public String getName() { + return "MSP430 Core"; + } + + public int getModeMax() { + return MODE_MAX; + } } Modified: mspsim/se/sics/mspsim/core/Multiplier.java =================================================================== --- mspsim/se/sics/mspsim/core/Multiplier.java 2008-01-24 17:58:34 UTC (rev 80) +++ mspsim/se/sics/mspsim/core/Multiplier.java 2008-01-24 18:48:06 UTC (rev 81) @@ -116,5 +116,9 @@ public void interruptServiced() { } + public int getModeMax() { + return 0; + } + } Added: mspsim/se/sics/mspsim/core/OperatingModeListener.java =================================================================== --- mspsim/se/sics/mspsim/core/OperatingModeListener.java (rev 0) +++ mspsim/se/sics/mspsim/core/OperatingModeListener.java 2008-01-24 18:48:06 UTC (rev 81) @@ -0,0 +1,49 @@ +/** + * 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: $ + * + * ----------------------------------------------------------------- + * + * OperatingModeListener - allow listening on IOUnits operating mode. + * + * Author : Joakim Eriksson + * Created : 17 jan 2008 + * Updated : $Date:$ + * $Revision:$ + */ +package se.sics.mspsim.core; + +/** + * @author Joakim + * + */ +public interface OperatingModeListener { + public void modeChanged(Chip source, int mode); +} Modified: mspsim/se/sics/mspsim/core/SFR.java =================================================================== --- mspsim/se/sics/mspsim/core/SFR.java 2008-01-24 17:58:34 UTC (rev 80) +++ mspsim/se/sics/mspsim/core/SFR.java 2008-01-24 18:48:06 UTC (rev 81) @@ -151,4 +151,8 @@ public String getName() { return "SpecialFunctionRegister, SFR"; } + + public int getModeMax() { + return 0; + } } // SFR Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2008-01-24 17:58:34 UTC (rev 80) +++ mspsim/se/sics/mspsim/core/Timer.java 2008-01-24 18:48:06 UTC (rev 81) @@ -629,4 +629,8 @@ System.out.println("interrupt Serviced..."); } } + + public int getModeMax() { + return 0; + } } Modified: mspsim/se/sics/mspsim/core/USART.java =================================================================== --- mspsim/se/sics/mspsim/core/USART.java 2008-01-24 17:58:34 UTC (rev 80) +++ mspsim/se/sics/mspsim/core/USART.java 2008-01-24 18:48:06 UTC (rev 81) @@ -308,4 +308,8 @@ } } + public int getModeMax() { + return 0; + } + } Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-01-24 17:58:34 UTC (rev 80) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-01-24 18:48:06 UTC (rev 81) @@ -43,6 +43,7 @@ import java.io.IOException; import se.sics.mspsim.chip.CC2420; +import se.sics.mspsim.core.Chip; import se.sics.mspsim.core.IOPort; import se.sics.mspsim.core.IOUnit; import se.sics.mspsim.core.MSP430; @@ -54,14 +55,20 @@ import se.sics.mspsim.util.ELF; import se.sics.mspsim.util.IHexReader; import se.sics.mspsim.util.MapTable; +import se.sics.mspsim.util.OperatingModeStatistics; /** * Emulation of Sky Mote */ -public class SkyNode implements PortListener, USARTListener { +public class SkyNode extends Chip implements PortListener, USARTListener { 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; @@ -81,7 +88,7 @@ private CC2420 radio; private ExtFlash flash; - + public static final int BLUE_LED = 0x40; public static final int GREEN_LED = 0x20; public static final int RED_LED = 0x10; @@ -89,7 +96,10 @@ public boolean redLed; public boolean blueLed; public boolean greenLed; + private int mode = MODE_LEDS_OFF; + private OperatingModeStatistics stats; + public SkyGui gui; /** * Creates a new <code>SkyNode</code> instance. @@ -127,6 +137,9 @@ ((IOPort) port4).setPortListener(this); } } + + stats = new OperatingModeStatistics(cpu); + stats.addMonitor(this); } public void setButton(boolean hi) { @@ -150,6 +163,14 @@ 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); + if (mode != newMode) { + mode = newMode; + modeChanged(mode); + } + // TODO: put this somewhere else!!! + //stats.printStat(); + if (gui != null) { gui.repaint(); } @@ -203,6 +224,15 @@ MapTable map = new MapTable(args[1]); cpu.getDisAsm().setMap(map); } + cpu.cpuloop(); } + + public int getModeMax() { + return MODE_MAX; + } + + public String getName() { + return "Tmote Sky"; + } } Added: mspsim/se/sics/mspsim/util/OperatingModeStatistics.java =================================================================== --- mspsim/se/sics/mspsim/util/OperatingModeStatistics.java (rev 0) +++ mspsim/se/sics/mspsim/util/OperatingModeStatistics.java 2008-01-24 18:48:06 UTC (rev 81) @@ -0,0 +1,111 @@ +/** + * 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: $ + * + * ----------------------------------------------------------------- + * + * OperatingModeStatistics + * + * Author : Joakim Eriksson + * Created : 17 jan 2008 + * Updated : $Date:$ + * $Revision:$ + */ +package se.sics.mspsim.util; + +import java.util.HashMap; +import java.util.Iterator; + +import se.sics.mspsim.core.Chip; +import se.sics.mspsim.core.MSP430Core; +import se.sics.mspsim.core.OperatingModeListener; + +/** + * @author Joakim + * + */ +public class OperatingModeStatistics implements OperatingModeListener { + + private MSP430Core cpu; + private HashMap<String, StatEntry> statistics = new HashMap<String, StatEntry>(); + + public OperatingModeStatistics(MSP430Core cpu) { + this.cpu = cpu; + } + + public void addMonitor(Chip chip) { + chip.addOperatingModeListener(this); + } + + public void modeChanged(Chip source, int mode) { + StatEntry entry = statistics.get(source.getName()); + if (entry == null) { + entry = new StatEntry(source.getName(), source.getModeMax()); + statistics.put(source.getName(), entry); + } + entry.updateStat(mode, cpu.cycles); + } + + public void printStat() { + for (Iterator<StatEntry> iterator = statistics.values().iterator(); iterator.hasNext();) { + StatEntry entry = iterator.next(); + entry.printStat(); + } + } + + + private class StatEntry { + String key; + long startTime; + int mode = -1; + long[] elapsed; + + StatEntry(String key, int max) { + this.key = key; + elapsed = new long[max + 1]; + } + + void updateStat(int mode, long cycles) { + if (this.mode != -1) { + elapsed[this.mode] += cycles - startTime; + } + this.mode = mode; + startTime = cycles; + } + + void printStat() { + System.out.println("Stat for: " + key); + for (int i = 0; i < elapsed.length; i++) { + System.out.println("" + (i + 1) + " = " + elapsed[i]); + } + } + } + +} Modified: mspsim/se/sics/mspsim/util/SimpleProfiler.java =================================================================== --- mspsim/se/sics/mspsim/util/SimpleProfiler.java 2008-01-24 17:58:34 UTC (rev 80) +++ mspsim/se/sics/mspsim/util/SimpleProfiler.java 2008-01-24 18:48:06 UTC (rev 81) @@ -91,16 +91,16 @@ public void clearProfile() { if (profileData != null) { CallEntry[] entries = - profileData.values().toArray(new CallEntry[0]); + profileData.values().toArray(new CallEntry[0]); for (int i = 0, n = entries.length; i < n; i++) { - entries[i].cycles = 0; - entries[i].calls = 0; + entries[i].cycles = 0; + entries[i].calls = 0; } for (int i = 0, n = callStack.length; i < n; i++) { - CallEntry e = callStack[i]; - if (e != null) { - e.calls = -1; - } + CallEntry e = callStack[i]; + if (e != null) { + e.calls = -1; + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-01-24 19:30:24
|
Revision: 82 http://mspsim.svn.sourceforge.net/mspsim/?rev=82&view=rev Author: joxe Date: 2008-01-24 11:26:52 -0800 (Thu, 24 Jan 2008) Log Message: ----------- Added datasource and jfreechart test. Added Paths: ----------- mspsim/se/sics/mspsim/extutil/jfreechart/ mspsim/se/sics/mspsim/extutil/jfreechart/DataSourceSampler.java mspsim/se/sics/mspsim/util/DataSource.java Added: mspsim/se/sics/mspsim/extutil/jfreechart/DataSourceSampler.java =================================================================== --- mspsim/se/sics/mspsim/extutil/jfreechart/DataSourceSampler.java (rev 0) +++ mspsim/se/sics/mspsim/extutil/jfreechart/DataSourceSampler.java 2008-01-24 19:26:52 UTC (rev 82) @@ -0,0 +1,109 @@ +package se.sics.mspsim.extutil.jfreechart; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; + +import javax.swing.JFrame; +import javax.swing.JWindow; +import javax.swing.Timer; + +import org.jfree.chart.ChartPanel; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.DateAxis; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.DefaultXYItemRenderer; +import org.jfree.chart.renderer.xy.XYItemRenderer; +import org.jfree.data.time.Millisecond; +import org.jfree.data.time.TimeSeries; +import org.jfree.data.time.TimeSeriesCollection; + +import se.sics.mspsim.util.DataSource; + +public class DataSourceSampler implements ActionListener { + + private int interval = 1000; + private Timer timer; + private ArrayList<DataSource> sources = new ArrayList<DataSource>(); + + private TimeSeries test; + private TimeSeriesCollection dataset; + + public DataSourceSampler() { + timer = new Timer(interval, this); + test = new TimeSeries("Data", Millisecond.class); + test.setMaximumItemCount(30000); + dataset = new TimeSeriesCollection(); + dataset.addSeries(test); +// timer.start(); + } + + public void addDataSource(DataSource source) { + sources.add(source); + } + + public void removeDataSource(DataSource source) { + sources.remove(source); + } + + public void setInterval(int intMsek) { + interval = intMsek; + timer.setDelay(interval); + } + + private void sampleAll() { + if (sources.size() > 0) { + DataSource[] srcs = (DataSource[]) sources.toArray(new DataSource[0]); + for (int i = 0; i < srcs.length; i++) { + int val = srcs[i].getValue(); + + } + } + test.add(new Millisecond(), Math.random()); + } + + public void actionPerformed(ActionEvent arg0) { + System.out.println("Scheduled for sampling..."); + sampleAll(); + } + + + public static void main(String[] args) { + DataSourceSampler samp = new DataSourceSampler(); + DateAxis domain = new DateAxis("Time"); + NumberAxis range = new NumberAxis("Memory"); + XYPlot xyplot = new XYPlot(); + xyplot.setDataset(samp.dataset); + xyplot.setDomainAxis(domain); + xyplot.setRangeAxis(range); + xyplot.setBackgroundPaint(Color.black); + + XYItemRenderer renderer = new DefaultXYItemRenderer(); + renderer.setSeriesPaint(0, Color.red); + renderer.setSeriesPaint(1, Color.green); + renderer.setBaseStroke( + new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL) + ); + xyplot.setRenderer(renderer); + + domain.setAutoRange(true); + domain.setLowerMargin(0.0); + domain.setUpperMargin(0.0); + domain.setTickLabelsVisible(true); + range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); + JFreeChart chart = new JFreeChart( + "Memory Usage", + JFreeChart.DEFAULT_TITLE_FONT, + xyplot,true); + ChartPanel chartPanel = new ChartPanel(chart); + JFrame jw = new JFrame("test"); + jw.add(chartPanel); + jw.setBounds(100, 100, 400, 200); + jw.setVisible(true); + + } + +} Added: mspsim/se/sics/mspsim/util/DataSource.java =================================================================== --- mspsim/se/sics/mspsim/util/DataSource.java (rev 0) +++ mspsim/se/sics/mspsim/util/DataSource.java 2008-01-24 19:26:52 UTC (rev 82) @@ -0,0 +1,43 @@ +/** + * 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. + * + * ----------------------------------------------------------------- + * + * DataSource + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 21:17:34 $ + * $Revision: 1.3 $ + */ +package se.sics.mspsim.util; + +public interface DataSource { + public int getValue(); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-01-24 23:06:09
|
Revision: 84 http://mspsim.svn.sourceforge.net/mspsim/?rev=84&view=rev Author: joxe Date: 2008-01-24 15:05:15 -0800 (Thu, 24 Jan 2008) Log Message: ----------- added new stack chart based on jfreechart. Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/jfreechart/DataSourceSampler.java mspsim/se/sics/mspsim/platform/sky/SkyNode.java mspsim/se/sics/mspsim/ui/ControlUI.java Added Paths: ----------- mspsim/se/sics/mspsim/extutil/jfreechart/DataChart.java mspsim/se/sics/mspsim/util/StackMonitor.java Added: mspsim/se/sics/mspsim/extutil/jfreechart/DataChart.java =================================================================== --- mspsim/se/sics/mspsim/extutil/jfreechart/DataChart.java (rev 0) +++ mspsim/se/sics/mspsim/extutil/jfreechart/DataChart.java 2008-01-24 23:05:15 UTC (rev 84) @@ -0,0 +1,83 @@ +package se.sics.mspsim.extutil.jfreechart; + +import java.awt.BasicStroke; +import java.awt.BorderLayout; +import java.awt.Color; + +import javax.swing.JFrame; +import javax.swing.JPanel; + +import org.jfree.chart.ChartPanel; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.DateAxis; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.DefaultXYItemRenderer; +import org.jfree.chart.renderer.xy.XYItemRenderer; +import org.jfree.data.time.Millisecond; +import org.jfree.data.time.TimeSeries; +import org.jfree.data.time.TimeSeriesCollection; + +import se.sics.mspsim.core.MSP430; +import se.sics.mspsim.util.StackMonitor; + +@SuppressWarnings("serial") +public class DataChart extends JPanel { + + private TimeSeriesCollection dataset; + + public DataChart(String title) { + DateAxis domain = new DateAxis("Time"); + NumberAxis range = new NumberAxis("Memory"); + XYPlot xyplot = new XYPlot(); + xyplot.setDomainAxis(domain); + xyplot.setRangeAxis(range); + // xyplot.setBackgroundPaint(Color.black); + xyplot.setDataset(dataset = new TimeSeriesCollection()); + + XYItemRenderer renderer = new DefaultXYItemRenderer(); + renderer.setSeriesPaint(0, Color.red); + renderer.setSeriesPaint(1, Color.green); +// renderer.setBaseStroke( +// new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL) +// ); + xyplot.setRenderer(renderer); + + domain.setAutoRange(true); + domain.setLowerMargin(0.0); + domain.setUpperMargin(0.0); + + domain.setTickLabelsVisible(true); + range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); + JFreeChart chart = new JFreeChart(title, + JFreeChart.DEFAULT_TITLE_FONT, xyplot, true); + ChartPanel chartPanel = new ChartPanel(chart); + setLayout(new BorderLayout()); + add(chartPanel, BorderLayout.CENTER); + } + + public void addTimeSeries(TimeSeries ts) { + dataset.addSeries(ts); + } + + public void openFrame(String name) { + JFrame jw = new JFrame("name"); + jw.add(this); + jw.setBounds(100, 100, 400, 200); + jw.setVisible(true); + } + + public void setupStackFrame(MSP430 cpu) { + openFrame("Stack Monitor"); + StackMonitor sm = new StackMonitor(cpu); + DataSourceSampler dss = new DataSourceSampler(); + TimeSeries ts = new TimeSeries("Max Stack", Millisecond.class); + ts.setMaximumItemAge(30000); + addTimeSeries(ts); + dss.addDataSource(sm.getMaxSource(), ts); + ts = new TimeSeries("Stack", Millisecond.class); + ts.setMaximumItemAge(30000); + addTimeSeries(ts); + dss.addDataSource(sm.getSource(), ts); + } +} Modified: mspsim/se/sics/mspsim/extutil/jfreechart/DataSourceSampler.java =================================================================== --- mspsim/se/sics/mspsim/extutil/jfreechart/DataSourceSampler.java 2008-01-24 19:45:13 UTC (rev 83) +++ mspsim/se/sics/mspsim/extutil/jfreechart/DataSourceSampler.java 2008-01-24 23:05:15 UTC (rev 84) @@ -27,30 +27,32 @@ private int interval = 100; private Timer timer; - private ArrayList<DataSource> sources = new ArrayList<DataSource>(); + private ArrayList<TimeSource> sources = new ArrayList<TimeSource>(); - private TimeSeries test; - private TimeSeries test2; - private TimeSeriesCollection dataset; +// private TimeSeries test; +// private TimeSeries test2; +// private TimeSeriesCollection dataset; public DataSourceSampler() { timer = new Timer(interval, this); - test = new TimeSeries("Data", Millisecond.class); - test.setMaximumItemAge(30000); - test2 = new TimeSeries("Data 2", Millisecond.class); - test2.setMaximumItemAge(30000); -// test2.setMaximumItemCount(30000); - dataset = new TimeSeriesCollection(); - dataset.addSeries(test); - dataset.addSeries(test2); +// test = new TimeSeries("Data", Millisecond.class); +// test.setMaximumItemAge(30000); +// test2 = new TimeSeries("Data 2", Millisecond.class); +// test2.setMaximumItemAge(30000); +//// test2.setMaximumItemCount(30000); +// dataset = new TimeSeriesCollection(); +// dataset.addSeries(test); +// dataset.addSeries(test2); timer.start(); } - public void addDataSource(DataSource source) { - sources.add(source); + public TimeSource addDataSource(DataSource source, TimeSeries ts) { + TimeSource times = new TimeSource(source, ts); + sources.add(times); + return times; } - public void removeDataSource(DataSource source) { + public void removeDataSource(TimeSource source) { sources.remove(source); } @@ -61,14 +63,14 @@ private void sampleAll() { if (sources.size() > 0) { - DataSource[] srcs = (DataSource[]) sources.toArray(new DataSource[0]); + TimeSource[] srcs = (TimeSource[]) sources.toArray(new TimeSource[0]); for (int i = 0; i < srcs.length; i++) { - int val = srcs[i].getValue(); - + srcs[i].update(); } } - test.add(new Millisecond(), Math.random() * 100); - test2.add(new Millisecond(), Math.random() * 100); + +// test.add(new Millisecond(), Math.random() * 100); +// test2.add(new Millisecond(), Math.random() * 100); } public void actionPerformed(ActionEvent arg0) { @@ -76,39 +78,55 @@ } - public static void main(String[] args) { - DataSourceSampler samp = new DataSourceSampler(); - DateAxis domain = new DateAxis("Time"); - NumberAxis range = new NumberAxis("Memory"); - XYPlot xyplot = new XYPlot(); - xyplot.setDataset(samp.dataset); - xyplot.setDomainAxis(domain); - xyplot.setRangeAxis(range); - xyplot.setBackgroundPaint(Color.black); +// public static void main(String[] args) { +// DataSourceSampler samp = new DataSourceSampler(); +// DateAxis domain = new DateAxis("Time"); +// NumberAxis range = new NumberAxis("Memory"); +// XYPlot xyplot = new XYPlot(); +// xyplot.setDataset(samp.dataset); +// xyplot.setDomainAxis(domain); +// xyplot.setRangeAxis(range); +// xyplot.setBackgroundPaint(Color.black); +// +// XYItemRenderer renderer = new DefaultXYItemRenderer(); +// renderer.setSeriesPaint(0, Color.red); +// renderer.setSeriesPaint(1, Color.green); +// renderer.setBaseStroke( +// new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL) +// ); +// xyplot.setRenderer(renderer); +// +// domain.setAutoRange(true); +// domain.setLowerMargin(0.0); +// domain.setUpperMargin(0.0); +// domain.setTickLabelsVisible(true); +// range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); +// JFreeChart chart = new JFreeChart( +// "Memory Usage", +// JFreeChart.DEFAULT_TITLE_FONT, +// xyplot,true); +// ChartPanel chartPanel = new ChartPanel(chart); +// JFrame jw = new JFrame("test"); +// jw.add(chartPanel); +// jw.setBounds(100, 100, 400, 200); +// jw.setVisible(true); +// +// } + + class TimeSource { + + private DataSource dataSource; + private TimeSeries timeSeries; + + TimeSource(DataSource ds, TimeSeries ts) { + dataSource = ds; + timeSeries = ts; + } - XYItemRenderer renderer = new DefaultXYItemRenderer(); - renderer.setSeriesPaint(0, Color.red); - renderer.setSeriesPaint(1, Color.green); - renderer.setBaseStroke( - new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL) - ); - xyplot.setRenderer(renderer); + public void update() { + timeSeries.add(new Millisecond(), dataSource.getValue()); + } - domain.setAutoRange(true); - domain.setLowerMargin(0.0); - domain.setUpperMargin(0.0); - domain.setTickLabelsVisible(true); - range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); - JFreeChart chart = new JFreeChart( - "Memory Usage", - JFreeChart.DEFAULT_TITLE_FONT, - xyplot,true); - ChartPanel chartPanel = new ChartPanel(chart); - JFrame jw = new JFrame("test"); - jw.add(chartPanel); - jw.setBounds(100, 100, 400, 200); - jw.setVisible(true); - } } Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-01-24 19:45:13 UTC (rev 83) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-01-24 23:05:15 UTC (rev 84) @@ -219,7 +219,7 @@ ControlUI control = new ControlUI(cpu, elf); HighlightSourceViewer sourceViewer = new HighlightSourceViewer(); control.setSourceViewer(sourceViewer); - + if (args.length > 1) { MapTable map = new MapTable(args[1]); cpu.getDisAsm().setMap(map); Modified: mspsim/se/sics/mspsim/ui/ControlUI.java =================================================================== --- mspsim/se/sics/mspsim/ui/ControlUI.java 2008-01-24 19:45:13 UTC (rev 83) +++ mspsim/se/sics/mspsim/ui/ControlUI.java 2008-01-24 23:05:15 UTC (rev 84) @@ -54,6 +54,7 @@ import javax.swing.KeyStroke; import se.sics.mspsim.core.*; +import se.sics.mspsim.extutil.jfreechart.DataChart; import se.sics.mspsim.util.DebugInfo; import se.sics.mspsim.util.ELF; import se.sics.mspsim.util.StackUI; @@ -82,6 +83,10 @@ this.cpu = cpu; this.stackUI = new StackUI(cpu); + + DataChart test = new DataChart("Stack Monitor"); + test.setupStackFrame(cpu); + stackWindow = new JFrame("Stack"); stackWindow.add(this.stackUI); WindowUtils.restoreWindowBounds("StackUI", stackWindow); Added: mspsim/se/sics/mspsim/util/StackMonitor.java =================================================================== --- mspsim/se/sics/mspsim/util/StackMonitor.java (rev 0) +++ mspsim/se/sics/mspsim/util/StackMonitor.java 2008-01-24 23:05:15 UTC (rev 84) @@ -0,0 +1,82 @@ +package se.sics.mspsim.util; + +import se.sics.mspsim.core.CPUMonitor; +import se.sics.mspsim.core.MSP430; +import se.sics.mspsim.core.MSP430Constants; + +public class StackMonitor implements CPUMonitor { + + private MSP430 cpu; + private int heapStartAddress; + private int stackStartAddress; + + private int stackMin = 0; + private int stackMax = 0; + private int stack = 0; + + private DataSource maxDataSource = new DataSource() { + public int getValue() { + int tmp = stackMax; + stackMax = stack; + return tmp; + } + }; + + private DataSource minDataSource = new DataSource() { + public int getValue() { + int tmp = stackMin; + stackMin = stack; + return tmp; + } + }; + + private DataSource dataSource = new DataSource() { + public int getValue() { + return stack; + } + }; + + public StackMonitor(MSP430 cpu) { + this.cpu = cpu; + this.cpu.setRegisterWriteMonitor(MSP430.SP, this); + + if (cpu.getDisAsm() != null) { + MapTable mapTable = cpu.getDisAsm().getMap(); + if (mapTable != null) { + this.heapStartAddress = mapTable.heapStartAddress; + this.stackStartAddress = mapTable.stackStartAddress; + } + } + } + + public int getStackStart() { + return stackStartAddress; + } + + public int getHeapStart() { + return heapStartAddress; + } + + + public DataSource getMaxSource() { + return maxDataSource; + } + + public DataSource getMinSource() { + return minDataSource; + } + + public DataSource getSource() { + return dataSource; + } + + public void cpuAction(int type, int adr, int data) { + stack = ((stackStartAddress - data) + 0xffff) % 0xffff; + if (stack > stackMax) { + stackMax = stack; + } + if (stack < stackMin) { + stackMin = stack; + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-01-26 00:26:57
|
Revision: 86 http://mspsim.svn.sourceforge.net/mspsim/?rev=86&view=rev Author: joxe Date: 2008-01-25 16:26:43 -0800 (Fri, 25 Jan 2008) Log Message: ----------- added duty-cycle diagram Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/jfreechart/DataChart.java mspsim/se/sics/mspsim/platform/sky/SkyNode.java mspsim/se/sics/mspsim/ui/ControlUI.java mspsim/se/sics/mspsim/util/OperatingModeStatistics.java Modified: mspsim/se/sics/mspsim/extutil/jfreechart/DataChart.java =================================================================== --- mspsim/se/sics/mspsim/extutil/jfreechart/DataChart.java 2008-01-24 23:15:41 UTC (rev 85) +++ mspsim/se/sics/mspsim/extutil/jfreechart/DataChart.java 2008-01-26 00:26:43 UTC (rev 86) @@ -18,7 +18,9 @@ import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; +import se.sics.mspsim.chip.CC2420; import se.sics.mspsim.core.MSP430; +import se.sics.mspsim.util.OperatingModeStatistics; import se.sics.mspsim.util.StackMonitor; @SuppressWarnings("serial") @@ -26,9 +28,9 @@ private TimeSeriesCollection dataset; - public DataChart(String title) { + public DataChart(String title, String yaxis) { DateAxis domain = new DateAxis("Time"); - NumberAxis range = new NumberAxis("Bytes"); + NumberAxis range = new NumberAxis(yaxis); XYPlot xyplot = new XYPlot(); xyplot.setDomainAxis(domain); xyplot.setRangeAxis(range); @@ -38,11 +40,15 @@ DefaultXYItemRenderer renderer = new DefaultXYItemRenderer(); renderer.setSeriesPaint(0, Color.red); renderer.setSeriesPaint(1, Color.green); + renderer.setSeriesPaint(2, Color.blue); + renderer.setSeriesPaint(3, Color.black); // renderer.setBaseStroke( // new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL) // ); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesShapesVisible(1, false); + renderer.setSeriesShapesVisible(2, false); + renderer.setSeriesShapesVisible(3, false); xyplot.setRenderer(renderer); domain.setAutoRange(true); @@ -74,12 +80,38 @@ StackMonitor sm = new StackMonitor(cpu); DataSourceSampler dss = new DataSourceSampler(); TimeSeries ts = new TimeSeries("Max Stack", Millisecond.class); - ts.setMaximumItemAge(30000); + ts.setMaximumItemCount(200); addTimeSeries(ts); dss.addDataSource(sm.getMaxSource(), ts); ts = new TimeSeries("Stack", Millisecond.class); - ts.setMaximumItemAge(30000); + ts.setMaximumItemCount(200); addTimeSeries(ts); dss.addDataSource(sm.getSource(), ts); } + + public void setupChipFrame(OperatingModeStatistics oms) { + openFrame("Duty-Cycle Monitor"); + DataSourceSampler dss = new DataSourceSampler(); + dss.setInterval(50); + TimeSeries ts = new TimeSeries("LEDS", Millisecond.class); + ts.setMaximumItemCount(200); + addTimeSeries(ts); + dss.addDataSource(oms.getMultiDataSource("Tmote Sky"), ts); + + ts = new TimeSeries("Listen", Millisecond.class); + ts.setMaximumItemCount(200); + addTimeSeries(ts); + dss.addDataSource(oms.getDataSource("CC2420", CC2420.MODE_RX_ON), ts); + + ts = new TimeSeries("Transmit", Millisecond.class); + ts.setMaximumItemCount(200); + addTimeSeries(ts); + dss.addDataSource(oms.getDataSource("CC2420", CC2420.MODE_TXRX_ON), ts); + + ts = new TimeSeries("CPU", Millisecond.class); + ts.setMaximumItemCount(200); + addTimeSeries(ts); + dss.addDataSource(oms.getDataSource("MSP430 Core", MSP430.MODE_ACTIVE), ts); + + } } Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-01-24 23:15:41 UTC (rev 85) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-01-26 00:26:43 UTC (rev 86) @@ -51,6 +51,7 @@ import se.sics.mspsim.core.USART; import se.sics.mspsim.core.USARTListener; import se.sics.mspsim.extutil.highlight.HighlightSourceViewer; +import se.sics.mspsim.extutil.jfreechart.DataChart; import se.sics.mspsim.ui.ControlUI; import se.sics.mspsim.util.ELF; import se.sics.mspsim.util.IHexReader; @@ -140,6 +141,8 @@ stats = new OperatingModeStatistics(cpu); stats.addMonitor(this); + stats.addMonitor(radio); + stats.addMonitor(cpu); } public void setButton(boolean hi) { @@ -163,7 +166,7 @@ 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); + int newMode = (redLed ? 1 : 0) + (greenLed ? 1 : 0) + (blueLed ? 1 : 0); if (mode != newMode) { mode = newMode; modeChanged(mode); @@ -225,6 +228,11 @@ cpu.getDisAsm().setMap(map); } + + // A HACK!!! + DataChart dataChart = new DataChart("Duty Cycle", "Duty Cycle"); + dataChart.setupChipFrame(node.stats); + cpu.cpuloop(); } Modified: mspsim/se/sics/mspsim/ui/ControlUI.java =================================================================== --- mspsim/se/sics/mspsim/ui/ControlUI.java 2008-01-24 23:15:41 UTC (rev 85) +++ mspsim/se/sics/mspsim/ui/ControlUI.java 2008-01-26 00:26:43 UTC (rev 86) @@ -84,7 +84,7 @@ this.stackUI = new StackUI(cpu); - DataChart test = new DataChart("Stack Monitor"); + DataChart test = new DataChart("Stack Monitor", "Bytes"); test.setupStackFrame(cpu); stackWindow = new JFrame("Stack"); Modified: mspsim/se/sics/mspsim/util/OperatingModeStatistics.java =================================================================== --- mspsim/se/sics/mspsim/util/OperatingModeStatistics.java 2008-01-24 23:15:41 UTC (rev 85) +++ mspsim/se/sics/mspsim/util/OperatingModeStatistics.java 2008-01-26 00:26:43 UTC (rev 86) @@ -43,6 +43,9 @@ import java.util.HashMap; import java.util.Iterator; +import org.jfree.chart.renderer.category.StatisticalBarRenderer; +import org.jfree.data.statistics.Statistics; + import se.sics.mspsim.core.Chip; import se.sics.mspsim.core.MSP430Core; import se.sics.mspsim.core.OperatingModeListener; @@ -62,15 +65,14 @@ public void addMonitor(Chip chip) { chip.addOperatingModeListener(this); + StatEntry entry = new StatEntry(chip.getName(), chip.getModeMax()); + statistics.put(chip.getName(), entry); } public void modeChanged(Chip source, int mode) { StatEntry entry = statistics.get(source.getName()); - if (entry == null) { - entry = new StatEntry(source.getName(), source.getModeMax()); - statistics.put(source.getName(), entry); - } - entry.updateStat(mode, cpu.cycles); + if (entry != null) + entry.updateStat(mode, cpu.cycles); } public void printStat() { @@ -80,7 +82,78 @@ } } + public DataSource getDataSource(String chip, int mode) { + StatEntry se = statistics.get(chip); + if (se != null) { + return new StatDataSource(se, mode); + } + return null; + } + + public DataSource getMultiDataSource(String chip) { + StatEntry se = statistics.get(chip); + if (se != null) { + return new StatMultiDataSource(se); + } + return null; + } + private class StatDataSource implements DataSource { + + private StatEntry entry; + private int mode; + private long lastCycles; + private long lastValue; + + public StatDataSource(StatEntry entry, int mode) { + this.entry = entry; + this.mode = mode; + lastCycles = cpu.cycles; + } + + // returns percentage since last call... + public int getValue() { + long diff = cpu.cycles - lastCycles; + if (diff == 0) return 0; + long val = entry.getValue(mode, cpu.cycles); + long valDiff = val - lastValue; + lastValue = val; + lastCycles = cpu.cycles; + return (int) (100 * valDiff / diff); + } + } + + private class StatMultiDataSource implements DataSource{ + + private StatEntry entry; + private long lastCycles; + private long[] lastValue; + + public StatMultiDataSource(StatEntry entry) { + this.entry = entry; + lastCycles = cpu.cycles; + lastValue = new long[entry.elapsed.length]; + } + + // returns percentage since last call... + public int getValue() { + long diff = cpu.cycles - lastCycles; + if (diff == 0) return 0; + + long valDiff = 0; + // Assume that 0 means "off" + for (int i = 1; i < lastValue.length; i++) { + // Just sum them - later a multiplicator array might be useful... + long val = entry.getValue(i, cpu.cycles); + valDiff += (val - lastValue[i]); + lastValue[i] = val; + } + lastCycles = cpu.cycles; + return (int) (100 * valDiff / diff); + } + } + + private class StatEntry { String key; long startTime; @@ -92,6 +165,13 @@ elapsed = new long[max + 1]; } + long getValue(int mode, long cycles) { + if (mode == this.mode) { + return elapsed[mode] + (cycles - startTime); + } + return elapsed[mode]; + } + void updateStat(int mode, long cycles) { if (this.mode != -1) { elapsed[this.mode] += cycles - startTime; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2008-01-28 11:09:40
|
Revision: 91 http://mspsim.svn.sourceforge.net/mspsim/?rev=91&view=rev Author: nifi Date: 2008-01-28 03:09:37 -0800 (Mon, 28 Jan 2008) Log Message: ----------- updated basic graph utils + moved ui classes from utils to ui Modified Paths: -------------- mspsim/se/sics/mspsim/ui/ControlUI.java mspsim/se/sics/mspsim/util/DotDiagram.java Added Paths: ----------- mspsim/se/sics/mspsim/ui/AbstractChart.java mspsim/se/sics/mspsim/ui/Chart.java mspsim/se/sics/mspsim/ui/ChartPanel.java mspsim/se/sics/mspsim/ui/ConstantLineChart.java mspsim/se/sics/mspsim/ui/IntSerieChart.java mspsim/se/sics/mspsim/ui/LineChart.java mspsim/se/sics/mspsim/ui/StackUI.java Removed Paths: ------------- mspsim/se/sics/mspsim/util/StackUI.java Added: mspsim/se/sics/mspsim/ui/AbstractChart.java =================================================================== --- mspsim/se/sics/mspsim/ui/AbstractChart.java (rev 0) +++ mspsim/se/sics/mspsim/ui/AbstractChart.java 2008-01-28 11:09:37 UTC (rev 91) @@ -0,0 +1,121 @@ +/** + * 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: 1.4 2007/10/21 22:19:07 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * AbstractChart + * + * Authors : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : May 3 2007 + * Updated : $Date: 2007/10/21 22:19:07 $ + * $Revision: 1.4 $ + */ + +package se.sics.mspsim.ui; + +import java.awt.Graphics2D; +import java.util.Hashtable; + +/** + * + */ +public abstract class AbstractChart implements Chart { + + protected String name; + protected double minx, maxx; + protected double miny, maxy; + protected boolean autoscale = true; + private Hashtable<String,Object> config = new Hashtable<String,Object>(); + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isAutoscaling() { + return autoscale; + } + + public void setAutoscale() { + if (!this.autoscale) { + this.autoscale = true; + updateMinMax(); + } + } + + public void setMinMax(double minVal, double maxVal) { + miny = minVal; + maxy = maxVal; + autoscale = false; + } + + public double getMinX() { + return minx; + } + + public double getMaxX() { + return maxx; + } + + public double getMinY() { + return miny; + } + + public double getMaxY() { + return maxy; + } + + public Object getConfig(String param) { + return getConfig(param, null); + } + + public Object getConfig(String param, Object defVal) { + Object retVal = config.get(param); + return retVal != null ? retVal : defVal; + } + + public void setConfig(String param, Object value) { + if (value != null) { + config.put(param, value); + } else { + config.remove(param); + } + } + + protected abstract void updateMinMax(); + + public abstract void drawChart(Graphics2D g, double xfac, double yfac, + int width, int height); + +} Added: mspsim/se/sics/mspsim/ui/Chart.java =================================================================== --- mspsim/se/sics/mspsim/ui/Chart.java (rev 0) +++ mspsim/se/sics/mspsim/ui/Chart.java 2008-01-28 11:09:37 UTC (rev 91) @@ -0,0 +1,66 @@ +/** + * 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: 1.4 2007/10/21 22:19:07 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * Chart + * + * Authors : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : April 26 2007 + * Updated : $Date: 2007/10/21 22:19:07 $ + * $Revision: 1.4 $ + */ + +package se.sics.mspsim.ui; +import java.awt.Graphics2D; + +/** + * + */ +public interface Chart { + + public String getName(); + + public void setAutoscale(); + public void setMinMax(double minValue, double maxValue); + + public double getMaxY(); + public double getMinY(); + public double getMaxX(); + public double getMinX(); + + public Object getConfig(String param); + public Object getConfig(String param, Object defaultValue); + public void setConfig(String param, Object value); + + public void drawChart(Graphics2D g, double xfac, double yfac, int width, int height); + +} Added: mspsim/se/sics/mspsim/ui/ChartPanel.java =================================================================== --- mspsim/se/sics/mspsim/ui/ChartPanel.java (rev 0) +++ mspsim/se/sics/mspsim/ui/ChartPanel.java 2008-01-28 11:09:37 UTC (rev 91) @@ -0,0 +1,344 @@ +/** + * 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: 1.4 2007/10/21 22:19:07 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * ChartPanel + * + * Authors : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : April 26 2007 + * Updated : $Date: 2007/10/21 22:19:07 $ + * $Revision: 1.4 $ + */ + +package se.sics.mspsim.ui; +import java.awt.Color; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Insets; +import java.util.ArrayList; +import java.util.Hashtable; + +import javax.swing.BorderFactory; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.border.Border; + +/** + * + */ +public class ChartPanel extends JComponent { + + private static final long serialVersionUID = 7243446493049199594L; + + public static final String COLOR_TICK = "color.tick"; + + private static final Border DEFAULT_BORDER = + BorderFactory.createEmptyBorder(10,10,10,10); + + private static final Color[] DEFAULT_COLOR = { + Color.blue, new Color(0xff008000), Color.red, Color.black + }; + + private static final Color LIGHT_GRAY = new Color(0xff909090); + + private ArrayList<Chart> charts = new ArrayList<Chart>(); + private Hashtable<String,Object> config = new Hashtable<String,Object>(); + private Chart[] chartCache = null; + + private Chart axisChart; + + /** + * + */ + public ChartPanel() { + setForeground(Color.black); + setBackground(Color.white); + setBorder(DEFAULT_BORDER); + setOpaque(true); + } + + public Chart getAxisChart() { + return axisChart; + } + + public void setAxisChart(Chart chart) { + this.axisChart = chart; + } + + public synchronized void addChart(Chart chart) { + charts.add(chart); + chartCache = null; + } + + public synchronized void removeChart(Chart chart) { + charts.remove(chart); + chartCache = null; + } + + public synchronized Chart getChart(String name) { + for (int i = 0, n = charts.size(); i < n; i++) { + if (name.equals(charts.get(i).getName())) { + return charts.get(i); + } + } + return null; + } + + public synchronized Chart[] getCharts() { + if (chartCache == null) { + chartCache = charts.toArray(new Chart[charts.size()]); + } + return chartCache; + } + + public Object getConfig(String param) { + return getConfig(param, null); + } + + public Object getConfig(String param, Object defVal) { + Object retVal = config.get(param); + return retVal != null ? retVal : defVal; + } + + public void setConfig(String param, Object value) { + if (value != null) { + config.put(param, value); + } else { + config.remove(param); + } + } + + private Color getDefaultColor(int index) { + return DEFAULT_COLOR[index % DEFAULT_COLOR.length]; + } + + + // ------------------------------------------------------------------- + // Paint handling + // ------------------------------------------------------------------- + + protected void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D) g.create(); + try { + if (isOpaque()) { + g2d.setColor(getBackground()); + g2d.fillRect(0, 0, getWidth(), getHeight()); + } + paintCharts(g2d); + } finally { + g2d.dispose(); + } + } + + protected void paintCharts(Graphics2D g) { + Chart axisChart = this.axisChart; + Color foreground = getForeground(); + Color tickColor = (Color) getConfig(COLOR_TICK, LIGHT_GRAY); + FontMetrics fm = getFontMetrics(g.getFont()); + int fmHeight = fm.getAscent(); + Insets insets = getInsets(); + int height = getHeight(); + int width = getWidth(); + int leftInset = 40; + height -= insets.top + insets.bottom + fmHeight + 2; + width -= leftInset + insets.left + insets.right + 2; + g.translate(leftInset + insets.left + 1, insets.top + 1); + + g.setColor(foreground); + g.drawRect(-1, -1, width + 2, height + 2); + + Chart[] chs = getCharts(); + if (chs.length > 0) { + double totMaxY = Double.MIN_VALUE, totMinY = Double.MAX_VALUE; + double totMaxX = Double.MIN_VALUE, totMinX = Double.MAX_VALUE; + + for (int i = 0, n = chs.length; i < n; i++) { + Chart chart = chs[i]; + double maxY = chart.getMaxY(); + double minY = chart.getMinY(); + double minX = chart.getMinX(); + double maxX = chart.getMaxX(); + if (maxY >= minY && maxX > minX) { + if (maxY > totMaxY) totMaxY = maxY; + if (minY < totMinY) totMinY = minY; + + if (maxX > totMaxX) totMaxX = maxX; + if (minX < totMinX) totMinX = minX; + } + } + if (totMaxY >= totMinY && totMaxX > totMinX) { + double yfac = (1.0 * height) / (totMaxY - totMinY); + double xfac = (1.0 * width) / (totMaxX - totMinX); + int zero = height; + if (totMinY < 0) { + zero += (int) (yfac * totMinY); + } + + if (axisChart != null) { +// double maxY = axisChart.getMaxY(); +// double minY = axisChart.getMinY(); +// double minX = axisChart.getMinX(); +// double maxX = axisChart.getMaxX(); + +// if (maxY != minY && maxX != minX) { + // Draw zero line + g.setColor(tickColor); + g.drawLine(0, zero, width, zero); + g.setColor(foreground); + g.drawString("0", -4 - fm.stringWidth("0"), zero + fmHeight / 2); + + double gridValue = getGridValue(totMinY, totMaxY, 10); + for (double d = gridValue; d < totMaxY; d += gridValue) { + int y = (int) (zero - yfac * d); + String text = "" + (int) d; + int tlen = fm.stringWidth(text); + g.setColor(tickColor); + g.drawLine(0, y, width, y); + g.setColor(foreground); + g.drawString(text, -4 - tlen, y + fmHeight / 2); + } + for (double d = gridValue; d < -totMinY; d += gridValue) { + int y = (int) (zero + yfac * d); + String text = "" + (int) -d; + int tlen = fm.stringWidth(text); + g.setColor(tickColor); + g.drawLine(0, y, width, y); + g.setColor(foreground); + g.drawString(text, -4 - tlen, y + fmHeight / 2); + } + + gridValue = getGridValue(totMinX, totMaxX, 10); + for (double d = gridValue; d < totMaxX; d += gridValue) { + int x = (int) (xfac * d); + String text = "" + (int) d; + int tlen = fm.stringWidth(text); + g.setColor(tickColor); + g.drawLine(x, 0, x, height); + g.setColor(foreground); + g.drawString(text, x - tlen / 2, height + fmHeight); + } + } + + for (int i = 0, n = chs.length; i < n; i++) { + Chart chart = chs[i]; + double maxY = chart.getMaxY(); + double minY = chart.getMinY(); + double minX = chart.getMinX(); + double maxX = chart.getMaxX(); + + if (maxY < minY || maxX <= minX) { + // No data in this chart + } else { +// double yfac = (1.0 * height) / (maxY - minY); +// double xfac = (1.0 * width) / (maxX - minX); + + g.setColor((Color) chart.getConfig("color", getDefaultColor(i))); + chart.drawChart(g, xfac, yfac, width, height); + } + } + } + } + } + + private double getGridValue(double totMinX, double totMaxX, int maxCount) { + double diff = totMaxX - totMinX; + if (diff <= 0) { + return 1; + } + double d = Math.log(diff) / Math.log(10); + int z = (int) d; + if ((d - z) > 0.69) { + z++; + } + if (z < 1) { + return 1; + } + d = Math.pow(10, z - 1); + if ((diff / (int) (1 * d)) <= maxCount) { + return (int) (1 * d); + } + if ((diff / (int) (2.5 * d)) <= maxCount) { + return (int) (2.5 * d); + } + return (int) (5 * d); + } + + + //------------------------------------------------------------------- + // Test Main + // ------------------------------------------------------------------- + + public static void main(String[] args) { + JFrame jf = new JFrame("test charts"); + jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + jf.setBounds(100,100,600,400); + jf.setVisible(true); + BarChart bc = new BarChart(); + LineChart lc = new LineChart(); + + int[] data = new int[40]; + for (int i = 0, n = data.length; i < n; i++) { + data[i] = (int) ((Math.random() * 300)); + } + bc.setConfig("color", new Color(0xffb0b0b0)); + bc.setData(data); + lc.setData(data); + + // bc.setMinMax(0, 500); + lc.setMinMax(-4096, 4096); + + ChartPanel chp = new ChartPanel(); + chp.addChart(lc); + chp.addChart(bc); + jf.getContentPane().add(chp); + jf.setVisible(true); + + while(true) { + try { + Thread.sleep(100); + } catch (Exception e) { + // Ignore interrupts + } + + int len = 1024; + data = new int[len]; + for (int i = 0, n = data.length; i < n; i++) { + data[i] = (int) (2500 - (Math.random() * 5000)); + } + lc.setData(data); + chp.repaint(); + } + + } + +} Added: mspsim/se/sics/mspsim/ui/ConstantLineChart.java =================================================================== --- mspsim/se/sics/mspsim/ui/ConstantLineChart.java (rev 0) +++ mspsim/se/sics/mspsim/ui/ConstantLineChart.java 2008-01-28 11:09:37 UTC (rev 91) @@ -0,0 +1,76 @@ +/** + * 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: 1.4 2007/10/21 22:19:07 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * ConstantLineChart + * + * Authors : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : April 26 2007 + * Updated : $Date: 2007/10/21 22:19:07 $ + * $Revision: 1.4 $ + */ + +package se.sics.mspsim.ui; + +import java.awt.Graphics2D; + +public class ConstantLineChart extends AbstractChart { + + private int lineY; + + public ConstantLineChart(int y) { + this.lineY = y; + } + + public ConstantLineChart(String name, int y) { + setName(name); + this.lineY = y; + updateMinMax(); + } + + public void drawChart(Graphics2D g, double xfac, double yfac, int width, int height) { + int zero = height; + if (getMinY() < 0) { + zero += (int) (yfac * getMinY()); + } + int y = (int) (zero - (yfac * lineY)); + g.drawLine(0, y, width, y); + } + + @Override + protected void updateMinMax() { + this.minx = 0; + this.maxx = 1; + this.miny = this.maxy = lineY; + } + +} Modified: mspsim/se/sics/mspsim/ui/ControlUI.java =================================================================== --- mspsim/se/sics/mspsim/ui/ControlUI.java 2008-01-28 11:08:40 UTC (rev 90) +++ mspsim/se/sics/mspsim/ui/ControlUI.java 2008-01-28 11:09:37 UTC (rev 91) @@ -57,11 +57,11 @@ import se.sics.mspsim.extutil.jfreechart.DataChart; import se.sics.mspsim.util.DebugInfo; import se.sics.mspsim.util.ELF; -import se.sics.mspsim.util.StackUI; public class ControlUI extends JPanel implements ActionListener { private static final String TITLE = "MSPSim monitor"; + private static final boolean USE_STACKUI = true; private JFrame window; private MSP430 cpu; @@ -82,16 +82,16 @@ super(new GridLayout(0, 1)); this.cpu = cpu; - this.stackUI = new StackUI(cpu); - DataChart test = new DataChart("Stack Monitor", "Bytes"); test.setupStackFrame(cpu); - - stackWindow = new JFrame("Stack"); - stackWindow.add(this.stackUI); - WindowUtils.restoreWindowBounds("StackUI", stackWindow); - WindowUtils.addSaveOnShutdown("StackUI", stackWindow); - stackWindow.setVisible(true); + if (USE_STACKUI) { + this.stackUI = new StackUI(cpu); + stackWindow = new JFrame("Stack"); + stackWindow.add(this.stackUI); + WindowUtils.restoreWindowBounds("StackUI", stackWindow); + WindowUtils.addSaveOnShutdown("StackUI", stackWindow); + stackWindow.setVisible(true); + } window = new JFrame(TITLE); // window.setSize(320,240); Added: mspsim/se/sics/mspsim/ui/IntSerieChart.java =================================================================== --- mspsim/se/sics/mspsim/ui/IntSerieChart.java (rev 0) +++ mspsim/se/sics/mspsim/ui/IntSerieChart.java 2008-01-28 11:09:37 UTC (rev 91) @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2007, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * $Id: 1.4 2007/10/21 22:19:07 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * IntSerieChart + * + * Authors : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : April 26 2007 + * Updated : $Date: 2007/10/21 22:19:07 $ + * $Revision: 1.4 $ + */ + +package se.sics.mspsim.ui; + +/** + * + */ +public abstract class IntSerieChart extends AbstractChart { + + protected int[] data; + + public void setData(int[] data) { + this.data = data; + updateMinMax(); + } + + protected void updateMinMax() { + this.minx = 0; + this.maxx = data == null ? 0 : data.length; + + if (!autoscale) { + // Do not update miny, maxy + } else if (data == null || data.length == 0) { + miny = maxy = 0.0; + } else { + miny = maxy = data[0]; + for (int i = 1, n = data.length; i < n; i++) { + int v = data[i]; + if (v < miny) miny = v; + if (v > maxy) maxy = v; + } + } + } + +} Added: mspsim/se/sics/mspsim/ui/LineChart.java =================================================================== --- mspsim/se/sics/mspsim/ui/LineChart.java (rev 0) +++ mspsim/se/sics/mspsim/ui/LineChart.java 2008-01-28 11:09:37 UTC (rev 91) @@ -0,0 +1,81 @@ +/** + * 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: 1.4 2007/10/21 22:19:07 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * LineChart + * + * Authors : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : April 26 2007 + * Updated : $Date: 2007/10/21 22:19:07 $ + * $Revision: 1.4 $ + */ + +package se.sics.mspsim.ui; +import java.awt.Graphics2D; + +/** + * + */ +public class LineChart extends IntSerieChart { + + public LineChart() { + // Do nothing + } + + public LineChart(String name) { + setName(name); + } + + public void drawChart(Graphics2D g, double xfac, double yfac, int width, int height) { + int[] lastData = this.data; + if (lastData != null) { +// int minWidth = 1; +// if (xfac > 1) minWidth = (int) (xfac + 0.9); + int lastX = -1; + int lastY = -1; + int zero = height; + if (getMinY() < 0) { + zero += (int) (yfac * getMinY()); + } + for (int i = 0, n = lastData.length; i < n; i++) { + int y = (int) (zero - (yfac * lastData[i])); + int x = (int) (xfac * i); + if (lastX != -1) { + g.drawLine(x, y, lastX, lastY); + } + lastX = x; + lastY = y; + } + } + } + +} Copied: mspsim/se/sics/mspsim/ui/StackUI.java (from rev 79, mspsim/se/sics/mspsim/util/StackUI.java) =================================================================== --- mspsim/se/sics/mspsim/ui/StackUI.java (rev 0) +++ mspsim/se/sics/mspsim/ui/StackUI.java 2008-01-28 11:09:37 UTC (rev 91) @@ -0,0 +1,177 @@ +/** + * 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: StackUI.java,v 1.3 2007/10/21 21:17:35 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * StackUI + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 21:17:35 $ + * $Revision: 1.3 $ + */ + +package se.sics.mspsim.ui; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; + +import javax.swing.JPanel; + +import se.sics.mspsim.core.CPUMonitor; +import se.sics.mspsim.core.MSP430; +import se.sics.mspsim.util.MapTable; + +public class StackUI extends JPanel implements CPUMonitor { + + private static final long serialVersionUID = 8648239617509299768L; + + private static final int STACK_FRAME = 1024; + private int updateCyclePeriod = 2500; + + private MSP430 cpu; + private int heapStartAddress; + private int stackStartAddress = 0xa00; + private ChartPanel chartPanel; + private LineChart minStackChart; + private LineChart maxStackChart; + +// private DotDiagram diagram; + private int[] minData = new int[STACK_FRAME]; + private int[] maxData = new int[STACK_FRAME]; + private int[] minCache = new int[STACK_FRAME]; + private int[] maxCache = new int[STACK_FRAME]; +// private String[] notes = new String[STACK_FRAME]; + + private long lastCycles = 0; + private int pos = 0; + + private boolean update = false; + + public StackUI(MSP430 cpu) { + this(cpu, 2500); + } + + public StackUI(MSP430 cpu, int updateCyclePeriod) { + super(new BorderLayout()); + this.updateCyclePeriod = updateCyclePeriod; + this.cpu = cpu; + this.cpu.setRegisterWriteMonitor(MSP430.SP, this); + + if (cpu.getDisAsm() != null) { + MapTable mapTable = cpu.getDisAsm().getMap(); + if (mapTable != null) { + this.heapStartAddress = mapTable.heapStartAddress; + this.stackStartAddress = mapTable.stackStartAddress; + } + } + +// diagram = new DotDiagram(2); +// diagram.setDotColor(0, Color.green); +// diagram.setDotColor(1, Color.green); +// diagram.addConstant(Color.red, +// this.stackStartAddress - this.heapStartAddress); +// diagram.setShowGrid(true); +// add(diagram, BorderLayout.CENTER); + chartPanel = new ChartPanel(); + + ConstantLineChart maxChart = new ConstantLineChart("Max", this.stackStartAddress - this.heapStartAddress); + maxChart.setConfig("color", Color.red); + chartPanel.addChart(maxChart); + + minStackChart = new LineChart("Min Stack"); + minStackChart.setConfig("color", Color.green); + chartPanel.addChart(minStackChart); + + maxStackChart = new LineChart("Max Stack"); + maxStackChart.setConfig("color", Color.green); + chartPanel.addChart(maxStackChart); + chartPanel.setAxisChart(maxStackChart); + + add(chartPanel, BorderLayout.CENTER); + setPreferredSize(new Dimension(320, 200)); + } + +// public void addNote(String note) { +// notes[pos] = note; +// } + + public void paint(Graphics g) { + if (update) { + update = false; + + int p = pos; + copy(this.minData, this.minCache, p); + copy(this.maxData, this.maxCache, p); + minStackChart.setData(this.minCache); + maxStackChart.setData(this.maxCache); + } + super.paint(g); + } + + + private void copy(int[] data1, int[] data2, int p) { + if (p + 1 < data1.length) { + System.arraycopy(data1, p + 1, data2, 0, data1.length - p - 1); + } + if (p > 0) { + System.arraycopy(data1, 0, data2, data1.length - p, p); + } + } + + // ------------------------------------------------------------------- + // CPUMonitor + // ------------------------------------------------------------------- + + public void cpuAction(int type, int adr, int data) { + int size = ((stackStartAddress - data) + 0xffff) % 0xffff; + if (this.minData[pos] > size) { + this.minData[pos] = size; + } + if (this.maxData[pos] < size) { + this.maxData[pos] = size; + } + if (cpu.cpuCycles - lastCycles > updateCyclePeriod) { + lastCycles = cpu.cpuCycles; +// System.out.println("STACK UPDATE: " + type + "," + adr + "," + data + "," + pos); + pos = (pos + 1) % this.minData.length; + this.minData[pos] = Integer.MAX_VALUE; + this.maxData[pos] = 0; + update = true; + repaint(); +// this.notes[pos] = null; +// diagram.setData(0, this.minData, pos, this.minData.length); +// diagram.setDataWithNotes(1, this.maxData, notes, pos, this.maxData.length); + } + } + +} Modified: mspsim/se/sics/mspsim/util/DotDiagram.java =================================================================== --- mspsim/se/sics/mspsim/util/DotDiagram.java 2008-01-28 11:08:40 UTC (rev 90) +++ mspsim/se/sics/mspsim/util/DotDiagram.java 2008-01-28 11:09:37 UTC (rev 91) @@ -56,6 +56,8 @@ public class DotDiagram extends JComponent { + private static final long serialVersionUID = -2284181166518780931L; + public static final int NORMAL = 0; public static final int ADDITIVE = 1; public static final int FILLED_ADDITIVE = 2; @@ -84,7 +86,6 @@ private int lowerY; private double xspace; private int ySpacing = 0; - private int xSpacing = 0; private boolean rescale = false; private boolean gridVisible = false; @@ -275,14 +276,26 @@ protected void paintComponent(Graphics g0) { Graphics2D g = (Graphics2D) g0; + FontMetrics fm = g.getFontMetrics(); + int fmHeight = fm.getAscent(); Color oldColor = g.getColor(); + Insets insets = getInsets(); int width = getWidth(); int height = getHeight(); + int leftInset = 2; + int topInset = 2; int yLabelSize = 0; if (yLabel != null || xLabel != null) { - FontMetrics fm = g.getFontMetrics(); yLabelSize = fm.stringWidth(yLabel); } + if(gridVisible) { + topInset += fmHeight / 2; + height -= fmHeight / 2; + leftInset += 40; + } + height -= topInset + insets.top + insets.bottom; + width -= leftInset + insets.left + insets.right; + g.translate(leftInset + insets.left + 1, topInset + insets.top + 1); if (isOpaque()) { g.setColor(Color.white); @@ -377,21 +390,54 @@ if (gridVisible) { g.setColor(Color.lightGray); - for (int i = 0, n = 10; i < n; i++) { - g.drawLine(x + (i * sizeX) / 10, y, - x + (i * sizeX) / 10, y + sizeY - 1); + + double yfac = (1.0 * height) / (totMax - totMin); +// if (totMin < 0) { +// zero += (int) (yfac * totMin); +// } + // Draw zero line + g.setColor(Color.lightGray); + g.drawLine(0, zero, width, zero); + g.setColor(Color.black); + g.drawString("0", -4 - fm.stringWidth("0"), zero + fmHeight / 2); + + double div = getDivider(totMin, totMax); + for (double d = div; d < totMax; d += div) { + int dy = (int) (zero - yfac * d); + String text = "" + (int) d; + int tlen = fm.stringWidth(text); + g.setColor(Color.lightGray); + g.drawLine(0, dy, width, dy); + g.setColor(Color.black); + g.drawString(text, -4 - tlen, dy + fmHeight / 2); } - int z0 = zero - y; - int z1 = zero - (y + sizeY); - double tot = (ySpacing * factor) == 0 ? (sizeY / 10.0) - : (factor * ySpacing); - for (double i = 0; i < z0; i += tot) { - g.drawLine(x + 1, (int) (zero - i), x + sizeX, (int) (zero - i)); + for (double d = div; d < -totMin; d += div) { + int dy = (int) (zero + yfac * d); + String text = "" + (int) -d; + int tlen = fm.stringWidth(text); + g.setColor(Color.lightGray); + g.drawLine(0, dy, width, dy); + g.setColor(Color.black); + g.drawString(text, -4 - tlen, dy + fmHeight / 2); } - for (double i = 0; i > z1; i -= tot) { - g.drawLine(x + 1, (int) (zero - i), x + sizeX, (int) (zero - i)); - } + + +// for (int i = 0, n = 10; i < n; i++) { +// g.drawLine(x + (i * sizeX) / 10, y, +// x + (i * sizeX) / 10, y + sizeY - 1); +// } +// int z0 = zero - y; +// int z1 = zero - (y + sizeY); +// double tot = (ySpacing * factor) == 0 ? (sizeY / 10.0) +// : (factor * ySpacing); +// for (double i = 0; i < z0; i += tot) { +// g.drawLine(x + 1, (int) (zero - i), x + sizeX, (int) (zero - i)); +// } +// +// for (double i = 0; i > z1; i -= tot) { +// g.drawLine(x + 1, (int) (zero - i), x + sizeX, (int) (zero - i)); +// } } if (isAdditive) { @@ -488,8 +534,28 @@ g.scale(height/200.0, width/200.0); g.drawString(yLabel, -100 - yLabelSize/2, 10); } + g.setColor(oldColor); } + private double getDivider(double minY, double maxY) { + double diff = Math.abs(maxY - minY); + if (diff >= 1500) { + return 500.0; + } + if (diff >= 400) { + return 100.0; + } + if (diff >= 80) { + return 20.0; + } + if (diff >= 20) { + return 10.0; + } + if (diff >= 10) { + return 5.0; + } + return 1.0; + } // ------------------------------------------------------------------- Deleted: mspsim/se/sics/mspsim/util/StackUI.java =================================================================== --- mspsim/se/sics/mspsim/util/StackUI.java 2008-01-28 11:08:40 UTC (rev 90) +++ mspsim/se/sics/mspsim/util/StackUI.java 2008-01-28 11:09:37 UTC (rev 91) @@ -1,121 +0,0 @@ -/** - * 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: StackUI.java,v 1.3 2007/10/21 21:17:35 nfi Exp $ - * - * ----------------------------------------------------------------- - * - * StackUI - * - * Author : Joakim Eriksson - * Created : Sun Oct 21 22:00:00 2007 - * Updated : $Date: 2007/10/21 21:17:35 $ - * $Revision: 1.3 $ - */ - -package se.sics.mspsim.util; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import javax.swing.JPanel; - -import se.sics.mspsim.core.*; - -public class StackUI extends JPanel implements CPUMonitor { - - private static final int STACK_FRAME = 1024; - private int updateCyclePeriod = 2500; - - private MSP430 cpu; - private int heapStartAddress; - private int stackStartAddress = 0xa00; - private DotDiagram diagram; - private int[] minData = new int[STACK_FRAME]; - private int[] maxData = new int[STACK_FRAME]; - private String[] notes = new String[STACK_FRAME]; - - private long lastCycles = 0; - private int pos = 0; - - public StackUI(MSP430 cpu) { - this(cpu, 2500); - } - - public StackUI(MSP430 cpu, int updateCyclePeriod) { - super(new BorderLayout()); - this.updateCyclePeriod = updateCyclePeriod; - this.cpu = cpu; - this.cpu.setRegisterWriteMonitor(MSP430.SP, this); - - if (cpu.getDisAsm() != null) { - MapTable mapTable = cpu.getDisAsm().getMap(); - if (mapTable != null) { - this.heapStartAddress = mapTable.heapStartAddress; - this.stackStartAddress = mapTable.stackStartAddress; - } - } - - diagram = new DotDiagram(2); - diagram.setDotColor(0, Color.green); - diagram.setDotColor(1, Color.green); - diagram.addConstant(Color.red, - this.stackStartAddress - this.heapStartAddress); - add(diagram, BorderLayout.CENTER); - setPreferredSize(new Dimension(320, 200)); - } - - public void addNote(String note) { - notes[pos] = note; - } - - // ------------------------------------------------------------------- - // CPUMonitor - // ------------------------------------------------------------------- - - public void cpuAction(int type, int adr, int data) { - int size = ((stackStartAddress - data) + 0xffff) % 0xffff; - if (this.minData[pos] > size) { - this.minData[pos] = size; - } - if (this.maxData[pos] < size) { - this.maxData[pos] = size; - } - if (cpu.cpuCycles - lastCycles > updateCyclePeriod) { - lastCycles = cpu.cpuCycles; - //System.out.println("STACK UPDATE: " + type + "," + adr + "," + data); - pos = (pos + 1) % this.minData.length; - this.minData[pos] = 0; - this.maxData[pos] = 0; - this.notes[pos] = null; - diagram.setData(0, this.minData, pos, this.minData.length); - diagram.setDataWithNotes(1, this.maxData, notes, pos, this.maxData.length); - } - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-02-02 12:25:44
|
Revision: 101 http://mspsim.svn.sourceforge.net/mspsim/?rev=101&view=rev Author: joxe Date: 2008-02-02 04:25:41 -0800 (Sat, 02 Feb 2008) Log Message: ----------- minor fixes, including makeing it possible for ACLK to be faster than SMCLK in Timer. Modified Paths: -------------- mspsim/se/sics/mspsim/core/BasicClockModule.java mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/se/sics/mspsim/core/Timer.java mspsim/se/sics/mspsim/extutil/jfreechart/DataSourceSampler.java Modified: mspsim/se/sics/mspsim/core/BasicClockModule.java =================================================================== --- mspsim/se/sics/mspsim/core/BasicClockModule.java 2008-02-01 13:15:53 UTC (rev 100) +++ mspsim/se/sics/mspsim/core/BasicClockModule.java 2008-02-02 12:25:41 UTC (rev 101) @@ -58,7 +58,8 @@ // Based on the scatterweb code it looks like less than // 5Mhz is more correct... public static final int MAX_DCO_FRQ = 4915200; - public static final int DCO_FACTOR = MAX_DCO_FRQ / 2048; + public static final int MIN_DCO_FRQ = 0; + public static final int DCO_FACTOR = (MAX_DCO_FRQ - MIN_DCO_FRQ) / 2048; private MSP430Core core; Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2008-02-01 13:15:53 UTC (rev 100) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2008-02-02 12:25:41 UTC (rev 101) @@ -99,16 +99,16 @@ private int interruptMax = -1; // Op/instruction represents the last executed OP / instruction - int op; + private int op; int instruction; int servicedInterrupt = -1; IOUnit servicedInterruptUnit = null; - boolean interruptsEnabled = false; - boolean cpuOff = false; + private boolean interruptsEnabled = false; + private boolean cpuOff = false; // Not private since they are needed (for fast access...) - int dcoFrq = 2500000; + private int dcoFrq = 2500000; int aclkFrq = 32768; int smclkFrq = dcoFrq; Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2008-02-01 13:15:53 UTC (rev 100) +++ mspsim/se/sics/mspsim/core/Timer.java 2008-02-02 12:25:41 UTC (rev 101) @@ -472,10 +472,12 @@ } private int updateCounter(long cycles) { - int divider = 1; + // Needs to be non-integer since smclk Frq can be lower + // than aclk + double divider = 1; if (clockSource == SRC_ACLK) { - // Is this correct? Should possibly be divided with DCO clock? - divider = core.smclkFrq / core.aclkFrq; + // Should later be divided with DCO clock? + divider = 1.0 * core.smclkFrq / core.aclkFrq; } divider = divider * inputDivider; long cycctr = cycles - counterStart; Modified: mspsim/se/sics/mspsim/extutil/jfreechart/DataSourceSampler.java =================================================================== --- mspsim/se/sics/mspsim/extutil/jfreechart/DataSourceSampler.java 2008-02-01 13:15:53 UTC (rev 100) +++ mspsim/se/sics/mspsim/extutil/jfreechart/DataSourceSampler.java 2008-02-02 12:25:41 UTC (rev 101) @@ -121,11 +121,10 @@ public void update() { long time = cpu.cycles / 2; if (time > lastUpdate) { - System.out.println("adding time " + time); lastUpdate = time; timeSeries.add(new Millisecond(new Date(time)), dataSource.getValue()); } else { - System.out.println("IGNORING TIME " + time); +// System.out.println("IGNORING TIME " + time); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-02-05 00:15:40
|
Revision: 105 http://mspsim.svn.sourceforge.net/mspsim/?rev=105&view=rev Author: joxe Date: 2008-02-04 16:15:39 -0800 (Mon, 04 Feb 2008) Log Message: ----------- added initial emulation of Sky external flash (not complete) Modified Paths: -------------- mspsim/se/sics/mspsim/platform/sky/SkyNode.java Added Paths: ----------- mspsim/se/sics/mspsim/chip/M25P80.java Removed Paths: ------------- mspsim/se/sics/mspsim/platform/sky/ExtFlash.java Added: mspsim/se/sics/mspsim/chip/M25P80.java =================================================================== --- mspsim/se/sics/mspsim/chip/M25P80.java (rev 0) +++ mspsim/se/sics/mspsim/chip/M25P80.java 2008-02-05 00:15:39 UTC (rev 105) @@ -0,0 +1,225 @@ +/** + * 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: ExtFlash.java,v 1.3 2007/10/21 21:17:34 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * ExtFlash + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 21:17:34 $ + * $Revision: 1.3 $ + */ + +package se.sics.mspsim.chip; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; + +import se.sics.mspsim.core.*; + +public class M25P80 extends Chip implements USARTListener, PortListener { + + public static final int WRITE_STATUS = 0x01; + public static final int PAGE_PROGRAM = 0x02; + public static final int READ_DATA = 0x03; + public static final int WRITE_DISABLE = 0x04; + public static final int READ_STATUS = 0x05; + public static final int WRITE_ENABLE = 0x06; + public static final int READ_DATA_FAST = 0x0b; + public static final int READ_IDENT = 0x9f; + public static final int SECTOR_ERASE = 0xd8; + public static final int BULK_ERASE = 0xc7; + public static final int DEEP_POWER_DOWN = 0xb9; + public static final int WAKE_UP = 0xab; + + private int state = 0; + public static final int CHIP_SELECT = 0x10; + private boolean chipSelect; + + private USART usart; + private int pos; + private int status = 0; + + private boolean writeEnable = false; + + private int[] identity = new int[] { + 0x20,0x20,0x14,0x10, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 + }; + private int readAddress; + private int loadedAddress; + private byte[] readMemory = new byte[256]; + private byte[] buffer = new byte[256]; + + private RandomAccessFile file; + + public M25P80(USART usart) { + this.usart = usart; + try { + file = new RandomAccessFile("flash.bin", "rw"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + return; + } + + try { + file.setLength(1024 * 1024); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void dataReceived(USART source, int data) { + if (chipSelect) { + System.out.println("M25P80: byte received: " + data); + switch(state) { + case READ_IDENT: + source.byteReceived(identity[pos]); + pos++; + if (pos >= identity.length) + pos = 0; + return; + case WRITE_STATUS: + status = data; + source.byteReceived(0); + return; + case READ_DATA: + if (pos < 3) { + readAddress = (readAddress << 8) + data; + source.byteReceived(0); + } else { + source.byteReceived(readMemory(readAddress++)); + if (readAddress > 0xfffff) { + readAddress = 0; + } + } + return; + case PAGE_PROGRAM: + if (pos < 3) { + readAddress = (readAddress << 8) + data; + source.byteReceived(0); + } else { + // Do the programming!!! + source.byteReceived(0); + writeBuffer((readAddress++) & 0xff, data); + } + return; + } + + switch (data) { + case WRITE_ENABLE: + System.out.println("M2580: Write Enable"); + writeEnable = true; + break; + case WRITE_DISABLE: + System.out.println("M2580: Write Disable"); + writeEnable = false; + break; + case READ_IDENT: + System.out.println("M2580: Read ident."); + state = READ_IDENT; + pos = 0; + source.byteReceived(identity[pos++]); + return; + case READ_STATUS: + System.out.println("M2580: Read status."); + status = status & (0xff - 1 - 2) | (writeEnable ? 0x02 : 0x00); + source.byteReceived(status); + return; + case WRITE_STATUS: + System.out.println("M2580: Write status"); + state = WRITE_STATUS; + break; + case READ_DATA: + System.out.println("M2580: Read Data"); + state = READ_DATA; + pos = 0; + break; + case PAGE_PROGRAM: + System.out.println("M2580: Page Program"); + state = PAGE_PROGRAM; + pos = 0; + break; + case SECTOR_ERASE: + System.out.println("M2580: Sector Erase"); + state = SECTOR_ERASE; + pos = 0; + break; + } + source.byteReceived(0); + } + } + + // Should return correct data! + private int readMemory(int address) { + System.out.println("M2580: Reading memory address: " + Integer.toHexString(address)); + ensureLoaded(address); + return readMemory[address & 0xff]; + } + + private void writeBuffer(int address, int data) { + buffer[address] = (byte) data; + } + + private void ensureLoaded(int address) { + if (!((loadedAddress & 0xfff00) == (address & 0xfff00))) { + try { + System.out.println("M2580: Loading memory: " + (address & 0xfff00)); + file.seek(address & 0xfff00); + file.readFully(readMemory); + } catch (IOException e) { + e.printStackTrace(); + } + loadedAddress = address & 0xfff00; + } + } + + public void portWrite(IOPort source, int data) { + // Chip select = active low... + chipSelect = (data & CHIP_SELECT) == 0; + System.out.println("M25P80: write to Port4: " + + Integer.toString(data, 16) + + " CS:" + chipSelect); + state = 0; + } + + public int getModeMax() { + return 0; + } + + public String getName() { + return "M25P80: external flash"; + } + + +} // ExtFlash Deleted: mspsim/se/sics/mspsim/platform/sky/ExtFlash.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/ExtFlash.java 2008-02-04 21:10:47 UTC (rev 104) +++ mspsim/se/sics/mspsim/platform/sky/ExtFlash.java 2008-02-05 00:15:39 UTC (rev 105) @@ -1,73 +0,0 @@ -/** - * 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: ExtFlash.java,v 1.3 2007/10/21 21:17:34 nfi Exp $ - * - * ----------------------------------------------------------------- - * - * ExtFlash - * - * Author : Joakim Eriksson - * Created : Sun Oct 21 22:00:00 2007 - * Updated : $Date: 2007/10/21 21:17:34 $ - * $Revision: 1.3 $ - */ - -package se.sics.mspsim.platform.sky; -import se.sics.mspsim.core.*; - -public class ExtFlash implements USARTListener, PortListener { - - private int state = 0; - public static final int CHIP_SELECT = 0x10; - private boolean chipSelect; - - private USART usart; - - public ExtFlash(USART usart) { - this.usart = usart; - } - - public void dataReceived(USART source, int data) { - if (chipSelect) { - System.out.println("ExtFlash: byte received: " + data); - source.byteReceived(42); - } - } - - public void portWrite(IOPort source, int data) { - // Chip select = active low... - chipSelect = (data & CHIP_SELECT) == 0; - System.out.println("ExtFlash: write to Port4: " + - Integer.toString(data, 16) - + " CS:" + chipSelect); - } - - -} // ExtFlash Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-02-04 21:10:47 UTC (rev 104) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-02-05 00:15:39 UTC (rev 105) @@ -43,6 +43,7 @@ import java.io.IOException; import se.sics.mspsim.chip.CC2420; +import se.sics.mspsim.chip.M25P80; import se.sics.mspsim.core.Chip; import se.sics.mspsim.core.IOPort; import se.sics.mspsim.core.IOUnit; @@ -88,7 +89,7 @@ private IOPort port5; private CC2420 radio; - private ExtFlash flash; + private M25P80 flash; public static final int BLUE_LED = 0x40; public static final int GREEN_LED = 0x20; @@ -130,7 +131,7 @@ radio.setCCAPort(port1, CC2420_CCA); radio.setFIFOPPort(port1, CC2420_FIFOP); radio.setFIFOPort(port1, CC2420_FIFO); - flash = new ExtFlash((USART)usart0); + flash = new M25P80((USART)usart0); ((USART) usart0).setUSARTListener(this); port4 = (IOPort) cpu.getIOUnit("Port 4"); if (port4 != null && port4 instanceof IOPort) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-02-05 14:31:16
|
Revision: 107 http://mspsim.svn.sourceforge.net/mspsim/?rev=107&view=rev Author: joxe Date: 2008-02-05 06:31:14 -0800 (Tue, 05 Feb 2008) Log Message: ----------- First working version of external flash for the Sky platform Modified Paths: -------------- mspsim/se/sics/mspsim/chip/CC2420.java mspsim/se/sics/mspsim/chip/M25P80.java mspsim/se/sics/mspsim/core/MSP430Constants.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-02-05 00:26:31 UTC (rev 106) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2008-02-05 14:31:14 UTC (rev 107) @@ -45,7 +45,7 @@ public class CC2420 extends Chip implements USARTListener { - public static final boolean DEBUG = true; + public static final boolean DEBUG = false; public static final int REG_SNOP = 0x00; public static final int REG_SXOSCON = 0x01; @@ -195,7 +195,7 @@ if (address == REG_RXFIFO) { // check read/write??? - System.out.println("CC2420: Reading RXFIFO!!!"); +// System.out.println("CC2420: Reading RXFIFO!!!"); state = READ_RXFIFO; } else if (address == REG_TXFIFO) { state = WRITE_TXFIFO; @@ -233,8 +233,8 @@ } break; case READ_RXFIFO: - System.out.println("CC2420: RXFIFO READ => " + - memory[RAM_RXFIFO + rxCursor]); +// 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; @@ -276,19 +276,19 @@ switch (data) { case REG_SRXON: - System.out.println("CC2420: Strobe RX-ON!!!"); +// System.out.println("CC2420: Strobe RX-ON!!!"); setMode(MODE_RX_ON); break; case REG_SRFOFF: - System.out.println("CC2420: Strobe RXTX-OFF!!!"); +// System.out.println("CC2420: Strobe RXTX-OFF!!!"); setMode(MODE_TXRX_OFF); break; case REG_STXON: - System.out.println("CC2420: Strobe TXON!"); +// System.out.println("CC2420: Strobe TXON!"); setMode(MODE_TXRX_ON); break; case REG_STXONCCA: - System.out.println("CC2420: Strobe TXONCCA!"); +// System.out.println("CC2420: Strobe TXONCCA!"); setMode(MODE_TXRX_ON); break; case REG_SFLUSHRX: @@ -307,7 +307,7 @@ chipSelect = select; if (!chipSelect) state = WAITING; - System.out.println("CC2420: chipSelect: " + chipSelect); +// System.out.println("CC2420: chipSelect: " + chipSelect); } public void setCCAPort(IOPort port, int pin) { Modified: mspsim/se/sics/mspsim/chip/M25P80.java =================================================================== --- mspsim/se/sics/mspsim/chip/M25P80.java 2008-02-05 00:26:31 UTC (rev 106) +++ mspsim/se/sics/mspsim/chip/M25P80.java 2008-02-05 14:31:14 UTC (rev 107) @@ -48,6 +48,8 @@ public class M25P80 extends Chip implements USARTListener, PortListener { + public static final boolean DEBUG = false; + public static final int WRITE_STATUS = 0x01; public static final int PAGE_PROGRAM = 0x02; public static final int READ_DATA = 0x03; @@ -78,6 +80,7 @@ }; private int readAddress; private int loadedAddress; + private int blockWriteAddress; private byte[] readMemory = new byte[256]; private byte[] buffer = new byte[256]; @@ -101,7 +104,9 @@ public void dataReceived(USART source, int data) { if (chipSelect) { - System.out.println("M25P80: byte received: " + data); + if (DEBUG) { + System.out.println("M25P80: byte received: " + data); + } switch(state) { case READ_IDENT: source.byteReceived(identity[pos]); @@ -118,7 +123,7 @@ readAddress = (readAddress << 8) + data; source.byteReceived(0); pos++; - if (pos == 3) + if (DEBUG && pos == 3) System.out.println("M25P80: reading from " + Integer.toHexString(readAddress)); } else { source.byteReceived(readMemory(readAddress++)); @@ -127,11 +132,31 @@ } } return; + case SECTOR_ERASE: + if (pos < 3) { + readAddress = (readAddress << 8) + data; + source.byteReceived(0); + pos++; + if (pos == 3) { + // Clear buffer + sectorErase(readAddress); + } + } + return; case PAGE_PROGRAM: if (pos < 3) { readAddress = (readAddress << 8) + data; source.byteReceived(0); pos++; + if (pos == 3) { + // Clear buffer + for (int i = 0; i < buffer.length; i++) { + buffer[i] = (byte) 0xff; + } + blockWriteAddress = readAddress & 0xfff00; + if (DEBUG) + System.out.println("M25P80: programming at " + Integer.toHexString(readAddress)); + } } else { // Do the programming!!! source.byteReceived(0); @@ -139,43 +164,52 @@ } return; } - + if (DEBUG) + System.out.println("M25P80: new command: " + data); switch (data) { case WRITE_ENABLE: - System.out.println("M2580: Write Enable"); + if (DEBUG) + System.out.println("M25P80: Write Enable"); writeEnable = true; break; case WRITE_DISABLE: - System.out.println("M2580: Write Disable"); + if (DEBUG) + System.out.println("M25P80: Write Disable"); writeEnable = false; break; case READ_IDENT: - System.out.println("M2580: Read ident."); + if (DEBUG) + System.out.println("M25P80: Read ident."); state = READ_IDENT; pos = 0; source.byteReceived(identity[pos++]); return; case READ_STATUS: - System.out.println("M2580: Read status."); - status = status & (0xff - 1 - 2) | (writeEnable ? 0x02 : 0x00); + status = (status & (0xff - 1 - 2)) | (writeEnable ? 0x02 : 0x00); source.byteReceived(status); + if (DEBUG) + System.out.println("M25P80: Read status => " + status); return; case WRITE_STATUS: - System.out.println("M2580: Write status"); + if (DEBUG) + System.out.println("M25P80: Write status"); state = WRITE_STATUS; break; case READ_DATA: - System.out.println("M2580: Read Data"); + if (DEBUG) + System.out.println("M25P80: Read Data"); state = READ_DATA; pos = readAddress = 0; break; case PAGE_PROGRAM: - System.out.println("M2580: Page Program"); + if (DEBUG) + System.out.println("M25P80: Page Program"); state = PAGE_PROGRAM; pos = readAddress = 0; break; case SECTOR_ERASE: - System.out.println("M2580: Sector Erase"); + if (DEBUG) + System.out.println("M25P80: Sector Erase"); state = SECTOR_ERASE; pos = 0; break; @@ -186,7 +220,8 @@ // Should return correct data! private int readMemory(int address) { - System.out.println("M2580: Reading memory address: " + Integer.toHexString(address)); + if (DEBUG) + System.out.println("M25P80: Reading memory address: " + Integer.toHexString(address)); ensureLoaded(address); return readMemory[address & 0xff]; } @@ -198,7 +233,8 @@ private void ensureLoaded(int address) { if (!((loadedAddress & 0xfff00) == (address & 0xfff00))) { try { - System.out.println("M2580: Loading memory: " + (address & 0xfff00)); + if (DEBUG) + System.out.println("M25P80: Loading memory: " + (address & 0xfff00)); file.seek(address & 0xfff00); file.readFully(readMemory); } catch (IOException e) { @@ -207,16 +243,59 @@ loadedAddress = address & 0xfff00; } } - + public void portWrite(IOPort source, int data) { // Chip select = active low... + if (chipSelect && (data & CHIP_SELECT) != 0) { + // Chip select will go "off" + switch(state) { + case PAGE_PROGRAM: + programPage(); + break; + } + } chipSelect = (data & CHIP_SELECT) == 0; - System.out.println("M25P80: write to Port4: " + - Integer.toString(data, 16) - + " CS:" + chipSelect); +// System.out.println("M25P80: write to Port4: " + +// Integer.toString(data, 16) +// + " CS:" + chipSelect); state = 0; } + private void programPage() { + ensureLoaded(blockWriteAddress); + for (int i = 0; i < readMemory.length; i++) { + readMemory[i] &= buffer[i]; + } + writeBack(blockWriteAddress, readMemory); + } + + private void sectorErase(int address) { + int sectorAddress = address & 0xf0000; + for (int i = 0; i < buffer.length; i++) { + buffer[i] = (byte)0xff; + } + // Erase a complete sector + blockWriteAddress = sectorAddress; + for (int i = 0; i < 0x100; i++) { + if (DEBUG) + System.out.println("M25P80: erasing at " + Integer.toHexString(blockWriteAddress)); + writeBack(blockWriteAddress, buffer); + blockWriteAddress += 0x100; + } + } + + + private void writeBack(int address, byte[] data) { + try { + if (DEBUG) + System.out.println("M25P80: Writing data to disk at " + Integer.toHexString(address)); + file.seek(address & 0xfff00); + file.write(data); + } catch (IOException e) { + e.printStackTrace(); + } + } + public int getModeMax() { return 0; } Modified: mspsim/se/sics/mspsim/core/MSP430Constants.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Constants.java 2008-02-05 00:26:31 UTC (rev 106) +++ mspsim/se/sics/mspsim/core/MSP430Constants.java 2008-02-05 14:31:14 UTC (rev 107) @@ -138,5 +138,5 @@ public static final int CLKCAPTURE_BOTH = 3; - public static final int DEBUGGING_LEVEL = 1; + public static final int DEBUGGING_LEVEL = 0; } Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-02-05 00:26:31 UTC (rev 106) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-02-05 14:31:14 UTC (rev 107) @@ -40,6 +40,7 @@ */ package se.sics.mspsim.platform.sky; +import java.io.File; import java.io.IOException; import se.sics.mspsim.chip.CC2420; @@ -227,6 +228,7 @@ node.gui = new SkyGui(node); ControlUI control = new ControlUI(cpu, elf); HighlightSourceViewer sourceViewer = new HighlightSourceViewer(); + sourceViewer.addSearchPath(new File("../../contiki-2.x/examples/energest-demo/")); control.setSourceViewer(sourceViewer); if (args.length > 1) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-02-12 23:09:31
|
Revision: 127 http://mspsim.svn.sourceforge.net/mspsim/?rev=127&view=rev Author: joxe Date: 2008-02-12 15:09:18 -0800 (Tue, 12 Feb 2008) Log Message: ----------- added event system for exernally clocked chips (radios, ext mems, etc). Modified Paths: -------------- mspsim/se/sics/mspsim/chip/CC2420.java mspsim/se/sics/mspsim/core/MSP430Core.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-02-12 12:03:01 UTC (rev 126) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2008-02-12 23:09:18 UTC (rev 127) @@ -125,11 +125,11 @@ public static final int MODE_TXRX_ON = 0x02; public static final int MODE_MAX = MODE_TXRX_ON; - // when reading registrers this flag is set! + // 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 comtains + // When accessing RAM the second byte of the address contains // a flag indicating read/write public static final int FLAG_RAM_READ = 0x20; @@ -169,11 +169,27 @@ private boolean rxPacket; private int rxCursor; private int rxLen; + private int txCursor; private PacketListener packetListener; - public CC2420() { + private MSP430Core cpu; + + private TimeEvent transmissionEvent = new TimeEvent(0) { + public void execute(long t) { + System.out.println(getName() + ": **** Transmitting package to listener (if any)"); + if (packetListener != null) { + int len = memory[RAM_TXFIFO]; + int[] data = new int[len]; + System.arraycopy(memory, RAM_TXFIFO + 1, data, 0, len); + packetListener.transmissionEnded(data); + } + } + }; + + public CC2420(MSP430Core cpu) { registers[REG_SNOP] = 0; + this.cpu = cpu; } public void dataReceived(USART source, int data) { @@ -246,6 +262,9 @@ updateFifopPin(); } break; + case WRITE_TXFIFO: + memory[RAM_TXFIFO + txCursor++] = data & 0xff; + break; case RAM_ACCESS: if (pos == 0) { address = address | (data << 1) & 0x180; @@ -288,16 +307,32 @@ case REG_STXON: // System.out.println("CC2420: Strobe TXON!"); setMode(MODE_TXRX_ON); + transmitPacket(); break; case REG_STXONCCA: // System.out.println("CC2420: Strobe TXONCCA!"); setMode(MODE_TXRX_ON); + transmitPacket(); break; case REG_SFLUSHRX: flushRX(); break; + case REG_SFLUSHTX: + flushTX(); + break; } } + + private void transmitPacket() { + int len = memory[RAM_TXFIFO]; + int kBps = 250000 / 8; + double time = 1.0 * len / kBps; + System.out.println(getName() + " Transmitting " + len + " bytes => " + time + " sec"); + if (packetListener != null) { + packetListener.transmissionStarted(); + cpu.scheduleTimeEventMillis(transmissionEvent, 1000 * time); + } + } private void setMode(int mode) { this.mode = mode; @@ -369,6 +404,12 @@ updateFifopPin(); } + // TODO: update any pins here? + private void flushTX() { + txCursor = 0; + } + + private void updateFifopPin() { fifopPort.setPinState(fifopPin, rxPacket ? 1 : 0); } Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2008-02-12 12:03:01 UTC (rev 126) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2008-02-12 23:09:18 UTC (rev 127) @@ -112,13 +112,17 @@ int aclkFrq = 32768; int smclkFrq = dcoFrq; - long lastTime = 0; + long lastCyclesTime = 0; + long lastVTime = 0; long currentTime = 0; double currentDCOFactor = 1.0; // Clk A can be "captured" by timers - needs to be handled close to CPU...? private int clkACaptureMode = CLKCAPTURE_NONE; // Other clocks too... + private long nextEventCycles; + private EventQueue vTimeEventQueue = new EventQueue(); + private long nextVTimeEventCycles; public MSP430Core(int type) { // Ignore type for now... @@ -335,8 +339,9 @@ public void setDCOFrq(int frequency, int smclkFrq) { dcoFrq = frequency; this.smclkFrq = smclkFrq; - // update time before updating DCOfactor - getTime(); + // update last virtual time before updating DCOfactor + lastCyclesTime = cycles; + lastVTime = getTime(); currentDCOFactor = 1.0 * BasicClockModule.MAX_DCO_FRQ / frequency; if (DEBUG) System.out.println("Set smclkFrq: " + smclkFrq); @@ -344,17 +349,75 @@ // returns global time counted in max speed of DCOs (~5Mhz) public long getTime() { - long diff = cycles - lastTime; - currentTime += (long) (diff * currentDCOFactor); - return currentTime; + long diff = cycles - lastCyclesTime; + return lastVTime + (long) (diff * currentDCOFactor); } + + // Converts a virtual time to a cycles time according to the current + // cycle speed + private long convertVTime(long vTime) { + long tmpTime = lastCyclesTime + (long) ((vTime - lastVTime) / currentDCOFactor); +// System.out.println("ConvertVTime: vTime=" + vTime + " => " + tmpTime); + return tmpTime; + } // get elapsed time in seconds - public double getTimeSeconds() { - return 1.0 * getTime() / BasicClockModule.MAX_DCO_FRQ; + public double getTimeMillis() { + return 1000.0 * getTime() / BasicClockModule.MAX_DCO_FRQ; } - // Should also return avtieve units... + + + private void executeEvents() { + if (cycles >= nextVTimeEventCycles) { + TimeEvent te = vTimeEventQueue.popFirst(); + long now = getTime(); + te.execute(now); + if (vTimeEventQueue.nextTime > 0) { + nextVTimeEventCycles = convertVTime(vTimeEventQueue.nextTime); + nextEventCycles = nextVTimeEventCycles; + } + } else { + // Allow 1000 cycles to pass if nothing to do... + nextEventCycles = cycles + 1000; + } + } + +// public void scheduleCycleEvent(long cycles, TimeEvent event) { +// } + + + /** + * Schedules a new Time event using the virtual time clock + * @param event + * @param time + */ + public void scheduleTimeEvent(TimeEvent event, long time) { + long currentNext = vTimeEventQueue.nextTime; + vTimeEventQueue.addEvent(event, time); + if (currentNext != vTimeEventQueue.nextTime) { + // This is only valid when not having a cycle event queue also... + // if we have it needs to be checked also! + nextVTimeEventCycles = nextEventCycles = + convertVTime(vTimeEventQueue.nextTime); + } + } + + + /** + * Schedules a new Time event msec milliseconds in the future + * @param event + * @param time + */ + public void scheduleTimeEventMillis(TimeEvent event, double msec) { + long time = (long) (getTime() + msec / 1000 * BasicClockModule.MAX_DCO_FRQ); +// System.out.println("Scheduling at: " + time + " (" + msec + ") getTime: " + getTime()); + scheduleTimeEvent(event, time); + } + + + + // Should also return active units... public IOUnit getIOUnit(String name) { for (int i = 0, n = passiveIOUnits.length; i < n; i++) { if (name.equals(passiveIOUnits[i].getName())) { @@ -476,7 +539,8 @@ // System.out.println("Smallest IO cycles: " + smallestCyc + " => " + // ioUnits[index].getName()); } - + + // Read method that handles read from IO units! public int read(int address, boolean word) { int val = 0; @@ -563,9 +627,9 @@ // ------------------------------------------------------------------- // Event processing // ------------------------------------------------------------------- -// if (cycles >= nextEventCycles) { -// executeEvents(); -// } + if (cycles >= nextEventCycles) { + executeEvents(); + } // ------------------------------------------------------------------- // (old) I/O processing Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-02-12 12:03:01 UTC (rev 126) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-02-12 23:09:18 UTC (rev 127) @@ -45,11 +45,13 @@ import se.sics.mspsim.chip.CC2420; import se.sics.mspsim.chip.M25P80; +import se.sics.mspsim.chip.PacketListener; import se.sics.mspsim.core.Chip; 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.TimeEvent; import se.sics.mspsim.core.USART; import se.sics.mspsim.core.USARTListener; import se.sics.mspsim.extutil.highlight.HighlightSourceViewer; @@ -133,7 +135,7 @@ IOUnit usart0 = cpu.getIOUnit("USART 0"); if (usart0 instanceof USART) { - radio = new CC2420(); + radio = new CC2420(cpu); radio.setCCAPort(port1, CC2420_CCA); radio.setFIFOPPort(port1, CC2420_FIFOP); radio.setFIFOPort(port1, CC2420_FIFO); @@ -150,6 +152,24 @@ stats.addMonitor(this); stats.addMonitor(radio); stats.addMonitor(cpu); + + cpu.scheduleTimeEventMillis(new TimeEvent(0) { + public void execute(long t) { + System.out.println("SkyNode: a second elapsed (wall time): " + t + " millis: " + SkyNode.this.cpu.getTimeMillis()); + SkyNode.this.cpu.scheduleTimeEventMillis(this, 1000.0); + } + }, 1000.0); + + // TODO: remove this test... + radio.setPacketListener(new PacketListener() { + public void transmissionEnded(int[] receivedData) { + System.out.println(getName() + " got packet from radio " + SkyNode.this.cpu.getTimeMillis()); + } + public void transmissionStarted() { + System.out.println(getName() + " got indication on transmission from radio " + SkyNode.this.cpu.getTimeMillis()); + } + }); + } public void setButton(boolean hi) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-02-19 16:04:44
|
Revision: 136 http://mspsim.svn.sourceforge.net/mspsim/?rev=136&view=rev Author: joxe Date: 2008-02-19 08:04:40 -0800 (Tue, 19 Feb 2008) Log Message: ----------- fixed symbol-sourcefile bug in elfloading Modified Paths: -------------- mspsim/se/sics/mspsim/chip/CC2420.java mspsim/se/sics/mspsim/util/ELF.java Modified: mspsim/se/sics/mspsim/chip/CC2420.java =================================================================== --- mspsim/se/sics/mspsim/chip/CC2420.java 2008-02-18 20:05:45 UTC (rev 135) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2008-02-19 16:04:40 UTC (rev 136) @@ -27,7 +27,7 @@ * * This file is part of MSPSim. * - * $Id: CC2420.java,v 1.4 2007/10/22 18:03:41 joakime Exp $ + * $Id:$ * * ----------------------------------------------------------------- * @@ -35,8 +35,7 @@ * * Author : Joakim Eriksson * Created : Sun Oct 21 22:00:00 2007 - * Updated : $Date: 2007/10/22 18:03:41 $ - * $Revision: 1.4 $ + * */ package se.sics.mspsim.chip; @@ -100,12 +99,12 @@ public static final int REG_TXFIFO = 0x3E; public static final int REG_RXFIFO = 0x3F; - public static final int ST_XOSC16M_STABLE = 1 << 6; - public static final int ST_TX_UNDERFLOW = 1 << 5; - public static final int ST_ENC_BUSY = 1 << 4; - public static final int ST_TX_ACTIVE = 1 << 3; - public static final int ST_LOCK = 1 << 2; - public static final int ST_RSSI_VALID = 1 << 1; + 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; @@ -147,7 +146,7 @@ private int address; private boolean ramRead = false; - private int status = ST_XOSC16M_STABLE; + private int status = STATUS_XOSC16M_STABLE | STATUS_RSSI_VALID; private int mode = MODE_TXRX_OFF; @@ -401,7 +400,7 @@ updateFifopPin(); } - private void flushRX() { + private void flushRX() { if (DEBUG) System.out.println("Flushing RX! was: " + rxPacket + " len = " + rxLen); Modified: mspsim/se/sics/mspsim/util/ELF.java =================================================================== --- mspsim/se/sics/mspsim/util/ELF.java 2008-02-18 20:05:45 UTC (rev 135) +++ mspsim/se/sics/mspsim/util/ELF.java 2008-02-19 16:04:40 UTC (rev 136) @@ -44,13 +44,14 @@ import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; +import java.util.ArrayList; public class ELF { public static final int EI_NIDENT = 16; public static final int EI_ENCODING = 5; - public static final boolean DEBUG = false; + public static final boolean DEBUG = true; //false; boolean encMSB = true; int type; @@ -72,6 +73,7 @@ private ELFSection sections[]; private ELFProgram programs[]; + private ArrayList<FileInfo> files = new ArrayList<FileInfo>(); ELFSection strTable; ELFSection symTable; @@ -276,6 +278,16 @@ return debug.getDebugInfo(adr); } + public String lookupFile(int address) { + for (int i = 0; i < files.size(); i++) { + FileInfo fi = files.get(i); + if (address >= fi.start && address <= fi.end) { + return fi.name; + } + } + return null; + } + public MapTable getMap() { MapTable map = new MapTable(); @@ -287,6 +299,7 @@ if (DEBUG) { System.out.println("Number of symbols:" + count); } + int currentAddress = 0; for (int i = 0, n = count; i < n; i++) { pos = addr; int nI = readElf32(); @@ -297,6 +310,14 @@ int bind = info >> 4; int type = info & 0xf; + if (type == 0 && "Letext".equals(sn)) { + if (currentFile != null) { + System.out.println("Found file addr for " + currentFile + " : 0x" + + Utils.hex16(currentAddress) + " - 0x" + Utils.hex16(sAddr)); + files.add(new FileInfo(currentFile, currentAddress, sAddr)); + currentAddress = sAddr; + } + } if (type == ELFSection.SYMTYPE_FILE) { currentFile = sn; } @@ -318,11 +339,16 @@ map.setStackStart(sAddr); } + if (type == ELFSection.SYMTYPE_FUNCTION) { - map.setEntry(new MapEntry(MapEntry.TYPE.function, sAddr, symbolName, currentFile, + String file = lookupFile(sAddr); + if (file == null) file = currentFile; + map.setEntry(new MapEntry(MapEntry.TYPE.function, sAddr, symbolName, file, bind == ELFSection.SYMBIND_LOCAL)); } else if (type == ELFSection.SYMTYPE_OBJECT) { - map.setEntry(new MapEntry(MapEntry.TYPE.variable, sAddr, symbolName, currentFile, + String file = lookupFile(sAddr); + if (file == null) file = currentFile; + map.setEntry(new MapEntry(MapEntry.TYPE.variable, sAddr, symbolName, file, bind == ELFSection.SYMBIND_LOCAL)); } else { if (DEBUG) { @@ -360,20 +386,20 @@ if (args.length < 2) { for (int i = 0, n = elf.shnum; i < n; i++) { - System.out.println("-- Section header " + i + " --\n" + elf.sections[i]); - if (".stab".equals(elf.sections[i].getSectionName()) || - ".stabstr".equals(elf.sections[i].getSectionName())) { - int adr = elf.sections[i].offset; - System.out.println(" == Section data =="); - for (int j = 0, m = 2000; j < m; j++) { - System.out.print((char) elf.elfData[adr++]); - if (i % 20 == 19) { - System.out.println(""); + System.out.println("-- Section header " + i + " --\n" + elf.sections[i]); + if (".stab".equals(elf.sections[i].getSectionName()) || + ".stabstr".equals(elf.sections[i].getSectionName())) { + int adr = elf.sections[i].offset; + System.out.println(" == Section data =="); + for (int j = 0, m = 2000; j < m; j++) { + System.out.print((char) elf.elfData[adr++]); + if (i % 20 == 19) { + System.out.println(); + } + } + } + System.out.println(); } - } - } - System.out.println(""); - } } elf.getMap(); if (args.length > 1) { @@ -387,4 +413,17 @@ } + class FileInfo { + String name; + int start; + int end; + + FileInfo(String name, int start, int end) { + this.name = name; + this.start = start; + this.end = end; + } + + } + } // ELF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-03-09 14:37:17
|
Revision: 161 http://mspsim.svn.sourceforge.net/mspsim/?rev=161&view=rev Author: joxe Date: 2008-03-09 07:36:02 -0700 (Sun, 09 Mar 2008) Log Message: ----------- added misc commands. Modified Paths: -------------- mspsim/se/sics/mspsim/cli/CommandContext.java mspsim/se/sics/mspsim/cli/DebugCommands.java mspsim/se/sics/mspsim/platform/GenericNode.java Added Paths: ----------- mspsim/se/sics/mspsim/cli/MiscCommands.java Modified: mspsim/se/sics/mspsim/cli/CommandContext.java =================================================================== --- mspsim/se/sics/mspsim/cli/CommandContext.java 2008-03-09 00:52:15 UTC (rev 160) +++ mspsim/se/sics/mspsim/cli/CommandContext.java 2008-03-09 14:36:02 UTC (rev 161) @@ -16,8 +16,6 @@ public final PrintStream err; public final InputStream in; - private CommandContext nextCommand; - public CommandContext(MapTable table, String[] args, int pid, InputStream in, PrintStream out, PrintStream err) { this.args = args; Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2008-03-09 00:52:15 UTC (rev 160) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2008-03-09 14:36:02 UTC (rev 161) @@ -195,17 +195,6 @@ return 0; } }); - // Does nothign yet... TODO!!! - ch.registerCommand("grep", new BasicLineCommand("grep", "regexp") { - public void lineRead(String line) { - } - public void stopCommand(CommandContext context) { - } - public int executeCommand(CommandContext context) { - return 0; - } - - }); } } } Added: mspsim/se/sics/mspsim/cli/MiscCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/MiscCommands.java (rev 0) +++ mspsim/se/sics/mspsim/cli/MiscCommands.java 2008-03-09 14:36:02 UTC (rev 161) @@ -0,0 +1,71 @@ +/** + * 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: $ + * + * ----------------------------------------------------------------- + * + * MiscCommands + * + * Author : Joakim Eriksson + * Created : 9 mar 2008 + * Updated : $Date:$ + * $Revision:$ + */ +package se.sics.mspsim.cli; + +import java.io.PrintStream; + +import se.sics.mspsim.util.ComponentRegistry; + +/** + * @author joakim + * + */ +public class MiscCommands implements CommandBundle { + + public void setupCommands(ComponentRegistry registry, CommandHandler handler) { + handler.registerCommand("grep", new BasicLineCommand("grep", "<regexp>") { + private PrintStream out; + public int executeCommand(CommandContext context) { + out = context.out; + return 0; + } + + public void lineRead(String line) { + out.println("Grep: " + line); + } + + public void stopCommand(CommandContext context) { + context.exit(0); + } + }); + } + +} Modified: mspsim/se/sics/mspsim/platform/GenericNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/GenericNode.java 2008-03-09 00:52:15 UTC (rev 160) +++ mspsim/se/sics/mspsim/platform/GenericNode.java 2008-03-09 14:36:02 UTC (rev 161) @@ -43,6 +43,7 @@ import se.sics.mspsim.cli.CommandHandler; import se.sics.mspsim.cli.DebugCommands; +import se.sics.mspsim.cli.MiscCommands; import se.sics.mspsim.core.Chip; import se.sics.mspsim.core.MSP430; import se.sics.mspsim.extutil.highlight.HighlightSourceViewer; @@ -74,6 +75,7 @@ registry.registerComponent("cpu", cpu); registry.registerComponent("commandHandler", ch); registry.registerComponent("debugcmd", new DebugCommands()); + registry.registerComponent("debugcmd", new MiscCommands()); registry.registerComponent("node", this); // Monitor execution This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2008-03-11 15:24:19
|
Revision: 175 http://mspsim.svn.sourceforge.net/mspsim/?rev=175&view=rev Author: nifi Date: 2008-03-11 08:24:03 -0700 (Tue, 11 Mar 2008) Log Message: ----------- started on implementation of TR1001 Modified Paths: -------------- mspsim/se/sics/mspsim/platform/esb/ESBGui.java mspsim/se/sics/mspsim/platform/esb/ESBNode.java Added Paths: ----------- mspsim/se/sics/mspsim/chip/TR1001.java Added: mspsim/se/sics/mspsim/chip/TR1001.java =================================================================== --- mspsim/se/sics/mspsim/chip/TR1001.java (rev 0) +++ mspsim/se/sics/mspsim/chip/TR1001.java 2008-03-11 15:24:03 UTC (rev 175) @@ -0,0 +1,84 @@ +/** + * Copyright (c) 2008, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * $Id$ + * + * ----------------------------------------------------------------- + * TR1001 + * + * Authors : Joakim Eriksson, Niclas Finne + * Created : 11 mar 2008 + * Updated : $Date$ + * $Rev$ + */ + +package se.sics.mspsim.chip; +import se.sics.mspsim.core.Chip; +import se.sics.mspsim.core.USART; +import se.sics.mspsim.core.USARTListener; + +/** + * + */ +public class TR1001 extends Chip implements USARTListener { + + 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 final USART usart; + private int mode; + + public TR1001(USART usart) { + this.usart = usart; + } + + @Override + public String getName() { + return "TR1001"; + } + + @Override + public int getModeMax() { + return MODE_MAX; + } + + public void setMode(int mode) { + if (this.mode != mode) { + this.mode = mode; + modeChanged(mode); + } + } + + @Override + public void dataReceived(USART source, int data) { + } + +} Property changes on: mspsim/se/sics/mspsim/chip/TR1001.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + LF Modified: mspsim/se/sics/mspsim/platform/esb/ESBGui.java =================================================================== --- mspsim/se/sics/mspsim/platform/esb/ESBGui.java 2008-03-11 15:05:45 UTC (rev 174) +++ mspsim/se/sics/mspsim/platform/esb/ESBGui.java 2008-03-11 15:24:03 UTC (rev 175) @@ -61,6 +61,8 @@ MouseMotionListener, MouseListener { + private static final long serialVersionUID = -139331418649524704L; + public static final int GREEN_X = 3; public static final int YELLOW_X = 10; public static final int RED_X = 17; @@ -75,7 +77,6 @@ public static final Color GREEN_C = new Color(0xff40ff40); private SerialMon serial; - private SerialMon radio; Beeper beeper; private ImageIcon esbImage; @@ -117,12 +118,6 @@ ((USART) usart).setUSARTListener(serial); } - IOUnit usart0 = cpu.getIOUnit("USART 0"); - if (usart0 instanceof USART) { - radio = new SerialMon((USART)usart0, "TR1001 Output"); - ((USART) usart0).setUSARTListener(radio); - } - beeper = new Beeper(); cpu.addIOUnit(-1,0,-1,0,beeper, true); } Modified: mspsim/se/sics/mspsim/platform/esb/ESBNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/esb/ESBNode.java 2008-03-11 15:05:45 UTC (rev 174) +++ mspsim/se/sics/mspsim/platform/esb/ESBNode.java 2008-03-11 15:24:03 UTC (rev 175) @@ -42,15 +42,16 @@ package se.sics.mspsim.platform.esb; import java.io.IOException; -import se.sics.mspsim.chip.CC2420; -import se.sics.mspsim.core.*; -import se.sics.mspsim.platform.GenericNode; -import se.sics.mspsim.platform.sky.SkyNode; -import se.sics.mspsim.ui.ControlUI; -import se.sics.mspsim.util.*; -import se.sics.mspsim.extutil.highlight.HighlightSourceViewer; +import se.sics.mspsim.chip.TR1001; +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.extutil.jfreechart.DataChart; import se.sics.mspsim.extutil.jfreechart.DataSourceSampler; +import se.sics.mspsim.platform.GenericNode; + public class ESBNode extends GenericNode implements PortListener { public static final boolean DEBUG = false; @@ -62,6 +63,7 @@ private IOPort port1; private IOPort port2; + private IOPort port5; public static final int RED_LED = 0x01; public static final int GREEN_LED = 0x02; @@ -72,7 +74,10 @@ public boolean greenLed; public boolean yellowLed; + private TR1001 radio; public ESBGui gui; + + /** * Creates a new <code>ESBNode</code> instance. * @@ -122,6 +127,15 @@ gui.repaint(); gui.beeper.beepOn((data & BEEPER) != 0); } + + } else if (source == port5) { + if ((data & 0xc0) == 0xc0) { + radio.setMode(TR1001.MODE_RX_ON); + } else if ((data & 0xc0) == 0x40) { + radio.setMode(TR1001.MODE_TXRX_ON); + } else { + radio.setMode(TR1001.MODE_TXRX_OFF); + } } } @@ -129,7 +143,6 @@ IOUnit unit = cpu.getIOUnit("Port 2"); if (unit instanceof IOPort) { port2 = (IOPort) unit; - System.out.println("Found port 2!!!"); port2.setPortListener(this); } @@ -137,19 +150,30 @@ if (unit instanceof IOPort) { port1 = (IOPort) unit; } - + + unit = cpu.getIOUnit("Port 5"); + if (unit instanceof IOPort) { + port5 = (IOPort) unit; + port5.setPortListener(this); + } + + IOUnit usart0 = cpu.getIOUnit("USART 0"); + if (usart0 instanceof USART) { + radio = new TR1001((USART)usart0); + ((USART) usart0).setUSARTListener(radio); + } + gui = new ESBGui(this); stats.addMonitor(this); -// stats.addMonitor(radio); + stats.addMonitor(radio); stats.addMonitor(cpu); // A HACK for some "graphs"!!! DataChart dataChart = new DataChart("Duty Cycle", "Duty Cycle"); DataSourceSampler dss = dataChart.setupChipFrame(cpu); -// dataChart.addDataSource(dss, "LEDS", stats.getMultiDataSource("Tmote Sky")); -// 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, "Listen", stats.getDataSource("TR1001", TR1001.MODE_RX_ON)); + dataChart.addDataSource(dss, "Transmit", stats.getDataSource("TR1001", TR1001.MODE_TXRX_ON)); dataChart.addDataSource(dss, "CPU", stats.getDataSource("MSP430 Core", MSP430.MODE_ACTIVE)); } @@ -166,5 +190,5 @@ node.setup(args); node.start(); } - + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-03-18 16:06:30
|
Revision: 198 http://mspsim.svn.sourceforge.net/mspsim/?rev=198&view=rev Author: joxe Date: 2008-03-18 09:06:23 -0700 (Tue, 18 Mar 2008) Log Message: ----------- fixed bug in the new eventsystem. Modified Paths: -------------- mspsim/se/sics/mspsim/core/EventQueue.java mspsim/se/sics/mspsim/core/Timer.java mspsim/se/sics/mspsim/platform/sky/SkyNode.java Modified: mspsim/se/sics/mspsim/core/EventQueue.java =================================================================== --- mspsim/se/sics/mspsim/core/EventQueue.java 2008-03-18 15:28:58 UTC (rev 197) +++ mspsim/se/sics/mspsim/core/EventQueue.java 2008-03-18 16:06:23 UTC (rev 198) @@ -59,7 +59,6 @@ if (event.scheduled) { removeEvent(event); } - eventCount++; if (first == null) { first = event; } else { @@ -86,6 +85,7 @@ nextTime = 0; } event.scheduled = true; + eventCount++; } // Not yet impl. @@ -136,6 +136,7 @@ nextTime = 0; } tmp.scheduled = false; + eventCount--; return tmp; } Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2008-03-18 15:28:58 UTC (rev 197) +++ mspsim/se/sics/mspsim/core/Timer.java 2008-03-18 16:06:23 UTC (rev 198) @@ -131,13 +131,10 @@ public static final int CC_IE = 0x10; // Bit 4 public static final int CC_TRIGGER_INT = CC_IE | CC_IFG; - private long lastCycles = 0; private long counterStart = 0; private long nextTimerTrigger = 0; // Number of cycles passed since current counter value was set - // useful for setting timeEvents to correct time. - private int counterPassed = 0; - + // useful for setting expected compare and capture times to correct time. // valid for timer A private int timerOverflow = 0x0a; @@ -177,7 +174,7 @@ private int mode; private int counter = 0; - private int countDirection = 1; + private int counterPassed = 0; // The IO registers private int tctl; @@ -365,7 +362,6 @@ counter = 0; counterStart = cycles; // inputDivider = 1; ???? - countDirection = 1; } int newMode = (data >> 4) & 3; Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-03-18 15:28:58 UTC (rev 197) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-03-18 16:06:23 UTC (rev 198) @@ -224,14 +224,14 @@ 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); +// cpu.scheduleCycleEvent(new TimeEvent(0) { +// public void execute(long t) { +// System.out.println("SkyNode: 1000000 cycles elapsed: " + t + " " + +// SkyNode.this.cpu.getTimeMillis()); +// // schedule at planned time + 1000000 +// SkyNode.this.cpu.scheduleCycleEvent(this, time + 1000000); +// } +// }, 1000000); // TODO: remove this test... radio.setPacketListener(new PacketListener() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2008-03-20 13:31:27
|
Revision: 205 http://mspsim.svn.sourceforge.net/mspsim/?rev=205&view=rev Author: nifi Date: 2008-03-20 06:31:07 -0700 (Thu, 20 Mar 2008) Log Message: ----------- - added config and argument handling - added option 'nogui' for ESB and Sky platforms - fixed Sky platform to use filename based on firmware name to store flash file Modified Paths: -------------- mspsim/se/sics/mspsim/platform/GenericNode.java mspsim/se/sics/mspsim/platform/esb/ESBNode.java mspsim/se/sics/mspsim/platform/sky/SkyNode.java Added Paths: ----------- mspsim/se/sics/mspsim/util/ArgumentManager.java mspsim/se/sics/mspsim/util/ConfigManager.java mspsim/se/sics/mspsim/util/PrefixConfigManager.java Modified: mspsim/se/sics/mspsim/platform/GenericNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/GenericNode.java 2008-03-20 12:49:27 UTC (rev 204) +++ mspsim/se/sics/mspsim/platform/GenericNode.java 2008-03-20 13:31:07 UTC (rev 205) @@ -47,7 +47,9 @@ import se.sics.mspsim.core.MSP430; import se.sics.mspsim.extutil.highlight.HighlightSourceViewer; import se.sics.mspsim.ui.ControlUI; +import se.sics.mspsim.util.ArgumentManager; import se.sics.mspsim.util.ComponentRegistry; +import se.sics.mspsim.util.ConfigManager; import se.sics.mspsim.util.ELF; import se.sics.mspsim.util.IHexReader; import se.sics.mspsim.util.MapTable; @@ -56,6 +58,8 @@ public abstract class GenericNode extends Chip implements Runnable { + protected ConfigManager config; + protected ComponentRegistry registry = new ComponentRegistry(); protected MSP430 cpu = new MSP430(0); protected String firmwareFile = null; @@ -64,12 +68,15 @@ public abstract void setupNode(); - public void setup(String[] args) throws IOException { + public void setup(ArgumentManager config) throws IOException { + String[] args = config.getArguments(); if (args.length == 0) { System.out.println("Usage: " + getClass().getName() + " <firmware>"); System.exit(1); } + this.config = config; + CommandHandler ch = new CommandHandler(); stats = new OperatingModeStatistics(cpu); @@ -101,13 +108,14 @@ cpu.reset(); setupNode(); - - // Setup control and other UI components - ControlUI control = new ControlUI(registry); - HighlightSourceViewer sourceViewer = new HighlightSourceViewer(); + + if (!config.getPropertyAsBoolean("nogui", false)) { + // Setup control and other UI components + ControlUI control = new ControlUI(registry); + HighlightSourceViewer sourceViewer = new HighlightSourceViewer(); // sourceViewer.addSearchPath(new File("../../contiki-2.x/examples/energest-demo/")); - control.setSourceViewer(sourceViewer); - + control.setSourceViewer(sourceViewer); + } if (args.length > 1) { MapTable map = new MapTable(args[1]); cpu.getDisAsm().setMap(map); @@ -119,9 +127,11 @@ public void run() { - System.out.println("Starting new CPU thread..."); - cpu.cpuloop(); - System.out.println("Stopping CPU thread..."); + if (!cpu.isRunning()) { + System.out.println("Starting new CPU thread..."); + cpu.cpuloop(); + System.out.println("Stopping CPU thread..."); + } } public void start() { if (!cpu.isRunning()) { Modified: mspsim/se/sics/mspsim/platform/esb/ESBNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/esb/ESBNode.java 2008-03-20 12:49:27 UTC (rev 204) +++ mspsim/se/sics/mspsim/platform/esb/ESBNode.java 2008-03-20 13:31:07 UTC (rev 205) @@ -41,7 +41,6 @@ package se.sics.mspsim.platform.esb; import java.io.IOException; - import se.sics.mspsim.chip.TR1001; import se.sics.mspsim.core.IOPort; import se.sics.mspsim.core.IOUnit; @@ -51,6 +50,7 @@ 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; public class ESBNode extends GenericNode implements PortListener { @@ -167,18 +167,19 @@ public void setupNode() { setupNodePorts(); - gui = new ESBGui(this); + if (!config.getPropertyAsBoolean("nogui", false)) { + gui = new ESBGui(this); + // A HACK for some "graphs"!!! + DataChart dataChart = new DataChart("Duty Cycle", "Duty Cycle"); + DataSourceSampler dss = dataChart.setupChipFrame(cpu); + dataChart.addDataSource(dss, "Listen", stats.getDataSource("TR1001", TR1001.MODE_RX_ON)); + dataChart.addDataSource(dss, "Transmit", stats.getDataSource("TR1001", TR1001.MODE_TXRX_ON)); + dataChart.addDataSource(dss, "CPU", stats.getDataSource("MSP430 Core", MSP430.MODE_ACTIVE)); + } stats.addMonitor(this); stats.addMonitor(radio); stats.addMonitor(cpu); - - // A HACK for some "graphs"!!! - DataChart dataChart = new DataChart("Duty Cycle", "Duty Cycle"); - DataSourceSampler dss = dataChart.setupChipFrame(cpu); - dataChart.addDataSource(dss, "Listen", stats.getDataSource("TR1001", TR1001.MODE_RX_ON)); - dataChart.addDataSource(dss, "Transmit", stats.getDataSource("TR1001", TR1001.MODE_TXRX_ON)); - dataChart.addDataSource(dss, "CPU", stats.getDataSource("MSP430 Core", MSP430.MODE_ACTIVE)); } public int getModeMax() { @@ -191,7 +192,9 @@ public static void main(String[] args) throws IOException { ESBNode node = new ESBNode(); - node.setup(args); + ArgumentManager config = new ArgumentManager(); + config.handleArguments(args); + node.setup(config); node.start(); } Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-03-20 12:49:27 UTC (rev 204) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-03-20 13:31:07 UTC (rev 205) @@ -55,6 +55,7 @@ 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.OperatingModeStatistics; @@ -216,7 +217,7 @@ fileName = fileName + ".flash"; System.out.println("Using flash file: " + fileName); - this.flashFile = flashFile; + this.flashFile = fileName; setupNodePorts(); @@ -251,21 +252,25 @@ // } // }); - gui = new SkyGui(this); + 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)); + // 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 { SkyNode node = new SkyNode(); - node.setup(args); + ArgumentManager config = new ArgumentManager(); + config.handleArguments(args); + node.setup(config); node.start(); } Added: mspsim/se/sics/mspsim/util/ArgumentManager.java =================================================================== --- mspsim/se/sics/mspsim/util/ArgumentManager.java (rev 0) +++ mspsim/se/sics/mspsim/util/ArgumentManager.java 2008-03-20 13:31:07 UTC (rev 205) @@ -0,0 +1,114 @@ +/** + * Copyright (c) 2008, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * $Id$ + * + * ----------------------------------------------------------------- + * + * ArgumentManager + * + * Author : Joakim Eriksson, Niclas Finne + * Created : Tue Apr 08 22:08:32 2003 + * Updated : $Date$ + * $Revision$ + */ +package se.sics.mspsim.util; +import java.util.ArrayList; + +/** + */ +public class ArgumentManager extends ConfigManager { + + private String configName = "config"; + private String[] arguments; + private boolean isConfigLoaded; + + public ArgumentManager() { + } + + public ArgumentManager(ConfigManager parent) { + super(parent); + } + + public boolean isConfigLoaded() { + return isConfigLoaded; + } + + public String getConfigArgumentName() { + return configName; + } + + public void setConfigArgumentName(String configName) { + this.configName = configName; + } + + public String[] getArguments() { + return arguments; + } + + public void handleArguments(String[] args) { + ArrayList<String> list = new ArrayList<String>(); + ArrayList<String> config = new ArrayList<String>(); + for (int i = 0, n = args.length; i < n; i++) { + if (args[i].startsWith("-")) { + String param = args[i].substring(1); + String value = ""; + int index = param.indexOf('='); + if (index >= 0) { + if (index < param.length()) { + value = param.substring(index + 1); + } + param = param.substring(0, index); + } + if (param.length() == 0) { + throw new IllegalArgumentException("illegal argument: " + args[i]); + } + if (configName != null && configName.equals(param)) { + if (value.length() == 0) { + throw new IllegalArgumentException("no config file name specified"); + } + if (!loadConfiguration(value)) { + throw new IllegalArgumentException("failed to load configuration " + value); + } + isConfigLoaded = true; + } + config.add(param); + config.add(value.length() > 0 ? value : "true"); + } else { + // Normal argument + list.add(args[i]); + } + } + this.arguments = list.toArray(new String[list.size()]); + for (int i = 0, n = config.size(); i < n; i += 2) { + setProperty(config.get(i), config.get(i + 1)); + } + } + +} // ArgumentManager Property changes on: mspsim/se/sics/mspsim/util/ArgumentManager.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + LF Added: mspsim/se/sics/mspsim/util/ConfigManager.java =================================================================== --- mspsim/se/sics/mspsim/util/ConfigManager.java (rev 0) +++ mspsim/se/sics/mspsim/util/ConfigManager.java 2008-03-20 13:31:07 UTC (rev 205) @@ -0,0 +1,335 @@ +/** + * Copyright (c) 2008, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * $Id$ + * + * ----------------------------------------------------------------- + * + * ConfigManager + * + * Author : Joakim Eriksson, Niclas Finne + * Created : Fri Oct 11 15:24:14 2002 + * Updated : $Date$ + * $Revision$ + */ +package se.sics.mspsim.util; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URL; +import java.util.Properties; +import java.util.StringTokenizer; + +public class ConfigManager { + + protected final ConfigManager parent; + protected Properties properties = null; + + public ConfigManager() { + this(null); + } + + public ConfigManager(ConfigManager parent) { + this.parent = parent; + } + + + + // ------------------------------------------------------------------- + // Config file handling + // ------------------------------------------------------------------- + + protected String getBackupFile(String configFile) { + int index = configFile.lastIndexOf('.'); + if (index > 0 && index < configFile.length() - 1) { + return configFile.substring(0, index) + ".bak"; + } + return null; + } + + public boolean loadConfiguration(String configFile) { + return loadConfiguration(new File(configFile)); + } + + public boolean loadConfiguration(File configFile) { + try { + InputStream input = + new BufferedInputStream(new FileInputStream(configFile)); + try { + loadConfiguration(input); + } finally { + input.close(); + } + return true; + } catch (FileNotFoundException e) { + return false; + } catch (IOException e) { + throw new IllegalArgumentException("could not read config file '" + + configFile + "': " + e); + } + } + + public boolean loadConfiguration(URL configURL) { + try { + InputStream input = new BufferedInputStream(configURL.openStream()); + try { + loadConfiguration(input); + } finally { + input.close(); + } + return true; + } catch (FileNotFoundException e) { + return false; + } catch (IOException e) { + throw new IllegalArgumentException("could not read config file '" + + configURL + "': " + e); + } + } + + public void loadConfiguration(InputStream input) throws IOException { + Properties p = new Properties(); + p.load(input); + this.properties = p; + } + + public boolean saveConfiguration(File filename, String comments) { + if (properties != null) { + OutputStream output = null; + try { + output = new FileOutputStream(filename); + properties.store(output, comments); + return true; + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (output != null) { + try { + output.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } + return false; + } + + + // ------------------------------------------------------------------- + // Properties handling + // ------------------------------------------------------------------- + + /** + * Returns the property names. Does not include inherited properties. + * + * @return an array with the non-inherited property names + */ + public String[] getPropertyNames() { + if (properties == null) { + return new String[0]; + } + synchronized (properties) { + return properties.keySet().toArray(new String[properties.size()]); + } + } + + public String getProperty(String name) { + return getProperty(name, null); + } + + public String getProperty(String name, String defaultValue) { + String value = (properties != null) + ? properties.getProperty(name) + : null; + + if (value == null || value.length() == 0) { + value = parent != null + ? parent.getProperty(name, defaultValue) + : defaultValue; + } + return value; + } + + public void setProperty(String name, String value) { + if (properties == null) { + synchronized (this) { + if (properties == null) { + properties = new Properties(); + } + } + } + + if (value == null) { + properties.remove(name); + } else { + properties.put(name, value); + } + } + + public String[] getPropertyAsArray(String name) { + return getPropertyAsArray(name, null); + } + + public String[] getPropertyAsArray(String name, String defaultValue) { + String valueList = getProperty(name, defaultValue); + if (valueList != null) { + StringTokenizer tok = new StringTokenizer(valueList, ", \t"); + int len = tok.countTokens(); + if (len > 0) { + String[] values = new String[len]; + for (int i = 0; i < len; i++) { + values[i] = tok.nextToken(); + } + return values; + } + } + return null; + } + + public int getPropertyAsInt(String name, int defaultValue) { + String value = getProperty(name, null); + return value != null ? parseInt(name, value, defaultValue) : defaultValue; + } + + public int[] getPropertyAsIntArray(String name) { + return getPropertyAsIntArray(name, null); + } + + public int[] getPropertyAsIntArray(String name, String defaultValue) { + String valueList = getProperty(name, defaultValue); + if (valueList != null) { + return parseIntArray(valueList, defaultValue); + } else if (defaultValue != null) { + return parseIntArray(defaultValue, null); + } else { + return null; + } + } + + private int[] parseIntArray(String valueList, String secondaryValue) { + StringTokenizer tok = new StringTokenizer(valueList, ", \t/"); + int len = tok.countTokens(); + if (len > 0) { + try { + int[] values = new int[len]; + for (int i = 0; i < len; i++) { + values[i] = Integer.parseInt(tok.nextToken()); + } + return values; + } catch (NumberFormatException e) { + // Ignore parse errors and try secondary value if specified and not already tried + } + } + if(secondaryValue != null && !secondaryValue.equals(valueList)) { + return parseIntArray(secondaryValue, null); + } + return null; + } + + public long getPropertyAsLong(String name, long defaultValue) { + String value = getProperty(name, null); + return value != null + ? parseLong(name, value, defaultValue) + : defaultValue; + } + + public float getPropertyAsFloat(String name, float defaultValue) { + String value = getProperty(name, null); + return value != null + ? parseFloat(name, value, defaultValue) + : defaultValue; + } + + public double getPropertyAsDouble(String name, double defaultValue) { + String value = getProperty(name, null); + return value != null + ? parseDouble(name, value, defaultValue) + : defaultValue; + } + + public boolean getPropertyAsBoolean(String name, boolean defaultValue) { + String value = getProperty(name, null); + return value != null + ? parseBoolean(name, value, defaultValue) + : defaultValue; + } + + protected int parseInt(String name, String value, int defaultValue) { + try { + return Integer.parseInt(value); + } catch (Exception e) { + System.err.println("config '" + name + "' has a non-integer value '" + + value + '\''); + } + return defaultValue; + } + + protected long parseLong(String name, String value, long defaultValue) { + try { + return Long.parseLong(value); + } catch (Exception e) { + System.err.println("config '" + name + "' has a non-long value '" + + value + '\''); + } + return defaultValue; + } + + protected float parseFloat(String name, String value, float defaultValue) { + try { + return Float.parseFloat(value); + } catch (Exception e) { + System.err.println("config '" + name + "' has a non-float value '" + + value + '\''); + } + return defaultValue; + } + + protected double parseDouble(String name, String value, + double defaultValue) { + try { + return Double.parseDouble(value); + } catch (Exception e) { + System.err.println("config '" + name + "' has a non-double value '" + + value + '\''); + } + return defaultValue; + } + + protected boolean parseBoolean(String name, String value, + boolean defaultValue) { + return "true".equals(value) || "yes".equals(value) || "1".equals(value); + } + +} // ConfigManager Property changes on: mspsim/se/sics/mspsim/util/ConfigManager.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + LF Added: mspsim/se/sics/mspsim/util/PrefixConfigManager.java =================================================================== --- mspsim/se/sics/mspsim/util/PrefixConfigManager.java (rev 0) +++ mspsim/se/sics/mspsim/util/PrefixConfigManager.java 2008-03-20 13:31:07 UTC (rev 205) @@ -0,0 +1,91 @@ +/** + * Copyright (c) 2008, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * $Id$ + * + * ----------------------------------------------------------------- + * + * PrefixConfigManager + * + * Authors : Joakim Eriksson, Niclas Finne + * Created : Fri Oct 11 15:24:14 2002 + * Updated : $Date$ + * $Revision$ + */ +package se.sics.mspsim.util; + +/** + * + */ +public class PrefixConfigManager extends ConfigManager { + + private final ConfigManager config; + private final String shortPrefix; + private final String longPrefix; + + public PrefixConfigManager(ConfigManager config, String prefix, String name) { + this(config, prefix, name, '.'); + } + + public PrefixConfigManager(ConfigManager config, String prefix, + String name, char separator) { + if (config == null) { + throw new NullPointerException(); + } + this.config = config; + prefix = prefix != null && prefix.length() > 0 ? (prefix + separator) : null; + + if (name != null && name.length() > 0) { + this.longPrefix = prefix == null ? (name + separator) : (prefix + name + separator); + this.shortPrefix = prefix; + } else if (prefix != null) { + this.longPrefix = prefix; + this.shortPrefix = null; + } else { + this.longPrefix = ""; + this.shortPrefix = null; + } + } + + public String getProperty(String name, String defaultValue) { + String value = config.getProperty(longPrefix + name); + if (value != null) { + return value; + } + if (shortPrefix == null) { + return defaultValue; + } + return config.getProperty(shortPrefix + name, defaultValue); + } + + public void setProperty(String name, String value) { + config.setProperty(longPrefix + name, value); + } + +} Property changes on: mspsim/se/sics/mspsim/util/PrefixConfigManager.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2008-03-25 10:30:20
|
Revision: 211 http://mspsim.svn.sourceforge.net/mspsim/?rev=211&view=rev Author: nifi Date: 2008-03-25 03:30:14 -0700 (Tue, 25 Mar 2008) Log Message: ----------- CLI help text cleanup + improved error handling Modified Paths: -------------- mspsim/se/sics/mspsim/cli/CommandHandler.java mspsim/se/sics/mspsim/cli/DebugCommands.java mspsim/se/sics/mspsim/cli/ExecCommand.java mspsim/se/sics/mspsim/cli/MiscCommands.java mspsim/se/sics/mspsim/util/StatCommands.java Modified: mspsim/se/sics/mspsim/cli/CommandHandler.java =================================================================== --- mspsim/se/sics/mspsim/cli/CommandHandler.java 2008-03-25 10:29:00 UTC (rev 210) +++ mspsim/se/sics/mspsim/cli/CommandHandler.java 2008-03-25 10:30:14 UTC (rev 211) @@ -74,8 +74,15 @@ out.flush(); String line = readLine(inReader);//.readLine(); if (line != null && line.length() > 0) { - String[][] parts = CommandParser.parseLine(line); - if(parts.length > 0 && checkCommands(parts) == 0) { + String[][] parts; + try { + parts = CommandParser.parseLine(line); + } catch (Exception e) { + err.println("Error: failed to parse command:"); + e.printStackTrace(err); + parts = null; + } + if(parts != null && parts.length > 0 && checkCommands(parts) == 0) { CommandContext[] commands = new CommandContext[parts.length]; boolean error = false; int pid = -1; @@ -145,11 +152,11 @@ for (int i = 0; i < cmds.length; i++) { Command command = commands.get(cmds[i][0]); if (command == null) { - err.println("CLI: Command not found: " + cmds[i][0]); + err.println("CLI: Command not found: \"" + cmds[i][0] + "\". Try \"help\"."); return -1; } if (i > 0 && !(command instanceof LineListener)) { - err.println("CLI: Error " + cmds[i][0] + " does not take input"); + err.println("CLI: Error, command \"" + cmds[i][0] + "\" does not take input."); return -1; } // TODO replace with command name @@ -200,20 +207,23 @@ for(Map.Entry<String,Command> entry: commands.entrySet()) { String name = entry.getKey(); Command command = entry.getValue(); - String prefix = ' ' + name + ' ' + command.getArgumentHelp(name); String helpText = command.getCommandHelp(name); - int n; - if (helpText != null && (n = helpText.indexOf('\n')) > 0) { - helpText = helpText.substring(0, n); + if (helpText != null) { + String argHelp = command.getArgumentHelp(name); + String prefix = argHelp != null ? (' ' + name + ' ' + argHelp) : (' ' + name); + int n; + if (helpText != null && (n = helpText.indexOf('\n')) > 0) { + helpText = helpText.substring(0, n); + } + context.out.print(prefix); + if (prefix.length() < 8) { + context.out.print('\t'); + } + if (prefix.length() < 16) { + context.out.print('\t'); + } + context.out.println("\t " + helpText); } - context.out.print(prefix); - if (prefix.length() < 8) { - context.out.print('\t'); - } - if (prefix.length() < 16) { - context.out.print('\t'); - } - context.out.println("\t " + helpText); } return 0; } @@ -221,15 +231,23 @@ String cmd = context.getArgument(0); Command command = commands.get(cmd); if (command != null) { - context.out.println(cmd + ' ' + command.getArgumentHelp(cmd)); - context.out.println(" " + command.getCommandHelp(cmd)); + String helpText = command.getCommandHelp(cmd); + String argHelp = command.getArgumentHelp(cmd); + context.out.print(cmd); + if (argHelp != null) { + context.out.print(' ' + argHelp); + } + context.out.println(); + if (helpText != null && helpText.length() > 0) { + context.out.println(" " + helpText); + } return 0; } context.err.println("Error: unknown command '" + cmd + '\''); return 1; } }); - registerCommand("workaround", new BasicCommand("", "") { + registerCommand("workaround", new BasicCommand("activate workaround for Java console input bug", "") { public int executeCommand(CommandContext context) { workaround = true; return 0; Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2008-03-25 10:29:00 UTC (rev 210) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2008-03-25 10:30:14 UTC (rev 211) @@ -52,13 +52,13 @@ public class DebugCommands implements CommandBundle { private long lastCall = 0; private long lastWall = 0; - + public void setupCommands(ComponentRegistry registry, CommandHandler ch) { final MSP430 cpu = (MSP430) registry.getComponent(MSP430.class); final ELF elf = (ELF) registry.getComponent(ELF.class); final GenericNode node = (GenericNode) registry.getComponent("node"); if (cpu != null) { - ch.registerCommand("break", new BasicAsyncCommand("adds a breakpoint to a given address or symbol", + ch.registerCommand("break", new BasicAsyncCommand("add a breakpoint to a given address or symbol", "<address or symbol>") { int address = 0; public int executeCommand(final CommandContext context) { @@ -78,7 +78,7 @@ }); ch.registerCommand("watch", - new BasicAsyncCommand("adds a write watch to a given address or symbol", "<address or symbol>") { + new BasicAsyncCommand("add a write watch to a given address or symbol", "<address or symbol>") { int mode = 0; int address = 0; public int executeCommand(final CommandContext context) { @@ -118,7 +118,7 @@ }); ch.registerCommand("watchreg", - new BasicAsyncCommand("adds a write watch to a given register", "<register> [int]") { + new BasicAsyncCommand("add a write watch to a given register", "<register> [int]") { int mode = 0; int register = 0; public int executeCommand(final CommandContext context) { @@ -169,13 +169,13 @@ } public String getCommandHelp(String commandName) { - return "clears a breakpoint or watch from a given address or symbol"; + return "clear a breakpoint or watch from a given address or symbol"; } }); - ch.registerCommand("symbol", new BasicCommand("lists matching symbold", "<regexp>") { + ch.registerCommand("symbol", new BasicCommand("list matching symbold", "<regexp>") { public int executeCommand(final CommandContext context) { String regExp = context.getArgument(0); MapEntry[] entries = context.getMapTable().getEntries(regExp); @@ -189,29 +189,29 @@ }); if (node != null) { - ch.registerCommand("stop", new BasicCommand("stops mspsim", "") { + ch.registerCommand("stop", new BasicCommand("stop the CPU", "") { public int executeCommand(CommandContext context) { node.stop(); context.out.println("CPU stopped at: $" + Utils.hex16(cpu.readRegister(0))); return 0; } }); - ch.registerCommand("start", new BasicCommand("starts mspsim", "") { + ch.registerCommand("start", new BasicCommand("start the CPU", "") { public int executeCommand(CommandContext context) { node.start(); return 0; } }); - ch.registerCommand("step", new BasicCommand("singlesteps mspsim", "<number of lines>") { + 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))); + context.out.println("CPU stepped to: $" + Utils.hex16(cpu.readRegister(0))); return 0; } }); - ch.registerCommand("print", new BasicCommand("prints value of an address or symbol", "<address or symbol>") { + ch.registerCommand("print", new BasicCommand("print value of an address or symbol", "<address or symbol>") { public int executeCommand(CommandContext context) { int adr = context.getArgumentAsAddress(0); if (adr != -1) { @@ -222,7 +222,7 @@ return 0; } }); - ch.registerCommand("printreg", new BasicCommand("prints value of an register", "<register>") { + ch.registerCommand("printreg", new BasicCommand("print value of an register", "<register>") { public int executeCommand(CommandContext context) { int register = context.getArgumentAsRegister(0); if (register >= 0) { @@ -232,14 +232,14 @@ return -1; } }); - ch.registerCommand("reset", new BasicCommand("resets the CPU", "") { + ch.registerCommand("reset", new BasicCommand("reset the CPU", "") { public int executeCommand(CommandContext context) { cpu.reset(); return 0; } }); - ch.registerCommand("time", new BasicCommand("prints the elapse time and cycles", "") { + ch.registerCommand("time", new BasicCommand("print the elapse time and cycles", "") { public int executeCommand(CommandContext context) { long time = ((long)(cpu.getTimeMillis())); context.out.println("Emulated time elapsed: " + time + "(ms) since last: " + (time - lastCall) + " ms" + " wallTime: " + Modified: mspsim/se/sics/mspsim/cli/ExecCommand.java =================================================================== --- mspsim/se/sics/mspsim/cli/ExecCommand.java 2008-03-25 10:29:00 UTC (rev 210) +++ mspsim/se/sics/mspsim/cli/ExecCommand.java 2008-03-25 10:30:14 UTC (rev 211) @@ -52,7 +52,7 @@ private PrintStream output; public ExecCommand() { - super("executes the specified command", "<cmd> [args...]"); + super("execute the specified command", "<cmd> [args...]"); } public int executeCommand(CommandContext context) { Modified: mspsim/se/sics/mspsim/cli/MiscCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/MiscCommands.java 2008-03-25 10:29:00 UTC (rev 210) +++ mspsim/se/sics/mspsim/cli/MiscCommands.java 2008-03-25 10:30:14 UTC (rev 211) @@ -39,14 +39,11 @@ * $Revision$ */ package se.sics.mspsim.cli; - -import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintStream; import java.util.Hashtable; import java.util.Iterator; import java.util.regex.Pattern; - import se.sics.mspsim.core.MSP430; import se.sics.mspsim.util.ComponentRegistry; @@ -55,10 +52,11 @@ * */ public class MiscCommands implements CommandBundle { - Hashtable <String, FileTarget> fileTargets = new Hashtable<String, FileTarget>(); + private Hashtable <String, FileTarget> fileTargets = new Hashtable<String, FileTarget>(); + public void setupCommands(final ComponentRegistry registry, CommandHandler handler) { - handler.registerCommand("grep", new BasicLineCommand("grep", "<regexp>") { + handler.registerCommand("grep", new BasicLineCommand("print lines matching the specified pattern", "<regexp>") { private PrintStream out; private Pattern pattern; public int executeCommand(CommandContext context) { @@ -77,14 +75,14 @@ // TODO: this should also be "registered" as a "sink". // probably this should be handled using ">" instead! - handler.registerCommand(">", new BasicLineCommand(">", "<filename>") { + handler.registerCommand(">", new BasicLineCommand(null, "<filename>") { FileTarget ft; public int executeCommand(CommandContext context) { String fileName = context.getArgument(0); ft = fileTargets.get(fileName); if (ft == null) { try { - System.out.println("Creating new file target: " + fileName); +// System.out.println("Creating new file target: " + fileName); ft = new FileTarget(fileName); fileTargets.put(fileName, ft); } catch (IOException e) { @@ -102,22 +100,23 @@ } }); - handler.registerCommand("fclose", new BasicCommand("fclose", "<filename>") { + handler.registerCommand("fclose", new BasicCommand("close the specified file", "<filename>") { public int executeCommand(CommandContext context) { String name = context.getArgument(0); FileTarget ft = fileTargets.get(name); if (ft != null) { - context.out.println("Closing file:" + name); + context.out.println("Closing file " + name); fileTargets.remove(name); ft.close(); + return 0; } else { - context.err.println("No file named: " + name + " open"); + context.err.println("Could not find the open file " + name); + return 1; } - return 0; } }); - handler.registerCommand("files", new BasicCommand("files", "") { + handler.registerCommand("files", new BasicCommand("list open files", "") { public int executeCommand(CommandContext context) { for (Iterator<FileTarget> iterator = fileTargets.values().iterator(); iterator.hasNext();) { FileTarget type = (FileTarget) iterator.next(); @@ -127,29 +126,37 @@ } }); - handler.registerCommand("speed", new BasicCommand("speed", "<factor>") { + handler.registerCommand("speed", new BasicCommand("set the speed factor for the CPU", "[factor]") { public int executeCommand(CommandContext context) { - double d = context.getArgumentAsDouble(0); MSP430 cpu = (MSP430) registry.getComponent(MSP430.class); - if (cpu != null) { - if (d < 0.0) { - System.out.println("Rate needs to be larger than zero"); + if (cpu == null) { + context.err.println("could not access the CPU."); + return 1; + } else if (context.getArgumentCount() == 0) { + long rate = cpu.getSleepRate(); + double d = rate / 25000.0; + context.out.println("Speed factor is set to " + (((int)(d * 100 + 0.5)) / 100.0)); + } else { + double d = context.getArgumentAsDouble(0); + if (d > 0.0) { + long rate = (long) (25000 * d); + cpu.setSleepRate(rate); } else { - long rate = (long)(25000 * d); - cpu.setSleepRate(rate); + context.err.println("Speed factor must be larger than zero."); + return 1; } } return 0; } }); - - handler.registerCommand("exit", new BasicCommand("exit", "") { + + handler.registerCommand("quit", new BasicCommand("exit MSPSim", "") { public int executeCommand(CommandContext context) { System.exit(0); return 0; } }); - + handler.registerCommand("exec", new ExecCommand()); } Modified: mspsim/se/sics/mspsim/util/StatCommands.java =================================================================== --- mspsim/se/sics/mspsim/util/StatCommands.java 2008-03-25 10:29:00 UTC (rev 210) +++ mspsim/se/sics/mspsim/util/StatCommands.java 2008-03-25 10:30:14 UTC (rev 211) @@ -62,23 +62,29 @@ @Override public void setupCommands(ComponentRegistry registry, CommandHandler handler) { - handler.registerCommand("chipinfo", new BasicCommand("shows information about specified chip", + handler.registerCommand("chipinfo", new BasicCommand("show information about specified chip", "[chips...]") { @Override public int executeCommand(CommandContext context) { if (context.getArgumentCount() > 0) { for (int i = 0, n = context.getArgumentCount(); i < n; i++) { - // TODO list chips + String chipName = context.getArgument(i); + Chip chip = statistics.getChip(chipName); + if (chip == null) { + context.out.println(" " + chipName + ": NOT FOUND"); + } else { + context.out.println(" " + chipName + ": " + chip); + } } - return 0; - } - Chip[] chips = statistics.getChips(); - if (chips == null) { - context.out.println("No chips found"); } else { - for (int i = 0, n = chips.length; i < n; i++) { - context.out.println(" " + chips[i].getName()); + Chip[] chips = statistics.getChips(); + if (chips == null) { + context.out.println("No chips found."); + } else { + for (int i = 0, n = chips.length; i < n; i++) { + context.out.println(" " + chips[i].getName()); + } } } return 0; @@ -86,7 +92,7 @@ }); - handler.registerCommand("duty", new BasicAsyncCommand("adds a duty cycle sampler for operating modes to the specified chips", + handler.registerCommand("duty", new BasicAsyncCommand("add a duty cycle sampler for operating modes to the specified chips", "<frequency> <chip> [chips...]") { private PrintStream out; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2008-04-04 06:53:50
|
Revision: 228 http://mspsim.svn.sourceforge.net/mspsim/?rev=228&view=rev Author: joxe Date: 2008-04-03 23:53:36 -0700 (Thu, 03 Apr 2008) Log Message: ----------- removed some debug printouts. 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-04-03 22:19:51 UTC (rev 227) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2008-04-04 06:53:36 UTC (rev 228) @@ -277,7 +277,7 @@ } break; case WRITE_TXFIFO: - System.out.println("Writing data: " + data + " to tx: " + txCursor); +// System.out.println("Writing data: " + data + " to tx: " + txCursor); memory[RAM_TXFIFO + txCursor++] = data & 0xff; break; case RAM_ACCESS: Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-04-03 22:19:51 UTC (rev 227) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-04-04 06:53:36 UTC (rev 228) @@ -264,11 +264,11 @@ // TODO: remove this test... radio.setPacketListener(new PacketListener() { public void transmissionEnded(int[] receivedData) { - System.out.println(getName() + " got packet from radio " + SkyNode.this.cpu.getTimeMillis()); +// System.out.println(getName() + " got packet from radio " + SkyNode.this.cpu.getTimeMillis()); network.dataSent(receivedData); } public void transmissionStarted() { - System.out.println(getName() + " got indication on transmission from radio " + SkyNode.this.cpu.getTimeMillis()); +// System.out.println(getName() + " got indication on transmission from radio " + SkyNode.this.cpu.getTimeMillis()); } }); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |