From: <fro...@us...> - 2008-09-18 04:20:14
|
Revision: 338 http://mspsim.svn.sourceforge.net/mspsim/?rev=338&view=rev Author: fros4943 Date: 2008-09-18 11:20:12 +0000 (Thu, 18 Sep 2008) Log Message: ----------- debug output (false) Modified Paths: -------------- mspsim/se/sics/mspsim/core/ADC12.java Modified: mspsim/se/sics/mspsim/core/ADC12.java =================================================================== --- mspsim/se/sics/mspsim/core/ADC12.java 2008-09-18 11:19:32 UTC (rev 337) +++ mspsim/se/sics/mspsim/core/ADC12.java 2008-09-18 11:20:12 UTC (rev 338) @@ -49,7 +49,7 @@ public class ADC12 extends IOUnit { - private static final boolean DEBUG = true; //false; + private static final boolean DEBUG = false; public static final int ADC12CTL0 = 0x01A0;// Reset with POR public static final int ADC12CTL1 = 0x01A2;// Reset with POR @@ -180,9 +180,9 @@ default: if (address >= ADC12MCTL0 && address <= ADC12MCTL15) { adc12mctl[address - ADC12MCTL0] = value & 0xff; - System.out.println("ADC12MCTL" + (address - ADC12MCTL0) + " source = " + (value & 0xf)); + if (DEBUG) System.out.println("ADC12MCTL" + (address - ADC12MCTL0) + " source = " + (value & 0xf)); if ((value & 0x80) != 0) { - System.out.println("ADC12MCTL" + (address - ADC12MCTL0) + " EOS bit set"); + if (DEBUG) System.out.println("ADC12MCTL" + (address - ADC12MCTL0) + " EOS bit set"); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-03-11 22:28:35
|
Revision: 479 http://mspsim.svn.sourceforge.net/mspsim/?rev=479&view=rev Author: joxe Date: 2009-03-11 22:28:15 +0000 (Wed, 11 Mar 2009) Log Message: ----------- minor bugfix of ADC12 Modified Paths: -------------- mspsim/se/sics/mspsim/core/ADC12.java Modified: mspsim/se/sics/mspsim/core/ADC12.java =================================================================== --- mspsim/se/sics/mspsim/core/ADC12.java 2009-03-11 22:22:40 UTC (rev 478) +++ mspsim/se/sics/mspsim/core/ADC12.java 2009-03-11 22:28:15 UTC (rev 479) @@ -203,11 +203,11 @@ if (address >= ADC12MCTL0 && address <= ADC12MCTL15) { return adc12mctl[address - ADC12MCTL0]; } else if (address >= ADC12MEM0) { - int reg = address - ADC12MEM0; + int reg = (address - ADC12MEM0) / 2; // Clear ifg! adc12ifg &= ~(1 << reg); // System.out.println("Read ADCMEM" + (reg / 2)); - if (adc12iv == reg + 6) { + if (adc12iv == reg * 2 + 6) { core.flagInterrupt(adc12Vector, this, false); adc12iv = 0; // System.out.println("** de-Trigger ADC12 IRQ for ADCMEM" + adc12Pos); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2010-05-28 17:09:36
|
Revision: 702 http://mspsim.svn.sourceforge.net/mspsim/?rev=702&view=rev Author: nifi Date: 2010-05-28 17:09:29 +0000 (Fri, 28 May 2010) Log Message: ----------- * corrected behaviour of ADC12IFG * added write protection during conversion * added reset handling Modified Paths: -------------- mspsim/se/sics/mspsim/core/ADC12.java Modified: mspsim/se/sics/mspsim/core/ADC12.java =================================================================== --- mspsim/se/sics/mspsim/core/ADC12.java 2010-05-17 09:43:04 UTC (rev 701) +++ mspsim/se/sics/mspsim/core/ADC12.java 2010-05-28 17:09:29 UTC (rev 702) @@ -35,7 +35,7 @@ * * Each time a sample is converted the ADC12 system will check for EOS flag * and if not set it just continues with the next conversion (x + 1). - * If EOS next conv is startMem. + * If EOS next conversion is startMem. * Interrupt is triggered when the IE flag are set! * * @@ -47,6 +47,8 @@ package se.sics.mspsim.core; +import java.util.Arrays; + public class ADC12 extends IOUnit { private static final boolean DEBUG = false; @@ -96,6 +98,7 @@ public static final int EOS_MASK = 0x80; + private final MSP430Core core; private int adc12ctl0 = 0; private int adc12ctl1 = 0; @@ -113,7 +116,7 @@ private int startMem = 0; private int adcDiv = 1; - private ADCInput adcInput[] = new ADCInput[8]; + private ADCInput adcInput[] = new ADCInput[16]; private int conSeq; private int adc12ie; @@ -121,7 +124,6 @@ private int adc12iv; private int adcSSel; - private MSP430Core core; private int adc12Vector = 7; private TimeEvent adcTrigger = new TimeEvent(0) { @@ -136,38 +138,70 @@ super(cpu.memory, 0); core = cpu; } - + + public void reset(int type) { + enableConversion = false; + startConversion = false; + adc12ctl0 = 0; + adc12ctl1 = 0; + shTime0 = shTime1 = 4; + adc12On = false; + shSource = 0; + startMem = adc12Pos = 0; + adcDiv = 1; + + conSeq = 0; + adc12ie = 0; + adc12ifg = 0; + adc12iv = 0; + adcSSel = 0; + + Arrays.fill(adc12mctl, 0); + } + public void setADCInput(int adindex, ADCInput input) { adcInput[adindex] = input; } // write a value to the IO unit - public void write(int address, int value, boolean word, - long cycles) { + public void write(int address, int value, boolean word, long cycles) { switch (address) { case ADC12CTL0: - adc12ctl0 = value; - shTime0 = SHTBITS[(value >> 8) & 0x0f]; - shTime1 = SHTBITS[(value >> 12) & 0x0f]; - adc12On = (value & 0x10) > 0; + if (enableConversion) { + // Ongoing conversion: only some parts may be changed + adc12ctl0 = (adc12ctl0 & 0xfff0) + (value & 0xf); + } else { + adc12ctl0 = value; + shTime0 = SHTBITS[(value >> 8) & 0x0f]; + shTime1 = SHTBITS[(value >> 12) & 0x0f]; + adc12On = (value & 0x10) > 0; + } enableConversion = (value & 0x02) > 0; startConversion = (value & 0x01) > 0; if (DEBUG) System.out.println(getName() + ": Set SHTime0: " + shTime0 + " SHTime1: " + shTime1 + " ENC:" + enableConversion + " Start: " + startConversion + " ADC12ON: " + adc12On); if (adc12On && enableConversion && startConversion) { - // Set the start time to be now! - adcTrigger.time = core.getTime(); - convert(); + if (!adcTrigger.isScheduled()) { + // Set the start time to be now! + adc12Pos = startMem; + int delay = adcDiv * ((adc12Pos < 8 ? shTime0 : shTime1) + 13); + core.scheduleTimeEvent(adcTrigger, core.getTime() + delay); + } } break; case ADC12CTL1: - adc12ctl1 = value; - startMem = (value >> 12) & 0xf; - shSource = (value >> 10) & 0x3; - adcDiv = ((value >> 5) & 0x7) + 1; + if (enableConversion) { + // Ongoing conversion: only some parts may be changed + adc12ctl1 = (adc12ctl1 & 0xfff8) + (value & 0x7); + } else { + adc12ctl1 = value; + startMem = (value >> 12) & 0xf; + shSource = (value >> 10) & 0x3; + adcDiv = ((value >> 5) & 0x7) + 1; + adcSSel = (value >> 3) & 0x03; + } conSeq = (value >> 1) & 0x03; - adcSSel = (value >> 3) & 0x03; if (DEBUG) System.out.println(getName() + ": Set startMem: " + startMem + " SHSource: " + shSource + " ConSeq-mode:" + conSeq + " Div: " + adcDiv + " ADCSSEL: " + adcSSel); break; @@ -179,10 +213,13 @@ break; default: if (address >= ADC12MCTL0 && address <= ADC12MCTL15) { - adc12mctl[address - ADC12MCTL0] = value & 0xff; - if (DEBUG) System.out.println("ADC12MCTL" + (address - ADC12MCTL0) + " source = " + (value & 0xf)); - if ((value & 0x80) != 0) { - if (DEBUG) System.out.println("ADC12MCTL" + (address - ADC12MCTL0) + " EOS bit set"); + if (enableConversion) { + /* Ongoing conversion: not possible to modify */ + } else { + adc12mctl[address - ADC12MCTL0] = value & 0xff; + if (DEBUG) System.out.println("ADC12MCTL" + (address - ADC12MCTL0) + + " source = " + (value & 0xf) + + (((value & EOS_MASK) != 0) ? " EOS bit set" : "")); } } } @@ -202,7 +239,7 @@ default: if (address >= ADC12MCTL0 && address <= ADC12MCTL15) { return adc12mctl[address - ADC12MCTL0]; - } else if (address >= ADC12MEM0) { + } else if (address >= ADC12MEM0 && address <= ADC12MEM15) { int reg = (address - ADC12MEM0) / 2; // Clear ifg! adc12ifg &= ~(1 << reg); @@ -226,12 +263,12 @@ private void convert() { // If either off or not enable conversion then just return... if (!adc12On || !enableConversion) return; - // Some noice... - ADCInput input = adcInput[adc12mctl[adc12Pos] & 0x7]; + // Some noise... + ADCInput input = adcInput[adc12mctl[adc12Pos] & 0xf]; adc12mem[adc12Pos] = input != null ? input.nextData() : 2048 + 100 - smp & 255; smp += 7; + adc12ifg |= (1 << adc12Pos); if ((adc12ie & (1 << adc12Pos)) > 0) { - adc12ifg |= (1 << adc12Pos); // This should check if there already is an higher iv! adc12iv = adc12Pos * 2 + 6; //System.out.println("** Trigger ADC12 IRQ for ADCMEM" + adc12Pos); @@ -243,8 +280,7 @@ } else { adc12Pos = (adc12Pos + 1) & 0x0f; } - int delay = adcDiv * (shTime0 + 13); - + int delay = adcDiv * ((adc12Pos < 8 ? shTime0 : shTime1) + 13); core.scheduleTimeEvent(adcTrigger, adcTrigger.time + delay); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2010-06-01 22:21:50
|
Revision: 704 http://mspsim.svn.sourceforge.net/mspsim/?rev=704&view=rev Author: nifi Date: 2010-06-01 22:21:43 +0000 (Tue, 01 Jun 2010) Log Message: ----------- Added handling of the four operating modes (CONSEQx) and ADC12BUSY Modified Paths: -------------- mspsim/se/sics/mspsim/core/ADC12.java Modified: mspsim/se/sics/mspsim/core/ADC12.java =================================================================== --- mspsim/se/sics/mspsim/core/ADC12.java 2010-05-31 13:54:39 UTC (rev 703) +++ mspsim/se/sics/mspsim/core/ADC12.java 2010-06-01 22:21:43 UTC (rev 704) @@ -96,8 +96,15 @@ 256, 384, 512, 768, 1024, 1024, 1024, 1024 }; + public static final int BUSY_MASK = 0x01; public static final int EOS_MASK = 0x80; - + + public static final int CONSEQ_SINGLE = 0x00; + public static final int CONSEQ_SEQUENCE = 0x01; + public static final int CONSEQ_REPEAT_SINGLE = 0x02; + public static final int CONSEQ_REPEAT_SEQUENCE = 0x03; + public static final int CONSEQ_SEQUENCE_MASK = 0x01; + private final MSP430Core core; private int adc12ctl0 = 0; @@ -111,6 +118,7 @@ private boolean adc12On = false; private boolean enableConversion; private boolean startConversion; + private boolean isConverting; private int shSource = 0; private int startMem = 0; @@ -142,6 +150,7 @@ public void reset(int type) { enableConversion = false; startConversion = false; + isConverting = false; adc12ctl0 = 0; adc12ctl1 = 0; shTime0 = shTime1 = 4; @@ -181,21 +190,20 @@ if (DEBUG) System.out.println(getName() + ": Set SHTime0: " + shTime0 + " SHTime1: " + shTime1 + " ENC:" + enableConversion + " Start: " + startConversion + " ADC12ON: " + adc12On); - if (adc12On && enableConversion && startConversion) { - if (!adcTrigger.isScheduled()) { - // Set the start time to be now! - adc12Pos = startMem; - int delay = adcDiv * ((adc12Pos < 8 ? shTime0 : shTime1) + 13); - core.scheduleTimeEvent(adcTrigger, core.getTime() + delay); - } + if (adc12On && enableConversion && startConversion && !isConverting) { + // Set the start time to be now! + isConverting = true; + adc12Pos = startMem; + int delay = adcDiv * ((adc12Pos < 8 ? shTime0 : shTime1) + 13); + core.scheduleTimeEvent(adcTrigger, core.getTime() + delay); } break; case ADC12CTL1: if (enableConversion) { // Ongoing conversion: only some parts may be changed - adc12ctl1 = (adc12ctl1 & 0xfff8) + (value & 0x7); + adc12ctl1 = (adc12ctl1 & 0xfff8) + (value & 0x6); } else { - adc12ctl1 = value; + adc12ctl1 = value & 0xfffe; startMem = (value >> 12) & 0xf; shSource = (value >> 10) & 0x3; adcDiv = ((value >> 5) & 0x7) + 1; @@ -231,7 +239,7 @@ case ADC12CTL0: return adc12ctl0; case ADC12CTL1: - return adc12ctl1; + return isConverting ? (adc12ctl1 | BUSY_MASK) : adc12ctl1; case ADC12IE: return adc12ie; case ADC12IFG: @@ -261,8 +269,12 @@ int smp = 0; private void convert() { - // If either off or not enable conversion then just return... - if (!adc12On || !enableConversion) return; + // If off then just return... + if (!adc12On) { + isConverting = false; + return; + } + boolean runAgain = enableConversion && conSeq != CONSEQ_SINGLE; // Some noise... ADCInput input = adcInput[adc12mctl[adc12Pos] & 0xf]; adc12mem[adc12Pos] = input != null ? input.nextData() : 2048 + 100 - smp & 255; @@ -274,14 +286,24 @@ //System.out.println("** Trigger ADC12 IRQ for ADCMEM" + adc12Pos); core.flagInterrupt(adc12Vector, this, true); } - // Increase - if ((adc12mctl[adc12Pos] & EOS_MASK) == EOS_MASK) { - adc12Pos = startMem; + if ((conSeq & CONSEQ_SEQUENCE_MASK) != 0) { + // Increase + if ((adc12mctl[adc12Pos] & EOS_MASK) == EOS_MASK) { + adc12Pos = startMem; + if (conSeq == CONSEQ_SEQUENCE) { + // Single sequence only + runAgain = false; + } + } else { + adc12Pos = (adc12Pos + 1) & 0x0f; + } + } + if (!runAgain) { + isConverting = false; } else { - adc12Pos = (adc12Pos + 1) & 0x0f; + int delay = adcDiv * ((adc12Pos < 8 ? shTime0 : shTime1) + 13); + core.scheduleTimeEvent(adcTrigger, adcTrigger.time + delay); } - int delay = adcDiv * ((adc12Pos < 8 ? shTime0 : shTime1) + 13); - core.scheduleTimeEvent(adcTrigger, adcTrigger.time + delay); } public void interruptServiced(int vector) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |