1 /*
2 * Copyright 2018-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, 1, 1)) /*!< Version 2.1.1. */
24
25 /*!
26 * @brief TMU interrupt enable.
27 */
28 enum _tmu_interrupt_enable
29 {
30 kTMU_ImmediateTemperatureInterruptEnable =
31 TMU_TIER_ITTEIE_MASK, /*!< Immediate temperature threshold exceeded interrupt enable. */
32 kTMU_AverageTemperatureInterruptEnable =
33 TMU_TIER_ATTEIE_MASK, /*!< Average temperature threshold exceeded interrupt enable. */
34 kTMU_AverageTemperatureCriticalInterruptEnable =
35 TMU_TIER_ATCTEIE_MASK, /*!< Average temperature critical threshold exceeded interrupt enable. >*/
36 };
37
38 /*!
39 * @brief TMU interrupt status flags.
40 */
41 enum _tmu_interrupt_status_flags
42 {
43 kTMU_ImmediateTemperatureStatusFlags = TMU_TIDR_ITTE_MASK, /*!< Immediate temperature threshold exceeded(ITTE). */
44 kTMU_AverageTemperatureStatusFlags = TMU_TIDR_ATTE_MASK, /*!< Average temperature threshold exceeded(ATTE). */
45 kTMU_AverageTemperatureCriticalStatusFlags =
46 TMU_TIDR_ATCTE_MASK, /*!< Average temperature critical threshold exceeded.(ATCTE) */
47 };
48
49 /*!
50 * @brief configuration for TMU thresold.
51 */
52 typedef struct _tmu_thresold_config
53 {
54 bool immediateThresoldEnable; /*!< Enable high temperature immediate threshold. */
55 bool AverageThresoldEnable; /*!< Enable high temperature average threshold. */
56 bool AverageCriticalThresoldEnable; /*!< Enable high temperature average critical threshold. */
57 uint8_t immediateThresoldValue; /*!< Range:10U-125U. Valid when corresponding threshold is enabled. High temperature
58 immediate threshold value.
59 Determines the current upper temperature threshold, for any enabled
60 monitored site. */
61 uint8_t averageThresoldValue; /*!< Range:10U-125U. Valid when corresponding threshold is enabled. High temperature
62 average threshold value.
63 Determines the average upper temperature threshold, for any enabled
64 monitored site. */
65 uint8_t averageCriticalThresoldValue; /*!< Range:10U-125U. Valid when corresponding threshold is enabled. High
66 temperature average critical threshold value.
67 Determines the average upper critical temperature threshold, for
68 any enabled monitored site. */
69 } tmu_thresold_config_t;
70
71 /*!
72 * @brief TMU interrupt status.
73 */
74 typedef struct _tmu_interrupt_status
75 {
76 uint32_t interruptDetectMask; /*!< The mask of interrupt status flags. Refer to "_tmu_interrupt_status_flags"
77 enumeration. */
78 } tmu_interrupt_status_t;
79
80 /*!
81 * @brief Average low pass filter setting.
82 */
83 typedef enum _tmu_average_low_pass_filter
84 {
85 kTMU_AverageLowPassFilter1_0 = 0U, /*!< Average low pass filter = 1. */
86 kTMU_AverageLowPassFilter0_5 = 1U, /*!< Average low pass filter = 0.5. */
87 kTMU_AverageLowPassFilter0_25 = 2U, /*!< Average low pass filter = 0.25. */
88 kTMU_AverageLowPassFilter0_125 = 3U, /*!< Average low pass filter = 0.125. */
89 } tmu_average_low_pass_filter_t;
90
91 /*!
92 * @brief Amplifier gain setting.
93 */
94 typedef enum _tmu_amplifier_gain
95 {
96 kTMU_AmplifierGain6_34 = 0U, /*!< TMU amplifier gain voltage 6.34mV. */
97 kTMU_AmplifierGain6_485 = 1U, /*!< TMU amplifier gain voltage 6.485mV. */
98 kTMU_AmplifierGain6_63 = 2U, /*!< TMU amplifier gain voltage 6.63mV. */
99 kTMU_AmplifierGain6_775 = 3U, /*!< TMU amplifier gain voltage 6.775mV. */
100 kTMU_AmplifierGain6_92 = 4U, /*!< TMU amplifier gain voltage 6.92mV. */
101 kTMU_AmplifierGain7_065 = 5U, /*!< TMU amplifier gain voltage 7.065mV. */
102 kTMU_AmplifierGain7_21 = 6U, /*!< TMU amplifier gain voltage 7.21mV. */
103 kTMU_AmplifierGain7_355 = 7U, /*!< TMU amplifier gain voltage 7.355mV. */
104 kTMU_AmplifierGain7_5 = 8U, /*!< TMU amplifier gain voltage 7.5mV. */
105 kTMU_AmplifierGain7_645 = 9U, /*!< TMU amplifier gain voltage 7.645mV. */
106 kTMU_AmplifierGain7_79 = 10U, /*!< TMU amplifier gain voltage 7.79mV. */
107 kTMU_AmplifierGain7_935 = 11U, /*!< TMU amplifier gain voltage 7.935mV. */
108 kTMU_AmplifierGain8_08 = 12U, /*!< TMU amplifier gain voltage 8.08mV(default). */
109 kTMU_AmplifierGain8_225 = 13U, /*!< TMU amplifier gain voltage 8.225mV. */
110 kTMU_AmplifierGain8_37 = 14U, /*!< TMU amplifier gain voltage 8.37mV. */
111 kTMU_AmplifierGain8_515 = 15U, /*!< TMU amplifier gain voltage 8.515mV. */
112 } tmu_amplifier_gain_t;
113
114 /*!
115 * @brief Amplifier reference voltage setting.
116 */
117 typedef enum _tmu_amplifier_reference_voltage
118 {
119 kTMU_AmplifierReferenceVoltage510 = 0U, /*!< TMU amplifier reference voltage 510mV. */
120 kTMU_AmplifierReferenceVoltage517_5 = 1U, /*!< TMU amplifier reference voltage 517.5mV. */
121 kTMU_AmplifierReferenceVoltage525 = 2U, /*!< TMU amplifier reference voltage 525mV. */
122 kTMU_AmplifierReferenceVoltage532_5 = 3U, /*!< TMU amplifier reference voltage 532.5mV. */
123 kTMU_AmplifierReferenceVoltage540 = 4U, /*!< TMU amplifier reference voltage 540mV. */
124 kTMU_AmplifierReferenceVoltage547_5 = 5U, /*!< TMU amplifier reference voltage 547.5mV. */
125 kTMU_AmplifierReferenceVoltage555 = 6U, /*!< TMU amplifier reference voltage 555mV. */
126 kTMU_AmplifierReferenceVoltage562_5 = 7U, /*!< TMU amplifier reference voltage 562.5mV. */
127 kTMU_AmplifierReferenceVoltage570 = 8U, /*!< TMU amplifier reference voltage 570mV. */
128 kTMU_AmplifierReferenceVoltage577_5 = 9U, /*!< TMU amplifier reference voltage 577.5mV. */
129 kTMU_AmplifierReferenceVoltage585 = 10U, /*!< TMU amplifier reference voltage 585mV. */
130 kTMU_AmplifierReferenceVoltage592_5 = 11U, /*!< TMU amplifier reference voltage 592.5mV. */
131 kTMU_AmplifierReferenceVoltage600 = 12U, /*!< TMU amplifier reference voltage 600mV. */
132 kTMU_AmplifierReferenceVoltage607_5 = 13U, /*!< TMU amplifier reference voltage 607.5mV. */
133 kTMU_AmplifierReferenceVoltage615 = 14U, /*!< TMU amplifier reference voltage 615mV. */
134 kTMU_AmplifierReferenceVoltage622_5 = 15U, /*!< TMU amplifier reference voltage 622.5mV. */
135 kTMU_AmplifierReferenceVoltage630 = 16U, /*!< TMU amplifier reference voltage 630mV. */
136 kTMU_AmplifierReferenceVoltage637_5 = 17U, /*!< TMU amplifier reference voltage 637.5mV. */
137 kTMU_AmplifierReferenceVoltage645 = 18U, /*!< TMU amplifier reference voltage 645mV. */
138 kTMU_AmplifierReferenceVoltage652_5 = 19U, /*!< TMU amplifier reference voltage 652.5mV(default). */
139 kTMU_AmplifierReferenceVoltage660 = 20U, /*!< TMU amplifier reference voltage 660mV. */
140 kTMU_AmplifierReferenceVoltage667_5 = 21U, /*!< TMU amplifier reference voltage 667.5mV. */
141 kTMU_AmplifierReferenceVoltage675 = 22U, /*!< TMU amplifier reference voltage 675mV. */
142 kTMU_AmplifierReferenceVoltage682_5 = 23U, /*!< TMU amplifier reference voltage 682.5mV. */
143 kTMU_AmplifierReferenceVoltage690 = 24U, /*!< TMU amplifier reference voltage 690mV. */
144 kTMU_AmplifierReferenceVoltage697_5 = 25U, /*!< TMU amplifier reference voltage 697.5mV. */
145 kTMU_AmplifierReferenceVoltage705 = 26U, /*!< TMU amplifier reference voltage 705mV. */
146 kTMU_AmplifierReferenceVoltage712_5 = 27U, /*!< TMU amplifier reference voltage 712.5mV. */
147 kTMU_AmplifierReferenceVoltage720 = 28U, /*!< TMU amplifier reference voltage 720mV. */
148 kTMU_AmplifierReferenceVoltage727_5 = 29U, /*!< TMU amplifier reference voltage 727.5mV. */
149 kTMU_AmplifierReferenceVoltage735 = 30U, /*!< TMU amplifier reference voltage 735mV. */
150 kTMU_AmplifierReferenceVoltage742_5 = 31U, /*!< TMU amplifier reference voltage 742.5mV. */
151 } tmu_amplifier_reference_voltage_t;
152
153 /*!
154 * @brief Configuration for TMU module.
155 */
156 typedef struct _tmu_config
157 {
158 tmu_average_low_pass_filter_t
159 averageLPF; /*!< The average temperature is calculated as: ALPF x Current_Temp + (1 - ALPF) x Average_Temp.
160 For proper operation, this field should only change when monitoring is disabled. */
161 } tmu_config_t;
162
163 #if defined(__cplusplus)
164 extern "C" {
165 #endif
166
167 /*******************************************************************************
168 * API
169 ******************************************************************************/
170 /*!
171 * @brief Enable the access to TMU registers and Initialize TMU module.
172 *
173 * @param base TMU peripheral base address.
174 * @param config Pointer to configuration structure. Refer to "tmu_config_t" structure.
175 */
176 void TMU_Init(TMU_Type *base, const tmu_config_t *config);
177
178 /*!
179 * @brief De-initialize TMU module and Disable the access to DCDC registers.
180 *
181 * @param base TMU peripheral base address.
182 */
183 void TMU_Deinit(TMU_Type *base);
184
185 /*!
186 * @brief Gets the default configuration for TMU.
187 *
188 * This function initializes the user configuration structure to default value. The default value are:
189 *
190 * Example:
191 @code
192 config->averageLPF = kTMU_AverageLowPassFilter0_5;
193 @endcode
194 *
195 * @param config Pointer to TMU configuration structure.
196 */
197 void TMU_GetDefaultConfig(tmu_config_t *config);
198
199 /*!
200 * @brief Enable/Disable monitoring the temperature sensor.
201 *
202 * @param base TMU peripheral base address.
203 * @param enable Switcher to enable/disable TMU.
204 */
TMU_Enable(TMU_Type * base,bool enable)205 static inline void TMU_Enable(TMU_Type *base, bool enable)
206 {
207 if (enable)
208 {
209 base->TER |= TMU_TER_EN_MASK;
210 }
211 else
212 {
213 base->TER &= ~TMU_TER_EN_MASK;
214 }
215 }
216
217 /*!
218 * @brief Enable 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_EnableInterrupts(TMU_Type * base,uint32_t mask)223 static inline void TMU_EnableInterrupts(TMU_Type *base, uint32_t mask)
224 {
225 base->TIER |= mask;
226 }
227
228 /*!
229 * @brief Disable the TMU interrupts.
230 *
231 * @param base TMU peripheral base address.
232 * @param mask The interrupt mask. Refer to "_tmu_interrupt_enable" enumeration.
233 */
TMU_DisableInterrupts(TMU_Type * base,uint32_t mask)234 static inline void TMU_DisableInterrupts(TMU_Type *base, uint32_t mask)
235 {
236 base->TIER &= ~mask;
237 }
238
239 /*!
240 * @brief Get interrupt status flags.
241 *
242 * @param base TMU peripheral base address.
243 * @param status The pointer to interrupt status structure. Record the current interrupt status.
244 * Please refer to "tmu_interrupt_status_t" structure.
245 */
246 void TMU_GetInterruptStatusFlags(TMU_Type *base, tmu_interrupt_status_t *status);
247
248 /*!
249 * @brief Clear interrupt status flags.
250 *
251 * @param base TMU peripheral base address.
252 * @param mask The mask of interrupt status flags. Refer to "_tmu_interrupt_status_flags" enumeration.
253 */
254 void TMU_ClearInterruptStatusFlags(TMU_Type *base, uint32_t mask);
255
256 /*!
257 * @brief Get the last immediate temperature at site.
258 *
259 * @param base TMU peripheral base address.
260 * @param temperature Last immediate temperature reading at site when V=1.
261 *
262 * @return Execution status.
263 * @retval kStatus_Success Temperature reading is valid.
264 * @retval kStatus_Fail Temperature reading is not valid because temperature out of sensor range or
265 * first measurement still pending.
266 */
267 status_t TMU_GetImmediateTemperature(TMU_Type *base, uint32_t *temperature);
268
269 /*!
270 * @brief Get the last average temperature at site.
271 *
272 * @param base TMU peripheral base address.
273 * @param temperature Last average temperature reading at site.
274 *
275 * @return Execution status.
276 * @retval kStatus_Success Temperature reading is valid.
277 * @retval kStatus_Fail Temperature reading is not valid because temperature out of sensor range or
278 * first measurement still pending.
279 */
280 status_t TMU_GetAverageTemperature(TMU_Type *base, uint32_t *temperature);
281
282 /*!
283 * @brief Configure the high temperature thresold value and enable/disable relevant thresold.
284 *
285 * @param base TMU peripheral base address.
286 * @param config Pointer to configuration structure. Refer to "tmu_thresold_config_t" structure.
287 */
288 void TMU_SetHighTemperatureThresold(TMU_Type *base, const tmu_thresold_config_t *config);
289
290 #if defined(__cplusplus)
291 }
292 #endif
293
294 /*@}*/
295
296 #endif /* __FSL_TMU_H__ */
297