STM32F103xB HAL User Manual
stm32f1xx_hal_rtc_ex.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f1xx_hal_rtc_ex.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of RTC HAL Extension module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
00010   * All rights reserved.</center></h2>
00011   *
00012   * This software component is licensed by ST under BSD 3-Clause license,
00013   * the "License"; You may not use this file except in compliance with the
00014   * License. You may obtain a copy of the License at:
00015   *                        opensource.org/licenses/BSD-3-Clause
00016   *
00017   ******************************************************************************
00018   */
00019 
00020 /* Define to prevent recursive inclusion -------------------------------------*/
00021 #ifndef __STM32F1xx_HAL_RTC_EX_H
00022 #define __STM32F1xx_HAL_RTC_EX_H
00023 
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "stm32f1xx_hal_def.h"
00030 
00031 /** @addtogroup STM32F1xx_HAL_Driver
00032   * @{
00033   */
00034 
00035 /** @addtogroup RTCEx
00036   * @{
00037   */
00038 
00039 /** @addtogroup RTCEx_Private_Macros
00040   * @{
00041   */
00042 
00043 /** @defgroup RTCEx_Alias_For_Legacy Alias define maintained for legacy
00044   * @{
00045   */
00046 #define HAL_RTCEx_TamperTimeStampIRQHandler HAL_RTCEx_TamperIRQHandler
00047 
00048 /**
00049   * @}
00050   */
00051 
00052 /** @defgroup RTCEx_IS_RTC_Definitions Private macros to check input parameters
00053   * @{
00054   */
00055 #define IS_RTC_TAMPER(__TAMPER__) ((__TAMPER__) == RTC_TAMPER_1)
00056 
00057 #define IS_RTC_TAMPER_TRIGGER(__TRIGGER__)  (((__TRIGGER__) == RTC_TAMPERTRIGGER_LOWLEVEL) || \
00058                                              ((__TRIGGER__) == RTC_TAMPERTRIGGER_HIGHLEVEL))
00059 
00060 #if RTC_BKP_NUMBER > 10U
00061 #define IS_RTC_BKP(BKP)                   (((BKP) <= (uint32_t)RTC_BKP_DR10) || (((BKP) >= (uint32_t)RTC_BKP_DR11) && ((BKP) <= (uint32_t)RTC_BKP_DR42)))
00062 #else
00063 #define IS_RTC_BKP(BKP)                   ((BKP) <= (uint32_t)RTC_BKP_NUMBER)
00064 #endif
00065 #define IS_RTC_SMOOTH_CALIB_MINUS(__VALUE__) ((__VALUE__) <= 0x0000007FU)
00066 
00067 /**
00068   * @}
00069   */
00070 
00071 /**
00072   * @}
00073   */
00074 
00075 /* Exported types ------------------------------------------------------------*/
00076 /** @defgroup RTCEx_Exported_Types RTCEx Exported Types
00077   * @{
00078   */
00079 /**
00080   * @brief  RTC Tamper structure definition
00081   */
00082 typedef struct
00083 {
00084   uint32_t Tamper;                      /*!< Specifies the Tamper Pin.
00085                                              This parameter can be a value of @ref  RTCEx_Tamper_Pins_Definitions */
00086 
00087   uint32_t Trigger;                     /*!< Specifies the Tamper Trigger.
00088                                              This parameter can be a value of @ref  RTCEx_Tamper_Trigger_Definitions */
00089 
00090 } RTC_TamperTypeDef;
00091 
00092 /**
00093   * @}
00094   */
00095 
00096 /* Exported constants --------------------------------------------------------*/
00097 /** @defgroup RTCEx_Exported_Constants RTCEx Exported Constants
00098   * @{
00099   */
00100 
00101 /** @defgroup RTCEx_Tamper_Pins_Definitions Tamper Pins Definitions
00102   * @{
00103   */
00104 #define RTC_TAMPER_1                        BKP_CR_TPE            /*!< Select tamper to be enabled (mainly for legacy purposes) */
00105 
00106 /**
00107   * @}
00108   */
00109 
00110 /** @defgroup RTCEx_Tamper_Trigger_Definitions Tamper Trigger Definitions
00111   * @{
00112   */
00113 #define RTC_TAMPERTRIGGER_LOWLEVEL          BKP_CR_TPAL           /*!< A high level on the TAMPER pin resets all data backup registers (if TPE bit is set) */
00114 #define RTC_TAMPERTRIGGER_HIGHLEVEL         0x00000000U           /*!< A low level on the TAMPER pin resets all data backup registers (if TPE bit is set) */
00115 
00116 /**
00117   * @}
00118   */
00119 
00120 /** @defgroup RTCEx_Backup_Registers_Definitions Backup Registers Definitions
00121   * @{
00122   */
00123 #if RTC_BKP_NUMBER > 0U
00124 #define RTC_BKP_DR1                         0x00000001U
00125 #define RTC_BKP_DR2                         0x00000002U
00126 #define RTC_BKP_DR3                         0x00000003U
00127 #define RTC_BKP_DR4                         0x00000004U
00128 #define RTC_BKP_DR5                         0x00000005U
00129 #define RTC_BKP_DR6                         0x00000006U
00130 #define RTC_BKP_DR7                         0x00000007U
00131 #define RTC_BKP_DR8                         0x00000008U
00132 #define RTC_BKP_DR9                         0x00000009U
00133 #define RTC_BKP_DR10                        0x0000000AU
00134 #endif /* RTC_BKP_NUMBER > 0 */
00135 
00136 #if RTC_BKP_NUMBER > 10U
00137 #define RTC_BKP_DR11                        0x00000010U
00138 #define RTC_BKP_DR12                        0x00000011U
00139 #define RTC_BKP_DR13                        0x00000012U
00140 #define RTC_BKP_DR14                        0x00000013U
00141 #define RTC_BKP_DR15                        0x00000014U
00142 #define RTC_BKP_DR16                        0x00000015U
00143 #define RTC_BKP_DR17                        0x00000016U
00144 #define RTC_BKP_DR18                        0x00000017U
00145 #define RTC_BKP_DR19                        0x00000018U
00146 #define RTC_BKP_DR20                        0x00000019U
00147 #define RTC_BKP_DR21                        0x0000001AU
00148 #define RTC_BKP_DR22                        0x0000001BU
00149 #define RTC_BKP_DR23                        0x0000001CU
00150 #define RTC_BKP_DR24                        0x0000001DU
00151 #define RTC_BKP_DR25                        0x0000001EU
00152 #define RTC_BKP_DR26                        0x0000001FU
00153 #define RTC_BKP_DR27                        0x00000020U
00154 #define RTC_BKP_DR28                        0x00000021U
00155 #define RTC_BKP_DR29                        0x00000022U
00156 #define RTC_BKP_DR30                        0x00000023U
00157 #define RTC_BKP_DR31                        0x00000024U
00158 #define RTC_BKP_DR32                        0x00000025U
00159 #define RTC_BKP_DR33                        0x00000026U
00160 #define RTC_BKP_DR34                        0x00000027U
00161 #define RTC_BKP_DR35                        0x00000028U
00162 #define RTC_BKP_DR36                        0x00000029U
00163 #define RTC_BKP_DR37                        0x0000002AU
00164 #define RTC_BKP_DR38                        0x0000002BU
00165 #define RTC_BKP_DR39                        0x0000002CU
00166 #define RTC_BKP_DR40                        0x0000002DU
00167 #define RTC_BKP_DR41                        0x0000002EU
00168 #define RTC_BKP_DR42                        0x0000002FU
00169 #endif /* RTC_BKP_NUMBER > 10 */
00170 
00171 /**
00172   * @}
00173   */
00174 
00175 /**
00176   * @}
00177   */
00178 
00179 /* Exported macro ------------------------------------------------------------*/
00180 /** @defgroup RTCEx_Exported_Macros RTCEx Exported Macros
00181   * @{
00182   */
00183 
00184 /**
00185   * @brief  Enable the RTC Tamper interrupt.
00186   * @param  __HANDLE__: specifies the RTC handle.
00187   * @param  __INTERRUPT__: specifies the RTC Tamper interrupt sources to be enabled
00188   *          This parameter can be any combination of the following values:
00189   *            @arg RTC_IT_TAMP1: Tamper A interrupt
00190   * @retval None
00191   */
00192 #define __HAL_RTC_TAMPER_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT(BKP->CSR, (__INTERRUPT__))
00193 
00194 /**
00195   * @brief  Disable the RTC Tamper interrupt.
00196   * @param  __HANDLE__: specifies the RTC handle.
00197   * @param  __INTERRUPT__: specifies the RTC Tamper interrupt sources to be disabled.
00198   *         This parameter can be any combination of the following values:
00199   *            @arg RTC_IT_TAMP1: Tamper A interrupt
00200   * @retval None
00201   */
00202 #define __HAL_RTC_TAMPER_DISABLE_IT(__HANDLE__, __INTERRUPT__)  CLEAR_BIT(BKP->CSR, (__INTERRUPT__))
00203 
00204 /**
00205   * @brief  Check whether the specified RTC Tamper interrupt has been enabled or not.
00206   * @param  __HANDLE__: specifies the RTC handle.
00207   * @param  __INTERRUPT__: specifies the RTC Tamper interrupt sources to be checked.
00208   *         This parameter can be:
00209   *            @arg  RTC_IT_TAMP1
00210   * @retval None
00211   */
00212 #define __HAL_RTC_TAMPER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)    ((((BKP->CSR) & ((__INTERRUPT__))) != RESET)? SET : RESET)
00213 
00214 /**
00215   * @brief  Get the selected RTC Tamper's flag status.
00216   * @param  __HANDLE__: specifies the RTC handle.
00217   * @param  __FLAG__: specifies the RTC Tamper Flag sources to be enabled or disabled.
00218   *         This parameter can be:
00219   *            @arg RTC_FLAG_TAMP1F
00220   * @retval None
00221   */
00222 #define __HAL_RTC_TAMPER_GET_FLAG(__HANDLE__, __FLAG__)       ((((BKP->CSR) & (__FLAG__)) != RESET)? SET : RESET)
00223 
00224 /**
00225   * @brief  Get the selected RTC Tamper's flag status.
00226   * @param  __HANDLE__: specifies the RTC handle.
00227   * @param  __INTERRUPT__: specifies the RTC Tamper interrupt sources to be checked.
00228   *         This parameter can be:
00229   *            @arg  RTC_IT_TAMP1
00230   * @retval None
00231   */
00232 #define __HAL_RTC_TAMPER_GET_IT(__HANDLE__, __INTERRUPT__)       ((((BKP->CSR) & (BKP_CSR_TEF)) != RESET)? SET : RESET)
00233 
00234 /**
00235   * @brief  Clear the RTC Tamper's pending flags.
00236   * @param  __HANDLE__: specifies the RTC handle.
00237   * @param  __FLAG__: specifies the RTC Tamper Flag sources to be enabled or disabled.
00238   *         This parameter can be:
00239   *            @arg RTC_FLAG_TAMP1F
00240   * @retval None
00241   */
00242 #define __HAL_RTC_TAMPER_CLEAR_FLAG(__HANDLE__, __FLAG__)     SET_BIT(BKP->CSR, BKP_CSR_CTE | BKP_CSR_CTI)
00243 
00244 /**
00245   * @brief  Enable the RTC Second interrupt.
00246   * @param  __HANDLE__: specifies the RTC handle.
00247   * @param  __INTERRUPT__: specifies the RTC Second interrupt sources to be enabled
00248   *          This parameter can be any combination of the following values:
00249   *            @arg RTC_IT_SEC: Second A interrupt
00250   * @retval None
00251   */
00252 #define __HAL_RTC_SECOND_ENABLE_IT(__HANDLE__, __INTERRUPT__)  SET_BIT((__HANDLE__)->Instance->CRH, (__INTERRUPT__))
00253 
00254 /**
00255   * @brief  Disable the RTC Second interrupt.
00256   * @param  __HANDLE__: specifies the RTC handle.
00257   * @param  __INTERRUPT__: specifies the RTC Second interrupt sources to be disabled.
00258   *         This parameter can be any combination of the following values:
00259   *            @arg RTC_IT_SEC: Second A interrupt
00260   * @retval None
00261   */
00262 #define __HAL_RTC_SECOND_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->CRH, (__INTERRUPT__))
00263 
00264 /**
00265   * @brief  Check whether the specified RTC Second interrupt has occurred or not.
00266   * @param  __HANDLE__: specifies the RTC handle.
00267   * @param  __INTERRUPT__: specifies the RTC Second interrupt sources to be enabled or disabled.
00268   *         This parameter can be:
00269   *            @arg RTC_IT_SEC: Second A interrupt
00270   * @retval None
00271   */
00272 #define __HAL_RTC_SECOND_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)      ((((((__HANDLE__)->Instance->CRH)& ((__INTERRUPT__)))) != RESET)? SET : RESET)
00273 
00274 /**
00275   * @brief  Get the selected RTC Second's flag status.
00276   * @param  __HANDLE__: specifies the RTC handle.
00277   * @param  __FLAG__: specifies the RTC Second Flag sources to be enabled or disabled.
00278   *          This parameter can be:
00279   *            @arg RTC_FLAG_SEC
00280   * @retval None
00281   */
00282 #define __HAL_RTC_SECOND_GET_FLAG(__HANDLE__, __FLAG__)        (((((__HANDLE__)->Instance->CRL) & (__FLAG__)) != RESET)? SET : RESET)
00283 
00284 /**
00285   * @brief  Clear the RTC Second's pending flags.
00286   * @param  __HANDLE__: specifies the RTC handle.
00287   * @param  __FLAG__: specifies the RTC Second Flag sources to be enabled or disabled.
00288   *         This parameter can be:
00289   *            @arg RTC_FLAG_SEC
00290   * @retval None
00291   */
00292 #define __HAL_RTC_SECOND_CLEAR_FLAG(__HANDLE__, __FLAG__)      ((__HANDLE__)->Instance->CRL) &= ~(__FLAG__)
00293 
00294 /**
00295   * @brief  Enable the RTC Overflow interrupt.
00296   * @param  __HANDLE__: specifies the RTC handle.
00297   * @param  __INTERRUPT__: specifies the RTC Overflow interrupt sources to be enabled
00298   *          This parameter can be any combination of the following values:
00299   *            @arg RTC_IT_OW: Overflow A interrupt
00300   * @retval None
00301   */
00302 #define __HAL_RTC_OVERFLOW_ENABLE_IT(__HANDLE__, __INTERRUPT__)  SET_BIT((__HANDLE__)->Instance->CRH, (__INTERRUPT__))
00303 
00304 /**
00305   * @brief  Disable the RTC Overflow interrupt.
00306   * @param  __HANDLE__: specifies the RTC handle.
00307   * @param  __INTERRUPT__: specifies the RTC Overflow interrupt sources to be disabled.
00308   *         This parameter can be any combination of the following values:
00309   *            @arg RTC_IT_OW: Overflow A interrupt
00310   * @retval None
00311   */
00312 #define __HAL_RTC_OVERFLOW_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->CRH, (__INTERRUPT__))
00313 
00314 /**
00315   * @brief  Check whether the specified RTC Overflow interrupt has occurred or not.
00316   * @param  __HANDLE__: specifies the RTC handle.
00317   * @param  __INTERRUPT__: specifies the RTC Overflow interrupt sources to be enabled or disabled.
00318   *         This parameter can be:
00319   *            @arg RTC_IT_OW: Overflow A interrupt
00320   * @retval None
00321   */
00322 #define __HAL_RTC_OVERFLOW_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)    ((((((__HANDLE__)->Instance->CRH)& ((__INTERRUPT__))) ) != RESET)? SET : RESET)
00323 
00324 /**
00325   * @brief  Get the selected RTC Overflow's flag status.
00326   * @param  __HANDLE__: specifies the RTC handle.
00327   * @param  __FLAG__: specifies the RTC Overflow Flag sources to be enabled or disabled.
00328   *          This parameter can be:
00329   *            @arg RTC_FLAG_OW
00330   * @retval None
00331   */
00332 #define __HAL_RTC_OVERFLOW_GET_FLAG(__HANDLE__, __FLAG__)        (((((__HANDLE__)->Instance->CRL) & (__FLAG__)) != RESET)? SET : RESET)
00333 
00334 /**
00335   * @brief  Clear the RTC Overflow's pending flags.
00336   * @param  __HANDLE__: specifies the RTC handle.
00337   * @param  __FLAG__: specifies the RTC Overflow Flag sources to be enabled or disabled.
00338   *         This parameter can be:
00339   *            @arg RTC_FLAG_OW
00340   * @retval None
00341   */
00342 #define __HAL_RTC_OVERFLOW_CLEAR_FLAG(__HANDLE__, __FLAG__)      ((__HANDLE__)->Instance->CRL) = ~(__FLAG__)
00343 
00344 /**
00345   * @}
00346   */
00347 
00348 /* Exported functions --------------------------------------------------------*/
00349 /** @addtogroup RTCEx_Exported_Functions
00350   * @{
00351   */
00352 
00353 /* RTC Tamper functions *****************************************/
00354 /** @addtogroup RTCEx_Exported_Functions_Group1
00355   * @{
00356   */
00357 HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper);
00358 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper);
00359 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper);
00360 void              HAL_RTCEx_TamperIRQHandler(RTC_HandleTypeDef *hrtc);
00361 void              HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc);
00362 HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
00363 
00364 /**
00365   * @}
00366   */
00367 
00368 /* RTC Second functions *****************************************/
00369 /** @addtogroup RTCEx_Exported_Functions_Group2
00370   * @{
00371   */
00372 HAL_StatusTypeDef HAL_RTCEx_SetSecond_IT(RTC_HandleTypeDef *hrtc);
00373 HAL_StatusTypeDef HAL_RTCEx_DeactivateSecond(RTC_HandleTypeDef *hrtc);
00374 void              HAL_RTCEx_RTCIRQHandler(RTC_HandleTypeDef *hrtc);
00375 void              HAL_RTCEx_RTCEventCallback(RTC_HandleTypeDef *hrtc);
00376 void              HAL_RTCEx_RTCEventErrorCallback(RTC_HandleTypeDef *hrtc);
00377 
00378 /**
00379   * @}
00380   */
00381 
00382 /* Extension Control functions ************************************************/
00383 /** @addtogroup RTCEx_Exported_Functions_Group3
00384   * @{
00385   */
00386 void              HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data);
00387 uint32_t          HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister);
00388 
00389 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmouthCalibMinusPulsesValue);
00390 /**
00391   * @}
00392   */
00393 
00394 /**
00395   * @}
00396   */
00397 
00398 /**
00399   * @}
00400   */
00401 
00402 /**
00403   * @}
00404   */
00405 
00406 #ifdef __cplusplus
00407 }
00408 #endif
00409 
00410 #endif /* __STM32F1xx_HAL_RTC_EX_H */
00411 
00412 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/