fsl_snvs_lp.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  4. * Copyright (c) 2017, NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include "fsl_snvs_lp.h"
  35. /*******************************************************************************
  36. * Definitions
  37. ******************************************************************************/
  38. /* Component ID definition, used by tools. */
  39. #ifndef FSL_COMPONENT_ID
  40. #define FSL_COMPONENT_ID "platform.drivers.snvs_lp"
  41. #endif
  42. #define SECONDS_IN_A_DAY (86400U)
  43. #define SECONDS_IN_A_HOUR (3600U)
  44. #define SECONDS_IN_A_MINUTE (60U)
  45. #define DAYS_IN_A_YEAR (365U)
  46. #define YEAR_RANGE_START (1970U)
  47. #define YEAR_RANGE_END (2099U)
  48. /*******************************************************************************
  49. * Prototypes
  50. ******************************************************************************/
  51. /*!
  52. * @brief Checks whether the date and time passed in is valid
  53. *
  54. * @param datetime Pointer to structure where the date and time details are stored
  55. *
  56. * @return Returns false if the date & time details are out of range; true if in range
  57. */
  58. static bool SNVS_LP_CheckDatetimeFormat(const snvs_lp_srtc_datetime_t *datetime);
  59. /*!
  60. * @brief Converts time data from datetime to seconds
  61. *
  62. * @param datetime Pointer to datetime structure where the date and time details are stored
  63. *
  64. * @return The result of the conversion in seconds
  65. */
  66. static uint32_t SNVS_LP_ConvertDatetimeToSeconds(const snvs_lp_srtc_datetime_t *datetime);
  67. /*!
  68. * @brief Converts time data from seconds to a datetime structure
  69. *
  70. * @param seconds Seconds value that needs to be converted to datetime format
  71. * @param datetime Pointer to the datetime structure where the result of the conversion is stored
  72. */
  73. static void SNVS_LP_ConvertSecondsToDatetime(uint32_t seconds, snvs_lp_srtc_datetime_t *datetime);
  74. /*!
  75. * @brief Returns SRTC time in seconds.
  76. *
  77. * This function is used internally to get actual SRTC time in seconds.
  78. *
  79. * @param base SNVS peripheral base address
  80. *
  81. * @return SRTC time in seconds
  82. */
  83. static uint32_t SNVS_LP_SRTC_GetSeconds(SNVS_Type *base);
  84. #if (!(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && \
  85. defined(SNVS_LP_CLOCKS))
  86. /*!
  87. * @brief Get the SNVS instance from peripheral base address.
  88. *
  89. * @param base SNVS peripheral base address.
  90. *
  91. * @return SNVS instance.
  92. */
  93. static uint32_t SNVS_LP_GetInstance(SNVS_Type *base);
  94. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  95. /*******************************************************************************
  96. * Variables
  97. ******************************************************************************/
  98. #if (!(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && \
  99. defined(SNVS_LP_CLOCKS))
  100. /*! @brief Pointer to snvs_lp clock. */
  101. const clock_ip_name_t s_snvsLpClock[] = SNVS_LP_CLOCKS;
  102. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  103. /*******************************************************************************
  104. * Code
  105. ******************************************************************************/
  106. static bool SNVS_LP_CheckDatetimeFormat(const snvs_lp_srtc_datetime_t *datetime)
  107. {
  108. assert(datetime);
  109. /* Table of days in a month for a non leap year. First entry in the table is not used,
  110. * valid months start from 1
  111. */
  112. uint8_t daysPerMonth[] = {0U, 31U, 28U, 31U, 30U, 31U, 30U, 31U, 31U, 30U, 31U, 30U, 31U};
  113. /* Check year, month, hour, minute, seconds */
  114. if ((datetime->year < YEAR_RANGE_START) || (datetime->year > YEAR_RANGE_END) || (datetime->month > 12U) ||
  115. (datetime->month < 1U) || (datetime->hour >= 24U) || (datetime->minute >= 60U) || (datetime->second >= 60U))
  116. {
  117. /* If not correct then error*/
  118. return false;
  119. }
  120. /* Adjust the days in February for a leap year */
  121. if ((((datetime->year & 3U) == 0) && (datetime->year % 100 != 0)) || (datetime->year % 400 == 0))
  122. {
  123. daysPerMonth[2] = 29U;
  124. }
  125. /* Check the validity of the day */
  126. if ((datetime->day > daysPerMonth[datetime->month]) || (datetime->day < 1U))
  127. {
  128. return false;
  129. }
  130. return true;
  131. }
  132. static uint32_t SNVS_LP_ConvertDatetimeToSeconds(const snvs_lp_srtc_datetime_t *datetime)
  133. {
  134. assert(datetime);
  135. /* Number of days from begin of the non Leap-year*/
  136. /* Number of days from begin of the non Leap-year*/
  137. uint16_t monthDays[] = {0U, 0U, 31U, 59U, 90U, 120U, 151U, 181U, 212U, 243U, 273U, 304U, 334U};
  138. uint32_t seconds;
  139. /* Compute number of days from 1970 till given year*/
  140. seconds = (datetime->year - 1970U) * DAYS_IN_A_YEAR;
  141. /* Add leap year days */
  142. seconds += ((datetime->year / 4) - (1970U / 4));
  143. /* Add number of days till given month*/
  144. seconds += monthDays[datetime->month];
  145. /* Add days in given month. We subtract the current day as it is
  146. * represented in the hours, minutes and seconds field*/
  147. seconds += (datetime->day - 1);
  148. /* For leap year if month less than or equal to Febraury, decrement day counter*/
  149. if ((!(datetime->year & 3U)) && (datetime->month <= 2U))
  150. {
  151. seconds--;
  152. }
  153. seconds = (seconds * SECONDS_IN_A_DAY) + (datetime->hour * SECONDS_IN_A_HOUR) +
  154. (datetime->minute * SECONDS_IN_A_MINUTE) + datetime->second;
  155. return seconds;
  156. }
  157. static void SNVS_LP_ConvertSecondsToDatetime(uint32_t seconds, snvs_lp_srtc_datetime_t *datetime)
  158. {
  159. assert(datetime);
  160. uint32_t x;
  161. uint32_t secondsRemaining, days;
  162. uint16_t daysInYear;
  163. /* Table of days in a month for a non leap year. First entry in the table is not used,
  164. * valid months start from 1
  165. */
  166. uint8_t daysPerMonth[] = {0U, 31U, 28U, 31U, 30U, 31U, 30U, 31U, 31U, 30U, 31U, 30U, 31U};
  167. /* Start with the seconds value that is passed in to be converted to date time format */
  168. secondsRemaining = seconds;
  169. /* Calcuate the number of days, we add 1 for the current day which is represented in the
  170. * hours and seconds field
  171. */
  172. days = secondsRemaining / SECONDS_IN_A_DAY + 1;
  173. /* Update seconds left*/
  174. secondsRemaining = secondsRemaining % SECONDS_IN_A_DAY;
  175. /* Calculate the datetime hour, minute and second fields */
  176. datetime->hour = secondsRemaining / SECONDS_IN_A_HOUR;
  177. secondsRemaining = secondsRemaining % SECONDS_IN_A_HOUR;
  178. datetime->minute = secondsRemaining / 60U;
  179. datetime->second = secondsRemaining % SECONDS_IN_A_MINUTE;
  180. /* Calculate year */
  181. daysInYear = DAYS_IN_A_YEAR;
  182. datetime->year = YEAR_RANGE_START;
  183. while (days > daysInYear)
  184. {
  185. /* Decrease day count by a year and increment year by 1 */
  186. days -= daysInYear;
  187. datetime->year++;
  188. /* Adjust the number of days for a leap year */
  189. if (datetime->year & 3U)
  190. {
  191. daysInYear = DAYS_IN_A_YEAR;
  192. }
  193. else
  194. {
  195. daysInYear = DAYS_IN_A_YEAR + 1;
  196. }
  197. }
  198. /* Adjust the days in February for a leap year */
  199. if (!(datetime->year & 3U))
  200. {
  201. daysPerMonth[2] = 29U;
  202. }
  203. for (x = 1U; x <= 12U; x++)
  204. {
  205. if (days <= daysPerMonth[x])
  206. {
  207. datetime->month = x;
  208. break;
  209. }
  210. else
  211. {
  212. days -= daysPerMonth[x];
  213. }
  214. }
  215. datetime->day = days;
  216. }
  217. #if (!(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && \
  218. defined(SNVS_LP_CLOCKS))
  219. static uint32_t SNVS_LP_GetInstance(SNVS_Type *base)
  220. {
  221. return 0U;
  222. }
  223. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  224. void SNVS_LP_SRTC_Init(SNVS_Type *base, const snvs_lp_srtc_config_t *config)
  225. {
  226. assert(config);
  227. #if (!(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && \
  228. defined(SNVS_LP_CLOCKS))
  229. uint32_t instance = SNVS_LP_GetInstance(base);
  230. CLOCK_EnableClock(s_snvsLpClock[instance]);
  231. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  232. int pin;
  233. if (config->srtcCalEnable)
  234. {
  235. base->LPCR = SNVS_LPCR_LPCALB_VAL_MASK & (config->srtcCalValue << SNVS_LPCR_LPCALB_VAL_SHIFT);
  236. base->LPCR |= SNVS_LPCR_LPCALB_EN_MASK;
  237. }
  238. for (pin = kSNVS_ExternalTamper1; pin <= SNVS_LP_MAX_TAMPER; pin++)
  239. {
  240. SNVS_LP_DisableExternalTamper(SNVS, (snvs_lp_external_tamper_t)pin);
  241. SNVS_LP_ClearExternalTamperStatus(SNVS, (snvs_lp_external_tamper_t)pin);
  242. }
  243. }
  244. void SNVS_LP_SRTC_Deinit(SNVS_Type *base)
  245. {
  246. base->LPCR &= ~SNVS_LPCR_SRTC_ENV_MASK;
  247. #if (!(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && \
  248. defined(SNVS_LP_CLOCKS))
  249. uint32_t instance = SNVS_LP_GetInstance(base);
  250. CLOCK_DisableClock(s_snvsLpClock[instance]);
  251. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  252. }
  253. void SNVS_LP_SRTC_GetDefaultConfig(snvs_lp_srtc_config_t *config)
  254. {
  255. assert(config);
  256. config->srtcCalEnable = false;
  257. config->srtcCalValue = 0U;
  258. }
  259. static uint32_t SNVS_LP_SRTC_GetSeconds(SNVS_Type *base)
  260. {
  261. uint32_t seconds = 0;
  262. uint32_t tmp = 0;
  263. /* Do consecutive reads until value is correct */
  264. do
  265. {
  266. seconds = tmp;
  267. tmp = (base->LPSRTCMR << 17U) | (base->LPSRTCLR >> 15U);
  268. } while (tmp != seconds);
  269. return seconds;
  270. }
  271. status_t SNVS_LP_SRTC_SetDatetime(SNVS_Type *base, const snvs_lp_srtc_datetime_t *datetime)
  272. {
  273. assert(datetime);
  274. uint32_t seconds = 0U;
  275. uint32_t tmp = base->LPCR;
  276. /* disable RTC */
  277. SNVS_LP_SRTC_StopTimer(base);
  278. /* Return error if the time provided is not valid */
  279. if (!(SNVS_LP_CheckDatetimeFormat(datetime)))
  280. {
  281. return kStatus_InvalidArgument;
  282. }
  283. /* Set time in seconds */
  284. seconds = SNVS_LP_ConvertDatetimeToSeconds(datetime);
  285. base->LPSRTCMR = (uint32_t)(seconds >> 17U);
  286. base->LPSRTCLR = (uint32_t)(seconds << 15U);
  287. /* reenable SRTC in case that it was enabled before */
  288. if (tmp & SNVS_LPCR_SRTC_ENV_MASK)
  289. {
  290. SNVS_LP_SRTC_StartTimer(base);
  291. }
  292. return kStatus_Success;
  293. }
  294. void SNVS_LP_SRTC_GetDatetime(SNVS_Type *base, snvs_lp_srtc_datetime_t *datetime)
  295. {
  296. assert(datetime);
  297. SNVS_LP_ConvertSecondsToDatetime(SNVS_LP_SRTC_GetSeconds(base), datetime);
  298. }
  299. status_t SNVS_LP_SRTC_SetAlarm(SNVS_Type *base, const snvs_lp_srtc_datetime_t *alarmTime)
  300. {
  301. assert(alarmTime);
  302. uint32_t alarmSeconds = 0U;
  303. uint32_t currSeconds = 0U;
  304. uint32_t tmp = base->LPCR;
  305. /* Return error if the alarm time provided is not valid */
  306. if (!(SNVS_LP_CheckDatetimeFormat(alarmTime)))
  307. {
  308. return kStatus_InvalidArgument;
  309. }
  310. alarmSeconds = SNVS_LP_ConvertDatetimeToSeconds(alarmTime);
  311. currSeconds = SNVS_LP_SRTC_GetSeconds(base);
  312. /* Return error if the alarm time has passed */
  313. if (alarmSeconds <= currSeconds)
  314. {
  315. return kStatus_Fail;
  316. }
  317. /* disable SRTC alarm interrupt */
  318. base->LPCR &= ~SNVS_LPCR_LPTA_EN_MASK;
  319. while (base->LPCR & SNVS_LPCR_LPTA_EN_MASK)
  320. {
  321. }
  322. /* Set alarm in seconds*/
  323. base->LPTAR = alarmSeconds;
  324. /* reenable SRTC alarm interrupt in case that it was enabled before */
  325. base->LPCR = tmp;
  326. return kStatus_Success;
  327. }
  328. void SNVS_LP_SRTC_GetAlarm(SNVS_Type *base, snvs_lp_srtc_datetime_t *datetime)
  329. {
  330. assert(datetime);
  331. uint32_t alarmSeconds = 0U;
  332. /* Get alarm in seconds */
  333. alarmSeconds = base->LPTAR;
  334. SNVS_LP_ConvertSecondsToDatetime(alarmSeconds, datetime);
  335. }
  336. uint32_t SNVS_LP_SRTC_GetStatusFlags(SNVS_Type *base)
  337. {
  338. uint32_t flags = 0U;
  339. if (base->LPSR & SNVS_LPSR_LPTA_MASK)
  340. {
  341. flags |= kSNVS_SRTC_AlarmInterruptFlag;
  342. }
  343. return flags;
  344. }
  345. uint32_t SNVS_LP_SRTC_GetEnabledInterrupts(SNVS_Type *base)
  346. {
  347. uint32_t val = 0U;
  348. if (base->LPCR & SNVS_LPCR_LPTA_EN_MASK)
  349. {
  350. val |= kSNVS_SRTC_AlarmInterrupt;
  351. }
  352. return val;
  353. }
  354. void SNVS_LP_EnableExternalTamper(SNVS_Type *base,
  355. snvs_lp_external_tamper_t pin,
  356. snvs_lp_external_tamper_polarity_t polarity)
  357. {
  358. switch (pin)
  359. {
  360. case (kSNVS_ExternalTamper1):
  361. base->LPTDCR = (base->LPTDCR & ~(1U << SNVS_LPTDCR_ET1P_SHIFT)) | (polarity << SNVS_LPTDCR_ET1P_SHIFT);
  362. base->LPTDCR |= SNVS_LPTDCR_ET1_EN_MASK;
  363. break;
  364. #if defined(FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER) && (FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER > 1)
  365. case (kSNVS_ExternalTamper2):
  366. base->LPTDCR = (base->LPTDCR & ~(1U << SNVS_LPTDCR_ET2P_SHIFT)) | (polarity << SNVS_LPTDCR_ET2P_SHIFT);
  367. base->LPTDCR |= SNVS_LPTDCR_ET2_EN_MASK;
  368. break;
  369. case (kSNVS_ExternalTamper3):
  370. base->LPTDC2R = (base->LPTDC2R & ~(1U << SNVS_LPTDC2R_ET3P_SHIFT)) | (polarity << SNVS_LPTDC2R_ET3P_SHIFT);
  371. base->LPTDC2R |= SNVS_LPTDC2R_ET3_EN_MASK;
  372. break;
  373. case (kSNVS_ExternalTamper4):
  374. base->LPTDC2R = (base->LPTDC2R & ~(1U << SNVS_LPTDC2R_ET4P_SHIFT)) | (polarity << SNVS_LPTDC2R_ET4P_SHIFT);
  375. base->LPTDC2R |= SNVS_LPTDC2R_ET4_EN_MASK;
  376. break;
  377. case (kSNVS_ExternalTamper5):
  378. base->LPTDC2R = (base->LPTDC2R & ~(1U << SNVS_LPTDC2R_ET5P_SHIFT)) | (polarity << SNVS_LPTDC2R_ET5P_SHIFT);
  379. base->LPTDC2R |= SNVS_LPTDC2R_ET5_EN_MASK;
  380. break;
  381. case (kSNVS_ExternalTamper6):
  382. base->LPTDC2R = (base->LPTDC2R & ~(1U << SNVS_LPTDC2R_ET6P_SHIFT)) | (polarity << SNVS_LPTDC2R_ET6P_SHIFT);
  383. base->LPTDC2R |= SNVS_LPTDC2R_ET6_EN_MASK;
  384. break;
  385. case (kSNVS_ExternalTamper7):
  386. base->LPTDC2R = (base->LPTDC2R & ~(1U << SNVS_LPTDC2R_ET7P_SHIFT)) | (polarity << SNVS_LPTDC2R_ET7P_SHIFT);
  387. base->LPTDC2R |= SNVS_LPTDC2R_ET7_EN_MASK;
  388. break;
  389. case (kSNVS_ExternalTamper8):
  390. base->LPTDC2R = (base->LPTDC2R & ~(1U << SNVS_LPTDC2R_ET8P_SHIFT)) | (polarity << SNVS_LPTDC2R_ET8P_SHIFT);
  391. base->LPTDC2R |= SNVS_LPTDC2R_ET8_EN_MASK;
  392. break;
  393. case (kSNVS_ExternalTamper9):
  394. base->LPTDC2R = (base->LPTDC2R & ~(1U << SNVS_LPTDC2R_ET9P_SHIFT)) | (polarity << SNVS_LPTDC2R_ET9P_SHIFT);
  395. base->LPTDC2R |= SNVS_LPTDC2R_ET9_EN_MASK;
  396. break;
  397. case (kSNVS_ExternalTamper10):
  398. base->LPTDC2R =
  399. (base->LPTDC2R & ~(1U << SNVS_LPTDC2R_ET10P_SHIFT)) | (polarity << SNVS_LPTDC2R_ET10P_SHIFT);
  400. base->LPTDC2R |= SNVS_LPTDC2R_ET10_EN_MASK;
  401. break;
  402. #endif
  403. default:
  404. break;
  405. }
  406. }
  407. void SNVS_LP_DisableExternalTamper(SNVS_Type *base, snvs_lp_external_tamper_t pin)
  408. {
  409. switch (pin)
  410. {
  411. case (kSNVS_ExternalTamper1):
  412. base->LPTDCR &= ~SNVS_LPTDCR_ET1_EN_MASK;
  413. break;
  414. #if defined(FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER) && (FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER > 1)
  415. case (kSNVS_ExternalTamper2):
  416. base->LPTDCR &= ~SNVS_LPTDCR_ET2_EN_MASK;
  417. break;
  418. case (kSNVS_ExternalTamper3):
  419. base->LPTDC2R &= ~SNVS_LPTDC2R_ET3_EN_MASK;
  420. break;
  421. case (kSNVS_ExternalTamper4):
  422. base->LPTDC2R &= ~SNVS_LPTDC2R_ET4_EN_MASK;
  423. break;
  424. case (kSNVS_ExternalTamper5):
  425. base->LPTDC2R &= ~SNVS_LPTDC2R_ET5_EN_MASK;
  426. break;
  427. case (kSNVS_ExternalTamper6):
  428. base->LPTDC2R &= ~SNVS_LPTDC2R_ET6_EN_MASK;
  429. break;
  430. case (kSNVS_ExternalTamper7):
  431. base->LPTDC2R &= ~SNVS_LPTDC2R_ET7_EN_MASK;
  432. break;
  433. case (kSNVS_ExternalTamper8):
  434. base->LPTDC2R &= ~SNVS_LPTDC2R_ET8_EN_MASK;
  435. break;
  436. case (kSNVS_ExternalTamper9):
  437. base->LPTDC2R &= ~SNVS_LPTDC2R_ET9_EN_MASK;
  438. break;
  439. case (kSNVS_ExternalTamper10):
  440. base->LPTDC2R &= ~SNVS_LPTDC2R_ET10_EN_MASK;
  441. break;
  442. #endif
  443. default:
  444. break;
  445. }
  446. }
  447. snvs_lp_external_tamper_status_t SNVS_LP_GetExternalTamperStatus(SNVS_Type *base, snvs_lp_external_tamper_t pin)
  448. {
  449. snvs_lp_external_tamper_status_t status = kSNVS_TamperNotDetected;
  450. switch (pin)
  451. {
  452. case (kSNVS_ExternalTamper1):
  453. status = (base->LPSR & SNVS_LPSR_ET1D_MASK) ? kSNVS_TamperDetected : kSNVS_TamperNotDetected;
  454. break;
  455. #if defined(FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER) && (FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER > 1)
  456. case (kSNVS_ExternalTamper2):
  457. status = (base->LPSR & SNVS_LPSR_ET2D_MASK) ? kSNVS_TamperDetected : kSNVS_TamperNotDetected;
  458. break;
  459. case (kSNVS_ExternalTamper3):
  460. status = (base->LPTDSR & SNVS_LPTDSR_ET3D_MASK) ? kSNVS_TamperDetected : kSNVS_TamperNotDetected;
  461. break;
  462. case (kSNVS_ExternalTamper4):
  463. status = (base->LPTDSR & SNVS_LPTDSR_ET4D_MASK) ? kSNVS_TamperDetected : kSNVS_TamperNotDetected;
  464. break;
  465. case (kSNVS_ExternalTamper5):
  466. status = (base->LPTDSR & SNVS_LPTDSR_ET5D_MASK) ? kSNVS_TamperDetected : kSNVS_TamperNotDetected;
  467. break;
  468. case (kSNVS_ExternalTamper6):
  469. status = (base->LPTDSR & SNVS_LPTDSR_ET6D_MASK) ? kSNVS_TamperDetected : kSNVS_TamperNotDetected;
  470. break;
  471. case (kSNVS_ExternalTamper7):
  472. status = (base->LPTDSR & SNVS_LPTDSR_ET7D_MASK) ? kSNVS_TamperDetected : kSNVS_TamperNotDetected;
  473. break;
  474. case (kSNVS_ExternalTamper8):
  475. status = (base->LPTDSR & SNVS_LPTDSR_ET8D_MASK) ? kSNVS_TamperDetected : kSNVS_TamperNotDetected;
  476. break;
  477. case (kSNVS_ExternalTamper9):
  478. status = (base->LPTDSR & SNVS_LPTDSR_ET9D_MASK) ? kSNVS_TamperDetected : kSNVS_TamperNotDetected;
  479. break;
  480. case (kSNVS_ExternalTamper10):
  481. status = (base->LPTDSR & SNVS_LPTDSR_ET10D_MASK) ? kSNVS_TamperDetected : kSNVS_TamperNotDetected;
  482. break;
  483. #endif
  484. default:
  485. break;
  486. }
  487. return status;
  488. }
  489. void SNVS_LP_ClearExternalTamperStatus(SNVS_Type *base, snvs_lp_external_tamper_t pin)
  490. {
  491. base->LPSR |= SNVS_LPSR_ET1D_MASK;
  492. switch (pin)
  493. {
  494. case (kSNVS_ExternalTamper1):
  495. base->LPSR |= SNVS_LPSR_ET1D_MASK;
  496. break;
  497. #if defined(FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER) && (FSL_FEATURE_SNVS_HAS_MULTIPLE_TAMPER > 1)
  498. case (kSNVS_ExternalTamper2):
  499. base->LPSR |= SNVS_LPSR_ET2D_MASK;
  500. break;
  501. case (kSNVS_ExternalTamper3):
  502. base->LPTDSR |= SNVS_LPTDSR_ET3D_MASK;
  503. break;
  504. case (kSNVS_ExternalTamper4):
  505. base->LPTDSR |= SNVS_LPTDSR_ET4D_MASK;
  506. break;
  507. case (kSNVS_ExternalTamper5):
  508. base->LPTDSR |= SNVS_LPTDSR_ET5D_MASK;
  509. break;
  510. case (kSNVS_ExternalTamper6):
  511. base->LPTDSR |= SNVS_LPTDSR_ET6D_MASK;
  512. break;
  513. case (kSNVS_ExternalTamper7):
  514. base->LPTDSR |= SNVS_LPTDSR_ET7D_MASK;
  515. break;
  516. case (kSNVS_ExternalTamper8):
  517. base->LPTDSR |= SNVS_LPTDSR_ET8D_MASK;
  518. break;
  519. case (kSNVS_ExternalTamper9):
  520. base->LPTDSR |= SNVS_LPTDSR_ET9D_MASK;
  521. break;
  522. case (kSNVS_ExternalTamper10):
  523. base->LPTDSR |= SNVS_LPTDSR_ET10D_MASK;
  524. break;
  525. #endif
  526. default:
  527. break;
  528. }
  529. }