1 /*
2  * Copyright 2023 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 #ifndef FSL_TDET_H_
8 #define FSL_TDET_H_
9 
10 #include "fsl_common.h"
11 
12 /*!
13  * @addtogroup TDET
14  * @{
15  */
16 
17 /*! @file */
18 
19 /*******************************************************************************
20  * Definitions
21  *******************************************************************************/
22 
23 /*! @name Driver version */
24 /*! @{ */
25 /*! @brief Defines TDET driver version 2.1.0.
26  *
27  * Change log:
28  * - Version 2.1.0
29  *   - Added setting of disabling prescaler on tamper event into TDET_SetConfig() and TDET_GetDefaultConfig functions.
30  * - Version 2.0.0
31  *   - Initial version
32  */
33 #define FSL_TDET_DRIVER_VERSION (MAKE_VERSION(2, 1, 0))
34 /*! @} */
35 
36 /*!
37  * @brief TDET Update Mode.
38  *
39  * These constants allow TDET interrupts to be cleared if no tampering has been detected, while still preventing
40  * the TDET Tamper Flag (SR[DTF]) from being cleared once it is set.
41  */
42 typedef enum _tdet_update_mode
43 {
44     kTDET_StatusLockNormal = 0U,     /*!< TDET Status Register cannot be written when the Status Register Lock bit
45                                           within the Lock Register (LR[SRL]) is clear */
46     kTDET_StatusLockWithTamper = 1U, /*!< TDET Status Register cannot be written when the Status Register Lock bit
47                                           within the Lock Register (LR[SRL]) is clear and TDET Tamper Flag (SR[DTF])
48                                           is set*/
49 } tdet_update_mode_t;
50 
51 /*!
52  * @brief TDET Active Tamper Clock Source.
53  *
54  * These constants define the clock source for Active Tamper Shift Register to configure in a TDET base.
55  */
56 typedef enum _tdet_active_tamper_clock
57 {
58     kTDET_ClockType1Hz  = 0U, /*!< clocked by 1 Hz prescaler clock  */
59     kTDET_ClockType64Hz = 1U, /*!< clocked by 614 Hz prescaler clock */
60 } tdet_active_tamper_clock_t;
61 
62 /*!
63  * @brief TDET Control Register.
64  *
65  * This structure defines values for TDET Control Register.
66  */
67 typedef struct _tdet_config
68 {
69     bool innerClockAndPrescalerEnable; /*!< Enable/disable 32768 Hz clock within TDET and the TDET prescaler that
70                                           generates 512 Hz, 64Hz and 1 Hz prescaler clocks  */
71     bool tamperForceSystemResetEnable; /*!< Enable/disable assertion of chip reset when tampering is detected */
72     enum _tdet_update_mode updateMode; /*!< Selects update mode for TDET Status Register */
73     enum _tdet_active_tamper_clock
74         clockSourceActiveTamper0; /*!< Selects clock source for Active Tamper Shift Register 0 */
75     enum _tdet_active_tamper_clock
76         clockSourceActiveTamper1;     /*!< Selects clock source for Active Tamper Shift Register 1 */
77     bool disablePrescalerAfterTamper; /*!< Allows the 32-KHz clock and prescaler to be automatically disabled after
78                                          tamper detection and until the system acknowledges the tamper. Disabling the
79                                          prescaler after detecting a tamper event conserves power and freezes the state
80                                          of the active tamper outputs and glitch filters. To ensure a clean transition,
81                                          the prescaler is disabled at the end of a 1 Hz period.  */
82     uint32_t prescaler;               /*!< Initial value for the TDET prescaler 15-bit value. */
83 } tdet_config_t;
84 
85 /*!
86  * @brief TDET Tamper Pin Polarity.
87  *
88  * These constants define tamper pin polarity to configure in a TDET base.
89  */
90 typedef enum _tdet_pin_polarity
91 {
92     kTDET_TamperPinPolarityExpectNormal   = 0U, /*!< Tamper pin expected value is not inverted  */
93     kTDET_TamperPinPolarityExpectInverted = 1U, /*!< Tamper pin expected value is inverted */
94 } tdet_pin_polarity_t;
95 
96 /*!
97  * @brief TDET Tamper Pin Direction.
98  *
99  * These constants define tamper pin direction to configure in a TDET base.
100  */
101 typedef enum _tdet_pin_direction
102 {
103     kTDET_TamperPinDirectionIn  = 0U, /*!< Tamper pins configured as input  */
104     kTDET_TamperPinDirectionOut = 1U, /*!< Tamper pins configured as output, drives inverse of expected value */
105 } tdet_pin_direction_t;
106 
107 /*!
108  * @brief TDET Glitch Filter Tamper Pin Sample Frequency.
109  *
110  * These constants define tamper pin glitch filter sample frequency to configure in a TDET base.
111  */
112 typedef enum _tdet_glitch_filter_sample_freq
113 {
114     kTDET_GlitchFilterSamplingEveryCycle8   = 0U, /*!<  Sample once every 8 cycles */
115     kTDET_GlitchFilterSamplingEveryCycle32  = 1U, /*!<  Sample once every 32 cycles */
116     kTDET_GlitchFilterSamplingEveryCycle128 = 2U, /*!<  Sample once every 128 cycles */
117     kTDET_GlitchFilterSamplingEveryCycle512 = 3U, /*!<  Sample once every 512 cycles */
118 } tdet_glitch_filter_sample_freq_t;
119 /*!
120  * @brief TDET Glitch Filter Tamper Pin Sample Width.
121  *
122  * These constants define tamper pin glitch filter sample width to configure in a TDET base.
123  */
124 typedef enum _tdet_glitch_filter_sample_width
125 {
126     kTDET_GlitchFilterSampleDisable = 0U, /*!<  Sampling disabled */
127     kTDET_GlitchFilterSampleCycle2  = 1U, /*!<  Sample width pull enable/input buffer enable=2 cycles/1 cycle */
128     kTDET_GlitchFilterSampleCycle4  = 2U, /*!<  Sample width pull enable/input buffer enable=4 cycles/2 cycles */
129     kTDET_GlitchFilterSampleCycle8  = 3U, /*!<  Sample width pull enable/input buffer enable=8 cycles/4 cycles */
130 } tdet_glitch_filter_sample_width_t;
131 
132 /*!
133  * @brief TDET Glitch Filter Tamper Pin Clock Source.
134  *
135  * These constants define tamper pin glitch filter clock source to configure in a TDET base.
136  */
137 typedef enum _tdet_glitch_filter_prescaler
138 {
139     kTDET_GlitchFilterClock512Hz   = 0U, /*!< Glitch Filter on tamper pin is clocked by the 512 Hz prescaler clock */
140     kTDET_GlitchFilterClock32768Hz = 1U, /*!< Glitch Filter on tamper pin is clocked by the 32768 Hz prescaler clock */
141 } tdet_glitch_filter_prescaler_t;
142 
143 /*!
144  * @brief TDET Glitch Filter Tamper Pin Expected Value.
145  *
146  * These constants define tamper pin glitch filter expected value to configure in a TDET base.
147  */
148 typedef enum _tdet_glitch_filter_expected
149 {
150     kTDET_GlitchFilterExpectedLogicZero     = 0U, /*!<  Expected value is logic zero */
151     kTDET_GlitchFilterExpectedActTamperOut0 = 1U, /*!<  Expected value is active tamper 0 output */
152     kTDET_GlitchFilterExpectedActTamperOut1 = 2U, /*!<  Expected value is active tamper 1 output */
153     kTDET_GlitchFilterExpectedActTamperOutXOR =
154         3U, /*!<  Expected value is active tamper 0 output XORed with active tamper 1 output */
155 } tdet_glitch_filter_expected_t;
156 
157 /*!
158  * @brief TDET Glitch Filter Tamper Pull Select.
159  *
160  * These constants define tamper pin glitch filter pull direction to configure in a TDET base.
161  */
162 typedef enum _tdet_glitch_filter_pull
163 {
164     kTDET_GlitchFilterPullTypeAssert = 0U, /*!< Tamper pin pull direction always asserts the tamper pin. */
165     kTDET_GlitchFilterPullTypeNegate = 1U, /*!< Tamper pin pull direction always negates the tamper pin. */
166 } tdet_glitch_filter_pull_t;
167 
168 /*!
169  * @brief TDET Tamper Pin configuration registers.
170  *
171  * This structure defines values for TDET Pin Direction, Pin Polarity, and Glitch Filter registers.
172  */
173 typedef struct _tdet_pin_config
174 {
175     enum _tdet_pin_polarity pinPolarity;   /*!< Selects tamper pin expected value */
176     enum _tdet_pin_direction pinDirection; /*!< Selects tamper pin direction */
177     bool tamperPullEnable;                 /*!< Enable/disable pull resistor on the tamper pin */
178     enum _tdet_glitch_filter_sample_freq tamperPinSampleFrequency; /*!< Selects tamper pin sample frequency */
179     enum _tdet_glitch_filter_sample_width tamperPinSampleWidth;    /*!< Selects tamper pin sample width */
180     bool glitchFilterEnable; /*!< Enable/disable glitch filter on the tamper pin */
181     enum _tdet_glitch_filter_prescaler
182         glitchFilterPrescaler; /*!< Selects the prescaler for the glitch filter on tamper pin */
183 
184     uint8_t glitchFilterWidth; /*!< 6-bit value to configure number of clock edges the input must remain stable for to
185                                   be passed through the glitch filter for the tamper pin */
186 
187     enum _tdet_glitch_filter_expected tamperPinExpected; /*!< Selects tamper pin expected value */
188     enum _tdet_glitch_filter_pull tamperPullSelect;      /*!< Selects the direction of the tamper pin pull resistor */
189 } tdet_pin_config_t;
190 
191 /*! @brief List of TDET external tampers */
192 typedef enum _tdet_external_tamper_pin
193 {
194     kTDET_ExternalTamper0 = 1U << 0,
195     kTDET_ExternalTamper1 = 1U << 1,
196     kTDET_ExternalTamper2 = 1U << 2,
197     kTDET_ExternalTamper3 = 1U << 3,
198     kTDET_ExternalTamper4 = 1U << 4,
199     kTDET_ExternalTamper5 = 1U << 5,
200     kTDET_ExternalTamper6 = 1U << 6,
201     kTDET_ExternalTamper7 = 1U << 7
202 } tdet_external_tamper_pin_t;
203 
204 /*!
205  * @brief TDET Active Tamper Register Select.
206  *
207  * These constants are used to define activeTamperRegisterSelect argument to be used with
208  * TDET_ActiveTamperConfigure().
209  */
210 typedef enum _tdet_active_tamper_register
211 {
212     kTDET_ActiveTamperRegister0 = 1u << 0,
213     kTDET_ActiveTamperRegister1 = 1u << 1,
214 } tdet_active_tamper_register_t;
215 
216 /*!
217  * @brief TDET Active Tamper registers.
218  *
219  * This structure defines values for TDET Active Tamper Registers.
220  */
221 typedef struct _tdet_active_tamper_config
222 {
223     uint32_t activeTamperShift;      /*!< Active tamper shift register. initialize to non-zero value. */
224     uint32_t activeTamperPolynomial; /*!< Polynomial of the active tamper shift register. */
225 } tdet_active_tamper_config_t;
226 
227 /*!
228  * @brief TDET Status Register flags.
229  *
230  * This provides constants for the TDET Status Register.
231  */
232 typedef enum _tdet_status_flag
233 {
234     kTDET_StatusTamperFlag            = 1U << DIGTMP_SR_DTF_SHIFT,    /*!< TDET  Digital Tamper Flag */
235     kTDET_StatusTamperAcknowledgeFlag = 1U << DIGTMP_SR_TAF_SHIFT,    /*!< TDET Tamper Acknowledge Flag */
236     kTDET_StatusClockTamper           = 1U << DIGTMP_IER_TIIE0_SHIFT, /*!< TDET Clock Tamper detected */
237     kTDET_StatusConfigurationTamper   = 1U << DIGTMP_IER_TIIE1_SHIFT, /*!< TDET Configuration Tamper detected */
238     kTDET_StatusVoltageTamper         = 1U << DIGTMP_IER_TIIE2_SHIFT, /*!< TDET Voltage Tamper detected */
239     kTDET_StatusTemperatureTamper     = 1U << DIGTMP_IER_TIIE3_SHIFT, /*!< TDET Temperature Tamper detected */
240     kTDET_StatusRamZeroizeTamper      = 1U << DIGTMP_IER_TIIE6_SHIFT, /*!< TDET RAM Zeroize Tamper detected */
241     kTDET_StatusTamperPinTamper0      = 1U << DIGTMP_IER_TPIE0_SHIFT, /*!< TDET Tamper Pin 0 Tamper detected */
242     kTDET_StatusTamperPinTamper1      = 1U << DIGTMP_IER_TPIE1_SHIFT, /*!< TDET Tamper Pin 1 Tamper detected */
243     kTDET_StatusTamperPinTamper2      = 1U << DIGTMP_IER_TPIE2_SHIFT, /*!< TDET Tamper Pin 2 Tamper detected */
244     kTDET_StatusTamperPinTamper3      = 1U << DIGTMP_IER_TPIE3_SHIFT, /*!< TDET Tamper Pin 3 Tamper detected */
245     kTDET_StatusTamperPinTamper4      = 1U << DIGTMP_IER_TPIE4_SHIFT, /*!< TDET Tamper Pin 4 Tamper detected */
246     kTDET_StatusTamperPinTamper5      = 1U << DIGTMP_IER_TPIE5_SHIFT, /*!< TDET Tamper Pin 5 Tamper detected */
247     kTDET_StatusTamperPinTamper6      = 1U << DIGTMP_IER_TPIE6_SHIFT, /*!< TDET Tamper Pin 6 Tamper detected */
248     kTDET_StatusTamperPinTamper7      = 1U << DIGTMP_IER_TPIE7_SHIFT, /*!< TDET Tamper Pin 7 Tamper detected */
249     kTDET_StatusAll = DIGTMP_SR_DTF_MASK | DIGTMP_SR_TAF_MASK | DIGTMP_IER_TIIE0_MASK | DIGTMP_IER_TIIE1_MASK |
250                       DIGTMP_IER_TIIE2_MASK | DIGTMP_IER_TIIE3_MASK | DIGTMP_IER_TIIE6_MASK | DIGTMP_IER_TPIE0_MASK |
251                       DIGTMP_IER_TPIE1_MASK | DIGTMP_IER_TPIE2_MASK | DIGTMP_IER_TPIE3_MASK | DIGTMP_IER_TPIE4_MASK |
252                       DIGTMP_IER_TPIE5_MASK | DIGTMP_IER_TPIE6_MASK |
253                       DIGTMP_IER_TPIE7_MASK, /*!< Mask for all of the TDET Status Register bits */
254 } tdet_status_flag_t;
255 
256 /*!
257  * @brief TDET Interrupt Enable Register.
258  *
259  * This provides constants for the TDET Interrupt Enable Register.
260  */
261 typedef enum _tdet_interrupt
262 {
263     kTDET_InterruptTamper              = 1U << DIGTMP_IER_DTIE_SHIFT,  /*!< TDET Digital Tamper Interrupt  */
264     kTDET_InterruptClockTamper         = 1U << DIGTMP_IER_TIIE0_SHIFT, /*!< TDET Clock Tamper Interrupt */
265     kTDET_InterruptConfigurationTamper = 1U << DIGTMP_IER_TIIE1_SHIFT, /*!< TDET Configuration error */
266     kTDET_InterruptVoltageTamper       = 1U << DIGTMP_IER_TIIE2_SHIFT, /*!< TDET Voltage Tamper */
267     kTDET_InterruptTemperatureTamper   = 1U << DIGTMP_IER_TIIE3_SHIFT, /*!< TDET Temperature Tamper Interrupt */
268     kTDET_InterruptRamZeroizeTamper    = 1U << DIGTMP_IER_TIIE6_SHIFT, /*!< TDET RAM Zeroize Tamper Interrupt */
269     kTDET_InterruptTamperPinTamper0    = 1U << DIGTMP_IER_TPIE0_SHIFT, /*!< TDET Tamper Pin Tamper 0 Interrupt */
270     kTDET_InterruptTamperPinTamper1    = 1U << DIGTMP_IER_TPIE1_SHIFT, /*!< TDET Tamper Pin Tamper 1 Interrupt */
271     kTDET_InterruptTamperPinTamper2    = 1U << DIGTMP_IER_TPIE2_SHIFT, /*!< TDET Tamper Pin Tamper 2 Interrupt */
272     kTDET_InterruptTamperPinTamper3    = 1U << DIGTMP_IER_TPIE3_SHIFT, /*!< TDET Tamper Pin Tamper 3 Interrupt */
273     kTDET_InterruptTamperPinTamper4    = 1U << DIGTMP_IER_TPIE4_SHIFT, /*!< TDET Tamper Pin Tamper 4 Interrupt */
274     kTDET_InterruptTamperPinTamper5    = 1U << DIGTMP_IER_TPIE5_SHIFT, /*!< TDET Tamper Pin Tamper 5 Interrupt */
275     kTDET_InterruptTamperPinTamper6    = 1U << DIGTMP_IER_TPIE6_SHIFT, /*!< TDET Tamper Pin Tamper 6 Interrupt */
276     kTDET_InterruptTamperPinTamper7    = 1U << DIGTMP_IER_TPIE7_SHIFT, /*!< TDET Tamper Pin Tamper 7 Interrupt */
277     kTDET_InterruptTamperPinTamper_All = DIGTMP_IER_TPIE0_MASK | DIGTMP_IER_TPIE1_MASK | DIGTMP_IER_TPIE2_MASK |
278                                          DIGTMP_IER_TPIE3_MASK | DIGTMP_IER_TPIE4_MASK | DIGTMP_IER_TPIE5_MASK |
279                                          DIGTMP_IER_TPIE6_MASK |
280                                          DIGTMP_IER_TPIE7_MASK, /*!< TDET All Tamper Pins Interrupt */
281     kTDET_InterruptAll = DIGTMP_IER_DTIE_MASK | DIGTMP_IER_TIIE0_MASK | DIGTMP_IER_TIIE1_MASK | DIGTMP_IER_TIIE2_MASK |
282                          DIGTMP_IER_TIIE3_MASK | DIGTMP_IER_TIIE6_MASK | DIGTMP_IER_TPIE0_MASK | DIGTMP_IER_TPIE1_MASK |
283                          DIGTMP_IER_TPIE2_MASK | DIGTMP_IER_TPIE3_MASK | DIGTMP_IER_TPIE4_MASK | DIGTMP_IER_TPIE5_MASK |
284                          DIGTMP_IER_TPIE6_MASK |
285                          DIGTMP_IER_TPIE7_MASK, /*!< Mask to select all TDET Interrupt Enable Register bits */
286 } tdet_interrupt_t;
287 
288 /*!
289  * @brief TDET Tamper Enable Register.
290  *
291  * This provides constants for the TDET Tamper Enable Register.
292  */
293 typedef enum _tdet_tamper
294 {
295     kTDET_TamperClock         = 1U << DIGTMP_TER_TIE0_SHIFT, /*!< Clock Tamper Enable */
296     kTDET_TamperConfiguration = 1U << DIGTMP_TER_TIE1_SHIFT, /*!< Configuration error Tamper Enable */
297     kTDET_TamperVoltage       = 1U << DIGTMP_TER_TIE2_SHIFT, /*!< Voltage Tamper Enable */
298     kTDET_TamperTemperature   = 1U << DIGTMP_TER_TIE3_SHIFT, /*!< Temperature Tamper Enable */
299     kTDET_TamperRamZeroize    = 1U << DIGTMP_TER_TIE6_SHIFT, /*!< RAM Zeroize Tamper Enable */
300     kTDET_TamperTamperPin0    = 1U << DIGTMP_TER_TPE0_SHIFT, /*!< Tamper Pin 0 Tamper Enable */
301     kTDET_TamperTamperPin1    = 1U << DIGTMP_TER_TPE1_SHIFT, /*!< Tamper Pin 1 Tamper Enable */
302     kTDET_TamperTamperPin2    = 1U << DIGTMP_TER_TPE2_SHIFT, /*!< Tamper Pin 2 Tamper Enable */
303     kTDET_TamperTamperPin3    = 1U << DIGTMP_TER_TPE3_SHIFT, /*!< Tamper Pin 3 Tamper Enable */
304     kTDET_TamperTamperPin4    = 1U << DIGTMP_TER_TPE4_SHIFT, /*!< Tamper Pin 4 Tamper Enable */
305     kTDET_TamperTamperPin5    = 1U << DIGTMP_TER_TPE5_SHIFT, /*!< Tamper Pin 5 Tamper Enable */
306     kTDET_TamperTamperPin6    = 1U << DIGTMP_TER_TPE6_SHIFT, /*!< Tamper Pin 6 Tamper Enable */
307     kTDET_TamperTamperPin7    = 1U << DIGTMP_TER_TPE7_SHIFT, /*!< Tamper Pin 7 Tamper Enable */
308     kTDET_TamperTamperPinAll  = DIGTMP_TER_TPE0_MASK | DIGTMP_TER_TPE1_MASK | DIGTMP_TER_TPE2_MASK |
309                                DIGTMP_TER_TPE3_MASK | DIGTMP_TER_TPE4_MASK | DIGTMP_TER_TPE5_MASK |
310                                DIGTMP_TER_TPE6_MASK | DIGTMP_TER_TPE7_MASK, /*!< All Tamper Pin Tamper Enable */
311     kTDET_TamperAll = DIGTMP_TER_TIE0_MASK | DIGTMP_TER_TIE1_MASK | DIGTMP_TER_TIE2_MASK | DIGTMP_TER_TIE3_MASK |
312                       DIGTMP_TER_TIE6_MASK | DIGTMP_TER_TPE0_MASK | DIGTMP_TER_TPE1_MASK | DIGTMP_TER_TPE2_MASK |
313                       DIGTMP_TER_TPE3_MASK | DIGTMP_TER_TPE4_MASK | DIGTMP_TER_TPE5_MASK | DIGTMP_TER_TPE6_MASK |
314                       DIGTMP_TER_TPE7_MASK, /*!< Mask to select all Tamper Enable Register bits */
315 } tdet_tamper_t;
316 
317 /*!
318  * @brief TDET Registers.
319  *
320  * This provides constants to encode a mask for the TDET Registers.
321  */
322 typedef enum _tdet_register
323 {
324     kTDET_NoRegister      = 0U,                         /*!< No Register */
325     kTDET_Control         = 1U << DIGTMP_LR_CRL_SHIFT,  /*!< Control Register */
326     kTDET_Status          = 1U << DIGTMP_LR_SRL_SHIFT,  /*!< Status Register */
327     kTDET_Lock            = 1U << DIGTMP_LR_LRL_SHIFT,  /*!< Lock Register */
328     kTDET_InterruptEnable = 1U << DIGTMP_LR_IEL_SHIFT,  /*!< Interrupt Enable Register */
329     kTDET_TamperSeconds   = 1U << DIGTMP_LR_TSL_SHIFT,  /*!< Tamper Seconds Register */
330     kTDET_TamperEnable    = 1U << DIGTMP_LR_TEL_SHIFT,  /*!< Tamper Enable Register */
331     kTDET_PinDirection    = 1U << DIGTMP_LR_PDL_SHIFT,  /*!< Pin Direction Register */
332     kTDET_PinPolarity     = 1U << DIGTMP_LR_PPL_SHIFT,  /*!< Pin Polarity Register */
333     kTDET_ActiveTamper0   = 1U << DIGTMP_LR_ATL0_SHIFT, /*!< Active Tamper Register 0 */
334     kTDET_ActiveTamper1   = 1U << DIGTMP_LR_ATL1_SHIFT, /*!< Active Tamper Register 1 */
335     kTDET_GlitchFilter0   = 1U << DIGTMP_LR_GFL0_SHIFT, /*!< Glitch Filter Register 0 */
336     kTDET_GlitchFilter1   = 1U << DIGTMP_LR_GFL1_SHIFT, /*!< Glitch Filter Register 1 */
337     kTDET_GlitchFilter2   = 1U << DIGTMP_LR_GFL2_SHIFT, /*!< Glitch Filter Register 2 */
338     kTDET_GlitchFilter3   = 1U << DIGTMP_LR_GFL3_SHIFT, /*!< Glitch Filter Register 3 */
339     kTDET_GlitchFilter4   = 1U << DIGTMP_LR_GFL4_SHIFT, /*!< Glitch Filter Register 4 */
340     kTDET_GlitchFilter5   = 1U << DIGTMP_LR_GFL5_SHIFT, /*!< Glitch Filter Register 5 */
341     kTDET_GlitchFilter6   = 1U << DIGTMP_LR_GFL6_SHIFT, /*!< Glitch Filter Register 6 */
342     kTDET_GlitchFilter7   = 1U << DIGTMP_LR_GFL7_SHIFT, /*!< Glitch Filter Register 7 */
343     kTDET_PinConfigurationRegisters =
344         DIGTMP_LR_PDL_MASK | DIGTMP_LR_PPL_MASK | DIGTMP_LR_ATL0_MASK | DIGTMP_LR_ATL1_MASK | DIGTMP_LR_GFL0_MASK |
345         DIGTMP_LR_GFL1_MASK | DIGTMP_LR_GFL2_MASK | DIGTMP_LR_GFL3_MASK | DIGTMP_LR_GFL4_MASK | DIGTMP_LR_GFL5_MASK |
346         DIGTMP_LR_GFL6_MASK | DIGTMP_LR_GFL7_MASK, /*!< Mask to select all TDET Pin Configuration Registers */
347     kTDET_AllRegisters = DIGTMP_LR_CRL_MASK | DIGTMP_LR_SRL_MASK | DIGTMP_LR_LRL_MASK | DIGTMP_LR_IEL_MASK |
348                          DIGTMP_LR_TSL_MASK | DIGTMP_LR_TEL_MASK | DIGTMP_LR_PDL_MASK | DIGTMP_LR_PPL_MASK |
349                          DIGTMP_LR_ATL0_MASK | DIGTMP_LR_ATL1_MASK | DIGTMP_LR_GFL0_MASK | DIGTMP_LR_GFL1_MASK |
350                          DIGTMP_LR_GFL2_MASK | DIGTMP_LR_GFL3_MASK | DIGTMP_LR_GFL4_MASK | DIGTMP_LR_GFL5_MASK |
351                          DIGTMP_LR_GFL6_MASK | DIGTMP_LR_GFL7_MASK, /*!< Mask to select all TDET Registers */
352 } tdet_register_t;
353 
354 /*******************************************************************************
355  * API
356  *******************************************************************************/
357 extern void VBAT0_DriverIRQHandler(void);
358 
359 #if defined(__cplusplus)
360 extern "C" {
361 #endif /* __cplusplus */
362 
363 /*!
364  * @name TDET Functional Operation
365  * @{
366  */
367 
368 /*!
369  * @brief Initialize TDET
370  *
371  * This function initializes TDET.
372  *
373  * @param base TDET peripheral base address
374  * @return Status of the init operation
375  */
376 status_t TDET_Init(DIGTMP_Type *base);
377 
378 /*!
379  * @brief Deinitialize TDET
380  *
381  * This function disables glitch filters and active tampers
382  * This function disables the TDET clock and prescaler in TDET Control Register.
383  * @param base TDET peripheral base address
384  */
385 void TDET_Deinit(DIGTMP_Type *base);
386 
387 /*!
388  * @brief Gets default values for the TDET Control Register.
389  *
390  * This function fills the given structure with default values for the TDET Control Register.
391  * The default values are:
392  * @code
393  *     defaultConfig->innerClockAndPrescalerEnable = true
394  *     defaultConfig->tamperForceSystemResetEnable = false
395  *     defaultConfig->updateMode = kTDET_StatusLockWithTamper
396  *     defaultConfig->clockSourceActiveTamper0 = kTDET_ClockType1Hz
397  *     defaultConfig->clockSourceActiveTamper1 = kTDET_ClockType1Hz
398  *     defaultConfig->prescaler = 0
399  * @endcode
400  * @param base TDET peripheral base address
401  * @param[out] defaultConfig Pointer to structure to be filled with default parameters
402  */
403 void TDET_GetDefaultConfig(DIGTMP_Type *base, tdet_config_t *defaultConfig);
404 
405 /*!
406  * @brief Writes to the TDET Control Register.
407  *
408  * This function writes the given structure to the TDET Control Register.
409  * @param base TDET peripheral base address
410  * @param config Pointer to structure with TDET peripheral configuration parameters
411  * @return kStatus_Fail when writing to TDET Control Register is not allowed
412  * @return kStatus_Success when operation completes successfully
413  */
414 status_t TDET_SetConfig(DIGTMP_Type *base, const tdet_config_t *config);
415 
416 /*!
417  * @brief Software reset.
418  *
419  * This function resets all TDET registers. The CR[SWR] itself is not affected;
420  * it is reset by VBAT POR only.
421  *
422  * @param base TDET peripheral base address
423  * @return kStatus_Fail when writing to TDET Control Register is not allowed
424  * @return kStatus_Success when operation completes successfully
425  */
426 status_t TDET_SoftwareReset(DIGTMP_Type *base);
427 
428 /*!
429  * @brief Writes to the active tamper register(s).
430  *
431  * This function writes per active tamper register parameters to active tamper register(s).
432  *
433  * @param base TDET peripheral base address
434  * @param activeTamperConfig Pointer to structure with active tamper register parameters
435  * @param activeTamperRegisterSelect Bit mask for active tamper registers to be configured. The passed value is
436  *                                   combination of tdet_active_tamper_register_t values (OR'ed).
437  * @return kStatus_Fail when writing to TDET Active Tamper Register(s) is not allowed
438  * @return kStatus_Success when operation completes successfully
439  */
440 status_t TDET_ActiveTamperSetConfig(DIGTMP_Type *base,
441                                     const tdet_active_tamper_config_t *activeTamperConfig,
442                                     uint32_t activeTamperRegisterSelect);
443 
444 /*!
445  * @brief Gets default values for tamper pin configuration.
446  *
447  * This function fills the give structure with default values for the tamper pin and glitch filter configuration.
448  * The default values are:
449  * code
450  *     pinConfig->pinPolarity = kTDET_TamperPinPolarityExpectNormal;
451  *     pinConfig->pinDirection = kTDET_TamperPinDirectionIn;
452  *     pinConfig->tamperPullEnable = false;
453  *     pinConfig->tamperPinSampleFrequency = kTDET_GlitchFilterSamplingEveryCycle8;
454  *     pinConfig->tamperPinSampleWidth = kTDET_GlitchFilterSampleDisable;
455  *     pinConfig->glitchFilterEnable = false;
456  *     pinConfig->glitchFilterPrescaler = kTDET_GlitchFilterClock512Hz;
457  *     pinConfig->glitchFilterWidth = 0;
458  *     pinConfig->tamperPinExpected = kTDET_GlitchFilterExpectedLogicZero;
459  *     pinConfig->tamperPullSelect = kTDET_GlitchFilterPullTypeAssert;
460  * endcode
461  *
462  * @param base TDET peripheral base address
463  * @param[out] pinConfig Pointer to structure to be filled with tamper pins default parameters
464  */
465 
466 void TDET_PinGetDefaultConfig(DIGTMP_Type *base, tdet_pin_config_t *pinConfig);
467 
468 /*!
469  * @brief Writes the tamper pin configuration.
470  *
471  * This function writes per pin parameters to tamper pin and glitch filter configuration registers.
472  *
473  * @param base TDET peripheral base address
474  * @param pinConfig Pointer to structure with tamper pin and glitch filter configuration parameters
475  * @param pinSelect Bit mask for tamper pins to be configured. The passed value is combination of
476  *                  enum _tdet_tamper_pin (tdet_tamper_pin_t) values (OR'ed).
477  * @return kStatus_Fail when writing to TDET Pin Direction, Pin Polarity or Glitch Filter Register(s) is not allowed
478  * @return kStatus_Success when operation completes successfully
479  */
480 status_t TDET_PinSetConfig(DIGTMP_Type *base, const tdet_pin_config_t *pinConfig, uint32_t pinSelect);
481 
482 /*!
483  * @brief Reads the Status Register.
484  *
485  * This function reads flag bits from TDET Status Register.
486  *
487  * @param base TDET peripheral base address
488  * @param[out] result Pointer to uint32_t where to write Status Register read value. Use tdet_status_flag_t to decode
489  *                    individual flags.
490  * @return kStatus_Fail when Status Register reading is not allowed
491  * @return kStatus_Success when result is written with the Status Register read value
492  */
493 status_t TDET_GetStatusFlags(DIGTMP_Type *base, uint32_t *result);
494 
495 /*!
496  * @brief Writes to the Status Register.
497  *
498  * This function clears specified flag bits in TDET Status Register.
499  *
500  * @param base TDET peripheral base address
501  * @param mask Bit mask for the flag bits to be cleared. Use tdet_status_flag_t to encode flags.
502  * @return kStatus_Fail when Status Register writing is not allowed
503  * @return kStatus_Success when mask is written to the Status Register
504  */
505 status_t TDET_ClearStatusFlags(DIGTMP_Type *base, uint32_t mask);
506 
507 /*!
508  * @brief Writes to the Interrupt Enable Register.
509  *
510  * This function sets specified interrupt enable bits in TDET Interrupt Enable Register.
511  *
512  * @param base TDET peripheral base address
513  * @param mask Bit mask for the interrupt enable bits to be set.
514  * @return kStatus_Fail when Interrupt Enable Register writing is not allowed
515  * @return kStatus_Success when mask is written to the Interrupt Enable Register
516  */
517 status_t TDET_EnableInterrupts(DIGTMP_Type *base, uint32_t mask);
518 
519 /*!
520  * @brief Writes to the Interrupt Enable Register.
521  *
522  * This function clears specified interrupt enable bits in TDET Interrupt Enable Register.
523  *
524  * @param base TDET peripheral base address
525  * @param mask Bit mask for the interrupt enable bits to be cleared.
526  * @return kStatus_Fail when Interrupt Enable Register writing is not allowed
527  * @return kStatus_Success when specified bits are cleared in the Interrupt Enable Register
528  */
529 status_t TDET_DisableInterrupts(DIGTMP_Type *base, uint32_t mask);
530 
531 /*!
532  * @brief Writes to the Tamper Enable Register.
533  *
534  * This function sets specified tamper enable bits in TDET Tamper Enable Register.
535  *
536  * @param base TDET peripheral base address
537  * @param mask Bit mask for the tamper enable bits to be set.
538  * @return kStatus_Fail when Tamper Enable Register writing is not allowed
539  * @return kStatus_Success when mask is written to the Tamper Enable Register
540  */
541 status_t TDET_EnableTampers(DIGTMP_Type *base, uint32_t mask);
542 
543 /*!
544  * @brief Writes to the Tamper Enable Register.
545  *
546  * This function clears specified tamper enable bits in TDET Tamper Enable Register.
547  *
548  * @param base TDET peripheral base address
549  * @param mask Bit mask for the tamper enable bits to be cleared.
550  * @return kStatus_Fail when Tamper Enable Register writing is not allowed
551  * @return kStatus_Success when specified bits are cleared in the Tamper Enable Register
552  */
553 status_t TDET_DisableTampers(DIGTMP_Type *base, uint32_t mask);
554 
555 /*!
556  * @brief Writes to the Tamper Seconds Register.
557  *
558  * This function writes to TDET Tamper Seconds Register. This causes Status Register DTF flag to be set (TDET
559  * tampering detected).
560  *
561  * @param base TDET peripheral base address
562  * @return kStatus_Fail when Tamper Seconds Register writing is not allowed
563  * @return kStatus_Success when Tamper Seconds Register is written
564  */
565 status_t TDET_ForceTamper(DIGTMP_Type *base);
566 
567 /*!
568  * @brief Reads the Tamper Seconds Register.
569  *
570  * This function reads TDET Tamper Seconds Register. The read value returns the time in seconds at which the Status
571  * Register DTF flag was set.
572  *
573  * @param base TDET peripheral base address
574  * @param tamperTimeSeconds Time in seconds at which the tamper detection SR[DTF] flag was set.
575  * @return kStatus_Fail when Tamper Seconds Register reading is not allowed
576  * @return kStatus_Success when Tamper Seconds Register is read
577  */
578 status_t TDET_GetTamperTimeSeconds(DIGTMP_Type *base, uint32_t *tamperTimeSeconds);
579 
580 /*!
581  * @brief Writes to the TDET Lock Register.
582  *
583  * This function clears specified lock bits in the TDET Lock Register.
584  * When a lock bit is clear, a write to corresponding TDET Register is ignored.
585  * Once cleared, these bits can only be set by VBAT POR or software reset.
586  *
587  * @param base TDET peripheral base address
588  * @param mask Bit mask for the lock bits to be cleared. Use tdet_register_t values to encode (OR'ed) which TDET
589  * Registers shall be locked.
590  */
591 void TDET_LockRegisters(DIGTMP_Type *base, uint32_t mask);
592 
593 /*! @}*/
594 
595 #if defined(__cplusplus)
596 }
597 #endif /* __cplusplus */
598 
599 /*! @}*/ /* end of group tdet */
600 
601 #endif /* FSL_TDET_H_ */
602