nu_rtc.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. /**************************************************************************//**
  2. * @file rtc.h
  3. * @version V3.00
  4. * @brief NUC980 series RTC driver header file
  5. *
  6. * SPDX-License-Identifier: Apache-2.0
  7. * @copyright (C) 2016 Nuvoton Technology Corp. All rights reserved.
  8. *****************************************************************************/
  9. #ifndef __NU_RTC_H__
  10. #define __NU_RTC_H__
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include "nuc980.h"
  15. /** @addtogroup Standard_Driver Standard Driver
  16. @{
  17. */
  18. /** @addtogroup RTC_Driver RTC Driver
  19. @{
  20. */
  21. /** @addtogroup RTC_EXPORTED_CONSTANTS RTC Exported Constants
  22. @{
  23. */
  24. /*---------------------------------------------------------------------------------------------------------*/
  25. /* RTC Initial Keyword Constant Definitions */
  26. /*---------------------------------------------------------------------------------------------------------*/
  27. #define RTC_INIT_KEY 0xA5EB1357UL /*!< RTC Initiation Key to make RTC leaving reset state \hideinitializer */
  28. #define RTC_WRITE_KEY 0x0000A965UL /*!< RTC Register Access Enable Key to enable RTC read/write accessible and kept 1024 RTC clock \hideinitializer */
  29. /*---------------------------------------------------------------------------------------------------------*/
  30. /* RTC Time Attribute Constant Definitions */
  31. /*---------------------------------------------------------------------------------------------------------*/
  32. #define RTC_CLOCK_12 0UL /*!< RTC as 12-hour time scale with AM and PM indication \hideinitializer */
  33. #define RTC_CLOCK_24 1UL /*!< RTC as 24-hour time scale \hideinitializer */
  34. #define RTC_AM 1UL /*!< RTC as AM indication \hideinitializer */
  35. #define RTC_PM 2UL /*!< RTC as PM indication \hideinitializer */
  36. /*---------------------------------------------------------------------------------------------------------*/
  37. /* RTC Tick Period Constant Definitions */
  38. /*---------------------------------------------------------------------------------------------------------*/
  39. #define RTC_TICK_1_SEC 0x0UL /*!< RTC time tick period is 1 second \hideinitializer */
  40. #define RTC_TICK_1_2_SEC 0x1UL /*!< RTC time tick period is 1/2 second \hideinitializer */
  41. #define RTC_TICK_1_4_SEC 0x2UL /*!< RTC time tick period is 1/4 second \hideinitializer */
  42. #define RTC_TICK_1_8_SEC 0x3UL /*!< RTC time tick period is 1/8 second \hideinitializer */
  43. #define RTC_TICK_1_16_SEC 0x4UL /*!< RTC time tick period is 1/16 second \hideinitializer */
  44. #define RTC_TICK_1_32_SEC 0x5UL /*!< RTC time tick period is 1/32 second \hideinitializer */
  45. #define RTC_TICK_1_64_SEC 0x6UL /*!< RTC time tick period is 1/64 second \hideinitializer */
  46. #define RTC_TICK_1_128_SEC 0x7UL /*!< RTC time tick period is 1/128 second \hideinitializer */
  47. /*---------------------------------------------------------------------------------------------------------*/
  48. /* RTC Day of Week Constant Definitions */
  49. /*---------------------------------------------------------------------------------------------------------*/
  50. #define RTC_SUNDAY 0x0UL /*!< Day of the Week is Sunday \hideinitializer */
  51. #define RTC_MONDAY 0x1UL /*!< Day of the Week is Monday \hideinitializer */
  52. #define RTC_TUESDAY 0x2UL /*!< Day of the Week is Tuesday \hideinitializer */
  53. #define RTC_WEDNESDAY 0x3UL /*!< Day of the Week is Wednesday \hideinitializer */
  54. #define RTC_THURSDAY 0x4UL /*!< Day of the Week is Thursday \hideinitializer */
  55. #define RTC_FRIDAY 0x5UL /*!< Day of the Week is Friday \hideinitializer */
  56. #define RTC_SATURDAY 0x6UL /*!< Day of the Week is Saturday \hideinitializer */
  57. /*---------------------------------------------------------------------------------------------------------*/
  58. /* RTC Miscellaneous Constant Definitions */
  59. /*---------------------------------------------------------------------------------------------------------*/
  60. #define RTC_WAIT_COUNT 0xFFFFFFFFUL /*!< Initial Time-out Value \hideinitializer */
  61. #define RTC_YEAR2000 2000UL /*!< RTC Reference for compute year data \hideinitializer */
  62. #define RTC_FCR_REFERENCE 32761UL /*!< RTC Reference for frequency compensation \hideinitializer */
  63. #define RTC_2POW10_CLK (0x0 << RTC_TAMPCTL_DYNRATE_Pos) /*!< 1024 RTC clock cycles \hideinitializer */
  64. #define RTC_2POW11_CLK (0x1 << RTC_TAMPCTL_DYNRATE_Pos) /*!< 1024 x 2 RTC clock cycles \hideinitializer */
  65. #define RTC_2POW12_CLK (0x2 << RTC_TAMPCTL_DYNRATE_Pos) /*!< 1024 x 4 RTC clock cycles \hideinitializer */
  66. #define RTC_2POW13_CLK (0x3 << RTC_TAMPCTL_DYNRATE_Pos) /*!< 1024 x 6 RTC clock cycles \hideinitializer */
  67. #define RTC_2POW14_CLK (0x4 << RTC_TAMPCTL_DYNRATE_Pos) /*!< 1024 x 8 RTC clock cycles \hideinitializer */
  68. #define RTC_2POW15_CLK (0x5 << RTC_TAMPCTL_DYNRATE_Pos) /*!< 1024 x 16 RTC clock cycles \hideinitializer */
  69. #define RTC_2POW16_CLK (0x6 << RTC_TAMPCTL_DYNRATE_Pos) /*!< 1024 x 32 RTC clock cycles \hideinitializer */
  70. #define RTC_2POW17_CLK (0x7 << RTC_TAMPCTL_DYNRATE_Pos) /*!< 1024 x 64 RTC clock cycles \hideinitializer */
  71. #define REF_RANDOM_PATTERN 0x0 /*!< The new reference pattern is generated by random number generator when the reference pattern run out \hideinitializer */
  72. #define REF_PREVIOUS_PATTERN 0x1 /*!< The new reference pattern is repeated previous random value when the reference pattern run out \hideinitializer */
  73. #define REF_SEED 0x3 /*!< The new reference pattern is repeated from SEED (RTC_TAMPSEED[31:0]) when the reference pattern run out \hideinitializer */
  74. /*@}*/ /* end of group RTC_EXPORTED_CONSTANTS */
  75. /** @addtogroup RTC_EXPORTED_STRUCTS RTC Exported Structs
  76. @{
  77. */
  78. /**
  79. * @details RTC define Time Data Struct
  80. */
  81. typedef struct
  82. {
  83. uint32_t u32Year; /*!< Year value */
  84. uint32_t u32Month; /*!< Month value */
  85. uint32_t u32Day; /*!< Day value */
  86. uint32_t u32DayOfWeek; /*!< Day of week value */
  87. uint32_t u32Hour; /*!< Hour value */
  88. uint32_t u32Minute; /*!< Minute value */
  89. uint32_t u32Second; /*!< Second value */
  90. uint32_t u32TimeScale; /*!< 12-Hour, 24-Hour */
  91. uint32_t u32AmPm; /*!< Only Time Scale select 12-hr used */
  92. } S_RTC_TIME_DATA_T;
  93. /*@}*/ /* end of group RTC_EXPORTED_STRUCTS */
  94. typedef struct
  95. {
  96. __IO uint32_t INIT; /*!< [0x0000] RTC Initiation Register */
  97. __IO uint32_t RWEN; /*!< [0x0004] RTC Access Enable Register */
  98. __IO uint32_t FREQADJ; /*!< [0x0008] RTC Frequency Compensation Register */
  99. __IO uint32_t TIME; /*!< [0x000c] RTC Time Loading Register */
  100. __IO uint32_t CAL; /*!< [0x0010] RTC Calendar Loading Register */
  101. __IO uint32_t CLKFMT; /*!< [0x0014] RTC Time Scale Selection Register */
  102. __IO uint32_t WEEKDAY; /*!< [0x0018] RTC Day of the Week Register */
  103. __IO uint32_t TALM; /*!< [0x001c] RTC Time Alarm Register */
  104. __IO uint32_t CALM; /*!< [0x0020] RTC Calendar Alarm Register */
  105. __I uint32_t LEAPYEAR; /*!< [0x0024] RTC Leap Year Indicator Register */
  106. __IO uint32_t INTEN; /*!< [0x0028] RTC Interrupt Enable Register */
  107. __IO uint32_t INTSTS; /*!< [0x002c] RTC Interrupt Status Register */
  108. __IO uint32_t TICK; /*!< [0x0030] RTC Time Tick Register */
  109. __IO uint32_t PWRCTL; /*!< [0x0034] RTC Power Control Register */
  110. __IO uint32_t PWRCNT; /*!< [0x0038] RTC Power Control Counter Register */
  111. __IO uint32_t RESERVE0; /*!< [0x003c] RTC Spare Functional Control Register */
  112. __I uint32_t SPR[16]; /*!< [0x0040] ~ [0x007c] RTC Spare Register 0 ~ 15 */
  113. } RTC_T;
  114. #define RTC_INIT_ACTIVE_Pos (0) /*!< RTC_T::INIT: INIT_ACTIVE Position */
  115. #define RTC_INIT_ACTIVE_Msk (0x1ul << RTC_INIT_ACTIVE_Pos) /*!< RTC_T::INIT: INIT_ACTIVE Mask */
  116. #define RTC_INIT_INIT_Pos (1) /*!< RTC_T::INIT: INIT Position */
  117. #define RTC_INIT_INIT_Msk (0x7ffffffful << RTC_INIT_INIT_Pos) /*!< RTC_T::INIT: INIT Mask */
  118. #define RTC_RWEN_RWENF_Pos (16) /*!< RTC_T::RWEN: RWENF Position */
  119. #define RTC_RWEN_RWENF_Msk (0x1ul << RTC_RWEN_RWENF_Pos) /*!< RTC_T::RWEN: RWENF Mask */
  120. #define RTC_RWEN_RTCBUSY_Pos (24) /*!< RTC_T::RWEN: RTCBUSY Position */
  121. #define RTC_RWEN_RTCBUSY_Msk (0x1ul << RTC_RWEN_RTCBUSY_Pos) /*!< RTC_T::RWEN: RTCBUSY Mask */
  122. #define RTC_FREQADJ_FRACTION_Pos (0) /*!< RTC_T::FRACTION: FRACTION Position */
  123. #define RTC_FREQADJ_FRACTION_Msk (0x3ful << RTC_FREQADJ_FRACTION_Pos) /*!< RTC_T::FRACTION: FRACTION Mask */
  124. #define RTC_INTEGER_FRACTION_Pos (8) /*!< RTC_T::INTEGER: INTEGER Position */
  125. #define RTC_INTEGER_FRACTION_Msk (0xful << RTC_FREQADJ_INTEGER_Pos) /*!< RTC_T::INTEGER: INTEGER Mask */
  126. #define RTC_TIME_SEC_Pos (0) /*!< RTC_T::TIME: SEC Position */
  127. #define RTC_TIME_SEC_Msk (0xful << RTC_TIME_SEC_Pos) /*!< RTC_T::TIME: SEC Mask */
  128. #define RTC_TIME_TENSEC_Pos (4) /*!< RTC_T::TIME: TENSEC Position */
  129. #define RTC_TIME_TENSEC_Msk (0x7ul << RTC_TIME_TENSEC_Pos) /*!< RTC_T::TIME: TENSEC Mask */
  130. #define RTC_TIME_MIN_Pos (8) /*!< RTC_T::TIME: MIN Position */
  131. #define RTC_TIME_MIN_Msk (0xful << RTC_TIME_MIN_Pos) /*!< RTC_T::TIME: MIN Mask */
  132. #define RTC_TIME_TENMIN_Pos (12) /*!< RTC_T::TIME: TENMIN Position */
  133. #define RTC_TIME_TENMIN_Msk (0x7ul << RTC_TIME_TENMIN_Pos) /*!< RTC_T::TIME: TENMIN Mask */
  134. #define RTC_TIME_HR_Pos (16) /*!< RTC_T::TIME: HR Position */
  135. #define RTC_TIME_HR_Msk (0xful << RTC_TIME_HR_Pos) /*!< RTC_T::TIME: HR Mask */
  136. #define RTC_TIME_TENHR_Pos (20) /*!< RTC_T::TIME: TENHR Position */
  137. #define RTC_TIME_TENHR_Msk (0x3ul << RTC_TIME_TENHR_Pos) /*!< RTC_T::TIME: TENHR Mask */
  138. #define RTC_CAL_DAY_Pos (0) /*!< RTC_T::CAL: DAY Position */
  139. #define RTC_CAL_DAY_Msk (0xful << RTC_CAL_DAY_Pos) /*!< RTC_T::CAL: DAY Mask */
  140. #define RTC_CAL_TENDAY_Pos (4) /*!< RTC_T::CAL: TENDAY Position */
  141. #define RTC_CAL_TENDAY_Msk (0x3ul << RTC_CAL_TENDAY_Pos) /*!< RTC_T::CAL: TENDAY Mask */
  142. #define RTC_CAL_MON_Pos (8) /*!< RTC_T::CAL: MON Position */
  143. #define RTC_CAL_MON_Msk (0xful << RTC_CAL_MON_Pos) /*!< RTC_T::CAL: MON Mask */
  144. #define RTC_CAL_TENMON_Pos (12) /*!< RTC_T::CAL: TENMON Position */
  145. #define RTC_CAL_TENMON_Msk (0x1ul << RTC_CAL_TENMON_Pos) /*!< RTC_T::CAL: TENMON Mask */
  146. #define RTC_CAL_YEAR_Pos (16) /*!< RTC_T::CAL: YEAR Position */
  147. #define RTC_CAL_YEAR_Msk (0xful << RTC_CAL_YEAR_Pos) /*!< RTC_T::CAL: YEAR Mask */
  148. #define RTC_CAL_TENYEAR_Pos (20) /*!< RTC_T::CAL: TENYEAR Position */
  149. #define RTC_CAL_TENYEAR_Msk (0xful << RTC_CAL_TENYEAR_Pos) /*!< RTC_T::CAL: TENYEAR Mask */
  150. #define RTC_CLKFMT_24HEN_Pos (0) /*!< RTC_T::CLKFMT: 24HEN Position */
  151. #define RTC_CLKFMT_24HEN_Msk (0x1ul << RTC_CLKFMT_24HEN_Pos) /*!< RTC_T::CLKFMT: 24HEN Mask */
  152. #define RTC_WEEKDAY_WEEKDAY_Pos (0) /*!< RTC_T::WEEKDAY: WEEKDAY Position */
  153. #define RTC_WEEKDAY_WEEKDAY_Msk (0x7ul << RTC_WEEKDAY_WEEKDAY_Pos) /*!< RTC_T::WEEKDAY: WEEKDAY Mask */
  154. #define RTC_TALM_SEC_Pos (0) /*!< RTC_T::TALM: SEC Position */
  155. #define RTC_TALM_SEC_Msk (0xful << RTC_TALM_SEC_Pos) /*!< RTC_T::TALM: SEC Mask */
  156. #define RTC_TALM_TENSEC_Pos (4) /*!< RTC_T::TALM: TENSEC Position */
  157. #define RTC_TALM_TENSEC_Msk (0x7ul << RTC_TALM_TENSEC_Pos) /*!< RTC_T::TALM: TENSEC Mask */
  158. #define RTC_TALM_MIN_Pos (8) /*!< RTC_T::TALM: MIN Position */
  159. #define RTC_TALM_MIN_Msk (0xful << RTC_TALM_MIN_Pos) /*!< RTC_T::TALM: MIN Mask */
  160. #define RTC_TALM_TENMIN_Pos (12) /*!< RTC_T::TALM: TENMIN Position */
  161. #define RTC_TALM_TENMIN_Msk (0x7ul << RTC_TALM_TENMIN_Pos) /*!< RTC_T::TALM: TENMIN Mask */
  162. #define RTC_TALM_HR_Pos (16) /*!< RTC_T::TALM: HR Position */
  163. #define RTC_TALM_HR_Msk (0xful << RTC_TALM_HR_Pos) /*!< RTC_T::TALM: HR Mask */
  164. #define RTC_TALM_TENHR_Pos (20) /*!< RTC_T::TALM: TENHR Position */
  165. #define RTC_TALM_TENHR_Msk (0x3ul << RTC_TALM_TENHR_Pos) /*!< RTC_T::TALM: TENHR Mask */
  166. #define RTC_CALM_DAY_Pos (0) /*!< RTC_T::CALM: DAY Position */
  167. #define RTC_CALM_DAY_Msk (0xful << RTC_CALM_DAY_Pos) /*!< RTC_T::CALM: DAY Mask */
  168. #define RTC_CALM_TENDAY_Pos (4) /*!< RTC_T::CALM: TENDAY Position */
  169. #define RTC_CALM_TENDAY_Msk (0x3ul << RTC_CALM_TENDAY_Pos) /*!< RTC_T::CALM: TENDAY Mask */
  170. #define RTC_CALM_MON_Pos (8) /*!< RTC_T::CALM: MON Position */
  171. #define RTC_CALM_MON_Msk (0xful << RTC_CALM_MON_Pos) /*!< RTC_T::CALM: MON Mask */
  172. #define RTC_CALM_TENMON_Pos (12) /*!< RTC_T::CALM: TENMON Position */
  173. #define RTC_CALM_TENMON_Msk (0x1ul << RTC_CALM_TENMON_Pos) /*!< RTC_T::CALM: TENMON Mask */
  174. #define RTC_CALM_YEAR_Pos (16) /*!< RTC_T::CALM: YEAR Position */
  175. #define RTC_CALM_YEAR_Msk (0xful << RTC_CALM_YEAR_Pos) /*!< RTC_T::CALM: YEAR Mask */
  176. #define RTC_CALM_TENYEAR_Pos (20) /*!< RTC_T::CALM: TENYEAR Position */
  177. #define RTC_CALM_TENYEAR_Msk (0xful << RTC_CALM_TENYEAR_Pos) /*!< RTC_T::CALM: TENYEAR Mask */
  178. #define RTC_LEAPYEAR_LEAPYEAR_Pos (0) /*!< RTC_T::LEAPYEAR: LEAPYEAR Position */
  179. #define RTC_LEAPYEAR_LEAPYEAR_Msk (0x1ul << RTC_LEAPYEAR_LEAPYEAR_Pos) /*!< RTC_T::LEAPYEAR: LEAPYEAR Mask */
  180. #define RTC_INTEN_ALMIEN_Pos (0) /*!< RTC_T::INTEN: ALMIEN Position */
  181. #define RTC_INTEN_ALMIEN_Msk (0x1ul << RTC_INTEN_ALMIEN_Pos) /*!< RTC_T::INTEN: ALMIEN Mask */
  182. #define RTC_INTEN_TICKIEN_Pos (1) /*!< RTC_T::INTEN: TICKIEN Position */
  183. #define RTC_INTEN_TICKIEN_Msk (0x1ul << RTC_INTEN_TICKIEN_Pos) /*!< RTC_T::INTEN: TICKIEN Mask */
  184. #define RTC_INTEN_WAKEUPIEN_Pos (2) /*!< RTC INTEN: WAKEUPIEN Position */
  185. #define RTC_INTEN_WAKEUPIEN_Msk (0x1ul << RTC_INTEN_WAKEUPIEN_Pos) /*!< RTC INTEN: WAKEUPIEN Mask */
  186. #define RTC_INTEN_RELALMIEN_Pos (4) /*!< RTC INTEN: RELALMIEN Position */
  187. #define RTC_INTEN_RELALMIEN_Msk (0x1ul << RTC_INTEN_RELALMIEN_Pos) /*!< RTC INTEN: RELALMIEN Mask */
  188. #define RTC_INTSTS_ALMIF_Pos (0) /*!< RTC_T::INTSTS: ALMIF Position */
  189. #define RTC_INTSTS_ALMIF_Msk (0x1ul << RTC_INTSTS_ALMIF_Pos) /*!< RTC_T::INTSTS: ALMIF Mask */
  190. #define RTC_INTSTS_TICKIF_Pos (1) /*!< RTC_T::INTSTS: TICKIF Position */
  191. #define RTC_INTSTS_TICKIF_Msk (0x1ul << RTC_INTSTS_TICKIF_Pos) /*!< RTC_T::INTSTS: TICKIF Mask */
  192. #define RTC_INTSTS_WAKEUPINT_Pos (2) /*!< RTC INTSTS: WAKEUPINT Position */
  193. #define RTC_INTSTS_WAKEUPINT_Msk (0x1ul << RTC_INTSTS_WAKEUPINT_Pos) /*!< RTC INTSTS: WAKEUPINT Mask */
  194. #define RTC_INTSTS_REGWRBUSY_Pos (31) /*!< RTC INTSTS: REGWRBUSY Position */
  195. #define RTC_INTSTS_REGWRBUSY_Msk (0x1ul << RTC_INTSTS_REGWRBUSY_Pos) /*!< RTC INTSTS: REGWRBUSY Mask */
  196. #define RTC_TICK_TICK_Pos (0) /*!< RTC_T::TICK: TICK Position */
  197. #define RTC_TICK_TICK_Msk (0x7ul << RTC_TICK_TICK_Pos) /*!< RTC_T::TICK: TICK Mask */
  198. #define RTC_PWRCTL_ALARM_EN_Pos (3)
  199. #define RTC_PWRCTL_ALARM_EN_Msk (0x1ul << RTC_PWRCTL_ALARM_EN_Pos)
  200. #define RTC_PWRCTL_REL_ALARM_EN_Pos (4)
  201. #define RTC_PWRCTL_REL_ALARM_EN_Msk (0x1ul << RTC_PWRCTL_REL_ALARM_EN_Pos)
  202. #define RTC_PWRCTL_RELALM_TIME_Pos (16)
  203. #define RTC_PWRCTL_RELALM_TIME_Msk (0xffful << RTC_PWRCTL_RELALM_TIME_Pos)
  204. #define RTC_SPR0_SPARE_Pos (0) /*!< RTC_T::SPR0: SPARE Position */
  205. #define RTC_SPR0_SPARE_Msk (0xfffffffful << RTC_SPR0_SPARE_Pos) /*!< RTC_T::SPR0: SPARE Mask */
  206. #define RTC_SPR1_SPARE_Pos (0) /*!< RTC_T::SPR1: SPARE Position */
  207. #define RTC_SPR1_SPARE_Msk (0xfffffffful << RTC_SPR1_SPARE_Pos) /*!< RTC_T::SPR1: SPARE Mask */
  208. #define RTC_SPR2_SPARE_Pos (0) /*!< RTC_T::SPR2: SPARE Position */
  209. #define RTC_SPR2_SPARE_Msk (0xfffffffful << RTC_SPR2_SPARE_Pos) /*!< RTC_T::SPR2: SPARE Mask */
  210. #define RTC_SPR3_SPARE_Pos (0) /*!< RTC_T::SPR3: SPARE Position */
  211. #define RTC_SPR3_SPARE_Msk (0xfffffffful << RTC_SPR3_SPARE_Pos) /*!< RTC_T::SPR3: SPARE Mask */
  212. #define RTC_SPR4_SPARE_Pos (0) /*!< RTC_T::SPR4: SPARE Position */
  213. #define RTC_SPR4_SPARE_Msk (0xfffffffful << RTC_SPR4_SPARE_Pos) /*!< RTC_T::SPR4: SPARE Mask */
  214. #define RTC_SPR5_SPARE_Pos (0) /*!< RTC_T::SPR5: SPARE Position */
  215. #define RTC_SPR5_SPARE_Msk (0xfffffffful << RTC_SPR5_SPARE_Pos) /*!< RTC_T::SPR5: SPARE Mask */
  216. #define RTC_SPR6_SPARE_Pos (0) /*!< RTC_T::SPR6: SPARE Position */
  217. #define RTC_SPR6_SPARE_Msk (0xfffffffful << RTC_SPR6_SPARE_Pos) /*!< RTC_T::SPR6: SPARE Mask */
  218. #define RTC_SPR7_SPARE_Pos (0) /*!< RTC_T::SPR7: SPARE Position */
  219. #define RTC_SPR7_SPARE_Msk (0xfffffffful << RTC_SPR7_SPARE_Pos) /*!< RTC_T::SPR7: SPARE Mask */
  220. #define RTC_SPR8_SPARE_Pos (0) /*!< RTC_T::SPR8: SPARE Position */
  221. #define RTC_SPR8_SPARE_Msk (0xfffffffful << RTC_SPR8_SPARE_Pos) /*!< RTC_T::SPR8: SPARE Mask */
  222. #define RTC_SPR9_SPARE_Pos (0) /*!< RTC_T::SPR9: SPARE Position */
  223. #define RTC_SPR9_SPARE_Msk (0xfffffffful << RTC_SPR9_SPARE_Pos) /*!< RTC_T::SPR9: SPARE Mask */
  224. #define RTC_SPR10_SPARE_Pos (0) /*!< RTC_T::SPR10: SPARE Position */
  225. #define RTC_SPR10_SPARE_Msk (0xfffffffful << RTC_SPR10_SPARE_Pos) /*!< RTC_T::SPR10: SPARE Mask */
  226. #define RTC_SPR11_SPARE_Pos (0) /*!< RTC_T::SPR11: SPARE Position */
  227. #define RTC_SPR11_SPARE_Msk (0xfffffffful << RTC_SPR11_SPARE_Pos) /*!< RTC_T::SPR11: SPARE Mask */
  228. #define RTC_SPR12_SPARE_Pos (0) /*!< RTC_T::SPR12: SPARE Position */
  229. #define RTC_SPR12_SPARE_Msk (0xfffffffful << RTC_SPR12_SPARE_Pos) /*!< RTC_T::SPR12: SPARE Mask */
  230. #define RTC_SPR13_SPARE_Pos (0) /*!< RTC_T::SPR13: SPARE Position */
  231. #define RTC_SPR13_SPARE_Msk (0xfffffffful << RTC_SPR13_SPARE_Pos) /*!< RTC_T::SPR13: SPARE Mask */
  232. #define RTC_SPR14_SPARE_Pos (0) /*!< RTC_T::SPR14: SPARE Position */
  233. #define RTC_SPR14_SPARE_Msk (0xfffffffful << RTC_SPR14_SPARE_Pos) /*!< RTC_T::SPR14: SPARE Mask */
  234. #define RTC_SPR15_SPARE_Pos (0) /*!< RTC_T::SPR15: SPARE Position */
  235. #define RTC_SPR15_SPARE_Msk (0xfffffffful << RTC_SPR15_SPARE_Pos) /*!< RTC_T::SPR15: SPARE Mask */
  236. #define RTC ((RTC_T *) RTC_BA)
  237. /** @addtogroup RTC_EXPORTED_FUNCTIONS RTC Exported Functions
  238. @{
  239. */
  240. /**
  241. * @brief Indicate is Leap Year or not
  242. *
  243. * @param None
  244. *
  245. * @retval 0 This year is not a leap year
  246. * @retval 1 This year is a leap year
  247. *
  248. * @details According to current date, return this year is leap year or not.
  249. * \hideinitializer
  250. */
  251. #define RTC_IS_LEAP_YEAR() (RTC->LEAPYEAR & RTC_LEAPYEAR_LEAPYEAR_Msk ? 1:0)
  252. /**
  253. * @brief Clear RTC Alarm Interrupt Flag
  254. *
  255. * @param None
  256. *
  257. * @return None
  258. *
  259. * @details This macro is used to clear RTC alarm interrupt flag.
  260. * \hideinitializer
  261. */
  262. #define RTC_CLEAR_ALARM_INT_FLAG() (RTC->INTSTS = RTC_INTSTS_ALMIF_Msk)
  263. /**
  264. * @brief Clear RTC Tick Interrupt Flag
  265. *
  266. * @param None
  267. *
  268. * @return None
  269. *
  270. * @details This macro is used to clear RTC tick interrupt flag.
  271. * \hideinitializer
  272. */
  273. #define RTC_CLEAR_TICK_INT_FLAG() (RTC->INTSTS = RTC_INTSTS_TICKIF_Msk)
  274. /**
  275. * @brief Get RTC Alarm Interrupt Flag
  276. *
  277. * @param None
  278. *
  279. * @retval 0 RTC alarm interrupt did not occur
  280. * @retval 1 RTC alarm interrupt occurred
  281. *
  282. * @details This macro indicates RTC alarm interrupt occurred or not.
  283. * \hideinitializer
  284. */
  285. #define RTC_GET_ALARM_INT_FLAG() ((RTC->INTSTS & RTC_INTSTS_ALMIF_Msk)? 1:0)
  286. /**
  287. * @brief Get RTC Time Tick Interrupt Flag
  288. *
  289. * @param None
  290. *
  291. * @retval 0 RTC time tick interrupt did not occur
  292. * @retval 1 RTC time tick interrupt occurred
  293. *
  294. * @details This macro indicates RTC time tick interrupt occurred or not.
  295. * \hideinitializer
  296. */
  297. #define RTC_GET_TICK_INT_FLAG() ((RTC->INTSTS & RTC_INTSTS_TICKIF_Msk)? 1:0)
  298. /**
  299. * @brief Read Spare Register
  300. *
  301. * @param[in] u32RegNum The spare register number, 0~19.
  302. *
  303. * @return Spare register content
  304. *
  305. * @details Read the specify spare register content.
  306. * @note The returned value is valid only when SPRRDY(SPRCTL[7] SPR Register Ready) bit is set. \n
  307. * And its controlled by RTC Access Enable Register.
  308. * \hideinitializer
  309. */
  310. #define RTC_READ_SPARE_REGISTER(u32RegNum) (RTC->SPR[(u32RegNum)])
  311. /**
  312. * @brief Write Spare Register
  313. *
  314. * @param[in] u32RegNum The spare register number, 0~19.
  315. * @param[in] u32RegValue The spare register value.
  316. *
  317. * @return None
  318. *
  319. * @details Write specify data to spare register.
  320. * @note This macro is effect only when SPRRDY(SPRCTL[7] SPR Register Ready) bit is set. \n
  321. * And its controlled by RTC Access Enable Register(RTC_RWEN).
  322. * \hideinitializer
  323. */
  324. #define RTC_WRITE_SPARE_REGISTER(u32RegNum, u32RegValue) (RTC->SPR[(u32RegNum)] = (u32RegValue))
  325. /* Declare these inline functions here to avoid MISRA C 2004 rule 8.1 error */
  326. void RTC_WaitAccessEnable(void);
  327. void RTC_Check(void);
  328. void RTC_Open(S_RTC_TIME_DATA_T *sPt);
  329. void RTC_Close(void);
  330. void RTC_32KCalibration(int32_t i32FrequencyX100);
  331. void RTC_GetDateAndTime(S_RTC_TIME_DATA_T *sPt);
  332. void RTC_GetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt);
  333. void RTC_SetDateAndTime(S_RTC_TIME_DATA_T *sPt);
  334. void RTC_SetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt);
  335. void RTC_SetDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day, uint32_t u32DayOfWeek);
  336. void RTC_SetTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm);
  337. void RTC_SetAlarmDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day, uint32_t u32DayOfWeek);
  338. void RTC_SetAlarmTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm);
  339. uint32_t RTC_GetDayOfWeek(void);
  340. void RTC_SetTickPeriod(uint32_t u32TickSelection);
  341. void RTC_EnableInt(uint32_t u32IntFlagMask);
  342. void RTC_DisableInt(uint32_t u32IntFlagMask);
  343. void RTC_EnableSpareAccess(void);
  344. void RTC_DisableSpareRegister(void);
  345. /*@}*/ /* end of group RTC_EXPORTED_FUNCTIONS */
  346. /*@}*/ /* end of group RTC_Driver */
  347. /*@}*/ /* end of group Standard_Driver */
  348. #endif /* __NU_RTC_H__ */
  349. /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/