]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Example application demonstrating the use of all commands/events in
authorjanhauer <janhauer>
Mon, 25 Jun 2007 15:43:37 +0000 (15:43 +0000)
committerjanhauer <janhauer>
Mon, 25 Jun 2007 15:43:37 +0000 (15:43 +0000)
Msp430Adc12SingleChannel and Msp430Adc12MultiChannel via different
ADC wrappers.

apps/tests/msp430/Adc12/EvaluatorC.nc [new file with mode: 0644]
apps/tests/msp430/Adc12/TestAdcAppC.nc
apps/tests/msp430/Adc12/TestAdcMultiC.nc [new file with mode: 0644]
apps/tests/msp430/Adc12/TestAdcSingleC.nc [new file with mode: 0644]
apps/tests/msp430/Adc12/evaluator.h [new file with mode: 0644]

diff --git a/apps/tests/msp430/Adc12/EvaluatorC.nc b/apps/tests/msp430/Adc12/EvaluatorC.nc
new file mode 100644 (file)
index 0000000..9217bde
--- /dev/null
@@ -0,0 +1,95 @@
+/* 
+ * Copyright (c) 2007, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ *   this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ *   of its contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+/**
+ * Checks whether all clients signalled Notify.notify(TRUE) and
+ * only then switches all three LEDs on. Displays on LEDs (binary)
+ * the ID of the first unsuccessful client otherwise.
+ *
+ * Author: Jan Hauer
+ **/
+#include "evaluator.h"
+module EvaluatorC
+{
+  uses {
+    interface Leds;
+    interface Notify<bool> as Notify[uint8_t client];
+  }
+}
+implementation
+{
+  enum {
+    NUM_CLIENTS = uniqueCount(EVALUATOR_CLIENT),
+  };
+  int numSuccess = 0;
+
+  void display(uint8_t client)
+  {
+    if (client & 0x1)
+      call Leds.led0On();
+    else 
+      call Leds.led0Off();
+    if (client & 0x2) 
+      call Leds.led1On();
+    else
+      call Leds.led1Off();
+    if (client & 0x4)
+      call Leds.led2On();
+    else
+      call Leds.led2Off();
+  }
+
+
+  event void Notify.notify[uint8_t client]( bool val )
+  {
+    if (val)
+      numSuccess++;
+    else {
+      if (client != 7) // would look like a success
+        display(client);
+      numSuccess = -1000;
+    }
+    if (NUM_CLIENTS == numSuccess){
+      call Leds.led0On();
+      call Leds.led1On();
+      call Leds.led2On();
+    }
+  }
+
+
+       
+
+}
+
index 73f0ef3494a0042eb88a4e23e159f2a2ec577e8f..30e176b32b2997e07f009a33d026620e84c3860e 100644 (file)
  */
 
 /**
- * Testing HAL of ADC12 on msp430. Switches three LEDs on, if successful.
+ * Testing HAL of ADC12 on msp430. Switches three LEDs on, if the test was
+ * successful.
  * 
  * Author: Jan Hauer
  */
 #include "Msp430Adc12.h"
