Contiki 3.x
ext-sensor.c
1 /*
2  * Copyright (c) 2006, Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * -----------------------------------------------------------------
30  *
31  * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne, Marcus Lundén,
32  * Jesper Karlsson
33  * Created : 2005-11-01
34  */
35 
36 #include "contiki.h"
37 #include "dev/ext-sensor.h"
38 #include "dev/sky-sensors.h"
39 
40 const struct sensors_sensor ext_sensor;
41 static uint8_t active;
42 /*---------------------------------------------------------------------------*/
43 static int
44 value(int type)
45 {
46  #if 0
47  /* ADC0 corresponds to the port under the logo,
48  * ADC1 to the port over the logo,
49  * ADC2 and ADC3 corresponds to port on the JCreate bottom expansion port) */
50  switch(type) {
51  case ADC0:
52  return ADC12MEM6;
53  case ADC1:
54  return ADC12MEM7;
55  case ADC2:
56  return ADC12MEM8;
57  case ADC3:
58  return ADC12MEM9;
59  }
60  #endif /* 0 */
61  return 0;
62 }
63 /*---------------------------------------------------------------------------*/
64 static int
65 status(int type)
66 {
67  switch(type) {
68  case SENSORS_ACTIVE:
69  case SENSORS_READY:
70  return active;
71  default:
72  return 0;
73  }
74 }
75 /*---------------------------------------------------------------------------*/
76 static int
77 configure(int type, int c)
78 {
79  switch(type) {
80  case SENSORS_ACTIVE:
81  if(c) {
82  if(!status(SENSORS_ACTIVE)) {
83  #if 0
84  /* SREF_1 is Vref+ */
85  /* MemReg6 == P6.0/A0 == port "under" logo */
86  ADC12MCTL6 = (INCH_0 + SREF_0);
87  /* MemReg7 == P6.1/A1 == port "over" logo */
88  ADC12MCTL7 = (INCH_1 + SREF_0);
89  /* MemReg8 == P6.2/A2, bottom expansion port */
90  ADC12MCTL8 = (INCH_2 + SREF_0);
91  /* MemReg9 == P6.1/A3, bottom expansion port, End Of (ADC-)Sequence */
92  ADC12MCTL9 = (INCH_3 + SREF_0);
93  #endif /* 0 */
94  sky_sensors_activate(0x0F);
95  active = 1;
96  }
97  } else {
98  sky_sensors_deactivate(0x0F);
99  active = 0;
100  }
101  return 1;
102  default:
103  return 0;
104  }
105 }
106 /*---------------------------------------------------------------------------*/
107 SENSORS_SENSOR(ext_sensor, "Ext", value, configure, status);
#define ADC0
Peripheral ADC0 base pointer.
Definition: MKL25Z4.h:541