hc32f460_rtc.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*******************************************************************************
  2. * Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
  3. *
  4. * This software component is licensed by HDSC under BSD 3-Clause license
  5. * (the "License"); You may not use this file except in compliance with the
  6. * License. You may obtain a copy of the License at:
  7. * opensource.org/licenses/BSD-3-Clause
  8. */
  9. /******************************************************************************/
  10. /** \file hc32f460_rtc.h
  11. **
  12. ** A detailed description is available at
  13. ** @link RtcGroup Real-Time Clock description @endlink
  14. **
  15. ** - 2018-11-22 CDT First version for Device Driver Library of RTC.
  16. **
  17. ******************************************************************************/
  18. #ifndef __HC32F460_RTC_H__
  19. #define __HC32F460_RTC_H__
  20. /*******************************************************************************
  21. * Include files
  22. ******************************************************************************/
  23. #include "hc32_common.h"
  24. #include "ddl_config.h"
  25. #if (DDL_RTC_ENABLE == DDL_ON)
  26. /* C binding of definitions if building with C++ compiler */
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. /**
  32. *******************************************************************************
  33. ** \defgroup RtcGroup Real-Time Clock(RTC)
  34. **
  35. ******************************************************************************/
  36. //@{
  37. /*******************************************************************************
  38. * Global type definitions ('typedef')
  39. ******************************************************************************/
  40. /**
  41. *******************************************************************************
  42. ** \brief RTC period interrupt type enumeration
  43. ******************************************************************************/
  44. typedef enum en_rtc_period_int_type
  45. {
  46. RtcPeriodIntInvalid = 0u, ///< Period interrupt invalid
  47. RtcPeriodIntHalfSec = 1u, ///< 0.5 second period interrupt
  48. RtcPeriodIntOneSec = 2u, ///< 1 second period interrupt
  49. RtcPeriodIntOneMin = 3u, ///< 1 minute period interrupt
  50. RtcPeriodIntOneHour = 4u, ///< 1 hour period interrupt
  51. RtcPeriodIntOneDay = 5u, ///< 1 day period interrupt
  52. RtcPeriodIntOneMon = 6u ///< 1 month period interrupt
  53. } en_rtc_period_int_type_t;
  54. /**
  55. *******************************************************************************
  56. ** \brief RTC time format enumeration
  57. ******************************************************************************/
  58. typedef enum en_rtc_time_format
  59. {
  60. RtcTimeFormat12Hour = 0u, ///< 12 hours mode
  61. RtcTimeFormat24Hour = 1u, ///< 24 hours mode
  62. } en_rtc_time_format_t;
  63. /**
  64. *******************************************************************************
  65. ** \brief RTC 1Hz output compensation way enumeration
  66. ******************************************************************************/
  67. typedef enum en_rtc_output_compen
  68. {
  69. RtcOutputCompenDistributed = 0u, ///< Distributed compensation 1hz output
  70. RtcOutputCompenUniform = 1u, ///< Uniform Compensation 1hz output
  71. } en_rtc_output_compen_t;
  72. /**
  73. *******************************************************************************
  74. ** \brief RTC work mode enumeration
  75. ******************************************************************************/
  76. typedef enum en_rtc_work_mode
  77. {
  78. RtcModeNormalCount = 0u, ///< Normal count mode
  79. RtcModeReadOrWrite = 1u, ///< Read or write mode
  80. } en_rtc_work_mode_t;
  81. /**
  82. *******************************************************************************
  83. ** \brief RTC count clock source enumeration
  84. ******************************************************************************/
  85. typedef enum en_rtc_clk_source
  86. {
  87. RtcClkXtal32 = 0u, ///< XTAL32 as clock source
  88. RtcClkLrc = 1u, ///< LRC as clock source
  89. } en_rtc_clk_source_t;
  90. /**
  91. *******************************************************************************
  92. ** \brief RTC data format enumeration
  93. ******************************************************************************/
  94. typedef enum en_rtc_data_format
  95. {
  96. RtcDataFormatDec = 0u, ///< Decimal format
  97. RtcDataFormatBcd = 1u, ///< BCD format
  98. } en_rtc_data_format_t;
  99. /**
  100. *******************************************************************************
  101. ** \brief RTC 12 hour AM/PM enumeration
  102. ******************************************************************************/
  103. typedef enum en_rtc_hour12_ampm
  104. {
  105. RtcHour12Am = 0u, ///< Ante meridiem
  106. RtcHour12Pm = 1u, ///< Post meridiem
  107. } en_rtc_hour12_ampm_t;
  108. /**
  109. *******************************************************************************
  110. ** \brief RTC month enumeration
  111. ******************************************************************************/
  112. typedef enum en_rtc_month
  113. {
  114. RtcMonthJanuary = 1u, ///< January
  115. RtcMonthFebruary = 2u, ///< February
  116. RtcMonthMarch = 3u, ///< March
  117. RtcMonthApril = 4u, ///< April
  118. RtcMonthMay = 5u, ///< May
  119. RtcMonthJune = 6u, ///< June
  120. RtcMonthJuly = 7u, ///< July
  121. RtcMonthAugust = 8u, ///< August
  122. RtcMonthSeptember = 9u, ///< September
  123. RtcMonthOctober = 10u, ///< October
  124. RtcMonthNovember = 11u, ///< November
  125. RtcMonthDecember = 12u, ///< December
  126. } en_rtc_month_t;
  127. /**
  128. *******************************************************************************
  129. ** \brief RTC weekday enumeration
  130. ******************************************************************************/
  131. typedef enum en_rtc_weekday
  132. {
  133. RtcWeekdaySunday = 0u, ///< Sunday
  134. RtcWeekdayMonday = 1u, ///< Monday
  135. RtcWeekdayTuesday = 2u, ///< Tuesday
  136. RtcWeekdayWednesday = 3u, ///< Wednesday
  137. RtcWeekdayThursday = 4u, ///< Thursday
  138. RtcWeekdayFriday = 5u, ///< Friday
  139. RtcWeekdaySaturday = 6u ///< Saturday
  140. } en_rtc_weekday_t;
  141. /**
  142. *******************************************************************************
  143. ** \brief RTC alarm weekday enumeration
  144. ******************************************************************************/
  145. typedef enum en_rtc_alarm_weekday
  146. {
  147. RtcAlarmWeekdaySunday = 0x01u, ///< Sunday
  148. RtcAlarmWeekdayMonday = 0x02u, ///< Monday
  149. RtcAlarmWeekdayTuesday = 0x04u, ///< Tuesday
  150. RtcAlarmWeekdayWednesday = 0x08u, ///< Wednesday
  151. RtcAlarmWeekdayThursday = 0x10u, ///< Thursday
  152. RtcAlarmWeekdayFriday = 0x20u, ///< Friday
  153. RtcAlarmWeekdaySaturday = 0x40u, ///< Saturday
  154. } en_rtc_alarm_weekday_t;
  155. /**
  156. *******************************************************************************
  157. ** \brief RTC interrupt request type enumeration
  158. ******************************************************************************/
  159. typedef enum en_rtc_irq_type_
  160. {
  161. RtcIrqPeriod = 0u, ///< Period count interrupt request
  162. RtcIrqAlarm = 1u, ///< Alarm interrupt request
  163. } en_rtc_irq_type_t;
  164. /**
  165. *******************************************************************************
  166. ** \brief RTC date and time structure definition
  167. ******************************************************************************/
  168. typedef struct stc_rtc_date_time
  169. {
  170. uint8_t u8Year; ///< Year (range 0-99)
  171. uint8_t u8Month; ///< Month (range 1-12)
  172. uint8_t u8Day; ///< Day (range 1-31)
  173. uint8_t u8Hour; ///< Hours (range 1-12 when 12 hour format; range 0-23 when 24 hour format)
  174. uint8_t u8Minute; ///< Minutes (range 0-59)
  175. uint8_t u8Second; ///< Seconds (range 0-59)
  176. uint8_t u8Weekday; ///< Weekday (range 0-6)
  177. en_rtc_hour12_ampm_t enAmPm; ///< The value is valid when 12-hour format
  178. } stc_rtc_date_time_t;
  179. /**
  180. *******************************************************************************
  181. ** \brief RTC alarm time structure definition
  182. ******************************************************************************/
  183. typedef struct stc_rtc_alarm_time
  184. {
  185. uint8_t u8Minute; ///< Minutes (range 0-59)
  186. uint8_t u8Hour; ///< Hours (range 1-12 when 12 hour format; range 0-23 when 24 hour format)
  187. uint8_t u8Weekday; ///< Weekday (range RtcAlarmWeekdaySunday to RtcAlarmWeekdaySaturday)
  188. en_rtc_hour12_ampm_t enAmPm; ///< The value is valid when 12-hour format
  189. } stc_rtc_alarm_time_t;
  190. /**
  191. *******************************************************************************
  192. ** \brief RTC init structure definition
  193. ******************************************************************************/
  194. typedef struct stc_rtc_init
  195. {
  196. en_rtc_clk_source_t enClkSource; ///< Clock source
  197. en_rtc_period_int_type_t enPeriodInt; ///< Period interrupt condition
  198. en_rtc_time_format_t enTimeFormat; ///< RTC time format
  199. en_rtc_output_compen_t enCompenWay; ///< 1HZ output compensation way
  200. uint16_t u16CompenVal; ///< Clock error compensation value
  201. en_functional_state_t enCompenEn; ///< Enable/Disable clock error compensation
  202. } stc_rtc_init_t;
  203. /*******************************************************************************
  204. * Global pre-processor symbols/macros ('#define')
  205. ******************************************************************************/
  206. /*******************************************************************************
  207. * Global variable definitions ('extern')
  208. ******************************************************************************/
  209. /*******************************************************************************
  210. Global function prototypes (definition in C source)
  211. ******************************************************************************/
  212. /* Base functions */
  213. en_result_t RTC_DeInit(void);
  214. en_result_t RTC_Init(const stc_rtc_init_t *pstcRtcInit);
  215. en_result_t RTC_Cmd(en_functional_state_t enNewSta);
  216. en_result_t RTC_EnterRwMode(void);
  217. en_result_t RTC_ExitRwMode(void);
  218. /* Extend functions */
  219. en_result_t RTC_PeriodIntConfig(en_rtc_period_int_type_t enIntType);
  220. en_result_t RTC_LowPowerSwitch(void);
  221. en_result_t RTC_SetClkCompenValue(uint16_t u16CompenVal);
  222. en_result_t RTC_ClkCompenCmd(en_functional_state_t enNewSta);
  223. en_result_t RTC_OneHzOutputCmd(en_functional_state_t enNewSta);
  224. /* Date and time functions */
  225. en_result_t RTC_SetDateTime(en_rtc_data_format_t enFormat, const stc_rtc_date_time_t *pstcRtcDateTime,
  226. en_functional_state_t enUpdateDateEn, en_functional_state_t enUpdateTimeEn);
  227. en_result_t RTC_GetDateTime(en_rtc_data_format_t enFormat, stc_rtc_date_time_t *pstcRtcDateTime);
  228. /* Alarm functions */
  229. en_result_t RTC_SetAlarmTime(en_rtc_data_format_t enFormat, const stc_rtc_alarm_time_t *pstcRtcAlarmTime);
  230. en_result_t RTC_GetAlarmTime(en_rtc_data_format_t enFormat, stc_rtc_alarm_time_t *pstcRtcAlarmTime);
  231. en_result_t RTC_AlarmCmd(en_functional_state_t enNewSta);
  232. /* Interrupt and flags management functions ******************************************/
  233. en_result_t RTC_IrqCmd(en_rtc_irq_type_t enIrq, en_functional_state_t enNewSta);
  234. en_flag_status_t RTC_GetAlarmFlag(void);
  235. en_result_t RTC_ClearAlarmFlag(void);
  236. //@} // RtcGroup
  237. #ifdef __cplusplus
  238. }
  239. #endif
  240. #endif /* DDL_RTC_ENABLE */
  241. #endif /* __HC32F460_RTC_H__ */
  242. /*******************************************************************************
  243. * EOF (not truncated)
  244. ******************************************************************************/