+#include "evaluator.h"
 configuration TestAdcAppC {
 }
 implementation
 {
-  components MainC,
-             new TestAdcC(REFVOLT_LEVEL_1_5) as TestAdcC1,
-             new Msp430Adc12ClientAutoRVGC() as Wrapper1,
-             LedsC;
-
-  TestAdcC1 -> MainC.Boot;
-  TestAdcC1.Leds -> LedsC;
-  TestAdcC1.Resource -> Wrapper1;
-  TestAdcC1.SingleChannel -> Wrapper1.Msp430Adc12SingleChannel;
-  Wrapper1.AdcConfigure -> TestAdcC1;
-
-  components new TestAdcC(REFVOLT_LEVEL_2_5) as TestAdcC2,
-             new Msp430Adc12ClientAutoRVGC() as Wrapper2;
-
-  TestAdcC2 -> MainC.Boot;
-  TestAdcC2.Leds -> LedsC;
-  TestAdcC2.Resource -> Wrapper2;
-  TestAdcC2.SingleChannel -> Wrapper2.Msp430Adc12SingleChannel;
-  Wrapper2.AdcConfigure -> TestAdcC2;
+  // msp430 internal temperature sensor with ref volt from generator
+#define CONFIG_VREF TEMPERATURE_DIODE_CHANNEL, REFERENCE_VREFplus_AVss, REFVOLT_LEVEL_2_5, SHT_SOURCE_ACLK, SHT_CLOCK_DIV_1, SAMPLE_HOLD_4_CYCLES, SAMPCON_SOURCE_SMCLK, SAMPCON_CLOCK_DIV_1
+
+  // msp430 internal temperature sensor with ref volt from AVcc
+#define CONFIG_AVCC TEMPERATURE_DIODE_CHANNEL, REFERENCE_AVcc_AVss, REFVOLT_LEVEL_NONE, SHT_SOURCE_SMCLK, SHT_CLOCK_DIV_1, SAMPLE_HOLD_4_CYCLES, SAMPCON_SOURCE_SMCLK, SAMPCON_CLOCK_DIV_1
+                        
+  components MainC, LedsC, EvaluatorC;
+  EvaluatorC.Leds -> LedsC;
+
+  // Single, none
+  components new TestAdcSingleC(CONFIG_AVCC) as TestSingle0,
+             new Msp430Adc12ClientC() as Wrapper0;
+
+  TestSingle0 -> MainC.Boot;
+  TestSingle0.Resource -> Wrapper0;
+  TestSingle0.SingleChannel -> Wrapper0.Msp430Adc12SingleChannel;
+  EvaluatorC.Notify[unique(EVALUATOR_CLIENT)] -> TestSingle0;
+
+  // Single, RefVolt
+  components new TestAdcSingleC(CONFIG_VREF) as TestSingle1,
+             new Msp430Adc12ClientAutoRVGC() as Wrapper1;
+
+  TestSingle1 -> MainC.Boot;
+  TestSingle1.Resource -> Wrapper1;
+  TestSingle1.SingleChannel -> Wrapper1.Msp430Adc12SingleChannel;
+  EvaluatorC.Notify[unique(EVALUATOR_CLIENT)] -> TestSingle1;
+  Wrapper1.AdcConfigure -> TestSingle1;
+
+  // Single, DMA
+  components new TestAdcSingleC(CONFIG_AVCC) as TestSingle2,
+             new Msp430Adc12ClientAutoDMAC() as Wrapper2;
+
+  TestSingle2 -> MainC.Boot;
+  TestSingle2.Resource -> Wrapper2;
+  TestSingle2.SingleChannel -> Wrapper2.Msp430Adc12SingleChannel;
+  EvaluatorC.Notify[unique(EVALUATOR_CLIENT)] -> TestSingle2;
+
+  // Single, RefVolt + DMA
+  components new TestAdcSingleC(CONFIG_VREF) as TestSingle3,
+             new Msp430Adc12ClientAutoDMA_RVGC() as Wrapper3;
+
+  TestSingle3 -> MainC.Boot;
+  TestSingle3.Resource -> Wrapper3;
+  TestSingle3.SingleChannel -> Wrapper3.Msp430Adc12SingleChannel;
+  EvaluatorC.Notify[unique(EVALUATOR_CLIENT)] -> TestSingle3;
+  Wrapper3.AdcConfigure -> TestSingle3;
+
+  // Multi, none
+  components new TestAdcMultiC(CONFIG_AVCC,
+                     SUPPLY_VOLTAGE_HALF_CHANNEL, REFERENCE_AVcc_AVss) as TestMulti1,
+             new Msp430Adc12ClientC() as Wrapper4;
+
+  TestMulti1 -> MainC.Boot;
+  TestMulti1.Resource -> Wrapper4;
+  TestMulti1.MultiChannel -> Wrapper4.Msp430Adc12MultiChannel;
+  EvaluatorC.Notify[unique(EVALUATOR_CLIENT)] -> TestMulti1;
+
+  // Multi, RefVolt
+  components new TestAdcMultiC(CONFIG_VREF,
+                      SUPPLY_VOLTAGE_HALF_CHANNEL, REFERENCE_VREFplus_AVss) as TestMulti2,
+             new Msp430Adc12ClientAutoRVGC() as Wrapper5;
+
+  TestMulti2 -> MainC.Boot;
+  TestMulti2.Resource -> Wrapper5;
+  TestMulti2.MultiChannel -> Wrapper5.Msp430Adc12MultiChannel;
+  EvaluatorC.Notify[unique(EVALUATOR_CLIENT)] -> TestMulti2;
+  Wrapper5.AdcConfigure -> TestMulti2;
+
 }
 
