rtc.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /**************************************************************************//**
  2. * @file rtc.h
  3. * @version V1.00
  4. * $Revision: 18 $
  5. * $Date: 14/10/01 2:43p $
  6. * @brief NUC472/NUC442 RTC driver header file
  7. *
  8. * @note
  9. * Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved.
  10. *****************************************************************************/
  11. #ifndef __RTC_H
  12. #define __RTC_H
  13. #ifdef __cplusplus
  14. extern "C"
  15. {
  16. #endif
  17. /** @addtogroup NUC472_442_Device_Driver NUC472/NUC442 Device Driver
  18. @{
  19. */
  20. /** @addtogroup NUC472_442_RTC_Driver RTC Driver
  21. @{
  22. */
  23. /** @addtogroup NUC472_442_RTC_EXPORTED_CONSTANTS RTC Exported Constants
  24. @{
  25. */
  26. #define RTC_INIT_KEY 0xA5EB1357UL /*!< RTC Access Key \hideinitializer */
  27. #define RTC_WRITE_KEY 0xA965 /*!< RTC Access Key \hideinitializer */
  28. #define RTC_WAIT_COUNT 0xFFFFFFFF /*!< Initial Time Out Value \hideinitializer */
  29. #define RTC_YEAR2000 2000 /*!< RTC Reference \hideinitializer */
  30. #define RTC_FCR_REFERENCE 32761 /*!< RTC Reference \hideinitializer */
  31. #define RTC_CLOCK_12 0 /*!< RTC 12 Hour \hideinitializer */
  32. #define RTC_CLOCK_24 1 /*!< RTC 24 Hour \hideinitializer */
  33. #define RTC_AM 1 /*!< RTC AM \hideinitializer */
  34. #define RTC_PM 2 /*!< RTC PM \hideinitializer */
  35. #define RTC_TICK_1_SEC ((uint32_t) 0x00000000) /*!< Time tick is 1 second \hideinitializer */
  36. #define RTC_TICK_1_2_SEC ((uint32_t) 0x00000001) /*!< Time tick is 1/2 second \hideinitializer */
  37. #define RTC_TICK_1_4_SEC ((uint32_t) 0x00000002) /*!< Time tick is 1/4 second \hideinitializer */
  38. #define RTC_TICK_1_8_SEC ((uint32_t) 0x00000003) /*!< Time tick is 1/8 second \hideinitializer */
  39. #define RTC_TICK_1_16_SEC ((uint32_t) 0x00000004) /*!< Time tick is 1/16 second \hideinitializer */
  40. #define RTC_TICK_1_32_SEC ((uint32_t) 0x00000005) /*!< Time tick is 1/32 second \hideinitializer */
  41. #define RTC_TICK_1_64_SEC ((uint32_t) 0x00000006) /*!< Time tick is 1/64 second \hideinitializer */
  42. #define RTC_TICK_1_128_SEC ((uint32_t) 0x00000007) /*!< Time tick is 1/128 second \hideinitializer */
  43. #define RTC_SUNDAY ((uint32_t) 0x00000000) /*!< Day of week is sunday \hideinitializer */
  44. #define RTC_MONDAY ((uint32_t) 0x00000001) /*!< Day of week is monday \hideinitializer */
  45. #define RTC_TUESDAY ((uint32_t) 0x00000002) /*!< Day of week is tuesday \hideinitializer */
  46. #define RTC_WEDNESDAY ((uint32_t) 0x00000003) /*!< Day of week is wednesday \hideinitializer */
  47. #define RTC_THURSDAY ((uint32_t) 0x00000004) /*!< Day of week is thuesday \hideinitializer */
  48. #define RTC_FRIDAY ((uint32_t) 0x00000005) /*!< Day of week is friday \hideinitializer */
  49. #define RTC_SATURDAY ((uint32_t) 0x00000006) /*!< Day of week is saturday \hideinitializer */
  50. #define RTC_TAMPER_0 0 /*!< Select Tamper 0 pin \hideinitializer */
  51. #define RTC_TAMPER_1 1 /*!< Select Tamper 0 pin \hideinitializer */
  52. /*@}*/ /* end of group NUC472_442_RTC_EXPORTED_CONSTANTS */
  53. /** @addtogroup NUC472_442_RTC_EXPORTED_STRUCTS RTC Exported Structs
  54. @{
  55. */
  56. /**
  57. * @brief RTC define Time Data Struct
  58. */
  59. typedef struct {
  60. uint32_t u32Year; /*!< Year value */
  61. uint32_t u32Month; /*!< Month value */
  62. uint32_t u32Day; /*!< Day value */
  63. uint32_t u32DayOfWeek; /*!< Day of week value */
  64. uint32_t u32Hour; /*!< Hour value */
  65. uint32_t u32Minute; /*!< Minute value */
  66. uint32_t u32Second; /*!< Second value */
  67. uint32_t u32TimeScale; /*!< 12-Hour, 24-Hour */
  68. uint32_t u32AmPm; /*!< Only Time Scale select 12-hr used */
  69. } S_RTC_TIME_DATA_T;
  70. /*@}*/ /* end of group NUC472_442_RTC_EXPORTED_STRUCTS */
  71. /** @addtogroup NUC472_442_RTC_EXPORTED_FUNCTIONS RTC Exported Functions
  72. @{
  73. */
  74. /**
  75. * @brief Read spare register
  76. *
  77. * @param[in] u32RegNum The spare register number(0~23)
  78. *
  79. * @return Spare register content.
  80. * \hideinitializer
  81. */
  82. #define RTC_READ_SPARE_REGISTER(u32RegNum) (RTC->SPR[u32RegNum])
  83. /**
  84. * @brief Write spare register
  85. *
  86. * @param[in] u32RegNum The spare register number(0~23)
  87. * @param[in] u32RegValue The spare register value
  88. *
  89. * @return None
  90. * \hideinitializer
  91. */
  92. #define RTC_WRITE_SPARE_REGISTER(u32RegNum, u32RegValue) (RTC->SPR[u32RegNum] = u32RegValue)
  93. /**
  94. * @brief According to current time, return this year is leap year or not
  95. *
  96. * @param None
  97. *
  98. * @return 0 = This year is not a leap year. \n
  99. * 1 = This year is a leap year.
  100. * \hideinitializer
  101. */
  102. #define RTC_IS_LEAP_YEAR ((RTC->LEAPYEAR & (RTC_LEAPYEAR_LEAPYEAR_Msk))?1:0)
  103. /**
  104. * @brief Clear alarm interrupt status.
  105. *
  106. * @param None
  107. *
  108. * @return None
  109. * \hideinitializer
  110. */
  111. #define RTC_CLEAR_ALARM_INT_FLAG (RTC->INTSTS = RTC_INTSTS_ALMIF_Msk)
  112. /**
  113. * @brief Clear tick interrupt status.
  114. *
  115. * @param None
  116. *
  117. * @return None
  118. * \hideinitializer
  119. */
  120. #define RTC_CLEAR_TICK_INT_FLAG (RTC->INTSTS = RTC_INTSTS_TICKIF_Msk)
  121. /**
  122. * @brief Clear tamper detect pin status.
  123. *
  124. * @param[in] u32PinNum tamper detect pin number. [ \ref RTC_TAMPER_0 / \ref RTC_TAMPER_1]
  125. *
  126. * @return None
  127. * \hideinitializer
  128. */
  129. #define RTC_CLEAR_TAMPER_FLAG(u32PinNum) (RTC->TAMPSTS = (1 << u32PinNum))
  130. /**
  131. * @brief Get alarm interrupt status.
  132. *
  133. * @param None
  134. *
  135. * @return Alarm interrupt status
  136. * \hideinitializer
  137. */
  138. #define RTC_GET_ALARM_INT_FLAG ((RTC->INTSTS & RTC_INTSTS_ALMIF_Msk) >> RTC_INTSTS_ALMIF_Pos)
  139. /**
  140. * @brief Get alarm interrupt status.
  141. *
  142. * @param None
  143. *
  144. * @return Alarm interrupt status
  145. * \hideinitializer
  146. */
  147. #define RTC_GET_TICK_INT_FLAG ((RTC->INTSTS & RTC_INTSTS_TICKIF_Msk) >> RTC_INTSTS_TICKIF_Pos)
  148. /**
  149. * @brief Get tamper detect pin status.
  150. *
  151. * @param[in] u32PinNum tamper detect pin number. [ \ref RTC_TAMPER_0 / \ref RTC_TAMPER_1]
  152. *
  153. * @return Tamper detect pin status
  154. * \hideinitializer
  155. */
  156. #define RTC_GET_TAMPER_FLAG(u32PinNum) ( (RTC->TAMPSTS & (1 << u32PinNum)) >> u32PinNum)
  157. void RTC_Open(S_RTC_TIME_DATA_T *sPt);
  158. void RTC_Close(void);
  159. void RTC_32KCalibration(int32_t i32FrequencyX100);
  160. void RTC_SetTickPeriod(uint32_t u32TickSelection);
  161. void RTC_EnableInt(uint32_t u32IntFlagMask);
  162. void RTC_DisableInt(uint32_t u32IntFlagMask);
  163. uint32_t RTC_GetDayOfWeek(void);
  164. void RTC_DisableTamperDetection(uint32_t u32PinNumber);
  165. void RTC_EnableTamperDetection(uint32_t u32PinNumber, uint32_t u32PinCondition, uint32_t u32IntFlag, uint32_t u32ClearFlag, uint32_t u32DestroyEn);
  166. void RTC_EnableSpareAccess(void);
  167. void RTC_SetAlarmTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm);
  168. void RTC_SetAlarmDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day);
  169. void RTC_SetTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm);
  170. void RTC_SetDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day, uint32_t u32DayOfWeek);
  171. void RTC_SetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt);
  172. void RTC_SetDateAndTime(S_RTC_TIME_DATA_T *sPt);
  173. void RTC_GetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt);
  174. void RTC_GetDateAndTime(S_RTC_TIME_DATA_T *sPt);
  175. /*@}*/ /* end of group NUC472_442_RTC_EXPORTED_FUNCTIONS */
  176. /*@}*/ /* end of group NUC472_442_RTC_Driver */
  177. /*@}*/ /* end of group NUC472_442_Device_Driver */
  178. #ifdef __cplusplus
  179. }
  180. #endif
  181. #endif /* __RTC_H */
  182. /*** (C) COPYRIGHT 2012 Nuvoton Technology Corp. ***/