1 /**
2   ******************************************************************************
3   * @file    stm32f1xx_hal_rtc_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of RTC HAL Extension module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2016 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef __STM32F1xx_HAL_RTC_EX_H
21 #define __STM32F1xx_HAL_RTC_EX_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32f1xx_hal_def.h"
29 
30 /** @addtogroup STM32F1xx_HAL_Driver
31   * @{
32   */
33 
34 /** @addtogroup RTCEx
35   * @{
36   */
37 
38 /** @addtogroup RTCEx_Private_Macros
39   * @{
40   */
41 
42 /** @defgroup RTCEx_Alias_For_Legacy Alias define maintained for legacy
43   * @{
44   */
45 #define HAL_RTCEx_TamperTimeStampIRQHandler HAL_RTCEx_TamperIRQHandler
46 
47 /**
48   * @}
49   */
50 
51 /** @defgroup RTCEx_IS_RTC_Definitions Private macros to check input parameters
52   * @{
53   */
54 #define IS_RTC_TAMPER(__TAMPER__) ((__TAMPER__) == RTC_TAMPER_1)
55 
56 #define IS_RTC_TAMPER_TRIGGER(__TRIGGER__)  (((__TRIGGER__) == RTC_TAMPERTRIGGER_LOWLEVEL) || \
57                                              ((__TRIGGER__) == RTC_TAMPERTRIGGER_HIGHLEVEL))
58 
59 #if RTC_BKP_NUMBER > 10U
60 #define IS_RTC_BKP(BKP)                   (((BKP) <= (uint32_t)RTC_BKP_DR10) || (((BKP) >= (uint32_t)RTC_BKP_DR11) && ((BKP) <= (uint32_t)RTC_BKP_DR42)))
61 #else
62 #define IS_RTC_BKP(BKP)                   ((BKP) <= (uint32_t)RTC_BKP_NUMBER)
63 #endif
64 #define IS_RTC_SMOOTH_CALIB_MINUS(__VALUE__) ((__VALUE__) <= 0x0000007FU)
65 
66 /**
67   * @}
68   */
69 
70 /**
71   * @}
72   */
73 
74 /* Exported types ------------------------------------------------------------*/
75 /** @defgroup RTCEx_Exported_Types RTCEx Exported Types
76   * @{
77   */
78 /**
79   * @brief  RTC Tamper structure definition
80   */
81 typedef struct
82 {
83   uint32_t Tamper;                      /*!< Specifies the Tamper Pin.
84                                              This parameter can be a value of @ref  RTCEx_Tamper_Pins_Definitions */
85 
86   uint32_t Trigger;                     /*!< Specifies the Tamper Trigger.
87                                              This parameter can be a value of @ref  RTCEx_Tamper_Trigger_Definitions */
88 
89 } RTC_TamperTypeDef;
90 
91 /**
92   * @}
93   */
94 
95 /* Exported constants --------------------------------------------------------*/
96 /** @defgroup RTCEx_Exported_Constants RTCEx Exported Constants
97   * @{
98   */
99 
100 /** @defgroup RTCEx_Tamper_Pins_Definitions Tamper Pins Definitions
101   * @{
102   */
103 #define RTC_TAMPER_1                        BKP_CR_TPE            /*!< Select tamper to be enabled (mainly for legacy purposes) */
104 
105 /**
106   * @}
107   */
108 
109 /** @defgroup RTCEx_Tamper_Trigger_Definitions Tamper Trigger Definitions
110   * @{
111   */
112 #define RTC_TAMPERTRIGGER_LOWLEVEL          BKP_CR_TPAL           /*!< A high level on the TAMPER pin resets all data backup registers (if TPE bit is set) */
113 #define RTC_TAMPERTRIGGER_HIGHLEVEL         0x00000000U           /*!< A low level on the TAMPER pin resets all data backup registers (if TPE bit is set) */
114 
115 /**
116   * @}
117   */
118 
119 /** @defgroup RTCEx_Backup_Registers_Definitions Backup Registers Definitions
120   * @{
121   */
122 #if RTC_BKP_NUMBER > 0U
123 #define RTC_BKP_DR1                         0x00000001U
124 #define RTC_BKP_DR2                         0x00000002U
125 #define RTC_BKP_DR3                         0x00000003U
126 #define RTC_BKP_DR4                         0x00000004U
127 #define RTC_BKP_DR5                         0x00000005U
128 #define RTC_BKP_DR6                         0x00000006U
129 #define RTC_BKP_DR7                         0x00000007U
130 #define RTC_BKP_DR8                         0x00000008U
131 #define RTC_BKP_DR9                         0x00000009U
132 #define RTC_BKP_DR10                        0x0000000AU
133 #endif /* RTC_BKP_NUMBER > 0 */
134 
135 #if RTC_BKP_NUMBER > 10U
136 #define RTC_BKP_DR11                        0x00000010U
137 #define RTC_BKP_DR12                        0x00000011U
138 #define RTC_BKP_DR13                        0x00000012U
139 #define RTC_BKP_DR14                        0x00000013U
140 #define RTC_BKP_DR15                        0x00000014U
141 #define RTC_BKP_DR16                        0x00000015U
142 #define RTC_BKP_DR17                        0x00000016U
143 #define RTC_BKP_DR18                        0x00000017U
144 #define RTC_BKP_DR19                        0x00000018U
145 #define RTC_BKP_DR20                        0x00000019U
146 #define RTC_BKP_DR21                        0x0000001AU
147 #define RTC_BKP_DR22                        0x0000001BU
148 #define RTC_BKP_DR23                        0x0000001CU
149 #define RTC_BKP_DR24                        0x0000001DU
150 #define RTC_BKP_DR25                        0x0000001EU
151 #define RTC_BKP_DR26                        0x0000001FU
152 #define RTC_BKP_DR27                        0x00000020U
153 #define RTC_BKP_DR28                        0x00000021U
154 #define RTC_BKP_DR29                        0x00000022U
155 #define RTC_BKP_DR30                        0x00000023U
156 #define RTC_BKP_DR31                        0x00000024U
157 #define RTC_BKP_DR32                        0x00000025U
158 #define RTC_BKP_DR33                        0x00000026U
159 #define RTC_BKP_DR34                        0x00000027U
160 #define RTC_BKP_DR35                        0x00000028U
161 #define RTC_BKP_DR36                        0x00000029U
162 #define RTC_BKP_DR37                        0x0000002AU
163 #define RTC_BKP_DR38                        0x0000002BU
164 #define RTC_BKP_DR39                        0x0000002CU
165 #define RTC_BKP_DR40                        0x0000002DU
166 #define RTC_BKP_DR41                        0x0000002EU
167 #define RTC_BKP_DR42                        0x0000002FU
168 #endif /* RTC_BKP_NUMBER > 10 */
169 
170 /**
171   * @}
172   */
173 
174 /**
175   * @}
176   */
177 
178 /* Exported macro ------------------------------------------------------------*/
179 /** @defgroup RTCEx_Exported_Macros RTCEx Exported Macros
180   * @{
181   */
182 
183 /**
184   * @brief  Enable the RTC Tamper interrupt.
185   * @param  __HANDLE__: specifies the RTC handle.
186   * @param  __INTERRUPT__: specifies the RTC Tamper interrupt sources to be enabled
187   *          This parameter can be any combination of the following values:
188   *            @arg RTC_IT_TAMP1: Tamper A interrupt
189   * @retval None
190   */
191 #define __HAL_RTC_TAMPER_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT(BKP->CSR, (__INTERRUPT__))
192 
193 /**
194   * @brief  Disable the RTC Tamper interrupt.
195   * @param  __HANDLE__: specifies the RTC handle.
196   * @param  __INTERRUPT__: specifies the RTC Tamper interrupt sources to be disabled.
197   *         This parameter can be any combination of the following values:
198   *            @arg RTC_IT_TAMP1: Tamper A interrupt
199   * @retval None
200   */
201 #define __HAL_RTC_TAMPER_DISABLE_IT(__HANDLE__, __INTERRUPT__)  CLEAR_BIT(BKP->CSR, (__INTERRUPT__))
202 
203 /**
204   * @brief  Check whether the specified RTC Tamper interrupt has been enabled or not.
205   * @param  __HANDLE__: specifies the RTC handle.
206   * @param  __INTERRUPT__: specifies the RTC Tamper interrupt sources to be checked.
207   *         This parameter can be:
208   *            @arg  RTC_IT_TAMP1
209   * @retval None
210   */
211 #define __HAL_RTC_TAMPER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)    ((((BKP->CSR) & ((__INTERRUPT__))) != RESET)? SET : RESET)
212 
213 /**
214   * @brief  Get the selected RTC Tamper's flag status.
215   * @param  __HANDLE__: specifies the RTC handle.
216   * @param  __FLAG__: specifies the RTC Tamper Flag sources to be enabled or disabled.
217   *         This parameter can be:
218   *            @arg RTC_FLAG_TAMP1F
219   * @retval None
220   */
221 #define __HAL_RTC_TAMPER_GET_FLAG(__HANDLE__, __FLAG__)       ((((BKP->CSR) & (__FLAG__)) != RESET)? SET : RESET)
222 
223 /**
224   * @brief  Get the selected RTC Tamper's flag status.
225   * @param  __HANDLE__: specifies the RTC handle.
226   * @param  __INTERRUPT__: specifies the RTC Tamper interrupt sources to be checked.
227   *         This parameter can be:
228   *            @arg  RTC_IT_TAMP1
229   * @retval None
230   */
231 #define __HAL_RTC_TAMPER_GET_IT(__HANDLE__, __INTERRUPT__)       ((((BKP->CSR) & (BKP_CSR_TEF)) != RESET)? SET : RESET)
232 
233 /**
234   * @brief  Clear the RTC Tamper's pending flags.
235   * @param  __HANDLE__: specifies the RTC handle.
236   * @param  __FLAG__: specifies the RTC Tamper Flag sources to be enabled or disabled.
237   *         This parameter can be:
238   *            @arg RTC_FLAG_TAMP1F
239   * @retval None
240   */
241 #define __HAL_RTC_TAMPER_CLEAR_FLAG(__HANDLE__, __FLAG__)     SET_BIT(BKP->CSR, BKP_CSR_CTE | BKP_CSR_CTI)
242 
243 /**
244   * @brief  Enable the RTC Second interrupt.
245   * @param  __HANDLE__: specifies the RTC handle.
246   * @param  __INTERRUPT__: specifies the RTC Second interrupt sources to be enabled
247   *          This parameter can be any combination of the following values:
248   *            @arg RTC_IT_SEC: Second A interrupt
249   * @retval None
250   */
251 #define __HAL_RTC_SECOND_ENABLE_IT(__HANDLE__, __INTERRUPT__)  SET_BIT((__HANDLE__)->Instance->CRH, (__INTERRUPT__))
252 
253 /**
254   * @brief  Disable the RTC Second interrupt.
255   * @param  __HANDLE__: specifies the RTC handle.
256   * @param  __INTERRUPT__: specifies the RTC Second interrupt sources to be disabled.
257   *         This parameter can be any combination of the following values:
258   *            @arg RTC_IT_SEC: Second A interrupt
259   * @retval None
260   */
261 #define __HAL_RTC_SECOND_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->CRH, (__INTERRUPT__))
262 
263 /**
264   * @brief  Check whether the specified RTC Second interrupt has occurred or not.
265   * @param  __HANDLE__: specifies the RTC handle.
266   * @param  __INTERRUPT__: specifies the RTC Second interrupt sources to be enabled or disabled.
267   *         This parameter can be:
268   *            @arg RTC_IT_SEC: Second A interrupt
269   * @retval None
270   */
271 #define __HAL_RTC_SECOND_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)      ((((((__HANDLE__)->Instance->CRH)& ((__INTERRUPT__)))) != RESET)? SET : RESET)
272 
273 /**
274   * @brief  Get the selected RTC Second's flag status.
275   * @param  __HANDLE__: specifies the RTC handle.
276   * @param  __FLAG__: specifies the RTC Second Flag sources to be enabled or disabled.
277   *          This parameter can be:
278   *            @arg RTC_FLAG_SEC
279   * @retval None
280   */
281 #define __HAL_RTC_SECOND_GET_FLAG(__HANDLE__, __FLAG__)        (((((__HANDLE__)->Instance->CRL) & (__FLAG__)) != RESET)? SET : RESET)
282 
283 /**
284   * @brief  Clear the RTC Second's pending flags.
285   * @param  __HANDLE__: specifies the RTC handle.
286   * @param  __FLAG__: specifies the RTC Second Flag sources to be enabled or disabled.
287   *         This parameter can be:
288   *            @arg RTC_FLAG_SEC
289   * @retval None
290   */
291 #define __HAL_RTC_SECOND_CLEAR_FLAG(__HANDLE__, __FLAG__)      ((__HANDLE__)->Instance->CRL) &= ~(__FLAG__)
292 
293 /**
294   * @brief  Enable the RTC Overflow interrupt.
295   * @param  __HANDLE__: specifies the RTC handle.
296   * @param  __INTERRUPT__: specifies the RTC Overflow interrupt sources to be enabled
297   *          This parameter can be any combination of the following values:
298   *            @arg RTC_IT_OW: Overflow A interrupt
299   * @retval None
300   */
301 #define __HAL_RTC_OVERFLOW_ENABLE_IT(__HANDLE__, __INTERRUPT__)  SET_BIT((__HANDLE__)->Instance->CRH, (__INTERRUPT__))
302 
303 /**
304   * @brief  Disable the RTC Overflow interrupt.
305   * @param  __HANDLE__: specifies the RTC handle.
306   * @param  __INTERRUPT__: specifies the RTC Overflow interrupt sources to be disabled.
307   *         This parameter can be any combination of the following values:
308   *            @arg RTC_IT_OW: Overflow A interrupt
309   * @retval None
310   */
311 #define __HAL_RTC_OVERFLOW_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->CRH, (__INTERRUPT__))
312 
313 /**
314   * @brief  Check whether the specified RTC Overflow interrupt has occurred or not.
315   * @param  __HANDLE__: specifies the RTC handle.
316   * @param  __INTERRUPT__: specifies the RTC Overflow interrupt sources to be enabled or disabled.
317   *         This parameter can be:
318   *            @arg RTC_IT_OW: Overflow A interrupt
319   * @retval None
320   */
321 #define __HAL_RTC_OVERFLOW_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)    ((((((__HANDLE__)->Instance->CRH)& ((__INTERRUPT__))) ) != RESET)? SET : RESET)
322 
323 /**
324   * @brief  Get the selected RTC Overflow's flag status.
325   * @param  __HANDLE__: specifies the RTC handle.
326   * @param  __FLAG__: specifies the RTC Overflow Flag sources to be enabled or disabled.
327   *          This parameter can be:
328   *            @arg RTC_FLAG_OW
329   * @retval None
330   */
331 #define __HAL_RTC_OVERFLOW_GET_FLAG(__HANDLE__, __FLAG__)        (((((__HANDLE__)->Instance->CRL) & (__FLAG__)) != RESET)? SET : RESET)
332 
333 /**
334   * @brief  Clear the RTC Overflow's pending flags.
335   * @param  __HANDLE__: specifies the RTC handle.
336   * @param  __FLAG__: specifies the RTC Overflow Flag sources to be enabled or disabled.
337   *         This parameter can be:
338   *            @arg RTC_FLAG_OW
339   * @retval None
340   */
341 #define __HAL_RTC_OVERFLOW_CLEAR_FLAG(__HANDLE__, __FLAG__)      ((__HANDLE__)->Instance->CRL) = ~(__FLAG__)
342 
343 /**
344   * @}
345   */
346 
347 /* Exported functions --------------------------------------------------------*/
348 /** @addtogroup RTCEx_Exported_Functions
349   * @{
350   */
351 
352 /* RTC Tamper functions *****************************************/
353 /** @addtogroup RTCEx_Exported_Functions_Group1
354   * @{
355   */
356 HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper);
357 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper);
358 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper);
359 void              HAL_RTCEx_TamperIRQHandler(RTC_HandleTypeDef *hrtc);
360 void              HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc);
361 HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
362 
363 /**
364   * @}
365   */
366 
367 /* RTC Second functions *****************************************/
368 /** @addtogroup RTCEx_Exported_Functions_Group2
369   * @{
370   */
371 HAL_StatusTypeDef HAL_RTCEx_SetSecond_IT(RTC_HandleTypeDef *hrtc);
372 HAL_StatusTypeDef HAL_RTCEx_DeactivateSecond(RTC_HandleTypeDef *hrtc);
373 void              HAL_RTCEx_RTCIRQHandler(RTC_HandleTypeDef *hrtc);
374 void              HAL_RTCEx_RTCEventCallback(RTC_HandleTypeDef *hrtc);
375 void              HAL_RTCEx_RTCEventErrorCallback(RTC_HandleTypeDef *hrtc);
376 
377 /**
378   * @}
379   */
380 
381 /* Extension Control functions ************************************************/
382 /** @addtogroup RTCEx_Exported_Functions_Group3
383   * @{
384   */
385 void              HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data);
386 uint32_t          HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister);
387 
388 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmouthCalibMinusPulsesValue);
389 /**
390   * @}
391   */
392 
393 /**
394   * @}
395   */
396 
397 /**
398   * @}
399   */
400 
401 /**
402   * @}
403   */
404 
405 #ifdef __cplusplus
406 }
407 #endif
408 
409 #endif /* __STM32F1xx_HAL_RTC_EX_H */
410