RTEMS 6.1-rc6
Loading...
Searching...
No Matches
fsl_snvs_lp.h
1/*
2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
3 * Copyright 2017-2022, 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
19/*******************************************************************************
20 * Definitions
21 ******************************************************************************/
22
25#define FSL_SNVS_LP_DRIVER_VERSION (MAKE_VERSION(2, 4, 4))
27
29#define SNVS_ZMK_REG_COUNT 8U /* 8 Zeroizable Master Key registers. */
30
33{
34 kSNVS_SRTC_AlarmInterrupt = SNVS_LPCR_LPTA_EN_MASK,
36
39{
40 kSNVS_SRTC_AlarmInterruptFlag = SNVS_LPSR_LPTA_MASK,
42
43#if defined(FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER) && (FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER > 0)
44
46typedef 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)
66typedef 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
76typedef 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
85typedef struct
86{
87 uint16_t polynomial;
88 uint16_t seed;
89 snvs_lp_active_clock_t clock;
90} tamper_active_tx_config_t;
91
93typedef 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
103typedef 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 */
111
112/* define max possible tamper present */
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
122{
123 kSNVS_TamperNotDetected = 0U,
124 kSNVS_TamperDetected = 1U
126
129{
130 kSNVS_ExternalTamperActiveLow = 0U,
131 kSNVS_ExternalTamperActiveHigh = 1U
133
136{
137 uint16_t year;
138 uint8_t month;
139 uint8_t day;
140 uint8_t hour;
141 uint8_t minute;
142 uint8_t second;
144
155{
158 uint32_t srtcCalValue;
161
166{
170
175{
180
181/*******************************************************************************
182 * API
183 ******************************************************************************/
184
185#if defined(__cplusplus)
186extern "C" {
187#endif
188
201void SNVS_LP_Init(SNVS_Type *base);
202
208void SNVS_LP_Deinit(SNVS_Type *base);
209
221
228
240
256
264
284
292
307static inline void SNVS_LP_SRTC_EnableInterrupts(SNVS_Type *base, uint32_t mask)
308{
309 base->LPCR |= mask;
310}
311
319static inline void SNVS_LP_SRTC_DisableInterrupts(SNVS_Type *base, uint32_t mask)
320{
321 base->LPCR &= ~mask;
322}
323
333
350
358static inline void SNVS_LP_SRTC_ClearStatusFlags(SNVS_Type *base, uint32_t mask)
359{
360 base->LPSR |= mask;
361}
362
375static 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
388static 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
403#if defined(FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER) && (FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER > 0)
404
412void 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)
424status_t SNVS_LP_EnableTxActiveTamper(SNVS_Type *base,
425 snvs_lp_active_tx_tamper_t pin,
426 tamper_active_tx_config_t config);
427
435status_t SNVS_LP_EnableRxActiveTamper(SNVS_Type *base, snvs_lp_external_tamper_t rx, tamper_active_rx_config_t config);
436
443status_t SNVS_LP_SetVoltageTamper(SNVS_Type *base, bool enable);
444
451status_t SNVS_LP_SetTemperatureTamper(SNVS_Type *base, bool enable);
452
459status_t SNVS_LP_SetClockTamper(SNVS_Type *base, bool enable);
460
466snvs_lp_external_tamper_status_t SNVS_LP_CheckVoltageTamper(SNVS_Type *base);
467
473snvs_lp_external_tamper_status_t SNVS_LP_CheckTemperatureTamper(SNVS_Type *base);
474
480snvs_lp_external_tamper_status_t SNVS_LP_CheckClockTamper(SNVS_Type *base);
481
493void SNVS_LP_TamperPinTx_GetDefaultConfig(tamper_active_tx_config_t *config);
494
506void 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
521
522#if defined(FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER) && (FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER > 0)
523
530void SNVS_LP_DisableExternalTamper(SNVS_Type *base, snvs_lp_external_tamper_t pin);
531
537void SNVS_LP_DisableAllExternalTamper(SNVS_Type *base);
538
547snvs_lp_external_tamper_status_t SNVS_LP_GetExternalTamperStatus(SNVS_Type *base, snvs_lp_external_tamper_t pin);
548
555void SNVS_LP_ClearExternalTamperStatus(SNVS_Type *base, snvs_lp_external_tamper_t pin);
556
562void SNVS_LP_ClearAllExternalTamperStatus(SNVS_Type *base);
563
564#endif /* defined(FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER) && (FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER > 0) */
565
579static 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
598
606static 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
626
637static 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
657static 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
668static 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
686static 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
706static 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)
722status_t SNVS_LP_SSM_State_Transition(SNVS_Type *base);
723#endif /* FSL_FEATURE_SNVS_HAS_STATE_TRANSITION */
724
727#if defined(__cplusplus)
728}
729#endif
730
733#endif /* _FSL_SNVS_LP_H_ */
#define SNVS_LPMKCR_MASTER_KEY_SEL(x)
Definition: MIMXRT1052.h:41897
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:225
_snvs_lp_external_tamper_status
List of SNVS_LP external tampers status.
Definition: fsl_snvs_lp.h:122
#define SNVS_ZMK_REG_COUNT
Define of SNVS_LP Zeroizable Master Key registers.
Definition: fsl_snvs_lp.h:29
void SNVS_LP_WriteZeroizableMasterKey(SNVS_Type *base, uint32_t ZMKey[SNVS_ZMK_REG_COUNT])
Write Zeroizable Master Key (ZMK) to the SNVS registers.
Definition: fsl_snvs_lp.c:1307
struct _snvs_lp_srtc_datetime snvs_lp_srtc_datetime_t
Structure is used to hold the date and time.
status_t SNVS_LP_SRTC_SetDatetime(SNVS_Type *base, const snvs_lp_srtc_datetime_t *datetime)
Sets the SNVS SRTC date and time according to the given time structure.
Definition: fsl_snvs_lp.c:366
enum _snvs_lp_srtc_interrupts snvs_lp_srtc_interrupts_t
List of SNVS_LP interrupts.
enum _snvs_lp_srtc_status_flags snvs_lp_srtc_status_flags_t
List of SNVS_LP flags.
uint64_t SNVS_LP_GetMonotonicCounter(SNVS_Type *base)
Get the current Monotonic Counter.
Definition: fsl_snvs_lp.c:1291
void SNVS_LP_PassiveTamperPin_GetDefaultConfig(snvs_lp_passive_tamper_t *config)
Fills in the SNVS tamper pin config struct with the default settings.
Definition: fsl_snvs_lp.c:535
void SNVS_LP_SRTC_Deinit(SNVS_Type *base)
Stops the SRTC timer.
Definition: fsl_snvs_lp.c:313
_snvs_lp_srtc_interrupts
List of SNVS_LP interrupts.
Definition: fsl_snvs_lp.h:33
struct _snvs_lp_srtc_config snvs_lp_srtc_config_t
SNVS_LP config structure.
void SNVS_LP_Init(SNVS_Type *base)
Ungates the SNVS clock and configures the peripheral for basic operation.
Definition: fsl_snvs_lp.c:242
_snvs_lp_master_key_mode
SNVS_LP Master Key mode.
Definition: fsl_snvs_lp.h:175
_snvs_lp_zmk_program_mode
SNVS_LP Zeroizable Master Key programming mode.
Definition: fsl_snvs_lp.h:166
uint32_t SNVS_LP_SRTC_GetStatusFlags(SNVS_Type *base)
Gets the SNVS status flags.
Definition: fsl_snvs_lp.c:492
_snvs_lp_srtc_status_flags
List of SNVS_LP flags.
Definition: fsl_snvs_lp.h:39
enum _snvs_lp_external_tamper_polarity snvs_lp_external_tamper_polarity_t
SNVS_LP external tamper polarity.
enum _snvs_lp_zmk_program_mode snvs_lp_zmk_program_mode_t
SNVS_LP Zeroizable Master Key programming mode.
void SNVS_LP_SRTC_GetDefaultConfig(snvs_lp_srtc_config_t *config)
Fills in the SNVS_LP config struct with the default settings.
Definition: fsl_snvs_lp.c:330
void SNVS_LP_SRTC_GetAlarm(SNVS_Type *base, snvs_lp_srtc_datetime_t *datetime)
Returns the SNVS SRTC alarm time.
Definition: fsl_snvs_lp.c:472
enum _snvs_lp_external_tamper_status snvs_lp_external_tamper_status_t
List of SNVS_LP external tampers status.
void SNVS_LP_SRTC_Init(SNVS_Type *base, const snvs_lp_srtc_config_t *config)
Ungates the SNVS clock and configures the peripheral for basic operation.
Definition: fsl_snvs_lp.c:284
uint32_t SNVS_LP_SRTC_GetEnabledInterrupts(SNVS_Type *base)
Gets the enabled SNVS interrupts.
Definition: fsl_snvs_lp.c:512
status_t SNVS_LP_SRTC_SetAlarm(SNVS_Type *base, const snvs_lp_srtc_datetime_t *alarmTime)
Sets the SNVS SRTC alarm time.
Definition: fsl_snvs_lp.c:428
enum _snvs_lp_master_key_mode snvs_lp_master_key_mode_t
SNVS_LP Master Key mode.
_snvs_lp_external_tamper_polarity
SNVS_LP external tamper polarity.
Definition: fsl_snvs_lp.h:129
void SNVS_LP_Deinit(SNVS_Type *base)
Deinit the SNVS LP section.
Definition: fsl_snvs_lp.c:267
void SNVS_LP_SRTC_GetDatetime(SNVS_Type *base, snvs_lp_srtc_datetime_t *datetime)
Gets the SNVS SRTC time and stores it in the given time structure.
Definition: fsl_snvs_lp.c:403
@ kSNVS_SRTC_AlarmInterrupt
Definition: fsl_snvs_lp.h:34
@ kSNVS_OTPMK
Definition: fsl_snvs_lp.h:176
@ kSNVS_ZMK
Definition: fsl_snvs_lp.h:177
@ kSNVS_CMK
Definition: fsl_snvs_lp.h:178
@ kSNVS_ZMKSoftwareProgram
Definition: fsl_snvs_lp.h:167
@ kSNVS_ZMKHardwareProgram
Definition: fsl_snvs_lp.h:168
@ kSNVS_SRTC_AlarmInterruptFlag
Definition: fsl_snvs_lp.h:40
Definition: MIMXRT1052.h:41032
SNVS_LP config structure.
Definition: fsl_snvs_lp.h:155
bool srtcCalEnable
Definition: fsl_snvs_lp.h:156
uint32_t srtcCalValue
Definition: fsl_snvs_lp.h:158
Structure is used to hold the date and time.
Definition: fsl_snvs_lp.h:136
uint8_t month
Definition: fsl_snvs_lp.h:138
uint8_t day
Definition: fsl_snvs_lp.h:139
uint8_t minute
Definition: fsl_snvs_lp.h:141
uint16_t year
Definition: fsl_snvs_lp.h:137
uint8_t second
Definition: fsl_snvs_lp.h:142
uint8_t hour
Definition: fsl_snvs_lp.h:140
Definition: deflate.c:114
Structure is used to configure SNVS LP passive tamper pins.
Definition: fsl_snvs_lp.h:104