1 /*
2  * Copyright 2023 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #include "fsl_tdet.h"
9 
10 /*******************************************************************************
11  * Definitions
12  *******************************************************************************/
13 
14 /* Component ID definition, used by tools. */
15 #ifndef FSL_COMPONENT_ID
16 #define FSL_COMPONENT_ID "platform.drivers.tdet"
17 #endif
18 
19 /* all bits defined in the LOCK Register. */
20 #define TDET_ALL_LC_MASK 0x00FF3FF0u
21 
22 /* all bits defined in the Interrupt Enable Register. */
23 #define TDET_ALL_IER_MASK 0x00FF03FDu
24 
25 /* all bits defined in the Tamper Enable Register. */
26 #define TDET_ALL_TER_MASK 0x00FF0FFCu
27 
28 /*******************************************************************************
29  * Prototypes
30  ******************************************************************************/
31 
32 /*******************************************************************************
33  * Code
34  ******************************************************************************/
35 
36 /*!
37  * Weak implementation of TDET IRQ, should be re-defined by user when using TDET IRQ
38  */
VBAT0_DriverIRQHandler(void)39 __WEAK void VBAT0_DriverIRQHandler(void)
40 {
41     /* TDET generates IRQ until corresponding bit in STATUS is cleared by calling
42      * TDET_ClearStatusFlags(TDET0,kTDET_StatusAll);
43      * which clear all bits or kTDET_StatusXXX to clear only one bit
44      */
45 }
46 
tdet_IsRegisterWriteAllowed(DIGTMP_Type * base,uint32_t mask)47 static bool tdet_IsRegisterWriteAllowed(DIGTMP_Type *base, uint32_t mask)
48 {
49     bool retval;
50 
51     retval = false;
52     mask   = mask & TDET_ALL_LC_MASK;
53 
54     /* specified LR bit(s) must be set */
55     if (mask == (mask & base->LR))
56     {
57         retval = true;
58     }
59     return retval;
60 }
61 
tdet_PinConfigure(DIGTMP_Type * base,const tdet_pin_config_t * pinConfig,uint32_t pin)62 static status_t tdet_PinConfigure(DIGTMP_Type *base, const tdet_pin_config_t *pinConfig, uint32_t pin)
63 {
64     uint32_t temp;
65     uint32_t mask;
66     status_t status;
67 
68     if ((tdet_IsRegisterWriteAllowed(
69             base, DIGTMP_LR_PDL_MASK | DIGTMP_LR_PPL_MASK | (((uint32_t)1u << DIGTMP_LR_GFL0_SHIFT) << pin))) &&
70         (pinConfig != NULL))
71     {
72         /* pin 0 to 7 selects bit0 to bit7 */
73         mask = ((uint32_t)1u << pin);
74 
75         /* Pin Direction Register */
76         temp = base->PDR;
77         temp &= ~mask; /* clear the bit */
78         if (kTDET_TamperPinDirectionOut == pinConfig->pinDirection)
79         {
80             temp |= mask; /* set the bit, if configured */
81         }
82         base->PDR = temp;
83 
84         /* Pin Polarity Register */
85         temp = base->PPR;
86         temp &= ~mask; /* clear the bit */
87         if (kTDET_TamperPinPolarityExpectInverted == pinConfig->pinPolarity)
88         {
89             temp |= mask; /* set the bit, if configured */
90         }
91         base->PPR = temp;
92 
93         /* compute and set the configured value to the glitch filter register */
94         temp = 0;
95         temp |= DIGTMP_PGFR_GFW(pinConfig->glitchFilterWidth);
96         temp |= DIGTMP_PGFR_GFP(pinConfig->glitchFilterPrescaler);
97         temp |= DIGTMP_PGFR_TPSW(pinConfig->tamperPinSampleWidth);
98         temp |= DIGTMP_PGFR_TPSF(pinConfig->tamperPinSampleFrequency);
99         temp |= DIGTMP_PGFR_TPEX(pinConfig->tamperPinExpected);
100         temp |= DIGTMP_PGFR_TPE(pinConfig->tamperPullEnable);
101         temp |= DIGTMP_PGFR_TPS(pinConfig->tamperPullSelect);
102         /* make sure the glitch filter is disabled when we configure glitch filter width */
103         base->PGFR[pin] = temp;
104         /* add glitch filter enabled */
105         if (pinConfig->glitchFilterEnable)
106         {
107             temp |= DIGTMP_PGFR_GFE(1u);
108             base->PGFR[pin] = temp;
109         }
110         status = kStatus_Success;
111     }
112     else
113     {
114         status = kStatus_Fail;
115     }
116 
117     return status;
118 }
119 
tdet_ActiveTamperConfigure(DIGTMP_Type * base,const tdet_active_tamper_config_t * activeTamperConfig,uint32_t activeTamperRegister)120 static status_t tdet_ActiveTamperConfigure(DIGTMP_Type *base,
121                                            const tdet_active_tamper_config_t *activeTamperConfig,
122                                            uint32_t activeTamperRegister)
123 {
124     uint32_t temp;
125     status_t status;
126 
127     /* check if writing to active tamper register is allowed */
128     if ((tdet_IsRegisterWriteAllowed(base, ((uint32_t)1u << DIGTMP_LR_ATL0_SHIFT) << activeTamperRegister)) &&
129         (activeTamperConfig != NULL))
130     {
131         /* compute and set the configured value to the active tamper register */
132         temp = 0;
133         temp |= DIGTMP_ATR_ATSR(activeTamperConfig->activeTamperShift);
134         temp |= DIGTMP_ATR_ATP(activeTamperConfig->activeTamperPolynomial);
135         base->ATR[activeTamperRegister] = temp;
136         status                          = kStatus_Success;
137     }
138     else
139     {
140         status = kStatus_Fail;
141     }
142 
143     return status;
144 }
145 
146 /*!
147  * brief Initialize TDET
148  *
149  * This function initializes TDET.
150  *
151  * param base TDET peripheral base address
152  * return Status of the init operation
153  */
TDET_Init(DIGTMP_Type * base)154 status_t TDET_Init(DIGTMP_Type *base)
155 {
156     return kStatus_Success;
157 }
158 
159 /*!
160  * brief Deinitialize TDET
161  *
162  * This function disables glitch filters and active tampers
163  * This function disables the TDET clock and prescaler in TDET Control Register.
164  * param base TDET peripheral base address
165  */
TDET_Deinit(DIGTMP_Type * base)166 void TDET_Deinit(DIGTMP_Type *base)
167 {
168     uint32_t i, j, k;
169     j = ARRAY_SIZE(base->PGFR);
170     k = ARRAY_SIZE(base->ATR);
171     /* disable all glitch filters and active tampers */
172     for (i = 0; i < j; i++)
173     {
174         base->PGFR[i] = 0;
175     }
176     for (i = 0; i < k; i++)
177     {
178         base->ATR[i] = 0;
179     }
180 
181     /* disable inner TDET clock and prescaler */
182     base->CR &= ~DIGTMP_CR_DEN_MASK;
183 }
184 
185 /*!
186  * brief Gets default values for the TDET Control Register.
187  *
188  * This function fills the given structure with default values for the TDET Control Register.
189  * The default values are:
190  * code
191  *     defaultConfig->innerClockAndPrescalerEnable = true
192  *     defaultConfig->tamperForceSystemResetEnable = false
193  *     defaultConfig->updateMode = kTDET_StatusLockWithTamper
194  *     defaultConfig->clockSourceActiveTamper0 = kTDET_ClockType1Hz
195  *     defaultConfig->clockSourceActiveTamper1 = kTDET_ClockType1Hz
196  *     defaultConfig->disablePrescalerAfterTamper = false
197  *     defaultConfig->prescaler = 0
198  * endcode
199  * param base TDET peripheral base address
200  * param[out] defaultConfig Pointer to structure to be filled with default parameters
201  */
TDET_GetDefaultConfig(DIGTMP_Type * base,tdet_config_t * defaultConfig)202 void TDET_GetDefaultConfig(DIGTMP_Type *base, tdet_config_t *defaultConfig)
203 {
204     /* Initializes the configure structure to zero. */
205     (void)memset(defaultConfig, 0, sizeof(*defaultConfig));
206 
207     struct _tdet_config myDefaultConfig = {
208         true,                       /* innerClockAndPrescalerEnable */
209         false,                      /* tamperForceSystemResetEnable */
210         kTDET_StatusLockWithTamper, /* updateMode */
211         kTDET_ClockType1Hz,         /* clockSourceActiveTamper0 */
212         kTDET_ClockType1Hz,         /* clockSourceActiveTamper1 */
213         false,                      /* disable prescaler on tamper event */
214         0,                          /* prescaler */
215     };
216 
217     *defaultConfig = myDefaultConfig;
218 }
219 
220 /*!
221  * brief Writes to the TDET Control Register.
222  *
223  * This function writes the given structure to the TDET Control Register.
224  * param base TDET peripheral base address
225  * param config Pointer to structure with TDET peripheral configuration parameters
226  * return kStatus_Fail when writing to TDET Control Register is not allowed
227  * return kStatus_Success when operation completes successfully
228  */
TDET_SetConfig(DIGTMP_Type * base,const tdet_config_t * config)229 status_t TDET_SetConfig(DIGTMP_Type *base, const tdet_config_t *config)
230 {
231     uint32_t tmpCR;
232 
233     status_t retval = kStatus_Fail;
234 
235     /* check if writing to CR is allowed */
236     if ((tdet_IsRegisterWriteAllowed(base, DIGTMP_LR_CRL_MASK)) && (config != NULL))
237     {
238         /* compute CR value */
239         tmpCR = 0;
240         tmpCR |= DIGTMP_CR_TFSR(config->tamperForceSystemResetEnable);
241         tmpCR |= DIGTMP_CR_UM(config->updateMode);
242         tmpCR |= DIGTMP_CR_ATCS0(config->clockSourceActiveTamper0);
243         tmpCR |= DIGTMP_CR_ATCS1(config->clockSourceActiveTamper1);
244         tmpCR |= DIGTMP_CR_DISTAM(config->disablePrescalerAfterTamper);
245         tmpCR |= DIGTMP_CR_DPR(config->prescaler);
246         /* write the computed value to the CR register */
247         base->CR = tmpCR;
248         /* after the prescaler is written to CR register, enable the inner TDET clock and prescaler */
249         if (config->innerClockAndPrescalerEnable)
250         {
251             base->CR = tmpCR | DIGTMP_CR_DEN_MASK;
252         }
253         retval = kStatus_Success;
254     }
255     else
256     {
257         retval = kStatus_Fail;
258     }
259 
260     return retval;
261 }
262 
263 /*!
264  * brief Software reset.
265  *
266  * This function resets all TDET registers. The CR[SWR] itself is not affected;
267  * it is reset by VBAT POR only.
268  *
269  * param base TDET peripheral base address
270  * return kStatus_Fail when writing to TDET Control Register is not allowed
271  * return kStatus_Success when operation completes successfully
272  */
TDET_SoftwareReset(DIGTMP_Type * base)273 status_t TDET_SoftwareReset(DIGTMP_Type *base)
274 {
275     status_t retval = kStatus_Fail;
276 
277     /* check if writing to CR is allowed */
278     if (tdet_IsRegisterWriteAllowed(base, DIGTMP_LR_CRL_MASK))
279     {
280         /* set the CR[SWR] */
281         base->CR = DIGTMP_CR_SWR_MASK;
282         retval   = kStatus_Success;
283     }
284     else
285     {
286         retval = kStatus_Fail;
287     }
288 
289     return retval;
290 }
291 
292 /*!
293  * brief Writes to the active tamper register(s).
294  *
295  * This function writes per active tamper register parameters to active tamper register(s).
296  *
297  * param base TDET peripheral base address
298  * param activeTamperConfig Pointer to structure with active tamper register parameters
299  * param activeTamperRegisterSelect Bit mask for active tamper registers to be configured. The passed value is
300  *                                   combination of tdet_active_tamper_register_t values (OR'ed).
301  * return kStatus_Fail when writing to TDET Active Tamper Register(s) is not allowed
302  * return kStatus_Success when operation completes successfully
303  */
TDET_ActiveTamperSetConfig(DIGTMP_Type * base,const tdet_active_tamper_config_t * activeTamperConfig,uint32_t activeTamperRegisterSelect)304 status_t TDET_ActiveTamperSetConfig(DIGTMP_Type *base,
305                                     const tdet_active_tamper_config_t *activeTamperConfig,
306                                     uint32_t activeTamperRegisterSelect)
307 {
308     uint32_t mask;
309     status_t status;
310     uint32_t i, j;
311 
312     mask   = 1u;
313     status = kStatus_Success;
314     j      = ARRAY_SIZE(base->ATR);
315     /* configure active tamper register by active tamper register, by moving through all active tamper registers */
316     for (i = 0; i < j; i++)
317     {
318         if ((activeTamperRegisterSelect & mask) != 0U)
319         {
320             /* configure this active tamper register */
321             status = tdet_ActiveTamperConfigure(base, activeTamperConfig, i);
322             if (status != kStatus_Success)
323             {
324                 break;
325             }
326         }
327         mask = mask << 1u;
328     }
329 
330     return status;
331 }
332 
333 /*!
334  * brief Gets default values for tamper pin configuration.
335  *
336  * This function fills the give structure with default values for the tamper pin and glitch filter configuration.
337  * The default values are:
338  * code
339  *     pinConfig->pinPolarity = kTDET_TamperPinPolarityExpectNormal;
340  *     pinConfig->pinDirection = kTDET_TamperPinDirectionIn;
341  *     pinConfig->tamperPullEnable = false;
342  *     pinConfig->tamperPinSampleFrequency = kTDET_GlitchFilterSamplingEveryCycle8;
343  *     pinConfig->tamperPinSampleWidth = kTDET_GlitchFilterSampleDisable;
344  *     pinConfig->glitchFilterEnable = false;
345  *     pinConfig->glitchFilterPrescaler = kTDET_GlitchFilterClock512Hz;
346  *     pinConfig->glitchFilterWidth = 0;
347  *     pinConfig->tamperPinExpected = kTDET_GlitchFilterExpectedLogicZero;
348  *     pinConfig->tamperPullSelect = kTDET_GlitchFilterPullTypeAssert;
349  * endcode
350  *
351  * param base TDET peripheral base address
352  * param[out] pinConfig Pointer to structure to be filled with tamper pins default parameters
353  */
TDET_PinGetDefaultConfig(DIGTMP_Type * base,tdet_pin_config_t * pinConfig)354 void TDET_PinGetDefaultConfig(DIGTMP_Type *base, tdet_pin_config_t *pinConfig)
355 {
356     /* Initializes the configure structure to zero. */
357     (void)memset(pinConfig, 0, sizeof(*pinConfig));
358 
359     struct _tdet_pin_config myPinDefaultConfig = {
360         kTDET_TamperPinPolarityExpectNormal,   /* pinPolarity */
361         kTDET_TamperPinDirectionIn,            /* pinDirection */
362         false,                                 /* tamperPullEnable */
363         kTDET_GlitchFilterSamplingEveryCycle8, /* tamperPinSampleFrequency */
364         kTDET_GlitchFilterSampleDisable,       /* tamperPinSampleWidth */
365         false,                                 /* glitchFilterEnable */
366         kTDET_GlitchFilterClock512Hz,          /* glitchFilterPrescaler */
367         0,                                     /* glitchFilterWidth */
368         kTDET_GlitchFilterExpectedLogicZero,   /* tamperPinExpected */
369         kTDET_GlitchFilterPullTypeAssert,      /* tamperPullSelect */
370     };
371 
372     *pinConfig = myPinDefaultConfig;
373 }
374 
375 /*!
376  * brief Writes the tamper pin configuration.
377  *
378  * This function writes per pin parameters to tamper pin and glitch filter configuration registers.
379  *
380  * param base TDET peripheral base address
381  * param pinConfig Pointer to structure with tamper pin and glitch filter configuration parameters
382  * param pinSelect Bit mask for tamper pins to be configured. The passed value is combination of
383  *                  enum _tdet_external_tamper_pin (tdet_external_tamper_pin_t) values (OR'ed).
384  * return kStatus_Fail when writing to TDET Pin Direction, Pin Polarity or Glitch Filter Register(s) is not allowed
385  * return kStatus_Success when operation completes successfully
386  */
TDET_PinSetConfig(DIGTMP_Type * base,const tdet_pin_config_t * pinConfig,uint32_t pinSelect)387 status_t TDET_PinSetConfig(DIGTMP_Type *base, const tdet_pin_config_t *pinConfig, uint32_t pinSelect)
388 {
389     uint32_t mask;
390     status_t status;
391     uint32_t i, j;
392 
393     mask   = 1u;
394     status = kStatus_Success;
395     j      = ARRAY_SIZE(base->PGFR);
396     /* configure pin by pin, by moving through all selected pins */
397     for (i = 0; i < j; i++)
398     {
399         if ((pinSelect & mask) != 0U)
400         {
401             /* clear this pin from pinSelect */
402             pinSelect &= ~mask;
403 
404             /* configure this pin */
405             status = tdet_PinConfigure(base, pinConfig, i);
406 
407             /* if pinSelect is zero, we have configured all pins selected by pinSelect, so skip */
408             if ((status != kStatus_Success) || (0U == pinSelect))
409             {
410                 break;
411             }
412         }
413         mask = mask << 1u;
414     }
415 
416     return status;
417 }
418 
419 /*!
420  * brief Reads the Status Register.
421  *
422  * This function reads flag bits from TDET Status Register.
423  *
424  * param base TDET peripheral base address
425  * param[out] result Pointer to uint32_t where to write Status Register read value. Use tdet_status_flag_t to decode
426  *                    individual flags.
427  * return kStatus_Fail when Status Register reading is not allowed
428  * return kStatus_Success when result is written with the Status Register read value
429  */
TDET_GetStatusFlags(DIGTMP_Type * base,uint32_t * result)430 status_t TDET_GetStatusFlags(DIGTMP_Type *base, uint32_t *result)
431 {
432     status_t status;
433 
434     if (result != NULL)
435     {
436         *result = base->SR;
437         status  = kStatus_Success;
438     }
439     else
440     {
441         status = kStatus_Fail;
442     }
443 
444     return status;
445 }
446 
447 /*!
448  * brief Writes to the Status Register.
449  *
450  * This function clears specified flag bits in TDET Status Register.
451  *
452  * param base TDET peripheral base address
453  * param mask Bit mask for the flag bits to be cleared. Use tdet_status_flag_t to encode flags.
454  * return kStatus_Fail when Status Register writing is not allowed
455  * return kStatus_Success when mask is written to the Status Register
456  */
TDET_ClearStatusFlags(DIGTMP_Type * base,uint32_t mask)457 status_t TDET_ClearStatusFlags(DIGTMP_Type *base, uint32_t mask)
458 {
459     status_t status;
460 
461     if (tdet_IsRegisterWriteAllowed(base, DIGTMP_LR_SRL_MASK))
462     {
463         base->SR = mask;
464         status   = kStatus_Success;
465     }
466     else
467     {
468         status = kStatus_Fail;
469     }
470 
471     return status;
472 }
473 
474 /*!
475  * brief Writes to the Interrupt Enable Register.
476  *
477  * This function sets specified interrupt enable bits in TDET Interrupt Enable Register.
478  *
479  * param base TDET peripheral base address
480  * param mask Bit mask for the interrupt enable bits to be set.
481  * return kStatus_Fail when Interrupt Enable Register writing is not allowed
482  * return kStatus_Success when mask is written to the Interrupt Enable Register
483  */
TDET_EnableInterrupts(DIGTMP_Type * base,uint32_t mask)484 status_t TDET_EnableInterrupts(DIGTMP_Type *base, uint32_t mask)
485 {
486     status_t status;
487 
488     mask = mask & TDET_ALL_IER_MASK; /* only set the bits documented in Reference Manual. */
489     if (tdet_IsRegisterWriteAllowed(base, DIGTMP_LR_IEL_MASK))
490     {
491         base->IER |= mask;
492         status = kStatus_Success;
493     }
494     else
495     {
496         status = kStatus_Fail;
497     }
498 
499     return status;
500 }
501 
502 /*!
503  * brief Writes to the Interrupt Enable Register.
504  *
505  * This function clears specified interrupt enable bits in TDET Interrupt Enable Register.
506  *
507  * param base TDET peripheral base address
508  * param mask Bit mask for the interrupt enable bits to be cleared.
509  * return kStatus_Fail when Interrupt Enable Register writing is not allowed
510  * return kStatus_Success when specified bits are cleared in the Interrupt Enable Register
511  */
TDET_DisableInterrupts(DIGTMP_Type * base,uint32_t mask)512 status_t TDET_DisableInterrupts(DIGTMP_Type *base, uint32_t mask)
513 {
514     status_t status;
515 
516     mask = mask & TDET_ALL_IER_MASK; /* only clear the bits documented in Reference Manual.  */
517     if (tdet_IsRegisterWriteAllowed(base, DIGTMP_LR_IEL_MASK))
518     {
519         base->IER &= ~mask;
520         status = kStatus_Success;
521     }
522     else
523     {
524         status = kStatus_Fail;
525     }
526 
527     return status;
528 }
529 
530 /*!
531  * brief Writes to the Tamper Enable Register.
532  *
533  * This function sets specified tamper enable bits in TDET Tamper Enable Register.
534  *
535  * param base TDET peripheral base address
536  * param mask Bit mask for the tamper enable bits to be set.
537  * return kStatus_Fail when Tamper Enable Register writing is not allowed
538  * return kStatus_Success when mask is written to the Tamper Enable Register
539  */
TDET_EnableTampers(DIGTMP_Type * base,uint32_t mask)540 status_t TDET_EnableTampers(DIGTMP_Type *base, uint32_t mask)
541 {
542     status_t status;
543 
544     mask = mask & TDET_ALL_TER_MASK; /* only set the bits documented in Reference Manual */
545     if (tdet_IsRegisterWriteAllowed(base, DIGTMP_LR_TEL_MASK))
546     {
547         base->TER |= mask;
548         status = kStatus_Success;
549     }
550     else
551     {
552         status = kStatus_Fail;
553     }
554 
555     return status;
556 }
557 
558 /*!
559  * brief Writes to the Tamper Enable Register.
560  *
561  * This function clears specified tamper enable bits in TDET Tamper Enable Register.
562  *
563  * param base TDET peripheral base address
564  * param mask Bit mask for the tamper enable bits to be cleared.
565  * return kStatus_Fail when Tamper Enable Register writing is not allowed
566  * return kStatus_Success when specified bits are cleared in the Tamper Enable Register
567  */
TDET_DisableTampers(DIGTMP_Type * base,uint32_t mask)568 status_t TDET_DisableTampers(DIGTMP_Type *base, uint32_t mask)
569 {
570     status_t status;
571 
572     mask = mask & TDET_ALL_TER_MASK; /* only clear the bits documented in Reference Manual */
573     if (tdet_IsRegisterWriteAllowed(base, DIGTMP_LR_TEL_MASK))
574     {
575         base->TER &= ~mask;
576         status = kStatus_Success;
577     }
578     else
579     {
580         status = kStatus_Fail;
581     }
582 
583     return status;
584 }
585 
586 /*!
587  * brief Writes to the Tamper Seconds Register.
588  *
589  * This function writes to TDET Tamper Seconds Register. This causes Status Register DTF flag to be set (TDET
590  * tampering detected).
591  *
592  * param base TDET peripheral base address
593  * return kStatus_Fail when Tamper Seconds Register writing is not allowed
594  * return kStatus_Success when Tamper Seconds Register is written
595  */
TDET_ForceTamper(DIGTMP_Type * base)596 status_t TDET_ForceTamper(DIGTMP_Type *base)
597 {
598     status_t status;
599 
600     if (tdet_IsRegisterWriteAllowed(base, DIGTMP_LR_TSL_MASK))
601     {
602         base->TSR = 0;
603         status    = kStatus_Success;
604     }
605     else
606     {
607         status = kStatus_Fail;
608     }
609 
610     return status;
611 }
612 
613 /*!
614  * brief Reads the Tamper Seconds Register.
615  *
616  * This function reads TDET Tamper Seconds Register. The read value returns the time in seconds at which the Status
617  * Register DTF flag was set.
618  *
619  * param base TDET peripheral base address
620  * param tamperTimeSeconds Time in seconds at which the tamper detection SR[DTF] flag was set.
621  * return kStatus_Fail when Tamper Seconds Register reading is not allowed
622  * return kStatus_Success when Tamper Seconds Register is read
623  */
TDET_GetTamperTimeSeconds(DIGTMP_Type * base,uint32_t * tamperTimeSeconds)624 status_t TDET_GetTamperTimeSeconds(DIGTMP_Type *base, uint32_t *tamperTimeSeconds)
625 {
626     status_t status;
627 
628     if (tamperTimeSeconds != NULL)
629     {
630         *tamperTimeSeconds = base->TSR;
631         status             = kStatus_Success;
632     }
633     else
634     {
635         status = kStatus_Fail;
636     }
637 
638     return status;
639 }
640 
641 /*!
642  * brief Writes to the TDET Lock Register.
643  *
644  * This function clears specified lock bits in the TDET Lock Register.
645  * When a lock bit is clear, a write to corresponding TDET Register is ignored.
646  * Once cleared, these bits can only be set by VBAT POR or software reset.
647  *
648  * param base TDET peripheral base address
649  * param mask Bit mask for the lock bits to be cleared. Use tdet_register_t values to encode (OR'ed) which TDET
650  * Registers shall be locked.
651  */
TDET_LockRegisters(DIGTMP_Type * base,uint32_t mask)652 void TDET_LockRegisters(DIGTMP_Type *base, uint32_t mask)
653 {
654     mask &= (uint32_t)kTDET_AllRegisters; /* make sure only documented registers are selected by the mask */
655     base->LR &= ~mask;                    /* clear the selected bits */
656 }
657