diff --git a/apps/tests/msp430/Adc12/TestAdcMultiC.nc b/apps/tests/msp430/Adc12/TestAdcMultiC.nc
new file mode 100644 (file)
index 0000000..2673783
--- /dev/null
@@ -0,0 +1,128 @@
+/* 
+ * Copyright (c) 2007, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ *   this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ *   of its contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+/**
+ * Testing MultiChannel HAL interface of ADC12 on msp430. 
+ *
+ * Author: Jan Hauer
+ **/
+generic module TestAdcMultiC(  
+                          uint8_t inch,            // first input channel 
+                          uint8_t sref,            // reference voltage 
+                          uint8_t ref2_5v,         // reference voltage level 
+                          uint8_t adc12ssel,       // clock source sample-hold-time 
+                          uint8_t adc12div,        // clock divider sample-hold-time 
+                          uint8_t sht,             // sample-hold-time
+                          uint8_t sampcon_ssel,    // clock source sampcon signal 
+                          uint8_t sampcon_id,      // clock divider sampcon 
+
+                          uint8_t inch2,           // second input channel 
+                          uint8_t sref2            // second reference voltage 
+)
+{
+  uses {
+    interface Boot;
+    interface Resource;
+    interface Msp430Adc12MultiChannel as MultiChannel;
+  }
+  provides {
+    interface Notify<bool>;
+    interface AdcConfigure<const msp430adc12_channel_config_t*>;
+  }
+}
+implementation
+{
+  
+#define BUFFER_SIZE 100
+  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;
+  uint16_t buffer[BUFFER_SIZE];
+  void task getData();
+
+  void task signalFailure()
+  {
+    signal Notify.notify(FALSE);
+  }
+
+  void task signalSuccess()
+  {
+    signal Notify.notify(TRUE);
+  }
+
+  bool assertData(uint16_t *data, uint16_t num)
+  {
+    uint16_t i;
+    for (i=0; i<num; i++)
+      if (!data[i] || data[i] >= 0xFFF){
+        post signalFailure();
+        return FALSE;
+      }
+    return TRUE;
+  }
+
+  async command const msp430adc12_channel_config_t* AdcConfigure.getConfiguration()
+  {
+    return &config;
+  }
+
+  event void Boot.booted()
+  {
+    state = 0;
+    post getData();
+  }
+
+  void task getData()
+  {
+    call Resource.request();
+  }
+  
+  event void Resource.granted()
+  {
+    if (call MultiChannel.configure(&config, &memCtl, 1, buffer, BUFFER_SIZE, 0) == SUCCESS)
+      call MultiChannel.getData();
+  }
+
+  async event void MultiChannel.dataReady(uint16_t *buf, uint16_t numSamples)
+  {
+    if (assertData(buf, numSamples))
+      post signalSuccess();
+    call Resource.release();
+  }
+
+  command error_t Notify.enable(){}
+  command error_t Notify.disable(){}
+}
+
diff --git a/apps/tests/msp430/Adc12/TestAdcSingleC.nc b/apps/tests/msp430/Adc12/TestAdcSingleC.nc
new file mode 100644 (file)
index 0000000..e1fe427
--- /dev/null
@@ -0,0 +1,145 @@
+/* 
+ * Copyright (c) 2007, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ *   this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ *   of its contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+/**
+ * Testing SingleChannel HAL interface of ADC12 on msp430. 
+ *
+ * Author: Jan Hauer
+ **/
+generic module TestAdcSingleC(  
+                          uint8_t inch,            // input channel 
+                          uint8_t sref,            // reference voltage 
+                          uint8_t ref2_5v,         // reference voltage level 
+                          uint8_t adc12ssel,       // clock source sample-hold-time 
+                          uint8_t adc12div,        // clock divider sample-hold-time 
+                          uint8_t sht,             // sample-hold-time
+                          uint8_t sampcon_ssel,    // clock source sampcon signal 
+                          uint8_t sampcon_id       // clock divider sampcon 
+)
+{
+  uses {
+    interface Boot;
+    interface Resource;
+    interface Msp430Adc12SingleChannel as SingleChannel;
+  }
+  provides {
+    interface AdcConfigure<const msp430adc12_channel_config_t*>;
+    interface Notify<bool>;
+  }
+}
+implementation
+{
+#define BUFFER_SIZE 100
+  const msp430adc12_channel_config_t config = {inch, sref, ref2_5v, adc12ssel, adc12div, sht, sampcon_ssel, sampcon_id};
+  uint8_t state;
+  uint16_t buffer[BUFFER_SIZE];
+  void task getData();
+
+  void task signalFailure()
+  {
+    signal Notify.notify(FALSE);
+  }
+
+  void assertData(uint16_t *data, uint16_t num)
+  {
+    uint16_t i;
+    for (i=0; i<num; i++)
+      if (!data[i] || data[i] >= 0xFFF)
+        post signalFailure();
+  }
+
+  event void Boot.booted()
+  {
+    state = 0;
+    post getData();
+  }
+
+  async command const msp430adc12_channel_config_t* AdcConfigure.getConfiguration()
+  {
+    return &config;
+  }
+
+  void task getData()
+  {
+    call Resource.request();
+  }
+  
+  event void Resource.granted()
+  {
+    switch(state)
+    {
+      case 0: state++;
+              if (call SingleChannel.configureSingleRepeat(&config, 0) == SUCCESS)
+                call SingleChannel.getData();
+              break;
+      case 1: state++;
+              if (call SingleChannel.configureSingle(&config) == SUCCESS)
+                call SingleChannel.getData();
+              break;
+      case 2: state++;
+              if (call SingleChannel.configureMultiple(&config, buffer, BUFFER_SIZE, 0) == SUCCESS)
+                call SingleChannel.getData();
+              break;
+      case 3: state++;
+              if (call SingleChannel.configureMultipleRepeat(&config, buffer, 16, 0) == SUCCESS)
+                call SingleChannel.getData();
+              break;
+      default: call Resource.release();
+              signal Notify.notify(TRUE);
+              break;
+    }
+  }
+
+  async event error_t SingleChannel.singleDataReady(uint16_t data)
+  { 
+    assertData(&data, 1);
+    call Resource.release();
+    post getData();
+    return FAIL;
+  }
+  
+    
+  async event uint16_t* SingleChannel.multipleDataReady(uint16_t *buf, uint16_t length)
+  {
+    assertData(buf, length);
+    call Resource.release();
+    post getData();
+    return 0;
+  }
+
+  command error_t Notify.enable(){}
+  command error_t Notify.disable(){}
+}
+
diff --git a/apps/tests/msp430/Adc12/evaluator.h b/apps/tests/msp430/Adc12/evaluator.h
new file mode 100644 (file)
index 0000000..0c008a8
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef EVALUATOR_H
+#define EVALUATOR_H
+
+#define EVALUATOR_CLIENT "ADC12.Evalutator.ID"
+
+#endif