04ab4d2020a22b69de89973e065152ac51888154
[bertos.git] / bertos / drv / ntc.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2004, 2005 Develer S.r.l. (http://www.develer.com/)
30  * All Rights Reserved.
31  * -->
32  *
33  * \brief Driver for NTC sensors (reads a temperature through an ADC)
34  *
35  * \version $Id$
36  *
37  * \author Giovanni Bajo <rasky@develer.com>
38  * \author Francesco Sacchi <batt@develer.com>
39  *
40  * $WIZ$ module_name = "ntc"
41  * $WIZ$ module_depends = "adc"
42  * $WIZ$ module_hw = "bertos/hw/hw_ntc.h", "bertos/hw/ntc_map.h"
43  */
44
45 #ifndef DRV_NTC_H
46 #define DRV_NTC_H
47
48 #include "hw/ntc_map.h"
49
50 #include <cfg/compiler.h>
51
52 #define NTC_OPEN_CIRCUIT  -32768
53 #define NTC_SHORT_CIRCUIT 32767
54
55 typedef int16_t  deg_t; /** type for celsius degrees deg_t = °C * 10 */
56
57 /** Macro for converting from deg to deg_t type */
58 #define DEG_TO_DEG_T(x)         ((deg_t)((x) * 10))
59
60 /** Macro for converting from deg_t to celsius degrees (returns only the integer part) */
61 #define DEG_T_TO_INTDEG(x)      ((x) / 10)
62
63 /** Macro for converting from deg_t to celsius degrees (returns only the decimal part) */
64 #define DEG_T_TO_DECIMALDEG(x)  ((x) % 10)
65
66 /** Macro for converting from deg_t to celsius degrees (returns type is float) */
67 #define DEG_T_TO_FLOATDEG(x)    ((x) / 10.0)
68
69
70 typedef uint32_t res_t; /** type for resistor res_t = Ohm * 100 */
71 typedef float    amp_t; /** type for defining amplifications  amp_t = A, where A is a pure number */
72
73 DB(extern bool ntc_initialized;)
74
75
76 /** Describe a NTC chip */
77 typedef struct NtcHwInfo
78 {
79         const res_t *resistances; ///< resistances of the NTC (ohms * 100)
80         size_t num_resistances;   ///< number of resistances
81         deg_t degrees_min;        ///< degrees corresponding to the first entry in the table (celsius * 10)
82         deg_t degrees_step;       ///< difference in degrees between two consecutive elements in the table (celsius * 10)
83 } NtcHwInfo;
84
85 /** Initialize the NTC module */
86 void ntc_init(void);
87
88 /** Read a single temperature value from the NTC */
89 deg_t ntc_read(NtcDev dev);
90
91 #endif /* DRV_NTC_H */