]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_rtc.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F4 / stm32f4xx_hal_rtc.h
1 /**
2   ******************************************************************************
3   * @file    stm32f4xx_hal_rtc.h
4   * @author  MCD Application Team
5   * @version V1.1.0
6   * @date    19-June-2014
7   * @brief   Header file of RTC HAL module.
8   ******************************************************************************
9   * @attention
10   *
11   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
12   *
13   * Redistribution and use in source and binary forms, with or without modification,
14   * are permitted provided that the following conditions are met:
15   *   1. Redistributions of source code must retain the above copyright notice,
16   *      this list of conditions and the following disclaimer.
17   *   2. Redistributions in binary form must reproduce the above copyright notice,
18   *      this list of conditions and the following disclaimer in the documentation
19   *      and/or other materials provided with the distribution.
20   *   3. Neither the name of STMicroelectronics nor the names of its contributors
21   *      may be used to endorse or promote products derived from this software
22   *      without specific prior written permission.
23   *
24   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34   *
35   ******************************************************************************
36   */ 
37
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F4xx_HAL_RTC_H
40 #define __STM32F4xx_HAL_RTC_H
41
42 #ifdef __cplusplus
43  extern "C" {
44 #endif
45
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f4xx_hal_def.h"
48
49 /** @addtogroup STM32F4xx_HAL_Driver
50   * @{
51   */
52
53 /** @addtogroup RTC
54   * @{
55   */ 
56
57 /* Exported types ------------------------------------------------------------*/ 
58 /** 
59   * @brief  HAL State structures definition  
60   */ 
61 typedef enum
62 {
63   HAL_RTC_STATE_RESET             = 0x00,  /*!< RTC not yet initialized or disabled */
64   HAL_RTC_STATE_READY             = 0x01,  /*!< RTC initialized and ready for use   */
65   HAL_RTC_STATE_BUSY              = 0x02,  /*!< RTC process is ongoing              */     
66   HAL_RTC_STATE_TIMEOUT           = 0x03,  /*!< RTC timeout state                   */  
67   HAL_RTC_STATE_ERROR             = 0x04   /*!< RTC error state                     */      
68                                                                         
69 }HAL_RTCStateTypeDef;
70
71 /** 
72   * @brief  RTC Configuration Structure definition  
73   */
74 typedef struct
75 {
76   uint32_t HourFormat;      /*!< Specifies the RTC Hour Format.
77                                  This parameter can be a value of @ref RTC_Hour_Formats */         
78
79   uint32_t AsynchPrediv;    /*!< Specifies the RTC Asynchronous Predivider value.
80                                  This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7F */        
81                                
82   uint32_t SynchPrediv;     /*!< Specifies the RTC Synchronous Predivider value.
83                                  This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7FFF */   
84   
85   uint32_t OutPut;          /*!< Specifies which signal will be routed to the RTC output.   
86                                  This parameter can be a value of @ref RTC_Output_selection_Definitions */      
87   
88   uint32_t OutPutPolarity;  /*!< Specifies the polarity of the output signal.  
89                                  This parameter can be a value of @ref RTC_Output_Polarity_Definitions */ 
90   
91   uint32_t OutPutType;      /*!< Specifies the RTC Output Pin mode.   
92                                  This parameter can be a value of @ref RTC_Output_Type_ALARM_OUT */             
93 }RTC_InitTypeDef;
94
95 /** 
96   * @brief  RTC Time structure definition  
97   */
98 typedef struct
99 {
100   uint8_t Hours;            /*!< Specifies the RTC Time Hour.
101                                  This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected.
102                                  This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected  */
103
104   uint8_t Minutes;          /*!< Specifies the RTC Time Minutes.
105                                  This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
106   
107   uint8_t Seconds;          /*!< Specifies the RTC Time Seconds.
108                                  This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
109   
110   uint32_t SubSeconds;      /*!< Specifies the RTC Time SubSeconds.
111                                  This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
112
113   uint8_t TimeFormat;       /*!< Specifies the RTC AM/PM Time.
114                                  This parameter can be a value of @ref RTC_AM_PM_Definitions */ 
115   
116   uint32_t DayLightSaving;  /*!< Specifies DayLight Save Operation.
117                                  This parameter can be a value of @ref RTC_DayLightSaving_Definitions */
118   
119   uint32_t StoreOperation;  /*!< Specifies RTC_StoreOperation value to be written in the BCK bit 
120                                  in CR register to store the operation.
121                                  This parameter can be a value of @ref RTC_StoreOperation_Definitions */
122 }RTC_TimeTypeDef; 
123   
124 /** 
125   * @brief  RTC Date structure definition  
126   */
127 typedef struct
128 {
129   uint8_t WeekDay;  /*!< Specifies the RTC Date WeekDay.
130                          This parameter can be a value of @ref RTC_WeekDay_Definitions */
131   
132   uint8_t Month;    /*!< Specifies the RTC Date Month (in BCD format).
133                          This parameter can be a value of @ref RTC_Month_Date_Definitions */
134
135   uint8_t Date;     /*!< Specifies the RTC Date.
136                          This parameter must be a number between Min_Data = 1 and Max_Data = 31 */
137   
138   uint8_t Year;     /*!< Specifies the RTC Date Year.
139                          This parameter must be a number between Min_Data = 0 and Max_Data = 99 */
140                         
141 }RTC_DateTypeDef;
142
143 /** 
144   * @brief  RTC Alarm structure definition  
145   */
146 typedef struct
147 {
148   RTC_TimeTypeDef AlarmTime;     /*!< Specifies the RTC Alarm Time members */
149     
150   uint32_t AlarmMask;            /*!< Specifies the RTC Alarm Masks.
151                                       This parameter can be a value of @ref RTC_AlarmMask_Definitions */
152   
153   uint32_t AlarmSubSecondMask;   /*!< Specifies the RTC Alarm SubSeconds Masks.
154                                       This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */                                   
155
156   uint32_t AlarmDateWeekDaySel;  /*!< Specifies the RTC Alarm is on Date or WeekDay.
157                                      This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */
158   
159   uint8_t AlarmDateWeekDay;      /*!< Specifies the RTC Alarm Date/WeekDay.
160                                       If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range.
161                                       If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */
162                                                                      
163   uint32_t Alarm;                /*!< Specifies the alarm .
164                                       This parameter can be a value of @ref RTC_Alarms_Definitions */                            
165 }RTC_AlarmTypeDef;
166
167 /** 
168   * @brief  Time Handle Structure definition  
169   */ 
170 typedef struct
171 {
172   RTC_TypeDef                 *Instance;  /*!< Register base address    */
173    
174   RTC_InitTypeDef             Init;       /*!< RTC required parameters  */ 
175   
176   HAL_LockTypeDef             Lock;       /*!< RTC locking object       */
177   
178   __IO HAL_RTCStateTypeDef    State;      /*!< Time communication state */
179     
180 }RTC_HandleTypeDef;
181
182 /* Exported constants --------------------------------------------------------*/
183 /** @defgroup RTC_Exported_Constants
184   * @{
185   */ 
186
187 /* Masks Definition */
188 #define RTC_TR_RESERVED_MASK    ((uint32_t)0x007F7F7F)
189 #define RTC_DR_RESERVED_MASK    ((uint32_t)0x00FFFF3F) 
190 #define RTC_INIT_MASK           ((uint32_t)0xFFFFFFFF)  
191 #define RTC_RSF_MASK            ((uint32_t)0xFFFFFF5F)
192 #define RTC_FLAGS_MASK          ((uint32_t)(RTC_FLAG_TSOVF | RTC_FLAG_TSF | RTC_FLAG_WUTF | \
193                                             RTC_FLAG_ALRBF | RTC_FLAG_ALRAF | RTC_FLAG_INITF | \
194                                             RTC_FLAG_RSF | RTC_FLAG_INITS | RTC_FLAG_WUTWF | \
195                                             RTC_FLAG_ALRBWF | RTC_FLAG_ALRAWF | RTC_FLAG_TAMP1F | \
196                                             RTC_FLAG_RECALPF | RTC_FLAG_SHPF))
197
198 #define RTC_TIMEOUT_VALUE       1000
199  
200 /** @defgroup RTC_Hour_Formats 
201   * @{
202   */ 
203 #define RTC_HOURFORMAT_24              ((uint32_t)0x00000000)
204 #define RTC_HOURFORMAT_12              ((uint32_t)0x00000040)
205
206 #define IS_RTC_HOUR_FORMAT(FORMAT)     (((FORMAT) == RTC_HOURFORMAT_12) || \
207                                         ((FORMAT) == RTC_HOURFORMAT_24))
208 /**
209   * @}
210   */ 
211   
212 /** @defgroup RTC_Output_selection_Definitions 
213   * @{
214   */ 
215 #define RTC_OUTPUT_DISABLE             ((uint32_t)0x00000000)
216 #define RTC_OUTPUT_ALARMA              ((uint32_t)0x00200000)
217 #define RTC_OUTPUT_ALARMB              ((uint32_t)0x00400000)
218 #define RTC_OUTPUT_WAKEUP              ((uint32_t)0x00600000)
219  
220 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \
221                                ((OUTPUT) == RTC_OUTPUT_ALARMA)  || \
222                                ((OUTPUT) == RTC_OUTPUT_ALARMB)  || \
223                                ((OUTPUT) == RTC_OUTPUT_WAKEUP))
224 /**
225   * @}
226   */ 
227
228 /** @defgroup RTC_Output_Polarity_Definitions 
229   * @{
230   */ 
231 #define RTC_OUTPUT_POLARITY_HIGH       ((uint32_t)0x00000000)
232 #define RTC_OUTPUT_POLARITY_LOW        ((uint32_t)0x00100000)
233
234 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \
235                                 ((POL) == RTC_OUTPUT_POLARITY_LOW))
236 /**
237   * @}
238   */ 
239
240 /** @defgroup RTC_Output_Type_ALARM_OUT 
241   * @{
242   */ 
243 #define RTC_OUTPUT_TYPE_OPENDRAIN      ((uint32_t)0x00000000)
244 #define RTC_OUTPUT_TYPE_PUSHPULL       ((uint32_t)0x00040000)
245
246 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \
247                                   ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL))
248
249 /**
250   * @}
251   */ 
252
253 /** @defgroup RTC_Asynchronous_Predivider 
254   * @{
255   */ 
256 #define IS_RTC_ASYNCH_PREDIV(PREDIV)   ((PREDIV) <= (uint32_t)0x7F) 
257 /**
258   * @}
259   */ 
260
261
262 /** @defgroup RTC_Synchronous_Predivider 
263   * @{
264   */ 
265 #define IS_RTC_SYNCH_PREDIV(PREDIV)    ((PREDIV) <= (uint32_t)0x7FFF)
266 /**
267   * @}
268   */ 
269
270 /** @defgroup RTC_Time_Definitions 
271   * @{
272   */ 
273 #define IS_RTC_HOUR12(HOUR)            (((HOUR) > (uint32_t)0) && ((HOUR) <= (uint32_t)12))
274 #define IS_RTC_HOUR24(HOUR)            ((HOUR) <= (uint32_t)23)
275 #define IS_RTC_MINUTES(MINUTES)        ((MINUTES) <= (uint32_t)59)
276 #define IS_RTC_SECONDS(SECONDS)        ((SECONDS) <= (uint32_t)59)
277 /**
278   * @}
279   */ 
280
281 /** @defgroup RTC_AM_PM_Definitions 
282   * @{
283   */ 
284 #define RTC_HOURFORMAT12_AM            ((uint8_t)0x00)
285 #define RTC_HOURFORMAT12_PM            ((uint8_t)0x40)
286
287 #define IS_RTC_HOURFORMAT12(PM)  (((PM) == RTC_HOURFORMAT12_AM) || ((PM) == RTC_HOURFORMAT12_PM))
288 /**
289   * @}
290   */ 
291
292 /** @defgroup RTC_DayLightSaving_Definitions 
293   * @{
294   */ 
295 #define RTC_DAYLIGHTSAVING_SUB1H       ((uint32_t)0x00020000)
296 #define RTC_DAYLIGHTSAVING_ADD1H       ((uint32_t)0x00010000)
297 #define RTC_DAYLIGHTSAVING_NONE        ((uint32_t)0x00000000)
298
299 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \
300                                       ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \
301                                       ((SAVE) == RTC_DAYLIGHTSAVING_NONE))
302 /**
303   * @}
304   */
305
306 /** @defgroup RTC_StoreOperation_Definitions 
307   * @{
308   */ 
309 #define RTC_STOREOPERATION_RESET        ((uint32_t)0x00000000)
310 #define RTC_STOREOPERATION_SET          ((uint32_t)0x00040000)
311
312 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \
313                                            ((OPERATION) == RTC_STOREOPERATION_SET))
314 /**
315   * @}
316   */
317
318 /** @defgroup RTC_Input_parameter_format_definitions 
319   * @{
320   */ 
321 #define FORMAT_BIN                      ((uint32_t)0x000000000)
322 #define FORMAT_BCD                      ((uint32_t)0x000000001)
323
324 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == FORMAT_BIN) || ((FORMAT) == FORMAT_BCD))
325 /**
326   * @}
327   */
328
329 /** @defgroup RTC_Year_Date_Definitions 
330   * @{
331   */ 
332 #define IS_RTC_YEAR(YEAR)              ((YEAR) <= (uint32_t)99)
333 /**
334   * @}
335   */ 
336
337 /** @defgroup RTC_Month_Date_Definitions 
338   * @{
339   */ 
340
341 /* Coded in BCD format */
342 #define RTC_MONTH_JANUARY              ((uint8_t)0x01)
343 #define RTC_MONTH_FEBRUARY             ((uint8_t)0x02)
344 #define RTC_MONTH_MARCH                ((uint8_t)0x03)
345 #define RTC_MONTH_APRIL                ((uint8_t)0x04)
346 #define RTC_MONTH_MAY                  ((uint8_t)0x05)
347 #define RTC_MONTH_JUNE                 ((uint8_t)0x06)
348 #define RTC_MONTH_JULY                 ((uint8_t)0x07)
349 #define RTC_MONTH_AUGUST               ((uint8_t)0x08)
350 #define RTC_MONTH_SEPTEMBER            ((uint8_t)0x09)
351 #define RTC_MONTH_OCTOBER              ((uint8_t)0x10)
352 #define RTC_MONTH_NOVEMBER             ((uint8_t)0x11)
353 #define RTC_MONTH_DECEMBER             ((uint8_t)0x12)
354
355 #define IS_RTC_MONTH(MONTH)            (((MONTH) >= (uint32_t)1) && ((MONTH) <= (uint32_t)12))
356 #define IS_RTC_DATE(DATE)              (((DATE) >= (uint32_t)1) && ((DATE) <= (uint32_t)31))
357 /**
358   * @}
359   */ 
360
361 /** @defgroup RTC_WeekDay_Definitions 
362   * @{
363   */   
364 #define RTC_WEEKDAY_MONDAY             ((uint8_t)0x01)
365 #define RTC_WEEKDAY_TUESDAY            ((uint8_t)0x02)
366 #define RTC_WEEKDAY_WEDNESDAY          ((uint8_t)0x03)
367 #define RTC_WEEKDAY_THURSDAY           ((uint8_t)0x04)
368 #define RTC_WEEKDAY_FRIDAY             ((uint8_t)0x05)
369 #define RTC_WEEKDAY_SATURDAY           ((uint8_t)0x06)
370 #define RTC_WEEKDAY_SUNDAY             ((uint8_t)0x07)
371
372 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY)    || \
373                                  ((WEEKDAY) == RTC_WEEKDAY_TUESDAY)   || \
374                                  ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
375                                  ((WEEKDAY) == RTC_WEEKDAY_THURSDAY)  || \
376                                  ((WEEKDAY) == RTC_WEEKDAY_FRIDAY)    || \
377                                  ((WEEKDAY) == RTC_WEEKDAY_SATURDAY)  || \
378                                  ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
379 /**
380   * @}
381   */ 
382                                     
383 /** @defgroup RTC_Alarm_Definitions
384   * @{
385   */ 
386 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) >(uint32_t) 0) && ((DATE) <= (uint32_t)31))
387 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY)    || \
388                                                     ((WEEKDAY) == RTC_WEEKDAY_TUESDAY)   || \
389                                                     ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
390                                                     ((WEEKDAY) == RTC_WEEKDAY_THURSDAY)  || \
391                                                     ((WEEKDAY) == RTC_WEEKDAY_FRIDAY)    || \
392                                                     ((WEEKDAY) == RTC_WEEKDAY_SATURDAY)  || \
393                                                     ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
394 /**
395   * @}
396   */ 
397
398
399 /** @defgroup RTC_AlarmDateWeekDay_Definitions 
400   * @{
401   */ 
402 #define RTC_ALARMDATEWEEKDAYSEL_DATE      ((uint32_t)0x00000000)
403 #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY   ((uint32_t)0x40000000)
404
405 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \
406                                             ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY))
407 /**
408   * @}
409   */ 
410
411
412 /** @defgroup RTC_AlarmMask_Definitions 
413   * @{
414   */ 
415 #define RTC_ALARMMASK_NONE                ((uint32_t)0x00000000)
416 #define RTC_ALARMMASK_DATEWEEKDAY         RTC_ALRMAR_MSK4
417 #define RTC_ALARMMASK_HOURS               RTC_ALRMAR_MSK3
418 #define RTC_ALARMMASK_MINUTES             RTC_ALRMAR_MSK2
419 #define RTC_ALARMMASK_SECONDS             RTC_ALRMAR_MSK1
420 #define RTC_ALARMMASK_ALL                 ((uint32_t)0x80808080)
421
422 #define IS_ALARM_MASK(MASK)  (((MASK) & 0x7F7F7F7F) == (uint32_t)RESET)
423 /**
424   * @}
425   */ 
426
427 /** @defgroup RTC_Alarms_Definitions 
428   * @{
429   */ 
430 #define RTC_ALARM_A                       RTC_CR_ALRAE
431 #define RTC_ALARM_B                       RTC_CR_ALRBE
432
433 #define IS_ALARM(ALARM)      (((ALARM) == RTC_ALARM_A) || ((ALARM) == RTC_ALARM_B))
434 /**
435   * @}
436   */ 
437
438 /** @defgroup RTC_Alarm_Sub_Seconds_Value
439   * @{
440   */ 
441 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= (uint32_t)0x00007FFF)
442 /**
443   * @}
444   */
445
446   /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions
447   * @{
448   */ 
449 #define RTC_ALARMSUBSECONDMASK_ALL         ((uint32_t)0x00000000)  /*!< All Alarm SS fields are masked. 
450                                                                         There is no comparison on sub seconds 
451                                                                         for Alarm */
452 #define RTC_ALARMSUBSECONDMASK_SS14_1      ((uint32_t)0x01000000)  /*!< SS[14:1] are don't care in Alarm 
453                                                                         comparison. Only SS[0] is compared.    */
454 #define RTC_ALARMSUBSECONDMASK_SS14_2      ((uint32_t)0x02000000)  /*!< SS[14:2] are don't care in Alarm 
455                                                                         comparison. Only SS[1:0] are compared  */
456 #define RTC_ALARMSUBSECONDMASK_SS14_3      ((uint32_t)0x03000000)  /*!< SS[14:3] are don't care in Alarm 
457                                                                         comparison. Only SS[2:0] are compared  */
458 #define RTC_ALARMSUBSECONDMASK_SS14_4      ((uint32_t)0x04000000)  /*!< SS[14:4] are don't care in Alarm 
459                                                                         comparison. Only SS[3:0] are compared  */
460 #define RTC_ALARMSUBSECONDMASK_SS14_5      ((uint32_t)0x05000000)  /*!< SS[14:5] are don't care in Alarm 
461                                                                         comparison. Only SS[4:0] are compared  */
462 #define RTC_ALARMSUBSECONDMASK_SS14_6      ((uint32_t)0x06000000)  /*!< SS[14:6] are don't care in Alarm 
463                                                                         comparison. Only SS[5:0] are compared  */
464 #define RTC_ALARMSUBSECONDMASK_SS14_7      ((uint32_t)0x07000000)  /*!< SS[14:7] are don't care in Alarm 
465                                                                         comparison. Only SS[6:0] are compared  */
466 #define RTC_ALARMSUBSECONDMASK_SS14_8      ((uint32_t)0x08000000)  /*!< SS[14:8] are don't care in Alarm 
467                                                                         comparison. Only SS[7:0] are compared  */
468 #define RTC_ALARMSUBSECONDMASK_SS14_9      ((uint32_t)0x09000000)  /*!< SS[14:9] are don't care in Alarm 
469                                                                         comparison. Only SS[8:0] are compared  */
470 #define RTC_ALARMSUBSECONDMASK_SS14_10     ((uint32_t)0x0A000000)  /*!< SS[14:10] are don't care in Alarm 
471                                                                         comparison. Only SS[9:0] are compared  */
472 #define RTC_ALARMSUBSECONDMASK_SS14_11     ((uint32_t)0x0B000000)  /*!< SS[14:11] are don't care in Alarm 
473                                                                         comparison. Only SS[10:0] are compared */
474 #define RTC_ALARMSUBSECONDMASK_SS14_12     ((uint32_t)0x0C000000)  /*!< SS[14:12] are don't care in Alarm 
475                                                                         comparison.Only SS[11:0] are compared  */
476 #define RTC_ALARMSUBSECONDMASK_SS14_13     ((uint32_t)0x0D000000)  /*!< SS[14:13] are don't care in Alarm 
477                                                                         comparison. Only SS[12:0] are compared */
478 #define RTC_ALARMSUBSECONDMASK_SS14        ((uint32_t)0x0E000000)  /*!< SS[14] is don't care in Alarm 
479                                                                         comparison.Only SS[13:0] are compared  */
480 #define RTC_ALARMSUBSECONDMASK_None        ((uint32_t)0x0F000000)  /*!< SS[14:0] are compared and must match 
481                                                                         to activate alarm. */
482
483 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK)   (((MASK) == RTC_ALARMSUBSECONDMASK_ALL) || \
484                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_1) || \
485                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_2) || \
486                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_3) || \
487                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_4) || \
488                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_5) || \
489                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_6) || \
490                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_7) || \
491                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_8) || \
492                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_9) || \
493                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_10) || \
494                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_11) || \
495                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_12) || \
496                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_13) || \
497                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14) || \
498                                               ((MASK) == RTC_ALARMSUBSECONDMASK_None))
499 /**
500   * @}
501   */   
502
503 /** @defgroup RTC_Interrupts_Definitions 
504   * @{
505   */ 
506 #define RTC_IT_TS                         ((uint32_t)0x00008000)
507 #define RTC_IT_WUT                        ((uint32_t)0x00004000)
508 #define RTC_IT_ALRB                       ((uint32_t)0x00002000)
509 #define RTC_IT_ALRA                       ((uint32_t)0x00001000)
510 #define RTC_IT_TAMP                       ((uint32_t)0x00000004) /* Used only to Enable the Tamper Interrupt */
511 #define RTC_IT_TAMP1                      ((uint32_t)0x00020000)
512 #define RTC_IT_TAMP2                      ((uint32_t)0x00040000)
513 /**
514   * @}
515   */
516
517 /** @defgroup RTC_Flags_Definitions 
518   * @{
519   */ 
520 #define RTC_FLAG_RECALPF                  ((uint32_t)0x00010000)
521 #define RTC_FLAG_TAMP2F                   ((uint32_t)0x00004000)
522 #define RTC_FLAG_TAMP1F                   ((uint32_t)0x00002000)
523 #define RTC_FLAG_TSOVF                    ((uint32_t)0x00001000)
524 #define RTC_FLAG_TSF                      ((uint32_t)0x00000800)
525 #define RTC_FLAG_WUTF                     ((uint32_t)0x00000400)
526 #define RTC_FLAG_ALRBF                    ((uint32_t)0x00000200)
527 #define RTC_FLAG_ALRAF                    ((uint32_t)0x00000100)
528 #define RTC_FLAG_INITF                    ((uint32_t)0x00000040)
529 #define RTC_FLAG_RSF                      ((uint32_t)0x00000020)
530 #define RTC_FLAG_INITS                    ((uint32_t)0x00000010)
531 #define RTC_FLAG_SHPF                     ((uint32_t)0x00000008)
532 #define RTC_FLAG_WUTWF                    ((uint32_t)0x00000004)
533 #define RTC_FLAG_ALRBWF                   ((uint32_t)0x00000002)
534 #define RTC_FLAG_ALRAWF                   ((uint32_t)0x00000001)
535 /**
536   * @}
537   */
538
539 /**
540   * @}
541   */ 
542   
543 /* Exported macro ------------------------------------------------------------*/
544
545 /** @brief Reset RTC handle state
546   * @param  __HANDLE__: specifies the RTC handle.
547   * @retval None
548   */
549 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET)
550
551 /**
552   * @brief  Disable the write protection for RTC registers.
553   * @param  __HANDLE__: specifies the RTC handle.
554   * @retval None
555   */
556 #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__)             \
557                         do{                                       \
558                             (__HANDLE__)->Instance->WPR = 0xCA;   \
559                             (__HANDLE__)->Instance->WPR = 0x53;   \
560                           } while(0)
561
562 /**
563   * @brief  Enable the write protection for RTC registers.
564   * @param  __HANDLE__: specifies the RTC handle.
565   * @retval None
566   */
567 #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__)              \
568                         do{                                       \
569                             (__HANDLE__)->Instance->WPR = 0xFF;   \
570                           } while(0)                            
571  
572 /**
573   * @brief  Enable the RTC ALARMA peripheral.
574   * @param  __HANDLE__: specifies the RTC handle.
575   * @retval None
576   */
577 #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__)                           ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE))
578
579 /**
580   * @brief  Disable the RTC ALARMA peripheral.
581   * @param  __HANDLE__: specifies the RTC handle.
582   * @retval None
583   */
584 #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__)                          ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE))
585
586 /**
587   * @brief  Enable the RTC ALARMB peripheral.
588   * @param  __HANDLE__: specifies the RTC handle.
589   * @retval None
590   */
591 #define __HAL_RTC_ALARMB_ENABLE(__HANDLE__)                           ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE))
592
593 /**
594   * @brief  Disable the RTC ALARMB peripheral.
595   * @param  __HANDLE__: specifies the RTC handle.
596   * @retval None
597   */
598 #define __HAL_RTC_ALARMB_DISABLE(__HANDLE__)                          ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE))
599
600 /**
601   * @brief  Enable the RTC Alarm interrupt.
602   * @param  __HANDLE__: specifies the RTC handle.
603   * @param  __INTERRUPT__: specifies the RTC Alarm interrupt sources to be enabled or disabled. 
604   *          This parameter can be any combination of the following values:
605   *             @arg RTC_IT_ALRA: Alarm A interrupt
606   *             @arg RTC_IT_ALRB: Alarm B interrupt  
607   * @retval None
608   */   
609 #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__)          ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
610
611 /**
612   * @brief  Disable the RTC Alarm interrupt.
613   * @param  __HANDLE__: specifies the RTC handle.
614   * @param  __INTERRUPT__: specifies the RTC Alarm interrupt sources to be enabled or disabled. 
615   *         This parameter can be any combination of the following values:
616   *            @arg RTC_IT_ALRA: Alarm A interrupt
617   *            @arg RTC_IT_ALRB: Alarm B interrupt  
618   * @retval None
619   */
620 #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__)         ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
621
622 /**
623   * @brief  Check whether the specified RTC Alarm interrupt has occurred or not.
624   * @param  __HANDLE__: specifies the RTC handle.
625   * @param  __FLAG__: specifies the RTC Alarm interrupt sources to be enabled or disabled.
626   *         This parameter can be:
627   *            @arg RTC_IT_ALRA: Alarm A interrupt
628   *            @arg RTC_IT_ALRB: Alarm B interrupt  
629   * @retval None
630   */
631 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __FLAG__)                  ((((((__HANDLE__)->Instance->ISR)& ((__FLAG__)>> 4)) & 0x0000FFFF) != RESET)? SET : RESET)
632
633 /**
634   * @brief  Get the selected RTC Alarm's flag status.
635   * @param  __HANDLE__: specifies the RTC handle.
636   * @param  __FLAG__: specifies the RTC Alarm Flag sources to be enabled or disabled.
637   *         This parameter can be:
638   *            @arg RTC_FLAG_ALRAF
639   *            @arg RTC_FLAG_ALRBF
640   *            @arg RTC_FLAG_ALRAWF     
641   *            @arg RTC_FLAG_ALRBWF    
642   * @retval None
643   */
644 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__)                (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != RESET)? SET : RESET)
645
646 /**
647   * @brief  Clear the RTC Alarm's pending flags.
648   * @param  __HANDLE__: specifies the RTC handle.
649   * @param  __FLAG__: specifies the RTC Alarm Flag sources to be enabled or disabled.
650   *          This parameter can be:
651   *             @arg RTC_FLAG_ALRAF
652   *             @arg RTC_FLAG_ALRBF 
653   * @retval None
654   */
655 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__)                  ((__HANDLE__)->Instance->ISR) = (~(((__FLAG__) | RTC_ISR_INIT)& 0x0000FFFF)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
656   
657   
658 #define RTC_EXTI_LINE_ALARM_EVENT             ((uint32_t)0x00020000)  /*!< External interrupt line 17 Connected to the RTC Alarm event */
659 #define RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT  ((uint32_t)0x00200000)  /*!< External interrupt line 21 Connected to the RTC Tamper and Time Stamp events */                                               
660 #define RTC_EXTI_LINE_WAKEUPTIMER_EVENT       ((uint32_t)0x00400000)  /*!< External interrupt line 22 Connected to the RTC Wakeup event */                                               
661
662 /**
663   * @brief  Enable the RTC Exti line.
664   * @param  __EXTILINE__: specifies the RTC Exti sources to be enabled or disabled.
665   *         This parameter can be:
666   *            @arg RTC_EXTI_LINE_ALARM_EVENT
667   *            @arg RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT
668   *            @arg RTC_EXTI_LINE_WAKEUPTIMER_EVENT
669   * @retval None
670   */
671 #define __HAL_RTC_EXTI_ENABLE_IT(__EXTILINE__)   (EXTI->IMR |= (__EXTILINE__))
672
673 /* alias define maintained for legacy */
674 #define __HAL_RTC_ENABLE_IT   __HAL_RTC_EXTI_ENABLE_IT
675
676 /**
677   * @brief  Disable the RTC Exti line.
678   * @param  __EXTILINE__: specifies the RTC Exti sources to be enabled or disabled.
679   *         This parameter can be:
680   *            @arg RTC_EXTI_LINE_ALARM_EVENT
681   *            @arg RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT
682   *            @arg RTC_EXTI_LINE_WAKEUPTIMER_EVENT
683   * @retval None
684   */
685 #define __HAL_RTC_EXTI_DISABLE_IT(__EXTILINE__)  (EXTI->IMR &= ~(__EXTILINE__))
686
687 /* alias define maintained for legacy */
688 #define __HAL_RTC_DISABLE_IT   __HAL_RTC_EXTI_DISABLE_IT
689
690 /**
691   * @brief  Generates a Software interrupt on selected EXTI line.
692   * @param  __EXTILINE__: specifies the RTC Exti sources to be enabled or disabled.
693   *         This parameter can be:
694   *            @arg RTC_EXTI_LINE_ALARM_EVENT
695   *            @arg RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT
696   *            @arg RTC_EXTI_LINE_WAKEUPTIMER_EVENT
697   * @retval None
698   */
699 #define __HAL_RTC_EXTI_GENERATE_SWIT(__EXTI_LINE__) (EXTI->SWIER |= (__EXTI_LINE__))
700
701 /**
702   * @brief  Clear the RTC Exti flags.
703   * @param  __FLAG__: specifies the RTC Exti sources to be enabled or disabled.
704   *         This parameter can be:
705   *            @arg RTC_EXTI_LINE_ALARM_EVENT
706   *            @arg RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT
707   *            @arg RTC_EXTI_LINE_WAKEUPTIMER_EVENT
708   * @retval None
709   */
710 #define __HAL_RTC_EXTI_CLEAR_FLAG(__FLAG__)  (EXTI->PR = (__FLAG__))
711
712 /* alias define maintained for legacy */
713 #define __HAL_RTC_CLEAR_FLAG   __HAL_RTC_EXTI_CLEAR_FLAG
714
715
716 /* Include RTC HAL Extension module */
717 #include "stm32f4xx_hal_rtc_ex.h"
718
719 /* Exported functions --------------------------------------------------------*/
720
721 /* Initialization and de-initialization functions  ****************************/
722 HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc);
723 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc);
724 void       HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc);
725 void       HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc);
726
727 /* RTC Time and Date functions ************************************************/
728 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
729 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
730 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
731 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
732
733 /* RTC Alarm functions ********************************************************/
734 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
735 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
736 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm);
737 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format);
738 void                HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc);
739 HAL_StatusTypeDef   HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
740 void         HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc);
741
742 /* Peripheral Control functions ***********************************************/
743 HAL_StatusTypeDef   HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc);
744
745 /* Peripheral State functions *************************************************/
746 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc);
747
748 HAL_StatusTypeDef  RTC_EnterInitMode(RTC_HandleTypeDef* hrtc);
749 uint8_t            RTC_ByteToBcd2(uint8_t Value);
750 uint8_t            RTC_Bcd2ToByte(uint8_t Value);
751
752 /**
753   * @}
754   */ 
755
756 /**
757   * @}
758   */ 
759   
760 #ifdef __cplusplus
761 }
762 #endif
763
764 #endif /* __STM32F4xx_HAL_RTC_H */
765
766 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/