1 /*
2  * Copyright 2020-2022 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 tempsensor
15  * @{
16  */
17 
18 /*! @file */
19 
20 /*******************************************************************************
21  * Definitions
22  ******************************************************************************/
23 
24 /*! @name Driver version */
25 /*@{*/
26 #define FSL_TMPSNS_DRIVER_VERSION (MAKE_VERSION(2, 1, 1))
27 /*@}*/
28 
29 /*! @brief TMPSNS interrupt status enable type, tmpsns_interrupt_status_enable_t. */
30 enum
31 {
32     kTEMPSENSOR_HighTempInterruptStatusEnable =
33         TMPSNS_CTRL1_HIGH_TEMP_IE_MASK, /*!< High temperature interrupt status enable.*/
34     kTEMPSENSOR_LowTempInterruptStatusEnable =
35         TMPSNS_CTRL1_LOW_TEMP_IE_MASK, /*!< Low temperature interrupt status enable.*/
36     kTEMPSENSOR_PanicTempInterruptStatusEnable =
37         TMPSNS_CTRL1_PANIC_TEMP_IE_MASK, /*!< Panic temperature interrupt status enable.*/
38     kTEMPSENSOR_FinishInterruptStatusEnable = TMPSNS_CTRL1_FINISH_IE_MASK, /*!< Finish interrupt enable.*/
39 };
40 
41 /*! @brief TMPSNS interrupt status type, tmpsns_interrupt_status_t. */
42 enum
43 {
44     kTEMPSENSOR_HighTempInterruptStatus  = TMPSNS_STATUS0_HIGH_TEMP_MASK,  /*!< High temperature interrupt status.*/
45     kTEMPSENSOR_LowTempInterruptStatus   = TMPSNS_STATUS0_LOW_TEMP_MASK,   /*!< Low temperature interrupt status.*/
46     kTEMPSENSOR_PanicTempInterruptStatus = TMPSNS_STATUS0_PANIC_TEMP_MASK, /*!< Panic temperature interrupt status.*/
47 };
48 
49 /*! @brief TMPSNS measure mode, tempsensor_measure_mode. */
50 typedef enum
51 {
52     kTEMPSENSOR_SingleMode     = 0U, /*!< Single measurement mode.*/
53     kTEMPSENSOR_ContinuousMode = 1U, /*!< Continuous measurement mode.*/
54 } tmpsns_measure_mode_t;
55 
56 /*! @brief TMPSNS temperature structure. */
57 typedef struct _tmpsns_config
58 {
59     tmpsns_measure_mode_t measureMode; /*!< The temperature measure mode.*/
60     uint16_t frequency;                /*!< The temperature measure frequency.*/
61     int32_t highAlarmTemp;             /*!< The high alarm temperature.*/
62     int32_t panicAlarmTemp;            /*!< The panic alarm temperature.*/
63     int32_t lowAlarmTemp;              /*!< The low alarm temperature.*/
64 } tmpsns_config_t;
65 
66 /*! @brief TMPSNS alarm mode. */
67 typedef enum _tmpsns_alarm_mode
68 {
69     kTEMPMON_HighAlarmMode  = 0U, /*!< The high alarm temperature interrupt mode.*/
70     kTEMPMON_PanicAlarmMode = 1U, /*!< The panic alarm temperature interrupt mode.*/
71     kTEMPMON_LowAlarmMode   = 2U, /*!< The low alarm temperature interrupt mode.*/
72 } tmpsns_alarm_mode_t;
73 
74 /*******************************************************************************
75  * API
76  ******************************************************************************/
77 
78 #if defined(__cplusplus)
79 extern "C" {
80 #endif
81 
82 /*!
83  * @brief Initializes the TMPSNS module.
84  *
85  * @param base TMPSNS base pointer
86  * @param config Pointer to configuration structure.
87  */
88 void TMPSNS_Init(TMPSNS_Type *base, const tmpsns_config_t *config);
89 
90 /*!
91  * @brief Deinitializes the TMPSNS module.
92  *
93  * @param base TMPSNS base pointer
94  */
95 void TMPSNS_Deinit(TMPSNS_Type *base);
96 
97 /*!
98  * @brief Gets the default configuration structure.
99  *
100  * This function initializes the TMPSNS configuration structure to a default value. The default
101  * values are:
102  *   tempmonConfig->frequency = 0x02U;
103  *   tempmonConfig->highAlarmTemp = 44U;
104  *   tempmonConfig->panicAlarmTemp = 90U;
105  *   tempmonConfig->lowAlarmTemp = 39U;
106  *
107  * @param config Pointer to a configuration structure.
108  */
109 void TMPSNS_GetDefaultConfig(tmpsns_config_t *config);
110 
111 /*!
112  * @brief start the temperature measurement process.
113  *
114  * @param base TMPSNS base pointer.
115  */
116 void TMPSNS_StartMeasure(TMPSNS_Type *base);
117 
118 /*!
119  * @brief stop the measurement process.
120  *
121  * @param base TMPSNS base pointer
122  */
123 void TMPSNS_StopMeasure(TMPSNS_Type *base);
124 
125 /*!
126  * @brief Get current temperature with the fused temperature calibration data.
127  *
128  * @param base TMPSNS base pointer
129  * @return current temperature with degrees Celsius.
130  */
131 float TMPSNS_GetCurrentTemperature(TMPSNS_Type *base);
132 
133 /*!
134  * @brief Set the temperature count (raw sensor output) that will generate an alarm interrupt.
135  *
136  * @param base TMPSNS base pointer
137  * @param tempVal The alarm temperature with degrees Celsius
138  * @param alarmMode The alarm mode.
139  */
140 void TMPSNS_SetTempAlarm(TMPSNS_Type *base, int32_t tempVal, tmpsns_alarm_mode_t alarmMode);
141 
142 /*!
143  * @brief Enable interrupt status.
144  *
145  * @param base TMPSNS base pointer
146  * @param mask The interrupts to enable from tmpsns_interrupt_status_enable_t.
147  */
148 void TMPSNS_EnableInterrupt(TMPSNS_Type *base, uint32_t mask);
149 
150 /*!
151  * @brief Disable interrupt status.
152  *
153  * @param base TMPSNS base pointer
154  * @param mask The interrupts to disable from tmpsns_interrupt_status_enable_t.
155  */
156 void TMPSNS_DisableInterrupt(TMPSNS_Type *base, uint32_t mask);
157 
158 /*!
159  * @brief Get interrupt status flag.
160  *
161  * @param base TMPSNS base pointer
162  * @param mask The interrupts to disable from tmpsns_interrupt_status_t.
163  */
TMPSNS_GetInterruptFlags(TMPSNS_Type * base)164 static inline uint32_t TMPSNS_GetInterruptFlags(TMPSNS_Type *base)
165 {
166     return base->STATUS0;
167 }
168 
169 /*!
170  * @brief Clear interrupt status flag.
171  *
172  * @param base TMPSNS base pointer
173  * @param mask The interrupts to disable from tmpsns_interrupt_status_t.
174  */
TMPSNS_ClearInterruptFlags(TMPSNS_Type * base,uint32_t mask)175 static inline void TMPSNS_ClearInterruptFlags(TMPSNS_Type *base, uint32_t mask)
176 {
177     base->STATUS0 = mask;
178 }
179 
180 #if defined(__cplusplus)
181 }
182 #endif
183 
184 /*! @}*/
185 
186 #endif /* _FSL_TEMPMON_H_ */
187