stm32f1xx_hal_rtc_ex.h 15 KB

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