nu_rtc.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /**************************************************************************//**
  2. * @file nu_rtc.h
  3. * @brief RTC driver header file
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. * @copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
  7. *****************************************************************************/
  8. #ifndef __NU_RTC_H__
  9. #define __NU_RTC_H__
  10. #ifdef __cplusplus
  11. extern "C"
  12. {
  13. #endif
  14. #include "NuMicro.h"
  15. #if defined(USE_MA35D1_SUBM)
  16. #define REG_RTC_TALM RTC->TALM_M
  17. #define REG_RTC_CALM RTC->CALM_M
  18. #define REG_RTC_INTEN RTC->INTEN_M
  19. #define REG_RTC_INTSTS RTC->INTSTS_M
  20. #define REG_RTC_TICK RTC->TICK_M
  21. #define REG_RTC_TAMSK RTC->TAMSK_M
  22. #define REG_RTC_CAMSK RTC->CAMSK_M
  23. #else
  24. #define REG_RTC_TALM RTC->TALM
  25. #define REG_RTC_CALM RTC->CALM
  26. #define REG_RTC_INTEN RTC->INTEN
  27. #define REG_RTC_INTSTS RTC->INTSTS
  28. #define REG_RTC_TICK RTC->TICK
  29. #define REG_RTC_TAMSK RTC->TAMSK
  30. #define REG_RTC_CAMSK RTC->CAMSK
  31. #endif
  32. /** @addtogroup Standard_Driver Standard Driver
  33. @{
  34. */
  35. /** @addtogroup RTC_Driver RTC Driver
  36. @{
  37. */
  38. /** @addtogroup RTC_EXPORTED_CONSTANTS RTC Exported Constants
  39. @{
  40. */
  41. /*---------------------------------------------------------------------------------------------------------*/
  42. /* RTC Initial Keyword Constant Definitions */
  43. /*---------------------------------------------------------------------------------------------------------*/
  44. #define RTC_INIT_KEY 0xA5EB1357UL /*!< RTC Initiation Key to make RTC leaving reset state \hideinitializer */
  45. /*---------------------------------------------------------------------------------------------------------*/
  46. /* RTC Time Attribute Constant Definitions */
  47. /*---------------------------------------------------------------------------------------------------------*/
  48. #define RTC_CLOCK_12 0UL /*!< RTC as 12-hour time scale with AM and PM indication \hideinitializer */
  49. #define RTC_CLOCK_24 1UL /*!< RTC as 24-hour time scale \hideinitializer */
  50. #define RTC_AM 1UL /*!< RTC as AM indication \hideinitializer */
  51. #define RTC_PM 2UL /*!< RTC as PM indication \hideinitializer */
  52. /*---------------------------------------------------------------------------------------------------------*/
  53. /* RTC Tick Period Constant Definitions */
  54. /*---------------------------------------------------------------------------------------------------------*/
  55. #define RTC_TICK_1_SEC 0x0UL /*!< RTC time tick period is 1 second \hideinitializer */
  56. #define RTC_TICK_1_2_SEC 0x1UL /*!< RTC time tick period is 1/2 second \hideinitializer */
  57. #define RTC_TICK_1_4_SEC 0x2UL /*!< RTC time tick period is 1/4 second \hideinitializer */
  58. #define RTC_TICK_1_8_SEC 0x3UL /*!< RTC time tick period is 1/8 second \hideinitializer */
  59. #define RTC_TICK_1_16_SEC 0x4UL /*!< RTC time tick period is 1/16 second \hideinitializer */
  60. #define RTC_TICK_1_32_SEC 0x5UL /*!< RTC time tick period is 1/32 second \hideinitializer */
  61. #define RTC_TICK_1_64_SEC 0x6UL /*!< RTC time tick period is 1/64 second \hideinitializer */
  62. #define RTC_TICK_1_128_SEC 0x7UL /*!< RTC time tick period is 1/128 second \hideinitializer */
  63. /*---------------------------------------------------------------------------------------------------------*/
  64. /* RTC Day of Week Constant Definitions */
  65. /*---------------------------------------------------------------------------------------------------------*/
  66. #define RTC_SUNDAY 0x0UL /*!< Day of the Week is Sunday \hideinitializer */
  67. #define RTC_MONDAY 0x1UL /*!< Day of the Week is Monday \hideinitializer */
  68. #define RTC_TUESDAY 0x2UL /*!< Day of the Week is Tuesday \hideinitializer */
  69. #define RTC_WEDNESDAY 0x3UL /*!< Day of the Week is Wednesday \hideinitializer */
  70. #define RTC_THURSDAY 0x4UL /*!< Day of the Week is Thursday \hideinitializer */
  71. #define RTC_FRIDAY 0x5UL /*!< Day of the Week is Friday \hideinitializer */
  72. #define RTC_SATURDAY 0x6UL /*!< Day of the Week is Saturday \hideinitializer */
  73. /*---------------------------------------------------------------------------------------------------------*/
  74. /* RTC Miscellaneous Constant Definitions */
  75. /*---------------------------------------------------------------------------------------------------------*/
  76. #define RTC_WAIT_COUNT 0xFFFFFFFFUL /*!< Initial Time-out Value \hideinitializer */
  77. #define RTC_YEAR2000 2000UL /*!< RTC Reference for compute year data \hideinitializer */
  78. /*@}*/ /* end of group RTC_EXPORTED_CONSTANTS */
  79. /** @addtogroup RTC_EXPORTED_STRUCTS RTC Exported Structs
  80. @{
  81. */
  82. /**
  83. * @details RTC define Time Data Struct
  84. */
  85. typedef struct
  86. {
  87. uint32_t u32Year; /*!< Year value */
  88. uint32_t u32Month; /*!< Month value */
  89. uint32_t u32Day; /*!< Day value */
  90. uint32_t u32DayOfWeek; /*!< Day of week value */
  91. uint32_t u32Hour; /*!< Hour value */
  92. uint32_t u32Minute; /*!< Minute value */
  93. uint32_t u32Second; /*!< Second value */
  94. uint32_t u32TimeScale; /*!< 12-Hour, 24-Hour */
  95. uint32_t u32AmPm; /*!< Only Time Scale select 12-hr used */
  96. } S_RTC_TIME_DATA_T;
  97. /*@}*/ /* end of group RTC_EXPORTED_STRUCTS */
  98. /** @addtogroup RTC_EXPORTED_FUNCTIONS RTC Exported Functions
  99. @{
  100. */
  101. /**
  102. * @brief Indicate is Leap Year or not
  103. *
  104. * @param None
  105. *
  106. * @retval 0 This year is not a leap year
  107. * @retval 1 This year is a leap year
  108. *
  109. * @details According to current date, return this year is leap year or not.
  110. * \hideinitializer
  111. */
  112. #define RTC_IS_LEAP_YEAR() (RTC->LEAPYEAR & RTC_LEAPYEAR_LEAPYEAR_Msk ? 1:0)
  113. /**
  114. * @brief Clear RTC Alarm Interrupt Flag
  115. *
  116. * @param None
  117. *
  118. * @return None
  119. *
  120. * @details This macro is used to clear RTC alarm interrupt flag.
  121. * \hideinitializer
  122. */
  123. #define RTC_CLEAR_ALARM_INT_FLAG() (REG_RTC_INTSTS = RTC_INTSTS_ALMIF_Msk)
  124. /**
  125. * @brief Clear RTC Tick Interrupt Flag
  126. *
  127. * @param None
  128. *
  129. * @return None
  130. *
  131. * @details This macro is used to clear RTC tick interrupt flag.
  132. * \hideinitializer
  133. */
  134. #define RTC_CLEAR_TICK_INT_FLAG() (REG_RTC_INTSTS = RTC_INTSTS_TICKIF_Msk)
  135. /**
  136. * @brief Get RTC Alarm Interrupt Flag
  137. *
  138. * @param None
  139. *
  140. * @retval 0 RTC alarm interrupt did not occur
  141. * @retval 1 RTC alarm interrupt occurred
  142. *
  143. * @details This macro indicates RTC alarm interrupt occurred or not.
  144. * \hideinitializer
  145. */
  146. #define RTC_GET_ALARM_INT_FLAG() ((REG_RTC_INTSTS & RTC_INTSTS_ALMIF_Msk)? 1:0)
  147. /**
  148. * @brief Get RTC Time Tick Interrupt Flag
  149. *
  150. * @param None
  151. *
  152. * @retval 0 RTC time tick interrupt did not occur
  153. * @retval 1 RTC time tick interrupt occurred
  154. *
  155. * @details This macro indicates RTC time tick interrupt occurred or not.
  156. * \hideinitializer
  157. */
  158. #define RTC_GET_TICK_INT_FLAG() ((REG_RTC_INTSTS & RTC_INTSTS_TICKIF_Msk)? 1:0)
  159. /**
  160. * @brief Read Spare Register
  161. *
  162. * @param[in] u32RegNum The spare register number, 0~19.
  163. *
  164. * @return Spare register content
  165. *
  166. * @details Read the specify spare register content.
  167. * @note The returned value is valid only when SPRRDY(SPRCTL[7] SPR Register Ready) bit is set. \n
  168. * And its controlled by RTC Access Enable Register.
  169. * \hideinitializer
  170. */
  171. #define RTC_READ_SPARE_REGISTER(u32RegNum) (RTC->SPR[(u32RegNum)])
  172. int32_t RTC_Open(S_RTC_TIME_DATA_T *sPt);
  173. void RTC_Close(void);
  174. void RTC_GetDateAndTime(S_RTC_TIME_DATA_T *sPt);
  175. void RTC_GetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt);
  176. void RTC_SetDateAndTime(S_RTC_TIME_DATA_T *sPt);
  177. void RTC_SetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt);
  178. void RTC_SetDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day, uint32_t u32DayOfWeek);
  179. void RTC_SetTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm);
  180. void RTC_SetAlarmDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day);
  181. void RTC_SetAlarmTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm);
  182. void RTC_SetAlarmDateMask(uint8_t u8IsTenYMsk, uint8_t u8IsYMsk, uint8_t u8IsTenMMsk, uint8_t u8IsMMsk, uint8_t u8IsTenDMsk, uint8_t u8IsDMsk);
  183. void RTC_SetAlarmTimeMask(uint8_t u8IsTenHMsk, uint8_t u8IsHMsk, uint8_t u8IsTenMMsk, uint8_t u8IsMMsk, uint8_t u8IsTenSMsk, uint8_t u8IsSMsk);
  184. uint32_t RTC_GetDayOfWeek(void);
  185. void RTC_SetTickPeriod(uint32_t u32TickSelection);
  186. void RTC_EnableInt(uint32_t u32IntFlagMask);
  187. void RTC_DisableInt(uint32_t u32IntFlagMask);
  188. /*@}*/ /* end of group RTC_EXPORTED_FUNCTIONS */
  189. /*@}*/ /* end of group RTC_Driver */
  190. /*@}*/ /* end of group Standard_Driver */
  191. #ifdef __cplusplus
  192. }
  193. #endif
  194. #endif /* __NU_RTC_H__ */