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