gd32f10x_pmu.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*!
  2. \file gd32f10x_pmu.h
  3. \brief definitions for the PMU
  4. \version 2014-12-26, V1.0.0, firmware for GD32F10x
  5. \version 2017-06-20, V2.0.0, firmware for GD32F10x
  6. \version 2018-07-31, V2.1.0, firmware for GD32F10x
  7. \version 2020-09-30, V2.2.0, firmware for GD32F10x
  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 GD32F10X_PMU_H
  33. #define GD32F10X_PMU_H
  34. #include "gd32f10x.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. /* PMU_CS */
  50. #define PMU_CS_WUF BIT(0) /*!< wakeup flag */
  51. #define PMU_CS_STBF BIT(1) /*!< standby flag */
  52. #define PMU_CS_LVDF BIT(2) /*!< low voltage detector status flag */
  53. #define PMU_CS_WUPEN BIT(8) /*!< wakeup pin enable */
  54. /* constants definitions */
  55. /* PMU ldo definitions */
  56. #define PMU_LDO_NORMAL ((uint32_t)0x00000000U) /*!< LDO normal work when PMU enter deepsleep mode */
  57. #define PMU_LDO_LOWPOWER PMU_CTL_LDOLP /*!< LDO work at low power status when PMU enter deepsleep mode */
  58. /* PMU low voltage detector threshold definitions */
  59. #define CTL_LVDT(regval) (BITS(5,7)&((uint32_t)(regval) << 5))
  60. #define PMU_LVDT_0 CTL_LVDT(0) /*!< voltage threshold is 2.2V */
  61. #define PMU_LVDT_1 CTL_LVDT(1) /*!< voltage threshold is 2.3V */
  62. #define PMU_LVDT_2 CTL_LVDT(2) /*!< voltage threshold is 2.4V */
  63. #define PMU_LVDT_3 CTL_LVDT(3) /*!< voltage threshold is 2.5V */
  64. #define PMU_LVDT_4 CTL_LVDT(4) /*!< voltage threshold is 2.6V */
  65. #define PMU_LVDT_5 CTL_LVDT(5) /*!< voltage threshold is 2.7V */
  66. #define PMU_LVDT_6 CTL_LVDT(6) /*!< voltage threshold is 2.8V */
  67. #define PMU_LVDT_7 CTL_LVDT(7) /*!< voltage threshold is 2.9V */
  68. /* PMU flag definitions */
  69. #define PMU_FLAG_WAKEUP PMU_CS_WUF /*!< wakeup flag status */
  70. #define PMU_FLAG_STANDBY PMU_CS_STBF /*!< standby flag status */
  71. #define PMU_FLAG_LVD PMU_CS_LVDF /*!< lvd flag status */
  72. /* PMU flag reset definitions */
  73. #define PMU_FLAG_RESET_WAKEUP ((uint8_t)0x00U) /*!< wakeup flag reset */
  74. #define PMU_FLAG_RESET_STANDBY ((uint8_t)0x01U) /*!< standby flag reset */
  75. /* PMU command constants definitions */
  76. #define WFI_CMD ((uint8_t)0x00U) /*!< use WFI command */
  77. #define WFE_CMD ((uint8_t)0x01U) /*!< use WFE command */
  78. /* function declarations */
  79. /* reset PMU registers */
  80. void pmu_deinit(void);
  81. /* LVD functions */
  82. /* select low voltage detector threshold */
  83. void pmu_lvd_select(uint32_t lvdt_n);
  84. /* disable PMU lvd */
  85. void pmu_lvd_disable(void);
  86. /* set PMU mode */
  87. /* PMU work in sleep mode */
  88. void pmu_to_sleepmode(uint8_t sleepmodecmd);
  89. /* PMU work in deepsleep mode */
  90. void pmu_to_deepsleepmode(uint32_t ldo, uint8_t deepsleepmodecmd);
  91. /* PMU work in standby mode */
  92. void pmu_to_standbymode(void);
  93. /* enable PMU wakeup pin */
  94. void pmu_wakeup_pin_enable(void);
  95. /* disable PMU wakeup pin */
  96. void pmu_wakeup_pin_disable(void);
  97. /* backup related functions */
  98. /* enable write access to the registers in backup domain */
  99. void pmu_backup_write_enable(void);
  100. /* disable write access to the registers in backup domain */
  101. void pmu_backup_write_disable(void);
  102. /* flag functions */
  103. /* get flag state */
  104. FlagStatus pmu_flag_get(uint32_t flag);
  105. /* clear flag bit */
  106. void pmu_flag_clear(uint32_t flag);
  107. #endif /* GD32F10X_PMU_H */