001
targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_rtc.c@0:13413ea9a877, 2022-06-12 (annotated)
- Committer:
- ganlikun
- Date:
- Sun Jun 12 14:02:44 2022 +0000
- Revision:
- 0:13413ea9a877
00
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ganlikun | 0:13413ea9a877 | 1 | /** |
ganlikun | 0:13413ea9a877 | 2 | ****************************************************************************** |
ganlikun | 0:13413ea9a877 | 3 | * @file stm32f4xx_hal_rtc.c |
ganlikun | 0:13413ea9a877 | 4 | * @author MCD Application Team |
ganlikun | 0:13413ea9a877 | 5 | * @version V1.7.1 |
ganlikun | 0:13413ea9a877 | 6 | * @date 14-April-2017 |
ganlikun | 0:13413ea9a877 | 7 | * @brief RTC HAL module driver. |
ganlikun | 0:13413ea9a877 | 8 | * This file provides firmware functions to manage the following |
ganlikun | 0:13413ea9a877 | 9 | * functionalities of the Real Time Clock (RTC) peripheral: |
ganlikun | 0:13413ea9a877 | 10 | * + Initialization and de-initialization functions |
ganlikun | 0:13413ea9a877 | 11 | * + RTC Time and Date functions |
ganlikun | 0:13413ea9a877 | 12 | * + RTC Alarm functions |
ganlikun | 0:13413ea9a877 | 13 | * + Peripheral Control functions |
ganlikun | 0:13413ea9a877 | 14 | * + Peripheral State functions |
ganlikun | 0:13413ea9a877 | 15 | * |
ganlikun | 0:13413ea9a877 | 16 | @verbatim |
ganlikun | 0:13413ea9a877 | 17 | ============================================================================== |
ganlikun | 0:13413ea9a877 | 18 | ##### Backup Domain Operating Condition ##### |
ganlikun | 0:13413ea9a877 | 19 | ============================================================================== |
ganlikun | 0:13413ea9a877 | 20 | [..] The real-time clock (RTC), the RTC backup registers, and the backup |
ganlikun | 0:13413ea9a877 | 21 | SRAM (BKP SRAM) can be powered from the VBAT voltage when the main |
ganlikun | 0:13413ea9a877 | 22 | VDD supply is powered off. |
ganlikun | 0:13413ea9a877 | 23 | To retain the content of the RTC backup registers, backup SRAM, and supply |
ganlikun | 0:13413ea9a877 | 24 | the RTC when VDD is turned off, VBAT pin can be connected to an optional |
ganlikun | 0:13413ea9a877 | 25 | standby voltage supplied by a battery or by another source. |
ganlikun | 0:13413ea9a877 | 26 | |
ganlikun | 0:13413ea9a877 | 27 | [..] To allow the RTC operating even when the main digital supply (VDD) is turned |
ganlikun | 0:13413ea9a877 | 28 | off, the VBAT pin powers the following blocks: |
ganlikun | 0:13413ea9a877 | 29 | (#) The RTC |
ganlikun | 0:13413ea9a877 | 30 | (#) The LSE oscillator |
ganlikun | 0:13413ea9a877 | 31 | (#) The backup SRAM when the low power backup regulator is enabled |
ganlikun | 0:13413ea9a877 | 32 | (#) PC13 to PC15 I/Os, plus PI8 I/O (when available) |
ganlikun | 0:13413ea9a877 | 33 | |
ganlikun | 0:13413ea9a877 | 34 | [..] When the backup domain is supplied by VDD (analog switch connected to VDD), |
ganlikun | 0:13413ea9a877 | 35 | the following pins are available: |
ganlikun | 0:13413ea9a877 | 36 | (#) PC14 and PC15 can be used as either GPIO or LSE pins |
ganlikun | 0:13413ea9a877 | 37 | (#) PC13 can be used as a GPIO or as the RTC_AF1 pin |
ganlikun | 0:13413ea9a877 | 38 | (#) PI8 can be used as a GPIO or as the RTC_AF2 pin |
ganlikun | 0:13413ea9a877 | 39 | |
ganlikun | 0:13413ea9a877 | 40 | [..] When the backup domain is supplied by VBAT (analog switch connected to VBAT |
ganlikun | 0:13413ea9a877 | 41 | because VDD is not present), the following pins are available: |
ganlikun | 0:13413ea9a877 | 42 | (#) PC14 and PC15 can be used as LSE pins only |
ganlikun | 0:13413ea9a877 | 43 | (#) PC13 can be used as the RTC_AF1 pin |
ganlikun | 0:13413ea9a877 | 44 | (#) PI8 can be used as the RTC_AF2 pin |
ganlikun | 0:13413ea9a877 | 45 | |
ganlikun | 0:13413ea9a877 | 46 | ##### Backup Domain Reset ##### |
ganlikun | 0:13413ea9a877 | 47 | ================================================================== |
ganlikun | 0:13413ea9a877 | 48 | [..] The backup domain reset sets all RTC registers and the RCC_BDCR register |
ganlikun | 0:13413ea9a877 | 49 | to their reset values. The BKPSRAM is not affected by this reset. The only |
ganlikun | 0:13413ea9a877 | 50 | way to reset the BKPSRAM is through the Flash interface by requesting |
ganlikun | 0:13413ea9a877 | 51 | a protection level change from 1 to 0. |
ganlikun | 0:13413ea9a877 | 52 | [..] A backup domain reset is generated when one of the following events occurs: |
ganlikun | 0:13413ea9a877 | 53 | (#) Software reset, triggered by setting the BDRST bit in the |
ganlikun | 0:13413ea9a877 | 54 | RCC Backup domain control register (RCC_BDCR). |
ganlikun | 0:13413ea9a877 | 55 | (#) VDD or VBAT power on, if both supplies have previously been powered off. |
ganlikun | 0:13413ea9a877 | 56 | |
ganlikun | 0:13413ea9a877 | 57 | ##### Backup Domain Access ##### |
ganlikun | 0:13413ea9a877 | 58 | ================================================================== |
ganlikun | 0:13413ea9a877 | 59 | [..] After reset, the backup domain (RTC registers, RTC backup data |
ganlikun | 0:13413ea9a877 | 60 | registers and backup SRAM) is protected against possible unwanted write |
ganlikun | 0:13413ea9a877 | 61 | accesses. |
ganlikun | 0:13413ea9a877 | 62 | [..] To enable access to the RTC Domain and RTC registers, proceed as follows: |
ganlikun | 0:13413ea9a877 | 63 | (+) Enable the Power Controller (PWR) APB1 interface clock using the |
ganlikun | 0:13413ea9a877 | 64 | __HAL_RCC_PWR_CLK_ENABLE() function. |
ganlikun | 0:13413ea9a877 | 65 | (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function. |
ganlikun | 0:13413ea9a877 | 66 | (+) Select the RTC clock source using the __HAL_RCC_RTC_CONFIG() function. |
ganlikun | 0:13413ea9a877 | 67 | (+) Enable RTC Clock using the __HAL_RCC_RTC_ENABLE() function. |
ganlikun | 0:13413ea9a877 | 68 | |
ganlikun | 0:13413ea9a877 | 69 | |
ganlikun | 0:13413ea9a877 | 70 | ##### How to use this driver ##### |
ganlikun | 0:13413ea9a877 | 71 | ================================================================== |
ganlikun | 0:13413ea9a877 | 72 | [..] |
ganlikun | 0:13413ea9a877 | 73 | (+) Enable the RTC domain access (see description in the section above). |
ganlikun | 0:13413ea9a877 | 74 | (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour |
ganlikun | 0:13413ea9a877 | 75 | format using the HAL_RTC_Init() function. |
ganlikun | 0:13413ea9a877 | 76 | |
ganlikun | 0:13413ea9a877 | 77 | *** Time and Date configuration *** |
ganlikun | 0:13413ea9a877 | 78 | =================================== |
ganlikun | 0:13413ea9a877 | 79 | [..] |
ganlikun | 0:13413ea9a877 | 80 | (+) To configure the RTC Calendar (Time and Date) use the HAL_RTC_SetTime() |
ganlikun | 0:13413ea9a877 | 81 | and HAL_RTC_SetDate() functions. |
ganlikun | 0:13413ea9a877 | 82 | (+) To read the RTC Calendar, use the HAL_RTC_GetTime() and HAL_RTC_GetDate() functions. |
ganlikun | 0:13413ea9a877 | 83 | |
ganlikun | 0:13413ea9a877 | 84 | *** Alarm configuration *** |
ganlikun | 0:13413ea9a877 | 85 | =========================== |
ganlikun | 0:13413ea9a877 | 86 | [..] |
ganlikun | 0:13413ea9a877 | 87 | (+) To configure the RTC Alarm use the HAL_RTC_SetAlarm() function. |
ganlikun | 0:13413ea9a877 | 88 | You can also configure the RTC Alarm with interrupt mode using the HAL_RTC_SetAlarm_IT() function. |
ganlikun | 0:13413ea9a877 | 89 | (+) To read the RTC Alarm, use the HAL_RTC_GetAlarm() function. |
ganlikun | 0:13413ea9a877 | 90 | |
ganlikun | 0:13413ea9a877 | 91 | ##### RTC and low power modes ##### |
ganlikun | 0:13413ea9a877 | 92 | ================================================================== |
ganlikun | 0:13413ea9a877 | 93 | [..] The MCU can be woken up from a low power mode by an RTC alternate |
ganlikun | 0:13413ea9a877 | 94 | function. |
ganlikun | 0:13413ea9a877 | 95 | [..] The RTC alternate functions are the RTC alarms (Alarm A and Alarm B), |
ganlikun | 0:13413ea9a877 | 96 | RTC wake-up, RTC tamper event detection and RTC time stamp event detection. |
ganlikun | 0:13413ea9a877 | 97 | These RTC alternate functions can wake up the system from the Stop and |
ganlikun | 0:13413ea9a877 | 98 | Standby low power modes. |
ganlikun | 0:13413ea9a877 | 99 | [..] The system can also wake up from low power modes without depending |
ganlikun | 0:13413ea9a877 | 100 | on an external interrupt (Auto-wake-up mode), by using the RTC alarm |
ganlikun | 0:13413ea9a877 | 101 | or the RTC wake-up events. |
ganlikun | 0:13413ea9a877 | 102 | [..] The RTC provides a programmable time base for waking up from the |
ganlikun | 0:13413ea9a877 | 103 | Stop or Standby mode at regular intervals. |
ganlikun | 0:13413ea9a877 | 104 | Wake-up from STOP and STANDBY modes is possible only when the RTC clock source |
ganlikun | 0:13413ea9a877 | 105 | is LSE or LSI. |
ganlikun | 0:13413ea9a877 | 106 | |
ganlikun | 0:13413ea9a877 | 107 | @endverbatim |
ganlikun | 0:13413ea9a877 | 108 | ****************************************************************************** |
ganlikun | 0:13413ea9a877 | 109 | * @attention |
ganlikun | 0:13413ea9a877 | 110 | * |
ganlikun | 0:13413ea9a877 | 111 | * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> |
ganlikun | 0:13413ea9a877 | 112 | * |
ganlikun | 0:13413ea9a877 | 113 | * Redistribution and use in source and binary forms, with or without modification, |
ganlikun | 0:13413ea9a877 | 114 | * are permitted provided that the following conditions are met: |
ganlikun | 0:13413ea9a877 | 115 | * 1. Redistributions of source code must retain the above copyright notice, |
ganlikun | 0:13413ea9a877 | 116 | * this list of conditions and the following disclaimer. |
ganlikun | 0:13413ea9a877 | 117 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
ganlikun | 0:13413ea9a877 | 118 | * this list of conditions and the following disclaimer in the documentation |
ganlikun | 0:13413ea9a877 | 119 | * and/or other materials provided with the distribution. |
ganlikun | 0:13413ea9a877 | 120 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
ganlikun | 0:13413ea9a877 | 121 | * may be used to endorse or promote products derived from this software |
ganlikun | 0:13413ea9a877 | 122 | * without specific prior written permission. |
ganlikun | 0:13413ea9a877 | 123 | * |
ganlikun | 0:13413ea9a877 | 124 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
ganlikun | 0:13413ea9a877 | 125 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
ganlikun | 0:13413ea9a877 | 126 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
ganlikun | 0:13413ea9a877 | 127 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
ganlikun | 0:13413ea9a877 | 128 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
ganlikun | 0:13413ea9a877 | 129 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
ganlikun | 0:13413ea9a877 | 130 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
ganlikun | 0:13413ea9a877 | 131 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
ganlikun | 0:13413ea9a877 | 132 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
ganlikun | 0:13413ea9a877 | 133 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
ganlikun | 0:13413ea9a877 | 134 | * |
ganlikun | 0:13413ea9a877 | 135 | ****************************************************************************** |
ganlikun | 0:13413ea9a877 | 136 | */ |
ganlikun | 0:13413ea9a877 | 137 | |
ganlikun | 0:13413ea9a877 | 138 | /* Includes ------------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 139 | #include "stm32f4xx_hal.h" |
ganlikun | 0:13413ea9a877 | 140 | |
ganlikun | 0:13413ea9a877 | 141 | /** @addtogroup STM32F4xx_HAL_Driver |
ganlikun | 0:13413ea9a877 | 142 | * @{ |
ganlikun | 0:13413ea9a877 | 143 | */ |
ganlikun | 0:13413ea9a877 | 144 | |
ganlikun | 0:13413ea9a877 | 145 | /** @defgroup RTC RTC |
ganlikun | 0:13413ea9a877 | 146 | * @brief RTC HAL module driver |
ganlikun | 0:13413ea9a877 | 147 | * @{ |
ganlikun | 0:13413ea9a877 | 148 | */ |
ganlikun | 0:13413ea9a877 | 149 | |
ganlikun | 0:13413ea9a877 | 150 | #ifdef HAL_RTC_MODULE_ENABLED |
ganlikun | 0:13413ea9a877 | 151 | |
ganlikun | 0:13413ea9a877 | 152 | /* Private typedef -----------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 153 | /* Private define ------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 154 | /* Private macro -------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 155 | /* Private variables ---------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 156 | /* Private function prototypes -----------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 157 | /* Private functions ---------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 158 | |
ganlikun | 0:13413ea9a877 | 159 | /** @defgroup RTC_Exported_Functions RTC Exported Functions |
ganlikun | 0:13413ea9a877 | 160 | * @{ |
ganlikun | 0:13413ea9a877 | 161 | */ |
ganlikun | 0:13413ea9a877 | 162 | |
ganlikun | 0:13413ea9a877 | 163 | /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions |
ganlikun | 0:13413ea9a877 | 164 | * @brief Initialization and Configuration functions |
ganlikun | 0:13413ea9a877 | 165 | * |
ganlikun | 0:13413ea9a877 | 166 | @verbatim |
ganlikun | 0:13413ea9a877 | 167 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 168 | ##### Initialization and de-initialization functions ##### |
ganlikun | 0:13413ea9a877 | 169 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 170 | [..] This section provides functions allowing to initialize and configure the |
ganlikun | 0:13413ea9a877 | 171 | RTC Prescaler (Synchronous and Asynchronous), RTC Hour format, disable |
ganlikun | 0:13413ea9a877 | 172 | RTC registers Write protection, enter and exit the RTC initialization mode, |
ganlikun | 0:13413ea9a877 | 173 | RTC registers synchronization check and reference clock detection enable. |
ganlikun | 0:13413ea9a877 | 174 | (#) The RTC Prescaler is programmed to generate the RTC 1Hz time base. |
ganlikun | 0:13413ea9a877 | 175 | It is split into 2 programmable prescalers to minimize power consumption. |
ganlikun | 0:13413ea9a877 | 176 | (++) A 7-bit asynchronous prescaler and a 13-bit synchronous prescaler. |
ganlikun | 0:13413ea9a877 | 177 | (++) When both prescalers are used, it is recommended to configure the |
ganlikun | 0:13413ea9a877 | 178 | asynchronous prescaler to a high value to minimize power consumption. |
ganlikun | 0:13413ea9a877 | 179 | (#) All RTC registers are Write protected. Writing to the RTC registers |
ganlikun | 0:13413ea9a877 | 180 | is enabled by writing a key into the Write Protection register, RTC_WPR. |
ganlikun | 0:13413ea9a877 | 181 | (#) To configure the RTC Calendar, user application should enter |
ganlikun | 0:13413ea9a877 | 182 | initialization mode. In this mode, the calendar counter is stopped |
ganlikun | 0:13413ea9a877 | 183 | and its value can be updated. When the initialization sequence is |
ganlikun | 0:13413ea9a877 | 184 | complete, the calendar restarts counting after 4 RTCCLK cycles. |
ganlikun | 0:13413ea9a877 | 185 | (#) To read the calendar through the shadow registers after Calendar |
ganlikun | 0:13413ea9a877 | 186 | initialization, calendar update or after wake-up from low power modes |
ganlikun | 0:13413ea9a877 | 187 | the software must first clear the RSF flag. The software must then |
ganlikun | 0:13413ea9a877 | 188 | wait until it is set again before reading the calendar, which means |
ganlikun | 0:13413ea9a877 | 189 | that the calendar registers have been correctly copied into the |
ganlikun | 0:13413ea9a877 | 190 | RTC_TR and RTC_DR shadow registers.The HAL_RTC_WaitForSynchro() function |
ganlikun | 0:13413ea9a877 | 191 | implements the above software sequence (RSF clear and RSF check). |
ganlikun | 0:13413ea9a877 | 192 | |
ganlikun | 0:13413ea9a877 | 193 | @endverbatim |
ganlikun | 0:13413ea9a877 | 194 | * @{ |
ganlikun | 0:13413ea9a877 | 195 | */ |
ganlikun | 0:13413ea9a877 | 196 | |
ganlikun | 0:13413ea9a877 | 197 | /** |
ganlikun | 0:13413ea9a877 | 198 | * @brief Initializes the RTC peripheral |
ganlikun | 0:13413ea9a877 | 199 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 200 | * the configuration information for RTC. |
ganlikun | 0:13413ea9a877 | 201 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 202 | */ |
ganlikun | 0:13413ea9a877 | 203 | HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc) |
ganlikun | 0:13413ea9a877 | 204 | { |
ganlikun | 0:13413ea9a877 | 205 | /* Check the RTC peripheral state */ |
ganlikun | 0:13413ea9a877 | 206 | if(hrtc == NULL) |
ganlikun | 0:13413ea9a877 | 207 | { |
ganlikun | 0:13413ea9a877 | 208 | return HAL_ERROR; |
ganlikun | 0:13413ea9a877 | 209 | } |
ganlikun | 0:13413ea9a877 | 210 | |
ganlikun | 0:13413ea9a877 | 211 | /* Check the parameters */ |
ganlikun | 0:13413ea9a877 | 212 | assert_param(IS_RTC_HOUR_FORMAT(hrtc->Init.HourFormat)); |
ganlikun | 0:13413ea9a877 | 213 | assert_param(IS_RTC_ASYNCH_PREDIV(hrtc->Init.AsynchPrediv)); |
ganlikun | 0:13413ea9a877 | 214 | assert_param(IS_RTC_SYNCH_PREDIV(hrtc->Init.SynchPrediv)); |
ganlikun | 0:13413ea9a877 | 215 | assert_param (IS_RTC_OUTPUT(hrtc->Init.OutPut)); |
ganlikun | 0:13413ea9a877 | 216 | assert_param (IS_RTC_OUTPUT_POL(hrtc->Init.OutPutPolarity)); |
ganlikun | 0:13413ea9a877 | 217 | assert_param(IS_RTC_OUTPUT_TYPE(hrtc->Init.OutPutType)); |
ganlikun | 0:13413ea9a877 | 218 | |
ganlikun | 0:13413ea9a877 | 219 | if(hrtc->State == HAL_RTC_STATE_RESET) |
ganlikun | 0:13413ea9a877 | 220 | { |
ganlikun | 0:13413ea9a877 | 221 | /* Allocate lock resource and initialize it */ |
ganlikun | 0:13413ea9a877 | 222 | hrtc->Lock = HAL_UNLOCKED; |
ganlikun | 0:13413ea9a877 | 223 | /* Initialize RTC MSP */ |
ganlikun | 0:13413ea9a877 | 224 | HAL_RTC_MspInit(hrtc); |
ganlikun | 0:13413ea9a877 | 225 | } |
ganlikun | 0:13413ea9a877 | 226 | |
ganlikun | 0:13413ea9a877 | 227 | /* Set RTC state */ |
ganlikun | 0:13413ea9a877 | 228 | hrtc->State = HAL_RTC_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 229 | |
ganlikun | 0:13413ea9a877 | 230 | /* Disable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 231 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 232 | |
ganlikun | 0:13413ea9a877 | 233 | /* Set Initialization mode */ |
ganlikun | 0:13413ea9a877 | 234 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
ganlikun | 0:13413ea9a877 | 235 | { |
ganlikun | 0:13413ea9a877 | 236 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 237 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 238 | |
ganlikun | 0:13413ea9a877 | 239 | /* Set RTC state */ |
ganlikun | 0:13413ea9a877 | 240 | hrtc->State = HAL_RTC_STATE_ERROR; |
ganlikun | 0:13413ea9a877 | 241 | |
ganlikun | 0:13413ea9a877 | 242 | return HAL_ERROR; |
ganlikun | 0:13413ea9a877 | 243 | } |
ganlikun | 0:13413ea9a877 | 244 | else |
ganlikun | 0:13413ea9a877 | 245 | { |
ganlikun | 0:13413ea9a877 | 246 | /* Clear RTC_CR FMT, OSEL and POL Bits */ |
ganlikun | 0:13413ea9a877 | 247 | hrtc->Instance->CR &= ((uint32_t)~(RTC_CR_FMT | RTC_CR_OSEL | RTC_CR_POL)); |
ganlikun | 0:13413ea9a877 | 248 | /* Set RTC_CR register */ |
ganlikun | 0:13413ea9a877 | 249 | hrtc->Instance->CR |= (uint32_t)(hrtc->Init.HourFormat | hrtc->Init.OutPut | hrtc->Init.OutPutPolarity); |
ganlikun | 0:13413ea9a877 | 250 | |
ganlikun | 0:13413ea9a877 | 251 | /* Configure the RTC PRER */ |
ganlikun | 0:13413ea9a877 | 252 | hrtc->Instance->PRER = (uint32_t)(hrtc->Init.SynchPrediv); |
ganlikun | 0:13413ea9a877 | 253 | hrtc->Instance->PRER |= (uint32_t)(hrtc->Init.AsynchPrediv << 16U); |
ganlikun | 0:13413ea9a877 | 254 | |
ganlikun | 0:13413ea9a877 | 255 | /* Exit Initialization mode */ |
ganlikun | 0:13413ea9a877 | 256 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
ganlikun | 0:13413ea9a877 | 257 | |
ganlikun | 0:13413ea9a877 | 258 | hrtc->Instance->TAFCR &= (uint32_t)~RTC_TAFCR_ALARMOUTTYPE; |
ganlikun | 0:13413ea9a877 | 259 | hrtc->Instance->TAFCR |= (uint32_t)(hrtc->Init.OutPutType); |
ganlikun | 0:13413ea9a877 | 260 | |
ganlikun | 0:13413ea9a877 | 261 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 262 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 263 | |
ganlikun | 0:13413ea9a877 | 264 | /* Set RTC state */ |
ganlikun | 0:13413ea9a877 | 265 | hrtc->State = HAL_RTC_STATE_READY; |
ganlikun | 0:13413ea9a877 | 266 | |
ganlikun | 0:13413ea9a877 | 267 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 268 | } |
ganlikun | 0:13413ea9a877 | 269 | } |
ganlikun | 0:13413ea9a877 | 270 | |
ganlikun | 0:13413ea9a877 | 271 | /** |
ganlikun | 0:13413ea9a877 | 272 | * @brief DeInitializes the RTC peripheral |
ganlikun | 0:13413ea9a877 | 273 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 274 | * the configuration information for RTC. |
ganlikun | 0:13413ea9a877 | 275 | * @note This function doesn't reset the RTC Backup Data registers. |
ganlikun | 0:13413ea9a877 | 276 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 277 | */ |
ganlikun | 0:13413ea9a877 | 278 | HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc) |
ganlikun | 0:13413ea9a877 | 279 | { |
ganlikun | 0:13413ea9a877 | 280 | uint32_t tickstart = 0U; |
ganlikun | 0:13413ea9a877 | 281 | |
ganlikun | 0:13413ea9a877 | 282 | /* Set RTC state */ |
ganlikun | 0:13413ea9a877 | 283 | hrtc->State = HAL_RTC_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 284 | |
ganlikun | 0:13413ea9a877 | 285 | /* Disable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 286 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 287 | |
ganlikun | 0:13413ea9a877 | 288 | /* Set Initialization mode */ |
ganlikun | 0:13413ea9a877 | 289 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
ganlikun | 0:13413ea9a877 | 290 | { |
ganlikun | 0:13413ea9a877 | 291 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 292 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 293 | |
ganlikun | 0:13413ea9a877 | 294 | /* Set RTC state */ |
ganlikun | 0:13413ea9a877 | 295 | hrtc->State = HAL_RTC_STATE_ERROR; |
ganlikun | 0:13413ea9a877 | 296 | |
ganlikun | 0:13413ea9a877 | 297 | return HAL_ERROR; |
ganlikun | 0:13413ea9a877 | 298 | } |
ganlikun | 0:13413ea9a877 | 299 | else |
ganlikun | 0:13413ea9a877 | 300 | { |
ganlikun | 0:13413ea9a877 | 301 | /* Reset TR, DR and CR registers */ |
ganlikun | 0:13413ea9a877 | 302 | hrtc->Instance->TR = 0x00000000U; |
ganlikun | 0:13413ea9a877 | 303 | hrtc->Instance->DR = 0x00002101U; |
ganlikun | 0:13413ea9a877 | 304 | /* Reset All CR bits except CR[2:0] */ |
ganlikun | 0:13413ea9a877 | 305 | hrtc->Instance->CR &= 0x00000007U; |
ganlikun | 0:13413ea9a877 | 306 | |
ganlikun | 0:13413ea9a877 | 307 | /* Get tick */ |
ganlikun | 0:13413ea9a877 | 308 | tickstart = HAL_GetTick(); |
ganlikun | 0:13413ea9a877 | 309 | |
ganlikun | 0:13413ea9a877 | 310 | /* Wait till WUTWF flag is set and if Time out is reached exit */ |
ganlikun | 0:13413ea9a877 | 311 | while(((hrtc->Instance->ISR) & RTC_ISR_WUTWF) == (uint32_t)RESET) |
ganlikun | 0:13413ea9a877 | 312 | { |
ganlikun | 0:13413ea9a877 | 313 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
ganlikun | 0:13413ea9a877 | 314 | { |
ganlikun | 0:13413ea9a877 | 315 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 316 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 317 | |
ganlikun | 0:13413ea9a877 | 318 | /* Set RTC state */ |
ganlikun | 0:13413ea9a877 | 319 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 320 | |
ganlikun | 0:13413ea9a877 | 321 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 322 | } |
ganlikun | 0:13413ea9a877 | 323 | } |
ganlikun | 0:13413ea9a877 | 324 | |
ganlikun | 0:13413ea9a877 | 325 | /* Reset all RTC CR register bits */ |
ganlikun | 0:13413ea9a877 | 326 | hrtc->Instance->CR &= 0x00000000U; |
ganlikun | 0:13413ea9a877 | 327 | hrtc->Instance->WUTR = 0x0000FFFFU; |
ganlikun | 0:13413ea9a877 | 328 | hrtc->Instance->PRER = 0x007F00FFU; |
ganlikun | 0:13413ea9a877 | 329 | hrtc->Instance->CALIBR = 0x00000000U; |
ganlikun | 0:13413ea9a877 | 330 | hrtc->Instance->ALRMAR = 0x00000000U; |
ganlikun | 0:13413ea9a877 | 331 | hrtc->Instance->ALRMBR = 0x00000000U; |
ganlikun | 0:13413ea9a877 | 332 | hrtc->Instance->SHIFTR = 0x00000000U; |
ganlikun | 0:13413ea9a877 | 333 | hrtc->Instance->CALR = 0x00000000U; |
ganlikun | 0:13413ea9a877 | 334 | hrtc->Instance->ALRMASSR = 0x00000000U; |
ganlikun | 0:13413ea9a877 | 335 | hrtc->Instance->ALRMBSSR = 0x00000000U; |
ganlikun | 0:13413ea9a877 | 336 | |
ganlikun | 0:13413ea9a877 | 337 | /* Reset ISR register and exit initialization mode */ |
ganlikun | 0:13413ea9a877 | 338 | hrtc->Instance->ISR = 0x00000000U; |
ganlikun | 0:13413ea9a877 | 339 | |
ganlikun | 0:13413ea9a877 | 340 | /* Reset Tamper and alternate functions configuration register */ |
ganlikun | 0:13413ea9a877 | 341 | hrtc->Instance->TAFCR = 0x00000000U; |
ganlikun | 0:13413ea9a877 | 342 | |
ganlikun | 0:13413ea9a877 | 343 | /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */ |
ganlikun | 0:13413ea9a877 | 344 | if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET) |
ganlikun | 0:13413ea9a877 | 345 | { |
ganlikun | 0:13413ea9a877 | 346 | if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
ganlikun | 0:13413ea9a877 | 347 | { |
ganlikun | 0:13413ea9a877 | 348 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 349 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 350 | |
ganlikun | 0:13413ea9a877 | 351 | hrtc->State = HAL_RTC_STATE_ERROR; |
ganlikun | 0:13413ea9a877 | 352 | |
ganlikun | 0:13413ea9a877 | 353 | return HAL_ERROR; |
ganlikun | 0:13413ea9a877 | 354 | } |
ganlikun | 0:13413ea9a877 | 355 | } |
ganlikun | 0:13413ea9a877 | 356 | } |
ganlikun | 0:13413ea9a877 | 357 | |
ganlikun | 0:13413ea9a877 | 358 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 359 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 360 | |
ganlikun | 0:13413ea9a877 | 361 | /* De-Initialize RTC MSP */ |
ganlikun | 0:13413ea9a877 | 362 | HAL_RTC_MspDeInit(hrtc); |
ganlikun | 0:13413ea9a877 | 363 | |
ganlikun | 0:13413ea9a877 | 364 | hrtc->State = HAL_RTC_STATE_RESET; |
ganlikun | 0:13413ea9a877 | 365 | |
ganlikun | 0:13413ea9a877 | 366 | /* Release Lock */ |
ganlikun | 0:13413ea9a877 | 367 | __HAL_UNLOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 368 | |
ganlikun | 0:13413ea9a877 | 369 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 370 | } |
ganlikun | 0:13413ea9a877 | 371 | |
ganlikun | 0:13413ea9a877 | 372 | /** |
ganlikun | 0:13413ea9a877 | 373 | * @brief Initializes the RTC MSP. |
ganlikun | 0:13413ea9a877 | 374 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 375 | * the configuration information for RTC. |
ganlikun | 0:13413ea9a877 | 376 | * @retval None |
ganlikun | 0:13413ea9a877 | 377 | */ |
ganlikun | 0:13413ea9a877 | 378 | __weak void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc) |
ganlikun | 0:13413ea9a877 | 379 | { |
ganlikun | 0:13413ea9a877 | 380 | /* Prevent unused argument(s) compilation warning */ |
ganlikun | 0:13413ea9a877 | 381 | UNUSED(hrtc); |
ganlikun | 0:13413ea9a877 | 382 | /* NOTE : This function Should not be modified, when the callback is needed, |
ganlikun | 0:13413ea9a877 | 383 | the HAL_RTC_MspInit could be implemented in the user file |
ganlikun | 0:13413ea9a877 | 384 | */ |
ganlikun | 0:13413ea9a877 | 385 | } |
ganlikun | 0:13413ea9a877 | 386 | |
ganlikun | 0:13413ea9a877 | 387 | /** |
ganlikun | 0:13413ea9a877 | 388 | * @brief DeInitializes the RTC MSP. |
ganlikun | 0:13413ea9a877 | 389 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 390 | * the configuration information for RTC. |
ganlikun | 0:13413ea9a877 | 391 | * @retval None |
ganlikun | 0:13413ea9a877 | 392 | */ |
ganlikun | 0:13413ea9a877 | 393 | __weak void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc) |
ganlikun | 0:13413ea9a877 | 394 | { |
ganlikun | 0:13413ea9a877 | 395 | /* Prevent unused argument(s) compilation warning */ |
ganlikun | 0:13413ea9a877 | 396 | UNUSED(hrtc); |
ganlikun | 0:13413ea9a877 | 397 | /* NOTE : This function Should not be modified, when the callback is needed, |
ganlikun | 0:13413ea9a877 | 398 | the HAL_RTC_MspDeInit could be implemented in the user file |
ganlikun | 0:13413ea9a877 | 399 | */ |
ganlikun | 0:13413ea9a877 | 400 | } |
ganlikun | 0:13413ea9a877 | 401 | |
ganlikun | 0:13413ea9a877 | 402 | /** |
ganlikun | 0:13413ea9a877 | 403 | * @} |
ganlikun | 0:13413ea9a877 | 404 | */ |
ganlikun | 0:13413ea9a877 | 405 | |
ganlikun | 0:13413ea9a877 | 406 | /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions |
ganlikun | 0:13413ea9a877 | 407 | * @brief RTC Time and Date functions |
ganlikun | 0:13413ea9a877 | 408 | * |
ganlikun | 0:13413ea9a877 | 409 | @verbatim |
ganlikun | 0:13413ea9a877 | 410 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 411 | ##### RTC Time and Date functions ##### |
ganlikun | 0:13413ea9a877 | 412 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 413 | |
ganlikun | 0:13413ea9a877 | 414 | [..] This section provides functions allowing to configure Time and Date features |
ganlikun | 0:13413ea9a877 | 415 | |
ganlikun | 0:13413ea9a877 | 416 | @endverbatim |
ganlikun | 0:13413ea9a877 | 417 | * @{ |
ganlikun | 0:13413ea9a877 | 418 | */ |
ganlikun | 0:13413ea9a877 | 419 | |
ganlikun | 0:13413ea9a877 | 420 | /** |
ganlikun | 0:13413ea9a877 | 421 | * @brief Sets RTC current time. |
ganlikun | 0:13413ea9a877 | 422 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 423 | * the configuration information for RTC. |
ganlikun | 0:13413ea9a877 | 424 | * @param sTime: Pointer to Time structure |
ganlikun | 0:13413ea9a877 | 425 | * @param Format: Specifies the format of the entered parameters. |
ganlikun | 0:13413ea9a877 | 426 | * This parameter can be one of the following values: |
ganlikun | 0:13413ea9a877 | 427 | * @arg RTC_FORMAT_BIN: Binary data format |
ganlikun | 0:13413ea9a877 | 428 | * @arg RTC_FORMAT_BCD: BCD data format |
ganlikun | 0:13413ea9a877 | 429 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 430 | */ |
ganlikun | 0:13413ea9a877 | 431 | HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format) |
ganlikun | 0:13413ea9a877 | 432 | { |
ganlikun | 0:13413ea9a877 | 433 | uint32_t tmpreg = 0U; |
ganlikun | 0:13413ea9a877 | 434 | |
ganlikun | 0:13413ea9a877 | 435 | /* Check the parameters */ |
ganlikun | 0:13413ea9a877 | 436 | assert_param(IS_RTC_FORMAT(Format)); |
ganlikun | 0:13413ea9a877 | 437 | assert_param(IS_RTC_DAYLIGHT_SAVING(sTime->DayLightSaving)); |
ganlikun | 0:13413ea9a877 | 438 | assert_param(IS_RTC_STORE_OPERATION(sTime->StoreOperation)); |
ganlikun | 0:13413ea9a877 | 439 | |
ganlikun | 0:13413ea9a877 | 440 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 441 | __HAL_LOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 442 | |
ganlikun | 0:13413ea9a877 | 443 | hrtc->State = HAL_RTC_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 444 | |
ganlikun | 0:13413ea9a877 | 445 | if(Format == RTC_FORMAT_BIN) |
ganlikun | 0:13413ea9a877 | 446 | { |
ganlikun | 0:13413ea9a877 | 447 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
ganlikun | 0:13413ea9a877 | 448 | { |
ganlikun | 0:13413ea9a877 | 449 | assert_param(IS_RTC_HOUR12(sTime->Hours)); |
ganlikun | 0:13413ea9a877 | 450 | assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat)); |
ganlikun | 0:13413ea9a877 | 451 | } |
ganlikun | 0:13413ea9a877 | 452 | else |
ganlikun | 0:13413ea9a877 | 453 | { |
ganlikun | 0:13413ea9a877 | 454 | sTime->TimeFormat = 0x00U; |
ganlikun | 0:13413ea9a877 | 455 | assert_param(IS_RTC_HOUR24(sTime->Hours)); |
ganlikun | 0:13413ea9a877 | 456 | } |
ganlikun | 0:13413ea9a877 | 457 | assert_param(IS_RTC_MINUTES(sTime->Minutes)); |
ganlikun | 0:13413ea9a877 | 458 | assert_param(IS_RTC_SECONDS(sTime->Seconds)); |
ganlikun | 0:13413ea9a877 | 459 | |
ganlikun | 0:13413ea9a877 | 460 | tmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(sTime->Hours) << 16U) | \ |
ganlikun | 0:13413ea9a877 | 461 | ((uint32_t)RTC_ByteToBcd2(sTime->Minutes) << 8U) | \ |
ganlikun | 0:13413ea9a877 | 462 | ((uint32_t)RTC_ByteToBcd2(sTime->Seconds)) | \ |
ganlikun | 0:13413ea9a877 | 463 | (((uint32_t)sTime->TimeFormat) << 16U)); |
ganlikun | 0:13413ea9a877 | 464 | } |
ganlikun | 0:13413ea9a877 | 465 | else |
ganlikun | 0:13413ea9a877 | 466 | { |
ganlikun | 0:13413ea9a877 | 467 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
ganlikun | 0:13413ea9a877 | 468 | { |
ganlikun | 0:13413ea9a877 | 469 | tmpreg = RTC_Bcd2ToByte(sTime->Hours); |
ganlikun | 0:13413ea9a877 | 470 | assert_param(IS_RTC_HOUR12(tmpreg)); |
ganlikun | 0:13413ea9a877 | 471 | assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat)); |
ganlikun | 0:13413ea9a877 | 472 | } |
ganlikun | 0:13413ea9a877 | 473 | else |
ganlikun | 0:13413ea9a877 | 474 | { |
ganlikun | 0:13413ea9a877 | 475 | sTime->TimeFormat = 0x00U; |
ganlikun | 0:13413ea9a877 | 476 | assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sTime->Hours))); |
ganlikun | 0:13413ea9a877 | 477 | } |
ganlikun | 0:13413ea9a877 | 478 | assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sTime->Minutes))); |
ganlikun | 0:13413ea9a877 | 479 | assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sTime->Seconds))); |
ganlikun | 0:13413ea9a877 | 480 | tmpreg = (((uint32_t)(sTime->Hours) << 16U) | \ |
ganlikun | 0:13413ea9a877 | 481 | ((uint32_t)(sTime->Minutes) << 8U) | \ |
ganlikun | 0:13413ea9a877 | 482 | ((uint32_t)sTime->Seconds) | \ |
ganlikun | 0:13413ea9a877 | 483 | ((uint32_t)(sTime->TimeFormat) << 16U)); |
ganlikun | 0:13413ea9a877 | 484 | } |
ganlikun | 0:13413ea9a877 | 485 | |
ganlikun | 0:13413ea9a877 | 486 | /* Disable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 487 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 488 | |
ganlikun | 0:13413ea9a877 | 489 | /* Set Initialization mode */ |
ganlikun | 0:13413ea9a877 | 490 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
ganlikun | 0:13413ea9a877 | 491 | { |
ganlikun | 0:13413ea9a877 | 492 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 493 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 494 | |
ganlikun | 0:13413ea9a877 | 495 | /* Set RTC state */ |
ganlikun | 0:13413ea9a877 | 496 | hrtc->State = HAL_RTC_STATE_ERROR; |
ganlikun | 0:13413ea9a877 | 497 | |
ganlikun | 0:13413ea9a877 | 498 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 499 | __HAL_UNLOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 500 | |
ganlikun | 0:13413ea9a877 | 501 | return HAL_ERROR; |
ganlikun | 0:13413ea9a877 | 502 | } |
ganlikun | 0:13413ea9a877 | 503 | else |
ganlikun | 0:13413ea9a877 | 504 | { |
ganlikun | 0:13413ea9a877 | 505 | /* Set the RTC_TR register */ |
ganlikun | 0:13413ea9a877 | 506 | hrtc->Instance->TR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK); |
ganlikun | 0:13413ea9a877 | 507 | |
ganlikun | 0:13413ea9a877 | 508 | /* Clear the bits to be configured */ |
ganlikun | 0:13413ea9a877 | 509 | hrtc->Instance->CR &= (uint32_t)~RTC_CR_BCK; |
ganlikun | 0:13413ea9a877 | 510 | |
ganlikun | 0:13413ea9a877 | 511 | /* Configure the RTC_CR register */ |
ganlikun | 0:13413ea9a877 | 512 | hrtc->Instance->CR |= (uint32_t)(sTime->DayLightSaving | sTime->StoreOperation); |
ganlikun | 0:13413ea9a877 | 513 | |
ganlikun | 0:13413ea9a877 | 514 | /* Exit Initialization mode */ |
ganlikun | 0:13413ea9a877 | 515 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
ganlikun | 0:13413ea9a877 | 516 | |
ganlikun | 0:13413ea9a877 | 517 | /* If CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */ |
ganlikun | 0:13413ea9a877 | 518 | if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET) |
ganlikun | 0:13413ea9a877 | 519 | { |
ganlikun | 0:13413ea9a877 | 520 | if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
ganlikun | 0:13413ea9a877 | 521 | { |
ganlikun | 0:13413ea9a877 | 522 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 523 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 524 | |
ganlikun | 0:13413ea9a877 | 525 | hrtc->State = HAL_RTC_STATE_ERROR; |
ganlikun | 0:13413ea9a877 | 526 | |
ganlikun | 0:13413ea9a877 | 527 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 528 | __HAL_UNLOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 529 | |
ganlikun | 0:13413ea9a877 | 530 | return HAL_ERROR; |
ganlikun | 0:13413ea9a877 | 531 | } |
ganlikun | 0:13413ea9a877 | 532 | } |
ganlikun | 0:13413ea9a877 | 533 | |
ganlikun | 0:13413ea9a877 | 534 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 535 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 536 | |
ganlikun | 0:13413ea9a877 | 537 | hrtc->State = HAL_RTC_STATE_READY; |
ganlikun | 0:13413ea9a877 | 538 | |
ganlikun | 0:13413ea9a877 | 539 | __HAL_UNLOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 540 | |
ganlikun | 0:13413ea9a877 | 541 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 542 | } |
ganlikun | 0:13413ea9a877 | 543 | } |
ganlikun | 0:13413ea9a877 | 544 | |
ganlikun | 0:13413ea9a877 | 545 | /** |
ganlikun | 0:13413ea9a877 | 546 | * @brief Gets RTC current time. |
ganlikun | 0:13413ea9a877 | 547 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 548 | * the configuration information for RTC. |
ganlikun | 0:13413ea9a877 | 549 | * @param sTime: Pointer to Time structure |
ganlikun | 0:13413ea9a877 | 550 | * @param Format: Specifies the format of the entered parameters. |
ganlikun | 0:13413ea9a877 | 551 | * This parameter can be one of the following values: |
ganlikun | 0:13413ea9a877 | 552 | * @arg RTC_FORMAT_BIN: Binary data format |
ganlikun | 0:13413ea9a877 | 553 | * @arg RTC_FORMAT_BCD: BCD data format |
ganlikun | 0:13413ea9a877 | 554 | * @note You can use SubSeconds and SecondFraction (sTime structure fields returned) to convert SubSeconds |
ganlikun | 0:13413ea9a877 | 555 | * value in second fraction ratio with time unit following generic formula: |
ganlikun | 0:13413ea9a877 | 556 | * Second fraction ratio * time_unit= [(SecondFraction-SubSeconds)/(SecondFraction+1)] * time_unit |
ganlikun | 0:13413ea9a877 | 557 | * This conversion can be performed only if no shift operation is pending (ie. SHFP=0) when PREDIV_S >= SS |
ganlikun | 0:13413ea9a877 | 558 | * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values |
ganlikun | 0:13413ea9a877 | 559 | * in the higher-order calendar shadow registers to ensure consistency between the time and date values. |
ganlikun | 0:13413ea9a877 | 560 | * Reading RTC current time locks the values in calendar shadow registers until current date is read. |
ganlikun | 0:13413ea9a877 | 561 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 562 | */ |
ganlikun | 0:13413ea9a877 | 563 | HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format) |
ganlikun | 0:13413ea9a877 | 564 | { |
ganlikun | 0:13413ea9a877 | 565 | uint32_t tmpreg = 0U; |
ganlikun | 0:13413ea9a877 | 566 | |
ganlikun | 0:13413ea9a877 | 567 | /* Check the parameters */ |
ganlikun | 0:13413ea9a877 | 568 | assert_param(IS_RTC_FORMAT(Format)); |
ganlikun | 0:13413ea9a877 | 569 | |
ganlikun | 0:13413ea9a877 | 570 | /* Get subseconds structure field from the corresponding register */ |
ganlikun | 0:13413ea9a877 | 571 | sTime->SubSeconds = (uint32_t)(hrtc->Instance->SSR); |
ganlikun | 0:13413ea9a877 | 572 | |
ganlikun | 0:13413ea9a877 | 573 | /* Get SecondFraction structure field from the corresponding register field*/ |
ganlikun | 0:13413ea9a877 | 574 | sTime->SecondFraction = (uint32_t)(hrtc->Instance->PRER & RTC_PRER_PREDIV_S); |
ganlikun | 0:13413ea9a877 | 575 | |
ganlikun | 0:13413ea9a877 | 576 | /* Get the TR register */ |
ganlikun | 0:13413ea9a877 | 577 | tmpreg = (uint32_t)(hrtc->Instance->TR & RTC_TR_RESERVED_MASK); |
ganlikun | 0:13413ea9a877 | 578 | |
ganlikun | 0:13413ea9a877 | 579 | /* Fill the structure fields with the read parameters */ |
ganlikun | 0:13413ea9a877 | 580 | sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16U); |
ganlikun | 0:13413ea9a877 | 581 | sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >> 8U); |
ganlikun | 0:13413ea9a877 | 582 | sTime->Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU)); |
ganlikun | 0:13413ea9a877 | 583 | sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16U); |
ganlikun | 0:13413ea9a877 | 584 | |
ganlikun | 0:13413ea9a877 | 585 | /* Check the input parameters format */ |
ganlikun | 0:13413ea9a877 | 586 | if(Format == RTC_FORMAT_BIN) |
ganlikun | 0:13413ea9a877 | 587 | { |
ganlikun | 0:13413ea9a877 | 588 | /* Convert the time structure parameters to Binary format */ |
ganlikun | 0:13413ea9a877 | 589 | sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours); |
ganlikun | 0:13413ea9a877 | 590 | sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes); |
ganlikun | 0:13413ea9a877 | 591 | sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds); |
ganlikun | 0:13413ea9a877 | 592 | } |
ganlikun | 0:13413ea9a877 | 593 | |
ganlikun | 0:13413ea9a877 | 594 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 595 | } |
ganlikun | 0:13413ea9a877 | 596 | |
ganlikun | 0:13413ea9a877 | 597 | /** |
ganlikun | 0:13413ea9a877 | 598 | * @brief Sets RTC current date. |
ganlikun | 0:13413ea9a877 | 599 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 600 | * the configuration information for RTC. |
ganlikun | 0:13413ea9a877 | 601 | * @param sDate: Pointer to date structure |
ganlikun | 0:13413ea9a877 | 602 | * @param Format: specifies the format of the entered parameters. |
ganlikun | 0:13413ea9a877 | 603 | * This parameter can be one of the following values: |
ganlikun | 0:13413ea9a877 | 604 | * @arg RTC_FORMAT_BIN: Binary data format |
ganlikun | 0:13413ea9a877 | 605 | * @arg RTC_FORMAT_BCD: BCD data format |
ganlikun | 0:13413ea9a877 | 606 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 607 | */ |
ganlikun | 0:13413ea9a877 | 608 | HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format) |
ganlikun | 0:13413ea9a877 | 609 | { |
ganlikun | 0:13413ea9a877 | 610 | uint32_t datetmpreg = 0U; |
ganlikun | 0:13413ea9a877 | 611 | |
ganlikun | 0:13413ea9a877 | 612 | /* Check the parameters */ |
ganlikun | 0:13413ea9a877 | 613 | assert_param(IS_RTC_FORMAT(Format)); |
ganlikun | 0:13413ea9a877 | 614 | |
ganlikun | 0:13413ea9a877 | 615 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 616 | __HAL_LOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 617 | |
ganlikun | 0:13413ea9a877 | 618 | hrtc->State = HAL_RTC_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 619 | |
ganlikun | 0:13413ea9a877 | 620 | if((Format == RTC_FORMAT_BIN) && ((sDate->Month & 0x10U) == 0x10U)) |
ganlikun | 0:13413ea9a877 | 621 | { |
ganlikun | 0:13413ea9a877 | 622 | sDate->Month = (uint8_t)((sDate->Month & (uint8_t)~(0x10U)) + (uint8_t)0x0AU); |
ganlikun | 0:13413ea9a877 | 623 | } |
ganlikun | 0:13413ea9a877 | 624 | |
ganlikun | 0:13413ea9a877 | 625 | assert_param(IS_RTC_WEEKDAY(sDate->WeekDay)); |
ganlikun | 0:13413ea9a877 | 626 | |
ganlikun | 0:13413ea9a877 | 627 | if(Format == RTC_FORMAT_BIN) |
ganlikun | 0:13413ea9a877 | 628 | { |
ganlikun | 0:13413ea9a877 | 629 | assert_param(IS_RTC_YEAR(sDate->Year)); |
ganlikun | 0:13413ea9a877 | 630 | assert_param(IS_RTC_MONTH(sDate->Month)); |
ganlikun | 0:13413ea9a877 | 631 | assert_param(IS_RTC_DATE(sDate->Date)); |
ganlikun | 0:13413ea9a877 | 632 | |
ganlikun | 0:13413ea9a877 | 633 | datetmpreg = (((uint32_t)RTC_ByteToBcd2(sDate->Year) << 16U) | \ |
ganlikun | 0:13413ea9a877 | 634 | ((uint32_t)RTC_ByteToBcd2(sDate->Month) << 8U) | \ |
ganlikun | 0:13413ea9a877 | 635 | ((uint32_t)RTC_ByteToBcd2(sDate->Date)) | \ |
ganlikun | 0:13413ea9a877 | 636 | ((uint32_t)sDate->WeekDay << 13U)); |
ganlikun | 0:13413ea9a877 | 637 | } |
ganlikun | 0:13413ea9a877 | 638 | else |
ganlikun | 0:13413ea9a877 | 639 | { |
ganlikun | 0:13413ea9a877 | 640 | assert_param(IS_RTC_YEAR(RTC_Bcd2ToByte(sDate->Year))); |
ganlikun | 0:13413ea9a877 | 641 | datetmpreg = RTC_Bcd2ToByte(sDate->Month); |
ganlikun | 0:13413ea9a877 | 642 | assert_param(IS_RTC_MONTH(datetmpreg)); |
ganlikun | 0:13413ea9a877 | 643 | datetmpreg = RTC_Bcd2ToByte(sDate->Date); |
ganlikun | 0:13413ea9a877 | 644 | assert_param(IS_RTC_DATE(datetmpreg)); |
ganlikun | 0:13413ea9a877 | 645 | |
ganlikun | 0:13413ea9a877 | 646 | datetmpreg = ((((uint32_t)sDate->Year) << 16U) | \ |
ganlikun | 0:13413ea9a877 | 647 | (((uint32_t)sDate->Month) << 8U) | \ |
ganlikun | 0:13413ea9a877 | 648 | ((uint32_t)sDate->Date) | \ |
ganlikun | 0:13413ea9a877 | 649 | (((uint32_t)sDate->WeekDay) << 13U)); |
ganlikun | 0:13413ea9a877 | 650 | } |
ganlikun | 0:13413ea9a877 | 651 | |
ganlikun | 0:13413ea9a877 | 652 | /* Disable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 653 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 654 | |
ganlikun | 0:13413ea9a877 | 655 | /* Set Initialization mode */ |
ganlikun | 0:13413ea9a877 | 656 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
ganlikun | 0:13413ea9a877 | 657 | { |
ganlikun | 0:13413ea9a877 | 658 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 659 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 660 | |
ganlikun | 0:13413ea9a877 | 661 | /* Set RTC state*/ |
ganlikun | 0:13413ea9a877 | 662 | hrtc->State = HAL_RTC_STATE_ERROR; |
ganlikun | 0:13413ea9a877 | 663 | |
ganlikun | 0:13413ea9a877 | 664 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 665 | __HAL_UNLOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 666 | |
ganlikun | 0:13413ea9a877 | 667 | return HAL_ERROR; |
ganlikun | 0:13413ea9a877 | 668 | } |
ganlikun | 0:13413ea9a877 | 669 | else |
ganlikun | 0:13413ea9a877 | 670 | { |
ganlikun | 0:13413ea9a877 | 671 | /* Set the RTC_DR register */ |
ganlikun | 0:13413ea9a877 | 672 | hrtc->Instance->DR = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK); |
ganlikun | 0:13413ea9a877 | 673 | |
ganlikun | 0:13413ea9a877 | 674 | /* Exit Initialization mode */ |
ganlikun | 0:13413ea9a877 | 675 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
ganlikun | 0:13413ea9a877 | 676 | |
ganlikun | 0:13413ea9a877 | 677 | /* If CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */ |
ganlikun | 0:13413ea9a877 | 678 | if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET) |
ganlikun | 0:13413ea9a877 | 679 | { |
ganlikun | 0:13413ea9a877 | 680 | if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
ganlikun | 0:13413ea9a877 | 681 | { |
ganlikun | 0:13413ea9a877 | 682 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 683 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 684 | |
ganlikun | 0:13413ea9a877 | 685 | hrtc->State = HAL_RTC_STATE_ERROR; |
ganlikun | 0:13413ea9a877 | 686 | |
ganlikun | 0:13413ea9a877 | 687 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 688 | __HAL_UNLOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 689 | |
ganlikun | 0:13413ea9a877 | 690 | return HAL_ERROR; |
ganlikun | 0:13413ea9a877 | 691 | } |
ganlikun | 0:13413ea9a877 | 692 | } |
ganlikun | 0:13413ea9a877 | 693 | |
ganlikun | 0:13413ea9a877 | 694 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 695 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 696 | |
ganlikun | 0:13413ea9a877 | 697 | hrtc->State = HAL_RTC_STATE_READY ; |
ganlikun | 0:13413ea9a877 | 698 | |
ganlikun | 0:13413ea9a877 | 699 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 700 | __HAL_UNLOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 701 | |
ganlikun | 0:13413ea9a877 | 702 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 703 | } |
ganlikun | 0:13413ea9a877 | 704 | } |
ganlikun | 0:13413ea9a877 | 705 | |
ganlikun | 0:13413ea9a877 | 706 | /** |
ganlikun | 0:13413ea9a877 | 707 | * @brief Gets RTC current date. |
ganlikun | 0:13413ea9a877 | 708 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 709 | * the configuration information for RTC. |
ganlikun | 0:13413ea9a877 | 710 | * @param sDate: Pointer to Date structure |
ganlikun | 0:13413ea9a877 | 711 | * @param Format: Specifies the format of the entered parameters. |
ganlikun | 0:13413ea9a877 | 712 | * This parameter can be one of the following values: |
ganlikun | 0:13413ea9a877 | 713 | * @arg RTC_FORMAT_BIN: Binary data format |
ganlikun | 0:13413ea9a877 | 714 | * @arg RTC_FORMAT_BCD: BCD data format |
ganlikun | 0:13413ea9a877 | 715 | * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values |
ganlikun | 0:13413ea9a877 | 716 | * in the higher-order calendar shadow registers to ensure consistency between the time and date values. |
ganlikun | 0:13413ea9a877 | 717 | * Reading RTC current time locks the values in calendar shadow registers until Current date is read. |
ganlikun | 0:13413ea9a877 | 718 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 719 | */ |
ganlikun | 0:13413ea9a877 | 720 | HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format) |
ganlikun | 0:13413ea9a877 | 721 | { |
ganlikun | 0:13413ea9a877 | 722 | uint32_t datetmpreg = 0U; |
ganlikun | 0:13413ea9a877 | 723 | |
ganlikun | 0:13413ea9a877 | 724 | /* Check the parameters */ |
ganlikun | 0:13413ea9a877 | 725 | assert_param(IS_RTC_FORMAT(Format)); |
ganlikun | 0:13413ea9a877 | 726 | |
ganlikun | 0:13413ea9a877 | 727 | /* Get the DR register */ |
ganlikun | 0:13413ea9a877 | 728 | datetmpreg = (uint32_t)(hrtc->Instance->DR & RTC_DR_RESERVED_MASK); |
ganlikun | 0:13413ea9a877 | 729 | |
ganlikun | 0:13413ea9a877 | 730 | /* Fill the structure fields with the read parameters */ |
ganlikun | 0:13413ea9a877 | 731 | sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16U); |
ganlikun | 0:13413ea9a877 | 732 | sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8U); |
ganlikun | 0:13413ea9a877 | 733 | sDate->Date = (uint8_t)(datetmpreg & (RTC_DR_DT | RTC_DR_DU)); |
ganlikun | 0:13413ea9a877 | 734 | sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> 13U); |
ganlikun | 0:13413ea9a877 | 735 | |
ganlikun | 0:13413ea9a877 | 736 | /* Check the input parameters format */ |
ganlikun | 0:13413ea9a877 | 737 | if(Format == RTC_FORMAT_BIN) |
ganlikun | 0:13413ea9a877 | 738 | { |
ganlikun | 0:13413ea9a877 | 739 | /* Convert the date structure parameters to Binary format */ |
ganlikun | 0:13413ea9a877 | 740 | sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year); |
ganlikun | 0:13413ea9a877 | 741 | sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month); |
ganlikun | 0:13413ea9a877 | 742 | sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date); |
ganlikun | 0:13413ea9a877 | 743 | } |
ganlikun | 0:13413ea9a877 | 744 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 745 | } |
ganlikun | 0:13413ea9a877 | 746 | |
ganlikun | 0:13413ea9a877 | 747 | /** |
ganlikun | 0:13413ea9a877 | 748 | * @} |
ganlikun | 0:13413ea9a877 | 749 | */ |
ganlikun | 0:13413ea9a877 | 750 | |
ganlikun | 0:13413ea9a877 | 751 | /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions |
ganlikun | 0:13413ea9a877 | 752 | * @brief RTC Alarm functions |
ganlikun | 0:13413ea9a877 | 753 | * |
ganlikun | 0:13413ea9a877 | 754 | @verbatim |
ganlikun | 0:13413ea9a877 | 755 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 756 | ##### RTC Alarm functions ##### |
ganlikun | 0:13413ea9a877 | 757 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 758 | |
ganlikun | 0:13413ea9a877 | 759 | [..] This section provides functions allowing to configure Alarm feature |
ganlikun | 0:13413ea9a877 | 760 | |
ganlikun | 0:13413ea9a877 | 761 | @endverbatim |
ganlikun | 0:13413ea9a877 | 762 | * @{ |
ganlikun | 0:13413ea9a877 | 763 | */ |
ganlikun | 0:13413ea9a877 | 764 | /** |
ganlikun | 0:13413ea9a877 | 765 | * @brief Sets the specified RTC Alarm. |
ganlikun | 0:13413ea9a877 | 766 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 767 | * the configuration information for RTC. |
ganlikun | 0:13413ea9a877 | 768 | * @param sAlarm: Pointer to Alarm structure |
ganlikun | 0:13413ea9a877 | 769 | * @param Format: Specifies the format of the entered parameters. |
ganlikun | 0:13413ea9a877 | 770 | * This parameter can be one of the following values: |
ganlikun | 0:13413ea9a877 | 771 | * @arg RTC_FORMAT_BIN: Binary data format |
ganlikun | 0:13413ea9a877 | 772 | * @arg RTC_FORMAT_BCD: BCD data format |
ganlikun | 0:13413ea9a877 | 773 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 774 | */ |
ganlikun | 0:13413ea9a877 | 775 | HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format) |
ganlikun | 0:13413ea9a877 | 776 | { |
ganlikun | 0:13413ea9a877 | 777 | uint32_t tickstart = 0U; |
ganlikun | 0:13413ea9a877 | 778 | uint32_t tmpreg = 0U, subsecondtmpreg = 0U; |
ganlikun | 0:13413ea9a877 | 779 | |
ganlikun | 0:13413ea9a877 | 780 | /* Check the parameters */ |
ganlikun | 0:13413ea9a877 | 781 | assert_param(IS_RTC_FORMAT(Format)); |
ganlikun | 0:13413ea9a877 | 782 | assert_param(IS_RTC_ALARM(sAlarm->Alarm)); |
ganlikun | 0:13413ea9a877 | 783 | assert_param(IS_RTC_ALARM_MASK(sAlarm->AlarmMask)); |
ganlikun | 0:13413ea9a877 | 784 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel)); |
ganlikun | 0:13413ea9a877 | 785 | assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds)); |
ganlikun | 0:13413ea9a877 | 786 | assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask)); |
ganlikun | 0:13413ea9a877 | 787 | |
ganlikun | 0:13413ea9a877 | 788 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 789 | __HAL_LOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 790 | |
ganlikun | 0:13413ea9a877 | 791 | hrtc->State = HAL_RTC_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 792 | |
ganlikun | 0:13413ea9a877 | 793 | if(Format == RTC_FORMAT_BIN) |
ganlikun | 0:13413ea9a877 | 794 | { |
ganlikun | 0:13413ea9a877 | 795 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
ganlikun | 0:13413ea9a877 | 796 | { |
ganlikun | 0:13413ea9a877 | 797 | assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours)); |
ganlikun | 0:13413ea9a877 | 798 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
ganlikun | 0:13413ea9a877 | 799 | } |
ganlikun | 0:13413ea9a877 | 800 | else |
ganlikun | 0:13413ea9a877 | 801 | { |
ganlikun | 0:13413ea9a877 | 802 | sAlarm->AlarmTime.TimeFormat = 0x00U; |
ganlikun | 0:13413ea9a877 | 803 | assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours)); |
ganlikun | 0:13413ea9a877 | 804 | } |
ganlikun | 0:13413ea9a877 | 805 | assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes)); |
ganlikun | 0:13413ea9a877 | 806 | assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds)); |
ganlikun | 0:13413ea9a877 | 807 | |
ganlikun | 0:13413ea9a877 | 808 | if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
ganlikun | 0:13413ea9a877 | 809 | { |
ganlikun | 0:13413ea9a877 | 810 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay)); |
ganlikun | 0:13413ea9a877 | 811 | } |
ganlikun | 0:13413ea9a877 | 812 | else |
ganlikun | 0:13413ea9a877 | 813 | { |
ganlikun | 0:13413ea9a877 | 814 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay)); |
ganlikun | 0:13413ea9a877 | 815 | } |
ganlikun | 0:13413ea9a877 | 816 | |
ganlikun | 0:13413ea9a877 | 817 | tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16U) | \ |
ganlikun | 0:13413ea9a877 | 818 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8U) | \ |
ganlikun | 0:13413ea9a877 | 819 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \ |
ganlikun | 0:13413ea9a877 | 820 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16U) | \ |
ganlikun | 0:13413ea9a877 | 821 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24U) | \ |
ganlikun | 0:13413ea9a877 | 822 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
ganlikun | 0:13413ea9a877 | 823 | ((uint32_t)sAlarm->AlarmMask)); |
ganlikun | 0:13413ea9a877 | 824 | } |
ganlikun | 0:13413ea9a877 | 825 | else |
ganlikun | 0:13413ea9a877 | 826 | { |
ganlikun | 0:13413ea9a877 | 827 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
ganlikun | 0:13413ea9a877 | 828 | { |
ganlikun | 0:13413ea9a877 | 829 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours); |
ganlikun | 0:13413ea9a877 | 830 | assert_param(IS_RTC_HOUR12(tmpreg)); |
ganlikun | 0:13413ea9a877 | 831 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
ganlikun | 0:13413ea9a877 | 832 | } |
ganlikun | 0:13413ea9a877 | 833 | else |
ganlikun | 0:13413ea9a877 | 834 | { |
ganlikun | 0:13413ea9a877 | 835 | sAlarm->AlarmTime.TimeFormat = 0x00U; |
ganlikun | 0:13413ea9a877 | 836 | assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours))); |
ganlikun | 0:13413ea9a877 | 837 | } |
ganlikun | 0:13413ea9a877 | 838 | |
ganlikun | 0:13413ea9a877 | 839 | assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes))); |
ganlikun | 0:13413ea9a877 | 840 | assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds))); |
ganlikun | 0:13413ea9a877 | 841 | |
ganlikun | 0:13413ea9a877 | 842 | if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
ganlikun | 0:13413ea9a877 | 843 | { |
ganlikun | 0:13413ea9a877 | 844 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
ganlikun | 0:13413ea9a877 | 845 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg)); |
ganlikun | 0:13413ea9a877 | 846 | } |
ganlikun | 0:13413ea9a877 | 847 | else |
ganlikun | 0:13413ea9a877 | 848 | { |
ganlikun | 0:13413ea9a877 | 849 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
ganlikun | 0:13413ea9a877 | 850 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg)); |
ganlikun | 0:13413ea9a877 | 851 | } |
ganlikun | 0:13413ea9a877 | 852 | |
ganlikun | 0:13413ea9a877 | 853 | tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16U) | \ |
ganlikun | 0:13413ea9a877 | 854 | ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8U) | \ |
ganlikun | 0:13413ea9a877 | 855 | ((uint32_t) sAlarm->AlarmTime.Seconds) | \ |
ganlikun | 0:13413ea9a877 | 856 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16U) | \ |
ganlikun | 0:13413ea9a877 | 857 | ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24U) | \ |
ganlikun | 0:13413ea9a877 | 858 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
ganlikun | 0:13413ea9a877 | 859 | ((uint32_t)sAlarm->AlarmMask)); |
ganlikun | 0:13413ea9a877 | 860 | } |
ganlikun | 0:13413ea9a877 | 861 | |
ganlikun | 0:13413ea9a877 | 862 | /* Configure the Alarm A or Alarm B Sub Second registers */ |
ganlikun | 0:13413ea9a877 | 863 | subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask)); |
ganlikun | 0:13413ea9a877 | 864 | |
ganlikun | 0:13413ea9a877 | 865 | /* Disable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 866 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 867 | |
ganlikun | 0:13413ea9a877 | 868 | /* Configure the Alarm register */ |
ganlikun | 0:13413ea9a877 | 869 | if(sAlarm->Alarm == RTC_ALARM_A) |
ganlikun | 0:13413ea9a877 | 870 | { |
ganlikun | 0:13413ea9a877 | 871 | /* Disable the Alarm A interrupt */ |
ganlikun | 0:13413ea9a877 | 872 | __HAL_RTC_ALARMA_DISABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 873 | |
ganlikun | 0:13413ea9a877 | 874 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
ganlikun | 0:13413ea9a877 | 875 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA); |
ganlikun | 0:13413ea9a877 | 876 | |
ganlikun | 0:13413ea9a877 | 877 | /* Get tick */ |
ganlikun | 0:13413ea9a877 | 878 | tickstart = HAL_GetTick(); |
ganlikun | 0:13413ea9a877 | 879 | |
ganlikun | 0:13413ea9a877 | 880 | /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */ |
ganlikun | 0:13413ea9a877 | 881 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET) |
ganlikun | 0:13413ea9a877 | 882 | { |
ganlikun | 0:13413ea9a877 | 883 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
ganlikun | 0:13413ea9a877 | 884 | { |
ganlikun | 0:13413ea9a877 | 885 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 886 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 887 | |
ganlikun | 0:13413ea9a877 | 888 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 889 | |
ganlikun | 0:13413ea9a877 | 890 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 891 | __HAL_UNLOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 892 | |
ganlikun | 0:13413ea9a877 | 893 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 894 | } |
ganlikun | 0:13413ea9a877 | 895 | } |
ganlikun | 0:13413ea9a877 | 896 | |
ganlikun | 0:13413ea9a877 | 897 | hrtc->Instance->ALRMAR = (uint32_t)tmpreg; |
ganlikun | 0:13413ea9a877 | 898 | /* Configure the Alarm A Sub Second register */ |
ganlikun | 0:13413ea9a877 | 899 | hrtc->Instance->ALRMASSR = subsecondtmpreg; |
ganlikun | 0:13413ea9a877 | 900 | /* Configure the Alarm state: Enable Alarm */ |
ganlikun | 0:13413ea9a877 | 901 | __HAL_RTC_ALARMA_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 902 | } |
ganlikun | 0:13413ea9a877 | 903 | else |
ganlikun | 0:13413ea9a877 | 904 | { |
ganlikun | 0:13413ea9a877 | 905 | /* Disable the Alarm B interrupt */ |
ganlikun | 0:13413ea9a877 | 906 | __HAL_RTC_ALARMB_DISABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 907 | |
ganlikun | 0:13413ea9a877 | 908 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
ganlikun | 0:13413ea9a877 | 909 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRB); |
ganlikun | 0:13413ea9a877 | 910 | |
ganlikun | 0:13413ea9a877 | 911 | /* Get tick */ |
ganlikun | 0:13413ea9a877 | 912 | tickstart = HAL_GetTick(); |
ganlikun | 0:13413ea9a877 | 913 | |
ganlikun | 0:13413ea9a877 | 914 | /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */ |
ganlikun | 0:13413ea9a877 | 915 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET) |
ganlikun | 0:13413ea9a877 | 916 | { |
ganlikun | 0:13413ea9a877 | 917 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
ganlikun | 0:13413ea9a877 | 918 | { |
ganlikun | 0:13413ea9a877 | 919 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 920 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 921 | |
ganlikun | 0:13413ea9a877 | 922 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 923 | |
ganlikun | 0:13413ea9a877 | 924 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 925 | __HAL_UNLOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 926 | |
ganlikun | 0:13413ea9a877 | 927 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 928 | } |
ganlikun | 0:13413ea9a877 | 929 | } |
ganlikun | 0:13413ea9a877 | 930 | |
ganlikun | 0:13413ea9a877 | 931 | hrtc->Instance->ALRMBR = (uint32_t)tmpreg; |
ganlikun | 0:13413ea9a877 | 932 | /* Configure the Alarm B Sub Second register */ |
ganlikun | 0:13413ea9a877 | 933 | hrtc->Instance->ALRMBSSR = subsecondtmpreg; |
ganlikun | 0:13413ea9a877 | 934 | /* Configure the Alarm state: Enable Alarm */ |
ganlikun | 0:13413ea9a877 | 935 | __HAL_RTC_ALARMB_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 936 | } |
ganlikun | 0:13413ea9a877 | 937 | |
ganlikun | 0:13413ea9a877 | 938 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 939 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 940 | |
ganlikun | 0:13413ea9a877 | 941 | /* Change RTC state */ |
ganlikun | 0:13413ea9a877 | 942 | hrtc->State = HAL_RTC_STATE_READY; |
ganlikun | 0:13413ea9a877 | 943 | |
ganlikun | 0:13413ea9a877 | 944 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 945 | __HAL_UNLOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 946 | |
ganlikun | 0:13413ea9a877 | 947 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 948 | } |
ganlikun | 0:13413ea9a877 | 949 | |
ganlikun | 0:13413ea9a877 | 950 | /** |
ganlikun | 0:13413ea9a877 | 951 | * @brief Sets the specified RTC Alarm with Interrupt |
ganlikun | 0:13413ea9a877 | 952 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 953 | * the configuration information for RTC. |
ganlikun | 0:13413ea9a877 | 954 | * @param sAlarm: Pointer to Alarm structure |
ganlikun | 0:13413ea9a877 | 955 | * @param Format: Specifies the format of the entered parameters. |
ganlikun | 0:13413ea9a877 | 956 | * This parameter can be one of the following values: |
ganlikun | 0:13413ea9a877 | 957 | * @arg RTC_FORMAT_BIN: Binary data format |
ganlikun | 0:13413ea9a877 | 958 | * @arg RTC_FORMAT_BCD: BCD data format |
ganlikun | 0:13413ea9a877 | 959 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 960 | */ |
ganlikun | 0:13413ea9a877 | 961 | HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format) |
ganlikun | 0:13413ea9a877 | 962 | { |
ganlikun | 0:13413ea9a877 | 963 | uint32_t tmpreg = 0U, subsecondtmpreg = 0U; |
ganlikun | 0:13413ea9a877 | 964 | __IO uint32_t count = RTC_TIMEOUT_VALUE * (SystemCoreClock / 32U / 1000U) ; |
ganlikun | 0:13413ea9a877 | 965 | |
ganlikun | 0:13413ea9a877 | 966 | /* Check the parameters */ |
ganlikun | 0:13413ea9a877 | 967 | assert_param(IS_RTC_FORMAT(Format)); |
ganlikun | 0:13413ea9a877 | 968 | assert_param(IS_RTC_ALARM(sAlarm->Alarm)); |
ganlikun | 0:13413ea9a877 | 969 | assert_param(IS_RTC_ALARM_MASK(sAlarm->AlarmMask)); |
ganlikun | 0:13413ea9a877 | 970 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel)); |
ganlikun | 0:13413ea9a877 | 971 | assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds)); |
ganlikun | 0:13413ea9a877 | 972 | assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask)); |
ganlikun | 0:13413ea9a877 | 973 | |
ganlikun | 0:13413ea9a877 | 974 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 975 | __HAL_LOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 976 | |
ganlikun | 0:13413ea9a877 | 977 | hrtc->State = HAL_RTC_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 978 | |
ganlikun | 0:13413ea9a877 | 979 | if(Format == RTC_FORMAT_BIN) |
ganlikun | 0:13413ea9a877 | 980 | { |
ganlikun | 0:13413ea9a877 | 981 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
ganlikun | 0:13413ea9a877 | 982 | { |
ganlikun | 0:13413ea9a877 | 983 | assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours)); |
ganlikun | 0:13413ea9a877 | 984 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
ganlikun | 0:13413ea9a877 | 985 | } |
ganlikun | 0:13413ea9a877 | 986 | else |
ganlikun | 0:13413ea9a877 | 987 | { |
ganlikun | 0:13413ea9a877 | 988 | sAlarm->AlarmTime.TimeFormat = 0x00U; |
ganlikun | 0:13413ea9a877 | 989 | assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours)); |
ganlikun | 0:13413ea9a877 | 990 | } |
ganlikun | 0:13413ea9a877 | 991 | assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes)); |
ganlikun | 0:13413ea9a877 | 992 | assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds)); |
ganlikun | 0:13413ea9a877 | 993 | |
ganlikun | 0:13413ea9a877 | 994 | if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
ganlikun | 0:13413ea9a877 | 995 | { |
ganlikun | 0:13413ea9a877 | 996 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay)); |
ganlikun | 0:13413ea9a877 | 997 | } |
ganlikun | 0:13413ea9a877 | 998 | else |
ganlikun | 0:13413ea9a877 | 999 | { |
ganlikun | 0:13413ea9a877 | 1000 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay)); |
ganlikun | 0:13413ea9a877 | 1001 | } |
ganlikun | 0:13413ea9a877 | 1002 | tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16U) | \ |
ganlikun | 0:13413ea9a877 | 1003 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8U) | \ |
ganlikun | 0:13413ea9a877 | 1004 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \ |
ganlikun | 0:13413ea9a877 | 1005 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16U) | \ |
ganlikun | 0:13413ea9a877 | 1006 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24U) | \ |
ganlikun | 0:13413ea9a877 | 1007 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
ganlikun | 0:13413ea9a877 | 1008 | ((uint32_t)sAlarm->AlarmMask)); |
ganlikun | 0:13413ea9a877 | 1009 | } |
ganlikun | 0:13413ea9a877 | 1010 | else |
ganlikun | 0:13413ea9a877 | 1011 | { |
ganlikun | 0:13413ea9a877 | 1012 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
ganlikun | 0:13413ea9a877 | 1013 | { |
ganlikun | 0:13413ea9a877 | 1014 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours); |
ganlikun | 0:13413ea9a877 | 1015 | assert_param(IS_RTC_HOUR12(tmpreg)); |
ganlikun | 0:13413ea9a877 | 1016 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
ganlikun | 0:13413ea9a877 | 1017 | } |
ganlikun | 0:13413ea9a877 | 1018 | else |
ganlikun | 0:13413ea9a877 | 1019 | { |
ganlikun | 0:13413ea9a877 | 1020 | sAlarm->AlarmTime.TimeFormat = 0x00U; |
ganlikun | 0:13413ea9a877 | 1021 | assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours))); |
ganlikun | 0:13413ea9a877 | 1022 | } |
ganlikun | 0:13413ea9a877 | 1023 | |
ganlikun | 0:13413ea9a877 | 1024 | assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes))); |
ganlikun | 0:13413ea9a877 | 1025 | assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds))); |
ganlikun | 0:13413ea9a877 | 1026 | |
ganlikun | 0:13413ea9a877 | 1027 | if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
ganlikun | 0:13413ea9a877 | 1028 | { |
ganlikun | 0:13413ea9a877 | 1029 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
ganlikun | 0:13413ea9a877 | 1030 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg)); |
ganlikun | 0:13413ea9a877 | 1031 | } |
ganlikun | 0:13413ea9a877 | 1032 | else |
ganlikun | 0:13413ea9a877 | 1033 | { |
ganlikun | 0:13413ea9a877 | 1034 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
ganlikun | 0:13413ea9a877 | 1035 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg)); |
ganlikun | 0:13413ea9a877 | 1036 | } |
ganlikun | 0:13413ea9a877 | 1037 | tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16U) | \ |
ganlikun | 0:13413ea9a877 | 1038 | ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8U) | \ |
ganlikun | 0:13413ea9a877 | 1039 | ((uint32_t) sAlarm->AlarmTime.Seconds) | \ |
ganlikun | 0:13413ea9a877 | 1040 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16U) | \ |
ganlikun | 0:13413ea9a877 | 1041 | ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24U) | \ |
ganlikun | 0:13413ea9a877 | 1042 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
ganlikun | 0:13413ea9a877 | 1043 | ((uint32_t)sAlarm->AlarmMask)); |
ganlikun | 0:13413ea9a877 | 1044 | } |
ganlikun | 0:13413ea9a877 | 1045 | /* Configure the Alarm A or Alarm B Sub Second registers */ |
ganlikun | 0:13413ea9a877 | 1046 | subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask)); |
ganlikun | 0:13413ea9a877 | 1047 | |
ganlikun | 0:13413ea9a877 | 1048 | /* Disable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 1049 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 1050 | |
ganlikun | 0:13413ea9a877 | 1051 | /* Configure the Alarm register */ |
ganlikun | 0:13413ea9a877 | 1052 | if(sAlarm->Alarm == RTC_ALARM_A) |
ganlikun | 0:13413ea9a877 | 1053 | { |
ganlikun | 0:13413ea9a877 | 1054 | /* Disable the Alarm A interrupt */ |
ganlikun | 0:13413ea9a877 | 1055 | __HAL_RTC_ALARMA_DISABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 1056 | |
ganlikun | 0:13413ea9a877 | 1057 | /* Clear flag alarm A */ |
ganlikun | 0:13413ea9a877 | 1058 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF); |
ganlikun | 0:13413ea9a877 | 1059 | |
ganlikun | 0:13413ea9a877 | 1060 | /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */ |
ganlikun | 0:13413ea9a877 | 1061 | do |
ganlikun | 0:13413ea9a877 | 1062 | { |
ganlikun | 0:13413ea9a877 | 1063 | if (count-- == 0U) |
ganlikun | 0:13413ea9a877 | 1064 | { |
ganlikun | 0:13413ea9a877 | 1065 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 1066 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 1067 | |
ganlikun | 0:13413ea9a877 | 1068 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 1069 | |
ganlikun | 0:13413ea9a877 | 1070 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 1071 | __HAL_UNLOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 1072 | |
ganlikun | 0:13413ea9a877 | 1073 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 1074 | } |
ganlikun | 0:13413ea9a877 | 1075 | } |
ganlikun | 0:13413ea9a877 | 1076 | while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET); |
ganlikun | 0:13413ea9a877 | 1077 | |
ganlikun | 0:13413ea9a877 | 1078 | hrtc->Instance->ALRMAR = (uint32_t)tmpreg; |
ganlikun | 0:13413ea9a877 | 1079 | /* Configure the Alarm A Sub Second register */ |
ganlikun | 0:13413ea9a877 | 1080 | hrtc->Instance->ALRMASSR = subsecondtmpreg; |
ganlikun | 0:13413ea9a877 | 1081 | /* Configure the Alarm state: Enable Alarm */ |
ganlikun | 0:13413ea9a877 | 1082 | __HAL_RTC_ALARMA_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 1083 | /* Configure the Alarm interrupt */ |
ganlikun | 0:13413ea9a877 | 1084 | __HAL_RTC_ALARM_ENABLE_IT(hrtc,RTC_IT_ALRA); |
ganlikun | 0:13413ea9a877 | 1085 | } |
ganlikun | 0:13413ea9a877 | 1086 | else |
ganlikun | 0:13413ea9a877 | 1087 | { |
ganlikun | 0:13413ea9a877 | 1088 | /* Disable the Alarm B interrupt */ |
ganlikun | 0:13413ea9a877 | 1089 | __HAL_RTC_ALARMB_DISABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 1090 | |
ganlikun | 0:13413ea9a877 | 1091 | /* Clear flag alarm B */ |
ganlikun | 0:13413ea9a877 | 1092 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF); |
ganlikun | 0:13413ea9a877 | 1093 | |
ganlikun | 0:13413ea9a877 | 1094 | /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */ |
ganlikun | 0:13413ea9a877 | 1095 | do |
ganlikun | 0:13413ea9a877 | 1096 | { |
ganlikun | 0:13413ea9a877 | 1097 | if (count-- == 0U) |
ganlikun | 0:13413ea9a877 | 1098 | { |
ganlikun | 0:13413ea9a877 | 1099 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 1100 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 1101 | |
ganlikun | 0:13413ea9a877 | 1102 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 1103 | |
ganlikun | 0:13413ea9a877 | 1104 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 1105 | __HAL_UNLOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 1106 | |
ganlikun | 0:13413ea9a877 | 1107 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 1108 | } |
ganlikun | 0:13413ea9a877 | 1109 | } |
ganlikun | 0:13413ea9a877 | 1110 | while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET); |
ganlikun | 0:13413ea9a877 | 1111 | |
ganlikun | 0:13413ea9a877 | 1112 | hrtc->Instance->ALRMBR = (uint32_t)tmpreg; |
ganlikun | 0:13413ea9a877 | 1113 | /* Configure the Alarm B Sub Second register */ |
ganlikun | 0:13413ea9a877 | 1114 | hrtc->Instance->ALRMBSSR = subsecondtmpreg; |
ganlikun | 0:13413ea9a877 | 1115 | /* Configure the Alarm state: Enable Alarm */ |
ganlikun | 0:13413ea9a877 | 1116 | __HAL_RTC_ALARMB_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 1117 | /* Configure the Alarm interrupt */ |
ganlikun | 0:13413ea9a877 | 1118 | __HAL_RTC_ALARM_ENABLE_IT(hrtc, RTC_IT_ALRB); |
ganlikun | 0:13413ea9a877 | 1119 | } |
ganlikun | 0:13413ea9a877 | 1120 | |
ganlikun | 0:13413ea9a877 | 1121 | /* RTC Alarm Interrupt Configuration: EXTI configuration */ |
ganlikun | 0:13413ea9a877 | 1122 | __HAL_RTC_ALARM_EXTI_ENABLE_IT(); |
ganlikun | 0:13413ea9a877 | 1123 | |
ganlikun | 0:13413ea9a877 | 1124 | EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT; |
ganlikun | 0:13413ea9a877 | 1125 | |
ganlikun | 0:13413ea9a877 | 1126 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 1127 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 1128 | |
ganlikun | 0:13413ea9a877 | 1129 | hrtc->State = HAL_RTC_STATE_READY; |
ganlikun | 0:13413ea9a877 | 1130 | |
ganlikun | 0:13413ea9a877 | 1131 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 1132 | __HAL_UNLOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 1133 | |
ganlikun | 0:13413ea9a877 | 1134 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 1135 | } |
ganlikun | 0:13413ea9a877 | 1136 | |
ganlikun | 0:13413ea9a877 | 1137 | /** |
ganlikun | 0:13413ea9a877 | 1138 | * @brief Deactivate the specified RTC Alarm |
ganlikun | 0:13413ea9a877 | 1139 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 1140 | * the configuration information for RTC. |
ganlikun | 0:13413ea9a877 | 1141 | * @param Alarm: Specifies the Alarm. |
ganlikun | 0:13413ea9a877 | 1142 | * This parameter can be one of the following values: |
ganlikun | 0:13413ea9a877 | 1143 | * @arg RTC_ALARM_A: AlarmA |
ganlikun | 0:13413ea9a877 | 1144 | * @arg RTC_ALARM_B: AlarmB |
ganlikun | 0:13413ea9a877 | 1145 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 1146 | */ |
ganlikun | 0:13413ea9a877 | 1147 | HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm) |
ganlikun | 0:13413ea9a877 | 1148 | { |
ganlikun | 0:13413ea9a877 | 1149 | uint32_t tickstart = 0U; |
ganlikun | 0:13413ea9a877 | 1150 | |
ganlikun | 0:13413ea9a877 | 1151 | /* Check the parameters */ |
ganlikun | 0:13413ea9a877 | 1152 | assert_param(IS_RTC_ALARM(Alarm)); |
ganlikun | 0:13413ea9a877 | 1153 | |
ganlikun | 0:13413ea9a877 | 1154 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 1155 | __HAL_LOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 1156 | |
ganlikun | 0:13413ea9a877 | 1157 | hrtc->State = HAL_RTC_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 1158 | |
ganlikun | 0:13413ea9a877 | 1159 | /* Disable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 1160 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 1161 | |
ganlikun | 0:13413ea9a877 | 1162 | if(Alarm == RTC_ALARM_A) |
ganlikun | 0:13413ea9a877 | 1163 | { |
ganlikun | 0:13413ea9a877 | 1164 | /* AlarmA */ |
ganlikun | 0:13413ea9a877 | 1165 | __HAL_RTC_ALARMA_DISABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 1166 | |
ganlikun | 0:13413ea9a877 | 1167 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
ganlikun | 0:13413ea9a877 | 1168 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA); |
ganlikun | 0:13413ea9a877 | 1169 | |
ganlikun | 0:13413ea9a877 | 1170 | /* Get tick */ |
ganlikun | 0:13413ea9a877 | 1171 | tickstart = HAL_GetTick(); |
ganlikun | 0:13413ea9a877 | 1172 | |
ganlikun | 0:13413ea9a877 | 1173 | /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */ |
ganlikun | 0:13413ea9a877 | 1174 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET) |
ganlikun | 0:13413ea9a877 | 1175 | { |
ganlikun | 0:13413ea9a877 | 1176 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
ganlikun | 0:13413ea9a877 | 1177 | { |
ganlikun | 0:13413ea9a877 | 1178 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 1179 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 1180 | |
ganlikun | 0:13413ea9a877 | 1181 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 1182 | |
ganlikun | 0:13413ea9a877 | 1183 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 1184 | __HAL_UNLOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 1185 | |
ganlikun | 0:13413ea9a877 | 1186 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 1187 | } |
ganlikun | 0:13413ea9a877 | 1188 | } |
ganlikun | 0:13413ea9a877 | 1189 | } |
ganlikun | 0:13413ea9a877 | 1190 | else |
ganlikun | 0:13413ea9a877 | 1191 | { |
ganlikun | 0:13413ea9a877 | 1192 | /* AlarmB */ |
ganlikun | 0:13413ea9a877 | 1193 | __HAL_RTC_ALARMB_DISABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 1194 | |
ganlikun | 0:13413ea9a877 | 1195 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
ganlikun | 0:13413ea9a877 | 1196 | __HAL_RTC_ALARM_DISABLE_IT(hrtc,RTC_IT_ALRB); |
ganlikun | 0:13413ea9a877 | 1197 | |
ganlikun | 0:13413ea9a877 | 1198 | /* Get tick */ |
ganlikun | 0:13413ea9a877 | 1199 | tickstart = HAL_GetTick(); |
ganlikun | 0:13413ea9a877 | 1200 | |
ganlikun | 0:13413ea9a877 | 1201 | /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */ |
ganlikun | 0:13413ea9a877 | 1202 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET) |
ganlikun | 0:13413ea9a877 | 1203 | { |
ganlikun | 0:13413ea9a877 | 1204 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
ganlikun | 0:13413ea9a877 | 1205 | { |
ganlikun | 0:13413ea9a877 | 1206 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 1207 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 1208 | |
ganlikun | 0:13413ea9a877 | 1209 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 1210 | |
ganlikun | 0:13413ea9a877 | 1211 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 1212 | __HAL_UNLOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 1213 | |
ganlikun | 0:13413ea9a877 | 1214 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 1215 | } |
ganlikun | 0:13413ea9a877 | 1216 | } |
ganlikun | 0:13413ea9a877 | 1217 | } |
ganlikun | 0:13413ea9a877 | 1218 | /* Enable the write protection for RTC registers */ |
ganlikun | 0:13413ea9a877 | 1219 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
ganlikun | 0:13413ea9a877 | 1220 | |
ganlikun | 0:13413ea9a877 | 1221 | hrtc->State = HAL_RTC_STATE_READY; |
ganlikun | 0:13413ea9a877 | 1222 | |
ganlikun | 0:13413ea9a877 | 1223 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 1224 | __HAL_UNLOCK(hrtc); |
ganlikun | 0:13413ea9a877 | 1225 | |
ganlikun | 0:13413ea9a877 | 1226 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 1227 | } |
ganlikun | 0:13413ea9a877 | 1228 | |
ganlikun | 0:13413ea9a877 | 1229 | /** |
ganlikun | 0:13413ea9a877 | 1230 | * @brief Gets the RTC Alarm value and masks. |
ganlikun | 0:13413ea9a877 | 1231 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 1232 | * the configuration information for RTC. |
ganlikun | 0:13413ea9a877 | 1233 | * @param sAlarm: Pointer to Date structure |
ganlikun | 0:13413ea9a877 | 1234 | * @param Alarm: Specifies the Alarm. |
ganlikun | 0:13413ea9a877 | 1235 | * This parameter can be one of the following values: |
ganlikun | 0:13413ea9a877 | 1236 | * @arg RTC_ALARM_A: AlarmA |
ganlikun | 0:13413ea9a877 | 1237 | * @arg RTC_ALARM_B: AlarmB |
ganlikun | 0:13413ea9a877 | 1238 | * @param Format: Specifies the format of the entered parameters. |
ganlikun | 0:13413ea9a877 | 1239 | * This parameter can be one of the following values: |
ganlikun | 0:13413ea9a877 | 1240 | * @arg RTC_FORMAT_BIN: Binary data format |
ganlikun | 0:13413ea9a877 | 1241 | * @arg RTC_FORMAT_BCD: BCD data format |
ganlikun | 0:13413ea9a877 | 1242 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 1243 | */ |
ganlikun | 0:13413ea9a877 | 1244 | HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format) |
ganlikun | 0:13413ea9a877 | 1245 | { |
ganlikun | 0:13413ea9a877 | 1246 | uint32_t tmpreg = 0U, subsecondtmpreg = 0U; |
ganlikun | 0:13413ea9a877 | 1247 | |
ganlikun | 0:13413ea9a877 | 1248 | /* Check the parameters */ |
ganlikun | 0:13413ea9a877 | 1249 | assert_param(IS_RTC_FORMAT(Format)); |
ganlikun | 0:13413ea9a877 | 1250 | assert_param(IS_RTC_ALARM(Alarm)); |
ganlikun | 0:13413ea9a877 | 1251 | |
ganlikun | 0:13413ea9a877 | 1252 | if(Alarm == RTC_ALARM_A) |
ganlikun | 0:13413ea9a877 | 1253 | { |
ganlikun | 0:13413ea9a877 | 1254 | /* AlarmA */ |
ganlikun | 0:13413ea9a877 | 1255 | sAlarm->Alarm = RTC_ALARM_A; |
ganlikun | 0:13413ea9a877 | 1256 | |
ganlikun | 0:13413ea9a877 | 1257 | tmpreg = (uint32_t)(hrtc->Instance->ALRMAR); |
ganlikun | 0:13413ea9a877 | 1258 | subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMASSR ) & RTC_ALRMASSR_SS); |
ganlikun | 0:13413ea9a877 | 1259 | } |
ganlikun | 0:13413ea9a877 | 1260 | else |
ganlikun | 0:13413ea9a877 | 1261 | { |
ganlikun | 0:13413ea9a877 | 1262 | sAlarm->Alarm = RTC_ALARM_B; |
ganlikun | 0:13413ea9a877 | 1263 | |
ganlikun | 0:13413ea9a877 | 1264 | tmpreg = (uint32_t)(hrtc->Instance->ALRMBR); |
ganlikun | 0:13413ea9a877 | 1265 | subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMBSSR) & RTC_ALRMBSSR_SS); |
ganlikun | 0:13413ea9a877 | 1266 | } |
ganlikun | 0:13413ea9a877 | 1267 | |
ganlikun | 0:13413ea9a877 | 1268 | /* Fill the structure with the read parameters */ |
ganlikun | 0:13413ea9a877 | 1269 | sAlarm->AlarmTime.Hours = (uint32_t)((tmpreg & (RTC_ALRMAR_HT | RTC_ALRMAR_HU)) >> 16U); |
ganlikun | 0:13413ea9a877 | 1270 | sAlarm->AlarmTime.Minutes = (uint32_t)((tmpreg & (RTC_ALRMAR_MNT | RTC_ALRMAR_MNU)) >> 8U); |
ganlikun | 0:13413ea9a877 | 1271 | sAlarm->AlarmTime.Seconds = (uint32_t)(tmpreg & (RTC_ALRMAR_ST | RTC_ALRMAR_SU)); |
ganlikun | 0:13413ea9a877 | 1272 | sAlarm->AlarmTime.TimeFormat = (uint32_t)((tmpreg & RTC_ALRMAR_PM) >> 16U); |
ganlikun | 0:13413ea9a877 | 1273 | sAlarm->AlarmTime.SubSeconds = (uint32_t) subsecondtmpreg; |
ganlikun | 0:13413ea9a877 | 1274 | sAlarm->AlarmDateWeekDay = (uint32_t)((tmpreg & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> 24U); |
ganlikun | 0:13413ea9a877 | 1275 | sAlarm->AlarmDateWeekDaySel = (uint32_t)(tmpreg & RTC_ALRMAR_WDSEL); |
ganlikun | 0:13413ea9a877 | 1276 | sAlarm->AlarmMask = (uint32_t)(tmpreg & RTC_ALARMMASK_ALL); |
ganlikun | 0:13413ea9a877 | 1277 | |
ganlikun | 0:13413ea9a877 | 1278 | if(Format == RTC_FORMAT_BIN) |
ganlikun | 0:13413ea9a877 | 1279 | { |
ganlikun | 0:13413ea9a877 | 1280 | sAlarm->AlarmTime.Hours = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours); |
ganlikun | 0:13413ea9a877 | 1281 | sAlarm->AlarmTime.Minutes = RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes); |
ganlikun | 0:13413ea9a877 | 1282 | sAlarm->AlarmTime.Seconds = RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds); |
ganlikun | 0:13413ea9a877 | 1283 | sAlarm->AlarmDateWeekDay = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
ganlikun | 0:13413ea9a877 | 1284 | } |
ganlikun | 0:13413ea9a877 | 1285 | |
ganlikun | 0:13413ea9a877 | 1286 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 1287 | } |
ganlikun | 0:13413ea9a877 | 1288 | |
ganlikun | 0:13413ea9a877 | 1289 | /** |
ganlikun | 0:13413ea9a877 | 1290 | * @brief This function handles Alarm interrupt request. |
ganlikun | 0:13413ea9a877 | 1291 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 1292 | * the configuration information for RTC. |
ganlikun | 0:13413ea9a877 | 1293 | * @retval None |
ganlikun | 0:13413ea9a877 | 1294 | */ |
ganlikun | 0:13413ea9a877 | 1295 | void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef* hrtc) |
ganlikun | 0:13413ea9a877 | 1296 | { |
ganlikun | 0:13413ea9a877 | 1297 | if(__HAL_RTC_ALARM_GET_IT(hrtc, RTC_IT_ALRA)) |
ganlikun | 0:13413ea9a877 | 1298 | { |
ganlikun | 0:13413ea9a877 | 1299 | /* Get the status of the Interrupt */ |
ganlikun | 0:13413ea9a877 | 1300 | if((uint32_t)(hrtc->Instance->CR & RTC_IT_ALRA) != (uint32_t)RESET) |
ganlikun | 0:13413ea9a877 | 1301 | { |
ganlikun | 0:13413ea9a877 | 1302 | /* AlarmA callback */ |
ganlikun | 0:13413ea9a877 | 1303 | HAL_RTC_AlarmAEventCallback(hrtc); |
ganlikun | 0:13413ea9a877 | 1304 | |
ganlikun | 0:13413ea9a877 | 1305 | /* Clear the Alarm interrupt pending bit */ |
ganlikun | 0:13413ea9a877 | 1306 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc,RTC_FLAG_ALRAF); |
ganlikun | 0:13413ea9a877 | 1307 | } |
ganlikun | 0:13413ea9a877 | 1308 | } |
ganlikun | 0:13413ea9a877 | 1309 | |
ganlikun | 0:13413ea9a877 | 1310 | if(__HAL_RTC_ALARM_GET_IT(hrtc, RTC_IT_ALRB)) |
ganlikun | 0:13413ea9a877 | 1311 | { |
ganlikun | 0:13413ea9a877 | 1312 | /* Get the status of the Interrupt */ |
ganlikun | 0:13413ea9a877 | 1313 | if((uint32_t)(hrtc->Instance->CR & RTC_IT_ALRB) != (uint32_t)RESET) |
ganlikun | 0:13413ea9a877 | 1314 | { |
ganlikun | 0:13413ea9a877 | 1315 | /* AlarmB callback */ |
ganlikun | 0:13413ea9a877 | 1316 | HAL_RTCEx_AlarmBEventCallback(hrtc); |
ganlikun | 0:13413ea9a877 | 1317 | |
ganlikun | 0:13413ea9a877 | 1318 | /* Clear the Alarm interrupt pending bit */ |
ganlikun | 0:13413ea9a877 | 1319 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc,RTC_FLAG_ALRBF); |
ganlikun | 0:13413ea9a877 | 1320 | } |
ganlikun | 0:13413ea9a877 | 1321 | } |
ganlikun | 0:13413ea9a877 | 1322 | |
ganlikun | 0:13413ea9a877 | 1323 | /* Clear the EXTI's line Flag for RTC Alarm */ |
ganlikun | 0:13413ea9a877 | 1324 | __HAL_RTC_ALARM_EXTI_CLEAR_FLAG(); |
ganlikun | 0:13413ea9a877 | 1325 | |
ganlikun | 0:13413ea9a877 | 1326 | /* Change RTC state */ |
ganlikun | 0:13413ea9a877 | 1327 | hrtc->State = HAL_RTC_STATE_READY; |
ganlikun | 0:13413ea9a877 | 1328 | } |
ganlikun | 0:13413ea9a877 | 1329 | |
ganlikun | 0:13413ea9a877 | 1330 | /** |
ganlikun | 0:13413ea9a877 | 1331 | * @brief Alarm A callback. |
ganlikun | 0:13413ea9a877 | 1332 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 1333 | * the configuration information for RTC. |
ganlikun | 0:13413ea9a877 | 1334 | * @retval None |
ganlikun | 0:13413ea9a877 | 1335 | */ |
ganlikun | 0:13413ea9a877 | 1336 | __weak void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) |
ganlikun | 0:13413ea9a877 | 1337 | { |
ganlikun | 0:13413ea9a877 | 1338 | /* Prevent unused argument(s) compilation warning */ |
ganlikun | 0:13413ea9a877 | 1339 | UNUSED(hrtc); |
ganlikun | 0:13413ea9a877 | 1340 | /* NOTE : This function Should not be modified, when the callback is needed, |
ganlikun | 0:13413ea9a877 | 1341 | the HAL_RTC_AlarmAEventCallback could be implemented in the user file |
ganlikun | 0:13413ea9a877 | 1342 | */ |
ganlikun | 0:13413ea9a877 | 1343 | } |
ganlikun | 0:13413ea9a877 | 1344 | |
ganlikun | 0:13413ea9a877 | 1345 | /** |
ganlikun | 0:13413ea9a877 | 1346 | * @brief This function handles AlarmA Polling request. |
ganlikun | 0:13413ea9a877 | 1347 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 1348 | * the configuration information for RTC. |
ganlikun | 0:13413ea9a877 | 1349 | * @param Timeout: Timeout duration |
ganlikun | 0:13413ea9a877 | 1350 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 1351 | */ |
ganlikun | 0:13413ea9a877 | 1352 | HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
ganlikun | 0:13413ea9a877 | 1353 | { |
ganlikun | 0:13413ea9a877 | 1354 | uint32_t tickstart = 0U; |
ganlikun | 0:13413ea9a877 | 1355 | |
ganlikun | 0:13413ea9a877 | 1356 | /* Get tick */ |
ganlikun | 0:13413ea9a877 | 1357 | tickstart = HAL_GetTick(); |
ganlikun | 0:13413ea9a877 | 1358 | |
ganlikun | 0:13413ea9a877 | 1359 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAF) == RESET) |
ganlikun | 0:13413ea9a877 | 1360 | { |
ganlikun | 0:13413ea9a877 | 1361 | if(Timeout != HAL_MAX_DELAY) |
ganlikun | 0:13413ea9a877 | 1362 | { |
ganlikun | 0:13413ea9a877 | 1363 | if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout)) |
ganlikun | 0:13413ea9a877 | 1364 | { |
ganlikun | 0:13413ea9a877 | 1365 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 1366 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 1367 | } |
ganlikun | 0:13413ea9a877 | 1368 | } |
ganlikun | 0:13413ea9a877 | 1369 | } |
ganlikun | 0:13413ea9a877 | 1370 | |
ganlikun | 0:13413ea9a877 | 1371 | /* Clear the Alarm interrupt pending bit */ |
ganlikun | 0:13413ea9a877 | 1372 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF); |
ganlikun | 0:13413ea9a877 | 1373 | |
ganlikun | 0:13413ea9a877 | 1374 | /* Change RTC state */ |
ganlikun | 0:13413ea9a877 | 1375 | hrtc->State = HAL_RTC_STATE_READY; |
ganlikun | 0:13413ea9a877 | 1376 | |
ganlikun | 0:13413ea9a877 | 1377 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 1378 | } |
ganlikun | 0:13413ea9a877 | 1379 | |
ganlikun | 0:13413ea9a877 | 1380 | /** |
ganlikun | 0:13413ea9a877 | 1381 | * @} |
ganlikun | 0:13413ea9a877 | 1382 | */ |
ganlikun | 0:13413ea9a877 | 1383 | |
ganlikun | 0:13413ea9a877 | 1384 | /** @defgroup RTC_Exported_Functions_Group4 Peripheral Control functions |
ganlikun | 0:13413ea9a877 | 1385 | * @brief Peripheral Control functions |
ganlikun | 0:13413ea9a877 | 1386 | * |
ganlikun | 0:13413ea9a877 | 1387 | @verbatim |
ganlikun | 0:13413ea9a877 | 1388 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 1389 | ##### Peripheral Control functions ##### |
ganlikun | 0:13413ea9a877 | 1390 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 1391 | [..] |
ganlikun | 0:13413ea9a877 | 1392 | This subsection provides functions allowing to |
ganlikun | 0:13413ea9a877 | 1393 | (+) Wait for RTC Time and Date Synchronization |
ganlikun | 0:13413ea9a877 | 1394 | |
ganlikun | 0:13413ea9a877 | 1395 | @endverbatim |
ganlikun | 0:13413ea9a877 | 1396 | * @{ |
ganlikun | 0:13413ea9a877 | 1397 | */ |
ganlikun | 0:13413ea9a877 | 1398 | |
ganlikun | 0:13413ea9a877 | 1399 | /** |
ganlikun | 0:13413ea9a877 | 1400 | * @brief Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are |
ganlikun | 0:13413ea9a877 | 1401 | * synchronized with RTC APB clock. |
ganlikun | 0:13413ea9a877 | 1402 | * @note The RTC Resynchronization mode is write protected, use the |
ganlikun | 0:13413ea9a877 | 1403 | * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function. |
ganlikun | 0:13413ea9a877 | 1404 | * @note To read the calendar through the shadow registers after Calendar |
ganlikun | 0:13413ea9a877 | 1405 | * initialization, calendar update or after wake-up from low power modes |
ganlikun | 0:13413ea9a877 | 1406 | * the software must first clear the RSF flag. |
ganlikun | 0:13413ea9a877 | 1407 | * The software must then wait until it is set again before reading |
ganlikun | 0:13413ea9a877 | 1408 | * the calendar, which means that the calendar registers have been |
ganlikun | 0:13413ea9a877 | 1409 | * correctly copied into the RTC_TR and RTC_DR shadow registers. |
ganlikun | 0:13413ea9a877 | 1410 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 1411 | * the configuration information for RTC. |
ganlikun | 0:13413ea9a877 | 1412 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 1413 | */ |
ganlikun | 0:13413ea9a877 | 1414 | HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc) |
ganlikun | 0:13413ea9a877 | 1415 | { |
ganlikun | 0:13413ea9a877 | 1416 | uint32_t tickstart = 0U; |
ganlikun | 0:13413ea9a877 | 1417 | |
ganlikun | 0:13413ea9a877 | 1418 | /* Clear RSF flag */ |
ganlikun | 0:13413ea9a877 | 1419 | hrtc->Instance->ISR &= (uint32_t)RTC_RSF_MASK; |
ganlikun | 0:13413ea9a877 | 1420 | |
ganlikun | 0:13413ea9a877 | 1421 | /* Get tick */ |
ganlikun | 0:13413ea9a877 | 1422 | tickstart = HAL_GetTick(); |
ganlikun | 0:13413ea9a877 | 1423 | |
ganlikun | 0:13413ea9a877 | 1424 | /* Wait the registers to be synchronised */ |
ganlikun | 0:13413ea9a877 | 1425 | while((hrtc->Instance->ISR & RTC_ISR_RSF) == (uint32_t)RESET) |
ganlikun | 0:13413ea9a877 | 1426 | { |
ganlikun | 0:13413ea9a877 | 1427 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
ganlikun | 0:13413ea9a877 | 1428 | { |
ganlikun | 0:13413ea9a877 | 1429 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 1430 | } |
ganlikun | 0:13413ea9a877 | 1431 | } |
ganlikun | 0:13413ea9a877 | 1432 | |
ganlikun | 0:13413ea9a877 | 1433 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 1434 | } |
ganlikun | 0:13413ea9a877 | 1435 | |
ganlikun | 0:13413ea9a877 | 1436 | /** |
ganlikun | 0:13413ea9a877 | 1437 | * @} |
ganlikun | 0:13413ea9a877 | 1438 | */ |
ganlikun | 0:13413ea9a877 | 1439 | |
ganlikun | 0:13413ea9a877 | 1440 | /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions |
ganlikun | 0:13413ea9a877 | 1441 | * @brief Peripheral State functions |
ganlikun | 0:13413ea9a877 | 1442 | * |
ganlikun | 0:13413ea9a877 | 1443 | @verbatim |
ganlikun | 0:13413ea9a877 | 1444 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 1445 | ##### Peripheral State functions ##### |
ganlikun | 0:13413ea9a877 | 1446 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 1447 | [..] |
ganlikun | 0:13413ea9a877 | 1448 | This subsection provides functions allowing to |
ganlikun | 0:13413ea9a877 | 1449 | (+) Get RTC state |
ganlikun | 0:13413ea9a877 | 1450 | |
ganlikun | 0:13413ea9a877 | 1451 | @endverbatim |
ganlikun | 0:13413ea9a877 | 1452 | * @{ |
ganlikun | 0:13413ea9a877 | 1453 | */ |
ganlikun | 0:13413ea9a877 | 1454 | /** |
ganlikun | 0:13413ea9a877 | 1455 | * @brief Returns the RTC state. |
ganlikun | 0:13413ea9a877 | 1456 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 1457 | * the configuration information for RTC. |
ganlikun | 0:13413ea9a877 | 1458 | * @retval HAL state |
ganlikun | 0:13413ea9a877 | 1459 | */ |
ganlikun | 0:13413ea9a877 | 1460 | HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef* hrtc) |
ganlikun | 0:13413ea9a877 | 1461 | { |
ganlikun | 0:13413ea9a877 | 1462 | return hrtc->State; |
ganlikun | 0:13413ea9a877 | 1463 | } |
ganlikun | 0:13413ea9a877 | 1464 | |
ganlikun | 0:13413ea9a877 | 1465 | /** |
ganlikun | 0:13413ea9a877 | 1466 | * @} |
ganlikun | 0:13413ea9a877 | 1467 | */ |
ganlikun | 0:13413ea9a877 | 1468 | |
ganlikun | 0:13413ea9a877 | 1469 | /** |
ganlikun | 0:13413ea9a877 | 1470 | * @brief Enters the RTC Initialization mode. |
ganlikun | 0:13413ea9a877 | 1471 | * @note The RTC Initialization mode is write protected, use the |
ganlikun | 0:13413ea9a877 | 1472 | * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function. |
ganlikun | 0:13413ea9a877 | 1473 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 1474 | * the configuration information for RTC. |
ganlikun | 0:13413ea9a877 | 1475 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 1476 | */ |
ganlikun | 0:13413ea9a877 | 1477 | HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef* hrtc) |
ganlikun | 0:13413ea9a877 | 1478 | { |
ganlikun | 0:13413ea9a877 | 1479 | uint32_t tickstart = 0U; |
ganlikun | 0:13413ea9a877 | 1480 | |
ganlikun | 0:13413ea9a877 | 1481 | /* Check if the Initialization mode is set */ |
ganlikun | 0:13413ea9a877 | 1482 | if((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET) |
ganlikun | 0:13413ea9a877 | 1483 | { |
ganlikun | 0:13413ea9a877 | 1484 | /* Set the Initialization mode */ |
ganlikun | 0:13413ea9a877 | 1485 | hrtc->Instance->ISR = (uint32_t)RTC_INIT_MASK; |
ganlikun | 0:13413ea9a877 | 1486 | |
ganlikun | 0:13413ea9a877 | 1487 | /* Get tick */ |
ganlikun | 0:13413ea9a877 | 1488 | tickstart = HAL_GetTick(); |
ganlikun | 0:13413ea9a877 | 1489 | |
ganlikun | 0:13413ea9a877 | 1490 | /* Wait till RTC is in INIT state and if Time out is reached exit */ |
ganlikun | 0:13413ea9a877 | 1491 | while((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET) |
ganlikun | 0:13413ea9a877 | 1492 | { |
ganlikun | 0:13413ea9a877 | 1493 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
ganlikun | 0:13413ea9a877 | 1494 | { |
ganlikun | 0:13413ea9a877 | 1495 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 1496 | } |
ganlikun | 0:13413ea9a877 | 1497 | } |
ganlikun | 0:13413ea9a877 | 1498 | } |
ganlikun | 0:13413ea9a877 | 1499 | |
ganlikun | 0:13413ea9a877 | 1500 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 1501 | } |
ganlikun | 0:13413ea9a877 | 1502 | |
ganlikun | 0:13413ea9a877 | 1503 | |
ganlikun | 0:13413ea9a877 | 1504 | /** |
ganlikun | 0:13413ea9a877 | 1505 | * @brief Converts a 2 digit decimal to BCD format. |
ganlikun | 0:13413ea9a877 | 1506 | * @param Value: Byte to be converted |
ganlikun | 0:13413ea9a877 | 1507 | * @retval Converted byte |
ganlikun | 0:13413ea9a877 | 1508 | */ |
ganlikun | 0:13413ea9a877 | 1509 | uint8_t RTC_ByteToBcd2(uint8_t Value) |
ganlikun | 0:13413ea9a877 | 1510 | { |
ganlikun | 0:13413ea9a877 | 1511 | uint32_t bcdhigh = 0U; |
ganlikun | 0:13413ea9a877 | 1512 | |
ganlikun | 0:13413ea9a877 | 1513 | while(Value >= 10U) |
ganlikun | 0:13413ea9a877 | 1514 | { |
ganlikun | 0:13413ea9a877 | 1515 | bcdhigh++; |
ganlikun | 0:13413ea9a877 | 1516 | Value -= 10U; |
ganlikun | 0:13413ea9a877 | 1517 | } |
ganlikun | 0:13413ea9a877 | 1518 | |
ganlikun | 0:13413ea9a877 | 1519 | return ((uint8_t)(bcdhigh << 4U) | Value); |
ganlikun | 0:13413ea9a877 | 1520 | } |
ganlikun | 0:13413ea9a877 | 1521 | |
ganlikun | 0:13413ea9a877 | 1522 | /** |
ganlikun | 0:13413ea9a877 | 1523 | * @brief Converts from 2 digit BCD to Binary. |
ganlikun | 0:13413ea9a877 | 1524 | * @param Value: BCD value to be converted |
ganlikun | 0:13413ea9a877 | 1525 | * @retval Converted word |
ganlikun | 0:13413ea9a877 | 1526 | */ |
ganlikun | 0:13413ea9a877 | 1527 | uint8_t RTC_Bcd2ToByte(uint8_t Value) |
ganlikun | 0:13413ea9a877 | 1528 | { |
ganlikun | 0:13413ea9a877 | 1529 | uint32_t tmp = 0U; |
ganlikun | 0:13413ea9a877 | 1530 | tmp = ((uint8_t)(Value & (uint8_t)0xF0) >> (uint8_t)0x4) * 10; |
ganlikun | 0:13413ea9a877 | 1531 | return (tmp + (Value & (uint8_t)0x0F)); |
ganlikun | 0:13413ea9a877 | 1532 | } |
ganlikun | 0:13413ea9a877 | 1533 | |
ganlikun | 0:13413ea9a877 | 1534 | /** |
ganlikun | 0:13413ea9a877 | 1535 | * @} |
ganlikun | 0:13413ea9a877 | 1536 | */ |
ganlikun | 0:13413ea9a877 | 1537 | |
ganlikun | 0:13413ea9a877 | 1538 | #endif /* HAL_RTC_MODULE_ENABLED */ |
ganlikun | 0:13413ea9a877 | 1539 | /** |
ganlikun | 0:13413ea9a877 | 1540 | * @} |
ganlikun | 0:13413ea9a877 | 1541 | */ |
ganlikun | 0:13413ea9a877 | 1542 | |
ganlikun | 0:13413ea9a877 | 1543 | /** |
ganlikun | 0:13413ea9a877 | 1544 | * @} |
ganlikun | 0:13413ea9a877 | 1545 | */ |
ganlikun | 0:13413ea9a877 | 1546 | |
ganlikun | 0:13413ea9a877 | 1547 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
ganlikun | 0:13413ea9a877 | 1548 |