gd32f10x_rtc.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*!
  2. \file gd32f10x_rtc.h
  3. \brief definitions for the RTC
  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_RTC_H
  33. #define GD32F10X_RTC_H
  34. #include "gd32f10x.h"
  35. /* RTC definitions */
  36. #define RTC RTC_BASE
  37. /* registers definitions */
  38. #define RTC_INTEN REG32(RTC + 0x00U) /*!< interrupt enable register */
  39. #define RTC_CTL REG32(RTC + 0x04U) /*!< control register */
  40. #define RTC_PSCH REG32(RTC + 0x08U) /*!< prescaler high register */
  41. #define RTC_PSCL REG32(RTC + 0x0CU) /*!< prescaler low register */
  42. #define RTC_DIVH REG32(RTC + 0x10U) /*!< divider high register */
  43. #define RTC_DIVL REG32(RTC + 0x14U) /*!< divider low register */
  44. #define RTC_CNTH REG32(RTC + 0x18U) /*!< counter high register */
  45. #define RTC_CNTL REG32(RTC + 0x1CU) /*!< counter low register */
  46. #define RTC_ALRMH REG32(RTC + 0x20U) /*!< alarm high register */
  47. #define RTC_ALRML REG32(RTC + 0x24U) /*!< alarm low register */
  48. /* bits definitions */
  49. /* RTC_INTEN */
  50. #define RTC_INTEN_SCIE BIT(0) /*!< second interrupt enable */
  51. #define RTC_INTEN_ALRMIE BIT(1) /*!< alarm interrupt enable */
  52. #define RTC_INTEN_OVIE BIT(2) /*!< overflow interrupt enable */
  53. /* RTC_CTL */
  54. #define RTC_CTL_SCIF BIT(0) /*!< second interrupt flag */
  55. #define RTC_CTL_ALRMIF BIT(1) /*!< alarm interrupt flag */
  56. #define RTC_CTL_OVIF BIT(2) /*!< overflow interrupt flag */
  57. #define RTC_CTL_RSYNF BIT(3) /*!< registers synchronized flag */
  58. #define RTC_CTL_CMF BIT(4) /*!< configuration mode flag */
  59. #define RTC_CTL_LWOFF BIT(5) /*!< last write operation finished flag */
  60. /* RTC_PSCH */
  61. #define RTC_PSCH_PSC BITS(0,3) /*!< prescaler high value */
  62. /* RTC_PSCL */
  63. #define RTC_PSCL_PSC BITS(0,15) /*!< prescaler low value */
  64. /* RTC_DIVH */
  65. #define RTC_DIVH_DIV BITS(0,3) /*!< divider high value */
  66. /* RTC_DIVL */
  67. #define RTC_DIVL_DIV BITS(0,15) /*!< divider low value */
  68. /* RTC_CNTH */
  69. #define RTC_CNTH_CNT BITS(0,15) /*!< counter high value */
  70. /* RTC_CNTL */
  71. #define RTC_CNTL_CNT BITS(0,15) /*!< counter low value */
  72. /* RTC_ALRMH */
  73. #define RTC_ALRMH_ALRM BITS(0,15) /*!< alarm high value */
  74. /* RTC_ALRML */
  75. #define RTC_ALRML_ALRM BITS(0,15) /*!< alarm low value */
  76. /* constants definitions */
  77. /* RTC interrupt enable or disable definitions */
  78. #define RTC_INT_SECOND RTC_INTEN_SCIE /*!< second interrupt enable */
  79. #define RTC_INT_ALARM RTC_INTEN_ALRMIE /*!< alarm interrupt enable */
  80. #define RTC_INT_OVERFLOW RTC_INTEN_OVIE /*!< overflow interrupt enable */
  81. /* RTC interrupt flag definitions */
  82. #define RTC_INT_FLAG_SECOND RTC_CTL_SCIF /*!< second interrupt flag */
  83. #define RTC_INT_FLAG_ALARM RTC_CTL_ALRMIF /*!< alarm interrupt flag */
  84. #define RTC_INT_FLAG_OVERFLOW RTC_CTL_OVIF /*!< overflow interrupt flag */
  85. /* RTC flag definitions */
  86. #define RTC_FLAG_SECOND RTC_CTL_SCIF /*!< second interrupt flag */
  87. #define RTC_FLAG_ALARM RTC_CTL_ALRMIF /*!< alarm interrupt flag */
  88. #define RTC_FLAG_OVERFLOW RTC_CTL_OVIF /*!< overflow interrupt flag */
  89. #define RTC_FLAG_RSYN RTC_CTL_RSYNF /*!< registers synchronized flag */
  90. #define RTC_FLAG_LWOF RTC_CTL_LWOFF /*!< last write operation finished flag */
  91. /* function declarations */
  92. /* initialization functions */
  93. /* enter RTC configuration mode */
  94. void rtc_configuration_mode_enter(void);
  95. /* exit RTC configuration mode */
  96. void rtc_configuration_mode_exit(void);
  97. /* set RTC counter value */
  98. void rtc_counter_set(uint32_t cnt);
  99. /* set RTC prescaler value */
  100. void rtc_prescaler_set(uint32_t psc);
  101. /* operation functions */
  102. /* wait RTC last write operation finished flag set */
  103. void rtc_lwoff_wait(void);
  104. /* wait RTC registers synchronized flag set */
  105. void rtc_register_sync_wait(void);
  106. /* set RTC alarm value */
  107. void rtc_alarm_config(uint32_t alarm);
  108. /* get RTC counter value */
  109. uint32_t rtc_counter_get(void);
  110. /* get RTC divider value */
  111. uint32_t rtc_divider_get(void);
  112. /* flag & interrupt functions */
  113. /* get RTC flag status */
  114. FlagStatus rtc_flag_get(uint32_t flag);
  115. /* clear RTC flag status */
  116. void rtc_flag_clear(uint32_t flag);
  117. /* get RTC interrupt flag status */
  118. FlagStatus rtc_interrupt_flag_get(uint32_t flag);
  119. /* clear RTC interrupt flag status */
  120. void rtc_interrupt_flag_clear(uint32_t flag);
  121. /* enable RTC interrupt */
  122. void rtc_interrupt_enable(uint32_t interrupt);
  123. /* disable RTC interrupt */
  124. void rtc_interrupt_disable(uint32_t interrupt);
  125. #endif /* GD32F10X_RTC_H */