py32f0xx_hal_rtc_ex.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /**
  2. ******************************************************************************
  3. * @file py32f0xx_hal_rtc_ex.c
  4. * @author MCU Application Team
  5. * @brief Extended RTC HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the Real Time Clock (RTC) Extension peripheral:
  8. * + RTC Tamper functions
  9. * + Extension Control functions
  10. * + Extension RTC features functions
  11. *
  12. ******************************************************************************
  13. * @attention
  14. *
  15. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  16. * All rights reserved.</center></h2>
  17. *
  18. * This software component is licensed by Puya under BSD 3-Clause license,
  19. * the "License"; You may not use this file except in compliance with the
  20. * License. You may obtain a copy of the License at:
  21. * opensource.org/licenses/BSD-3-Clause
  22. *
  23. ******************************************************************************
  24. * @attention
  25. *
  26. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  27. * All rights reserved.</center></h2>
  28. *
  29. * This software component is licensed by ST under BSD 3-Clause license,
  30. * the "License"; You may not use this file except in compliance with the
  31. * License. You may obtain a copy of the License at:
  32. * opensource.org/licenses/BSD-3-Clause
  33. *
  34. ******************************************************************************
  35. */
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "py32f0xx_hal.h"
  38. /** @addtogroup PY32F0xx_HAL_Driver
  39. * @{
  40. */
  41. #ifdef HAL_RTC_MODULE_ENABLED
  42. /** @defgroup RTCEx RTCEx
  43. * @brief RTC Extended HAL module driver
  44. * @{
  45. */
  46. /* Private typedef -----------------------------------------------------------*/
  47. /* Private define ------------------------------------------------------------*/
  48. /* Private macro -------------------------------------------------------------*/
  49. /** @defgroup RTCEx_Private_Macros RTCEx Private Macros
  50. * @{
  51. */
  52. /**
  53. * @}
  54. */
  55. /* Private variables ---------------------------------------------------------*/
  56. /* Private function prototypes -----------------------------------------------*/
  57. /* Private functions ---------------------------------------------------------*/
  58. /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions
  59. * @{
  60. */
  61. /** @defgroup RTCEx_Exported_Functions_Group2 RTC Second functions
  62. * @brief RTC Second functions
  63. *
  64. @verbatim
  65. ===============================================================================
  66. ##### RTC Second functions #####
  67. ===============================================================================
  68. [..] This section provides functions implementing second interupt handlers
  69. @endverbatim
  70. * @{
  71. */
  72. /**
  73. * @brief Sets Interrupt for second
  74. * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
  75. * the configuration information for RTC.
  76. * @retval HAL status
  77. */
  78. HAL_StatusTypeDef HAL_RTCEx_SetSecond_IT(RTC_HandleTypeDef *hrtc)
  79. {
  80. /* Check input parameters */
  81. if (hrtc == NULL)
  82. {
  83. return HAL_ERROR;
  84. }
  85. /* Process Locked */
  86. __HAL_LOCK(hrtc);
  87. hrtc->State = HAL_RTC_STATE_BUSY;
  88. /* Enable Second interuption */
  89. __HAL_RTC_SECOND_ENABLE_IT(hrtc, RTC_IT_SEC);
  90. hrtc->State = HAL_RTC_STATE_READY;
  91. /* Process Unlocked */
  92. __HAL_UNLOCK(hrtc);
  93. return HAL_OK;
  94. }
  95. /**
  96. * @brief Deactivates Second.
  97. * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
  98. * the configuration information for RTC.
  99. * @retval HAL status
  100. */
  101. HAL_StatusTypeDef HAL_RTCEx_DeactivateSecond(RTC_HandleTypeDef *hrtc)
  102. {
  103. /* Check input parameters */
  104. if (hrtc == NULL)
  105. {
  106. return HAL_ERROR;
  107. }
  108. /* Process Locked */
  109. __HAL_LOCK(hrtc);
  110. hrtc->State = HAL_RTC_STATE_BUSY;
  111. /* Deactivate Second interuption*/
  112. __HAL_RTC_SECOND_DISABLE_IT(hrtc, RTC_IT_SEC);
  113. hrtc->State = HAL_RTC_STATE_READY;
  114. /* Process Unlocked */
  115. __HAL_UNLOCK(hrtc);
  116. return HAL_OK;
  117. }
  118. /**
  119. * @brief This function handles second interrupt request.
  120. * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
  121. * the configuration information for RTC.
  122. * @retval None
  123. */
  124. void HAL_RTCEx_RTCIRQHandler(RTC_HandleTypeDef *hrtc)
  125. {
  126. if (__HAL_RTC_SECOND_GET_IT_SOURCE(hrtc, RTC_IT_SEC))
  127. {
  128. /* Get the status of the Interrupt */
  129. if (__HAL_RTC_SECOND_GET_FLAG(hrtc, RTC_FLAG_SEC))
  130. {
  131. /* Check if Overrun occurred */
  132. if (__HAL_RTC_SECOND_GET_FLAG(hrtc, RTC_FLAG_OW))
  133. {
  134. /* Second error callback */
  135. HAL_RTCEx_RTCEventErrorCallback(hrtc);
  136. /* Clear flag Second */
  137. __HAL_RTC_OVERFLOW_CLEAR_FLAG(hrtc, RTC_FLAG_OW);
  138. /* Change RTC state */
  139. hrtc->State = HAL_RTC_STATE_ERROR;
  140. }
  141. else
  142. {
  143. /* Second callback */
  144. HAL_RTCEx_RTCEventCallback(hrtc);
  145. /* Change RTC state */
  146. hrtc->State = HAL_RTC_STATE_READY;
  147. }
  148. /* Clear flag Second */
  149. __HAL_RTC_SECOND_CLEAR_FLAG(hrtc, RTC_FLAG_SEC);
  150. }
  151. }
  152. if (__HAL_RTC_ALARM_GET_IT_SOURCE(hrtc, RTC_IT_ALRA))
  153. {
  154. /* Get the status of the Interrupt */
  155. if (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAF) != (uint32_t)RESET)
  156. {
  157. /* AlarmA callback */
  158. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  159. hrtc->AlarmAEventCallback(hrtc);
  160. #else
  161. HAL_RTC_AlarmAEventCallback(hrtc);
  162. #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
  163. /* Clear the Alarm interrupt pending bit */
  164. __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);
  165. }
  166. }
  167. }
  168. /**
  169. * @brief Second event callback.
  170. * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
  171. * the configuration information for RTC.
  172. * @retval None
  173. */
  174. __weak void HAL_RTCEx_RTCEventCallback(RTC_HandleTypeDef *hrtc)
  175. {
  176. /* Prevent unused argument(s) compilation warning */
  177. UNUSED(hrtc);
  178. /* NOTE : This function Should not be modified, when the callback is needed,
  179. the HAL_RTCEx_RTCEventCallback could be implemented in the user file
  180. */
  181. }
  182. /**
  183. * @brief Second event error callback.
  184. * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
  185. * the configuration information for RTC.
  186. * @retval None
  187. */
  188. __weak void HAL_RTCEx_RTCEventErrorCallback(RTC_HandleTypeDef *hrtc)
  189. {
  190. /* Prevent unused argument(s) compilation warning */
  191. UNUSED(hrtc);
  192. /* NOTE : This function Should not be modified, when the callback is needed,
  193. the HAL_RTCEx_RTCEventErrorCallback could be implemented in the user file
  194. */
  195. }
  196. /**
  197. * @}
  198. */
  199. /** @defgroup RTCEx_Exported_Functions_Group3 Extended Peripheral Control functions
  200. * @brief Extended Peripheral Control functions
  201. *
  202. @verbatim
  203. ===============================================================================
  204. ##### Extension Peripheral Control functions #####
  205. ===============================================================================
  206. [..]
  207. This subsection provides functions allowing to
  208. (+) Writes a data in a specified RTC Backup data register
  209. (+) Read a data in a specified RTC Backup data register
  210. (+) Sets the Smooth calibration parameters.
  211. @endverbatim
  212. * @{
  213. */
  214. /**
  215. * @brief Sets the Smooth calibration parameters.
  216. * @param hrtc: RTC handle
  217. * @param SmoothCalibPeriod: Not used (only present for compatibility with another families)
  218. * @param SmoothCalibPlusPulses: Not used (only present for compatibility with another families)
  219. * @param SmouthCalibMinusPulsesValue: specifies the RTC Clock Calibration value.
  220. * This parameter must be a number between 0 and 0x7F.
  221. * @retval HAL status
  222. */
  223. HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmouthCalibMinusPulsesValue)
  224. {
  225. /* Check input parameters */
  226. if (hrtc == NULL)
  227. {
  228. return HAL_ERROR;
  229. }
  230. /* Prevent unused argument(s) compilation warning */
  231. UNUSED(SmoothCalibPeriod);
  232. UNUSED(SmoothCalibPlusPulses);
  233. /* Check the parameters */
  234. assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmouthCalibMinusPulsesValue));
  235. /* Process Locked */
  236. __HAL_LOCK(hrtc);
  237. hrtc->State = HAL_RTC_STATE_BUSY;
  238. /* Sets RTC Clock Calibration value.*/
  239. MODIFY_REG(RTC->BKP_RTCCR, BKP_RTCCR_CAL, SmouthCalibMinusPulsesValue);
  240. /* Change RTC state */
  241. hrtc->State = HAL_RTC_STATE_READY;
  242. /* Process Unlocked */
  243. __HAL_UNLOCK(hrtc);
  244. return HAL_OK;
  245. }
  246. /**
  247. * @}
  248. */
  249. /**
  250. * @}
  251. */
  252. /**
  253. * @}
  254. */
  255. #endif /* HAL_RTC_MODULE_ENABLED */
  256. /**
  257. * @}
  258. */
  259. /************************ (C) COPYRIGHT Puya *****END OF FILE****/