fm33lc0xx_fl_pmu.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /**
  2. ****************************************************************************************************
  3. * @file fm33lc0xx_fl_pmu.c
  4. * @author FMSH Application Team
  5. * @brief Src file of PMU FL Module
  6. ****************************************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) [2019] [Fudan Microelectronics]
  10. * THIS SOFTWARE is licensed under the Mulan PSL v1.
  11. * can use this software according to the terms and conditions of the Mulan PSL v1.
  12. * You may obtain a copy of Mulan PSL v1 at:
  13. * http://license.coscl.org.cn/MulanPSL
  14. * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
  16. * PURPOSE.
  17. * See the Mulan PSL v1 for more details.
  18. *
  19. ****************************************************************************************************
  20. */
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "fm33lc0xx_fl_rmu.h"
  23. #include "fm33lc0xx_fl_pmu.h"
  24. #include "fm33_assert.h"
  25. #define IS_FL_PMU_INSTANCE(INSTANCE) (((INSTANCE) == PMU))
  26. #define IS_FL_PMU_MODE(__VALUE__) (((__VALUE__) == FL_PMU_POWER_MODE_ACTIVE_OR_LPACTIVE)||\
  27. ((__VALUE__) == FL_PMU_POWER_MODE_LPRUN_ONLY)||\
  28. ((__VALUE__) == FL_PMU_POWER_MODE_SLEEP_OR_DEEPSLEEP))
  29. #define IS_FL_PMU_COREVOLTAGESCALING(__VALUE__) (((__VALUE__) == FL_DISABLE)||\
  30. ((__VALUE__) == FL_ENABLE))
  31. #define IS_FL_PMU_DEEPSLEEP(__VALUE__) (((__VALUE__) == FL_PMU_SLEEP_MODE_DEEP)||\
  32. ((__VALUE__) == FL_PMU_SLEEP_MODE_NORMAL))
  33. #define IS_FL_PMU_WAKEUPFREQUENCY(__VALUE__) (((__VALUE__) == FL_PMU_RCHF_WAKEUP_FREQ_8MHZ)||\
  34. ((__VALUE__) == FL_PMU_RCHF_WAKEUP_FREQ_16MHZ)||\
  35. ((__VALUE__) == FL_PMU_RCHF_WAKEUP_FREQ_24MHZ))
  36. #define IS_FL_PMU_LDOLOWMODE(__VALUE__) (((__VALUE__) == FL_PMU_LDO_LPM_DISABLE)||\
  37. ((__VALUE__) == FL_PMU_LDO_LPM_ENABLE))
  38. #define IS_FL_PMU_WAKEUPDELAY(__VALUE__) (((__VALUE__) == FL_PMU_WAKEUP_DELAY_0US)||\
  39. ((__VALUE__) == FL_PMU_WAKEUP_DELAY_2US)||\
  40. ((__VALUE__) == FL_PMU_WAKEUP_DELAY_4US)||\
  41. ((__VALUE__) == FL_PMU_WAKEUP_DELAY_8US))
  42. /**
  43. *@}
  44. */
  45. /** @addtogroup PMU_FL_EF_Init
  46. * @{
  47. */
  48. /**
  49. * @brief 复位PMU外设
  50. *
  51. * @param 外设入口地址
  52. *
  53. * @retval 返回错误状态,可能值:
  54. * -FL_PASS 外设寄存器值恢复复位值
  55. * -FL_FAIL 未成功执行
  56. */
  57. FL_ErrorStatus FL_PMU_Sleep_DeInit(PMU_Type *PMUx)
  58. {
  59. FL_ErrorStatus status = FL_FAIL;
  60. /* 参数合法性检查 */
  61. assert_param(IS_FL_PMU_INSTANCE(PMUx));
  62. PMUx->CR = 0x00060000U;
  63. PMUx->WKTR = 0xC0000001U;
  64. PMUx->IER = 0x00000000U;
  65. status = FL_PASS;
  66. return status;
  67. }
  68. /**
  69. * @brief 根据LPM_InitStruct结构体包含的配置信息配置PMU寄存器
  70. *
  71. * @note 为更好的睡眠功耗用户可能需要根据实际应用,调用 @ref fm33lc0xx_fl_pmu.h中的其他接口
  72. * 来完成睡眠前的模式配置,包括睡眠行为和唤醒后的行为(注:此函数会关闭BOR)
  73. * @param PMUx 外设入口地址
  74. * @param LPM_InitStruct 指向一个 @ref LL_PMU_SleepInitTypeDef 类型的结构体,它包含指定LPUART外设的配置信息
  75. *
  76. * @retval ErrorStatus枚举值
  77. * -FL_FAIL 配置过程发生错误
  78. * -FL_PASS LPUART配置成功
  79. */
  80. FL_ErrorStatus FL_PMU_Sleep_Init(PMU_Type *PMUx, FL_PMU_SleepInitTypeDef *LPM_InitStruct)
  81. {
  82. FL_ErrorStatus status = FL_FAIL;
  83. /* 参数合法性检查 */
  84. assert_param(IS_FL_PMU_INSTANCE(PMUx));
  85. assert_param(IS_FL_PMU_LDOLOWMODE(LPM_InitStruct->LDOLowPowerMode));
  86. assert_param(IS_FL_PMU_COREVOLTAGESCALING(LPM_InitStruct->coreVoltageScaling));
  87. assert_param(IS_FL_PMU_DEEPSLEEP(LPM_InitStruct->deepSleep));
  88. assert_param(IS_FL_PMU_WAKEUPFREQUENCY(LPM_InitStruct->wakeupFrequency));
  89. assert_param(IS_FL_PMU_WAKEUPDELAY(LPM_InitStruct->wakeupDelay));
  90. /* 唤醒延时 */
  91. FL_PMU_SetWakeupDelay(PMUx, LPM_InitStruct->wakeupDelay);
  92. /* 唤醒后RCHF的频率 */
  93. FL_PMU_SetRCHFWakeupFrequency(PMUx, LPM_InitStruct->wakeupFrequency);
  94. /* 睡眠下内核电压配置 */
  95. if(LPM_InitStruct->coreVoltageScaling == FL_ENABLE)
  96. {
  97. FL_PMU_EnableCoreVoltageScaling(PMUx);
  98. }
  99. else
  100. {
  101. FL_PMU_DisableCoreVoltageScaling(PMUx);
  102. }
  103. /* M0系统控制器,一般配置为0即可*/
  104. SCB->SCR = 0;
  105. /* 睡眠模式 */
  106. FL_PMU_SetSleepMode(PMUx, LPM_InitStruct->deepSleep);
  107. status = FL_PASS;
  108. return status;
  109. }
  110. /**
  111. * @brief LPM_InitStruct 为默认配置
  112. * @param LPM_InitStruct 指向需要将值设置为默认配置的结构体 @ref FL_PMU_SleepInitTypeDef structure
  113. * 结构体
  114. * @retval None
  115. */
  116. void FL_PMU_StructInit(FL_PMU_SleepInitTypeDef *LPM_InitStruct)
  117. {
  118. LPM_InitStruct->deepSleep = FL_PMU_SLEEP_MODE_NORMAL;
  119. LPM_InitStruct->LDOLowPowerMode = FL_PMU_LDO_LPM_DISABLE;
  120. LPM_InitStruct->wakeupFrequency = FL_PMU_RCHF_WAKEUP_FREQ_8MHZ;
  121. LPM_InitStruct->wakeupDelay = FL_PMU_WAKEUP_DELAY_2US;
  122. LPM_InitStruct->coreVoltageScaling = FL_DISABLE;
  123. }
  124. /**
  125. *@}
  126. */
  127. /**
  128. *@}
  129. */
  130. /*********************** (C) COPYRIGHT Fudan Microelectronics *****END OF FILE************************/