1 /*
2  * Copyright  2018-2021 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 #ifndef _FSL_TEMPMON_H_
9 #define _FSL_TEMPMON_H_
10 
11 #include "fsl_common.h"
12 
13 /*!
14  * @addtogroup tempmon
15  * @{
16  */
17 
18 /*! @file */
19 
20 /*******************************************************************************
21  * Definitions
22  ******************************************************************************/
23 
24 /*! @name Driver version */
25 /*@{*/
26 /*! @brief TEMPMON driver version. */
27 #define FSL_TEMPMON_DRIVER_VERSION (MAKE_VERSION(2, 1, 1))
28 /*@}*/
29 
30 /*! @brief TEMPMON temperature structure. */
31 typedef struct _tempmon_config
32 {
33     uint16_t frequency;    /*!< The temperature measure frequency.*/
34     int8_t highAlarmTemp;  /*!< The high alarm temperature.*/
35     int8_t panicAlarmTemp; /*!< The panic alarm temperature.*/
36     int8_t lowAlarmTemp;   /*!< The low alarm temperature.*/
37 } tempmon_config_t;
38 
39 /*! @brief TEMPMON alarm mode. */
40 typedef enum _tempmon_alarm_mode
41 {
42     kTEMPMON_HighAlarmMode  = 0U, /*!< The high alarm temperature interrupt mode.*/
43     kTEMPMON_PanicAlarmMode = 1U, /*!< The panic alarm temperature interrupt mode.*/
44     kTEMPMON_LowAlarmMode   = 2U, /*!< The low alarm temperature interrupt mode.*/
45 } tempmon_alarm_mode;
46 
47 /*******************************************************************************
48  * API
49  ******************************************************************************/
50 
51 #if defined(__cplusplus)
52 extern "C" {
53 #endif
54 
55 /*!
56  * @brief Initializes the TEMPMON module.
57  *
58  * @param base TEMPMON base pointer
59  * @param config Pointer to configuration structure.
60  */
61 void TEMPMON_Init(TEMPMON_Type *base, const tempmon_config_t *config);
62 
63 /*!
64  * @brief Deinitializes the TEMPMON module.
65  *
66  * @param base TEMPMON base pointer
67  */
68 void TEMPMON_Deinit(TEMPMON_Type *base);
69 
70 /*!
71  * @brief Gets the default configuration structure.
72  *
73  * This function initializes the TEMPMON configuration structure to a default value. The default
74  * values are:
75  *   tempmonConfig->frequency = 0x02U;
76  *   tempmonConfig->highAlarmTemp = 44U;
77  *   tempmonConfig->panicAlarmTemp = 90U;
78  *   tempmonConfig->lowAlarmTemp = 39U;
79  *
80  * @param config Pointer to a configuration structure.
81  */
82 void TEMPMON_GetDefaultConfig(tempmon_config_t *config);
83 
84 /*!
85  * @brief start the temperature measurement process.
86  *
87  * @param base TEMPMON base pointer.
88  */
TEMPMON_StartMeasure(TEMPMON_Type * base)89 static inline void TEMPMON_StartMeasure(TEMPMON_Type *base)
90 {
91     base->TEMPSENSE0 |= TEMPMON_TEMPSENSE0_MEASURE_TEMP_MASK;
92 }
93 
94 /*!
95  * @brief stop the measurement process.
96  *
97  * @param base TEMPMON base pointer
98  */
TEMPMON_StopMeasure(TEMPMON_Type * base)99 static inline void TEMPMON_StopMeasure(TEMPMON_Type *base)
100 {
101     base->TEMPSENSE0 &= ~TEMPMON_TEMPSENSE0_MEASURE_TEMP_MASK;
102 }
103 
104 /*!
105  * @brief Get current temperature with the fused temperature calibration data.
106  *
107  * @param base TEMPMON base pointer
108  * @return current temperature with degrees Celsius.
109  */
110 float TEMPMON_GetCurrentTemperature(TEMPMON_Type *base);
111 
112 /*!
113  * @brief Set the temperature count (raw sensor output) that will generate an alarm interrupt.
114  *
115  * @param base TEMPMON base pointer
116  * @param tempVal The alarm temperature with degrees Celsius
117  * @param alarmMode The alarm mode.
118  */
119 void TEMPMON_SetTempAlarm(TEMPMON_Type *base, int8_t tempVal, tempmon_alarm_mode alarmMode);
120 
121 #if defined(__cplusplus)
122 }
123 #endif
124 
125 /*! @}*/
126 
127 #endif /* _FSL_TEMPMON_H_ */
128