at32f413_rtc.h 6.3 KB

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