stm32f1xx_hal_rtc_ex.h 17 KB

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