1 /*
2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
3 * Copyright 2017-2023, NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #ifndef FSL_SNVS_LP_H_
10 #define FSL_SNVS_LP_H_
11
12 #include "fsl_common.h"
13
14 /*!
15 * @addtogroup snvs_lp
16 * @{
17 */
18
19 /*******************************************************************************
20 * Definitions
21 ******************************************************************************/
22
23 /*! @name Driver version */
24 /*! @{ */
25 #define FSL_SNVS_LP_DRIVER_VERSION (MAKE_VERSION(2, 4, 6)) /*!< Version 2.4.6 */
26 /*! @} */
27
28 /*! @brief Define of SNVS_LP Zeroizable Master Key registers */
29 #define SNVS_ZMK_REG_COUNT 8U /* 8 Zeroizable Master Key registers. */
30
31 /*! @brief List of SNVS_LP interrupts */
32 typedef enum _snvs_lp_srtc_interrupts
33 {
34 kSNVS_SRTC_AlarmInterrupt = SNVS_LPCR_LPTA_EN_MASK, /*!< SRTC time alarm.*/
35 } snvs_lp_srtc_interrupts_t;
36
37 /*! @brief List of SNVS_LP flags */
38 typedef enum _snvs_lp_srtc_status_flags
39 {
40 kSNVS_SRTC_AlarmInterruptFlag = SNVS_LPSR_LPTA_MASK, /*!< SRTC time alarm flag */
41 } snvs_lp_srtc_status_flags_t;
42
43 #if defined(FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER) && (FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER > 0)
44
45 /*! @brief List of SNVS_LP external tampers */
46 typedef enum _snvs_lp_external_tamper
47 {
48 kSNVS_ExternalTamper1 = 1U,
49 #if defined(FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER) && (FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER > 1)
50 kSNVS_ExternalTamper2 = 2U,
51 kSNVS_ExternalTamper3 = 3U,
52 kSNVS_ExternalTamper4 = 4U,
53 kSNVS_ExternalTamper5 = 5U,
54 kSNVS_ExternalTamper6 = 6U,
55 kSNVS_ExternalTamper7 = 7U,
56 kSNVS_ExternalTamper8 = 8U,
57 kSNVS_ExternalTamper9 = 9U,
58 kSNVS_ExternalTamper10 = 10U
59 #endif /* defined(FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER) && (FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER > 1) */
60 } snvs_lp_external_tamper_t;
61
62 #endif /* defined(FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER) && (FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER > 0) */
63
64 #if defined(FSL_FEATURE_SNVS_HAS_ACTIVE_TAMPERS) && (FSL_FEATURE_SNVS_HAS_ACTIVE_TAMPERS > 0)
65 /*! @brief List of SNVS_LP active tampers */
66 typedef enum _snvs_lp_active_tamper
67 {
68 kSNVS_ActiveTamper1 = 1U,
69 kSNVS_ActiveTamper2 = 2U,
70 kSNVS_ActiveTamper3 = 3U,
71 kSNVS_ActiveTamper4 = 4U,
72 kSNVS_ActiveTamper5 = 5U,
73 } snvs_lp_active_tx_tamper_t;
74
75 /*! @brief List of SNVS_LP external tampers */
76 typedef enum _snvs_lp_active_clock
77 {
78 kSNVS_ActiveTamper16HZ = 0U,
79 kSNVS_ActiveTamper8HZ = 1U,
80 kSNVS_ActiveTamper4HZ = 2U,
81 kSNVS_ActiveTamper2HZ = 3U
82 } snvs_lp_active_clock_t;
83
84 /*! @brief Structure is used to configure SNVS LP active TX tamper pins */
85 typedef struct
86 {
87 uint16_t polynomial;
88 uint16_t seed;
89 snvs_lp_active_clock_t clock;
90 } tamper_active_tx_config_t;
91
92 /*! @brief Structure is used to configure SNVS LP active RX tamper pins */
93 typedef struct
94 {
95 uint16_t filterenable;
96 uint8_t filter;
97 snvs_lp_active_tx_tamper_t activeTamper;
98 } tamper_active_rx_config_t;
99
100 #endif /* FSL_FEATURE_SNVS_HAS_ACTIVE_TAMPERS */
101
102 /*! @brief Structure is used to configure SNVS LP passive tamper pins */
103 typedef struct
104 {
105 uint8_t polarity;
106 #if defined(FSL_FEATURE_SNVS_PASSIVE_TAMPER_FILTER) && (FSL_FEATURE_SNVS_PASSIVE_TAMPER_FILTER > 0)
107 uint8_t filterenable;
108 uint8_t filter;
109 #endif /* FSL_FEATURE_SNVS_PASSIVE_TAMPER_FILTER */
110 } snvs_lp_passive_tamper_t;
111
112 /* define max possible tamper present */
113 /*! @brief Define of SNVS_LP Max possible tamper */
114 #if defined(FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER) && (FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER > 1)
115 #define SNVS_LP_MAX_TAMPER kSNVS_ExternalTamper10
116 #else
117 #define SNVS_LP_MAX_TAMPER kSNVS_ExternalTamper1
118 #endif
119
120 /*! @brief List of SNVS_LP external tampers status */
121 typedef enum _snvs_lp_external_tamper_status
122 {
123 kSNVS_TamperNotDetected = 0U,
124 kSNVS_TamperDetected = 1U
125 } snvs_lp_external_tamper_status_t;
126
127 /*! @brief SNVS_LP external tamper polarity */
128 typedef enum _snvs_lp_external_tamper_polarity
129 {
130 kSNVS_ExternalTamperActiveLow = 0U,
131 kSNVS_ExternalTamperActiveHigh = 1U
132 } snvs_lp_external_tamper_polarity_t;
133
134 /*! @brief Structure is used to hold the date and time */
135 typedef struct _snvs_lp_srtc_datetime
136 {
137 uint16_t year; /*!< Range from 1970 to 2099.*/
138 uint8_t month; /*!< Range from 1 to 12.*/
139 uint8_t day; /*!< Range from 1 to 31 (depending on month).*/
140 uint8_t hour; /*!< Range from 0 to 23.*/
141 uint8_t minute; /*!< Range from 0 to 59.*/
142 uint8_t second; /*!< Range from 0 to 59.*/
143 } snvs_lp_srtc_datetime_t;
144
145 /*!
146 * @brief SNVS_LP config structure
147 *
148 * This structure holds the configuration settings for the SNVS_LP peripheral. To initialize this
149 * structure to reasonable defaults, call the SNVS_LP_GetDefaultConfig() function and pass a
150 * pointer to your config structure instance.
151 *
152 * The config struct can be made const so it resides in flash
153 */
154 typedef struct _snvs_lp_srtc_config
155 {
156 bool srtcCalEnable; /*!< true: SRTC calibration mechanism is enabled;
157 false: No calibration is used */
158 uint32_t srtcCalValue; /*!< Defines signed calibration value for SRTC;
159 This is a 5-bit 2's complement value, range from -16 to +15 */
160 } snvs_lp_srtc_config_t;
161
162 /*!
163 * @brief SNVS_LP Zeroizable Master Key programming mode.
164 */
165 typedef enum _snvs_lp_zmk_program_mode
166 {
167 kSNVS_ZMKSoftwareProgram, /*!< Software programming mode. */
168 kSNVS_ZMKHardwareProgram, /*!< Hardware programming mode. */
169 } snvs_lp_zmk_program_mode_t;
170
171 /*!
172 * @brief SNVS_LP Master Key mode.
173 */
174 typedef enum _snvs_lp_master_key_mode
175 {
176 kSNVS_OTPMK = 0, /*!< One Time Programmable Master Key. */
177 kSNVS_ZMK = 2, /*!< Zeroizable Master Key. */
178 kSNVS_CMK = 3, /*!< Combined Master Key, it is XOR of OPTMK and ZMK. */
179 } snvs_lp_master_key_mode_t;
180
181 /*******************************************************************************
182 * API
183 ******************************************************************************/
184
185 #if defined(__cplusplus)
186 extern "C" {
187 #endif
188
189 /*!
190 * @name Initialization and deinitialization
191 * @{
192 */
193
194 /*!
195 * @brief Ungates the SNVS clock and configures the peripheral for basic operation.
196 *
197 * @note This API should be called at the beginning of the application using the SNVS driver.
198 *
199 * @param base SNVS peripheral base address
200 */
201 void SNVS_LP_Init(SNVS_Type *base);
202
203 /*!
204 * @brief Deinit the SNVS LP section.
205 *
206 * @param base SNVS peripheral base address
207 */
208 void SNVS_LP_Deinit(SNVS_Type *base);
209
210 /*! @}*/
211
212 /*!
213 * @brief Ungates the SNVS clock and configures the peripheral for basic operation.
214 *
215 * @note This API should be called at the beginning of the application using the SNVS driver.
216 *
217 * @param base SNVS peripheral base address
218 * @param config Pointer to the user's SNVS configuration structure.
219 */
220 void SNVS_LP_SRTC_Init(SNVS_Type *base, const snvs_lp_srtc_config_t *config);
221
222 /*!
223 * @brief Stops the SRTC timer.
224 *
225 * @param base SNVS peripheral base address
226 */
227 void SNVS_LP_SRTC_Deinit(SNVS_Type *base);
228
229 /*!
230 * @brief Fills in the SNVS_LP config struct with the default settings.
231 *
232 * The default values are as follows.
233 * @code
234 * config->srtccalenable = false;
235 * config->srtccalvalue = 0U;
236 * @endcode
237 * @param config Pointer to the user's SNVS configuration structure.
238 */
239 void SNVS_LP_SRTC_GetDefaultConfig(snvs_lp_srtc_config_t *config);
240
241 /*!
242 * @name Secure RTC (SRTC) current Time & Alarm
243 * @{
244 */
245
246 /*!
247 * @brief Sets the SNVS SRTC date and time according to the given time structure.
248 *
249 * @param base SNVS peripheral base address
250 * @param datetime Pointer to the structure where the date and time details are stored.
251 *
252 * @return kStatus_Success: Success in setting the time and starting the SNVS SRTC
253 * kStatus_InvalidArgument: Error because the datetime format is incorrect
254 */
255 status_t SNVS_LP_SRTC_SetDatetime(SNVS_Type *base, const snvs_lp_srtc_datetime_t *datetime);
256
257 /*!
258 * @brief Gets the SNVS SRTC time and stores it in the given time structure.
259 *
260 * @param base SNVS peripheral base address
261 * @param datetime Pointer to the structure where the date and time details are stored.
262 */
263 void SNVS_LP_SRTC_GetDatetime(SNVS_Type *base, snvs_lp_srtc_datetime_t *datetime);
264
265 /*!
266 * @brief Sets the SNVS SRTC alarm time.
267 *
268 * The function sets the SRTC alarm. It also checks whether the specified alarm
269 * time is greater than the present time. If not, the function does not set the alarm
270 * and returns an error.
271 * Please note, that SRTC alarm has limited resolution because only 32 most
272 * significant bits of SRTC counter are compared to SRTC Alarm register.
273 * If the alarm time is beyond SRTC resolution, the function does not set the alarm
274 * and returns an error.
275 *
276 * @param base SNVS peripheral base address
277 * @param alarmTime Pointer to the structure where the alarm time is stored.
278 *
279 * @return kStatus_Success: success in setting the SNVS SRTC alarm
280 * kStatus_InvalidArgument: Error because the alarm datetime format is incorrect
281 * kStatus_Fail: Error because the alarm time has already passed or is beyond resolution
282 */
283 status_t SNVS_LP_SRTC_SetAlarm(SNVS_Type *base, const snvs_lp_srtc_datetime_t *alarmTime);
284
285 /*!
286 * @brief Returns the SNVS SRTC alarm time.
287 *
288 * @param base SNVS peripheral base address
289 * @param datetime Pointer to the structure where the alarm date and time details are stored.
290 */
291 void SNVS_LP_SRTC_GetAlarm(SNVS_Type *base, snvs_lp_srtc_datetime_t *datetime);
292
293 /*! @}*/
294
295 /*!
296 * @name Interrupt Interface
297 * @{
298 */
299
300 /*!
301 * @brief Enables the selected SNVS interrupts.
302 *
303 * @param base SNVS peripheral base address
304 * @param mask The interrupts to enable. This is a logical OR of members of the
305 * enumeration :: _snvs_lp_srtc_interrupts
306 */
SNVS_LP_SRTC_EnableInterrupts(SNVS_Type * base,uint32_t mask)307 static inline void SNVS_LP_SRTC_EnableInterrupts(SNVS_Type *base, uint32_t mask)
308 {
309 base->LPCR |= mask;
310 }
311
312 /*!
313 * @brief Disables the selected SNVS interrupts.
314 *
315 * @param base SNVS peripheral base address
316 * @param mask The interrupts to enable. This is a logical OR of members of the
317 * enumeration :: _snvs_lp_srtc_interrupts
318 */
SNVS_LP_SRTC_DisableInterrupts(SNVS_Type * base,uint32_t mask)319 static inline void SNVS_LP_SRTC_DisableInterrupts(SNVS_Type *base, uint32_t mask)
320 {
321 base->LPCR &= ~mask;
322 }
323
324 /*!
325 * @brief Gets the enabled SNVS interrupts.
326 *
327 * @param base SNVS peripheral base address
328 *
329 * @return The enabled interrupts. This is the logical OR of members of the
330 * enumeration :: _snvs_lp_srtc_interrupts
331 */
332 uint32_t SNVS_LP_SRTC_GetEnabledInterrupts(SNVS_Type *base);
333
334 /*! @}*/
335
336 /*!
337 * @name Status Interface
338 * @{
339 */
340
341 /*!
342 * @brief Gets the SNVS status flags.
343 *
344 * @param base SNVS peripheral base address
345 *
346 * @return The status flags. This is the logical OR of members of the
347 * enumeration :: _snvs_lp_srtc_status_flags
348 */
349 uint32_t SNVS_LP_SRTC_GetStatusFlags(SNVS_Type *base);
350
351 /*!
352 * @brief Clears the SNVS status flags.
353 *
354 * @param base SNVS peripheral base address
355 * @param mask The status flags to clear. This is a logical OR of members of the
356 * enumeration :: _snvs_lp_srtc_status_flags
357 */
SNVS_LP_SRTC_ClearStatusFlags(SNVS_Type * base,uint32_t mask)358 static inline void SNVS_LP_SRTC_ClearStatusFlags(SNVS_Type *base, uint32_t mask)
359 {
360 base->LPSR |= mask;
361 }
362
363 /*! @}*/
364
365 /*!
366 * @name Timer Start and Stop
367 * @{
368 */
369
370 /*!
371 * @brief Starts the SNVS SRTC time counter.
372 *
373 * @param base SNVS peripheral base address
374 */
SNVS_LP_SRTC_StartTimer(SNVS_Type * base)375 static inline void SNVS_LP_SRTC_StartTimer(SNVS_Type *base)
376 {
377 base->LPCR |= SNVS_LPCR_SRTC_ENV_MASK;
378 while ((0U == (base->LPCR & SNVS_LPCR_SRTC_ENV_MASK)))
379 {
380 }
381 }
382
383 /*!
384 * @brief Stops the SNVS SRTC time counter.
385 *
386 * @param base SNVS peripheral base address
387 */
SNVS_LP_SRTC_StopTimer(SNVS_Type * base)388 static inline void SNVS_LP_SRTC_StopTimer(SNVS_Type *base)
389 {
390 base->LPCR &= ~SNVS_LPCR_SRTC_ENV_MASK;
391 while ((base->LPCR & SNVS_LPCR_SRTC_ENV_MASK) != 0U)
392 {
393 }
394 }
395
396 /*! @}*/
397
398 /*!
399 * @name External tampering
400 * @{
401 */
402
403 #if defined(FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER) && (FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER > 0)
404
405 /*!
406 * @brief Enables the specified SNVS external tamper.
407 *
408 * @param base SNVS peripheral base address
409 * @param pin SNVS external tamper pin
410 * @param config Configuration structure of external passive tamper
411 */
412 void SNVS_LP_EnablePassiveTamper(SNVS_Type *base, snvs_lp_external_tamper_t pin, snvs_lp_passive_tamper_t config);
413
414 #endif /* defined(FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER) && (FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER > 0) */
415
416 #if defined(FSL_FEATURE_SNVS_HAS_ACTIVE_TAMPERS) && (FSL_FEATURE_SNVS_HAS_ACTIVE_TAMPERS > 0)
417 /*!
418 * @brief Enable active tamper tx external pad
419 *
420 * @param base SNVS peripheral base address
421 * @param pin SNVS active tamper pin
422 * @param config Configuration structure of external active tamper
423 */
424 status_t SNVS_LP_EnableTxActiveTamper(SNVS_Type *base,
425 snvs_lp_active_tx_tamper_t pin,
426 tamper_active_tx_config_t config);
427
428 /*!
429 * @brief Enable active tamper rx external pad
430 *
431 * @param base SNVS peripheral base address
432 * @param rx SNVS external RX tamper pin
433 * @param config SNVS RX tamper config structure
434 */
435 status_t SNVS_LP_EnableRxActiveTamper(SNVS_Type *base, snvs_lp_external_tamper_t rx, tamper_active_rx_config_t config);
436
437 /*!
438 * @brief Sets voltage tamper detect
439 *
440 * @param base SNVS peripheral base address
441 * @param enable True if enable false if disable
442 */
443 status_t SNVS_LP_SetVoltageTamper(SNVS_Type *base, bool enable);
444
445 /*!
446 * @brief Sets temperature tamper detect
447 *
448 * @param base SNVS peripheral base address
449 * @param enable True if enable false if disable
450 */
451 status_t SNVS_LP_SetTemperatureTamper(SNVS_Type *base, bool enable);
452
453 /*!
454 * @brief Sets clock tamper detect
455 *
456 * @param base SNVS peripheral base address
457 * @param enable True if enable false if disable
458 */
459 status_t SNVS_LP_SetClockTamper(SNVS_Type *base, bool enable);
460
461 /*!
462 * brief Check voltage tamper
463 *
464 * param base SNVS peripheral base address
465 */
466 snvs_lp_external_tamper_status_t SNVS_LP_CheckVoltageTamper(SNVS_Type *base);
467
468 /*!
469 * @brief Check temperature tamper
470 *
471 * @param base SNVS peripheral base address
472 */
473 snvs_lp_external_tamper_status_t SNVS_LP_CheckTemperatureTamper(SNVS_Type *base);
474
475 /*!
476 * brief Check clock tamper
477 *
478 * param base SNVS peripheral base address
479 */
480 snvs_lp_external_tamper_status_t SNVS_LP_CheckClockTamper(SNVS_Type *base);
481
482 /*!
483 * @brief Fills in the SNVS tamper pin config struct with the default settings.
484 *
485 * The default values are as follows.
486 * code
487 * config->clock = kSNVS_ActiveTamper16HZ;
488 * config->seed = 0U;
489 * config->polynomial = 0U;
490 * endcode
491 * @param config Pointer to the user's SNVS configuration structure.
492 */
493 void SNVS_LP_TamperPinTx_GetDefaultConfig(tamper_active_tx_config_t *config);
494
495 /*!
496 * brief Fills in the SNVS tamper pin config struct with the default settings.
497 *
498 * The default values are as follows.
499 * code
500 * config->filterenable = 0U;
501 * config->filter = 0U;
502 * config->tx = kSNVS_ActiveTamper1;
503 * endcode
504 * param config Pointer to the user's SNVS configuration structure.
505 */
506 void SNVS_LP_TamperPinRx_GetDefaultConfig(tamper_active_rx_config_t *config);
507 #endif /* defined(FSL_FEATURE_SNVS_HAS_ACTIVE_TAMPERS) && (FSL_FEATURE_SNVS_HAS_ACTIVE_TAMPERS > 0) */
508
509 /*!
510 * @brief Fills in the SNVS tamper pin config struct with the default settings.
511 *
512 * The default values are as follows.
513 * code
514 * config->polarity = 0U;
515 * config->filterenable = 0U; if available on SoC
516 * config->filter = 0U; if available on SoC
517 * endcode
518 * @param config Pointer to the user's SNVS configuration structure.
519 */
520 void SNVS_LP_PassiveTamperPin_GetDefaultConfig(snvs_lp_passive_tamper_t *config);
521
522 #if defined(FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER) && (FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER > 0)
523
524 /*!
525 * @brief Disables the specified SNVS external tamper.
526 *
527 * @param base SNVS peripheral base address
528 * @param pin SNVS external tamper pin
529 */
530 void SNVS_LP_DisableExternalTamper(SNVS_Type *base, snvs_lp_external_tamper_t pin);
531
532 /*!
533 * @brief Disable all external tamper.
534 *
535 * @param base SNVS peripheral base address
536 */
537 void SNVS_LP_DisableAllExternalTamper(SNVS_Type *base);
538
539 /*!
540 * @brief Returns status of the specified external tamper.
541 *
542 * @param base SNVS peripheral base address
543 * @param pin SNVS external tamper pin
544 *
545 * @return The status flag. This is the enumeration :: _snvs_lp_external_tamper_status
546 */
547 snvs_lp_external_tamper_status_t SNVS_LP_GetExternalTamperStatus(SNVS_Type *base, snvs_lp_external_tamper_t pin);
548
549 /*!
550 * @brief Clears status of the specified external tamper.
551 *
552 * @param base SNVS peripheral base address
553 * @param pin SNVS external tamper pin
554 */
555 void SNVS_LP_ClearExternalTamperStatus(SNVS_Type *base, snvs_lp_external_tamper_t pin);
556
557 /*!
558 * @brief Clears status of the all external tamper.
559 *
560 * @param base SNVS peripheral base address
561 */
562 void SNVS_LP_ClearAllExternalTamperStatus(SNVS_Type *base);
563
564 #endif /* defined(FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER) && (FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER > 0) */
565
566 /*! @}*/
567
568 /*!
569 * @name Monotonic Counter (MC)
570 * @{
571 */
572
573 /*!
574 * @brief Enable or disable the Monotonic Counter.
575 *
576 * @param base SNVS peripheral base address
577 * @param enable Pass true to enable, false to disable.
578 */
SNVS_LP_EnableMonotonicCounter(SNVS_Type * base,bool enable)579 static inline void SNVS_LP_EnableMonotonicCounter(SNVS_Type *base, bool enable)
580 {
581 if (enable)
582 {
583 base->LPCR |= SNVS_LPCR_MC_ENV_MASK;
584 }
585 else
586 {
587 base->LPCR &= (~SNVS_LPCR_MC_ENV_MASK);
588 }
589 }
590
591 /*!
592 * @brief Get the current Monotonic Counter.
593 *
594 * @param base SNVS peripheral base address
595 * @return Current Monotonic Counter value.
596 */
597 uint64_t SNVS_LP_GetMonotonicCounter(SNVS_Type *base);
598
599 /*!
600 * @brief Increase the Monotonic Counter.
601 *
602 * Increase the Monotonic Counter by 1.
603 *
604 * @param base SNVS peripheral base address
605 */
SNVS_LP_IncreaseMonotonicCounter(SNVS_Type * base)606 static inline void SNVS_LP_IncreaseMonotonicCounter(SNVS_Type *base)
607 {
608 /* Write to the LPSMCLR or LPSMCLR, the counter increases. */
609 *((volatile uint32_t *)(uint32_t)(&(base->LPSMCLR))) = 0xFFFFFFFFU;
610 }
611
612 /*! @}*/
613
614 /*!
615 * @name Zeroizable Master Key (ZMK)
616 * @{
617 */
618
619 /*!
620 * @brief Write Zeroizable Master Key (ZMK) to the SNVS registers.
621 *
622 * @param base SNVS peripheral base address
623 * @param ZMKey The ZMK write to the SNVS register.
624 */
625 void SNVS_LP_WriteZeroizableMasterKey(SNVS_Type *base, uint32_t ZMKey[SNVS_ZMK_REG_COUNT]);
626
627 /*!
628 * @brief Set Zeroizable Master Key valid.
629 *
630 * This API could only be called when using software programming mode. After writing
631 * ZMK using @ref SNVS_LP_WriteZeroizableMasterKey, call this API to make the ZMK
632 * valid.
633 *
634 * @param base SNVS peripheral base address
635 * @param valid Pass true to set valid, false to set invalid.
636 */
SNVS_LP_SetZeroizableMasterKeyValid(SNVS_Type * base,bool valid)637 static inline void SNVS_LP_SetZeroizableMasterKeyValid(SNVS_Type *base, bool valid)
638 {
639 if (valid)
640 {
641 base->LPMKCR |= SNVS_LPMKCR_ZMK_VAL_MASK;
642 }
643 else
644 {
645 base->LPMKCR &= (~SNVS_LPMKCR_ZMK_VAL_MASK);
646 }
647 }
648
649 /*!
650 * @brief Get Zeroizable Master Key valid status.
651 *
652 * In hardware programming mode, call this API to check whether the ZMK is valid.
653 *
654 * @param base SNVS peripheral base address
655 * @return true if valid, false if invalid.
656 */
SNVS_LP_GetZeroizableMasterKeyValid(SNVS_Type * base)657 static inline bool SNVS_LP_GetZeroizableMasterKeyValid(SNVS_Type *base)
658 {
659 return (SNVS_LPMKCR_ZMK_VAL_MASK == (base->LPMKCR & SNVS_LPMKCR_ZMK_VAL_MASK));
660 }
661
662 /*!
663 * @brief Set Zeroizable Master Key programming mode.
664 *
665 * @param base SNVS peripheral base address
666 * @param mode ZMK programming mode.
667 */
SNVS_LP_SetZeroizableMasterKeyProgramMode(SNVS_Type * base,snvs_lp_zmk_program_mode_t mode)668 static inline void SNVS_LP_SetZeroizableMasterKeyProgramMode(SNVS_Type *base, snvs_lp_zmk_program_mode_t mode)
669 {
670 if (kSNVS_ZMKSoftwareProgram == mode)
671 {
672 base->LPMKCR &= (~SNVS_LPMKCR_ZMK_HWP_MASK);
673 }
674 else
675 {
676 base->LPMKCR |= SNVS_LPMKCR_ZMK_HWP_MASK;
677 }
678 }
679
680 /*!
681 * @brief Enable or disable Zeroizable Master Key ECC.
682 *
683 * @param base SNVS peripheral base address
684 * @param enable Pass true to enable, false to disable.
685 */
SNVS_LP_EnableZeroizableMasterKeyECC(SNVS_Type * base,bool enable)686 static inline void SNVS_LP_EnableZeroizableMasterKeyECC(SNVS_Type *base, bool enable)
687 {
688 if (enable)
689 {
690 base->LPMKCR |= SNVS_LPMKCR_ZMK_ECC_EN_MASK;
691 }
692 else
693 {
694 base->LPMKCR &= (~SNVS_LPMKCR_ZMK_ECC_EN_MASK);
695 }
696 }
697
698 /*!
699 * @brief Set SNVS Master Key mode.
700 *
701 * @param base SNVS peripheral base address
702 * @param mode Master Key mode.
703 * @note When @ref kSNVS_ZMK or @ref kSNVS_CMK used, the SNVS_HP must be configured
704 * to enable the master key selection.
705 */
SNVS_LP_SetMasterKeyMode(SNVS_Type * base,snvs_lp_master_key_mode_t mode)706 static inline void SNVS_LP_SetMasterKeyMode(SNVS_Type *base, snvs_lp_master_key_mode_t mode)
707 {
708 uint32_t lpmkcr = base->LPMKCR;
709 lpmkcr = (lpmkcr & (~SNVS_LPMKCR_MASTER_KEY_SEL_MASK)) | SNVS_LPMKCR_MASTER_KEY_SEL(mode);
710 base->LPMKCR = lpmkcr;
711 }
712
713 #if defined(FSL_FEATURE_SNVS_HAS_STATE_TRANSITION) && (FSL_FEATURE_SNVS_HAS_STATE_TRANSITION > 0)
714 /*!
715 * brief Transition SNVS SSM state to Trusted/Non-secure from Check state
716 *
717 * param base SNVS peripheral base address
718 *
719 * return kStatus_Success: Success in transitioning SSM State
720 * kStatus_Fail: SSM State transition failed
721 */
722 status_t SNVS_LP_SSM_State_Transition(SNVS_Type *base);
723 #endif /* FSL_FEATURE_SNVS_HAS_STATE_TRANSITION */
724
725 /*! @}*/
726
727 #if defined(__cplusplus)
728 }
729 #endif
730
731 /*! @}*/
732
733 #endif /* FSL_SNVS_LP_H_ */
734