1 /**
2   ******************************************************************************
3   * @file    ald_rtc.h
4   * @brief   Header file of RTC Module driver.
5   *
6   * @version V1.0
7   * @date    16 Nov 2019
8   * @author  AE Team
9   * @note
10   *          Change Logs:
11   *          Date            Author          Notes
12   *          16 Nov 2019     AE Team         The first version
13   *
14   * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
15   *
16   * SPDX-License-Identifier: Apache-2.0
17   *
18   * Licensed under the Apache License, Version 2.0 (the License); you may
19   * not use this file except in compliance with the License.
20   * You may obtain a copy of the License at
21   *
22   * www.apache.org/licenses/LICENSE-2.0
23   *
24   * Unless required by applicable law or agreed to in writing, software
25   * distributed under the License is distributed on an AS IS BASIS, WITHOUT
26   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27   * See the License for the specific language governing permissions and
28   * limitations under the License.
29   **********************************************************************************
30   */
31 
32 #ifndef __ALD_RTC_H__
33 #define __ALD_RTC_H__
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #include "utils.h"
40 
41 
42 /** @addtogroup ES32FXXX_ALD
43   * @{
44   */
45 
46 /** @addtogroup RTC
47   * @{
48   */
49 
50 /** @defgroup RTC_Public_Types RTC Public Types
51   * @{
52   */
53 
54 /**
55   * @brief Hours format
56   */
57 typedef enum {
58 	RTC_HOUR_FORMAT_24 = 0x0U,	/**< 24-hours format */
59 	RTC_HOUR_FORMAT_12 = 0x1U,	/**< 12-hours format */
60 } rtc_hour_format_t;
61 
62 /**
63   * @brief Output mode
64   */
65 typedef enum {
66 	RTC_OUTPUT_DISABLE = 0x0U,	/**< Disable output */
67 	RTC_OUTPUT_ALARM_A = 0x1U,	/**< Output alarm_a signal */
68 	RTC_OUTPUT_ALARM_B = 0x2U,	/**< Output alarm_b signal */
69 	RTC_OUTPUT_WAKEUP  = 0x3U,	/**< Output wakeup signal */
70 } rtc_output_select_t;
71 
72 /**
73   * @brief Output polarity
74   */
75 typedef enum {
76 	RTC_OUTPUT_POLARITY_HIGH = 0x0U,	/**< Polarity is high */
77 	RTC_OUTPUT_POLARITY_LOW  = 0x1U,	/**< Polarity is low */
78 } rtc_output_polarity_t;
79 
80 /**
81   * @brief Initialization structure
82   */
83 typedef struct {
84 	rtc_hour_format_t hour_format;		/**< Hours format */
85 	uint32_t asynch_pre_div;		/**< Asynchronous predivider value */
86 	uint32_t synch_pre_div;			/**< Synchronous predivider value */
87 	rtc_output_select_t output;		/**< Output signal type */
88 	rtc_output_polarity_t output_polarity;	/**< Output polarity */
89 } rtc_init_t;
90 
91 /**
92   * @brief Source select
93   */
94 typedef enum {
95 	RTC_SOURCE_LOSC        = 0x0U,	/**< LOSC */
96 	RTC_SOURCE_LRC         = 0x1U,	/**< LRC */
97 	RTC_SOURCE_HRC_DIV_1M  = 0x2U,	/**< HRC divide to 1MHz */
98 	RTC_SOURCE_HOSC_DIV_1M = 0x3U,	/**< HOSC divide to 1MHz */
99 } rtc_source_sel_t;
100 
101 /**
102   * @brief Time structure
103   */
104 typedef struct {
105 	uint8_t hour;		/**< Hours */
106 	uint8_t minute;		/**< Minutes */
107 	uint8_t second;		/**< Seconds */
108 	uint16_t sub_sec;	/**< Sub-seconds */
109 } rtc_time_t;
110 
111 /**
112   * @brief Date structure
113   */
114 typedef struct {
115 	uint8_t week;	/**< Weeks */
116 	uint8_t day;	/**< days */
117 	uint8_t month;	/**< months */
118 	uint8_t year;	/**< years */
119 } rtc_date_t;
120 
121 /**
122   * @brief Data format
123   */
124 typedef enum {
125 	RTC_FORMAT_DEC = 0U,	/**< Decimal */
126 	RTC_FORMAT_BCD = 1U,	/**< BSD */
127 } rtc_format_t;
128 
129 /**
130   * @brief Index of alarm
131   */
132 typedef enum {
133 	RTC_ALARM_A = 0x0U,	/**< Alarm-A */
134 	RTC_ALARM_B = 0x1U,	/**< Alarm-B */
135 } rtc_alarm_idx_t;
136 
137 /**
138   * @brief Alarm mask
139   */
140 typedef enum {
141 	RTC_ALARM_MASK_NONE     = 0x0U,		/**< Mask is disable */
142 	RTC_ALARM_MASK_WEEK_DAY = (1U << 30),	/**< Mask week or day */
143 	RTC_ALARM_MASK_HOUR     = (1U << 23),	/**< Mask hour */
144 	RTC_ALARM_MASK_MINUTE   = (1U << 15),	/**< Mask minute */
145 	RTC_ALARM_MASK_SECOND   = (1U << 7),	/**< Mask second */
146 	RTC_ALARM_MASK_ALL      = 0x40808080U,	/**< Mask all */
147 } rtc_alarm_mask_t;
148 
149 /**
150   * @brief Alarm sub-second mask
151   */
152 typedef enum {
153 	RTC_ALARM_SS_MASK_NONE  = 0xFU,	/**< Mask is disable */
154 	RTC_ALARM_SS_MASK_14_1  = 0x1U,	/**< Mask bit(1-14) */
155 	RTC_ALARM_SS_MASK_14_2  = 0x2U,	/**< Mask bit(2-14) */
156 	RTC_ALARM_SS_MASK_14_3  = 0x3U,	/**< Mask bit(3-14) */
157 	RTC_ALARM_SS_MASK_14_4  = 0x4U,	/**< Mask bit(4-14) */
158 	RTC_ALARM_SS_MASK_14_5  = 0x5U,	/**< Mask bit(5-14) */
159 	RTC_ALARM_SS_MASK_14_6  = 0x6U,	/**< Mask bit(6-14) */
160 	RTC_ALARM_SS_MASK_14_7  = 0x7U,	/**< Mask bit(7-14) */
161 	RTC_ALARM_SS_MASK_14_8  = 0x8U,	/**< Mask bit(8-14) */
162 	RTC_ALARM_SS_MASK_14_9  = 0x9U,	/**< Mask bit(9-14) */
163 	RTC_ALARM_SS_MASK_14_10 = 0xAU,	/**< Mask bit(10-14) */
164 	RTC_ALARM_SS_MASK_14_11 = 0xBU,	/**< Mask bit(11-14) */
165 	RTC_ALARM_SS_MASK_14_12 = 0xCU,	/**< Mask bit(12-14) */
166 	RTC_ALARM_SS_MASK_14_13 = 0xDU,	/**< Mask bit(13-14) */
167 	RTC_ALARM_SS_MASK_14    = 0xEU,	/**< Mask bit14 */
168 	RTC_ALARM_SS_MASK_ALL   = 0x0U,	/**< Mask bit(0-14) */
169 } rtc_sub_second_mask_t;
170 
171 /**
172   * @brief Alarm select week or day */
173 typedef enum {
174 	RTC_SELECT_DAY  = 0x0U,	/**< Alarm select day */
175 	RTC_SELECT_WEEK = 0x1U,	/**< Alarm select week */
176 } rtc_week_day_sel_t;
177 
178 /**
179   * @brief Alarm structure
180   */
181 typedef struct {
182 	rtc_alarm_idx_t idx;		/**< Index of alarm */
183 	rtc_time_t time;		/**< Time structure */
184 	uint32_t mask;			/**< Alarm mask */
185 	rtc_sub_second_mask_t ss_mask;	/**< Alarm sub-second mask */
186 	rtc_week_day_sel_t sel;		/**< Select week or day */
187 
188 	union {
189 		uint8_t week;		/**< Alarm select week */
190 		uint8_t day;		/**< Alarm select day */
191 	};
192 } rtc_alarm_t;
193 
194 /**
195   * @brief Time stamp signel select
196   */
197 typedef enum {
198 	RTC_TS_SIGNAL_SEL_TAMPER0 = 0U,	/**< Select tamper0 */
199 	RTC_TS_SIGNAL_SEL_TAMPER1 = 1U,	/**< Select tamper1 */
200 } rtc_ts_signal_sel_t;
201 
202 /**
203   * @brief Time stamp trigger style
204   */
205 typedef enum {
206 	RTC_TS_RISING_EDGE  = 0U,	/**< Rising edge */
207 	RTC_TS_FALLING_EDGE = 1U,	/**< Falling edge */
208 } rtc_ts_trigger_style_t;
209 
210 /**
211   * @brief Index of tamper
212   */
213 typedef enum {
214 	RTC_TAMPER_0 = 0U,	/**< Tamper0 */
215 	RTC_TAMPER_1 = 1U,	/**< Tamper1 */
216 } rtc_tamper_idx_t;
217 
218 /**
219   * @brief Tamper trigger type
220   */
221 typedef enum {
222 	RTC_TAMPER_TRIGGER_LOW  = 0U,	/**< High trigger */
223 	RTC_TAMPER_TRIGGER_HIGH = 1U,	/**< Low trigger */
224 } rtc_tamper_trigger_t;
225 
226 /**
227   * @brief Tamper sampling frequency
228   */
229 typedef enum {
230 	RTC_TAMPER_SAMPLING_FREQ_32768 = 0U,	/**< RTCCLK / 32768 */
231 	RTC_TAMPER_SAMPLING_FREQ_16384 = 1U,	/**< RTCCLK / 16384 */
232 	RTC_TAMPER_SAMPLING_FREQ_8192  = 2U,	/**< RTCCLK / 8192 */
233 	RTC_TAMPER_SAMPLING_FREQ_4096  = 3U,	/**< RTCCLK / 4096 */
234 	RTC_TAMPER_SAMPLING_FREQ_2048  = 4U,	/**< RTCCLK / 2048 */
235 	RTC_TAMPER_SAMPLING_FREQ_1024  = 5U,	/**< RTCCLK / 1024 */
236 	RTC_TAMPER_SAMPLING_FREQ_512   = 6U,	/**< RTCCLK / 512 */
237 	RTC_TAMPER_SAMPLING_FREQ_256   = 7U,	/**< RTCCLK / 256 */
238 } rtc_tamper_sampling_freq_t;
239 
240 /**
241   * @brief Tamper filter time
242   */
243 typedef enum {
244 	RTC_TAMPER_DURATION_1 = 0U,	/**< Duration 1 sampling */
245 	RTC_TAMPER_DURATION_2 = 1U,	/**< Duration 2 sampling */
246 	RTC_TAMPER_DURATION_4 = 2U,	/**< Duration 4 sampling */
247 	RTC_TAMPER_DURATION_8 = 3U,	/**< Duration 8 sampling */
248 } rtc_tamper_duration_t;
249 
250 /**
251   * @brief Tamper structure
252   */
253 typedef struct {
254 	rtc_tamper_idx_t idx;			/**< Index of tamper */
255 	rtc_tamper_trigger_t trig;		/**< Trigger type */
256 	rtc_tamper_sampling_freq_t freq;	/**< Sampling frequency */
257 	rtc_tamper_duration_t dur;		/**< Filter time */
258 	type_func_t ts;				/**< Enable/Disable trigger time stamp event */
259 } rtc_tamper_t;
260 
261 /**
262   * @brief Wake-up clock
263   */
264 typedef enum {
265 	RTC_WAKEUP_CLOCK_DIV_16   = 0U,	/**< RTCCLK / 16 */
266 	RTC_WAKEUP_CLOCK_DIV_8    = 1U,	/**< RTCCLK / 8 */
267 	RTC_WAKEUP_CLOCK_DIV_4    = 2U,	/**< RTCCLK / 4 */
268 	RTC_WAKEUP_CLOCK_DIV_2    = 3U,	/**< RTCCLK / 2 */
269 	RTC_WAKEUP_CLOCK_1HZ      = 4U,	/**< 1Hz */
270 	RTC_WAKEUP_CLOCK_1HZ_PULS = 6U,	/**< 1Hz and WUT + 65536 */
271 } rtc_wakeup_clock_t;
272 
273 /**
274   * @brief RTC clock output type
275   */
276 typedef enum {
277 	RTC_CLOCK_OUTPUT_32768 = 0U,	/**< 32768Hz */
278 	RTC_CLOCK_OUTPUT_1024  = 1U,	/**< 1024Hz */
279 	RTC_CLOCK_OUTPUT_32    = 2U,	/**< 32Hz */
280 	RTC_CLOCK_OUTPUT_1     = 3U,	/**< 1Hz */
281 	RTC_CLOCK_OUTPUT_CAL_1 = 4U,	/**< 1Hz after calibration */
282 	RTC_CLOCK_OUTPUT_EXA_1 = 5U,	/**< Exact 1Hz */
283 } rtc_clock_output_t;
284 
285 /**
286   * @ Calibration frequency
287   */
288 typedef enum {
289 	RTC_CALI_FREQ_10_SEC = 0U,	/**< Calibrate every 10 seconds */
290 	RTC_CALI_FREQ_20_SEC = 1U,	/**< Calibrate every 20 seconds */
291 	RTC_CALI_FREQ_1_MIN  = 2U,	/**< Calibrate every 1 minute */
292 	RTC_CALI_FREQ_2_MIN  = 3U,	/**< Calibrate every 2 minutes */
293 	RTC_CALI_FREQ_5_MIN  = 4U,	/**< Calibrate every 5 minutes */
294 	RTC_CALI_FREQ_10_MIN = 5U,	/**< Calibrate every 10 minutes */
295 	RTC_CALI_FREQ_20_MIN = 6U,	/**< Calibrate every 20 minutes */
296 	RTC_CALI_FREQ_1_SEC  = 7U,	/**< Calibrate every 1 second */
297 } rtc_cali_freq_t;
298 
299 /**
300   * @brief Temperature compensate type
301   */
302 typedef enum {
303 	RTC_CALI_TC_NONE          = 0U,	/**< Temperature compensate disable */
304 	RTC_CALI_TC_AUTO_BY_HW    = 1U,	/**< Temperature compensate by hardware */
305 	RTC_CALI_TC_AUTO_BY_SF    = 2U,	/**< Temperature compensate by software */
306 	RTC_CALI_TC_AUTO_BY_HW_SF = 3U,	/**< Temperature compensate by hardware, trigger by software */
307 } rtc_cali_tc_t;
308 
309 /**
310   * @ Calculate frequency
311   */
312 typedef enum {
313 	RTC_CALI_CALC_FREQ_10_SEC = 0U,	/**< Calculate every 10 seconds */
314 	RTC_CALI_CALC_FREQ_20_SEC = 1U,	/**< Calculate every 20 seconds */
315 	RTC_CALI_CALC_FREQ_1_MIN  = 2U,	/**< Calculate every 1 minute */
316 	RTC_CALI_CALC_FREQ_2_MIN  = 3U,	/**< Calculate every 2 minutes */
317 	RTC_CALI_CALC_FREQ_5_MIN  = 4U,	/**< Calculate every 5 minutes */
318 	RTC_CALI_CALC_FREQ_10_MIN = 5U,	/**< Calculate every 10 minutes */
319 	RTC_CALI_CALC_FREQ_20_MIN = 6U,	/**< Calculate every 20 minutes */
320 	RTC_CALI_CALC_FREQ_1_HOUR = 7U,	/**< Calculate every 1 hour */
321 } rtc_cali_calc_freq_t;
322 
323 /**
324   * @brief Calibration algorithm
325   */
326 typedef enum {
327 	RTC_CALI_CALC_4 = 0U,	/**< 4-polynomial */
328 	RTC_CALI_CALC_2 = 1U,	/**< 2-parabola */
329 } rtc_cali_calc_t;
330 
331 /**
332   * @brief Calibration structure
333   */
334 typedef struct {
335 	rtc_cali_freq_t cali_freq;	/**< calibrate frequency */
336 	rtc_cali_tc_t tc;		/**< Temperature compensate type */
337 	rtc_cali_calc_freq_t calc_freq;	/**< Calculate frequency */
338 	rtc_cali_calc_t calc;		/**< algorithm */
339 	type_func_t acc;		/**< Enable/Disable decimal accumulate */
340 } rtc_cali_t;
341 
342 /**
343   * @brief Interrupt type
344   */
345 typedef enum {
346 	RTC_IT_SEC  = (1U << 0),	/**< Second */
347 	RTC_IT_MIN  = (1U << 1),	/**< Minute */
348 	RTC_IT_HR   = (1U << 2),	/**< Hour */
349 	RTC_IT_DAY  = (1U << 3),	/**< Day */
350 	RTC_IT_MON  = (1U << 4),	/**< Month */
351 	RTC_IT_YR   = (1U << 5),	/**< Year */
352 	RTC_IT_ALMA = (1U << 8),	/**< Alarm-A */
353 	RTC_IT_ALMB = (1U << 9),	/**< Alarm-B */
354 	RTC_IT_TS   = (1U << 10),	/**< Time stamp */
355 	RTC_IT_TSOV = (1U << 11),	/**< Time stamp overflow */
356 	RTC_IT_TP0  = (1U << 12),	/**< Tamper-0 */
357 	RTC_IT_TP1  = (1U << 13),	/**< Tamper-1 */
358 	RTC_IT_RSC  = (1U << 16),	/**< Synchronous complete */
359 	RTC_IT_SFC  = (1U << 17),	/**< Shift complete */
360 	RTC_IT_WU   = (1U << 18),	/**< Wake-up */
361 	RTC_IT_TCC  = (1U << 24),	/**< Temperature compensate complete */
362 	RTC_IT_TCE  = (1U << 25),	/**< Temperature compensate error */
363 } rtc_it_t;
364 
365 /**
366   * @brief Interrupt flag
367   */
368 typedef enum {
369 	RTC_IF_SEC  = (1U << 0),	/**< Second */
370 	RTC_IF_MIN  = (1U << 1),	/**< Minute */
371 	RTC_IF_HR   = (1U << 2),	/**< Hour */
372 	RTC_IF_DAY  = (1U << 3),	/**< Day */
373 	RTC_IF_MON  = (1U << 4),	/**< Month */
374 	RTC_IF_YR   = (1U << 5),	/**< Year */
375 	RTC_IF_ALMA = (1U << 8),	/**< Alarm-A */
376 	RTC_IF_ALMB = (1U << 9),	/**< Alarm-B */
377 	RTC_IF_TS   = (1U << 10),	/**< Time stamp */
378 	RTC_IF_TSOV = (1U << 11),	/**< Time stamp overflow */
379 	RTC_IF_TP0  = (1U << 12),	/**< Tamper-0 */
380 	RTC_IF_TP1  = (1U << 13),	/**< Tamper-1 */
381 	RTC_IF_RSC  = (1U << 16),	/**< Synchronous complete */
382 	RTC_IF_SFC  = (1U << 17),	/**< Shift complete */
383 	RTC_IF_WU   = (1U << 18),	/**< Wake-up */
384 	RTC_IF_TCC  = (1U << 24),	/**< Temperature compensate complete */
385 	RTC_IF_TCE  = (1U << 25),	/**< Temperature compensate error */
386 } rtc_flag_t;
387 /**
388   * @}
389   */
390 
391 /** @defgroup RTC_Public_Macro RTC Public Macros
392   * @{
393   */
394 #define RTC_UNLOCK()		(WRITE_REG(RTC->WPR, 0x55AAAA55U))
395 #define RTC_LOCK()		(WRITE_REG(RTC->WPR, 0x0U))
396 #define RTC_BY_PASS_ENABLE()			\
397 do {						\
398 	RTC_UNLOCK();				\
399 	SET_BIT(RTC->CON, RTC_CON_SHDBP_MSK);	\
400 	RTC_LOCK();				\
401 } while (0)
402 #define RTC_BY_PASS_DISABLE()			\
403 do {						\
404 	RTC_UNLOCK();				\
405 	CLEAR_BIT(RTC->CON, RTC_CON_SHDBP_MSK);	\
406 	RTC_LOCK();				\
407 } while (0)
408 #define RTC_SUMMER_TIME_ENABLE()		\
409 do {						\
410 	RTC_UNLOCK();				\
411 	SET_BIT(RTC->CON, RTC_CON_ADD1H_MSK);	\
412 	RTC_LOCK();				\
413 } while (0)
414 #define RTC_SUMMER_TIME_DISABLE()		\
415 do {						\
416 	RTC_UNLOCK();				\
417 	CLEAR_BIT(RTC->CON, RTC_CON_ADD1H_MSK);	\
418 	RTC_LOCK();				\
419 } while (0)
420 #define RTC_WINTER_TIME_ENABLE()		\
421 do {						\
422 	RTC_UNLOCK();				\
423 	SET_BIT(RTC->CON, RTC_CON_SUB1H_MSK);	\
424 	RTC_LOCK();				\
425 } while (0)
426 #define RTC_WINTER_TIME_DISABLE()		\
427 do {						\
428 	RTC_UNLOCK();				\
429 	CLEAR_BIT(RTC->CON, RTC_CON_SUB1H_MSK);	\
430 	RTC_LOCK();				\
431 } while (0)
432 /**
433  * @}
434  */
435 
436 /** @defgroup CAN_Private_Macros CAN Private Macros
437   * @{
438   */
439 #define RTC_CALI_UNLOCK()	(WRITE_REG(RTC->CALWPR, 0x699655AAU))
440 #define RTC_CALI_LOCK()		(WRITE_REG(RTC->CALWPR, 0x0U))
441 #define ALARM_MASK_ALL		0x40808080
442 #define RTC_TIMEOUT_VALUE	100
443 
444 #define IS_SHIFT_SUB_SS(x)	((x) < (1U << 15))
445 #define IS_RTC_HOUR_FORMAT(x)	(((x) == RTC_HOUR_FORMAT_24) || \
446                                  ((x) == RTC_HOUR_FORMAT_12))
447 #define IS_RTC_OUTPUT_SEL(x)	(((x) == RTC_OUTPUT_DISABLE) || \
448                                  ((x) == RTC_OUTPUT_ALARM_A) || \
449                                  ((x) == RTC_OUTPUT_ALARM_B) || \
450                                  ((x) == RTC_OUTPUT_WAKEUP))
451 #define IS_RTC_OUTPUT_POLARITY(x)	(((x) == RTC_OUTPUT_POLARITY_HIGH) || \
452                                          ((x) == RTC_OUTPUT_POLARITY_LOW))
453 #define IS_RTC_SOURCE_SEL(x)	(((x) == RTC_SOURCE_LOSC)        || \
454                                  ((x) == RTC_SOURCE_LRC)         || \
455                                  ((x) == RTC_SOURCE_HRC_DIV_1M ) || \
456                                  ((x) == RTC_SOURCE_HOSC_DIV_1M))
457 #define IS_RTC_ALARM(x)		(((x) == RTC_ALARM_A) || \
458                                  ((x) == RTC_ALARM_B))
459 #define IS_RTC_ALARM_SEL(x)	(((x) == RTC_SELECT_DAY) || \
460                                  ((x) == RTC_SELECT_WEEK))
461 #define IS_RTC_ALARM_MASK(x)	(((x) == RTC_ALARM_MASK_NONE)     || \
462                                  ((x) == RTC_ALARM_MASK_WEEK_DAY) || \
463                                  ((x) == RTC_ALARM_MASK_HOUR)     || \
464                                  ((x) == RTC_ALARM_MASK_MINUTE)   || \
465                                  ((x) == RTC_ALARM_MASK_SECOND)   || \
466                                  ((x) == RTC_ALARM_MASK_ALL))
467 #define IS_RTC_ALARM_SS_MASK(x)	(((x) == RTC_ALARM_SS_MASK_NONE)  || \
468                                  ((x) == RTC_ALARM_SS_MASK_14_1)  || \
469                                  ((x) == RTC_ALARM_SS_MASK_14_2)  || \
470                                  ((x) == RTC_ALARM_SS_MASK_14_3)  || \
471                                  ((x) == RTC_ALARM_SS_MASK_14_4)  || \
472                                  ((x) == RTC_ALARM_SS_MASK_14_5)  || \
473                                  ((x) == RTC_ALARM_SS_MASK_14_6)  || \
474                                  ((x) == RTC_ALARM_SS_MASK_14_7)  || \
475                                  ((x) == RTC_ALARM_SS_MASK_14_8)  || \
476                                  ((x) == RTC_ALARM_SS_MASK_14_9)  || \
477                                  ((x) == RTC_ALARM_SS_MASK_14_10) || \
478                                  ((x) == RTC_ALARM_SS_MASK_14_11) || \
479                                  ((x) == RTC_ALARM_SS_MASK_14_12) || \
480                                  ((x) == RTC_ALARM_SS_MASK_14_13) || \
481                                  ((x) == RTC_ALARM_SS_MASK_14)    || \
482                                  ((x) == RTC_ALARM_SS_MASK_ALL))
483 #define IS_RTC_TS_SIGNAL(x)	(((x) == RTC_TS_SIGNAL_SEL_TAMPER0) || \
484                                  ((x) == RTC_TS_SIGNAL_SEL_TAMPER1))
485 #define IS_RTC_TS_STYLE(x)	(((x) == RTC_TS_RISING_EDGE) || \
486                                  ((x) == RTC_TS_FALLING_EDGE))
487 #define IS_RTC_FORMAT(x)	(((x) == RTC_FORMAT_DEC) || \
488                                  ((x) == RTC_FORMAT_BCD))
489 #define IS_RTC_TAMPER(x)	(((x) == RTC_TAMPER_0) || \
490                                  ((x) == RTC_TAMPER_1))
491 #define IS_RTC_TAMPER_TRIGGER(x)	(((x) == RTC_TAMPER_TRIGGER_LOW) || \
492                                          ((x) == RTC_TAMPER_TRIGGER_HIGH))
493 #define IS_RTC_TAMPER_SAMPLING_FREQ(x)	(((x) == RTC_TAMPER_SAMPLING_FREQ_32768) || \
494                                          ((x) == RTC_TAMPER_SAMPLING_FREQ_16384) || \
495                                          ((x) == RTC_TAMPER_SAMPLING_FREQ_8192)  || \
496                                          ((x) == RTC_TAMPER_SAMPLING_FREQ_4096)  || \
497                                          ((x) == RTC_TAMPER_SAMPLING_FREQ_2048)  || \
498                                          ((x) == RTC_TAMPER_SAMPLING_FREQ_1024)  || \
499                                          ((x) == RTC_TAMPER_SAMPLING_FREQ_512)   || \
500                                          ((x) == RTC_TAMPER_SAMPLING_FREQ_256))
501 #define IS_RTC_TAMPER_DURATION(x)	(((x) == RTC_TAMPER_DURATION_1) || \
502                                          ((x) == RTC_TAMPER_DURATION_2) || \
503                                          ((x) == RTC_TAMPER_DURATION_4) || \
504                                          ((x) == RTC_TAMPER_DURATION_8))
505 #define IS_RTC_WAKEUP_CLOCK(x)	(((x) == RTC_WAKEUP_CLOCK_DIV_16) || \
506                                  ((x) == RTC_WAKEUP_CLOCK_DIV_8)  || \
507                                  ((x) == RTC_WAKEUP_CLOCK_DIV_4)  || \
508                                  ((x) == RTC_WAKEUP_CLOCK_DIV_2)  || \
509                                  ((x) == RTC_WAKEUP_CLOCK_1HZ)    || \
510                                  ((x) == RTC_WAKEUP_CLOCK_1HZ_PULS))
511 #define IS_RTC_CLOCK_OUTPUT(x)	(((x) == RTC_CLOCK_OUTPUT_32768) || \
512                                  ((x) == RTC_CLOCK_OUTPUT_1024)  || \
513                                  ((x) == RTC_CLOCK_OUTPUT_32)    || \
514                                  ((x) == RTC_CLOCK_OUTPUT_1)     || \
515                                  ((x) == RTC_CLOCK_OUTPUT_CAL_1) || \
516                                  ((x) == RTC_CLOCK_OUTPUT_EXA_1))
517 #define IS_RTC_CALI_FREQ(x)	(((x) == RTC_CALI_FREQ_10_SEC) || \
518                                  ((x) == RTC_CALI_FREQ_20_SEC) || \
519                                  ((x) == RTC_CALI_FREQ_1_MIN)  || \
520                                  ((x) == RTC_CALI_FREQ_2_MIN)  || \
521                                  ((x) == RTC_CALI_FREQ_5_MIN)  || \
522                                  ((x) == RTC_CALI_FREQ_10_MIN) || \
523                                  ((x) == RTC_CALI_FREQ_20_MIN) || \
524                                  ((x) == RTC_CALI_FREQ_1_SEC))
525 #define IS_RTC_CALI_TC(x)	(((x) == RTC_CALI_TC_NONE)       || \
526                                  ((x) == RTC_CALI_TC_AUTO_BY_HW) || \
527                                  ((x) == RTC_CALI_TC_AUTO_BY_SF) || \
528                                  ((x) == RTC_CALI_TC_AUTO_BY_HW_SF))
529 #define IS_RTC_CALC_FREQ(x)	(((x) == RTC_CALI_CALC_FREQ_10_SEC) || \
530                                  ((x) == RTC_CALI_CALC_FREQ_20_SEC) || \
531                                  ((x) == RTC_CALI_CALC_FREQ_1_MIN)  || \
532                                  ((x) == RTC_CALI_CALC_FREQ_2_MIN)  || \
533                                  ((x) == RTC_CALI_CALC_FREQ_5_MIN)  || \
534                                  ((x) == RTC_CALI_CALC_FREQ_10_MIN) || \
535                                  ((x) == RTC_CALI_CALC_FREQ_20_MIN) || \
536                                  ((x) == RTC_CALI_CALC_FREQ_1_HOUR))
537 #define IS_RTC_CALI_CALC(x)	(((x) == RTC_CALI_CALC_4) || \
538                                  ((x) == RTC_CALI_CALC_2))
539 #define IS_RTC_IT(x)		(((x) == RTC_IT_SEC)  || \
540                                  ((x) == RTC_IT_MIN)  || \
541                                  ((x) == RTC_IT_HR)   || \
542                                  ((x) == RTC_IT_DAY)  || \
543                                  ((x) == RTC_IT_MON)  || \
544                                  ((x) == RTC_IT_YR)   || \
545                                  ((x) == RTC_IT_ALMA) || \
546                                  ((x) == RTC_IT_ALMB) || \
547                                  ((x) == RTC_IT_TS)   || \
548                                  ((x) == RTC_IT_TSOV) || \
549                                  ((x) == RTC_IT_TP0)  || \
550                                  ((x) == RTC_IT_TP1)  || \
551                                  ((x) == RTC_IT_RSC)  || \
552                                  ((x) == RTC_IT_SFC)  || \
553                                  ((x) == RTC_IT_WU)   || \
554                                  ((x) == RTC_IT_TCC)  || \
555                                  ((x) == RTC_IT_TCE))
556 #define IS_RTC_IF(x)		(((x) == RTC_IF_SEC)  || \
557                                  ((x) == RTC_IF_MIN)  || \
558                                  ((x) == RTC_IF_HR)   || \
559                                  ((x) == RTC_IF_DAY)  || \
560                                  ((x) == RTC_IF_MON)  || \
561                                  ((x) == RTC_IF_YR)   || \
562                                  ((x) == RTC_IF_ALMA) || \
563                                  ((x) == RTC_IF_ALMB) || \
564                                  ((x) == RTC_IF_TS)   || \
565                                  ((x) == RTC_IF_TSOV) || \
566                                  ((x) == RTC_IF_TP0)  || \
567                                  ((x) == RTC_IF_TP1)  || \
568                                  ((x) == RTC_IF_RSC)  || \
569                                  ((x) == RTC_IF_SFC)  || \
570                                  ((x) == RTC_IF_WU)   || \
571                                  ((x) == RTC_IF_TCC)  || \
572                                  ((x) == RTC_IF_TCE))
573 #define IS_RTC_SECOND(x)	((x) < 60)
574 #define IS_RTC_MINUTE(x)	((x) < 60)
575 #define IS_RTC_HOUR(x)		((x) < 24)
576 #define IS_RTC_DAY(x)		(((x) > 0) && ((x) < 32))
577 #define IS_RTC_MONTH(x)		(((x) > 0) && ((x) < 13))
578 #define IS_RTC_YEAR(x)		((x) < 100)
579 /**
580   * @}
581   */
582 
583 /** @addtogroup RTC_Public_Functions
584   * @{
585   */
586 
587 /** @addtogroup RTC_Public_Functions_Group1
588   *  @{
589   */
590 /* Initialization functions */
591 void ald_rtc_reset(void);
592 void ald_rtc_init(rtc_init_t *init);
593 void ald_rtc_source_select(rtc_source_sel_t sel);
594 /**
595   * @}
596   */
597 /** @addtogroup RTC_Public_Functions_Group2
598   * @{
599   */
600 /* Time and date operation functions */
601 ald_status_t ald_rtc_set_time(rtc_time_t *time, rtc_format_t format);
602 ald_status_t ald_rtc_set_date(rtc_date_t *date, rtc_format_t format);
603 void ald_rtc_get_time(rtc_time_t *time, rtc_format_t format);
604 void ald_rtc_get_date(rtc_date_t *date, rtc_format_t format);
605 int32_t ald_rtc_get_date_time(rtc_date_t *date, rtc_time_t *time, rtc_format_t format);
606 /**
607   * @}
608   */
609 /** @addtogroup RTC_Public_Functions_Group3
610   * @{
611   */
612 /* Alarm functions */
613 void ald_rtc_set_alarm(rtc_alarm_t *alarm, rtc_format_t format);
614 void ald_rtc_get_alarm(rtc_alarm_t *alarm, rtc_format_t format);
615 /**
616   * @}
617   */
618 /** @addtogroup RTC_Public_Functions_Group4
619   * @{
620   */
621 /* Time stamp functions */
622 void ald_rtc_set_time_stamp(rtc_ts_signal_sel_t sel, rtc_ts_trigger_style_t style);
623 void ald_rtc_cancel_time_stamp(void);
624 void ald_rtc_get_time_stamp(rtc_time_t *ts_time, rtc_date_t *ts_date, rtc_format_t format);
625 /**
626   * @}
627   */
628 /** @addtogroup RTC_Public_Functions_Group5
629   * @{
630   */
631 /* Tamper functions */
632 void ald_rtc_set_tamper(rtc_tamper_t *tamper);
633 void ald_rtc_cancel_tamper(rtc_tamper_idx_t idx);
634 /**
635   * @}
636   */
637 /** @addtogroup RTC_Public_Functions_Group6
638   * @{
639   */
640 /* Wakeup functions */
641 void ald_rtc_set_wakeup(rtc_wakeup_clock_t clock, uint16_t value);
642 void ald_rtc_cancel_wakeup(void);
643 uint16_t ald_rtc_get_wakeup_timer_value(void);
644 /**
645   * @}
646   */
647 /** @addtogroup RTC_Public_Functions_Group7
648   * @{
649   */
650 /* Clock output functions */
651 ald_status_t ald_rtc_set_clock_output(rtc_clock_output_t clock);
652 void ald_rtc_cancel_clock_output(void);
653 /**
654   * @}
655   */
656 /** @addtogroup RTC_Public_Functions_Group8
657   * @{
658   */
659 /* Control functions */
660 void ald_rtc_interrupt_config(rtc_it_t it, type_func_t state);
661 void ald_rtc_alarm_cmd(rtc_alarm_idx_t idx, type_func_t state);
662 ald_status_t ald_rtc_set_shift(type_func_t add_1s, uint16_t sub_ss);
663 void ald_rtc_set_cali(rtc_cali_t *config);
664 void ald_rtc_cancel_cali(void);
665 ald_status_t ald_rtc_get_cali_status(void);
666 void ald_rtc_write_temp(uint16_t temp);
667 it_status_t ald_rtc_get_it_status(rtc_it_t it);
668 flag_status_t ald_rtc_get_flag_status(rtc_flag_t flag);
669 void ald_rtc_clear_flag_status(rtc_flag_t flag);
670 /**
671   * @}
672   */
673 /**
674   * @}
675   */
676 /**
677   * @}
678   */
679 /**
680   * @}
681   */
682 #ifdef __cplusplus
683 }
684 #endif
685 #endif
686