stm32f1xx_hal_rtc_ex.h 16 KB

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