]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - apps/tests/msp430/Adc12/TestAdcMultiC.nc
Merge TinyOS 2.1.1 into master.
[tinyos-2.x.git] / apps / tests / msp430 / Adc12 / TestAdcMultiC.nc
index 26737838a144d6bfc577ec7de7ef9be49147e668..6a2495031e016980f8eedd8c491f5b8d854b7efb 100644 (file)
@@ -50,7 +50,7 @@ generic module TestAdcMultiC(
 
                           uint8_t inch2,           // second input channel 
                           uint8_t sref2            // second reference voltage 
-)
+) @safe()
 {
   uses {
     interface Boot;
@@ -66,10 +66,12 @@ implementation
 {
   
 #define BUFFER_SIZE 100
+#define NUM_REPETITIONS 5
   const msp430adc12_channel_config_t config = {inch, sref, ref2_5v, adc12ssel, adc12div, sht, sampcon_ssel, sampcon_id};
   adc12memctl_t memCtl = {inch2, sref2};
-  uint8_t state;
+  norace uint8_t state;
   uint16_t buffer[BUFFER_SIZE];
+  norace uint8_t count = 0;
   void task getData();
 
   void task signalFailure()
@@ -85,6 +87,8 @@ implementation
   bool assertData(uint16_t *data, uint16_t num)
   {
     uint16_t i;
+    if (num != BUFFER_SIZE)
+      post signalFailure();
     for (i=0; i<num; i++)
       if (!data[i] || data[i] >= 0xFFF){
         post signalFailure();
@@ -100,7 +104,7 @@ implementation
 
   event void Boot.booted()
   {
-    state = 0;
+    count = NUM_REPETITIONS;
     post getData();
   }
 
@@ -117,9 +121,15 @@ implementation
 
   async event void MultiChannel.dataReady(uint16_t *buf, uint16_t numSamples)
   {
-    if (assertData(buf, numSamples))
+    if (!assertData(buf, numSamples)){
+      post signalFailure();
+    } else if (count){
+      count--;
+      call MultiChannel.getData();
+    } else {
       post signalSuccess();
-    call Resource.release();
+      call Resource.release();
+    }
   }
 
   command error_t Notify.enable(){}