1 /*
2 * Copyright 2017-2020, NXP
3 * All rights reserved.
4 *
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #ifndef __FSL_TMU_H__
10 #define __FSL_TMU_H__
11
12 #include "fsl_common.h"
13
14 /*!
15 * @addtogroup tmu
16 * @{
17 */
18
19 /*******************************************************************************
20 * Definitions
21 ******************************************************************************/
22 /*! @brief TMU driver version. */
23 #define FSL_TMU_DRIVER_VERSION (MAKE_VERSION(2, 0, 3)) /*!< Version 2.0.3. */
24
25 enum _tmu_monitor_site
26 {
27 kTMU_MonitorSite0 = 1U << 15U, /* TMU monitoring site 0. */
28 kTMU_MonitorSite1 = 1U << 14U, /* TMU monitoring site 1. */
29 kTMU_MonitorSite2 = 1U << 13U, /* TMU monitoring site 2. */
30 kTMU_MonitorSite3 = 1U << 12U, /* TMU monitoring site 3. */
31 kTMU_MonitorSite4 = 1U << 11U, /* TMU monitoring site 4. */
32 kTMU_MonitorSite5 = 1U << 10U, /* TMU monitoring site 5. */
33 kTMU_MonitorSite6 = 1U << 9U, /* TMU monitoring site 6. */
34 kTMU_MonitorSite7 = 1U << 8U, /* TMU monitoring site 7. */
35 kTMU_MonitorSite8 = 1U << 7U, /* TMU monitoring site 8. */
36 kTMU_MonitorSite9 = 1U << 6U, /* TMU monitoring site 9. */
37 kTMU_MonitorSite10 = 1U << 5U, /* TMU monitoring site 10. */
38 kTMU_MonitorSite11 = 1U << 4U, /* TMU monitoring site 11. */
39 kTMU_MonitorSite12 = 1U << 3U, /* TMU monitoring site 12. */
40 kTMU_MonitorSite13 = 1U << 2U, /* TMU monitoring site 13. */
41 kTMU_MonitorSite14 = 1U << 1U, /* TMU monitoring site 14. */
42 kTMU_MonitorSite15 = 1U << 0U, /* TMU monitoring site 15. */
43 };
44
45 /*!
46 * @brief TMU interrupt enable.
47 */
48 enum _tmu_interrupt_enable
49 {
50 kTMU_ImmediateTemperatureInterruptEnable =
51 TMU_TIER_ITTEIE_MASK, /*!< Immediate temperature threshold exceeded interrupt enable. */
52 kTMU_AverageTemperatureInterruptEnable =
53 TMU_TIER_ATTEIE_MASK, /*!< Average temperature threshold exceeded interrupt enable. */
54 kTMU_AverageTemperatureCriticalInterruptEnable =
55 TMU_TIER_ATCTEIE_MASK, /*!< Average temperature critical threshold exceeded interrupt enable. >*/
56 };
57
58 /*!
59 * @brief TMU interrupt status flags.
60 */
61 enum _tmu_interrupt_status_flags
62 {
63 kTMU_ImmediateTemperatureStatusFlags = TMU_TIDR_ITTE_MASK, /*!< Immediate temperature threshold exceeded(ITTE). */
64 kTMU_AverageTemperatureStatusFlags = TMU_TIDR_ATTE_MASK, /*!< Average temperature threshold exceeded(ATTE). */
65 kTMU_AverageTemperatureCriticalStatusFlags =
66 TMU_TIDR_ATCTE_MASK, /*!< Average temperature critical threshold exceeded.(ATCTE) */
67 };
68
69 /*!
70 * @brief TMU status flags.
71 */
72 enum _tmu_status_flags
73 {
74 kTMU_IntervalExceededStatusFlags = TMU_TSR_MIE_MASK, /*!< Monitoring interval exceeded. The time required to perform
75 measurement of all monitored sites has
76 exceeded the monitoring interval as defined by TMTMIR. */
77 kTMU_OutOfLowRangeStatusFlags = TMU_TSR_ORL_MASK, /*!< Out-of-range low temperature measurement detected. A
78 temperature sensor detected a temperature
79 reading below the lowest measurable temperature of 0 °C. */
80 kTMU_OutOfHighRangeStatusFlags =
81 TMU_TSR_ORH_MASK, /*!< Out-of-range high temperature measurement detected. A temperature sensor detected a
82 temperature
83 reading above the highest measurable temperature of 125 °C. */
84 };
85
86 /*!
87 * @brief configuration for TMU thresold.
88 */
89 typedef struct _tmu_thresold_config
90 {
91 bool immediateThresoldEnable; /*!< Enable high temperature immediate threshold. */
92 bool AverageThresoldEnable; /*!< Enable high temperature average threshold. */
93 bool AverageCriticalThresoldEnable; /*!< Enable high temperature average critical threshold. */
94 uint8_t immediateThresoldValue; /*!< Range:0U-125U. Valid when corresponding thresold is enabled. High temperature
95 immediate threshold value.
96 Determines the current upper temperature threshold, for anyenabled
97 monitored site. */
98 uint8_t averageThresoldValue; /*!< Range:0U-125U. Valid when corresponding thresold is enabled. High temperature
99 average threshold value.
100 Determines the average upper temperature threshold, for any enabled
101 monitored site. */
102 uint8_t averageCriticalThresoldValue; /*!< Range:0U-125U. Valid when corresponding thresold is enabled. High
103 temperature average critical threshold value.
104 Determines the average upper critical temperature threshold, for
105 any enabled monitored site. */
106 } tmu_thresold_config_t;
107
108 /*!
109 * @brief TMU interrupt status.
110 */
111 typedef struct _tmu_interrupt_status
112 {
113 uint32_t interruptDetectMask; /*!< The mask of interrupt status flags. Refer to "_tmu_interrupt_status_flags"
114 enumeration. */
115 uint16_t immediateInterruptsSiteMask; /*!< The mask of the temperature sensor site associated with a detected ITTE
116 event. Please refer to "_tmu_monitor_site" enumeration. */
117 uint16_t AverageInterruptsSiteMask; /*!< The mask of the temperature sensor site associated with a detected ATTE
118 event. Please refer to "_tmu_monitor_site" enumeration. */
119 uint16_t AverageCriticalInterruptsSiteMask; /*!< The mask of the temperature sensor site associated with a detected
120 ATCTE event.
121 Please refer to "_tmu_monitor_site" enumeration. */
122 } tmu_interrupt_status_t;
123 /*!
124 * @brief Average low pass filter setting.
125 */
126 typedef enum _tmu_average_low_pass_filter
127 {
128 kTMU_AverageLowPassFilter1_0 = 0U, /*!< Average low pass filter = 1. */
129 kTMU_AverageLowPassFilter0_5 = 1U, /*!< Average low pass filter = 0.5. */
130 kTMU_AverageLowPassFilter0_25 = 2U, /*!< Average low pass filter = 0.25. */
131 kTMU_AverageLowPassFilter0_125 = 3U, /*!< Average low pass filter = 0.125. */
132 } tmu_average_low_pass_filter_t;
133
134 /*!
135 * @brief Configuration for TMU module.
136 */
137 typedef struct _tmu_config
138 {
139 uint8_t monitorInterval; /*!< Temperature monitoring interval in seconds. Please refer to specific table in RM. */
140 uint16_t monitorSiteSelection; /*!< By setting the select bit for a temperature sensor site, it is enabled and
141 included in all monitoring functions.
142 If no site is selected, site 0 is monitored by default. Refer to
143 "_tmu_monitor_site" enumeration. Please look up
144 relevant table in reference manual. */
145 tmu_average_low_pass_filter_t
146 averageLPF; /*!< The average temperature is calculated as: ALPF x Current_Temp + (1 - ALPF) x Average_Temp.
147 For proper operation, this field should only change when monitoring is disabled. */
148 } tmu_config_t;
149
150 #if defined(__cplusplus)
151 extern "C" {
152 #endif
153
154 /*******************************************************************************
155 * API
156 ******************************************************************************/
157 /*!
158 * @brief Enable the access to TMU registers and Initialize TMU module.
159 *
160 * @param base TMU peripheral base address.
161 * @param config Pointer to configuration structure. Refer to "tmu_config_t" structure.
162 */
163 void TMU_Init(TMU_Type *base, const tmu_config_t *config);
164
165 /*!
166 * @brief De-initialize TMU module and Disable the access to DCDC registers.
167 *
168 * @param base TMU peripheral base address.
169 */
170 void TMU_Deinit(TMU_Type *base);
171
172 /*!
173 * @brief Gets the default configuration for TMU.
174 *
175 * This function initializes the user configuration structure to default value. The default value are:
176 *
177 * Example:
178 @code
179 config->monitorInterval = 0U;
180 config->monitorSiteSelection = 0U;
181 config->averageLPF = kTMU_AverageLowPassFilter1_0;
182 @endcode
183 *
184 * @param config Pointer to TMU configuration structure.
185 */
186 void TMU_GetDefaultConfig(tmu_config_t *config);
187
188 /*!
189 * @brief Enable/Disable the TMU module.
190 *
191 * @param base TMU peripheral base address.
192 * @param enable Switcher to enable/disable TMU.
193 */
TMU_Enable(TMU_Type * base,bool enable)194 static inline void TMU_Enable(TMU_Type *base, bool enable)
195 {
196 if (enable)
197 {
198 base->TMR |= TMU_TMR_ME_MASK;
199 }
200 else
201 {
202 base->TMR &= ~TMU_TMR_ME_MASK;
203 }
204 }
205
206 /*!
207 * @brief Enable the TMU interrupts.
208 *
209 * @param base TMU peripheral base address.
210 * @param mask The interrupt mask. Refer to "_tmu_interrupt_enable" enumeration.
211 */
TMU_EnableInterrupts(TMU_Type * base,uint32_t mask)212 static inline void TMU_EnableInterrupts(TMU_Type *base, uint32_t mask)
213 {
214 base->TIER |= mask;
215 }
216
217 /*!
218 * @brief Disable the TMU interrupts.
219 *
220 * @param base TMU peripheral base address.
221 * @param mask The interrupt mask. Refer to "_tmu_interrupt_enable" enumeration.
222 */
TMU_DisableInterrupts(TMU_Type * base,uint32_t mask)223 static inline void TMU_DisableInterrupts(TMU_Type *base, uint32_t mask)
224 {
225 base->TIER &= ~mask;
226 }
227
228 /*!
229 * @brief Get interrupt status flags.
230 *
231 * @param base TMU peripheral base address.
232 * @param status The pointer to interrupt status structure. Record the current interrupt status.
233 * Please refer to "tmu_interrupt_status_t" structure.
234 */
235 void TMU_GetInterruptStatusFlags(TMU_Type *base, tmu_interrupt_status_t *status);
236
237 /*!
238 * @brief Clear interrupt status flags and corresponding interrupt critical site capture register.
239 *
240 * @param base TMU peripheral base address.
241 * @param mask The mask of interrupt status flags. Refer to "_tmu_interrupt_status_flags" enumeration.
242 */
243 void TMU_ClearInterruptStatusFlags(TMU_Type *base, uint32_t mask);
244
245 /*!
246 * @brief Get TMU status flags.
247 *
248 * @param base TMU peripheral base address.
249 *
250 * @return The mask of status flags. Refer to "_tmu_status_flags" enumeration.
251 */
TMU_GetStatusFlags(TMU_Type * base)252 static inline uint32_t TMU_GetStatusFlags(TMU_Type *base)
253 {
254 return base->TSR;
255 }
256
257 /*!
258 * @brief Get the highest temperature reached for any enabled monitored site within the temperature
259 * sensor range.
260 *
261 * @param base TMU peripheral base address.
262 * @param temperature Highest temperature recorded in degrees Celsius by any enabled monitored site.
263 *
264 * @return Execution status.
265 * @retval kStatus_Success Temperature reading is valid.
266 * @retval kStatus_Fail Temperature reading is not valid due to no measured temperature within the
267 * sensor range of 0-125 °C for an enabled monitored site.
268 */
269 status_t TMU_GetHighestTemperature(TMU_Type *base, uint32_t *temperature);
270
271 /*!
272 * @brief Get the lowest temperature reached for any enabled monitored site within the temperature
273 * sensor range.
274 *
275 * @param base TMU peripheral base address.
276 * @param temperature Lowest temperature recorded in degrees Celsius by any enabled monitored site.
277 *
278 * @return Execution status.
279 * @retval kStatus_Success Temperature reading is valid.
280 * @retval kStatus_Fail Temperature reading is not valid due to no measured temperature within the
281 * sensor range of 0-125 °C for an enabled monitored site.
282 */
283 status_t TMU_GetLowestTemperature(TMU_Type *base, uint32_t *temperature);
284
285 /*!
286 * @brief Get the last immediate temperature at site n. The site must be part of the list of enabled
287 * monitored sites as defined by monitorSiteSelection in "tmu_config_t" structure.
288 *
289 * @param base TMU peripheral base address.
290 * @param siteIndex The index of the site user want to read. 0U: site0 ~ 15U: site15.
291 * @param temperature Last immediate temperature reading at site n .
292 *
293 * @return Execution status.
294 * @retval kStatus_Success Temperature reading is valid.
295 * @retval kStatus_Fail Temperature reading is not valid because temperature out of sensor range or
296 * first measurement still pending.
297 */
298 status_t TMU_GetImmediateTemperature(TMU_Type *base, uint32_t siteIndex, uint32_t *temperature);
299
300 /*!
301 * @brief Get the last average temperature at site n. The site must be part of the list of enabled
302 * monitored sites as defined by monitorSiteSelection in "tmu_config_t" structure.
303 *
304 * @param base TMU peripheral base address.
305 * @param siteIndex The index of the site user want to read. 0U: site0 ~ 15U: site15.
306 * @param temperature Last average temperature reading at site n .
307 *
308 * @return Execution status.
309 * @retval kStatus_Success Temperature reading is valid.
310 * @retval kStatus_Fail Temperature reading is not valid because temperature out of sensor range or
311 * first measurement still pending.
312 */
313 status_t TMU_GetAverageTemperature(TMU_Type *base, uint32_t siteIndex, uint32_t *temperature);
314
315 /*!
316 * @brief Configure the high temperature thresold value and enable/disable relevant thresold.
317 *
318 * @param base TMU peripheral base address.
319 * @param config Pointer to configuration structure. Refer to "tmu_thresold_config_t" structure.
320 */
321 void TMU_SetHighTemperatureThresold(TMU_Type *base, const tmu_thresold_config_t *config);
322
323 #if defined(__cplusplus)
324 }
325 #endif
326
327 /* @} */
328
329 #endif /* __FSL_TMU_H__ */
330