您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

413 行
15 KiB

  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017, 2019-2020 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_RCM_H_
  9. #define _FSL_RCM_H_
  10. #include "fsl_common.h"
  11. /*! @addtogroup rcm */
  12. /*! @{*/
  13. /*******************************************************************************
  14. * Definitions
  15. ******************************************************************************/
  16. /*! @name Driver version */
  17. /*@{*/
  18. /*! @brief RCM driver version 2.0.4. */
  19. #define FSL_RCM_DRIVER_VERSION (MAKE_VERSION(2, 0, 4))
  20. /*@}*/
  21. /*!
  22. * @brief System Reset Source Name definitions
  23. */
  24. typedef enum _rcm_reset_source
  25. {
  26. #if (defined(FSL_FEATURE_RCM_REG_WIDTH) && (FSL_FEATURE_RCM_REG_WIDTH == 32))
  27. /* RCM register bit width is 32. */
  28. #if (defined(FSL_FEATURE_RCM_HAS_WAKEUP) && FSL_FEATURE_RCM_HAS_WAKEUP)
  29. kRCM_SourceWakeup = RCM_SRS_WAKEUP_MASK, /*!< Low-leakage wakeup reset */
  30. #endif
  31. kRCM_SourceLvd = RCM_SRS_LVD_MASK, /*!< Low-voltage detect reset */
  32. #if (defined(FSL_FEATURE_RCM_HAS_LOC) && FSL_FEATURE_RCM_HAS_LOC)
  33. kRCM_SourceLoc = RCM_SRS_LOC_MASK, /*!< Loss of clock reset */
  34. #endif /* FSL_FEATURE_RCM_HAS_LOC */
  35. #if (defined(FSL_FEATURE_RCM_HAS_LOL) && FSL_FEATURE_RCM_HAS_LOL)
  36. kRCM_SourceLol = RCM_SRS_LOL_MASK, /*!< Loss of lock reset */
  37. #endif /* FSL_FEATURE_RCM_HAS_LOL */
  38. kRCM_SourceWdog = RCM_SRS_WDOG_MASK, /*!< Watchdog reset */
  39. kRCM_SourcePin = RCM_SRS_PIN_MASK, /*!< External pin reset */
  40. kRCM_SourcePor = RCM_SRS_POR_MASK, /*!< Power on reset */
  41. #if (defined(FSL_FEATURE_RCM_HAS_JTAG) && FSL_FEATURE_RCM_HAS_JTAG)
  42. kRCM_SourceJtag = RCM_SRS_JTAG_MASK, /*!< JTAG generated reset */
  43. #endif /* FSL_FEATURE_RCM_HAS_JTAG */
  44. kRCM_SourceLockup = RCM_SRS_LOCKUP_MASK, /*!< Core lock up reset */
  45. kRCM_SourceSw = RCM_SRS_SW_MASK, /*!< Software reset */
  46. #if (defined(FSL_FEATURE_RCM_HAS_MDM_AP) && FSL_FEATURE_RCM_HAS_MDM_AP)
  47. kRCM_SourceMdmap = RCM_SRS_MDM_AP_MASK, /*!< MDM-AP system reset */
  48. #endif /* FSL_FEATURE_RCM_HAS_MDM_AP */
  49. #if (defined(FSL_FEATURE_RCM_HAS_EZPORT) && FSL_FEATURE_RCM_HAS_EZPORT)
  50. kRCM_SourceEzpt = RCM_SRS_EZPT_MASK, /*!< EzPort reset */
  51. #endif /* FSL_FEATURE_RCM_HAS_EZPORT */
  52. kRCM_SourceSackerr = RCM_SRS_SACKERR_MASK, /*!< Parameter could get all reset flags */
  53. #else /* (FSL_FEATURE_RCM_REG_WIDTH == 32) */
  54. /* RCM register bit width is 8. */
  55. #if (defined(FSL_FEATURE_RCM_HAS_WAKEUP) && FSL_FEATURE_RCM_HAS_WAKEUP)
  56. kRCM_SourceWakeup = RCM_SRS0_WAKEUP_MASK, /*!< Low-leakage wakeup reset */
  57. #endif
  58. kRCM_SourceLvd = RCM_SRS0_LVD_MASK, /*!< Low-voltage detect reset */
  59. #if (defined(FSL_FEATURE_RCM_HAS_LOC) && FSL_FEATURE_RCM_HAS_LOC)
  60. kRCM_SourceLoc = RCM_SRS0_LOC_MASK, /*!< Loss of clock reset */
  61. #endif /* FSL_FEATURE_RCM_HAS_LOC */
  62. #if (defined(FSL_FEATURE_RCM_HAS_LOL) && FSL_FEATURE_RCM_HAS_LOL)
  63. kRCM_SourceLol = RCM_SRS0_LOL_MASK, /*!< Loss of lock reset */
  64. #endif /* FSL_FEATURE_RCM_HAS_LOL */
  65. kRCM_SourceWdog = RCM_SRS0_WDOG_MASK, /*!< Watchdog reset */
  66. kRCM_SourcePin = RCM_SRS0_PIN_MASK, /*!< External pin reset */
  67. kRCM_SourcePor = RCM_SRS0_POR_MASK, /*!< Power on reset */
  68. #if (defined(FSL_FEATURE_RCM_HAS_JTAG) && FSL_FEATURE_RCM_HAS_JTAG)
  69. kRCM_SourceJtag = RCM_SRS1_JTAG_MASK << 8U, /*!< JTAG generated reset */
  70. #endif /* FSL_FEATURE_RCM_HAS_JTAG */
  71. kRCM_SourceLockup = RCM_SRS1_LOCKUP_MASK << 8U, /*!< Core lock up reset */
  72. kRCM_SourceSw = RCM_SRS1_SW_MASK << 8U, /*!< Software reset */
  73. #if (defined(FSL_FEATURE_RCM_HAS_MDM_AP) && FSL_FEATURE_RCM_HAS_MDM_AP)
  74. kRCM_SourceMdmap = RCM_SRS1_MDM_AP_MASK << 8U, /*!< MDM-AP system reset */
  75. #endif /* FSL_FEATURE_RCM_HAS_MDM_AP */
  76. #if (defined(FSL_FEATURE_RCM_HAS_EZPORT) && FSL_FEATURE_RCM_HAS_EZPORT)
  77. kRCM_SourceEzpt = RCM_SRS1_EZPT_MASK << 8U, /*!< EzPort reset */
  78. #endif /* FSL_FEATURE_RCM_HAS_EZPORT */
  79. kRCM_SourceSackerr = RCM_SRS1_SACKERR_MASK << 8U, /*!< Parameter could get all reset flags */
  80. #endif /* (FSL_FEATURE_RCM_REG_WIDTH == 32) */
  81. kRCM_SourceAll = (int)0xffffffffU,
  82. } rcm_reset_source_t;
  83. /*!
  84. * @brief Reset pin filter select in Run and Wait modes.
  85. */
  86. typedef enum _rcm_run_wait_filter_mode
  87. {
  88. kRCM_FilterDisable = 0U, /*!< All filtering disabled */
  89. kRCM_FilterBusClock = 1U, /*!< Bus clock filter enabled */
  90. kRCM_FilterLpoClock = 2U /*!< LPO clock filter enabled */
  91. } rcm_run_wait_filter_mode_t;
  92. #if (defined(FSL_FEATURE_RCM_HAS_BOOTROM) && FSL_FEATURE_RCM_HAS_BOOTROM)
  93. /*!
  94. * @brief Boot from ROM configuration.
  95. */
  96. typedef enum _rcm_boot_rom_config
  97. {
  98. kRCM_BootFlash = 0U, /*!< Boot from flash */
  99. kRCM_BootRomCfg0 = 1U, /*!< Boot from boot ROM due to BOOTCFG0 */
  100. kRCM_BootRomFopt = 2U, /*!< Boot from boot ROM due to FOPT[7] */
  101. kRCM_BootRomBoth = 3U /*!< Boot from boot ROM due to both BOOTCFG0 and FOPT[7] */
  102. } rcm_boot_rom_config_t;
  103. #endif /* FSL_FEATURE_RCM_HAS_BOOTROM */
  104. #if (defined(FSL_FEATURE_RCM_HAS_SRIE) && FSL_FEATURE_RCM_HAS_SRIE)
  105. /*!
  106. * @brief Maximum delay time from interrupt asserts to system reset.
  107. */
  108. typedef enum _rcm_reset_delay
  109. {
  110. kRCM_ResetDelay8Lpo = 0U, /*!< Delay 8 LPO cycles. */
  111. kRCM_ResetDelay32Lpo = 1U, /*!< Delay 32 LPO cycles. */
  112. kRCM_ResetDelay128Lpo = 2U, /*!< Delay 128 LPO cycles. */
  113. kRCM_ResetDelay512Lpo = 3U /*!< Delay 512 LPO cycles. */
  114. } rcm_reset_delay_t;
  115. /*!
  116. * @brief System reset interrupt enable bit definitions.
  117. */
  118. typedef enum _rcm_interrupt_enable
  119. {
  120. kRCM_IntNone = 0U, /*!< No interrupt enabled. */
  121. kRCM_IntLossOfClk = RCM_SRIE_LOC_MASK, /*!< Loss of clock interrupt. */
  122. kRCM_IntLossOfLock = RCM_SRIE_LOL_MASK, /*!< Loss of lock interrupt. */
  123. kRCM_IntWatchDog = RCM_SRIE_WDOG_MASK, /*!< Watch dog interrupt. */
  124. kRCM_IntExternalPin = RCM_SRIE_PIN_MASK, /*!< External pin interrupt. */
  125. kRCM_IntGlobal = RCM_SRIE_GIE_MASK, /*!< Global interrupts. */
  126. kRCM_IntCoreLockup = RCM_SRIE_LOCKUP_MASK, /*!< Core lock up interrupt */
  127. kRCM_IntSoftware = RCM_SRIE_SW_MASK, /*!< software interrupt */
  128. kRCM_IntStopModeAckErr = RCM_SRIE_SACKERR_MASK, /*!< Stop mode ACK error interrupt. */
  129. #if (defined(FSL_FEATURE_RCM_HAS_CORE1) && FSL_FEATURE_RCM_HAS_CORE1)
  130. kRCM_IntCore1 = RCM_SRIE_CORE1_MASK, /*!< Core 1 interrupt. */
  131. #endif
  132. kRCM_IntAll = RCM_SRIE_LOC_MASK /*!< Enable all interrupts. */
  133. | RCM_SRIE_LOL_MASK | RCM_SRIE_WDOG_MASK | RCM_SRIE_PIN_MASK | RCM_SRIE_GIE_MASK |
  134. RCM_SRIE_LOCKUP_MASK | RCM_SRIE_SW_MASK | RCM_SRIE_SACKERR_MASK
  135. #if (defined(FSL_FEATURE_RCM_HAS_CORE1) && FSL_FEATURE_RCM_HAS_CORE1)
  136. | RCM_SRIE_CORE1_MASK
  137. #endif
  138. } rcm_interrupt_enable_t;
  139. #endif /* FSL_FEATURE_RCM_HAS_SRIE */
  140. #if (defined(FSL_FEATURE_RCM_HAS_VERID) && FSL_FEATURE_RCM_HAS_VERID)
  141. /*!
  142. * @brief IP version ID definition.
  143. */
  144. typedef struct _rcm_version_id
  145. {
  146. uint16_t feature; /*!< Feature Specification Number. */
  147. uint8_t minor; /*!< Minor version number. */
  148. uint8_t major; /*!< Major version number. */
  149. } rcm_version_id_t;
  150. #endif
  151. /*!
  152. * @brief Reset pin filter configuration.
  153. */
  154. typedef struct _rcm_reset_pin_filter_config
  155. {
  156. bool enableFilterInStop; /*!< Reset pin filter select in stop mode. */
  157. rcm_run_wait_filter_mode_t filterInRunWait; /*!< Reset pin filter in run/wait mode. */
  158. uint8_t busClockFilterCount; /*!< Reset pin bus clock filter width. */
  159. } rcm_reset_pin_filter_config_t;
  160. /*******************************************************************************
  161. * API
  162. ******************************************************************************/
  163. #if defined(__cplusplus)
  164. extern "C" {
  165. #endif /* __cplusplus*/
  166. /*! @name Reset Control Module APIs*/
  167. /*@{*/
  168. #if (defined(FSL_FEATURE_RCM_HAS_VERID) && FSL_FEATURE_RCM_HAS_VERID)
  169. /*!
  170. * @brief Gets the RCM version ID.
  171. *
  172. * This function gets the RCM version ID including the major version number,
  173. * the minor version number, and the feature specification number.
  174. *
  175. * @param base RCM peripheral base address.
  176. * @param versionId Pointer to the version ID structure.
  177. */
  178. static inline void RCM_GetVersionId(RCM_Type *base, rcm_version_id_t *versionId)
  179. {
  180. uint32_t tmp = base->VERID;
  181. versionId->feature = (uint16_t)(tmp & 0x0000FFFFUL);
  182. versionId->minor = (uint8_t)((tmp & 0x00FF0000UL) >> 16U);
  183. versionId->major = (uint8_t)((tmp & 0x000000FFUL) >> 24U);
  184. }
  185. #endif
  186. #if (defined(FSL_FEATURE_RCM_HAS_PARAM) && FSL_FEATURE_RCM_HAS_PARAM)
  187. /*!
  188. * @brief Gets the reset source implemented status.
  189. *
  190. * This function gets the RCM parameter that indicates whether the corresponding reset source is implemented.
  191. * Use source masks defined in the rcm_reset_source_t to get the desired source status.
  192. *
  193. * This is an example.
  194. * @code
  195. * uint32_t status;
  196. *
  197. * To test whether the MCU is reset using Watchdog.
  198. * status = RCM_GetResetSourceImplementedStatus(RCM) & (kRCM_SourceWdog | kRCM_SourcePin);
  199. * @endcode
  200. *
  201. * @param base RCM peripheral base address.
  202. * @return All reset source implemented status bit map.
  203. */
  204. static inline uint32_t RCM_GetResetSourceImplementedStatus(RCM_Type *base)
  205. {
  206. return base->PARAM;
  207. }
  208. #endif /* FSL_FEATURE_RCM_HAS_PARAM */
  209. /*!
  210. * @brief Gets the reset source status which caused a previous reset.
  211. *
  212. * This function gets the current reset source status. Use source masks
  213. * defined in the rcm_reset_source_t to get the desired source status.
  214. *
  215. * This is an example.
  216. * @code
  217. * uint32_t resetStatus;
  218. *
  219. * To get all reset source statuses.
  220. * resetStatus = RCM_GetPreviousResetSources(RCM) & kRCM_SourceAll;
  221. *
  222. * To test whether the MCU is reset using Watchdog.
  223. * resetStatus = RCM_GetPreviousResetSources(RCM) & kRCM_SourceWdog;
  224. *
  225. * To test multiple reset sources.
  226. * resetStatus = RCM_GetPreviousResetSources(RCM) & (kRCM_SourceWdog | kRCM_SourcePin);
  227. * @endcode
  228. *
  229. * @param base RCM peripheral base address.
  230. * @return All reset source status bit map.
  231. */
  232. static inline uint32_t RCM_GetPreviousResetSources(RCM_Type *base)
  233. {
  234. #if (defined(FSL_FEATURE_RCM_REG_WIDTH) && (FSL_FEATURE_RCM_REG_WIDTH == 32))
  235. return base->SRS;
  236. #else
  237. uint8_t tmpSrs0 = base->SRS0;
  238. uint8_t tmpSrs1 = base->SRS1;
  239. return (uint32_t)((uint32_t)tmpSrs0 | ((uint32_t)tmpSrs1 << 8U));
  240. #endif /* (FSL_FEATURE_RCM_REG_WIDTH == 32) */
  241. }
  242. #if (defined(FSL_FEATURE_RCM_HAS_SSRS) && FSL_FEATURE_RCM_HAS_SSRS)
  243. /*!
  244. * @brief Gets the sticky reset source status.
  245. *
  246. * This function gets the current reset source status that has not been cleared
  247. * by software for a specific source.
  248. *
  249. * This is an example.
  250. * @code
  251. * uint32_t resetStatus;
  252. *
  253. * To get all reset source statuses.
  254. * resetStatus = RCM_GetStickyResetSources(RCM) & kRCM_SourceAll;
  255. *
  256. * To test whether the MCU is reset using Watchdog.
  257. * resetStatus = RCM_GetStickyResetSources(RCM) & kRCM_SourceWdog;
  258. *
  259. * To test multiple reset sources.
  260. * resetStatus = RCM_GetStickyResetSources(RCM) & (kRCM_SourceWdog | kRCM_SourcePin);
  261. * @endcode
  262. *
  263. * @param base RCM peripheral base address.
  264. * @return All reset source status bit map.
  265. */
  266. static inline uint32_t RCM_GetStickyResetSources(RCM_Type *base)
  267. {
  268. #if (defined(FSL_FEATURE_RCM_REG_WIDTH) && (FSL_FEATURE_RCM_REG_WIDTH == 32))
  269. return base->SSRS;
  270. #else
  271. return (base->SSRS0 | ((uint32_t)base->SSRS1 << 8U));
  272. #endif /* (FSL_FEATURE_RCM_REG_WIDTH == 32) */
  273. }
  274. /*!
  275. * @brief Clears the sticky reset source status.
  276. *
  277. * This function clears the sticky system reset flags indicated by source masks.
  278. *
  279. * This is an example.
  280. * @code
  281. * Clears multiple reset sources.
  282. * RCM_ClearStickyResetSources(kRCM_SourceWdog | kRCM_SourcePin);
  283. * @endcode
  284. *
  285. * @param base RCM peripheral base address.
  286. * @param sourceMasks reset source status bit map
  287. */
  288. static inline void RCM_ClearStickyResetSources(RCM_Type *base, uint32_t sourceMasks)
  289. {
  290. #if (defined(FSL_FEATURE_RCM_REG_WIDTH) && (FSL_FEATURE_RCM_REG_WIDTH == 32))
  291. base->SSRS = sourceMasks;
  292. #else
  293. base->SSRS0 = (uint8_t)(sourceMasks & 0xffU);
  294. base->SSRS1 = (uint8_t)((sourceMasks >> 8U) & 0xffU);
  295. #endif /* (FSL_FEATURE_RCM_REG_WIDTH == 32) */
  296. }
  297. #endif /* FSL_FEATURE_RCM_HAS_SSRS */
  298. /*!
  299. * @brief Configures the reset pin filter.
  300. *
  301. * This function sets the reset pin filter including the filter source, filter
  302. * width, and so on.
  303. *
  304. * @param base RCM peripheral base address.
  305. * @param config Pointer to the configuration structure.
  306. */
  307. void RCM_ConfigureResetPinFilter(RCM_Type *base, const rcm_reset_pin_filter_config_t *config);
  308. #if (defined(FSL_FEATURE_RCM_HAS_EZPMS) && FSL_FEATURE_RCM_HAS_EZPMS)
  309. /*!
  310. * @brief Gets the EZP_MS_B pin assert status.
  311. *
  312. * This function gets the easy port mode status (EZP_MS_B) pin assert status.
  313. *
  314. * @param base RCM peripheral base address.
  315. * @return status true - asserted, false - reasserted
  316. */
  317. static inline bool RCM_GetEasyPortModePinStatus(RCM_Type *base)
  318. {
  319. return (bool)(base->MR & RCM_MR_EZP_MS_MASK);
  320. }
  321. #endif /* FSL_FEATURE_RCM_HAS_EZPMS */
  322. #if (defined(FSL_FEATURE_RCM_HAS_BOOTROM) && FSL_FEATURE_RCM_HAS_BOOTROM)
  323. /*!
  324. * @brief Gets the ROM boot source.
  325. *
  326. * This function gets the ROM boot source during the last chip reset.
  327. *
  328. * @param base RCM peripheral base address.
  329. * @return The ROM boot source.
  330. */
  331. static inline rcm_boot_rom_config_t RCM_GetBootRomSource(RCM_Type *base)
  332. {
  333. return (rcm_boot_rom_config_t)(uint8_t)((base->MR & RCM_MR_BOOTROM_MASK) >> RCM_MR_BOOTROM_SHIFT);
  334. }
  335. /*!
  336. * @brief Clears the ROM boot source flag.
  337. *
  338. * This function clears the ROM boot source flag.
  339. *
  340. * @param base Register base address of RCM
  341. */
  342. static inline void RCM_ClearBootRomSource(RCM_Type *base)
  343. {
  344. base->MR |= RCM_MR_BOOTROM_MASK;
  345. }
  346. /*!
  347. * @brief Forces the boot from ROM.
  348. *
  349. * This function forces booting from ROM during all subsequent system resets.
  350. *
  351. * @param base RCM peripheral base address.
  352. * @param config Boot configuration.
  353. */
  354. void RCM_SetForceBootRomSource(RCM_Type *base, rcm_boot_rom_config_t config);
  355. #endif /* FSL_FEATURE_RCM_HAS_BOOTROM */
  356. #if (defined(FSL_FEATURE_RCM_HAS_SRIE) && FSL_FEATURE_RCM_HAS_SRIE)
  357. /*!
  358. * @brief Sets the system reset interrupt configuration.
  359. *
  360. * For a graceful shut down, the RCM supports delaying the assertion of the system
  361. * reset for a period of time when the reset interrupt is generated. This function
  362. * can be used to enable the interrupt and the delay period. The interrupts
  363. * are passed in as bit mask. See rcm_int_t for details. For example, to
  364. * delay a reset for 512 LPO cycles after the WDOG timeout or loss-of-clock occurs,
  365. * configure as follows:
  366. * RCM_SetSystemResetInterruptConfig(kRCM_IntWatchDog | kRCM_IntLossOfClk, kRCM_ResetDelay512Lpo);
  367. *
  368. * @param base RCM peripheral base address.
  369. * @param intMask Bit mask of the system reset interrupts to enable. See
  370. * rcm_interrupt_enable_t for details.
  371. * @param delay Bit mask of the system reset interrupts to enable.
  372. */
  373. static inline void RCM_SetSystemResetInterruptConfig(RCM_Type *base, uint32_t intMask, rcm_reset_delay_t delay)
  374. {
  375. base->SRIE = (intMask | (uint32_t)delay);
  376. }
  377. #endif /* FSL_FEATURE_RCM_HAS_SRIE */
  378. /*@}*/
  379. #if defined(__cplusplus)
  380. }
  381. #endif /* __cplusplus*/
  382. /*! @}*/
  383. #endif /* _FSL_RCM_H_ */