Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:01

0001 /*
0002  * Copyright 2020-2021 NXP
0003  * All rights reserved.
0004  *
0005  * SPDX-License-Identifier: BSD-3-Clause
0006  */
0007 
0008 #include "fsl_ssarc.h"
0009 
0010 /* Component ID definition, used by tools. */
0011 #ifndef FSL_COMPONENT_ID
0012 #define FSL_COMPONENT_ID "platform.drivers.ssarc"
0013 #endif
0014 
0015 /*******************************************************************************
0016  * Definitions
0017  ******************************************************************************/
0018 
0019 /*******************************************************************************
0020  * Prototypes
0021  ******************************************************************************/
0022 static void SSARC_MapDescriptorsToGroup(SSARC_LP_Type *base, uint8_t groupID, uint32_t startIndex, uint32_t endIndex);
0023 static void SSARC_SetGroupRestoreOrder(SSARC_LP_Type *base, uint8_t groupID, ssarc_save_restore_order_t order);
0024 static void SSARC_SetGroupSaveOrder(SSARC_LP_Type *base, uint8_t groupID, ssarc_save_restore_order_t order);
0025 /*******************************************************************************
0026  * Variables
0027  ******************************************************************************/
0028 
0029 /*******************************************************************************
0030  * Code
0031  ******************************************************************************/
0032 
0033 /*!
0034  * @brief Maps the descriptors to the selected group.
0035  *
0036  * @note One descriptor can be mapped to different group, but please make sure
0037  *       one descriptor can only be mapped to one power domain.
0038  *
0039  * @param base SSARC_LP peripheral base address.
0040  * @param groupID The index of the group. Range from 0 to 15.
0041  * @param startIndex The index of the first descriptor of the group.
0042  * @param endIndex The index of the last descriptor of the group.
0043  */
0044 static void SSARC_MapDescriptorsToGroup(SSARC_LP_Type *base, uint8_t groupID, uint32_t startIndex, uint32_t endIndex)
0045 {
0046     assert(groupID < SSARC_LP_DESC_CTRL0_COUNT);
0047     assert((startIndex < endIndex) || (startIndex == endIndex));
0048 
0049     base->GROUPS[groupID].DESC_CTRL0 = SSARC_LP_DESC_CTRL0_START(startIndex) | SSARC_LP_DESC_CTRL0_END(endIndex);
0050 }
0051 
0052 /*!
0053  * @brief Set the order of descriptors within the group are processed when restoring register values.
0054  *
0055  * @param base SSARC_LP peripheral base address.
0056  * @param groupID The index of the group. Range from 0 to 15.
0057  * @param order The restore order.
0058  */
0059 static void SSARC_SetGroupRestoreOrder(SSARC_LP_Type *base, uint8_t groupID, ssarc_save_restore_order_t order)
0060 {
0061     assert(groupID < SSARC_LP_DESC_CTRL0_COUNT);
0062 
0063     if (order == kSSARC_ProcessFromStartToEnd)
0064     {
0065         base->GROUPS[groupID].DESC_CTRL0 &= ~SSARC_LP_DESC_CTRL0_RT_ORDER_MASK;
0066     }
0067     else
0068     {
0069         base->GROUPS[groupID].DESC_CTRL0 |= SSARC_LP_DESC_CTRL0_RT_ORDER_MASK;
0070     }
0071 }
0072 
0073 /*!
0074  * @brief Set the order of descriptors within the group are processed when saving register values.
0075  *
0076  * @param base SSARC_LP peripheral base address.
0077  * @param groupID The index of the group. Range from 0 to 15.
0078  * @param order The save order.
0079  */
0080 static void SSARC_SetGroupSaveOrder(SSARC_LP_Type *base, uint8_t groupID, ssarc_save_restore_order_t order)
0081 {
0082     assert(groupID < SSARC_LP_DESC_CTRL0_COUNT);
0083 
0084     if (order == kSSARC_ProcessFromStartToEnd)
0085     {
0086         base->GROUPS[groupID].DESC_CTRL0 &= ~SSARC_LP_DESC_CTRL0_SV_ORDER_MASK;
0087     }
0088     else
0089     {
0090         base->GROUPS[groupID].DESC_CTRL0 |= SSARC_LP_DESC_CTRL0_SV_ORDER_MASK;
0091     }
0092 }
0093 
0094 /*!
0095  * brief Sets the configuration of the descriptor.
0096  *
0097  * param base SSARC_HP peripheral base address.
0098  * param index The index of descriptor. Range from 0 to 1023.
0099  * param config Pointer to the structure ssarc_descriptor_config_t. Please refer to @ref ssarc_descriptor_config_t for
0100  * details.
0101  */
0102 void SSARC_SetDescriptorConfig(SSARC_HP_Type *base, uint32_t index, const ssarc_descriptor_config_t *config)
0103 {
0104     assert(config != NULL);
0105 
0106     uint32_t temp32 = 0UL;
0107 
0108     /* Set the address of the register to be saved/restored. */
0109     base->DESC[index].SRAM0 = config->address;
0110 
0111     temp32 = SSARC_HP_SRAM2_TYPE(config->type) | SSARC_HP_SRAM2_SIZE(config->size);
0112     temp32 |= (uint32_t)(config->operation);
0113 
0114     base->DESC[index].SRAM2 = temp32;
0115 
0116     /* Set the value of the register to be saved/restored. */
0117     /* If the type is set as kSSARC_ReadValueWriteBack, the SRAM1 register will be
0118        loaded with the value on save operation, and the data in SRAM1 register will be over-written, so
0119        it is no need to set SRAM1 register in that type. */
0120     if (config->type != kSSARC_ReadValueWriteBack)
0121     {
0122         base->DESC[index].SRAM1 = config->data;
0123     }
0124 }
0125 
0126 /*!
0127  * brief Init the selected group.
0128  *
0129  * note For the groups with the same save priority or restore priority,
0130  *      the save/restore operation runs in the group order.
0131  *
0132  * param base SSARC_LP peripheral base address.
0133  * param groupID The index of the group. Range from 0 to 15.
0134  * param config Pointer to the structure ssarc_group_config_t. Please refer to @ref ssarc_group_config_t for details.
0135  */
0136 void SSARC_GroupInit(SSARC_LP_Type *base, uint8_t groupID, const ssarc_group_config_t *config)
0137 {
0138     assert(config != NULL);
0139     assert(groupID < SSARC_LP_DESC_CTRL0_COUNT);
0140 
0141     uint32_t temp32;
0142 
0143     temp32 = SSARC_LP_DESC_CTRL1_POWER_DOMAIN(config->powerDomain) |
0144              SSARC_LP_DESC_CTRL1_SV_PRIORITY(config->savePriority) |
0145              SSARC_LP_DESC_CTRL1_RT_PRIORITY(config->restorePriority) | SSARC_LP_DESC_CTRL1_CPUD(config->cpuDomain);
0146     base->GROUPS[groupID].DESC_CTRL1 = temp32;
0147 
0148     SSARC_MapDescriptorsToGroup(base, groupID, config->startIndex, config->endIndex);
0149     SSARC_SetGroupRestoreOrder(base, groupID, config->restoreOrder);
0150     SSARC_SetGroupSaveOrder(base, groupID, config->saveOrder);
0151 
0152     /* Config the highest address and the lowest address. */
0153     base->GROUPS[groupID].DESC_ADDR_UP   = config->highestAddress;
0154     base->GROUPS[groupID].DESC_ADDR_DOWN = config->lowestAddress;
0155 
0156     /* Enable the group. */
0157     base->GROUPS[groupID].DESC_CTRL1 |= SSARC_LP_DESC_CTRL1_GP_EN_MASK;
0158 }
0159 
0160 /*!
0161  * brief Triggers software request.
0162  *
0163  * note Each group allows software to trigger the save/restore operation without getting the request
0164  *       from basic power controller.
0165  *
0166  * param base SSARC_LP peripheral base address.
0167  * param groupID The index of the group. Range from 0 to 15.
0168  * param mode. Software trigger mode. Please refer to @ref ssarc_software_trigger_mode_t for details.
0169  */
0170 void SSARC_TriggerSoftwareRequest(SSARC_LP_Type *base, uint8_t groupID, ssarc_software_trigger_mode_t mode)
0171 {
0172     assert(groupID < SSARC_LP_DESC_CTRL0_COUNT);
0173 
0174     base->GROUPS[groupID].DESC_CTRL1 |= (uint32_t)mode;
0175 
0176     while (((base->GROUPS[groupID].DESC_CTRL1) & (uint32_t)mode) != 0UL)
0177     {
0178     }
0179 }