gd32f30x_pmu.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*!
  2. \file gd32f30x_pmu.h
  3. \brief definitions for the PMU
  4. \version 2017-02-10, V1.0.0, firmware for GD32F30x
  5. \version 2018-10-10, V1.1.0, firmware for GD32F30x
  6. \version 2018-12-25, V2.0.0, firmware for GD32F30x
  7. \version 2020-09-30, V2.1.0, firmware for GD32F30x
  8. */
  9. /*
  10. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  11. Redistribution and use in source and binary forms, with or without modification,
  12. are permitted provided that the following conditions are met:
  13. 1. Redistributions of source code must retain the above copyright notice, this
  14. list of conditions and the following disclaimer.
  15. 2. Redistributions in binary form must reproduce the above copyright notice,
  16. this list of conditions and the following disclaimer in the documentation
  17. and/or other materials provided with the distribution.
  18. 3. Neither the name of the copyright holder nor the names of its contributors
  19. may be used to endorse or promote products derived from this software without
  20. specific prior written permission.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  23. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  25. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  30. OF SUCH DAMAGE.
  31. */
  32. #ifndef GD32F30X_PMU_H
  33. #define GD32F30X_PMU_H
  34. #include "gd32f30x.h"
  35. /* PMU definitions */
  36. #define PMU PMU_BASE /*!< PMU base address */
  37. /* registers definitions */
  38. #define PMU_CTL REG32((PMU) + 0x00000000U) /*!< PMU control register */
  39. #define PMU_CS REG32((PMU) + 0x00000004U) /*!< PMU control and status register */
  40. /* bits definitions */
  41. /* PMU_CTL */
  42. #define PMU_CTL_LDOLP BIT(0) /*!< LDO low power mode */
  43. #define PMU_CTL_STBMOD BIT(1) /*!< standby mode */
  44. #define PMU_CTL_WURST BIT(2) /*!< wakeup flag reset */
  45. #define PMU_CTL_STBRST BIT(3) /*!< standby flag reset */
  46. #define PMU_CTL_LVDEN BIT(4) /*!< low voltage detector enable */
  47. #define PMU_CTL_LVDT BITS(5,7) /*!< low voltage detector threshold */
  48. #define PMU_CTL_BKPWEN BIT(8) /*!< backup domain write enable */
  49. #define PMU_CTL_LDLP BIT(10) /*!< low-driver mode when use low power LDO */
  50. #define PMU_CTL_LDNP BIT(11) /*!< low-driver mode when use normal power LDO */
  51. #define PMU_CTL_LDOVS BITS(14,15) /*!< LDO output voltage select */
  52. #define PMU_CTL_HDEN BIT(16) /*!< high-driver mode enable */
  53. #define PMU_CTL_HDS BIT(17) /*!< high-driver mode switch */
  54. #define PMU_CTL_LDEN BITS(18,19) /*!< low-driver mode enable in deep-sleep mode */
  55. /* PMU_CS */
  56. #define PMU_CS_WUF BIT(0) /*!< wakeup flag */
  57. #define PMU_CS_STBF BIT(1) /*!< standby flag */
  58. #define PMU_CS_LVDF BIT(2) /*!< low voltage detector status flag */
  59. #define PMU_CS_WUPEN BIT(8) /*!< wakeup pin enable */
  60. #define PMU_CS_LDOVSRF BIT(14) /*!< LDO voltage select ready flag */
  61. #define PMU_CS_HDRF BIT(16) /*!< high-driver ready flag */
  62. #define PMU_CS_HDSRF BIT(17) /*!< high-driver switch ready flag */
  63. #define PMU_CS_LDRF BITS(18,19) /*!< Low-driver mode ready flag */
  64. /* constants definitions */
  65. /* PMU ldo definitions */
  66. #define PMU_LDO_NORMAL ((uint32_t)0x00000000U) /*!< LDO normal work when PMU enter deepsleep mode */
  67. #define PMU_LDO_LOWPOWER PMU_CTL_LDOLP /*!< LDO work in low power status when PMU enter deepsleep mode */
  68. /* PMU low voltage detector threshold definitions */
  69. #define CTL_LVDT(regval) (BITS(5,7)&((uint32_t)(regval)<<5))
  70. #define PMU_LVDT_0 CTL_LVDT(0) /*!< voltage threshold is 2.1V */
  71. #define PMU_LVDT_1 CTL_LVDT(1) /*!< voltage threshold is 2.3V */
  72. #define PMU_LVDT_2 CTL_LVDT(2) /*!< voltage threshold is 2.4V */
  73. #define PMU_LVDT_3 CTL_LVDT(3) /*!< voltage threshold is 2.6V */
  74. #define PMU_LVDT_4 CTL_LVDT(4) /*!< voltage threshold is 2.7V */
  75. #define PMU_LVDT_5 CTL_LVDT(5) /*!< voltage threshold is 2.9V */
  76. #define PMU_LVDT_6 CTL_LVDT(6) /*!< voltage threshold is 3.0V */
  77. #define PMU_LVDT_7 CTL_LVDT(7) /*!< voltage threshold is 3.1V */
  78. /* PMU low-driver mode when use low power LDO */
  79. #define CTL_LDLP(regval) (BIT(10)&((uint32_t)(regval)<<10))
  80. #define PMU_NORMALDR_LOWPWR CTL_LDLP(0) /*!< normal driver when use low power LDO */
  81. #define PMU_LOWDR_LOWPWR CTL_LDLP(1) /*!< low-driver mode enabled when LDEN is 11 and use low power LDO */
  82. /* PMU low-driver mode when use normal power LDO */
  83. #define CTL_LDNP(regval) (BIT(11)&((uint32_t)(regval)<<11))
  84. #define PMU_NORMALDR_NORMALPWR CTL_LDNP(0) /*!< normal driver when use normal power LDO */
  85. #define PMU_LOWDR_NORMALPWR CTL_LDNP(1) /*!< low-driver mode enabled when LDEN is 11 and use normal power LDO */
  86. /* PMU LDO output voltage select definitions */
  87. #define CTL_LDOVS(regval) (BITS(14,15)&((uint32_t)(regval)<<14))
  88. #define PMU_LDOVS_LOW CTL_LDOVS(1) /*!< LDO output voltage low mode */
  89. #define PMU_LDOVS_MID CTL_LDOVS(2) /*!< LDO output voltage mid mode */
  90. #define PMU_LDOVS_HIGH CTL_LDOVS(3) /*!< LDO output voltage high mode */
  91. /* PMU high-driver mode switch */
  92. #define CTL_HDS(regval) (BIT(17)&((uint32_t)(regval)<<17))
  93. #define PMU_HIGHDR_SWITCH_NONE CTL_HDS(0) /*!< no high-driver mode switch */
  94. #define PMU_HIGHDR_SWITCH_EN CTL_HDS(1) /*!< high-driver mode switch */
  95. /* low-driver mode in deep-sleep mode */
  96. #define PMU_LOWDRIVER_DISABLE ((uint32_t)0x00000000U) /*!< low-driver mode disable in deep-sleep mode */
  97. #define PMU_LOWDRIVER_ENABLE PMU_CTL_LDEN /*!< low-driver mode enable in deep-sleep mode */
  98. /* PMU low power mode ready flag definitions */
  99. #define CS_LDRF(regval) (BITS(18,19)&((uint32_t)(regval)<<18))
  100. #define PMU_LDRF_NORMAL CS_LDRF(0) /*!< normal driver in deep-sleep mode */
  101. #define PMU_LDRF_LOWDRIVER CS_LDRF(3) /*!< low-driver mode in deep-sleep mode */
  102. /* PMU flag definitions */
  103. #define PMU_FLAG_WAKEUP PMU_CS_WUF /*!< wakeup flag status */
  104. #define PMU_FLAG_STANDBY PMU_CS_STBF /*!< standby flag status */
  105. #define PMU_FLAG_LVD PMU_CS_LVDF /*!< lvd flag status */
  106. #define PMU_FLAG_LDOVSRF PMU_CS_LDOVSRF /*!< LDO voltage select ready flag */
  107. #define PMU_FLAG_HDRF PMU_CS_HDRF /*!< high-driver ready flag */
  108. #define PMU_FLAG_HDSRF PMU_CS_HDSRF /*!< high-driver switch ready flag */
  109. #define PMU_FLAG_LDRF PMU_CS_LDRF /*!< low-driver mode ready flag */
  110. /* PMU flag reset definitions */
  111. #define PMU_FLAG_RESET_WAKEUP ((uint8_t)0x00U) /*!< wakeup flag reset */
  112. #define PMU_FLAG_RESET_STANDBY ((uint8_t)0x01U) /*!< standby flag reset */
  113. /* PMU command constants definitions */
  114. #define WFI_CMD ((uint8_t)0x00U) /*!< use WFI command */
  115. #define WFE_CMD ((uint8_t)0x01U) /*!< use WFE command */
  116. /* function declarations */
  117. /* reset PMU registers */
  118. void pmu_deinit(void);
  119. /* LVD functions */
  120. /* select low voltage detector threshold */
  121. void pmu_lvd_select(uint32_t lvdt_n);
  122. /* select LDO output voltage */
  123. void pmu_ldo_output_select(uint32_t ldo_output);
  124. /* disable PMU lvd */
  125. void pmu_lvd_disable(void);
  126. /* functions of low-driver mode and high-driver mode in deep-sleep mode */
  127. /* switch high-driver mode */
  128. void pmu_highdriver_switch_select(uint32_t highdr_switch);
  129. /* enable high-driver mode */
  130. void pmu_highdriver_mode_enable(void);
  131. /* disable high-driver mode */
  132. void pmu_highdriver_mode_disable(void);
  133. /* enable low-driver mode in deep-sleep mode */
  134. void pmu_lowdriver_mode_enable(void);
  135. /* disable low-driver mode in deep-sleep mode */
  136. void pmu_lowdriver_mode_disable(void);
  137. /* in deep-sleep mode, driver mode when use low power LDO */
  138. void pmu_lowpower_driver_config(uint32_t mode);
  139. /* in deep-sleep mode, driver mode when use normal power LDO */
  140. void pmu_normalpower_driver_config(uint32_t mode);
  141. /* set PMU mode */
  142. /* PMU work in sleep mode */
  143. void pmu_to_sleepmode(uint8_t sleepmodecmd);
  144. /* PMU work in deepsleep mode */
  145. void pmu_to_deepsleepmode(uint32_t ldo, uint32_t lowdrive, uint8_t deepsleepmodecmd);
  146. /* PMU work in standby mode */
  147. void pmu_to_standbymode(void);
  148. /* enable PMU wakeup pin */
  149. void pmu_wakeup_pin_enable(void);
  150. /* disable PMU wakeup pin */
  151. void pmu_wakeup_pin_disable(void);
  152. /* backup related functions */
  153. /* enable backup domain write */
  154. void pmu_backup_write_enable(void);
  155. /* disable backup domain write */
  156. void pmu_backup_write_disable(void);
  157. /* flag functions */
  158. /* get flag state */
  159. FlagStatus pmu_flag_get(uint32_t flag);
  160. /* clear flag bit */
  161. void pmu_flag_clear(uint32_t flag);
  162. #endif /* GD32F30X_PMU_H */