You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(21) |
Nov
(12) |
Dec
(41) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(25) |
Feb
(54) |
Mar
(63) |
Apr
(52) |
May
(17) |
Jun
(3) |
Jul
(3) |
Aug
(5) |
Sep
(49) |
Oct
(50) |
Nov
(34) |
Dec
(14) |
2009 |
Jan
(9) |
Feb
(15) |
Mar
(38) |
Apr
(12) |
May
(35) |
Jun
(20) |
Jul
(2) |
Aug
(7) |
Sep
(36) |
Oct
(24) |
Nov
(2) |
Dec
(2) |
2010 |
Jan
(14) |
Feb
(1) |
Mar
(36) |
Apr
(2) |
May
(4) |
Jun
(6) |
Jul
(35) |
Aug
(11) |
Sep
(8) |
Oct
(3) |
Nov
|
Dec
(1) |
2011 |
Jan
(11) |
Feb
(12) |
Mar
(3) |
Apr
(7) |
May
(12) |
Jun
(8) |
Jul
|
Aug
(3) |
Sep
(4) |
Oct
|
Nov
(2) |
Dec
(4) |
2012 |
Jan
(2) |
Feb
(1) |
Mar
(14) |
Apr
(5) |
May
(28) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(21) |
Nov
(4) |
Dec
(1) |
2013 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Joakim E. <jo...@us...> - 2012-10-05 18:18:29
|
The branch "master" has been updated via 47321ce6164a56d2ca478d0719dec4f3ee1437ec (commit) from 13eb76ff7e706527996d408ec7658d53e76af77d (commit) Changed paths: M se/sics/mspsim/core/DbgInstruction.java M se/sics/mspsim/core/DisAsm.java M se/sics/mspsim/core/MSP430Constants.java M se/sics/mspsim/core/MSP430Core.java M se/sics/mspsim/core/Memory.java - Log ----------------------------------------------------------------- commit 47321ce6164a56d2ca478d0719dec4f3ee1437ec Author: Joakim Eriksson <jo...@si...> Date: Fri Oct 5 20:18:11 2012 +0200 cleaned up MSP430X byte/word/addressword handling and added support for additional instructions diff --git a/se/sics/mspsim/core/DbgInstruction.java b/se/sics/mspsim/core/DbgInstruction.java index 9b059c3..5092ff0 100644 --- a/se/sics/mspsim/core/DbgInstruction.java +++ b/se/sics/mspsim/core/DbgInstruction.java @@ -50,9 +50,16 @@ private int size; private int pos; + private boolean extWord = false; + public DbgInstruction() { } + + public boolean isExtensionWord() { + return extWord; + } + public void setPos(int p) { pos = p; } @@ -103,4 +110,9 @@ public String toString() { return getASMLine(); } + + public void setExtWord(boolean b) { + extWord = b; + } + } diff --git a/se/sics/mspsim/core/DisAsm.java b/se/sics/mspsim/core/DisAsm.java index e0e64a8..dda6689 100644 --- a/se/sics/mspsim/core/DisAsm.java +++ b/se/sics/mspsim/core/DisAsm.java @@ -79,6 +79,15 @@ public DbgInstruction disassemble(int pc, int[] memory, int[] reg, System.out.println("//// " + fkn); } System.out.println(dbg.getASMLine()); + + /* Hack for printing the instruction after the ext word... */ + if (dbg.isExtensionWord()) { + pc = pc + 2; + dbg = disassemble(pc, memory, reg, new DbgInstruction(), + interrupt); + System.out.println(dbg.getASMLine()); + } + return dbg; } @@ -128,6 +137,7 @@ public DbgInstruction disassemble(int pc, int[] memory, int[] reg, int srcdata = (instruction & 0x0f00) >> 8; int dst = instruction & 0x000f; int nextData = memory[pc] + (memory[pc + 1] << 8); + boolean rrword = true; switch(op) { case MOVA_IND: @@ -180,6 +190,26 @@ public DbgInstruction disassemble(int pc, int[] memory, int[] reg, case SUBA_REG: opstr = "SUBA R" + srcdata + ",R" + dst; break; + case RRXX_ADDR: + rrword = false; + case RRXX_WORD: + String rrwordStr = rrword ? ".W" : ".A"; + int count = ((instruction >> 10) & 0x03) + 1; // shift amount + switch (instruction & RRMASK) { + case RRCM: + opstr = "RRCM" + rrwordStr + " #" + count + ",R" + dst; + break; + case RRAM: + opstr = "RRAM" + rrwordStr + " #" + count + ",R" + dst; + break; + case RLAM: + opstr = "RLAM" + rrwordStr + " #" + count + ",R" + dst; + break; + case RRUM: + opstr = "RRUM" + rrwordStr + " #" + count + ",R" + dst; + break; + } + break; } output += dumpMem(startPC, size, memory); @@ -311,6 +341,7 @@ public DbgInstruction disassemble(int pc, int[] memory, int[] reg, int dhi = (instruction & EXTWORD_DST); opstr = "ExtWord " + Utils.hex16(instruction) + ":ZC:" + zc + " #:" + rp + " A/L:" + al + " src:" + shi + " dst:" + dhi; + dbg.setExtWord(true); } else { System.out.println("Not implemented instruction: $" + Utils.hex16(instruction) + " at " + Utils.hex16(startPC)); diff --git a/se/sics/mspsim/core/MSP430Constants.java b/se/sics/mspsim/core/MSP430Constants.java index 8097c26..5f30467 100644 --- a/se/sics/mspsim/core/MSP430Constants.java +++ b/se/sics/mspsim/core/MSP430Constants.java @@ -148,6 +148,7 @@ public static final int CALLA_MASK = 0xfff0; public static final int CALLA_REG = 0x1340; + public static final int CALLA_INDEX = 0x1350; public static final int CALLA_IND = 0x1360; public static final int CALLA_IND_AUTOINC = 0x1370; public static final int CALLA_ABS = 0x1380; diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java index b0c2c86..c09d87e 100644 --- a/se/sics/mspsim/core/MSP430Core.java +++ b/se/sics/mspsim/core/MSP430Core.java @@ -972,6 +972,7 @@ public int emulateOP(long maxCycles) throws EmulationException { return -2; } int ext3_0 = 0; + int ext10_7 = 0; boolean repeatsInDstReg = false; boolean wordx20 = false; @@ -979,6 +980,7 @@ public int emulateOP(long maxCycles) throws EmulationException { if ((instruction & 0xf800) == 0x1800) { extWord = instruction; ext3_0 = instruction & 0xf; /* bit 3 - 0 - either repeat count or dest 19-16 */ + ext10_7 = (instruction >> 7) & 0xf; /* bit 10 - 7 - src 19-16 */ pc += 2; // Bit 7 in the extension word indicates that the number of // repeats is found in the register pointed to by ext3_0. If @@ -1010,6 +1012,10 @@ public int emulateOP(long maxCycles) throws EmulationException { boolean zeroCarry = false; /* msp430X can zero carry in repeats */ boolean word = (instruction & 0x40) == 0; + /* NOTE: there is a mode when wordx20 = true & word = true that is resereved */ + AccessMode mode = wordx20 ? AccessMode.WORD20 : (word ? AccessMode.WORD : AccessMode.BYTE); + + if (mode == AccessMode.WORD20) System.out.println("WORD20 not really supported..."); // Destination vars int dstRegister = 0; @@ -1041,8 +1047,8 @@ public int emulateOP(long maxCycles) throws EmulationException { switch(op) { // 20 bit register write case MOVA_IND: - /* Read from address in src register, move to destination register. */ - writeRegister(dstData, readRegister(srcData)); + /* Read from address in src register (20-bit?), move to destination register (=20 bit). */ + writeRegister(dstData, currentSegment.read(readRegister(srcData), AccessMode.WORD20, AccessType.READ)); updateStatus = false; cycles += 3; break; @@ -1327,6 +1333,19 @@ public int emulateOP(long maxCycles) throws EmulationException { System.out.println("CALLA REG => " + Utils.hex20(dst)); cycles += 5; break; + case CALLA_INDEX: + /* CALLA X(REG) => REG + X is the address*/ + System.out.println("CALLA INDX: R" + dstRegister); + dst = readRegister(dstRegister); + /* what happens if wrapping here??? */ + System.out.println("CALLA INDX: Reg = " + Utils.hex20(dst) + " Mem: " + + currentSegment.read(pc, AccessMode.WORD, AccessType.READ)); + dst += currentSegment.read(pc, AccessMode.WORD, AccessType.READ); + System.out.println("CALLA INDX => " + Utils.hex20(dst)); + cycles += 5; + pc += 2; +// System.exit(0); + break; case CALLA_IMM: dst = (dstRegister << 16) | currentSegment.read(pc, AccessMode.WORD, AccessType.READ); pc += 2; @@ -1467,7 +1486,7 @@ public int emulateOP(long maxCycles) throws EmulationException { writeRegister(PC, pc); } else { dstAddress = readRegister(dstRegister); - writeRegister(dstRegister, dstAddress + (word ? 2 : 1)); + writeRegister(dstRegister, dstAddress + mode.bytes); // XXX (word ? 2 : 1)); } cycles += 3; break; @@ -1478,13 +1497,16 @@ public int emulateOP(long maxCycles) throws EmulationException { if (dstRegMode) { dst = readRegisterCG(dstRegister, ad); - if (word) { - dst &= 0xffff; - } else if (wordx20) { - dst &= 0xfffff; - } else { - dst &= 0xff; - } +//XXX if (word) { +// dst &= 0xffff; +// } else if (wordx20) { +// dst &= 0xfffff; +// } else { +// dst &= 0xff; +// } + + dst &= mode.mask; + /* set the repeat here! */ if (repeatsInDstReg) { repeats = 1 + readRegister(ext3_0); @@ -1515,13 +1537,14 @@ public int emulateOP(long maxCycles) throws EmulationException { case RRC: nxtCarry = (dst & 1) > 0 ? CARRY : 0; dst = dst >> 1; - if (word) { - dst |= (sr & CARRY) > 0 ? 0x8000 : 0; - } else if (wordx20) { - dst |= (sr & CARRY) > 0 ? 0x80000 : 0; - } else { - dst |= (sr & CARRY) > 0 ? 0x80 : 0; - } + dst |= (sr & CARRY) > 0 ? mode.msb : 0; +//XXX if (word) { +// dst |= (sr & CARRY) > 0 ? 0x8000 : 0; +// } else if (wordx20) { +// dst |= (sr & CARRY) > 0 ? 0x80000 : 0; +// } else { +// dst |= (sr & CARRY) > 0 ? 0x80 : 0; +// } // Indicate write to memory!! write = true; @@ -1535,13 +1558,14 @@ public int emulateOP(long maxCycles) throws EmulationException { break; case RRA: nxtCarry = (dst & 1) > 0 ? CARRY : 0; - if (word) { - dst = (dst & 0x8000) | (dst >> 1); - } else if (wordx20) { - dst = (dst & 0x80000) | (dst >> 1); - } else { - dst = (dst & 0x80) | (dst >> 1); - } + dst = (dst & mode.msb) | dst >> 1; +//XXX if (word) { +// dst = (dst & 0x8000) | (dst >> 1); +// } else if (wordx20) { +// dst = (dst & 0x80000) | (dst >> 1); +// } else { +// dst = (dst & 0x80) | (dst >> 1); +// } write = true; writeRegister(SR, (sr & ~(CARRY | OVERFLOW)) | nxtCarry); break; @@ -1626,13 +1650,14 @@ public int emulateOP(long maxCycles) throws EmulationException { Utils.hex16(instruction)); } if (repeats > 0) { - if (word) { - dst &= 0xffff; - } else if (wordx20) { - dst &= 0xfffff; - } else { - dst &= 0xff; - } +//XXX if (word) { +// dst &= 0xffff; +// } else if (wordx20) { +// dst &= 0xfffff; +// } else { +// dst &= 0xff; +// } + dst &= mode.mask; } } } @@ -1701,13 +1726,14 @@ public int emulateOP(long maxCycles) throws EmulationException { // Some CGs should be handled as registry reads only... if ((srcRegister == CG1 && as > AM_INDEX) || srcRegister == CG2) { src = CREG_VALUES[srcRegister - 2][as]; - if (word) { - src &= 0xffff; - } else if (wordx20) { - src &= 0xfffff; - } else { - src &= 0xff; - } + src &= mode.mask; +//XXX if (word) { +// src &= 0xffff; +// } else if (wordx20) { +// src &= 0xfffff; +// } else { +// src &= 0xff; +// } cycles += dstRegMode ? 1 : 4; } else { switch(as) { @@ -1715,13 +1741,14 @@ public int emulateOP(long maxCycles) throws EmulationException { case AM_REG: // CG handled above! src = readRegister(srcRegister); - if (word) { - src &= 0xffff; - } else if (wordx20) { - src &= 0xfffff; - } else { - src &= 0xff; - } + src &= mode.mask; +//XXX if (word) { +// src &= 0xffff; +// } else if (wordx20) { +// src &= 0xfffff; +// } else { +// src &= 0xff; +// } cycles += dstRegMode ? 1 : 4; /* add cycle if destination register = PC */ if (dstRegister == PC) cycles++; @@ -1776,7 +1803,7 @@ public int emulateOP(long maxCycles) throws EmulationException { cycles += dstRegMode ? 2 : 5; } else { srcAddress = readRegister(srcRegister); - incRegister(srcRegister, word ? 2 : 1); + incRegister(srcRegister, mode.bytes);//XXX word ? 2 : 1); cycles += dstRegMode ? 2 : 5; } /* If destination register is PC another cycle is consumed */ @@ -1791,13 +1818,14 @@ public int emulateOP(long maxCycles) throws EmulationException { if (dstRegMode) { if (op != MOV) { dst = readRegister(dstRegister); - if (word) { - dst &= 0xffff; - } else if (wordx20) { - dst &= 0xfffff; - } else { - dst &= 0xff; - } + dst &= mode.mask; +//XXX if (word) { +// dst &= 0xffff; +// } else if (wordx20) { +// dst &= 0xfffff; +// } else { +// dst &= 0xff; +// } } } else { // PC Could have changed above! @@ -1836,8 +1864,9 @@ public int emulateOP(long maxCycles) throws EmulationException { // System.out.println("SrcAddress is: " + Utils.hex20(srcAddress)); // } // srcAddress = srcAddress & 0xffff; + src = currentSegment.read(srcAddress, mode, AccessType.READ); - src = currentSegment.read(srcAddress, word ? AccessMode.WORD : AccessMode.BYTE, AccessType.READ); +// src = currentSegment.read(srcAddress, word ? AccessMode.WORD : AccessMode.BYTE, AccessType.READ); // if (debug) { // System.out.println("Reading from " + getAddressAsString(srcAddress) + @@ -1906,7 +1935,7 @@ public int emulateOP(long maxCycles) throws EmulationException { break; case CMP: // CMP // Set CARRY if A >= B, and it's clear if A < B - b = word ? 0x8000 : (wordx20 ? 0x80000 : 0x80); + b = mode.msb; sr = (sr & ~(CARRY | OVERFLOW)) | (dst >= src ? CARRY : 0); tmp = (dst - src); @@ -1954,7 +1983,7 @@ public int emulateOP(long maxCycles) throws EmulationException { break; case XOR: // XOR sr = sr & ~(CARRY | OVERFLOW); - b = word ? 0x8000 : (wordx20 ? 0x80000 : 0x80); + b = mode.msb; //word ? 0x8000 : (wordx20 ? 0x80000 : 0x80); if ((src & b) != 0 && (dst & b) != 0) { sr |= OVERFLOW; } @@ -1988,31 +2017,33 @@ public int emulateOP(long maxCycles) throws EmulationException { */ if (repeats > 0 && srcRegister == dstRegister) { src = dst; - if (word) { - src &= 0xffff; - } else if (wordx20) { - src &= 0xfffff; - } else { - src &= 0xff; - } + src &= mode.mask; +//XXX if (word) { +// src &= 0xffff; +// } else if (wordx20) { +// src &= 0xfffff; +// } else { +// src &= 0xff; +// } } } } /* Processing after each instruction */ - if (word) { - dst &= 0xffff; - } else if (wordx20) { - dst &= 0xfffff; - } else { - dst &= 0xff; - } + dst &= mode.mask; +//XXX if (word) { +// dst &= 0xffff; +// } else if (wordx20) { +// dst &= 0xfffff; +// } else { +// dst &= 0xff; +// } if (write) { if (dstRegMode) { writeRegister(dstRegister, dst); } else { dstAddress &= 0xffff; - currentSegment.write(dstAddress, dst, word ? AccessMode.WORD : AccessMode.BYTE); + currentSegment.write(dstAddress, dst, mode); } } if (updateStatus) { @@ -2020,10 +2051,10 @@ public int emulateOP(long maxCycles) throws EmulationException { // Carry and overflow must be set separately! sr = readRegister(SR); sr = (sr & ~(ZERO | NEGATIVE)) | - ((dst == 0) ? ZERO : 0) | - (word ? ((dst & 0x8000) > 0 ? NEGATIVE : 0) : - (wordx20 ? ((dst & 0x80000) > 0 ? NEGATIVE : 0) : - ((dst & 0x80) > 0 ? NEGATIVE : 0))); + ((dst == 0) ? ZERO : 0) | ((dst & mode.msb) > 0 ? NEGATIVE : 0); +//XXX (word ? ((dst & 0x8000) > 0 ? NEGATIVE : 0) : +// (wordx20 ? ((dst & 0x80000) > 0 ? NEGATIVE : 0) : +// ((dst & 0x80) > 0 ? NEGATIVE : 0))); writeRegister(SR, sr); } diff --git a/se/sics/mspsim/core/Memory.java b/se/sics/mspsim/core/Memory.java index ea19683..37ed95d 100644 --- a/se/sics/mspsim/core/Memory.java +++ b/se/sics/mspsim/core/Memory.java @@ -55,11 +55,13 @@ public final int bytes; public final int bitSize; public final int mask; + public final int msb; AccessMode(int bytes, int bitSize, int mask) { this.bytes = bytes; this.bitSize = bitSize; this.mask = mask; + this.msb = 1 << (bitSize - 1); } }; ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/core/DbgInstruction.java | 12 ++ se/sics/mspsim/core/DisAsm.java | 31 +++++ se/sics/mspsim/core/MSP430Constants.java | 1 + se/sics/mspsim/core/MSP430Core.java | 181 +++++++++++++++++------------ se/sics/mspsim/core/Memory.java | 4 +- 5 files changed, 153 insertions(+), 76 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-10-04 17:54:10
|
The branch "master" has been updated via 13eb76ff7e706527996d408ec7658d53e76af77d (commit) from 46695715b633af458ba1b060cf2419c678cad3e5 (commit) Changed paths: M se/sics/mspsim/core/MSP430Core.java - Log ----------------------------------------------------------------- commit 13eb76ff7e706527996d408ec7658d53e76af77d Author: Joakim Eriksson <jo...@si...> Date: Thu Oct 4 19:53:30 2012 +0200 implemented CALLA_REG instruction diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java index 76a03ef..b0c2c86 100644 --- a/se/sics/mspsim/core/MSP430Core.java +++ b/se/sics/mspsim/core/MSP430Core.java @@ -1322,6 +1322,11 @@ public int emulateOP(long maxCycles) throws EmulationException { /* do not update status after these instructions!!! */ updateStatus = false; switch(op) { + case CALLA_REG: + dst = readRegister(dstRegister); + System.out.println("CALLA REG => " + Utils.hex20(dst)); + cycles += 5; + break; case CALLA_IMM: dst = (dstRegister << 16) | currentSegment.read(pc, AccessMode.WORD, AccessType.READ); pc += 2; @@ -1372,7 +1377,6 @@ public int emulateOP(long maxCycles) throws EmulationException { regNo = instruction & 0x0f; // System.out.println("POPM W " + (type == AccessMode.WORD20 ? "A" : "W") + " n: " + // n + " " + regNo + " at " + Utils.hex16(pcBefore)); - /* read and increase stack pointer n times */ for(int i = 0; i < n; i++) { cycles += 2; ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/core/MSP430Core.java | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-10-04 16:14:01
|
The branch "master" has been updated via 46695715b633af458ba1b060cf2419c678cad3e5 (commit) from 632f4ac2557e4f7cfcfbae50ba85f0304b463ea3 (commit) Changed paths: M se/sics/mspsim/debug/DwarfReader.java - Log ----------------------------------------------------------------- commit 46695715b633af458ba1b060cf2419c678cad3e5 Author: Joakim Eriksson <jo...@si...> Date: Thu Oct 4 18:13:25 2012 +0200 fixed minor bug in setaddress in Dwarfreader state machine diff --git a/se/sics/mspsim/debug/DwarfReader.java b/se/sics/mspsim/debug/DwarfReader.java index ce7ed7f..4a5cc9e 100644 --- a/se/sics/mspsim/debug/DwarfReader.java +++ b/se/sics/mspsim/debug/DwarfReader.java @@ -240,6 +240,7 @@ private void readLines(ELFSection sec) { case DW_LNS_EXT: /* extended opcodes */ int len = (int) sec.readLEB128(); + int extPos = sec.getPosition(); int extIns = sec.readElf8(); if (DEBUG) System.out.println("EXT: " + Utils.hex8(extIns) + " LEN: " + len); switch(extIns) { @@ -257,7 +258,13 @@ private void readLines(ELFSection sec) { if (DEBUG) System.out.println("Line: End sequence executed!!!"); break; case DW_LNE_set_address: + if (len == 3) { lineAddress = sec.readElf16(); + } else if (len == 5) { + lineAddress = sec.readElf32(); + } else { + throw new IllegalStateException("No support for " + (len - 1) + " bytes addresses"); + } if (DEBUG) System.out.println("Line: Set address to: " + Utils.hex16(lineAddress) + " (len: " + len + ")"); break; @@ -280,6 +287,10 @@ private void readLines(ELFSection sec) { /* XXX TODO Implement me */ if (DEBUG) System.out.println("Line: unhandled EXT instr: " + Utils.hex8(extIns)); } + if (sec.getPosition() != extPos + len) { + throw new IllegalStateException("*** ERROR posistion is not as exepected!!!!" + (extPos + len) + " is " + + sec.getPosition()); + } break; case DW_LNS_copy: /* copy data to matrix... */ ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/debug/DwarfReader.java | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-) hooks/post-receive -- mspsim |
From: Niclas F. <ni...@us...> - 2012-10-04 15:29:15
|
The branch "master" has been updated via 632f4ac2557e4f7cfcfbae50ba85f0304b463ea3 (commit) via 6986c81b0cceea40b2058483ac73cb7ff558f005 (commit) from df95ab477f2aafaef9982ecfe54293c5152d02dd (commit) Changed paths: M se/sics/mspsim/debug/DwarfReader.java M se/sics/mspsim/util/ELFSection.java - Log ----------------------------------------------------------------- commit 632f4ac2557e4f7cfcfbae50ba85f0304b463ea3 Author: Niclas Finne <nf...@si...> Date: Thu Oct 4 17:28:35 2012 +0200 Added more debug output diff --git a/se/sics/mspsim/debug/DwarfReader.java b/se/sics/mspsim/debug/DwarfReader.java index b7d7de7..ce7ed7f 100644 --- a/se/sics/mspsim/debug/DwarfReader.java +++ b/se/sics/mspsim/debug/DwarfReader.java @@ -241,7 +241,7 @@ private void readLines(ELFSection sec) { /* extended opcodes */ int len = (int) sec.readLEB128(); int extIns = sec.readElf8(); - if (DEBUG) System.out.println("EXT: " + Utils.hex8(extIns)); + if (DEBUG) System.out.println("EXT: " + Utils.hex8(extIns) + " LEN: " + len); switch(extIns) { case DW_LNE_end_sequence: endSequence = true; @@ -261,16 +261,24 @@ private void readLines(ELFSection sec) { if (DEBUG) System.out.println("Line: Set address to: " + Utils.hex16(lineAddress) + " (len: " + len + ")"); break; - case DW_LNE_define_file: + case DW_LNE_define_file: { /* XXX TODO Implement me */ - if (DEBUG) System.out.println("Line: Should define a file!!!!"); + String filename = sec.readString(); + long directoryIndex = sec.readLEB128(); + long lastModified = sec.readLEB128(); + long fileSize = sec.readLEB128(); + if (DEBUG) System.out.println("Line: Should define the file '" + filename + "' dir " + + directoryIndex + " modified " + lastModified + " size " + fileSize); break; + } case DW_LNE_set_discriminator: // DWARF 4.0? /* currently just read it but ignore it - TODO: use this info */ /*reg_discriminator = */sec.readElf8(); + if (DEBUG) System.out.println("Line: Should support DW_LNE_set_discriminator"); break; default: /* XXX TODO Implement me */ + if (DEBUG) System.out.println("Line: unhandled EXT instr: " + Utils.hex8(extIns)); } break; case DW_LNS_copy: @@ -332,7 +340,8 @@ private void readLines(ELFSection sec) { break; default: if (DEBUG) { - System.out.println("INS: " + Utils.hex8(opCode)); + System.out.println("INS: " + Utils.hex8(opCode) + " AINS: " + Utils.hex8(opCode - opcodeBase) + + " lineRange: " + lineRange); } int adjustedOpcode = opCode - opcodeBase; commit 6986c81b0cceea40b2058483ac73cb7ff558f005 Author: Niclas Finne <nf...@si...> Date: Thu Oct 4 17:27:15 2012 +0200 Added method to read null terminated string diff --git a/se/sics/mspsim/util/ELFSection.java b/se/sics/mspsim/util/ELFSection.java index 31812a8..7f90d3a 100644 --- a/se/sics/mspsim/util/ELFSection.java +++ b/se/sics/mspsim/util/ELFSection.java @@ -114,7 +114,7 @@ public int getSize() { public String getName(int i) { int pos = getOffset() + i; - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); char c; int elfSize = elf.elfData.length; while (pos < elfSize && (c = (char) elf.elfData[pos++]) != 0) { @@ -123,6 +123,15 @@ public String getName(int i) { return sb.toString(); } + public String readString() { + StringBuilder sb = new StringBuilder(); + int c; + while ((c = readElf8()) != 0) { + sb.append((char)c); + } + return sb.toString(); + } + public int readElf8() { return readElf8(pos++); } ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/debug/DwarfReader.java | 17 +++++++++++++---- se/sics/mspsim/util/ELFSection.java | 11 ++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) hooks/post-receive -- mspsim |
From: Niclas F. <ni...@us...> - 2012-05-31 13:34:59
|
The branch "master" has been updated via df95ab477f2aafaef9982ecfe54293c5152d02dd (commit) from e2e1fba86dadc0c8d0b49ded4591c52620b620b5 (commit) Changed paths: M se/sics/mspsim/platform/GenericNode.java - Log ----------------------------------------------------------------- commit df95ab477f2aafaef9982ecfe54293c5152d02dd Author: Niclas Finne <nf...@si...> Date: Thu May 31 10:48:59 2012 +0200 Added methods to load a firmware without specifying a memory. diff --git a/se/sics/mspsim/platform/GenericNode.java b/se/sics/mspsim/platform/GenericNode.java index 156ee81..4bdfdcf 100644 --- a/se/sics/mspsim/platform/GenericNode.java +++ b/se/sics/mspsim/platform/GenericNode.java @@ -295,7 +295,11 @@ public void step(int nr) throws EmulationException { } } - public ELF loadFirmware(URL url, int[] memory) throws IOException { + public ELF loadFirmware(URL url) throws IOException { + return loadFirmware(url, cpu.memory); + } + + @Deprecated public ELF loadFirmware(URL url, int[] memory) throws IOException { DataInputStream inputStream = new DataInputStream(url.openStream()); ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); byte[] firmwareData = new byte[2048]; @@ -309,11 +313,19 @@ public ELF loadFirmware(URL url, int[] memory) throws IOException { return loadFirmware(elf, memory); } - public ELF loadFirmware(String name, int[] memory) throws IOException { + public ELF loadFirmware(String name) throws IOException { + return loadFirmware(name, cpu.memory); + } + + @Deprecated public ELF loadFirmware(String name, int[] memory) throws IOException { return loadFirmware(ELF.readELF(firmwareFile = name), memory); } - public ELF loadFirmware(ELF elf, int[] memory) { + public ELF loadFirmware(ELF elf) { + return loadFirmware(elf, cpu.memory); + } + + @Deprecated public ELF loadFirmware(ELF elf, int[] memory) { if (cpu.isRunning()) { stop(); } ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/platform/GenericNode.java | 18 +++++++++++++++--- 1 files changed, 15 insertions(+), 3 deletions(-) hooks/post-receive -- mspsim |
From: Niclas F. <ni...@us...> - 2012-05-30 23:56:18
|
The branch "master" has been updated via e2e1fba86dadc0c8d0b49ded4591c52620b620b5 (commit) via 3ddcfefe04621e69da7deb619111ed98d1793368 (commit) via bf6233669d8193970ec75225a2ee7e81133fa616 (commit) via d33bd84726715ecdfe60fea0979ec2c89e364d6c (commit) from f3e9c856e83243f580f1045b9f38424c9e265688 (commit) Changed paths: A images/wismote.jpg D images/wismote.png M se/sics/mspsim/chip/AT45DB.java C065 se/sics/mspsim/chip/ChannelListener.java se/sics/mspsim/chip/Accelerometer.java C067 se/sics/mspsim/chip/ChannelListener.java se/sics/mspsim/chip/ExternalFlash.java D se/sics/mspsim/chip/FileAT45DB.java D se/sics/mspsim/chip/FileM25P80.java A se/sics/mspsim/chip/FileStorage.java C080 se/sics/mspsim/chip/RFSource.java se/sics/mspsim/chip/M25P16.java M se/sics/mspsim/chip/M25P80.java M se/sics/mspsim/chip/MMA7260QT.java A se/sics/mspsim/chip/MemoryStorage.java C074 se/sics/mspsim/config/MSP430f149Config.java se/sics/mspsim/chip/Storage.java M se/sics/mspsim/platform/esb/ESBNode.java M se/sics/mspsim/platform/jcreate/JCreateNode.java M se/sics/mspsim/platform/sentillausb/SentillaUSBNode.java M se/sics/mspsim/platform/sky/CC2420Node.java M se/sics/mspsim/platform/sky/SkyNode.java M se/sics/mspsim/platform/sky/TelosNode.java M se/sics/mspsim/platform/ti/Exp5438Node.java M se/sics/mspsim/platform/tyndall/TyndallNode.java M se/sics/mspsim/platform/wismote/WismoteGui.java M se/sics/mspsim/platform/wismote/WismoteNode.java M se/sics/mspsim/platform/z1/Z1Node.java - Log ----------------------------------------------------------------- commit e2e1fba86dadc0c8d0b49ded4591c52620b620b5 Author: Niclas Finne <nf...@si...> Date: Thu May 31 01:23:34 2012 +0200 Publish the UART/USCI used for serial output by the platform in the registry as 'serialio' diff --git a/se/sics/mspsim/platform/esb/ESBNode.java b/se/sics/mspsim/platform/esb/ESBNode.java index cbbe5c9..c95fd0d 100644 --- a/se/sics/mspsim/platform/esb/ESBNode.java +++ b/se/sics/mspsim/platform/esb/ESBNode.java @@ -161,6 +161,11 @@ public void setupNodePorts() { leds = new Leds(cpu, LEDS); button = new Button("Button", cpu, port2, BUTTON_PIN, true); beeper = new Beeper(cpu); + + USART usart = cpu.getIOUnit(USART.class, "USART1"); + if (usart != null) { + registry.registerComponent("serialio", usart); + } } public void setupNode() { diff --git a/se/sics/mspsim/platform/sky/CC2420Node.java b/se/sics/mspsim/platform/sky/CC2420Node.java index 7d46e16..1a2a580 100644 --- a/se/sics/mspsim/platform/sky/CC2420Node.java +++ b/se/sics/mspsim/platform/sky/CC2420Node.java @@ -92,6 +92,11 @@ public void setupNodePorts() { usart0.addUSARTListener(this); radio.setSFDPort(port4, CC2420_SFD); + + USART usart = cpu.getIOUnit(USART.class, "USART1"); + if (usart != null) { + registry.registerComponent("serialio", usart); + } } public void setupNode() { diff --git a/se/sics/mspsim/platform/ti/Exp5438Node.java b/se/sics/mspsim/platform/ti/Exp5438Node.java index 079f1ca..3cbeb35 100644 --- a/se/sics/mspsim/platform/ti/Exp5438Node.java +++ b/se/sics/mspsim/platform/ti/Exp5438Node.java @@ -8,6 +8,7 @@ import se.sics.mspsim.core.IOPort; import se.sics.mspsim.core.IOUnit; import se.sics.mspsim.core.PortListener; +import se.sics.mspsim.core.USART; import se.sics.mspsim.core.USARTListener; import se.sics.mspsim.core.USARTSource; import se.sics.mspsim.platform.GenericNode; @@ -91,6 +92,11 @@ private void setupNodePorts() { } else { throw new EmulationException("Could not setup exp5438 mote - missing USCI B0"); } + + IOUnit usart = cpu.getIOUnit("USCI A1"); + if (usart instanceof USARTSource) { + registry.registerComponent("serialio", usart); + } } public void setupNode() { diff --git a/se/sics/mspsim/platform/tyndall/TyndallNode.java b/se/sics/mspsim/platform/tyndall/TyndallNode.java index 28f72bc..e472f2e 100644 --- a/se/sics/mspsim/platform/tyndall/TyndallNode.java +++ b/se/sics/mspsim/platform/tyndall/TyndallNode.java @@ -117,6 +117,11 @@ private void setupNodePorts() { } else { throw new EmulationException("Could not setup tyndall mote - missing USCI B0"); } + + IOUnit usart = cpu.getIOUnit("USCI A0"); + if (usart instanceof USARTSource) { + registry.registerComponent("serialio", usart); + } } public void setupNode() { diff --git a/se/sics/mspsim/platform/wismote/WismoteNode.java b/se/sics/mspsim/platform/wismote/WismoteNode.java index 44eb885..d2b2853 100644 --- a/se/sics/mspsim/platform/wismote/WismoteNode.java +++ b/se/sics/mspsim/platform/wismote/WismoteNode.java @@ -174,6 +174,11 @@ private void setupNodePorts() { } leds = new Leds(cpu, LEDS); button = new Button("Button", cpu, port2, BUTTON_PIN, true); + + IOUnit usart = cpu.getIOUnit("USCI A1"); + if (usart instanceof USARTSource) { + registry.registerComponent("serialio", usart); + } } public void setupNode() { @@ -202,7 +207,7 @@ public void setupNode() { // Add some windows for listening to serial output IOUnit usart = cpu.getIOUnit("USCI A1"); if (usart instanceof USARTSource) { - SerialMon serial = new SerialMon((USARTSource)usart, "USCI A0 Port Output"); + SerialMon serial = new SerialMon((USARTSource)usart, "USCI A1 Port Output"); registry.registerComponent("serialgui", serial); } } diff --git a/se/sics/mspsim/platform/z1/Z1Node.java b/se/sics/mspsim/platform/z1/Z1Node.java index 8c938ea..3fff11a 100644 --- a/se/sics/mspsim/platform/z1/Z1Node.java +++ b/se/sics/mspsim/platform/z1/Z1Node.java @@ -173,6 +173,12 @@ private void setupNodePorts() { leds = new Leds(cpu, LEDS); button = new Button("Button", cpu, port2, BUTTON_PIN, true); + + IOUnit usart = cpu.getIOUnit("USCI A0"); + if (usart instanceof USARTSource) { + registry.registerComponent("serialio", usart); + } + if (getFlash() == null) { setFlash(new M25P80(cpu)); } @@ -207,7 +213,7 @@ public void setupNode() { // Add some windows for listening to serial output IOUnit usart = cpu.getIOUnit("USCI A0"); if (usart instanceof USARTSource) { - SerialMon serial = new SerialMon((USARTSource)usart, "USART1 Port Output"); + SerialMon serial = new SerialMon((USARTSource)usart, "USCI A0 Port Output"); registry.registerComponent("serialgui", serial); } } commit 3ddcfefe04621e69da7deb619111ed98d1793368 Author: Niclas Finne <nf...@si...> Date: Wed May 30 22:40:54 2012 +0200 Added ExternalFlash base class for emulation of external flash chips. Replaced FileAT45DB and FileM25P80 with storage abstraction for storing data in memory or on file diff --git a/se/sics/mspsim/chip/AT45DB.java b/se/sics/mspsim/chip/AT45DB.java index 5d07695..3f7135e 100644 --- a/se/sics/mspsim/chip/AT45DB.java +++ b/se/sics/mspsim/chip/AT45DB.java @@ -43,7 +43,7 @@ import java.io.IOException; import se.sics.mspsim.core.*; -public abstract class AT45DB extends Chip implements USARTListener { +public class AT45DB extends ExternalFlash implements USARTListener { public static final int PAGE_SIZE = 264; public static final int NUM_PAGES = 2048; @@ -337,11 +337,10 @@ public void setChipSelect(boolean select) { private void bufferToPage(int buf) { try { - seek(pageAddress * PAGE_SIZE); if(buf == 1) - write(buffer1); + getStorage().write(pageAddress * PAGE_SIZE, buffer1); else - write(buffer2); + getStorage().write(pageAddress * PAGE_SIZE, buffer2); } catch (IOException e) { e.printStackTrace(); } @@ -349,11 +348,10 @@ private void bufferToPage(int buf) { private void pageToBuffer(int buf) { try { - seek(pageAddress * PAGE_SIZE); if(buf == 1) - read(buffer1); + getStorage().read(pageAddress * PAGE_SIZE, buffer1); else - read(buffer2); + getStorage().read(pageAddress * PAGE_SIZE, buffer2); } catch (IOException e) { e.printStackTrace(); } @@ -363,12 +361,8 @@ public int getModeMax() { return 0; } - public abstract void seek(long pos) throws IOException; - public abstract int read(byte[] b) throws IOException; - public abstract void write(byte[] b) throws IOException; - - /* not yet any meaningful support for getting configuration */ - public int getConfiguration(int param) { + @Override + public int getSize() { return 0; } diff --git a/se/sics/mspsim/chip/ExternalFlash.java b/se/sics/mspsim/chip/ExternalFlash.java new file mode 100644 index 0000000..319ec59 --- /dev/null +++ b/se/sics/mspsim/chip/ExternalFlash.java @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2012, 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. + * + */ +package se.sics.mspsim.chip; + +import se.sics.mspsim.core.Chip; +import se.sics.mspsim.core.MSP430Core; + +public abstract class ExternalFlash extends Chip { + + private Storage storage; + + protected ExternalFlash(String id, MSP430Core cpu) { + super(id, cpu); + } + + protected ExternalFlash(String id, String name, MSP430Core cpu) { + super(id, name, cpu); + } + + public Storage getStorage() { + if (storage ==null) { + // No storage set. Create a memory storage + storage = new MemoryStorage(); + storage.setMaxSize(getSize()); + } + return storage; + } + + public void setStorage(Storage storage) { + this.storage = storage; + } + + @Override + public int getConfiguration(int param) { + return 0; + } + + public abstract int getSize(); + +} diff --git a/se/sics/mspsim/chip/FileAT45DB.java b/se/sics/mspsim/chip/FileAT45DB.java deleted file mode 100644 index cc123ba..0000000 --- a/se/sics/mspsim/chip/FileAT45DB.java +++ /dev/null @@ -1,146 +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: $ - * - * ----------------------------------------------------------------- - * - * FileAT45DB - File based implementation of external flash. - * - * Author : Joakim Eriksson, Fredrik Osterlind - * Created : Sun Oct 21 22:00:00 2007 - * Updated : $Date: 2008-05-12 18:10:17 +0000 (Mon, 12 May 2008) $ - * $Revision: 280 $ - */ - -package se.sics.mspsim.chip; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.nio.channels.FileChannel; -import java.nio.channels.FileLock; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import se.sics.mspsim.core.MSP430Core; - -public class FileAT45DB extends AT45DB { - - // PAGE_SIZE and NUM_PAGES defined in AT45DB - private static final int FLASH_SIZE = PAGE_SIZE * NUM_PAGES; - - private RandomAccessFile file; - private FileChannel fileChannel; - private FileLock fileLock; - - public FileAT45DB(MSP430Core cpu, String filename) { - super(cpu); - if (filename == null) { - filename = "flash.bin"; - } - - // Open flash file for R/W - if (!openFile(filename)) { - // Failed to open/lock the specified file. Add a counter and try with next filename. - Matcher m = Pattern.compile("(.+?)(\\d*)(\\.[^.]+)").matcher(filename); - if (m.matches()) { - String baseName = m.group(1); - String c = m.group(2); - String extName = m.group(3); - int count = 1; - if (c != null && c.length() > 0) { - count = Integer.parseInt(c) + 1; - } - for (int i = 0; !openFile(baseName + count + extName) && i < 100; i++, count++); - } - } - if (fileLock == null) { - // Failed to open flash file - throw new IllegalStateException("failed to open flash file '" + filename + '\''); - } - // Set size of flash - try { - file.setLength(FLASH_SIZE); - } catch (IOException e) { - e.printStackTrace(); - } - } - - private boolean openFile(String filename) { - // Open flash file for R/W - try { - file = new RandomAccessFile(filename, "rw"); - fileChannel = file.getChannel(); - fileLock = fileChannel.tryLock(); - if (fileLock != null) { - // The file is now locked for use - if (DEBUG) log("using flash file '" + filename + '\''); - return true; - } else { - fileChannel.close(); - return false; - } - } catch (IOException e) { - e.printStackTrace(); - closeFile(); - return false; - } - } - - private void closeFile() { - try { - if (fileLock != null) { - fileLock.release(); - fileLock = null; - } - if (fileChannel != null) { - fileChannel.close(); - fileChannel = null; - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void seek(long pos) throws IOException { - file.seek(pos); - } - - public int read(byte[] b) throws IOException { - return file.read(b); - } - - public void write(byte[] b) throws IOException { - file.write(b); - } - - public void stateChanged(int state) { - // TODO Auto-generated method stub - - } - -} // FileAT45DB diff --git a/se/sics/mspsim/chip/FileM25P80.java b/se/sics/mspsim/chip/FileM25P80.java deleted file mode 100644 index 8be8c86..0000000 --- a/se/sics/mspsim/chip/FileM25P80.java +++ /dev/null @@ -1,180 +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$ - * - * ----------------------------------------------------------------- - * - * FileM25P80 - File based implementation of external flash. - * - * Author : Joakim Eriksson, Fredrik Osterlind - * Created : Sun Oct 21 22:00:00 2007 - * Updated : $Date$ - * $Revision$ - */ - -package se.sics.mspsim.chip; -import java.io.File; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.nio.channels.FileChannel; -import java.nio.channels.FileLock; -import java.util.Arrays; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import se.sics.mspsim.core.MSP430Core; - -public class FileM25P80 extends M25P80 { - - private String filename; - private RandomAccessFile file; - private FileChannel fileChannel; - private FileLock fileLock; - private long pos = 0; - - public FileM25P80(MSP430Core cpu, String filename) { - super(cpu); - if (filename == null) { - filename = "flash.bin"; - } - this.filename = filename; - } - - private boolean ensureOpen(boolean write) { - if (fileChannel != null) { - return true; - } - if (!write) { - File fp = new File(filename); - if (!fp.exists()) { - // File does not exist and only trying to read. Delay file creation until first write - return false; - } - } - - // Open flash file for R/W - if (!openFile(filename)) { - // Failed to open/lock the specified file. Add a counter and try with next filename. - Matcher m = Pattern.compile("(.+?)(\\d*)(\\.[^.]+)").matcher(filename); - if (m.matches()) { - String baseName = m.group(1); - String c = m.group(2); - String extName = m.group(3); - int count = 1; - if (c != null && c.length() > 0) { - count = Integer.parseInt(c) + 1; - } - for (int i = 0; !openFile(baseName + count + extName) && i < 100; i++, count++); - } - } - if (fileLock == null) { - // Failed to open flash file - if (write) { - logw("failed to open flash file '" + filename + '\''); - } - return false; - } - // Set size of flash - try { - file.setLength(MEMORY_SIZE); - if (pos > 0) { - file.seek(pos); - } - return true; - } catch (IOException e) { - e.printStackTrace(); - return false; - } - } - - private boolean openFile(String filename) { - // Open flash file for R/W - try { - file = new RandomAccessFile(filename, "rw"); - fileChannel = file.getChannel(); - fileLock = fileChannel.tryLock(); - if (fileLock != null) { - // The file is now locked for use - if (DEBUG) log("using flash file '" + filename + '\''); - return true; - } - fileChannel.close(); - return false; - } catch (IOException e) { - e.printStackTrace(); - closeFile(); - return false; - } - } - - private void closeFile() { - try { - file = null; - if (fileLock != null) { - fileLock.release(); - fileLock = null; - } - if (fileChannel != null) { - fileChannel.close(); - fileChannel = null; - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void seek(long pos) throws IOException { - if (file != null) { - file.seek(pos); - } - this.pos = pos; - } - - public int readFully(byte[] b) throws IOException { - if (file != null || ensureOpen(false)) { - pos += b.length; - return file.read(b); - } - Arrays.fill(b, (byte) 0); - pos += b.length; - return b.length; - } - - public void write(byte[] b) throws IOException { - if (file != null || ensureOpen(true)) { - file.write(b); - } - pos += b.length; - } - - public void stateChanged(int state) { - // TODO Auto-generated method stub - } - -} // FileM25P80 diff --git a/se/sics/mspsim/chip/FileStorage.java b/se/sics/mspsim/chip/FileStorage.java new file mode 100644 index 0000000..1bd5796 --- /dev/null +++ b/se/sics/mspsim/chip/FileStorage.java @@ -0,0 +1,229 @@ +/** + * Copyright (c) 2012, 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. + * + */ +package se.sics.mspsim.chip; +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; +import java.util.Arrays; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author Niclas Finne + */ +public class FileStorage implements Storage { + + private String filename; + private String currentFilename; + private RandomAccessFile file; + private FileChannel fileChannel; + private FileLock fileLock; + private long maxSize = 0; + + public FileStorage() { + this("flash.bin"); + } + + public FileStorage(String filename) { + this.filename = filename; + } + + private boolean ensureOpen(boolean write) throws IOException { + if (fileChannel != null) { + return true; + } + if (!write) { + File fp = new File(filename); + if (!fp.exists()) { + // File does not exist and only trying to read. Delay file creation until first write + return false; + } + } + + // Open flash file for R/W + if (!openFile(filename)) { + // Failed to open/lock the specified file. Add a counter and try with next filename. + Matcher m = Pattern.compile("(.+?)(\\d*)(\\.[^.]+)").matcher(filename); + if (m.matches()) { + String baseName = m.group(1); + String c = m.group(2); + String extName = m.group(3); + int count = 1; + if (c != null && c.length() > 0) { + count = Integer.parseInt(c) + 1; + } + for (int i = 0; !openFile(baseName + count + extName) && i < 100; i++, count++); + } + } + if (fileLock == null) { + // Failed to open flash file + if (write) { + throw new IOException("failed to open storage file '" + filename + '\''); + } + return false; + } + return true; + } + + private boolean openFile(String filename) { + // Open flash file for R/W + try { + currentFilename = filename; + file = new RandomAccessFile(filename, "rw"); + fileChannel = file.getChannel(); + fileLock = fileChannel.tryLock(); + if (fileLock != null) { + // The file is now locked for use +// if (DEBUG) log("using flash file '" + filename + '\''); + return true; + } + fileChannel.close(); + return false; + } catch (IOException e) { + e.printStackTrace(); + close(); + return false; + } + } + + public String getFilename() { + return filename; + } + + public void setFilename(String filename) { + this.filename = filename; + close(); + } + + public File getCurrentFile() { + if (file != null) { + return new File(currentFilename); + } + return null; + } + + @Override + public int read(long pos, byte[] b) throws IOException { + return read(pos, b, 0, b.length); + } + + @Override + public int read(long pos, byte[] b, int offset, int len) throws IOException { + if (maxSize > 0 && pos + len > maxSize) { + throw new IOException("outside storage"); + } + if (file != null || ensureOpen(false)) { + file.seek(pos); + return file.read(b, offset, len); + } + Arrays.fill(b, (byte) 0); + return len; + } + + @Override + public void write(long pos, byte[] b) throws IOException { + write(pos, b, 0, b.length); + } + + public void write(long pos, byte[] b, int offset, int len) throws IOException { + if (maxSize > 0 && pos + len > maxSize) { + throw new IOException("outside storage"); + } + if (file != null || ensureOpen(true)) { + file.seek(pos); + file.write(b, offset, len); + } + } + + @Override + public long getMaxSize() { + return maxSize; + } + + @Override + public void setMaxSize(long size) { + this.maxSize = size; + if (size > 0 && file != null) { + try { + if (file.length() > size) { + file.setLength(size); + } + } catch (IOException e) { + // Ignore + } + } + } + + @Override + public void close() { + try { + file = null; + if (fileLock != null) { + fileLock.release(); + fileLock = null; + } + if (fileChannel != null) { + fileChannel.close(); + fileChannel = null; + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public String info() { + File fp = getCurrentFile(); + StringBuilder sb = new StringBuilder(); + sb.append("FileStorage("); + if (file != null) { + try { + long len = file.length(); + sb.append(len); + } catch (Exception e) { + // Ignore + sb.append('0'); + } + } + if (maxSize > 0) { + sb.append('/').append(maxSize); + } + sb.append(" bytes): "); + if (fp != null) { + sb.append(fp.getAbsolutePath()); + } else { + sb.append(filename); + } + return sb.toString(); + } +} diff --git a/se/sics/mspsim/chip/M25P16.java b/se/sics/mspsim/chip/M25P16.java new file mode 100644 index 0000000..d678641 --- /dev/null +++ b/se/sics/mspsim/chip/M25P16.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) 2012, 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. + * + */ +package se.sics.mspsim.chip; + +import se.sics.mspsim.core.MSP430Core; + +/** + * @author Niclas Finne + */ +public class M25P16 extends M25P80 { + + public static final int MEMORY_SIZE = 2 * 1024 * 1024; + + public M25P16(MSP430Core cpu) { + super("M25P16", cpu); + } + + @Override + public int getSize() { + return MEMORY_SIZE; + } + +} diff --git a/se/sics/mspsim/chip/M25P80.java b/se/sics/mspsim/chip/M25P80.java index 0f9cb76..191d6c2 100644 --- a/se/sics/mspsim/chip/M25P80.java +++ b/se/sics/mspsim/chip/M25P80.java @@ -44,7 +44,7 @@ import se.sics.mspsim.core.*; import se.sics.mspsim.util.Utils; -public abstract class M25P80 extends Chip implements USARTListener, PortListener, Memory { +public class M25P80 extends ExternalFlash implements USARTListener, PortListener, Memory { public static final int WRITE_STATUS = 0x01; public static final int PAGE_PROGRAM = 0x02; @@ -93,6 +93,10 @@ public void execute(long t) { writing = false; }}; + protected M25P80(String id, MSP430Core cpu) { + super(id, "External Flash", cpu); + } + public M25P80(MSP430Core cpu) { super("M25P80", "External Flash", cpu); } @@ -271,6 +275,7 @@ public void writeByte(int address, int data) { } } + @Override public int getSize() { return MEMORY_SIZE; } @@ -304,8 +309,7 @@ private void ensureLoaded(int address) { } private void loadMemory(int address, byte[] readMemory) throws IOException { - seek(address & 0xfff00); - readFully(readMemory); + getStorage().read(address & 0xfff00, readMemory); for (int i = 0; i < readMemory.length; i++) { readMemory[i] = (byte) (~readMemory[i] & 0xff); } @@ -372,32 +376,25 @@ private void writeBack(int address, byte[] data) { if (DEBUG) { log("Writing data to disk at $" + Integer.toHexString(address)); } - seek(address & 0xfff00); for (int i = 0; i < data.length; i++) { tmp[i] = (byte) (~data[i] & 0xff); } - write(tmp); + getStorage().write(address & 0xfff00, tmp); } catch (IOException e) { e.printStackTrace(); } } + @Override public int getModeMax() { return 0; } - public abstract void seek(long pos) throws IOException; - public abstract int readFully(byte[] b) throws IOException; - public abstract void write(byte[] b) throws IOException; - - /* by default - there is not configuration to return for m25p80 */ - public int getConfiguration(int param) { - return 0; - } - + @Override public String info() { return " Status: " + getStatus() + " Write Enabled: " + writeEnable - + " Write in Progress: " + writing + '\n' + " Chip Select: " + chipSelect; + + " Write in Progress: " + writing + " Chip Select: " + chipSelect + + "\n " + getStorage().info(); } } // M25P80 diff --git a/se/sics/mspsim/chip/MemoryStorage.java b/se/sics/mspsim/chip/MemoryStorage.java new file mode 100644 index 0000000..752dd36 --- /dev/null +++ b/se/sics/mspsim/chip/MemoryStorage.java @@ -0,0 +1,116 @@ +/** + * Copyright (c) 2012, 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. + * + */ +package se.sics.mspsim.chip; + +import java.io.IOException; +import java.util.Arrays; + +/** + * @author Niclas Finne + */ +public class MemoryStorage implements Storage { + + private byte[] data; + private int maxSize; + + private void ensureCapacity(int size) throws IOException { + if (data == null) { + data = new byte[size]; + } else if (data.length < size) { + data = Arrays.copyOf(data, size); + } + } + + @Override + public int read(long pos, byte[] b) throws IOException { + return read(pos, b, 0, b.length); + } + + @Override + public int read(long storagePos, byte[] buffer, int offset, int len) throws IOException { + if (maxSize > 0 && storagePos + len > maxSize) { + throw new IOException("outside storage"); + } + if (data == null) { + Arrays.fill(buffer, offset, offset + len, (byte)0); + } else { + int pos = (int) storagePos; + if (pos + len > data.length) { + System.arraycopy(data, pos, buffer, offset, data.length - pos); + Arrays.fill(buffer, offset + data.length - pos, offset + len, (byte) 0); + } else { + System.arraycopy(data, pos, buffer, offset, len); + } + } + return len; + } + + @Override + public void write(long storagePos, byte[] buffer) throws IOException { + write(storagePos, buffer, 0, buffer.length); + } + + @Override + public void write(long storagePos, byte[] buffer, int offset, int len) throws IOException { + int pos = (int) storagePos; + if (maxSize > 0 && pos + len > maxSize) { + throw new IOException("outside storage"); + } + ensureCapacity(pos + len); + System.arraycopy(buffer, offset, data, pos, len); + } + + @Override + public long getMaxSize() { + return maxSize; + } + + @Override + public void setMaxSize(long size) { + this.maxSize = (int) size; + if (maxSize > 0 && data != null && data.length > maxSize) { + data = Arrays.copyOf(data, maxSize); + } + } + + @Override + public void close() { + // Nothing to close + } + + @Override + public String info() { + if (maxSize > 0) { + return "MemoryStorage(" + data.length + "/" + maxSize + " bytes)"; + } + return "MemoryStorage(" + data.length + " bytes allocated)"; + } +} diff --git a/se/sics/mspsim/chip/Storage.java b/se/sics/mspsim/chip/Storage.java new file mode 100644 index 0000000..1b684e7 --- /dev/null +++ b/se/sics/mspsim/chip/Storage.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2012, 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. + * + */ +package se.sics.mspsim.chip; + +import java.io.IOException; + +/** + * @author Niclas Finne + */ +public interface Storage { + + public int read(long pos, byte[] buffer) throws IOException; + + public int read(long pos, byte[] buffer, int offset, int len) throws IOException; + + public void write(long pos, byte[] buffer) throws IOException; + + public void write(long pos, byte[] buffer, int offset, int len) throws IOException; + + public long getMaxSize(); + + public void setMaxSize(long size); + + public void close(); + + public String info(); + +} diff --git a/se/sics/mspsim/platform/jcreate/JCreateNode.java b/se/sics/mspsim/platform/jcreate/JCreateNode.java index b3031bb..754e18f 100644 --- a/se/sics/mspsim/platform/jcreate/JCreateNode.java +++ b/se/sics/mspsim/platform/jcreate/JCreateNode.java @@ -41,16 +41,13 @@ package se.sics.mspsim.platform.jcreate; import java.io.IOException; - -import se.sics.mspsim.chip.FileM25P80; +import se.sics.mspsim.chip.FileStorage; import se.sics.mspsim.chip.Leds; import se.sics.mspsim.chip.M25P80; import se.sics.mspsim.chip.MMA7260QT; import se.sics.mspsim.core.ADC12; import se.sics.mspsim.core.ADCInput; import se.sics.mspsim.core.IOPort; -import se.sics.mspsim.core.IOUnit; -import se.sics.mspsim.core.USART; import se.sics.mspsim.core.USARTSource; import se.sics.mspsim.platform.sky.CC2420Node; import se.sics.mspsim.util.ArgumentManager; @@ -134,8 +131,11 @@ public int nextData() { } }); + if (getFlash() == null) { + setFlash(new M25P80(cpu)); + } if (flashFile != null) { - setFlash(new FileM25P80(cpu, flashFile)); + getFlash().setStorage(new FileStorage(flashFile)); } } diff --git a/se/sics/mspsim/platform/sentillausb/SentillaUSBNode.java b/se/sics/mspsim/platform/sentillausb/SentillaUSBNode.java index 3a47929..b9c3324 100644 --- a/se/sics/mspsim/platform/sentillausb/SentillaUSBNode.java +++ b/se/sics/mspsim/platform/sentillausb/SentillaUSBNode.java @@ -41,12 +41,10 @@ package se.sics.mspsim.platform.sentillausb; import java.io.IOException; - -import se.sics.mspsim.chip.FileM25P80; +import se.sics.mspsim.chip.FileStorage; import se.sics.mspsim.chip.Leds; import se.sics.mspsim.chip.M25P80; import se.sics.mspsim.core.IOPort; -import se.sics.mspsim.core.USART; import se.sics.mspsim.core.USARTSource; import se.sics.mspsim.platform.sky.CC2420Node; import se.sics.mspsim.util.ArgumentManager; @@ -110,8 +108,11 @@ protected void flashWrite(IOPort source, int data) { public void setupNodePorts() { super.setupNodePorts(); leds = new Leds(cpu, LEDS); + if (getFlash() == null) { + setFlash(new M25P80(cpu)); + } if (flashFile != null) { - setFlash(new FileM25P80(cpu, flashFile)); + getFlash().setStorage(new FileStorage(flashFile)); } } diff --git a/se/sics/mspsim/platform/sky/CC2420Node.java b/se/sics/mspsim/platform/sky/CC2420Node.java index 7914997..7d46e16 100644 --- a/se/sics/mspsim/platform/sky/CC2420Node.java +++ b/se/sics/mspsim/platform/sky/CC2420Node.java @@ -4,7 +4,6 @@ import se.sics.mspsim.chip.PacketListener; import se.sics.mspsim.config.MSP430f1611Config; 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; diff --git a/se/sics/mspsim/platform/sky/SkyNode.java b/se/sics/mspsim/platform/sky/SkyNode.java index 6ef74ce..998e3f5 100644 --- a/se/sics/mspsim/platform/sky/SkyNode.java +++ b/se/sics/mspsim/platform/sky/SkyNode.java @@ -41,7 +41,7 @@ package se.sics.mspsim.platform.sky; import java.io.IOException; -import se.sics.mspsim.chip.FileM25P80; +import se.sics.mspsim.chip.FileStorage; import se.sics.mspsim.chip.M25P80; import se.sics.mspsim.core.IOPort; import se.sics.mspsim.core.USARTSource; @@ -88,8 +88,11 @@ protected void flashWrite(IOPort source, int data) { public void setupNodePorts() { super.setupNodePorts(); + if (getFlash() == null) { + setFlash(new M25P80(cpu)); + } if (flashFile != null) { - setFlash(new FileM25P80(cpu, flashFile)); + getFlash().setStorage(new FileStorage(flashFile)); } } diff --git a/se/sics/mspsim/platform/sky/TelosNode.java b/se/sics/mspsim/platform/sky/TelosNode.java index 212a09f..1d02286 100644 --- a/se/sics/mspsim/platform/sky/TelosNode.java +++ b/se/sics/mspsim/platform/sky/TelosNode.java @@ -42,7 +42,7 @@ package se.sics.mspsim.platform.sky; import java.io.IOException; import se.sics.mspsim.chip.AT45DB; -import se.sics.mspsim.chip.FileAT45DB; +import se.sics.mspsim.chip.FileStorage; import se.sics.mspsim.core.IOPort; import se.sics.mspsim.core.USARTSource; import se.sics.mspsim.util.ArgumentManager; @@ -90,8 +90,11 @@ public void dataReceived(USARTSource source, int data) { public void setupNodePorts() { super.setupNodePorts(); + if (getFlash() == null) { + setFlash(new AT45DB(cpu)); + } if (flashFile != null) { - flash = new FileAT45DB(cpu, flashFile); + getFlash().setStorage(new FileStorage(flashFile)); } } diff --git a/se/sics/mspsim/platform/z1/Z1Node.java b/se/sics/mspsim/platform/z1/Z1Node.java index 3931010..8c938ea 100644 --- a/se/sics/mspsim/platform/z1/Z1Node.java +++ b/se/sics/mspsim/platform/z1/Z1Node.java @@ -3,7 +3,7 @@ import java.io.IOException; import se.sics.mspsim.chip.Button; import se.sics.mspsim.chip.CC2420; -import se.sics.mspsim.chip.FileM25P80; +import se.sics.mspsim.chip.FileStorage; import se.sics.mspsim.chip.Leds; import se.sics.mspsim.chip.M25P80; import se.sics.mspsim.config.MSP430f2617Config; @@ -89,6 +89,9 @@ public Button getButton() { } public M25P80 getFlash() { + // TODO Replace with M25P16. + // The Z1 platform has a M25P16 chip with 2MB compared to the M25P80 + // with 1MB but the chips are compatible. return flash; } @@ -142,10 +145,6 @@ public void portWrite(IOPort source, int data) { } private void setupNodePorts() { - if (flashFile != null) { - setFlash(new FileM25P80(cpu, flashFile)); - } - port1 = cpu.getIOUnit(IOPort.class, "P1"); // port1.addPortListener(this); port2 = cpu.getIOUnit(IOPort.class, "P2"); @@ -174,6 +173,12 @@ private void setupNodePorts() { leds = new Leds(cpu, LEDS); button = new Button("Button", cpu, port2, BUTTON_PIN, true); + if (getFlash() == null) { + setFlash(new M25P80(cpu)); + } + if (flashFile != null) { + getFlash().setStorage(new FileStorage(flashFile)); + } } public void setupNode() { @@ -190,7 +195,7 @@ public void setupNode() { fileName = fileName + ".flash"; } } - if (DEBUG) System.out.println("Using flash file: " + (fileName == null ? "no file" : fileName)); + if (DEBUG) log("Using flash file: " + (fileName == null ? "no file" : fileName)); this.flashFile = fileName; commit bf6233669d8193970ec75225a2ee7e81133fa616 Author: Niclas Finne <nf...@si...> Date: Wed May 30 20:31:22 2012 +0200 Added base class for accelerometers diff --git a/se/sics/mspsim/chip/Accelerometer.java b/se/sics/mspsim/chip/Accelerometer.java new file mode 100644 index 0000000..c567448 --- /dev/null +++ b/se/sics/mspsim/chip/Accelerometer.java @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2012, 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. + * + */ +package se.sics.mspsim.chip; + +import se.sics.mspsim.core.Chip; +import se.sics.mspsim.core.MSP430Core; + +/** + * @author Niclas Finne + * + */ +public abstract class Accelerometer extends Chip { + + protected double x, y, z; + + protected Accelerometer(String id, MSP430Core cpu) { + super(id, "Accelerometer", cpu); + } + + protected Accelerometer(String id, String name, MSP430Core cpu) { + super(id, name, cpu); + } + + public void setX(double x) { + this.x = x; + } + + public double getX() { + return x; + } + + public void setY(double y) { + this.y = y; + } + + public double getY() { + return y; + } + + public void setZ(double z) { + this.z = z; + } + + public double getZ() { + return z; + } + + public void setPosition(double x, double y, double z) { + setX(x); + setY(y); + setZ(z); + } + +} diff --git a/se/sics/mspsim/chip/MMA7260QT.java b/se/sics/mspsim/chip/MMA7260QT.java index 063a607..cc0e4b3 100644 --- a/se/sics/mspsim/chip/MMA7260QT.java +++ b/se/sics/mspsim/chip/MMA7260QT.java @@ -39,13 +39,12 @@ */ package se.sics.mspsim.chip; -import se.sics.mspsim.core.Chip; import se.sics.mspsim.core.MSP430Core; /** * MMA7260QT - 1.5g-6g Three Axis Low-g Micromachined Accelerometer */ -public class MMA7260QT extends Chip { +public class MMA7260QT extends Accelerometer { public static final int MODE_SLEEP = 0x00; public static final int MODE_ACTIVE = 0x01; @@ -56,52 +55,36 @@ 1.5f, 2, 4, 6 }; - private int x = 4095, y = 2715, z = 2715; private int gSelect = 0; public MMA7260QT(MSP430Core cpu) { - super("MMA7260QT", "Accelerometer", cpu); + super("MMA7260QT", cpu); setModeNames(MODE_NAMES); setMode(MODE_SLEEP); - } - - public int getADCX() { - int v = getX(); - return v > 4095 ? 4095 : v; - } - - public int getADCY() { - int v = getY(); - return v > 4095 ? 4095 : v; - } - public int getADCZ() { - int v = getZ(); - return v > 4095 ? 4095 : v; - } - - public void setX(int x) { - this.x = x; + // Set initial state: x=4094, y=2715, z=2715 + setPosition(1.0, -0.0156, -0.0156); } - public int getX() { - return x; + private int convertToADC(double x) { + if (x > 1.0) { + x = 1.0; + } else if (x < -1.0) { + x = -1.0; } - - public void setY(int y) { - this.y = y; + return 2047 + (int) (x * 2047); } - public int getY() { - return y; + public int getADCX() { + return convertToADC(getX()); } - public void setZ(int z) { - this.z = z; + public int getADCY() { + return convertToADC(getY()); } - public int getZ() { - return z; + public int getADCZ() { + return convertToADC(getZ()); } public int getSensitivity() { @@ -116,21 +99,26 @@ public void setSensitivity(int gSelect) { this.gSelect = gSelect & 0x03; } + @Override public void setMode(int mode) { super.setMode(mode); } + @Override public int getModeMax() { return MODE_NAMES.length; } + @Override public String info() { return "Mode: " + getModeName(getMode()) + " Sensitivity: " + getSensitivityAsString() - + " [x=" + getADCX() + ",y=" + getADCY() + ",z=" + getADCZ() + ']'; + + String.format(" [x=%.2f (%d),y=%.2f (%d),z=%.2f (%d)]", + getX(), getADCX(), getY(), getADCY(), getZ(), getADCZ()); } /* currently just return the gSelect as configuration */ + @Override public int getConfiguration(int parameter) { return gSelect; } commit d33bd84726715ecdfe60fea0979ec2c89e364d6c Author: Niclas Finne <nf...@si...> Date: Wed May 30 20:08:11 2012 +0200 Updated image for the wismote platform. Picture by Joel Hoglund. diff --git a/images/wismote.jpg b/images/wismote.jpg new file mode 100644 index 0000000..360c14e Binary files /dev/null and b/images/wismote.jpg differ diff --git a/images/wismote.png b/images/wismote.png deleted file mode 100644 index 5e13bb8..0000000 Binary files a/images/wismote.png and /dev/null differ diff --git a/se/sics/mspsim/platform/wismote/WismoteGui.java b/se/sics/mspsim/platform/wismote/WismoteGui.java index 6f1f7c6..4d57ff2 100755 --- a/se/sics/mspsim/platform/wismote/WismoteGui.java +++ b/se/sics/mspsim/platform/wismote/WismoteGui.java @@ -73,7 +73,7 @@ public void stateChanged(Object source, int oldState, int newState) { private boolean resetDown = false; public WismoteGui(WismoteNode node) { - super("WismoteGui", "images/wismote.png"); + super("WismoteGui", "images/wismote.jpg"); this.node = node; } ----------------------------------------------------------------------- Summary of changes: images/wismote.jpg | Bin 0 -> 60885 bytes images/wismote.png | Bin 199821 -> 0 bytes se/sics/mspsim/chip/AT45DB.java | 22 +-- .../{ChannelListener.java => Accelerometer.java} | 61 ++++-- .../{ChannelListener.java => ExternalFlash.java} | 45 +++-- se/sics/mspsim/chip/FileAT45DB.java | 146 ------------- se/sics/mspsim/chip/FileM25P80.java | 180 --------------- se/sics/mspsim/chip/FileStorage.java | 229 ++++++++++++++++++++ se/sics/mspsim/chip/{RFSource.java => M25P16.java} | 28 ++- se/sics/mspsim/chip/M25P80.java | 29 ++-- se/sics/mspsim/chip/MMA7260QT.java | 58 ++--- se/sics/mspsim/chip/MemoryStorage.java | 116 ++++++++++ .../MSP430f149Config.java => chip/Storage.java} | 32 ++- se/sics/mspsim/platform/esb/ESBNode.java | 5 + se/sics/mspsim/platform/jcreate/JCreateNode.java | 10 +- .../platform/sentillausb/SentillaUSBNode.java | 9 +- se/sics/mspsim/platform/sky/CC2420Node.java | 6 +- se/sics/mspsim/platform/sky/SkyNode.java | 7 +- se/sics/mspsim/platform/sky/TelosNode.java | 7 +- se/sics/mspsim/platform/ti/Exp5438Node.java | 6 + se/sics/mspsim/platform/tyndall/TyndallNode.java | 5 + se/sics/mspsim/platform/wismote/WismoteGui.java | 2 +- se/sics/mspsim/platform/wismote/WismoteNode.java | 7 +- se/sics/mspsim/platform/z1/Z1Node.java | 25 ++- 24 files changed, 568 insertions(+), 467 deletions(-) create mode 100644 images/wismote.jpg delete mode 100644 images/wismote.png copy se/sics/mspsim/chip/{ChannelListener.java => Accelerometer.java} (65%) copy se/sics/mspsim/chip/{ChannelListener.java => ExternalFlash.java} (67%) delete mode 100644 se/sics/mspsim/chip/FileAT45DB.java delete mode 100644 se/sics/mspsim/chip/FileM25P80.java create mode 100644 se/sics/mspsim/chip/FileStorage.java copy se/sics/mspsim/chip/{RFSource.java => M25P16.java} (80%) create mode 100644 se/sics/mspsim/chip/MemoryStorage.java copy se/sics/mspsim/{config/MSP430f149Config.java => chip/Storage.java} (74%) hooks/post-receive -- mspsim |
From: Niclas F. <ni...@us...> - 2012-05-29 13:48:08
|
The branch "master" has been updated via f3e9c856e83243f580f1045b9f38424c9e265688 (commit) via 4e78dae2614a010ceb2954b01d6d9121d91321e9 (commit) from 0480ed94cbfda912bb6333e2b829247dc073e8a4 (commit) Changed paths: M se/sics/mspsim/core/Timer.java - Log ----------------------------------------------------------------- commit f3e9c856e83243f580f1045b9f38424c9e265688 Author: Niclas Finne <nf...@si...> Date: Tue May 29 15:48:03 2012 +0200 Bug fix: overflow interrupt vector was not set in Timer. Patch by Olaf Landsiedel. diff --git a/se/sics/mspsim/core/Timer.java b/se/sics/mspsim/core/Timer.java index 4b53b70..cb8bad0 100644 --- a/se/sics/mspsim/core/Timer.java +++ b/se/sics/mspsim/core/Timer.java @@ -592,6 +592,7 @@ private void resetTIV(long cycles) { } /* if the timer overflow interrupt is triggering - lowest priority => signal! */ if (lastTIV == 0 && interruptEnable & interruptPending) { + lastTIV = timerOverflow; cpu.flagInterrupt(ccr1Vector, this, true); } } commit 4e78dae2614a010ceb2954b01d6d9121d91321e9 Author: Niclas Finne <nf...@si...> Date: Tue May 29 15:43:12 2012 +0200 minor cleanup diff --git a/se/sics/mspsim/core/Timer.java b/se/sics/mspsim/core/Timer.java index 6e195ef..4b53b70 100644 --- a/se/sics/mspsim/core/Timer.java +++ b/se/sics/mspsim/core/Timer.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007-2010, Swedish Institute of Computer Science. + * Copyright (c) 2007-2012, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,16 +27,12 @@ * * This file is part of MSPSim. * - * $Id$ - * * ----------------------------------------------------------------- * * Timer * * Author : Joakim Eriksson * Created : Sun Oct 21 22:00:00 2007 - * Updated : $Date$ - * $Revision$ */ package se.sics.mspsim.core; @@ -71,7 +67,6 @@ */ public class Timer extends IOUnit { - public static final boolean DEBUG = false; public static final int TBIV = 0x011e; public static final int TAIV = 0x012e; @@ -201,6 +196,7 @@ // Support variables Max 7 compare regs for now (timer b) private final int noCompare; + private final CCR ccr[]; /* this is class represents a capture and compare register */ private class CCR extends TimeEvent { @@ -219,8 +215,8 @@ boolean sync; int outMode; - int interruptVector; - int index; + final int interruptVector; + final int index; public CCR(long time, String name, int vector, int index) { super(time, name); @@ -387,8 +383,6 @@ public String info() { } - private CCR ccr[]; - private TimeEvent counterTrigger = new TimeEvent(0, "Timer Counter Trigger") { public void execute(long t) { interruptPending = true; @@ -441,9 +435,6 @@ public Timer(MSP430Core cpu, int[] memory, MSP430Config.TimerConfig config) { } reset(0); - - if (DEBUG) setLogStream(System.out); - } public void reset(int type) { @@ -481,7 +472,7 @@ public void reset(int type) { // Should handle read of byte also (currently ignores that...) public int read(int address, boolean word, long cycles) { - if (DEBUG) System.out.println(getName() + " read from: $" + Utils.hex(address, 4)); +// if (DEBUG) log("read from: $" + Utils.hex(address, 4)); if (address == tiv) { // should clear registers for cause of interrupt (highest value)? @@ -620,7 +611,7 @@ public void write(int address, int data, boolean word, long cycles) { int iAddress = address - offset; - if (DEBUG) System.out.println(getName() + " write to: " + Utils.hex16(address) + + if (DEBUG) log("write to: $" + Utils.hex(address, 4) + " => " + iAddress + " = " + data); @@ -965,7 +956,7 @@ public int getModeMax() { return 0; } - public String getName(int address) { + private String getName(int address) { int reg = address - offset; if (reg == 0) return "TCTL"; if (reg < 0x10) return "TCTL" + (reg - 2) / 2; @@ -974,14 +965,15 @@ public String getName(int address) { return " UNDEF(" + Utils.hex(address, 4) + ")"; } + @Override public String info() { StringBuilder sb = new StringBuilder(); sb.append(" Source: " + getSourceName(clockSource) + " Speed: " + clockSpeed - + " Hz inDiv: " + inputDivider + " Multiplyer: " + cyclesMultiplicator + '\n' + + " Hz inDiv: " + inputDivider + " Multiplier: " + cyclesMultiplicator + '\n' + " Mode: " + modeNames[mode] + " IEn: " + interruptEnable + " IFG: " + interruptPending + " TR: " + updateCounter(cpu.cycles) + '\n'); for (CCR reg : ccr) { - if (reg != null) sb.append(" ").append(reg.info()).append('\n'); + sb.append(" ").append(reg.info()).append('\n'); } return sb.toString(); } ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/core/Timer.java | 33 +++++++++++++-------------------- 1 files changed, 13 insertions(+), 20 deletions(-) hooks/post-receive -- mspsim |
From: Niclas F. <ni...@us...> - 2012-05-29 13:14:12
|
The branch "master" has been updated via 0480ed94cbfda912bb6333e2b829247dc073e8a4 (commit) via 4a71c1a02120724a87df4ed331075b66498d83f3 (commit) via 2426d82ea1032e64e233eaf1581f37c3a14b2b2f (commit) via 202ddb5dffec37fdbd0b742ed2068c46ee42bf69 (commit) from 52996923022277b395f9470b5928d67febe3b193 (commit) Changed paths: M build.xml M firmware/z1/blink.z1 M se/sics/mspsim/cli/MiscCommands.java M se/sics/mspsim/core/MSP430.java - Log ----------------------------------------------------------------- commit 0480ed94cbfda912bb6333e2b829247dc073e8a4 Author: Niclas Finne <nf...@si...> Date: Tue May 29 15:13:04 2012 +0200 Added option to the timestamp command to print CPU cycles instead of milliseconds diff --git a/se/sics/mspsim/cli/MiscCommands.java b/se/sics/mspsim/cli/MiscCommands.java index 6940ad0..7a90e6d 100644 --- a/se/sics/mspsim/cli/MiscCommands.java +++ b/se/sics/mspsim/cli/MiscCommands.java @@ -97,9 +97,10 @@ public void lineRead(String line) { } }); - handler.registerCommand("timestamp", new BasicLineCommand("print lines with timestamp prefixed", "") { + handler.registerCommand("timestamp", new BasicLineCommand("print lines prefixed with timestamp as milliseconds or CPU cycles", "[-c]") { private PrintStream out; private MSP430 cpu; + boolean useCycles; long startTime; public int executeCommand(CommandContext context) { @@ -109,12 +110,24 @@ public int executeCommand(CommandContext context) { return 1; } out = context.out; + if (context.getArgumentCount() > 0) { + if ("-c".equals(context.getArgument(0))) { + useCycles = true; + } else { + context.err.println("unknown argument: " + context.getArgument(0)); + return 1; + } + } startTime = System.currentTimeMillis() - (long)cpu.getTimeMillis(); return 0; } public void lineRead(String line) { + if (useCycles) { + out.println(Long.toString(cpu.cycles) + ' ' + line); + } else { out.println(Long.toString(startTime + (long)cpu.getTimeMillis()) + ' ' + line); } + } }); handler.registerCommand("speed", new BasicCommand("set the speed factor for the CPU", "[factor]") { commit 4a71c1a02120724a87df4ed331075b66498d83f3 Author: Niclas Finne <nf...@si...> Date: Tue May 29 15:12:21 2012 +0200 Bug fix in the execution rate calculation - did not respect current CPU frequency diff --git a/se/sics/mspsim/cli/MiscCommands.java b/se/sics/mspsim/cli/MiscCommands.java index 9ab34e3..6940ad0 100644 --- a/se/sics/mspsim/cli/MiscCommands.java +++ b/se/sics/mspsim/cli/MiscCommands.java @@ -126,18 +126,16 @@ public int executeCommand(CommandContext context) { } else if (context.getArgumentCount() == 0) { /* No speed specified. Simply show current speed. */ } else { - double d = context.getArgumentAsDouble(0); - if (d > 0.0) { - long rate = (long) (25000 * d); - cpu.setSleepRate(rate); + double rate = context.getArgumentAsDouble(0); + if (rate > 0.0) { + cpu.setExecutionRate(rate); } else { context.err.println("Speed factor must be larger than zero."); return 1; } } - long rate = cpu.getSleepRate(); - double d = rate / 25000.0; - context.out.println("Speed factor is set to " + (((int)(d * 100 + 0.5)) / 100.0)); + double rate = cpu.getExecutionRate(); + context.out.printf("Speed factor is set to %.2f\n", rate); return 0; } }); diff --git a/se/sics/mspsim/core/MSP430.java b/se/sics/mspsim/core/MSP430.java index 9e2e461..498b817 100644 --- a/se/sics/mspsim/core/MSP430.java +++ b/se/sics/mspsim/core/MSP430.java @@ -52,7 +52,7 @@ private boolean debug = false; private boolean running = false; private boolean isBreaking = false; - private long sleepRate = 50000; + private double rate = 2.0; // Debug time - measure cycles private long lastCycles = 0; @@ -131,12 +131,12 @@ private void run() throws EmulationException { /* Just a test to see if it gets down to a reasonable speed */ if (cycles > nextSleep) { try { - Thread.sleep(10); + Thread.sleep(100); } catch (Exception e) { } // Frequency = 100 * cycles ratio // Ratio = Frq / 100 - nextSleep = cycles + sleepRate; + nextSleep = cycles + (long)(rate * dcoFrq / 10); } // if ((instruction & 0xff80) == CALL) { @@ -428,12 +428,12 @@ public boolean isRunning() { return running; } - public long getSleepRate() { - return sleepRate; + public double getExecutionRate() { + return rate; } - public void setSleepRate(long rate) { - sleepRate = rate; + public void setExecutionRate(double rate) { + this.rate = rate; } public synchronized void addSimEventListener(SimEventListener l) { commit 2426d82ea1032e64e233eaf1581f37c3a14b2b2f Author: Niclas Finne <nf...@si...> Date: Tue May 29 13:22:32 2012 +0200 Added run rule for z1 platform diff --git a/build.xml b/build.xml index 54d4501..a81ab06 100644 --- a/build.xml +++ b/build.xml @@ -81,6 +81,13 @@ </java> </target> + <target name="runz1" depends="jar" description="run MSPSim with platform Zolertia Z1"> + <property name="FIRMWAREFILE" value="firmware/z1/blink.z1"/> + <java fork="true" classpath="${jarfile}" classname="se.sics.mspsim.platform.z1.Z1Node"> + <arg value="${FIRMWAREFILE}"/> + </java> + </target> + <target name="run" depends="runsky"/> <target name="cputest" depends="jar" description="run MSPSim CPU test"> commit 202ddb5dffec37fdbd0b742ed2068c46ee42bf69 Author: Niclas Finne <nf...@si...> Date: Tue May 29 13:22:15 2012 +0200 Updated test firmware for Z1 platform diff --git a/firmware/z1/blink.z1 b/firmware/z1/blink.z1 index ef86e5f..1e07f4c 100644 Binary files a/firmware/z1/blink.z1 and b/firmware/z1/blink.z1 differ ----------------------------------------------------------------------- Summary of changes: build.xml | 7 +++++++ firmware/z1/blink.z1 | Bin 465002 -> 193828 bytes se/sics/mspsim/cli/MiscCommands.java | 29 ++++++++++++++++++++--------- se/sics/mspsim/core/MSP430.java | 14 +++++++------- 4 files changed, 34 insertions(+), 16 deletions(-) hooks/post-receive -- mspsim |
From: Niclas F. <ni...@us...> - 2012-05-29 11:06:23
|
The branch "master" has been updated via 52996923022277b395f9470b5928d67febe3b193 (commit) via 5491550e1efc36602f1e97b40efaf8fc9fbd1deb (commit) via 0f1d0ff978fb464db07e5871cacabd1ca53002e0 (commit) from b207699337cef22cb20f04cb611b2df30af7d75d (commit) Changed paths: A images/z1.jpg M se/sics/mspsim/config/MSP430f2617Config.java M se/sics/mspsim/config/MSP430f5437Config.java M se/sics/mspsim/core/IOPort.java M se/sics/mspsim/core/MSP430Config.java M se/sics/mspsim/core/MSP430Core.java M se/sics/mspsim/core/Multiplier32.java C065 se/sics/mspsim/platform/wismote/WismoteGui.java se/sics/mspsim/platform/z1/Z1Gui.java M se/sics/mspsim/platform/z1/Z1Node.java - Log ----------------------------------------------------------------- commit 52996923022277b395f9470b5928d67febe3b193 Author: Niclas Finne <nf...@si...> Date: Tue May 29 13:06:12 2012 +0200 Added node gui for the Zolertia Z1 platform diff --git a/se/sics/mspsim/platform/z1/Z1Gui.java b/se/sics/mspsim/platform/z1/Z1Gui.java new file mode 100644 index 0000000..4d68825 --- /dev/null +++ b/se/sics/mspsim/platform/z1/Z1Gui.java @@ -0,0 +1,160 @@ +/** + * Copyright (c) 2012, 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. + */ + +package se.sics.mspsim.platform.z1; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import se.sics.mspsim.core.StateChangeListener; +import se.sics.mspsim.platform.AbstractNodeGUI; + +public class Z1Gui extends AbstractNodeGUI { + + private static final long serialVersionUID = 7016480889484768582L; + + private static final int GREEN_Y = 88; + private static final int BLUE_Y = 99; + private static final int RED_Y = 77; + private static final int LED_X = 184; + private static final int LED_WIDTH = 11; + private static final int LED_HEIGHT = 6; + + private static final Color BLUE_TRANS = new Color(0x80, 0x80, 0xff, 0xa0); + private static final Color GREEN_TRANS = new Color(0x40, 0xf0, 0x40, 0xa0); + private static final Color RED_TRANS = new Color(0xf0, 0x40, 0x40, 0xa0); + + private static final Color BLUE_C = new Color(0xffa0a0ff); + private static final Color GREEN_C = new Color(0xff60ff60); + private static final Color RED_C = new Color(0xffff8000); + + private static final Color BUTTON_C = new Color(0x60ffffff); + + private static final Rectangle LEDS_BOUNDS = + new Rectangle(LED_X - 2, RED_Y - 2, LED_WIDTH + 1, BLUE_Y - RED_Y + LED_HEIGHT + 1); + + private boolean buttonDown = false; + private boolean resetDown = false; + + private final Z1Node node; + private final StateChangeListener ledsListener = new StateChangeListener() { + public void stateChanged(Object source, int oldState, int newState) { + repaint(LEDS_BOUNDS); + } + }; + + public Z1Gui(Z1Node node) { + super("Z1Gui", "images/z1.jpg"); + this.node = node; + } + + protected void startGUI() { + MouseAdapter mouseHandler = new MouseAdapter() { + + // For the button sensor and reset button on the Sky nodes. + public void mousePressed(MouseEvent e) { + int x = e.getX(); + int y = e.getY(); + if (x > 53 && x < 66) { + if (y > 231 && y < 246) { + buttonDown = true; + Z1Gui.this.node.getButton().setPressed(true); + repaint(53, 231, 14, 16); + } else if (y > 260 && y < 273) { + resetDown = true; + repaint(53, 260, 14, 13); + } + } + } + + public void mouseReleased(MouseEvent e) { + if (buttonDown) { + buttonDown = false; + Z1Gui.this.node.getButton().setPressed(false); + repaint(53, 231, 14, 16); + + } else if (resetDown) { + int x = e.getX(); + int y = e.getY(); + resetDown = false; + if (x > 53 && x < 66 && y > 260 && y < 273) { + Z1Gui.this.node.getCPU().reset(); + } + repaint(53, 260, 14, 13); + } + } + }; + + this.addMouseListener(mouseHandler); + node.getLeds().addStateChangeListener(ledsListener); + } + + protected void stopGUI() { + node.getLeds().removeStateChangeListener(ledsListener); + } + + protected void paintComponent(Graphics g) { + Color old = g.getColor(); + + super.paintComponent(g); + + // Display all active leds + if (node.redLed) { + g.setColor(RED_TRANS); + g.fillOval(LED_X - 2, RED_Y - 1, LED_WIDTH, LED_HEIGHT); + g.setColor(RED_C); + g.fillOval(LED_X, RED_Y, LED_WIDTH - 5, LED_HEIGHT - 2); + } + if (node.greenLed) { + g.setColor(GREEN_TRANS); + g.fillOval(LED_X - 2, GREEN_Y - 1, LED_WIDTH, LED_HEIGHT); + g.setColor(GREEN_C); + g.fillOval(LED_X, GREEN_Y, LED_WIDTH - 5, LED_HEIGHT - 2); + } + if (node.blueLed) { + g.setColor(BLUE_TRANS); + g.fillOval(LED_X - 2, BLUE_Y - 1, LED_WIDTH, LED_HEIGHT); + g.setColor(BLUE_C); + g.fillOval(LED_X, BLUE_Y, LED_WIDTH - 5, LED_HEIGHT - 2); + } + if (buttonDown) { + g.setColor(BUTTON_C); + g.fillOval(55, 234, 9, 9); + } + if (resetDown) { + g.setColor(BUTTON_C); + g.fillOval(55, 262, 9, 9); + } + g.setColor(old); + } + +} diff --git a/se/sics/mspsim/platform/z1/Z1Node.java b/se/sics/mspsim/platform/z1/Z1Node.java index c06f197..3931010 100644 --- a/se/sics/mspsim/platform/z1/Z1Node.java +++ b/se/sics/mspsim/platform/z1/Z1Node.java @@ -1,9 +1,10 @@ package se.sics.mspsim.platform.z1; import java.io.IOException; - +import se.sics.mspsim.chip.Button; import se.sics.mspsim.chip.CC2420; import se.sics.mspsim.chip.FileM25P80; +import se.sics.mspsim.chip.Leds; import se.sics.mspsim.chip.M25P80; import se.sics.mspsim.config.MSP430f2617Config; import se.sics.mspsim.core.EmulationException; @@ -19,6 +20,15 @@ public class Z1Node extends GenericNode implements PortListener, USARTListener { + public static final int MODE_LEDS_OFF = 0; + public static final int MODE_LEDS_1 = 1; + public static final int MODE_LEDS_2 = 2; + public static final int MODE_LEDS_3 = 3; + public static final int MODE_MAX = MODE_LEDS_3; + + // Port 2.5 - Button + public static final int BUTTON_PIN = 5; + /* P1.2 - Input: FIFOP from CC2420 */ /* P1.3 - Input: FIFO from CC2420 */ /* P1.4 - Input: CCA from CC2420 */ @@ -33,23 +43,49 @@ public static final int CC2420_VREG = (1 << 5); public static final int CC2420_CHIP_SELECT = 0x01; + public static final int TMP102_PWR_PIN = 0; + public static final int TMP102_PWR = 1 << TMP102_PWR_PIN; - IOPort port1; - IOPort port3; - IOPort port4; - IOPort port5; + public static final int I2C_DATA_PIN = 1; + public static final int I2C_DATA = 1 << I2C_DATA_PIN; + public static final int I2C_CLK_PIN = 2; + public static final int I2C_CLK = 1 << I2C_CLK_PIN; + + private IOPort port1; + private IOPort port2; + private IOPort port3; + private IOPort port4; + private IOPort port5; public static final int LEDS_CONF_RED = 0x10; public static final int LEDS_CONF_GREEN = 0x40; - public static final int LEDS_CONF_YELLOW = 0x20; + public static final int LEDS_CONF_BLUE = 0x20; + private static final int[] LEDS = { 0xff2020, 0x40ff40, 0x4040ff }; + + boolean redLed; + boolean blueLed; + boolean greenLed; + private Leds leds; + private Button button; + private Z1Gui gui; + + private CC2420 radio; +// private TMP102 tmp102; private M25P80 flash; private String flashFile; - public CC2420 radio; - public Z1Node() { super("Z1", new MSP430f2617Config()); + setMode(MODE_LEDS_OFF); + } + + public Leds getLeds() { + return leds; + } + + public Button getButton() { + return button; } public M25P80 getFlash() { @@ -71,20 +107,37 @@ public void dataReceived(USARTSource source, int data) { } } + private int lastPort5 = 0; public void portWrite(IOPort source, int data) { - if (source == port5) { - System.out.println("LEDS GREEN = " + ((data & LEDS_CONF_GREEN) > 0)); - System.out.println("LEDS RED = " + ((data & LEDS_CONF_RED) > 0)); - System.out.println("LEDS YELLOW = " + ((data & LEDS_CONF_YELLOW) > 0)); - } - if (source == port3) { + switch (source.getPort()) { + case 3: // Chip select = active low... radio.setChipSelect((data & CC2420_CHIP_SELECT) == 0); - } - if (source == port4) { + break; + case 4: radio.setVRegOn((data & CC2420_VREG) != 0); //radio.portWrite(source, data); flash.portWrite(source, data); + break; + case 5: { + if ((data & (LEDS_CONF_RED|LEDS_CONF_BLUE|LEDS_CONF_GREEN)) != + (lastPort5 & (LEDS_CONF_RED|LEDS_CONF_BLUE|LEDS_CONF_GREEN))) { + redLed = (data & LEDS_CONF_RED) == 0; + blueLed = (data & LEDS_CONF_BLUE) == 0; + greenLed = (data & LEDS_CONF_GREEN) == 0; + leds.setLeds((redLed ? 1 : 0) + (greenLed ? 2 : 0) + (blueLed ? 4 : 0)); + int newMode = (redLed ? 1 : 0) + (greenLed ? 1 : 0) + (blueLed ? 1 : 0); + setMode(newMode); + } + if ((data & TMP102_PWR) != (lastPort5 & TMP102_PWR)) { +// tmp102.setPowerPin((data & TMP102_PWR) != 0); + } + if ((data & (I2C_CLK | I2C_DATA)) != (lastPort5 & (I2C_CLK|I2C_DATA))) { +// tmp102.setI2CPins((data & I2C_CLK) != 0, (data & I2C_DATA) != 0); + } + lastPort5 = data; + break; + } } } @@ -94,7 +147,9 @@ private void setupNodePorts() { } port1 = cpu.getIOUnit(IOPort.class, "P1"); - port1.addPortListener(this); +// port1.addPortListener(this); + port2 = cpu.getIOUnit(IOPort.class, "P2"); +// port2.addPortListener(this); port3 = cpu.getIOUnit(IOPort.class, "P3"); port3.addPortListener(this); port4 = cpu.getIOUnit(IOPort.class, "P4"); @@ -102,18 +157,23 @@ private void setupNodePorts() { port5 = cpu.getIOUnit(IOPort.class, "P5"); port5.addPortListener(this); - IOUnit usart0 = cpu.getIOUnit("USCI B0"); - if (usart0 instanceof USCI) { +// tmp102 = new TMP102(cpu); + + USCI usart0 = cpu.getIOUnit(USCI.class, "USCI B0"); + if (usart0 != null) { radio = new CC2420(cpu); radio.setCCAPort(port1, CC2420_CCA); radio.setFIFOPPort(port1, CC2420_FIFOP); radio.setFIFOPort(port1, CC2420_FIFO); - ((USARTSource) usart0).addUSARTListener(this); + usart0.addUSARTListener(this); radio.setSFDPort(port4, CC2420_SFD); } else { throw new EmulationException("Could not setup mote - missing USCI B0"); } + + leds = new Leds(cpu, LEDS); + button = new Button("Button", cpu, port2, BUTTON_PIN, true); } public void setupNode() { @@ -151,11 +211,14 @@ public void setupNode() { } public void setupGUI() { - System.out.println("No gui for Z1 yet..."); + if (gui == null) { + gui = new Z1Gui(this); + registry.registerComponent("nodegui", gui); + } } public int getModeMax() { - return 0; + return MODE_MAX; } public static void main(String[] args) throws IOException { commit 5491550e1efc36602f1e97b40efaf8fc9fbd1deb Author: Niclas Finne <nf...@si...> Date: Tue May 29 13:00:17 2012 +0200 Zolertia Z1 platform image. Picture by Joel Hoglund. diff --git a/images/z1.jpg b/images/z1.jpg new file mode 100644 index 0000000..9a16bf6 Binary files /dev/null and b/images/z1.jpg differ commit 0f1d0ff978fb464db07e5871cacabd1ca53002e0 Author: Niclas Finne <nf...@si...> Date: Tue May 29 11:41:33 2012 +0200 Improved support for emulation of msp430f2xxx series diff --git a/se/sics/mspsim/config/MSP430f2617Config.java b/se/sics/mspsim/config/MSP430f2617Config.java index bbf1fc3..5d4670c 100644 --- a/se/sics/mspsim/config/MSP430f2617Config.java +++ b/se/sics/mspsim/config/MSP430f2617Config.java @@ -49,6 +49,16 @@ public class MSP430f2617Config extends MSP430Config { + private static final String portConfig[] = { + "P1=0,IN 20,OUT 21,DIR 22,IFG 23,IES 24,IE 25,SEL 26,SEL2 41,REN 27", + "P2=0,IN 28,OUT 29,DIR 2A,IFG 2B,IES 2C,IE 2D,SEL 2E,SEL2 42,REN 2F", + "P3=0,IN 18,OUT 19,DIR 1A,SEL 1B,SEL2 43,REN 10", + "P4=0,IN 1C,OUT 1D,DIR 1E,SEL 1F,SEL2 44,REN 11", + "P5=0,IN 30,OUT 31,DIR 32,SEL 33,SEL2 45,REN 12", + "P6=0,IN 34,OUT 35,DIR 36,SEL 37,SEL2 46,REN 13", + "P7=0,IN 38,OUT 3A,DIR 3C,SEL 3E,SEL2 47,REN 14", + "P8=0,IN 39,OUT 3B,DIR 3D,SEL 3F,SEL2 48,REN 15" + }; public MSP430f2617Config() { /* 32 vectors for the MSP430X series */ @@ -62,9 +72,9 @@ public MSP430f2617Config() { /* TX Vec, RX Vec, TX Bit, RX Bit, SFR-reg, Offset, Name, A?*/ UARTConfig uA0 = new UARTConfig(22, 23, 1, 0, 1, 0x60, "USCI A0", true); - UARTConfig uB0 = new UARTConfig(22, 23, 3, 2, 1, 0x60, "USCI B0", false); + UARTConfig uB0 = new UARTConfig(22, 23, 3, 2, 1, 0x68, "USCI B0", false); UARTConfig uA1 = new UARTConfig(16, 17, 1, 0, 6, 0xD0, "USCI A1", true); - UARTConfig uB1 = new UARTConfig(16, 17, 3, 2, 6, 0xD0, "USCI B1", false); + UARTConfig uB1 = new UARTConfig(16, 17, 3, 2, 6, 0xD8, "USCI B1", false); uartConfig = new UARTConfig[] {uA0, uB0, uA1, uB1}; /* configure memory */ @@ -103,13 +113,12 @@ public int setup(MSP430Core cpu, ArrayList<IOUnit> ioUnits) { // Add port 1,2 with interrupt capability! // IOPorts will add themselves to the CPU - ioUnits.add(new IOPort(cpu, 1, 4, cpu.memory, 0x20)); - ioUnits.add(new IOPort(cpu, 2, 1, cpu.memory, 0x28)); + IOPort last = null; + ioUnits.add(last = IOPort.parseIOPort(cpu, 18, portConfig[0], last)); + ioUnits.add(last = IOPort.parseIOPort(cpu, 19, portConfig[1], last)); - // Add port 3,4 & 5,6 - for (int i = 0, n = 2; i < n; i++) { - ioUnits.add(new IOPort(cpu, (3 + i), 0, cpu.memory, 0x18 + i * 4)); - ioUnits.add(new IOPort(cpu, (5 + i), 0, cpu.memory, 0x30 + i * 4)); + for (int i = 2; i < portConfig.length; i++) { + ioUnits.add(last = IOPort.parseIOPort(cpu, 0, portConfig[i], last)); } ADC12 adc12 = new ADC12(cpu); diff --git a/se/sics/mspsim/config/MSP430f5437Config.java b/se/sics/mspsim/config/MSP430f5437Config.java index 4b849b6..15570ee 100644 --- a/se/sics/mspsim/config/MSP430f5437Config.java +++ b/se/sics/mspsim/config/MSP430f5437Config.java @@ -36,6 +36,7 @@ package se.sics.mspsim.config; import java.util.ArrayList; +import se.sics.mspsim.core.ClockSystem; import se.sics.mspsim.core.GenericUSCI; import se.sics.mspsim.core.IOPort; import se.sics.mspsim.core.IOUnit; @@ -43,6 +44,7 @@ import se.sics.mspsim.core.MSP430Core; import se.sics.mspsim.core.Multiplier32; import se.sics.mspsim.core.Timer; +import se.sics.mspsim.core.UnifiedClockSystem; import se.sics.mspsim.util.Utils; public class MSP430f5437Config extends MSP430Config { @@ -113,12 +115,12 @@ public int setup(MSP430Core cpu, ArrayList<IOUnit> ioUnits) { // System.out.println("Adding IOUnit USCI: " + usci.getName()); ioUnits.add(usci); } - - ioUnits.add(IOPort.parseIOPort(cpu, 47, portConfig[0])); - ioUnits.add(IOPort.parseIOPort(cpu, 42, portConfig[1])); + IOPort last = null; + ioUnits.add(last = IOPort.parseIOPort(cpu, 47, portConfig[0], last)); + ioUnits.add(last = IOPort.parseIOPort(cpu, 42, portConfig[1], last)); for (int i = 2; i < portConfig.length; i++) { - ioUnits.add(IOPort.parseIOPort(cpu, 0, portConfig[i])); + ioUnits.add(last = IOPort.parseIOPort(cpu, 0, portConfig[i], last)); } return portConfig.length + uartConfig.length; @@ -129,4 +131,9 @@ public String getAddressAsString(int addr) { return Utils.hex20(addr); } + @Override + public ClockSystem createClockSystem(MSP430Core cpu, int[] memory, Timer[] timers) { + return new UnifiedClockSystem(cpu, memory, 0, timers); + } + } diff --git a/se/sics/mspsim/core/IOPort.java b/se/sics/mspsim/core/IOPort.java index f5331e1..7db6a7b 100644 --- a/se/sics/mspsim/core/IOPort.java +++ b/se/sics/mspsim/core/IOPort.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007, Swedish Institute of Computer Science. + * Copyright (c) 2007-2012, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,47 +36,14 @@ */ package se.sics.mspsim.core; +import java.util.Arrays; import se.sics.mspsim.util.Utils; public class IOPort extends IOUnit { public enum PinState { LOW, HI }; - private final int port; - private final int interrupt; - - // External pin state! - private PinState pinState[] = new PinState[8]; - - /* NOTE: The offset needs to be configurable since the new IOPorts on - * the 5xxx series are located at other addresses. - * Maybe create another IOPort that just convert IOAddress to this 'old' mode? - * - will be slightly slower on IOWrite/read but very easy to implement. - * - * - * - * - * - * - */ - - enum PortReg {IN, OUT, DIR, SEL, IFG, IES, IE, REN, DS, IV_L, IV_H}; - - public static final int IN = 0; - public static final int OUT = 1; - public static final int DIR = 2; - public static final int SEL = 4; /* what about SEL2? */ - public static final int IFG = 5; - public static final int IES = 6; - public static final int IE = 7; - public static final int REN = 8; - public static final int DS = 9; - public static final int IV_L = 10; - public static final int IV_H = 11; - - private static final String[] names = { - "IN", "OUT", "DIR", "SEL", "IFG", "IES", "IE", "REN", "DS" }; - + public enum PortReg {IN, OUT, DIR, SEL, SEL2, IFG, IES, IE, REN, DS, IV_L, IV_H}; /* portmaps for 1611 */ private static final PortReg[] PORTMAP_INTERRUPT = @@ -84,10 +51,15 @@ private static final PortReg[] PORTMAP_NO_INTERRUPT = {PortReg.IN, PortReg.OUT, PortReg.DIR, PortReg.SEL}; + private final int port; + private final int interrupt; + + // External pin state! + private final PinState pinState[] = new PinState[8]; + private final PortReg[] portMap; private PortListener portListener = null; - // represents the direction register /* Registers for Digital I/O */ @@ -95,11 +67,12 @@ private int out; private int dir; private int sel; + private int sel2; private int ie; private int ifg; private int ies; /* edge select */ private int ren; -// private int ds; + private int ds; private int iv; /* low / high */ @@ -136,7 +109,7 @@ public IOPort(MSP430Core cpu, int port, } } - public static IOPort parseIOPort(MSP430Core cpu, int interrupt, String specification) { + public static IOPort parseIOPort(MSP430Core cpu, int interrupt, String specification, IOPort last) { /* Specification = Px=Offset,REG Off, ... */ String[] specs = specification.split(","); int port = specs[0].charAt(1) - '0'; @@ -148,10 +121,17 @@ public static IOPort parseIOPort(MSP430Core cpu, int interrupt, String specifica String[] preg = specs[i].split(" "); PortReg pr = PortReg.valueOf(preg[0]); int offs = Integer.parseInt(preg[1], 16); + if (offs >= portMap.length) { + portMap = Arrays.copyOf(portMap, offs + 1); + } portMap[offs] = pr; } - - return new IOPort(cpu, port, interrupt, cpu.memory, offset, portMap); + IOPort newPort = new IOPort(cpu, port, interrupt, cpu.memory, offset, portMap); + if (last != null && offset == last.offset && offset > 0) { + // This port is a pair with previous port to allow 16 bits writes + last.ioPair = newPort; + } + return newPort; } public int getPort() { @@ -203,6 +183,36 @@ public void updateIV() { //System.out.println("*** Setting IV to: " + iv + " ifg: " + ifg); } + public int getRegister(PortReg register) { + switch(register) { + case DIR: + return dir; + case IE: + return ie; + case IES: + return ies; + case IFG: + return ifg; + case IN: + return in; + case IV_H: + return (iv >> 8) & 0xff; + case IV_L: + return iv & 0xff; + case OUT: + return out; + case REN: + return ren; + case DS: + return ds; + case SEL: + return sel; + case SEL2: + return sel2; + } + return 0; + } + /* only byte access!!! */ int read_port(PortReg function, long cycles) { switch(function) { @@ -222,6 +232,10 @@ int read_port(PortReg function, long cycles) { return ies; case SEL: return sel; + case SEL2: + return sel2; + case DS: + return ds; case IV_L: return iv & 0xff; case IV_H: @@ -282,7 +296,13 @@ void write_port(PortReg function, int data, long cycles) { case SEL: sel = data; break; + case SEL2: + sel2 = data; + break; /* Can IV be written ? */ + case DS: + ds = data; + break; case IV_L: iv = (iv & 0xff00) | data; break; @@ -381,9 +401,7 @@ public void setPinState(int pin, PinState state) { public void reset(int type) { int oldValue = out | (~dir) & 0xff; - for (int i = 0, n = 8; i < n; i++) { - pinState[i] = PinState.LOW; - } + Arrays.fill(pinState, PinState.LOW); in = 0; dir = 0; ren = 0; @@ -401,12 +419,13 @@ public void reset(int type) { public String info() { StringBuilder sb = new StringBuilder(); - /* TODO: USE PORTMAP FOR THIS!!! */ - String[] regs = names; - sb.append('$').append(Utils.hex16(offset)).append(':'); - for (int i = 0, n = regs.length; i < n; i++) { - sb.append(' ').append(regs[i]).append(":$") - .append(Utils.hex8(0)); + sb.append(" $").append(Utils.hex(offset, 2)).append(':'); + for (int i = 0, n = portMap.length; i < n; i++) { + PortReg reg = portMap[i]; + if (reg != null) { + sb.append(' ').append(reg).append("($").append(Utils.hex(i, 2)).append("):$") + .append(Utils.hex(0, 2)); + } } return sb.toString(); } diff --git a/se/sics/mspsim/core/MSP430Config.java b/se/sics/mspsim/core/MSP430Config.java index fae8440..3cb67d1 100644 --- a/se/sics/mspsim/core/MSP430Config.java +++ b/se/sics/mspsim/core/MSP430Config.java @@ -143,5 +143,8 @@ public void ioMemSize(int size) { maxMemIO = size; } + public ClockSystem createClockSystem(MSP430Core cpu, int[] memory, Timer[] timers) { + return new BasicClockModule(cpu, memory, 0, timers); + } } diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java index db3fde5..76a03ef 100644 --- a/se/sics/mspsim/core/MSP430Core.java +++ b/se/sics/mspsim/core/MSP430Core.java @@ -239,13 +239,7 @@ public int read(int address, boolean word, long cycles) { timers[i] = t; } - // XXX this should be handled by the config, but we do it here to - // avoid changing too much of the mspsim architecture for now - if (MSP430XArch) { - bcs = new UnifiedClockSystem(this, memory, 0, timers); - } else { - bcs = new BasicClockModule(this, memory, 0, timers); - } + bcs = config.createClockSystem(this, memory, timers); ioSegment.setIORange(bcs.getAddressRangeMin(), bcs.getAddressRangeMax() - bcs.getAddressRangeMin() + 1, bcs); // SFR and Basic clock system. diff --git a/se/sics/mspsim/core/Multiplier32.java b/se/sics/mspsim/core/Multiplier32.java index e5024b2..141f752 100644 --- a/se/sics/mspsim/core/Multiplier32.java +++ b/se/sics/mspsim/core/Multiplier32.java @@ -168,12 +168,12 @@ public int read(int address, boolean word, long cycles) { public void write(int address, int data, boolean word, long cycles) { address = address - offset; if (DEBUG) { - log("write to: " + Utils.hex(address, 4) + " data = " + data + " word = " + word); + log("write to: $" + Utils.hex(address, 4) + " data=" + data + " word=" + word); } switch(address) { case MPY: - op1 = mpy = data; if (DEBUG) log("Write to MPY: " + data); + op1 = mpy = data; signed = false; accumulating = false; break; ----------------------------------------------------------------------- Summary of changes: images/z1.jpg | Bin 0 -> 71702 bytes se/sics/mspsim/config/MSP430f2617Config.java | 27 +++-- se/sics/mspsim/config/MSP430f5437Config.java | 15 ++- se/sics/mspsim/core/IOPort.java | 121 +++++++++++-------- se/sics/mspsim/core/MSP430Config.java | 3 + se/sics/mspsim/core/MSP430Core.java | 8 +- se/sics/mspsim/core/Multiplier32.java | 4 +- .../{wismote/WismoteGui.java => z1/Z1Gui.java} | 93 +++++++-------- se/sics/mspsim/platform/z1/Z1Node.java | 107 ++++++++++++++---- 9 files changed, 235 insertions(+), 143 deletions(-) create mode 100644 images/z1.jpg copy se/sics/mspsim/platform/{wismote/WismoteGui.java => z1/Z1Gui.java} (65%) mode change 100755 => 100644 hooks/post-receive -- mspsim |
From: Niclas F. <ni...@us...> - 2012-05-29 09:35:16
|
The branch "master" has been updated via b207699337cef22cb20f04cb611b2df30af7d75d (commit) via 79455275227d0ade64dada1038e80e680d693aca (commit) via 80050b799e0b2ccda7f5d7775f263359d0ef1b89 (commit) via fcae84940391da9bca0b7129bf4a83f79d787e40 (commit) via 231714ecdc18ea3c226806eca7bbf9a952576cc1 (commit) via 30bc7ce06c4fc2e8eb76007d9de2716a2bc5541f (commit) via 929e11c1526232df584993cb6f19a054a937a9c8 (commit) via 0892dc05829cc243e919e8d593f2ad692e039edf (commit) via 15539b97fd8d913bd52c5ab14fac9a51d0eec6e2 (commit) via d551aa7d06f7d6630788ec8c830e953f4d406fa6 (commit) via a9d2715df9b6ef6b3a79982d969a930f3b70099a (commit) via 67753f5093a6db50779b33382e88649ba9ef6c91 (commit) via b445b94c5ae75f20d5dc7e8bd2c11163b7695b68 (commit) via 2d63127469ccb79634f2d9356843c1651aa5dc89 (commit) via bab03367866524b420f5c3d389b119fe871d7aa6 (commit) via 60659635dec390aeda0973d9b36ac71416bef9eb (commit) via 5766a65c597366b337810586fbbd86311e5123e6 (commit) via 02cdeef5179eddd419e2018308a915afb2c4c067 (commit) via 9e8b624d74bc756c4e0cae485a2880346176d52e (commit) via 6e0f149bf694a6a7b3d6f0625ac6639374c59d9f (commit) via fac365d1319222852058acac28427e64135110c7 (commit) via 496be4558d385f1cd75d6558c61c0fe2a96411d4 (commit) via b272931e53e428d9842b841681e848984040eb30 (commit) via a4bdb2b864f42671e98cc7efcc22a58632c35bd0 (commit) via c4a91ce25caa0bcfa911c54085b1461f1f087f95 (commit) via 7baefad3ddbdf765055583388d1a1e617c9fd836 (commit) via 586420e75b25dc4cc4f075a530dfcc2603dcb897 (commit) via 14ca3e1e223785d66b7a8a03848b5caa95dd75e2 (commit) via c8a135bcea44c507d54120327afd7d604ff561e1 (commit) from 4254ad072080be9ab7e07477861583729ff0c6d7 (commit) Changed paths: M Makefile M build.xml A firmware/wismote/blink.wismote A images/wismote.png C058 se/sics/mspsim/chip/ChannelListener.java se/sics/mspsim/chip/Button.java M se/sics/mspsim/chip/CC2420.java M se/sics/mspsim/chip/CC2520.java M se/sics/mspsim/chip/CC2520SPI.java M se/sics/mspsim/chip/DS2411.java M se/sics/mspsim/chip/Leds.java C050 se/sics/mspsim/chip/ChannelListener.java se/sics/mspsim/chip/Radio802154.java M se/sics/mspsim/chip/SHT11.java M se/sics/mspsim/chip/SPICommand.java M se/sics/mspsim/chip/SPIData.java M se/sics/mspsim/cli/DebugCommands.java M se/sics/mspsim/config/MSP430f1611Config.java M se/sics/mspsim/config/MSP430f2617Config.java M se/sics/mspsim/config/MSP430f5437Config.java M se/sics/mspsim/core/ADC12.java M se/sics/mspsim/core/BasicClockModule.java M se/sics/mspsim/core/Chip.java M se/sics/mspsim/core/ClockSystem.java M se/sics/mspsim/core/DMA.java M se/sics/mspsim/core/Flash.java M se/sics/mspsim/core/GenericUSCI.java M se/sics/mspsim/core/IOPort.java M se/sics/mspsim/core/IOSegment.java M se/sics/mspsim/core/IOUnit.java M se/sics/mspsim/core/InterruptMultiplexer.java M se/sics/mspsim/core/MSP430Config.java M se/sics/mspsim/core/MSP430Core.java M se/sics/mspsim/core/Multiplier.java M se/sics/mspsim/core/Multiplier32.java M se/sics/mspsim/core/SFR.java M se/sics/mspsim/core/Timer.java M se/sics/mspsim/core/USART.java M se/sics/mspsim/core/USCI.java M se/sics/mspsim/core/UnifiedClockSystem.java M se/sics/mspsim/core/Watchdog.java M se/sics/mspsim/platform/AbstractNodeGUI.java M se/sics/mspsim/platform/esb/ESBGui.java M se/sics/mspsim/platform/esb/ESBNode.java M se/sics/mspsim/platform/sky/MoteIVNode.java M se/sics/mspsim/platform/sky/SkyGui.java A se/sics/mspsim/platform/wismote/WismoteGui.java M se/sics/mspsim/platform/wismote/WismoteNode.java M se/sics/mspsim/ui/JFrameWindowManager.java M se/sics/mspsim/ui/ManagedWindow.java - Log ----------------------------------------------------------------- commit b207699337cef22cb20f04cb611b2df30af7d75d Author: Niclas Finne <nf...@si...> Date: Tue May 29 11:34:41 2012 +0200 Added getOutputPowerMax() to describe the max output power of the radio chip diff --git a/se/sics/mspsim/chip/CC2420.java b/se/sics/mspsim/chip/CC2420.java index 3bbfe05..8e0b015 100644 --- a/se/sics/mspsim/chip/CC2420.java +++ b/se/sics/mspsim/chip/CC2420.java @@ -1348,6 +1348,11 @@ public int getOutputPower() { return -100; } + @Override + public int getOutputPowerMax() { + return 0; + } + public void notifyReset() { super.notifyReset(); setChipSelect(false); diff --git a/se/sics/mspsim/chip/CC2520.java b/se/sics/mspsim/chip/CC2520.java index 33c98af..925f441 100644 --- a/se/sics/mspsim/chip/CC2520.java +++ b/se/sics/mspsim/chip/CC2520.java @@ -1384,6 +1384,11 @@ public int getOutputPower() { } @Override + public int getOutputPowerMax() { + return 5; + } + + @Override public void notifyReset() { super.notifyReset(); setChipSelect(false); diff --git a/se/sics/mspsim/chip/Radio802154.java b/se/sics/mspsim/chip/Radio802154.java index 0957ea1..077e305 100644 --- a/se/sics/mspsim/chip/Radio802154.java +++ b/se/sics/mspsim/chip/Radio802154.java @@ -51,6 +51,7 @@ public Radio802154(String id, String name, MSP430Core cpu) { public abstract int getActiveChannel(); public abstract int getActiveFrequency(); public abstract int getOutputPower(); + public abstract int getOutputPowerMax(); public abstract int getOutputPowerIndicator(); public abstract int getOutputPowerIndicatorMax(); commit 79455275227d0ade64dada1038e80e680d693aca Author: Niclas Finne <nf...@si...> Date: Mon May 28 17:42:26 2012 +0200 Clear background for transparent node images diff --git a/se/sics/mspsim/platform/AbstractNodeGUI.java b/se/sics/mspsim/platform/AbstractNodeGUI.java index 1971954..a8f943c 100644 --- a/se/sics/mspsim/platform/AbstractNodeGUI.java +++ b/se/sics/mspsim/platform/AbstractNodeGUI.java @@ -157,18 +157,12 @@ public final void stop() { protected void paintComponent(Graphics g) { Color old = g.getColor(); + g.setColor(getBackground()); + g.fillRect(0, 0, getWidth(), getHeight()); + ImageIcon nodeImage = getNodeImage(); - int w = getWidth(), h = getHeight(); - int iw = nodeImage.getIconWidth(), ih = nodeImage.getIconHeight(); nodeImage.paintIcon(this, g, 0, 0); - // Clear all areas not covered by the image - g.setColor(getBackground()); - if (w > iw) { - g.fillRect(iw, 0, w, h); - } - if (h > ih) { - g.fillRect(0, ih, w, h); - } + g.setColor(old); } } commit 80050b799e0b2ccda7f5d7775f263359d0ef1b89 Author: Niclas Finne <nf...@si...> Date: Mon May 28 17:40:05 2012 +0200 disabled debug output diff --git a/se/sics/mspsim/core/IOSegment.java b/se/sics/mspsim/core/IOSegment.java index 072bdb5..494bb33 100644 --- a/se/sics/mspsim/core/IOSegment.java +++ b/se/sics/mspsim/core/IOSegment.java @@ -17,14 +17,17 @@ } void setIORange(int address, int range, IOUnit io) { - System.out.println("IO: 0x" + Utils.hex(address, 4) + "-" - + Utils.hex(address + range, 4) + ": " + io.id); +// System.out.println("IO: 0x" + Utils.hex(address, 4) + "-" +// + Utils.hex(address + range - 1, 4) + ": " + io.id); for (int i = 0; i < range; i++) { - if (mem[address + i] != voidIO) { - throw new IllegalStateException("IO unit already set: 0x" - + Utils.hex(address + i, 4) - + " (" + io.id + " => " + mem[address + i].id + ')'); - } +// if (mem[address + i] != voidIO) { +// System.err.println("Warning, IO unit already set: 0x" +// + Utils.hex(address + i, 4) +// + " (" + io.id + " => " + mem[address + i].id + ')'); +// throw new IllegalStateException("IO unit already set: 0x" +// + Utils.hex(address + i, 4) +// + " (" + io.id + " => " + mem[address + i].id + ')'); +// } mem[address + i] = io; } } diff --git a/se/sics/mspsim/core/USCI.java b/se/sics/mspsim/core/USCI.java index 10c3762..fc3cf16 100644 --- a/se/sics/mspsim/core/USCI.java +++ b/se/sics/mspsim/core/USCI.java @@ -188,13 +188,13 @@ public void enableChanged(int reg, int bit, boolean enabled) { } private void setBitIFG(int bits) { - if ((bits) > 0) { - System.out.println(getName() + " Set utxifg = " + utxifg + - " sfrA: " + sfrAddress + " bits: " + bits); - } +// if ((bits) > 0) { +// System.out.println(getName() + " Set utxifg = " + utxifg + +// " sfrA: " + sfrAddress + " bits: " + bits); +// } if (sfr != null) { sfr.setBitIFG(sfrAddress, bits); - System.out.println("SFR =>" + sfr.getIFG(sfrAddress)); +// System.out.println("SFR =>" + sfr.getIFG(sfrAddress)); } else { memory[ifgAddress] |= bits; } @@ -410,7 +410,7 @@ public void interruptServiced(int vector) { private void handleTransmit(long cycles) { if (cpu.getMode() >= MSP430Core.MODE_LPM3) { - System.out.println(getName() + " Warning: USART transmission during LPM!!! " + nextTXByte); + logw("Warning: USART transmission during LPM!!! " + nextTXByte); } if (transmitting) { @@ -488,10 +488,10 @@ public boolean getDMATriggerState(int index) { } public void clearDMATrigger(int index) { - System.out.println("UART clearing DMA " + index); +// System.out.println("UART clearing DMA " + index); if (index == 0) { /* clear RX - might be different in different modes... */ - System.out.println("UART clearing read bit!"); +// System.out.println("UART clearing read bit!"); clrBitIFG(urxifg); stateChanged(USARTListener.RXFLAG_CLEARED, true); } else { commit fcae84940391da9bca0b7129bf4a83f79d787e40 Author: Niclas Finne <nf...@si...> Date: Fri May 25 20:14:44 2012 +0200 Moved IO unit memory map into the IO memory segments diff --git a/se/sics/mspsim/config/MSP430f1611Config.java b/se/sics/mspsim/config/MSP430f1611Config.java index fbb1804..410dfaa 100644 --- a/se/sics/mspsim/config/MSP430f1611Config.java +++ b/se/sics/mspsim/config/MSP430f1611Config.java @@ -72,35 +72,22 @@ public int setup(MSP430Core cpu, ArrayList<IOUnit> ioUnits) { USART usart0 = new USART(cpu, 0, cpu.memory, 0x70); USART usart1 = new USART(cpu, 1, cpu.memory, 0x78); - - for (int i = 0, n = 8; i < n; i++) { - cpu.memOut[0x70 + i] = usart0; - cpu.memIn[0x70 + i] = usart0; - - cpu.memOut[0x78 + i] = usart1; - cpu.memIn[0x78 + i] = usart1; - } + cpu.setIORange(0x70, 8, usart0); + cpu.setIORange(0x78, 8, usart1); Multiplier mp = new Multiplier(cpu, cpu.memory, 0); - // Only cares of writes! - for (int i = 0x130, n = 0x13f; i < n; i++) { - cpu.memOut[i] = mp; - cpu.memIn[i] = mp; - } + cpu.setIORange(0x130, 0x0f, mp); // Usarts ioUnits.add(usart0); ioUnits.add(usart1); DMA dma = new DMA("dma", cpu, cpu.memory, 0); - for (int i = 0, n = 24; i < n; i++) { - cpu.memOut[0x1E0 + i] = dma; - cpu.memIn[0x1E0 + i] = dma; - } + cpu.setIORange(0x1e0, 24, dma); /* DMA Ctl */ - cpu.memOut[0x122] = dma; - cpu.memIn[0x124] = dma; + cpu.setIORange(0x122, 1, dma); + cpu.setIORange(0x124, 1, dma); /* configure the DMA */ dma.setDMATrigger(DMA.URXIFG0, usart0, 0); @@ -112,59 +99,22 @@ public int setup(MSP430Core cpu, ArrayList<IOUnit> ioUnits) { ioUnits.add(dma); // Add port 1,2 with interrupt capability! - IOPort io1; - IOPort io2; - ioUnits.add(io1 = new IOPort(cpu, 1, 4, cpu.memory, 0x20)); - ioUnits.add(io2 = new IOPort(cpu, 2, 1, cpu.memory, 0x28)); - for (int i = 0, n = 8; i < n; i++) { - cpu.memOut[0x20 + i] = io1; - cpu.memOut[0x28 + i] = io2; - cpu.memIn[0x20 + i] = io1; - cpu.memIn[0x28 + i] = io2; - } + // IOPorts will add themselves to the CPU + ioUnits.add(new IOPort(cpu, 1, 4, cpu.memory, 0x20)); + ioUnits.add(new IOPort(cpu, 2, 1, cpu.memory, 0x28)); // Add port 3,4 & 5,6 for (int i = 0, n = 2; i < n; i++) { - IOPort p = new IOPort(cpu, (3 + i), 0, cpu.memory, 0x18 + i * 4); - ioUnits.add(p); - cpu.memOut[0x18 + i * 4] = p; - cpu.memOut[0x19 + i * 4] = p; - cpu.memOut[0x1a + i * 4] = p; - cpu.memOut[0x1b + i * 4] = p; - cpu.memIn[0x18 + i * 4] = p; - cpu.memIn[0x19 + i * 4] = p; - cpu.memIn[0x1a + i * 4] = p; - cpu.memIn[0x1b + i * 4] = p; - } - - for (int i = 0, n = 2; i < n; i++) { - IOPort p = new IOPort(cpu, (5 + i), 0, cpu.memory, 0x30 + i * 4); - ioUnits.add(p); - cpu.memOut[0x30 + i * 4] = p; - cpu.memOut[0x31 + i * 4] = p; - cpu.memOut[0x32 + i * 4] = p; - cpu.memOut[0x33 + i * 4] = p; - cpu.memIn[0x30 + i * 4] = p; - cpu.memIn[0x31 + i * 4] = p; - cpu.memIn[0x32 + i * 4] = p; - cpu.memIn[0x33 + i * 4] = p; + ioUnits.add(new IOPort(cpu, (3 + i), 0, cpu.memory, 0x18 + i * 4)); + ioUnits.add(new IOPort(cpu, (5 + i), 0, cpu.memory, 0x30 + i * 4)); } ADC12 adc12 = new ADC12(cpu); ioUnits.add(adc12); - - for (int i = 0, n = 16; i < n; i++) { - cpu.memOut[0x80 + i] = adc12; - cpu.memIn[0x80 + i] = adc12; - cpu.memOut[0x140 + i] = adc12; - cpu.memIn[0x140 + i] = adc12; - cpu.memOut[0x150 + i] = adc12; - cpu.memIn[0x150 + i] = adc12; - } - for (int i = 0, n = 8; i < n; i++) { - cpu.memOut[0x1A0 + i] = adc12; - cpu.memIn[0x1A0 + i] = adc12; - } + cpu.setIORange(0x080, 16, adc12); + cpu.setIORange(0x140, 16, adc12); + cpu.setIORange(0x150, 16, adc12); + cpu.setIORange(0x1a0, 8, adc12); return 3 + 6; } diff --git a/se/sics/mspsim/config/MSP430f2617Config.java b/se/sics/mspsim/config/MSP430f2617Config.java index 3a9f0ff..bbf1fc3 100644 --- a/se/sics/mspsim/config/MSP430f2617Config.java +++ b/se/sics/mspsim/config/MSP430f2617Config.java @@ -76,33 +76,22 @@ public MSP430f2617Config() { public int setup(MSP430Core cpu, ArrayList<IOUnit> ioUnits) { Multiplier mp = new Multiplier(cpu, cpu.memory, 0); - // Only cares of writes! - for (int i = 0x130, n = 0x13f; i < n; i++) { - cpu.memOut[i] = mp; - cpu.memIn[i] = mp; - } + cpu.setIORange(0x130, 0x0f, mp); USCI usciA0 = new USCI(cpu, 0, cpu.memory, this); USCI usciB0 = new USCI(cpu, 1, cpu.memory, this); USCI usciA1 = new USCI(cpu, 2, cpu.memory, this); USCI usciB1 = new USCI(cpu, 3, cpu.memory, this); + cpu.setIORange(0x60, 8, usciA0); + cpu.setIORange(0x68, 8, usciB0); + cpu.setIORange(0xd0, 8, usciA1); + cpu.setIORange(0xd8, 8, usciB1); - for (int i = 0, n = 8; i < n; i++) { - cpu.memOut[0x60 + i] = usciA0; - cpu.memIn[0x60 + i] = usciA0; - cpu.memOut[0x68 + i] = usciB0; - cpu.memIn[0x68 + i] = usciB0; - - cpu.memOut[0xd0 + i] = usciA1; - cpu.memIn[0xd0 + i] = usciA1; - cpu.memOut[0xd8 + i] = usciB1; - cpu.memIn[0xd8 + i] = usciB1; - } /* usciBx for i2c mode */ - cpu.setIO(0x118, usciB0, true); - cpu.setIO(0x11a, usciB0, true); - cpu.setIO(0x17c, usciB1, true); - cpu.setIO(0x17e, usciB1, true); + cpu.setIORange(0x118, 2, usciB0); + cpu.setIORange(0x11a, 2, usciB0); + cpu.setIORange(0x17c, 2, usciB1); + cpu.setIORange(0x17e, 2, usciB1); ioUnits.add(usciA0); ioUnits.add(usciB0); @@ -110,65 +99,25 @@ public int setup(MSP430Core cpu, ArrayList<IOUnit> ioUnits) { ioUnits.add(usciB1); /* usciA1 handles interrupts for both usciA1 and B1 */ - cpu.memOut[6] = usciA1; - cpu.memIn[6] = usciA1; - cpu.memOut[7] = usciA1; - cpu.memIn[7] = usciA1; + cpu.setIORange(0x06, 2, usciA1); // Add port 1,2 with interrupt capability! - IOPort io1; - IOPort io2; - ioUnits.add(io1 = new IOPort(cpu, 1, 4, cpu.memory, 0x20)); - ioUnits.add(io2 = new IOPort(cpu, 2, 1, cpu.memory, 0x28)); - for (int i = 0, n = 8; i < n; i++) { - cpu.memOut[0x20 + i] = io1; - cpu.memOut[0x28 + i] = io2; - cpu.memIn[0x20 + i] = io1; - cpu.memIn[0x28 + i] = io2; - } + // IOPorts will add themselves to the CPU + ioUnits.add(new IOPort(cpu, 1, 4, cpu.memory, 0x20)); + ioUnits.add(new IOPort(cpu, 2, 1, cpu.memory, 0x28)); // Add port 3,4 & 5,6 for (int i = 0, n = 2; i < n; i++) { - IOPort p = new IOPort(cpu, (3 + i), 0, cpu.memory, 0x18 + i * 4); - ioUnits.add(p); - cpu.memOut[0x18 + i * 4] = p; - cpu.memOut[0x19 + i * 4] = p; - cpu.memOut[0x1a + i * 4] = p; - cpu.memOut[0x1b + i * 4] = p; - cpu.memIn[0x18 + i * 4] = p; - cpu.memIn[0x19 + i * 4] = p; - cpu.memIn[0x1a + i * 4] = p; - cpu.memIn[0x1b + i * 4] = p; - } - - for (int i = 0, n = 2; i < n; i++) { - IOPort p = new IOPort(cpu, (5 + i), 0, cpu.memory, 0x30 + i * 4); - ioUnits.add(p); - cpu.memOut[0x30 + i * 4] = p; - cpu.memOut[0x31 + i * 4] = p; - cpu.memOut[0x32 + i * 4] = p; - cpu.memOut[0x33 + i * 4] = p; - cpu.memIn[0x30 + i * 4] = p; - cpu.memIn[0x31 + i * 4] = p; - cpu.memIn[0x32 + i * 4] = p; - cpu.memIn[0x33 + i * 4] = p; + ioUnits.add(new IOPort(cpu, (3 + i), 0, cpu.memory, 0x18 + i * 4)); + ioUnits.add(new IOPort(cpu, (5 + i), 0, cpu.memory, 0x30 + i * 4)); } ADC12 adc12 = new ADC12(cpu); ioUnits.add(adc12); - - for (int i = 0, n = 16; i < n; i++) { - cpu.memOut[0x80 + i] = adc12; - cpu.memIn[0x80 + i] = adc12; - cpu.memOut[0x140 + i] = adc12; - cpu.memIn[0x140 + i] = adc12; - cpu.memOut[0x150 + i] = adc12; - cpu.memIn[0x150 + i] = adc12; - } - for (int i = 0, n = 8; i < n; i++) { - cpu.memOut[0x1A0 + i] = adc12; - cpu.memIn[0x1A0 + i] = adc12; - } + cpu.setIORange(0x080, 16, adc12); + cpu.setIORange(0x140, 16, adc12); + cpu.setIORange(0x150, 16, adc12); + cpu.setIORange(0x1a0, 8, adc12); /* 4 usci units + 6 io port*/ return 4 + 6; diff --git a/se/sics/mspsim/config/MSP430f5437Config.java b/se/sics/mspsim/config/MSP430f5437Config.java index 196f900..4b849b6 100644 --- a/se/sics/mspsim/config/MSP430f5437Config.java +++ b/se/sics/mspsim/config/MSP430f5437Config.java @@ -103,18 +103,13 @@ public MSP430f5437Config() { public int setup(MSP430Core cpu, ArrayList<IOUnit> ioUnits) { Multiplier32 mp = new Multiplier32(cpu, cpu.memory, 0x4c0); - for (int i = 0x4c0, n = 0x4c0 + 0x2e; i < n; i++) { - cpu.memOut[i] = mp; - cpu.memIn[i] = mp; - } + cpu.setIORange(0x4c0, 0x2e, mp); /* this code should be slightly more generic... and be somewhere else... */ for (int i = 0, n = uartConfig.length; i < n; i++) { GenericUSCI usci = new GenericUSCI(cpu, i, cpu.memory, this); /* setup 0 - 1f as IO addresses */ - for (int a = 0; a < 0x20; a++) { - cpu.setIO(a + uartConfig[i].offset, usci, false); - } + cpu.setIORange(uartConfig[i].offset, 0x20, usci); // System.out.println("Adding IOUnit USCI: " + usci.getName()); ioUnits.add(usci); } diff --git a/se/sics/mspsim/core/IOPort.java b/se/sics/mspsim/core/IOPort.java index 9fe4251..f5331e1 100644 --- a/se/sics/mspsim/core/IOPort.java +++ b/se/sics/mspsim/core/IOPort.java @@ -84,7 +84,7 @@ private static final PortReg[] PORTMAP_NO_INTERRUPT = {PortReg.IN, PortReg.OUT, PortReg.DIR, PortReg.SEL}; - private PortReg[] portMap; + private final PortReg[] portMap; private PortListener portListener = null; // represents the direction register @@ -111,25 +111,19 @@ * Creates a new <code>IOPort</code> instance. * */ + public IOPort(MSP430Core cpu, int port, int interrupt, int[] memory, int offset) { + this(cpu, port, interrupt, memory, offset, + interrupt == 0 ? PORTMAP_NO_INTERRUPT : PORTMAP_INTERRUPT); + } + + /* Create an IOPort with a special PortMap */ public IOPort(MSP430Core cpu, int port, - int interrupt, int[] memory, int offset) { + int interrupt, int[] memory, int offset, PortReg[] portMap) { super("P" + port, "Port " + port, cpu, memory, offset); this.port = port; this.interrupt = interrupt; this.ie = 0; this.ifg = 0; - - if (interrupt == 0) { - portMap = PORTMAP_NO_INTERRUPT; - } else { - portMap = PORTMAP_INTERRUPT; - } - } - - /* Create an IOPort with a special PortMap */ - public IOPort(MSP430Core cpu, int port, - int interrupt, int[] memory, int offset, PortReg[] portMap) { - this(cpu, port, interrupt, memory, offset); this.portMap = portMap; // System.out.println("Port " + port + " interrupt vector: " + interrupt); @@ -137,7 +131,7 @@ public IOPort(MSP430Core cpu, int port, for (int i = 0; i < portMap.length; i++) { if (portMap[i] != null) { // System.out.println(" P" + port + portMap[i] + " at " + Utils.hex16(offset + i)); - cpu.setIO(offset + i, this, false); + cpu.setIORange(offset + i, 1, this); } } } diff --git a/se/sics/mspsim/core/IOSegment.java b/se/sics/mspsim/core/IOSegment.java index 8e21b0a..072bdb5 100644 --- a/se/sics/mspsim/core/IOSegment.java +++ b/se/sics/mspsim/core/IOSegment.java @@ -1,20 +1,41 @@ package se.sics.mspsim.core; +import java.util.Arrays; +import se.sics.mspsim.util.Utils; + public class IOSegment implements Memory { private final MSP430Core core; + private final IOUnit[] mem; + private final IOUnit voidIO; - IOSegment(MSP430Core core) { + IOSegment(MSP430Core core, int maxMemIO, IOUnit voidIO) { this.core = core; + this.voidIO = voidIO; + this.mem = new IOUnit[maxMemIO]; + Arrays.fill(mem, voidIO); + } + + void setIORange(int address, int range, IOUnit io) { + System.out.println("IO: 0x" + Utils.hex(address, 4) + "-" + + Utils.hex(address + range, 4) + ": " + io.id); + for (int i = 0; i < range; i++) { + if (mem[address + i] != voidIO) { + throw new IllegalStateException("IO unit already set: 0x" + + Utils.hex(address + i, 4) + + " (" + io.id + " => " + mem[address + i].id + ')'); + } + mem[address + i] = io; + } } @Override public int read(int address, AccessMode mode, AccessType type) throws EmulationException { boolean word = mode != AccessMode.BYTE; // Only word reads at 0x1fe which is highest address... - int val = core.memIn[address].read(address, word, core.cycles); + int val = mem[address].read(address, word, core.cycles); if (mode == AccessMode.WORD20) { - val |= core.memIn[address + 2].read(address, word, core.cycles) << 16; + val |= mem[address + 2].read(address, word, core.cycles) << 16; } return val; } @@ -24,9 +45,9 @@ public void write(int dstAddress, int data, AccessMode mode) throws EmulationExc boolean word = mode != AccessMode.BYTE; if (!word) data &= 0xff; - core.memOut[dstAddress].write(dstAddress, data & 0xffff, word, core.cycles); + mem[dstAddress].write(dstAddress, data & 0xffff, word, core.cycles); if (mode == AccessMode.WORD20) { - core.memOut[dstAddress].write(dstAddress + 2, data >> 16, word, core.cycles); + mem[dstAddress].write(dstAddress + 2, data >> 16, word, core.cycles); } } @@ -40,4 +61,20 @@ public void set(int address, int data, AccessMode mode) { write(address, data, mode); } + public String info() { + StringBuilder sb = new StringBuilder(); + sb.append("IOSegment[0x0000-").append(Utils.hex(mem.length, 4)).append("]\n"); + + int start = 0; + for (int i = 1; i < mem.length; i++) { + if (mem[i] != mem[i - 1]) { + sb.append(" 0x").append(Utils.hex(start, 4)) + .append("-").append(Utils.hex(i - 1, 4)) + .append(": ").append(mem[i - 1].id).append(" (") + .append(mem[i - 1].name).append(")\n"); + start = i; + } + } + return sb.toString(); + } } diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java index d013643..db3fde5 100644 --- a/se/sics/mspsim/core/MSP430Core.java +++ b/se/sics/mspsim/core/MSP430Core.java @@ -70,6 +70,9 @@ boolean breakpointActive = true; public final int memory[]; + private final Flash flash; + boolean isFlashBusy; + boolean isStopping = false; private final Memory memorySegments[]; Memory currentSegment; @@ -80,15 +83,10 @@ public final boolean MSP430XArch; public final MSP430Config config; - // Most HW needs only notify write and clocking, others need also read... - // For notify write... - public final IOUnit[] memOut; - // For notify read... -> which will happen before actual read! - public final IOUnit[] memIn; - - private ArrayList<IOUnit> ioUnits; - private SFR sfr; - private Watchdog watchdog; + private final ArrayList<IOUnit> ioUnits; + private final SFR sfr; + private final Watchdog watchdog; + private final ClockSystem bcs; // From the possible interrupt sources - to be able to indicate is serviced. // NOTE: 64 since more modern MSP430's have more than 16 vectors (5xxx has 64). @@ -129,43 +127,24 @@ private ArrayList<Chip> chips = new ArrayList<Chip>(); - ComponentRegistry registry; + final ComponentRegistry registry; Profiler profiler; - private Flash flash; - - boolean isFlashBusy; - boolean isStopping = false; - - ClockSystem bcs; - - public void setIO(int adr, IOUnit io, boolean word) { - memOut[adr] = io; - memIn[adr] = io; - if (word) { - memOut[adr + 1] = io; - memIn[adr + 1] = io; - } - } - - public void setIORange(int adr, int size, IOUnit io) { - for (int i = 0; i < size; i++) { - memOut[adr + i] = io; - memIn[adr + i] = io; - } - } public MSP430Core(int type, ComponentRegistry registry, MSP430Config config) { super("MSP430", "MSP430 Core", null); MAX_INTERRUPT = config.maxInterruptVector; MAX_MEM_IO = config.maxMemIO; MAX_MEM = config.maxMem; - memOut = new IOUnit[MAX_MEM_IO]; - memIn = new IOUnit[MAX_MEM_IO]; MSP430XArch = config.MSP430XArch; memory = new int[MAX_MEM]; memorySegments = new Memory[MAX_MEM >> 8]; + flash = new Flash(this, memory, + new FlashRange(config.mainFlashStart, config.mainFlashStart + config.mainFlashSize, 512, 64), + new FlashRange(config.infoMemStart, config.infoMemStart + config.infoMemSize, 128, 64), + config.flashControllerOffset); + currentSegment = new Memory() { @Override public int read(int address, AccessMode mode, AccessType type) throws EmulationException { @@ -197,10 +176,10 @@ public void set(int address, int data, AccessMode mode) { } }; - System.out.println("Set up MSP430 Core with " + MAX_MEM + " bytes memory"); +// System.out.println("Set up MSP430 Core with " + MAX_MEM + " bytes memory"); /* this is for detecting writes/read to/from non-existing IO */ - IOUnit voidIO = new IOUnit(id, cpu, memory, 0) { + IOUnit voidIO = new IOUnit("void", cpu, memory, 0) { public void interruptServiced(int vector) { } public void write(int address, int value, boolean word, long cycles) { @@ -212,10 +191,26 @@ public int read(int address, boolean word, long cycles) { } }; - /* fill with void IO */ - for (int i = 0; i < MAX_MEM_IO; i++) { - memOut[i] = voidIO; - memIn[i] = voidIO; + /* setup memory segments */ + int maxSeg = MAX_MEM >> 8; + Memory ramSegment = new RAMSegment(this); + Memory flashSegment = new FlashSegment(this, flash); + IOSegment ioSegment = new IOSegment(this, MAX_MEM_IO, voidIO); + Memory noMemorySegment = new NoMemSegment(this); + for (int i = 0; i < maxSeg; i++) { + if (config.isRAM(i << 8)) { +// System.out.println("Setting RAM segment at: " + Utils.hex16(i << 8)); + memorySegments[i] = ramSegment; + } else if (config.isFlash(i << 8) || config.isInfoMem(i << 8)) { +// System.out.println("Setting Flash segment at: " + Utils.hex16(i << 8)); + memorySegments[i] = flashSegment; + } else if (config.isIO(i << 8)) { +// System.out.println("Setting IO segment at: " + Utils.hex16(i << 8)); + memorySegments[i] = ioSegment; + } else { +// System.out.println("Setting NoMem segment at: " + Utils.hex16(i << 8)); + memorySegments[i] = noMemorySegment; + } } this.registry = registry; @@ -229,34 +224,18 @@ public int read(int address, boolean word, long cycles) { // Maybe for debugging purposes... ioUnits = new ArrayList<IOUnit>(); - flash = new Flash(this, memory, - new FlashRange(config.mainFlashStart, config.mainFlashStart + config.mainFlashSize, 512, 64), - new FlashRange(config.infoMemStart, config.infoMemStart + config.infoMemSize, 128, 64), - config.flashControllerOffset); - for (int i = 0; i < 8; i++) { - memOut[i + config.flashControllerOffset] = flash; - memIn[i + config.flashControllerOffset] = flash; - } + ioSegment.setIORange(config.flashControllerOffset, 6, flash); /* Setup special function registers */ sfr = new SFR(this, memory); - for (int i = 0, n = 0x10; i < n; i++) { - memOut[i + config.sfrOffset] = sfr; - memIn[i + config.sfrOffset] = sfr; - } + ioSegment.setIORange(config.sfrOffset, 0x10, sfr); // first step towards making core configurable Timer[] timers = new Timer[config.timerConfig.length]; - for (int i = 0; i < config.timerConfig.length; i++) { Timer t = new Timer(this, memory, config.timerConfig[i]); - for (int a = 0, n = 0x20; a < n; a++) { - memOut[config.timerConfig[i].offset + a] = t; - memIn[config.timerConfig[i].offset + a] = t; - } - memIn[config.timerConfig[i].timerIVAddr] = t; - memOut[config.timerConfig[i].timerIVAddr] = t; - + ioSegment.setIORange(config.timerConfig[i].offset, 0x20, t); + ioSegment.setIORange(config.timerConfig[i].timerIVAddr, 1, t); timers[i] = t; } @@ -267,11 +246,7 @@ public int read(int address, boolean word, long cycles) { } else { bcs = new BasicClockModule(this, memory, 0, timers); } - for (int i = bcs.getAddressRangeMin(), n = bcs.getAddressRangeMax(); - i <= n; i++) { - memOut[i] = bcs; - memIn[i] = bcs; - } + ioSegment.setIORange(bcs.getAddressRangeMin(), bcs.getAddressRangeMax() - bcs.getAddressRangeMin() + 1, bcs); // SFR and Basic clock system. ioUnits.add(sfr); @@ -285,34 +260,19 @@ public int read(int address, boolean word, long cycles) { } watchdog = new Watchdog(this); - memOut[config.watchdogOffset] = watchdog; - memIn[config.watchdogOffset] = watchdog; + ioSegment.setIORange(config.watchdogOffset, 1, watchdog); ioUnits.add(watchdog); - /* setup memory segments */ - int maxSeg = MAX_MEM >> 8; - Memory ramSegment = new RAMSegment(this); - Memory flashSegment = new FlashSegment(this, flash); - Memory ioSegment = new IOSegment(this); - Memory noMemorySegment = new NoMemSegment(this); - for (int i = 0; i < maxSeg; i++) { - if (config.isRAM(i << 8)) { -// System.out.println("Setting RAM segment at: " + Utils.hex16(i << 8)); - memorySegments[i] = ramSegment; - } else if (config.isFlash(i << 8) || config.isInfoMem(i << 8)) { -// System.out.println("Setting Flash segment at: " + Utils.hex16(i << 8)); - memorySegments[i] = flashSegment; - } else if (config.isIO(i << 8)) { -// System.out.println("Setting IO segment at: " + Utils.hex16(i << 8)); - memorySegments[i] = ioSegment; - } else { -// System.out.println("Setting NoMem segment at: " + Utils.hex16(i << 8)); - memorySegments[i] = noMemorySegment; - } + bcs.reset(0); } - bcs.reset(0); + public void setIORange(int address, int range, IOUnit io) { + if (address + range > MAX_MEM_IO) { + throw new IllegalStateException("Outside IO memory: 0x" + Utils.hex(address, 4)); + } + IOSegment ioSegment = (IOSegment) memorySegments[address >> 8]; + ioSegment.setIORange(address, range, io); } public Profiler getProfiler() { commit 231714ecdc18ea3c226806eca7bbf9a952576cc1 Author: Niclas Finne <nf...@si...> Date: Fri May 25 20:11:15 2012 +0200 Maded TimerConfig and UARTConfig immutable diff --git a/se/sics/mspsim/core/MSP430Config.java b/se/sics/mspsim/core/MSP430Config.java index 6b0c80a..fae8440 100644 --- a/se/sics/mspsim/core/MSP430Config.java +++ b/se/sics/mspsim/core/MSP430Config.java @@ -6,14 +6,14 @@ public abstract class MSP430Config { - public class TimerConfig { - int ccr0Vector; - int ccrXVector; - int ccrCount; - int offset; - String name; - public int[] srcMap; - public int timerIVAddr; + public static class TimerConfig { + public final int ccr0Vector; + public final int ccrXVector; + public final int ccrCount; + public final int offset; + public final String name; + public final int[] srcMap; + public final int timerIVAddr; public TimerConfig(int ccr0Vec, int ccrXVec, int ccrCount, int offset, int[] srcMap, String name, int tiv) { @@ -27,29 +27,33 @@ public TimerConfig(int ccr0Vec, int ccrXVec, int ccrCount, int offset, } } - public class UARTConfig { + public static class UARTConfig { private static final int USCI_2 = 1; private static final int USCI_5 = 2; - public int txVector; - public int rxVector; - public int offset; - public String name; - public int txBit; - public int rxBit; - public int sfrAddr; - public boolean usciA; - public int type = USCI_2; + public final int txVector; + public final int rxVector; + public final int offset; + public final String name; + public final int txBit; + public final int rxBit; + public final int sfrAddr; + public final boolean usciA; + public final int type; public UARTConfig(String name, int vector, int offset) { type = USCI_5; txVector = rxVector = vector; + this.txBit = this.rxBit = 0; this.offset = offset; this.name = name; + this.usciA = false; + this.sfrAddr = 0; } public UARTConfig(int txVector, int rxVector, int txBit, int rxBit, int sftAddr, int offset, String name, boolean usciA) { + this.type = USCI_2; this.txVector = txVector; this.rxVector = rxVector; this.txBit = txBit; commit 30bc7ce06c4fc2e8eb76007d9de2716a2bc5541f Author: Niclas Finne <nf...@si...> Date: Fri May 25 17:55:22 2012 +0200 Disabled debug output diff --git a/se/sics/mspsim/config/MSP430f5437Config.java b/se/sics/mspsim/config/MSP430f5437Config.java index bb57263..196f900 100644 --- a/se/sics/mspsim/config/MSP430f5437Config.java +++ b/se/sics/mspsim/config/MSP430f5437Config.java @@ -36,16 +36,13 @@ package se.sics.mspsim.config; import java.util.ArrayList; - import se.sics.mspsim.core.GenericUSCI; import se.sics.mspsim.core.IOPort; import se.sics.mspsim.core.IOUnit; import se.sics.mspsim.core.MSP430Config; import se.sics.mspsim.core.MSP430Core; -import se.sics.mspsim.core.Multiplier; import se.sics.mspsim.core.Multiplier32; import se.sics.mspsim.core.Timer; -import se.sics.mspsim.core.USCI; import se.sics.mspsim.util.Utils; public class MSP430f5437Config extends MSP430Config { @@ -54,7 +51,7 @@ // - positions of all timers (A0, A1, B) // - memory configuration // - - String portConfig[] = { + private static final String portConfig[] = { "P1=200,IN 00,OUT 02,DIR 04,REN 06,DS 08,SEL 0A,IV_L 0E,IV_H 0F,IES 18,IE 1A,IFG 1C", "P2=200,IN 01,OUT 03,DIR 05,REN 07,DS 09,SEL 0B,IV_L 1E,IV_H 1F,IES 19,IE 1B,IFG 1D", "P3=220,IN 00,OUT 02,DIR 04,REN 06,DS 08,SEL 0A", @@ -118,7 +115,7 @@ public int setup(MSP430Core cpu, ArrayList<IOUnit> ioUnits) { for (int a = 0; a < 0x20; a++) { cpu.setIO(a + uartConfig[i].offset, usci, false); } - System.out.println("Adding IOUnit USCI: " + usci.getName()); +// System.out.println("Adding IOUnit USCI: " + usci.getName()); ioUnits.add(usci); } diff --git a/se/sics/mspsim/core/IOPort.java b/se/sics/mspsim/core/IOPort.java index 7624940..9fe4251 100644 --- a/se/sics/mspsim/core/IOPort.java +++ b/se/sics/mspsim/core/IOPort.java @@ -132,11 +132,11 @@ public IOPort(MSP430Core cpu, int port, this(cpu, port, interrupt, memory, offset); this.portMap = portMap; - System.out.println("Port " + port + " interrupt vector: " + interrupt); +// System.out.println("Port " + port + " interrupt vector: " + interrupt); /* register all the registers from the port-map */ for (int i = 0; i < portMap.length; i++) { if (portMap[i] != null) { - System.out.println(" P" + port + portMap[i] + " at " + Utils.hex16(offset + i)); +// System.out.println(" P" + port + portMap[i] + " at " + Utils.hex16(offset + i)); cpu.setIO(offset + i, this, false); } } commit 929e11c1526232df584993cb6f19a054a937a9c8 Author: Niclas Finne <nf...@si...> Date: Fri May 25 17:53:40 2012 +0200 Added example Wismote firmware diff --git a/firmware/wismote/blink.wismote b/firmware/wismote/blink.wismote new file mode 100644 index 0000000..3343349 Binary files /dev/null and b/firmware/wismote/blink.wismote differ commit 0892dc05829cc243e919e8d593f2ad692e039edf Author: Niclas Finne <nf...@si...> Date: Fri May 25 17:52:01 2012 +0200 Replaced constants PIN_HI, PIN_LOW with enum PinState diff --git a/se/sics/mspsim/chip/Button.java b/se/sics/mspsim/chip/Button.java index 9b01d04..8a9f47f 100644 --- a/se/sics/mspsim/chip/Button.java +++ b/se/sics/mspsim/chip/Button.java @@ -60,7 +60,7 @@ public void setPressed(boolean isPressed) { this.isPressed = isPressed; stateChanged(isPressed ? 1 : 0); if (DEBUG) log(isPressed ? "pressed" : "released"); - port.setPinState(pin, isPressed == polarity ? IOPort.PIN_HI : IOPort.PIN_LOW); + port.setPinState(pin, isPressed == polarity ? IOPort.PinState.HI : IOPort.PinState.LOW); } } diff --git a/se/sics/mspsim/chip/CC2420.java b/se/sics/mspsim/chip/CC2420.java index e92bdb5..3bbfe05 100644 --- a/se/sics/mspsim/chip/CC2420.java +++ b/se/sics/mspsim/chip/CC2420.java @@ -1208,9 +1208,9 @@ private void setInternalCCA(boolean clear) { private void setSFD(boolean sfd) { currentSFD = sfd; if( (registers[REG_IOCFG0] & SFD_POLARITY) == SFD_POLARITY) - sfdPort.setPinState(sfdPin, sfd ? 0 : 1); + sfdPort.setPinState(sfdPin, sfd ? IOPort.PinState.LOW : IOPort.PinState.HI); else - sfdPort.setPinState(sfdPin, sfd ? 1 : 0); + sfdPort.setPinState(sfdPin, sfd ? IOPort.PinState.HI : IOPort.PinState.LOW); if (DEBUG) log("SFD: " + sfd + " " + cpu.cycles); } @@ -1218,18 +1218,18 @@ private void setCCA(boolean cca) { currentCCA = cca; if (DEBUG) log("Setting CCA to: " + cca); if( (registers[REG_IOCFG0] & CCA_POLARITY) == CCA_POLARITY) - ccaPort.setPinState(ccaPin, cca ? 0 : 1); + ccaPort.setPinState(ccaPin, cca ? IOPort.PinState.LOW : IOPort.PinState.HI); else - ccaPort.setPinState(ccaPin, cca ? 1 : 0); + ccaPort.setPinState(ccaPin, cca ? IOPort.PinState.HI : IOPort.PinState.LOW); } private void setFIFOP(boolean fifop) { currentFIFOP = fifop; if (DEBUG) log("Setting FIFOP to " + fifop); if( (registers[REG_IOCFG0] & FIFOP_POLARITY) == FIFOP_POLARITY) { - fifopPort.setPinState(fifopPin, fifop ? 0 : 1); + fifopPort.setPinState(fifopPin, fifop ? IOPort.PinState.LOW : IOPort.PinState.HI); } else { - fifopPort.setPinState(fifopPin, fifop ? 1 : 0); + fifopPort.setPinState(fifopPin, fifop ? IOPort.PinState.HI : IOPort.PinState.LOW); } } @@ -1237,9 +1237,9 @@ private void setFIFO(boolean fifo) { currentFIFO = fifo; if (DEBUG) log("Setting FIFO to " + fifo); if((registers[REG_IOCFG0] & FIFO_POLARITY) == FIFO_POLARITY) { - fifoPort.setPinState(fifoPin, fifo ? 0 : 1); + fifoPort.setPinState(fifoPin, fifo ? IOPort.PinState.LOW : IOPort.PinState.HI); } else { - fifoPort.setPinState(fifoPin, fifo ? 1 : 0); + fifoPort.setPinState(fifoPin, fifo ? IOPort.PinState.HI : IOPort.PinState.LOW); } } diff --git a/se/sics/mspsim/chip/CC2520.java b/se/sics/mspsim/chip/CC2520.java index c9fb57b..33c98af 100644 --- a/se/sics/mspsim/chip/CC2520.java +++ b/se/sics/mspsim/chip/CC2520.java @@ -52,7 +52,7 @@ public void setConfig(IOPort port, int pin) { this.port = port; this.pin = pin; - port.setPinState(pin, isActive == polarity ? IOPort.PIN_HI : IOPort.PIN_LOW); + port.setPinState(pin, isActive == polarity ? IOPort.PinState.HI : IOPort.PinState.LOW); } public boolean isActive() { @@ -63,7 +63,7 @@ public void setActive(boolean isActive) { if (this.isActive != isActive) { this.isActive = isActive; if (port != null) { - port.setPinState(pin, isActive == polarity ? IOPort.PIN_HI : IOPort.PIN_LOW); + port.setPinState(pin, isActive == polarity ? IOPort.PinState.HI : IOPort.PinState.LOW); } } } @@ -72,7 +72,7 @@ public void setPolarity(boolean |
From: Niclas F. <ni...@us...> - 2012-05-15 21:51:42
|
The branch "master" has been updated via 4254ad072080be9ab7e07477861583729ff0c6d7 (commit) from 4bb3c2e5f3cb53c5013bc1b526d7f50b760bdfb3 (commit) Changed paths: M se/sics/mspsim/core/Timer.java M se/sics/mspsim/platform/esb/ESBGui.java M se/sics/mspsim/platform/esb/ESBNode.java M se/sics/mspsim/platform/jcreate/JCreateNode.java M se/sics/mspsim/platform/sky/CC2420Node.java M se/sics/mspsim/platform/ti/Exp5438Node.java M se/sics/mspsim/platform/tyndall/TyndallNode.java M se/sics/mspsim/platform/z1/Z1Node.java - Log ----------------------------------------------------------------- commit 4254ad072080be9ab7e07477861583729ff0c6d7 Author: Niclas Finne <nf...@si...> Date: Tue Apr 24 19:40:24 2012 +0200 Minor code cleanup in the node setup diff --git a/se/sics/mspsim/core/Timer.java b/se/sics/mspsim/core/Timer.java index 8d785e5..a5b52d1 100644 --- a/se/sics/mspsim/core/Timer.java +++ b/se/sics/mspsim/core/Timer.java @@ -727,7 +727,7 @@ public void write(int address, int data, boolean word, long cycles) { if (!oldCapture && reg.captureOn && (src & SRC_PORT) != 0) { int port = (src & 0xff) >> 4; int pin = src & 0x0f; - IOPort ioPort = (IOPort) core.getIOUnit("P" + port); + IOPort ioPort = core.getIOUnit(IOPort.class, "P" + port); if (DEBUG) log("Assigning Port: " + port + " pin: " + pin + " for capture"); ioPort.setTimerCapture(this, pin); diff --git a/se/sics/mspsim/platform/esb/ESBGui.java b/se/sics/mspsim/platform/esb/ESBGui.java index 9ddd3b7..8213224 100644 --- a/se/sics/mspsim/platform/esb/ESBGui.java +++ b/se/sics/mspsim/platform/esb/ESBGui.java @@ -54,7 +54,6 @@ import se.sics.mspsim.core.ADC12; import se.sics.mspsim.core.ADCInput; -import se.sics.mspsim.core.IOUnit; import se.sics.mspsim.core.StateChangeListener; import se.sics.mspsim.platform.AbstractNodeGUI; @@ -159,9 +158,9 @@ public void mouseReleased(MouseEvent e) { node.getLeds().addStateChangeListener(ledsListener); - IOUnit adc = node.getCPU().getIOUnit("ADC12"); - if (adc instanceof ADC12) { - ((ADC12) adc).setADCInput(0, this); + ADC12 adc = node.getCPU().getIOUnit(ADC12.class, "ADC12"); + if (adc != null) { + adc.setADCInput(0, this); } // Just a test... TODO: remove!!! diff --git a/se/sics/mspsim/platform/esb/ESBNode.java b/se/sics/mspsim/platform/esb/ESBNode.java index a9e1ad8..935e650 100644 --- a/se/sics/mspsim/platform/esb/ESBNode.java +++ b/se/sics/mspsim/platform/esb/ESBNode.java @@ -46,8 +46,8 @@ import se.sics.mspsim.chip.Leds; import se.sics.mspsim.chip.TR1001; import se.sics.mspsim.config.MSP430f149Config; +import se.sics.mspsim.core.EmulationException; 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; @@ -141,27 +141,19 @@ public void portWrite(IOPort source, int data) { } public void setupNodePorts() { - IOUnit unit = cpu.getIOUnit("Port 2"); - if (unit instanceof IOPort) { - port2 = (IOPort) unit; - port2.addPortListener(this); - } - - unit = cpu.getIOUnit("Port 1"); - if (unit instanceof IOPort) { - port1 = (IOPort) unit; - } + port1 = cpu.getIOUnit(IOPort.class, "P1"); - unit = cpu.getIOUnit("Port 5"); - if (unit instanceof IOPort) { - port5 = (IOPort) unit; + port2 = cpu.getIOUnit(IOPort.class, "P2"); + port2.addPortListener(this); + port5 = cpu.getIOUnit(IOPort.class, "P5"); port5.addPortListener(this); - } - IOUnit usart0 = cpu.getIOUnit("USART 0"); - if (usart0 instanceof USART) { - radio = new TR1001(cpu, (USART) usart0); + USART usart0 = cpu.getIOUnit(USART.class, "USART0"); + if (usart0 == null) { + throw new EmulationException("Could not setup mote - missing USART0"); } + radio = new TR1001(cpu, usart0); + leds = new Leds(cpu, LEDS); beeper = new Beeper(cpu); } @@ -181,9 +173,9 @@ public void setupNode() { beeper.setSoundEnabled(true); // Add some windows for listening to serial output - IOUnit usart = cpu.getIOUnit("USART 1"); - if (usart instanceof USART) { - SerialMon serial = new SerialMon((USART)usart, "USART1 Port Output"); + USART usart = cpu.getIOUnit(USART.class, "USART1"); + if (usart != null) { + SerialMon serial = new SerialMon(usart, "USART1 Port Output"); registry.registerComponent("serialgui", serial); } diff --git a/se/sics/mspsim/platform/jcreate/JCreateNode.java b/se/sics/mspsim/platform/jcreate/JCreateNode.java index 9297a2d..b3031bb 100644 --- a/se/sics/mspsim/platform/jcreate/JCreateNode.java +++ b/se/sics/mspsim/platform/jcreate/JCreateNode.java @@ -117,9 +117,7 @@ public void setupNodePorts() { super.setupNodePorts(); leds = new Leds(cpu, LEDS); accelerometer = new MMA7260QT(cpu); - IOUnit io = cpu.getIOUnit("ADC12"); - if (io instanceof ADC12) { - ADC12 adc = (ADC12) io; + ADC12 adc = cpu.getIOUnit(ADC12.class, "ADC12"); adc.setADCInput(4, new ADCInput() { public int nextData() { return accelerometer.getADCX(); @@ -135,7 +133,6 @@ public int nextData() { return accelerometer.getADCZ(); } }); - } if (flashFile != null) { setFlash(new FileM25P80(cpu, flashFile)); diff --git a/se/sics/mspsim/platform/sky/CC2420Node.java b/se/sics/mspsim/platform/sky/CC2420Node.java index 22c9f9c..7914997 100644 --- a/se/sics/mspsim/platform/sky/CC2420Node.java +++ b/se/sics/mspsim/platform/sky/CC2420Node.java @@ -72,44 +72,28 @@ public void setNodeID(int id) { public void setupNodePorts() { ds2411 = new DS2411(cpu); - IOUnit unit = cpu.getIOUnit("P1"); - if (unit instanceof IOPort) { - port1 = (IOPort) unit; + port1 = cpu.getIOUnit(IOPort.class, "P1"); port1.addPortListener(this); - } - unit = cpu.getIOUnit("P2"); - if (unit instanceof IOPort) { - port2 = (IOPort) unit; + port2 = cpu.getIOUnit(IOPort.class, "P2"); ds2411.setDataPort(port2, DS2411_DATA_PIN); port2.addPortListener(this); - } - unit = cpu.getIOUnit("P4"); - if (unit instanceof IOPort) { - port4 = (IOPort) unit; + port4 = cpu.getIOUnit(IOPort.class, "P4"); port4.addPortListener(this); - } - unit = cpu.getIOUnit("P5"); - if (unit instanceof IOPort) { - port5 = (IOPort) unit; + port5 = cpu.getIOUnit(IOPort.class, "P5"); port5.addPortListener(this); - } - IOUnit usart0 = cpu.getIOUnit("USART0"); - if (usart0 instanceof USART) { + USART usart0 = cpu.getIOUnit(USART.class, "USART0"); radio = new CC2420(cpu); radio.setCCAPort(port1, CC2420_CCA); radio.setFIFOPPort(port1, CC2420_FIFOP); radio.setFIFOPort(port1, CC2420_FIFO); - ((USART) usart0).addUSARTListener(this); - if (port4 != null) { + usart0.addUSARTListener(this); radio.setSFDPort(port4, CC2420_SFD); } - } - } public void setupNode() { // create a filename for the flash file @@ -140,9 +124,9 @@ public void setupNode() { setupGUI(); // Add some windows for listening to serial output - IOUnit usart = cpu.getIOUnit("USART1"); - if (usart instanceof USART) { - SerialMon serial = new SerialMon((USART)usart, "USART1 Port Output"); + USART usart = cpu.getIOUnit(USART.class, "USART1"); + if (usart != null) { + SerialMon serial = new SerialMon(usart, "USART1 Port Output"); registry.registerComponent("serialgui", serial); } if (stats != null) { diff --git a/se/sics/mspsim/platform/ti/Exp5438Node.java b/se/sics/mspsim/platform/ti/Exp5438Node.java index 887933b..079f1ca 100644 --- a/se/sics/mspsim/platform/ti/Exp5438Node.java +++ b/se/sics/mspsim/platform/ti/Exp5438Node.java @@ -66,40 +66,18 @@ public void portWrite(IOPort source, int data) { } private void setupNodePorts() { - IOUnit unit = cpu.getIOUnit("P1"); - if (unit instanceof IOPort) { - port1 = (IOPort) unit; + port1 = cpu.getIOUnit(IOPort.class, "P1"); port1.addPortListener(this); - } - unit = cpu.getIOUnit("P3"); - if (unit instanceof IOPort) { - port3 = (IOPort) unit; + port3 = cpu.getIOUnit(IOPort.class, "P3"); port3.addPortListener(this); - } - - unit = cpu.getIOUnit("P4"); - if (unit instanceof IOPort) { - port4 = (IOPort) unit; + port4 = cpu.getIOUnit(IOPort.class, "P4"); port4.addPortListener(this); - } - - unit = cpu.getIOUnit("P5"); - if (unit instanceof IOPort) { - port5 = (IOPort) unit; + port5 = cpu.getIOUnit(IOPort.class, "P5"); port5.addPortListener(this); - } - - unit = cpu.getIOUnit("P7"); - if (unit instanceof IOPort) { - port7 = (IOPort) unit; + port7 = cpu.getIOUnit(IOPort.class, "P7"); port7.addPortListener(this); - } - - unit = cpu.getIOUnit("P8"); - if (unit instanceof IOPort) { - port8 = (IOPort) unit; + port8 = cpu.getIOUnit(IOPort.class, "P8"); port8.addPortListener(this); - } IOUnit usart0 = cpu.getIOUnit("USCI B0"); if (usart0 instanceof USARTSource) { @@ -109,9 +87,7 @@ private void setupNodePorts() { radio.setFIFOPort(port1, CC2420_FIFO); ((USARTSource) usart0).addUSARTListener(this); - if (port1 != null) { radio.setSFDPort(port1, CC2420_SFD); - } } else { throw new EmulationException("Could not setup exp5438 mote - missing USCI B0"); } diff --git a/se/sics/mspsim/platform/tyndall/TyndallNode.java b/se/sics/mspsim/platform/tyndall/TyndallNode.java index 26bac29..28f72bc 100644 --- a/se/sics/mspsim/platform/tyndall/TyndallNode.java +++ b/se/sics/mspsim/platform/tyndall/TyndallNode.java @@ -92,41 +92,18 @@ private void setupNodePorts() { // setFlash(new FileM25P80(cpu, flashFile)); // } - IOUnit unit = cpu.getIOUnit("P1"); - if (unit instanceof IOPort) { - port1 = (IOPort) unit; + port1 = cpu.getIOUnit(IOPort.class, "P1"); port1.addPortListener(this); - } - unit = cpu.getIOUnit("P3"); - if (unit instanceof IOPort) { - port3 = (IOPort) unit; + port3 = cpu.getIOUnit(IOPort.class, "P3"); port3.addPortListener(this); - } - - unit = cpu.getIOUnit("P4"); - if (unit instanceof IOPort) { - port4 = (IOPort) unit; + port4 = cpu.getIOUnit(IOPort.class, "P4"); port4.addPortListener(this); - } - - unit = cpu.getIOUnit("P5"); - if (unit instanceof IOPort) { - port5 = (IOPort) unit; + port5 = cpu.getIOUnit(IOPort.class, "P5"); port5.addPortListener(this); - } - - unit = cpu.getIOUnit("P7"); - if (unit instanceof IOPort) { - port7 = (IOPort) unit; + port7 = cpu.getIOUnit(IOPort.class, "P7"); port7.addPortListener(this); - } - - unit = cpu.getIOUnit("P8"); - if (unit instanceof IOPort) { - port8 = (IOPort) unit; + port8 = cpu.getIOUnit(IOPort.class, "P8"); port8.addPortListener(this); - } - IOUnit usart0 = cpu.getIOUnit("USCI B0"); if (usart0 instanceof USARTSource) { @@ -136,9 +113,7 @@ private void setupNodePorts() { radio.setFIFOPort(port8, CC2420_FIFO); ((USARTSource) usart0).addUSARTListener(this); - if (port4 != null) { radio.setSFDPort(port8, CC2420_SFD); - } } else { throw new EmulationException("Could not setup tyndall mote - missing USCI B0"); } diff --git a/se/sics/mspsim/platform/z1/Z1Node.java b/se/sics/mspsim/platform/z1/Z1Node.java index 6816418..c06f197 100644 --- a/se/sics/mspsim/platform/z1/Z1Node.java +++ b/se/sics/mspsim/platform/z1/Z1Node.java @@ -6,6 +6,7 @@ import se.sics.mspsim.chip.FileM25P80; import se.sics.mspsim.chip.M25P80; import se.sics.mspsim.config.MSP430f2617Config; +import se.sics.mspsim.core.EmulationException; import se.sics.mspsim.core.IOPort; import se.sics.mspsim.core.IOUnit; import se.sics.mspsim.core.PortListener; @@ -92,26 +93,14 @@ private void setupNodePorts() { setFlash(new FileM25P80(cpu, flashFile)); } - IOUnit unit = cpu.getIOUnit("P1"); - if (unit instanceof IOPort) { - port1 = (IOPort) unit; + port1 = cpu.getIOUnit(IOPort.class, "P1"); port1.addPortListener(this); - } - unit = cpu.getIOUnit("P3"); - if (unit instanceof IOPort) { - port3 = (IOPort) unit; + port3 = cpu.getIOUnit(IOPort.class, "P3"); port3.addPortListener(this); - } - unit = cpu.getIOUnit("P4"); - if (unit instanceof IOPort) { - port4 = (IOPort) unit; + port4 = cpu.getIOUnit(IOPort.class, "P4"); port4.addPortListener(this); - } - unit = cpu.getIOUnit("P5"); - if (unit instanceof IOPort) { - port5 = (IOPort) unit; + port5 = cpu.getIOUnit(IOPort.class, "P5"); port5.addPortListener(this); - } IOUnit usart0 = cpu.getIOUnit("USCI B0"); if (usart0 instanceof USCI) { @@ -121,9 +110,9 @@ private void setupNodePorts() { radio.setFIFOPort(port1, CC2420_FIFO); ((USARTSource) usart0).addUSARTListener(this); - if (port4 != null) { radio.setSFDPort(port4, CC2420_SFD); - } + } else { + throw new EmulationException("Could not setup mote - missing USCI B0"); } } ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/core/Timer.java | 2 +- se/sics/mspsim/platform/esb/ESBGui.java | 7 +-- se/sics/mspsim/platform/esb/ESBNode.java | 36 ++++++--------- se/sics/mspsim/platform/jcreate/JCreateNode.java | 35 ++++++-------- se/sics/mspsim/platform/sky/CC2420Node.java | 54 ++++++++-------------- se/sics/mspsim/platform/ti/Exp5438Node.java | 50 +++++--------------- se/sics/mspsim/platform/tyndall/TyndallNode.java | 55 ++++++---------------- se/sics/mspsim/platform/z1/Z1Node.java | 35 +++++--------- 8 files changed, 93 insertions(+), 181 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-05-15 13:25:56
|
The branch "master" has been updated via 4bb3c2e5f3cb53c5013bc1b526d7f50b760bdfb3 (commit) from 213677fc011e18451b7196197be5565c216cb48b (commit) Changed paths: M se/sics/mspsim/chip/CC2520.java - Log ----------------------------------------------------------------- commit 4bb3c2e5f3cb53c5013bc1b526d7f50b760bdfb3 Author: Joakim Eriksson <jo...@si...> Date: Tue May 15 15:25:36 2012 +0200 fixed channel calculations diff --git a/se/sics/mspsim/chip/CC2520.java b/se/sics/mspsim/chip/CC2520.java index df5fb22..664c834 100644 --- a/se/sics/mspsim/chip/CC2520.java +++ b/se/sics/mspsim/chip/CC2520.java @@ -1234,8 +1234,9 @@ private void setRxOverflow() { *****************************************************************************/ public void updateActiveFrequency() { /* INVERTED: f = 5 * (c - 11) + 357 + 0x4000 */ - activeFrequency = memory[REG_FSCTRL] - 357 + 2405 - 0x4000; - activeChannel = (memory[REG_FSCTRL] - 357 - 0x4000)/5 + 11; + int freg = memory[REG_FREQCTRL] & 0x7f; + activeFrequency = freg + 2394; + activeChannel = 11 + (freg - 11) / 5; } public int getActiveFrequency() { ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/chip/CC2520.java | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-05-15 13:12:23
|
The branch "master" has been updated via 213677fc011e18451b7196197be5565c216cb48b (commit) from 74a7b02958035678b41e6be84b2f3bd808f62247 (commit) Changed paths: M se/sics/mspsim/platform/wismote/WismoteNode.java - Log ----------------------------------------------------------------- commit 213677fc011e18451b7196197be5565c216cb48b Author: Joakim Eriksson <jo...@si...> Date: Tue May 15 15:11:48 2012 +0200 fixed output diff --git a/se/sics/mspsim/platform/wismote/WismoteNode.java b/se/sics/mspsim/platform/wismote/WismoteNode.java index 25e6298..37e9142 100644 --- a/se/sics/mspsim/platform/wismote/WismoteNode.java +++ b/se/sics/mspsim/platform/wismote/WismoteNode.java @@ -175,7 +175,7 @@ public void setupNode() { setupGUI(); // Add some windows for listening to serial output - IOUnit usart = cpu.getIOUnit("USCI A0"); + IOUnit usart = cpu.getIOUnit("USCI A1"); if (usart instanceof USARTSource) { SerialMon serial = new SerialMon((USARTSource)usart, "USCI A0 Port Output"); registry.registerComponent("serialgui", serial); ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/platform/wismote/WismoteNode.java | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-05-15 13:06:31
|
The branch "master" has been updated via 74a7b02958035678b41e6be84b2f3bd808f62247 (commit) from cca03fcfde150a98e95a8d6ce228307089858962 (commit) Changed paths: M se/sics/mspsim/chip/CC2520.java M se/sics/mspsim/chip/CC2520SPI.java - Log ----------------------------------------------------------------- commit 74a7b02958035678b41e6be84b2f3bd808f62247 Author: Joakim Eriksson <jo...@si...> Date: Tue May 15 15:06:17 2012 +0200 added reading data from RXFIFO diff --git a/se/sics/mspsim/chip/CC2520.java b/se/sics/mspsim/chip/CC2520.java index 37b552e..df5fb22 100644 --- a/se/sics/mspsim/chip/CC2520.java +++ b/se/sics/mspsim/chip/CC2520.java @@ -1162,14 +1162,6 @@ void flushTX() { private void updateCCA() { boolean oldCCA = cca; - // int ccaMux = (memory[REG_IOCFG1] & CCAMUX); - - // if (ccaMux == CCAMUX_CCA) { - // /* If RSSI is less than -95 then we have CCA / clear channel! */ - // cca = (status & STATUS_RSSI_VALID) > 0 && rssi < -95; - // } else if (ccaMux == CCAMUX_XOSC16M_STABLE) { - // cca = (status & STATUS_XOSC16M_STABLE) > 0; - // } cca = (status & STATUS_RSSI_VALID) > 0 && rssi < -95; @@ -1478,4 +1470,42 @@ public int getSPIlen() { return spiLen; } + /* reads one byte from RX fifo */ + public void readRXFifo() { + int fifoData = rxFIFO.read(); + if (DEBUG) log("RXFIFO READ: " + rxFIFO.stateToString()); + outputSPI = fifoData; + + /* first check and clear FIFOP - since we now have read a byte! */ + if (currentFIFOP && !overflow) { + /* FIFOP is lowered when rxFIFO is lower than or equal to fifopThr */ + if(rxFIFO.length() <= fifopThr) { + if (DEBUG) log("*** FIFOP cleared at: " + rxFIFO.stateToString()); + setFIFOP(false); + } + } + + /* initiate read of another packet - update some variables to keep track of packet reading... */ + if (rxfifoReadLeft == 0) { + rxfifoReadLeft = fifoData; + if (DEBUG) log("Init read of packet - len: " + rxfifoReadLeft + + " fifo: " + rxFIFO.stateToString()); + } else if (--rxfifoReadLeft == 0) { + /* check if we have another packet in buffer */ + if (rxFIFO.length() > 0) { + /* check if the packet is complete or longer than fifopThr */ + if (rxFIFO.length() > rxFIFO.peek(0) || + (rxFIFO.length() > fifopThr && !decodeAddress && !frameRejected)) { + if (DEBUG) log("More in FIFO - FIFOP = 1! plen: " + rxFIFO.stateToString()); + if (!overflow) setFIFOP(true); + } + } + } + // Set the FIFO pin low if there are no more bytes available in the RXFIFO. + if (rxFIFO.length() == 0) { + if (DEBUG) log("Setting FIFO to low (buffer empty)"); + setFIFO(false); + } + } + } // CC2520 diff --git a/se/sics/mspsim/chip/CC2520SPI.java b/se/sics/mspsim/chip/CC2520SPI.java index 9710c19..91d0e77 100644 --- a/se/sics/mspsim/chip/CC2520SPI.java +++ b/se/sics/mspsim/chip/CC2520SPI.java @@ -57,7 +57,15 @@ public boolean dataReceived(int data) { } public void executeSPICommand() {} }, - new SPICommand("RXBUF 0 0 1 1 0 0 0 0 - - - - - - - - ...",cc2520), + new SPICommand("RXBUF 0 0 1 1 0 0 0 0 - - - - - - - - ...",cc2520) { + public boolean dataReceived(int data) { + /* second byte is fifo data instead of status... */ + if (spiData.getSPIlen() > 1) { + cc2520.readRXFifo(); + } + return true; + } + }, new SPICommand("RXBUFCP 0 0 1 1 1 0 0 0 0 0 0 0 a a a a a a a a a a a a - - - - - - - - ...",cc2520), new SPICommand("RXBUFMOV 0 0 1 1 0 0 1 p c c c c c c c c 0 0 0 0 a a a a a a a a a a a a",cc2520), new SPICommand("TXBUF 0 0 1 1 1 0 1 0 d d d d d d d d d d d d d d d d ...",cc2520) { ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/chip/CC2520.java | 46 +++++++++++++++++++++++++++++------ se/sics/mspsim/chip/CC2520SPI.java | 10 +++++++- 2 files changed, 47 insertions(+), 9 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-05-15 12:52:25
|
The branch "master" has been updated via cca03fcfde150a98e95a8d6ce228307089858962 (commit) from d32d80e23fa5805d4c6ccb83c4c3008209a21f65 (commit) Changed paths: M se/sics/mspsim/chip/CC2520.java M se/sics/mspsim/chip/CC2520SPI.java - Log ----------------------------------------------------------------- commit cca03fcfde150a98e95a8d6ce228307089858962 Author: Joakim Eriksson <jo...@si...> Date: Tue May 15 14:52:09 2012 +0200 fixed more commands - TX probably works diff --git a/se/sics/mspsim/chip/CC2520.java b/se/sics/mspsim/chip/CC2520.java index 945d619..37b552e 100644 --- a/se/sics/mspsim/chip/CC2520.java +++ b/se/sics/mspsim/chip/CC2520.java @@ -413,11 +413,7 @@ public void execute(long t) { status |= STATUS_XOSC16M_STABLE; if(DEBUG) log("Oscillator Stable Event."); setState(RadioState.IDLE); -// if( (memory[REG_IOCFG1] & CCAMUX) == CCAMUX_XOSC16M_STABLE) { -// updateCCA(); -// } else { -// if(DEBUG) log("CCAMUX != CCA_XOSC16M_STABLE! Not raising CCA"); -// } + updateCCA(); } }; @@ -500,8 +496,6 @@ public CC2520(MSP430Core cpu) { } -// memory[REG_SNOP] = 0; -// memory[REG_TXCTRL] = 0xa0ff; setModeNames(MODE_NAMES); setMode(MODE_POWER_OFF); currentFIFOP = false; @@ -519,7 +513,6 @@ private void updateGPIOConfig() { } private void reset() { -// setReg(REG_MDMCTRL0, 0x0ae2); memory[REG_RSSISTAT] = 0; /* back to default configuration of GPIOs */ @@ -942,6 +935,18 @@ void rxon() { } } + void rxtxoff() { + if (DEBUG) { + log("Strobe RXTX-OFF!!! at " + cpu.cycles); + if (stateMachine == RadioState.TX_ACK || + stateMachine == RadioState.TX_FRAME || + stateMachine == RadioState.RX_FRAME) { + log("WARNING: turning off RXTX during " + stateMachine); + } + } + setState(RadioState.IDLE); + } + void stxon() { // State transition valid from IDLE state or all RX states if( (stateMachine == RadioState.IDLE) || @@ -983,71 +988,14 @@ void stxoncca() { } } - // Needs to get information about when it is possible to write - // next data... - private void strobe(int data) { - // Resets, on/off of different things... - if (DEBUG) { - log("Strobe on: " + Utils.hex8(data)); // + " => " + Reg.values()[data]); - } - - if( (stateMachine == RadioState.POWER_DOWN) && (data != INS_SXOSCON) ) { - if (DEBUG) log("Got command strobe: " + data + " in POWER_DOWN. Ignoring."); - return; - } - - switch (data) { - case INS_SNOP: - if (DEBUG) log("SNOP => " + Utils.hex8(status) + " at " + cpu.cycles); - break; - case INS_SRFOFF: - if (DEBUG) { - log("Strobe RXTX-OFF!!! at " + cpu.cycles); - if (stateMachine == RadioState.TX_ACK || - stateMachine == RadioState.TX_FRAME || - stateMachine == RadioState.RX_FRAME) { - log("WARNING: turning off RXTX during " + stateMachine); - } - } - setState(RadioState.IDLE); - break; - case INS_STXON: - stxon(); - break; - case INS_STXONCCA: - stxoncca(); - break; - case INS_SFLUSHRX: - flushRX(); - break; - case INS_SFLUSHTX: - if (DEBUG) log("Flushing TXFIFO"); - flushTX(); - break; - case INS_SXOSCON: - //log("Strobe Oscillator On"); - startOscillator(); - break; - case INS_SXOSCOFF: - //log("Strobe Oscillator Off"); - stopOscillator(); - break; - case INS_SACK: - case INS_SACKPEND: + void sack(boolean pend) { // Set the frame pending flag for all future autoack based on SACK/SACKPEND - ackFramePending = data == INS_SACKPEND; + ackFramePending = pend; if (stateMachine == RadioState.RX_FRAME) { shouldAck = true; } else if (crcOk) { setState(RadioState.TX_ACK_CALIBRATE); } - break; - default: - if (DEBUG) { - log("Unknown strobe command: " + data); - } - break; - } } private void shrNext() { @@ -1158,7 +1106,7 @@ void startOscillator() { cpu.scheduleTimeEventMillis(oscillatorEvent, 1); } - private void stopOscillator() { + void stopOscillator() { status &= ~STATUS_XOSC16M_STABLE; setState(RadioState.POWER_DOWN); if (DEBUG) log("Oscillator Off."); @@ -1213,7 +1161,7 @@ void flushTX() { } private void updateCCA() { - // boolean oldCCA = cca; + boolean oldCCA = cca; // int ccaMux = (memory[REG_IOCFG1] & CCAMUX); // if (ccaMux == CCAMUX_CCA) { @@ -1223,9 +1171,11 @@ private void updateCCA() { // cca = (status & STATUS_XOSC16M_STABLE) > 0; // } - // if (cca != oldCCA) { - // setInternalCCA(cca); - // } + cca = (status & STATUS_RSSI_VALID) > 0 && rssi < -95; + + if (cca != oldCCA) { + setInternalCCA(cca); + } } private void setInternalCCA(boolean clear) { diff --git a/se/sics/mspsim/chip/CC2520SPI.java b/se/sics/mspsim/chip/CC2520SPI.java index 552c8e2..9710c19 100644 --- a/se/sics/mspsim/chip/CC2520SPI.java +++ b/se/sics/mspsim/chip/CC2520SPI.java @@ -92,8 +92,16 @@ public void executeSPICommand() { cc2520.stxoncca(); } }, - new SPICommand("SRFOFF 0 1 0 0 0 1 0 1",cc2520), - new SPICommand("SXOSCOFF 0 1 0 0 0 1 1 0",cc2520), + new SPICommand("SRFOFF 0 1 0 0 0 1 0 1",cc2520) { + public void executeSPICommand() { + cc2520.rxtxoff(); + } + }, + new SPICommand("SXOSCOFF 0 1 0 0 0 1 1 0",cc2520) { + public void executeSPICommand() { + cc2520.stopOscillator(); + } + }, new SPICommand("SFLUSHRX 0 1 0 0 0 1 1 1",cc2520) { public void executeSPICommand() { cc2520.flushRX(); @@ -104,8 +112,16 @@ public void executeSPICommand() { cc2520.flushTX(); } }, - new SPICommand("SACK 0 1 0 0 1 0 0 1",cc2520), - new SPICommand("SACKPEND 0 1 0 0 1 0 1 0",cc2520), + new SPICommand("SACK 0 1 0 0 1 0 0 1",cc2520) { + public void executeSPICommand() { + cc2520.sack(false); + } + }, + new SPICommand("SACKPEND 0 1 0 0 1 0 1 0",cc2520) { + public void executeSPICommand() { + cc2520.sack(true); + } + }, new SPICommand("SNACK 0 1 0 0 1 0 1 1",cc2520), new SPICommand("SRXMASKBITSET 0 1 0 0 1 1 0 0",cc2520), new SPICommand("SRXMASKBITCLR 0 1 0 0 1 1 0 1",cc2520), ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/chip/CC2520.java | 104 +++++++++-------------------------- se/sics/mspsim/chip/CC2520SPI.java | 26 +++++++-- 2 files changed, 48 insertions(+), 82 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-05-15 12:36:01
|
The branch "master" has been updated via d32d80e23fa5805d4c6ccb83c4c3008209a21f65 (commit) from 5146a540cfa9313afe3db4fde17a7a1f0e80111f (commit) Changed paths: M se/sics/mspsim/chip/CC2520.java M se/sics/mspsim/chip/CC2520SPI.java - Log ----------------------------------------------------------------- commit d32d80e23fa5805d4c6ccb83c4c3008209a21f65 Author: Joakim Eriksson <jo...@si...> Date: Tue May 15 14:35:39 2012 +0200 more functionality of CC2520 diff --git a/se/sics/mspsim/chip/CC2520.java b/se/sics/mspsim/chip/CC2520.java index 31ff60b..945d619 100644 --- a/se/sics/mspsim/chip/CC2520.java +++ b/se/sics/mspsim/chip/CC2520.java @@ -340,11 +340,6 @@ public int getFSMState() { private static final int[] BC_ADDRESS = new int[] {0xff, 0xff}; - private int instruction = -1; - - private int usartDataPos; - private int usartDataAddress; - private int usartDataValue; private int shrPos; private int txfifoPos; private boolean txfifoFlush; // TXFIFO is automatically flushed on next write @@ -352,7 +347,6 @@ public int getFSMState() { private int rxlen; private int rxread; private int zeroSymbols; - private boolean ramRead = false; /* RSSI is an externally set value of the RSSI for this CC2520 */ /* low RSSI => CCA = true in normal mode */ @@ -516,11 +510,22 @@ public CC2520(MSP430Core cpu) { reset(); } + private void updateGPIOConfig() { + int bit = 1; + for (int i = 0; i < gpio.length; i++) { + gpio[i].setPolarity((memory[REG_GPIOPOLARITY] & bit) > 0); + bit = bit << 1; + } + } + private void reset() { // setReg(REG_MDMCTRL0, 0x0ae2); memory[REG_RSSISTAT] = 0; /* back to default configuration of GPIOs */ + memory[REG_GPIOPOLARITY] = 0x3f; + updateGPIOConfig(); + fifoGPIO = gpio[1]; fifopGPIO = gpio[2]; ccaGPIO = gpio[3]; @@ -832,6 +837,7 @@ void writeMemory(int address, int data) { case REG_GPIOPOLARITY: if (DEBUG) log("GIOPOLARITY: 0x" + Utils.hex16(oldValue) + " => 0x" + Utils.hex16(data)); if (oldValue != data) { + updateGPIOConfig(); // Polarity has changed - must update pins setFIFOP(currentFIFOP); setFIFO(currentFIFO); @@ -921,128 +927,18 @@ public void dataReceived(USARTSource source, int data) { spiLen = 0; } } - - if (instruction == -1) { - // New instruction - if ((data & 0xc0) == INS_REGRD) { - // Register read -// source.byteReceived(oldStatus); - source.byteReceived(memory[data & 0x3f]); - return; - } - if ((data & 0xc0) == INS_REGWR) { - // Register write - instruction = data; source.byteReceived(outputSPI); - return; - } - if ((data & 0xf0) == INS_MEMRD || (data & 0xf0) == INS_MEMWR) { - // Memory read or write - instruction = data; - source.byteReceived(outputSPI); - return; } - switch (data & 0xff) { - case INS_SNOP: - // Do nothing - break; - case INS_IBUFLD: - instruction = data & 0xff; - break; - case INS_SIBUFEX: -// strobe(ibufld); -// ibufld = INS_SNOP; - break; - case INS_SSAMPLECCA: - break; - case INS_SRES: - break; - case INS_RXBUF: - break; - case INS_RXBUFCP: - break; - case INS_RXBUFMOV: - break; - case INS_TXBUF: - break; - case INS_TXBUFCP: - break; - case INS_RANDOM: - break; - case INS_SXOSCON: - break; - case INS_STXCAL: - break; - case INS_SRXON: - break; - case INS_STXON: - break; - case INS_STXONCCA: - break; - case INS_SRFOFF: - break; - case INS_SXOSCOFF: - break; - case INS_SFLUSHRX: - break; - case INS_SFLUSHTX: - break; - case INS_SACK: - break; - case INS_SACKPEND: - break; - case INS_SNACK: - break; - case INS_SRXMASKBITSET: - break; - case INS_SRXMASKBITCLR: - break; - case INS_RXMASKAND: - break; - case INS_RXMASKOR: - break; - case INS_MEMCP: - break; - case INS_MEMCPR: - break; - case INS_MEMXCP: - break; - case INS_MEMXWR: - break; - case INS_BCLR: - break; - case INS_BSET: - break; - case INS_CTR: - break; - case INS_CBCMAC: - break; - case INS_UCBCMAC: - break; - case INS_CCM: - break; - case INS_UCCM: - break; - case INS_ECB: - break; - case INS_ECBO: - break; - case INS_ECBX: - break; - case INS_ECBXO: - break; - case INS_INC: - break; - case INS_ABORT: - break; - default: - // Unknown instruction - logw("**** Warning - unknown instruction sent to CC2520: " + data); - break; + void rxon() { + if(stateMachine == RadioState.IDLE) { + setState(RadioState.RX_CALIBRATE); + //updateActiveFrequency(); + if (DEBUG) { + log("Strobe RX-ON!!!"); } - source.byteReceived(outputSPI); - return; + } else { + if (DEBUG) log("WARNING: SRXON when not IDLE"); } } @@ -1104,18 +1000,6 @@ private void strobe(int data) { case INS_SNOP: if (DEBUG) log("SNOP => " + Utils.hex8(status) + " at " + cpu.cycles); break; - case INS_SRXON: - if(stateMachine == RadioState.IDLE) { - setState(RadioState.RX_CALIBRATE); - //updateActiveFrequency(); - if (DEBUG) { - log("Strobe RX-ON!!!"); - } - } else { - if (DEBUG) log("WARNING: SRXON when not IDLE"); - } - - break; case INS_SRFOFF: if (DEBUG) { log("Strobe RXTX-OFF!!! at " + cpu.cycles); @@ -1269,7 +1153,7 @@ private void setSymbolEvent(int symbols) { //log("Set Symbol event: " + period); } - private void startOscillator() { + void startOscillator() { // 1ms crystal startup from datasheet pg12 cpu.scheduleTimeEventMillis(oscillatorEvent, 1); } @@ -1549,20 +1433,10 @@ public void setVRegOn(boolean newOn) { public void setChipSelect(boolean select) { chipSelect = select; if (!chipSelect) { -// if (state == SpiState.WRITE_REGISTER && usartDataPos == 1) { -// // Register write incomplete. Do a 8 bit register write. -// usartDataValue = (memory[usartDataAddress] & 0xff) | (usartDataValue & 0xff00); -// if (DEBUG) { -// log("wrote 8 MSB to 0x" + Utils.hex8(usartDataAddress) + " = " + usartDataValue); -// } -// setReg(usartDataAddress, usartDataValue); -// } - instruction = -1; spiLen = 0; if (command != null) command.executeSPICommand(); command = null; -// state = SpiState.WAITING; } if (DEBUG) { @@ -1615,13 +1489,14 @@ private String getLongAddress() { @Override public String info() { updateActiveFrequency(); + String commandStr = command == null ? "<waiting>" : command.name; return " VREG_ON: " + isRadioOn + " Chip Select: " + chipSelect + " OSC Stable: " + ((status & STATUS_XOSC16M_STABLE) > 0) + "\n RSSI Valid: " + ((status & STATUS_RSSI_VALID) > 0) + " CCA: " + cca + - "\n FIFOP Polarity: " + ((memory[REG_GPIOPOLARITY] & FIFOP_POLARITY) == FIFOP_POLARITY) + + "\n GPIO Polarity: " + Utils.hex8(memory[REG_GPIOPOLARITY]) + " FIFOP: " + currentFIFOP + " FIFO: " + currentFIFO + " SFD: " + currentSFD + "\n " + rxFIFO.stateToString() + " expPacketLen: " + rxlen + - "\n Radio State: " + stateMachine + " SPI State: " + command + + "\n Radio State: " + stateMachine + " SPI State: " + commandStr + "\n AutoACK: " + autoAck + " AddrDecode: " + addressDecode + " AutoCRC: " + autoCRC + "\n PanID: 0x" + Utils.hex8(memory[RAM_PANID + 1]) + Utils.hex8(memory[RAM_PANID]) + " ShortAddr: 0x" + Utils.hex8(memory[RAM_SHORTADDR + 1]) + Utils.hex8(memory[RAM_SHORTADDR]) + diff --git a/se/sics/mspsim/chip/CC2520SPI.java b/se/sics/mspsim/chip/CC2520SPI.java index cd8b9e1..552c8e2 100644 --- a/se/sics/mspsim/chip/CC2520SPI.java +++ b/se/sics/mspsim/chip/CC2520SPI.java @@ -63,7 +63,6 @@ public void executeSPICommand() {} new SPICommand("TXBUF 0 0 1 1 1 0 1 0 d d d d d d d d d d d d d d d d ...",cc2520) { public boolean dataReceived(int data) { if (spiData.getSPIlen() > 1) { - System.out.printf("Writing %x to TXFIFO\n", data); cc2520.writeTXFIFO(data); } return true; @@ -72,9 +71,17 @@ public void executeSPICommand() {} }, new SPICommand("TXBUFCP 0 0 1 1 1 1 1 p c c c c c c c c 0 0 0 0 a a a a a a a a a a a a",cc2520), new SPICommand("RANDOM 0 0 1 1 1 1 0 0 - - - - - - - - - - - - - - - - ...",cc2520), - new SPICommand("SXOSCON 0 1 0 0 0 0 0 0",cc2520), + new SPICommand("SXOSCON 0 1 0 0 0 0 0 0",cc2520) { + public void executeSPICommand() { + cc2520.startOscillator(); + } + }, new SPICommand("STXCAL 0 1 0 0 0 0 0 1",cc2520), - new SPICommand("SRXON 0 1 0 0 0 0 1 0",cc2520), + new SPICommand("SRXON 0 1 0 0 0 0 1 0",cc2520) { + public void executeSPICommand() { + cc2520.rxon(); + } + }, new SPICommand("STXON 0 1 0 0 0 0 1 1",cc2520) { public void executeSPICommand() { cc2520.stxon(); ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/chip/CC2520.java | 179 ++++++------------------------------ se/sics/mspsim/chip/CC2520SPI.java | 13 ++- 2 files changed, 37 insertions(+), 155 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-05-15 10:39:18
|
The branch "master" has been updated via 5146a540cfa9313afe3db4fde17a7a1f0e80111f (commit) from 10cb6a85d01198c069143d3e98087b5074ac2846 (commit) Changed paths: M se/sics/mspsim/chip/CC2520.java M se/sics/mspsim/chip/CC2520SPI.java - Log ----------------------------------------------------------------- commit 5146a540cfa9313afe3db4fde17a7a1f0e80111f Author: Joakim Eriksson <jo...@si...> Date: Tue May 15 12:38:57 2012 +0200 fixed some more bugs diff --git a/se/sics/mspsim/chip/CC2520.java b/se/sics/mspsim/chip/CC2520.java index 405fa07..31ff60b 100644 --- a/se/sics/mspsim/chip/CC2520.java +++ b/se/sics/mspsim/chip/CC2520.java @@ -901,7 +901,9 @@ public void dataReceived(USARTSource source, int data) { if (command == null) { logw("**** Warning - not implemented command on SPI: " + data); } else { - logw("CC2520: found command " + command.name); + if (!"SNOP".equals(command.name)) { + logw("Found command " + command.name); + } } } diff --git a/se/sics/mspsim/chip/CC2520SPI.java b/se/sics/mspsim/chip/CC2520SPI.java index ef2beae..cd8b9e1 100644 --- a/se/sics/mspsim/chip/CC2520SPI.java +++ b/se/sics/mspsim/chip/CC2520SPI.java @@ -63,10 +63,12 @@ public void executeSPICommand() {} new SPICommand("TXBUF 0 0 1 1 1 0 1 0 d d d d d d d d d d d d d d d d ...",cc2520) { public boolean dataReceived(int data) { if (spiData.getSPIlen() > 1) { + System.out.printf("Writing %x to TXFIFO\n", data); cc2520.writeTXFIFO(data); } return true; } + public void executeSPICommand() {} }, new SPICommand("TXBUFCP 0 0 1 1 1 1 1 p c c c c c c c c 0 0 0 0 a a a a a a a a a a a a",cc2520), new SPICommand("RANDOM 0 0 1 1 1 1 0 0 - - - - - - - - - - - - - - - - ...",cc2520), ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/chip/CC2520.java | 4 +++- se/sics/mspsim/chip/CC2520SPI.java | 2 ++ 2 files changed, 5 insertions(+), 1 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-05-15 10:28:43
|
The branch "master" has been updated via 10cb6a85d01198c069143d3e98087b5074ac2846 (commit) from 7d5978210bfa1ebe8d6c61042438b725a6600f04 (commit) Changed paths: M se/sics/mspsim/chip/CC2520.java M se/sics/mspsim/chip/CC2520SPI.java M se/sics/mspsim/chip/SPICommand.java - Log ----------------------------------------------------------------- commit 10cb6a85d01198c069143d3e98087b5074ac2846 Author: Joakim Eriksson <jo...@si...> Date: Tue May 15 12:28:24 2012 +0200 fixed some bugs added write/read mem diff --git a/se/sics/mspsim/chip/CC2520.java b/se/sics/mspsim/chip/CC2520.java index 5111c66..405fa07 100644 --- a/se/sics/mspsim/chip/CC2520.java +++ b/se/sics/mspsim/chip/CC2520.java @@ -233,7 +233,7 @@ public void setActive(boolean isActive) { public static final int STATUS_TX_ACTIVE = 1 << 1; public static final int STATUS_RX_ACTIVE = 1 << 0; - // Exceptions (bits in the EXCFLAGx registers) + // Exceptions (bits in the EXCFLAGx memory) public final static int EXC_RF_IDLE = 1 << 0; public final static int EXC_TX_FRM_DONE = 1 << 1; public final static int EXC_RX_FRM_ABORTED = 0x20; @@ -255,11 +255,11 @@ public void setActive(boolean isActive) { /* one single byte instruction can be stored in the IBUF */ int instructionBuffer = 0; - // IOCFG0 Register Bit masks + // IOCFG0 memory Bit masks public static final int BCN_ACCEPT = (1<<11); public static final int FIFOP_THR = 0x7F; - // IOCFG1 Register Bit Masks + // IOCFG1 memory Bit Masks // public static final int SFDMUX = 0x3E0; // public static final int CCAMUX = 0x1F; @@ -388,7 +388,6 @@ public int getFSMState() { //private int status = STATUS_XOSC16M_STABLE | STATUS_RSSI_VALID; private int status = 0; - private final int[] registers = new int[128]; private final int[] memory = new int[0x400]; /* total memory */ private CC2520SPI cc2520SPI = new CC2520SPI(this); @@ -420,7 +419,7 @@ public void execute(long t) { status |= STATUS_XOSC16M_STABLE; if(DEBUG) log("Oscillator Stable Event."); setState(RadioState.IDLE); -// if( (registers[REG_IOCFG1] & CCAMUX) == CCAMUX_XOSC16M_STABLE) { +// if( (memory[REG_IOCFG1] & CCAMUX) == CCAMUX_XOSC16M_STABLE) { // updateCCA(); // } else { // if(DEBUG) log("CCAMUX != CCA_XOSC16M_STABLE! Not raising CCA"); @@ -465,7 +464,7 @@ public void execute(long t) { /* this will be called 8 symbols after first SFD_SEARCH */ case RX_SFD_SEARCH: status |= STATUS_RSSI_VALID; - registers[REG_RSSISTAT] = 1; + memory[REG_RSSISTAT] = 1; updateCCA(); break; @@ -507,8 +506,8 @@ public CC2520(MSP430Core cpu) { } -// registers[REG_SNOP] = 0; -// registers[REG_TXCTRL] = 0xa0ff; +// memory[REG_SNOP] = 0; +// memory[REG_TXCTRL] = 0xa0ff; setModeNames(MODE_NAMES); setMode(MODE_POWER_OFF); currentFIFOP = false; @@ -519,7 +518,7 @@ public CC2520(MSP430Core cpu) { private void reset() { // setReg(REG_MDMCTRL0, 0x0ae2); - registers[REG_RSSISTAT] = 0; + memory[REG_RSSISTAT] = 0; /* back to default configuration of GPIOs */ fifoGPIO = gpio[1]; @@ -538,7 +537,7 @@ private boolean setState(RadioState state) { if(DEBUG) log("State transition from " + stateMachine + " to " + state); stateMachine = state; /* write to FSM state register */ - registers[REG_FSMSTAT0] = (registers[REG_FSMSTAT0] & 0x3f);//state.getFSMState(); + memory[REG_FSMSTAT0] = (memory[REG_FSMSTAT0] & 0x3f);//state.getFSMState(); switch(stateMachine) { @@ -547,7 +546,7 @@ private boolean setState(RadioState state) { flushRX(); flushTX(); status &= ~(STATUS_RSSI_VALID | STATUS_XOSC16M_STABLE); - registers[REG_RSSISTAT] = 0; + memory[REG_RSSISTAT] = 0; crcOk = false; reset(); setMode(MODE_POWER_OFF); @@ -557,7 +556,7 @@ private boolean setState(RadioState state) { case POWER_DOWN: rxFIFO.reset(); status &= ~(STATUS_RSSI_VALID | STATUS_XOSC16M_STABLE); - registers[REG_RSSISTAT] = 0; + memory[REG_RSSISTAT] = 0; crcOk = false; reset(); setMode(MODE_POWER_OFF); @@ -612,7 +611,7 @@ private boolean setState(RadioState state) { case IDLE: status &= ~STATUS_RSSI_VALID; - registers[REG_RSSISTAT] = 0; + memory[REG_RSSISTAT] = 0; setMode(MODE_TXRX_OFF); updateCCA(); break; @@ -791,7 +790,7 @@ public void receivedByte(byte data) { log("CRC not OK: recv:" + Utils.hex16(crc) + " calc: " + Utils.hex16(rxCrc.getCRCBitrev())); } // Should take a RSSI value as input or use a set-RSSI value... - rxFIFO.set(-2, registers[REG_RSSI] & 0xff); + rxFIFO.set(-2, memory[REG_RSSI] & 0xff); rxFIFO.set(-1, (corrval & 0x7F) | (crcOk ? 0x80 : 0)); // memory[RAM_RXFIFO + ((rxfifoWritePos + 128 - 2) & 127)] = ; // // Set CRC ok and add a correlation - TODO: fix better correlation value!!! @@ -820,18 +819,11 @@ public void receivedByte(byte data) { } } - /* API used in CC2520 SPI for both registers and memory */ + /* API used in CC2520 SPI for both memory and memory */ void writeMemory(int address, int data) { - - } - - int readMemory(int address) { - return memory[address]; - } - - private void setReg(int address, int data) { - int oldValue = registers[address]; - registers[address] = data; + System.out.printf("CC2520: writing to %x => %x\n", address, data); + int oldValue = memory[address]; + memory[address] = data; switch(address) { case REG_FIFOPCTRL: fifopThr = data & FIFOP_THR; @@ -847,13 +839,13 @@ private void setReg(int address, int data) { setCCA(currentCCA); } break; -// case REG_IOCFG1: -// if (DEBUG) -// log("IOCFG1: SFDMUX " -// + ((registers[address] & SFDMUX) >> SFDMUX) -// + " CCAMUX: " + (registers[address] & CCAMUX)); -// updateCCA(); -// break; + // case REG_IOCFG1: + // if (DEBUG) + // log("IOCFG1: SFDMUX " + // + ((memory[address] & SFDMUX) >> SFDMUX) + // + " CCAMUX: " + (memory[address] & CCAMUX)); + // updateCCA(); + // break; case REG_MDMCTRL0: addressDecode = (data & ADR_DECODE) != 0; autoCRC = (data & ADR_AUTOCRC) != 0; @@ -874,6 +866,10 @@ private void setReg(int address, int data) { configurationChanged(address, oldValue, data); } + int readMemory(int address) { + return memory[address]; + } + /* the data that should be SPI response */ int outputSPI; public void outputSPI(int data) { @@ -904,6 +900,8 @@ public void dataReceived(USARTSource source, int data) { command = cc2520SPI.getCommand(data); if (command == null) { logw("**** Warning - not implemented command on SPI: " + data); + } else { + logw("CC2520: found command " + command.name); } } @@ -915,9 +913,10 @@ public void dataReceived(USARTSource source, int data) { if (command != null) { command.dataReceived(data); if (spiLen == command.commandLen) { - System.out.println("CC2520 Executing command: " + command.name); +// System.out.println("CC2520 Executing command: " + command.name); command.executeSPICommand(); command = null; + spiLen = 0; } } @@ -926,7 +925,7 @@ public void dataReceived(USARTSource source, int data) { if ((data & 0xc0) == INS_REGRD) { // Register read // source.byteReceived(oldStatus); - source.byteReceived(registers[data & 0x3f]); + source.byteReceived(memory[data & 0x3f]); return; } if ((data & 0xc0) == INS_REGWR) { @@ -1329,7 +1328,7 @@ void flushTX() { private void updateCCA() { // boolean oldCCA = cca; - // int ccaMux = (registers[REG_IOCFG1] & CCAMUX); + // int ccaMux = (memory[REG_IOCFG1] & CCAMUX); // if (ccaMux == CCAMUX_CCA) { // /* If RSSI is less than -95 then we have CCA / clear channel! */ @@ -1351,7 +1350,7 @@ private void setInternalCCA(boolean clear) { private void setSFD(boolean sfd) { currentSFD = sfd; sfdGPIO.setActive(sfd); -// if( (registers[REG_GPIOPOLARITY] & SFD_POLARITY) == SFD_POLARITY) +// if( (memory[REG_GPIOPOLARITY] & SFD_POLARITY) == SFD_POLARITY) // sfdPort.setPinState(sfdPin, sfd ? 0 : 1); // else // sfdPort.setPinState(sfdPin, sfd ? 1 : 0); @@ -1362,7 +1361,7 @@ private void setCCA(boolean cca) { currentCCA = cca; ccaGPIO.setActive(cca); if (DEBUG) log("Setting CCA to: " + cca); -// if( (registers[REG_GPIOPOLARITY] & CCA_POLARITY) == CCA_POLARITY) +// if( (memory[REG_GPIOPOLARITY] & CCA_POLARITY) == CCA_POLARITY) // ccaPort.setPinState(ccaPin, cca ? 0 : 1); // else // ccaPort.setPinState(ccaPin, cca ? 1 : 0); @@ -1372,7 +1371,7 @@ private void setFIFOP(boolean fifop) { currentFIFOP = fifop; fifopGPIO.setActive(fifop); // if (DEBUG) log("Setting FIFOP to " + fifop); -// if( (registers[REG_GPIOPOLARITY] & FIFOP_POLARITY) == FIFOP_POLARITY) { +// if( (memory[REG_GPIOPOLARITY] & FIFOP_POLARITY) == FIFOP_POLARITY) { // fifopPort.setPinState(fifopPin, fifop ? 0 : 1); // } else { // fifopPort.setPinState(fifopPin, fifop ? 1 : 0); @@ -1383,7 +1382,7 @@ private void setFIFO(boolean fifo) { currentFIFO = fifo; fifoGPIO.setActive(fifo); if (DEBUG) log("Setting FIFO to " + fifo); -// if((registers[REG_GPIOPOLARITY] & FIFO_POLARITY) == FIFO_POLARITY) { +// if((memory[REG_GPIOPOLARITY] & FIFO_POLARITY) == FIFO_POLARITY) { // fifoPort.setPinState(fifoPin, fifo ? 0 : 1); // } else { // fifoPort.setPinState(fifoPin, fifo ? 1 : 0); @@ -1407,8 +1406,8 @@ private void setRxOverflow() { *****************************************************************************/ public void updateActiveFrequency() { /* INVERTED: f = 5 * (c - 11) + 357 + 0x4000 */ - activeFrequency = registers[REG_FSCTRL] - 357 + 2405 - 0x4000; - activeChannel = (registers[REG_FSCTRL] - 357 - 0x4000)/5 + 11; + activeFrequency = memory[REG_FSCTRL] - 357 + 2405 - 0x4000; + activeChannel = (memory[REG_FSCTRL] - 357 - 0x4000)/5 + 11; } public int getActiveFrequency() { @@ -1420,7 +1419,7 @@ public int getActiveChannel() { } public int getOutputPowerIndicator() { - return (registers[REG_TXPOWER] & 0x1f); + return (memory[REG_TXPOWER] & 0x1f); } /** @@ -1447,7 +1446,7 @@ public void setRSSI(int power) { if (DEBUG) log("external setRSSI to: " + power); rssi = power; - registers[REG_RSSI] = power - RSSI_OFFSET; + memory[REG_RSSI] = power - RSSI_OFFSET; updateCCA(); } @@ -1550,7 +1549,7 @@ public void setChipSelect(boolean select) { if (!chipSelect) { // if (state == SpiState.WRITE_REGISTER && usartDataPos == 1) { // // Register write incomplete. Do a 8 bit register write. -// usartDataValue = (registers[usartDataAddress] & 0xff) | (usartDataValue & 0xff00); +// usartDataValue = (memory[usartDataAddress] & 0xff) | (usartDataValue & 0xff00); // if (DEBUG) { // log("wrote 8 MSB to 0x" + Utils.hex8(usartDataAddress) + " = " + usartDataValue); // } @@ -1558,6 +1557,8 @@ public void setChipSelect(boolean select) { // } instruction = -1; spiLen = 0; + if (command != null) + command.executeSPICommand(); command = null; // state = SpiState.WAITING; } @@ -1575,38 +1576,18 @@ public boolean getChipSelect() { public void setGPIO(int index, IOPort port, int pin) { gpio[index].setConfig(port, pin); } -// public void setCCAPort(IOPort port, int pin) { -// ccaPort = port; -// ccaPin = pin; -// } -// -// public void setFIFOPPort(IOPort port, int pin) { -// fifopPort = port; -// fifopPin = pin; -// } -// -// public void setFIFOPort(IOPort port, int pin) { -// fifoPort = port; -// fifoPin = pin; -// } -// -// public void setSFDPort(IOPort port, int pin) { -// sfdPort = port; -// sfdPin = pin; -// } - // ------------------------------------------------------------------- - // Methods for accessing and writing to registers, etc from outside + // Methods for accessing and writing to memory, etc from outside // And for receiving data // ------------------------------------------------------------------- public int getRegister(int register) { - return registers[register]; + return memory[register]; } public void setRegister(int register, int data) { - registers[register] = data; + memory[register] = data; } /***************************************************************************** @@ -1635,7 +1616,7 @@ public String info() { return " VREG_ON: " + isRadioOn + " Chip Select: " + chipSelect + " OSC Stable: " + ((status & STATUS_XOSC16M_STABLE) > 0) + "\n RSSI Valid: " + ((status & STATUS_RSSI_VALID) > 0) + " CCA: " + cca + - "\n FIFOP Polarity: " + ((registers[REG_GPIOPOLARITY] & FIFOP_POLARITY) == FIFOP_POLARITY) + + "\n FIFOP Polarity: " + ((memory[REG_GPIOPOLARITY] & FIFOP_POLARITY) == FIFOP_POLARITY) + " FIFOP: " + currentFIFOP + " FIFO: " + currentFIFO + " SFD: " + currentSFD + "\n " + rxFIFO.stateToString() + " expPacketLen: " + rxlen + "\n Radio State: " + stateMachine + " SPI State: " + command + @@ -1655,7 +1636,7 @@ public void stateChanged(int state) { /* return data in register at the correct position */ @Override public int getConfiguration(int parameter) { - return registers[parameter]; + return memory[parameter]; } @@ -1667,7 +1648,7 @@ public int getConfiguration(int parameter) { @Override public int getSPIlen() { - return 0; + return spiLen; } } // CC2520 diff --git a/se/sics/mspsim/chip/CC2520SPI.java b/se/sics/mspsim/chip/CC2520SPI.java index c2b941e..ef2beae 100644 --- a/se/sics/mspsim/chip/CC2520SPI.java +++ b/se/sics/mspsim/chip/CC2520SPI.java @@ -22,8 +22,41 @@ public void executeSPICommand() { new SPICommand("SIBUFEX 0 0 0 0 0 0 1 1",cc2520), new SPICommand("SSAMPLECCA 0 0 0 0 0 1 0 0",cc2520), new SPICommand("SRES 0 0 0 0 1 1 1 1 - - - - - - - -",cc2520), - new SPICommand("MEMRD 0 0 0 1 a a a a a a a a a a a a - - - - - - - - ...",cc2520), - new SPICommand("MEMWR 0 0 1 0 a a a a a a a a a a a a d d d d d d d d ...",cc2520), + new SPICommand("MEMRD 0 0 0 1 a a a a a a a a a a a a - - - - - - - - ...",cc2520) { + BitField adr = getBitField("a"); + int cAdr = 0; + public boolean dataReceived(int data) { + /* check if this is first two bytes*/ + if (spiData.getSPIlen() == 2) { + cAdr = adr.getValue(); + } else if (spiData.getSPIlen() > 2){ + spiData.outputSPI(cc2520.readMemory(cAdr)); + cAdr = (cAdr + 1) & 0x3ff; + } + return true; + } + public void executeSPICommand() {} + }, + new SPICommand("MEMWR 0 0 1 0 a a a a a a a a a a a a d d d d d d d d ...",cc2520) { + BitField adr = getBitField("a"); + int cAdr = -1; + public boolean dataReceived(int data) { + /* check if this is first two bytes*/ + int len = spiData.getSPIlen(); + int sdata[] = spiData.getSPIData(); + if (len == 2) { + cAdr = adr.getValue(); +// System.out.println("SPI BitValue: [" + adr.startBit + " - " + +// adr.endBit + "] mask:" + adr.firstMask); +// System.out.printf("SPI Data: %02x %02x => adr:%x\n", sdata[0], sdata[1], cAdr); + } else if (len > 2){ + cc2520.writeMemory(cAdr, data); + cAdr = (cAdr + 1) & 0x3ff; + } + return true; + } + public void executeSPICommand() {} + }, new SPICommand("RXBUF 0 0 1 1 0 0 0 0 - - - - - - - - ...",cc2520), new SPICommand("RXBUFCP 0 0 1 1 1 0 0 0 0 0 0 0 a a a a a a a a a a a a - - - - - - - - ...",cc2520), new SPICommand("RXBUFMOV 0 0 1 1 0 0 1 p c c c c c c c c 0 0 0 0 a a a a a a a a a a a a",cc2520), diff --git a/se/sics/mspsim/chip/SPICommand.java b/se/sics/mspsim/chip/SPICommand.java index b52abfb..2c68ac2 100644 --- a/se/sics/mspsim/chip/SPICommand.java +++ b/se/sics/mspsim/chip/SPICommand.java @@ -36,10 +36,11 @@ public int getValue() { int firstByte = startBit / 8; int lastByte = endBit / 8; int nrBitsRoll = 7 - endBit & 7; + int data[] = spiData.getSPIData(); + value = data[firstByte] & firstMask; - value = spiData.getSPIData()[firstByte] & firstMask; - for (int i = firstByte + 1; i < lastByte; i++) { - value = value << 8 + spiData.getSPIData()[firstByte]; + for (int i = firstByte + 1; i < lastByte + 1; i++) { + value = (value << 8) + data[i]; } value = value >> nrBitsRoll; ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/chip/CC2520.java | 123 +++++++++++++++-------------------- se/sics/mspsim/chip/CC2520SPI.java | 37 ++++++++++- se/sics/mspsim/chip/SPICommand.java | 9 ++- 3 files changed, 92 insertions(+), 77 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-05-15 09:31:33
|
The branch "master" has been updated via 7d5978210bfa1ebe8d6c61042438b725a6600f04 (commit) from e0a6c1c9dafc0513c3af874555a12bb5cc42d9fd (commit) Changed paths: M Makefile M se/sics/mspsim/chip/CC2520.java M se/sics/mspsim/chip/CC2520SPI.java - Log ----------------------------------------------------------------- commit 7d5978210bfa1ebe8d6c61042438b725a6600f04 Author: Joakim Eriksson <jo...@si...> Date: Tue May 15 11:31:13 2012 +0200 fixed some minor bugs diff --git a/Makefile b/Makefile index 9579034..e5bedbd 100644 --- a/Makefile +++ b/Makefile @@ -75,7 +75,7 @@ TIMERTEST := tests/timertest.firmware SCRIPTS := ${addprefix scripts/,autorun.sc duty.sc} BINARY := README.txt license.txt CHANGE_LOG.txt images/*.jpg firmware/*/*.firmware ${SCRIPTS} -PACKAGES := se/sics/mspsim ${addprefix se/sics/mspsim/,core chip cli config debug platform ${addprefix platform/,esb sky jcreate sentillausb z1 tyndall ti} plugin profiler net ui util extutil/highlight extutil/jfreechart} +PACKAGES := se/sics/mspsim ${addprefix se/sics/mspsim/,core chip cli config debug platform ${addprefix platform/,esb sky jcreate sentillausb z1 tyndall ti wismote} plugin profiler net ui util extutil/highlight extutil/jfreechart} SOURCES := ${wildcard *.java $(addsuffix /*.java,$(PACKAGES))} diff --git a/se/sics/mspsim/chip/CC2520.java b/se/sics/mspsim/chip/CC2520.java index e89f43f..5111c66 100644 --- a/se/sics/mspsim/chip/CC2520.java +++ b/se/sics/mspsim/chip/CC2520.java @@ -389,7 +389,7 @@ public int getFSMState() { private int status = 0; private final int[] registers = new int[128]; - private final int[] memory = new int[384 + 128]; + private final int[] memory = new int[0x400]; /* total memory */ private CC2520SPI cc2520SPI = new CC2520SPI(this); private SPICommand command; @@ -909,7 +909,8 @@ public void dataReceived(USARTSource source, int data) { /* command handling */ spiData[spiLen] = data; - if (spiLen < spiData.length) spiLen++; + /* ensure that we do not store too many spiDatas */ + if (spiLen < (spiData.length - 1)) spiLen++; if (command != null) { command.dataReceived(data); @@ -1062,6 +1063,29 @@ void stxon() { } } + void stxoncca() { + // Only valid from all RX states, + // since CCA requires ??(look this up) receive symbol periods to be valid + if( (stateMachine == RadioState.RX_CALIBRATE) || + (stateMachine == RadioState.RX_SFD_SEARCH) || + (stateMachine == RadioState.RX_FRAME) || + (stateMachine == RadioState.RX_OVERFLOW) || + (stateMachine == RadioState.RX_WAIT)) { + + if (sendEvents) { + sendEvent("STXON_CCA", null); + } + + if(cca) { + status |= STATUS_TX_ACTIVE; + setState(RadioState.TX_CALIBRATE); + if (DEBUG) log("Strobe STXONCCA - transmit on! at " + cpu.cycles); + }else{ + if (DEBUG) log("STXONCCA Ignored, CCA false"); + } + } + } + // Needs to get information about when it is possible to write // next data... private void strobe(int data) { @@ -1106,26 +1130,7 @@ private void strobe(int data) { stxon(); break; case INS_STXONCCA: - // Only valid from all RX states, - // since CCA requires ??(look this up) receive symbol periods to be valid - if( (stateMachine == RadioState.RX_CALIBRATE) || - (stateMachine == RadioState.RX_SFD_SEARCH) || - (stateMachine == RadioState.RX_FRAME) || - (stateMachine == RadioState.RX_OVERFLOW) || - (stateMachine == RadioState.RX_WAIT)) { - - if (sendEvents) { - sendEvent("STXON_CCA", null); - } - - if(cca) { - status |= STATUS_TX_ACTIVE; - setState(RadioState.TX_CALIBRATE); - if (DEBUG) log("Strobe STXONCCA - transmit on! at " + cpu.cycles); - }else{ - if (DEBUG) log("STXONCCA Ignored, CCA false"); - } - } + stxoncca(); break; case INS_SFLUSHRX: flushRX(); diff --git a/se/sics/mspsim/chip/CC2520SPI.java b/se/sics/mspsim/chip/CC2520SPI.java index 0a13aac..c2b941e 100644 --- a/se/sics/mspsim/chip/CC2520SPI.java +++ b/se/sics/mspsim/chip/CC2520SPI.java @@ -8,6 +8,7 @@ public CC2520SPI(CC2520 cc) { /* the SPI commands for CC2520 */ + cc2520 = cc; SPICommand[] spiCommands = { new SPICommand("SNOP 0 0 0 0 0 0 0 0",cc2520) { public void executeSPICommand() {} @@ -44,7 +45,11 @@ public void executeSPICommand() { cc2520.stxon(); } }, - new SPICommand("STXONCCA 0 1 0 0 0 1 0 0",cc2520), + new SPICommand("STXONCCA 0 1 0 0 0 1 0 0",cc2520) { + public void executeSPICommand() { + cc2520.stxoncca(); + } + }, new SPICommand("SRFOFF 0 1 0 0 0 1 0 1",cc2520), new SPICommand("SXOSCOFF 0 1 0 0 0 1 1 0",cc2520), new SPICommand("SFLUSHRX 0 1 0 0 0 1 1 1",cc2520) { ----------------------------------------------------------------------- Summary of changes: Makefile | 2 +- se/sics/mspsim/chip/CC2520.java | 49 +++++++++++++++++++---------------- se/sics/mspsim/chip/CC2520SPI.java | 7 ++++- 3 files changed, 34 insertions(+), 24 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-05-15 07:21:31
|
The branch "master" has been updated via e0a6c1c9dafc0513c3af874555a12bb5cc42d9fd (commit) from 38fe5db6f184aeefdfe1ac3de43ad9f892a96920 (commit) Changed paths: M Makefile - Log ----------------------------------------------------------------- commit e0a6c1c9dafc0513c3af874555a12bb5cc42d9fd Author: Joakim Eriksson <jo...@si...> Date: Tue May 15 09:21:15 2012 +0200 fixed makefile bug diff --git a/Makefile b/Makefile index 81c6268..9579034 100644 --- a/Makefile +++ b/Makefile @@ -121,6 +121,7 @@ $(JARFILE): $(OBJECTS) %.wismote: jar java -jar $(JARFILE) -platform=wismote $(ARGS) $@ + help: @echo "Usage: make [all,compile,clean,run,runsky,runesb]" ----------------------------------------------------------------------- Summary of changes: Makefile | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-05-15 07:19:02
|
The branch "master" has been updated via 38fe5db6f184aeefdfe1ac3de43ad9f892a96920 (commit) from 4b4f9bd00d5c4b0dd1a85e567d9abd30a3fb0d92 (commit) Changed paths: M Makefile - Log ----------------------------------------------------------------- commit 38fe5db6f184aeefdfe1ac3de43ad9f892a96920 Author: Joakim Eriksson <jo...@si...> Date: Tue May 15 09:18:49 2012 +0200 added rule for wismote diff --git a/Makefile b/Makefile index 33b6fb7..81c6268 100644 --- a/Makefile +++ b/Makefile @@ -119,6 +119,8 @@ $(JARFILE): $(OBJECTS) %.tyndall: jar java -jar $(JARFILE) -platform=tyndall $(ARGS) $@ +%.wismote: jar + java -jar $(JARFILE) -platform=wismote $(ARGS) $@ help: @echo "Usage: make [all,compile,clean,run,runsky,runesb]" ----------------------------------------------------------------------- Summary of changes: Makefile | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-05-15 06:56:55
|
The branch "master" has been updated via 4b4f9bd00d5c4b0dd1a85e567d9abd30a3fb0d92 (commit) via fdf35261012b04471f4966804ea8bbe15709878a (commit) from 8171e1fc16a889e6805dd76beeba36ef38159c02 (commit) Changed paths: A se/sics/mspsim/platform/wismote/WismoteNode.java - Log ----------------------------------------------------------------- commit 4b4f9bd00d5c4b0dd1a85e567d9abd30a3fb0d92 Author: Joakim Eriksson <jo...@si...> Date: Tue May 15 08:56:35 2012 +0200 fixed GPIO config diff --git a/se/sics/mspsim/platform/wismote/WismoteNode.java b/se/sics/mspsim/platform/wismote/WismoteNode.java index d3c9d01..25e6298 100644 --- a/se/sics/mspsim/platform/wismote/WismoteNode.java +++ b/se/sics/mspsim/platform/wismote/WismoteNode.java @@ -138,13 +138,14 @@ private void setupNodePorts() { IOUnit usart0 = cpu.getIOUnit("USCI B0"); if (usart0 instanceof USARTSource) { + radio = new CC2520(cpu); - radio.setCCAPort(port1, CC2520_CCA); - radio.setFIFOPPort(port1, CC2520_FIFOP); - radio.setFIFOPort(port1, CC2520_FIFO); + radio.setGPIO(1, port1, CC2520_FIFO); + radio.setGPIO(3, port1, CC2520_CCA); + radio.setGPIO(2, port1, CC2520_FIFOP); + radio.setGPIO(4, port2, CC2520_SFD); ((USARTSource) usart0).addUSARTListener(this); - radio.setSFDPort(port2, CC2520_SFD); } else { throw new EmulationException("Could not setup wismote mote - missing USCI B0"); } commit fdf35261012b04471f4966804ea8bbe15709878a Author: Joakim Eriksson <jo...@si...> Date: Tue May 15 08:53:25 2012 +0200 added wismote diff --git a/se/sics/mspsim/platform/wismote/WismoteNode.java b/se/sics/mspsim/platform/wismote/WismoteNode.java new file mode 100644 index 0000000..d3c9d01 --- /dev/null +++ b/se/sics/mspsim/platform/wismote/WismoteNode.java @@ -0,0 +1,199 @@ +/** + * Copyright (c) 2012, 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. + * + * ----------------------------------------------------------------- + * + * WismoteNode + * + * Author : Niclas Finne + */ + +package se.sics.mspsim.platform.wismote; +import java.io.IOException; + +import se.sics.mspsim.chip.CC2520; +import se.sics.mspsim.config.MSP430f5437Config; +import se.sics.mspsim.core.EmulationException; +import se.sics.mspsim.core.IOPort; +import se.sics.mspsim.core.IOUnit; +import se.sics.mspsim.core.PortListener; +import se.sics.mspsim.core.USARTListener; +import se.sics.mspsim.core.USARTSource; +import se.sics.mspsim.platform.GenericNode; +import se.sics.mspsim.ui.SerialMon; +import se.sics.mspsim.util.ArgumentManager; + +public class WismoteNode extends GenericNode implements PortListener, USARTListener { + + /* P1.6 - Input: FIFOP from CC2520 */ + /* P1.5 - Input: FIFO from CC2520 */ + /* P1.7 - Input: CCA from CC2520 */ + public static final int CC2520_FIFOP = 6; + public static final int CC2520_FIFO = 5; + public static final int CC2520_CCA = 7; + /* P2.0 - Input: SFD from CC2520 */ + public static final int CC2520_SFD = 0; + /* P3.0 - Output: SPI Chip Select (CS_N) */ + public static final int CC2520_CHIP_SELECT = 0x01; + /* P4.3 - Output: VREG_EN to CC2520 */ + public static final int CC2520_VREG = 1 << 3; + /* P4.4 - Output: RESET_N to CC2520 */ + public static final int CC2520_RESET = 1 << 4; + + /* P8.6 - Red led */ + public static final int LEDS_CONF_RED = 1 << 6; + /* P2.4 - Green led */ + public static final int LEDS_CONF_GREEN = 1 << 4; + /* P5.2 - Yellow led */ + public static final int LEDS_CONF_YELLOW = 1 << 2; + + //private M25P80 flash; + //private String flashFile; + private CC2520 radio; + + public WismoteNode() { + super("Wismote", new MSP430f5437Config()); + } + +// public M25P80 getFlash() { +// return flash; +// } + +// public void setFlash(M25P80 flash) { +// this.flash = flash; +// registry.registerComponent("xmem", flash); +// } + + public void dataReceived(USARTSource source, int data) { + radio.dataReceived(source, data); + //flash.dataReceived(source, data); + /* if nothing selected, just write back a random byte to these devs */ + if (!radio.getChipSelect() /*&& !flash.getChipSelect()*/) { + source.byteReceived(0); + } + } + + public void portWrite(IOPort source, int data) { + switch (source.getPort()) { + case 2: + //System.out.println("LEDS GREEN = " + ((data & LEDS_CONF_GREEN) > 0)); + break; + case 3: + // Chip select = active low... + radio.setChipSelect((data & CC2520_CHIP_SELECT) == 0); + break; + case 4: + //radio.portWrite(source, data); + //flash.portWrite(source, data); + radio.setVRegOn((data & CC2520_VREG) != 0); + break; + case 5: + //System.out.println("LEDS YELLOW = " + ((data & LEDS_CONF_YELLOW) > 0)); + break; + case 8: + //System.out.println("LEDS RED = " + ((data & LEDS_CONF_RED) > 0)); + break; + } + } + + private void setupNodePorts() { +// if (flashFile != null) { +// setFlash(new FileM25P80(cpu, flashFile)); +// } + + IOPort port1 = cpu.getIOUnit(IOPort.class, "P1"); + port1.addPortListener(this); + IOPort port2 = cpu.getIOUnit(IOPort.class, "P2"); + port2.addPortListener(this); + cpu.getIOUnit(IOPort.class, "P3").addPortListener(this); + cpu.getIOUnit(IOPort.class, "P4").addPortListener(this); + cpu.getIOUnit(IOPort.class, "P5").addPortListener(this); + cpu.getIOUnit(IOPort.class, "P8").addPortListener(this); + + IOUnit usart0 = cpu.getIOUnit("USCI B0"); + if (usart0 instanceof USARTSource) { + radio = new CC2520(cpu); + radio.setCCAPort(port1, CC2520_CCA); + radio.setFIFOPPort(port1, CC2520_FIFOP); + radio.setFIFOPort(port1, CC2520_FIFO); + + ((USARTSource) usart0).addUSARTListener(this); + radio.setSFDPort(port2, CC2520_SFD); + } else { + throw new EmulationException("Could not setup wismote mote - missing USCI B0"); + } + } + + public void setupNode() { + // create a filename for the flash file + // This should be possible to take from a config file later! + String fileName = config.getProperty("flashfile"); + if (fileName == null) { + fileName = firmwareFile; + if (fileName != null) { + int ix = fileName.lastIndexOf('.'); + if (ix > 0) { + fileName = fileName.substring(0, ix); + } + fileName = fileName + ".flash"; + } + } + if (DEBUG) System.out.println("Using flash file: " + (fileName == null ? "no file" : fileName)); + + //this.flashFile = fileName; + + setupNodePorts(); + + if (!config.getPropertyAsBoolean("nogui", true)) { + setupGUI(); + + // Add some windows for listening to serial output + IOUnit usart = cpu.getIOUnit("USCI A0"); + if (usart instanceof USARTSource) { + SerialMon serial = new SerialMon((USARTSource)usart, "USCI A0 Port Output"); + registry.registerComponent("serialgui", serial); + } + } + } + + public void setupGUI() { + System.out.println("No gui for Wismote yet..."); + } + + public int getModeMax() { + return 0; + } + + public static void main(String[] args) throws IOException { + WismoteNode node = new WismoteNode(); + ArgumentManager config = new ArgumentManager(); + config.handleArguments(args); + node.setupArgs(config); + } +} ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/platform/wismote/WismoteNode.java | 200 ++++++++++++++++++++++ 1 files changed, 200 insertions(+), 0 deletions(-) create mode 100644 se/sics/mspsim/platform/wismote/WismoteNode.java hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-05-15 05:17:55
|
The branch "master" has been updated via 8171e1fc16a889e6805dd76beeba36ef38159c02 (commit) from 893cd81906c3d928d2f79479f1e5c1115018c9fc (commit) Changed paths: M se/sics/mspsim/chip/CC2520.java M se/sics/mspsim/chip/CC2520SPI.java - Log ----------------------------------------------------------------- commit 8171e1fc16a889e6805dd76beeba36ef38159c02 Author: Joakim Eriksson <jo...@si...> Date: Tue May 15 07:17:36 2012 +0200 removed old CC2420 code and connected FIFO Write + TX diff --git a/se/sics/mspsim/chip/CC2520.java b/se/sics/mspsim/chip/CC2520.java index 7564b34..e89f43f 100644 --- a/se/sics/mspsim/chip/CC2520.java +++ b/se/sics/mspsim/chip/CC2520.java @@ -255,11 +255,6 @@ public void setActive(boolean isActive) { /* one single byte instruction can be stored in the IBUF */ int instructionBuffer = 0; - public enum SpiState { - WAITING, WRITE_REGISTER, READ_REGISTER, RAM_ACCESS, - READ_RXFIFO, WRITE_TXFIFO - }; - // IOCFG0 Register Bit masks public static final int BCN_ACCEPT = (1<<11); public static final int FIFOP_THR = 0x7F; @@ -345,9 +340,7 @@ public int getFSMState() { private static final int[] BC_ADDRESS = new int[] {0xff, 0xff}; - private SpiState state = SpiState.WAITING; private int instruction = -1; - private int ibufld = INS_SNOP; private int usartDataPos; private int usartDataAddress; @@ -827,6 +820,15 @@ public void receivedByte(byte data) { } } + /* API used in CC2520 SPI for both registers and memory */ + void writeMemory(int address, int data) { + + } + + int readMemory(int address) { + return memory[address]; + } + private void setReg(int address, int data) { int oldValue = registers[address]; registers[address] = data; @@ -883,7 +885,7 @@ public void dataReceived(USARTSource source, int data) { if (DEBUG) { log("byte received: " + Utils.hex8(data) + " (" + ((data >= ' ' && data <= 'Z') ? (char) data : '.') + ')' + - " CS: " + chipSelect + " SPI state: " + state + " StateMachine: " + stateMachine); + " CS: " + chipSelect + " SPI state: " + 0 + " StateMachine: " + stateMachine); } if (!chipSelect) { @@ -905,8 +907,10 @@ public void dataReceived(USARTSource source, int data) { } } + /* command handling */ spiData[spiLen] = data; if (spiLen < spiData.length) spiLen++; + if (command != null) { command.dataReceived(data); if (spiLen == command.commandLen) { @@ -945,8 +949,8 @@ public void dataReceived(USARTSource source, int data) { instruction = data & 0xff; break; case INS_SIBUFEX: - strobe(ibufld); - ibufld = INS_SNOP; +// strobe(ibufld); +// ibufld = INS_SNOP; break; case INS_SSAMPLECCA: break; @@ -1038,164 +1042,6 @@ public void dataReceived(USARTSource source, int data) { source.byteReceived(outputSPI); return; } - -// switch (instruction) { -// case WAITING: -// if ((data & FLAG_READ) != 0) { -// state = SpiState.READ_REGISTER; -// } else { -// state = SpiState.WRITE_REGISTER; -// } -// if ((data & FLAG_RAM) != 0) { -// state = SpiState.RAM_ACCESS; -// usartDataAddress = data & 0x7f; -// } else { -// // The register address -// usartDataAddress = data & 0x3f; -// -// if (usartDataAddress == REG_RXFIFO) { -// // check read/write??? -// // log("Reading RXFIFO!!!"); -// state = SpiState.READ_RXFIFO; -// } else if (usartDataAddress == REG_TXFIFO) { -// state = SpiState.WRITE_TXFIFO; -// } -// } -// if (data < 0x0f) { -// strobe(data); -// state = SpiState.WAITING; -// } -// usartDataPos = 0; -// // Assuming that the status always is sent back??? -// //source.byteReceived(status); -// break; -// -// case WRITE_REGISTER: -// if (usartDataPos == 0) { -// source.byteReceived(registers[usartDataAddress] >> 8); -// // set the high bits -// usartDataValue = data << 8; -// // registers[usartDataAddress] = (registers[usartDataAddress] & 0xff) | (data << 8); -// usartDataPos = 1; -// } else { -// source.byteReceived(registers[usartDataAddress] & 0xff); -// // set the low bits -// usartDataValue |= data; -// // registers[usartDataAddress] = (registers[usartDataAddress] & 0xff00) | data; -// -// if (DEBUG) { -// log("wrote to " + Utils.hex8(usartDataAddress) + " = " + usartDataValue); -// } -// setReg(usartDataAddress, usartDataValue); -// /* register written - go back to waiting... */ -// state = SpiState.WAITING; -// } -// break; -// case READ_REGISTER: -// if (usartDataPos == 0) { -// source.byteReceived(registers[usartDataAddress] >> 8); -// usartDataPos = 1; -// } else { -// source.byteReceived(registers[usartDataAddress] & 0xff); -// if (DEBUG) { -// log("read from " + Utils.hex8(usartDataAddress) + " = " -// + registers[usartDataAddress]); -// } -// state = SpiState.WAITING; -// } -// return; -// //break; -// case READ_RXFIFO: { -// int fifoData = rxFIFO.read(); -// if (DEBUG) log("RXFIFO READ: " + rxFIFO.stateToString()); -// source.byteReceived(fifoData); -// -// /* first check and clear FIFOP - since we now have read a byte! */ -// if (currentFIFOP && !overflow) { -// /* FIFOP is lowered when rxFIFO is lower than or equal to fifopThr */ -// if(rxFIFO.length() <= fifopThr) { -// if (DEBUG) log("*** FIFOP cleared at: " + rxFIFO.stateToString()); -// setFIFOP(false); -// } -// } -// -// /* initiate read of another packet - update some variables to keep track of packet reading... */ -// if (rxfifoReadLeft == 0) { -// rxfifoReadLeft = fifoData; -// if (DEBUG) log("Init read of packet - len: " + rxfifoReadLeft + -// " fifo: " + rxFIFO.stateToString()); -// } else if (--rxfifoReadLeft == 0) { -// /* check if we have another packet in buffer */ -// if (rxFIFO.length() > 0) { -// /* check if the packet is complete or longer than fifopThr */ -// if (rxFIFO.length() > rxFIFO.peek(0) || -// (rxFIFO.length() > fifopThr && !decodeAddress && !frameRejected)) { -// if (DEBUG) log("More in FIFO - FIFOP = 1! plen: " + rxFIFO.stateToString()); -// if (!overflow) setFIFOP(true); -// } -// } -// } -// // Set the FIFO pin low if there are no more bytes available in the RXFIFO. -// if (rxFIFO.length() == 0) { -// if (DEBUG) log("Setting FIFO to low (buffer empty)"); -// setFIFO(false); -// } -// } -// return; /* avoid returning the status byte */ -// case WRITE_TXFIFO: -// if(txfifoFlush) { -// txCursor = 0; -// txfifoFlush = false; -// } -// if (DEBUG) log("Writing data: " + data + " to tx: " + txCursor); -// -// if(txCursor == 0) { -// if ((data & 0xff) > 127) { -// logger.warning(this, "CC2520: Warning - packet size too large: " + (data & 0xff)); -// } -// } else if (txCursor > 127) { -// logger.warning(this, "CC2520: Warning - TX Cursor wrapped"); -// txCursor = 0; -// } -// memory[RAM_TXFIFO + txCursor] = data & 0xff; -// txCursor++; -// if (sendEvents) { -// sendEvent("WRITE_TXFIFO", null); -// } -// break; -// case RAM_ACCESS: -// if (usartDataPos == 0) { -// usartDataAddress |= (data << 1) & 0x180; -// ramRead = (data & FLAG_RAM_READ) != 0; -// if (DEBUG) { -// log("Address: " + Utils.hex16(usartDataAddress) + " read: " + ramRead); -// } -// usartDataPos++; -// } else { -// if (!ramRead) { -// memory[usartDataAddress++] = data; -// if (usartDataAddress >= 0x180) { -// logger.warning(this, "CC2520: Warning - RAM position too big - wrapping!"); -// usartDataAddress = 0; -// } -// if (DEBUG && usartDataAddress == RAM_PANID + 2) { -// log("Pan ID set to: 0x" + -// Utils.hex8(memory[RAM_PANID]) + -// Utils.hex8(memory[RAM_PANID + 1])); -// } -// } else { -// //log("Read RAM Addr: " + address + " Data: " + memory[address]); -// source.byteReceived(memory[usartDataAddress++]); -// if (usartDataAddress >= 0x180) { -// logger.warning(this, "CC2520: Warning - RAM position too big - wrapping!"); -// usartDataAddress = 0; -// } -// return; -// } -// } -// break; -// } -// source.byteReceived(oldStatus); } void stxon() { @@ -1430,7 +1276,7 @@ private void stopOscillator() { setFIFOP(false); } - private void flushRX() { + void flushRX() { if (DEBUG) { log("Flushing RX len = " + rxFIFO.length()); } @@ -1449,8 +1295,30 @@ private void flushRX() { } } + void writeTXFIFO(int data) { + if(txfifoFlush) { + txCursor = 0; + txfifoFlush = false; + } + if (DEBUG) log("Writing data: " + data + " to tx: " + txCursor); + + if(txCursor == 0) { + if ((data & 0xff) > 127) { + logger.warning(this, "CC2420: Warning - packet size too large: " + (data & 0xff)); + } + } else if (txCursor > 127) { + logger.warning(this, "CC2420: Warning - TX Cursor wrapped"); + txCursor = 0; + } + memory[RAM_TXFIFO + txCursor] = data & 0xff; + txCursor++; + if (sendEvents) { + sendEvent("WRITE_TXFIFO", null); + } + } + // TODO: update any pins here? - private void flushTX() { + void flushTX() { txCursor = 0; } @@ -1765,7 +1633,7 @@ public String info() { "\n FIFOP Polarity: " + ((registers[REG_GPIOPOLARITY] & FIFOP_POLARITY) == FIFOP_POLARITY) + " FIFOP: " + currentFIFOP + " FIFO: " + currentFIFO + " SFD: " + currentSFD + "\n " + rxFIFO.stateToString() + " expPacketLen: " + rxlen + - "\n Radio State: " + stateMachine + " SPI State: " + state + + "\n Radio State: " + stateMachine + " SPI State: " + command + "\n AutoACK: " + autoAck + " AddrDecode: " + addressDecode + " AutoCRC: " + autoCRC + "\n PanID: 0x" + Utils.hex8(memory[RAM_PANID + 1]) + Utils.hex8(memory[RAM_PANID]) + " ShortAddr: 0x" + Utils.hex8(memory[RAM_SHORTADDR + 1]) + Utils.hex8(memory[RAM_SHORTADDR]) + diff --git a/se/sics/mspsim/chip/CC2520SPI.java b/se/sics/mspsim/chip/CC2520SPI.java index c5b2596..0a13aac 100644 --- a/se/sics/mspsim/chip/CC2520SPI.java +++ b/se/sics/mspsim/chip/CC2520SPI.java @@ -26,7 +26,14 @@ public void executeSPICommand() { new SPICommand("RXBUF 0 0 1 1 0 0 0 0 - - - - - - - - ...",cc2520), new SPICommand("RXBUFCP 0 0 1 1 1 0 0 0 0 0 0 0 a a a a a a a a a a a a - - - - - - - - ...",cc2520), new SPICommand("RXBUFMOV 0 0 1 1 0 0 1 p c c c c c c c c 0 0 0 0 a a a a a a a a a a a a",cc2520), - new SPICommand("TXBUF 0 0 1 1 1 0 1 0 d d d d d d d d d d d d d d d d ...",cc2520), + new SPICommand("TXBUF 0 0 1 1 1 0 1 0 d d d d d d d d d d d d d d d d ...",cc2520) { + public boolean dataReceived(int data) { + if (spiData.getSPIlen() > 1) { + cc2520.writeTXFIFO(data); + } + return true; + } + }, new SPICommand("TXBUFCP 0 0 1 1 1 1 1 p c c c c c c c c 0 0 0 0 a a a a a a a a a a a a",cc2520), new SPICommand("RANDOM 0 0 1 1 1 1 0 0 - - - - - - - - - - - - - - - - ...",cc2520), new SPICommand("SXOSCON 0 1 0 0 0 0 0 0",cc2520), @@ -40,8 +47,16 @@ public void executeSPICommand() { new SPICommand("STXONCCA 0 1 0 0 0 1 0 0",cc2520), new SPICommand("SRFOFF 0 1 0 0 0 1 0 1",cc2520), new SPICommand("SXOSCOFF 0 1 0 0 0 1 1 0",cc2520), - new SPICommand("SFLUSHRX 0 1 0 0 0 1 1 1",cc2520), - new SPICommand("SFLUSHTX 0 1 0 0 1 0 0 0",cc2520), + new SPICommand("SFLUSHRX 0 1 0 0 0 1 1 1",cc2520) { + public void executeSPICommand() { + cc2520.flushRX(); + } + }, + new SPICommand("SFLUSHTX 0 1 0 0 1 0 0 0",cc2520) { + public void executeSPICommand() { + cc2520.flushTX(); + } + }, new SPICommand("SACK 0 1 0 0 1 0 0 1",cc2520), new SPICommand("SACKPEND 0 1 0 0 1 0 1 0",cc2520), new SPICommand("SNACK 0 1 0 0 1 0 1 1",cc2520), @@ -70,16 +85,31 @@ public void executeSPICommand() { int cAdr = 0; public boolean dataReceived(int data) { /* check if this is first byte*/ - if (spiData.getSPIlen() == 0) { + if (spiData.getSPIlen() == 1) { cAdr = adr.getValue(); } else { - spiData.outputSPI(memory[cAdr++]); + spiData.outputSPI(cc2520.readMemory(cAdr)); + cAdr = (cAdr + 1) & 0x7f; } return true; } public void executeSPICommand() {} }, - new SPICommand("REGWR 1 1 a a a a a a d d d d d d d d ...",cc2520)}; + new SPICommand("REGWR 1 1 a a a a a a d d d d d d d d ...",cc2520) { + BitField adr = getBitField("a"); + int cAdr = 0; + public boolean dataReceived(int data) { + /* check if this is first byte*/ + if (spiData.getSPIlen() == 1) { + cAdr = adr.getValue(); + } else { + cc2520.writeMemory(cAdr, data); + cAdr = (cAdr + 1) & 0x7f; + } + return true; + } + public void executeSPICommand() {} + }}; /* set up the commands */ for (int i = 0; i < spiCommands.length; i++) { ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/chip/CC2520.java | 210 +++++++----------------------------- se/sics/mspsim/chip/CC2520SPI.java | 42 ++++++- 2 files changed, 75 insertions(+), 177 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-05-15 04:48:34
|
The branch "master" has been updated via 893cd81906c3d928d2f79479f1e5c1115018c9fc (commit) from 31dfdad8e5b7a903340f30e0ebfc99ae2b3b4681 (commit) Changed paths: M se/sics/mspsim/chip/CC2520.java M se/sics/mspsim/chip/CC2520SPI.java M se/sics/mspsim/chip/SPICommand.java - Log ----------------------------------------------------------------- commit 893cd81906c3d928d2f79479f1e5c1115018c9fc Author: Joakim Eriksson <jo...@si...> Date: Tue May 15 06:48:00 2012 +0200 connected CC2520 SPI with commands diff --git a/se/sics/mspsim/chip/CC2520.java b/se/sics/mspsim/chip/CC2520.java index 884f963..7564b34 100644 --- a/se/sics/mspsim/chip/CC2520.java +++ b/se/sics/mspsim/chip/CC2520.java @@ -398,6 +398,8 @@ public int getFSMState() { private final int[] registers = new int[128]; private final int[] memory = new int[384 + 128]; + private CC2520SPI cc2520SPI = new CC2520SPI(this); + private SPICommand command; private int[] spiData = new int[20]; /* SPI data buffer */ private int spiLen; @@ -896,6 +898,24 @@ public void dataReceived(USARTSource source, int data) { return; } + if (command == null) { + command = cc2520SPI.getCommand(data); + if (command == null) { + logw("**** Warning - not implemented command on SPI: " + data); + } + } + + spiData[spiLen] = data; + if (spiLen < spiData.length) spiLen++; + if (command != null) { + command.dataReceived(data); + if (spiLen == command.commandLen) { + System.out.println("CC2520 Executing command: " + command.name); + command.executeSPICommand(); + command = null; + } + } + if (instruction == -1) { // New instruction if ((data & 0xc0) == INS_REGRD) { @@ -1664,6 +1684,8 @@ public void setChipSelect(boolean select) { // setReg(usartDataAddress, usartDataValue); // } instruction = -1; + spiLen = 0; + command = null; // state = SpiState.WAITING; } diff --git a/se/sics/mspsim/chip/CC2520SPI.java b/se/sics/mspsim/chip/CC2520SPI.java index fff57f0..c5b2596 100644 --- a/se/sics/mspsim/chip/CC2520SPI.java +++ b/se/sics/mspsim/chip/CC2520SPI.java @@ -1,59 +1,86 @@ package se.sics.mspsim.chip; public class CC2520SPI { - SPICommand[] spiCommands = { - new SPICommand("SNOP 0 0 0 0 0 0 0 0"), - new SPICommand("IBUFLD 0 0 0 0 0 0 1 0 i i i i i i i i"), - new SPICommand("SIBUFEX 0 0 0 0 0 0 1 1"), - new SPICommand("SSAMPLECCA 0 0 0 0 0 1 0 0"), - new SPICommand("SRES 0 0 0 0 1 1 1 1 - - - - - - - -"), - new SPICommand("MEMRD 0 0 0 1 a a a a a a a a a a a a - - - - - - - - ..."), - new SPICommand("MEMWR 0 0 1 0 a a a a a a a a a a a a d d d d d d d d ..."), - new SPICommand("RXBUF 0 0 1 1 0 0 0 0 - - - - - - - - ..."), - new SPICommand("RXBUFCP 0 0 1 1 1 0 0 0 0 0 0 0 a a a a a a a a a a a a - - - - - - - - ..."), - new SPICommand("RXBUFMOV 0 0 1 1 0 0 1 p c c c c c c c c 0 0 0 0 a a a a a a a a a a a a"), - new SPICommand("TXBUF 0 0 1 1 1 0 1 0 d d d d d d d d d d d d d d d d ..."), - new SPICommand("TXBUFCP 0 0 1 1 1 1 1 p c c c c c c c c 0 0 0 0 a a a a a a a a a a a a"), - new SPICommand("RANDOM 0 0 1 1 1 1 0 0 - - - - - - - - - - - - - - - - ..."), - new SPICommand("SXOSCON 0 1 0 0 0 0 0 0"), - new SPICommand("STXCAL 0 1 0 0 0 0 0 1"), - new SPICommand("SRXON 0 1 0 0 0 0 1 0"), - new SPICommand("STXON 0 1 0 0 0 0 1 1"), - new SPICommand("STXONCCA 0 1 0 0 0 1 0 0"), - new SPICommand("SRFOFF 0 1 0 0 0 1 0 1"), - new SPICommand("SXOSCOFF 0 1 0 0 0 1 1 0"), - new SPICommand("SFLUSHRX 0 1 0 0 0 1 1 1"), - new SPICommand("SFLUSHTX 0 1 0 0 1 0 0 0"), - new SPICommand("SACK 0 1 0 0 1 0 0 1"), - new SPICommand("SACKPEND 0 1 0 0 1 0 1 0"), - new SPICommand("SNACK 0 1 0 0 1 0 1 1"), - new SPICommand("SRXMASKBITSET 0 1 0 0 1 1 0 0"), - new SPICommand("SRXMASKBITCLR 0 1 0 0 1 1 0 1"), - new SPICommand("RXMASKAND 0 1 0 0 1 1 1 0 d d d d d d d d d d d d d d d d"), - new SPICommand("RXMASKOR 0 1 0 0 1 1 1 1 d d d d d d d d d d d d d d d d"), - new SPICommand("MEMCP 0 1 0 1 0 0 0 p c c c c c c c c a a a a e e e e a a a a a a a a e e e e e e e e"), - new SPICommand("MEMCPR 0 1 0 1 0 0 1 p c c c c c c c c a a a a e e e e a a a a a a a a e e e e e e e e"), - new SPICommand("MEMXCP 0 1 0 1 0 1 0 p c c c c c c c c a a a a e e e e a a a a a a a a e e e e e e e e"), - new SPICommand("MEMXWR 0 1 0 1 0 1 1 0 0 0 0 0 a a a a a a a a a a a a d d d d d d d d ..."), - new SPICommand("BCLR 0 1 0 1 1 0 0 0 a a a a a b b b"), - new SPICommand("BSET 0 1 0 1 1 0 0 1 a a a a a b b b"), - new SPICommand("CTR/UCTR 0 1 1 0 0 0 0 p k k k k k k k k 0 c c c c c c c n n n n n n n n a a a a e e e e a a a a a a a a e e e e e e e e"), - new SPICommand("CBCMAC 0 1 1 0 0 1 0 p k k k k k k k k 0 c c c c c c c a a a a e e e e a a a a a a a a e e e e e e e e 0 0 0 0 0 mmm"), - new SPICommand("UCBCMAC 0 1 1 0 0 1 1 p k k k k k k k k 0 c c c c c c c 0 0 0 0 a a a a a a a a a a a a 0 0 0 0 0 mmm"), - new SPICommand("CCM 0 1 1 0 1 0 0 p k k k k k k k k 0 c c c c c c c n n n n n n n n a a a a e e e e a a a a a a a a e e e e e e e e 0 f f f f f f f 0 0 0 0 0 0 mm"), - new SPICommand("UCCM 0 1 1 0 1 0 1 p k k k k k k k k 0 c c c c c c c n n n n n n n n a a a a e e e e a a a a a a a a e e e e e e e e 0 f f f f f f f 0 0 0 0 0 0 mm"), - new SPICommand("ECB 0 1 1 1 0 0 0 p k k k k k k k k c c c c a a a a a a a a a a a a 0 0 0 0 e e e e e e e e e e e e"), - new SPICommand("ECBO 0 1 1 1 0 0 1 p k k k k k k k k c c c c a a a a a a a a a a a a"), - new SPICommand("ECBX 0 1 1 1 0 1 0 p k k k k k k k k c c c c a a a a a a a a a a a a 0 0 0 0 e e e e e e e e e e e e"), - new SPICommand("INC 0 1 1 1 1 0 0 p 0 0 c c a a a a a a a a a a a a"), - new SPICommand("ABORT 0 1 1 1 1 1 1 1 0 0 0 0 0 0 c c"), - new SPICommand("REGRD 1 0 a a a a a a - - - - - - - - ..."), - new SPICommand("REGWR 1 1 a a a a a a d d d d d d d d ...") - }; + CC2520 cc2520; + private int[] memory; /* pointer to the memory of cc2520 */ SPICommand[] commands = new SPICommand[256]; - CC2520SPI() { + public CC2520SPI(CC2520 cc) { + /* the SPI commands for CC2520 */ + SPICommand[] spiCommands = { + new SPICommand("SNOP 0 0 0 0 0 0 0 0",cc2520) { + public void executeSPICommand() {} + }, + new SPICommand("IBUFLD 0 0 0 0 0 0 1 0 i i i i i i i i",cc2520) { + public void executeSPICommand() { + System.out.println(name + " storing in buffer: " + spiData.getSPIData()[1]); + cc2520.instructionBuffer = spiData.getSPIData()[1]; + } + }, + new SPICommand("SIBUFEX 0 0 0 0 0 0 1 1",cc2520), + new SPICommand("SSAMPLECCA 0 0 0 0 0 1 0 0",cc2520), + new SPICommand("SRES 0 0 0 0 1 1 1 1 - - - - - - - -",cc2520), + new SPICommand("MEMRD 0 0 0 1 a a a a a a a a a a a a - - - - - - - - ...",cc2520), + new SPICommand("MEMWR 0 0 1 0 a a a a a a a a a a a a d d d d d d d d ...",cc2520), + new SPICommand("RXBUF 0 0 1 1 0 0 0 0 - - - - - - - - ...",cc2520), + new SPICommand("RXBUFCP 0 0 1 1 1 0 0 0 0 0 0 0 a a a a a a a a a a a a - - - - - - - - ...",cc2520), + new SPICommand("RXBUFMOV 0 0 1 1 0 0 1 p c c c c c c c c 0 0 0 0 a a a a a a a a a a a a",cc2520), + new SPICommand("TXBUF 0 0 1 1 1 0 1 0 d d d d d d d d d d d d d d d d ...",cc2520), + new SPICommand("TXBUFCP 0 0 1 1 1 1 1 p c c c c c c c c 0 0 0 0 a a a a a a a a a a a a",cc2520), + new SPICommand("RANDOM 0 0 1 1 1 1 0 0 - - - - - - - - - - - - - - - - ...",cc2520), + new SPICommand("SXOSCON 0 1 0 0 0 0 0 0",cc2520), + new SPICommand("STXCAL 0 1 0 0 0 0 0 1",cc2520), + new SPICommand("SRXON 0 1 0 0 0 0 1 0",cc2520), + new SPICommand("STXON 0 1 0 0 0 0 1 1",cc2520) { + public void executeSPICommand() { + cc2520.stxon(); + } + }, + new SPICommand("STXONCCA 0 1 0 0 0 1 0 0",cc2520), + new SPICommand("SRFOFF 0 1 0 0 0 1 0 1",cc2520), + new SPICommand("SXOSCOFF 0 1 0 0 0 1 1 0",cc2520), + new SPICommand("SFLUSHRX 0 1 0 0 0 1 1 1",cc2520), + new SPICommand("SFLUSHTX 0 1 0 0 1 0 0 0",cc2520), + new SPICommand("SACK 0 1 0 0 1 0 0 1",cc2520), + new SPICommand("SACKPEND 0 1 0 0 1 0 1 0",cc2520), + new SPICommand("SNACK 0 1 0 0 1 0 1 1",cc2520), + new SPICommand("SRXMASKBITSET 0 1 0 0 1 1 0 0",cc2520), + new SPICommand("SRXMASKBITCLR 0 1 0 0 1 1 0 1",cc2520), + new SPICommand("RXMASKAND 0 1 0 0 1 1 1 0 d d d d d d d d d d d d d d d d",cc2520), + new SPICommand("RXMASKOR 0 1 0 0 1 1 1 1 d d d d d d d d d d d d d d d d",cc2520), + new SPICommand("MEMCP 0 1 0 1 0 0 0 p c c c c c c c c a a a a e e e e a a a a a a a a e e e e e e e e",cc2520), + new SPICommand("MEMCPR 0 1 0 1 0 0 1 p c c c c c c c c a a a a e e e e a a a a a a a a e e e e e e e e",cc2520), + new SPICommand("MEMXCP 0 1 0 1 0 1 0 p c c c c c c c c a a a a e e e e a a a a a a a a e e e e e e e e",cc2520), + new SPICommand("MEMXWR 0 1 0 1 0 1 1 0 0 0 0 0 a a a a a a a a a a a a d d d d d d d d ...",cc2520), + new SPICommand("BCLR 0 1 0 1 1 0 0 0 a a a a a b b b",cc2520), + new SPICommand("BSET 0 1 0 1 1 0 0 1 a a a a a b b b",cc2520), + new SPICommand("CTR/UCTR 0 1 1 0 0 0 0 p k k k k k k k k 0 c c c c c c c n n n n n n n n a a a a e e e e a a a a a a a a e e e e e e e e",cc2520), + new SPICommand("CBCMAC 0 1 1 0 0 1 0 p k k k k k k k k 0 c c c c c c c a a a a e e e e a a a a a a a a e e e e e e e e 0 0 0 0 0 mmm",cc2520), + new SPICommand("UCBCMAC 0 1 1 0 0 1 1 p k k k k k k k k 0 c c c c c c c 0 0 0 0 a a a a a a a a a a a a 0 0 0 0 0 mmm",cc2520), + new SPICommand("CCM 0 1 1 0 1 0 0 p k k k k k k k k 0 c c c c c c c n n n n n n n n a a a a e e e e a a a a a a a a e e e e e e e e 0 f f f f f f f 0 0 0 0 0 0 mm",cc2520), + new SPICommand("UCCM 0 1 1 0 1 0 1 p k k k k k k k k 0 c c c c c c c n n n n n n n n a a a a e e e e a a a a a a a a e e e e e e e e 0 f f f f f f f 0 0 0 0 0 0 mm",cc2520), + new SPICommand("ECB 0 1 1 1 0 0 0 p k k k k k k k k c c c c a a a a a a a a a a a a 0 0 0 0 e e e e e e e e e e e e",cc2520), + new SPICommand("ECBO 0 1 1 1 0 0 1 p k k k k k k k k c c c c a a a a a a a a a a a a",cc2520), + new SPICommand("ECBX 0 1 1 1 0 1 0 p k k k k k k k k c c c c a a a a a a a a a a a a 0 0 0 0 e e e e e e e e e e e e",cc2520), + new SPICommand("INC 0 1 1 1 1 0 0 p 0 0 c c a a a a a a a a a a a a",cc2520), + new SPICommand("ABORT 0 1 1 1 1 1 1 1 0 0 0 0 0 0 c c",cc2520), + new SPICommand("REGRD 1 0 a a a a a a - - - - - - - - ...",cc2520) { + BitField adr = getBitField("a"); + int cAdr = 0; + public boolean dataReceived(int data) { + /* check if this is first byte*/ + if (spiData.getSPIlen() == 0) { + cAdr = adr.getValue(); + } else { + spiData.outputSPI(memory[cAdr++]); + } + return true; + } + public void executeSPICommand() {} + }, + new SPICommand("REGWR 1 1 a a a a a a d d d d d d d d ...",cc2520)}; + /* set up the commands */ for (int i = 0; i < spiCommands.length; i++) { SPICommand c = spiCommands[i]; @@ -70,6 +97,7 @@ } } + SPICommand getCommand(int cmd) { if (cmd < 256 && commands[cmd] != null) return commands[cmd]; @@ -77,11 +105,11 @@ SPICommand getCommand(int cmd) { } - public static void main(String[] args) { - CC2520SPI spi = new CC2520SPI(); - SPICommand cmd = spi.getCommand(0xff); - /* commands that take infinite number of bytes have the bitfield ... */ - System.out.println("Has ... => " + cmd.getBitField("...")); - } +// public static void main(String[] args) { +// CC2520SPI spi = new CC2520SPI(); +// SPICommand cmd = spi.getCommand(0xff); +// /* commands that take infinite number of bytes have the bitfield ... */ +// System.out.println("Has ... => " + cmd.getBitField("...",cc2520)); +// } } diff --git a/se/sics/mspsim/chip/SPICommand.java b/se/sics/mspsim/chip/SPICommand.java index 55ebfe0..b52abfb 100644 --- a/se/sics/mspsim/chip/SPICommand.java +++ b/se/sics/mspsim/chip/SPICommand.java @@ -1,19 +1,22 @@ package se.sics.mspsim.chip; import java.util.ArrayList; -import java.util.Iterator; public class SPICommand { /* * MEMXCP 0 1 0 1 0 1 0 p c c c c c c c c a a a a e e e e a a a a a a a a e e e e e e e e */ + public final static int DYNAMIC_LENGTH = 0xffff; + String name; int mask; int value; int bitCount; int commandLen = 0; - private class BitField { + SPIData spiData; + + class BitField { String name; int startBit; int endBit; @@ -28,15 +31,15 @@ public BitField(String currentName, int start, int c) { System.out.printf("First mask %x\n", firstMask); } - public int getValue(int[] spiData) { + public int getValue() { int value; int firstByte = startBit / 8; int lastByte = endBit / 8; int nrBitsRoll = 7 - endBit & 7; - value = spiData[firstByte] & firstMask; + value = spiData.getSPIData()[firstByte] & firstMask; for (int i = firstByte + 1; i < lastByte; i++) { - value = value << 8 + spiData[firstByte]; + value = value << 8 + spiData.getSPIData()[firstByte]; } value = value >> nrBitsRoll; @@ -46,7 +49,8 @@ public int getValue(int[] spiData) { ArrayList<BitField> bitFields; - SPICommand(String pattern) { + SPICommand(String pattern, SPIData data) { + spiData = data; String[] subs = pattern.split(" "); name = subs[0]; System.out.println("Name:" + subs[0]); @@ -98,9 +102,12 @@ public int getValue(int[] spiData) { bitFields = new ArrayList<SPICommand.BitField>(); bitFields.add(new BitField(currentName, start, c - 1)); } - + commandLen = c / 8; + if ("...".equals(currentName)) + commandLen = DYNAMIC_LENGTH; System.out.printf("Value %x\n", value); System.out.printf("Mask %x\n", mask); + System.out.println("Command len: " + commandLen); } /* return -1 if no match */ @@ -112,15 +119,15 @@ public int matchSPI(int spiData) { return -1; } + /* do nothing here... - override if needed */ - public boolean dataReceived(int spiData) { + public boolean dataReceived(int data) { return true; } /* for any command that is executable (finite commands) */ - public boolean executeSPICommand(int[] spiData) { + public void executeSPICommand() { System.out.println("Command " + name + " not implemented..."); - return true; } public BitField getBitField(String arg) { @@ -128,29 +135,6 @@ public BitField getBitField(String arg) { if (b.name.equals(arg)) return b; } /* not existing ... */ - return null; - } - - public static void main(String[] args) { - SPICommand c = new SPICommand("MEMXCP 0 1 0 1 0 1 0 p c c c c c c c c a a a a e e e e a a a a a a a a e e e e e e e e") { - public boolean executeSPICommand(int[] spiData) { - System.out.println("Yes!"); - return true; - } - }; - int[] data = new int[]{1,0x13,0xab,0xaa,0xbb}; - for (int i = 0; i < c.bitFields.size(); i++) { - System.out.printf("Data %s: %x\n", c.bitFields.get(i).name, c.bitFields.get(i).getValue(data)); - } - c.executeSPICommand(data); - - System.out.println("Bitcount:" + c.bitCount); - int maxv = 1 << (8 - c.bitCount); - int v = c.value; - - /* populate an array with the values for quick decoding */ - for (int i = 0; i < maxv; i++) { - System.out.printf("Value: %x\n", (v + i)); - } + throw new IllegalArgumentException("No bitfield with name " + arg + " exists for " + name); } } ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/chip/CC2520.java | 22 ++++++ se/sics/mspsim/chip/CC2520SPI.java | 140 +++++++++++++++++++++-------------- se/sics/mspsim/chip/SPICommand.java | 52 +++++--------- 3 files changed, 124 insertions(+), 90 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-05-15 04:38:40
|
The branch "master" has been updated via 31dfdad8e5b7a903340f30e0ebfc99ae2b3b4681 (commit) from 351c7b6a63d598488c8bc13fc1af2279bfa33df6 (commit) Changed paths: A se/sics/mspsim/chip/CC2520.java A se/sics/mspsim/chip/SPIData.java - Log ----------------------------------------------------------------- commit 31dfdad8e5b7a903340f30e0ebfc99ae2b3b4681 Author: Joakim Eriksson <jo...@si...> Date: Tue May 15 06:38:05 2012 +0200 started to connect CC2520 with SPICommands diff --git a/se/sics/mspsim/chip/CC2520.java b/se/sics/mspsim/chip/CC2520.java new file mode 100644 index 0000000..884f963 --- /dev/null +++ b/se/sics/mspsim/chip/CC2520.java @@ -0,0 +1,1778 @@ +/** + * Copyright (c) 2012 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. + * + * ----------------------------------------------------------------- + * + * CC2520 + * + * Author : Joakim Eriksson, Niclas Finne + */ + +package se.sics.mspsim.chip; +import se.sics.mspsim.core.*; +import se.sics.mspsim.util.ArrayFIFO; +import se.sics.mspsim.util.CCITT_CRC; +import se.sics.mspsim.util.Utils; + +public class CC2520 extends Chip implements USARTListener, RFListener, RFSource, SPIData { + public static final int FIFO_POLARITY = (1<<10); + public static final int FIFOP_POLARITY = (1<<9); + public static final int SFD_POLARITY = (1<<8); + public static final int CCA_POLARITY = (1<<7); + public static final int POLARITY_MASK = FIFO_POLARITY | FIFOP_POLARITY | SFD_POLARITY | CCA_POLARITY; + + public static class GPIO { + public IOPort port; + public int pin; + + boolean polarity = true; + boolean isActive; + + public void setConfig(IOPort port, int pin) { + this.port = port; + this.pin = pin; + } + + public boolean isActive() { + return isActive; + } + + public void setActive(boolean isActive) { + if (this.isActive != isActive) { + this.isActive = isActive; + port.setPinState(pin, isActive == polarity ? IOPort.PIN_HI : IOPort.PIN_LOW); + } + } + + public void setPolarity(boolean polarity) { + if (this.polarity != polarity) { + this.polarity = polarity; + port.setPinState(pin, isActive == polarity ? IOPort.PIN_HI : IOPort.PIN_LOW); + } + } + } + + static class VoidGPIO extends GPIO { + + @Override + public void setActive(boolean isActive) { + // Ignore + } + } + + // FREG definitions (BSET/BCLR supported) + public final static int REG_FRMFILT0 = 0x000; + public final static int REG_FRMFILT1 = 0x001; + public final static int REG_SRCMATCH = 0x002; + public final static int REG_SRCSHORTEN0 = 0x004; + public final static int REG_SRCSHORTEN1 = 0x005; + public final static int REG_SRCSHORTEN2 = 0x006; + public final static int REG_SRCEXTEN0 = 0x008; + public final static int REG_SRCEXTEN1 = 0x009; + public final static int REG_SRCEXTEN2 = 0x00A; + public final static int REG_FRMCTRL0 = 0x00C; + public final static int REG_FRMCTRL1 = 0x00D; + public final static int REG_RXENABLE0 = 0x00E; + public final static int REG_RXENABLE1 = 0x00F; + public final static int REG_EXCFLAG0 = 0x010; + public final static int REG_EXCFLAG1 = 0x011; + public final static int REG_EXCFLAG2 = 0x012; + public final static int REG_EXCMASKA0 = 0x014; + public final static int REG_EXCMASKA1 = 0x015; + public final static int REG_EXCMASKA2 = 0x016; + public final static int REG_EXCMASKB0 = 0x018; + public final static int REG_EXCMASKB1 = 0x019; + public final static int REG_EXCMASKB2 = 0x01A; + public final static int REG_EXCBINDX0 = 0x01C; + public final static int REG_EXCBINDX1 = 0x01D; + public final static int REG_EXCBINDY0 = 0x01E; + public final static int REG_EXCBINDY1 = 0x01F; + public final static int REG_GPIOCTRL0 = 0x020; + public final static int REG_GPIOCTRL1 = 0x021; + public final static int REG_GPIOCTRL2 = 0x022; + public final static int REG_GPIOCTRL3 = 0x023; + public final static int REG_GPIOCTRL4 = 0x024; + public final static int REG_GPIOCTRL5 = 0x025; + public final static int REG_GPIOPOLARITY = 0x026; + public final static int REG_GPIOCTRL = 0x028; + public final static int REG_DPUCON = 0x02A; + public final static int REG_DPUSTAT = 0x02C; + public final static int REG_FREQCTRL = 0x02E; + public final static int REG_FREQTUNE = 0x02F; + public final static int REG_TXPOWER = 0x030; + public final static int REG_TXCTRL = 0x031; + public final static int REG_FSMSTAT0 = 0x032; + public final static int REG_FSMSTAT1 = 0x033; + public final static int REG_FIFOPCTRL = 0x034; + public final static int REG_FSMCTRL = 0x035; + public final static int REG_CCACTRL0 = 0x036; + public final static int REG_CCACTRL1 = 0x037; + public final static int REG_RSSI = 0x038; + public final static int REG_RSSISTAT = 0x039; + public final static int REG_TXFIFO_BUF = 0x03A; + public final static int REG_RXFIRST = 0x03C; + public final static int REG_RXFIFOCNT = 0x03E; + public final static int REG_TXFIFOCNT = 0x03F; + + // SREG definitions (BSET/BCLR unsupported) + public final static int REG_CHIPID = 0x040; + public final static int REG_VERSION = 0x042; + public final static int REG_EXTCLOCK = 0x044; + public final static int REG_MDMCTRL0 = 0x046; + public final static int REG_MDMCTRL1 = 0x047; + public final static int REG_FREQEST = 0x048; + public final static int REG_RXCTRL = 0x04A; + public final static int REG_FSCTRL = 0x04C; + public final static int REG_FSCAL0 = 0x04E; + public final static int REG_FSCAL1 = 0x04F; + public final static int REG_FSCAL2 = 0x050; + public final static int REG_FSCAL3 = 0x051; + public final static int REG_AGCCTRL0 = 0x052; + public final static int REG_AGCCTRL1 = 0x053; + public final static int REG_AGCCTRL2 = 0x054; + public final static int REG_AGCCTRL3 = 0x055; + public final static int REG_ADCTEST0 = 0x056; + public final static int REG_ADCTEST1 = 0x057; + public final static int REG_ADCTEST2 = 0x058; + public final static int REG_MDMTEST0 = 0x05A; + public final static int REG_MDMTEST1 = 0x05B; + public final static int REG_DACTEST0 = 0x05C; + public final static int REG_DACTEST1 = 0x05D; + public final static int REG_ATEST = 0x05E; + public final static int REG_DACTEST2 = 0x05F; + public final static int REG_PTEST0 = 0x060; + public final static int REG_PTEST1 = 0x061; + public final static int REG_RESERVED = 0x062; + public final static int REG_DPUBIST = 0x07A; + public final static int REG_ACTBIST = 0x07C; + public final static int REG_RAMBIST = 0x07E; + + // Instructions + public final static int INS_SNOP = 0x00; + public final static int INS_IBUFLD = 0x02; + public final static int INS_SIBUFEX = 0x03; + public final static int INS_SSAMPLECCA = 0x04; + public final static int INS_SRES = 0x0F; + public final static int INS_MEMRD = 0x10; + public final static int INS_MEMWR = 0x20; + public final static int INS_RXBUF = 0x30; + public final static int INS_RXBUFCP = 0x38; + public final static int INS_RXBUFMOV = 0x32; + public final static int INS_TXBUF = 0x3A; + public final static int INS_TXBUFCP = 0x3E; + public final static int INS_RANDOM = 0x3C; + public final static int INS_SXOSCON = 0x40; + public final static int INS_STXCAL = 0x41; + public final static int INS_SRXON = 0x42; + public final static int INS_STXON = 0x43; + public final static int INS_STXONCCA = 0x44; + public final static int INS_SRFOFF = 0x45; + public final static int INS_SXOSCOFF = 0x46; + public final static int INS_SFLUSHRX = 0x47; + public final static int INS_SFLUSHTX = 0x48; + public final static int INS_SACK = 0x49; + public final static int INS_SACKPEND = 0x4A; + public final static int INS_SNACK = 0x4B; + public final static int INS_SRXMASKBITSET = 0x4C; + public final static int INS_SRXMASKBITCLR = 0x4D; + public final static int INS_RXMASKAND = 0x4E; + public final static int INS_RXMASKOR = 0x4F; + public final static int INS_MEMCP = 0x50; + public final static int INS_MEMCPR = 0x52; + public final static int INS_MEMXCP = 0x54; + public final static int INS_MEMXWR = 0x56; + public final static int INS_BCLR = 0x58; + public final static int INS_BSET = 0x59; + public final static int INS_CTR = 0x60; + public final static int INS_CBCMAC = 0x64; + public final static int INS_UCBCMAC = 0x66; + public final static int INS_CCM = 0x68; + public final static int INS_UCCM = 0x6A; + public final static int INS_ECB = 0x70; + public final static int INS_ECBO = 0x72; + public final static int INS_ECBX = 0x74; + public final static int INS_ECBXO = 0x76; + public final static int INS_INC = 0x78; + public final static int INS_ABORT = 0x7F; + public final static int INS_REGRD = 0x80; + public final static int INS_REGWR = 0xC0; + + // Status register flags + public static final int STATUS_XOSC16M_STABLE = 1 << 7; + public static final int STATUS_RSSI_VALID = 1 << 6; + public static final int STATUS_EXCEPTION_CHA = 1 << 5; + public static final int STATUS_EXCEPTION_CHB = 1 << 4; + public static final int STATUS_DPU_H = 1 << 3; + public static final int STATUS_DPU_L = 1 << 2; + public static final int STATUS_TX_ACTIVE = 1 << 1; + public static final int STATUS_RX_ACTIVE = 1 << 0; + + // Exceptions (bits in the EXCFLAGx registers) + public final static int EXC_RF_IDLE = 1 << 0; + public final static int EXC_TX_FRM_DONE = 1 << 1; + public final static int EXC_RX_FRM_ABORTED = 0x20; + public final static int EXC_RX_FRM_UNDERFLOW = 0x20; + + // RAM Addresses + public static final int RAM_TXFIFO = 0x100; + public static final int RAM_RXFIFO = 0x180; + public static final int RAM_IEEEADDR = 0x3EA; + public static final int RAM_PANID = 0x3F2; + public static final int RAM_SHORTADDR = 0x3F4; +// public static final int RAM_KEY0 = 0x100; +// public static final int RAM_RXNONCE = 0x110; +// public static final int RAM_SABUF = 0x120; +// public static final int RAM_KEY1 = 0x130; +// public static final int RAM_TXNONCE = 0x140; +// public static final int RAM_CBCSTATE = 0x150; + + /* one single byte instruction can be stored in the IBUF */ + int instructionBuffer = 0; + + public enum SpiState { + WAITING, WRITE_REGISTER, READ_REGISTER, RAM_ACCESS, + READ_RXFIFO, WRITE_TXFIFO + }; + + // IOCFG0 Register Bit masks + public static final int BCN_ACCEPT = (1<<11); + public static final int FIFOP_THR = 0x7F; + + // IOCFG1 Register Bit Masks +// public static final int SFDMUX = 0x3E0; +// public static final int CCAMUX = 0x1F; + + // CCAMUX values +// public static final int CCAMUX_CCA = 0; +// public static final int CCAMUX_XOSC16M_STABLE = 24; + + // MDMCTRO0 values + public static final int ADR_DECODE = (1 << 11); + public static final int ADR_AUTOCRC = (1 << 5); + public static final int AUTOACK = (1 << 4); + public static final int PREAMBLE_LENGTH = 0x0f; + + public static final int SHORT_ADDRESS = 2; + public static final int LONG_ADDRESS = 3; + + + // The Operation modes of the CC2520 + public static final int MODE_TXRX_OFF = 0x00; + public static final int MODE_RX_ON = 0x01; + public static final int MODE_TXRX_ON = 0x02; + public static final int MODE_POWER_OFF = 0x03; + public static final int MODE_MAX = MODE_POWER_OFF; + private static final String[] MODE_NAMES = new String[] { + "off", "listen", "transmit", "power_off" + }; + + // State Machine - Datasheet Figure 30 page 85 + public enum RadioState { + VREG_OFF(-2), + POWER_DOWN(-1), + IDLE(0), + RX_CALIBRATE(2), + RX_SFD_SEARCH(3), + RX_WAIT(14), + RX_FRAME(15), + RX_OVERFLOW(17), + TX_CALIBRATE(32), + TX_PREAMBLE(34), + TX_FRAME(37), + TX_ACK_CALIBRATE(48), + TX_ACK_PREAMBLE(49), + TX_ACK(52), + TX_UNDERFLOW(56); + + private final int state; + RadioState(int stateNo) { + state = stateNo; + } + + public int getFSMState() { + return state; + } + }; + + // FCF High + public static final int FRAME_TYPE = 0x07; + public static final int SECURITY_ENABLED = (1 << 3); + public static final int FRAME_PENDING = (1 << 4); + public static final int ACK_REQUEST = (1 << 5); + public static final int INTRA_PAN = (1 << 6); + + public static final int TYPE_BEACON_FRAME = 0x00; + public static final int TYPE_DATA_FRAME = 0x01; + public static final int TYPE_ACK_FRAME = 0x02; + + // FCF Low + public static final int DESTINATION_ADDRESS_MODE = 0x30; + public static final int SOURCE_ADDRESS_MODE = 0x3; + + // Position of SEQ-NO in ACK packet... + public static final int ACK_SEQPOS = 3; + + private RadioState stateMachine = RadioState.VREG_OFF; + + // 802.15.4 symbol period in ms + public static final double SYMBOL_PERIOD = 0.016; // 16 us + + private static final int[] BC_ADDRESS = new int[] {0xff, 0xff}; + + private SpiState state = SpiState.WAITING; + private int instruction = -1; + private int ibufld = INS_SNOP; + + private int usartDataPos; + private int usartDataAddress; + private int usartDataValue; + private int shrPos; + private int txfifoPos; + private boolean txfifoFlush; // TXFIFO is automatically flushed on next write + private int rxfifoReadLeft; // number of bytes left to read from current packet + private int rxlen; + private int rxread; + private int zeroSymbols; + private boolean ramRead = false; + + /* RSSI is an externally set value of the RSSI for this CC2520 */ + /* low RSSI => CCA = true in normal mode */ + + private int rssi = -100; + private static int RSSI_OFFSET = -45; /* cc2520 datasheet */ + /* current CCA value */ + private boolean cca = false; + + /* This is the magical LQI */ + private int corrval = 37; + + /* FIFOP Threshold */ + private int fifopThr = 0x40; + + /* if autoack is configured or if */ + private boolean autoAck = false; + private boolean shouldAck = false; + private boolean addressDecode = false; + private boolean ackRequest = false; + private boolean autoCRC = false; + + // Data from last received packet + private int dsn = 0; + private int fcf0 = 0; + private int fcf1 = 0; + private int frameType = 0; + private boolean crcOk = false; + + private int activeFrequency = 0; + private int activeChannel = 0; + + //private int status = STATUS_XOSC16M_STABLE | STATUS_RSSI_VALID; + private int status = 0; + + private final int[] registers = new int[128]; + private final int[] memory = new int[384 + 128]; + + private int[] spiData = new int[20]; /* SPI data buffer */ + private int spiLen; + + // Buffer to hold 5 byte Synchronization header, as it is not written to the TXFIFO + private final byte[] SHR = new byte[5]; + + private boolean chipSelect; + private final GPIO[] gpio = new GPIO[6]; + private GPIO ccaGPIO; + private GPIO fifopGPIO; + private GPIO fifoGPIO; + private GPIO sfdGPIO; + private boolean currentCCA; + private boolean currentSFD; + private boolean currentFIFO; + private boolean currentFIFOP; + + private int txCursor; + private boolean isRadioOn; + private RFListener rfListener; + private ChannelListener channelListener; + + private TimeEvent oscillatorEvent = new TimeEvent(0, "CC2520 OSC") { + public void execute(long t) { + status |= STATUS_XOSC16M_STABLE; + if(DEBUG) log("Oscillator Stable Event."); + setState(RadioState.IDLE); +// if( (registers[REG_IOCFG1] & CCAMUX) == CCAMUX_XOSC16M_STABLE) { +// updateCCA(); +// } else { +// if(DEBUG) log("CCAMUX != CCA_XOSC16M_STABLE! Not raising CCA"); +// } + } + }; + + private TimeEvent vregEvent = new TimeEvent(0, "CC2520 VREG") { + public void execute(long t) { + if(DEBUG) log("VREG Started at: " + t + " cyc: " + + cpu.cycles + " " + getTime()); + isRadioOn = true; + setState(RadioState.POWER_DOWN); + updateCCA(); + } + }; + + private TimeEvent sendEvent = new TimeEvent(0, "CC2520 Send") { + public void execute(long t) { + txNext(); + } + }; + + private TimeEvent ackEvent = new TimeEvent(0, "CC2520 Ack") { + public void execute(long t) { + ackNext(); + } + }; + + private TimeEvent shrEvent = new TimeEvent(0, "CC2520 SHR") { + public void execute(long t) { + shrNext(); + } + }; + + private TimeEvent symbolEvent = new TimeEvent(0, "CC2520 Symbol") { + public void execute(long t) { + switch(stateMachine) { + case RX_CALIBRATE: + setState(RadioState.RX_SFD_SEARCH); + break; + /* this will be called 8 symbols after first SFD_SEARCH */ + case RX_SFD_SEARCH: + status |= STATUS_RSSI_VALID; + registers[REG_RSSISTAT] = 1; + updateCCA(); + break; + + case TX_CALIBRATE: + setState(RadioState.TX_PREAMBLE); + break; + + case RX_WAIT: + setState(RadioState.RX_SFD_SEARCH); + break; + + case TX_ACK_CALIBRATE: + setState(RadioState.TX_ACK_PREAMBLE); + break; + } + } + }; + private boolean overflow = false; + private boolean frameRejected = false; + + private int ackPos; + /* type = 2 (ACK), third byte needs to be sequence number... */ + private int[] ackBuf = {0x05, 0x02, 0x00, 0x00, 0x00, 0x00}; + private boolean ackFramePending = false; + private CCITT_CRC rxCrc = new CCITT_CRC(); + private CCITT_CRC txCrc = new CCITT_CRC(); + + private final ArrayFIFO rxFIFO = new ArrayFIFO("RXFIFO", memory, 128, 128); + + public RadioState getState() { + return stateMachine; + } + + public CC2520(MSP430Core cpu) { + super("CC2520", "Radio", cpu); + + for (int i = 0; i < gpio.length; i++) { + gpio[i] = new GPIO(); + } + + +// registers[REG_SNOP] = 0; +// registers[REG_TXCTRL] = 0xa0ff; + setModeNames(MODE_NAMES); + setMode(MODE_POWER_OFF); + currentFIFOP = false; + rxFIFO.reset(); + overflow = false; + reset(); + } + + private void reset() { +// setReg(REG_MDMCTRL0, 0x0ae2); + registers[REG_RSSISTAT] = 0; + + /* back to default configuration of GPIOs */ + fifoGPIO = gpio[1]; + fifopGPIO = gpio[2]; + ccaGPIO = gpio[3]; + sfdGPIO = gpio[4]; + + for (int i = 0; i < gpio.length; i++) { + gpio[i].setPolarity(true); /* reset to positive polarity */ + } + + + } + + private boolean setState(RadioState state) { + if(DEBUG) log("State transition from " + stateMachine + " to " + state); + stateMachine = state; + /* write to FSM state register */ + registers[REG_FSMSTAT0] = (registers[REG_FSMSTAT0] & 0x3f);//state.getFSMState(); + + switch(stateMachine) { + + case VREG_OFF: + if (DEBUG) log("VREG Off."); + flushRX(); + flushTX(); + status &= ~(STATUS_RSSI_VALID | STATUS_XOSC16M_STABLE); + registers[REG_RSSISTAT] = 0; + crcOk = false; + reset(); + setMode(MODE_POWER_OFF); + updateCCA(); + break; + + case POWER_DOWN: + rxFIFO.reset(); + status &= ~(STATUS_RSSI_VALID | STATUS_XOSC16M_STABLE); + registers[REG_RSSISTAT] = 0; + crcOk = false; + reset(); + setMode(MODE_POWER_OFF); + updateCCA(); + break; + + case RX_CALIBRATE: + /* should be 12 according to specification */ + setSymbolEvent(12); + setMode(MODE_RX_ON); + break; + case RX_SFD_SEARCH: + zeroSymbols = 0; + /* eight symbols after first SFD search RSSI will be valid */ + if ((status & STATUS_RSSI_VALID) == 0) { + setSymbolEvent(8); + } + // status |= STATUS_RSSI_VALID; + updateCCA(); + setMode(MODE_RX_ON); + break; + + case TX_CALIBRATE: + /* 12 symbols calibration, and one byte's wait since we deliver immediately + * to listener when after calibration? + */ + setSymbolEvent(12 + 2); + setMode(MODE_TXRX_ON); + break; + + case TX_PREAMBLE: + shrPos = 0; + SHR[0] = 0; + SHR[1] = 0; + SHR[2] = 0; + SHR[3] = 0; + SHR[4] = 0x7A; + shrNext(); + break; + + case TX_FRAME: + txfifoPos = 0; + // Reset CRC ok flag to disable software acknowledgments until next received packet + crcOk = false; + txNext(); + break; + + case RX_WAIT: + setSymbolEvent(8); + setMode(MODE_RX_ON); + break; + + case IDLE: + status &= ~STATUS_RSSI_VALID; + registers[REG_RSSISTAT] = 0; + setMode(MODE_TXRX_OFF); + updateCCA(); + break; + + case TX_ACK_CALIBRATE: + /* TX active during ACK + NOTE: we ignore the SFD when receiving full packets so + * we need to add another extra 2 symbols here to get a correct timing */ + status |= STATUS_TX_ACTIVE; + setSymbolEvent(12 + 2 + 2); + setMode(MODE_TXRX_ON); + break; + case TX_ACK_PREAMBLE: + /* same as normal preamble ?? */ + shrPos = 0; + SHR[0] = 0; + SHR[1] = 0; + SHR[2] = 0; + SHR[3] = 0; + SHR[4] = 0x7A; + shrNext(); + break; + case TX_ACK: + ackPos = 0; + // Reset CRC ok flag to disable software acknowledgments until next received packet + crcOk = false; + ackNext(); + break; + case RX_FRAME: + /* mark position of frame start - for rejecting when address is wrong */ + rxFIFO.mark(); + rxread = 0; + frameRejected = false; + shouldAck = false; + crcOk = false; + break; + } + + /* Notify state listener */ + stateChanged(stateMachine.state); + + return true; + } + + private void rejectFrame() { + // Immediately jump to SFD Search again... something more??? + /* reset state */ + rxFIFO.restore(); + setSFD(false); + setFIFO(rxFIFO.length() > 0); + frameRejected = true; + } + + /* variables for the address recognition */ + int destinationAddressMode = 0; + boolean decodeAddress = false; + /* Receive a byte from the radio medium + * @see se.sics.mspsim.chip.RFListener#receivedByte(byte) + */ + public void receivedByte(byte data) { + // Received a byte from the "air" + + if (DEBUG) + log("RF Byte received: " + Utils.hex8(data) + " state: " + stateMachine + " noZeroes: " + zeroSymbols + + ((stateMachine == RadioState.RX_SFD_SEARCH || stateMachine == RadioState.RX_FRAME) ? "" : " *** Ignored")); + + if(stateMachine == RadioState.RX_SFD_SEARCH) { + // Look for the preamble (4 zero bytes) followed by the SFD byte 0x7A + if(data == 0) { + // Count zero bytes + zeroSymbols++; + } else if(zeroSymbols >= 4 && data == 0x7A) { + // If the received byte is !zero, we have counted 4 zero bytes prior to this one, + // and the current received byte == 0x7A (SFD), we're in sync. + // In RX mode, SFD goes high when the SFD is received + setSFD(true); + if (DEBUG) log("RX: Preamble/SFD Synchronized."); + setState(RadioState.RX_FRAME); + } else { + /* if not four zeros and 0x7A then no zeroes... */ + zeroSymbols = 0; + } + + } else if(stateMachine == RadioState.RX_FRAME) { + if (overflow) { + /* if the CC2520 RX FIFO is in overflow - it needs a flush before receiving again */ + } else if(rxFIFO.isFull()) { + setRxOverflow(); + } else { + if (!frameRejected) { + rxFIFO.write(data); + if (rxread == 0) { + rxCrc.setCRC(0); + rxlen = data & 0xff; + //System.out.println("Starting to get packet at: " + rxfifoWritePos + " len = " + rxlen); + decodeAddress = addressDecode; + if (DEBUG) log("RX: Start frame length " + rxlen); + // FIFO pin goes high after length byte is written to RXFIFO + setFIFO(true); + } else if (rxread < rxlen - 1) { + /* As long as we are not in the length or FCF (CRC) we count CRC */ + rxCrc.addBitrev(data & 0xff); + if (rxread == 1) { + fcf0 = data & 0xff; + frameType = fcf0 & FRAME_TYPE; + } else if (rxread == 2) { + fcf1 = data & 0xff; + if (frameType == TYPE_DATA_FRAME) { + ackRequest = (fcf0 & ACK_REQUEST) > 0; + destinationAddressMode = (fcf1 >> 2) & 3; + /* check this !!! */ + if (addressDecode && destinationAddressMode != LONG_ADDRESS && + destinationAddressMode != SHORT_ADDRESS) { + rejectFrame(); + } + } else if (frameType == TYPE_BEACON_FRAME || + frameType == TYPE_ACK_FRAME){ + decodeAddress = false; + ackRequest = false; + } else if (addressDecode) { + /* illegal frame when decoding address... */ + rejectFrame(); + } + } else if (rxread == 3) { + // save data sequence number + dsn = data & 0xff; + } else if (decodeAddress) { + boolean flushPacket = false; + /* here we decode the address !!! */ + if (destinationAddressMode == LONG_ADDRESS && rxread == 8 + 5) { + /* here we need to check that this address is correct compared to the stored address */ + flushPacket = !rxFIFO.tailEquals(memory, RAM_IEEEADDR, 8); + flushPacket |= !rxFIFO.tailEquals(memory, RAM_PANID, 2, 8) + && !rxFIFO.tailEquals(BC_ADDRESS, 0, 2, 8); + decodeAddress = false; + } else if (destinationAddressMode == SHORT_ADDRESS && rxread == 2 + 5){ + /* should check short address */ + flushPacket = !rxFIFO.tailEquals(BC_ADDRESS, 0, 2) + && !rxFIFO.tailEquals(memory, RAM_SHORTADDR, 2); + flushPacket |= !rxFIFO.tailEquals(memory, RAM_PANID, 2, 2) + && !rxFIFO.tailEquals(BC_ADDRESS, 0, 2, 2); + decodeAddress = false; + } + if (flushPacket) { + rejectFrame(); + } + } + } + + /* In RX mode, FIFOP goes high when the size of the first enqueued packet exceeds + * the programmable threshold and address recognition isn't ongoing */ + if (currentFIFOP == false + && rxFIFO.length() <= rxlen + 1 + && !decodeAddress && !frameRejected + && rxFIFO.length() > fifopThr) { + setFIFOP(true); + if (DEBUG) log("RX: FIFOP Threshold reached - setting FIFOP"); + } + } + + if (rxread++ == rxlen) { + if (frameRejected) { + if (DEBUG) log("Frame rejected - setting SFD to false and RXWAIT\n"); + setSFD(false); + setState(RadioState.RX_WAIT); + return; + } + // In RX mode, FIFOP goes high, if threshold is higher than frame length.... + + // Here we check the CRC of the packet! + //System.out.println("Reading from " + ((rxfifoWritePos + 128 - 2) & 127)); + int crc = rxFIFO.get(-2) << 8; + crc += rxFIFO.get(-1); //memory[RAM_RXFIFO + ((rxfifoWritePos + 128 - 1) & 127)]; + + crcOk = crc == rxCrc.getCRCBitrev(); + if (DEBUG && !crcOk) { + log("CRC not OK: recv:" + Utils.hex16(crc) + " calc: " + Utils.hex16(rxCrc.getCRCBitrev())); + } + // Should take a RSSI value as input or use a set-RSSI value... + rxFIFO.set(-2, registers[REG_RSSI] & 0xff); + rxFIFO.set(-1, (corrval & 0x7F) | (crcOk ? 0x80 : 0)); + // memory[RAM_RXFIFO + ((rxfifoWritePos + 128 - 2) & 127)] = ; + // // Set CRC ok and add a correlation - TODO: fix better correlation value!!! + // memory[RAM_RXFIFO + ((rxfifoWritePos + 128 - 1) & 127)] = 37 | + // (crcOk ? 0x80 : 0); + + /* set FIFOP only if this is the first received packet - e.g. if rxfifoLen is at most rxlen + 1 + * TODO: check what happens when rxfifoLen < rxlen - e.g we have been reading before FIFOP */ + if (rxFIFO.length() <= rxlen + 1) { + setFIFOP(true); + } else { + if (DEBUG) log("Did not set FIFOP rxfifoLen: " + rxFIFO.length() + " rxlen: " + rxlen); + } + setSFD(false); + if (DEBUG) log("RX: Complete: packetStart: " + rxFIFO.stateToString()); + + /* if either manual ack request (shouldAck) or autoack + ACK_REQ on package do ack! */ + /* Autoack-mode + good CRC => autoack */ + if (((autoAck && ackRequest) || shouldAck) && crcOk) { + setState(RadioState.TX_ACK_CALIBRATE); + } else { + setState(RadioState.RX_WAIT); + } + } + } + } + } + + private void setReg(int address, int data) { + int oldValue = registers[address]; + registers[address] = data; + switch(address) { + case REG_FIFOPCTRL: + fifopThr = data & FIFOP_THR; + if (DEBUG) log("FIFOPCTRL: 0x" + Utils.hex16(oldValue) + " => 0x" + Utils.hex16(data)); + break; + case REG_GPIOPOLARITY: + if (DEBUG) log("GIOPOLARITY: 0x" + Utils.hex16(oldValue) + " => 0x" + Utils.hex16(data)); + if (oldValue != data) { + // Polarity has changed - must update pins + setFIFOP(currentFIFOP); + setFIFO(currentFIFO); + setSFD(currentSFD); + setCCA(currentCCA); + } + break; +// case REG_IOCFG1: +// if (DEBUG) +// log("IOCFG1: SFDMUX " +// + ((registers[address] & SFDMUX) >> SFDMUX) +// + " CCAMUX: " + (registers[address] & CCAMUX)); +// updateCCA(); +// break; + case REG_MDMCTRL0: + addressDecode = (data & ADR_DECODE) != 0; + autoCRC = (data & ADR_AUTOCRC) != 0; + autoAck = (data & AUTOACK) != 0; + break; + case REG_FSCTRL: { + ChannelListener listener = this.channelListener; + if (listener != null) { + int oldChannel = activeChannel; + updateActiveFrequency(); + if (oldChannel != activeChannel) { + listener.channelChanged(activeChannel); + } + } + break; + } + } + configurationChanged(address, oldValue, data); + } + + /* the data that should be SPI response */ + int outputSPI; + public void outputSPI(int data) { + outputSPI = data; + } + + public void dataReceived(USARTSource source, int data) { + outputSPI = status; /* if nothing replace the outputSPI it will be output */ + if (DEBUG) { + log("byte received: " + Utils.hex8(data) + + " (" + ((data >= ' ' && data <= 'Z') ? (char) data : '.') + ')' + + " CS: " + chipSelect + " SPI state: " + state + " StateMachine: " + stateMachine); + } + + if (!chipSelect) { + // Chip is not selected + return; + } + + if (stateMachine == RadioState.VREG_OFF) { + /* No VREG but chip select */ + source.byteReceived(0); + logw("**** Warning - writing to CC2520 when VREG is off!!!"); + return; + } + + if (instruction == -1) { + // New instruction + if ((data & 0xc0) == INS_REGRD) { + // Register read +// source.byteReceived(oldStatus); + source.byteReceived(registers[data & 0x3f]); + return; + } + if ((data & 0xc0) == INS_REGWR) { + // Register write + instruction = data; + source.byteReceived(outputSPI); + return; + } + if ((data & 0xf0) == INS_MEMRD || (data & 0xf0) == INS_MEMWR) { + // Memory read or write + instruction = data; + source.byteReceived(outputSPI); + return; + } + + switch (data & 0xff) { + case INS_SNOP: + // Do nothing + break; + case INS_IBUFLD: + instruction = data & 0xff; + break; + case INS_SIBUFEX: + strobe(ibufld); + ibufld = INS_SNOP; + break; + case INS_SSAMPLECCA: + break; + case INS_SRES: + break; + case INS_RXBUF: + break; + case INS_RXBUFCP: + break; + case INS_RXBUFMOV: + break; + case INS_TXBUF: + break; + case INS_TXBUFCP: + break; + case INS_RANDOM: + break; + case INS_SXOSCON: + break; + case INS_STXCAL: + break; + case INS_SRXON: + break; + case INS_STXON: + break; + case INS_STXONCCA: + break; + case INS_SRFOFF: + break; + case INS_SXOSCOFF: + break; + case INS_SFLUSHRX: + break; + case INS_SFLUSHTX: + break; + case INS_SACK: + break; + case INS_SACKPEND: + break; + case INS_SNACK: + break; + case INS_SRXMASKBITSET: + break; + case INS_SRXMASKBITCLR: + break; + case INS_RXMASKAND: + break; + case INS_RXMASKOR: + break; + case INS_MEMCP: + break; + case INS_MEMCPR: + break; + case INS_MEMXCP: + break; + case INS_MEMXWR: + break; + case INS_BCLR: + break; + case INS_BSET: + break; + case INS_CTR: + break; + case INS_CBCMAC: + break; + case INS_UCBCMAC: + break; + case INS_CCM: + break; + case INS_UCCM: + break; + case INS_ECB: + break; + case INS_ECBO: + break; + case INS_ECBX: + break; + case INS_ECBXO: + break; + case INS_INC: + break; + case INS_ABORT: + break; + default: + // Unknown instruction + logw("**** Warning - unknown instruction sent to CC2520: " + data); + break; + } + source.byteReceived(outputSPI); + return; + } + +// switch (instruction) { +// case WAITING: +// if ((data & FLAG_READ) != 0) { +// state = SpiState.READ_REGISTER; +// } else { +// state = SpiState.WRITE_REGISTER; +// } +// if ((data & FLAG_RAM) != 0) { +// state = SpiState.RAM_ACCESS; +// usartDataAddress = data & 0x7f; +// } else { +// // The register address +// usartDataAddress = data & 0x3f; +// +// if (usartDataAddress == REG_RXFIFO) { +// // check read/write??? +// // log("Reading RXFIFO!!!"); +// state = SpiState.READ_RXFIFO; +// } else if (usartDataAddress == REG_TXFIFO) { +// state = SpiState.WRITE_TXFIFO; +// } +// } +// if (data < 0x0f) { +// strobe(data); +// state = SpiState.WAITING; +// } +// usartDataPos = 0; +// // Assuming that the status always is sent back??? +// //source.byteReceived(status); +// break; +// +// case WRITE_REGISTER: +// if (usartDataPos == 0) { +// source.byteReceived(registers[usartDataAddress] >> 8); +// // set the high bits +// usartDataValue = data << 8; +// // registers[usartDataAddress] = (registers[usartDataAddress] & 0xff) | (data << 8); +// usartDataPos = 1; +// } else { +// source.byteReceived(registers[usartDataAddress] & 0xff); +// // set the low bits +// usartDataValue |= data; +// // registers[usartDataAddress] = (registers[usartDataAddress] & 0xff00) | data; +// +// if (DEBUG) { +// log("wrote to " + Utils.hex8(usartDataAddress) + " = " + usartDataValue); +// } +// setReg(usartDataAddress, usartDataValue); +// /* register written - go back to waiting... */ +// state = SpiState.WAITING; +// } +// break; +// case READ_REGISTER: +// if (usartDataPos == 0) { +// source.byteReceived(registers[usartDataAddress] >> 8); +// usartDataPos = 1; +// } else { +// source.byteReceived(registers[usartDataAddress] & 0xff); +// if (DEBUG) { +// log("read from " + Utils.hex8(usartDataAddress) + " = " +// + registers[usartDataAddress]); +// } +// state = SpiState.WAITING; +// } +// return; +// //break; +// case READ_RXFIFO: { +// int fifoData = rxFIFO.read(); +// if (DEBUG) log("RXFIFO READ: " + rxFIFO.stateToString()); +// source.byteReceived(fifoData); +// +// /* first check and clear FIFOP - since we now have read a byte! */ +// if (currentFIFOP && !overflow) { +// /* FIFOP is lowered when rxFIFO is lower than or equal to fifopThr */ +// if(rxFIFO.length() <= fifopThr) { +// if (DEBUG) log("*** FIFOP cleared at: " + rxFIFO.stateToString()); +// setFIFOP(false); +// } +// } +// +// /* initiate read of another packet - update some variables to keep track of packet reading... */ +// if (rxfifoReadLeft == 0) { +// rxfifoReadLeft = fifoData; +// if (DEBUG) log("Init read of packet - len: " + rxfifoReadLeft + +// " fifo: " + rxFIFO.stateToString()); +// } else if (--rxfifoReadLeft == 0) { +// /* check if we have another packet in buffer */ +// if (rxFIFO.length() > 0) { +// /* check if the packet is complete or longer than fifopThr */ +// if (rxFIFO.length() > rxFIFO.peek(0) || +// (rxFIFO.length() > fifopThr && !decodeAddress && !frameRejected)) { +// if (DEBUG) log("More in FIFO - FIFOP = 1! plen: " + rxFIFO.stateToString()); +// if (!overflow) setFIFOP(true); +// } +// } +// } +// // Set the FIFO pin low if there are no more bytes available in the RXFIFO. +// if (rxFIFO.length() == 0) { +// if (DEBUG) log("Setting FIFO to low (buffer empty)"); +// setFIFO(false); +// } +// } +// return; /* avoid returning the status byte */ +// case WRITE_TXFIFO: +// if(txfifoFlush) { +// txCursor = 0; +// txfifoFlush = false; +// } +// if (DEBUG) log("Writing data: " + data + " to tx: " + txCursor); +// +// if(txCursor == 0) { +// if ((data & 0xff) > 127) { +// logger.warning(this, "CC2520: Warning - packet size too large: " + (data & 0xff)); +// } +// } else if (txCursor > 127) { +// logger.warning(this, "CC2520: Warning - TX Cursor wrapped"); +// txCursor = 0; +// } +// memory[RAM_TXFIFO + txCursor] = data & 0xff; +// txCursor++; +// if (sendEvents) { +// sendEvent("WRITE_TXFIFO", null); +// } +// break; +// case RAM_ACCESS: +// if (usartDataPos == 0) { +// usartDataAddress |= (data << 1) & 0x180; +// ramRead = (data & FLAG_RAM_READ) != 0; +// if (DEBUG) { +// log("Address: " + Utils.hex16(usartDataAddress) + " read: " + ramRead); +// } +// usartDataPos++; +// } else { +// if (!ramRead) { +// memory[usartDataAddress++] = data; +// if (usartDataAddress >= 0x180) { +// logger.warning(this, "CC2520: Warning - RAM position too big - wrapping!"); +// usartDataAddress = 0; +// } +// if (DEBUG && usartDataAddress == RAM_PANID + 2) { +// log("Pan ID set to: 0x" + +// Utils.hex8(memory[RAM_PANID]) + +// Utils.hex8(memory[RAM_PANID + 1])); +// } +// } else { +// //log("Read RAM Addr: " + address + " Data: " + memory[address]); +// source.byteReceived(memory[usartDataAddress++]); +// if (usartDataAddress >= 0x180) { +// logger.warning(this, "CC2520: Warning - RAM position too big - wrapping!"); +// usartDataAddress = 0; +// } +// return; +// } +// } +// break; +// } +// source.byteReceived(oldStatus); + } + + void stxon() { + // State transition valid from IDLE state or all RX states + if( (stateMachine == RadioState.IDLE) || + (stateMachine == RadioState.RX_CALIBRATE) || + (stateMachine == RadioState.RX_SFD_SEARCH) || + (stateMachine == RadioState.RX_FRAME) || + (stateMachine == RadioState.RX_OVERFLOW) || + (stateMachine == RadioState.RX_WAIT)) { + status |= STATUS_TX_ACTIVE; + setState(RadioState.TX_CALIBRATE); + if (sendEvents) { + sendEvent("STXON", null); + } + // Starting up TX subsystem - indicate that we are in TX mode! + if (DEBUG) log("Strobe STXON - transmit on! at " + cpu.cycles); + } + } + + // Needs to get information about when it is possible to write + // next data... + private void strobe(int data) { + // Resets, on/off of different things... + if (DEBUG) { + log("Strobe on: " + Utils.hex8(data)); // + " => " + Reg.values()[data]); + } + + if( (stateMachine == RadioState.POWER_DOWN) && (data != INS_SXOSCON) ) { + if (DEBUG) log("Got command strobe: " + data + " in POWER_DOWN. Ignoring."); + return; + } + + switch (data) { + case INS_SNOP: + if (DEBUG) log("SNOP => " + Utils.hex8(status) + " at " + cpu.cycles); + break; + case INS_SRXON: + if(stateMachine == RadioState.IDLE) { + setState(RadioState.RX_CALIBRATE); + //updateActiveFrequency(); + if (DEBUG) { + log("Strobe RX-ON!!!"); + } + } else { + if (DEBUG) log("WARNING: SRXON when not IDLE"); + } + + break; + case INS_SRFOFF: + if (DEBUG) { + log("Strobe RXTX-OFF!!! at " + cpu.cycles); + if (stateMachine == RadioState.TX_ACK || + stateMachine == RadioState.TX_FRAME || + stateMachine == RadioState.RX_FRAME) { + log("WARNING: turning off RXTX during " + stateMachine); + } + } + setState(RadioState.IDLE); + break; + case INS_STXON: + stxon(); + break; + case INS_STXONCCA: + // Only valid from all RX states, + // since CCA requires ??(look this up) receive symbol periods to be valid + if( (stateMachine == RadioState.RX_CALIBRATE) || + (stateMachine == RadioState.RX_SFD_SEARCH) || + (stateMachine == RadioState.RX_FRAME) || + (stateMachine == RadioState.RX_OVERFLOW) || + (stateMachine == RadioState.RX_WAIT)) { + + if (sendEvents) { + sendEvent("STXON_CCA", null); + } + + if(cca) { + status |= STATUS_TX_ACTIVE; + setState(RadioState.TX_CALIBRATE); + if (DEBUG) log("Strobe STXONCCA - transmit on! at " + cpu.cycles); + }else{ + if (DEBUG) log("STXONCCA Ignored, CCA false"); + } + } + break; + case INS_SFLUSHRX: + flushRX(); + break; + case INS_SFLUSHTX: + if (DEBUG) log("Flushing TXFIFO"); + flushTX(); + break; + case INS_SXOSCON: + //log("Strobe Oscillator On"); + startOscillator(); + break; + case INS_SXOSCOFF: + //log("Strobe Oscillator Off"); + stopOscillator(); + break; + case INS_SACK: + case INS_SACKPEND: + // Set the frame pending flag for all future autoack based on SACK/SACKPEND + ackFramePending = data == INS_SACKPEND; + if (stateMachine == RadioState.RX_FRAME) { + shouldAck = true; + } else if (crcOk) { + setState(RadioState.TX_ACK_CALIBRATE); + } + break; + default: + if (DEBUG) { + log("Unknown strobe command: " + data); + } + break; + } + } + + private void shrNext() { + if(shrPos == 5) { + // Set SFD high + setSFD(true); + + if (stateMachine == RadioState.TX_PREAMBLE) { + setState(RadioState.TX_FRAME); + } else if (stateMachine == RadioState.TX_ACK_PREAMBLE) { + setState(RadioState.TX_ACK); + } else { + log("Can not move to TX_FRAME or TX_ACK after preamble since radio is in wrong mode: " + + stateMachine); + } + } else { + if (rfListener != null) { + if (DEBUG) log("transmitting byte: " + Utils.hex8(SHR[shrPos])); + rfListener.receivedByte(SHR[shrPos]); + } + shrPos++; + cpu.scheduleTimeEventMillis(shrEvent, SYMBOL_PERIOD * 2); + } + } + + private void txNext() { + if(txfifoPos <= memory[RAM_TXFIFO]) { + int len = memory[RAM_TXFIFO] & 0xff; + if (txfifoPos == len - 1) { + txCrc.setCRC(0); + for (int i = 1; i < len - 1; i++) { + txCrc.addBitrev(memory[RAM_TXFIFO + i] & 0xff); + } + memory[RAM_TXFIFO + len - 1] = txCrc.getCRCHi(); + memory[RAM_TXFIFO + len] = txCrc.getCRCLow(); + } + if (txfifoPos > 0x7f) { + logw("**** Warning - packet size too large - repeating packet bytes txfifoPos: " + txfifoPos); + } + if (rfListener != null) { + if (DEBUG) log("transmitting byte: " + Utils.hex8(memory[RAM_TXFIFO + (txfifoPos & 0x7f)] & 0xFF)); + rfListener.receivedByte((byte)(memory[RAM_TXFIFO + (txfifoPos & 0x7f)] & 0xFF)); + } + txfifoPos++; + // Two symbol periods to send a byte... + cpu.scheduleTimeEventMillis(sendEvent, SYMBOL_PERIOD * 2); + } else { + if (DEBUG) log("Completed Transmission."); + status &= ~STATUS_TX_ACTIVE; + setSFD(false); + if (overflow) { + /* TODO: is it going back to overflow here ?=? */ + setState(RadioState.RX_OVERFLOW); + } else { + setState(RadioState.RX_CALIBRATE); + } + /* Back to RX ON */ + setMode(MODE_RX_ON); + txfifoFlush = true; + } + } + + private void ackNext() { + if (ackPos < ackBuf.length) { + if(ackPos == 0) { + txCrc.setCRC(0); + if (ackFramePending) { + ackBuf[1] |= FRAME_PENDING; + } else { + ackBuf[1] &= ~FRAME_PENDING; + } + // set dsn + ackBuf[3] = dsn; + int len = 4; + for (int i = 1; i < len; i++) { + txCrc.addBitrev(ackBuf[i] & 0xff); + } + ackBuf[4] = txCrc.getCRCHi(); + ackBuf[5] = txCrc.getCRCLow(); + } + if (rfListener != null) { + if (DEBUG) log("transmitting byte: " + Utils.hex8(memory[RAM_TXFIFO + (txfifoPos & 0x7f)] & 0xFF)); + + rfListener.receivedByte((byte)(ackBuf[ackPos] & 0xFF)); + } + ackPos++; + // Two symbol periods to send a byte... + cpu.scheduleTimeEventMillis(ackEvent, SYMBOL_PERIOD * 2); + } else { + if (DEBUG) log("Completed Transmission of ACK."); + status &= ~STATUS_TX_ACTIVE; + setSFD(false); + setState(RadioState.RX_CALIBRATE); + /* Back to RX ON */ + setMode(MODE_RX_ON); + } + } + + + private void setSymbolEvent(int symbols) { + double period = SYMBOL_PERIOD * symbols; + cpu.scheduleTimeEventMillis(symbolEvent, period); + //log("Set Symbol event: " + period); + } + + private void startOscillator() { + // 1ms crystal startup from datasheet pg12 + cpu.scheduleTimeEventMillis(oscillatorEvent, 1); + } + + private void stopOscillator() { + status &= ~STATUS_XOSC16M_STABLE; + setState(RadioState.POWER_DOWN); + if (DEBUG) log("Oscillator Off."); + // Reset state + setFIFOP(false); + } + + private void flushRX() { + if (DEBUG) { + log("Flushing RX len = " + rxFIFO.length()); + } + rxFIFO.reset(); + setSFD(false); + setFIFOP(false); + setFIFO(false); + overflow = false; + /* goto RX Calibrate */ + if( (stateMachine == RadioState.RX_CALIBRATE) || + (stateMachine == RadioState.RX_SFD_SEARCH) || + (stateMachine == RadioState.RX_FRAME) || + (stateMachine == RadioState.RX_OVERFLOW) || + (stateMachine == RadioState.RX_WAIT)) { + setState(RadioState.RX_SFD_SEARCH); + } + } + + // TODO: update any pins here? + private void flushTX() { + txCursor = 0; + } + + private void updateCCA() { + // boolean oldCCA = cca; + // int ccaMux = (registers[REG_IOCFG1] & CCAMUX); + + // if (ccaMux == CCAMUX_CCA) { + // /* If RSSI is less than -95 then we have CCA / clear channel! */ + // cca = (status & STATUS_RSSI_VALID) > 0 && rssi < -95; + // } else if (ccaMux == CCAMUX_XOSC16M_STABLE) { + // cca = (status & STATUS_XOSC16M_STABLE) > 0; + // } + + // if (cca != oldCCA) { + // setInternalCCA(cca); + // } + } + + private void setInternalCCA(boolean clear) { + setCCA(clear); + if (DEBUG) log("Internal CCA: " + clear); + } + + private void setSFD(boolean sfd) { + currentSFD = sfd; + sfdGPIO.setActive(sfd); +// if( (registers[REG_GPIOPOLARITY] & SFD_POLARITY) == SFD_POLARITY) +// sfdPort.setPinState(sfdPin, sfd ? 0 : 1); +// else +// sfdPort.setPinState(sfdPin, sfd ? 1 : 0); + if (DEBUG) log("SFD: " + sfd + " " + cpu.cycles); + } + + private void setCCA(boolean cca) { + currentCCA = cca; + ccaGPIO.setActive(cca); + if (DEBUG) log("Setting CCA to: " + cca); +// if( (registers[REG_GPIOPOLARITY] & CCA_POLARITY) == CCA_POLARITY) +// ccaPort.setPinState(ccaPin, cca ? 0 : 1); +// else +// ccaPort.setPinState(ccaPin, cca ? 1 : 0); + } + + private void setFIFOP(boolean fifop) { + currentFIFOP = fifop; + fifopGPIO.setActive(fifop); +// if (DEBUG) log("Setting FIFOP to " + fifop); +// if( (registers[REG_GPIOPOLARITY] & FIFOP_POLARITY) == FIFOP_POLA... [truncated message content] |