Contiki-NG
Loading...
Searching...
No Matches
temp-arch.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 Yago Fontoura do Rosario <yago.rosario@hotmail.com.br>
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 copyright holder nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30/*---------------------------------------------------------------------------*/
31/**
32 * \addtogroup nrf
33 * @{
34 *
35 * \addtogroup nrf-os OS drivers
36 * @{
37 *
38 * \addtogroup nrf-temp Temperature driver
39 * @{
40 *
41 * \file
42 * Temperatue implementation for the nRF.
43 * \author
44 * Yago Fontoura do Rosario <yago.rosario@hotmail.com.br>
45 *
46 */
47/*---------------------------------------------------------------------------*/
48#include "contiki.h"
49
50#include "nrfx.h"
51
52#include "lib/sensors.h"
53/*---------------------------------------------------------------------------*/
54#define TEMPERATURE_SENSOR "Temperature"
55/*---------------------------------------------------------------------------*/
56#ifdef NRF_TEMP
57/*---------------------------------------------------------------------------*/
58#include "hal/nrf_temp.h"
59/*---------------------------------------------------------------------------*/
60#define TEMP_ARCH_WAIT_US 4
61#define TEMP_ARCH_TRIES 10
62/*---------------------------------------------------------------------------*/
63/**
64 * @brief Returns device temperature
65 * @param type ignored
66 * @return Device temperature in degrees Celsius
67 */
68static int
69value(int type)
70{
72
73 (void) type;
74
77
79 do {
81 break;
82 }
83 NRFX_DELAY_US(TEMP_ARCH_WAIT_US);
84 } while(--tries);
85
88
90}
91/*---------------------------------------------------------------------------*/
92/**
93 * @brief Configures temperature sensor
94 * @param type ignored
95 * @param c ignored
96 * @return 1
97 */
98static int
99configure(int type, int c)
100{
101 (void) type;
102 (void) c;
103
104 return 1;
105}
106/**
107 * \brief Return temperature sensor status
108 * \param type ignored
109 * \return 1
110 */
111/*---------------------------------------------------------------------------*/
112static int
113status(int type)
114{
115 (void) type;
116
117 return 1;
118}
119/*---------------------------------------------------------------------------*/
120#else /* NRF_TEMP */
121/**
122 * \brief Returns device temperature
123 * \param type ignored
124 * \return Device temperature in degrees Celsius
125 */
126static int
127value(int type)
128{
129 (void) type;
130
131 return 0;
132}
133/*---------------------------------------------------------------------------*/
134/**
135 * \brief Configures temperature sensor
136 * \param type ignored
137 * \param c ignored
138 * \return 1
139 */
140static int
141configure(int type, int c)
142{
143 (void) type;
144 (void) c;
145
146 return 0;
147}
148/**
149 * \brief Return temperature sensor status
150 * \param type ignored
151 * \return 1
152 */
153/*---------------------------------------------------------------------------*/
154static int
155status(int type)
156{
157 (void) type;
158
159 return 0;
160}
161/*---------------------------------------------------------------------------*/
162#endif /* NRF_TEMP */
163/*---------------------------------------------------------------------------*/
164SENSORS_SENSOR(temperature_sensor, TEMPERATURE_SENSOR, value, configure, status);
165/*---------------------------------------------------------------------------*/
166/**
167 * @}
168 * @}
169 * @}
170 */
static int configure(int type, int c)
Configures temperature sensor.
Definition temp-arch.c:141
static int value(int type)
Returns device temperature.
Definition temp-arch.c:127
static int status(int type)
Return temperature sensor status.
Definition temp-arch.c:155