1 /*!
2  * @file        apm32f4xx_rtc.h
3  *
4  * @brief       This file contains all the functions prototypes for the RTC firmware library.
5  *
6  * @version     V1.0.2
7  *
8  * @date        2022-06-23
9  *
10  * @attention
11  *
12  *  Copyright (C) 2021-2022 Geehy Semiconductor
13  *
14  *  You may not use this file except in compliance with the
15  *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
16  *
17  *  The program is only for reference, which is distributed in the hope
18  *  that it will be usefull and instructional for customers to develop
19  *  their software. Unless required by applicable law or agreed to in
20  *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
21  *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
22  *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
23  *  and limitations under the License.
24  */
25 
26 /* Define to prevent recursive inclusion */
27 #ifndef __APM32F4XX_RTC_H
28 #define __APM32F4XX_RTC_H
29 
30 #ifdef __cplusplus
31   extern "C" {
32 #endif
33 
34 /* Includes */
35 #include "apm32f4xx.h"
36 
37 /** @addtogroup APM32F4xx_StdPeriphDriver
38   @{
39 */
40 
41 /** @addtogroup RTC_Driver
42   @{
43 */
44 
45 /** @defgroup RTC_Enumerations
46   @{
47 */
48 
49 /**
50  * @brief RTC Hour Formats
51  */
52 typedef enum
53 {
54     RTC_HOURFORMAT_24,  /*!< 24 hour/day format */
55     RTC_HOURFORMAT_12   /*!< AM/PM hour format */
56 } RTC_HOUR_FORMAT_T;
57 
58 /**
59  * @brief RTC Input parameter format
60  */
61 typedef enum
62 {
63     RTC_FORMAT_BIN, /*!< Format in BIN */
64     RTC_FORMAT_BCD  /*!< Format in BCD */
65 } RTC_FORMAT_T;
66 
67 /**
68  * @brief RTC AM PM
69  */
70 typedef enum
71 {
72     RTC_H12_AM, /*!< Set RTC time to AM */
73     RTC_H12_PM  /*!< Set RTC time to PM */
74 } RTC_H12_T;
75 
76 /**
77  * @brief RTC MONTH
78  */
79 typedef enum
80 {
81     RTC_MONTH_JANUARY   = 0x01, /*!< January */
82     RTC_MONTH_FEBRUARY  = 0x02, /*!< February */
83     RTC_MONTH_MARCH     = 0x03, /*!< March */
84     RTC_MONTH_APRIL     = 0x04, /*!< April */
85     RTC_MONTH_MAY       = 0x05, /*!< May */
86     RTC_MONTH_JUNE      = 0x06, /*!< June */
87     RTC_MONTH_JULY      = 0x07, /*!< July */
88     RTC_MONTH_AUGUST    = 0x08, /*!< August */
89     RTC_MONTH_SEPTEMBER = 0x09, /*!< September */
90     RTC_MONTH_OCTOBER   = 0x10, /*!< October */
91     RTC_MONTH_NOVEMBER  = 0x11, /*!< November */
92     RTC_MONTH_DECEMBER  = 0x12  /*!< December */
93 } RTC_MONTH_T;
94 
95 /**
96  * @brief RTC WEEKDAY
97  */
98 typedef enum
99 {
100     RTC_WEEKDAY_MONDAY    = 0x01,   /*!< Set Monday as the weekend */
101     RTC_WEEKDAY_TUESDAY   = 0x02,   /*!< Set Tuesday as the weekend */
102     RTC_WEEKDAY_WEDNESDAY = 0x03,   /*!< Set Wednesday as the weekend */
103     RTC_WEEKDAY_THURSDAY  = 0x04,   /*!< Set Thursday as the weekend */
104     RTC_WEEKDAY_FRIDAY    = 0x05,   /*!< Set Friday as the weekend */
105     RTC_WEEKDAY_SATURDAY  = 0x06,   /*!< Set Saturday as the weekend */
106     RTC_WEEKDAY_SUNDAY    = 0x07    /*!< Set sunday as the weekend */
107 } RTC_WEEKDAY_T;
108 
109 /**
110  * @brief RTC AlarmDateWeekDay
111  */
112 typedef enum
113 {
114     RTC_WEEKDAY_SEL_DATE,       /*!< Select DAYU to represent the date */
115     RTC_WEEKDAY_SEL_WEEKDAY     /*!< Select DAYU to represent the weekday */
116 } RTC_WEEKDAY_SEL_T;
117 
118 /**
119  * @brief  RTC AlarmMask
120  */
121 typedef enum
122 {
123     RTC_MASK_NONE        = (uint32_t)0x00000000,    /*!< No mask */
124     RTC_MASK_DATEWEEK    = (int32_t)0x80000000,     /*!< Dateweek mask */
125     RTC_MASK_HOURS       = (uint32_t)0x00800000,    /*!< Hours mask */
126     RTC_MASK_MINUTES     = (uint32_t)0x00008000,    /*!< Minutes mask */
127     RTC_MASK_SECONDS     = (uint32_t)0x00000080,    /*!< Seconds mask */
128     RTC_MASK_ALL         = (int32_t)0x80808080      /*!< All mask  */
129 } RTC_MASK_T;
130 
131 /**
132  * @brief RTC ALARMA ALARMB
133  */
134 typedef enum
135 {
136     RTC_ALARM_A = 0x0100,   /*!< Select Alarm A */
137     RTC_ALARM_B = 0x0200    /*!< Select Alarm B */
138 } RTC_ALARM_T;
139 
140 /**
141  * @brief RTC_ALARM_SS description
142  */
143 typedef enum
144 {
145     RTC_ALARM_SUBSEC_MASK_ALL ,   /*!< All Alarm SUBSEC fields are masked */
146     RTC_ALARM_SUBSEC_MASK_14_1,   /*!< Mask SUBSEC[14:1] and Alarm comparison is SUBSEC[0] */
147     RTC_ALARM_SUBSEC_MASK_14_2,   /*!< Mask SUBSEC[14:2] and Alarm comparison is SUBSEC[1:0] */
148     RTC_ALARM_SUBSEC_MASK_14_3,   /*!< Mask SUBSEC[14:3] and Alarm comparison is SUBSEC[2:0] */
149     RTC_ALARM_SUBSEC_MASK_14_4,   /*!< Mask SUBSEC[14:4] and Alarm comparison is SUBSEC[3:0] */
150     RTC_ALARM_SUBSEC_MASK_14_5,   /*!< Mask SUBSEC[14:5] and Alarm comparison is SUBSEC[4:0] */
151     RTC_ALARM_SUBSEC_MASK_14_6,   /*!< Mask SUBSEC[14:6] and Alarm comparison is SUBSEC[5:0] */
152     RTC_ALARM_SUBSEC_MASK_14_7,   /*!< Mask SUBSEC[14:7] and Alarm comparison is SUBSEC[6:0] */
153     RTC_ALARM_SUBSEC_MASK_14_8,   /*!< Mask SUBSEC[14:8] and Alarm comparison is SUBSEC[7:0] */
154     RTC_ALARM_SUBSEC_MASK_14_9,   /*!< Mask SUBSEC[14:9] and Alarm comparison is SUBSEC[8:0] */
155     RTC_ALARM_SUBSEC_MASK_14_10,  /*!< Mask SUBSEC[14:10] and Alarm comparison is SUBSEC[9:0] */
156     RTC_ALARM_SUBSEC_MASK_14_11,  /*!< Mask SUBSEC[14:11] and Alarm comparison is SUBSEC[10:0] */
157     RTC_ALARM_SUBSEC_MASK_14_12,  /*!< Mask SUBSEC[14:12] and Alarm comparison is SUBSEC[11:0] */
158     RTC_ALARM_SUBSEC_MASK_14_13,  /*!< Mask SUBSEC[14:13] and Alarm comparison is SUBSEC[12:0] */
159     RTC_ALARM_SUBSEC_MASK_14,     /*!< Mask SUBSEC[14] and Alarm comparison is SUBSEC[13:0] */
160     RTC_ALARM_SUBSEC_MASK_NONE    /*!< Alarm comparison is all the SUBSEC bit */
161 } RTC_ALARM_SUBSEC_MASK_T;
162 
163 /**
164  * @brief RTC Wakeup clock select
165  */
166 typedef enum
167 {
168     RTC_WAKEUP_CLOCK_RTC_DIV16   = 0x00, /*!<  Wakeup Clock select to RTC/16 */
169     RTC_WAKEUP_CLOCK_RTC_DIV8    = 0x01, /*!<  Wakeup Clock select to RTC/8 */
170     RTC_WAKEUP_CLOCK_RTC_DIV4    = 0x02, /*!<  Wakeup Clock select to RTC/4 */
171     RTC_WAKEUP_CLOCK_RTC_DIV2    = 0x03, /*!<  Wakeup Clock select to RTC/2 */
172     RTC_WAKEUP_CLOCK_CK_SPRE_16B = 0x04, /*!<  Wakeup Clock select to clk_spre */
173     RTC_WAKEUP_CLOCK_CK_SPRE_17B = 0x06  /*!<  Wakeup Clock select to clk_spre */
174 } RTC_WAKEUP_CLOCK_T;
175 
176 /**
177  * @brief RTC Time Stamp Edges
178  */
179 typedef enum
180 {
181     RTC_TIMESTAMP_EDGE_RISING,  /*!< Rising edge generates a timestamp event */
182     RTC_TIMESTAMP_EDGE_FALLING  /*!< Falling edge generates a timestamp event */
183 } RTC_TIMESTAMP_EDGE_T;
184 
185 /**
186  * @brief RTC Output selection
187  */
188 typedef enum
189 {
190     RTC_OUT_SEL_DISABLE,    /*!< Disable RTC output */
191     RTC_OUT_SEL_ALARM_A,    /*!< Select alarm A as RTC output */
192     RTC_OUT_SEL_ALARM_B,    /*!< Select alarm B as RTC output */
193     RTC_OUT_SEL_WAKEUP      /*!< Select wake up as RTC output */
194 } RTC_OUT_SEL_T;
195 
196 /**
197  * @brief RTC Output Polarity
198  */
199 typedef enum
200 {
201     RTC_OUT_POLARITY_HIGH,  /*!< The output polarity is high */
202     RTC_OUT_POLARITY_LOW    /*!< The output polarity is low */
203 } RTC_OUT_POLARITY_T;
204 
205 /**
206  * @brief RTC Digital Calibration sign
207  */
208 typedef enum
209 {
210     RTC_CALIB_SIGN_POSITIVE,    /*!< The Calibration sign is positive */
211     RTC_CALIB_SIGN_NEGATIVE     /*!< The Calibration sign is negative */
212 } RTC_CALIB_SIGN_T;
213 
214 /**
215  * @brief RTC Calibration Output selection
216  */
217 typedef enum
218 {
219     RTC_CALIB_OUTPUT_512HZ, /*!< Calibration output is 512 Hz */
220     RTC_CALIB_OUTPUT_1HZ    /*!< Calibration output is 1 Hz */
221 } RTC_CALIB_OUTPUT_T;
222 
223 /**
224  * @brief RTC Smooth Calibration period
225  */
226 typedef enum
227 {
228     RTC_SCP_32SEC, /*!< if RTCCLK is 32768 Hz, Smooth calibration period will be 32s,
229                         else 2exp20 RTCCLK seconds */
230     RTC_SCP_16SEC, /*!< if RTCCLK is 32768 Hz, Smooth calibration period will be 16s,
231                         else 2exp19 RTCCLK seconds */
232     RTC_SCP_8SEC   /*!< if RTCCLK is 32768 Hz, Smooth calibration period will be 8s,
233                         else 2exp18 RTCCLK seconds */
234 } RTC_SCP_T;
235 
236 /**
237  * @brief  RTC Smooth Calibration Plus pulses
238  */
239 typedef enum
240 {
241     RTC_SCPP_RESET, /*!< Add one RTCCLK puls every 2**11 pulses */
242     RTC_SCPP_SET    /*!< No RTCCLK pulses are added */
243 } RTC_SCPP_T;
244 
245 /**
246  * @brief RTC DayLight Saving
247  */
248 typedef enum
249 {
250     RTC_DLS_SUB_1H, /*!< Winter time change */
251     RTC_DLS_ADD_1H  /*!< Summer time change */
252 } RTC_DLS_T;
253 
254 /**
255  * @brief RTC Store Operation to Backup bit
256  */
257 typedef enum
258 {
259     RTC_BACKUP_RESET,   /*!< Reset backup value */
260     RTC_BACKUP_SET      /*!< Set backup value */
261 } RTC_BACKUP_T;
262 
263 /**
264  * @brief RTC Tamper Trigger
265  */
266 typedef enum
267 {
268     RTC_TAMPER_TRIGGER_EDGE_RISING  = 0,    /*!< Rising Edge of the tamper pin causes tamper event */
269     RTC_TAMPER_TRIGGER_EDGE_FALLING = 1,    /*!< Falling Edge of the tamper pin causes tamper event */
270     RTC_TAMPER_TRIGGER_LEVEL_LOW    = 0,    /*!< Low Level of the tamper pin causes tamper event */
271     RTC_TAMPER_TRIGGER_LEVEL_HIGH   = 1     /*!< High Level of the tamper pin causes tamper event */
272 } RTC_TAMPER_TRIGGER_T;
273 
274 /**
275  * @brief Tampers Filter
276  */
277 typedef enum
278 {
279     RTC_TAMPER_FILTER_DISABLE,  /*!< Tamper filter is disabled */
280     RTC_TAMPER_FILTER_2SAMPLE,  /*!< Tamper is activated after 2 consecutive samples at the active level */
281     RTC_TAMPER_FILTER_4SAMPLE,  /*!< Tamper is activated after 4 consecutive samples at the active level */
282     RTC_TAMPER_FILTER_8SAMPLE   /*!< Tamper is activated after 8 consecutive samples at the active level */
283 } RTC_TAMPER_FILTER_T;
284 
285 /**
286  * @brief Tampers Sampling Frequency
287  */
288 typedef enum
289 {
290     RTC_TSF_DIV_32768, /*!< Tampers Sampling Frequency = RTC_CLK / 32768 */
291     RTC_TSF_DIV_16384, /*!< Tampers Sampling Frequency = RTC_CLK / 16384 */
292     RTC_TSF_DIV_8192,  /*!< Tampers Sampling Frequency = RTC_CLK / 8192 */
293     RTC_TSF_DIV_4096,  /*!< Tampers Sampling Frequency = RTC_CLK / 4096 */
294     RTC_TSF_DIV_2048,  /*!< Tampers Sampling Frequency = RTC_CLK / 2048 */
295     RTC_TSF_DIV_1024,  /*!< Tampers Sampling Frequency = RTC_CLK / 1024 */
296     RTC_TSF_DIV_512,   /*!< Tampers Sampling Frequency = RTC_CLK / 512 */
297     RTC_TSF_DIV_256    /*!< Tampers Sampling Frequency = RTC_CLK / 256 */
298 } RTC_TSF_DIV_T;
299 
300 /**
301  * @brief Tamper Precharge Duration
302  */
303 typedef enum
304 {
305     RTC_TPD_RTCCLK_1, /*!< Duration is 1 RTCCLK cycle */
306     RTC_TPD_RTCCLK_2, /*!< Duration is 2 RTCCLK cycle */
307     RTC_TPD_RTCCLK_4, /*!< Duration is 4 RTCCLK cycle */
308     RTC_TPD_RTCCLK_8  /*!< Duration is 8 RTCCLK cycle */
309 } RTC_TPD_RTCCLK_T;
310 
311 /**
312  * @brief RTC Tamper Pin Selection
313  */
314 typedef enum
315 {
316     RTC_TAMPER_PIN_AF1, /*!< RTC_TAMP1 is mapped to PC13 */
317     RTC_TAMPER_PIN_AF2  /*!< RTC_TAMP1 is mapped to PI8 */
318 } RTC_TAMPER_PIN_T;
319 
320 /**
321  * @brief RTC TimeStamp Pin Selection
322  */
323 typedef enum
324 {
325     RTC_TIMESTAMP_PIN_AF1, /*!< TimeStamp Pin is mapped to PC13 */
326     RTC_TIMESTAMP_PIN_AF2  /*!< TimeStamp Pin is mapped to PI8 */
327 } RTC_TIMESTAMP_PIN_T;
328 
329 /**
330  * @brief RTC Output Type ALARM OUT
331  */
332 typedef enum
333 {
334     RTC_OUTPUT_OD, /*!< RTC_ALARM output Open-drain */
335     RTC_OUTPUT_PP  /*!< RTC_ALARM output Push-pull */
336 } RTC_OUTPUT_T;
337 
338 /**
339  * @brief RTC Add 1 Second Parameter
340  */
341 typedef enum
342 {
343     RTC_SHIFT_ADD1S_RESET,  /*!< No effect */
344     RTC_SHIFT_ADD1S_SET     /*!< Add one second to the clock calendar */
345 } RTC_SHIFT_ADD1S_T;
346 
347 /**
348  * @brief RTC_Backup register
349  */
350 typedef enum
351 {
352     RTC_BAKP_REG_0,  /*!< Backup register 0 */
353     RTC_BAKP_REG_1,  /*!< Backup register 1 */
354     RTC_BAKP_REG_2,  /*!< Backup register 2 */
355     RTC_BAKP_REG_3,  /*!< Backup register 3 */
356     RTC_BAKP_REG_4,  /*!< Backup register 4 */
357     RTC_BAKP_REG_5,  /*!< Backup register 5 */
358     RTC_BAKP_REG_6,  /*!< Backup register 6 */
359     RTC_BAKP_REG_7,  /*!< Backup register 7 */
360     RTC_BAKP_REG_8,  /*!< Backup register 8 */
361     RTC_BAKP_REG_9,  /*!< Backup register 9 */
362     RTC_BAKP_REG_10, /*!< Backup register 10 */
363     RTC_BAKP_REG_11, /*!< Backup register 11 */
364     RTC_BAKP_REG_12, /*!< Backup register 12 */
365     RTC_BAKP_REG_13, /*!< Backup register 13 */
366     RTC_BAKP_REG_14, /*!< Backup register 14 */
367     RTC_BAKP_REG_15, /*!< Backup register 15 */
368     RTC_BAKP_REG_16, /*!< Backup register 16 */
369     RTC_BAKP_REG_17, /*!< Backup register 17 */
370     RTC_BAKP_REG_18, /*!< Backup register 18 */
371     RTC_BAKP_REG_19  /*!< Backup register 19 */
372 } RTC_BAKP_REG_T;
373 
374 /**
375  * @brief RTC flag
376  */
377 typedef enum
378 {
379     RTC_FLAG_AAWF  = BIT0,  /*!< Alarm A Write Flag */
380     RTC_FLAG_ABWF  = BIT1,  /*!< Alarm B Write Flag */
381     RTC_FLAG_WTWF  = BIT2,  /*!< Wakeup Timer Write Flag */
382     RTC_FLAG_SOPF  = BIT3,  /*!< Shift Operation Pending Flag */
383     RTC_FLAG_ISF   = BIT4,  /*!< Initialization State Flag */
384     RTC_FLAG_RSF   = BIT5,  /*!< Registers Synchronization Flag */
385     RTC_FLAG_INTF  = BIT6,  /*!< Register Initialization Flag */
386     RTC_FLAG_ALRAF = BIT8,  /*!< Alarm A Match Flag */
387     RTC_FLAG_ALRBF = BIT9,  /*!< Alarm B Match Flag */
388     RTC_FLAG_WTF   = BIT10, /*!< Wakeup Timer Flag */
389     RTC_FLAG_TSF   = BIT11, /*!< Time Stamp Flag */
390     RTC_FLAG_TSOF  = BIT12, /*!< Time Stamp Overflow Flag */
391     RTC_FLAG_TP1F  = BIT13, /*!< Tamper 1 event Detection Flag */
392     RTC_FLAG_TP2F  = BIT14, /*!< Tamper 2 event Detection Flag */
393     RTC_FLAG_RPF   = BIT16  /*!< Recalibration Pending Flag */
394 } RTC_FLAG_T;
395 
396 /**
397  * @brief RTC Interrupts  Flag
398  */
399 typedef enum
400 {
401     RTC_INT_FLAG_ALRA  = (uint32_t)0x00001000, /*!< Alarm A interrupt flag */
402     RTC_INT_FLAG_ALRB  = (uint32_t)0x00002000, /*!< Alarm B interrupt flag */
403     RTC_INT_FLAG_WT    = (uint32_t)0x00004000, /*!< Time Stamp interrupt flag */
404     RTC_INT_FLAG_TS    = (uint32_t)0x00008000, /*!< WakeUp Timer interrupt flag */
405     RTC_INT_FLAG_TAMP1 = (uint32_t)0x00020001, /*!< Tamper1 event interrupt flag */
406     RTC_INT_FLAG_TAMP2 = (uint32_t)0x00040001  /*!< Tamper2 event interrupt flag */
407 } RTC_INT_FLAG_T;
408 
409 /**
410  * @brief RTC Interrupts
411  */
412 typedef enum
413 {
414     RTC_INT_ALRA = BIT12, /*!< Alarm A interrupt */
415     RTC_INT_ALRB = BIT13, /*!< Alarm B interrupt */
416     RTC_INT_WT   = BIT14, /*!< WakeUp Timer interrupt */
417     RTC_INT_TS   = BIT15, /*!< Time Stamp interrupt */
418     RTC_INT_TAMP = BIT2   /*!< Tamper Interrupt in TACFG register */
419 } RTC_INT_T;
420 
421 /**
422  * @brief Selected RTC Tamper Pin
423  */
424 typedef enum
425 {
426     RTC_TAMPER_1,   /*!< Select Tamper 1 */
427     RTC_TAMPER_2    /*!< Select Tamper 2 */
428 } RTC_TAMPER_T;
429 
430 /**@} end of group RTC_Enumerations*/
431 
432 /** @addtogroup RTC_Structure Data Structure
433   @{
434 */
435 
436 /**
437  * @brief  RTC Init structures definition
438  */
439 typedef struct
440 {
441     RTC_HOUR_FORMAT_T format;       /*!< RTC hour formats selection */
442     uint32_t          asynchPrediv; /*!< Asynchronous prescaler coefficient setting */
443     uint32_t          synchPrediv;  /*!< Synchronous prescaler coefficient setting */
444 } RTC_Config_T;
445 
446 /**
447   * @brief  RTC Time structure definition
448   */
449 typedef struct
450 {
451     uint8_t   hours;    /*!< Set hours of RTC time */
452     uint8_t   minutes;  /*!< Set minutes of RTC time */
453     uint8_t   seconds;  /*!< Set seconds of RTC time */
454     RTC_H12_T h12;      /*!< Set RTC time to AM or PM */
455 } RTC_TimeConfig_T;
456 
457 /**
458   * @brief  RTC Date structure definition
459   */
460 typedef struct
461 {
462     RTC_WEEKDAY_T weekday;  /*!< Set weekday of RTC date */
463     RTC_MONTH_T   month;    /*!< Set month of RTC date */
464     uint8_t       date;     /*!< Set date of RTC date */
465     uint8_t       year;     /*!< Set year of RTC date */
466 } RTC_DateConfig_T;
467 
468 /**
469   * @brief  RTC ALRMA structure definition
470   */
471 typedef struct
472 {
473     RTC_TimeConfig_T  time;                 /*!< Set RTC time */
474     uint32_t          alarmMask;            /*!< Set alarm mask */
475     RTC_WEEKDAY_SEL_T alarmDateWeekDaySel;  /*!< Set weekday's DAYU of alarm date */
476     uint8_t           alarmDateWeekDay;     /*!< Set weekday of alarm date */
477 } RTC_AlarmConfig_T;
478 
479 /**@} end of group RTC_Structure*/
480 
481 /** @addtogroup RTC_Functions
482   @{
483 */
484 
485 /* RTC reset */
486 uint8_t RTC_Reset(void);
487 
488 /* Initialization and Configuration */
489 uint8_t RTC_Config(RTC_Config_T* rtcConfig);
490 void RTC_ConfigStructInit(RTC_Config_T* rtcConfig);
491 void RTC_EnableWriteProtection(void);
492 void RTC_DisableWriteProtection(void);
493 uint8_t RTC_EnableInit(void);
494 void RTC_DisableInit(void);
495 uint8_t RTC_WaitForSynchro(void);
496 uint8_t RTC_EnableRefClock(void);
497 uint8_t RTC_DisableRefClock(void);
498 void RTC_EnableBypassShadow(void);
499 void RTC_DisableBypassShadow(void);
500 
501 /* Time */
502 uint8_t RTC_ConfigTime(RTC_FORMAT_T format, RTC_TimeConfig_T* timeConfig);
503 void RTC_ConfigTimeStructInit(RTC_TimeConfig_T* timeConfig);
504 void RTC_ReadTime(RTC_FORMAT_T format, RTC_TimeConfig_T* time);
505 uint32_t RTC_ReadSubSecond(void);
506 
507 /* Date */
508 uint8_t RTC_ConfigDate(RTC_FORMAT_T format, RTC_DateConfig_T* dateConfig);
509 void RTC_ConfigDateStructInit(RTC_DateConfig_T* dateConfig);
510 void RTC_ReadDate(RTC_FORMAT_T format, RTC_DateConfig_T* date);
511 
512 /* Alarms (Alarm A and Alarm B)*/
513 void RTC_ConfigAlarm(RTC_FORMAT_T format, RTC_ALARM_T alarm, RTC_AlarmConfig_T* alarmConfig);
514 void RTC_ConfigAlarmStructInit(RTC_AlarmConfig_T* alarmConfig);
515 void RTC_ReadAlarm(RTC_FORMAT_T format, RTC_ALARM_T alarm, RTC_AlarmConfig_T* alarmConfig);
516 void RTC_EnableAlarmA(void);
517 uint8_t RTC_DisableAlarmA(void);
518 void RTC_EnableAlarmB(void);
519 uint8_t RTC_DisableAlarmB(void);
520 void RTC_ConfigAlarmSubSecond(RTC_ALARM_T alarm, uint32_t val, RTC_ALARM_SUBSEC_MASK_T mask);
521 uint16_t RTC_ReadAlarmSubSecond(RTC_ALARM_T alarm);
522 
523 /* WakeUp Timer */
524 void RTC_ConfigWakeUpClock(RTC_WAKEUP_CLOCK_T wakeUpClock);
525 void RTC_ConfigWakeUpValue(uint16_t wakeUpValue);
526 uint16_t RTC_ReadWakeUpValue(void);
527 void RTC_EnableWakeUp(void);
528 uint8_t RTC_DisableWakeUp(void);
529 
530 /* Daylight Saving */
531 void RTC_ConfigDayLightSaving(RTC_DLS_T saving, RTC_BACKUP_T bit);
532 uint8_t RTC_ReadStoreOperation(void);
533 
534 /* Alarm Output */
535 void RTC_ConfigOutput(RTC_OUT_SEL_T outputSel, RTC_OUT_POLARITY_T polarity);
536 
537 /* Coarse Digital Calibration */
538 uint8_t RTC_ConfigCoarseCalib(RTC_CALIB_SIGN_T calibSign, uint32_t value);
539 uint8_t RTC_EnableCoarseCalib(void);
540 uint8_t RTC_DisableCoarseCalib(void);
541 
542 /* Calibration Output */
543 void RTC_EnableCalibOutput(void);
544 void RTC_DisableCalibOutput(void);
545 void RTC_ConfigCalibOutput(RTC_CALIB_OUTPUT_T calib);
546 
547 /* Smooth Digital Calibration */
548 uint8_t RTC_ConfigSmoothCalib(RTC_SCP_T period, RTC_SCPP_T calibPulse, uint16_t value);
549 
550 /* TimeStamp */
551 void RTC_EnableTimeStamp(RTC_TIMESTAMP_EDGE_T edge);
552 void RTC_DisableTimeStamp(void);
553 void RTC_ReadTimeDate(RTC_FORMAT_T format, RTC_TimeConfig_T* time, RTC_DateConfig_T* date);
554 uint16_t RTC_ReadTimeStampSubSecond(void);
555 
556 /* Tamper */
557 void RTC_ConfigTamperTrigger(RTC_TAMPER_T tamper, RTC_TAMPER_TRIGGER_T trigger);
558 void RTC_EnableTamper(RTC_TAMPER_T tamper);
559 void RTC_DisableTamper(RTC_TAMPER_T tamper);
560 void RTC_ConfigFilter(RTC_TAMPER_FILTER_T filter);
561 void RTC_ConfigSamplingFreq(RTC_TSF_DIV_T freq);
562 void RTC_PinsPrechargeDuration(RTC_TPD_RTCCLK_T duration);
563 void RTC_EnableTDE(void);
564 void RTC_DisableTDE(void);
565 void RTC_EnablePullUp(void);
566 void RTC_DisablePullUp(void);
567 
568 /* Backup Data Registers */
569 void RTC_WriteBackup(RTC_BAKP_REG_T backupReg, uint32_t data);
570 uint32_t RTC_ReadBackup(RTC_BAKP_REG_T backup);
571 
572 /* Tamper and TimeStamp Pins mapping */
573 void RTC_ConfigTamperPin(RTC_TAMPER_PIN_T tamperPin);
574 void RTC_ConfigTimeStampPin(RTC_TIMESTAMP_PIN_T timeStampPin);
575 /* Output Type */
576 void RTC_ConfigOutputType(RTC_OUTPUT_T outputType);
577 
578 /* Shift control synchonisation */
579 uint8_t RTC_ConfigSynchroShift(RTC_SHIFT_ADD1S_T add1S, uint16_t subFS);
580 
581 /* Interrupts and flags */
582 void RTC_EnableInterrupt(uint32_t interrupt);
583 void RTC_DisableInterrupt(uint32_t interrupt);
584 uint8_t RTC_ReadStatusFlag(RTC_FLAG_T flag);
585 void RTC_ClearStatusFlag(uint32_t flag);
586 uint8_t RTC_ReadIntFlag(RTC_INT_FLAG_T flag);
587 void RTC_ClearIntFlag(uint32_t flag);
588 
589 #ifdef __cplusplus
590 }
591 #endif
592 
593 #endif /* __APM32F4XX_RTC_H */
594 
595 /**@} end of group RTC_Enumerations */
596 /**@} end of group RTC_Driver */
597 /**@} end of group APM32F4xx_StdPeriphDriver */
598