Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
vdd3-sensor.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
3
* Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk
4
* All rights reserved.
5
*
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
8
* are met:
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
*
15
* 3. Neither the name of the copyright holder nor the names of its
16
* contributors may be used to endorse or promote products derived
17
* from this software without specific prior written permission.
18
*
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30
* OF THE POSSIBILITY OF SUCH DAMAGE.
31
*/
32
/*---------------------------------------------------------------------------*/
33
/**
34
* \addtogroup cc2538-vdd3-sensor
35
* @{
36
*
37
* \file
38
* Driver for the CC2538 VDD3 sensor
39
*/
40
/*---------------------------------------------------------------------------*/
41
#include "contiki.h"
42
#include "lib/sensors.h"
43
#include "
dev/vdd3-sensor.h
"
44
#include "
dev/adc.h
"
45
#include "
dev/cc2538-sensors.h
"
46
47
#include <stdint.h>
48
/*---------------------------------------------------------------------------*/
49
static
int
50
value
(
int
type)
51
{
52
int
raw =
adc_get
(
SOC_ADC_ADCCON_CH_VDD_3
,
SOC_ADC_ADCCON_REF_INT
,
53
SOC_ADC_ADCCON_DIV_512
);
54
55
if
(type ==
CC2538_SENSORS_VALUE_TYPE_RAW
) {
56
return
raw;
57
}
else
if
(type ==
CC2538_SENSORS_VALUE_TYPE_CONVERTED
) {
58
return
raw * (3 * 1190) / (2047 << 4);
59
}
60
61
return
CC2538_SENSORS_ERROR
;
62
}
63
/*---------------------------------------------------------------------------*/
64
static
int
65
configure(
int
type,
int
value
)
66
{
67
return
0;
68
}
69
/*---------------------------------------------------------------------------*/
70
static
int
71
status(
int
type)
72
{
73
return
1;
74
}
75
/*---------------------------------------------------------------------------*/
76
SENSORS_SENSOR(
vdd3_sensor
, VDD3_SENSOR,
value
, configure, status);
77
/*---------------------------------------------------------------------------*/
78
/** @} */
adc.h
Header file for the cc2538 ADC driver.
cc2538-sensors.h
Generic header usable by all CC2538 sensor drivers.
adc_get
int16_t adc_get(uint8_t channel, uint8_t ref, uint8_t div)
Performs a single conversion on a given ADC channel.
Definition
adc.c:57
CC2538_SENSORS_ERROR
#define CC2538_SENSORS_ERROR
Generic Error.
Definition
cc2538-sensors.h:64
CC2538_SENSORS_VALUE_TYPE_CONVERTED
#define CC2538_SENSORS_VALUE_TYPE_CONVERTED
Request the converted reading.
Definition
cc2538-sensors.h:62
CC2538_SENSORS_VALUE_TYPE_RAW
#define CC2538_SENSORS_VALUE_TYPE_RAW
Request the raw reading.
Definition
cc2538-sensors.h:61
SOC_ADC_ADCCON_CH_VDD_3
#define SOC_ADC_ADCCON_CH_VDD_3
VDD/3.
Definition
soc-adc.h:111
SOC_ADC_ADCCON_DIV_512
#define SOC_ADC_ADCCON_DIV_512
512 decimation rate (12 bits ENOB)
Definition
soc-adc.h:96
SOC_ADC_ADCCON_REF_INT
#define SOC_ADC_ADCCON_REF_INT
Internal reference.
Definition
soc-adc.h:89
value
static int value(int type)
Definition
cc2538-temp-sensor.c:49
vdd3_sensor
const struct sensors_sensor vdd3_sensor
Exports global symbols for the sensor API.
Definition
zoul-sensors.c:50
vdd3-sensor.h
Header file for the CC2538 VDD3 Sensor Driver.
arch
cpu
cc2538
dev
vdd3-sensor.c
Generated on
for Contiki-NG by
1.17.0