0ad7884ff4c6db20b0d0be68eefafb98a57418b0
[bertos.git] / drv / ntc.h
1 /**
2  * \file
3  * <!--
4  * Copyright 2004, 2005 Develer S.r.l. (http://www.develer.com/)
5  * All Rights Reserved.
6  * -->
7  *
8  * \brief Driver for NTC (reads a temperature through an ADC)
9  *
10  * \version $Id$
11  *
12  * \author Giovanni Bajo <rasky@develer.com>
13  * \author Francesco Sacchi <batt@develer.com>
14  */
15
16 /*#*
17  *#* $Log$
18  *#* Revision 1.2  2006/07/19 12:56:26  bernie
19  *#* Convert to new Doxygen style.
20  *#*
21  *#* Revision 1.1  2005/11/04 17:59:47  bernie
22  *#* Import into DevLib.
23  *#*
24  *#* Revision 1.3  2005/06/10 08:56:47  batt
25  *#* Avoid calling DEG_T_TO_DEG().
26  *#*
27  *#* Revision 1.2  2005/06/10 08:54:58  batt
28  *#* Rename deg_t conversion macros to accomplish coding standard.
29  *#*
30  *#* Revision 1.1  2005/05/24 09:17:58  batt
31  *#* Move drivers to top-level.
32  *#*/
33
34 #ifndef DRV_NTC_H
35 #define DRV_NTC_H
36
37 #include <ntc_map.h>
38 #include <cfg/debug.h>
39 #include <cfg/compiler.h>
40
41 #define NTC_OPEN_CIRCUIT  -32768
42 #define NTC_SHORT_CIRCUIT 32767
43
44 typedef int16_t  deg_t; /** type for celsius degrees deg_t = °C * 10 */
45
46 /** Macro for converting from deg to deg_t type */
47 #define DEG_TO_DEG_T(x)         ((deg_t)((x) * 10))
48
49 /** Macro for converting from deg_t to celsius degrees (returns only the integer part) */
50 #define DEG_T_TO_INTDEG(x)      ((x) / 10)
51
52 /** Macro for converting from deg_t to celsius degrees (returns only the decimal part) */
53 #define DEG_T_TO_DECIMALDEG(x)  ((x) % 10)
54
55 /** Macro for converting from deg_t to celsius degrees (returns type is float) */
56 #define DEG_T_TO_FLOATDEG(x)    ((x) / 10.0)
57
58
59 typedef uint32_t res_t; /** type for resistor res_t = Ohm * 100 */
60 typedef float    amp_t; /** type for defining amplifications  amp_t = A, where A is a pure number */
61
62 DB(extern bool ntc_initialized;)
63
64
65 /** Describe a NTC chip */
66 typedef struct NtcHwInfo
67 {
68         const res_t *resistances; ///< resistances of the NTC (ohms * 100)
69         size_t num_resistances;   ///< number of resistances
70         deg_t degrees_min;        ///< degrees corresponding to the first entry in the table (celsius * 10)
71         deg_t degrees_step;       ///< difference in degrees between two consecutive elements in the table (celsius * 10)
72 } NtcHwInfo;
73
74 /** Initialize the NTC module */
75 void ntc_init(void);
76
77 /** Read a single temperature value from the NTC */
78 deg_t ntc_read(NtcDev dev);
79
80 #endif /* DRV_NTC_H */