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