gd32f1x0_pmu.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*!
  2. \file gd32f1x0_pmu.h
  3. \brief definitions for the PMU
  4. \version 2014-12-26, V1.0.0, platform GD32F1x0(x=3,5)
  5. \version 2016-01-15, V2.0.0, platform GD32F1x0(x=3,5,7,9)
  6. \version 2016-04-30, V3.0.0, firmware update for GD32F1x0(x=3,5,7,9)
  7. \version 2017-06-19, V3.1.0, firmware update for GD32F1x0(x=3,5,7,9)
  8. \version 2019-11-20, V3.2.0, firmware update for GD32F1x0(x=3,5,7,9)
  9. */
  10. /*
  11. Copyright (c) 2019, GigaDevice Semiconductor Inc.
  12. Redistribution and use in source and binary forms, with or without modification,
  13. are permitted provided that the following conditions are met:
  14. 1. Redistributions of source code must retain the above copyright notice, this
  15. list of conditions and the following disclaimer.
  16. 2. Redistributions in binary form must reproduce the above copyright notice,
  17. this list of conditions and the following disclaimer in the documentation
  18. and/or other materials provided with the distribution.
  19. 3. Neither the name of the copyright holder nor the names of its contributors
  20. may be used to endorse or promote products derived from this software without
  21. specific prior written permission.
  22. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  25. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  26. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  27. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  29. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  31. OF SUCH DAMAGE.
  32. */
  33. #ifndef GD32F1X0_PMU_H
  34. #define GD32F1X0_PMU_H
  35. #include "gd32f1x0.h"
  36. /* PMU definitions */
  37. #define PMU PMU_BASE
  38. /* registers definitions */
  39. #define PMU_CTL REG32(PMU + 0x00000000U) /*!< PMU control register */
  40. #define PMU_CS REG32(PMU + 0x00000004U) /*!< PMU control and status register */
  41. /* bits definitions */
  42. /* PMU_CTL */
  43. #define PMU_CTL_LDOLP BIT(0) /*!< LDO low power mode */
  44. #define PMU_CTL_STBMOD BIT(1) /*!< standby mode */
  45. #define PMU_CTL_WURST BIT(2) /*!< wakeup flag reset */
  46. #define PMU_CTL_STBRST BIT(3) /*!< standby flag reset */
  47. #define PMU_CTL_LVDEN BIT(4) /*!< low voltage detector enable */
  48. #define PMU_CTL_LVDT BITS(5,7) /*!< low voltage detector threshold */
  49. #define PMU_CTL_BKPWEN BIT(8) /*!< backup domain write enable */
  50. /* PMU_CS */
  51. #define PMU_CS_WUF BIT(0) /*!< wakeup flag */
  52. #define PMU_CS_STBF BIT(1) /*!< standby flag */
  53. #define PMU_CS_LVDF BIT(2) /*!< low voltage detector status flag */
  54. #define PMU_CS_WUPEN0 BIT(8) /*!< wakeup pin 0 enable */
  55. #define PMU_CS_WUPEN1 BIT(9) /*!< wakeup pin 1 enable */
  56. /* constants definitions */
  57. /* PMU low voltage detector threshold definitions */
  58. #define CTL_LVDT(regval) (BITS(5,7)&((uint32_t)(regval) << 5))
  59. #define PMU_LVDT_0 CTL_LVDT(0) /*!< voltage threshold is 2.2V */
  60. #define PMU_LVDT_1 CTL_LVDT(1) /*!< voltage threshold is 2.3V */
  61. #define PMU_LVDT_2 CTL_LVDT(2) /*!< voltage threshold is 2.4V */
  62. #define PMU_LVDT_3 CTL_LVDT(3) /*!< voltage threshold is 2.5V */
  63. #define PMU_LVDT_4 CTL_LVDT(4) /*!< voltage threshold is 2.6V */
  64. #define PMU_LVDT_5 CTL_LVDT(5) /*!< voltage threshold is 2.7V */
  65. #define PMU_LVDT_6 CTL_LVDT(6) /*!< voltage threshold is 2.8V */
  66. #define PMU_LVDT_7 CTL_LVDT(7) /*!< voltage threshold is 2.9V */
  67. /* PMU flag definitions */
  68. #define PMU_FLAG_WAKEUP PMU_CS_WUF /*!< wakeup flag status */
  69. #define PMU_FLAG_STANDBY PMU_CS_STBF /*!< standby flag status */
  70. #define PMU_FLAG_LVD PMU_CS_LVDF /*!< lvd flag status */
  71. /* PMU ldo definitions */
  72. #define PMU_LDO_NORMAL ((uint32_t)0x00000000U) /*!< LDO normal work when pmu enter deepsleep mode */
  73. #define PMU_LDO_LOWPOWER PMU_CTL_LDOLP /*!< LDO work at low power status when pmu enter deepsleep mode */
  74. /* PMU flag reset definitions */
  75. #define PMU_FLAG_RESET_WAKEUP ((uint8_t)0x00) /*!< wakeup flag reset */
  76. #define PMU_FLAG_RESET_STANDBY ((uint8_t)0x01) /*!< standby flag reset */
  77. /* PMU command constants definitions */
  78. #define WFI_CMD ((uint8_t)0x00) /*!< use WFI command */
  79. #define WFE_CMD ((uint8_t)0x01) /*!< use WFE command */
  80. /* PMU wakeup pin definitions */
  81. #define PMU_WAKEUP_PIN0 PMU_CS_WUPEN0 /*!< wakeup pin 0 */
  82. #define PMU_WAKEUP_PIN1 PMU_CS_WUPEN1 /*!< wakeup pin 1 */
  83. /* function declarations */
  84. /* reset PMU registers */
  85. void pmu_deinit(void);
  86. /* select low voltage detector threshold */
  87. void pmu_lvd_select(uint32_t lvdt_n);
  88. /* disable PMU lvd */
  89. void pmu_lvd_disable(void);
  90. /* set PMU mode */
  91. /* PMU work in sleep mode */
  92. void pmu_to_sleepmode(uint8_t sleepmodecmd);
  93. /* PMU work in deepsleep mode */
  94. void pmu_to_deepsleepmode(uint32_t ldo,uint8_t deepsleepmodecmd);
  95. /* PMU work in standby mode */
  96. void pmu_to_standbymode(uint8_t standbymodecmd);
  97. /* enable PMU wakeup pin*/
  98. void pmu_wakeup_pin_enable(uint32_t wakeup_pin);
  99. /* disable PMU wakeup pin */
  100. void pmu_wakeup_pin_disable(uint32_t wakeup_pin);
  101. /* backup related functions */
  102. /* enable backup domain write */
  103. void pmu_backup_write_enable(void);
  104. /* disable backup domain write */
  105. void pmu_backup_write_disable(void);
  106. /* flag functions */
  107. /* clear flag bit */
  108. void pmu_flag_clear(uint32_t flag_clear);
  109. /* get flag state */
  110. FlagStatus pmu_flag_get(uint32_t flag);
  111. #endif /* GD32F1X0_PMU_H */