From: <jo...@us...> - 2008-09-15 14:16:53
|
Revision: 327 http://mspsim.svn.sourceforge.net/mspsim/?rev=327&view=rev Author: joxe Date: 2008-09-15 21:16:47 +0000 (Mon, 15 Sep 2008) Log Message: ----------- added xmem cli commands and implemented memory interface in Sky-node flash memory Modified Paths: -------------- mspsim/se/sics/mspsim/chip/FileM25P80.java mspsim/se/sics/mspsim/chip/M25P80.java mspsim/se/sics/mspsim/cli/DebugCommands.java mspsim/se/sics/mspsim/platform/sky/SkyNode.java Modified: mspsim/se/sics/mspsim/chip/FileM25P80.java =================================================================== --- mspsim/se/sics/mspsim/chip/FileM25P80.java 2008-09-15 21:11:08 UTC (rev 326) +++ mspsim/se/sics/mspsim/chip/FileM25P80.java 2008-09-15 21:16:47 UTC (rev 327) @@ -83,7 +83,7 @@ } // Set size of flash try { - file.setLength(1024 * 1024); + file.setLength(MEMORY_SIZE); } catch (IOException e) { e.printStackTrace(); } Modified: mspsim/se/sics/mspsim/chip/M25P80.java =================================================================== --- mspsim/se/sics/mspsim/chip/M25P80.java 2008-09-15 21:11:08 UTC (rev 326) +++ mspsim/se/sics/mspsim/chip/M25P80.java 2008-09-15 21:16:47 UTC (rev 327) @@ -43,7 +43,7 @@ import java.io.IOException; import se.sics.mspsim.core.*; -public abstract class M25P80 extends Chip implements USARTListener, PortListener { +public abstract class M25P80 extends Chip implements USARTListener, PortListener, Memory { public static final boolean DEBUG = false; @@ -59,7 +59,9 @@ public static final int BULK_ERASE = 0xc7; public static final int DEEP_POWER_DOWN = 0xb9; public static final int WAKE_UP = 0xab; - + + public static final int MEMORY_SIZE = 1024 * 1024; + private int state = 0; public static final int CHIP_SELECT = 0x10; private boolean chipSelect; @@ -224,6 +226,34 @@ } } + /*********************************************** + * Memory interface methods + ***********************************************/ + public int readByte(int address) { + byte[] data = new byte[256]; + try { + loadMemory(address, data); + } catch (IOException e) { + e.printStackTrace(); + } + return ~(byte)data[address & 0xff]; + } + + public void writeByte(int address, int data) { + byte[] mem = new byte[256]; + try { + loadMemory(address, mem); + mem[address & 0xff] = (byte) ~data; + writeBack(address, mem); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public int getSize() { + return MEMORY_SIZE; + } + // Should return correct data! private int readMemory(int address) { if (DEBUG) { @@ -244,11 +274,7 @@ if (DEBUG) { System.out.println("M25P80: Loading memory: " + (address & 0xfff00)); } - seek(address & 0xfff00); - readFully(readMemory); - for (int i = 0; i < readMemory.length; i++) { - readMemory[i] = (byte) (~readMemory[i] & 0xff); - } + loadMemory(address, readMemory); } catch (IOException e) { e.printStackTrace(); } @@ -256,6 +282,14 @@ } } + private void loadMemory(int address, byte[] readMemory) throws IOException { + seek(address & 0xfff00); + readFully(readMemory); + for (int i = 0; i < readMemory.length; i++) { + readMemory[i] = (byte) (~readMemory[i] & 0xff); + } + } + public void portWrite(IOPort source, int data) { // Chip select = active low... if (chipSelect && (data & CHIP_SELECT) != 0) { @@ -329,7 +363,7 @@ public String getName() { return "M25P80: external flash"; } - + public abstract void seek(long pos) throws IOException; public abstract int readFully(byte[] b) throws IOException; public abstract void write(byte[] b) throws IOException; Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2008-09-15 21:11:08 UTC (rev 326) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2008-09-15 21:16:47 UTC (rev 327) @@ -44,6 +44,7 @@ import se.sics.mspsim.core.CPUMonitor; import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.MSP430Constants; +import se.sics.mspsim.core.Memory; import se.sics.mspsim.platform.GenericNode; import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.DebugInfo; @@ -54,8 +55,10 @@ public class DebugCommands implements CommandBundle { private long lastCall = 0; private long lastWall = 0; - + private ComponentRegistry registry; + public void setupCommands(ComponentRegistry registry, CommandHandler ch) { + this.registry = registry; final MSP430 cpu = (MSP430) registry.getComponent(MSP430.class); final ELF elf = (ELF) registry.getComponent(ELF.class); final GenericNode node = (GenericNode) registry.getComponent("node"); @@ -303,7 +306,7 @@ return 0; } }); - + ch.registerCommand("set", new BasicCommand("set memory", "<address> <value> [type]") { public int executeCommand(final CommandContext context) { int adr = context.getArgumentAsAddress(0); @@ -313,8 +316,63 @@ return 0; }}); + /****************************************************** + * handle external memory (flash, etc). + ******************************************************/ + ch.registerCommand("xmem", new BasicCommand("dump flash memory", "<start address> <num_emtries> [type]") { + public int executeCommand(final CommandContext context) { + Memory xmem = (Memory) DebugCommands.this.registry.getComponent("xmem"); + if (xmem == null) { + context.err.print("No xmem component registered"); + return 0; + } + int start = context.getArgumentAsAddress(0); + int count = context.getArgumentAsInt(1); + int size = 1; // unsigned byte + boolean signed = false; + if (context.getArgumentCount() > 2) { + String tS = context.getArgument(2); + if ("byte".equals(tS)) { + signed = true; + } else if ("word".equals(tS)) { + signed = true; + size = 2; + } else if ("uword".equals(tS)) { + size = 2; + } + } + // Does not yet handle signed data... + for (int i = 0; i < count; i++) { + int data = 0; + data = xmem.readByte(start++); + if (size == 2) { + data = data + (xmem.readByte(start++) << 8); + } + context.out.print(" " + data); + } + context.out.println(); + return 0; + } + }); - + ch.registerCommand("xset", new BasicCommand("set memory", "<address> <value> [type]") { + public int executeCommand(final CommandContext context) { + Memory xmem = (Memory) DebugCommands.this.registry.getComponent("xmem"); + if (xmem == null) { + context.err.print("No xmem component registered"); + return 0; + } + int adr = context.getArgumentAsAddress(0); + int val = context.getArgumentAsInt(1); + boolean word = val > 0xff; + if (word) { + xmem.writeByte(adr, val >> 8); + val = val & 0xff; + adr++; + } + xmem.writeByte(adr, val & 0xff); + return 0; + }}); } } Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-09-15 21:11:08 UTC (rev 326) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2008-09-15 21:16:47 UTC (rev 327) @@ -199,6 +199,7 @@ dataChart.addDataSource(dss, "Transmit", stats.getDataSource("CC2420", CC2420.MODE_TXRX_ON)); dataChart.addDataSource(dss, "CPU", stats.getDataSource("MSP430 Core", MSP430.MODE_ACTIVE)); } + registry.registerComponent("xmem", flash); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |