fsl_ssarc.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. /*
  2. * Copyright 2020-2021 NXP
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef _FSL_SSARC_H_
  8. #define _FSL_SSARC_H_
  9. #include "fsl_common.h"
  10. /*!
  11. * @addtogroup ssarc
  12. * @{
  13. */
  14. /*******************************************************************************
  15. * Definitions
  16. ******************************************************************************/
  17. /*! @name Driver version */
  18. /*@{*/
  19. /*! @brief SSARC driver version 2.1.0. */
  20. #define FSL_SSARC_DRIVER_VERSION (MAKE_VERSION(2, 1, 0))
  21. /*@}*/
  22. #define SSARC_INT_STATUS_ALL \
  23. (SSARC_LP_INT_STATUS_ADDR_ERR_MASK | SSARC_LP_INT_STATUS_AHB_ERR_MASK | SSARC_LP_INT_STATUS_SW_REQ_DONE_MASK | \
  24. SSARC_LP_INT_STATUS_TIMEOUT_MASK | SSARC_LP_INT_STATUS_GROUP_CONFLICT_MASK)
  25. /*!
  26. * @brief The enumeration of ssarc status flags.
  27. */
  28. enum _ssarc_interrupt_status_flags
  29. {
  30. kSSARC_AddressErrorFlag = SSARC_LP_INT_STATUS_ADDR_ERR_MASK, /*!< If the descriptor is not in the range,
  31. assert address error. */
  32. kSSARC_AHBErrorFlag = SSARC_LP_INT_STATUS_AHB_ERR_MASK, /*!< If any AHB master access receives none-OKAY,
  33. assert AHB error. */
  34. kSSARC_SoftwareRequestDoneFlag = SSARC_LP_INT_STATUS_SW_REQ_DONE_MASK, /*!< If a software triggered save or restore
  35. process is completed, assert sofware
  36. request done . */
  37. kSSARC_TimeoutFlag = SSARC_LP_INT_STATUS_TIMEOUT_MASK, /*!< If processing of a group has exceeded the
  38. timeout value, assert timeout. */
  39. kSSARC_GroupConflictFlag = SSARC_LP_INT_STATUS_GROUP_CONFLICT_MASK, /*!< Group conflict. */
  40. };
  41. /*!
  42. * @brief The size of the register to be saved/restored.
  43. */
  44. typedef enum _ssarc_descriptor_register_size
  45. {
  46. kSSARC_DescriptorRegister8bitWidth = 0x0U, /*!< The register to be saved/restored is 8 bit width. */
  47. kSSARC_DescriptorRegister16bitWidth = 0x1U, /*!< The register to be saved/restored is 16 bit width. */
  48. kSSARC_DescriptorRegister32bitWidth = 0x2U, /*!< The register to be saved/restored is 32 bit width. */
  49. } ssarc_descriptor_register_size_t;
  50. /*!
  51. * @brief The operation of the descriptor.
  52. */
  53. typedef enum _ssarc_descriptor_operation
  54. {
  55. kSSARC_SaveDisableRestoreDisable = 0x0U, /*!< Disable Save operation, disable restore operation. */
  56. kSSARC_SaveEnableRestoreDisable = SSARC_HP_SRAM2_SV_EN_MASK, /*!< Enable Save operation,
  57. disable restore operation. */
  58. kSSARC_SaveDisableRestoreEnable = SSARC_HP_SRAM2_RT_EN_MASK, /*!< Disable Save operation,
  59. enable restore operation. */
  60. kSSARC_SaveEnableRestoreEnable = (SSARC_HP_SRAM2_RT_EN_MASK | SSARC_HP_SRAM2_SV_EN_MASK),
  61. /*!< Enable Save operation, enable restore operation. */
  62. } ssarc_descriptor_operation_t;
  63. /*!
  64. * @brief The type of operation.
  65. */
  66. typedef enum _ssarc_descriptor_type
  67. {
  68. kSSARC_ReadValueWriteBack = 0x00U, /*!< Read the register value on save operation
  69. and write it back on restore operation */
  70. kSSARC_WriteFixedValue = 0x01U, /*!< Always write a fixed value from DATA[31:0] */
  71. kSSARC_RMWOr = 0x02U, /*!< Read register, OR with the DATA[31:0], and write it back */
  72. kSSARC_RMWAnd = 0x03U, /*!< Read register, AND with the DATA[31:0], and write it back */
  73. kSSARC_DelayCycles = 0x04U, /*!< Delay for number of cycles based on the DATA[31:0] */
  74. kSSARC_Polling0 = 0x05U, /*!< Read the register until read_data[31:0] & DATA[31:0] == 0 */
  75. kSSARC_Polling1 = 0x06U, /*!< Read the register until read_data[31:0] & DATA[31:0] != 0 */
  76. } ssarc_descriptor_type_t;
  77. /*!
  78. * @brief The order of the restore/save operation.
  79. */
  80. typedef enum _ssarc_save_restore_order
  81. {
  82. kSSARC_ProcessFromStartToEnd = 0U, /*!< Descriptors within the group are processed from start to end. */
  83. kSSARC_ProcessFromEndToStart = 1U, /*!< Descriptors within the group are processed from end to start. */
  84. } ssarc_save_restore_order_t;
  85. /*!
  86. * @brief Software trigger mode.
  87. */
  88. typedef enum _ssarc_software_trigger_mode
  89. {
  90. kSSARC_TriggerSaveRequest = SSARC_LP_DESC_CTRL1_SW_TRIG_SV_MASK, /*!< Don't trigger restore operation, trigger the
  91. save operation by software. */
  92. kSSARC_TriggerRestoreRequest = SSARC_LP_DESC_CTRL1_SW_TRIG_RT_MASK, /*!< Trigger the restore operation, don't
  93. trigger the save operation. */
  94. } ssarc_software_trigger_mode_t;
  95. /*!
  96. * @brief The configuration of descriptor.
  97. */
  98. typedef struct _ssarc_descriptor_config
  99. {
  100. uint32_t address; /*!< The address of the register/memory to be saved/restored. */
  101. uint32_t data; /*!< The value of the register/memory to be saved/restored, please note that if the type
  102. is selected as kSSARC_ReadValueWriteBack, this data field is useless. */
  103. ssarc_descriptor_register_size_t size; /*!< The size of register to be saved/restored. */
  104. ssarc_descriptor_operation_t operation; /*!< The operation mode of descriptor. */
  105. ssarc_descriptor_type_t type; /*!< The type of operation. */
  106. } ssarc_descriptor_config_t;
  107. /*!
  108. * @brief The configuration of the group.
  109. */
  110. typedef struct _ssarc_group_config
  111. {
  112. ssarc_cpu_domain_name_t cpuDomain; /*!< CPU domain, define the ownership of this group. */
  113. uint32_t startIndex; /*!< The index of the first descriptor of the group. */
  114. uint32_t endIndex; /*!< The index of the last descriptor of the group. */
  115. ssarc_save_restore_order_t restoreOrder; /*!< The restore order. */
  116. ssarc_save_restore_order_t saveOrder; /*!< The save order. */
  117. uint8_t restorePriority; /*!< Restore priority of current group.
  118. 0 is the highest priority, 15 is the lowest priority */
  119. uint8_t savePriority; /*!< Save priority of current group.
  120. 0 is the highest priority, 15 is the lowest priority. */
  121. ssarc_power_domain_name_t powerDomain; /*!< Power domain. */
  122. uint32_t highestAddress; /*!< Highest address that can be accessed for the descriptors in the group. */
  123. uint32_t lowestAddress; /*!< Lowest address that can be accessed for the descriptors in the group. */
  124. } ssarc_group_config_t;
  125. /*******************************************************************************
  126. * API
  127. ******************************************************************************/
  128. #if defined(__cplusplus)
  129. extern "C" {
  130. #endif
  131. /*!
  132. * @name Descriptor related APIs.
  133. * @{
  134. */
  135. /*!
  136. * @brief Gets the address of the register to be saved/restored.
  137. *
  138. * @param base SSARC_HP peripheral base address.
  139. * @param index The index of descriptor. Range from 0 to 1023.
  140. * @return The address of the register.
  141. */
  142. static inline uint32_t SSARC_GetDescriptorRegisterAddress(SSARC_HP_Type *base, uint32_t index)
  143. {
  144. assert(index < SSARC_HP_SRAM0_COUNT);
  145. return (base->DESC[index].SRAM0);
  146. }
  147. /*!
  148. * @brief Gets the value of the register to be saved/restored.
  149. *
  150. * @param base SSARC_HP peripheral base address.
  151. * @param index The index of descriptor. Range from 0 to 1023.
  152. * @return The value of the register.
  153. */
  154. static inline uint32_t SSARC_GetDescriptorRegisterData(SSARC_HP_Type *base, uint32_t index)
  155. {
  156. assert(index < SSARC_HP_SRAM0_COUNT);
  157. return (base->DESC[index].SRAM1);
  158. }
  159. /*!
  160. * @brief Sets the configuration of the descriptor.
  161. *
  162. * @param base SSARC_HP peripheral base address.
  163. * @param index The index of descriptor. Range from 0 to 1023.
  164. * @param config Pointer to the structure ssarc_descriptor_config_t. Please refer to @ref ssarc_descriptor_config_t for
  165. * details.
  166. */
  167. void SSARC_SetDescriptorConfig(SSARC_HP_Type *base, uint32_t index, const ssarc_descriptor_config_t *config);
  168. /*!
  169. * @}
  170. */
  171. /*!
  172. * @name Group Related APIs
  173. * @{
  174. */
  175. /*!
  176. * @brief Inits the selected group.
  177. *
  178. * @note For the groups with the same save priority or restore priority,
  179. * the save/restore operation runs in the group order.
  180. *
  181. * @param base SSARC_LP peripheral base address.
  182. * @param groupID The index of the group. Range from 0 to 15.
  183. * @param config Pointer to the structure ssarc_group_config_t. Please refer to @ref ssarc_group_config_t for details.
  184. */
  185. void SSARC_GroupInit(SSARC_LP_Type *base, uint8_t groupID, const ssarc_group_config_t *config);
  186. /*!
  187. * @brief De-inits the selected group.
  188. *
  189. * @param base SSARC_LP peripheral base address.
  190. * @param groupID The index of the group. Range from 0 to 15.
  191. */
  192. static inline void SSARC_GroupDeinit(SSARC_LP_Type *base, uint8_t groupID)
  193. {
  194. assert(groupID < SSARC_LP_DESC_CTRL0_COUNT);
  195. base->GROUPS[groupID].DESC_CTRL1 &= ~SSARC_LP_DESC_CTRL1_GP_EN_MASK;
  196. }
  197. /*!
  198. * @brief Locks the configuration of the domain.
  199. *
  200. * This function locks the configuration of the domain. Once locked, only the access from the same domain is allowed,
  201. * access from other domains will be blocked. Once locked, it can only be unlocked by a hardware reset.
  202. *
  203. * @param base SSARC_LP peripheral base address.
  204. * @param groupID The index of the group. Range from 0 to 15.
  205. */
  206. static inline void SSARC_LockGroupDomain(SSARC_LP_Type *base, uint8_t groupID)
  207. {
  208. assert(groupID < SSARC_LP_DESC_CTRL0_COUNT);
  209. base->GROUPS[groupID].DESC_CTRL1 |= SSARC_LP_DESC_CTRL1_DL_MASK;
  210. }
  211. /*!
  212. * @brief Locks the write access to the control registers and descriptors for the selected group.
  213. *
  214. * This function Locks the write access to the control registers and descriptors for the selected group.
  215. * All writes are blocked. Once locked, it can only be unlocked by a hardware reset.
  216. *
  217. * @param base SSARC_LP peripheral base address.
  218. * @param groupID The index of the group. Range from 0 to 15.
  219. */
  220. static inline void SSARC_LockGroupWrite(SSARC_LP_Type *base, uint8_t groupID)
  221. {
  222. assert(groupID < SSARC_LP_DESC_CTRL0_COUNT);
  223. base->GROUPS[groupID].DESC_CTRL1 |= SSARC_LP_DESC_CTRL1_WL_MASK;
  224. }
  225. /*!
  226. * @brief Locks the read access to the control registers and descriptors for the selected group.
  227. *
  228. * This function Locks the read access to the control registers and descriptors for the selected group.
  229. * All reads are blocked. Once locked, it can only be unlocked by a hardware reset.
  230. *
  231. * @param base SSARC_LP peripheral base address.
  232. * @param groupID The index of the group. Range from 0 to 15.
  233. */
  234. static inline void SSARC_LockGroupRead(SSARC_LP_Type *base, uint8_t groupID)
  235. {
  236. assert(groupID < SSARC_LP_DESC_CTRL0_COUNT);
  237. base->GROUPS[groupID].DESC_CTRL1 |= SSARC_LP_DESC_CTRL1_RL_MASK;
  238. }
  239. /*!
  240. * @brief Triggers software request.
  241. *
  242. * @note Each group allows software to trigger the save/restore operation without getting the request
  243. * from basic power controller.
  244. *
  245. * @param base SSARC_LP peripheral base address.
  246. * @param groupID The index of the group. Range from 0 to 15.
  247. * @param mode Software trigger mode. Please refer to @ref ssarc_software_trigger_mode_t for details.
  248. */
  249. void SSARC_TriggerSoftwareRequest(SSARC_LP_Type *base, uint8_t groupID, ssarc_software_trigger_mode_t mode);
  250. /*!
  251. * @}
  252. */
  253. /*!
  254. * @name Global Setting Related APIs
  255. */
  256. /*!
  257. * @brief Resets the whole SSARC block by software.
  258. *
  259. * @note Only reset the SSARC registers, not include the DESC in SRAM.
  260. *
  261. * @param base SSARC_LP peripheral base address.
  262. */
  263. static inline void SSARC_ResetWholeBlock(SSARC_LP_Type *base)
  264. {
  265. base->CTRL |= SSARC_LP_CTRL_SW_RESET_MASK;
  266. base->CTRL &= ~SSARC_LP_CTRL_SW_RESET_MASK;
  267. }
  268. /*!
  269. * @brief Enables/Disables save/restore request from the PGMC module.
  270. *
  271. * @param base SSARC_LP peripheral base address.
  272. * @param enable Used to enable/disable save/restore hardware request.
  273. * - \b true Enable GPC save/restore requests.
  274. * - \b false Disable GPC save/restore requests.
  275. */
  276. static inline void SSARC_EnableHardwareRequest(SSARC_LP_Type *base, bool enable)
  277. {
  278. if (enable)
  279. {
  280. base->CTRL &= ~SSARC_LP_CTRL_DIS_HW_REQ_MASK;
  281. }
  282. else
  283. {
  284. base->CTRL |= SSARC_LP_CTRL_DIS_HW_REQ_MASK;
  285. }
  286. }
  287. /*!
  288. * @}
  289. */
  290. /*!
  291. * @name Status Related APIs
  292. * @{
  293. */
  294. /*!
  295. * @brief Gets status flags.
  296. *
  297. * @param base SSARC_LP peripheral base address.
  298. * @return The value of status flags. See @ref _ssarc_interrupt_status_flags for details.
  299. */
  300. static inline uint32_t SSARC_GetStatusFlags(SSARC_LP_Type *base)
  301. {
  302. return ((base->INT_STATUS) & SSARC_INT_STATUS_ALL);
  303. }
  304. /*!
  305. * @brief Clears status flags.
  306. *
  307. * @note Only @ref kSSARC_AddressErrorFlag, @ref kSSARC_AHBErrorFlag, @ref kSSARC_TimeoutFlag and
  308. * @ref kSSARC_GroupConflictFlag can be cleared.
  309. *
  310. * @param base SSARC_LP peripheral base address.
  311. * @param mask The mask value for flags to be cleared. See @ref _ssarc_interrupt_status_flags for details.
  312. */
  313. static inline void SSARC_ClearStatusFlags(SSARC_LP_Type *base, uint32_t mask)
  314. {
  315. base->INT_STATUS = mask;
  316. }
  317. /*!
  318. * @brief Gets the error index that indicates which descriptor will trigger the AHB_ERR or ADDR_ERR interrupt.
  319. *
  320. * @param base SSARC_LP peripheral base address.
  321. * @return The error index.
  322. */
  323. static inline uint32_t SSARC_GetErrorIndex(SSARC_LP_Type *base)
  324. {
  325. return (base->INT_STATUS & SSARC_LP_INT_STATUS_ERR_INDEX_MASK);
  326. }
  327. /*!
  328. *@}
  329. */
  330. /*!
  331. * @name Time Out Related APIs
  332. * @{
  333. */
  334. /*!
  335. * @brief Sets timeout value for the entire group to complete.
  336. *
  337. * This function sets timeout value for the entire group to complete. Setting timeout value
  338. * to 0 will disable this feature.
  339. *
  340. * @param base SSARC_LP peripheral base address.
  341. * @param value The timeout value, 0 means disable time out feature.
  342. */
  343. static inline void SSARC_SetTimeoutValue(SSARC_LP_Type *base, uint32_t value)
  344. {
  345. base->HP_TIMEOUT = value;
  346. }
  347. /*!
  348. * @brief Gets timeout value for AHB clock.
  349. *
  350. * @param base SSARC_LP peripheral base address.
  351. * @return The timeout value.
  352. */
  353. static inline uint32_t SSARC_GetTimeoutValue(SSARC_LP_Type *base)
  354. {
  355. return base->HP_TIMEOUT;
  356. }
  357. /*!
  358. * @}
  359. */
  360. /*!
  361. * @name Pending Group Related APIs
  362. */
  363. /*!
  364. * @brief Gets the value that indicates which groups are pending for restore from hardware request.
  365. *
  366. * @param base SSARC_LP peripheral base address.
  367. * @return The value of the pending groups.
  368. */
  369. static inline uint16_t SSARC_GetHardwareRequestRestorePendingGroup(SSARC_LP_Type *base)
  370. {
  371. return (uint16_t)(((base->HW_GROUP_PENDING) & SSARC_LP_HW_GROUP_PENDING_HW_RESTORE_PENDING_MASK) >>
  372. SSARC_LP_HW_GROUP_PENDING_HW_RESTORE_PENDING_SHIFT);
  373. }
  374. /*!
  375. * @brief Gets the value that indicates which groups are pending for save from hardware request.
  376. *
  377. * @param base SSARC_LP peripheral base address.
  378. * @return The value of the pending groups.
  379. */
  380. static inline uint16_t SSARC_GetHardwareRequestSavePendingGroup(SSARC_LP_Type *base)
  381. {
  382. return (uint16_t)(((base->HW_GROUP_PENDING) & SSARC_LP_HW_GROUP_PENDING_HW_SAVE_PENDING_MASK) >>
  383. SSARC_LP_HW_GROUP_PENDING_HW_SAVE_PENDING_SHIFT);
  384. }
  385. /*!
  386. * @brief Gets the value that indicates which groups are pending for restore from software request.
  387. *
  388. * @param base SSARC_LP peripheral base address.
  389. * @return The value of the pending groups.
  390. */
  391. static inline uint16_t SSARC_GetSoftwareRequestRestorePendingGroup(SSARC_LP_Type *base)
  392. {
  393. return (uint16_t)(((base->SW_GROUP_PENDING) & SSARC_LP_SW_GROUP_PENDING_SW_RESTORE_PENDING_MASK) >>
  394. SSARC_LP_SW_GROUP_PENDING_SW_RESTORE_PENDING_SHIFT);
  395. }
  396. /*!
  397. * @brief Gets the value that indicates which groups are pending for save from software request.
  398. *
  399. * @param base SSARC_LP peripheral base address.
  400. * @return The value of the pending groups.
  401. */
  402. static inline uint16_t SSARC_GetSoftwareRequestSavePendingGroup(SSARC_LP_Type *base)
  403. {
  404. return (uint16_t)(((base->SW_GROUP_PENDING) & SSARC_LP_SW_GROUP_PENDING_SW_SAVE_PENDING_MASK) >>
  405. SSARC_LP_SW_GROUP_PENDING_SW_SAVE_PENDING_SHIFT);
  406. }
  407. /*!
  408. * @}
  409. */
  410. #if defined(__cplusplus)
  411. }
  412. #endif
  413. /*!
  414. * @}
  415. */
  416. #endif /* _FSL_SSARC_H_ */