Mouse code for the MacroRat
mbed-dev/targets/TARGET_STM/TARGET_STM32F2/device/stm32f2xx_hal_rtc_ex.c@46:b156ef445742, 2017-06-03 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sat Jun 03 00:22:44 2017 +0000
- Revision:
- 46:b156ef445742
- Parent:
- 18:6a4db94011d3
Final code for internal battlebot competition.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /** |
sahilmgandhi | 18:6a4db94011d3 | 2 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @file stm32f2xx_hal_rtc_ex.c |
sahilmgandhi | 18:6a4db94011d3 | 4 | * @author MCD Application Team |
sahilmgandhi | 18:6a4db94011d3 | 5 | * @version V1.1.3 |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @date 29-June-2016 |
sahilmgandhi | 18:6a4db94011d3 | 7 | * @brief RTC HAL module driver. |
sahilmgandhi | 18:6a4db94011d3 | 8 | * This file provides firmware functions to manage the following |
sahilmgandhi | 18:6a4db94011d3 | 9 | * functionalities of the Real Time Clock (RTC) Extension peripheral: |
sahilmgandhi | 18:6a4db94011d3 | 10 | * + RTC Time Stamp functions |
sahilmgandhi | 18:6a4db94011d3 | 11 | * + RTC Tamper functions |
sahilmgandhi | 18:6a4db94011d3 | 12 | * + RTC Wake-up functions |
sahilmgandhi | 18:6a4db94011d3 | 13 | * + Extension Control functions |
sahilmgandhi | 18:6a4db94011d3 | 14 | * + Extension RTC features functions |
sahilmgandhi | 18:6a4db94011d3 | 15 | * |
sahilmgandhi | 18:6a4db94011d3 | 16 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 17 | ============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 18 | ##### How to use this driver ##### |
sahilmgandhi | 18:6a4db94011d3 | 19 | ============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 20 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 21 | (+) Enable the RTC domain access. |
sahilmgandhi | 18:6a4db94011d3 | 22 | (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour |
sahilmgandhi | 18:6a4db94011d3 | 23 | format using the HAL_RTC_Init() function. |
sahilmgandhi | 18:6a4db94011d3 | 24 | |
sahilmgandhi | 18:6a4db94011d3 | 25 | *** RTC Wake-up configuration *** |
sahilmgandhi | 18:6a4db94011d3 | 26 | ================================ |
sahilmgandhi | 18:6a4db94011d3 | 27 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 28 | (+) To configure the RTC Wake-up Clock source and Counter use the HAL_RTCEx_SetWakeUpTimer() |
sahilmgandhi | 18:6a4db94011d3 | 29 | function. You can also configure the RTC Wake-up timer in interrupt mode |
sahilmgandhi | 18:6a4db94011d3 | 30 | using the HAL_RTCEx_SetWakeUpTimer_IT() function. |
sahilmgandhi | 18:6a4db94011d3 | 31 | (+) To read the RTC Wake-up Counter register, use the HAL_RTCEx_GetWakeUpTimer() |
sahilmgandhi | 18:6a4db94011d3 | 32 | function. |
sahilmgandhi | 18:6a4db94011d3 | 33 | |
sahilmgandhi | 18:6a4db94011d3 | 34 | *** TimeStamp configuration *** |
sahilmgandhi | 18:6a4db94011d3 | 35 | =============================== |
sahilmgandhi | 18:6a4db94011d3 | 36 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 37 | (+) Configure the RTC_AFx trigger and enable the RTC TimeStamp using the |
sahilmgandhi | 18:6a4db94011d3 | 38 | HAL_RTCEx_SetTimeStamp() function. You can also configure the RTC TimeStamp with |
sahilmgandhi | 18:6a4db94011d3 | 39 | interrupt mode using the HAL_RTCEx_SetTimeStamp_IT() function. |
sahilmgandhi | 18:6a4db94011d3 | 40 | (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTCEx_GetTimeStamp() |
sahilmgandhi | 18:6a4db94011d3 | 41 | function. |
sahilmgandhi | 18:6a4db94011d3 | 42 | (+) The TIMESTAMP alternate function can be mapped either to RTC_AF1 (PC13) |
sahilmgandhi | 18:6a4db94011d3 | 43 | or RTC_AF2 (PI8) depending on the value of TSINSEL bit in |
sahilmgandhi | 18:6a4db94011d3 | 44 | RTC_TAFCR register. The corresponding pin is also selected by HAL_RTCEx_SetTimeStamp() |
sahilmgandhi | 18:6a4db94011d3 | 45 | or HAL_RTCEx_SetTimeStamp_IT() function. |
sahilmgandhi | 18:6a4db94011d3 | 46 | |
sahilmgandhi | 18:6a4db94011d3 | 47 | *** Tamper configuration *** |
sahilmgandhi | 18:6a4db94011d3 | 48 | ============================ |
sahilmgandhi | 18:6a4db94011d3 | 49 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 50 | (+) Enable the RTC Tamper and configure the trigger using the HAL_RTCEx_SetTamper() function. |
sahilmgandhi | 18:6a4db94011d3 | 51 | You can configure RTC Tamper in interrupt mode using HAL_RTCEx_SetTamper_IT() function. |
sahilmgandhi | 18:6a4db94011d3 | 52 | (+) The TAMPER1 alternate function can be mapped either to RTC_AF1 (PC13) |
sahilmgandhi | 18:6a4db94011d3 | 53 | or RTC_AF2 (PI8) depending on the value of TAMP1INSEL bit in |
sahilmgandhi | 18:6a4db94011d3 | 54 | RTC_TAFCR register. The corresponding pin is also selected by HAL_RTCEx_SetTamper() |
sahilmgandhi | 18:6a4db94011d3 | 55 | or HAL_RTCEx_SetTamper_IT() function. |
sahilmgandhi | 18:6a4db94011d3 | 56 | |
sahilmgandhi | 18:6a4db94011d3 | 57 | *** Backup Data Registers configuration *** |
sahilmgandhi | 18:6a4db94011d3 | 58 | =========================================== |
sahilmgandhi | 18:6a4db94011d3 | 59 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 60 | (+) To write to the RTC Backup Data registers, use the HAL_RTCEx_BKUPWrite() |
sahilmgandhi | 18:6a4db94011d3 | 61 | function. |
sahilmgandhi | 18:6a4db94011d3 | 62 | (+) To read the RTC Backup Data registers, use the HAL_RTCEx_BKUPRead() |
sahilmgandhi | 18:6a4db94011d3 | 63 | function. |
sahilmgandhi | 18:6a4db94011d3 | 64 | |
sahilmgandhi | 18:6a4db94011d3 | 65 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 66 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 67 | * @attention |
sahilmgandhi | 18:6a4db94011d3 | 68 | * |
sahilmgandhi | 18:6a4db94011d3 | 69 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
sahilmgandhi | 18:6a4db94011d3 | 70 | * |
sahilmgandhi | 18:6a4db94011d3 | 71 | * Redistribution and use in source and binary forms, with or without modification, |
sahilmgandhi | 18:6a4db94011d3 | 72 | * are permitted provided that the following conditions are met: |
sahilmgandhi | 18:6a4db94011d3 | 73 | * 1. Redistributions of source code must retain the above copyright notice, |
sahilmgandhi | 18:6a4db94011d3 | 74 | * this list of conditions and the following disclaimer. |
sahilmgandhi | 18:6a4db94011d3 | 75 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
sahilmgandhi | 18:6a4db94011d3 | 76 | * this list of conditions and the following disclaimer in the documentation |
sahilmgandhi | 18:6a4db94011d3 | 77 | * and/or other materials provided with the distribution. |
sahilmgandhi | 18:6a4db94011d3 | 78 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
sahilmgandhi | 18:6a4db94011d3 | 79 | * may be used to endorse or promote products derived from this software |
sahilmgandhi | 18:6a4db94011d3 | 80 | * without specific prior written permission. |
sahilmgandhi | 18:6a4db94011d3 | 81 | * |
sahilmgandhi | 18:6a4db94011d3 | 82 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
sahilmgandhi | 18:6a4db94011d3 | 83 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
sahilmgandhi | 18:6a4db94011d3 | 84 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
sahilmgandhi | 18:6a4db94011d3 | 85 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
sahilmgandhi | 18:6a4db94011d3 | 86 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
sahilmgandhi | 18:6a4db94011d3 | 87 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
sahilmgandhi | 18:6a4db94011d3 | 88 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
sahilmgandhi | 18:6a4db94011d3 | 89 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
sahilmgandhi | 18:6a4db94011d3 | 90 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
sahilmgandhi | 18:6a4db94011d3 | 91 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
sahilmgandhi | 18:6a4db94011d3 | 92 | * |
sahilmgandhi | 18:6a4db94011d3 | 93 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 94 | */ |
sahilmgandhi | 18:6a4db94011d3 | 95 | |
sahilmgandhi | 18:6a4db94011d3 | 96 | /* Includes ------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 97 | #include "stm32f2xx_hal.h" |
sahilmgandhi | 18:6a4db94011d3 | 98 | |
sahilmgandhi | 18:6a4db94011d3 | 99 | /** @addtogroup STM32F2xx_HAL_Driver |
sahilmgandhi | 18:6a4db94011d3 | 100 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 101 | */ |
sahilmgandhi | 18:6a4db94011d3 | 102 | |
sahilmgandhi | 18:6a4db94011d3 | 103 | /** @defgroup RTCEx RTCEx |
sahilmgandhi | 18:6a4db94011d3 | 104 | * @brief RTC HAL module driver |
sahilmgandhi | 18:6a4db94011d3 | 105 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 106 | */ |
sahilmgandhi | 18:6a4db94011d3 | 107 | |
sahilmgandhi | 18:6a4db94011d3 | 108 | #ifdef HAL_RTC_MODULE_ENABLED |
sahilmgandhi | 18:6a4db94011d3 | 109 | |
sahilmgandhi | 18:6a4db94011d3 | 110 | /* Private typedef -----------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 111 | /* Private define ------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 112 | /* Private macro -------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 113 | /* Private variables ---------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 114 | /* Private function prototypes -----------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 115 | /* Private functions ---------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 116 | |
sahilmgandhi | 18:6a4db94011d3 | 117 | /** @defgroup RTCEx_Exported_Functions RTC Exported Functions |
sahilmgandhi | 18:6a4db94011d3 | 118 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 119 | */ |
sahilmgandhi | 18:6a4db94011d3 | 120 | |
sahilmgandhi | 18:6a4db94011d3 | 121 | /** @defgroup RTCEx_Exported_Functions_Group1 RTC TimeStamp and Tamper functions |
sahilmgandhi | 18:6a4db94011d3 | 122 | * @brief RTC TimeStamp and Tamper functions |
sahilmgandhi | 18:6a4db94011d3 | 123 | * |
sahilmgandhi | 18:6a4db94011d3 | 124 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 125 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 126 | ##### RTC TimeStamp and Tamper functions ##### |
sahilmgandhi | 18:6a4db94011d3 | 127 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 128 | |
sahilmgandhi | 18:6a4db94011d3 | 129 | [..] This section provides functions allowing to configure TimeStamp feature |
sahilmgandhi | 18:6a4db94011d3 | 130 | |
sahilmgandhi | 18:6a4db94011d3 | 131 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 132 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 133 | */ |
sahilmgandhi | 18:6a4db94011d3 | 134 | |
sahilmgandhi | 18:6a4db94011d3 | 135 | /** |
sahilmgandhi | 18:6a4db94011d3 | 136 | * @brief Sets TimeStamp. |
sahilmgandhi | 18:6a4db94011d3 | 137 | * @note This API must be called before enabling the TimeStamp feature. |
sahilmgandhi | 18:6a4db94011d3 | 138 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 139 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 140 | * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is |
sahilmgandhi | 18:6a4db94011d3 | 141 | * activated. |
sahilmgandhi | 18:6a4db94011d3 | 142 | * This parameter can be one of the following values: |
sahilmgandhi | 18:6a4db94011d3 | 143 | * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the |
sahilmgandhi | 18:6a4db94011d3 | 144 | * rising edge of the related pin. |
sahilmgandhi | 18:6a4db94011d3 | 145 | * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the |
sahilmgandhi | 18:6a4db94011d3 | 146 | * falling edge of the related pin. |
sahilmgandhi | 18:6a4db94011d3 | 147 | * @param RTC_TimeStampPin: specifies the RTC TimeStamp Pin. |
sahilmgandhi | 18:6a4db94011d3 | 148 | * This parameter can be one of the following values: |
sahilmgandhi | 18:6a4db94011d3 | 149 | * @arg RTC_TIMESTAMPPIN_DEFAULT: PC13 is selected as RTC TimeStamp Pin. |
sahilmgandhi | 18:6a4db94011d3 | 150 | * @arg RTC_TIMESTAMPPIN_POS1: PI8 is selected as RTC TimeStamp Pin. |
sahilmgandhi | 18:6a4db94011d3 | 151 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 152 | */ |
sahilmgandhi | 18:6a4db94011d3 | 153 | HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin) |
sahilmgandhi | 18:6a4db94011d3 | 154 | { |
sahilmgandhi | 18:6a4db94011d3 | 155 | uint32_t tmpreg = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 156 | |
sahilmgandhi | 18:6a4db94011d3 | 157 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 158 | assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge)); |
sahilmgandhi | 18:6a4db94011d3 | 159 | assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin)); |
sahilmgandhi | 18:6a4db94011d3 | 160 | |
sahilmgandhi | 18:6a4db94011d3 | 161 | /* Process Locked */ |
sahilmgandhi | 18:6a4db94011d3 | 162 | __HAL_LOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 163 | |
sahilmgandhi | 18:6a4db94011d3 | 164 | hrtc->State = HAL_RTC_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 165 | |
sahilmgandhi | 18:6a4db94011d3 | 166 | /* Get the RTC_CR register and clear the bits to be configured */ |
sahilmgandhi | 18:6a4db94011d3 | 167 | tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE)); |
sahilmgandhi | 18:6a4db94011d3 | 168 | |
sahilmgandhi | 18:6a4db94011d3 | 169 | tmpreg|= TimeStampEdge; |
sahilmgandhi | 18:6a4db94011d3 | 170 | |
sahilmgandhi | 18:6a4db94011d3 | 171 | /* Disable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 172 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 173 | |
sahilmgandhi | 18:6a4db94011d3 | 174 | hrtc->Instance->TAFCR &= (uint32_t)~RTC_TAFCR_TSINSEL; |
sahilmgandhi | 18:6a4db94011d3 | 175 | hrtc->Instance->TAFCR |= (uint32_t)(RTC_TimeStampPin); |
sahilmgandhi | 18:6a4db94011d3 | 176 | |
sahilmgandhi | 18:6a4db94011d3 | 177 | /* Configure the Time Stamp TSEDGE and Enable bits */ |
sahilmgandhi | 18:6a4db94011d3 | 178 | hrtc->Instance->CR = (uint32_t)tmpreg; |
sahilmgandhi | 18:6a4db94011d3 | 179 | |
sahilmgandhi | 18:6a4db94011d3 | 180 | __HAL_RTC_TIMESTAMP_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 181 | |
sahilmgandhi | 18:6a4db94011d3 | 182 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 183 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 184 | |
sahilmgandhi | 18:6a4db94011d3 | 185 | /* Change RTC state */ |
sahilmgandhi | 18:6a4db94011d3 | 186 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 187 | |
sahilmgandhi | 18:6a4db94011d3 | 188 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 189 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 190 | |
sahilmgandhi | 18:6a4db94011d3 | 191 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 192 | } |
sahilmgandhi | 18:6a4db94011d3 | 193 | |
sahilmgandhi | 18:6a4db94011d3 | 194 | /** |
sahilmgandhi | 18:6a4db94011d3 | 195 | * @brief Sets TimeStamp with Interrupt. |
sahilmgandhi | 18:6a4db94011d3 | 196 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 197 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 198 | * @note This API must be called before enabling the TimeStamp feature. |
sahilmgandhi | 18:6a4db94011d3 | 199 | * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is |
sahilmgandhi | 18:6a4db94011d3 | 200 | * activated. |
sahilmgandhi | 18:6a4db94011d3 | 201 | * This parameter can be one of the following values: |
sahilmgandhi | 18:6a4db94011d3 | 202 | * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the |
sahilmgandhi | 18:6a4db94011d3 | 203 | * rising edge of the related pin. |
sahilmgandhi | 18:6a4db94011d3 | 204 | * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the |
sahilmgandhi | 18:6a4db94011d3 | 205 | * falling edge of the related pin. |
sahilmgandhi | 18:6a4db94011d3 | 206 | * @param RTC_TimeStampPin: Specifies the RTC TimeStamp Pin. |
sahilmgandhi | 18:6a4db94011d3 | 207 | * This parameter can be one of the following values: |
sahilmgandhi | 18:6a4db94011d3 | 208 | * @arg RTC_TIMESTAMPPIN_DEFAULT: PC13 is selected as RTC TimeStamp Pin. |
sahilmgandhi | 18:6a4db94011d3 | 209 | * @arg RTC_TIMESTAMPPIN_POS1: PI8 is selected as RTC TimeStamp Pin. |
sahilmgandhi | 18:6a4db94011d3 | 210 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 211 | */ |
sahilmgandhi | 18:6a4db94011d3 | 212 | HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin) |
sahilmgandhi | 18:6a4db94011d3 | 213 | { |
sahilmgandhi | 18:6a4db94011d3 | 214 | uint32_t tmpreg = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 215 | |
sahilmgandhi | 18:6a4db94011d3 | 216 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 217 | assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge)); |
sahilmgandhi | 18:6a4db94011d3 | 218 | assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin)); |
sahilmgandhi | 18:6a4db94011d3 | 219 | |
sahilmgandhi | 18:6a4db94011d3 | 220 | /* Process Locked */ |
sahilmgandhi | 18:6a4db94011d3 | 221 | __HAL_LOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 222 | |
sahilmgandhi | 18:6a4db94011d3 | 223 | hrtc->State = HAL_RTC_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 224 | |
sahilmgandhi | 18:6a4db94011d3 | 225 | /* Get the RTC_CR register and clear the bits to be configured */ |
sahilmgandhi | 18:6a4db94011d3 | 226 | tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE)); |
sahilmgandhi | 18:6a4db94011d3 | 227 | |
sahilmgandhi | 18:6a4db94011d3 | 228 | tmpreg |= TimeStampEdge; |
sahilmgandhi | 18:6a4db94011d3 | 229 | |
sahilmgandhi | 18:6a4db94011d3 | 230 | /* Disable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 231 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 232 | |
sahilmgandhi | 18:6a4db94011d3 | 233 | /* Configure the Time Stamp TSEDGE and Enable bits */ |
sahilmgandhi | 18:6a4db94011d3 | 234 | hrtc->Instance->CR = (uint32_t)tmpreg; |
sahilmgandhi | 18:6a4db94011d3 | 235 | |
sahilmgandhi | 18:6a4db94011d3 | 236 | hrtc->Instance->TAFCR &= (uint32_t)~RTC_TAFCR_TSINSEL; |
sahilmgandhi | 18:6a4db94011d3 | 237 | hrtc->Instance->TAFCR |= (uint32_t)(RTC_TimeStampPin); |
sahilmgandhi | 18:6a4db94011d3 | 238 | |
sahilmgandhi | 18:6a4db94011d3 | 239 | /* Clear RTC Timestamp flag */ |
sahilmgandhi | 18:6a4db94011d3 | 240 | __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF); |
sahilmgandhi | 18:6a4db94011d3 | 241 | |
sahilmgandhi | 18:6a4db94011d3 | 242 | __HAL_RTC_TIMESTAMP_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 243 | |
sahilmgandhi | 18:6a4db94011d3 | 244 | /* Enable IT timestamp */ |
sahilmgandhi | 18:6a4db94011d3 | 245 | __HAL_RTC_TIMESTAMP_ENABLE_IT(hrtc,RTC_IT_TS); |
sahilmgandhi | 18:6a4db94011d3 | 246 | |
sahilmgandhi | 18:6a4db94011d3 | 247 | /* RTC timestamp Interrupt Configuration: EXTI configuration */ |
sahilmgandhi | 18:6a4db94011d3 | 248 | __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT(); |
sahilmgandhi | 18:6a4db94011d3 | 249 | |
sahilmgandhi | 18:6a4db94011d3 | 250 | EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT; |
sahilmgandhi | 18:6a4db94011d3 | 251 | |
sahilmgandhi | 18:6a4db94011d3 | 252 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 253 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 254 | |
sahilmgandhi | 18:6a4db94011d3 | 255 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 256 | |
sahilmgandhi | 18:6a4db94011d3 | 257 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 258 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 259 | |
sahilmgandhi | 18:6a4db94011d3 | 260 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 261 | } |
sahilmgandhi | 18:6a4db94011d3 | 262 | |
sahilmgandhi | 18:6a4db94011d3 | 263 | /** |
sahilmgandhi | 18:6a4db94011d3 | 264 | * @brief Deactivates TimeStamp. |
sahilmgandhi | 18:6a4db94011d3 | 265 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 266 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 267 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 268 | */ |
sahilmgandhi | 18:6a4db94011d3 | 269 | HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc) |
sahilmgandhi | 18:6a4db94011d3 | 270 | { |
sahilmgandhi | 18:6a4db94011d3 | 271 | uint32_t tmpreg = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 272 | |
sahilmgandhi | 18:6a4db94011d3 | 273 | /* Process Locked */ |
sahilmgandhi | 18:6a4db94011d3 | 274 | __HAL_LOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 275 | |
sahilmgandhi | 18:6a4db94011d3 | 276 | hrtc->State = HAL_RTC_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 277 | |
sahilmgandhi | 18:6a4db94011d3 | 278 | /* Disable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 279 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 280 | |
sahilmgandhi | 18:6a4db94011d3 | 281 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
sahilmgandhi | 18:6a4db94011d3 | 282 | __HAL_RTC_TIMESTAMP_DISABLE_IT(hrtc, RTC_IT_TS); |
sahilmgandhi | 18:6a4db94011d3 | 283 | |
sahilmgandhi | 18:6a4db94011d3 | 284 | /* Get the RTC_CR register and clear the bits to be configured */ |
sahilmgandhi | 18:6a4db94011d3 | 285 | tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE)); |
sahilmgandhi | 18:6a4db94011d3 | 286 | |
sahilmgandhi | 18:6a4db94011d3 | 287 | /* Configure the Time Stamp TSEDGE and Enable bits */ |
sahilmgandhi | 18:6a4db94011d3 | 288 | hrtc->Instance->CR = (uint32_t)tmpreg; |
sahilmgandhi | 18:6a4db94011d3 | 289 | |
sahilmgandhi | 18:6a4db94011d3 | 290 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 291 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 292 | |
sahilmgandhi | 18:6a4db94011d3 | 293 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 294 | |
sahilmgandhi | 18:6a4db94011d3 | 295 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 296 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 297 | |
sahilmgandhi | 18:6a4db94011d3 | 298 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 299 | } |
sahilmgandhi | 18:6a4db94011d3 | 300 | |
sahilmgandhi | 18:6a4db94011d3 | 301 | /** |
sahilmgandhi | 18:6a4db94011d3 | 302 | * @brief Gets the RTC TimeStamp value. |
sahilmgandhi | 18:6a4db94011d3 | 303 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 304 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 305 | * @param sTimeStamp: Pointer to Time structure |
sahilmgandhi | 18:6a4db94011d3 | 306 | * @param sTimeStampDate: Pointer to Date structure |
sahilmgandhi | 18:6a4db94011d3 | 307 | * @param Format: specifies the format of the entered parameters. |
sahilmgandhi | 18:6a4db94011d3 | 308 | * This parameter can be one of the following values: |
sahilmgandhi | 18:6a4db94011d3 | 309 | * RTC_FORMAT_BIN: Binary data format |
sahilmgandhi | 18:6a4db94011d3 | 310 | * RTC_FORMAT_BCD: BCD data format |
sahilmgandhi | 18:6a4db94011d3 | 311 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 312 | */ |
sahilmgandhi | 18:6a4db94011d3 | 313 | HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef* sTimeStamp, RTC_DateTypeDef* sTimeStampDate, uint32_t Format) |
sahilmgandhi | 18:6a4db94011d3 | 314 | { |
sahilmgandhi | 18:6a4db94011d3 | 315 | uint32_t tmptime = 0U, tmpdate = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 316 | |
sahilmgandhi | 18:6a4db94011d3 | 317 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 318 | assert_param(IS_RTC_FORMAT(Format)); |
sahilmgandhi | 18:6a4db94011d3 | 319 | |
sahilmgandhi | 18:6a4db94011d3 | 320 | /* Get the TimeStamp time and date registers values */ |
sahilmgandhi | 18:6a4db94011d3 | 321 | tmptime = (uint32_t)(hrtc->Instance->TSTR & RTC_TR_RESERVED_MASK); |
sahilmgandhi | 18:6a4db94011d3 | 322 | tmpdate = (uint32_t)(hrtc->Instance->TSDR & RTC_DR_RESERVED_MASK); |
sahilmgandhi | 18:6a4db94011d3 | 323 | |
sahilmgandhi | 18:6a4db94011d3 | 324 | /* Fill the Time structure fields with the read parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 325 | sTimeStamp->Hours = (uint8_t)((tmptime & (RTC_TR_HT | RTC_TR_HU)) >> 16U); |
sahilmgandhi | 18:6a4db94011d3 | 326 | sTimeStamp->Minutes = (uint8_t)((tmptime & (RTC_TR_MNT | RTC_TR_MNU)) >> 8U); |
sahilmgandhi | 18:6a4db94011d3 | 327 | sTimeStamp->Seconds = (uint8_t)(tmptime & (RTC_TR_ST | RTC_TR_SU)); |
sahilmgandhi | 18:6a4db94011d3 | 328 | sTimeStamp->TimeFormat = (uint8_t)((tmptime & (RTC_TR_PM)) >> 16U); |
sahilmgandhi | 18:6a4db94011d3 | 329 | |
sahilmgandhi | 18:6a4db94011d3 | 330 | /* Fill the Date structure fields with the read parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 331 | sTimeStampDate->Year = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 332 | sTimeStampDate->Month = (uint8_t)((tmpdate & (RTC_DR_MT | RTC_DR_MU)) >> 8U); |
sahilmgandhi | 18:6a4db94011d3 | 333 | sTimeStampDate->Date = (uint8_t)(tmpdate & (RTC_DR_DT | RTC_DR_DU)); |
sahilmgandhi | 18:6a4db94011d3 | 334 | sTimeStampDate->WeekDay = (uint8_t)((tmpdate & (RTC_DR_WDU)) >> 13U); |
sahilmgandhi | 18:6a4db94011d3 | 335 | |
sahilmgandhi | 18:6a4db94011d3 | 336 | /* Check the input parameters format */ |
sahilmgandhi | 18:6a4db94011d3 | 337 | if(Format == RTC_FORMAT_BIN) |
sahilmgandhi | 18:6a4db94011d3 | 338 | { |
sahilmgandhi | 18:6a4db94011d3 | 339 | /* Convert the TimeStamp structure parameters to Binary format */ |
sahilmgandhi | 18:6a4db94011d3 | 340 | sTimeStamp->Hours = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Hours); |
sahilmgandhi | 18:6a4db94011d3 | 341 | sTimeStamp->Minutes = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Minutes); |
sahilmgandhi | 18:6a4db94011d3 | 342 | sTimeStamp->Seconds = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Seconds); |
sahilmgandhi | 18:6a4db94011d3 | 343 | |
sahilmgandhi | 18:6a4db94011d3 | 344 | /* Convert the DateTimeStamp structure parameters to Binary format */ |
sahilmgandhi | 18:6a4db94011d3 | 345 | sTimeStampDate->Month = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Month); |
sahilmgandhi | 18:6a4db94011d3 | 346 | sTimeStampDate->Date = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Date); |
sahilmgandhi | 18:6a4db94011d3 | 347 | sTimeStampDate->WeekDay = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->WeekDay); |
sahilmgandhi | 18:6a4db94011d3 | 348 | } |
sahilmgandhi | 18:6a4db94011d3 | 349 | |
sahilmgandhi | 18:6a4db94011d3 | 350 | /* Clear the TIMESTAMP Flag */ |
sahilmgandhi | 18:6a4db94011d3 | 351 | __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF); |
sahilmgandhi | 18:6a4db94011d3 | 352 | |
sahilmgandhi | 18:6a4db94011d3 | 353 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 354 | } |
sahilmgandhi | 18:6a4db94011d3 | 355 | |
sahilmgandhi | 18:6a4db94011d3 | 356 | /** |
sahilmgandhi | 18:6a4db94011d3 | 357 | * @brief Sets Tamper |
sahilmgandhi | 18:6a4db94011d3 | 358 | * @note By calling this API we disable the tamper interrupt for all tampers. |
sahilmgandhi | 18:6a4db94011d3 | 359 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 360 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 361 | * @param sTamper: Pointer to Tamper Structure. |
sahilmgandhi | 18:6a4db94011d3 | 362 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 363 | */ |
sahilmgandhi | 18:6a4db94011d3 | 364 | HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper) |
sahilmgandhi | 18:6a4db94011d3 | 365 | { |
sahilmgandhi | 18:6a4db94011d3 | 366 | uint32_t tmpreg = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 367 | |
sahilmgandhi | 18:6a4db94011d3 | 368 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 369 | assert_param(IS_RTC_TAMPER(sTamper->Tamper)); |
sahilmgandhi | 18:6a4db94011d3 | 370 | assert_param(IS_RTC_TAMPER_PIN(sTamper->PinSelection)); |
sahilmgandhi | 18:6a4db94011d3 | 371 | assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger)); |
sahilmgandhi | 18:6a4db94011d3 | 372 | |
sahilmgandhi | 18:6a4db94011d3 | 373 | /* Process Locked */ |
sahilmgandhi | 18:6a4db94011d3 | 374 | __HAL_LOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 375 | |
sahilmgandhi | 18:6a4db94011d3 | 376 | hrtc->State = HAL_RTC_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 377 | |
sahilmgandhi | 18:6a4db94011d3 | 378 | tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->PinSelection | (uint32_t)(sTamper->Trigger)); |
sahilmgandhi | 18:6a4db94011d3 | 379 | |
sahilmgandhi | 18:6a4db94011d3 | 380 | hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)RTC_TAFCR_TAMP1E | (uint32_t)RTC_TAFCR_TAMP1TRG | (uint32_t)RTC_TAFCR_TAMPINSEL); |
sahilmgandhi | 18:6a4db94011d3 | 381 | |
sahilmgandhi | 18:6a4db94011d3 | 382 | hrtc->Instance->TAFCR |= tmpreg; |
sahilmgandhi | 18:6a4db94011d3 | 383 | |
sahilmgandhi | 18:6a4db94011d3 | 384 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 385 | |
sahilmgandhi | 18:6a4db94011d3 | 386 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 387 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 388 | |
sahilmgandhi | 18:6a4db94011d3 | 389 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 390 | } |
sahilmgandhi | 18:6a4db94011d3 | 391 | |
sahilmgandhi | 18:6a4db94011d3 | 392 | /** |
sahilmgandhi | 18:6a4db94011d3 | 393 | * @brief Sets Tamper with interrupt. |
sahilmgandhi | 18:6a4db94011d3 | 394 | * @note By calling this API we force the tamper interrupt for all tampers. |
sahilmgandhi | 18:6a4db94011d3 | 395 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 396 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 397 | * @param sTamper: Pointer to RTC Tamper. |
sahilmgandhi | 18:6a4db94011d3 | 398 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 399 | */ |
sahilmgandhi | 18:6a4db94011d3 | 400 | HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper) |
sahilmgandhi | 18:6a4db94011d3 | 401 | { |
sahilmgandhi | 18:6a4db94011d3 | 402 | uint32_t tmpreg = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 403 | |
sahilmgandhi | 18:6a4db94011d3 | 404 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 405 | assert_param(IS_RTC_TAMPER(sTamper->Tamper)); |
sahilmgandhi | 18:6a4db94011d3 | 406 | assert_param(IS_RTC_TAMPER_PIN(sTamper->PinSelection)); |
sahilmgandhi | 18:6a4db94011d3 | 407 | assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger)); |
sahilmgandhi | 18:6a4db94011d3 | 408 | |
sahilmgandhi | 18:6a4db94011d3 | 409 | /* Process Locked */ |
sahilmgandhi | 18:6a4db94011d3 | 410 | __HAL_LOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 411 | |
sahilmgandhi | 18:6a4db94011d3 | 412 | hrtc->State = HAL_RTC_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 413 | |
sahilmgandhi | 18:6a4db94011d3 | 414 | tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->PinSelection | (uint32_t)sTamper->Trigger); |
sahilmgandhi | 18:6a4db94011d3 | 415 | |
sahilmgandhi | 18:6a4db94011d3 | 416 | hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)RTC_TAFCR_TAMP1E | (uint32_t)RTC_TAFCR_TAMP1TRG | (uint32_t)RTC_TAFCR_TAMPINSEL | (uint32_t)RTC_TAFCR_TAMPIE); |
sahilmgandhi | 18:6a4db94011d3 | 417 | |
sahilmgandhi | 18:6a4db94011d3 | 418 | hrtc->Instance->TAFCR |= tmpreg; |
sahilmgandhi | 18:6a4db94011d3 | 419 | |
sahilmgandhi | 18:6a4db94011d3 | 420 | /* Configure the Tamper Interrupt in the RTC_TAFCR */ |
sahilmgandhi | 18:6a4db94011d3 | 421 | hrtc->Instance->TAFCR |= (uint32_t)RTC_TAFCR_TAMPIE; |
sahilmgandhi | 18:6a4db94011d3 | 422 | |
sahilmgandhi | 18:6a4db94011d3 | 423 | /* Clear RTC Tamper 1 flag */ |
sahilmgandhi | 18:6a4db94011d3 | 424 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F); |
sahilmgandhi | 18:6a4db94011d3 | 425 | |
sahilmgandhi | 18:6a4db94011d3 | 426 | /* RTC Tamper Interrupt Configuration: EXTI configuration */ |
sahilmgandhi | 18:6a4db94011d3 | 427 | __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT(); |
sahilmgandhi | 18:6a4db94011d3 | 428 | |
sahilmgandhi | 18:6a4db94011d3 | 429 | EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT; |
sahilmgandhi | 18:6a4db94011d3 | 430 | |
sahilmgandhi | 18:6a4db94011d3 | 431 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 432 | |
sahilmgandhi | 18:6a4db94011d3 | 433 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 434 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 435 | |
sahilmgandhi | 18:6a4db94011d3 | 436 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 437 | } |
sahilmgandhi | 18:6a4db94011d3 | 438 | |
sahilmgandhi | 18:6a4db94011d3 | 439 | /** |
sahilmgandhi | 18:6a4db94011d3 | 440 | * @brief Deactivates Tamper. |
sahilmgandhi | 18:6a4db94011d3 | 441 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 442 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 443 | * @param Tamper: Selected tamper pin. |
sahilmgandhi | 18:6a4db94011d3 | 444 | * This parameter can be RTC_Tamper_1. |
sahilmgandhi | 18:6a4db94011d3 | 445 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 446 | */ |
sahilmgandhi | 18:6a4db94011d3 | 447 | HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper) |
sahilmgandhi | 18:6a4db94011d3 | 448 | { |
sahilmgandhi | 18:6a4db94011d3 | 449 | assert_param(IS_RTC_TAMPER(Tamper)); |
sahilmgandhi | 18:6a4db94011d3 | 450 | |
sahilmgandhi | 18:6a4db94011d3 | 451 | /* Process Locked */ |
sahilmgandhi | 18:6a4db94011d3 | 452 | __HAL_LOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 453 | |
sahilmgandhi | 18:6a4db94011d3 | 454 | hrtc->State = HAL_RTC_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 455 | |
sahilmgandhi | 18:6a4db94011d3 | 456 | /* Disable the selected Tamper pin */ |
sahilmgandhi | 18:6a4db94011d3 | 457 | hrtc->Instance->TAFCR &= (uint32_t)~Tamper; |
sahilmgandhi | 18:6a4db94011d3 | 458 | |
sahilmgandhi | 18:6a4db94011d3 | 459 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 460 | |
sahilmgandhi | 18:6a4db94011d3 | 461 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 462 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 463 | |
sahilmgandhi | 18:6a4db94011d3 | 464 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 465 | } |
sahilmgandhi | 18:6a4db94011d3 | 466 | |
sahilmgandhi | 18:6a4db94011d3 | 467 | /** |
sahilmgandhi | 18:6a4db94011d3 | 468 | * @brief This function handles TimeStamp interrupt request. |
sahilmgandhi | 18:6a4db94011d3 | 469 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 470 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 471 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 472 | */ |
sahilmgandhi | 18:6a4db94011d3 | 473 | void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc) |
sahilmgandhi | 18:6a4db94011d3 | 474 | { |
sahilmgandhi | 18:6a4db94011d3 | 475 | if(__HAL_RTC_TIMESTAMP_GET_IT(hrtc, RTC_IT_TS)) |
sahilmgandhi | 18:6a4db94011d3 | 476 | { |
sahilmgandhi | 18:6a4db94011d3 | 477 | /* Get the status of the Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 478 | if((uint32_t)(hrtc->Instance->CR & RTC_IT_TS) != (uint32_t)RESET) |
sahilmgandhi | 18:6a4db94011d3 | 479 | { |
sahilmgandhi | 18:6a4db94011d3 | 480 | /* TIMESTAMP callback */ |
sahilmgandhi | 18:6a4db94011d3 | 481 | HAL_RTCEx_TimeStampEventCallback(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 482 | |
sahilmgandhi | 18:6a4db94011d3 | 483 | /* Clear the TIMESTAMP interrupt pending bit */ |
sahilmgandhi | 18:6a4db94011d3 | 484 | __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc,RTC_FLAG_TSF); |
sahilmgandhi | 18:6a4db94011d3 | 485 | } |
sahilmgandhi | 18:6a4db94011d3 | 486 | } |
sahilmgandhi | 18:6a4db94011d3 | 487 | |
sahilmgandhi | 18:6a4db94011d3 | 488 | /* Get the status of the Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 489 | if(__HAL_RTC_TAMPER_GET_IT(hrtc,RTC_IT_TAMP1)) |
sahilmgandhi | 18:6a4db94011d3 | 490 | { |
sahilmgandhi | 18:6a4db94011d3 | 491 | /* Get the TAMPER Interrupt enable bit and pending bit */ |
sahilmgandhi | 18:6a4db94011d3 | 492 | if(((hrtc->Instance->TAFCR & (RTC_TAFCR_TAMPIE))) != (uint32_t)RESET) |
sahilmgandhi | 18:6a4db94011d3 | 493 | { |
sahilmgandhi | 18:6a4db94011d3 | 494 | /* Tamper callback */ |
sahilmgandhi | 18:6a4db94011d3 | 495 | HAL_RTCEx_Tamper1EventCallback(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 496 | |
sahilmgandhi | 18:6a4db94011d3 | 497 | /* Clear the Tamper interrupt pending bit */ |
sahilmgandhi | 18:6a4db94011d3 | 498 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F); |
sahilmgandhi | 18:6a4db94011d3 | 499 | } |
sahilmgandhi | 18:6a4db94011d3 | 500 | } |
sahilmgandhi | 18:6a4db94011d3 | 501 | |
sahilmgandhi | 18:6a4db94011d3 | 502 | /* Clear the EXTI's Flag for RTC TimeStamp and Tamper */ |
sahilmgandhi | 18:6a4db94011d3 | 503 | __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG(); |
sahilmgandhi | 18:6a4db94011d3 | 504 | |
sahilmgandhi | 18:6a4db94011d3 | 505 | /* Change RTC state */ |
sahilmgandhi | 18:6a4db94011d3 | 506 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 507 | } |
sahilmgandhi | 18:6a4db94011d3 | 508 | |
sahilmgandhi | 18:6a4db94011d3 | 509 | /** |
sahilmgandhi | 18:6a4db94011d3 | 510 | * @brief TimeStamp callback. |
sahilmgandhi | 18:6a4db94011d3 | 511 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 512 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 513 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 514 | */ |
sahilmgandhi | 18:6a4db94011d3 | 515 | __weak void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc) |
sahilmgandhi | 18:6a4db94011d3 | 516 | { |
sahilmgandhi | 18:6a4db94011d3 | 517 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 518 | UNUSED(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 519 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 520 | the HAL_RTC_TimeStampEventCallback could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 521 | */ |
sahilmgandhi | 18:6a4db94011d3 | 522 | } |
sahilmgandhi | 18:6a4db94011d3 | 523 | |
sahilmgandhi | 18:6a4db94011d3 | 524 | /** |
sahilmgandhi | 18:6a4db94011d3 | 525 | * @brief Tamper 1 callback. |
sahilmgandhi | 18:6a4db94011d3 | 526 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 527 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 528 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 529 | */ |
sahilmgandhi | 18:6a4db94011d3 | 530 | __weak void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc) |
sahilmgandhi | 18:6a4db94011d3 | 531 | { |
sahilmgandhi | 18:6a4db94011d3 | 532 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 533 | UNUSED(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 534 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 535 | the HAL_RTC_Tamper1EventCallback could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 536 | */ |
sahilmgandhi | 18:6a4db94011d3 | 537 | } |
sahilmgandhi | 18:6a4db94011d3 | 538 | |
sahilmgandhi | 18:6a4db94011d3 | 539 | /** |
sahilmgandhi | 18:6a4db94011d3 | 540 | * @brief This function handles TimeStamp polling request. |
sahilmgandhi | 18:6a4db94011d3 | 541 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 542 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 543 | * @param Timeout: Timeout duration |
sahilmgandhi | 18:6a4db94011d3 | 544 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 545 | */ |
sahilmgandhi | 18:6a4db94011d3 | 546 | HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
sahilmgandhi | 18:6a4db94011d3 | 547 | { |
sahilmgandhi | 18:6a4db94011d3 | 548 | uint32_t tickstart = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 549 | |
sahilmgandhi | 18:6a4db94011d3 | 550 | /* Get tick */ |
sahilmgandhi | 18:6a4db94011d3 | 551 | tickstart = HAL_GetTick(); |
sahilmgandhi | 18:6a4db94011d3 | 552 | |
sahilmgandhi | 18:6a4db94011d3 | 553 | while(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) == RESET) |
sahilmgandhi | 18:6a4db94011d3 | 554 | { |
sahilmgandhi | 18:6a4db94011d3 | 555 | if(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSOVF) != RESET) |
sahilmgandhi | 18:6a4db94011d3 | 556 | { |
sahilmgandhi | 18:6a4db94011d3 | 557 | /* Clear the TIMESTAMP Overrun Flag */ |
sahilmgandhi | 18:6a4db94011d3 | 558 | __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSOVF); |
sahilmgandhi | 18:6a4db94011d3 | 559 | |
sahilmgandhi | 18:6a4db94011d3 | 560 | /* Change TIMESTAMP state */ |
sahilmgandhi | 18:6a4db94011d3 | 561 | hrtc->State = HAL_RTC_STATE_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 562 | |
sahilmgandhi | 18:6a4db94011d3 | 563 | return HAL_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 564 | } |
sahilmgandhi | 18:6a4db94011d3 | 565 | |
sahilmgandhi | 18:6a4db94011d3 | 566 | if(Timeout != HAL_MAX_DELAY) |
sahilmgandhi | 18:6a4db94011d3 | 567 | { |
sahilmgandhi | 18:6a4db94011d3 | 568 | if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout)) |
sahilmgandhi | 18:6a4db94011d3 | 569 | { |
sahilmgandhi | 18:6a4db94011d3 | 570 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 571 | return HAL_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 572 | } |
sahilmgandhi | 18:6a4db94011d3 | 573 | } |
sahilmgandhi | 18:6a4db94011d3 | 574 | } |
sahilmgandhi | 18:6a4db94011d3 | 575 | |
sahilmgandhi | 18:6a4db94011d3 | 576 | /* Change RTC state */ |
sahilmgandhi | 18:6a4db94011d3 | 577 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 578 | |
sahilmgandhi | 18:6a4db94011d3 | 579 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 580 | } |
sahilmgandhi | 18:6a4db94011d3 | 581 | |
sahilmgandhi | 18:6a4db94011d3 | 582 | /** |
sahilmgandhi | 18:6a4db94011d3 | 583 | * @brief This function handles Tamper1 Polling. |
sahilmgandhi | 18:6a4db94011d3 | 584 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 585 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 586 | * @param Timeout: Timeout duration |
sahilmgandhi | 18:6a4db94011d3 | 587 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 588 | */ |
sahilmgandhi | 18:6a4db94011d3 | 589 | HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
sahilmgandhi | 18:6a4db94011d3 | 590 | { |
sahilmgandhi | 18:6a4db94011d3 | 591 | uint32_t tickstart = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 592 | |
sahilmgandhi | 18:6a4db94011d3 | 593 | /* Get tick */ |
sahilmgandhi | 18:6a4db94011d3 | 594 | tickstart = HAL_GetTick(); |
sahilmgandhi | 18:6a4db94011d3 | 595 | |
sahilmgandhi | 18:6a4db94011d3 | 596 | /* Get the status of the Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 597 | while(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F)== RESET) |
sahilmgandhi | 18:6a4db94011d3 | 598 | { |
sahilmgandhi | 18:6a4db94011d3 | 599 | if(Timeout != HAL_MAX_DELAY) |
sahilmgandhi | 18:6a4db94011d3 | 600 | { |
sahilmgandhi | 18:6a4db94011d3 | 601 | if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout)) |
sahilmgandhi | 18:6a4db94011d3 | 602 | { |
sahilmgandhi | 18:6a4db94011d3 | 603 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 604 | return HAL_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 605 | } |
sahilmgandhi | 18:6a4db94011d3 | 606 | } |
sahilmgandhi | 18:6a4db94011d3 | 607 | } |
sahilmgandhi | 18:6a4db94011d3 | 608 | |
sahilmgandhi | 18:6a4db94011d3 | 609 | /* Clear the Tamper Flag */ |
sahilmgandhi | 18:6a4db94011d3 | 610 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F); |
sahilmgandhi | 18:6a4db94011d3 | 611 | |
sahilmgandhi | 18:6a4db94011d3 | 612 | /* Change RTC state */ |
sahilmgandhi | 18:6a4db94011d3 | 613 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 614 | |
sahilmgandhi | 18:6a4db94011d3 | 615 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 616 | } |
sahilmgandhi | 18:6a4db94011d3 | 617 | |
sahilmgandhi | 18:6a4db94011d3 | 618 | /** |
sahilmgandhi | 18:6a4db94011d3 | 619 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 620 | */ |
sahilmgandhi | 18:6a4db94011d3 | 621 | |
sahilmgandhi | 18:6a4db94011d3 | 622 | /** @defgroup RTCEx_Exported_Functions_Group2 RTC Wake-up functions |
sahilmgandhi | 18:6a4db94011d3 | 623 | * @brief RTC Wake-up functions |
sahilmgandhi | 18:6a4db94011d3 | 624 | * |
sahilmgandhi | 18:6a4db94011d3 | 625 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 626 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 627 | ##### RTC Wake-up functions ##### |
sahilmgandhi | 18:6a4db94011d3 | 628 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 629 | |
sahilmgandhi | 18:6a4db94011d3 | 630 | [..] This section provides functions allowing to configure Wake-up feature |
sahilmgandhi | 18:6a4db94011d3 | 631 | |
sahilmgandhi | 18:6a4db94011d3 | 632 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 633 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 634 | */ |
sahilmgandhi | 18:6a4db94011d3 | 635 | |
sahilmgandhi | 18:6a4db94011d3 | 636 | /** |
sahilmgandhi | 18:6a4db94011d3 | 637 | * @brief Sets wake up timer. |
sahilmgandhi | 18:6a4db94011d3 | 638 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 639 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 640 | * @param WakeUpCounter: Wake up counter |
sahilmgandhi | 18:6a4db94011d3 | 641 | * @param WakeUpClock: Wake up clock |
sahilmgandhi | 18:6a4db94011d3 | 642 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 643 | */ |
sahilmgandhi | 18:6a4db94011d3 | 644 | HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock) |
sahilmgandhi | 18:6a4db94011d3 | 645 | { |
sahilmgandhi | 18:6a4db94011d3 | 646 | uint32_t tickstart = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 647 | |
sahilmgandhi | 18:6a4db94011d3 | 648 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 649 | assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock)); |
sahilmgandhi | 18:6a4db94011d3 | 650 | assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter)); |
sahilmgandhi | 18:6a4db94011d3 | 651 | |
sahilmgandhi | 18:6a4db94011d3 | 652 | /* Process Locked */ |
sahilmgandhi | 18:6a4db94011d3 | 653 | __HAL_LOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 654 | |
sahilmgandhi | 18:6a4db94011d3 | 655 | hrtc->State = HAL_RTC_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 656 | |
sahilmgandhi | 18:6a4db94011d3 | 657 | /* Disable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 658 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 659 | |
sahilmgandhi | 18:6a4db94011d3 | 660 | /*Check RTC WUTWF flag is reset only when wake up timer enabled*/ |
sahilmgandhi | 18:6a4db94011d3 | 661 | if((hrtc->Instance->CR & RTC_CR_WUTE) != RESET) |
sahilmgandhi | 18:6a4db94011d3 | 662 | { |
sahilmgandhi | 18:6a4db94011d3 | 663 | tickstart = HAL_GetTick(); |
sahilmgandhi | 18:6a4db94011d3 | 664 | |
sahilmgandhi | 18:6a4db94011d3 | 665 | /* Wait till RTC WUTWF flag is reset and if Time out is reached exit */ |
sahilmgandhi | 18:6a4db94011d3 | 666 | while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == SET) |
sahilmgandhi | 18:6a4db94011d3 | 667 | { |
sahilmgandhi | 18:6a4db94011d3 | 668 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
sahilmgandhi | 18:6a4db94011d3 | 669 | { |
sahilmgandhi | 18:6a4db94011d3 | 670 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 671 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 672 | |
sahilmgandhi | 18:6a4db94011d3 | 673 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 674 | |
sahilmgandhi | 18:6a4db94011d3 | 675 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 676 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 677 | |
sahilmgandhi | 18:6a4db94011d3 | 678 | return HAL_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 679 | } |
sahilmgandhi | 18:6a4db94011d3 | 680 | } |
sahilmgandhi | 18:6a4db94011d3 | 681 | } |
sahilmgandhi | 18:6a4db94011d3 | 682 | |
sahilmgandhi | 18:6a4db94011d3 | 683 | __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 684 | |
sahilmgandhi | 18:6a4db94011d3 | 685 | /* Get tick */ |
sahilmgandhi | 18:6a4db94011d3 | 686 | tickstart = HAL_GetTick(); |
sahilmgandhi | 18:6a4db94011d3 | 687 | |
sahilmgandhi | 18:6a4db94011d3 | 688 | /* Wait till RTC WUTWF flag is set and if Time out is reached exit */ |
sahilmgandhi | 18:6a4db94011d3 | 689 | while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET) |
sahilmgandhi | 18:6a4db94011d3 | 690 | { |
sahilmgandhi | 18:6a4db94011d3 | 691 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
sahilmgandhi | 18:6a4db94011d3 | 692 | { |
sahilmgandhi | 18:6a4db94011d3 | 693 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 694 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 695 | |
sahilmgandhi | 18:6a4db94011d3 | 696 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 697 | |
sahilmgandhi | 18:6a4db94011d3 | 698 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 699 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 700 | |
sahilmgandhi | 18:6a4db94011d3 | 701 | return HAL_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 702 | } |
sahilmgandhi | 18:6a4db94011d3 | 703 | } |
sahilmgandhi | 18:6a4db94011d3 | 704 | |
sahilmgandhi | 18:6a4db94011d3 | 705 | /* Clear the Wake-up Timer clock source bits in CR register */ |
sahilmgandhi | 18:6a4db94011d3 | 706 | hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL; |
sahilmgandhi | 18:6a4db94011d3 | 707 | |
sahilmgandhi | 18:6a4db94011d3 | 708 | /* Configure the clock source */ |
sahilmgandhi | 18:6a4db94011d3 | 709 | hrtc->Instance->CR |= (uint32_t)WakeUpClock; |
sahilmgandhi | 18:6a4db94011d3 | 710 | |
sahilmgandhi | 18:6a4db94011d3 | 711 | /* Configure the Wake-up Timer counter */ |
sahilmgandhi | 18:6a4db94011d3 | 712 | hrtc->Instance->WUTR = (uint32_t)WakeUpCounter; |
sahilmgandhi | 18:6a4db94011d3 | 713 | |
sahilmgandhi | 18:6a4db94011d3 | 714 | /* Enable the Wake-up Timer */ |
sahilmgandhi | 18:6a4db94011d3 | 715 | __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 716 | |
sahilmgandhi | 18:6a4db94011d3 | 717 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 718 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 719 | |
sahilmgandhi | 18:6a4db94011d3 | 720 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 721 | |
sahilmgandhi | 18:6a4db94011d3 | 722 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 723 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 724 | |
sahilmgandhi | 18:6a4db94011d3 | 725 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 726 | } |
sahilmgandhi | 18:6a4db94011d3 | 727 | |
sahilmgandhi | 18:6a4db94011d3 | 728 | /** |
sahilmgandhi | 18:6a4db94011d3 | 729 | * @brief Sets wake up timer with interrupt |
sahilmgandhi | 18:6a4db94011d3 | 730 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 731 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 732 | * @param WakeUpCounter: Wake up counter |
sahilmgandhi | 18:6a4db94011d3 | 733 | * @param WakeUpClock: Wake up clock |
sahilmgandhi | 18:6a4db94011d3 | 734 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 735 | */ |
sahilmgandhi | 18:6a4db94011d3 | 736 | HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock) |
sahilmgandhi | 18:6a4db94011d3 | 737 | { |
sahilmgandhi | 18:6a4db94011d3 | 738 | __IO uint32_t count; |
sahilmgandhi | 18:6a4db94011d3 | 739 | |
sahilmgandhi | 18:6a4db94011d3 | 740 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 741 | assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock)); |
sahilmgandhi | 18:6a4db94011d3 | 742 | assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter)); |
sahilmgandhi | 18:6a4db94011d3 | 743 | |
sahilmgandhi | 18:6a4db94011d3 | 744 | /* Process Locked */ |
sahilmgandhi | 18:6a4db94011d3 | 745 | __HAL_LOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 746 | |
sahilmgandhi | 18:6a4db94011d3 | 747 | hrtc->State = HAL_RTC_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 748 | |
sahilmgandhi | 18:6a4db94011d3 | 749 | /* Disable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 750 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 751 | |
sahilmgandhi | 18:6a4db94011d3 | 752 | /*Check RTC WUTWF flag is reset only when wake up timer enabled*/ |
sahilmgandhi | 18:6a4db94011d3 | 753 | if((hrtc->Instance->CR & RTC_CR_WUTE) != RESET) |
sahilmgandhi | 18:6a4db94011d3 | 754 | { |
sahilmgandhi | 18:6a4db94011d3 | 755 | /* Wait till RTC WUTWF flag is reset and if Time out is reached exit */ |
sahilmgandhi | 18:6a4db94011d3 | 756 | count = RTC_TIMEOUT_VALUE * (SystemCoreClock / 32U / 1000U); |
sahilmgandhi | 18:6a4db94011d3 | 757 | do |
sahilmgandhi | 18:6a4db94011d3 | 758 | { |
sahilmgandhi | 18:6a4db94011d3 | 759 | if (count-- == 0U) |
sahilmgandhi | 18:6a4db94011d3 | 760 | { |
sahilmgandhi | 18:6a4db94011d3 | 761 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 762 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 763 | |
sahilmgandhi | 18:6a4db94011d3 | 764 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 765 | |
sahilmgandhi | 18:6a4db94011d3 | 766 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 767 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 768 | |
sahilmgandhi | 18:6a4db94011d3 | 769 | return HAL_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 770 | } |
sahilmgandhi | 18:6a4db94011d3 | 771 | } |
sahilmgandhi | 18:6a4db94011d3 | 772 | while (__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == SET); |
sahilmgandhi | 18:6a4db94011d3 | 773 | } |
sahilmgandhi | 18:6a4db94011d3 | 774 | |
sahilmgandhi | 18:6a4db94011d3 | 775 | __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 776 | |
sahilmgandhi | 18:6a4db94011d3 | 777 | /* Wait till RTC WUTWF flag is set and if Time out is reached exit */ |
sahilmgandhi | 18:6a4db94011d3 | 778 | count = RTC_TIMEOUT_VALUE * (SystemCoreClock / 32U / 1000U); |
sahilmgandhi | 18:6a4db94011d3 | 779 | do |
sahilmgandhi | 18:6a4db94011d3 | 780 | { |
sahilmgandhi | 18:6a4db94011d3 | 781 | if (count-- == 0U) |
sahilmgandhi | 18:6a4db94011d3 | 782 | { |
sahilmgandhi | 18:6a4db94011d3 | 783 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 784 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 785 | |
sahilmgandhi | 18:6a4db94011d3 | 786 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 787 | |
sahilmgandhi | 18:6a4db94011d3 | 788 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 789 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 790 | |
sahilmgandhi | 18:6a4db94011d3 | 791 | return HAL_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 792 | } |
sahilmgandhi | 18:6a4db94011d3 | 793 | } |
sahilmgandhi | 18:6a4db94011d3 | 794 | while (__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET); |
sahilmgandhi | 18:6a4db94011d3 | 795 | |
sahilmgandhi | 18:6a4db94011d3 | 796 | /* Configure the Wake-up Timer counter */ |
sahilmgandhi | 18:6a4db94011d3 | 797 | hrtc->Instance->WUTR = (uint32_t)WakeUpCounter; |
sahilmgandhi | 18:6a4db94011d3 | 798 | |
sahilmgandhi | 18:6a4db94011d3 | 799 | /* Clear the Wake-up Timer clock source bits in CR register */ |
sahilmgandhi | 18:6a4db94011d3 | 800 | hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL; |
sahilmgandhi | 18:6a4db94011d3 | 801 | |
sahilmgandhi | 18:6a4db94011d3 | 802 | /* Configure the clock source */ |
sahilmgandhi | 18:6a4db94011d3 | 803 | hrtc->Instance->CR |= (uint32_t)WakeUpClock; |
sahilmgandhi | 18:6a4db94011d3 | 804 | |
sahilmgandhi | 18:6a4db94011d3 | 805 | /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */ |
sahilmgandhi | 18:6a4db94011d3 | 806 | __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT(); |
sahilmgandhi | 18:6a4db94011d3 | 807 | |
sahilmgandhi | 18:6a4db94011d3 | 808 | EXTI->RTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT; |
sahilmgandhi | 18:6a4db94011d3 | 809 | |
sahilmgandhi | 18:6a4db94011d3 | 810 | /* Clear RTC Wake Up timer Flag */ |
sahilmgandhi | 18:6a4db94011d3 | 811 | __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF); |
sahilmgandhi | 18:6a4db94011d3 | 812 | |
sahilmgandhi | 18:6a4db94011d3 | 813 | /* Configure the Interrupt in the RTC_CR register */ |
sahilmgandhi | 18:6a4db94011d3 | 814 | __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc,RTC_IT_WUT); |
sahilmgandhi | 18:6a4db94011d3 | 815 | |
sahilmgandhi | 18:6a4db94011d3 | 816 | /* Enable the Wake-up Timer */ |
sahilmgandhi | 18:6a4db94011d3 | 817 | __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 818 | |
sahilmgandhi | 18:6a4db94011d3 | 819 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 820 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 821 | |
sahilmgandhi | 18:6a4db94011d3 | 822 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 823 | |
sahilmgandhi | 18:6a4db94011d3 | 824 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 825 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 826 | |
sahilmgandhi | 18:6a4db94011d3 | 827 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 828 | } |
sahilmgandhi | 18:6a4db94011d3 | 829 | |
sahilmgandhi | 18:6a4db94011d3 | 830 | /** |
sahilmgandhi | 18:6a4db94011d3 | 831 | * @brief Deactivates wake up timer counter. |
sahilmgandhi | 18:6a4db94011d3 | 832 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 833 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 834 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 835 | */ |
sahilmgandhi | 18:6a4db94011d3 | 836 | uint32_t HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc) |
sahilmgandhi | 18:6a4db94011d3 | 837 | { |
sahilmgandhi | 18:6a4db94011d3 | 838 | uint32_t tickstart = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 839 | |
sahilmgandhi | 18:6a4db94011d3 | 840 | /* Process Locked */ |
sahilmgandhi | 18:6a4db94011d3 | 841 | __HAL_LOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 842 | |
sahilmgandhi | 18:6a4db94011d3 | 843 | hrtc->State = HAL_RTC_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 844 | |
sahilmgandhi | 18:6a4db94011d3 | 845 | /* Disable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 846 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 847 | |
sahilmgandhi | 18:6a4db94011d3 | 848 | /* Disable the Wake-up Timer */ |
sahilmgandhi | 18:6a4db94011d3 | 849 | __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 850 | |
sahilmgandhi | 18:6a4db94011d3 | 851 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
sahilmgandhi | 18:6a4db94011d3 | 852 | __HAL_RTC_WAKEUPTIMER_DISABLE_IT(hrtc,RTC_IT_WUT); |
sahilmgandhi | 18:6a4db94011d3 | 853 | |
sahilmgandhi | 18:6a4db94011d3 | 854 | /* Get tick */ |
sahilmgandhi | 18:6a4db94011d3 | 855 | tickstart = HAL_GetTick(); |
sahilmgandhi | 18:6a4db94011d3 | 856 | |
sahilmgandhi | 18:6a4db94011d3 | 857 | /* Wait till RTC WUTWF flag is set and if Time out is reached exit */ |
sahilmgandhi | 18:6a4db94011d3 | 858 | while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET) |
sahilmgandhi | 18:6a4db94011d3 | 859 | { |
sahilmgandhi | 18:6a4db94011d3 | 860 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
sahilmgandhi | 18:6a4db94011d3 | 861 | { |
sahilmgandhi | 18:6a4db94011d3 | 862 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 863 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 864 | |
sahilmgandhi | 18:6a4db94011d3 | 865 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 866 | |
sahilmgandhi | 18:6a4db94011d3 | 867 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 868 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 869 | |
sahilmgandhi | 18:6a4db94011d3 | 870 | return HAL_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 871 | } |
sahilmgandhi | 18:6a4db94011d3 | 872 | } |
sahilmgandhi | 18:6a4db94011d3 | 873 | |
sahilmgandhi | 18:6a4db94011d3 | 874 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 875 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 876 | |
sahilmgandhi | 18:6a4db94011d3 | 877 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 878 | |
sahilmgandhi | 18:6a4db94011d3 | 879 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 880 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 881 | |
sahilmgandhi | 18:6a4db94011d3 | 882 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 883 | } |
sahilmgandhi | 18:6a4db94011d3 | 884 | |
sahilmgandhi | 18:6a4db94011d3 | 885 | /** |
sahilmgandhi | 18:6a4db94011d3 | 886 | * @brief Gets wake up timer counter. |
sahilmgandhi | 18:6a4db94011d3 | 887 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 888 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 889 | * @retval Counter value |
sahilmgandhi | 18:6a4db94011d3 | 890 | */ |
sahilmgandhi | 18:6a4db94011d3 | 891 | uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc) |
sahilmgandhi | 18:6a4db94011d3 | 892 | { |
sahilmgandhi | 18:6a4db94011d3 | 893 | /* Get the counter value */ |
sahilmgandhi | 18:6a4db94011d3 | 894 | return ((uint32_t)(hrtc->Instance->WUTR & RTC_WUTR_WUT)); |
sahilmgandhi | 18:6a4db94011d3 | 895 | } |
sahilmgandhi | 18:6a4db94011d3 | 896 | |
sahilmgandhi | 18:6a4db94011d3 | 897 | /** |
sahilmgandhi | 18:6a4db94011d3 | 898 | * @brief This function handles Wake Up Timer interrupt request. |
sahilmgandhi | 18:6a4db94011d3 | 899 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 900 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 901 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 902 | */ |
sahilmgandhi | 18:6a4db94011d3 | 903 | void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc) |
sahilmgandhi | 18:6a4db94011d3 | 904 | { |
sahilmgandhi | 18:6a4db94011d3 | 905 | if(__HAL_RTC_WAKEUPTIMER_GET_IT(hrtc, RTC_IT_WUT)) |
sahilmgandhi | 18:6a4db94011d3 | 906 | { |
sahilmgandhi | 18:6a4db94011d3 | 907 | /* Get the status of the Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 908 | if((uint32_t)(hrtc->Instance->CR & RTC_IT_WUT) != (uint32_t)RESET) |
sahilmgandhi | 18:6a4db94011d3 | 909 | { |
sahilmgandhi | 18:6a4db94011d3 | 910 | /* WAKEUPTIMER callback */ |
sahilmgandhi | 18:6a4db94011d3 | 911 | HAL_RTCEx_WakeUpTimerEventCallback(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 912 | |
sahilmgandhi | 18:6a4db94011d3 | 913 | /* Clear the WAKEUPTIMER interrupt pending bit */ |
sahilmgandhi | 18:6a4db94011d3 | 914 | __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF); |
sahilmgandhi | 18:6a4db94011d3 | 915 | } |
sahilmgandhi | 18:6a4db94011d3 | 916 | } |
sahilmgandhi | 18:6a4db94011d3 | 917 | |
sahilmgandhi | 18:6a4db94011d3 | 918 | /* Clear the EXTI's line Flag for RTC WakeUpTimer */ |
sahilmgandhi | 18:6a4db94011d3 | 919 | __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG(); |
sahilmgandhi | 18:6a4db94011d3 | 920 | |
sahilmgandhi | 18:6a4db94011d3 | 921 | /* Change RTC state */ |
sahilmgandhi | 18:6a4db94011d3 | 922 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 923 | } |
sahilmgandhi | 18:6a4db94011d3 | 924 | |
sahilmgandhi | 18:6a4db94011d3 | 925 | /** |
sahilmgandhi | 18:6a4db94011d3 | 926 | * @brief Wake Up Timer callback. |
sahilmgandhi | 18:6a4db94011d3 | 927 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 928 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 929 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 930 | */ |
sahilmgandhi | 18:6a4db94011d3 | 931 | __weak void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) |
sahilmgandhi | 18:6a4db94011d3 | 932 | { |
sahilmgandhi | 18:6a4db94011d3 | 933 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 934 | UNUSED(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 935 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 936 | the HAL_RTC_WakeUpTimerEventCallback could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 937 | */ |
sahilmgandhi | 18:6a4db94011d3 | 938 | } |
sahilmgandhi | 18:6a4db94011d3 | 939 | |
sahilmgandhi | 18:6a4db94011d3 | 940 | /** |
sahilmgandhi | 18:6a4db94011d3 | 941 | * @brief This function handles Wake Up Timer Polling. |
sahilmgandhi | 18:6a4db94011d3 | 942 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 943 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 944 | * @param Timeout: Timeout duration |
sahilmgandhi | 18:6a4db94011d3 | 945 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 946 | */ |
sahilmgandhi | 18:6a4db94011d3 | 947 | HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
sahilmgandhi | 18:6a4db94011d3 | 948 | { |
sahilmgandhi | 18:6a4db94011d3 | 949 | uint32_t tickstart = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 950 | |
sahilmgandhi | 18:6a4db94011d3 | 951 | /* Get tick */ |
sahilmgandhi | 18:6a4db94011d3 | 952 | tickstart = HAL_GetTick(); |
sahilmgandhi | 18:6a4db94011d3 | 953 | |
sahilmgandhi | 18:6a4db94011d3 | 954 | while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) == RESET) |
sahilmgandhi | 18:6a4db94011d3 | 955 | { |
sahilmgandhi | 18:6a4db94011d3 | 956 | if(Timeout != HAL_MAX_DELAY) |
sahilmgandhi | 18:6a4db94011d3 | 957 | { |
sahilmgandhi | 18:6a4db94011d3 | 958 | if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout)) |
sahilmgandhi | 18:6a4db94011d3 | 959 | { |
sahilmgandhi | 18:6a4db94011d3 | 960 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 961 | |
sahilmgandhi | 18:6a4db94011d3 | 962 | return HAL_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 963 | } |
sahilmgandhi | 18:6a4db94011d3 | 964 | } |
sahilmgandhi | 18:6a4db94011d3 | 965 | } |
sahilmgandhi | 18:6a4db94011d3 | 966 | |
sahilmgandhi | 18:6a4db94011d3 | 967 | /* Clear the WAKEUPTIMER Flag */ |
sahilmgandhi | 18:6a4db94011d3 | 968 | __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF); |
sahilmgandhi | 18:6a4db94011d3 | 969 | |
sahilmgandhi | 18:6a4db94011d3 | 970 | /* Change RTC state */ |
sahilmgandhi | 18:6a4db94011d3 | 971 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 972 | |
sahilmgandhi | 18:6a4db94011d3 | 973 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 974 | } |
sahilmgandhi | 18:6a4db94011d3 | 975 | |
sahilmgandhi | 18:6a4db94011d3 | 976 | /** |
sahilmgandhi | 18:6a4db94011d3 | 977 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 978 | */ |
sahilmgandhi | 18:6a4db94011d3 | 979 | |
sahilmgandhi | 18:6a4db94011d3 | 980 | /** @defgroup RTCEx_Exported_Functions_Group3 Extension Peripheral Control functions |
sahilmgandhi | 18:6a4db94011d3 | 981 | * @brief Extension Peripheral Control functions |
sahilmgandhi | 18:6a4db94011d3 | 982 | * |
sahilmgandhi | 18:6a4db94011d3 | 983 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 984 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 985 | ##### Extension Peripheral Control functions ##### |
sahilmgandhi | 18:6a4db94011d3 | 986 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 987 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 988 | This subsection provides functions allowing to |
sahilmgandhi | 18:6a4db94011d3 | 989 | (+) Write a data in a specified RTC Backup data register |
sahilmgandhi | 18:6a4db94011d3 | 990 | (+) Read a data in a specified RTC Backup data register |
sahilmgandhi | 18:6a4db94011d3 | 991 | (+) Set the Coarse calibration parameters. |
sahilmgandhi | 18:6a4db94011d3 | 992 | (+) Deactivate the Coarse calibration parameters |
sahilmgandhi | 18:6a4db94011d3 | 993 | (+) Configure the Synchronization Shift Control Settings. |
sahilmgandhi | 18:6a4db94011d3 | 994 | (+) Configure the Calibration Pinout (RTC_CALIB). |
sahilmgandhi | 18:6a4db94011d3 | 995 | (+) Deactivate the Calibration Pinout (RTC_CALIB). |
sahilmgandhi | 18:6a4db94011d3 | 996 | (+) Enable the RTC reference clock detection. |
sahilmgandhi | 18:6a4db94011d3 | 997 | (+) Disable the RTC reference clock detection. |
sahilmgandhi | 18:6a4db94011d3 | 998 | |
sahilmgandhi | 18:6a4db94011d3 | 999 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 1000 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 1001 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1002 | |
sahilmgandhi | 18:6a4db94011d3 | 1003 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1004 | * @brief Writes a data in a specified RTC Backup data register. |
sahilmgandhi | 18:6a4db94011d3 | 1005 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 1006 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 1007 | * @param BackupRegister: RTC Backup data Register number. |
sahilmgandhi | 18:6a4db94011d3 | 1008 | * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to |
sahilmgandhi | 18:6a4db94011d3 | 1009 | * specify the register. |
sahilmgandhi | 18:6a4db94011d3 | 1010 | * @param Data: Data to be written in the specified RTC Backup data register. |
sahilmgandhi | 18:6a4db94011d3 | 1011 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 1012 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1013 | void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data) |
sahilmgandhi | 18:6a4db94011d3 | 1014 | { |
sahilmgandhi | 18:6a4db94011d3 | 1015 | uint32_t tmp = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 1016 | |
sahilmgandhi | 18:6a4db94011d3 | 1017 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 1018 | assert_param(IS_RTC_BKP(BackupRegister)); |
sahilmgandhi | 18:6a4db94011d3 | 1019 | |
sahilmgandhi | 18:6a4db94011d3 | 1020 | tmp = (uint32_t)&(hrtc->Instance->BKP0R); |
sahilmgandhi | 18:6a4db94011d3 | 1021 | tmp += (BackupRegister * 4U); |
sahilmgandhi | 18:6a4db94011d3 | 1022 | |
sahilmgandhi | 18:6a4db94011d3 | 1023 | /* Write the specified register */ |
sahilmgandhi | 18:6a4db94011d3 | 1024 | *(__IO uint32_t *)tmp = (uint32_t)Data; |
sahilmgandhi | 18:6a4db94011d3 | 1025 | } |
sahilmgandhi | 18:6a4db94011d3 | 1026 | |
sahilmgandhi | 18:6a4db94011d3 | 1027 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1028 | * @brief Reads data from the specified RTC Backup data Register. |
sahilmgandhi | 18:6a4db94011d3 | 1029 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 1030 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 1031 | * @param BackupRegister: RTC Backup data Register number. |
sahilmgandhi | 18:6a4db94011d3 | 1032 | * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to |
sahilmgandhi | 18:6a4db94011d3 | 1033 | * specify the register. |
sahilmgandhi | 18:6a4db94011d3 | 1034 | * @retval Read value |
sahilmgandhi | 18:6a4db94011d3 | 1035 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1036 | uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister) |
sahilmgandhi | 18:6a4db94011d3 | 1037 | { |
sahilmgandhi | 18:6a4db94011d3 | 1038 | uint32_t tmp = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 1039 | |
sahilmgandhi | 18:6a4db94011d3 | 1040 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 1041 | assert_param(IS_RTC_BKP(BackupRegister)); |
sahilmgandhi | 18:6a4db94011d3 | 1042 | |
sahilmgandhi | 18:6a4db94011d3 | 1043 | tmp = (uint32_t)&(hrtc->Instance->BKP0R); |
sahilmgandhi | 18:6a4db94011d3 | 1044 | tmp += (BackupRegister * 4U); |
sahilmgandhi | 18:6a4db94011d3 | 1045 | |
sahilmgandhi | 18:6a4db94011d3 | 1046 | /* Read the specified register */ |
sahilmgandhi | 18:6a4db94011d3 | 1047 | return (*(__IO uint32_t *)tmp); |
sahilmgandhi | 18:6a4db94011d3 | 1048 | } |
sahilmgandhi | 18:6a4db94011d3 | 1049 | |
sahilmgandhi | 18:6a4db94011d3 | 1050 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1051 | * @brief Sets the Coarse calibration parameters. |
sahilmgandhi | 18:6a4db94011d3 | 1052 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 1053 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 1054 | * @param CalibSign: Specifies the sign of the coarse calibration value. |
sahilmgandhi | 18:6a4db94011d3 | 1055 | * This parameter can be one of the following values : |
sahilmgandhi | 18:6a4db94011d3 | 1056 | * @arg RTC_CALIBSIGN_POSITIVE: The value sign is positive |
sahilmgandhi | 18:6a4db94011d3 | 1057 | * @arg RTC_CALIBSIGN_NEGATIVE: The value sign is negative |
sahilmgandhi | 18:6a4db94011d3 | 1058 | * @param Value: value of coarse calibration expressed in ppm (coded on 5 bits). |
sahilmgandhi | 18:6a4db94011d3 | 1059 | * |
sahilmgandhi | 18:6a4db94011d3 | 1060 | * @note This Calibration value should be between 0 and 63 when using negative |
sahilmgandhi | 18:6a4db94011d3 | 1061 | * sign with a 2-ppm step. |
sahilmgandhi | 18:6a4db94011d3 | 1062 | * |
sahilmgandhi | 18:6a4db94011d3 | 1063 | * @note This Calibration value should be between 0 and 126 when using positive |
sahilmgandhi | 18:6a4db94011d3 | 1064 | * sign with a 4-ppm step. |
sahilmgandhi | 18:6a4db94011d3 | 1065 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 1066 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1067 | HAL_StatusTypeDef HAL_RTCEx_SetCoarseCalib(RTC_HandleTypeDef* hrtc, uint32_t CalibSign, uint32_t Value) |
sahilmgandhi | 18:6a4db94011d3 | 1068 | { |
sahilmgandhi | 18:6a4db94011d3 | 1069 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 1070 | assert_param(IS_RTC_CALIB_SIGN(CalibSign)); |
sahilmgandhi | 18:6a4db94011d3 | 1071 | assert_param(IS_RTC_CALIB_VALUE(Value)); |
sahilmgandhi | 18:6a4db94011d3 | 1072 | |
sahilmgandhi | 18:6a4db94011d3 | 1073 | /* Process Locked */ |
sahilmgandhi | 18:6a4db94011d3 | 1074 | __HAL_LOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1075 | |
sahilmgandhi | 18:6a4db94011d3 | 1076 | hrtc->State = HAL_RTC_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 1077 | |
sahilmgandhi | 18:6a4db94011d3 | 1078 | /* Disable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 1079 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1080 | |
sahilmgandhi | 18:6a4db94011d3 | 1081 | /* Set Initialization mode */ |
sahilmgandhi | 18:6a4db94011d3 | 1082 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
sahilmgandhi | 18:6a4db94011d3 | 1083 | { |
sahilmgandhi | 18:6a4db94011d3 | 1084 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 1085 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1086 | |
sahilmgandhi | 18:6a4db94011d3 | 1087 | /* Set RTC state*/ |
sahilmgandhi | 18:6a4db94011d3 | 1088 | hrtc->State = HAL_RTC_STATE_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 1089 | |
sahilmgandhi | 18:6a4db94011d3 | 1090 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 1091 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1092 | |
sahilmgandhi | 18:6a4db94011d3 | 1093 | return HAL_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 1094 | } |
sahilmgandhi | 18:6a4db94011d3 | 1095 | else |
sahilmgandhi | 18:6a4db94011d3 | 1096 | { |
sahilmgandhi | 18:6a4db94011d3 | 1097 | /* Enable the Coarse Calibration */ |
sahilmgandhi | 18:6a4db94011d3 | 1098 | __HAL_RTC_COARSE_CALIB_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1099 | |
sahilmgandhi | 18:6a4db94011d3 | 1100 | /* Set the coarse calibration value */ |
sahilmgandhi | 18:6a4db94011d3 | 1101 | hrtc->Instance->CALIBR = (uint32_t)(CalibSign|Value); |
sahilmgandhi | 18:6a4db94011d3 | 1102 | |
sahilmgandhi | 18:6a4db94011d3 | 1103 | /* Exit Initialization mode */ |
sahilmgandhi | 18:6a4db94011d3 | 1104 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
sahilmgandhi | 18:6a4db94011d3 | 1105 | } |
sahilmgandhi | 18:6a4db94011d3 | 1106 | |
sahilmgandhi | 18:6a4db94011d3 | 1107 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 1108 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1109 | |
sahilmgandhi | 18:6a4db94011d3 | 1110 | /* Change state */ |
sahilmgandhi | 18:6a4db94011d3 | 1111 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 1112 | |
sahilmgandhi | 18:6a4db94011d3 | 1113 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 1114 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1115 | |
sahilmgandhi | 18:6a4db94011d3 | 1116 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1117 | } |
sahilmgandhi | 18:6a4db94011d3 | 1118 | |
sahilmgandhi | 18:6a4db94011d3 | 1119 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1120 | * @brief Deactivates the Coarse calibration parameters. |
sahilmgandhi | 18:6a4db94011d3 | 1121 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 1122 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 1123 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 1124 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1125 | HAL_StatusTypeDef HAL_RTCEx_DeactivateCoarseCalib(RTC_HandleTypeDef* hrtc) |
sahilmgandhi | 18:6a4db94011d3 | 1126 | { |
sahilmgandhi | 18:6a4db94011d3 | 1127 | /* Process Locked */ |
sahilmgandhi | 18:6a4db94011d3 | 1128 | __HAL_LOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1129 | |
sahilmgandhi | 18:6a4db94011d3 | 1130 | hrtc->State = HAL_RTC_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 1131 | |
sahilmgandhi | 18:6a4db94011d3 | 1132 | /* Disable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 1133 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1134 | |
sahilmgandhi | 18:6a4db94011d3 | 1135 | /* Set Initialization mode */ |
sahilmgandhi | 18:6a4db94011d3 | 1136 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
sahilmgandhi | 18:6a4db94011d3 | 1137 | { |
sahilmgandhi | 18:6a4db94011d3 | 1138 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 1139 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1140 | |
sahilmgandhi | 18:6a4db94011d3 | 1141 | /* Set RTC state*/ |
sahilmgandhi | 18:6a4db94011d3 | 1142 | hrtc->State = HAL_RTC_STATE_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 1143 | |
sahilmgandhi | 18:6a4db94011d3 | 1144 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 1145 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1146 | |
sahilmgandhi | 18:6a4db94011d3 | 1147 | return HAL_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 1148 | } |
sahilmgandhi | 18:6a4db94011d3 | 1149 | else |
sahilmgandhi | 18:6a4db94011d3 | 1150 | { |
sahilmgandhi | 18:6a4db94011d3 | 1151 | /* Enable the Coarse Calibration */ |
sahilmgandhi | 18:6a4db94011d3 | 1152 | __HAL_RTC_COARSE_CALIB_DISABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1153 | |
sahilmgandhi | 18:6a4db94011d3 | 1154 | /* Exit Initialization mode */ |
sahilmgandhi | 18:6a4db94011d3 | 1155 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
sahilmgandhi | 18:6a4db94011d3 | 1156 | } |
sahilmgandhi | 18:6a4db94011d3 | 1157 | |
sahilmgandhi | 18:6a4db94011d3 | 1158 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 1159 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1160 | |
sahilmgandhi | 18:6a4db94011d3 | 1161 | /* Change state */ |
sahilmgandhi | 18:6a4db94011d3 | 1162 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 1163 | |
sahilmgandhi | 18:6a4db94011d3 | 1164 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 1165 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1166 | |
sahilmgandhi | 18:6a4db94011d3 | 1167 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1168 | } |
sahilmgandhi | 18:6a4db94011d3 | 1169 | |
sahilmgandhi | 18:6a4db94011d3 | 1170 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1171 | * @brief Configure the Calibration Pinout (RTC_CALIB). |
sahilmgandhi | 18:6a4db94011d3 | 1172 | * @param hrtc : RTC handle |
sahilmgandhi | 18:6a4db94011d3 | 1173 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 1174 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1175 | HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef* hrtc) |
sahilmgandhi | 18:6a4db94011d3 | 1176 | { |
sahilmgandhi | 18:6a4db94011d3 | 1177 | /* Process Locked */ |
sahilmgandhi | 18:6a4db94011d3 | 1178 | __HAL_LOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1179 | |
sahilmgandhi | 18:6a4db94011d3 | 1180 | hrtc->State = HAL_RTC_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 1181 | |
sahilmgandhi | 18:6a4db94011d3 | 1182 | /* Disable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 1183 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1184 | |
sahilmgandhi | 18:6a4db94011d3 | 1185 | __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1186 | |
sahilmgandhi | 18:6a4db94011d3 | 1187 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 1188 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1189 | |
sahilmgandhi | 18:6a4db94011d3 | 1190 | /* Change RTC state */ |
sahilmgandhi | 18:6a4db94011d3 | 1191 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 1192 | |
sahilmgandhi | 18:6a4db94011d3 | 1193 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 1194 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1195 | |
sahilmgandhi | 18:6a4db94011d3 | 1196 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1197 | } |
sahilmgandhi | 18:6a4db94011d3 | 1198 | |
sahilmgandhi | 18:6a4db94011d3 | 1199 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1200 | * @brief Deactivates the Calibration Pinout (RTC_CALIB). |
sahilmgandhi | 18:6a4db94011d3 | 1201 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 1202 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 1203 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 1204 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1205 | HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef* hrtc) |
sahilmgandhi | 18:6a4db94011d3 | 1206 | { |
sahilmgandhi | 18:6a4db94011d3 | 1207 | /* Process Locked */ |
sahilmgandhi | 18:6a4db94011d3 | 1208 | __HAL_LOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1209 | |
sahilmgandhi | 18:6a4db94011d3 | 1210 | hrtc->State = HAL_RTC_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 1211 | |
sahilmgandhi | 18:6a4db94011d3 | 1212 | /* Disable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 1213 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1214 | |
sahilmgandhi | 18:6a4db94011d3 | 1215 | __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1216 | |
sahilmgandhi | 18:6a4db94011d3 | 1217 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 1218 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1219 | |
sahilmgandhi | 18:6a4db94011d3 | 1220 | /* Change RTC state */ |
sahilmgandhi | 18:6a4db94011d3 | 1221 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 1222 | |
sahilmgandhi | 18:6a4db94011d3 | 1223 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 1224 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1225 | |
sahilmgandhi | 18:6a4db94011d3 | 1226 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1227 | } |
sahilmgandhi | 18:6a4db94011d3 | 1228 | |
sahilmgandhi | 18:6a4db94011d3 | 1229 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1230 | * @brief Enables the RTC reference clock detection. |
sahilmgandhi | 18:6a4db94011d3 | 1231 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 1232 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 1233 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 1234 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1235 | HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef* hrtc) |
sahilmgandhi | 18:6a4db94011d3 | 1236 | { |
sahilmgandhi | 18:6a4db94011d3 | 1237 | /* Process Locked */ |
sahilmgandhi | 18:6a4db94011d3 | 1238 | __HAL_LOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1239 | |
sahilmgandhi | 18:6a4db94011d3 | 1240 | hrtc->State = HAL_RTC_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 1241 | |
sahilmgandhi | 18:6a4db94011d3 | 1242 | /* Disable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 1243 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1244 | |
sahilmgandhi | 18:6a4db94011d3 | 1245 | /* Set Initialization mode */ |
sahilmgandhi | 18:6a4db94011d3 | 1246 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
sahilmgandhi | 18:6a4db94011d3 | 1247 | { |
sahilmgandhi | 18:6a4db94011d3 | 1248 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 1249 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1250 | |
sahilmgandhi | 18:6a4db94011d3 | 1251 | /* Set RTC state*/ |
sahilmgandhi | 18:6a4db94011d3 | 1252 | hrtc->State = HAL_RTC_STATE_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 1253 | |
sahilmgandhi | 18:6a4db94011d3 | 1254 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 1255 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1256 | |
sahilmgandhi | 18:6a4db94011d3 | 1257 | return HAL_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 1258 | } |
sahilmgandhi | 18:6a4db94011d3 | 1259 | else |
sahilmgandhi | 18:6a4db94011d3 | 1260 | { |
sahilmgandhi | 18:6a4db94011d3 | 1261 | __HAL_RTC_CLOCKREF_DETECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1262 | |
sahilmgandhi | 18:6a4db94011d3 | 1263 | /* Exit Initialization mode */ |
sahilmgandhi | 18:6a4db94011d3 | 1264 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
sahilmgandhi | 18:6a4db94011d3 | 1265 | } |
sahilmgandhi | 18:6a4db94011d3 | 1266 | |
sahilmgandhi | 18:6a4db94011d3 | 1267 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 1268 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1269 | |
sahilmgandhi | 18:6a4db94011d3 | 1270 | /* Change RTC state */ |
sahilmgandhi | 18:6a4db94011d3 | 1271 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 1272 | |
sahilmgandhi | 18:6a4db94011d3 | 1273 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 1274 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1275 | |
sahilmgandhi | 18:6a4db94011d3 | 1276 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1277 | } |
sahilmgandhi | 18:6a4db94011d3 | 1278 | |
sahilmgandhi | 18:6a4db94011d3 | 1279 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1280 | * @brief Disable the RTC reference clock detection. |
sahilmgandhi | 18:6a4db94011d3 | 1281 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 1282 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 1283 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 1284 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1285 | HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef* hrtc) |
sahilmgandhi | 18:6a4db94011d3 | 1286 | { |
sahilmgandhi | 18:6a4db94011d3 | 1287 | /* Process Locked */ |
sahilmgandhi | 18:6a4db94011d3 | 1288 | __HAL_LOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1289 | |
sahilmgandhi | 18:6a4db94011d3 | 1290 | hrtc->State = HAL_RTC_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 1291 | |
sahilmgandhi | 18:6a4db94011d3 | 1292 | /* Disable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 1293 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1294 | |
sahilmgandhi | 18:6a4db94011d3 | 1295 | /* Set Initialization mode */ |
sahilmgandhi | 18:6a4db94011d3 | 1296 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
sahilmgandhi | 18:6a4db94011d3 | 1297 | { |
sahilmgandhi | 18:6a4db94011d3 | 1298 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 1299 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1300 | |
sahilmgandhi | 18:6a4db94011d3 | 1301 | /* Set RTC state*/ |
sahilmgandhi | 18:6a4db94011d3 | 1302 | hrtc->State = HAL_RTC_STATE_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 1303 | |
sahilmgandhi | 18:6a4db94011d3 | 1304 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 1305 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1306 | |
sahilmgandhi | 18:6a4db94011d3 | 1307 | return HAL_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 1308 | } |
sahilmgandhi | 18:6a4db94011d3 | 1309 | else |
sahilmgandhi | 18:6a4db94011d3 | 1310 | { |
sahilmgandhi | 18:6a4db94011d3 | 1311 | __HAL_RTC_CLOCKREF_DETECTION_DISABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1312 | |
sahilmgandhi | 18:6a4db94011d3 | 1313 | /* Exit Initialization mode */ |
sahilmgandhi | 18:6a4db94011d3 | 1314 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
sahilmgandhi | 18:6a4db94011d3 | 1315 | } |
sahilmgandhi | 18:6a4db94011d3 | 1316 | |
sahilmgandhi | 18:6a4db94011d3 | 1317 | /* Enable the write protection for RTC registers */ |
sahilmgandhi | 18:6a4db94011d3 | 1318 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1319 | |
sahilmgandhi | 18:6a4db94011d3 | 1320 | /* Change RTC state */ |
sahilmgandhi | 18:6a4db94011d3 | 1321 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 1322 | |
sahilmgandhi | 18:6a4db94011d3 | 1323 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 1324 | __HAL_UNLOCK(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1325 | |
sahilmgandhi | 18:6a4db94011d3 | 1326 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1327 | } |
sahilmgandhi | 18:6a4db94011d3 | 1328 | |
sahilmgandhi | 18:6a4db94011d3 | 1329 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1330 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 1331 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1332 | |
sahilmgandhi | 18:6a4db94011d3 | 1333 | /** @defgroup RTCEx_Exported_Functions_Group4 Extended features functions |
sahilmgandhi | 18:6a4db94011d3 | 1334 | * @brief Extended features functions |
sahilmgandhi | 18:6a4db94011d3 | 1335 | * |
sahilmgandhi | 18:6a4db94011d3 | 1336 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 1337 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 1338 | ##### Extended features functions ##### |
sahilmgandhi | 18:6a4db94011d3 | 1339 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 1340 | [..] This section provides functions allowing to: |
sahilmgandhi | 18:6a4db94011d3 | 1341 | (+) RTC Alarm B callback |
sahilmgandhi | 18:6a4db94011d3 | 1342 | (+) RTC Poll for Alarm B request |
sahilmgandhi | 18:6a4db94011d3 | 1343 | |
sahilmgandhi | 18:6a4db94011d3 | 1344 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 1345 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 1346 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1347 | |
sahilmgandhi | 18:6a4db94011d3 | 1348 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1349 | * @brief Alarm B callback. |
sahilmgandhi | 18:6a4db94011d3 | 1350 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 1351 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 1352 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 1353 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1354 | __weak void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc) |
sahilmgandhi | 18:6a4db94011d3 | 1355 | { |
sahilmgandhi | 18:6a4db94011d3 | 1356 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 1357 | UNUSED(hrtc); |
sahilmgandhi | 18:6a4db94011d3 | 1358 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 1359 | the HAL_RTC_AlarmBEventCallback could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 1360 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1361 | } |
sahilmgandhi | 18:6a4db94011d3 | 1362 | |
sahilmgandhi | 18:6a4db94011d3 | 1363 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1364 | * @brief This function handles AlarmB Polling request. |
sahilmgandhi | 18:6a4db94011d3 | 1365 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 1366 | * the configuration information for RTC. |
sahilmgandhi | 18:6a4db94011d3 | 1367 | * @param Timeout: Timeout duration |
sahilmgandhi | 18:6a4db94011d3 | 1368 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 1369 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1370 | HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
sahilmgandhi | 18:6a4db94011d3 | 1371 | { |
sahilmgandhi | 18:6a4db94011d3 | 1372 | uint32_t tickstart = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 1373 | |
sahilmgandhi | 18:6a4db94011d3 | 1374 | /* Get tick */ |
sahilmgandhi | 18:6a4db94011d3 | 1375 | tickstart = HAL_GetTick(); |
sahilmgandhi | 18:6a4db94011d3 | 1376 | |
sahilmgandhi | 18:6a4db94011d3 | 1377 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBF) == RESET) |
sahilmgandhi | 18:6a4db94011d3 | 1378 | { |
sahilmgandhi | 18:6a4db94011d3 | 1379 | if(Timeout != HAL_MAX_DELAY) |
sahilmgandhi | 18:6a4db94011d3 | 1380 | { |
sahilmgandhi | 18:6a4db94011d3 | 1381 | if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout)) |
sahilmgandhi | 18:6a4db94011d3 | 1382 | { |
sahilmgandhi | 18:6a4db94011d3 | 1383 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 1384 | return HAL_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 1385 | } |
sahilmgandhi | 18:6a4db94011d3 | 1386 | } |
sahilmgandhi | 18:6a4db94011d3 | 1387 | } |
sahilmgandhi | 18:6a4db94011d3 | 1388 | |
sahilmgandhi | 18:6a4db94011d3 | 1389 | /* Clear the Alarm Flag */ |
sahilmgandhi | 18:6a4db94011d3 | 1390 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF); |
sahilmgandhi | 18:6a4db94011d3 | 1391 | |
sahilmgandhi | 18:6a4db94011d3 | 1392 | /* Change RTC state */ |
sahilmgandhi | 18:6a4db94011d3 | 1393 | hrtc->State = HAL_RTC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 1394 | |
sahilmgandhi | 18:6a4db94011d3 | 1395 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1396 | } |
sahilmgandhi | 18:6a4db94011d3 | 1397 | |
sahilmgandhi | 18:6a4db94011d3 | 1398 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1399 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 1400 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1401 | |
sahilmgandhi | 18:6a4db94011d3 | 1402 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1403 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 1404 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1405 | |
sahilmgandhi | 18:6a4db94011d3 | 1406 | #endif /* HAL_RTC_MODULE_ENABLED */ |
sahilmgandhi | 18:6a4db94011d3 | 1407 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1408 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 1409 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1410 | |
sahilmgandhi | 18:6a4db94011d3 | 1411 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1412 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 1413 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1414 | |
sahilmgandhi | 18:6a4db94011d3 | 1415 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |