fsl_ssarc.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright 2020-2021 NXP
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #include "fsl_ssarc.h"
  8. /* Component ID definition, used by tools. */
  9. #ifndef FSL_COMPONENT_ID
  10. #define FSL_COMPONENT_ID "platform.drivers.ssarc"
  11. #endif
  12. /*******************************************************************************
  13. * Definitions
  14. ******************************************************************************/
  15. /*******************************************************************************
  16. * Prototypes
  17. ******************************************************************************/
  18. static void SSARC_MapDescriptorsToGroup(SSARC_LP_Type *base, uint8_t groupID, uint32_t startIndex, uint32_t endIndex);
  19. static void SSARC_SetGroupRestoreOrder(SSARC_LP_Type *base, uint8_t groupID, ssarc_save_restore_order_t order);
  20. static void SSARC_SetGroupSaveOrder(SSARC_LP_Type *base, uint8_t groupID, ssarc_save_restore_order_t order);
  21. /*******************************************************************************
  22. * Variables
  23. ******************************************************************************/
  24. /*******************************************************************************
  25. * Code
  26. ******************************************************************************/
  27. /*!
  28. * @brief Maps the descriptors to the selected group.
  29. *
  30. * @note One descriptor can be mapped to different group, but please make sure
  31. * one descriptor can only be mapped to one power domain.
  32. *
  33. * @param base SSARC_LP peripheral base address.
  34. * @param groupID The index of the group. Range from 0 to 15.
  35. * @param startIndex The index of the first descriptor of the group.
  36. * @param endIndex The index of the last descriptor of the group.
  37. */
  38. static void SSARC_MapDescriptorsToGroup(SSARC_LP_Type *base, uint8_t groupID, uint32_t startIndex, uint32_t endIndex)
  39. {
  40. assert(groupID < SSARC_LP_DESC_CTRL0_COUNT);
  41. assert((startIndex < endIndex) || (startIndex == endIndex));
  42. base->GROUPS[groupID].DESC_CTRL0 = SSARC_LP_DESC_CTRL0_START(startIndex) | SSARC_LP_DESC_CTRL0_END(endIndex);
  43. }
  44. /*!
  45. * @brief Set the order of descriptors within the group are processed when restoring register values.
  46. *
  47. * @param base SSARC_LP peripheral base address.
  48. * @param groupID The index of the group. Range from 0 to 15.
  49. * @param order The restore order.
  50. */
  51. static void SSARC_SetGroupRestoreOrder(SSARC_LP_Type *base, uint8_t groupID, ssarc_save_restore_order_t order)
  52. {
  53. assert(groupID < SSARC_LP_DESC_CTRL0_COUNT);
  54. if (order == kSSARC_ProcessFromStartToEnd)
  55. {
  56. base->GROUPS[groupID].DESC_CTRL0 &= ~SSARC_LP_DESC_CTRL0_RT_ORDER_MASK;
  57. }
  58. else
  59. {
  60. base->GROUPS[groupID].DESC_CTRL0 |= SSARC_LP_DESC_CTRL0_RT_ORDER_MASK;
  61. }
  62. }
  63. /*!
  64. * @brief Set the order of descriptors within the group are processed when saving register values.
  65. *
  66. * @param base SSARC_LP peripheral base address.
  67. * @param groupID The index of the group. Range from 0 to 15.
  68. * @param order The save order.
  69. */
  70. static void SSARC_SetGroupSaveOrder(SSARC_LP_Type *base, uint8_t groupID, ssarc_save_restore_order_t order)
  71. {
  72. assert(groupID < SSARC_LP_DESC_CTRL0_COUNT);
  73. if (order == kSSARC_ProcessFromStartToEnd)
  74. {
  75. base->GROUPS[groupID].DESC_CTRL0 &= ~SSARC_LP_DESC_CTRL0_SV_ORDER_MASK;
  76. }
  77. else
  78. {
  79. base->GROUPS[groupID].DESC_CTRL0 |= SSARC_LP_DESC_CTRL0_SV_ORDER_MASK;
  80. }
  81. }
  82. /*!
  83. * brief Sets the configuration of the descriptor.
  84. *
  85. * param base SSARC_HP peripheral base address.
  86. * param index The index of descriptor. Range from 0 to 1023.
  87. * param config Pointer to the structure ssarc_descriptor_config_t. Please refer to @ref ssarc_descriptor_config_t for
  88. * details.
  89. */
  90. void SSARC_SetDescriptorConfig(SSARC_HP_Type *base, uint32_t index, const ssarc_descriptor_config_t *config)
  91. {
  92. assert(config != NULL);
  93. uint32_t temp32 = 0UL;
  94. /* Set the address of the register to be saved/restored. */
  95. base->DESC[index].SRAM0 = config->address;
  96. temp32 = SSARC_HP_SRAM2_TYPE(config->type) | SSARC_HP_SRAM2_SIZE(config->size);
  97. temp32 |= (uint32_t)(config->operation);
  98. base->DESC[index].SRAM2 = temp32;
  99. /* Set the value of the register to be saved/restored. */
  100. /* If the type is set as kSSARC_ReadValueWriteBack, the SRAM1 register will be
  101. loaded with the value on save operation, and the data in SRAM1 register will be over-written, so
  102. it is no need to set SRAM1 register in that type. */
  103. if (config->type != kSSARC_ReadValueWriteBack)
  104. {
  105. base->DESC[index].SRAM1 = config->data;
  106. }
  107. }
  108. /*!
  109. * brief Init the selected group.
  110. *
  111. * note For the groups with the same save priority or restore priority,
  112. * the save/restore operation runs in the group order.
  113. *
  114. * param base SSARC_LP peripheral base address.
  115. * param groupID The index of the group. Range from 0 to 15.
  116. * param config Pointer to the structure ssarc_group_config_t. Please refer to @ref ssarc_group_config_t for details.
  117. */
  118. void SSARC_GroupInit(SSARC_LP_Type *base, uint8_t groupID, const ssarc_group_config_t *config)
  119. {
  120. assert(config != NULL);
  121. assert(groupID < SSARC_LP_DESC_CTRL0_COUNT);
  122. uint32_t temp32;
  123. temp32 = SSARC_LP_DESC_CTRL1_POWER_DOMAIN(config->powerDomain) |
  124. SSARC_LP_DESC_CTRL1_SV_PRIORITY(config->savePriority) |
  125. SSARC_LP_DESC_CTRL1_RT_PRIORITY(config->restorePriority) | SSARC_LP_DESC_CTRL1_CPUD(config->cpuDomain);
  126. base->GROUPS[groupID].DESC_CTRL1 = temp32;
  127. SSARC_MapDescriptorsToGroup(base, groupID, config->startIndex, config->endIndex);
  128. SSARC_SetGroupRestoreOrder(base, groupID, config->restoreOrder);
  129. SSARC_SetGroupSaveOrder(base, groupID, config->saveOrder);
  130. /* Config the highest address and the lowest address. */
  131. base->GROUPS[groupID].DESC_ADDR_UP = config->highestAddress;
  132. base->GROUPS[groupID].DESC_ADDR_DOWN = config->lowestAddress;
  133. /* Enable the group. */
  134. base->GROUPS[groupID].DESC_CTRL1 |= SSARC_LP_DESC_CTRL1_GP_EN_MASK;
  135. }
  136. /*!
  137. * brief Triggers software request.
  138. *
  139. * note Each group allows software to trigger the save/restore operation without getting the request
  140. * from basic power controller.
  141. *
  142. * param base SSARC_LP peripheral base address.
  143. * param groupID The index of the group. Range from 0 to 15.
  144. * param mode. Software trigger mode. Please refer to @ref ssarc_software_trigger_mode_t for details.
  145. */
  146. void SSARC_TriggerSoftwareRequest(SSARC_LP_Type *base, uint8_t groupID, ssarc_software_trigger_mode_t mode)
  147. {
  148. assert(groupID < SSARC_LP_DESC_CTRL0_COUNT);
  149. base->GROUPS[groupID].DESC_CTRL1 |= (uint32_t)mode;
  150. while (((base->GROUPS[groupID].DESC_CTRL1) & (uint32_t)mode) != 0UL)
  151. {
  152. }
  153. }