fsl_snvs_lp.h 21 KB

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