gd32f30x_rtc.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*!
  2. \file gd32f30x_rtc.h
  3. \brief definitions for the RTC
  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_RTC_H
  33. #define GD32F30X_RTC_H
  34. #include "gd32f30x.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_PSC */
  61. #define RTC_PSCH_PSC BITS(0, 3) /*!< prescaler high value */
  62. #define RTC_PSCL_PSC BITS(0, 15) /*!< prescaler low value */
  63. /* RTC_DIV */
  64. #define RTC_DIVH_DIV BITS(0, 3) /*!< divider high value */
  65. #define RTC_DIVL_DIV BITS(0, 15) /*!< divider low value */
  66. /* RTC_CNT */
  67. #define RTC_CNTH_CNT BITS(0, 15) /*!< counter high value */
  68. #define RTC_CNTL_CNT BITS(0, 15) /*!< counter low value */
  69. /* RTC_ALRM */
  70. #define RTC_ALRMH_ALRM BITS(0, 15) /*!< alarm high value */
  71. #define RTC_ALRML_ALRM BITS(0, 15) /*!< alarm low value */
  72. /* constants definitions */
  73. #define RTC_HIGH_VALUE 0x000F0000U /*!< RTC high value */
  74. #define RTC_LOW_VALUE 0x0000FFFFU /*!< RTC low value */
  75. /* RTC interrupt enable or disable definitions */
  76. #define RTC_INT_SECOND RTC_INTEN_SCIE /*!< second interrupt enable */
  77. #define RTC_INT_ALARM RTC_INTEN_ALRMIE /*!< alarm interrupt enable */
  78. #define RTC_INT_OVERFLOW RTC_INTEN_OVIE /*!< overflow interrupt enable */
  79. /* RTC flag definitions */
  80. #define RTC_FLAG_SECOND RTC_CTL_SCIF /*!< second interrupt flag */
  81. #define RTC_FLAG_ALARM RTC_CTL_ALRMIF /*!< alarm interrupt flag */
  82. #define RTC_FLAG_OVERFLOW RTC_CTL_OVIF /*!< overflow interrupt flag */
  83. #define RTC_FLAG_RSYN RTC_CTL_RSYNF /*!< registers synchronized flag */
  84. #define RTC_FLAG_LWOF RTC_CTL_LWOFF /*!< last write operation finished flag */
  85. /* function declarations */
  86. /* enable RTC interrupt */
  87. void rtc_interrupt_enable(uint32_t interrupt);
  88. /* disable RTC interrupt */
  89. void rtc_interrupt_disable(uint32_t interrupt);
  90. /* enter RTC configuration mode */
  91. void rtc_configuration_mode_enter(void);
  92. /* exit RTC configuration mode */
  93. void rtc_configuration_mode_exit(void);
  94. /* wait RTC last write operation finished flag set */
  95. void rtc_lwoff_wait(void);
  96. /* wait RTC registers synchronized flag set */
  97. void rtc_register_sync_wait(void);
  98. /* get RTC counter value */
  99. uint32_t rtc_counter_get(void);
  100. /* set RTC counter value */
  101. void rtc_counter_set(uint32_t cnt);
  102. /* set RTC prescaler value */
  103. void rtc_prescaler_set(uint32_t psc);
  104. /* set RTC alarm value */
  105. void rtc_alarm_config(uint32_t alarm);
  106. /* get RTC divider value */
  107. uint32_t rtc_divider_get(void);
  108. /* get RTC flag status */
  109. FlagStatus rtc_flag_get(uint32_t flag);
  110. /* clear RTC flag status */
  111. void rtc_flag_clear(uint32_t flag);
  112. #endif /* GD32F30X_RTC_H */