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