annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_rtc_ex.c @ 38:5f11787b4f42

include in ostc4 repository
author heinrichsweikamp
date Sat, 28 Apr 2018 11:52:34 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file stm32f4xx_hal_rtc_ex.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author MCD Application Team
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V1.2.0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 26-December-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief RTC HAL module driver.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * This file provides firmware functions to manage the following
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * functionalities of the Real Time Clock (RTC) Extension peripheral:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * + RTC Time Stamp functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 * + RTC Tamper functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 * + RTC Wake-up functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 * + Extension Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 * + Extension RTC features functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 ##### How to use this driver #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 (+) Enable the RTC domain access.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 format using the HAL_RTC_Init() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 *** RTC Wake-up configuration ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 ================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 (+) To configure the RTC Wake-up Clock source and Counter use the HAL_RTC_SetWakeUpTimer()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 function. You can also configure the RTC Wake-up timer in interrupt mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 using the HAL_RTC_SetWakeUpTimer_IT() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 (+) To read the RTC Wake-up Counter register, use the HAL_RTC_GetWakeUpTimer()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 *** TimeStamp configuration ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 ===============================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 (+) Configure the RTC_AFx trigger and enable the RTC TimeStamp using the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 HAL_RTC_SetTimeStamp() function. You can also configure the RTC TimeStamp with
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 interrupt mode using the HAL_RTC_SetTimeStamp_IT() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTC_GetTimeStamp()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 (+) The TIMESTAMP alternate function can be mapped either to RTC_AF1 (PC13)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 or RTC_AF2 (PI8) depending on the value of TSINSEL bit in
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 RTC_TAFCR register. The corresponding pin is also selected by HAL_RTC_SetTimeStamp()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 or HAL_RTC_SetTimeStamp_IT() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 *** Tamper configuration ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 ============================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 (+) Enable the RTC Tamper and configure the Tamper filter count, trigger Edge
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 or Level according to the Tamper filter (if equal to 0 Edge else Level)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 value, sampling frequency, precharge or discharge and Pull-UP using the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 HAL_RTC_SetTamper() function. You can configure RTC Tamper in interrupt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 mode using HAL_RTC_SetTamper_IT() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 (+) The TAMPER1 alternate function can be mapped either to RTC_AF1 (PC13)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 or RTC_AF2 (PI8) depending on the value of TAMP1INSEL bit in
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 RTC_TAFCR register. The corresponding pin is also selected by HAL_RTC_SetTamper()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 or HAL_RTC_SetTamper_IT() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 *** Backup Data Registers configuration ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 ===========================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 (+) To write to the RTC Backup Data registers, use the HAL_RTC_BKUPWrite()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 (+) To read the RTC Backup Data registers, use the HAL_RTC_BKUPRead()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 * Redistribution and use in source and binary forms, with or without modification,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 * are permitted provided that the following conditions are met:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 * 1. Redistributions of source code must retain the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 * this list of conditions and the following disclaimer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 * 2. Redistributions in binary form must reproduce the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 * this list of conditions and the following disclaimer in the documentation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 * and/or other materials provided with the distribution.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 * 3. Neither the name of STMicroelectronics nor the names of its contributors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 * may be used to endorse or promote products derived from this software
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 * without specific prior written permission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 /** @addtogroup STM32F4xx_HAL_Driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 /** @defgroup RTCEx RTCEx
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 * @brief RTC HAL module driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 #ifdef HAL_RTC_MODULE_ENABLED
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 /* Private typedef -----------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 /* Private define ------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 /* Private macro -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 /* Private function prototypes -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 /* Private functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 /** @defgroup RTCEx_Exported_Functions_Group1 RTC TimeStamp and Tamper functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 * @brief RTC TimeStamp and Tamper functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 ##### RTC TimeStamp and Tamper functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 [..] This section provides functions allowing to configure TimeStamp feature
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 * @brief Sets TimeStamp.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 * @note This API must be called before enabling the TimeStamp feature.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 * activated.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 * rising edge of the related pin.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 * falling edge of the related pin.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 * @param RTC_TimeStampPin: specifies the RTC TimeStamp Pin.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 * @arg RTC_TIMESTAMPPIN_PC13: PC13 is selected as RTC TimeStamp Pin.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 * @arg RTC_TIMESTAMPPIN_PI8: PI8 is selected as RTC TimeStamp Pin.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 /* Get the RTC_CR register and clear the bits to be configured */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 tmpreg|= TimeStampEdge;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 hrtc->Instance->TAFCR &= (uint32_t)~RTC_TAFCR_TSINSEL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 hrtc->Instance->TAFCR |= (uint32_t)(RTC_TimeStampPin);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 /* Configure the Time Stamp TSEDGE and Enable bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 hrtc->Instance->CR = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 __HAL_RTC_TIMESTAMP_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 * @brief Sets TimeStamp with Interrupt.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 * @note This API must be called before enabling the TimeStamp feature.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 * activated.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 * rising edge of the related pin.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 * falling edge of the related pin.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 * @param RTC_TimeStampPin: Specifies the RTC TimeStamp Pin.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 * @arg RTC_TIMESTAMPPIN_PC13: PC13 is selected as RTC TimeStamp Pin.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 * @arg RTC_TIMESTAMPPIN_PI8: PI8 is selected as RTC TimeStamp Pin.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 /* Get the RTC_CR register and clear the bits to be configured */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 tmpreg |= TimeStampEdge;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 /* Configure the Time Stamp TSEDGE and Enable bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 hrtc->Instance->CR = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 hrtc->Instance->TAFCR &= (uint32_t)~RTC_TAFCR_TSINSEL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 hrtc->Instance->TAFCR |= (uint32_t)(RTC_TimeStampPin);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 __HAL_RTC_TIMESTAMP_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 /* Enable IT timestamp */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 __HAL_RTC_TIMESTAMP_ENABLE_IT(hrtc,RTC_IT_TS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 /* RTC timestamp Interrupt Configuration: EXTI configuration */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 * @brief Deactivates TimeStamp.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 /* In case of interrupt mode is used, the interrupt source must disabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 __HAL_RTC_TIMESTAMP_DISABLE_IT(hrtc, RTC_IT_TS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 /* Get the RTC_CR register and clear the bits to be configured */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 /* Configure the Time Stamp TSEDGE and Enable bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 hrtc->Instance->CR = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 * @brief Gets the RTC TimeStamp value.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 * @param sTimeStamp: Pointer to Time structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 * @param sTimeStampDate: Pointer to Date structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 * @param Format: specifies the format of the entered parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 * RTC_FORMAT_BIN: Binary data format
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 * RTC_FORMAT_BCD: BCD data format
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef* sTimeStamp, RTC_DateTypeDef* sTimeStampDate, uint32_t Format)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 uint32_t tmptime = 0, tmpdate = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 assert_param(IS_RTC_FORMAT(Format));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 /* Get the TimeStamp time and date registers values */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 tmptime = (uint32_t)(hrtc->Instance->TSTR & RTC_TR_RESERVED_MASK);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 tmpdate = (uint32_t)(hrtc->Instance->TSDR & RTC_DR_RESERVED_MASK);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 /* Fill the Time structure fields with the read parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 sTimeStamp->Hours = (uint8_t)((tmptime & (RTC_TR_HT | RTC_TR_HU)) >> 16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 sTimeStamp->Minutes = (uint8_t)((tmptime & (RTC_TR_MNT | RTC_TR_MNU)) >> 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 sTimeStamp->Seconds = (uint8_t)(tmptime & (RTC_TR_ST | RTC_TR_SU));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 sTimeStamp->TimeFormat = (uint8_t)((tmptime & (RTC_TR_PM)) >> 16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 sTimeStamp->SubSeconds = (uint32_t) hrtc->Instance->TSSSR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 /* Fill the Date structure fields with the read parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 sTimeStampDate->Year = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 sTimeStampDate->Month = (uint8_t)((tmpdate & (RTC_DR_MT | RTC_DR_MU)) >> 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 sTimeStampDate->Date = (uint8_t)(tmpdate & (RTC_DR_DT | RTC_DR_DU));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 sTimeStampDate->WeekDay = (uint8_t)((tmpdate & (RTC_DR_WDU)) >> 13);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 /* Check the input parameters format */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 if(Format == RTC_FORMAT_BIN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 /* Convert the TimeStamp structure parameters to Binary format */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 sTimeStamp->Hours = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Hours);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 sTimeStamp->Minutes = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Minutes);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 sTimeStamp->Seconds = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Seconds);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 /* Convert the DateTimeStamp structure parameters to Binary format */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 sTimeStampDate->Month = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Month);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 sTimeStampDate->Date = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Date);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 sTimeStampDate->WeekDay = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->WeekDay);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 /* Clear the TIMESTAMP Flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 * @brief Sets Tamper
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 * @note By calling this API we disable the tamper interrupt for all tampers.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 * @param sTamper: Pointer to Tamper Structure.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 assert_param(IS_RTC_TAMPER(sTamper->Tamper));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 assert_param(IS_RTC_TAMPER_PIN(sTamper->PinSelection));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 if(sTamper->Trigger != RTC_TAMPERTRIGGER_RISINGEDGE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 sTamper->Trigger = (uint32_t)(sTamper->Tamper << 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->PinSelection | (uint32_t)sTamper->Trigger |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 (uint32_t)sTamper->Filter | (uint32_t)sTamper->SamplingFrequency | (uint32_t)sTamper->PrechargeDuration |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | (uint32_t)RTC_TAFCR_TAMPTS |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 (uint32_t)RTC_TAFCR_TAMPFREQ | (uint32_t)RTC_TAFCR_TAMPFLT | (uint32_t)RTC_TAFCR_TAMPPRCH |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 (uint32_t)RTC_TAFCR_TAMPPUDIS | (uint32_t)RTC_TAFCR_TAMPINSEL | (uint32_t)RTC_TAFCR_TAMPIE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 hrtc->Instance->TAFCR |= tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 * @brief Sets Tamper with interrupt.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 * @note By calling this API we force the tamper interrupt for all tampers.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 * @param sTamper: Pointer to RTC Tamper.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 assert_param(IS_RTC_TAMPER(sTamper->Tamper));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 assert_param(IS_RTC_TAMPER_PIN(sTamper->PinSelection));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 /* Configure the tamper trigger */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 if(sTamper->Trigger != RTC_TAMPERTRIGGER_RISINGEDGE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 sTamper->Trigger = (uint32_t)(sTamper->Tamper << 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->PinSelection | (uint32_t)sTamper->Trigger |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 (uint32_t)sTamper->Filter | (uint32_t)sTamper->SamplingFrequency | (uint32_t)sTamper->PrechargeDuration |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | (uint32_t)RTC_TAFCR_TAMPTS |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 (uint32_t)RTC_TAFCR_TAMPFREQ | (uint32_t)RTC_TAFCR_TAMPFLT | (uint32_t)RTC_TAFCR_TAMPPRCH |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 (uint32_t)RTC_TAFCR_TAMPPUDIS | (uint32_t)RTC_TAFCR_TAMPINSEL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 hrtc->Instance->TAFCR |= tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 /* Configure the Tamper Interrupt in the RTC_TAFCR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 hrtc->Instance->TAFCR |= (uint32_t)RTC_TAFCR_TAMPIE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 /* RTC Tamper Interrupt Configuration: EXTI configuration */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 * @brief Deactivates Tamper.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 * @param Tamper: Selected tamper pin.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 * This parameter can be RTC_Tamper_1 and/or RTC_TAMPER_2.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 assert_param(IS_RTC_TAMPER(Tamper));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 /* Disable the selected Tamper pin */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 hrtc->Instance->TAFCR &= (uint32_t)~Tamper;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 * @brief This function handles TimeStamp interrupt request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500 void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502 if(__HAL_RTC_TIMESTAMP_GET_IT(hrtc, RTC_IT_TS))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504 /* Get the status of the Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 if((uint32_t)(hrtc->Instance->CR & RTC_IT_TS) != (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 /* TIMESTAMP callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 HAL_RTCEx_TimeStampEventCallback(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510 /* Clear the TIMESTAMP interrupt pending bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc,RTC_FLAG_TSF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 /* Get the status of the Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 if(__HAL_RTC_TAMPER_GET_IT(hrtc,RTC_IT_TAMP1))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 /* Get the TAMPER Interrupt enable bit and pending bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 if(((hrtc->Instance->TAFCR & (RTC_TAFCR_TAMPIE))) != (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 /* Tamper callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 HAL_RTCEx_Tamper1EventCallback(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 /* Clear the Tamper interrupt pending bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529 /* Get the status of the Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530 if(__HAL_RTC_TAMPER_GET_IT(hrtc, RTC_IT_TAMP2))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 /* Get the TAMPER Interrupt enable bit and pending bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533 if(((hrtc->Instance->TAFCR & RTC_TAFCR_TAMPIE)) != (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 /* Tamper callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 HAL_RTCEx_Tamper2EventCallback(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538 /* Clear the Tamper interrupt pending bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 /* Clear the EXTI's Flag for RTC TimeStamp and Tamper */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550 * @brief TimeStamp callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555 __weak void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558 the HAL_RTC_TimeStampEventCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 * @brief Tamper 1 callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 __weak void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571 the HAL_RTC_Tamper1EventCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576 * @brief Tamper 2 callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581 __weak void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584 the HAL_RTC_Tamper2EventCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 * @brief This function handles TimeStamp polling request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595 HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 while(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604 if(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSOVF) != RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606 /* Clear the TIMESTAMP Overrun Flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSOVF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609 /* Change TIMESTAMP state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610 hrtc->State = HAL_RTC_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619 hrtc->State = HAL_RTC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632 * @brief This function handles Tamper1 Polling.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638 HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 /* Get the status of the Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F)== RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652 hrtc->State = HAL_RTC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658 /* Clear the Tamper Flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 * @brief This function handles Tamper2 Polling.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 /* Get the status of the Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 hrtc->State = HAL_RTC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 /* Clear the Tamper Flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP2F);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 /** @defgroup RTCEx_Exported_Functions_Group2 RTC Wake-up functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708 * @brief RTC Wake-up functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 ##### RTC Wake-up functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715 [..] This section provides functions allowing to configure Wake-up feature
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 * @brief Sets wake up timer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 * @param WakeUpCounter: Wake up counter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 * @param WakeUpClock: Wake up clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734 assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735 assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 hrtc->State = HAL_RTC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 /* Clear the Wake-up Timer clock source bits in CR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770 /* Configure the clock source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771 hrtc->Instance->CR |= (uint32_t)WakeUpClock;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 /* Configure the Wake-up Timer counter */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774 hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776 /* Enable the Wake-up Timer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791 * @brief Sets wake up timer with interrupt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 * @param WakeUpCounter: Wake up counter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 * @param WakeUpClock: Wake up clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803 assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 hrtc->State = HAL_RTC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836 /* Configure the Wake-up Timer counter */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 /* Clear the Wake-up Timer clock source bits in CR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842 /* Configure the clock source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 hrtc->Instance->CR |= (uint32_t)WakeUpClock;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845 /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 EXTI->RTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 /* Configure the Interrupt in the RTC_CR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851 __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc,RTC_IT_WUT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853 /* Enable the Wake-up Timer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
868 * @brief Deactivates wake up timer counter.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
871 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
872 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
873 uint32_t HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
875 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
876
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
877 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
878 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
879
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
880 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
881
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
882 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
883 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
884
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
885 /* Disable the Wake-up Timer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
886 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888 /* In case of interrupt mode is used, the interrupt source must disabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889 __HAL_RTC_WAKEUPTIMER_DISABLE_IT(hrtc,RTC_IT_WUT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
897 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
898 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
899 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
900 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
901
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
902 hrtc->State = HAL_RTC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
903
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
904 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
905 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
906
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
907 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
912 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
915
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
916 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
917 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923 * @brief Gets wake up timer counter.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
925 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
926 * @retval Counter value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
927 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
928 uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
929 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
930 /* Get the counter value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
931 return ((uint32_t)(hrtc->Instance->WUTR & RTC_WUTR_WUT));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
932 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
933
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
934 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
935 * @brief This function handles Wake Up Timer interrupt request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
936 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
937 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
938 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
939 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
940 void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
941 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
942 if(__HAL_RTC_WAKEUPTIMER_GET_IT(hrtc, RTC_IT_WUT))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
943 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
944 /* Get the status of the Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
945 if((uint32_t)(hrtc->Instance->CR & RTC_IT_WUT) != (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
946 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
947 /* WAKEUPTIMER callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
948 HAL_RTCEx_WakeUpTimerEventCallback(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
949
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
950 /* Clear the WAKEUPTIMER interrupt pending bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
951 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
952 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
953 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
954
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
955 /* Clear the EXTI's line Flag for RTC WakeUpTimer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
956 __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
957
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
958 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
959 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
960 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
961
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
962 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
963 * @brief Wake Up Timer callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
964 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
965 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
966 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
967 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
968 __weak void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
969 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
970 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
971 the HAL_RTC_WakeUpTimerEventCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
972 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
973 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
974
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
975 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
976 * @brief This function handles Wake Up Timer Polling.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
977 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
978 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
979 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
980 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
981 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
982 HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
983 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
984 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
985
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
986 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
987 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
988
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
989 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
990 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
991 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
992 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
993 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
994 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
995 hrtc->State = HAL_RTC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
996
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
997 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
998 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
999 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1000 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1001
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1002 /* Clear the WAKEUPTIMER Flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1003 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1004
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1005 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1006 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1007
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1008 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1009 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1010
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1011 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1012 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1013 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1016 /** @defgroup RTCEx_Exported_Functions_Group3 Extension Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1017 * @brief Extension Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1018 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1019 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1020 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1021 ##### Extension Peripheral Control functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1022 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1023 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1024 This subsection provides functions allowing to
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1025 (+) Write a data in a specified RTC Backup data register
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1026 (+) Read a data in a specified RTC Backup data register
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1027 (+) Set the Coarse calibration parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1028 (+) Deactivate the Coarse calibration parameters
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1029 (+) Set the Smooth calibration parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1030 (+) Configure the Synchronization Shift Control Settings.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1031 (+) Configure the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1032 (+) Deactivate the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1033 (+) Enable the RTC reference clock detection.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1034 (+) Disable the RTC reference clock detection.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1035 (+) Enable the Bypass Shadow feature.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1036 (+) Disable the Bypass Shadow feature.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1037
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1038 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1039 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1040 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1041
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1042 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1043 * @brief Writes a data in a specified RTC Backup data register.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1044 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1045 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1046 * @param BackupRegister: RTC Backup data Register number.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1047 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1048 * specify the register.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1049 * @param Data: Data to be written in the specified RTC Backup data register.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1050 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1051 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1052 void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1053 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1054 uint32_t tmp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1055
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1056 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1057 assert_param(IS_RTC_BKP(BackupRegister));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1058
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1059 tmp = (uint32_t)&(hrtc->Instance->BKP0R);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1060 tmp += (BackupRegister * 4);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1061
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1062 /* Write the specified register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1063 *(__IO uint32_t *)tmp = (uint32_t)Data;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1064 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1065
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1066 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1067 * @brief Reads data from the specified RTC Backup data Register.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1068 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1069 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1070 * @param BackupRegister: RTC Backup data Register number.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1071 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1072 * specify the register.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1073 * @retval Read value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1074 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1075 uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1076 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1077 uint32_t tmp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1078
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1079 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1080 assert_param(IS_RTC_BKP(BackupRegister));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1081
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1082 tmp = (uint32_t)&(hrtc->Instance->BKP0R);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1083 tmp += (BackupRegister * 4);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1084
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1085 /* Read the specified register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1086 return (*(__IO uint32_t *)tmp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1087 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1088
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1089 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1090 * @brief Sets the Coarse calibration parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1091 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1092 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1093 * @param CalibSign: Specifies the sign of the coarse calibration value.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1094 * This parameter can be one of the following values :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1095 * @arg RTC_CALIBSIGN_POSITIVE: The value sign is positive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1096 * @arg RTC_CALIBSIGN_NEGATIVE: The value sign is negative
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1097 * @param Value: value of coarse calibration expressed in ppm (coded on 5 bits).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1098 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1099 * @note This Calibration value should be between 0 and 63 when using negative
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1100 * sign with a 2-ppm step.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1101 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1102 * @note This Calibration value should be between 0 and 126 when using positive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1103 * sign with a 4-ppm step.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1104 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1105 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1106 HAL_StatusTypeDef HAL_RTCEx_SetCoarseCalib(RTC_HandleTypeDef* hrtc, uint32_t CalibSign, uint32_t Value)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1107 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1108 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1109 assert_param(IS_RTC_CALIB_SIGN(CalibSign));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1110 assert_param(IS_RTC_CALIB_VALUE(Value));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1111
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1112 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1113 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1114
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1115 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1116
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1117 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1118 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1119
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1120 /* Set Initialization mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1121 if(RTC_EnterInitMode(hrtc) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1122 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1123 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1124 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1125
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1126 /* Set RTC state*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1127 hrtc->State = HAL_RTC_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1128
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1129 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1130 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1131
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1132 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1133 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1134 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1135 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1136 /* Enable the Coarse Calibration */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1137 __HAL_RTC_COARSE_CALIB_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1138
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1139 /* Set the coarse calibration value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1140 hrtc->Instance->CALIBR = (uint32_t)(CalibSign|Value);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1141
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1142 /* Exit Initialization mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1143 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1144 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1145
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1146 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1147 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1148
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1149 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1150 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1151
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1152 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1153 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1154
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1155 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1156 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1157
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1158 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1159 * @brief Deactivates the Coarse calibration parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1160 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1161 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1162 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1163 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1164 HAL_StatusTypeDef HAL_RTCEx_DeactivateCoarseCalib(RTC_HandleTypeDef* hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1165 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1166 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1167 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1168
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1169 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1170
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1171 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1172 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1173
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1174 /* Set Initialization mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1175 if(RTC_EnterInitMode(hrtc) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1176 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1177 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1178 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1179
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1180 /* Set RTC state*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1181 hrtc->State = HAL_RTC_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1182
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1183 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1184 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1185
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1186 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1187 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1188 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1189 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1190 /* Enable the Coarse Calibration */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1191 __HAL_RTC_COARSE_CALIB_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1192
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1193 /* Exit Initialization mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1194 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1195 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1196
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1197 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1198 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1199
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1200 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1201 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1202
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1203 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1204 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1205
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1206 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1207 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1208
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1209 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1210 * @brief Sets the Smooth calibration parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1211 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1212 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1213 * @param SmoothCalibPeriod: Select the Smooth Calibration Period.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1214 * This parameter can be can be one of the following values :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1215 * @arg RTC_SMOOTHCALIB_PERIOD_32SEC: The smooth calibration period is 32s.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1216 * @arg RTC_SMOOTHCALIB_PERIOD_16SEC: The smooth calibration period is 16s.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1217 * @arg RTC_SMOOTHCALIB_PERIOD_8SEC: The smooth calibration period is 8s.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1218 * @param SmoothCalibPlusPulses: Select to Set or reset the CALP bit.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1219 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1220 * @arg RTC_SMOOTHCALIB_PLUSPULSES_SET: Add one RTCCLK pulse every 2*11 pulses.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1221 * @arg RTC_SMOOTHCALIB_PLUSPULSES_RESET: No RTCCLK pulses are added.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1222 * @param SmouthCalibMinusPulsesValue: Select the value of CALM[8:0] bits.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1223 * This parameter can be one any value from 0 to 0x000001FF.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1224 * @note To deactivate the smooth calibration, the field SmoothCalibPlusPulses
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1225 * must be equal to SMOOTHCALIB_PLUSPULSES_RESET and the field
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1226 * SmouthCalibMinusPulsesValue must be equal to 0.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1227 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1228 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1229 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef* hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmouthCalibMinusPulsesValue)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1230 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1231 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1232
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1233 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1234 assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(SmoothCalibPeriod));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1235 assert_param(IS_RTC_SMOOTH_CALIB_PLUS(SmoothCalibPlusPulses));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1236 assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmouthCalibMinusPulsesValue));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1237
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1238 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1239 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1240
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1241 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1242
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1243 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1244 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1245
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1246 /* check if a calibration is pending*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1247 if((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1248 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1249 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1250 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1251
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1252 /* check if a calibration is pending*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1253 while((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1254 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1255 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1256 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1257 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1258 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1259
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1260 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1261 hrtc->State = HAL_RTC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1262
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1263 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1264 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1265
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1266 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1267 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1268 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1269 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1270
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1271 /* Configure the Smooth calibration settings */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1272 hrtc->Instance->CALR = (uint32_t)((uint32_t)SmoothCalibPeriod | (uint32_t)SmoothCalibPlusPulses | (uint32_t)SmouthCalibMinusPulsesValue);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1273
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1274 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1275 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1276
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1277 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1278 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1279
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1280 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1281 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1282
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1283 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1284 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1285
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1286 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1287 * @brief Configures the Synchronization Shift Control Settings.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1288 * @note When REFCKON is set, firmware must not write to Shift control register.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1289 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1290 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1291 * @param ShiftAdd1S: Select to add or not 1 second to the time calendar.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1292 * This parameter can be one of the following values :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1293 * @arg RTC_SHIFTADD1S_SET: Add one second to the clock calendar.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1294 * @arg RTC_SHIFTADD1S_RESET: No effect.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1295 * @param ShiftSubFS: Select the number of Second Fractions to substitute.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1296 * This parameter can be one any value from 0 to 0x7FFF.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1297 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1298 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1299 HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef* hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1300 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1301 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1302
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1303 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1304 assert_param(IS_RTC_SHIFT_ADD1S(ShiftAdd1S));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1305 assert_param(IS_RTC_SHIFT_SUBFS(ShiftSubFS));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1306
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1307 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1308 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1309
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1310 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1311
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1312 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1313 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1314
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1315 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1316 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1317
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1318 /* Wait until the shift is completed*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1319 while((hrtc->Instance->ISR & RTC_ISR_SHPF) != RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1320 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1321 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1322 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1323 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1324 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1325
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1326 hrtc->State = HAL_RTC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1327
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1328 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1329 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1330
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1331 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1332 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1333 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1334
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1335 /* Check if the reference clock detection is disabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1336 if((hrtc->Instance->CR & RTC_CR_REFCKON) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1337 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1338 /* Configure the Shift settings */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1339 hrtc->Instance->SHIFTR = (uint32_t)(uint32_t)(ShiftSubFS) | (uint32_t)(ShiftAdd1S);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1340
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1341 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1342 if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1343 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1344 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1345 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1346 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1347 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1348
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1349 hrtc->State = HAL_RTC_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1350
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1351 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1352 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1353
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1354 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1355 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1356 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1357 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1358 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1359 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1360 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1361 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1362
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1363 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1364 hrtc->State = HAL_RTC_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1365
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1366 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1367 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1368
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1369 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1370 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1371
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1372 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1373 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1374
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1375 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1376 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1377
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1378 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1379 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1380
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1381 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1382 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1383
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1384 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1385 * @brief Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1386 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1387 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1388 * @param CalibOutput: Select the Calibration output Selection .
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1389 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1390 * @arg RTC_CALIBOUTPUT_512HZ: A signal has a regular waveform at 512Hz.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1391 * @arg RTC_CALIBOUTPUT_1HZ: A signal has a regular waveform at 1Hz.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1392 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1393 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1394 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef* hrtc, uint32_t CalibOutput)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1395 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1396 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1397 assert_param(IS_RTC_CALIB_OUTPUT(CalibOutput));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1398
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1399 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1400 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1401
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1402 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1403
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1404 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1405 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1406
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1407 /* Clear flags before config */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1408 hrtc->Instance->CR &= (uint32_t)~RTC_CR_COSEL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1409
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1410 /* Configure the RTC_CR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1411 hrtc->Instance->CR |= (uint32_t)CalibOutput;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1412
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1413 __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1414
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1415 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1416 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1417
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1418 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1419 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1420
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1421 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1422 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1423
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1424 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1425 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1426
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1427 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1428 * @brief Deactivates the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1429 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1430 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1431 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1432 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1433 HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef* hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1434 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1435 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1436 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1437
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1438 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1439
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1440 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1441 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1442
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1443 __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1444
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1445 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1446 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1447
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1448 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1449 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1450
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1451 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1452 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1453
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1454 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1455 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1456
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1457 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1458 * @brief Enables the RTC reference clock detection.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1459 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1460 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1461 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1462 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1463 HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef* hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1464 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1465 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1466 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1467
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1468 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1469
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1470 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1471 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1472
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1473 /* Set Initialization mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1474 if(RTC_EnterInitMode(hrtc) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1475 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1476 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1477 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1478
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1479 /* Set RTC state*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1480 hrtc->State = HAL_RTC_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1481
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1482 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1483 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1484
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1485 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1486 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1487 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1488 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1489 __HAL_RTC_CLOCKREF_DETECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1490
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1491 /* Exit Initialization mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1492 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1493 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1494
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1495 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1496 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1497
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1498 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1499 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1500
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1501 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1502 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1503
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1504 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1505 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1506
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1507 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1508 * @brief Disable the RTC reference clock detection.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1509 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1510 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1511 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1512 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1513 HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef* hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1514 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1515 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1516 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1517
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1518 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1519
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1520 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1521 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1522
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1523 /* Set Initialization mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1524 if(RTC_EnterInitMode(hrtc) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1525 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1526 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1527 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1528
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1529 /* Set RTC state*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1530 hrtc->State = HAL_RTC_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1531
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1532 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1533 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1534
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1535 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1536 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1537 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1538 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1539 __HAL_RTC_CLOCKREF_DETECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1540
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1541 /* Exit Initialization mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1542 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1543 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1544
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1545 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1546 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1547
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1548 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1549 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1550
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1551 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1552 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1553
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1554 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1555 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1556
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1557 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1558 * @brief Enables the Bypass Shadow feature.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1559 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1560 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1561 * @note When the Bypass Shadow is enabled the calendar value are taken
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1562 * directly from the Calendar counter.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1563 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1564 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1565 HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef* hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1566 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1567 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1568 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1569
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1570 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1571
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1572 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1573 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1574
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1575 /* Set the BYPSHAD bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1576 hrtc->Instance->CR |= (uint8_t)RTC_CR_BYPSHAD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1577
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1578 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1579 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1580
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1581 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1582 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1583
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1584 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1585 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1586
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1587 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1588 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1589
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1590 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1591 * @brief Disables the Bypass Shadow feature.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1592 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1593 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1594 * @note When the Bypass Shadow is enabled the calendar value are taken
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1595 * directly from the Calendar counter.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1596 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1597 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1598 HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef* hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1599 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1600 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1601 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1602
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1603 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1604
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1605 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1606 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1607
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1608 /* Reset the BYPSHAD bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1609 hrtc->Instance->CR &= (uint8_t)~RTC_CR_BYPSHAD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1610
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1611 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1612 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1613
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1614 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1615 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1616
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1617 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1618 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1619
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1620 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1621 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1622
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1623 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1624 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1625 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1626
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1627 /** @defgroup RTCEx_Exported_Functions_Group4 Extended features functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1628 * @brief Extended features functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1629 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1630 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1631 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1632 ##### Extended features functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1633 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1634 [..] This section provides functions allowing to:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1635 (+) RTC Alarm B callback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1636 (+) RTC Poll for Alarm B request
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1637
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1638 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1639 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1640 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1641
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1642 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1643 * @brief Alarm B callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1644 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1645 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1646 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1647 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1648 __weak void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1649 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1650 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1651 the HAL_RTC_AlarmBEventCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1652 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1653 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1654
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1655 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1656 * @brief This function handles AlarmB Polling request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1657 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1658 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1659 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1660 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1661 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1662 HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1663 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1664 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1665
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1666 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1667 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1668
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1669 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBF) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1670 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1671 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1672 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1673 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1674 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1675 hrtc->State = HAL_RTC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1676 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1677 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1678 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1679 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1680
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1681 /* Clear the Alarm Flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1682 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1683
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1684 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1685 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1686
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1687 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1688 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1689
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1690 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1691 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1692 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1693
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1694 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1695 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1696 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1697
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1698 #endif /* HAL_RTC_MODULE_ENABLED */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1699 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1700 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1701 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1702
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1703 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1704 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1705 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1706
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1707 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/