at32f413_rtc.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /**
  2. **************************************************************************
  3. * @file at32f413_rtc.h
  4. * @version v2.0.5
  5. * @date 2022-05-20
  6. * @brief at32f413 rtc header file
  7. **************************************************************************
  8. * Copyright notice & Disclaimer
  9. *
  10. * The software Board Support Package (BSP) that is made available to
  11. * download from Artery official website is the copyrighted work of Artery.
  12. * Artery authorizes customers to use, copy, and distribute the BSP
  13. * software and its related documentation for the purpose of design and
  14. * development in conjunction with Artery microcontrollers. Use of the
  15. * software is governed by this copyright notice and the following disclaimer.
  16. *
  17. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  18. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  19. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  20. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  21. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  23. *
  24. **************************************************************************
  25. */
  26. /* Define to prevent recursive inclusion -------------------------------------*/
  27. #ifndef __AT32F413_RTC_H
  28. #define __AT32F413_RTC_H
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /* Includes ------------------------------------------------------------------*/
  33. #include "at32f413.h"
  34. /** @addtogroup AT32F413_periph_driver
  35. * @{
  36. */
  37. /** @addtogroup RTC
  38. * @{
  39. */
  40. /** @defgroup RTC_interrupts_definition
  41. * @brief rtc interrupt
  42. * @{
  43. */
  44. #define RTC_TS_INT ((uint16_t)0x0001) /*!< rtc time second interrupt */
  45. #define RTC_TA_INT ((uint16_t)0x0002) /*!< rtc time alarm interrupt */
  46. #define RTC_OVF_INT ((uint16_t)0x0004) /*!< rtc overflow interrupt */
  47. /**
  48. * @}
  49. */
  50. /** @defgroup RTC_flags_definition
  51. * @brief rtc flag
  52. * @{
  53. */
  54. #define RTC_TS_FLAG ((uint16_t)0x0001) /*!< rtc time second flag */
  55. #define RTC_TA_FLAG ((uint16_t)0x0002) /*!< rtc time alarm flag */
  56. #define RTC_OVF_FLAG ((uint16_t)0x0004) /*!< rtc overflow flag */
  57. #define RTC_UPDF_FLAG ((uint16_t)0x0008) /*!< rtc update finish flag */
  58. #define RTC_CFGF_FLAG ((uint16_t)0x0020) /*!< rtc configuration finish flag */
  59. /**
  60. * @}
  61. */
  62. /** @defgroup RTC_exported_types
  63. * @{
  64. */
  65. /**
  66. * @brief type define rtc register all
  67. */
  68. typedef struct
  69. {
  70. /**
  71. * @brief rtc ctrlh register, offset:0x00
  72. */
  73. union
  74. {
  75. __IO uint32_t ctrlh;
  76. struct
  77. {
  78. __IO uint32_t tsien : 1; /* [0] */
  79. __IO uint32_t taien : 1; /* [1] */
  80. __IO uint32_t ovfien : 1; /* [2] */
  81. __IO uint32_t reserved1 : 29;/* [31:3] */
  82. } ctrlh_bit;
  83. };
  84. /**
  85. * @brief rtc ctrll register, offset:0x04
  86. */
  87. union
  88. {
  89. __IO uint32_t ctrll;
  90. struct
  91. {
  92. __IO uint32_t tsf : 1; /* [0] */
  93. __IO uint32_t taf : 1; /* [1] */
  94. __IO uint32_t ovff : 1; /* [2] */
  95. __IO uint32_t updf : 1; /* [3] */
  96. __IO uint32_t cfgen : 1; /* [4] */
  97. __IO uint32_t cfgf : 1; /* [5] */
  98. __IO uint32_t reserved1 : 26;/* [31:6] */
  99. } ctrll_bit;
  100. };
  101. /**
  102. * @brief rtc divh register, offset:0x08
  103. */
  104. union
  105. {
  106. __IO uint32_t divh;
  107. struct
  108. {
  109. __IO uint32_t div : 4; /* [3:0] */
  110. __IO uint32_t reserved1 : 28;/* [31:4] */
  111. } divh_bit;
  112. };
  113. /**
  114. * @brief rtc divl register, offset:0x0C
  115. */
  116. union
  117. {
  118. __IO uint32_t divl;
  119. struct
  120. {
  121. __IO uint32_t div : 16;/* [15:0] */
  122. __IO uint32_t reserved1 : 16;/* [31:15] */
  123. } divl_bit;
  124. };
  125. /**
  126. * @brief rtc divcnth register, offset:0x10
  127. */
  128. union
  129. {
  130. __IO uint32_t divcnth;
  131. struct
  132. {
  133. __IO uint32_t divcnt : 4; /* [3:0] */
  134. __IO uint32_t reserved1 : 28;/* [31:15] */
  135. } divcnth_bit;
  136. };
  137. /**
  138. * @brief rtc divcntl register, offset:0x14
  139. */
  140. union
  141. {
  142. __IO uint32_t divcntl;
  143. struct
  144. {
  145. __IO uint32_t divcnt : 16;/* [15:0] */
  146. __IO uint32_t reserved1 : 16;/* [31:15] */
  147. } divcntl_bit;
  148. };
  149. /**
  150. * @brief rtc cnth register, offset:0x18
  151. */
  152. union
  153. {
  154. __IO uint32_t cnth;
  155. struct
  156. {
  157. __IO uint32_t cnt : 16;/* [15:0] */
  158. __IO uint32_t reserved1 : 16;/* [31:15] */
  159. } cnth_bit;
  160. };
  161. /**
  162. * @brief rtc cntl register, offset:0x1C
  163. */
  164. union
  165. {
  166. __IO uint32_t cntl;
  167. struct
  168. {
  169. __IO uint32_t cnt : 16;/* [15:0] */
  170. __IO uint32_t reserved1 : 16;/* [31:15] */
  171. } cntl_bit;
  172. };
  173. /**
  174. * @brief rtc tah register, offset:0x20
  175. */
  176. union
  177. {
  178. __IO uint32_t tah;
  179. struct
  180. {
  181. __IO uint32_t ta : 16;/* [15:0] */
  182. __IO uint32_t reserved1 : 16;/* [31:15] */
  183. } tah_bit;
  184. };
  185. /**
  186. * @brief rtc tal register, offset:0x24
  187. */
  188. union
  189. {
  190. __IO uint32_t tal;
  191. struct
  192. {
  193. __IO uint32_t ta : 16;/* [15:0] */
  194. __IO uint32_t reserved1 : 16;/* [31:15] */
  195. } tal_bit;
  196. };
  197. } rtc_type;
  198. /**
  199. * @}
  200. */
  201. #define RTC ((rtc_type *) RTC_BASE)
  202. /** @defgroup RTC_exported_functions
  203. * @{
  204. */
  205. void rtc_counter_set(uint32_t counter_value);
  206. uint32_t rtc_counter_get(void);
  207. void rtc_divider_set(uint32_t div_value);
  208. uint32_t rtc_divider_get(void);
  209. void rtc_alarm_set(uint32_t alarm_value);
  210. void rtc_interrupt_enable(uint16_t source, confirm_state new_state);
  211. flag_status rtc_flag_get(uint16_t flag);
  212. void rtc_flag_clear(uint16_t flag);
  213. void rtc_wait_config_finish(void);
  214. void rtc_wait_update_finish(void);
  215. /**
  216. * @}
  217. */
  218. /**
  219. * @}
  220. */
  221. /**
  222. * @}
  223. */
  224. #ifdef __cplusplus
  225. }
  226. #endif
  227. #endif