Contiki 3.x
Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
platform
wismote
dev
acc-sensor.c
1
/*
2
* Copyright (c) 2010, 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
32
* Created : 2005-11-01
33
*/
34
35
#include "dev/acc-sensor.h"
36
37
const
struct
sensors_sensor acc_sensor;
38
static
uint8_t active;
39
40
/*---------------------------------------------------------------------------*/
41
static
void
42
activate(
void
)
43
{
44
/* This assumes that some other sensor system already did setup the ADC
45
/* (in the case of the sky platform it is sensors_light_init that does it)
46
47
P6SEL |= 0x70;
48
P6DIR = 0x00;
49
P6OUT = 0x00;
50
51
P2DIR |= 0x48;
52
P2OUT |= 0x48;
53
54
55
/* stop converting immediately
56
ADC12CTL0 &= ~ENC;
57
ADC12CTL1 &= ~CONSEQ_3;
58
59
/* Configure ADC12_2 to sample channel 11 (voltage) and use
60
/* the Vref+ as reference (SREF_1) since it is a stable reference
61
ADC12MCTL2 = (INCH_4 + SREF_1);
62
ADC12MCTL3 = (INCH_5 + SREF_1);
63
ADC12MCTL4 = (INCH_6 + SREF_1);
64
/* internal temperature can be read as value(3)
65
ADC12MCTL5 = (INCH_10 + SREF_1);
66
67
ADC12CTL1 |= CONSEQ_3;
68
ADC12CTL0 |= ENC | ADC12SC;
69
70
/* Irq_adc12_activate(&acc_sensor, 6, (INCH_11 + SREF_1)); */
71
active = 1;
72
}
73
/*---------------------------------------------------------------------------*/
74
static
void
75
deactivate(
void
)
76
{
77
/* irq_adc12_deactivate(&acc_sensor, 6);
78
acc_value = 0;*/
79
active = 0;
80
}
81
/*---------------------------------------------------------------------------*/
82
static
int
83
value(
int
type)
84
{
85
/*
86
switch(type) {
87
case 0:
88
return ADC12MEM2;
89
case 1:
90
return ADC12MEM3;
91
case 2:
92
return ADC12MEM4;
93
case 3:
94
return ADC12MEM5;
95
}*/
96
return
0;
97
}
98
/*---------------------------------------------------------------------------*/
99
static
int
100
configure(
int
type,
int
value)
101
{
102
if
(type == SENSORS_ACTIVE) {
103
if
(value) {
104
activate();
105
}
else
{
106
deactivate();
107
}
108
return
1;
109
}
110
return
0;
111
}
112
/*---------------------------------------------------------------------------*/
113
static
int
114
status(
int
type)
115
{
116
switch
(type) {
117
case
SENSORS_ACTIVE:
118
case
SENSORS_READY:
119
return
active;
120
default
:
121
return
0;
122
}
123
}
124
/*---------------------------------------------------------------------------*/
125
SENSORS_SENSOR(acc_sensor, ACC_SENSOR,
126
value, configure, status);
Generated on Sun Nov 30 2014 09:59:00 for Contiki 3.x by
1.8.5