hk32f0xx_rtc.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. /**
  2. ******************************************************************************
  3. * @file hk32f0xx_rtc.h
  4. * @version V1.0.1
  5. * @date 2019-08-15
  6. ******************************************************************************
  7. */
  8. /* Define to prevent recursive inclusion -------------------------------------*/
  9. #ifndef __HK32F0XX_RTC_H
  10. #define __HK32F0XX_RTC_H
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /* Includes ------------------------------------------------------------------*/
  15. #include "hk32f0xx.h"
  16. /** @addtogroup HK32F0xx_StdPeriph_Driver
  17. * @{
  18. */
  19. /** @addtogroup RTC
  20. * @{
  21. */
  22. /* Exported types ------------------------------------------------------------*/
  23. /**
  24. * @brief RTC Init structures definition
  25. */
  26. typedef struct
  27. {
  28. uint32_t RTC_HourFormat; /*!< Specifies the RTC Hour Format.
  29. This parameter can be a value of @ref RTC_Hour_Formats */
  30. uint32_t RTC_AsynchPrediv; /*!< Specifies the RTC Asynchronous Predivider value.
  31. This parameter must be set to a value lower than 0x7F */
  32. uint32_t RTC_SynchPrediv; /*!< Specifies the RTC Synchronous Predivider value.
  33. This parameter must be set to a value lower than 0x1FFF */
  34. }RTC_InitTypeDef;
  35. /**
  36. * @brief RTC Time structure definition
  37. */
  38. typedef struct
  39. {
  40. uint8_t RTC_Hours; /*!< Specifies the RTC Time Hour.
  41. This parameter must be set to a value in the 0-12 range
  42. if the RTC_HourFormat_12 is selected or 0-23 range if
  43. the RTC_HourFormat_24 is selected. */
  44. uint8_t RTC_Minutes; /*!< Specifies the RTC Time Minutes.
  45. This parameter must be set to a value in the 0-59 range. */
  46. uint8_t RTC_Seconds; /*!< Specifies the RTC Time Seconds.
  47. This parameter must be set to a value in the 0-59 range. */
  48. uint8_t RTC_H12; /*!< Specifies the RTC AM/PM Time.
  49. This parameter can be a value of @ref RTC_AM_PM_Definitions */
  50. }RTC_TimeTypeDef;
  51. /**
  52. * @brief RTC Date structure definition
  53. */
  54. typedef struct
  55. {
  56. uint8_t RTC_WeekDay; /*!< Specifies the RTC Date WeekDay.
  57. This parameter can be a value of @ref RTC_WeekDay_Definitions */
  58. uint8_t RTC_Month; /*!< Specifies the RTC Date Month.
  59. This parameter can be a value of @ref RTC_Month_Date_Definitions */
  60. uint8_t RTC_Date; /*!< Specifies the RTC Date.
  61. This parameter must be set to a value in the 1-31 range. */
  62. uint8_t RTC_Year; /*!< Specifies the RTC Date Year.
  63. This parameter must be set to a value in the 0-99 range. */
  64. }RTC_DateTypeDef;
  65. /**
  66. * @brief RTC Alarm structure definition
  67. */
  68. typedef struct
  69. {
  70. RTC_TimeTypeDef RTC_AlarmTime; /*!< Specifies the RTC Alarm Time members. */
  71. uint32_t RTC_AlarmMask; /*!< Specifies the RTC Alarm Masks.
  72. This parameter can be a value of @ref RTC_AlarmMask_Definitions */
  73. uint32_t RTC_AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay.
  74. This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */
  75. uint8_t RTC_AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay.
  76. This parameter must be set to a value in the 1-31 range
  77. if the Alarm Date is selected.
  78. This parameter can be a value of @ref RTC_WeekDay_Definitions
  79. if the Alarm WeekDay is selected. */
  80. }RTC_AlarmTypeDef;
  81. /* Exported constants --------------------------------------------------------*/
  82. /** @defgroup RTC_Exported_Constants
  83. * @{
  84. */
  85. /** @defgroup RTC_Hour_Formats
  86. * @{
  87. */
  88. #define RTC_HourFormat_24 ((uint32_t)0x00000000)
  89. #define RTC_HourFormat_12 ((uint32_t)0x00000040)
  90. #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HourFormat_12) || \
  91. ((FORMAT) == RTC_HourFormat_24))
  92. /**
  93. * @}
  94. */
  95. /** @defgroup RTC_Asynchronous_Predivider
  96. * @{
  97. */
  98. #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7F)
  99. /**
  100. * @}
  101. */
  102. /** @defgroup RTC_Synchronous_Predivider
  103. * @{
  104. */
  105. #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FFF)
  106. /**
  107. * @}
  108. */
  109. /** @defgroup RTC_Time_Definitions
  110. * @{
  111. */
  112. #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0) && ((HOUR) <= 12))
  113. #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23)
  114. #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59)
  115. #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59)
  116. /**
  117. * @}
  118. */
  119. /** @defgroup RTC_AM_PM_Definitions
  120. * @{
  121. */
  122. #define RTC_H12_AM ((uint8_t)0x00)
  123. #define RTC_H12_PM ((uint8_t)0x40)
  124. #define IS_RTC_H12(PM) (((PM) == RTC_H12_AM) || ((PM) == RTC_H12_PM))
  125. /**
  126. * @}
  127. */
  128. /** @defgroup RTC_Year_Date_Definitions
  129. * @{
  130. */
  131. #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99)
  132. /**
  133. * @}
  134. */
  135. /** @defgroup RTC_Month_Date_Definitions
  136. * @{
  137. */
  138. #define RTC_Month_January ((uint8_t)0x01)
  139. #define RTC_Month_February ((uint8_t)0x02)
  140. #define RTC_Month_March ((uint8_t)0x03)
  141. #define RTC_Month_April ((uint8_t)0x04)
  142. #define RTC_Month_May ((uint8_t)0x05)
  143. #define RTC_Month_June ((uint8_t)0x06)
  144. #define RTC_Month_July ((uint8_t)0x07)
  145. #define RTC_Month_August ((uint8_t)0x08)
  146. #define RTC_Month_September ((uint8_t)0x09)
  147. #define RTC_Month_October ((uint8_t)0x10)
  148. #define RTC_Month_November ((uint8_t)0x11)
  149. #define RTC_Month_December ((uint8_t)0x12)
  150. #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1) && ((MONTH) <= 12))
  151. #define IS_RTC_DATE(DATE) (((DATE) >= 1) && ((DATE) <= 31))
  152. /**
  153. * @}
  154. */
  155. /** @defgroup RTC_WeekDay_Definitions
  156. * @{
  157. */
  158. #define RTC_Weekday_Monday ((uint8_t)0x01)
  159. #define RTC_Weekday_Tuesday ((uint8_t)0x02)
  160. #define RTC_Weekday_Wednesday ((uint8_t)0x03)
  161. #define RTC_Weekday_Thursday ((uint8_t)0x04)
  162. #define RTC_Weekday_Friday ((uint8_t)0x05)
  163. #define RTC_Weekday_Saturday ((uint8_t)0x6)
  164. #define RTC_Weekday_Sunday ((uint8_t)0x07)
  165. #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_Weekday_Monday) || \
  166. ((WEEKDAY) == RTC_Weekday_Tuesday) || \
  167. ((WEEKDAY) == RTC_Weekday_Wednesday) || \
  168. ((WEEKDAY) == RTC_Weekday_Thursday) || \
  169. ((WEEKDAY) == RTC_Weekday_Friday) || \
  170. ((WEEKDAY) == RTC_Weekday_Saturday) || \
  171. ((WEEKDAY) == RTC_Weekday_Sunday))
  172. /**
  173. * @}
  174. */
  175. /** @defgroup RTC_Alarm_Definitions
  176. * @{
  177. */
  178. #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) > 0) && ((DATE) <= 31))
  179. #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_Weekday_Monday) || \
  180. ((WEEKDAY) == RTC_Weekday_Tuesday) || \
  181. ((WEEKDAY) == RTC_Weekday_Wednesday) || \
  182. ((WEEKDAY) == RTC_Weekday_Thursday) || \
  183. ((WEEKDAY) == RTC_Weekday_Friday) || \
  184. ((WEEKDAY) == RTC_Weekday_Saturday) || \
  185. ((WEEKDAY) == RTC_Weekday_Sunday))
  186. /**
  187. * @}
  188. */
  189. /** @defgroup RTC_AlarmDateWeekDay_Definitions
  190. * @{
  191. */
  192. #define RTC_AlarmDateWeekDaySel_Date ((uint32_t)0x00000000)
  193. #define RTC_AlarmDateWeekDaySel_WeekDay ((uint32_t)0x40000000)
  194. #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_AlarmDateWeekDaySel_Date) || \
  195. ((SEL) == RTC_AlarmDateWeekDaySel_WeekDay))
  196. /**
  197. * @}
  198. */
  199. /** @defgroup RTC_AlarmMask_Definitions
  200. * @{
  201. */
  202. #define RTC_AlarmMask_None ((uint32_t)0x00000000)
  203. #define RTC_AlarmMask_DateWeekDay ((uint32_t)0x80000000)
  204. #define RTC_AlarmMask_Hours ((uint32_t)0x00800000)
  205. #define RTC_AlarmMask_Minutes ((uint32_t)0x00008000)
  206. #define RTC_AlarmMask_Seconds ((uint32_t)0x00000080)
  207. #define RTC_AlarmMask_All ((uint32_t)0x80808080)
  208. #define IS_RTC_ALARM_MASK(MASK) (((MASK) & 0x7F7F7F7F) == (uint32_t)RESET)
  209. /**
  210. * @}
  211. */
  212. /** @defgroup RTC_Alarms_Definitions
  213. * @{
  214. */
  215. #define RTC_Alarm_A ((uint32_t)0x00000100)
  216. #define IS_RTC_ALARM(ALARM) ((ALARM) == RTC_Alarm_A)
  217. #define IS_RTC_CMD_ALARM(ALARM) (((ALARM) & (RTC_Alarm_A)) != (uint32_t)RESET)
  218. /**
  219. * @}
  220. */
  221. /** @defgroup RTC_Alarm_Sub_Seconds_Masks Definitions.
  222. * @{
  223. */
  224. #define RTC_AlarmSubSecondMask_All ((uint8_t)0x00) /*!< All Alarm SS fields are masked.
  225. There is no comparison on sub seconds
  226. for Alarm */
  227. #define RTC_AlarmSubSecondMask_SS14_1 ((uint8_t)0x01) /*!< SS[14:1] are don't care in Alarm
  228. comparison. Only SS[0] is compared. */
  229. #define RTC_AlarmSubSecondMask_SS14_2 ((uint8_t)0x02) /*!< SS[14:2] are don't care in Alarm
  230. comparison. Only SS[1:0] are compared */
  231. #define RTC_AlarmSubSecondMask_SS14_3 ((uint8_t)0x03) /*!< SS[14:3] are don't care in Alarm
  232. comparison. Only SS[2:0] are compared */
  233. #define RTC_AlarmSubSecondMask_SS14_4 ((uint8_t)0x04) /*!< SS[14:4] are don't care in Alarm
  234. comparison. Only SS[3:0] are compared */
  235. #define RTC_AlarmSubSecondMask_SS14_5 ((uint8_t)0x05) /*!< SS[14:5] are don't care in Alarm
  236. comparison. Only SS[4:0] are compared */
  237. #define RTC_AlarmSubSecondMask_SS14_6 ((uint8_t)0x06) /*!< SS[14:6] are don't care in Alarm
  238. comparison. Only SS[5:0] are compared */
  239. #define RTC_AlarmSubSecondMask_SS14_7 ((uint8_t)0x07) /*!< SS[14:7] are don't care in Alarm
  240. comparison. Only SS[6:0] are compared */
  241. #define RTC_AlarmSubSecondMask_SS14_8 ((uint8_t)0x08) /*!< SS[14:8] are don't care in Alarm
  242. comparison. Only SS[7:0] are compared */
  243. #define RTC_AlarmSubSecondMask_SS14_9 ((uint8_t)0x09) /*!< SS[14:9] are don't care in Alarm
  244. comparison. Only SS[8:0] are compared */
  245. #define RTC_AlarmSubSecondMask_SS14_10 ((uint8_t)0x0A) /*!< SS[14:10] are don't care in Alarm
  246. comparison. Only SS[9:0] are compared */
  247. #define RTC_AlarmSubSecondMask_SS14_11 ((uint8_t)0x0B) /*!< SS[14:11] are don't care in Alarm
  248. comparison. Only SS[10:0] are compared */
  249. #define RTC_AlarmSubSecondMask_SS14_12 ((uint8_t)0x0C) /*!< SS[14:12] are don't care in Alarm
  250. comparison.Only SS[11:0] are compared */
  251. #define RTC_AlarmSubSecondMask_SS14_13 ((uint8_t)0x0D) /*!< SS[14:13] are don't care in Alarm
  252. comparison. Only SS[12:0] are compared */
  253. #define RTC_AlarmSubSecondMask_SS14 ((uint8_t)0x0E) /*!< SS[14] is don't care in Alarm
  254. comparison.Only SS[13:0] are compared */
  255. #define RTC_AlarmSubSecondMask_None ((uint8_t)0x0F) /*!< SS[14:0] are compared and must match
  256. to activate alarm. */
  257. #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == RTC_AlarmSubSecondMask_All) || \
  258. ((MASK) == RTC_AlarmSubSecondMask_SS14_1) || \
  259. ((MASK) == RTC_AlarmSubSecondMask_SS14_2) || \
  260. ((MASK) == RTC_AlarmSubSecondMask_SS14_3) || \
  261. ((MASK) == RTC_AlarmSubSecondMask_SS14_4) || \
  262. ((MASK) == RTC_AlarmSubSecondMask_SS14_5) || \
  263. ((MASK) == RTC_AlarmSubSecondMask_SS14_6) || \
  264. ((MASK) == RTC_AlarmSubSecondMask_SS14_7) || \
  265. ((MASK) == RTC_AlarmSubSecondMask_SS14_8) || \
  266. ((MASK) == RTC_AlarmSubSecondMask_SS14_9) || \
  267. ((MASK) == RTC_AlarmSubSecondMask_SS14_10) || \
  268. ((MASK) == RTC_AlarmSubSecondMask_SS14_11) || \
  269. ((MASK) == RTC_AlarmSubSecondMask_SS14_12) || \
  270. ((MASK) == RTC_AlarmSubSecondMask_SS14_13) || \
  271. ((MASK) == RTC_AlarmSubSecondMask_SS14) || \
  272. ((MASK) == RTC_AlarmSubSecondMask_None))
  273. /**
  274. * @}
  275. */
  276. /** @defgroup RTC_Alarm_Sub_Seconds_Value
  277. * @{
  278. */
  279. #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= 0x00007FFF)
  280. /**
  281. * @}
  282. */
  283. /** @defgroup RTC_Wakeup_Timer_Definitions
  284. * @{
  285. */
  286. #define RTC_WakeUpClock_RTCCLK_Div16 ((uint32_t)0x00000000)
  287. #define RTC_WakeUpClock_RTCCLK_Div8 ((uint32_t)0x00000001)
  288. #define RTC_WakeUpClock_RTCCLK_Div4 ((uint32_t)0x00000002)
  289. #define RTC_WakeUpClock_RTCCLK_Div2 ((uint32_t)0x00000003)
  290. #define RTC_WakeUpClock_CK_SPRE_16bits ((uint32_t)0x00000004)
  291. #define RTC_WakeUpClock_CK_SPRE_17bits ((uint32_t)0x00000006)
  292. #define IS_RTC_WAKEUP_CLOCK(CLOCK) (((CLOCK) == RTC_WakeUpClock_RTCCLK_Div16) || \
  293. ((CLOCK) == RTC_WakeUpClock_RTCCLK_Div8) || \
  294. ((CLOCK) == RTC_WakeUpClock_RTCCLK_Div4) || \
  295. ((CLOCK) == RTC_WakeUpClock_RTCCLK_Div2) || \
  296. ((CLOCK) == RTC_WakeUpClock_CK_SPRE_16bits) || \
  297. ((CLOCK) == RTC_WakeUpClock_CK_SPRE_17bits))
  298. #define IS_RTC_WAKEUP_COUNTER(COUNTER) ((COUNTER) <= 0xFFFF)
  299. /**
  300. * @}
  301. */
  302. /** @defgroup RTC_Time_Stamp_Edges_definitions
  303. * @{
  304. */
  305. #define RTC_TimeStampEdge_Rising ((uint32_t)0x00000000)
  306. #define RTC_TimeStampEdge_Falling ((uint32_t)0x00000008)
  307. #define IS_RTC_TIMESTAMP_EDGE(EDGE) (((EDGE) == RTC_TimeStampEdge_Rising) || \
  308. ((EDGE) == RTC_TimeStampEdge_Falling))
  309. /**
  310. * @}
  311. */
  312. /** @defgroup RTC_Output_selection_Definitions
  313. * @{
  314. */
  315. #define RTC_Output_Disable ((uint32_t)0x00000000)
  316. #define RTC_Output_AlarmA ((uint32_t)0x00200000)
  317. #define RTC_Output_WakeUp ((uint32_t)0x00600000)
  318. #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_Output_Disable) || \
  319. ((OUTPUT) == RTC_Output_AlarmA) || \
  320. ((OUTPUT) == RTC_Output_WakeUp))
  321. /**
  322. * @}
  323. */
  324. /** @defgroup RTC_Output_Polarity_Definitions
  325. * @{
  326. */
  327. #define RTC_OutputPolarity_High ((uint32_t)0x00000000)
  328. #define RTC_OutputPolarity_Low ((uint32_t)0x00100000)
  329. #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OutputPolarity_High) || \
  330. ((POL) == RTC_OutputPolarity_Low))
  331. /**
  332. * @}
  333. */
  334. /** @defgroup RTC_Calib_Output_selection_Definitions
  335. * @{
  336. */
  337. #define RTC_CalibOutput_512Hz ((uint32_t)0x00000000)
  338. #define RTC_CalibOutput_1Hz ((uint32_t)0x00080000)
  339. #define IS_RTC_CALIB_OUTPUT(OUTPUT) (((OUTPUT) == RTC_CalibOutput_512Hz) || \
  340. ((OUTPUT) == RTC_CalibOutput_1Hz))
  341. /**
  342. * @}
  343. */
  344. /** @defgroup RTC_Smooth_calib_period_Definitions
  345. * @{
  346. */
  347. #define RTC_SmoothCalibPeriod_32sec ((uint32_t)0x00000000) /*!< if RTCCLK = 32768 Hz, Smooth calibation
  348. period is 32s, else 2exp20 RTCCLK seconds */
  349. #define RTC_SmoothCalibPeriod_16sec ((uint32_t)0x00002000) /*!< if RTCCLK = 32768 Hz, Smooth calibation
  350. period is 16s, else 2exp19 RTCCLK seconds */
  351. #define RTC_SmoothCalibPeriod_8sec ((uint32_t)0x00004000) /*!< if RTCCLK = 32768 Hz, Smooth calibation
  352. period is 8s, else 2exp18 RTCCLK seconds */
  353. #define IS_RTC_SMOOTH_CALIB_PERIOD(PERIOD) (((PERIOD) == RTC_SmoothCalibPeriod_32sec) || \
  354. ((PERIOD) == RTC_SmoothCalibPeriod_16sec) || \
  355. ((PERIOD) == RTC_SmoothCalibPeriod_8sec))
  356. /**
  357. * @}
  358. */
  359. /** @defgroup RTC_Smooth_calib_Plus_pulses_Definitions
  360. * @{
  361. */
  362. #define RTC_SmoothCalibPlusPulses_Set ((uint32_t)0x00008000) /*!< The number of RTCCLK pulses added
  363. during a X -second window = Y - CALM[8:0].
  364. with Y = 512, 256, 128 when X = 32, 16, 8 */
  365. #define RTC_SmoothCalibPlusPulses_Reset ((uint32_t)0x00000000) /*!< The number of RTCCLK pulses subbstited
  366. during a 32-second window = CALM[8:0]. */
  367. #define IS_RTC_SMOOTH_CALIB_PLUS(PLUS) (((PLUS) == RTC_SmoothCalibPlusPulses_Set) || \
  368. ((PLUS) == RTC_SmoothCalibPlusPulses_Reset))
  369. /**
  370. * @}
  371. */
  372. /** @defgroup RTC_Smooth_calib_Minus_pulses_Definitions
  373. * @{
  374. */
  375. #define IS_RTC_SMOOTH_CALIB_MINUS(VALUE) ((VALUE) <= 0x000001FF)
  376. /**
  377. * @}
  378. */
  379. /** @defgroup RTC_DayLightSaving_Definitions
  380. * @{
  381. */
  382. #define RTC_DayLightSaving_SUB1H ((uint32_t)0x00020000)
  383. #define RTC_DayLightSaving_ADD1H ((uint32_t)0x00010000)
  384. #define IS_RTC_DAYLIGHT_SAVING(SAVING) (((SAVING) == RTC_DayLightSaving_SUB1H) || \
  385. ((SAVING) == RTC_DayLightSaving_ADD1H))
  386. #define RTC_StoreOperation_Reset ((uint32_t)0x00000000)
  387. #define RTC_StoreOperation_Set ((uint32_t)0x00040000)
  388. #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_StoreOperation_Reset) || \
  389. ((OPERATION) == RTC_StoreOperation_Set))
  390. /**
  391. * @}
  392. */
  393. /** @defgroup RTC_Tamper_Trigger_Definitions
  394. * @{
  395. */
  396. #define RTC_TamperTrigger_RisingEdge ((uint32_t)0x00000000)
  397. #define RTC_TamperTrigger_FallingEdge ((uint32_t)0x00000001)
  398. #define RTC_TamperTrigger_LowLevel ((uint32_t)0x00000000)
  399. #define RTC_TamperTrigger_HighLevel ((uint32_t)0x00000001)
  400. #define IS_RTC_TAMPER_TRIGGER(TRIGGER) (((TRIGGER) == RTC_TamperTrigger_RisingEdge) || \
  401. ((TRIGGER) == RTC_TamperTrigger_FallingEdge) || \
  402. ((TRIGGER) == RTC_TamperTrigger_LowLevel) || \
  403. ((TRIGGER) == RTC_TamperTrigger_HighLevel))
  404. /**
  405. * @}
  406. */
  407. /** @defgroup RTC_Tamper_Filter_Definitions
  408. * @{
  409. */
  410. #define RTC_TamperFilter_Disable ((uint32_t)0x00000000) /*!< Tamper filter is disabled */
  411. #define RTC_TamperFilter_2Sample ((uint32_t)0x00000800) /*!< Tamper is activated after 2
  412. consecutive samples at the active level */
  413. #define RTC_TamperFilter_4Sample ((uint32_t)0x00001000) /*!< Tamper is activated after 4
  414. consecutive samples at the active level */
  415. #define RTC_TamperFilter_8Sample ((uint32_t)0x00001800) /*!< Tamper is activated after 8
  416. consecutive samples at the active leve. */
  417. #define IS_RTC_TAMPER_FILTER(FILTER) (((FILTER) == RTC_TamperFilter_Disable) || \
  418. ((FILTER) == RTC_TamperFilter_2Sample) || \
  419. ((FILTER) == RTC_TamperFilter_4Sample) || \
  420. ((FILTER) == RTC_TamperFilter_8Sample))
  421. /**
  422. * @}
  423. */
  424. /** @defgroup RTC_Tamper_Sampling_Frequencies_Definitions
  425. * @{
  426. */
  427. #define RTC_TamperSamplingFreq_RTCCLK_Div32768 ((uint32_t)0x00000000) /*!< Each of the tamper inputs are sampled
  428. with a frequency = RTCCLK / 32768 */
  429. #define RTC_TamperSamplingFreq_RTCCLK_Div16384 ((uint32_t)0x00000100) /*!< Each of the tamper inputs are sampled
  430. with a frequency = RTCCLK / 16384 */
  431. #define RTC_TamperSamplingFreq_RTCCLK_Div8192 ((uint32_t)0x00000200) /*!< Each of the tamper inputs are sampled
  432. with a frequency = RTCCLK / 8192 */
  433. #define RTC_TamperSamplingFreq_RTCCLK_Div4096 ((uint32_t)0x00000300) /*!< Each of the tamper inputs are sampled
  434. with a frequency = RTCCLK / 4096 */
  435. #define RTC_TamperSamplingFreq_RTCCLK_Div2048 ((uint32_t)0x00000400) /*!< Each of the tamper inputs are sampled
  436. with a frequency = RTCCLK / 2048 */
  437. #define RTC_TamperSamplingFreq_RTCCLK_Div1024 ((uint32_t)0x00000500) /*!< Each of the tamper inputs are sampled
  438. with a frequency = RTCCLK / 1024 */
  439. #define RTC_TamperSamplingFreq_RTCCLK_Div512 ((uint32_t)0x00000600) /*!< Each of the tamper inputs are sampled
  440. with a frequency = RTCCLK / 512 */
  441. #define RTC_TamperSamplingFreq_RTCCLK_Div256 ((uint32_t)0x00000700) /*!< Each of the tamper inputs are sampled
  442. with a frequency = RTCCLK / 256 */
  443. #define IS_RTC_TAMPER_SAMPLING_FREQ(FREQ) (((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div32768) || \
  444. ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div16384) || \
  445. ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div8192) || \
  446. ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div4096) || \
  447. ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div2048) || \
  448. ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div1024) || \
  449. ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div512) || \
  450. ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div256))
  451. /**
  452. * @}
  453. */
  454. /** @defgroup RTC_Tamper_Pin_Precharge_Duration_Definitions
  455. * @{
  456. */
  457. #define RTC_TamperPrechargeDuration_1RTCCLK ((uint32_t)0x00000000) /*!< Tamper pins are pre-charged before
  458. sampling during 1 RTCCLK cycle */
  459. #define RTC_TamperPrechargeDuration_2RTCCLK ((uint32_t)0x00002000) /*!< Tamper pins are pre-charged before
  460. sampling during 2 RTCCLK cycles */
  461. #define RTC_TamperPrechargeDuration_4RTCCLK ((uint32_t)0x00004000) /*!< Tamper pins are pre-charged before
  462. sampling during 4 RTCCLK cycles */
  463. #define RTC_TamperPrechargeDuration_8RTCCLK ((uint32_t)0x00006000) /*!< Tamper pins are pre-charged before
  464. sampling during 8 RTCCLK cycles */
  465. #define IS_RTC_TAMPER_PRECHARGE_DURATION(DURATION) (((DURATION) == RTC_TamperPrechargeDuration_1RTCCLK) || \
  466. ((DURATION) == RTC_TamperPrechargeDuration_2RTCCLK) || \
  467. ((DURATION) == RTC_TamperPrechargeDuration_4RTCCLK) || \
  468. ((DURATION) == RTC_TamperPrechargeDuration_8RTCCLK))
  469. /**
  470. * @}
  471. */
  472. /** @defgroup RTC_Tamper_Pins_Definitions
  473. * @{
  474. */
  475. #define RTC_Tamper_1 RTC_TAFCR_TAMP1E /*!< Tamper detection enable for
  476. input tamper 1 */
  477. #define RTC_Tamper_2 RTC_TAFCR_TAMP2E /*!< Tamper detection enable for
  478. input tamper 2 */
  479. #define IS_RTC_TAMPER(TAMPER) ((((TAMPER) & (uint32_t)0xFFFFFFD6) == 0x00) && ((TAMPER) != (uint32_t)RESET))
  480. /**
  481. * @}
  482. */
  483. /** @defgroup RTC_Output_Type_ALARM_OUT
  484. * @{
  485. */
  486. #define RTC_OutputType_OpenDrain ((uint32_t)0x00000000)
  487. #define RTC_OutputType_PushPull ((uint32_t)0x00040000)
  488. #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OutputType_OpenDrain) || \
  489. ((TYPE) == RTC_OutputType_PushPull))
  490. /**
  491. * @}
  492. */
  493. /** @defgroup RTC_Add_1_Second_Parameter_Definitions
  494. * @{
  495. */
  496. #define RTC_ShiftAdd1S_Reset ((uint32_t)0x00000000)
  497. #define RTC_ShiftAdd1S_Set ((uint32_t)0x80000000)
  498. #define IS_RTC_SHIFT_ADD1S(SEL) (((SEL) == RTC_ShiftAdd1S_Reset) || \
  499. ((SEL) == RTC_ShiftAdd1S_Set))
  500. /**
  501. * @}
  502. */
  503. /** @defgroup RTC_Substract_Fraction_Of_Second_Value
  504. * @{
  505. */
  506. #define IS_RTC_SHIFT_SUBFS(FS) ((FS) <= 0x00007FFF)
  507. /**
  508. * @}
  509. */
  510. /** @defgroup RTC_Backup_Registers_Definitions
  511. * @{
  512. */
  513. #define RTC_BKP_DR0 ((uint32_t)0x00000000)
  514. #define RTC_BKP_DR1 ((uint32_t)0x00000001)
  515. #define RTC_BKP_DR2 ((uint32_t)0x00000002)
  516. #define RTC_BKP_DR3 ((uint32_t)0x00000003)
  517. #define RTC_BKP_DR4 ((uint32_t)0x00000004)
  518. #define IS_RTC_BKP(BKP) (((BKP) == RTC_BKP_DR0) || \
  519. ((BKP) == RTC_BKP_DR1) || \
  520. ((BKP) == RTC_BKP_DR2) || \
  521. ((BKP) == RTC_BKP_DR3) || \
  522. ((BKP) == RTC_BKP_DR4))
  523. /**
  524. * @}
  525. */
  526. /** @defgroup RTC_Input_parameter_format_definitions
  527. * @{
  528. */
  529. #define RTC_Format_BIN ((uint32_t)0x000000000)
  530. #define RTC_Format_BCD ((uint32_t)0x000000001)
  531. #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_Format_BIN) || ((FORMAT) == RTC_Format_BCD))
  532. /**
  533. * @}
  534. */
  535. /** @defgroup RTC_Flags_Definitions
  536. * @{
  537. */
  538. #define RTC_FLAG_RECALPF RTC_ISR_RECALPF
  539. #define RTC_FLAG_TAMP2F RTC_ISR_TAMP2F
  540. #define RTC_FLAG_TAMP1F RTC_ISR_TAMP1F
  541. #define RTC_FLAG_TSOVF RTC_ISR_TSOVF
  542. #define RTC_FLAG_TSF RTC_ISR_TSF
  543. #define RTC_FLAG_WUTF RTC_ISR_WUTF
  544. #define RTC_FLAG_ALRAF RTC_ISR_ALRAF
  545. #define RTC_FLAG_INITF RTC_ISR_INITF
  546. #define RTC_FLAG_RSF RTC_ISR_RSF
  547. #define RTC_FLAG_INITS RTC_ISR_INITS
  548. #define RTC_FLAG_SHPF RTC_ISR_SHPF
  549. #define RTC_FLAG_WUTWF RTC_ISR_WUTWF
  550. #define RTC_FLAG_ALRAWF RTC_ISR_ALRAWF
  551. #define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_TSOVF) || ((FLAG) == RTC_FLAG_TSF) || \
  552. ((FLAG) == RTC_FLAG_WUTF) || ((FLAG) == RTC_FLAG_ALRAWF) || \
  553. ((FLAG) == RTC_FLAG_ALRAF) || ((FLAG) == RTC_FLAG_INITF) || \
  554. ((FLAG) == RTC_FLAG_RSF) || ((FLAG) == RTC_FLAG_WUTWF) || \
  555. ((FLAG) == RTC_FLAG_TAMP1F) || ((FLAG) == RTC_FLAG_TAMP2F) || \
  556. ((FLAG) == RTC_FLAG_TAMP3F) || ((FLAG) == RTC_FLAG_RECALPF) || \
  557. ((FLAG) == RTC_FLAG_SHPF))
  558. #define IS_RTC_CLEAR_FLAG(FLAG) (((FLAG) != (uint32_t)RESET) && (((FLAG) & 0xFFFF02DF) == (uint32_t)RESET))
  559. /**
  560. * @}
  561. */
  562. /** @defgroup RTC_Interrupts_Definitions
  563. * @{
  564. */
  565. #define RTC_IT_TS ((uint32_t)0x00008000)
  566. #define RTC_IT_WUT ((uint32_t)0x00004000)
  567. #define RTC_IT_ALRA ((uint32_t)0x00001000)
  568. #define RTC_IT_TAMP ((uint32_t)0x00000004) /* Used only to Enable the Tamper Interrupt */
  569. #define RTC_IT_TAMP1 ((uint32_t)0x00020000)
  570. #define RTC_IT_TAMP2 ((uint32_t)0x00040000)
  571. #define IS_RTC_CONFIG_IT(IT) (((IT) != (uint32_t)RESET) && (((IT) & 0xFFFF2FFB) == (uint32_t)RESET))
  572. #define IS_RTC_GET_IT(IT) (((IT) == RTC_IT_TS) || ((IT) == RTC_IT_ALRA) || \
  573. ((IT) == RTC_IT_TAMP1) || ((IT) == RTC_IT_WUT) || \
  574. ((IT) == RTC_IT_TAMP2) )
  575. #define IS_RTC_CLEAR_IT(IT) (((IT) != (uint32_t)RESET) && (((IT) & 0xFFF12FFF) == (uint32_t)RESET))
  576. /**
  577. * @}
  578. */
  579. /**
  580. * @}
  581. */
  582. /* Exported macro ------------------------------------------------------------*/
  583. /* Exported functions ------------------------------------------------------- */
  584. /* Function used to set the RTC configuration to the default reset state *****/
  585. ErrorStatus RTC_DeInit(void);
  586. /* Initialization and Configuration functions *********************************/
  587. ErrorStatus RTC_Init(RTC_InitTypeDef* RTC_InitStruct);
  588. void RTC_StructInit(RTC_InitTypeDef* RTC_InitStruct);
  589. void RTC_WriteProtectionCmd(FunctionalState NewState);
  590. ErrorStatus RTC_EnterInitMode(void);
  591. void RTC_ExitInitMode(void);
  592. ErrorStatus RTC_WaitForSynchro(void);
  593. ErrorStatus RTC_RefClockCmd(FunctionalState NewState);
  594. void RTC_BypassShadowCmd(FunctionalState NewState);
  595. /* Time and Date configuration functions **************************************/
  596. ErrorStatus RTC_SetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct);
  597. void RTC_TimeStructInit(RTC_TimeTypeDef* RTC_TimeStruct);
  598. void RTC_GetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct);
  599. uint32_t RTC_GetSubSecond(void);
  600. ErrorStatus RTC_SetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct);
  601. void RTC_DateStructInit(RTC_DateTypeDef* RTC_DateStruct);
  602. void RTC_GetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct);
  603. /* Alarms (Alarm A) configuration functions **********************************/
  604. void RTC_SetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct);
  605. void RTC_AlarmStructInit(RTC_AlarmTypeDef* RTC_AlarmStruct);
  606. void RTC_GetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct);
  607. ErrorStatus RTC_AlarmCmd(uint32_t RTC_Alarm, FunctionalState NewState);
  608. void RTC_AlarmSubSecondConfig(uint32_t RTC_Alarm, uint32_t RTC_AlarmSubSecondValue, uint8_t RTC_AlarmSubSecondMask);
  609. uint32_t RTC_GetAlarmSubSecond(uint32_t RTC_Alarm);
  610. /* WakeUp Timer configuration functions ***************************************/
  611. void RTC_WakeUpClockConfig(uint32_t RTC_WakeUpClock);
  612. void RTC_SetWakeUpCounter(uint32_t RTC_WakeUpCounter);
  613. uint32_t RTC_GetWakeUpCounter(void);
  614. ErrorStatus RTC_WakeUpCmd(FunctionalState NewState);
  615. /* Daylight Saving configuration functions ************************************/
  616. void RTC_DayLightSavingConfig(uint32_t RTC_DayLightSaving, uint32_t RTC_StoreOperation);
  617. uint32_t RTC_GetStoreOperation(void);
  618. /* Output pin Configuration function ******************************************/
  619. void RTC_OutputConfig(uint32_t RTC_Output, uint32_t RTC_OutputPolarity);
  620. /* Digital Calibration configuration functions ********************************/
  621. void RTC_CalibOutputCmd(FunctionalState NewState);
  622. void RTC_CalibOutputConfig(uint32_t RTC_CalibOutput);
  623. ErrorStatus RTC_SmoothCalibConfig(uint32_t RTC_SmoothCalibPeriod,
  624. uint32_t RTC_SmoothCalibPlusPulses,
  625. uint32_t RTC_SmouthCalibMinusPulsesValue);
  626. /* TimeStamp configuration functions ******************************************/
  627. void RTC_TimeStampCmd(uint32_t RTC_TimeStampEdge, FunctionalState NewState);
  628. void RTC_GetTimeStamp(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_StampTimeStruct, RTC_DateTypeDef* RTC_StampDateStruct);
  629. uint32_t RTC_GetTimeStampSubSecond(void);
  630. /* Tampers configuration functions ********************************************/
  631. void RTC_TamperTriggerConfig(uint32_t RTC_Tamper, uint32_t RTC_TamperTrigger);
  632. void RTC_TamperCmd(uint32_t RTC_Tamper, FunctionalState NewState);
  633. void RTC_TamperFilterConfig(uint32_t RTC_TamperFilter);
  634. void RTC_TamperSamplingFreqConfig(uint32_t RTC_TamperSamplingFreq);
  635. void RTC_TamperPinsPrechargeDuration(uint32_t RTC_TamperPrechargeDuration);
  636. void RTC_TimeStampOnTamperDetectionCmd(FunctionalState NewState);
  637. void RTC_TamperPullUpCmd(FunctionalState NewState);
  638. /* Backup Data Registers configuration functions ******************************/
  639. void RTC_WriteBackupRegister(uint32_t RTC_BKP_DR, uint32_t Data);
  640. uint32_t RTC_ReadBackupRegister(uint32_t RTC_BKP_DR);
  641. /* Output Type Config configuration functions *********************************/
  642. void RTC_OutputTypeConfig(uint32_t RTC_OutputType);
  643. /* RTC_Shift_control_synchonisation_functions *********************************/
  644. ErrorStatus RTC_SynchroShiftConfig(uint32_t RTC_ShiftAdd1S, uint32_t RTC_ShiftSubFS);
  645. /* Interrupts and flags management functions **********************************/
  646. void RTC_ITConfig(uint32_t RTC_IT, FunctionalState NewState);
  647. FlagStatus RTC_GetFlagStatus(uint32_t RTC_FLAG);
  648. void RTC_ClearFlag(uint32_t RTC_FLAG);
  649. ITStatus RTC_GetITStatus(uint32_t RTC_IT);
  650. void RTC_ClearITPendingBit(uint32_t RTC_IT);
  651. #ifdef __cplusplus
  652. }
  653. #endif
  654. #endif /*__HK32F0XX_RTC_H */
  655. /**
  656. * @}
  657. */
  658. /**
  659. * @}
  660. */