You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

422 line
15 KiB

  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017, 2020 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_SMC_H_
  9. #define _FSL_SMC_H_
  10. #include "fsl_common.h"
  11. /*! @addtogroup smc */
  12. /*! @{ */
  13. /*******************************************************************************
  14. * Definitions
  15. ******************************************************************************/
  16. /*! @name Driver version */
  17. /*@{*/
  18. /*! @brief SMC driver version */
  19. #define FSL_SMC_DRIVER_VERSION (MAKE_VERSION(2, 0, 7))
  20. /*@}*/
  21. /*!
  22. * @brief Power Modes Protection
  23. */
  24. typedef enum _smc_power_mode_protection
  25. {
  26. #if (defined(FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE)
  27. kSMC_AllowPowerModeVlls = SMC_PMPROT_AVLLS_MASK, /*!< Allow Very-low-leakage Stop Mode. */
  28. #endif
  29. #if (defined(FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE)
  30. kSMC_AllowPowerModeLls = SMC_PMPROT_ALLS_MASK, /*!< Allow Low-leakage Stop Mode. */
  31. #endif /* FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE */
  32. kSMC_AllowPowerModeVlp = SMC_PMPROT_AVLP_MASK, /*!< Allow Very-Low-power Mode. */
  33. #if (defined(FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE) && FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE)
  34. kSMC_AllowPowerModeHsrun = SMC_PMPROT_AHSRUN_MASK, /*!< Allow High-speed Run mode. */
  35. #endif /* FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE */
  36. kSMC_AllowPowerModeAll = (0U
  37. #if (defined(FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE)
  38. | SMC_PMPROT_AVLLS_MASK
  39. #endif
  40. #if (defined(FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE)
  41. | SMC_PMPROT_ALLS_MASK
  42. #endif /* FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE */
  43. | SMC_PMPROT_AVLP_MASK
  44. #if (defined(FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE) && FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE)
  45. | kSMC_AllowPowerModeHsrun
  46. #endif /* FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE */
  47. ) /*!< Allow all power mode. */
  48. } smc_power_mode_protection_t;
  49. /*!
  50. * @brief Power Modes in PMSTAT
  51. */
  52. typedef enum _smc_power_state
  53. {
  54. kSMC_PowerStateRun = 0x01U << 0U, /*!< 0000_0001 - Current power mode is RUN */
  55. kSMC_PowerStateStop = 0x01U << 1U, /*!< 0000_0010 - Current power mode is STOP */
  56. kSMC_PowerStateVlpr = 0x01U << 2U, /*!< 0000_0100 - Current power mode is VLPR */
  57. kSMC_PowerStateVlpw = 0x01U << 3U, /*!< 0000_1000 - Current power mode is VLPW */
  58. kSMC_PowerStateVlps = 0x01U << 4U, /*!< 0001_0000 - Current power mode is VLPS */
  59. #if (defined(FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE)
  60. kSMC_PowerStateLls = 0x01U << 5U, /*!< 0010_0000 - Current power mode is LLS */
  61. #endif /* FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE */
  62. #if (defined(FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE)
  63. kSMC_PowerStateVlls = 0x01U << 6U, /*!< 0100_0000 - Current power mode is VLLS */
  64. #endif
  65. #if (defined(FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE) && FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE)
  66. kSMC_PowerStateHsrun = 0x01U << 7U /*!< 1000_0000 - Current power mode is HSRUN */
  67. #endif /* FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE */
  68. } smc_power_state_t;
  69. /*!
  70. * @brief Run mode definition
  71. */
  72. typedef enum _smc_run_mode
  73. {
  74. kSMC_RunNormal = 0U, /*!< Normal RUN mode. */
  75. kSMC_RunVlpr = 2U, /*!< Very-low-power RUN mode. */
  76. #if (defined(FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE) && FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE)
  77. kSMC_Hsrun = 3U /*!< High-speed Run mode (HSRUN). */
  78. #endif /* FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE */
  79. } smc_run_mode_t;
  80. /*!
  81. * @brief Stop mode definition
  82. */
  83. typedef enum _smc_stop_mode
  84. {
  85. kSMC_StopNormal = 0U, /*!< Normal STOP mode. */
  86. kSMC_StopVlps = 2U, /*!< Very-low-power STOP mode. */
  87. #if (defined(FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE)
  88. kSMC_StopLls = 3U, /*!< Low-leakage Stop mode. */
  89. #endif /* FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE */
  90. #if (defined(FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE)
  91. kSMC_StopVlls = 4U /*!< Very-low-leakage Stop mode. */
  92. #endif
  93. } smc_stop_mode_t;
  94. #if (defined(FSL_FEATURE_SMC_USE_VLLSCTRL_REG) && FSL_FEATURE_SMC_USE_VLLSCTRL_REG) || \
  95. (defined(FSL_FEATURE_SMC_USE_STOPCTRL_VLLSM) && FSL_FEATURE_SMC_USE_STOPCTRL_VLLSM) || \
  96. (defined(FSL_FEATURE_SMC_HAS_LLS_SUBMODE) && FSL_FEATURE_SMC_HAS_LLS_SUBMODE)
  97. /*!
  98. * @brief VLLS/LLS stop sub mode definition
  99. */
  100. typedef enum _smc_stop_submode
  101. {
  102. kSMC_StopSub0 = 0U, /*!< Stop submode 0, for VLLS0/LLS0. */
  103. kSMC_StopSub1 = 1U, /*!< Stop submode 1, for VLLS1/LLS1. */
  104. kSMC_StopSub2 = 2U, /*!< Stop submode 2, for VLLS2/LLS2. */
  105. kSMC_StopSub3 = 3U /*!< Stop submode 3, for VLLS3/LLS3. */
  106. } smc_stop_submode_t;
  107. #endif
  108. /*!
  109. * @brief Partial STOP option
  110. */
  111. typedef enum _smc_partial_stop_mode
  112. {
  113. kSMC_PartialStop = 0U, /*!< STOP - Normal Stop mode*/
  114. kSMC_PartialStop1 = 1U, /*!< Partial Stop with both system and bus clocks disabled*/
  115. kSMC_PartialStop2 = 2U, /*!< Partial Stop with system clock disabled and bus clock enabled*/
  116. } smc_partial_stop_option_t;
  117. /*!
  118. * @brief _smc_status, SMC configuration status.
  119. */
  120. enum
  121. {
  122. kStatus_SMC_StopAbort = MAKE_STATUS(kStatusGroup_POWER, 0) /*!< Entering Stop mode is abort*/
  123. };
  124. #if (defined(FSL_FEATURE_SMC_HAS_VERID) && FSL_FEATURE_SMC_HAS_VERID)
  125. /*!
  126. * @brief IP version ID definition.
  127. */
  128. typedef struct _smc_version_id
  129. {
  130. uint16_t feature; /*!< Feature Specification Number. */
  131. uint8_t minor; /*!< Minor version number. */
  132. uint8_t major; /*!< Major version number. */
  133. } smc_version_id_t;
  134. #endif /* FSL_FEATURE_SMC_HAS_VERID */
  135. #if (defined(FSL_FEATURE_SMC_HAS_PARAM) && FSL_FEATURE_SMC_HAS_PARAM)
  136. /*!
  137. * @brief IP parameter definition.
  138. */
  139. typedef struct _smc_param
  140. {
  141. bool hsrunEnable; /*!< HSRUN mode enable. */
  142. bool llsEnable; /*!< LLS mode enable. */
  143. bool lls2Enable; /*!< LLS2 mode enable. */
  144. bool vlls0Enable; /*!< VLLS0 mode enable. */
  145. } smc_param_t;
  146. #endif /* FSL_FEATURE_SMC_HAS_PARAM */
  147. #if (defined(FSL_FEATURE_SMC_HAS_LLS_SUBMODE) && FSL_FEATURE_SMC_HAS_LLS_SUBMODE) || \
  148. (defined(FSL_FEATURE_SMC_HAS_LPOPO) && FSL_FEATURE_SMC_HAS_LPOPO)
  149. /*!
  150. * @brief SMC Low-Leakage Stop power mode configuration.
  151. */
  152. typedef struct _smc_power_mode_lls_config
  153. {
  154. #if (defined(FSL_FEATURE_SMC_HAS_LLS_SUBMODE) && FSL_FEATURE_SMC_HAS_LLS_SUBMODE)
  155. smc_stop_submode_t subMode; /*!< Low-leakage Stop sub-mode */
  156. #endif
  157. #if (defined(FSL_FEATURE_SMC_HAS_LPOPO) && FSL_FEATURE_SMC_HAS_LPOPO)
  158. bool enableLpoClock; /*!< Enable LPO clock in LLS mode */
  159. #endif
  160. } smc_power_mode_lls_config_t;
  161. #endif /* (FSL_FEATURE_SMC_HAS_LLS_SUBMODE || FSL_FEATURE_SMC_HAS_LPOPO) */
  162. #if (defined(FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE)
  163. /*!
  164. * @brief SMC Very Low-Leakage Stop power mode configuration.
  165. */
  166. typedef struct _smc_power_mode_vlls_config
  167. {
  168. #if (defined(FSL_FEATURE_SMC_USE_VLLSCTRL_REG) && FSL_FEATURE_SMC_USE_VLLSCTRL_REG) || \
  169. (defined(FSL_FEATURE_SMC_USE_STOPCTRL_VLLSM) && FSL_FEATURE_SMC_USE_STOPCTRL_VLLSM) || \
  170. (defined(FSL_FEATURE_SMC_HAS_LLS_SUBMODE) && FSL_FEATURE_SMC_HAS_LLS_SUBMODE)
  171. smc_stop_submode_t subMode; /*!< Very Low-leakage Stop sub-mode */
  172. #endif
  173. #if (defined(FSL_FEATURE_SMC_HAS_PORPO) && FSL_FEATURE_SMC_HAS_PORPO)
  174. bool enablePorDetectInVlls0; /*!< Enable Power on reset detect in VLLS mode */
  175. #endif
  176. #if (defined(FSL_FEATURE_SMC_HAS_RAM2_POWER_OPTION) && FSL_FEATURE_SMC_HAS_RAM2_POWER_OPTION)
  177. bool enableRam2InVlls2; /*!< Enable RAM2 power in VLLS2 */
  178. #endif
  179. #if (defined(FSL_FEATURE_SMC_HAS_LPOPO) && FSL_FEATURE_SMC_HAS_LPOPO)
  180. bool enableLpoClock; /*!< Enable LPO clock in VLLS mode */
  181. #endif
  182. } smc_power_mode_vlls_config_t;
  183. #endif
  184. /*******************************************************************************
  185. * API
  186. ******************************************************************************/
  187. #if defined(__cplusplus)
  188. extern "C" {
  189. #endif /* __cplusplus */
  190. /*! @name System mode controller APIs*/
  191. /*@{*/
  192. #if (defined(FSL_FEATURE_SMC_HAS_VERID) && FSL_FEATURE_SMC_HAS_VERID)
  193. /*!
  194. * @brief Gets the SMC version ID.
  195. *
  196. * This function gets the SMC version ID, including major version number,
  197. * minor version number, and feature specification number.
  198. *
  199. * @param base SMC peripheral base address.
  200. * @param versionId Pointer to the version ID structure.
  201. */
  202. static inline void SMC_GetVersionId(SMC_Type *base, smc_version_id_t *versionId)
  203. {
  204. *((uint32_t *)(uint32_t)versionId) = base->VERID;
  205. }
  206. #endif /* FSL_FEATURE_SMC_HAS_VERID */
  207. #if (defined(FSL_FEATURE_SMC_HAS_PARAM) && FSL_FEATURE_SMC_HAS_PARAM)
  208. /*!
  209. * @brief Gets the SMC parameter.
  210. *
  211. * This function gets the SMC parameter including the enabled power mdoes.
  212. *
  213. * @param base SMC peripheral base address.
  214. * @param param Pointer to the SMC param structure.
  215. */
  216. void SMC_GetParam(SMC_Type *base, smc_param_t *param);
  217. #endif
  218. /*!
  219. * @brief Configures all power mode protection settings.
  220. *
  221. * This function configures the power mode protection settings for
  222. * supported power modes in the specified chip family. The available power modes
  223. * are defined in the smc_power_mode_protection_t. This should be done at an early
  224. * system level initialization stage. See the reference manual for details.
  225. * This register can only write once after the power reset.
  226. *
  227. * The allowed modes are passed as bit map. For example, to allow LLS and VLLS,
  228. * use SMC_SetPowerModeProtection(kSMC_AllowPowerModeVlls | kSMC_AllowPowerModeVlps).
  229. * To allow all modes, use SMC_SetPowerModeProtection(kSMC_AllowPowerModeAll).
  230. *
  231. * @param base SMC peripheral base address.
  232. * @param allowedModes Bitmap of the allowed power modes.
  233. */
  234. static inline void SMC_SetPowerModeProtection(SMC_Type *base, uint8_t allowedModes)
  235. {
  236. base->PMPROT = allowedModes;
  237. }
  238. /*!
  239. * @brief Gets the current power mode status.
  240. *
  241. * This function returns the current power mode status. After the application
  242. * switches the power mode, it should always check the status to check whether it
  243. * runs into the specified mode or not. The application should check
  244. * this mode before switching to a different mode. The system requires that
  245. * only certain modes can switch to other specific modes. See the
  246. * reference manual for details and the smc_power_state_t for information about
  247. * the power status.
  248. *
  249. * @param base SMC peripheral base address.
  250. * @return Current power mode status.
  251. */
  252. static inline smc_power_state_t SMC_GetPowerModeState(SMC_Type *base)
  253. {
  254. return (smc_power_state_t)base->PMSTAT;
  255. }
  256. /*!
  257. * @brief Prepares to enter stop modes.
  258. *
  259. * This function should be called before entering STOP/VLPS/LLS/VLLS modes.
  260. */
  261. void SMC_PreEnterStopModes(void);
  262. /*!
  263. * @brief Recovers after wake up from stop modes.
  264. *
  265. * This function should be called after wake up from STOP/VLPS/LLS/VLLS modes.
  266. * It is used with @ref SMC_PreEnterStopModes.
  267. */
  268. void SMC_PostExitStopModes(void);
  269. /*!
  270. * @brief Prepares to enter wait modes.
  271. *
  272. * This function should be called before entering WAIT/VLPW modes.
  273. */
  274. void SMC_PreEnterWaitModes(void);
  275. /*!
  276. * @brief Recovers after wake up from stop modes.
  277. *
  278. * This function should be called after wake up from WAIT/VLPW modes.
  279. * It is used with @ref SMC_PreEnterWaitModes.
  280. */
  281. void SMC_PostExitWaitModes(void);
  282. /*!
  283. * @brief Configures the system to RUN power mode.
  284. *
  285. * @param base SMC peripheral base address.
  286. * @return SMC configuration error code.
  287. */
  288. status_t SMC_SetPowerModeRun(SMC_Type *base);
  289. #if (defined(FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE) && FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE)
  290. /*!
  291. * @brief Configures the system to HSRUN power mode.
  292. *
  293. * @param base SMC peripheral base address.
  294. * @return SMC configuration error code.
  295. */
  296. status_t SMC_SetPowerModeHsrun(SMC_Type *base);
  297. #endif /* FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE */
  298. /*!
  299. * @brief Configures the system to WAIT power mode.
  300. *
  301. * @param base SMC peripheral base address.
  302. * @return SMC configuration error code.
  303. */
  304. status_t SMC_SetPowerModeWait(SMC_Type *base);
  305. /*!
  306. * @brief Configures the system to Stop power mode.
  307. *
  308. * @param base SMC peripheral base address.
  309. * @param option Partial Stop mode option.
  310. * @return SMC configuration error code.
  311. */
  312. status_t SMC_SetPowerModeStop(SMC_Type *base, smc_partial_stop_option_t option);
  313. #if (defined(FSL_FEATURE_SMC_HAS_LPWUI) && FSL_FEATURE_SMC_HAS_LPWUI)
  314. /*!
  315. * @brief Configures the system to VLPR power mode.
  316. *
  317. * @param base SMC peripheral base address.
  318. * @param wakeupMode Enter Normal Run mode if true, else stay in VLPR mode.
  319. * @return SMC configuration error code.
  320. */
  321. status_t SMC_SetPowerModeVlpr(SMC_Type *base, bool wakeupMode);
  322. #else
  323. /*!
  324. * @brief Configures the system to VLPR power mode.
  325. *
  326. * @param base SMC peripheral base address.
  327. * @return SMC configuration error code.
  328. */
  329. status_t SMC_SetPowerModeVlpr(SMC_Type *base);
  330. #endif /* FSL_FEATURE_SMC_HAS_LPWUI */
  331. /*!
  332. * @brief Configures the system to VLPW power mode.
  333. *
  334. * @param base SMC peripheral base address.
  335. * @return SMC configuration error code.
  336. */
  337. status_t SMC_SetPowerModeVlpw(SMC_Type *base);
  338. /*!
  339. * @brief Configures the system to VLPS power mode.
  340. *
  341. * @param base SMC peripheral base address.
  342. * @return SMC configuration error code.
  343. */
  344. status_t SMC_SetPowerModeVlps(SMC_Type *base);
  345. #if (defined(FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE)
  346. #if ((defined(FSL_FEATURE_SMC_HAS_LLS_SUBMODE) && FSL_FEATURE_SMC_HAS_LLS_SUBMODE) || \
  347. (defined(FSL_FEATURE_SMC_HAS_LPOPO) && FSL_FEATURE_SMC_HAS_LPOPO))
  348. /*!
  349. * @brief Configures the system to LLS power mode.
  350. *
  351. * @param base SMC peripheral base address.
  352. * @param config The LLS power mode configuration structure
  353. * @return SMC configuration error code.
  354. */
  355. status_t SMC_SetPowerModeLls(SMC_Type *base, const smc_power_mode_lls_config_t *config);
  356. #else
  357. /*!
  358. * @brief Configures the system to LLS power mode.
  359. *
  360. * @param base SMC peripheral base address.
  361. * @return SMC configuration error code.
  362. */
  363. status_t SMC_SetPowerModeLls(SMC_Type *base);
  364. #endif
  365. #endif /* FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE */
  366. #if (defined(FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE)
  367. /*!
  368. * @brief Configures the system to VLLS power mode.
  369. *
  370. * @param base SMC peripheral base address.
  371. * @param config The VLLS power mode configuration structure.
  372. * @return SMC configuration error code.
  373. */
  374. status_t SMC_SetPowerModeVlls(SMC_Type *base, const smc_power_mode_vlls_config_t *config);
  375. #endif /* FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE */
  376. /*@}*/
  377. #if defined(__cplusplus)
  378. }
  379. #endif /* __cplusplus */
  380. /*! @}*/
  381. #endif /* _FSL_SMC_H_ */