]> 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 157d65cfb10ea590b5c2fac2a1ce643623acdfc0..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,59 +96,32 @@ 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 uint16_t HplAdc12.getIFGs(){ return (uint16_t) ADC12IFG; } 
-
-  async command bool HplAdc12.isBusy(){ return ADC12CTL1 & ADC12BUSY; }
-  
-  async command void HplAdc12.enableConversion(){ ADC12CTL0 |= ENC;}
-  async command void HplAdc12.disableConversion(){ ADC12CTL0 &= ~ENC; }
-  async command void HplAdc12.startConversion(){ ADC12CTL0 |= ADC12SC + ENC; }
-  async command void HplAdc12.stopConversion(){ 
-    ADC12CTL1 &= ~(CONSEQ_1 | CONSEQ_3); 
-    ADC12CTL0 &= ~ENC; 
+  async command void HplAdc12.startConversion(){ 
+    ADC12CTL0 |= ADC12ON; 
+    ADC12CTL0 |= (ADC12SC + ENC); 
   }
   
-  async command void HplAdc12.setMSC(){ ADC12CTL0 |= MSC; }
-  async command void HplAdc12.resetMSC(){ ADC12CTL0 &= ~MSC; }
-  
-  async command void HplAdc12.setRefOn(){ ADC12CTL0 |= REFON;}
-  async command void HplAdc12.resetRefOn(){ ADC12CTL0 &= ~REFON;}
-  async command uint8_t HplAdc12.getRefon(){ return (ADC12CTL0 & REFON) >> 5;}
-  async command void HplAdc12.setRef1_5V(){ ADC12CTL0 &= ~REF2_5V;}
-  async command void HplAdc12.setRef2_5V(){ ADC12CTL0 |= REF2_5V;}
-  async command uint8_t HplAdc12.isRef2_5V(){ return (ADC12CTL0 & REF2_5V) >> 6;}
-  
-  async command void HplAdc12.setSHT(uint8_t sht){
-    uint16_t ctl0 = ADC12CTL0;
-    uint16_t shttemp = sht & 0x0F;    
-    ctl0 &= 0x00FF;
-    ctl0 |= (shttemp << 8);
-    ctl0 |= (shttemp << 12);
-    ADC12CTL0 = ctl0; 
+  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);
+    ADC12CTL1 |= (ctl1 & (CONSEQ0 | CONSEQ1));
   }
   
-  async command void HplAdc12.adcOff(){ ADC12CTL0 &= ~ADC12ON; }
-  async command void HplAdc12.adcOn(){ ADC12CTL0 |= ADC12ON; }
+  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);
   }
 }