1 /*****************************************************************************
2  * Copyright (c) 2022, Nations Technologies Inc.
3  *
4  * All rights reserved.
5  * ****************************************************************************
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * - Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the disclaimer below.
12  *
13  * Nations' name may not be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
19  * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
22  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  * ****************************************************************************/
27 
28 /**
29  * @file n32l43x_rtc.h
30  * @author Nations
31  * @version v1.2.0
32  *
33  * @copyright Copyright (c) 2022, Nations Technologies Inc. All rights reserved.
34  */
35 #ifndef __N32L43X_RTC_H__
36 #define __N32L43X_RTC_H__
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #include "n32l43x.h"
43 
44 /** @addtogroup n32l43x_StdPeriph_Driver
45  * @{
46  */
47 
48 /** @addtogroup RTC
49  * @{
50  */
51 
52 /**
53  * @brief  RTC Init structures definition
54  */
55 typedef struct
56 {
57     uint32_t RTC_HourFormat; /*!< Specifies the RTC Hour Format.
58                              This parameter can be a value of @ref RTC_Hour_Formats */
59 
60     uint32_t RTC_AsynchPrediv; /*!< Specifies the RTC Asynchronous Predivider value.
61                                This parameter must be set to a value lower than 0x7F */
62 
63     uint32_t RTC_SynchPrediv; /*!< Specifies the RTC Synchronous Predivider value.
64                               This parameter must be set to a value lower than 0x7FFF */
65 } RTC_InitType;
66 
67 /**
68  * @brief  RTC Time structure definition
69  */
70 typedef struct
71 {
72     uint8_t Hours; /*!< Specifies the RTC Time Hour.
73                        This parameter must be set to a value in the 0-12 range
74                        if the RTC_12HOUR_FORMAT is selected or 0-23 range if
75                        the RTC_24HOUR_FORMAT is selected. */
76 
77     uint8_t Minutes; /*!< Specifies the RTC Time Minutes.
78                          This parameter must be set to a value in the 0-59 range. */
79 
80     uint8_t Seconds; /*!< Specifies the RTC Time Seconds.
81                          This parameter must be set to a value in the 0-59 range. */
82 
83     uint8_t H12; /*!< Specifies the RTC AM/PM Time.
84                      This parameter can be a value of @ref RTC_AM_PM_Definitions */
85 } RTC_TimeType;
86 
87 /**
88  * @brief  RTC Date structure definition
89  */
90 typedef struct
91 {
92     uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay.
93                           This parameter can be a value of @ref RTC_WeekDay_Definitions */
94 
95     uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format).
96                         This parameter can be a value of @ref RTC_Month_Date_Definitions */
97 
98     uint8_t Date; /*!< Specifies the RTC Date.
99                       This parameter must be set to a value in the 1-31 range. */
100 
101     uint8_t Year; /*!< Specifies the RTC Date Year.
102                       This parameter must be set to a value in the 0-99 range. */
103 } RTC_DateType;
104 
105 /**
106  * @brief  RTC Alarm structure definition
107  */
108 typedef struct
109 {
110     RTC_TimeType AlarmTime; /*!< Specifies the RTC Alarm Time members. */
111 
112     uint32_t AlarmMask; /*!< Specifies the RTC Alarm Masks.
113                             This parameter can be a value of @ref RTC_AlarmMask_Definitions */
114 
115     uint32_t DateWeekMode; /*!< Specifies the RTC Alarm is on Date or WeekDay.
116                                       This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */
117 
118     uint8_t DateWeekValue; /*!< Specifies the RTC Alarm Date/WeekDay.
119                                   If the Alarm Date is selected, this parameter
120                                   must be set to a value in the 1-31 range.
121                                   If the Alarm WeekDay is selected, this
122                                   parameter can be a value of @ref RTC_WeekDay_Definitions */
123 } RTC_AlarmType;
124 
125 /** @addtogroup RTC_Exported_Constants
126  * @{
127  */
128 
129 /** @addtogroup RTC_Hour_Formats
130  * @{
131  */
132 #define RTC_24HOUR_FORMAT          ((uint32_t)0x00000000)
133 #define RTC_12HOUR_FORMAT          ((uint32_t)0x00000040)
134 #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_12HOUR_FORMAT) || ((FORMAT) == RTC_24HOUR_FORMAT))
135 /**
136  * @}
137  */
138 
139 /** @addtogroup RTC_Asynchronous_Predivider
140  * @{
141  */
142 #define IS_RTC_PREDIV_ASYNCH(PREDIV) ((PREDIV) <= 0x7F)
143 
144 /**
145  * @}
146  */
147 
148 /** @addtogroup RTC_Synchronous_Predivider
149  * @{
150  */
151 #define IS_RTC_PREDIV_SYNCH(PREDIV) ((PREDIV) <= 0x7FFF)
152 
153 /**
154  * @}
155  */
156 
157 /** @addtogroup RTC_Time_Definitions
158  * @{
159  */
160 #define IS_RTC_12HOUR(HOUR)     (((HOUR) > 0) && ((HOUR) <= 12))
161 #define IS_RTC_24HOUR(HOUR)     ((HOUR) <= 23)
162 #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59)
163 #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59)
164 
165 /**
166  * @}
167  */
168 
169 /** @addtogroup RTC_AM_PM_Definitions
170  * @{
171  */
172 #define RTC_AM_H12     ((uint8_t)0x00)
173 #define RTC_PM_H12     ((uint8_t)0x40)
174 #define IS_RTC_H12(PM) (((PM) == RTC_AM_H12) || ((PM) == RTC_PM_H12))
175 
176 /**
177  * @}
178  */
179 
180 /** @addtogroup RTC_Year_Date_Definitions
181  * @{
182  */
183 #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99)
184 
185 /**
186  * @}
187  */
188 
189 /** @addtogroup RTC_Month_Date_Definitions
190  * @{
191  */
192 
193 /* Coded in BCD format */
194 #define RTC_MONTH_JANUARY   ((uint8_t)0x01)
195 #define RTC_MONTH_FEBRURY   ((uint8_t)0x02)
196 #define RTC_MONTH_MARCH     ((uint8_t)0x03)
197 #define RTC_MONTH_APRIL     ((uint8_t)0x04)
198 #define RTC_MONTH_MAY       ((uint8_t)0x05)
199 #define RTC_MONTH_JUNE      ((uint8_t)0x06)
200 #define RTC_MONTH_JULY      ((uint8_t)0x07)
201 #define RTC_MONTH_AUGUST    ((uint8_t)0x08)
202 #define RTC_MONTH_SEPTEMBER ((uint8_t)0x09)
203 #define RTC_MONTH_OCTOBER   ((uint8_t)0x10)
204 #define RTC_MONTH_NOVEMBER  ((uint8_t)0x11)
205 #define RTC_MONTH_DECEMBER  ((uint8_t)0x12)
206 #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1) && ((MONTH) <= 12))
207 #define IS_RTC_DATE(DATE)   (((DATE) >= 1) && ((DATE) <= 31))
208 
209 /**
210  * @}
211  */
212 
213 /** @addtogroup RTC_WeekDay_Definitions
214  * @{
215  */
216 
217 #define RTC_WEEKDAY_MONDAY    ((uint8_t)0x01)
218 #define RTC_WEEKDAY_TUESDAY   ((uint8_t)0x02)
219 #define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03)
220 #define RTC_WEEKDAY_THURSDAY  ((uint8_t)0x04)
221 #define RTC_WEEKDAY_FRIDAY    ((uint8_t)0x05)
222 #define RTC_WEEKDAY_SATURDAY  ((uint8_t)0x06)
223 #define RTC_WEEKDAY_SUNDAY    ((uint8_t)0x07)
224 #define IS_RTC_WEEKDAY(WEEKDAY)                                                                                        \
225     (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY)   \
226      || ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || ((WEEKDAY) == RTC_WEEKDAY_FRIDAY)                                       \
227      || ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
228 /**
229  * @}
230  */
231 
232 /** @addtogroup RTC_Alarm_Definitions
233  * @{
234  */
235 #define IS_RTC_ALARM_WEEKDAY_DATE(DATE) (((DATE) > 0) && ((DATE) <= 31))
236 #define IS_RTC_ALARM_WEEKDAY_WEEKDAY(WEEKDAY)                                                                          \
237     (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY)   \
238      || ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || ((WEEKDAY) == RTC_WEEKDAY_FRIDAY)                                       \
239      || ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
240 
241 /**
242  * @}
243  */
244 
245 /** @addtogroup RTC_AlarmDateWeekDay_Definitions
246  * @{
247  */
248 #define RTC_ALARM_SEL_WEEKDAY_DATE    ((uint32_t)0x00000000)
249 #define RTC_ALARM_SEL_WEEKDAY_WEEKDAY ((uint32_t)0x40000000)
250 
251 #define IS_RTC_ALARM_WEEKDAY_SEL(SEL)                                                                                  \
252     (((SEL) == RTC_ALARM_SEL_WEEKDAY_DATE) || ((SEL) == RTC_ALARM_SEL_WEEKDAY_WEEKDAY))
253 
254 /**
255  * @}
256  */
257 
258 /** @addtogroup RTC_AlarmMask_Definitions
259  * @{
260  */
261 #define RTC_ALARMMASK_NONE    ((uint32_t)0x00000000)
262 #define RTC_ALARMMASK_WEEKDAY ((uint32_t)0x80000000)
263 #define RTC_ALARMMASK_HOURS   ((uint32_t)0x00800000)
264 #define RTC_ALARMMASK_MINUTES ((uint32_t)0x00008000)
265 #define RTC_ALARMMASK_SECONDS ((uint32_t)0x00000080)
266 #define RTC_ALARMMASK_ALL     ((uint32_t)0x80808080)
267 #define IS_ALARM_MASK(INTEN)  (((INTEN)&0x7F7F7F7F) == (uint32_t)RESET)
268 
269 /**
270  * @}
271  */
272 
273 /** @addtogroup RTC_Alarms_Definitions
274  * @{
275  */
276 #define RTC_A_ALARM                ((uint32_t)0x00000100)
277 #define RTC_B_ALARM                ((uint32_t)0x00000200)
278 #define IS_RTC_ALARM_SEL(ALARM)    (((ALARM) == RTC_A_ALARM) || ((ALARM) == RTC_B_ALARM))
279 #define IS_RTC_ALARM_ENABLE(ALARM) (((ALARM) & (RTC_A_ALARM | RTC_B_ALARM)) != (uint32_t)RESET)
280 
281 /**
282  * @}
283  */
284 
285 /** @addtogroup RTC_Alarm_Sub_Seconds_Masks_Definitions
286  * @{
287  */
288 #define RTC_SUBS_MASK_ALL                                                                                              \
289     ((uint32_t)0x00000000) /*!< All Alarm SS fields are masked.                                                        \
290                                          There is no comparison on sub seconds                                         \
291                                          for Alarm */
292 #define RTC_SUBS_MASK_SS14_1                                                                                           \
293     ((uint32_t)0x01000000) /*!< SS[14:1] are don't care in Alarm                                                       \
294                                          comparison. Only SS[0] is compared. */
295 #define RTC_SUBS_MASK_SS14_2                                                                                           \
296     ((uint32_t)0x02000000) /*!< SS[14:2] are don't care in Alarm                                                       \
297                                          comparison. Only SS[1:0] are compared */
298 #define RTC_SUBS_MASK_SS14_3                                                                                           \
299     ((uint32_t)0x03000000) /*!< SS[14:3] are don't care in Alarm                                                       \
300                                          comparison. Only SS[2:0] are compared */
301 #define RTC_SUBS_MASK_SS14_4                                                                                           \
302     ((uint32_t)0x04000000) /*!< SS[14:4] are don't care in Alarm                                                       \
303                                          comparison. Only SS[3:0] are compared */
304 #define RTC_SUBS_MASK_SS14_5                                                                                           \
305     ((uint32_t)0x05000000) /*!< SS[14:5] are don't care in Alarm                                                       \
306                                          comparison. Only SS[4:0] are compared */
307 #define RTC_SUBS_MASK_SS14_6                                                                                           \
308     ((uint32_t)0x06000000) /*!< SS[14:6] are don't care in Alarm                                                       \
309                                          comparison. Only SS[5:0] are compared */
310 #define RTC_SUBS_MASK_SS14_7                                                                                           \
311     ((uint32_t)0x07000000) /*!< SS[14:7] are don't care in Alarm                                                       \
312                                          comparison. Only SS[6:0] are compared */
313 #define RTC_SUBS_MASK_SS14_8                                                                                           \
314     ((uint32_t)0x08000000) /*!< SS[14:8] are don't care in Alarm                                                       \
315                                          comparison. Only SS[7:0] are compared */
316 #define RTC_SUBS_MASK_SS14_9                                                                                           \
317     ((uint32_t)0x09000000) /*!< SS[14:9] are don't care in Alarm                                                       \
318                                          comparison. Only SS[8:0] are compared */
319 #define RTC_SUBS_MASK_SS14_10                                                                                          \
320     ((uint32_t)0x0A000000) /*!< SS[14:10] are don't care in Alarm                                                      \
321                                          comparison. Only SS[9:0] are compared */
322 #define RTC_SUBS_MASK_SS14_11                                                                                          \
323     ((uint32_t)0x0B000000) /*!< SS[14:11] are don't care in Alarm                                                      \
324                                          comparison. Only SS[10:0] are compared */
325 #define RTC_SUBS_MASK_SS14_12                                                                                          \
326     ((uint32_t)0x0C000000) /*!< SS[14:12] are don't care in Alarm                                                      \
327                                          comparison.Only SS[11:0] are compared */
328 #define RTC_SUBS_MASK_SS14_13                                                                                          \
329     ((uint32_t)0x0D000000) /*!< SS[14:13] are don't care in Alarm                                                      \
330                                          comparison. Only SS[12:0] are compared */
331 #define RTC_SUBS_MASK_SS14_14                                                                                          \
332     ((uint32_t)0x0E000000) /*!< SS[14] is don't care in Alarm                                                          \
333                                       comparison.Only SS[13:0] are compared */
334 #define RTC_SUBS_MASK_NONE                                                                                             \
335     ((uint32_t)0x0F000000) /*!< SS[14:0] are compared and must match                                                   \
336                                          to activate alarm. */
337 #define IS_RTC_ALARM_SUB_SECOND_MASK_MODE(INTEN)                                                                       \
338     (((INTEN) == RTC_SUBS_MASK_ALL) || ((INTEN) == RTC_SUBS_MASK_SS14_1) || ((INTEN) == RTC_SUBS_MASK_SS14_2)          \
339      || ((INTEN) == RTC_SUBS_MASK_SS14_3) || ((INTEN) == RTC_SUBS_MASK_SS14_4) || ((INTEN) == RTC_SUBS_MASK_SS14_5)    \
340      || ((INTEN) == RTC_SUBS_MASK_SS14_6) || ((INTEN) == RTC_SUBS_MASK_SS14_7) || ((INTEN) == RTC_SUBS_MASK_SS14_8)    \
341      || ((INTEN) == RTC_SUBS_MASK_SS14_9) || ((INTEN) == RTC_SUBS_MASK_SS14_10) || ((INTEN) == RTC_SUBS_MASK_SS14_11)  \
342      || ((INTEN) == RTC_SUBS_MASK_SS14_12) || ((INTEN) == RTC_SUBS_MASK_SS14_13) || ((INTEN) == RTC_SUBS_MASK_SS14_14) \
343      || ((INTEN) == RTC_SUBS_MASK_NONE))
344 /**
345  * @}
346  */
347 
348 /** @addtogroup RTC_Alarm_Sub_Seconds_Value
349  * @{
350  */
351 
352 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= 0x00007FFF)
353 
354 /**
355  * @}
356  */
357 
358 /** @addtogroup RTC_Wakeup_Timer_Definitions
359  * @{
360  */
361 #define RTC_WKUPCLK_RTCCLK_DIV16   ((uint32_t)0x00000000)
362 #define RTC_WKUPCLK_RTCCLK_DIV8    ((uint32_t)0x00000001)
363 #define RTC_WKUPCLK_RTCCLK_DIV4    ((uint32_t)0x00000002)
364 #define RTC_WKUPCLK_RTCCLK_DIV2    ((uint32_t)0x00000003)
365 #define RTC_WKUPCLK_CK_SPRE_16BITS ((uint32_t)0x00000004)
366 #define RTC_WKUPCLK_CK_SPRE_17BITS ((uint32_t)0x00000006)
367 #define IS_RTC_WKUP_CLOCK(CLOCK)                                                                                       \
368     (((CLOCK) == RTC_WKUPCLK_RTCCLK_DIV16) || ((CLOCK) == RTC_WKUPCLK_RTCCLK_DIV8)                                     \
369      || ((CLOCK) == RTC_WKUPCLK_RTCCLK_DIV4) || ((CLOCK) == RTC_WKUPCLK_RTCCLK_DIV2)                                   \
370      || ((CLOCK) == RTC_WKUPCLK_CK_SPRE_16BITS) || ((CLOCK) == RTC_WKUPCLK_CK_SPRE_17BITS))
371 #define IS_RTC_WKUP_COUNTER(COUNTER) ((COUNTER) <= 0xFFFF)
372 /**
373  * @}
374  */
375 
376 /** @addtogroup RTC_Time_Stamp_Edges_definitions
377  * @{
378  */
379 #define RTC_TIMESTAMP_EDGE_RISING  ((uint32_t)0x00000000)
380 #define RTC_TIMESTAMP_EDGE_FALLING ((uint32_t)0x00000008)
381 #define IS_RTC_TIMESTAMP_EDGE_MODE(EDGE)                                                                               \
382     (((EDGE) == RTC_TIMESTAMP_EDGE_RISING) || ((EDGE) == RTC_TIMESTAMP_EDGE_FALLING))
383 /**
384  * @}
385  */
386 
387 /** @addtogroup RTC_Output_selection_Definitions
388  * @{
389  */
390 #define RTC_OUTPUT_DIS  ((uint32_t)0x00000000)
391 #define RTC_OUTPUT_ALA  ((uint32_t)0x00200000)
392 #define RTC_OUTPUT_ALB  ((uint32_t)0x00400000)
393 #define RTC_OUTPUT_WKUP ((uint32_t)0x00600000)
394 
395 #define IS_RTC_OUTPUT_MODE(OUTPUT)                                                                                     \
396     (((OUTPUT) == RTC_OUTPUT_DIS) || ((OUTPUT) == RTC_OUTPUT_ALA) || ((OUTPUT) == RTC_OUTPUT_ALB)                      \
397      || ((OUTPUT) == RTC_OUTPUT_WKUP))
398 
399 /**
400  * @}
401  */
402 
403 /** @addtogroup RTC_Output_Polarity_Definitions
404  * @{
405  */
406 #define RTC_OUTPOL_HIGH        ((uint32_t)0x00000000)
407 #define RTC_OUTPOL_LOW         ((uint32_t)0x00100000)
408 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPOL_HIGH) || ((POL) == RTC_OUTPOL_LOW))
409 /**
410  * @}
411  */
412 
413 
414 /** @addtogroup RTC_Calib_Output_selection_Definitions
415  * @{
416  */
417 #define RTC_CALIB_OUTPUT_256HZ      ((uint32_t)0x00000000)
418 #define RTC_CALIB_OUTPUT_1HZ        ((uint32_t)0x00080000)
419 #define IS_RTC_CALIB_OUTPUT(OUTPUT) (((OUTPUT) == RTC_CALIB_OUTPUT_256HZ) || ((OUTPUT) == RTC_CALIB_OUTPUT_1HZ))
420 /**
421  * @}
422  */
423 
424 /** @addtogroup RTC_Smooth_calib_period_Definitions
425  * @{
426  */
427 #define SMOOTH_CALIB_32SEC                                                                                             \
428     ((uint32_t)0x00000000) /*!<  if RTCCLK = 32768 Hz, Smooth calibation                                               \
429                                     period is 32s,  else 2exp20 RTCCLK seconds */
430 #define SMOOTH_CALIB_16SEC                                                                                             \
431     ((uint32_t)0x00002000) /*!<  if RTCCLK = 32768 Hz, Smooth calibation                                               \
432                                     period is 16s, else 2exp19 RTCCLK seconds */
433 #define SMOOTH_CALIB_8SEC                                                                                              \
434     ((uint32_t)0x00004000) /*!<  if RTCCLK = 32768 Hz, Smooth calibation                                               \
435                                     period is 8s, else 2exp18 RTCCLK seconds */
436 #define IS_RTC_SMOOTH_CALIB_PERIOD_SEL(PERIOD)                                                                         \
437     (((PERIOD) == SMOOTH_CALIB_32SEC) || ((PERIOD) == SMOOTH_CALIB_16SEC) || ((PERIOD) == SMOOTH_CALIB_8SEC))
438 
439 /**
440  * @}
441  */
442 
443 /** @addtogroup RTC_Smooth_calib_Plus_pulses_Definitions
444  * @{
445  */
446 #define RTC_SMOOTH_CALIB_PLUS_PULSES_SET                                                                               \
447     ((uint32_t)0x00008000) /*!<  The number of RTCCLK pulses added                                                     \
448                         during a X -second window = Y - CALM[8:0].                                                     \
449                          with Y = 512, 256, 128 when X = 32, 16, 8 */
450 #define RTC_SMOOTH_CALIB_PLUS_PULSES__RESET                                                                            \
451     ((uint32_t)0x00000000) /*!<  The number of RTCCLK pulses subbstited                                                \
452                         during a 32-second window =   CALM[8:0]. */
453 #define IS_RTC_SMOOTH_CALIB_PLUS(PLUS)                                                                                 \
454     (((PLUS) == RTC_SMOOTH_CALIB_PLUS_PULSES_SET) || ((PLUS) == RTC_SMOOTH_CALIB_PLUS_PULSES__RESET))
455 
456 /**
457  * @}
458  */
459 
460 /** @addtogroup RTC_Smooth_calib_Minus_pulses_Definitions
461  * @{
462  */
463 #define IS_RTC_SMOOTH_CALIB_MINUS(VALUE) ((VALUE) <= 0x000001FF)
464 
465 /**
466  * @}
467  */
468 
469 /** @addtogroup RTC_DayLightSaving_Definitions
470  * @{
471  */
472 #define RTC_DAYLIGHT_SAVING_SUB1H    ((uint32_t)0x00020000)
473 #define RTC_DAYLIGHT_SAVING_ADD1H    ((uint32_t)0x00010000)
474 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHT_SAVING_SUB1H) || ((SAVE) == RTC_DAYLIGHT_SAVING_ADD1H))
475 
476 #define RTC_STORE_OPERATION_RESET ((uint32_t)0x00000000)
477 #define RTC_STORE_OPERATION_SET   ((uint32_t)0x00040000)
478 #define IS_RTC_STORE_OPERATION(OPERATION)                                                                              \
479     (((OPERATION) == RTC_STORE_OPERATION_RESET) || ((OPERATION) == RTC_STORE_OPERATION_SET))
480 /**
481  * @}
482  */
483 
484 /** @addtogroup RTC_Output_Type_ALARM_OUT
485  * @{
486  */
487 #define RTC_OUTPUT_OPENDRAIN     ((uint32_t)0x00000000)
488 #define RTC_OUTPUT_PUSHPULL      ((uint32_t)0x00000001)
489 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_OPENDRAIN) || ((TYPE) == RTC_OUTPUT_PUSHPULL))
490 
491 /**
492  * @}
493  */
494 
495 /** @addtogroup RTC_Add_1_Second_Parameter_Definitions
496  * @{
497  */
498 #define RTC_SHIFT_ADD1S_DISABLE ((uint32_t)0x00000000)
499 #define RTC_SHIFT_ADD1S_ENABLE  ((uint32_t)0x80000000)
500 #define IS_RTC_SHIFT_ADD1S(SEL) (((SEL) == RTC_SHIFT_ADD1S_DISABLE) || ((SEL) == RTC_SHIFT_ADD1S_ENABLE))
501 /**
502  * @}
503  */
504 
505 /** @addtogroup RTC_Substract_Fraction_Of_Second_Value
506  * @{
507  */
508 #define IS_RTC_SHIFT_SUBFS(FS) ((FS) <= 0x00007FFF)
509 
510 /**
511  * @}
512  */
513 
514 /** @addtogroup RTC_Input_parameter_format_definitions
515  * @{
516  */
517 #define RTC_FORMAT_BIN        ((uint32_t)0x000000000)
518 #define RTC_FORMAT_BCD        ((uint32_t)0x000000001)
519 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || ((FORMAT) == RTC_FORMAT_BCD))
520 
521 /**
522  * @}
523  */
524 
525 /** @addtogroup RTC_Flags_Definitions
526  * @{
527  */
528 #define RTC_FLAG_RECPF  ((uint32_t)0x00010000)
529 #define RTC_FLAG_TAMP3F ((uint32_t)0x00008000)
530 #define RTC_FLAG_TAMP2F ((uint32_t)0x00004000)
531 #define RTC_FLAG_TAMP1F ((uint32_t)0x00002000)
532 #define RTC_FLAG_TISOVF ((uint32_t)0x00001000)
533 #define RTC_FLAG_TISF   ((uint32_t)0x00000800)
534 #define RTC_FLAG_WTF    ((uint32_t)0x00000400)
535 #define RTC_FLAG_ALBF   ((uint32_t)0x00000200)
536 #define RTC_FLAG_ALAF   ((uint32_t)0x00000100)
537 #define RTC_FLAG_INITF  ((uint32_t)0x00000040)
538 #define RTC_FLAG_RSYF   ((uint32_t)0x00000020)
539 #define RTC_FLAG_INITSF ((uint32_t)0x00000010)
540 #define RTC_FLAG_SHOPF  ((uint32_t)0x00000008)
541 #define RTC_FLAG_WTWF   ((uint32_t)0x00000004)
542 #define RTC_FLAG_ALBWF  ((uint32_t)0x00000002)
543 #define RTC_FLAG_ALAWF  ((uint32_t)0x00000001)
544 #define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_RECPF) || ((FLAG) == RTC_FLAG_TAMP3F) || \
545                                ((FLAG) == RTC_FLAG_TAMP2F) || ((FLAG) == RTC_FLAG_TAMP1F) || \
546                                ((FLAG) == RTC_FLAG_TISOVF) || ((FLAG) == RTC_FLAG_TISF) || \
547                                ((FLAG) == RTC_FLAG_WTF) || ((FLAG) == RTC_FLAG_ALBF) || \
548                                ((FLAG) == RTC_FLAG_ALAF) || ((FLAG) == RTC_FLAG_INITF) || \
549                                ((FLAG) == RTC_FLAG_RSYF) || ((FLAG) == RTC_FLAG_INITSF) || \
550                                ((FLAG) == RTC_FLAG_SHOPF) || ((FLAG) == RTC_FLAG_WTWF) || \
551                                ((FLAG) == RTC_FLAG_ALBWF)|| ((FLAG) == RTC_FLAG_ALAWF))
552 #define IS_RTC_CLEAR_FLAG(FLAG) (((FLAG) != (uint32_t)RESET) && (((FLAG) & 0xFFFF00DF) == (uint32_t)RESET))
553 
554 /**
555  * @}
556  */
557 
558 /** @addtogroup RTC_Interrupts_Definitions
559  * @{
560  */
561 #define RTC_INT_TAMP3     ((uint32_t)0x00080000)
562 #define RTC_INT_TAMP2     ((uint32_t)0x00040000)
563 #define RTC_INT_TAMP1     ((uint32_t)0x00020000)
564 #define RTC_INT_TS        ((uint32_t)0x00008000)
565 #define RTC_INT_WUT  ((uint32_t)0x00004000)
566 #define RTC_INT_ALRB ((uint32_t)0x00002000)
567 #define RTC_INT_ALRA ((uint32_t)0x00001000)
568 
569 #define IS_RTC_CONFIG_INT(IT) (((IT) != (uint32_t)RESET) && (((IT)&0xFFFF0FFB) == (uint32_t)RESET))
570 #define IS_RTC_GET_INT(IT)                                                                                             \
571     (((IT) == RTC_INT_TAMP3) ||((IT) == RTC_INT_TAMP2) ||((IT) == RTC_INT_TAMP1) ||((IT) == RTC_INT_TS) || ((IT) == RTC_INT_WUT) || ((IT) == RTC_INT_ALRB) || ((IT) == RTC_INT_ALRA))
572 #define IS_RTC_CLEAR_INT(IT) (((IT) != (uint32_t)RESET) && (((IT)&0xFFF10FFF) == (uint32_t)RESET))
573 
574 /**
575  * @}
576  */
577 
578 /** @addtogroup RTC_Legacy
579  * @{
580  */
581 #define RTC_DigitalCalibConfig RTC_CoarseCalibConfig
582 #define RTC_DigitalCalibCmd    RTC_CoarseCalibCmd
583 /** @defgroup RTC_Tamper_Trigger_Definitions
584   * @{
585   */
586 #define RTC_TamperTrigger_RisingEdge            ((uint32_t)0x00000000)
587 #define RTC_TamperTrigger_FallingEdge           ((uint32_t)0x00000002)
588 #define RTC_TamperTrigger_LowLevel              ((uint32_t)0x00000000)
589 #define RTC_TamperTrigger_HighLevel             ((uint32_t)0x00000002)
590 #define IS_RTC_TAMPER_TRIGGER(TRIGGER) (((TRIGGER) == RTC_TamperTrigger_RisingEdge) || \
591                                         ((TRIGGER) == RTC_TamperTrigger_FallingEdge) || \
592                                         ((TRIGGER) == RTC_TamperTrigger_LowLevel) || \
593                                         ((TRIGGER) == RTC_TamperTrigger_HighLevel))
594 
595 /**
596   * @}
597   */
598 
599 /** @defgroup RTC_Tamper_Filter_Definitions
600   * @{
601   */
602 #define RTC_TamperFilter_Disable   ((uint32_t)0x00000000) /*!< Tamper filter is disabled */
603 
604 #define RTC_TamperFilter_2Sample   ((uint32_t)0x00000800) /*!< Tamper is activated after 2
605                                                           consecutive samples at the active level */
606 #define RTC_TamperFilter_4Sample   ((uint32_t)0x00001000) /*!< Tamper is activated after 4
607                                                           consecutive samples at the active level */
608 #define RTC_TamperFilter_8Sample   ((uint32_t)0x00001800) /*!< Tamper is activated after 8
609                                                           consecutive samples at the active leve. */
610 
611 #define IS_RTC_TAMPER_FILTER(FILTER) (((FILTER) == RTC_TamperFilter_Disable) || \
612                                       ((FILTER) == RTC_TamperFilter_2Sample) || \
613                                       ((FILTER) == RTC_TamperFilter_4Sample) || \
614                                       ((FILTER) == RTC_TamperFilter_8Sample))
615 /**
616   * @}
617   */
618 
619 /** @defgroup RTC_Tamper_Sampling_Frequencies_Definitions
620   * @{
621   */
622 #define RTC_TamperSamplingFreq_RTCCLK_Div32768  ((uint32_t)0x00000000) /*!< Each of the tamper inputs are sampled
623                                                                            with a frequency =  RTCCLK / 32768 */
624 #define RTC_TamperSamplingFreq_RTCCLK_Div16384  ((uint32_t)0x000000100) /*!< Each of the tamper inputs are sampled
625                                                                             with a frequency =  RTCCLK / 16384 */
626 #define RTC_TamperSamplingFreq_RTCCLK_Div8192   ((uint32_t)0x00000200) /*!< Each of the tamper inputs are sampled
627                                                                            with a frequency =  RTCCLK / 8192  */
628 #define RTC_TamperSamplingFreq_RTCCLK_Div4096   ((uint32_t)0x00000300) /*!< Each of the tamper inputs are sampled
629                                                                            with a frequency =  RTCCLK / 4096  */
630 #define RTC_TamperSamplingFreq_RTCCLK_Div2048   ((uint32_t)0x00000400) /*!< Each of the tamper inputs are sampled
631                                                                            with a frequency =  RTCCLK / 2048  */
632 #define RTC_TamperSamplingFreq_RTCCLK_Div1024   ((uint32_t)0x00000500) /*!< Each of the tamper inputs are sampled
633                                                                            with a frequency =  RTCCLK / 1024  */
634 #define RTC_TamperSamplingFreq_RTCCLK_Div512    ((uint32_t)0x00000600) /*!< Each of the tamper inputs are sampled
635                                                                            with a frequency =  RTCCLK / 512   */
636 #define RTC_TamperSamplingFreq_RTCCLK_Div256    ((uint32_t)0x00000700) /*!< Each of the tamper inputs are sampled
637                                                                            with a frequency =  RTCCLK / 256   */
638 #define RTC_TAMPCR_TAMPFREQ                      ((uint32_t)0x00000700) /* Clear TAMPFREQ[2:0] bits in the RTC_TAMPCR register */
639 
640 #define IS_RTC_TAMPER_SAMPLING_FREQ(FREQ) (((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div32768) || \
641                                            ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div16384) || \
642                                            ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div8192) || \
643                                            ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div4096) || \
644                                            ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div2048) || \
645                                            ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div1024) || \
646                                            ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div512) || \
647                                            ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div256))
648 
649 /**
650   * @}
651   */
652 
653   /** @defgroup RTC_Tamper_Pin_Precharge_Duration_Definitions
654   * @{
655   */
656 #define RTC_TamperPrechargeDuration_1RTCCLK ((uint32_t)0x00000000)  /*!< Tamper pins are pre-charged before
657                                                                          sampling during 1 RTCCLK cycle */
658 #define RTC_TamperPrechargeDuration_2RTCCLK ((uint32_t)0x00002000)  /*!< Tamper pins are pre-charged before
659                                                                          sampling during 2 RTCCLK cycles */
660 #define RTC_TamperPrechargeDuration_4RTCCLK ((uint32_t)0x00004000)  /*!< Tamper pins are pre-charged before
661                                                                          sampling during 4 RTCCLK cycles */
662 #define RTC_TamperPrechargeDuration_8RTCCLK ((uint32_t)0x00006000)  /*!< Tamper pins are pre-charged before
663                                                                          sampling during 8 RTCCLK cycles */
664 #define IS_RTC_TAMPER_PRECHARGE_DURATION(DURATION) (((DURATION) == RTC_TamperPrechargeDuration_1RTCCLK) || \
665                                                     ((DURATION) == RTC_TamperPrechargeDuration_2RTCCLK) || \
666                                                     ((DURATION) == RTC_TamperPrechargeDuration_4RTCCLK) || \
667                                                     ((DURATION) == RTC_TamperPrechargeDuration_8RTCCLK))
668 /**
669   * @}
670   */
671 
672 /** @defgroup RTC_Tamper_Pins_Definitions
673   * @{
674   */
675 #define RTC_TAMPER_1            RTC_TMPCFG_TP1EN /*!< Tamper detection enable for
676                                                       input tamper 1 */
677 #define RTC_TAMPER_2            RTC_TMPCFG_TP2EN /*!< Tamper detection enable for
678                                                       input tamper 2 */
679 #define RTC_TAMPER_3            RTC_TMPCFG_TP3EN /*!< Tamper detection enable for
680                                                       input tamper 3 */
681 #define IS_RTC_TAMPER(TAMPER) ((((TAMPER) & (uint32_t)0xFFFFFFD6) == 0x00) && ((TAMPER) != (uint32_t)RESET))
682 
683 
684 #define RTC_TAMPER1_INT        RTC_TMPCFG_TP1INTEN  /*!< Tamper detection interruput enable */
685 #define RTC_TAMPER2_INT        RTC_TMPCFG_TP2INTEN  /*!< Tamper detection interruput enable */
686 #define RTC_TAMPER3_INT        RTC_TMPCFG_TP3INTEN  /*!< Tamper detection interruput enable */
687 /**
688  * @}
689  */
690 
691 /**
692  * @}
693  */
694 
695 /*  Function used to set the RTC configuration to the default reset state *****/
696 ErrorStatus RTC_DeInit(void);
697 
698 /* Initialization and Configuration functions *********************************/
699 ErrorStatus RTC_Init(RTC_InitType* RTC_InitStruct);
700 void RTC_StructInit(RTC_InitType* RTC_InitStruct);
701 void RTC_EnableWriteProtection(FunctionalState Cmd);
702 ErrorStatus RTC_EnterInitMode(void);
703 void RTC_ExitInitMode(void);
704 ErrorStatus RTC_WaitForSynchro(void);
705 ErrorStatus RTC_EnableRefClock(FunctionalState Cmd);
706 void RTC_EnableBypassShadow(FunctionalState Cmd);
707 
708 /* Time and Date configuration functions **************************************/
709 ErrorStatus RTC_ConfigTime(uint32_t RTC_Format, RTC_TimeType* RTC_TimeStruct);
710 void RTC_TimeStructInit(RTC_TimeType* RTC_TimeStruct);
711 void RTC_GetTime(uint32_t RTC_Format, RTC_TimeType* RTC_TimeStruct);
712 uint32_t RTC_GetSubSecond(void);
713 ErrorStatus RTC_SetDate(uint32_t RTC_Format, RTC_DateType* RTC_DateStruct);
714 void RTC_DateStructInit(RTC_DateType* RTC_DateStruct);
715 void RTC_GetDate(uint32_t RTC_Format, RTC_DateType* RTC_DateStruct);
716 
717 /* Alarms (Alarm A and Alarm B) configuration functions  **********************/
718 void RTC_SetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmType* RTC_AlarmStruct);
719 void RTC_AlarmStructInit(RTC_AlarmType* RTC_AlarmStruct);
720 void RTC_GetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmType* RTC_AlarmStruct);
721 ErrorStatus RTC_EnableAlarm(uint32_t RTC_Alarm, FunctionalState Cmd);
722 void RTC_ConfigAlarmSubSecond(uint32_t RTC_Alarm, uint32_t RTC_AlarmSubSecondValue, uint32_t RTC_AlarmSubSecondMask);
723 uint32_t RTC_GetAlarmSubSecond(uint32_t RTC_Alarm);
724 
725 /* WakeUp Timer configuration functions ***************************************/
726 void RTC_ConfigWakeUpClock(uint32_t RTC_WakeUpClock);
727 void RTC_SetWakeUpCounter(uint32_t RTC_WakeUpCounter);
728 uint32_t RTC_GetWakeUpCounter(void);
729 ErrorStatus RTC_EnableWakeUp(FunctionalState Cmd);
730 
731 /* Daylight Saving configuration functions ************************************/
732 void RTC_ConfigDayLightSaving(uint32_t RTC_DayLightSaving, uint32_t RTC_StoreOperation);
733 uint32_t RTC_GetStoreOperation(void);
734 
735 /* Output pin Configuration function ******************************************/
736 void RTC_ConfigOutput(uint32_t RTC_Output, uint32_t RTC_OutputPolarity);
737 
738 /* Coarse and Smooth Calibration configuration functions **********************/
739 void RTC_EnableCalibOutput(FunctionalState Cmd);
740 void RTC_ConfigCalibOutput(uint32_t RTC_CalibOutput);
741 ErrorStatus RTC_ConfigSmoothCalib(uint32_t RTC_SmoothCalibPeriod,
742                                   uint32_t RTC_SmoothCalibPlusPulses,
743                                   uint32_t RTC_SmouthCalibMinusPulsesValue);
744 
745 /* TimeStamp configuration functions ******************************************/
746 void RTC_EnableTimeStamp(uint32_t RTC_TimeStampEdge, FunctionalState Cmd);
747 void RTC_GetTimeStamp(uint32_t RTC_Format, RTC_TimeType* RTC_StampTimeStruct, RTC_DateType* RTC_StampDateStruct);
748 uint32_t RTC_GetTimeStampSubSecond(void);
749 
750 /* Output Type Config configuration functions *********************************/
751 void RTC_ConfigOutputType(uint32_t RTC_OutputType);
752 
753 /* RTC_Shift_control_synchonisation_functions *********************************/
754 ErrorStatus RTC_ConfigSynchroShift(uint32_t RTC_ShiftAdd1S, uint32_t RTC_ShiftSubFS);
755 
756 /* Interrupts and flags management functions **********************************/
757 void RTC_ConfigInt(uint32_t RTC_INT, FunctionalState Cmd);
758 FlagStatus RTC_GetFlagStatus(uint32_t RTC_FLAG);
759 void RTC_ClrFlag(uint32_t RTC_FLAG);
760 INTStatus RTC_GetITStatus(uint32_t RTC_INT);
761 void RTC_ClrIntPendingBit(uint32_t RTC_INT);
762 
763 /* WakeUp TSC function **********************************/
764 void RTC_EnableWakeUpTsc(uint32_t count);
765 
766 /* Tampers configuration functions ********************************************/
767 void RTC_TamperTriggerConfig(uint32_t RTC_Tamper, uint32_t RTC_TamperTrigger);
768 void RTC_TamperCmd(uint32_t RTC_Tamper, FunctionalState NewState);
769 void RTC_TamperFilterConfig(uint32_t RTC_TamperFilter);
770 void RTC_TamperSamplingFreqConfig(uint32_t RTC_TamperSamplingFreq);
771 void RTC_TamperPinsPrechargeDuration(uint32_t RTC_TamperPrechargeDuration);
772 void RTC_TimeStampOnTamperDetectionCmd(FunctionalState NewState);
773 void RTC_TamperPullUpCmd(FunctionalState NewState);
774 void RTC_TamperIECmd(uint32_t TAMPxIE, FunctionalState NewState);
775 void RTC_TamperTAMPTSCmd(FunctionalState NewState);
776 
777 #ifdef __cplusplus
778 }
779 #endif
780 
781 #endif /*__N32L43X_RTC_H__ */
782 
783 /**
784  * @}
785  */
786 
787 /**
788  * @}
789  */
790