bf221369a1a116c9f1e14f67c5add7a55df7a3f5
[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.1  2005/11/04 17:59:47  bernie
19  *#* Import into DevLib.
20  *#*
21  *#* Revision 1.3  2005/06/10 08:56:47  batt
22  *#* Avoid calling DEG_T_TO_DEG().
23  *#*
24  *#* Revision 1.2  2005/06/10 08:54:58  batt
25  *#* Rename deg_t conversion macros to accomplish coding standard.
26  *#*
27  *#* Revision 1.1  2005/05/24 09:17:58  batt
28  *#* Move drivers to top-level.
29  *#*/
30
31 #ifndef DRV_NTC_H
32 #define DRV_NTC_H
33
34 #include <ntc_map.h>
35 #include <cfg/debug.h>
36 #include <cfg/compiler.h>
37
38 #define NTC_OPEN_CIRCUIT  -32768
39 #define NTC_SHORT_CIRCUIT 32767
40
41 typedef int16_t  deg_t; /*! type for celsius degrees deg_t = °C * 10 */
42
43 /*! Macro for converting from deg to deg_t type */
44 #define DEG_TO_DEG_T(x)         ((deg_t)((x) * 10))
45
46 /*! Macro for converting from deg_t to celsius degrees (returns only the integer part) */
47 #define DEG_T_TO_INTDEG(x)      ((x) / 10)
48
49 /*! Macro for converting from deg_t to celsius degrees (returns only the decimal part) */
50 #define DEG_T_TO_DECIMALDEG(x)  ((x) % 10)
51
52 /*! Macro for converting from deg_t to celsius degrees (returns type is float) */
53 #define DEG_T_TO_FLOATDEG(x)    ((x) / 10.0)
54
55
56 typedef uint32_t res_t; /*! type for resistor res_t = Ohm * 100 */
57 typedef float    amp_t; /*! type for defining amplifications  amp_t = A, where A is a pure number */
58
59 DB(extern bool ntc_initialized;)
60
61
62 /*! Describe a NTC chip */
63 typedef struct NtcHwInfo
64 {
65         const res_t *resistances; //!< resistances of the NTC (ohms * 100)
66         size_t num_resistances;   //!< number of resistances
67         deg_t degrees_min;        //!< degrees corresponding to the first entry in the table (celsius * 10)
68         deg_t degrees_step;       //!< difference in degrees between two consecutive elements in the table (celsius * 10)
69 } NtcHwInfo;
70
71 /*! Initialize the NTC module */
72 void ntc_init(void);
73
74 /*! Read a single temperature value from the NTC */
75 deg_t ntc_read(NtcDev dev);
76
77 #endif /* DRV_NTC_H */