Subversion Repositories LedShow

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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