Rev 61 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
56 | mjames | 1 | /** |
2 | ****************************************************************************** |
||
3 | * @file stm32l1xx_ll_rtc.c |
||
4 | * @author MCD Application Team |
||
5 | * @brief RTC LL module driver. |
||
6 | ****************************************************************************** |
||
7 | * @attention |
||
8 | * |
||
9 | * <h2><center>© Copyright (c) 2017 STMicroelectronics. |
||
10 | * All rights reserved.</center></h2> |
||
11 | * |
||
12 | * This software component is licensed by ST under BSD 3-Clause license, |
||
13 | * the "License"; You may not use this file except in compliance with the |
||
14 | * License. You may obtain a copy of the License at: |
||
15 | * opensource.org/licenses/BSD-3-Clause |
||
16 | * |
||
17 | ****************************************************************************** |
||
18 | */ |
||
19 | #if defined(USE_FULL_LL_DRIVER) |
||
20 | |||
21 | /* Includes ------------------------------------------------------------------*/ |
||
22 | #include "stm32l1xx_ll_rtc.h" |
||
23 | #include "stm32l1xx_ll_cortex.h" |
||
24 | #ifdef USE_FULL_ASSERT |
||
25 | #include "stm32_assert.h" |
||
26 | #else |
||
27 | #define assert_param(expr) ((void)0U) |
||
28 | #endif |
||
29 | |||
30 | /** @addtogroup STM32L1xx_LL_Driver |
||
31 | * @{ |
||
32 | */ |
||
33 | |||
34 | #if defined(RTC) |
||
35 | |||
36 | /** @addtogroup RTC_LL |
||
37 | * @{ |
||
38 | */ |
||
39 | |||
40 | /* Private types -------------------------------------------------------------*/ |
||
41 | /* Private variables ---------------------------------------------------------*/ |
||
42 | /* Private constants ---------------------------------------------------------*/ |
||
43 | /** @addtogroup RTC_LL_Private_Constants |
||
44 | * @{ |
||
45 | */ |
||
46 | /* Default values used for prescaler */ |
||
47 | #define RTC_ASYNCH_PRESC_DEFAULT 0x0000007FU |
||
48 | #define RTC_SYNCH_PRESC_DEFAULT 0x000000FFU |
||
49 | |||
50 | /* Values used for timeout */ |
||
51 | #define RTC_INITMODE_TIMEOUT 1000U /* 1s when tick set to 1ms */ |
||
52 | #define RTC_SYNCHRO_TIMEOUT 1000U /* 1s when tick set to 1ms */ |
||
53 | /** |
||
54 | * @} |
||
55 | */ |
||
56 | |||
57 | /* Private macros ------------------------------------------------------------*/ |
||
58 | /** @addtogroup RTC_LL_Private_Macros |
||
59 | * @{ |
||
60 | */ |
||
61 | |||
62 | #define IS_LL_RTC_HOURFORMAT(__VALUE__) (((__VALUE__) == LL_RTC_HOURFORMAT_24HOUR) \ |
||
63 | || ((__VALUE__) == LL_RTC_HOURFORMAT_AMPM)) |
||
64 | |||
65 | #define IS_LL_RTC_ASYNCH_PREDIV(__VALUE__) ((__VALUE__) <= 0x7FU) |
||
66 | |||
67 | #define IS_LL_RTC_SYNCH_PREDIV(__VALUE__) ((__VALUE__) <= 0x7FFFU) |
||
68 | |||
69 | #define IS_LL_RTC_FORMAT(__VALUE__) (((__VALUE__) == LL_RTC_FORMAT_BIN) \ |
||
70 | || ((__VALUE__) == LL_RTC_FORMAT_BCD)) |
||
71 | |||
72 | #define IS_LL_RTC_TIME_FORMAT(__VALUE__) (((__VALUE__) == LL_RTC_TIME_FORMAT_AM_OR_24) \ |
||
73 | || ((__VALUE__) == LL_RTC_TIME_FORMAT_PM)) |
||
74 | |||
75 | #define IS_LL_RTC_HOUR12(__HOUR__) (((__HOUR__) > 0U) && ((__HOUR__) <= 12U)) |
||
76 | #define IS_LL_RTC_HOUR24(__HOUR__) ((__HOUR__) <= 23U) |
||
77 | #define IS_LL_RTC_MINUTES(__MINUTES__) ((__MINUTES__) <= 59U) |
||
78 | #define IS_LL_RTC_SECONDS(__SECONDS__) ((__SECONDS__) <= 59U) |
||
79 | |||
80 | #define IS_LL_RTC_WEEKDAY(__VALUE__) (((__VALUE__) == LL_RTC_WEEKDAY_MONDAY) \ |
||
81 | || ((__VALUE__) == LL_RTC_WEEKDAY_TUESDAY) \ |
||
82 | || ((__VALUE__) == LL_RTC_WEEKDAY_WEDNESDAY) \ |
||
83 | || ((__VALUE__) == LL_RTC_WEEKDAY_THURSDAY) \ |
||
84 | || ((__VALUE__) == LL_RTC_WEEKDAY_FRIDAY) \ |
||
85 | || ((__VALUE__) == LL_RTC_WEEKDAY_SATURDAY) \ |
||
86 | || ((__VALUE__) == LL_RTC_WEEKDAY_SUNDAY)) |
||
87 | |||
88 | #define IS_LL_RTC_DAY(__DAY__) (((__DAY__) >= 1U) && ((__DAY__) <= 31U)) |
||
89 | |||
90 | #define IS_LL_RTC_MONTH(__VALUE__) (((__VALUE__) == LL_RTC_MONTH_JANUARY) \ |
||
91 | || ((__VALUE__) == LL_RTC_MONTH_FEBRUARY) \ |
||
92 | || ((__VALUE__) == LL_RTC_MONTH_MARCH) \ |
||
93 | || ((__VALUE__) == LL_RTC_MONTH_APRIL) \ |
||
94 | || ((__VALUE__) == LL_RTC_MONTH_MAY) \ |
||
95 | || ((__VALUE__) == LL_RTC_MONTH_JUNE) \ |
||
96 | || ((__VALUE__) == LL_RTC_MONTH_JULY) \ |
||
97 | || ((__VALUE__) == LL_RTC_MONTH_AUGUST) \ |
||
98 | || ((__VALUE__) == LL_RTC_MONTH_SEPTEMBER) \ |
||
99 | || ((__VALUE__) == LL_RTC_MONTH_OCTOBER) \ |
||
100 | || ((__VALUE__) == LL_RTC_MONTH_NOVEMBER) \ |
||
101 | || ((__VALUE__) == LL_RTC_MONTH_DECEMBER)) |
||
102 | |||
103 | #define IS_LL_RTC_YEAR(__YEAR__) ((__YEAR__) <= 99U) |
||
104 | |||
105 | #define IS_LL_RTC_ALMA_MASK(__VALUE__) (((__VALUE__) == LL_RTC_ALMA_MASK_NONE) \ |
||
106 | || ((__VALUE__) == LL_RTC_ALMA_MASK_DATEWEEKDAY) \ |
||
107 | || ((__VALUE__) == LL_RTC_ALMA_MASK_HOURS) \ |
||
108 | || ((__VALUE__) == LL_RTC_ALMA_MASK_MINUTES) \ |
||
109 | || ((__VALUE__) == LL_RTC_ALMA_MASK_SECONDS) \ |
||
110 | || ((__VALUE__) == LL_RTC_ALMA_MASK_ALL)) |
||
111 | |||
112 | #define IS_LL_RTC_ALMB_MASK(__VALUE__) (((__VALUE__) == LL_RTC_ALMB_MASK_NONE) \ |
||
113 | || ((__VALUE__) == LL_RTC_ALMB_MASK_DATEWEEKDAY) \ |
||
114 | || ((__VALUE__) == LL_RTC_ALMB_MASK_HOURS) \ |
||
115 | || ((__VALUE__) == LL_RTC_ALMB_MASK_MINUTES) \ |
||
116 | || ((__VALUE__) == LL_RTC_ALMB_MASK_SECONDS) \ |
||
117 | || ((__VALUE__) == LL_RTC_ALMB_MASK_ALL)) |
||
118 | |||
119 | |||
120 | #define IS_LL_RTC_ALMA_DATE_WEEKDAY_SEL(__SEL__) (((__SEL__) == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE) || \ |
||
121 | ((__SEL__) == LL_RTC_ALMA_DATEWEEKDAYSEL_WEEKDAY)) |
||
122 | |||
123 | #define IS_LL_RTC_ALMB_DATE_WEEKDAY_SEL(__SEL__) (((__SEL__) == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE) || \ |
||
124 | ((__SEL__) == LL_RTC_ALMB_DATEWEEKDAYSEL_WEEKDAY)) |
||
125 | |||
126 | |||
127 | /** |
||
128 | * @} |
||
129 | */ |
||
130 | /* Private function prototypes -----------------------------------------------*/ |
||
131 | /* Exported functions --------------------------------------------------------*/ |
||
132 | /** @addtogroup RTC_LL_Exported_Functions |
||
133 | * @{ |
||
134 | */ |
||
135 | |||
136 | /** @addtogroup RTC_LL_EF_Init |
||
137 | * @{ |
||
138 | */ |
||
139 | |||
140 | /** |
||
141 | * @brief De-Initializes the RTC registers to their default reset values. |
||
142 | * @note This function does not reset the RTC Clock source and RTC Backup Data |
||
143 | * registers. |
||
144 | * @param RTCx RTC Instance |
||
145 | * @retval An ErrorStatus enumeration value: |
||
146 | * - SUCCESS: RTC registers are de-initialized |
||
147 | * - ERROR: RTC registers are not de-initialized |
||
148 | */ |
||
149 | ErrorStatus LL_RTC_DeInit(RTC_TypeDef *RTCx) |
||
150 | { |
||
151 | ErrorStatus status = ERROR; |
||
152 | |||
153 | /* Check the parameter */ |
||
154 | assert_param(IS_RTC_ALL_INSTANCE(RTCx)); |
||
155 | |||
156 | /* Disable the write protection for RTC registers */ |
||
157 | LL_RTC_DisableWriteProtection(RTCx); |
||
158 | |||
159 | /* Set Initialization mode */ |
||
160 | if (LL_RTC_EnterInitMode(RTCx) != ERROR) |
||
161 | { |
||
162 | /* Reset TR, DR and CR registers */ |
||
163 | LL_RTC_WriteReg(RTCx, TR, 0x00000000U); |
||
164 | #if defined(RTC_WAKEUP_SUPPORT) |
||
165 | LL_RTC_WriteReg(RTCx, WUTR, RTC_WUTR_WUT); |
||
166 | #endif /* RTC_WAKEUP_SUPPORT */ |
||
167 | LL_RTC_WriteReg(RTCx, DR, (RTC_DR_WDU_0 | RTC_DR_MU_0 | RTC_DR_DU_0)); |
||
168 | /* Reset All CR bits except CR[2:0] */ |
||
169 | #if defined(RTC_WAKEUP_SUPPORT) |
||
170 | LL_RTC_WriteReg(RTCx, CR, (LL_RTC_ReadReg(RTCx, CR) & RTC_CR_WUCKSEL)); |
||
171 | #else |
||
172 | LL_RTC_WriteReg(RTCx, CR, 0x00000000U); |
||
173 | #endif /* RTC_WAKEUP_SUPPORT */ |
||
174 | LL_RTC_WriteReg(RTCx, PRER, (RTC_PRER_PREDIV_A | RTC_SYNCH_PRESC_DEFAULT)); |
||
175 | LL_RTC_WriteReg(RTCx, ALRMAR, 0x00000000U); |
||
176 | LL_RTC_WriteReg(RTCx, ALRMBR, 0x00000000U); |
||
177 | #if defined(RTC_SHIFTR_ADD1S) |
||
178 | LL_RTC_WriteReg(RTCx, SHIFTR, 0x00000000U); |
||
179 | #endif /* RTC_SHIFTR_ADD1S */ |
||
180 | #if defined(RTC_SMOOTHCALIB_SUPPORT) |
||
181 | LL_RTC_WriteReg(RTCx, CALR, 0x00000000U); |
||
182 | #endif /* RTC_SMOOTHCALIB_SUPPORT */ |
||
183 | #if defined(RTC_SUBSECOND_SUPPORT) |
||
184 | LL_RTC_WriteReg(RTCx, ALRMASSR, 0x00000000U); |
||
185 | LL_RTC_WriteReg(RTCx, ALRMBSSR, 0x00000000U); |
||
186 | #endif /* RTC_SUBSECOND_SUPPORT */ |
||
187 | |||
188 | /* Reset ISR register and exit initialization mode */ |
||
189 | LL_RTC_WriteReg(RTCx, ISR, 0x00000000U); |
||
190 | |||
191 | /* Reset Tamper and alternate functions configuration register */ |
||
192 | LL_RTC_WriteReg(RTCx, TAFCR, 0x00000000U); |
||
193 | |||
194 | /* Wait till the RTC RSF flag is set */ |
||
195 | status = LL_RTC_WaitForSynchro(RTCx); |
||
196 | } |
||
197 | |||
198 | /* Enable the write protection for RTC registers */ |
||
199 | LL_RTC_EnableWriteProtection(RTCx); |
||
200 | |||
201 | return status; |
||
202 | } |
||
203 | |||
204 | /** |
||
205 | * @brief Initializes the RTC registers according to the specified parameters |
||
206 | * in RTC_InitStruct. |
||
207 | * @param RTCx RTC Instance |
||
208 | * @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure that contains |
||
209 | * the configuration information for the RTC peripheral. |
||
210 | * @note The RTC Prescaler register is write protected and can be written in |
||
211 | * initialization mode only. |
||
212 | * @retval An ErrorStatus enumeration value: |
||
213 | * - SUCCESS: RTC registers are initialized |
||
214 | * - ERROR: RTC registers are not initialized |
||
215 | */ |
||
216 | ErrorStatus LL_RTC_Init(RTC_TypeDef *RTCx, LL_RTC_InitTypeDef *RTC_InitStruct) |
||
217 | { |
||
218 | ErrorStatus status = ERROR; |
||
219 | |||
220 | /* Check the parameters */ |
||
221 | assert_param(IS_RTC_ALL_INSTANCE(RTCx)); |
||
222 | assert_param(IS_LL_RTC_HOURFORMAT(RTC_InitStruct->HourFormat)); |
||
223 | assert_param(IS_LL_RTC_ASYNCH_PREDIV(RTC_InitStruct->AsynchPrescaler)); |
||
224 | assert_param(IS_LL_RTC_SYNCH_PREDIV(RTC_InitStruct->SynchPrescaler)); |
||
225 | |||
226 | /* Disable the write protection for RTC registers */ |
||
227 | LL_RTC_DisableWriteProtection(RTCx); |
||
228 | |||
229 | /* Set Initialization mode */ |
||
230 | if (LL_RTC_EnterInitMode(RTCx) != ERROR) |
||
231 | { |
||
232 | /* Set Hour Format */ |
||
233 | LL_RTC_SetHourFormat(RTCx, RTC_InitStruct->HourFormat); |
||
234 | |||
235 | /* Configure Synchronous and Asynchronous prescaler factor */ |
||
236 | LL_RTC_SetSynchPrescaler(RTCx, RTC_InitStruct->SynchPrescaler); |
||
237 | LL_RTC_SetAsynchPrescaler(RTCx, RTC_InitStruct->AsynchPrescaler); |
||
238 | |||
239 | /* Exit Initialization mode */ |
||
240 | LL_RTC_DisableInitMode(RTCx); |
||
241 | |||
242 | status = SUCCESS; |
||
243 | } |
||
244 | /* Enable the write protection for RTC registers */ |
||
245 | LL_RTC_EnableWriteProtection(RTCx); |
||
246 | |||
247 | return status; |
||
248 | } |
||
249 | |||
250 | /** |
||
251 | * @brief Set each @ref LL_RTC_InitTypeDef field to default value. |
||
252 | * @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure which will be initialized. |
||
253 | * @retval None |
||
254 | */ |
||
255 | void LL_RTC_StructInit(LL_RTC_InitTypeDef *RTC_InitStruct) |
||
256 | { |
||
257 | /* Set RTC_InitStruct fields to default values */ |
||
258 | RTC_InitStruct->HourFormat = LL_RTC_HOURFORMAT_24HOUR; |
||
259 | RTC_InitStruct->AsynchPrescaler = RTC_ASYNCH_PRESC_DEFAULT; |
||
260 | RTC_InitStruct->SynchPrescaler = RTC_SYNCH_PRESC_DEFAULT; |
||
261 | } |
||
262 | |||
263 | /** |
||
264 | * @brief Set the RTC current time. |
||
265 | * @param RTCx RTC Instance |
||
266 | * @param RTC_Format This parameter can be one of the following values: |
||
267 | * @arg @ref LL_RTC_FORMAT_BIN |
||
268 | * @arg @ref LL_RTC_FORMAT_BCD |
||
269 | * @param RTC_TimeStruct pointer to a RTC_TimeTypeDef structure that contains |
||
270 | * the time configuration information for the RTC. |
||
271 | * @retval An ErrorStatus enumeration value: |
||
272 | * - SUCCESS: RTC Time register is configured |
||
273 | * - ERROR: RTC Time register is not configured |
||
274 | */ |
||
275 | ErrorStatus LL_RTC_TIME_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_TimeTypeDef *RTC_TimeStruct) |
||
276 | { |
||
277 | ErrorStatus status = ERROR; |
||
278 | |||
279 | /* Check the parameters */ |
||
280 | assert_param(IS_RTC_ALL_INSTANCE(RTCx)); |
||
281 | assert_param(IS_LL_RTC_FORMAT(RTC_Format)); |
||
282 | |||
283 | if (RTC_Format == LL_RTC_FORMAT_BIN) |
||
284 | { |
||
285 | if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR) |
||
286 | { |
||
287 | assert_param(IS_LL_RTC_HOUR12(RTC_TimeStruct->Hours)); |
||
288 | assert_param(IS_LL_RTC_TIME_FORMAT(RTC_TimeStruct->TimeFormat)); |
||
289 | } |
||
290 | else |
||
291 | { |
||
292 | RTC_TimeStruct->TimeFormat = 0x00U; |
||
293 | assert_param(IS_LL_RTC_HOUR24(RTC_TimeStruct->Hours)); |
||
294 | } |
||
295 | assert_param(IS_LL_RTC_MINUTES(RTC_TimeStruct->Minutes)); |
||
296 | assert_param(IS_LL_RTC_SECONDS(RTC_TimeStruct->Seconds)); |
||
297 | } |
||
298 | else |
||
299 | { |
||
300 | if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR) |
||
301 | { |
||
302 | assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Hours))); |
||
303 | assert_param(IS_LL_RTC_TIME_FORMAT(RTC_TimeStruct->TimeFormat)); |
||
304 | } |
||
305 | else |
||
306 | { |
||
307 | RTC_TimeStruct->TimeFormat = 0x00U; |
||
308 | assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Hours))); |
||
309 | } |
||
310 | assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Minutes))); |
||
311 | assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Seconds))); |
||
312 | } |
||
313 | |||
314 | /* Disable the write protection for RTC registers */ |
||
315 | LL_RTC_DisableWriteProtection(RTCx); |
||
316 | |||
317 | /* Set Initialization mode */ |
||
318 | if (LL_RTC_EnterInitMode(RTCx) != ERROR) |
||
319 | { |
||
320 | /* Check the input parameters format */ |
||
321 | if (RTC_Format != LL_RTC_FORMAT_BIN) |
||
322 | { |
||
323 | LL_RTC_TIME_Config(RTCx, RTC_TimeStruct->TimeFormat, RTC_TimeStruct->Hours, |
||
324 | RTC_TimeStruct->Minutes, RTC_TimeStruct->Seconds); |
||
325 | } |
||
326 | else |
||
327 | { |
||
328 | LL_RTC_TIME_Config(RTCx, RTC_TimeStruct->TimeFormat, __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct->Hours), |
||
329 | __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct->Minutes), |
||
330 | __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct->Seconds)); |
||
331 | } |
||
332 | |||
333 | /* Exit Initialization mode */ |
||
334 | LL_RTC_DisableInitMode(RTC); |
||
335 | |||
336 | #if defined(RTC_CR_BYPSHAD) |
||
337 | /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */ |
||
338 | if (LL_RTC_IsShadowRegBypassEnabled(RTCx) == 0U) |
||
339 | { |
||
340 | status = LL_RTC_WaitForSynchro(RTCx); |
||
341 | } |
||
342 | else |
||
343 | { |
||
344 | status = SUCCESS; |
||
345 | } |
||
346 | #else |
||
347 | status = SUCCESS; |
||
348 | #endif /* RTC_CR_BYPSHAD */ |
||
349 | } |
||
350 | /* Enable the write protection for RTC registers */ |
||
351 | LL_RTC_EnableWriteProtection(RTCx); |
||
352 | |||
353 | return status; |
||
354 | } |
||
355 | |||
356 | /** |
||
357 | * @brief Set each @ref LL_RTC_TimeTypeDef field to default value (Time = 00h:00min:00sec). |
||
358 | * @param RTC_TimeStruct pointer to a @ref LL_RTC_TimeTypeDef structure which will be initialized. |
||
359 | * @retval None |
||
360 | */ |
||
361 | void LL_RTC_TIME_StructInit(LL_RTC_TimeTypeDef *RTC_TimeStruct) |
||
362 | { |
||
363 | /* Time = 00h:00min:00sec */ |
||
364 | RTC_TimeStruct->TimeFormat = LL_RTC_TIME_FORMAT_AM_OR_24; |
||
365 | RTC_TimeStruct->Hours = 0U; |
||
366 | RTC_TimeStruct->Minutes = 0U; |
||
367 | RTC_TimeStruct->Seconds = 0U; |
||
368 | } |
||
369 | |||
370 | /** |
||
371 | * @brief Set the RTC current date. |
||
372 | * @param RTCx RTC Instance |
||
373 | * @param RTC_Format This parameter can be one of the following values: |
||
374 | * @arg @ref LL_RTC_FORMAT_BIN |
||
375 | * @arg @ref LL_RTC_FORMAT_BCD |
||
376 | * @param RTC_DateStruct pointer to a RTC_DateTypeDef structure that contains |
||
377 | * the date configuration information for the RTC. |
||
378 | * @retval An ErrorStatus enumeration value: |
||
379 | * - SUCCESS: RTC Day register is configured |
||
380 | * - ERROR: RTC Day register is not configured |
||
381 | */ |
||
382 | ErrorStatus LL_RTC_DATE_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_DateTypeDef *RTC_DateStruct) |
||
383 | { |
||
384 | ErrorStatus status = ERROR; |
||
385 | |||
386 | /* Check the parameters */ |
||
387 | assert_param(IS_RTC_ALL_INSTANCE(RTCx)); |
||
388 | assert_param(IS_LL_RTC_FORMAT(RTC_Format)); |
||
389 | |||
390 | if ((RTC_Format == LL_RTC_FORMAT_BIN) && ((RTC_DateStruct->Month & 0x10U) == 0x10U)) |
||
391 | { |
||
392 | RTC_DateStruct->Month = ((RTC_DateStruct->Month & (uint8_t)~(0x10U)) + 0x0AU); |
||
393 | } |
||
394 | if (RTC_Format == LL_RTC_FORMAT_BIN) |
||
395 | { |
||
396 | assert_param(IS_LL_RTC_YEAR(RTC_DateStruct->Year)); |
||
397 | assert_param(IS_LL_RTC_MONTH(RTC_DateStruct->Month)); |
||
398 | assert_param(IS_LL_RTC_DAY(RTC_DateStruct->Day)); |
||
399 | } |
||
400 | else |
||
401 | { |
||
402 | assert_param(IS_LL_RTC_YEAR(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Year))); |
||
403 | assert_param(IS_LL_RTC_MONTH(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Month))); |
||
404 | assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Day))); |
||
405 | } |
||
406 | assert_param(IS_LL_RTC_WEEKDAY(RTC_DateStruct->WeekDay)); |
||
407 | |||
408 | /* Disable the write protection for RTC registers */ |
||
409 | LL_RTC_DisableWriteProtection(RTCx); |
||
410 | |||
411 | /* Set Initialization mode */ |
||
412 | if (LL_RTC_EnterInitMode(RTCx) != ERROR) |
||
413 | { |
||
414 | /* Check the input parameters format */ |
||
415 | if (RTC_Format != LL_RTC_FORMAT_BIN) |
||
416 | { |
||
417 | LL_RTC_DATE_Config(RTCx, RTC_DateStruct->WeekDay, RTC_DateStruct->Day, RTC_DateStruct->Month, RTC_DateStruct->Year); |
||
418 | } |
||
419 | else |
||
420 | { |
||
421 | LL_RTC_DATE_Config(RTCx, RTC_DateStruct->WeekDay, __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct->Day), |
||
422 | __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct->Month), __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct->Year)); |
||
423 | } |
||
424 | |||
425 | /* Exit Initialization mode */ |
||
426 | LL_RTC_DisableInitMode(RTC); |
||
427 | |||
428 | #if defined(RTC_CR_BYPSHAD) |
||
429 | /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */ |
||
430 | if (LL_RTC_IsShadowRegBypassEnabled(RTCx) == 0U) |
||
431 | { |
||
432 | status = LL_RTC_WaitForSynchro(RTCx); |
||
433 | } |
||
434 | else |
||
435 | { |
||
436 | status = SUCCESS; |
||
437 | } |
||
438 | #else |
||
439 | status = SUCCESS; |
||
440 | #endif /* RTC_CR_BYPSHAD */ |
||
441 | } |
||
442 | /* Enable the write protection for RTC registers */ |
||
443 | LL_RTC_EnableWriteProtection(RTCx); |
||
444 | |||
445 | return status; |
||
446 | } |
||
447 | |||
448 | /** |
||
449 | * @brief Set each @ref LL_RTC_DateTypeDef field to default value (date = Monday, January 01 xx00) |
||
450 | * @param RTC_DateStruct pointer to a @ref LL_RTC_DateTypeDef structure which will be initialized. |
||
451 | * @retval None |
||
452 | */ |
||
453 | void LL_RTC_DATE_StructInit(LL_RTC_DateTypeDef *RTC_DateStruct) |
||
454 | { |
||
455 | /* Monday, January 01 xx00 */ |
||
456 | RTC_DateStruct->WeekDay = LL_RTC_WEEKDAY_MONDAY; |
||
457 | RTC_DateStruct->Day = 1U; |
||
458 | RTC_DateStruct->Month = LL_RTC_MONTH_JANUARY; |
||
459 | RTC_DateStruct->Year = 0U; |
||
460 | } |
||
461 | |||
462 | /** |
||
463 | * @brief Set the RTC Alarm A. |
||
464 | * @note The Alarm register can only be written when the corresponding Alarm |
||
465 | * is disabled (Use @ref LL_RTC_ALMA_Disable function). |
||
466 | * @param RTCx RTC Instance |
||
467 | * @param RTC_Format This parameter can be one of the following values: |
||
468 | * @arg @ref LL_RTC_FORMAT_BIN |
||
469 | * @arg @ref LL_RTC_FORMAT_BCD |
||
470 | * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure that |
||
471 | * contains the alarm configuration parameters. |
||
472 | * @retval An ErrorStatus enumeration value: |
||
473 | * - SUCCESS: ALARMA registers are configured |
||
474 | * - ERROR: ALARMA registers are not configured |
||
475 | */ |
||
476 | ErrorStatus LL_RTC_ALMA_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_AlarmTypeDef *RTC_AlarmStruct) |
||
477 | { |
||
478 | /* Check the parameters */ |
||
479 | assert_param(IS_RTC_ALL_INSTANCE(RTCx)); |
||
480 | assert_param(IS_LL_RTC_FORMAT(RTC_Format)); |
||
481 | assert_param(IS_LL_RTC_ALMA_MASK(RTC_AlarmStruct->AlarmMask)); |
||
482 | assert_param(IS_LL_RTC_ALMA_DATE_WEEKDAY_SEL(RTC_AlarmStruct->AlarmDateWeekDaySel)); |
||
483 | |||
484 | if (RTC_Format == LL_RTC_FORMAT_BIN) |
||
485 | { |
||
486 | if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR) |
||
487 | { |
||
488 | assert_param(IS_LL_RTC_HOUR12(RTC_AlarmStruct->AlarmTime.Hours)); |
||
489 | assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat)); |
||
490 | } |
||
491 | else |
||
492 | { |
||
493 | RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U; |
||
494 | assert_param(IS_LL_RTC_HOUR24(RTC_AlarmStruct->AlarmTime.Hours)); |
||
495 | } |
||
496 | assert_param(IS_LL_RTC_MINUTES(RTC_AlarmStruct->AlarmTime.Minutes)); |
||
497 | assert_param(IS_LL_RTC_SECONDS(RTC_AlarmStruct->AlarmTime.Seconds)); |
||
498 | |||
499 | if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE) |
||
500 | { |
||
501 | assert_param(IS_LL_RTC_DAY(RTC_AlarmStruct->AlarmDateWeekDay)); |
||
502 | } |
||
503 | else |
||
504 | { |
||
505 | assert_param(IS_LL_RTC_WEEKDAY(RTC_AlarmStruct->AlarmDateWeekDay)); |
||
506 | } |
||
507 | } |
||
508 | else |
||
509 | { |
||
510 | if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR) |
||
511 | { |
||
512 | assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours))); |
||
513 | assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat)); |
||
514 | } |
||
515 | else |
||
516 | { |
||
517 | RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U; |
||
518 | assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours))); |
||
519 | } |
||
520 | |||
521 | assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Minutes))); |
||
522 | assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Seconds))); |
||
523 | |||
524 | if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE) |
||
525 | { |
||
526 | assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay))); |
||
527 | } |
||
528 | else |
||
529 | { |
||
530 | assert_param(IS_LL_RTC_WEEKDAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay))); |
||
531 | } |
||
532 | } |
||
533 | |||
534 | /* Disable the write protection for RTC registers */ |
||
535 | LL_RTC_DisableWriteProtection(RTCx); |
||
536 | |||
537 | /* Select weekday selection */ |
||
538 | if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE) |
||
539 | { |
||
540 | /* Set the date for ALARM */ |
||
541 | LL_RTC_ALMA_DisableWeekday(RTCx); |
||
542 | if (RTC_Format != LL_RTC_FORMAT_BIN) |
||
543 | { |
||
544 | LL_RTC_ALMA_SetDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay); |
||
545 | } |
||
546 | else |
||
547 | { |
||
548 | LL_RTC_ALMA_SetDay(RTCx, __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmDateWeekDay)); |
||
549 | } |
||
550 | } |
||
551 | else |
||
552 | { |
||
553 | /* Set the week day for ALARM */ |
||
554 | LL_RTC_ALMA_EnableWeekday(RTCx); |
||
555 | LL_RTC_ALMA_SetWeekDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay); |
||
556 | } |
||
557 | |||
558 | /* Configure the Alarm register */ |
||
559 | if (RTC_Format != LL_RTC_FORMAT_BIN) |
||
560 | { |
||
561 | LL_RTC_ALMA_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat, RTC_AlarmStruct->AlarmTime.Hours, |
||
562 | RTC_AlarmStruct->AlarmTime.Minutes, RTC_AlarmStruct->AlarmTime.Seconds); |
||
563 | } |
||
564 | else |
||
565 | { |
||
566 | LL_RTC_ALMA_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat, |
||
567 | __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Hours), |
||
568 | __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Minutes), |
||
569 | __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Seconds)); |
||
570 | } |
||
571 | /* Set ALARM mask */ |
||
572 | LL_RTC_ALMA_SetMask(RTCx, RTC_AlarmStruct->AlarmMask); |
||
573 | |||
574 | /* Enable the write protection for RTC registers */ |
||
575 | LL_RTC_EnableWriteProtection(RTCx); |
||
576 | |||
577 | return SUCCESS; |
||
578 | } |
||
579 | |||
580 | /** |
||
581 | * @brief Set the RTC Alarm B. |
||
582 | * @note The Alarm register can only be written when the corresponding Alarm |
||
583 | * is disabled (@ref LL_RTC_ALMB_Disable function). |
||
584 | * @param RTCx RTC Instance |
||
585 | * @param RTC_Format This parameter can be one of the following values: |
||
586 | * @arg @ref LL_RTC_FORMAT_BIN |
||
587 | * @arg @ref LL_RTC_FORMAT_BCD |
||
588 | * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure that |
||
589 | * contains the alarm configuration parameters. |
||
590 | * @retval An ErrorStatus enumeration value: |
||
591 | * - SUCCESS: ALARMB registers are configured |
||
592 | * - ERROR: ALARMB registers are not configured |
||
593 | */ |
||
594 | ErrorStatus LL_RTC_ALMB_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_AlarmTypeDef *RTC_AlarmStruct) |
||
595 | { |
||
596 | /* Check the parameters */ |
||
597 | assert_param(IS_RTC_ALL_INSTANCE(RTCx)); |
||
598 | assert_param(IS_LL_RTC_FORMAT(RTC_Format)); |
||
599 | assert_param(IS_LL_RTC_ALMB_MASK(RTC_AlarmStruct->AlarmMask)); |
||
600 | assert_param(IS_LL_RTC_ALMB_DATE_WEEKDAY_SEL(RTC_AlarmStruct->AlarmDateWeekDaySel)); |
||
601 | |||
602 | if (RTC_Format == LL_RTC_FORMAT_BIN) |
||
603 | { |
||
604 | if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR) |
||
605 | { |
||
606 | assert_param(IS_LL_RTC_HOUR12(RTC_AlarmStruct->AlarmTime.Hours)); |
||
607 | assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat)); |
||
608 | } |
||
609 | else |
||
610 | { |
||
611 | RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U; |
||
612 | assert_param(IS_LL_RTC_HOUR24(RTC_AlarmStruct->AlarmTime.Hours)); |
||
613 | } |
||
614 | assert_param(IS_LL_RTC_MINUTES(RTC_AlarmStruct->AlarmTime.Minutes)); |
||
615 | assert_param(IS_LL_RTC_SECONDS(RTC_AlarmStruct->AlarmTime.Seconds)); |
||
616 | |||
617 | if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE) |
||
618 | { |
||
619 | assert_param(IS_LL_RTC_DAY(RTC_AlarmStruct->AlarmDateWeekDay)); |
||
620 | } |
||
621 | else |
||
622 | { |
||
623 | assert_param(IS_LL_RTC_WEEKDAY(RTC_AlarmStruct->AlarmDateWeekDay)); |
||
624 | } |
||
625 | } |
||
626 | else |
||
627 | { |
||
628 | if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR) |
||
629 | { |
||
630 | assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours))); |
||
631 | assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat)); |
||
632 | } |
||
633 | else |
||
634 | { |
||
635 | RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U; |
||
636 | assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours))); |
||
637 | } |
||
638 | |||
639 | assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Minutes))); |
||
640 | assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Seconds))); |
||
641 | |||
642 | if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE) |
||
643 | { |
||
644 | assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay))); |
||
645 | } |
||
646 | else |
||
647 | { |
||
648 | assert_param(IS_LL_RTC_WEEKDAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay))); |
||
649 | } |
||
650 | } |
||
651 | |||
652 | /* Disable the write protection for RTC registers */ |
||
653 | LL_RTC_DisableWriteProtection(RTCx); |
||
654 | |||
655 | /* Select weekday selection */ |
||
656 | if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE) |
||
657 | { |
||
658 | /* Set the date for ALARM */ |
||
659 | LL_RTC_ALMB_DisableWeekday(RTCx); |
||
660 | if (RTC_Format != LL_RTC_FORMAT_BIN) |
||
661 | { |
||
662 | LL_RTC_ALMB_SetDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay); |
||
663 | } |
||
664 | else |
||
665 | { |
||
666 | LL_RTC_ALMB_SetDay(RTCx, __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmDateWeekDay)); |
||
667 | } |
||
668 | } |
||
669 | else |
||
670 | { |
||
671 | /* Set the week day for ALARM */ |
||
672 | LL_RTC_ALMB_EnableWeekday(RTCx); |
||
673 | LL_RTC_ALMB_SetWeekDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay); |
||
674 | } |
||
675 | |||
676 | /* Configure the Alarm register */ |
||
677 | if (RTC_Format != LL_RTC_FORMAT_BIN) |
||
678 | { |
||
679 | LL_RTC_ALMB_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat, RTC_AlarmStruct->AlarmTime.Hours, |
||
680 | RTC_AlarmStruct->AlarmTime.Minutes, RTC_AlarmStruct->AlarmTime.Seconds); |
||
681 | } |
||
682 | else |
||
683 | { |
||
684 | LL_RTC_ALMB_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat, |
||
685 | __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Hours), |
||
686 | __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Minutes), |
||
687 | __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Seconds)); |
||
688 | } |
||
689 | /* Set ALARM mask */ |
||
690 | LL_RTC_ALMB_SetMask(RTCx, RTC_AlarmStruct->AlarmMask); |
||
691 | |||
692 | /* Enable the write protection for RTC registers */ |
||
693 | LL_RTC_EnableWriteProtection(RTCx); |
||
694 | |||
695 | return SUCCESS; |
||
696 | } |
||
697 | |||
698 | /** |
||
699 | * @brief Set each @ref LL_RTC_AlarmTypeDef of ALARMA field to default value (Time = 00h:00mn:00sec / |
||
700 | * Day = 1st day of the month/Mask = all fields are masked). |
||
701 | * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure which will be initialized. |
||
702 | * @retval None |
||
703 | */ |
||
704 | void LL_RTC_ALMA_StructInit(LL_RTC_AlarmTypeDef *RTC_AlarmStruct) |
||
705 | { |
||
706 | /* Alarm Time Settings : Time = 00h:00mn:00sec */ |
||
707 | RTC_AlarmStruct->AlarmTime.TimeFormat = LL_RTC_ALMA_TIME_FORMAT_AM; |
||
708 | RTC_AlarmStruct->AlarmTime.Hours = 0U; |
||
709 | RTC_AlarmStruct->AlarmTime.Minutes = 0U; |
||
710 | RTC_AlarmStruct->AlarmTime.Seconds = 0U; |
||
711 | |||
712 | /* Alarm Day Settings : Day = 1st day of the month */ |
||
713 | RTC_AlarmStruct->AlarmDateWeekDaySel = LL_RTC_ALMA_DATEWEEKDAYSEL_DATE; |
||
714 | RTC_AlarmStruct->AlarmDateWeekDay = 1U; |
||
715 | |||
716 | /* Alarm Masks Settings : Mask = all fields are not masked */ |
||
717 | RTC_AlarmStruct->AlarmMask = LL_RTC_ALMA_MASK_NONE; |
||
718 | } |
||
719 | |||
720 | /** |
||
721 | * @brief Set each @ref LL_RTC_AlarmTypeDef of ALARMA field to default value (Time = 00h:00mn:00sec / |
||
722 | * Day = 1st day of the month/Mask = all fields are masked). |
||
723 | * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure which will be initialized. |
||
724 | * @retval None |
||
725 | */ |
||
726 | void LL_RTC_ALMB_StructInit(LL_RTC_AlarmTypeDef *RTC_AlarmStruct) |
||
727 | { |
||
728 | /* Alarm Time Settings : Time = 00h:00mn:00sec */ |
||
729 | RTC_AlarmStruct->AlarmTime.TimeFormat = LL_RTC_ALMB_TIME_FORMAT_AM; |
||
730 | RTC_AlarmStruct->AlarmTime.Hours = 0U; |
||
731 | RTC_AlarmStruct->AlarmTime.Minutes = 0U; |
||
732 | RTC_AlarmStruct->AlarmTime.Seconds = 0U; |
||
733 | |||
734 | /* Alarm Day Settings : Day = 1st day of the month */ |
||
735 | RTC_AlarmStruct->AlarmDateWeekDaySel = LL_RTC_ALMB_DATEWEEKDAYSEL_DATE; |
||
736 | RTC_AlarmStruct->AlarmDateWeekDay = 1U; |
||
737 | |||
738 | /* Alarm Masks Settings : Mask = all fields are not masked */ |
||
739 | RTC_AlarmStruct->AlarmMask = LL_RTC_ALMB_MASK_NONE; |
||
740 | } |
||
741 | |||
742 | /** |
||
743 | * @brief Enters the RTC Initialization mode. |
||
744 | * @note The RTC Initialization mode is write protected, use the |
||
745 | * @ref LL_RTC_DisableWriteProtection before calling this function. |
||
746 | * @param RTCx RTC Instance |
||
747 | * @retval An ErrorStatus enumeration value: |
||
748 | * - SUCCESS: RTC is in Init mode |
||
749 | * - ERROR: RTC is not in Init mode |
||
750 | */ |
||
751 | ErrorStatus LL_RTC_EnterInitMode(RTC_TypeDef *RTCx) |
||
752 | { |
||
753 | __IO uint32_t timeout = RTC_INITMODE_TIMEOUT; |
||
754 | ErrorStatus status = SUCCESS; |
||
755 | uint32_t tmp; |
||
756 | |||
757 | /* Check the parameter */ |
||
758 | assert_param(IS_RTC_ALL_INSTANCE(RTCx)); |
||
759 | |||
760 | /* Check if the Initialization mode is set */ |
||
761 | if (LL_RTC_IsActiveFlag_INIT(RTCx) == 0U) |
||
762 | { |
||
763 | /* Set the Initialization mode */ |
||
764 | LL_RTC_EnableInitMode(RTCx); |
||
765 | |||
766 | /* Wait till RTC is in INIT state and if Time out is reached exit */ |
||
767 | tmp = LL_RTC_IsActiveFlag_INIT(RTCx); |
||
768 | while ((timeout != 0U) && (tmp != 1U)) |
||
769 | { |
||
770 | if (LL_SYSTICK_IsActiveCounterFlag() == 1U) |
||
771 | { |
||
772 | timeout --; |
||
773 | } |
||
774 | tmp = LL_RTC_IsActiveFlag_INIT(RTCx); |
||
775 | if (timeout == 0U) |
||
776 | { |
||
777 | status = ERROR; |
||
778 | } |
||
779 | } |
||
780 | } |
||
781 | return status; |
||
782 | } |
||
783 | |||
784 | /** |
||
785 | * @brief Exit the RTC Initialization mode. |
||
786 | * @note When the initialization sequence is complete, the calendar restarts |
||
787 | * counting after 4 RTCCLK cycles. |
||
788 | * @note The RTC Initialization mode is write protected, use the |
||
789 | * @ref LL_RTC_DisableWriteProtection before calling this function. |
||
790 | * @param RTCx RTC Instance |
||
791 | * @retval An ErrorStatus enumeration value: |
||
792 | * - SUCCESS: RTC exited from in Init mode |
||
793 | * - ERROR: Not applicable |
||
794 | */ |
||
795 | ErrorStatus LL_RTC_ExitInitMode(RTC_TypeDef *RTCx) |
||
796 | { |
||
797 | /* Check the parameter */ |
||
798 | assert_param(IS_RTC_ALL_INSTANCE(RTCx)); |
||
799 | |||
800 | /* Disable initialization mode */ |
||
801 | LL_RTC_DisableInitMode(RTCx); |
||
802 | |||
803 | return SUCCESS; |
||
804 | } |
||
805 | |||
806 | /** |
||
807 | * @brief Waits until the RTC Time and Day registers (RTC_TR and RTC_DR) are |
||
808 | * synchronized with RTC APB clock. |
||
809 | * @note The RTC Resynchronization mode is write protected, use the |
||
810 | * @ref LL_RTC_DisableWriteProtection before calling this function. |
||
811 | * @note To read the calendar through the shadow registers after Calendar |
||
812 | * initialization, calendar update or after wakeup from low power modes |
||
813 | * the software must first clear the RSF flag. |
||
814 | * The software must then wait until it is set again before reading |
||
815 | * the calendar, which means that the calendar registers have been |
||
816 | * correctly copied into the RTC_TR and RTC_DR shadow registers. |
||
817 | * @param RTCx RTC Instance |
||
818 | * @retval An ErrorStatus enumeration value: |
||
819 | * - SUCCESS: RTC registers are synchronised |
||
820 | * - ERROR: RTC registers are not synchronised |
||
821 | */ |
||
822 | ErrorStatus LL_RTC_WaitForSynchro(RTC_TypeDef *RTCx) |
||
823 | { |
||
824 | __IO uint32_t timeout = RTC_SYNCHRO_TIMEOUT; |
||
825 | ErrorStatus status = SUCCESS; |
||
826 | uint32_t tmp; |
||
827 | |||
828 | /* Check the parameter */ |
||
829 | assert_param(IS_RTC_ALL_INSTANCE(RTCx)); |
||
830 | |||
831 | /* Clear RSF flag */ |
||
832 | LL_RTC_ClearFlag_RS(RTCx); |
||
833 | |||
834 | /* Wait the registers to be synchronised */ |
||
835 | tmp = LL_RTC_IsActiveFlag_RS(RTCx); |
||
836 | while ((timeout != 0U) && (tmp != 0U)) |
||
837 | { |
||
838 | if (LL_SYSTICK_IsActiveCounterFlag() == 1U) |
||
839 | { |
||
840 | timeout--; |
||
841 | } |
||
842 | tmp = LL_RTC_IsActiveFlag_RS(RTCx); |
||
843 | if (timeout == 0U) |
||
844 | { |
||
845 | status = ERROR; |
||
846 | } |
||
847 | } |
||
848 | |||
849 | if (status != ERROR) |
||
850 | { |
||
851 | timeout = RTC_SYNCHRO_TIMEOUT; |
||
852 | tmp = LL_RTC_IsActiveFlag_RS(RTCx); |
||
853 | while ((timeout != 0U) && (tmp != 1U)) |
||
854 | { |
||
855 | if (LL_SYSTICK_IsActiveCounterFlag() == 1U) |
||
856 | { |
||
857 | timeout--; |
||
858 | } |
||
859 | tmp = LL_RTC_IsActiveFlag_RS(RTCx); |
||
860 | if (timeout == 0U) |
||
861 | { |
||
862 | status = ERROR; |
||
863 | } |
||
864 | } |
||
865 | } |
||
866 | |||
867 | return (status); |
||
868 | } |
||
869 | |||
870 | /** |
||
871 | * @} |
||
872 | */ |
||
873 | |||
874 | /** |
||
875 | * @} |
||
876 | */ |
||
877 | |||
878 | /** |
||
879 | * @} |
||
880 | */ |
||
881 | |||
882 | #endif /* defined(RTC) */ |
||
883 | |||
884 | /** |
||
885 | * @} |
||
886 | */ |
||
887 | |||
888 | #endif /* USE_FULL_LL_DRIVER */ |
||
889 | |||
890 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |