You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(21) |
Nov
(12) |
Dec
(41) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(25) |
Feb
(54) |
Mar
(63) |
Apr
(52) |
May
(17) |
Jun
(3) |
Jul
(3) |
Aug
(5) |
Sep
(49) |
Oct
(50) |
Nov
(34) |
Dec
(14) |
2009 |
Jan
(9) |
Feb
(15) |
Mar
(38) |
Apr
(12) |
May
(35) |
Jun
(20) |
Jul
(2) |
Aug
(7) |
Sep
(36) |
Oct
(24) |
Nov
(2) |
Dec
(2) |
2010 |
Jan
(14) |
Feb
(1) |
Mar
(36) |
Apr
(2) |
May
(4) |
Jun
(6) |
Jul
(35) |
Aug
(11) |
Sep
(8) |
Oct
(3) |
Nov
|
Dec
(1) |
2011 |
Jan
(11) |
Feb
(12) |
Mar
(3) |
Apr
(7) |
May
(12) |
Jun
(8) |
Jul
|
Aug
(3) |
Sep
(4) |
Oct
|
Nov
(2) |
Dec
(4) |
2012 |
Jan
(2) |
Feb
(1) |
Mar
(14) |
Apr
(5) |
May
(28) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(21) |
Nov
(4) |
Dec
(1) |
2013 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <jo...@us...> - 2010-03-01 22:27:17
|
Revision: 662 http://mspsim.svn.sourceforge.net/mspsim/?rev=662&view=rev Author: joxe Date: 2010-03-01 22:27:08 +0000 (Mon, 01 Mar 2010) Log Message: ----------- minor change for timers to handle start/stop better Modified Paths: -------------- mspsim/se/sics/mspsim/core/Timer.java Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2010-02-17 12:31:40 UTC (rev 661) +++ mspsim/se/sics/mspsim/core/Timer.java 2010-03-01 22:27:08 UTC (rev 662) @@ -791,6 +791,21 @@ } void resetCounter(long cycles) { + double divider = 1.0; + if (clockSource == SRC_ACLK) { + // Should later be divided with DCO clock? + divider = 1.0 * core.smclkFrq / core.aclkFrq; + } + divider = divider * inputDivider; + + // These calculations assume that we have a big counter that counts from + // last reset and upwards (without any roundoff errors). + // tick - represent the counted value since last "reset" of some kind + // counterAcc - represent the value of the counter at the last reset. + long cycctr = cycles - counterStart; + double tick = cycctr / divider; + counterPassed = (int) (divider * (tick - (long) (tick))); + counterStart = cycles - counterPassed; // set counterACC to the last returned value (which is the same // as bigCounter except that it is "moduloed" to a smaller value This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2010-02-17 12:51:22
|
Revision: 661 http://mspsim.svn.sourceforge.net/mspsim/?rev=661&view=rev Author: joxe Date: 2010-02-17 12:31:40 +0000 (Wed, 17 Feb 2010) Log Message: ----------- added short addr recognition for autoack Modified Paths: -------------- mspsim/se/sics/mspsim/chip/CC2420.java Modified: mspsim/se/sics/mspsim/chip/CC2420.java =================================================================== --- mspsim/se/sics/mspsim/chip/CC2420.java 2010-01-30 15:16:06 UTC (rev 660) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2010-02-17 12:31:40 UTC (rev 661) @@ -166,6 +166,10 @@ public static final int RAM_PANID = 0x168; public static final int RAM_SHORTADDR = 0x16A; + public static final int SHORT_ADDRESS = 2; + public static final int LONG_ADDRESS = 3; + + // The Operation modes of the CC2420 public static final int MODE_TXRX_OFF = 0x00; public static final int MODE_RX_ON = 0x01; @@ -611,18 +615,36 @@ } } + /* TODO: refactor into two different methods on for ADDR_DECODE / ADDR_RECOG one for autoack. */ + /* Also add PAN_ID checks */ private boolean checkAutoack() { + /* ack request or not ? */ boolean ackReq = (memory[RAM_RXFIFO + lastPacketStart] & ACK_REQUEST) != 0; if (!ackReq) return false; - /* here we need to check that this address is correct compared to the stored address */ - int addrSize = 8; /* this is hard coded to a long address - can be short!!! */ - int addrPos = lastPacketStart + 5; // where starts the destination address of the packet!!!?? - for (int i = 0; i < addrSize; i++) { - /* System.out.println("checkAutoack i " + i + " mem " + + + /* check addressing mode */ + int destAddrMode = (memory[RAM_RXFIFO + lastPacketStart + 1] >> 2) & 3; + if (destAddrMode == LONG_ADDRESS) { + /* here we need to check that this address is correct compared to the stored address */ + int addrSize = 8; /* this is hard coded to a long address - can be short!!! */ + int addrPos = lastPacketStart + 5; // where starts the destination address of the packet!!!?? + for (int i = 0; i < addrSize; i++) { + /* System.out.println("checkAutoack i " + i + " mem " + memory[RAM_IEEEADDR + i] + " != " + memory[RAM_RXFIFO + ((addrPos + i) & 127)]);*/ - if (memory[RAM_IEEEADDR + i] != memory[RAM_RXFIFO + ((addrPos + i) & 127)]) { - return false; + if (memory[RAM_IEEEADDR + i] != memory[RAM_RXFIFO + ((addrPos + i) & 127)]) { + return false; + } } + } else { + /* should check short address */ + int addrPos = lastPacketStart + 5; // where starts the destination address of the packet!!!?? + for (int i = 0; i < 2; i++) { + /* System.out.println("checkAutoack i " + i + " mem " + + memory[RAM_IEEEADDR + i] + " != " + memory[RAM_RXFIFO + ((addrPos + i) & 127)]);*/ + if (memory[RAM_SHORTADDR + i] != memory[RAM_RXFIFO + ((addrPos + i) & 127)]) { + return false; + } + } } return true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2010-01-30 15:16:13
|
Revision: 660 http://mspsim.svn.sourceforge.net/mspsim/?rev=660&view=rev Author: joxe Date: 2010-01-30 15:16:06 +0000 (Sat, 30 Jan 2010) Log Message: ----------- improved autoack functionality - only for long addr yet. Modified Paths: -------------- mspsim/se/sics/mspsim/chip/CC2420.java Modified: mspsim/se/sics/mspsim/chip/CC2420.java =================================================================== --- mspsim/se/sics/mspsim/chip/CC2420.java 2010-01-30 14:07:51 UTC (rev 659) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2010-01-30 15:16:06 UTC (rev 660) @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007, 2008, 2009 Swedish Institute of Computer Science. + * Copyright (c) 2007, 2008, 2009, 2010 Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -425,7 +425,8 @@ break; case RX_CALIBRATE: - setSymbolEvent(12); + /* should be 12 according to specification */ + setSymbolEvent(8); setMode(MODE_RX_ON); break; @@ -557,11 +558,11 @@ int crc = memory[RAM_RXFIFO + ((rxfifoWritePos + 128 - 2) & 127)] << 8; crc += memory[RAM_RXFIFO + ((rxfifoWritePos + 128 - 1) & 127)]; -// if (crc == rxCrc.getCRC()) { -// System.out.println("CRC OK"); -// } else { -// //System.out.println("CRC not OK: recv:" + crc + " calc: " + rxCrc.getCRC()); -// } + if (crc == rxCrc.getCRC()) { + System.out.println("CRC OK"); + } else { + System.out.println("CRC not OK: recv:" + crc + " calc: " + rxCrc.getCRC()); + } // Should take a RSSI value as input or use a set-RSSI value... memory[RAM_RXFIFO + ((rxfifoWritePos + 128 - 2) & 127)] = (registers[REG_RSSI]) & 0xff; // Set CRC ok and add a correlation - TODO: fix better correlation value!!! @@ -575,6 +576,7 @@ lastPacketStart); /* if either manual ack request (shouldAck) or autoack + ACK_REQ on package do ack! */ + // System.out.println("Autoack " + autoAck + " checkAutoack " + checkAutoack() + " shouldAck " + shouldAck); if ((autoAck && checkAutoack()) || shouldAck) { ackBuf[ACK_SEQPOS] = memory[RAM_RXFIFO + lastPacketStart + 2]; /* find the seq no!!! */ setState(RadioState.TX_ACK_CALIBRATE); @@ -614,9 +616,11 @@ if (!ackReq) return false; /* here we need to check that this address is correct compared to the stored address */ int addrSize = 8; /* this is hard coded to a long address - can be short!!! */ - int addrPos = lastPacketStart + 2 + 1; // where starts the destination address of the packet!!!?? + int addrPos = lastPacketStart + 5; // where starts the destination address of the packet!!!?? for (int i = 0; i < addrSize; i++) { - if (memory[RAM_IEEEADDR + i] != memory[RAM_RXFIFO + (addrPos + i) & 127]) { + /* System.out.println("checkAutoack i " + i + " mem " + + memory[RAM_IEEEADDR + i] + " != " + memory[RAM_RXFIFO + ((addrPos + i) & 127)]);*/ + if (memory[RAM_IEEEADDR + i] != memory[RAM_RXFIFO + ((addrPos + i) & 127)]) { return false; } } @@ -884,7 +888,7 @@ if(shrPos == 5) { // Set SFD high setSFD(true); - + if (stateMachine == RadioState.TX_PREAMBLE) { setState(RadioState.TX_FRAME); } else if (stateMachine == RadioState.TX_ACK_PREAMBLE) { @@ -943,11 +947,25 @@ txfifoFlush = true; } } - + private void ackNext() { if (ackPos < ackBuf.length) { + if(ackPos == 0) { + txCrc.setCRC(0); + int len = 3; + for (int i = 0; i < len; i++) { + txCrc.add(ackBuf[i] & 0xff); + } + // System.out.println("Setting TX CRC to: " + txCrc.getCRC()); + /* this is not correct - will probably not be compliant with the order + * that the actual CC2420 sends the CRC... + */ + ackBuf[4] = txCrc.getCRC() >> 8; + ackBuf[5] = txCrc.getCRC() & 0xff; + } if (listener != null) { if (DEBUG) log("transmitting byte: " + Utils.hex8(memory[RAM_TXFIFO + (txfifoPos & 0x7f)] & 0xFF)); + listener.receivedByte((byte)(ackBuf[ackPos] & 0xFF)); } ackPos++; @@ -1233,5 +1251,4 @@ public void stateChanged(int state) { } -} // CC2420 - +} // CC2420 \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2010-01-30 14:07:57
|
Revision: 659 http://mspsim.svn.sourceforge.net/mspsim/?rev=659&view=rev Author: joxe Date: 2010-01-30 14:07:51 +0000 (Sat, 30 Jan 2010) Log Message: ----------- changed events and interrupt handling in Timer subsystem Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/se/sics/mspsim/core/Timer.java Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2010-01-21 08:21:54 UTC (rev 658) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2010-01-30 14:07:51 UTC (rev 659) @@ -604,7 +604,7 @@ if (triggerIR) { interruptSource[interrupt] = source; - if (debugInterrupts ) { + if (debugInterrupts) { if (source != null) { System.out.println("### Interrupt flagged ON by " + source.getName() + " prio: " + interrupt); } else { Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2010-01-21 08:21:54 UTC (rev 658) +++ mspsim/se/sics/mspsim/core/Timer.java 2010-01-30 14:07:51 UTC (rev 659) @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007, Swedish Institute of Computer Science. + * Copyright (c) 2007-2010, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -197,8 +197,6 @@ private final int ccr0Vector; private final MSP430Core core; - private String triggerDesc = ""; - // Support variables Max 7 compare regs for now (timer b) private final int noCompare; @@ -215,6 +213,7 @@ boolean captureOn = false; int inputSel; int inputSrc; + long cyclesLeft = 0; boolean sync; int outMode; @@ -226,15 +225,28 @@ interruptVector = vector; this.index = index; } + + String getName() { + return "CCR " + index; + } public void execute(long t) { if (mode == STOP) { + //System.out.println("**** IGNORING EXECUTION OF CCR - timer stopped!!!"); return; } long cycles = core.cycles; updateCounter(cycles); if (expCaptureTime != -1 && cycles >= expCaptureTime) { + /* sometimes the event seems to be triggered too early... */ + if (counter < tccr) { + if (DEBUG) System.out.println("**** Counter too small: " + counter + " vs " + tccr); + int diff = tccr - counter; + expCaptureTime = cycles + (long) (diff * cyclesMultiplicator); + update(); + return; + } if (DEBUG) { System.out.println(getName() + (captureOn ? " CAPTURE: " : " COMPARE: ") + index + " Cycles: " + cycles + " expCap: " + expCaptureTime + @@ -267,10 +279,26 @@ } /* schedule again! */ update(); - triggerInterrupts(cycles); + triggerInterrupt(cycles); } } + /* this method only takes care of the interrupt triggering! */ + public void triggerInterrupt(long cycles) { + /* trigger if trigger should be... */ + if ((tcctl & CC_TRIGGER_INT) == CC_TRIGGER_INT) { + if (index == 0) { + core.flagInterrupt(interruptVector, Timer.this, true); + } else if (lastTIV == 0) { + lastTIV = index * 2; + core.flagInterrupt(interruptVector, Timer.this, true); + } else if (lastTIV > index * 2) { + /* interrupt already triggered, but set to this lower IRQ */ + lastTIV = index * 2; + } + } + } + public void updateCaptures(long cycles) { int divisor = 1; int frqClk = 1; @@ -326,22 +354,44 @@ public void update() { /* schedule this capture register for update*/ if (expCaptureTime != -1 && expCaptureTime != time) { + if (DEBUG) System.out.println(core.cycles + ":" + ">> SCHEDULING " + getName() + " = " + tccr + + " TR: " + counter + " at: " + expCaptureTime); core.scheduleCycleEvent(this, expCaptureTime); } } + + public void timerStarted(long cycles) { + if (cyclesLeft != 0) { + expCaptureTime = cycles + cyclesLeft; + update(); + } + } + + public void timerStopped(long cycles) { + if (expCaptureTime != -1) { + cyclesLeft = cycles - expCaptureTime; + if (cyclesLeft < 0) { + cyclesLeft = 0; + } + } + } + } private CCR ccr[] = new CCR[7]; private TimeEvent counterTrigger = new TimeEvent(0, "Timer Counter Trigger") { public void execute(long t) { - long cycles = core.cycles; interruptPending = true; /* and can be something else if mode is another... */ // This should be updated whenever clockspeed changes... nextTimerTrigger = (long) (nextTimerTrigger + 0x10000 * cyclesMultiplicator); core.scheduleCycleEvent(this, nextTimerTrigger); - triggerInterrupts(cycles); + + if (lastTIV == 0 && interruptEnable) { + lastTIV = memory[tiv] = timerOverflow; + core.flagInterrupt(ccr1Vector, Timer.this, true); + } } }; @@ -480,7 +530,7 @@ System.out.println("Not supported read, returning zero!!!"); } - if (DEBUG && false) { + if (DEBUG) { System.out.println(getName() + ": Read " + getName(address) + "(" + Utils.hex16(address) + ") => " + Utils.hex16(val) + " (" + val + ")"); } @@ -514,20 +564,29 @@ private void resetTIV(long cycles) { if (lastTIV == timerOverflow) { interruptPending = false; - lastTIV = 0; if (DEBUG) { System.out.println(getName() + " Clearing TIV - overflow "); } - triggerInterrupts(cycles); - } - if (lastTIV / 2 < noCompare) { + } else if (lastTIV / 2 < noCompare) { if (DEBUG) { - System.out.println(getName() + " Clearing IFG for CCR" + (lastTIV/2)); + System.out.println(core.cycles + ":" + getName() + " Clearing IFG for CCR" + (lastTIV/2)); } // Clear interrupt flags! ccr[lastTIV / 2].tcctl &= ~CC_IFG; - triggerInterrupts(cycles); } + + /* flag this interrupt off */ + core.flagInterrupt(ccr1Vector, this, false); + lastTIV = 0; + + /* reevaluate interrupts for the ccr1 vector - possibly flag on again... */ + for (int i = 1; i < noCompare; i++) { + ccr[i].triggerInterrupt(cycles); + } + /* if the timer overflow interrupt is triggering - lowest priority => signal! */ + if (lastTIV == 0 && interruptEnable & interruptPending) { + core.flagInterrupt(ccr1Vector, this, true); + } } public void write(int address, int data, boolean word, long cycles) { @@ -563,7 +622,6 @@ counter = 0; resetCounter(cycles); -// updateCaptures(-1, cycles); for (int i = 0; i < noCompare; i++) { ccr[i].updateCaptures(cycles); } @@ -580,8 +638,23 @@ if (DEBUG) { System.out.println(getName() + " Starting timer!"); } - recalculateCompares(cycles); + + for (int i = 0; i < noCompare; i++) { + ccr[i].timerStarted(cycles); + } + + if (DEBUG) System.out.println(core.cycles + ":" + getName() + " Timer started: " + counter + " CCR1:" + ccr[1].expCaptureTime); + } + if (mode != STOP && newMode == STOP) { + /* call update counter to remember how many cycles that passed before this stop... */ + updateCounter(cycles); + for (int i = 0; i < noCompare; i++) { + ccr[i].timerStopped(cycles); + } + if (DEBUG) System.out.println(core.cycles + ":" + getName() + " Timer stopped: " + counter + " CCR1:" + ccr[1].expCaptureTime); + } + mode = newMode; interruptEnable = (data & 0x02) > 0; @@ -642,8 +715,6 @@ updateCounter(cycles); - triggerInterrupts(cycles); - if (DEBUG) { System.out.println(getName() + " Write: CCTL" + index + ": => " + Utils.hex16(data) + @@ -679,7 +750,7 @@ ccr[index].tccr = data; int diff = data - counter; - if (diff < 0) { + if (diff <= 0) { // Ok we need to wrap! diff += 0x10000; } @@ -735,7 +806,6 @@ resetCounter(cycles); } - private int updateCounter(long cycles) { if (mode == STOP) return counter; @@ -790,101 +860,6 @@ return counter; } - private void recalculateCompares(long cycles) { - for (int i = 0; i < noCompare; i++) { - CCR reg = ccr[i]; - if (reg.expCaptureTime != 0) { - int diff = reg.tccr - counter; - if (diff < 0) { - // Wrap... - diff += 0x10000; - } - reg.expCaptureTime = cycles + (long) (diff * cyclesMultiplicator); - reg.update(); - } - } - } - - // Can be called to generate any interrupt... - // TODO: check if it is ok that this also sets the flags to false or if that must - // be done by software (e.g. firmware) - public void triggerInterrupts(long cycles) { - // First check if any capture register is generating an interrupt... - boolean trigger = false; - - int tIndex = 0; - for (int i = 0, n = noCompare; i < n; i++) { - CCR reg = ccr[i]; - // check for both IFG and IE - boolean newTrigger = (reg.tcctl & CC_TRIGGER_INT) == CC_TRIGGER_INT; - trigger = trigger | newTrigger; - - // This only triggers interrupts - reading TIV clears!??! - if (i == 0) { - // Execute the interrupt vector... the high-pri one... - if (DEBUG) { - System.out.println(getName() +" >>>> Trigger IRQ for CCR0: " + reg.tccr + - " TAR: " + counter + " cycles: " + cycles + " expCap: " + reg.expCaptureTime); - } - if (DEBUG && counter < reg.tccr && trigger) { - System.out.print("***** WARNING!!! CTR Err "); - System.out.println(getName() +" >>>> Trigger IRQ for CCR0: " + reg.tccr + - " TAR: " + counter + " cycles: " + cycles + " expCap: " + reg.expCaptureTime + - " counterPassed: " + counterPassed); - } - core.flagInterrupt(ccr0Vector, this, trigger); - // Trigger this! - // This is handled by its own vector!!! - if (trigger) { - lastTIV = 0; - triggerTime = cycles; - return; - } - } else { - // Which would have the highest pri? Will/should this trigger more - // than one interrupt at a time?!!?!?! - // If so, which TIV would be the correct one? - if (newTrigger) { - if (DEBUG) { - System.out.println(getName() + " >>>> Triggering IRQ for CCR" + i + - " at cycles:" + cycles + " CCR" + i + ": " + reg.tccr + " TAR: " + - counter); - } - tIndex = i; - // Lower numbers are higher priority - break; - } - } - } - - if (trigger) { - // Or if other CCR execute the normal one with correct TAIV - lastTIV = memory[tiv] = tIndex * 2; - triggerTime = cycles; - if (DEBUG) System.out.println(getName() + - " >>>> Triggering IRQ for CCR" + tIndex + - " at cycles:" + cycles + " CCR" + tIndex + ": " + ccr[tIndex].tccr + " TAR: " + - counter); - if (DEBUG && counter < ccr[tIndex].tccr) { - System.out.print("***** WARNING!!! CTR Err "); - System.out.println(getName() + - " >>>> Triggering IRQ for CCR" + tIndex + - " at cycles:" + cycles + " CCR" + tIndex + ": " + ccr[tIndex].tccr + " TAR: " + - counter + " expCap: " + ccr[tIndex].expCaptureTime + " counterPassed: " + counterPassed); - } - } - - if (!trigger) { - if (interruptEnable && interruptPending) { - trigger = true; - lastTIV = memory[tiv] = timerOverflow; - } - } - -// System.out.println(getName() +">>>> Trigger IRQ for CCR:" + tIndex); - core.flagInterrupt(ccr1Vector, this, trigger); - } - public String getSourceName(int source) { switch (source) { case SRC_ACLK: @@ -926,7 +901,8 @@ // value); // Set the interrupt flag... reg.tcctl |= CC_IFG; - triggerInterrupts(core.cycles); + reg.triggerInterrupt(core.cycles); + /* triggerInterrupts(core.cycles); */ } } } @@ -937,14 +913,15 @@ if (vector == ccr0Vector) { // Reset the interrupt trigger in "core". core.flagInterrupt(ccr0Vector, this, false); - // Remove the flag also... + // Remove the flag also - but only for the dedicated vector (CCR0) ccr[0].tcctl &= ~CC_IFG; } if (MSP430Core.debugInterrupts) { System.out.println(getName() + " >>>> interrupt Serviced " + lastTIV + " at cycles: " + core.cycles + " servicing delay: " + (core.cycles - triggerTime)); } - triggerInterrupts(core.cycles); + /* old method is replaced */ + /* triggerInterrupts(core.cycles); */ } public int getModeMax() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2010-01-21 08:22:00
|
Revision: 658 http://mspsim.svn.sourceforge.net/mspsim/?rev=658&view=rev Author: joxe Date: 2010-01-21 08:21:54 +0000 (Thu, 21 Jan 2010) Log Message: ----------- fixed CC2420 defaults on MDM0 register + removed cloneable from CLI commands Modified Paths: -------------- mspsim/se/sics/mspsim/chip/CC2420.java mspsim/se/sics/mspsim/cli/BasicAsyncCommand.java mspsim/se/sics/mspsim/cli/Command.java mspsim/se/sics/mspsim/cli/CommandHandler.java Modified: mspsim/se/sics/mspsim/chip/CC2420.java =================================================================== --- mspsim/se/sics/mspsim/chip/CC2420.java 2010-01-20 20:15:49 UTC (rev 657) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2010-01-21 08:21:54 UTC (rev 658) @@ -389,9 +389,14 @@ rxfifoReadPos = 0; rxfifoWritePos = 0; overflow = false; + reset(); cpu.addChip(this); } + private void reset() { + setReg(REG_MDMCTRL0, 0x0ae2); + } + private boolean setState(RadioState state) { if(DEBUG) log("State transition from " + stateMachine + " to " + state); stateMachine = state; @@ -405,6 +410,7 @@ flushRX(); flushTX(); status &= ~(STATUS_RSSI_VALID | STATUS_XOSC16M_STABLE); + reset(); setMode(MODE_POWER_OFF); updateCCA(); break; @@ -413,6 +419,7 @@ rxfifoReadPos = 0; rxfifoWritePos = 0; status &= ~(STATUS_RSSI_VALID | STATUS_XOSC16M_STABLE); + reset(); setMode(MODE_POWER_OFF); updateCCA(); break; @@ -579,6 +586,29 @@ } } + private void setReg(int address, int data) { + registers[address] = data; + switch(address) { + case REG_IOCFG0: + setFIFOP(false); + log("IOCFG0: " + registers[address]); + break; + case REG_IOCFG1: + log("IOCFG1: SFDMUX " + + ((registers[address] & SFDMUX) >> SFDMUX) + + " CCAMUX: " + (registers[address] & CCAMUX)); +// if( (registers[address] & CCAMUX) == CCA_CCA) +// setCCA(false); + updateCCA(); + break; + case REG_MDMCTRL0: + addressDecode = (data & ADR_DECODE) != 0; + autoCRC = (data & ADR_AUTOCRC) != 0; + autoAck = (data & AUTOACK) != 0; + break; + } + } + private boolean checkAutoack() { boolean ackReq = (memory[RAM_RXFIFO + lastPacketStart] & ACK_REQUEST) != 0; if (!ackReq) return false; @@ -650,25 +680,7 @@ + registers[address]); } data = registers[address]; - switch(address) { - case REG_IOCFG0: - setFIFOP(false); - log("IOCFG0: " + registers[address]); - break; - case REG_IOCFG1: - log("IOCFG1: SFDMUX " - + ((registers[address] & SFDMUX) >> SFDMUX) - + " CCAMUX: " + (registers[address] & CCAMUX)); -// if( (registers[address] & CCAMUX) == CCA_CCA) -// setCCA(false); - updateCCA(); - break; - case REG_MDMCTRL0: - addressDecode = (data & ADR_DECODE) != 0; - autoCRC = (data & ADR_AUTOCRC) != 0; - autoAck = (data & AUTOACK) != 0; - break; - } + setReg(address, data); /* register written - go back to wating... */ state = SpiState.WAITING; } @@ -1212,6 +1224,7 @@ " FIFOP: " + fifoP + " FIFO: " + currentFIFO + " SFD: " + currentSFD + "\n Radio State: " + stateMachine + " rxFifoLen: " + rxfifoLen + " rxFifoWritePos: " + rxfifoWritePos + " rxFifoReadPos: " + rxfifoReadPos + + "\n AutoACK: " + autoAck + " AddrDecode: " + addressDecode + " AutoCRC: " + autoCRC + "\n SPI State: " + state + "\n Channel: " + activeChannel + "\n"; Modified: mspsim/se/sics/mspsim/cli/BasicAsyncCommand.java =================================================================== --- mspsim/se/sics/mspsim/cli/BasicAsyncCommand.java 2010-01-20 20:15:49 UTC (rev 657) +++ mspsim/se/sics/mspsim/cli/BasicAsyncCommand.java 2010-01-21 08:21:54 UTC (rev 658) @@ -44,9 +44,19 @@ * @author joakim * */ -public abstract class BasicAsyncCommand extends BasicCommand implements AsyncCommand { +public abstract class BasicAsyncCommand extends BasicCommand implements AsyncCommand, Cloneable { public BasicAsyncCommand(String cmdHelp, String argHelp) { super(cmdHelp, argHelp); } + + public Command getInstance() { + try { + return (Command) this.clone(); + } catch (CloneNotSupportedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } } Modified: mspsim/se/sics/mspsim/cli/Command.java =================================================================== --- mspsim/se/sics/mspsim/cli/Command.java 2010-01-20 20:15:49 UTC (rev 657) +++ mspsim/se/sics/mspsim/cli/Command.java 2010-01-21 08:21:54 UTC (rev 658) @@ -1,6 +1,6 @@ package se.sics.mspsim.cli; -public abstract class Command implements Cloneable { +public abstract class Command { /** * Returns a text describing this command. First line is a short description that may be followed by @@ -22,7 +22,8 @@ public abstract int executeCommand(CommandContext context); - public Object clone() throws CloneNotSupportedException { - return super.clone(); + /* default behavior is that it returns *this* instance (which might be bad in some cases) */ + public Object getInstance() { + return this; } } Modified: mspsim/se/sics/mspsim/cli/CommandHandler.java =================================================================== --- mspsim/se/sics/mspsim/cli/CommandHandler.java 2010-01-20 20:15:49 UTC (rev 657) +++ mspsim/se/sics/mspsim/cli/CommandHandler.java 2010-01-21 08:21:54 UTC (rev 658) @@ -126,12 +126,7 @@ private Command getCommand(String cmd) { Command command = commands.get(cmd); if (command != null) { - try { - return (Command) command.clone(); - } catch (CloneNotSupportedException e) { - e.printStackTrace(err); - return null; - } + return (Command) command.getInstance(); } File scriptFile = new File(scriptDirectory, cmd); if (scriptFile.isFile() && scriptFile.canRead()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2010-01-20 20:15:57
|
Revision: 657 http://mspsim.svn.sourceforge.net/mspsim/?rev=657&view=rev Author: joxe Date: 2010-01-20 20:15:49 +0000 (Wed, 20 Jan 2010) Log Message: ----------- some steps toward auto-ack functionality on cc2420 Modified Paths: -------------- mspsim/se/sics/mspsim/chip/CC2420.java Modified: mspsim/se/sics/mspsim/chip/CC2420.java =================================================================== --- mspsim/se/sics/mspsim/chip/CC2420.java 2010-01-19 20:50:43 UTC (rev 656) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2010-01-20 20:15:49 UTC (rev 657) @@ -212,6 +212,9 @@ // 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; @@ -252,6 +255,8 @@ /* if autoack is configured or if */ private boolean autoAck = false; private boolean shouldAck = false; + private boolean addressDecode = false; + private boolean autoCRC = false; private int activeFrequency = 0; private int activeChannel = 0; @@ -361,7 +366,7 @@ private StateListener stateListener = null; private int ackPos; /* type = 2 (ACK), third byte needs to be sequence number... */ - private int[] ackBuf = {0x02, 0x00, 0x00, 0x00, 0x00}; + private int[] ackBuf = {0x05, 0x02, 0x00, 0x00, 0x00, 0x00}; private CCITT_CRC rxCrc = new CCITT_CRC(); private CCITT_CRC txCrc = new CCITT_CRC(); @@ -564,6 +569,7 @@ /* if either manual ack request (shouldAck) or autoack + ACK_REQ on package do ack! */ if ((autoAck && checkAutoack()) || shouldAck) { + ackBuf[ACK_SEQPOS] = memory[RAM_RXFIFO + lastPacketStart + 2]; /* find the seq no!!! */ setState(RadioState.TX_ACK_CALIBRATE); } else { setState(RadioState.RX_WAIT); @@ -584,7 +590,7 @@ return false; } } - return false; + return true; } public void dataReceived(USART source, int data) { @@ -633,20 +639,20 @@ source.byteReceived(registers[address] >> 8); // set the high bits registers[address] = (registers[address] & 0xff) | (data << 8); - pos = 1; + pos = 1; } else { source.byteReceived(registers[address] & 0xff); // set the low bits registers[address] = (registers[address] & 0xff00) | data; - if (address == REG_IOCFG0) { - setFIFOP(false); - } if (DEBUG) { log("wrote to " + Utils.hex8(address) + " = " + registers[address]); + } + data = registers[address]; switch(address) { case REG_IOCFG0: + setFIFOP(false); log("IOCFG0: " + registers[address]); break; case REG_IOCFG1: @@ -657,8 +663,12 @@ // setCCA(false); updateCCA(); break; + case REG_MDMCTRL0: + addressDecode = (data & ADR_DECODE) != 0; + autoCRC = (data & ADR_AUTOCRC) != 0; + autoAck = (data & AUTOACK) != 0; + break; } - } /* register written - go back to wating... */ state = SpiState.WAITING; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2010-01-19 20:50:49
|
Revision: 656 http://mspsim.svn.sourceforge.net/mspsim/?rev=656&view=rev Author: nifi Date: 2010-01-19 20:50:43 +0000 (Tue, 19 Jan 2010) Log Message: ----------- Made TR1001 implement RFSource Modified Paths: -------------- mspsim/se/sics/mspsim/chip/TR1001.java Modified: mspsim/se/sics/mspsim/chip/TR1001.java =================================================================== --- mspsim/se/sics/mspsim/chip/TR1001.java 2010-01-19 20:45:14 UTC (rev 655) +++ mspsim/se/sics/mspsim/chip/TR1001.java 2010-01-19 20:50:43 UTC (rev 656) @@ -47,7 +47,7 @@ /** * */ -public class TR1001 extends Chip implements RFListener { +public class TR1001 extends Chip implements RFListener, RFSource { public static final int MODE_TXRX_OFF = 0x00; public static final int MODE_RX_ON = 0x01; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2010-01-19 20:45:20
|
Revision: 655 http://mspsim.svn.sourceforge.net/mspsim/?rev=655&view=rev Author: nifi Date: 2010-01-19 20:45:14 +0000 (Tue, 19 Jan 2010) Log Message: ----------- added warning for illegal start address Modified Paths: -------------- mspsim/se/sics/mspsim/cli/DebugCommands.java Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2010-01-19 20:29:53 UTC (rev 654) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2010-01-19 20:45:14 UTC (rev 655) @@ -154,7 +154,7 @@ cpu.setBreakPoint(address + i, monitor); } } - context.out.println("Watch set at $" + Utils.hex16(baddr)); + context.err.println("Watch set at $" + Utils.hex16(baddr)); return 0; } @@ -365,6 +365,11 @@ ch.registerCommand("mem", new BasicCommand("dump memory", "<start address> <num_entries> [type] [hex|char]") { public int executeCommand(final CommandContext context) { int start = context.getArgumentAsAddress(0); + if (start < 0) { + context.err.println("Illegal start address: " + + context.getArgument(0)); + return 1; + } int count = context.getArgumentAsInt(1); int mode = Utils.DEC; int type = Utils.UBYTE; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2010-01-19 20:30:05
|
Revision: 654 http://mspsim.svn.sourceforge.net/mspsim/?rev=654&view=rev Author: nifi Date: 2010-01-19 20:29:53 +0000 (Tue, 19 Jan 2010) Log Message: ----------- Fixed TR1001 to register as chip and to handle operation modes Modified Paths: -------------- mspsim/se/sics/mspsim/chip/TR1001.java mspsim/se/sics/mspsim/platform/esb/ESBNode.java Modified: mspsim/se/sics/mspsim/chip/TR1001.java =================================================================== --- mspsim/se/sics/mspsim/chip/TR1001.java 2010-01-19 16:56:31 UTC (rev 653) +++ mspsim/se/sics/mspsim/chip/TR1001.java 2010-01-19 20:29:53 UTC (rev 654) @@ -40,23 +40,46 @@ package se.sics.mspsim.chip; import se.sics.mspsim.core.Chip; +import se.sics.mspsim.core.MSP430Core; import se.sics.mspsim.core.USART; import se.sics.mspsim.core.USARTListener; /** * */ -public class TR1001 extends Chip implements USARTListener { +public class TR1001 extends Chip implements RFListener { public static final int MODE_TXRX_OFF = 0x00; public static final int MODE_RX_ON = 0x01; public static final int MODE_TXRX_ON = 0x02; public static final int MODE_MAX = MODE_TXRX_ON; - + private static final String[] MODE_NAMES = new String[] { + "off", "listen", "transmit" + }; private final USART usart; + private RFListener rfListener; - public TR1001(USART usart) { + public TR1001(MSP430Core cpu, USART usart) { this.usart = usart; + setModeNames(MODE_NAMES); + setMode(MODE_TXRX_OFF); + cpu.addChip(this); + usart.setUSARTListener(new USARTListener() { + + public void dataReceived(USART source, int data) { + RFListener listener = rfListener; + if (getMode() != MODE_TXRX_ON) { + // Radio is turned off during transmission + if (DEBUG) { + log(" ----- TR1001 OFF DURING TRANSMISSION -----"); + } + } else if (listener != null) { + listener.receivedByte((byte) (data & 0xff)); + } + } + + public void stateChanged(int state) { + }}); } @Override @@ -73,10 +96,29 @@ return MODE_MAX; } - public void dataReceived(USART source, int data) { + public void setRFListener(RFListener rfListener) { + this.rfListener = rfListener; } - public void stateChanged(int state) { + /* Receive a byte from the radio medium + * @see se.sics.mspsim.chip.RFListener#receivedByte(byte) + */ + public void receivedByte(byte data) { + if (getMode() == MODE_TXRX_OFF) { + // Radio turned off + if (DEBUG) { + log(" ----- TR1001 OFF DURING RECEPTION -----"); + } + + } else if (usart.isReceiveFlagCleared()) { + /* logger.info("----- TR1001 RECEIVED BYTE -----"); */ + usart.byteReceived(data); + + } else { + if (DEBUG) { + log(" ----- TR1001 RECEIVED BYTE TOO EARLY -----"); + } + } } } Modified: mspsim/se/sics/mspsim/platform/esb/ESBNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/esb/ESBNode.java 2010-01-19 16:56:31 UTC (rev 653) +++ mspsim/se/sics/mspsim/platform/esb/ESBNode.java 2010-01-19 20:29:53 UTC (rev 654) @@ -147,8 +147,7 @@ IOUnit usart0 = cpu.getIOUnit("USART 0"); if (usart0 instanceof USART) { - radio = new TR1001((USART)usart0); - ((USART) usart0).setUSARTListener(radio); + radio = new TR1001(cpu, (USART) usart0); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2010-01-19 16:56:52
|
Revision: 653 http://mspsim.svn.sourceforge.net/mspsim/?rev=653&view=rev Author: joxe Date: 2010-01-19 16:56:31 +0000 (Tue, 19 Jan 2010) Log Message: ----------- removed debug output Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430.java Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2010-01-19 15:58:38 UTC (rev 652) +++ mspsim/se/sics/mspsim/core/MSP430.java 2010-01-19 16:56:31 UTC (rev 653) @@ -279,10 +279,6 @@ if (cpuOff && !(interruptsEnabled && servicedInterrupt == -1 && interruptMax >= 0)) { lastReturnedMicros = (1000000 * (nextEventCycles - cycles)) / dcoFrq; - if (lastReturnedMicros > 10000) { - System.out.println("More than 10 ms: " + lastReturnedMicros / 1000000.0 + " s"); - printEventQueues(System.out); - } } else { lastReturnedMicros = 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2010-01-19 15:58:44
|
Revision: 652 http://mspsim.svn.sourceforge.net/mspsim/?rev=652&view=rev Author: joxe Date: 2010-01-19 15:58:38 +0000 (Tue, 19 Jan 2010) Log Message: ----------- fixed so that mspsim checks for pending interrupts while in CPUOFF before returning to COOJA Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430.java mspsim/se/sics/mspsim/core/MSP430Core.java Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2010-01-18 22:33:06 UTC (rev 651) +++ mspsim/se/sics/mspsim/core/MSP430.java 2010-01-19 15:58:38 UTC (rev 652) @@ -277,7 +277,7 @@ } } - if (cpuOff) { + if (cpuOff && !(interruptsEnabled && servicedInterrupt == -1 && interruptMax >= 0)) { lastReturnedMicros = (1000000 * (nextEventCycles - cycles)) / dcoFrq; if (lastReturnedMicros > 10000) { System.out.println("More than 10 ms: " + lastReturnedMicros / 1000000.0 + " s"); Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2010-01-18 22:33:06 UTC (rev 651) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2010-01-19 15:58:38 UTC (rev 652) @@ -93,14 +93,14 @@ // From the possible interrupt sources - to be able to indicate is serviced. private InterruptHandler interruptSource[] = new IOUnit[16]; - private int interruptMax = -1; + protected int interruptMax = -1; // Op/instruction represents the last executed OP / instruction private int op; public int instruction; int servicedInterrupt = -1; InterruptHandler servicedInterruptUnit = null; - private boolean interruptsEnabled = false; + protected boolean interruptsEnabled = false; protected boolean cpuOff = false; // Not private since they are needed (for fast access...) @@ -834,7 +834,7 @@ // If CPU is not active we must run the events here!!! // this can trigger interrupts that wake the CPU // ------------------------------------------------------------------- - // Event processing + // Event processing - note: This can trigger IRQs! // ------------------------------------------------------------------- while (cycles >= nextEventCycles) { executeEvents(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2010-01-18 22:33:20
|
Revision: 651 http://mspsim.svn.sourceforge.net/mspsim/?rev=651&view=rev Author: joxe Date: 2010-01-18 22:33:06 +0000 (Mon, 18 Jan 2010) Log Message: ----------- fixed printout Modified Paths: -------------- mspsim/se/sics/mspsim/core/Timer.java Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2010-01-18 22:13:51 UTC (rev 650) +++ mspsim/se/sics/mspsim/core/Timer.java 2010-01-18 22:33:06 UTC (rev 651) @@ -364,23 +364,26 @@ if (DEBUG) { System.out.println("Timer: noComp:" + noCompare); } - + String type = ""; if (srcMap == TIMER_Ax149) { name = "Timer A"; + type = " A"; tiv = TAIV; timerOverflow = 0x0a; ccr0Vector = TACCR0_VECTOR; ccr1Vector = TACCR1_VECTOR; } else { + type = " B"; name = "Timer B"; tiv = TBIV; timerOverflow = 0x0e; ccr0Vector = TBCCR0_VECTOR; ccr1Vector = TBCCR1_VECTOR; } + counterTrigger.name += type; for (int i = 0; i < noCompare; i++) { - ccr[i] = new CCR(0, "CCR" + i, i == 0 ? ccr0Vector : ccr1Vector, i); + ccr[i] = new CCR(0, "CCR" + i + type, i == 0 ? ccr0Vector : ccr1Vector, i); } reset(0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2010-01-18 22:13:57
|
Revision: 650 http://mspsim.svn.sourceforge.net/mspsim/?rev=650&view=rev Author: joxe Date: 2010-01-18 22:13:51 +0000 (Mon, 18 Jan 2010) Log Message: ----------- added events command for printing internal event queues Modified Paths: -------------- mspsim/se/sics/mspsim/cli/DebugCommands.java Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2010-01-18 22:05:19 UTC (rev 649) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2010-01-18 22:13:51 UTC (rev 650) @@ -560,6 +560,14 @@ return 0; } }); + + ch.registerCommand("events", new BasicCommand("print event queues", "") { + @Override + public int executeCommand(CommandContext context) { + cpu.printEventQueues(context.out); + return 0; + } + }); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2010-01-18 22:05:26
|
Revision: 649 http://mspsim.svn.sourceforge.net/mspsim/?rev=649&view=rev Author: joxe Date: 2010-01-18 22:05:19 +0000 (Mon, 18 Jan 2010) Log Message: ----------- refactoring of timer system - hopefully works at all... Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/se/sics/mspsim/core/Timer.java Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2010-01-18 20:26:58 UTC (rev 648) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2010-01-18 22:05:19 UTC (rev 649) @@ -42,9 +42,6 @@ package se.sics.mspsim.core; import java.io.PrintStream; import java.util.ArrayList; - -import com.sun.xml.internal.fastinfoset.tools.PrintTable; - import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.MapEntry; import se.sics.mspsim.util.MapTable; Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2010-01-18 20:26:58 UTC (rev 648) +++ mspsim/se/sics/mspsim/core/Timer.java 2010-01-18 22:05:19 UTC (rev 649) @@ -210,48 +210,139 @@ int expCompare; int expCapInterval; long expCaptureTime; - + int capMode; boolean captureOn = false; int inputSel; int inputSrc; boolean sync; int outMode; - + int interruptVector; + int index; - public CCR(long time, String name, int vector) { + public CCR(long time, String name, int vector, int index) { super(time, name); interruptVector = vector; + this.index = index; } - + public void execute(long t) { + if (mode == STOP) { + return; + } + long cycles = core.cycles; + updateCounter(cycles); + + if (expCaptureTime != -1 && cycles >= expCaptureTime) { + if (DEBUG) { + System.out.println(getName() + (captureOn ? " CAPTURE: " : " COMPARE: ") + index + + " Cycles: " + cycles + " expCap: " + expCaptureTime + + " => ExpCR: " + Utils.hex16(expCompare) + + " TR: " + counter + " CCR" + index + ": " + tccr + " pass: " + + counterPassed); + } + // Set the interrupt flag... + tcctl |= CC_IFG; + + if (captureOn) { + // Write the expected capture time to the register (counter could + // differ slightly) + tccr = expCompare; + // Update capture times... for next capture + expCompare = (expCompare + expCapInterval) & 0xffff; + expCaptureTime += expCapInterval * cyclesMultiplicator; + if (DEBUG) { + System.out.println(getName() + " setting expCaptureTime to next capture: " + + expCaptureTime); + } + } else { + // Update expected compare time for this compare/cap register + // 0x10000 cycles... e.g. a full 16 bits wrap of the timer + expCaptureTime = expCaptureTime + (long) (0x10000 * cyclesMultiplicator); + if (DEBUG) { + System.out.println(getName() + " setting expCaptureTime to full wrap: " + + expCaptureTime); + } + } + /* schedule again! */ + update(); + triggerInterrupts(cycles); + } } - - public void triggerInterrupt() { - + + public void updateCaptures(long cycles) { + int divisor = 1; + int frqClk = 1; + /* used to set next capture independent of counter when another clock is source + * for the capture register! + */ + boolean clkSource = false; + + if (clockSource == SRC_SMCLK) { + frqClk = core.smclkFrq / inputDivider; + } else if (clockSource == SRC_ACLK) { + frqClk = core.aclkFrq / inputDivider; + } + + // Handle the captures... + if (captureOn) { + if (inputSrc == SRC_ACLK) { + divisor = core.aclkFrq; + clkSource = true; + } + + if (DEBUG) { + System.out.println(getName() + " expCapInterval[" + index + "] frq = " + + frqClk + " div = " + divisor + " SMCLK_FRQ: " + core.smclkFrq); + } + + // This is used to calculate expected time before next capture of + // clock-edge to occur - including what value the compare reg. will get + expCapInterval = frqClk / divisor; + // This is not 100% correct - depending on clock mode I guess... + if (clkSource) { + /* assume that this was capture recently */ + // System.out.println(">>> ACLK! fixing with expCompare!!!"); + expCompare = (tccr + expCapInterval) & 0xffff; + } else { + expCompare = (counter + expCapInterval) & 0xffff; + } + // This could be formulated in something other than cycles... + // ...??? should be multiplied with clockspeed diff also? + expCaptureTime = cycles + (long)(expCapInterval * cyclesMultiplicator); + if (DEBUG) { + System.out.println(getName() + + " Expected compare " + index + + " => " + expCompare + " Diff: " + expCapInterval); + System.out.println(getName() + + " Expected cap time: " + expCaptureTime + " cycMult: " + cyclesMultiplicator); + System.out.println("Capture: " + captureOn); + } + update(); + } } - + + public void update() { + /* schedule this capture register for update*/ + if (expCaptureTime != -1 && expCaptureTime != time) { + core.scheduleCycleEvent(this, expCaptureTime); + } + } } private CCR ccr[] = new CCR[7]; - - private TimeEvent timerTrigger = new TimeEvent(0, "TimerTrigger") { - long last; + + private TimeEvent counterTrigger = new TimeEvent(0, "Timer Counter Trigger") { public void execute(long t) { - // System.out.println(getName() + " **** executing update timers at " + t + " cycles=" + core.cycles); -// if (t - last > 400000) { -// System.out.println(getName() + " ***** Timer trigger " + getShort() + " slow ? " -// + (t - last) + " cycles since last..." -// + " " + 1.0 * (t - last) / core.dcoFrq + " s"); -// core.printEventQueues(System.out); -// } - last = t; - updateTimers(core.cycles); + long cycles = core.cycles; + interruptPending = true; + /* and can be something else if mode is another... */ + // This should be updated whenever clockspeed changes... + nextTimerTrigger = (long) (nextTimerTrigger + 0x10000 * cyclesMultiplicator); + core.scheduleCycleEvent(this, nextTimerTrigger); + triggerInterrupts(cycles); } - public String getShort() { - return name + " " + triggerDesc; - } }; private int lastTIV; @@ -276,14 +367,12 @@ if (srcMap == TIMER_Ax149) { name = "Timer A"; - timerTrigger.name += " A"; tiv = TAIV; timerOverflow = 0x0a; ccr0Vector = TACCR0_VECTOR; ccr1Vector = TACCR1_VECTOR; } else { name = "Timer B"; - timerTrigger.name += " B"; tiv = TBIV; timerOverflow = 0x0e; ccr0Vector = TBCCR0_VECTOR; @@ -291,9 +380,8 @@ } for (int i = 0; i < noCompare; i++) { - ccr[i] = new CCR(0, "CCR" + i, i == 0 ? ccr0Vector : ccr1Vector); + ccr[i] = new CCR(0, "CCR" + i, i == 0 ? ccr0Vector : ccr1Vector, i); } - reset(0); } @@ -402,7 +490,6 @@ * and other dynamic values */ private void updateTCCTL(int cctl, long cycles) { - // TODO Auto-generated method stub // update the CCI depending on speed of clocks... boolean input = false; /* if ACLK we can calculate edge... */ @@ -473,7 +560,10 @@ counter = 0; resetCounter(cycles); - updateCaptures(-1, cycles); +// updateCaptures(-1, cycles); + for (int i = 0; i < noCompare; i++) { + ccr[i].updateCaptures(cycles); + } } int newMode = (data >> 4) & 3; @@ -512,7 +602,10 @@ interruptPending = false; } - updateCaptures(-1, cycles); + // updateCaptures(-1, cycles); + for (int i = 0; i < noCompare; i++) { + ccr[i].updateCaptures(cycles); + } break; case TCCTL0: @@ -557,8 +650,9 @@ " Capture: " + reg.captureOn + " IE: " + ((data & CC_IE) != 0)); } - - updateCaptures(index, cycles); + + reg.updateCaptures(cycles); +// updateCaptures(index, cycles); break; // Write to compare register! case TCCR0: @@ -606,7 +700,8 @@ (100 * (cyclesMultiplicator * diff * 1L) / 2500000) / 100.0 + " sec" + "at cycles: " + ccr[index].expCaptureTime); } - calculateNextEventTime(cycles); + ccr[index].update(); + //calculateNextEventTime(cycles); } } void updateCyclesMultiplicator() { @@ -629,6 +724,7 @@ updateCyclesMultiplicator(); if (DEBUG) System.out.println(getName() + " Counter reset at " + cycles + " cycMul: " + cyclesMultiplicator); + core.scheduleCycleEvent(counterTrigger, (long) ((0x100000 - counter) * cyclesMultiplicator)); } private void setCounter(int newCtr, long cycles) { @@ -636,67 +732,7 @@ resetCounter(cycles); } - private void updateCaptures(int index, long cycles) { - int hi = noCompare; - if (index != -1) { - hi = index + 1; - } - // A hack to handle the SMCLK synchronization - for (int i = 0, n = hi; i < n; i++) { - CCR reg = ccr[i]; - int divisor = 1; - int frqClk = 1; - /* used to set next capture independent of counter when another clock is source - * for the capture register! - */ - boolean clkSource = false; - - if (clockSource == SRC_SMCLK) { - frqClk = core.smclkFrq / inputDivider; - } else if (clockSource == SRC_ACLK) { - frqClk = core.aclkFrq / inputDivider; - } - - // Handle the captures... - if (reg.captureOn) { - if (reg.inputSrc == SRC_ACLK) { - divisor = core.aclkFrq; - clkSource = true; - } - - if (DEBUG) { - System.out.println(getName() + " expCapInterval[" + i + "] frq = " + - frqClk + " div = " + divisor + " SMCLK_FRQ: " + core.smclkFrq); - } - - // This is used to calculate expected time before next capture of - // clock-edge to occur - including what value the compare reg. will get - reg.expCapInterval = frqClk / divisor; - // This is not 100% correct - depending on clock mode I guess... - if (clkSource) { - /* assume that this was capture recently */ -// System.out.println(">>> ACLK! fixing with expCompare!!!"); - reg.expCompare = (reg.tccr + reg.expCapInterval) & 0xffff; - } else { - reg.expCompare = (counter + reg.expCapInterval) & 0xffff; - } - // This could be formulated in something other than cycles... - // ...??? should be multiplied with clockspeed diff also? - reg.expCaptureTime = cycles + (long)(reg.expCapInterval * cyclesMultiplicator); - if (DEBUG) { - System.out.println(getName() + - " Expected compare " + i + - " => " + reg.expCompare + " Diff: " + reg.expCapInterval); - System.out.println(getName() + - " Expected cap time: " + reg.expCaptureTime + " cycMult: " + cyclesMultiplicator); - System.out.println("Capture: " + reg.captureOn); - } - } - } - calculateNextEventTime(cycles); - } - private int updateCounter(long cycles) { if (mode == STOP) return counter; @@ -751,83 +787,6 @@ return counter; } - public long ioTick(long cycles) { - System.out.println(getName() + " UNEXPECTED CALL TO IOTICK ****"); - return 100000 + cycles; - } - - // Only called by the interrupt handler - private void updateTimers(long cycles) { - if (mode == STOP) { - if (DEBUG) { - System.out.println("No timer running -> no interrupt can be caused -> no scheduling..."); - } - return; - } - - updateCounter(cycles); - - if (cycles >= nextTimerTrigger) { - interruptPending = true; - // This should be updated whenever clockspeed changes... - nextTimerTrigger = (long) (nextTimerTrigger + 0x10000 * cyclesMultiplicator); - } - - // This will not work very good... - // But the timer does not need to be updated this often... - // Do we need to update the counter here??? - // System.out.println("Checking capture register [ioTick]: " + cycles); - for (int i = 0, n = noCompare; i < n; i++) { - CCR reg = ccr[i]; - if (reg.expCaptureTime != -1 && cycles >= reg.expCaptureTime) { - if (DEBUG) { - System.out.println(getName() + (reg.captureOn ? " CAPTURE: " : " COMPARE: ") + i + - " Cycles: " + cycles + " expCap: " + - reg.expCaptureTime + - " => ExpCR: " + Utils.hex16(reg.expCompare) + - " TR: " + counter + " CCR" + i + ": " + reg.tccr + " pass: " + - counterPassed); - } - // Set the interrupt flag... - reg.tcctl |= CC_IFG; - - if (reg.captureOn) { - // Write the expected capture time to the register (counter could - // differ slightly) - reg.tccr = reg.expCompare; - // Update capture times... for next capture - reg.expCompare = (reg.expCompare + reg.expCapInterval) & 0xffff; - reg.expCaptureTime += reg.expCapInterval * cyclesMultiplicator; - if (DEBUG) { - System.out.println(getName() + - " setting expCaptureTime to next capture: " + - reg.expCaptureTime); - } - } else { - // Update expected compare time for this compare/cap reg. - // 0x10000 cycles... e.g. a full 16 bits wrap of the timer - reg.expCaptureTime = reg.expCaptureTime + - (long) (0x10000 * cyclesMultiplicator); - if (DEBUG) { - System.out.println(getName() + - " setting expCaptureTime to full wrap: " + - reg.expCaptureTime); - } - } - - if (DEBUG) { - System.out.println("Wrote to: " + - Utils.hex16(offset + TCCTL0 + i * 2 + 1)); - } - } - } - - - // Trigger interrupts that are up for triggering! - triggerInterrupts(cycles); - calculateNextEventTime(cycles); - } - private void recalculateCompares(long cycles) { for (int i = 0; i < noCompare; i++) { CCR reg = ccr[i]; @@ -838,50 +797,11 @@ diff += 0x10000; } reg.expCaptureTime = cycles + (long) (diff * cyclesMultiplicator); + reg.update(); } } } - private long lastTrigger = 0; - private void calculateNextEventTime(long cycles) { - if (mode == STOP) { - // If nothing is "running" there is no point scheduling... - return; - } - long time = nextTimerTrigger; -// int smallest = -1; - triggerDesc = "TR"; - - for (int i = 0; i < noCompare; i++) { - long ct = ccr[i].expCaptureTime; - if (ct > 0 && ct < time) { - time = ct; -// smallest = i; - triggerDesc = "CCR" + i; - } - } - - if (time == 0) { - time = cycles + 1000; - } - -// if (time == nextTimerTrigger && timerTrigger.time >= nextTimerTrigger) { -// System.out.println(getName() + ": TIMER WRAP! " + (time - cycles) + " " + -// (timerTrigger.time - cycles) + " last: " + (cycles - lastTrigger) + " TAR: " + counter); -// } - lastTrigger = cycles; - - if (timerTrigger.scheduledIn == null) { -// System.out.println(getName() + " new trigger (nothing sch) ..." + time + " re:" + -// smallest + " => " + (smallest > 0 ? expCaptureTime[smallest] + " > " + expCompare[smallest]: -// nextTimerTrigger) + " C:"+ cycles); - core.scheduleCycleEvent(timerTrigger, time); - } else if (timerTrigger.time > time) { - // System.out.println(getName() + " new trigger (new time)..." + time + " C:"+ cycles); - core.scheduleCycleEvent(timerTrigger, time); - } - } - // Can be called to generate any interrupt... // TODO: check if it is ok that this also sets the flags to false or if that must // be done by software (e.g. firmware) @@ -1008,7 +928,6 @@ } } - // The interrupt has been serviced... // Some flags should be cleared (the highest priority flags)? public void interruptServiced(int vector) { @@ -1036,6 +955,5 @@ if (reg == 0x10) return "TR"; if (reg < 0x20) return "TCCR" + (reg - 0x12) / 2; return " UNDEF(" + Utils.hex16(address) + ")"; - } - + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2010-01-18 20:27:14
|
Revision: 648 http://mspsim.svn.sourceforge.net/mspsim/?rev=648&view=rev Author: joxe Date: 2010-01-18 20:26:58 +0000 (Mon, 18 Jan 2010) Log Message: ----------- started refactoring of Timer subsystem Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430.java mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/se/sics/mspsim/core/Timer.java mspsim/se/sics/mspsim/core/Watchdog.java Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2010-01-18 15:50:22 UTC (rev 647) +++ mspsim/se/sics/mspsim/core/MSP430.java 2010-01-18 20:26:58 UTC (rev 648) @@ -279,6 +279,10 @@ if (cpuOff) { lastReturnedMicros = (1000000 * (nextEventCycles - cycles)) / dcoFrq; + if (lastReturnedMicros > 10000) { + System.out.println("More than 10 ms: " + lastReturnedMicros / 1000000.0 + " s"); + printEventQueues(System.out); + } } else { lastReturnedMicros = 0; } Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2010-01-18 15:50:22 UTC (rev 647) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2010-01-18 20:26:58 UTC (rev 648) @@ -43,6 +43,8 @@ import java.io.PrintStream; import java.util.ArrayList; +import com.sun.xml.internal.fastinfoset.tools.PrintTable; + import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.MapEntry; import se.sics.mspsim.util.MapTable; @@ -345,8 +347,8 @@ interruptsEnabled = ((value & GIE) == GIE); if (oldIE == false && interruptsEnabled && servicedInterrupt >= 0) { - System.out.println("*** Interrupts enabled while in interrupt : " + - servicedInterrupt + " PC: " + Utils.hex16(reg[PC])); +// System.out.println("*** Interrupts enabled while in interrupt : " + +// servicedInterrupt + " PC: " + Utils.hex16(reg[PC])); /* must handle pending immediately */ handlePendingInterrupts(); } Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2010-01-18 15:50:22 UTC (rev 647) +++ mspsim/se/sics/mspsim/core/Timer.java 2010-01-18 20:26:58 UTC (rev 648) @@ -189,34 +189,69 @@ // The IO registers private int tctl; - private int[] tcctl = new int[7]; - private int[] tccr = new int[7]; - // Support variables Max 7 compare regs for now (timer b) - private final int noCompare; - private int[] expCompare = new int[7]; - private int[] expCapInterval = new int[7]; - private long[] expCaptureTime = new long[7]; - - private int[] capMode = new int[7]; - private boolean[] captureOn = new boolean[7]; - private int[] inputSel = new int[7]; - private int[] inputSrc = new int[7]; - private boolean[] sync = new boolean[7]; - private int[] outMode = new int[7]; - private boolean interruptEnable = false; private boolean interruptPending = false; private final int ccr1Vector; private final int ccr0Vector; private final MSP430Core core; + + private String triggerDesc = ""; + // Support variables Max 7 compare regs for now (timer b) + private final int noCompare; + + /* this is class represents a capture and compare register */ + private class CCR extends TimeEvent { + int tcctl; + int tccr; + + int expCompare; + int expCapInterval; + long expCaptureTime; + + int capMode; + boolean captureOn = false; + int inputSel; + int inputSrc; + boolean sync; + int outMode; + + int interruptVector; + + public CCR(long time, String name, int vector) { + super(time, name); + interruptVector = vector; + } + + public void execute(long t) { + } + + public void triggerInterrupt() { + + } + + } + + private CCR ccr[] = new CCR[7]; + private TimeEvent timerTrigger = new TimeEvent(0, "TimerTrigger") { - public void execute(long t) { -// System.out.println(getName() + " **** executing update timers at " + t + " cycles=" + core.cycles); - updateTimers(core.cycles); - } + long last; + public void execute(long t) { + // System.out.println(getName() + " **** executing update timers at " + t + " cycles=" + core.cycles); +// if (t - last > 400000) { +// System.out.println(getName() + " ***** Timer trigger " + getShort() + " slow ? " +// + (t - last) + " cycles since last..." +// + " " + 1.0 * (t - last) / core.dcoFrq + " s"); +// core.printEventQueues(System.out); +// } + last = t; + updateTimers(core.cycles); + } + public String getShort() { + return name + " " + triggerDesc; + } }; private int lastTIV; @@ -238,6 +273,7 @@ if (DEBUG) { System.out.println("Timer: noComp:" + noCompare); } + if (srcMap == TIMER_Ax149) { name = "Timer A"; timerTrigger.name += " A"; @@ -254,37 +290,44 @@ ccr1Vector = TBCCR1_VECTOR; } + for (int i = 0; i < noCompare; i++) { + ccr[i] = new CCR(0, "CCR" + i, i == 0 ? ccr0Vector : ccr1Vector); + } + + reset(0); } public void reset(int type) { - for (int i = 0, n = expCompare.length; i < n; i++) { - expCompare[i] = -1; - expCaptureTime[i] = -1; - expCapInterval[i] = 0; - outMode[i] = 0; - capMode[i] = 0; - inputSel[i] = 0; - inputSrc[i] = 0; - captureOn[i] = false; - } - for (int i = 0; i < tcctl.length; i++) { - tcctl[i] = 0; - tccr[i] = 0; - } - tctl = 0; - lastTIV = 0; - interruptEnable = false; - interruptPending = false; - counter = 0; - counterPassed = 0; - counterStart = 0; - counterAcc = 0; - clockSource = 0; - cyclesMultiplicator = 1; - mode = STOP; - nextTimerTrigger = 0; - inputDivider = 1; + + /* reset the capture and compare registers */ + for (int i = 0, n = noCompare; i < n; i++) { + CCR reg = ccr[i]; + reg.expCompare = -1; + reg.expCaptureTime = -1; + reg.expCapInterval = 0; + reg.outMode = 0; + reg.capMode = 0; + reg.inputSel = 0; + reg.inputSrc = 0; + reg.captureOn = false; + reg.tcctl = 0; + reg.tccr = 0; + } + + tctl = 0; + lastTIV = 0; + interruptEnable = false; + interruptPending = false; + counter = 0; + counterPassed = 0; + counterStart = 0; + counterAcc = 0; + clockSource = 0; + cyclesMultiplicator = 1; + mode = STOP; + nextTimerTrigger = 0; + inputDivider = 1; } // Should handle read of byte also (currently ignores that...) @@ -330,7 +373,7 @@ case TCCTL6: int i = (index - TCCTL0) / 2; updateTCCTL(i, cycles); - val = tcctl[i]; + val = ccr[i].tcctl; break; case TCCR0: case TCCR1: @@ -340,7 +383,7 @@ case TCCR5: case TCCR6: i = (index - TCCR0) / 2; - val = tccr[i]; + val = ccr[i].tccr; break; default: System.out.println("Not supported read, returning zero!!!"); @@ -363,7 +406,7 @@ // update the CCI depending on speed of clocks... boolean input = false; /* if ACLK we can calculate edge... */ - if (inputSrc[cctl] == SRC_ACLK) { + if (ccr[cctl].inputSrc == SRC_ACLK) { /* needs the TimerA clock speed here... */ int aTicks = clockSpeed / core.aclkFrq; updateCounter(cycles); @@ -375,7 +418,7 @@ input = true; } } - tcctl[cctl] = (tcctl[cctl] & ~CC_I) | (input ? CC_I : 0); + ccr[cctl].tcctl = (ccr[cctl].tcctl & ~CC_I) | (input ? CC_I : 0); } private void resetTIV(long cycles) { @@ -392,7 +435,7 @@ System.out.println(getName() + " Clearing IFG for CCR" + (lastTIV/2)); } // Clear interrupt flags! - tcctl[lastTIV / 2] &= ~CC_IFG; + ccr[lastTIV / 2].tcctl &= ~CC_IFG; triggerInterrupts(cycles); } } @@ -481,17 +524,18 @@ case TCCTL6: // Control register... int index = (iAddress - TCCTL0) / 2; - tcctl[index] = data; - outMode[index] = (data >> 5)& 7; - boolean oldCapture = captureOn[index]; - captureOn[index] = (data & 0x100) > 0; - sync[index] = (data & 0x800) > 0; - inputSel[index] = (data >> 12) & 3; - int src = inputSrc[index] = srcMap[4 + index * 4 + inputSel[index]]; - capMode[index] = (data >> 14) & 3; + CCR reg = ccr[index]; + reg.tcctl = data; + reg.outMode = (data >> 5)& 7; + boolean oldCapture = reg.captureOn; + reg.captureOn = (data & 0x100) > 0; + reg.sync = (data & 0x800) > 0; + reg.inputSel = (data >> 12) & 3; + int src = reg.inputSrc = srcMap[4 + index * 4 + reg.inputSel]; + reg.capMode = (data >> 14) & 3; /* capture a port state? */ - if (!oldCapture && captureOn[index] && (src & SRC_PORT) != 0) { + if (!oldCapture && reg.captureOn && (src & SRC_PORT) != 0) { int port = (src & 0xff) >> 4; int pin = src & 0x0f; IOPort ioPort = core.getIOPort(port); @@ -507,10 +551,10 @@ if (DEBUG) { System.out.println(getName() + " Write: CCTL" + index + ": => " + Utils.hex16(data) + - " CM: " + capNames[capMode[index]] + - " CCIS:" + inputSel[index] + " name: " + - getSourceName(inputSrc[index]) + - " Capture: " + captureOn[index] + + " CM: " + capNames[reg.capMode] + + " CCIS:" + reg.inputSel + " name: " + + getSourceName(reg.inputSrc) + + " Capture: " + reg.captureOn + " IE: " + ((data & CC_IE) != 0)); } @@ -535,7 +579,7 @@ } resetCounter(cycles); } - tccr[index] = data; + ccr[index].tccr = data; int diff = data - counter; if (diff < 0) { @@ -549,18 +593,18 @@ Utils.hex16(counter) + " diff: " + Utils.hex16(diff)); } // Use the counterPassed information to compensate the expected capture/compare time!!! - expCaptureTime[index] = cycles + (long)(cyclesMultiplicator * diff + 1) - counterPassed; + ccr[index].expCaptureTime = cycles + (long)(cyclesMultiplicator * diff + 1) - counterPassed; if (DEBUG && counterPassed > 0) { System.out.println(getName() + " Comp: " + counterPassed + " cycl: " + cycles + " TR: " + counter + " CCR" + index + " = " + data + " diff = " + diff + " cycMul: " + cyclesMultiplicator + " expCyc: " + - expCaptureTime[index]); + ccr[index].expCaptureTime); } counterPassed = 0; if (DEBUG) { - System.out.println(getName() + " Cycles: " + cycles + " expCap[" + index + "]: " + expCaptureTime[index] + " ctr:" + counter + + System.out.println(getName() + " Cycles: " + cycles + " expCap[" + index + "]: " + ccr[index].expCaptureTime + " ctr:" + counter + " data: " + data + " ~" + (100 * (cyclesMultiplicator * diff * 1L) / 2500000) / 100.0 + " sec" + - "at cycles: " + expCaptureTime[index]); + "at cycles: " + ccr[index].expCaptureTime); } calculateNextEventTime(cycles); } @@ -600,6 +644,7 @@ // A hack to handle the SMCLK synchronization for (int i = 0, n = hi; i < n; i++) { + CCR reg = ccr[i]; int divisor = 1; int frqClk = 1; /* used to set next capture independent of counter when another clock is source @@ -614,8 +659,8 @@ } // Handle the captures... - if (captureOn[i]) { - if (inputSrc[i] == SRC_ACLK) { + if (reg.captureOn) { + if (reg.inputSrc == SRC_ACLK) { divisor = core.aclkFrq; clkSource = true; } @@ -627,25 +672,25 @@ // This is used to calculate expected time before next capture of // clock-edge to occur - including what value the compare reg. will get - expCapInterval[i] = frqClk / divisor; + reg.expCapInterval = frqClk / divisor; // This is not 100% correct - depending on clock mode I guess... if (clkSource) { /* assume that this was capture recently */ // System.out.println(">>> ACLK! fixing with expCompare!!!"); - expCompare[i] = (tccr[i] + expCapInterval[i]) & 0xffff; + reg.expCompare = (reg.tccr + reg.expCapInterval) & 0xffff; } else { - expCompare[i] = (counter + expCapInterval[i]) & 0xffff; + reg.expCompare = (counter + reg.expCapInterval) & 0xffff; } // This could be formulated in something other than cycles... // ...??? should be multiplied with clockspeed diff also? - expCaptureTime[i] = cycles + (long)(expCapInterval[i] * cyclesMultiplicator); + reg.expCaptureTime = cycles + (long)(reg.expCapInterval * cyclesMultiplicator); if (DEBUG) { System.out.println(getName() + " Expected compare " + i + - " => " + expCompare[i] + " Diff: " + expCapInterval[i]); + " => " + reg.expCompare + " Diff: " + reg.expCapInterval); System.out.println(getName() + - " Expected cap time: " + expCaptureTime[i] + " cycMult: " + cyclesMultiplicator); - System.out.println("Capture: " + captureOn[i]); + " Expected cap time: " + reg.expCaptureTime + " cycMult: " + cyclesMultiplicator); + System.out.println("Capture: " + reg.captureOn); } } } @@ -679,20 +724,20 @@ counter = (int) (bigCounter & 0xffff); break; case UP: - if (tccr[0] == 0) { + if (ccr[0].tccr == 0) { counter = 0; } else { - counter = (int) (bigCounter % tccr[0]); + counter = (int) (bigCounter % ccr[0].tccr); } break; case UPDWN: - if (tccr[0] == 0) { + if (ccr[0].tccr == 0) { counter = 0; } else { - counter = (int) (bigCounter % (tccr[0] * 2)); - if (counter > tccr[0]) { + counter = (int) (bigCounter % (ccr[0].tccr * 2)); + if (counter > ccr[0].tccr) { // Should back down to start again! - counter = 2 * tccr[0] - counter; + counter = 2 * ccr[0].tccr - counter; } } } @@ -732,40 +777,41 @@ // But the timer does not need to be updated this often... // Do we need to update the counter here??? // System.out.println("Checking capture register [ioTick]: " + cycles); - for (int i = 0, n = noCompare; i < n; i++) { - if (expCaptureTime[i] != -1 && cycles >= expCaptureTime[i]) { + for (int i = 0, n = noCompare; i < n; i++) { + CCR reg = ccr[i]; + if (reg.expCaptureTime != -1 && cycles >= reg.expCaptureTime) { if (DEBUG) { - System.out.println(getName() + (captureOn[i] ? " CAPTURE: " : " COMPARE: ") + i + + System.out.println(getName() + (reg.captureOn ? " CAPTURE: " : " COMPARE: ") + i + " Cycles: " + cycles + " expCap: " + - expCaptureTime[i] + - " => ExpCR: " + Utils.hex16(expCompare[i]) + - " TR: " + counter + " CCR" + i + ": " + tccr[i] + " pass: " + + reg.expCaptureTime + + " => ExpCR: " + Utils.hex16(reg.expCompare) + + " TR: " + counter + " CCR" + i + ": " + reg.tccr + " pass: " + counterPassed); } // Set the interrupt flag... - tcctl[i] |= CC_IFG; + reg.tcctl |= CC_IFG; - if (captureOn[i]) { + if (reg.captureOn) { // Write the expected capture time to the register (counter could // differ slightly) - tccr[i] = expCompare[i]; + reg.tccr = reg.expCompare; // Update capture times... for next capture - expCompare[i] = (expCompare[i] + expCapInterval[i]) & 0xffff; - expCaptureTime[i] += expCapInterval[i] * cyclesMultiplicator; + reg.expCompare = (reg.expCompare + reg.expCapInterval) & 0xffff; + reg.expCaptureTime += reg.expCapInterval * cyclesMultiplicator; if (DEBUG) { System.out.println(getName() + " setting expCaptureTime to next capture: " + - expCaptureTime[i]); + reg.expCaptureTime); } } else { // Update expected compare time for this compare/cap reg. // 0x10000 cycles... e.g. a full 16 bits wrap of the timer - expCaptureTime[i] = expCaptureTime[i] + + reg.expCaptureTime = reg.expCaptureTime + (long) (0x10000 * cyclesMultiplicator); if (DEBUG) { System.out.println(getName() + " setting expCaptureTime to full wrap: " + - expCaptureTime[i]); + reg.expCaptureTime); } } @@ -783,14 +829,15 @@ } private void recalculateCompares(long cycles) { - for (int i = 0; i < expCaptureTime.length; i++) { - if (expCaptureTime[i] != 0) { - int diff = tccr[i] - counter; + for (int i = 0; i < noCompare; i++) { + CCR reg = ccr[i]; + if (reg.expCaptureTime != 0) { + int diff = reg.tccr - counter; if (diff < 0) { // Wrap... diff += 0x10000; } - expCaptureTime[i] = cycles + (long) (diff * cyclesMultiplicator); + reg.expCaptureTime = cycles + (long) (diff * cyclesMultiplicator); } } } @@ -803,11 +850,14 @@ } long time = nextTimerTrigger; // int smallest = -1; + triggerDesc = "TR"; + for (int i = 0; i < noCompare; i++) { - long ct = expCaptureTime[i]; + long ct = ccr[i].expCaptureTime; if (ct > 0 && ct < time) { time = ct; // smallest = i; + triggerDesc = "CCR" + i; } } @@ -841,21 +891,22 @@ int tIndex = 0; for (int i = 0, n = noCompare; i < n; i++) { - // check for both IFG and IE - boolean newTrigger = (tcctl[i] & CC_TRIGGER_INT) == CC_TRIGGER_INT; + CCR reg = ccr[i]; + // check for both IFG and IE + boolean newTrigger = (reg.tcctl & CC_TRIGGER_INT) == CC_TRIGGER_INT; trigger = trigger | newTrigger; // This only triggers interrupts - reading TIV clears!??! if (i == 0) { // Execute the interrupt vector... the high-pri one... if (DEBUG) { - System.out.println(getName() +" >>>> Trigger IRQ for CCR0: " + tccr[0] + - " TAR: " + counter + " cycles: " + cycles + " expCap: " + expCaptureTime[0]); + System.out.println(getName() +" >>>> Trigger IRQ for CCR0: " + reg.tccr + + " TAR: " + counter + " cycles: " + cycles + " expCap: " + reg.expCaptureTime); } - if (DEBUG && counter < tccr[0] && trigger) { + if (DEBUG && counter < reg.tccr && trigger) { System.out.print("***** WARNING!!! CTR Err "); - System.out.println(getName() +" >>>> Trigger IRQ for CCR0: " + tccr[0] + - " TAR: " + counter + " cycles: " + cycles + " expCap: " + expCaptureTime[0] + + System.out.println(getName() +" >>>> Trigger IRQ for CCR0: " + reg.tccr + + " TAR: " + counter + " cycles: " + cycles + " expCap: " + reg.expCaptureTime + " counterPassed: " + counterPassed); } core.flagInterrupt(ccr0Vector, this, trigger); @@ -873,7 +924,7 @@ if (newTrigger) { if (DEBUG) { System.out.println(getName() + " >>>> Triggering IRQ for CCR" + i + - " at cycles:" + cycles + " CCR" + i + ": " + tccr[i] + " TAR: " + + " at cycles:" + cycles + " CCR" + i + ": " + reg.tccr + " TAR: " + counter); } tIndex = i; @@ -889,14 +940,14 @@ triggerTime = cycles; if (DEBUG) System.out.println(getName() + " >>>> Triggering IRQ for CCR" + tIndex + - " at cycles:" + cycles + " CCR" + tIndex + ": " + tccr[tIndex] + " TAR: " + + " at cycles:" + cycles + " CCR" + tIndex + ": " + ccr[tIndex].tccr + " TAR: " + counter); - if (DEBUG && counter < tccr[tIndex]) { + if (DEBUG && counter < ccr[tIndex].tccr) { System.out.print("***** WARNING!!! CTR Err "); System.out.println(getName() + " >>>> Triggering IRQ for CCR" + tIndex + - " at cycles:" + cycles + " CCR" + tIndex + ": " + tccr[tIndex] + " TAR: " + - counter + " expCap: " + expCaptureTime[tIndex] + " counterPassed: " + counterPassed); + " at cycles:" + cycles + " CCR" + tIndex + ": " + ccr[tIndex].tccr + " TAR: " + + counter + " expCap: " + ccr[tIndex].expCaptureTime + " counterPassed: " + counterPassed); } } @@ -941,18 +992,19 @@ * @param source - the capture source (0/1) */ public void capture(int ccrIndex, int source, int value) { - if (ccrIndex < noCompare && captureOn[ccrIndex] && inputSel[ccrIndex] == source) { - /* This is obviously a capture! */ - boolean rise = (capMode[ccrIndex] & CM_RISING) != 0; - boolean fall = (capMode[ccrIndex] & CM_FALLING) != 0; - if ((value == IOPort.PIN_HI && rise) || - (value == IOPort.PIN_LOW && fall)) { -// System.out.println("*** Capture on CCR_" + ccrIndex + " " + " value: " + -// value); - // Set the interrupt flag... - tcctl[ccrIndex] |= CC_IFG; - triggerInterrupts(core.cycles); - } + CCR reg = ccr[ccrIndex]; + if (ccrIndex < noCompare && reg.captureOn && reg.inputSel == source) { + /* This is obviously a capture! */ + boolean rise = (reg.capMode & CM_RISING) != 0; + boolean fall = (reg.capMode & CM_FALLING) != 0; + if ((value == IOPort.PIN_HI && rise) || + (value == IOPort.PIN_LOW && fall)) { + // System.out.println("*** Capture on CCR_" + ccrIndex + " " + " value: " + + // value); + // Set the interrupt flag... + reg.tcctl |= CC_IFG; + triggerInterrupts(core.cycles); + } } } @@ -964,7 +1016,7 @@ // Reset the interrupt trigger in "core". core.flagInterrupt(ccr0Vector, this, false); // Remove the flag also... - tcctl[0] &= ~CC_IFG; + ccr[0].tcctl &= ~CC_IFG; } if (MSP430Core.debugInterrupts) { System.out.println(getName() + " >>>> interrupt Serviced " + lastTIV + Modified: mspsim/se/sics/mspsim/core/Watchdog.java =================================================================== --- mspsim/se/sics/mspsim/core/Watchdog.java 2010-01-18 15:50:22 UTC (rev 647) +++ mspsim/se/sics/mspsim/core/Watchdog.java 2010-01-18 20:26:58 UTC (rev 648) @@ -75,7 +75,7 @@ private boolean sourceACLK = false; - private TimeEvent wdtTrigger = new TimeEvent(0) { + private TimeEvent wdtTrigger = new TimeEvent(0, "Watchdog") { public void execute(long t) { // System.out.println(getName() + " **** executing update timers at " + t + " cycles=" + core.cycles); triggerWDT(t); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2010-01-18 15:50:30
|
Revision: 647 http://mspsim.svn.sourceforge.net/mspsim/?rev=647&view=rev Author: joxe Date: 2010-01-18 15:50:22 +0000 (Mon, 18 Jan 2010) Log Message: ----------- added more debug info when scheduling fails Modified Paths: -------------- mspsim/se/sics/mspsim/chip/CC2420.java mspsim/se/sics/mspsim/core/EventQueue.java mspsim/se/sics/mspsim/core/MSP430.java mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/se/sics/mspsim/core/TimeEvent.java mspsim/se/sics/mspsim/core/Timer.java Modified: mspsim/se/sics/mspsim/chip/CC2420.java =================================================================== --- mspsim/se/sics/mspsim/chip/CC2420.java 2009-12-15 16:34:40 UTC (rev 646) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2010-01-18 15:50:22 UTC (rev 647) @@ -288,7 +288,7 @@ private MSP430Core cpu; - private TimeEvent oscillatorEvent = new TimeEvent(0) { + private TimeEvent oscillatorEvent = new TimeEvent(0, "CC2420 OSC") { public void execute(long t) { status |= STATUS_XOSC16M_STABLE; if(DEBUG) log("Oscillator Stable Event."); @@ -301,7 +301,7 @@ } }; - private TimeEvent vregEvent = new TimeEvent(0) { + private TimeEvent vregEvent = new TimeEvent(0, "CC2420 VREG") { public void execute(long t) { if(DEBUG) log("VREG Started at: " + t + " cyc: " + cpu.cycles + " " + getTime()); @@ -311,25 +311,25 @@ } }; - private TimeEvent sendEvent = new TimeEvent(0) { + private TimeEvent sendEvent = new TimeEvent(0, "CC2420 Send") { public void execute(long t) { txNext(); } }; - private TimeEvent ackEvent = new TimeEvent(0) { + private TimeEvent ackEvent = new TimeEvent(0, "CC2420 Ack") { public void execute(long t) { ackNext(); } }; - private TimeEvent shrEvent = new TimeEvent(0) { + private TimeEvent shrEvent = new TimeEvent(0, "CC2420 SHR") { public void execute(long t) { shrNext(); } }; - private TimeEvent symbolEvent = new TimeEvent(0) { + private TimeEvent symbolEvent = new TimeEvent(0, "CC2420 Symbol") { public void execute(long t) { switch(stateMachine) { case RX_CALIBRATE: Modified: mspsim/se/sics/mspsim/core/EventQueue.java =================================================================== --- mspsim/se/sics/mspsim/core/EventQueue.java 2009-12-15 16:34:40 UTC (rev 646) +++ mspsim/se/sics/mspsim/core/EventQueue.java 2010-01-18 15:50:22 UTC (rev 647) @@ -41,6 +41,8 @@ package se.sics.mspsim.core; +import java.io.PrintStream; + public class EventQueue { private TimeEvent first; @@ -156,14 +158,14 @@ eventCount = 0; } - public void print() { + public void print(PrintStream out) { TimeEvent t = first; - System.out.print("nxt: " + nextTime + " ["); + out.print("nxt: " + nextTime + " ["); while(t != null) { - System.out.print(t.getShort()); + out.print(t.getShort()); t = t.nextEvent; - if (t != null) System.out.print(", "); + if (t != null) out.print(", "); } - System.out.println("]"); + out.println("]"); } } // LLEventQueue Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2009-12-15 16:34:40 UTC (rev 646) +++ mspsim/se/sics/mspsim/core/MSP430.java 2010-01-18 15:50:22 UTC (rev 647) @@ -231,8 +231,9 @@ if(maxCycles > nextEventCycles) { /* back this time again... */ lastMicrosDelta -= jumpMicros; + printEventQueues(System.out); throw new IllegalArgumentException("Jumping to a time that is further than possible in LPM maxCycles:" + - maxCycles + " cycles: " + cycles); + maxCycles + " cycles: " + cycles + " nextEventCycles: " + nextEventCycles); } } else if (maxCycles > cycles) { /* back this time again... */ Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2009-12-15 16:34:40 UTC (rev 646) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2010-01-18 15:50:22 UTC (rev 647) @@ -451,17 +451,6 @@ return 1000.0 * getTime() / BasicClockModule.MAX_DCO_FRQ; } - - /** - * getCyclesToNext - returns the number of cycles that it will take before next - * execution of an event or zero if CPU is running. - * @return number of cycles left before next event executes or 0 if CPU is on. - */ - public long getCyclesToNext() { - if (!cpuOff) return 0; - return cycles - nextEventCycles; - } - private void executeEvents() { if (cycles >= nextVTimeEventCycles) { if (vTimeEventQueue.eventCount == 0) { @@ -554,8 +543,14 @@ return time; } + public void printEventQueues(PrintStream out) { + out.println("Current cycles: " + cycles + " virtual time:" + getTime()); + out.println("Cycle event queue: (next time: " + nextCycleEventCycles + ")"); + cycleEventQueue.print(out); + out.println("Virtual time event queue: (next time: " + nextVTimeEventCycles + ")"); + vTimeEventQueue.print(out); + } - // Should also return active units... public IOUnit getIOUnit(String name) { for (int i = 0, n = ioUnits.length; i < n; i++) { Modified: mspsim/se/sics/mspsim/core/TimeEvent.java =================================================================== --- mspsim/se/sics/mspsim/core/TimeEvent.java 2009-12-15 16:34:40 UTC (rev 646) +++ mspsim/se/sics/mspsim/core/TimeEvent.java 2010-01-18 15:50:22 UTC (rev 647) @@ -79,7 +79,7 @@ public abstract void execute(long t); public String getShort() { - return "" + time + (name != null ? ": " + name : ""); + return "" + time + ": " + (name != null ? name : this.getClass().getName()); } } // TimeEvent Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2009-12-15 16:34:40 UTC (rev 646) +++ mspsim/se/sics/mspsim/core/Timer.java 2010-01-18 15:50:22 UTC (rev 647) @@ -212,7 +212,7 @@ private final int ccr0Vector; private final MSP430Core core; - private TimeEvent timerTrigger = new TimeEvent(0) { + private TimeEvent timerTrigger = new TimeEvent(0, "TimerTrigger") { public void execute(long t) { // System.out.println(getName() + " **** executing update timers at " + t + " cycles=" + core.cycles); updateTimers(core.cycles); @@ -240,12 +240,14 @@ } if (srcMap == TIMER_Ax149) { name = "Timer A"; + timerTrigger.name += " A"; tiv = TAIV; timerOverflow = 0x0a; ccr0Vector = TACCR0_VECTOR; ccr1Vector = TACCR1_VECTOR; } else { name = "Timer B"; + timerTrigger.name += " B"; tiv = TBIV; timerOverflow = 0x0e; ccr0Vector = TBCCR0_VECTOR; @@ -793,6 +795,7 @@ } } + private long lastTrigger = 0; private void calculateNextEventTime(long cycles) { if (mode == STOP) { // If nothing is "running" there is no point scheduling... @@ -812,13 +815,19 @@ time = cycles + 1000; } +// if (time == nextTimerTrigger && timerTrigger.time >= nextTimerTrigger) { +// System.out.println(getName() + ": TIMER WRAP! " + (time - cycles) + " " + +// (timerTrigger.time - cycles) + " last: " + (cycles - lastTrigger) + " TAR: " + counter); +// } + lastTrigger = cycles; + if (timerTrigger.scheduledIn == null) { // System.out.println(getName() + " new trigger (nothing sch) ..." + time + " re:" + // smallest + " => " + (smallest > 0 ? expCaptureTime[smallest] + " > " + expCompare[smallest]: // nextTimerTrigger) + " C:"+ cycles); core.scheduleCycleEvent(timerTrigger, time); } else if (timerTrigger.time > time) { -// System.out.println(getName() + " new trigger (new time)..." + time + " C:"+ cycles); + // System.out.println(getName() + " new trigger (new time)..." + time + " C:"+ cycles); core.scheduleCycleEvent(timerTrigger, time); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-12-15 16:34:47
|
Revision: 646 http://mspsim.svn.sourceforge.net/mspsim/?rev=646&view=rev Author: joxe Date: 2009-12-15 16:34:40 +0000 (Tue, 15 Dec 2009) Log Message: ----------- added watch of arrays as chars or hex Modified Paths: -------------- mspsim/se/sics/mspsim/cli/DebugCommands.java Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-12-07 22:22:54 UTC (rev 645) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-12-15 16:34:40 UTC (rev 646) @@ -94,9 +94,10 @@ }); ch.registerCommand("watch", - new BasicAsyncCommand("add a write/read watch to a given address or symbol", "<address or symbol> [char | break]") { + new BasicAsyncCommand("add a write/read watch to a given address or symbol", "<address or symbol> [length] [char | hex | break]") { int mode = 0; int address = 0; + int length = 1; public int executeCommand(final CommandContext context) { int baddr = context.getArgumentAsAddress(0); if (baddr == -1) { @@ -104,36 +105,55 @@ return -1; } if (context.getArgumentCount() > 1) { - String modeStr = context.getArgument(1); - if ("char".equals(modeStr)) { - mode = 1; - } else if ("break".equals(modeStr)) { - mode = 2; - } + for (int i = 1; i < context.getArgumentCount(); i++) { + String modeStr = context.getArgument(i); + if (Character.isDigit(modeStr.charAt(0))) { + length = Integer.parseInt(modeStr); + } else if ("char".equals(modeStr)) { + mode = 1; + } else if ("break".equals(modeStr)) { + mode = 2; + } else if ("hex".equals(modeStr)) { + mode = 3; + } + } } - cpu.setBreakPoint(address = baddr, - new CPUMonitor() { - public void cpuAction(int type, int adr, int data) { - if (mode == 0 || mode == 2) { - int pc = cpu.readRegister(0); - String adrStr = getSymOrAddr(context, adr); - String pcStr = getSymOrAddrELF(getELF(), pc); - String op = "op"; - if (type == MEMORY_READ) { - op = "Read"; - } else if (type == MEMORY_WRITE){ - op = "Write"; - } - context.out.println("*** " + op + " from " + pcStr + - ": " + adrStr + " = " + data); - if (mode == 2) { - cpu.stop(); - } - } else { - context.out.print((char) data); + CPUMonitor monitor = new CPUMonitor() { + public void cpuAction(int type, int adr, int data) { + if (mode == 0 || mode == 2) { + int pc = cpu.readRegister(0); + String adrStr = getSymOrAddr(context, adr); + String pcStr = getSymOrAddrELF(getELF(), pc); + String op = "op"; + if (type == MEMORY_READ) { + op = "Read"; + } else if (type == MEMORY_WRITE){ + op = "Write"; + } + context.out.println("*** " + op + " from " + pcStr + + ": " + adrStr + " = " + data); + if (mode == 2) { + cpu.stop(); + } + } else { + if (length > 1) { + for (int i = address; i < address + length; i++) { + context.out.print(Utils.toString(cpu.memory[i], Utils.BYTE, mode == 1 ? Utils.ASCII : Utils.HEX)); + } + context.out.println(); + } else { + context.out.print(Utils.toString(data, Utils.BYTE, mode == 1 ? Utils.ASCII : Utils.HEX)); + } + } } + }; + + cpu.setBreakPoint(address = baddr, monitor); + if (length > 1) { + for (int i = 1; i < length; i++) { + cpu.setBreakPoint(address + i, monitor); } - }); + } context.out.println("Watch set at $" + Utils.hex16(baddr)); return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-12-07 22:23:18
|
Revision: 645 http://mspsim.svn.sourceforge.net/mspsim/?rev=645&view=rev Author: joxe Date: 2009-12-07 22:22:54 +0000 (Mon, 07 Dec 2009) Log Message: ----------- added timertest and fixed so that it is possoble to get interrupts while in interrupt Modified Paths: -------------- mspsim/Makefile mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/tests/Makefile Added Paths: ----------- mspsim/tests/timertest.c Modified: mspsim/Makefile =================================================================== --- mspsim/Makefile 2009-11-17 12:26:44 UTC (rev 644) +++ mspsim/Makefile 2009-12-07 22:22:54 UTC (rev 645) @@ -66,6 +66,7 @@ endif CPUTEST := tests/cputest.firmware +TIMERTEST := tests/timertest.firmware SCRIPTS := ${addprefix scripts/,autorun.sc duty.sc} BINARY := README.txt license.txt CHANGE_LOG.txt images/*.jpg firmware/*/*.firmware ${SCRIPTS} @@ -122,8 +123,13 @@ cputest: $(CPUTEST) $(JAVA) $(JAVAARGS) se.sics.mspsim.util.Test $(CPUTEST) +timertest: $(TIMERTEST) + $(JAVA) $(JAVAARGS) se.sics.mspsim.util.Test $(TIMERTEST) + $(CPUTEST): (cd tests && $(MAKE)) +$(TIMERTEST): + (cd tests && $(MAKE)) mtest: compile $(CPUTEST) @-$(RM) mini-test_cpu.txt Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2009-11-17 12:26:44 UTC (rev 644) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2009-12-07 22:22:54 UTC (rev 645) @@ -43,7 +43,6 @@ import java.io.PrintStream; import java.util.ArrayList; -import se.sics.mspsim.core.EmulationLogger.WarningMode; import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.MapEntry; import se.sics.mspsim.util.MapTable; @@ -342,7 +341,16 @@ // if (((value & GIE) == GIE) != interruptsEnabled) { // System.out.println("InterruptEnabled changed: " + !interruptsEnabled); // } + boolean oldIE = interruptsEnabled; interruptsEnabled = ((value & GIE) == GIE); + + if (oldIE == false && interruptsEnabled && servicedInterrupt >= 0) { + System.out.println("*** Interrupts enabled while in interrupt : " + + servicedInterrupt + " PC: " + Utils.hex16(reg[PC])); + /* must handle pending immediately */ + handlePendingInterrupts(); + } + cpuOff = ((value & CPUOFF) == CPUOFF); if (cpuOff != oldCpuOff) { // System.out.println("LPM CPUOff: " + cpuOff + " cycles: " + cycles); @@ -1031,6 +1039,7 @@ break; case RETI: // Put Top of stack to Status DstRegister (TOS -> SR) + servicedInterrupt = -1; /* needed before write to SR!!! */ sp = readRegister(SP); writeRegister(SR, memory[sp++] + (memory[sp++] << 8)); // TOS -> PC Modified: mspsim/tests/Makefile =================================================================== --- mspsim/tests/Makefile 2009-11-17 12:26:44 UTC (rev 644) +++ mspsim/tests/Makefile 2009-12-07 22:22:54 UTC (rev 645) @@ -30,8 +30,9 @@ OBJECTS := $(SOURCES:.c=.o) #all: cputest.ihex -all: cputest.firmware +all: cputest.firmware timertest.firmware + %.firmware: %.co $(OBJECTS) $(CC) -mmcu=$(MCU) -Wl,-Map=$(@:.firmware=.map) $(CFLAGS) -o $@ $^ Added: mspsim/tests/timertest.c =================================================================== --- mspsim/tests/timertest.c (rev 0) +++ mspsim/tests/timertest.c 2009-12-07 22:22:54 UTC (rev 645) @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2007, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * + * $Id: cputest.c,v 1.19 2007/10/24 22:17:46 nfi Exp $ + * + * ----------------------------------------------------------------- + * + * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : 2006-03-07 + * Updated : $Date: 2007/10/24 22:17:46 $ + * $Revision: 1.19 $ + */ + +#include "msp430setup.h" +#include <signal.h> +#include <stdio.h> +#include <string.h> +#include <io.h> + +/* From Adams test-suite */ +#define TEST(...) if(__VA_ARGS__) { \ + printf("OK: " #__VA_ARGS__ " passed at %s:%d\n", __FILE__,__LINE__); \ + } else { \ + printf("FAIL: " #__VA_ARGS__ " failed at %s:%d\n", __FILE__,__LINE__); \ + } + +#define TEST2(text,...) if(__VA_ARGS__) { \ + printf("OK: " #text " passed at %s:%d\n", __FILE__,__LINE__); \ + } else { \ + printf("FAIL: " #text " failed at %s:%d\n", __FILE__,__LINE__); \ + } + +#define assertTrue(...) TEST(__VA_ARGS__) +#define assertFalse(...) TEST(!(__VA_ARGS__)) + +#define assertTrue2(text,...) TEST2(text,__VA_ARGS__) +#define assertFalse2(text,...) TEST2(text,!(__VA_ARGS__)) + +static int testzero(int hm) +{ + return hm > 0; +} + +static int caseID = 0; + +#define RTIMER_ARCH_SECOND 4096 +#define CLOCK_SECOND 128 +#define CLOCK_CONF_SECOND CLOCK_SECOND +#define INTERVAL (RTIMER_ARCH_SECOND / CLOCK_SECOND) + +/*---------------------------------------------------------------------------*/ +static int pos = 0; +static unsigned int ticka0 = 0; +static unsigned int count = 0; +static unsigned int seconds = 0; +static unsigned int last_tar = 0; + +interrupt(TIMERA1_VECTOR) timera1 (void) { + if(TAIV == 2) { + eint(); + do { + TACCR1 += INTERVAL; + ++count; + + if (count == 5) { + for (pos = 0; pos < 2000; pos++) { + last_tar = TAR; + } + } + + if(count % CLOCK_CONF_SECOND == 0) { + ++seconds; + } + } while((TACCR1 - TAR) > INTERVAL); + last_tar = TAR; + } +} + + +/*---------------------------------------------------------------------------*/ +interrupt(TIMERA0_VECTOR) timera0 (void) { + ticka0++; + TACCR0 += 4; +} +/*---------------------------------------------------------------------------*/ +void +rtimer_arch_init(void) +{ +} + +/*---------------------------------------------------------------------------*/ + +static void initTest() { + caseID = 0; +} + +static void testCase(char *description) { + caseID++; + printf("-------------\n"); + printf("TEST %d: %s\n", caseID, description); +} + +static void testTimers() { + dint(); + /* Timer A1 */ + /* Select ACLK 32768Hz clock, divide by 8 */ + TACTL = TASSEL0 | TACLR | ID_3; + /* Initialize ccr1 to create the X ms interval. */ + /* CCR1 interrupt enabled, interrupt occurs when timer equals CCR1. */ + TACCTL1 = CCIE; + /* Interrupt after X ms. */ + TACCR1 = INTERVAL; + /* Start Timer_A in continuous mode. */ + TACTL |= MC1; + count = 0; + + /* Timer A0 */ + /* CCR0 interrupt enabled, interrupt occurs when timer equals CCR0. */ + TACCTL0 = CCIE; + TACCR0 = 40; + + /* Enable interrupts. */ + eint(); + + + while (ticka0 < 200) { + printf("Timer a0:%d \n", ticka0); + } + +} + +int +main(void) +{ + msp430_setup(); + + initTest(); + + testTimers(); + + printf("EXIT\n"); + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-11-17 12:27:07
|
Revision: 644 http://mspsim.svn.sourceforge.net/mspsim/?rev=644&view=rev Author: joxe Date: 2009-11-17 12:26:44 +0000 (Tue, 17 Nov 2009) Log Message: ----------- added CRC to CC2420 Modified Paths: -------------- mspsim/se/sics/mspsim/chip/CC2420.java mspsim/se/sics/mspsim/util/CCITT_CRC.java Modified: mspsim/se/sics/mspsim/chip/CC2420.java =================================================================== --- mspsim/se/sics/mspsim/chip/CC2420.java 2009-11-11 13:40:49 UTC (rev 643) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2009-11-17 12:26:44 UTC (rev 644) @@ -40,10 +40,8 @@ package se.sics.mspsim.chip; -import java.util.Arrays; - import se.sics.mspsim.core.*; -import se.sics.mspsim.core.EmulationLogger.WarningMode; +import se.sics.mspsim.util.CCITT_CRC; import se.sics.mspsim.util.Utils; public class CC2420 extends Chip implements USARTListener, RFListener, RFSource { @@ -364,6 +362,8 @@ private int ackPos; /* type = 2 (ACK), third byte needs to be sequence number... */ private int[] ackBuf = {0x02, 0x00, 0x00, 0x00, 0x00}; + private CCITT_CRC rxCrc = new CCITT_CRC(); + private CCITT_CRC txCrc = new CCITT_CRC(); public void setStateListener(StateListener listener) { stateListener = listener; @@ -519,25 +519,43 @@ } else if(stateMachine == RadioState.RX_FRAME) { if(rxfifoLen == 128) { setRxOverflow(); - } else { + } else { memory[RAM_RXFIFO + rxfifoWritePos] = data & 0xFF; rxfifoWritePos = (rxfifoWritePos + 1) & 127; rxfifoLen++; if(rxread == 0) { + rxCrc.setCRC(0); rxlen = data & 0xff; if (DEBUG) log("RX: Start frame length " + rxlen); // FIFO pin goes high after length byte is written to RXFIFO setFIFO(true); } + /* as long as we are not in the FCF (CRC) we count CRC */ + if (rxread < rxlen - 2) { + rxCrc.add(data & 0xff); + } + if(rxread++ == rxlen) { // 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 = memory[RAM_RXFIFO + ((rxfifoWritePos + 128 - 2) & 127)] << 8; + crc += memory[RAM_RXFIFO + ((rxfifoWritePos + 128 - 1) & 127)]; + +// if (crc == rxCrc.getCRC()) { +// System.out.println("CRC OK"); +// } else { +// //System.out.println("CRC not OK: recv:" + crc + " calc: " + rxCrc.getCRC()); +// } // Should take a RSSI value as input or use a set-RSSI value... memory[RAM_RXFIFO + ((rxfifoWritePos + 128 - 2) & 127)] = (registers[REG_RSSI]) & 0xff; // Set CRC ok and add a correlation - TODO: fix better correlation value!!! - memory[RAM_RXFIFO + ((rxfifoWritePos + 128 - 1) & 127)] = 37 | 0x80; + memory[RAM_RXFIFO + ((rxfifoWritePos + 128 - 1) & 127)] = 37 | (crc == rxCrc.getCRC() ? 0x80 : 0); + + // FIFOP should not be set if CRC is not ok??? - depends on autoCRC! setFIFOP(true); setSFD(false); lastPacketStart = (rxfifoWritePos + 128 - rxlen) & 127; @@ -609,6 +627,7 @@ // Assuming that the status always is sent back??? //source.byteReceived(status); break; + case WRITE_REGISTER: if (pos == 0) { source.byteReceived(registers[address] >> 8); @@ -843,6 +862,7 @@ if(shrPos == 5) { // Set SFD high setSFD(true); + if (stateMachine == RadioState.TX_PREAMBLE) { setState(RadioState.TX_FRAME); } else if (stateMachine == RadioState.TX_ACK_PREAMBLE) { @@ -863,6 +883,19 @@ private void txNext() { if(txfifoPos <= memory[RAM_TXFIFO]) { + if (txfifoPos == 0) { + txCrc.setCRC(0); + int len = memory[RAM_TXFIFO] & 0xff; + for (int i = 0; i < memory[RAM_TXFIFO] - 2; i++) { + txCrc.add(memory[RAM_TXFIFO + i] & 0xff); + } +// System.out.println("Setting TX CRC to: " + txCrc.getCRC()); + /* this is not correct - will probably not be compliant with the order + * that the actual CC2420 sends the CRC... + */ + memory[RAM_TXFIFO + len - 1] = txCrc.getCRC() >> 8; + memory[RAM_TXFIFO + len] = txCrc.getCRC() & 0xff; + } if (txfifoPos > 0x7f) { log("Warning: packet size too large - repeating packet bytes txfifoPos: " + txfifoPos); } Modified: mspsim/se/sics/mspsim/util/CCITT_CRC.java =================================================================== --- mspsim/se/sics/mspsim/util/CCITT_CRC.java 2009-11-11 13:40:49 UTC (rev 643) +++ mspsim/se/sics/mspsim/util/CCITT_CRC.java 2009-11-17 12:26:44 UTC (rev 644) @@ -42,6 +42,10 @@ return crc; } + public void setCRC(int val) { + crc = val; + } + public void clr() { crc = 0xffff; } @@ -52,7 +56,7 @@ newCrc ^= (newCrc & 0xff) >> 4; newCrc ^= (newCrc << 12); newCrc ^= (newCrc & 0xff) << 5; - crc = newCrc; + crc = newCrc & 0xffff; return crc; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fro...@us...> - 2009-11-11 13:40:59
|
Revision: 643 http://mspsim.svn.sourceforge.net/mspsim/?rev=643&view=rev Author: fros4943 Date: 2009-11-11 13:40:49 +0000 (Wed, 11 Nov 2009) Log Message: ----------- removed obsolete setCCA method Modified Paths: -------------- mspsim/se/sics/mspsim/chip/CC2420.java Modified: mspsim/se/sics/mspsim/chip/CC2420.java =================================================================== --- mspsim/se/sics/mspsim/chip/CC2420.java 2009-10-27 23:22:35 UTC (rev 642) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2009-11-11 13:40:49 UTC (rev 643) @@ -1149,17 +1149,6 @@ registers[register] = data; } - /* External API for radio mediums - will change to setRSSI only later...*/ - public void setCCA(boolean clear) { - if (DEBUG) log("*** CCA set to: " + clear + " ignored...."); -// if (clear) { -// rssi = 0; -// } else { -// rssi = 127; -// } -// updateCCA(); - } - /***************************************************************************** * Chip APIs *****************************************************************************/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-10-27 23:22:48
|
Revision: 642 http://mspsim.svn.sourceforge.net/mspsim/?rev=642&view=rev Author: joxe Date: 2009-10-27 23:22:35 +0000 (Tue, 27 Oct 2009) Log Message: ----------- prepared for autoack in CC2420 - not ready Modified Paths: -------------- mspsim/se/sics/mspsim/chip/CC2420.java Modified: mspsim/se/sics/mspsim/chip/CC2420.java =================================================================== --- mspsim/se/sics/mspsim/chip/CC2420.java 2009-10-27 13:48:47 UTC (rev 641) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2009-10-27 23:22:35 UTC (rev 642) @@ -40,7 +40,10 @@ package se.sics.mspsim.chip; +import java.util.Arrays; + import se.sics.mspsim.core.*; +import se.sics.mspsim.core.EmulationLogger.WarningMode; import se.sics.mspsim.util.Utils; public class CC2420 extends Chip implements USARTListener, RFListener, RFSource { @@ -146,7 +149,12 @@ 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; + // RAM Addresses public static final int RAM_TXFIFO = 0x000; public static final int RAM_RXFIFO = 0x080; @@ -184,7 +192,7 @@ TX_PREAMBLE(34), TX_FRAME(37), TX_ACK_CALIBRATE(48), - TX_ACK_PREABLE(49), + TX_ACK_PREAMBLE(49), TX_ACK(52), TX_UNDERFLOW(56); @@ -199,11 +207,10 @@ }; // FCF High - public static final int FRAME_TYPE = 0xC0; - public static final int SECURITY_ENABLED = (1<<6); - public static final int FRAME_PENDING = (1<<5); - public static final int ACK_REQUEST = (1<<4); - public static final int INTRA_PAN = (1<<3); + public static final int FRAME_TYPE = 0x07; + public static final int SECURITY_ENABLED = (1<<3); + public static final int ACK_REQUEST = (1<<5); + public static final int INTRA_PAN = (1<<6); // FCF Low public static final int DESTINATION_ADDRESS_MODE = 0x30; public static final int SOURCE_ADDRESS_MODE = 0x3; @@ -244,6 +251,10 @@ /* current CCA value */ private boolean cca = false; + /* if autoack is configured or if */ + private boolean autoAck = false; + private boolean shouldAck = false; + private int activeFrequency = 0; private int activeChannel = 0; @@ -308,6 +319,12 @@ } }; + private TimeEvent ackEvent = new TimeEvent(0) { + public void execute(long t) { + ackNext(); + } + }; + private TimeEvent shrEvent = new TimeEvent(0) { public void execute(long t) { shrNext(); @@ -328,6 +345,10 @@ case RX_WAIT: setState(RadioState.RX_SFD_SEARCH); break; + + case TX_ACK_CALIBRATE: + setState(RadioState.TX_ACK_PREAMBLE); + break; } } }; @@ -340,13 +361,16 @@ } private StateListener stateListener = null; + private int ackPos; + /* type = 2 (ACK), third byte needs to be sequence number... */ + private int[] ackBuf = {0x02, 0x00, 0x00, 0x00, 0x00}; public void setStateListener(StateListener listener) { stateListener = listener; } public RadioState getState() { - return stateMachine; + return stateMachine; } // TODO: super(cpu) and chip autoregister chips into the CPU. @@ -434,6 +458,27 @@ setMode(MODE_TXRX_OFF); updateCCA(); break; + + case TX_ACK_CALIBRATE: + /* TX active during ACK ? */ + status |= STATUS_TX_ACTIVE; + setSymbolEvent(12 + 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; + ackNext(); + break; } /* Notify state listener */ @@ -491,19 +536,39 @@ // Should take a RSSI value as input or use a set-RSSI value... memory[RAM_RXFIFO + ((rxfifoWritePos + 128 - 2) & 127)] = (registers[REG_RSSI]) & 0xff; - // Set CRC ok and add a correlation + // Set CRC ok and add a correlation - TODO: fix better correlation value!!! memory[RAM_RXFIFO + ((rxfifoWritePos + 128 - 1) & 127)] = 37 | 0x80; setFIFOP(true); setSFD(false); lastPacketStart = (rxfifoWritePos + 128 - rxlen) & 127; if (DEBUG) log("RX: Complete: packetStart: " + lastPacketStart); - setState(RadioState.RX_WAIT); + + /* if either manual ack request (shouldAck) or autoack + ACK_REQ on package do ack! */ + if ((autoAck && checkAutoack()) || shouldAck) { + setState(RadioState.TX_ACK_CALIBRATE); + } else { + setState(RadioState.RX_WAIT); + } } } } } + private boolean checkAutoack() { + boolean ackReq = (memory[RAM_RXFIFO + lastPacketStart] & ACK_REQUEST) != 0; + if (!ackReq) return false; + /* here we need to check that this address is correct compared to the stored address */ + int addrSize = 8; /* this is hard coded to a long address - can be short!!! */ + int addrPos = lastPacketStart + 2 + 1; // where starts the destination address of the packet!!!?? + for (int i = 0; i < addrSize; i++) { + if (memory[RAM_IEEEADDR + i] != memory[RAM_RXFIFO + (addrPos + i) & 127]) { + return false; + } + } + return false; + } + public void dataReceived(USART source, int data) { int oldStatus = status; if (DEBUG) { @@ -778,7 +843,14 @@ if(shrPos == 5) { // Set SFD high setSFD(true); - setState(RadioState.TX_FRAME); + 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 (listener != null) { if (DEBUG) log("transmitting byte: " + Utils.hex8(SHR[shrPos])); @@ -816,7 +888,27 @@ txfifoFlush = true; } } + + private void ackNext() { + if (ackPos < ackBuf.length) { + if (listener != null) { + if (DEBUG) log("transmitting byte: " + Utils.hex8(memory[RAM_TXFIFO + (txfifoPos & 0x7f)] & 0xFF)); + listener.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); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-10-27 13:48:55
|
Revision: 641 http://mspsim.svn.sourceforge.net/mspsim/?rev=641&view=rev Author: joxe Date: 2009-10-27 13:48:47 +0000 (Tue, 27 Oct 2009) Log Message: ----------- fixed bug that caused division by zero when updating TCCTL and calculating CC_I Modified Paths: -------------- mspsim/se/sics/mspsim/core/Timer.java Modified: mspsim/se/sics/mspsim/core/Timer.java =================================================================== --- mspsim/se/sics/mspsim/core/Timer.java 2009-10-27 09:55:05 UTC (rev 640) +++ mspsim/se/sics/mspsim/core/Timer.java 2009-10-27 13:48:47 UTC (rev 641) @@ -365,7 +365,11 @@ /* needs the TimerA clock speed here... */ int aTicks = clockSpeed / core.aclkFrq; updateCounter(cycles); - if (counter % aTicks > aTicks / 2) { + + /* only calculate this if clock runs faster then ACLK - otherwise it + * this will be dividing by zero... + */ + if (aTicks > 0 && counter % aTicks > aTicks / 2) { input = true; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fro...@us...> - 2009-10-27 09:55:16
|
Revision: 640 http://mspsim.svn.sourceforge.net/mspsim/?rev=640&view=rev Author: fros4943 Date: 2009-10-27 09:55:05 +0000 (Tue, 27 Oct 2009) Log Message: ----------- bugfix: when resetting cycle counter after dco reset + removed debugging output Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430.java Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2009-10-27 09:54:20 UTC (rev 639) +++ mspsim/se/sics/mspsim/core/MSP430.java 2009-10-27 09:55:05 UTC (rev 640) @@ -205,6 +205,7 @@ * Note: jumpMicros just jump the clock until that time * executeMicros also check eventQ, etc and executes instructions */ + long maxCycles = 0; public long stepMicros(long jumpMicros, long executeMicros) throws EmulationException { if (isRunning()) { throw new IllegalStateException("step not possible when CPU is running"); @@ -217,16 +218,15 @@ /* quick hack - if microdelta == 0 => ensure that we have correct zery cycles */ if (!microClockReady) { - System.out.println("Setting cycles to zero at " + cycles); - lastMicrosCycles = cycles; - microClockReady = true; + lastMicrosCycles = maxCycles; } // Note: will be reset during DCO-syncs... => problems ??? lastMicrosDelta += jumpMicros; + if (microClockReady) { /* check that we did not miss any events (by comparing with last return value) */ - long maxCycles = lastMicrosCycles + (lastMicrosDelta * dcoFrq) / 1000000; + maxCycles = lastMicrosCycles + (lastMicrosDelta * dcoFrq) / 1000000; if (cpuOff) { if(maxCycles > nextEventCycles) { /* back this time again... */ @@ -240,11 +240,14 @@ throw new IllegalArgumentException("Jumping to a time that is further than possible not LPM maxCycles:" + maxCycles + " cycles: " + cycles); } - + + } + microClockReady = true; + /* run until this cycle time */ maxCycles = lastMicrosCycles + ((lastMicrosDelta + executeMicros) * dcoFrq) / 1000000; - System.out.println("Current cycles: " + cycles + " additional micros: " + (jumpMicros) + - " exec micros: " + executeMicros + " => Execute until cycles: " + maxCycles); + /*System.out.println("Current cycles: " + cycles + " additional micros: " + (jumpMicros) + + " exec micros: " + executeMicros + " => Execute until cycles: " + maxCycles);*/ // ------------------------------------------------------------------- // Debug information @@ -259,15 +262,16 @@ boolean emuOP = false; - while (cycles < maxCycles) { + while (cycles < maxCycles || (cpuOff && (nextEventCycles < cycles))) { if (emuOP = emulateOP(maxCycles)) { if (execCounter != null) { execCounter[reg[PC]]++; } if (trace != null) { - trace[tracePos++] = reg[PC]; - if (tracePos > trace.length) - tracePos = 0; + if (tracePos > trace.length) { + tracePos = 0; + } + trace[tracePos++] = reg[PC]; } } } @@ -278,6 +282,13 @@ lastReturnedMicros = 0; } + if(cycles < maxCycles) { + throw new RuntimeException("cycles < maxCycles : " + cycles + " < " + maxCycles); + } + if(lastReturnedMicros < 0) { + throw new RuntimeException("lastReturnedMicros < 0 : " + lastReturnedMicros); + } + return lastReturnedMicros; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2009-10-27 09:54:26
|
Revision: 639 http://mspsim.svn.sourceforge.net/mspsim/?rev=639&view=rev Author: nifi Date: 2009-10-27 09:54:20 +0000 (Tue, 27 Oct 2009) Log Message: ----------- Removed obsolete window redirection ">#\. Replaced by window command. Modified Paths: -------------- mspsim/se/sics/mspsim/cli/CommandParser.java Modified: mspsim/se/sics/mspsim/cli/CommandParser.java =================================================================== --- mspsim/se/sics/mspsim/cli/CommandParser.java 2009-10-27 08:41:01 UTC (rev 638) +++ mspsim/se/sics/mspsim/cli/CommandParser.java 2009-10-27 09:54:20 UTC (rev 639) @@ -135,19 +135,19 @@ quote = c; } break; - case '#': - if (!handleRedirect) { - // No redirect handling. Process as normal character. - if (state == TEXT) { - index = i; - state = ARG; - } - } else if (state == TEXT && redirectCommand != null && redirectFile == args.size()) { - redirectCommand += '#'; - } else if (state != QUOTE) { - throw new IllegalArgumentException("illegal character '#'"); - } - break; +// case '#': +// if (!handleRedirect) { +// // No redirect handling. Process as normal character. +// if (state == TEXT) { +// index = i; +// state = ARG; +// } +// } else if (state == TEXT && redirectCommand != null && redirectFile == args.size()) { +// redirectCommand += '#'; +// } else if (state != QUOTE) { +// throw new IllegalArgumentException("illegal character '#'"); +// } +// break; case '>': if (!handleRedirect) { // No redirect handling. Process as normal character. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2009-10-27 08:41:29
|
Revision: 638 http://mspsim.svn.sourceforge.net/mspsim/?rev=638&view=rev Author: nifi Date: 2009-10-27 08:41:01 +0000 (Tue, 27 Oct 2009) Log Message: ----------- Changed file redirection in CLI to be more similar to normal shell. ">file" will overwrite file and ">>file" will append to file. Closing a file will stop all attached commands Modified Paths: -------------- mspsim/scripts/autorun.sc mspsim/se/sics/mspsim/cli/FileCommands.java mspsim/se/sics/mspsim/cli/FileTarget.java mspsim/se/sics/mspsim/cli/FileTargetCommand.java Modified: mspsim/scripts/autorun.sc =================================================================== --- mspsim/scripts/autorun.sc 2009-10-27 00:36:52 UTC (rev 637) +++ mspsim/scripts/autorun.sc 2009-10-27 08:41:01 UTC (rev 638) @@ -1,8 +1,7 @@ # autorun script for MSPSim # - all commands will run after loaded firmware into MSPSim -#exec rm log.txt #log CC2420 >log.txt -#printcalls >log.txt +#printcalls >>log.txt # Install and activate the plugin 'ContikiChecker' # install ContikiChecker @@ -12,5 +11,5 @@ service controlgui start service nodegui start #service stackchart start -rflistener output CC2420 > rfdata.txt +#rflistener output CC2420 >> rfdata.txt start Modified: mspsim/se/sics/mspsim/cli/FileCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/FileCommands.java 2009-10-27 00:36:52 UTC (rev 637) +++ mspsim/se/sics/mspsim/cli/FileCommands.java 2009-10-27 08:41:01 UTC (rev 638) @@ -1,21 +1,24 @@ package se.sics.mspsim.cli; import java.util.Hashtable; -import java.util.Iterator; import se.sics.mspsim.util.ComponentRegistry; public class FileCommands implements CommandBundle { - private Hashtable <String, FileTarget> fileTargets = new Hashtable<String, FileTarget>(); + private final Hashtable <String, FileTarget> fileTargets = new Hashtable<String, FileTarget>(); public void setupCommands(final ComponentRegistry registry, CommandHandler handler) { // TODO: this should also be "registered" as a "sink". // probably this should be handled using ">" instead! handler.registerCommand(">", new FileTargetCommand(fileTargets, - null, "<filename>", false)); + null, "<filename>", false, false)); + + handler.registerCommand(">>", new FileTargetCommand(fileTargets, + null, "<filename>", false, true)); + handler.registerCommand("tee", new FileTargetCommand(fileTargets, - "redirect to file and std-out", "<filename>", true)); + "redirect to file and standard out", "<filename>", true, true)); handler.registerCommand("fclose", new BasicCommand("close the specified file", "<filename>") { public int executeCommand(CommandContext context) { @@ -23,22 +26,29 @@ FileTarget ft = fileTargets.get(name); if (ft != null) { context.out.println("Closing file " + name); - fileTargets.remove(name); ft.close(); return 0; - } else { - context.err.println("Could not find the open file " + name); - return 1; } + context.err.println("Could not find the open file " + name); + return 1; } }); handler.registerCommand("files", new BasicCommand("list open files", "") { public int executeCommand(CommandContext context) { - for (Iterator<FileTarget> iterator = fileTargets.values().iterator(); iterator.hasNext();) { - FileTarget type = iterator.next(); - context.out.println(type.getName()); + FileTarget[] files = null; + synchronized (fileTargets) { + if (fileTargets.size() > 0) { + files = fileTargets.values().toArray(new FileTarget[fileTargets.size()]); + } } + if (files == null) { + context.out.println("There are no open files."); + } else { + for (FileTarget type : files) { + context.out.println(type.getStatus()); + } + } return 0; } }); Modified: mspsim/se/sics/mspsim/cli/FileTarget.java =================================================================== --- mspsim/se/sics/mspsim/cli/FileTarget.java 2009-10-27 00:36:52 UTC (rev 637) +++ mspsim/se/sics/mspsim/cli/FileTarget.java 2009-10-27 08:41:01 UTC (rev 638) @@ -42,48 +42,141 @@ import java.io.FileWriter; import java.io.IOException; +import java.util.ArrayList; +import java.util.Hashtable; /** * @author joakim - * */ -public class FileTarget implements LineListener { +public class FileTarget { - private final FileWriter out; - private final String name; + private static final boolean DEBUG = false; - public FileTarget(String name) throws IOException { - this.out = new FileWriter(name); - this.name = name; - } + private final Hashtable<String,FileTarget> fileTargets; + private final String name; + private final FileWriter out; + private ArrayList<CommandContext> contexts = new ArrayList<CommandContext>(); - public String getName() { - return name; - } + public FileTarget(Hashtable<String,FileTarget> fileTargets, String name, + boolean append) throws IOException { + this.fileTargets = fileTargets; + this.out = new FileWriter(name, append); + this.name = name; + fileTargets.put(name, this); + } - /* (non-Javadoc) - * @see se.sics.mspsim.cli.LineListener#lineRead(java.lang.String) - */ - public void lineRead(String line) { - if (line == null) { - close(); - } else { - try { - out.write(line); - out.write('\n'); - out.flush(); - } catch (IOException e) { - e.printStackTrace(); - }; + public String getName() { + return name; } - } - public void close() { - try { - out.close(); - } catch (IOException e) { - e.printStackTrace(); + public String getStatus() { + StringBuilder sb = new StringBuilder(); + sb.append(name); + synchronized (fileTargets) { + if (contexts != null) { + sb.append(" \tPIDs: ["); + for (int i = 0, n = contexts.size(); i < n; i++) { + int pid = contexts.get(i).getPID(); + if (i > 0) { + sb.append(','); + } + if (pid < 0) { + sb.append('?'); + } else { + sb.append(pid); + } + } + sb.append(']'); + } + } + return sb.toString(); } - } + public void lineRead(CommandContext context, String line) { + if (line == null) { + removeContext(context); + } else { + try { + out.write(line); + out.write('\n'); + out.flush(); + } catch (IOException e) { + e.printStackTrace(context.err); + } + } + } + + public void addContext(CommandContext context) { + boolean added = false; + synchronized (fileTargets) { + if (contexts != null) { + contexts.add(context); + added = true; + if (DEBUG) { + System.out.println("FileTarget: new writer to " + name + + " (" + contexts.size() + ')'); + } + } + } + if (!added) { + context.kill(); + } + } + + public void removeContext(CommandContext context) { + boolean close = false; + synchronized (fileTargets) { + if (contexts != null && contexts.remove(context)) { + if (DEBUG) { + System.out.println("FileTarget: removed writer from " + + name + " (" + contexts.size() + ')'); + } + if (contexts.size() == 0) { + close = true; + } + } + } + if (close) { + close(false); + } + } + + public void close() { + close(true); + } + + private void close(boolean forceClose) { + ArrayList<CommandContext> list; + synchronized (fileTargets) { + if (contexts == null) { + // Already closed + return; + } + if (contexts.size() > 0 && !forceClose) { + // File still has connected writers. + return; + } + list = contexts; + contexts = null; + if (fileTargets.get(name) == this) { + fileTargets.remove(name); + if (DEBUG) { + System.out.println("FileTarget: closed file " + name); + } + } + } + + if (list != null) { + // Close any connected writers + for (CommandContext context : list) { + context.kill(); + } + } + try { + out.close(); + } catch (IOException e) { + // Ignore close errors + } + } + } Modified: mspsim/se/sics/mspsim/cli/FileTargetCommand.java =================================================================== --- mspsim/se/sics/mspsim/cli/FileTargetCommand.java 2009-10-27 00:36:52 UTC (rev 637) +++ mspsim/se/sics/mspsim/cli/FileTargetCommand.java 2009-10-27 08:41:01 UTC (rev 638) @@ -4,39 +4,50 @@ import java.util.Hashtable; public class FileTargetCommand extends BasicLineCommand { - FileTarget ft; - Hashtable<String, FileTarget> fileTargets; - private boolean print; + private final Hashtable<String, FileTarget> fileTargets; + private final boolean print; + private final boolean append; + + private FileTarget ft; private CommandContext context; public FileTargetCommand(Hashtable<String,FileTarget> fileTargets, - String name, String desc, boolean print) { + String name, String desc, boolean print, boolean append) { super(name, desc); this.fileTargets = fileTargets; this.print = print; + this.append = append; } + public int executeCommand(CommandContext context) { this.context = context; String fileName = context.getArgument(0); - ft = fileTargets.get(fileName); - if (ft == null) { - try { - ft = new FileTarget(fileName); - fileTargets.put(fileName, ft); - } catch (IOException e) { - e.printStackTrace(); + synchronized (fileTargets) { + ft = fileTargets.get(fileName); + if (ft == null) { + try { + ft = new FileTarget(fileTargets, fileName, append); + } catch (IOException e) { + e.printStackTrace(context.err); + return -1; + } + } else if (!append) { + context.err.println("File already opened: can not overwrite"); + return -1; } + ft.addContext(context); } return 0; } - + public void lineRead(String line) { - ft.lineRead(line); if (print) context.out.println(line); + ft.lineRead(context, line); } - + public void stopCommand(CommandContext context) { - // Should this do anything? - // Probably depending on the ft's config + if (ft != null) { + ft.removeContext(context); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |