]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/msp430/adc12/HplAdc12P.nc
The bugfix of Apr 18 introduced a new problem that is now fixed.
[tinyos-2.x.git] / tos / chips / msp430 / adc12 / HplAdc12P.nc
index 7240e7668edc1a011c6ad9d85ca09632294677aa..54c9c3464511c7b7d7668c88bd2ed470cf08051b 100644 (file)
@@ -53,21 +53,25 @@ implementation
   MSP430REG_NORACE(ADC12IFG);
   MSP430REG_NORACE(ADC12IE);
   MSP430REG_NORACE(ADC12IV);
+
+  // SFRs are accessed directly or cast to a pointer, both works fine
+  // (we don't access all SFRs directly, because that would result in
+  // much higher memory footprint)
   
   async command void HplAdc12.setCtl0(adc12ctl0_t control0){
-    ADC12CTL0 = *(uint16_t*)&control0
+    ADC12CTL0 = *((uint16_t*) &control0)
   }
   
   async command void HplAdc12.setCtl1(adc12ctl1_t control1){
-    ADC12CTL1 = *(uint16_t*)&control1
+    ADC12CTL1 = *((uint16_t*) &control1)
   }
   
   async command adc12ctl0_t HplAdc12.getCtl0(){ 
-    return *(adc12ctl0_t*) &ADC12CTL0
+    return *((adc12ctl0_t*) &ADC12CTL0)
   }
   
   async command adc12ctl1_t HplAdc12.getCtl1(){
-    return *(adc12ctl1_t*) &ADC12CTL1
+    return *((adc12ctl1_t*) &ADC12CTL1)
   }
   
   async command void HplAdc12.setMCtl(uint8_t i, adc12memctl_t memControl){
@@ -92,15 +96,8 @@ implementation
   async command uint16_t HplAdc12.getIEFlags(){ return (uint16_t) ADC12IE; } 
   
   async command void HplAdc12.resetIFGs(){ 
-    if (!ADC12IFG)
-      return;
-    else {
-      // workaround, because ADC12IFG is not writable 
-      uint8_t i;
-      volatile uint16_t tmp;
-      for (i=0; i<16; i++)
-        tmp = call HplAdc12.getMem(i);
-    }
+    ADC12IV = 0; 
+    ADC12IFG = 0;
   } 
   
   async command void HplAdc12.startConversion(){ 
@@ -108,21 +105,23 @@ implementation
     ADC12CTL0 |= (ADC12SC + ENC); 
   }
   
-  async command void HplAdc12.stopConversion(){ 
+  async command void HplAdc12.stopConversion(){
+    // stop conversion mode immediately, conversion data is unreliable
+    uint16_t ctl1 = ADC12CTL1;
+    ADC12CTL1 &= ~(CONSEQ0 | CONSEQ1);
     ADC12CTL0 &= ~(ADC12SC + ENC); 
-    ADC12CTL0 &= ~(ADC12ON); 
+    ADC12CTL0 &= ~(ADC12ON);
+    ADC12CTL1 |= (ctl1 & (CONSEQ0 | CONSEQ1));
   }
   
+  async command void HplAdc12.enableConversion(){ 
+    ADC12CTL0 |= ENC; 
+  }
+    
   async command bool HplAdc12.isBusy(){ return ADC12CTL1 & ADC12BUSY; }
 
   TOSH_SIGNAL(ADC_VECTOR) {
-    uint16_t iv = ADC12IV;
-    switch(iv)
-    {
-      case  2: signal HplAdc12.memOverflow(); return;
-      case  4: signal HplAdc12.conversionTimeOverflow(); return;
-    }
-    signal HplAdc12.conversionDone(iv);
+    signal HplAdc12.conversionDone(ADC12IV);
   }
 }