stm32f1xx_hal_rtc_ex.h 15 KB

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