4 * This file is part of BeRTOS.
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.
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.
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
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.
29 * Copyright 2004, 2005 Develer S.r.l. (http://www.develer.com/)
30 * All Rights Reserved.
33 * \brief Driver for NTC sensors (reads a temperature through an ADC).
36 * \author Giovanni Bajo <rasky@develer.com>
37 * \author Francesco Sacchi <batt@develer.com>
39 * $WIZ$ module_name = "ntc"
40 * $WIZ$ module_hw = "bertos/hw/hw_ntc.h", "bertos/hw/ntc_map.h", "bertos/hw/hw_ntc.c"
46 #include "hw/ntc_map.h"
48 #include <cfg/compiler.h>
49 #include <cfg/debug.h>
51 #define NTC_OPEN_CIRCUIT -32768
52 #define NTC_SHORT_CIRCUIT 32767
54 typedef int16_t deg_t; /** type for celsius degrees deg_t = °C * 10 */
56 /** Macro for converting from deg to deg_t type */
57 #define DEG_TO_DEG_T(x) ((deg_t)((x) * 10))
59 /** Macro for converting from deg_t to celsius degrees (returns only the integer part) */
60 #define DEG_T_TO_INTDEG(x) ((x) / 10)
62 /** Macro for converting from deg_t to celsius degrees (returns only the decimal part) */
63 #define DEG_T_TO_DECIMALDEG(x) ((x) % 10)
65 /** Macro for converting from deg_t to celsius degrees (returns type is float) */
66 #define DEG_T_TO_FLOATDEG(x) ((x) / 10.0)
69 typedef uint32_t res_t; /** type for resistor res_t = Ohm * 100 */
70 typedef float amp_t; /** type for defining amplifications amp_t = A, where A is a pure number */
72 DB(extern bool ntc_initialized;)
75 /** Describe a NTC chip */
76 typedef struct NtcHwInfo
78 const res_t *resistances; ///< resistances of the NTC (ohms * 100)
79 size_t num_resistances; ///< number of resistances
80 deg_t degrees_min; ///< degrees corresponding to the first entry in the table (celsius * 10)
81 deg_t degrees_step; ///< difference in degrees between two consecutive elements in the table (celsius * 10)
84 /** Initialize the NTC module */
87 /** Read a single temperature value from the NTC */
88 deg_t ntc_read(NtcDev dev);
90 #endif /* DRV_NTC_H */