]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Changes to MultiSampleC
authorsmckown <smckown@4bc1554a-c7f2-4f65-a403-e0be01f0239c>
Mon, 9 Nov 2009 19:30:53 +0000 (19:30 +0000)
committerR. Steve McKown <rsmckown@gmail.com>
Tue, 1 Dec 2009 03:01:50 +0000 (20:01 -0700)
* Returns the array of samples rather than their sum.
* Hard coded to work with uint16_t samples.

tos/platforms/tmirws/sensors/MultiSampleC.nc
tos/platforms/tmirws/sensors/MultiSampleP.nc

index 50069c86b03e7e537968989defa04a25ea2c87e1..ac9c3c4c48bf531851228a8be3a9f99ba57e9b5f 100644 (file)
  */
  
 /**
- * A generic component that multiply samples via the ADC, returning the sum of
- * ADC sample values.
+ * A generic component that multiply samples via the ADC, returning an array
+ * of ADC results.
  * 
  * @author R. Steve McKown <smckown@gmail.com>
  */
  
 #include <Msp430Adc12.h>
 
-generic configuration MultiSampleC(typedef val_t @integer(), uint16_t count) {
+generic configuration MultiSampleC(uint16_t count) {
   provides {
     interface Get<uint16_t> as Count;
-    interface Read<val_t>;
+    interface ReadRef<uint16_t>;
   }
   uses interface AdcConfigure<const msp430adc12_channel_config_t*>;
 }
 implementation {
-  components new MultiSampleP(val_t, count);
+  components new MultiSampleP(count);
   Count = MultiSampleP;
-  Read = MultiSampleP;
+  ReadRef = MultiSampleP;
 
   components new AdcReadStreamClientC();
   AdcConfigure = AdcReadStreamClientC;
index 031f4ba2e8583148e6b2a0465e3fbe1ea9e33509..79714ad822e98ab1694418589a03046a7579d4fc 100644 (file)
  */
  
 /**
- * A generic component that multiply samples via the ADC, returning the sum of
- * ADC sample values.
+ * A generic component that multiply samples via the ADC, returning an array
+ * of ADC results.
  * 
  * @author R. Steve McKown <smckown@gmail.com>
  */
  
-generic module MultiSampleP(typedef val_t @integer(), uint16_t count) @safe()
+generic module MultiSampleP(uint16_t count) @safe()
 {
   provides {
     interface Get<uint16_t> as Count;
-    interface Read<val_t>;
+    interface ReadRef<uint16_t>;
   }
   uses interface ReadStream<uint16_t>;
 }
 implementation
 {
-  bool busy;
-  uint16_t values[count];
+  uint16_t* m_array;
 
   command uint16_t Count.get()
   {
     return count;
   }
 
-  command error_t Read.read()
+  command error_t ReadRef.read(uint16_t* array)
   {
-    if (busy)
+    if (m_array)
       return EBUSY;
 
-    if (call ReadStream.postBuffer(values, count) != SUCCESS ||
-       call ReadStream.read(0) != SUCCESS)
+    m_array = array;
+    if (call ReadStream.postBuffer(m_array, count) != SUCCESS ||
+       call ReadStream.read(0) != SUCCESS) {
+      m_array = NULL;
       return FAIL;
-
-    busy = TRUE;
+    }
     return SUCCESS;
   }
 
   void signalReadDone(error_t error)
   {
-    val_t sum = 0;
+    uint16_t* tmp = m_array;
 
-    if (error == SUCCESS) {
-      uint16_t i;
-
-      /* Average all the incoming readings */
-      for (i = 0; i < count; i++)
-         sum += values[i];
-    }
-    busy = FALSE;
-    signal Read.readDone(error, sum);
+    m_array = NULL;
+    signal ReadRef.readDone(error, tmp);
   }
 
   event void ReadStream.bufferDone(error_t error, uint16_t* buf,