1 /**************************************************************************//**
\r
4 * @brief Real Time Clock(RTC) driver source file
\r
6 * @copyright (C) 2016 Nuvoton Technology Corp. All rights reserved.
\r
7 *****************************************************************************/
\r
11 /** @cond HIDDEN_SYMBOLS */
\r
13 /*---------------------------------------------------------------------------------------------------------*/
\r
14 /* Macro, type and constant definitions */
\r
15 /*---------------------------------------------------------------------------------------------------------*/
\r
18 /*---------------------------------------------------------------------------------------------------------*/
\r
19 /* Global file scope (static) variables */
\r
20 /*---------------------------------------------------------------------------------------------------------*/
\r
21 static volatile uint32_t g_u32hiYear, g_u32loYear, g_u32hiMonth, g_u32loMonth, g_u32hiDay, g_u32loDay;
\r
22 static volatile uint32_t g_u32hiHour, g_u32loHour, g_u32hiMin, g_u32loMin, g_u32hiSec, g_u32loSec;
\r
24 /** @endcond HIDDEN_SYMBOLS */
\r
27 /** @addtogroup Standard_Driver Standard Driver
\r
31 /** @addtogroup RTC_Driver RTC Driver
\r
35 /** @addtogroup RTC_EXPORTED_FUNCTIONS RTC Exported Functions
\r
40 * @brief Initialize RTC module and start counting
\r
42 * @param[in] sPt Specify the time property and current date and time. It includes: \n
\r
43 * u32Year: Year value, range between 2000 ~ 2099. \n
\r
44 * u32Month: Month value, range between 1 ~ 12. \n
\r
45 * u32Day: Day value, range between 1 ~ 31. \n
\r
46 * u32DayOfWeek: Day of the week. [RTC_SUNDAY / RTC_MONDAY / RTC_TUESDAY /
\r
47 * RTC_WEDNESDAY / RTC_THURSDAY / RTC_FRIDAY /
\r
49 * u32Hour: Hour value, range between 0 ~ 23. \n
\r
50 * u32Minute: Minute value, range between 0 ~ 59. \n
\r
51 * u32Second: Second value, range between 0 ~ 59. \n
\r
52 * u32TimeScale: [RTC_CLOCK_12 / RTC_CLOCK_24] \n
\r
53 * u8AmPm: [RTC_AM / RTC_PM] \n
\r
57 * @details This function is used to: \n
\r
58 * 1. Write initial key to let RTC start count. \n
\r
59 * 2. Input parameter indicates start date/time. \n
\r
60 * 3. User has to make sure that parameters of RTC date/time are reasonable. \n
\r
61 * @note Null pointer for using default starting date/time.
\r
63 void RTC_Open(S_RTC_TIME_DATA_T *sPt)
\r
67 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
76 pRTC->INIT = RTC_INIT_KEY;
\r
78 if(pRTC->INIT != RTC_INIT_ACTIVE_Msk)
\r
80 pRTC->INIT = RTC_INIT_KEY;
\r
81 while(pRTC->INIT != RTC_INIT_ACTIVE_Msk) {}
\r
86 ; /* No RTC date/time data */
\r
90 /* Set RTC date and time */
\r
91 RTC_SetDateAndTime(sPt);
\r
96 * @brief Disable RTC Clock
\r
102 * @details This API will disable RTC peripheral clock and stops RTC counting.
\r
104 void RTC_Close(void)
\r
106 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
108 ; /* Disable RTC clock in secure mode only */
\r
112 CLK->APBCLK0 &= ~CLK_APBCLK0_RTCCKEN_Msk;
\r
117 * @brief Set 32k Frequency Compensation Data
\r
119 * @param[in] i32FrequencyX10000 Specify the RTC clock X10000, ex: 327736512 means 32773.6512.
\r
123 * @details This API is used to compensate the 32 kHz frequency by current LXT frequency for RTC application.
\r
125 void RTC_32KCalibration(int32_t i32FrequencyX10000)
\r
127 uint64_t u64Compensate;
\r
130 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
139 /* u64Compensate = (uint64_t)(0x64000000000); */
\r
140 u64Compensate = (uint64_t)(0x2710000000000);
\r
141 u64Compensate = (uint64_t)(u64Compensate / (uint64_t)i32FrequencyX10000);
\r
143 Formula for 32K compensation is
\r
144 FREQADJ = 0x200000 * (32768 / LXT_freq)
\r
146 if(u64Compensate >= (uint64_t)0x400000)
\r
148 u64Compensate = (uint64_t)0x3FFFFF;
\r
151 RTC_WaitAccessEnable();
\r
152 pRTC->FREQADJ = (uint32_t)u64Compensate;
\r
156 * @brief Get Current RTC Date and Time
\r
158 * @param[out] sPt The returned pointer is specified the current RTC value. It includes: \n
\r
159 * u32Year: Year value \n
\r
160 * u32Month: Month value \n
\r
161 * u32Day: Day value \n
\r
162 * u32DayOfWeek: Day of week \n
\r
163 * u32Hour: Hour value \n
\r
164 * u32Minute: Minute value \n
\r
165 * u32Second: Second value \n
\r
166 * u32TimeScale: [RTC_CLOCK_12 / RTC_CLOCK_24] \n
\r
167 * u8AmPm: [RTC_AM / RTC_PM] \n
\r
171 * @details This API is used to get the current RTC date and time value.
\r
173 void RTC_GetDateAndTime(S_RTC_TIME_DATA_T *sPt)
\r
178 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
187 sPt->u32TimeScale = pRTC->CLKFMT & RTC_CLKFMT_24HEN_Msk; /* 12/24-hour */
\r
188 sPt->u32DayOfWeek = pRTC->WEEKDAY & RTC_WEEKDAY_WEEKDAY_Msk; /* Day of the week */
\r
190 /* Get [Date digit] data */
\r
191 g_u32hiYear = (pRTC->CAL & RTC_CAL_TENYEAR_Msk) >> RTC_CAL_TENYEAR_Pos;
\r
192 g_u32loYear = (pRTC->CAL & RTC_CAL_YEAR_Msk) >> RTC_CAL_YEAR_Pos;
\r
193 g_u32hiMonth = (pRTC->CAL & RTC_CAL_TENMON_Msk) >> RTC_CAL_TENMON_Pos;
\r
194 g_u32loMonth = (pRTC->CAL & RTC_CAL_MON_Msk) >> RTC_CAL_MON_Pos;
\r
195 g_u32hiDay = (pRTC->CAL & RTC_CAL_TENDAY_Msk) >> RTC_CAL_TENDAY_Pos;
\r
196 g_u32loDay = (pRTC->CAL & RTC_CAL_DAY_Msk) >> RTC_CAL_DAY_Pos;
\r
198 /* Get [Time digit] data */
\r
199 g_u32hiHour = (pRTC->TIME & RTC_TIME_TENHR_Msk) >> RTC_TIME_TENHR_Pos;
\r
200 g_u32loHour = (pRTC->TIME & RTC_TIME_HR_Msk) >> RTC_TIME_HR_Pos;
\r
201 g_u32hiMin = (pRTC->TIME & RTC_TIME_TENMIN_Msk) >> RTC_TIME_TENMIN_Pos;
\r
202 g_u32loMin = (pRTC->TIME & RTC_TIME_MIN_Msk) >> RTC_TIME_MIN_Pos;
\r
203 g_u32hiSec = (pRTC->TIME & RTC_TIME_TENSEC_Msk) >> RTC_TIME_TENSEC_Pos;
\r
204 g_u32loSec = (pRTC->TIME & RTC_TIME_SEC_Msk) >> RTC_TIME_SEC_Pos;
\r
206 /* Compute to 20XX year */
\r
207 u32Tmp = (g_u32hiYear * 10UL);
\r
208 u32Tmp += g_u32loYear;
\r
209 sPt->u32Year = u32Tmp + (uint32_t)RTC_YEAR2000;
\r
211 /* Compute 0~12 month */
\r
212 u32Tmp = (g_u32hiMonth * 10UL);
\r
213 sPt->u32Month = u32Tmp + g_u32loMonth;
\r
215 /* Compute 0~31 day */
\r
216 u32Tmp = (g_u32hiDay * 10UL);
\r
217 sPt->u32Day = u32Tmp + g_u32loDay;
\r
219 /* Compute 12/24 hour */
\r
220 if(sPt->u32TimeScale == (uint32_t)RTC_CLOCK_12)
\r
222 u32Tmp = (g_u32hiHour * 10UL);
\r
223 u32Tmp += g_u32loHour;
\r
224 sPt->u32Hour = u32Tmp; /* AM: 1~12. PM: 21~32. */
\r
226 if(sPt->u32Hour >= 21UL)
\r
228 sPt->u32AmPm = (uint32_t)RTC_PM;
\r
229 sPt->u32Hour -= 20UL;
\r
233 sPt->u32AmPm = (uint32_t)RTC_AM;
\r
236 u32Tmp = (g_u32hiMin * 10UL);
\r
237 u32Tmp += g_u32loMin;
\r
238 sPt->u32Minute = u32Tmp;
\r
240 u32Tmp = (g_u32hiSec * 10UL);
\r
241 u32Tmp += g_u32loSec;
\r
242 sPt->u32Second = u32Tmp;
\r
246 u32Tmp = (g_u32hiHour * 10UL);
\r
247 u32Tmp += g_u32loHour;
\r
248 sPt->u32Hour = u32Tmp;
\r
250 u32Tmp = (g_u32hiMin * 10UL);
\r
251 u32Tmp += g_u32loMin;
\r
252 sPt->u32Minute = u32Tmp;
\r
254 u32Tmp = (g_u32hiSec * 10UL);
\r
255 u32Tmp += g_u32loSec;
\r
256 sPt->u32Second = u32Tmp;
\r
261 * @brief Get RTC Alarm Date and Time
\r
263 * @param[out] sPt The returned pointer is specified the RTC alarm value. It includes: \n
\r
264 * u32Year: Year value \n
\r
265 * u32Month: Month value \n
\r
266 * u32Day: Day value \n
\r
267 * u32DayOfWeek: Day of week \n
\r
268 * u32Hour: Hour value \n
\r
269 * u32Minute: Minute value \n
\r
270 * u32Second: Second value \n
\r
271 * u32TimeScale: [RTC_CLOCK_12 / RTC_CLOCK_24] \n
\r
272 * u8AmPm: [RTC_AM / RTC_PM] \n
\r
276 * @details This API is used to get the RTC alarm date and time setting.
\r
278 void RTC_GetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt)
\r
283 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
292 sPt->u32TimeScale = pRTC->CLKFMT & RTC_CLKFMT_24HEN_Msk; /* 12/24-hour */
\r
293 sPt->u32DayOfWeek = pRTC->WEEKDAY & RTC_WEEKDAY_WEEKDAY_Msk; /* Day of the week */
\r
295 /* Get alarm [Date digit] data */
\r
296 RTC_WaitAccessEnable();
\r
297 g_u32hiYear = (pRTC->CALM & RTC_CALM_TENYEAR_Msk) >> RTC_CALM_TENYEAR_Pos;
\r
298 g_u32loYear = (pRTC->CALM & RTC_CALM_YEAR_Msk) >> RTC_CALM_YEAR_Pos;
\r
299 g_u32hiMonth = (pRTC->CALM & RTC_CALM_TENMON_Msk) >> RTC_CALM_TENMON_Pos;
\r
300 g_u32loMonth = (pRTC->CALM & RTC_CALM_MON_Msk) >> RTC_CALM_MON_Pos;
\r
301 g_u32hiDay = (pRTC->CALM & RTC_CALM_TENDAY_Msk) >> RTC_CALM_TENDAY_Pos;
\r
302 g_u32loDay = (pRTC->CALM & RTC_CALM_DAY_Msk) >> RTC_CALM_DAY_Pos;
\r
304 /* Get alarm [Time digit] data */
\r
305 RTC_WaitAccessEnable();
\r
306 g_u32hiHour = (pRTC->TALM & RTC_TALM_TENHR_Msk) >> RTC_TALM_TENHR_Pos;
\r
307 g_u32loHour = (pRTC->TALM & RTC_TALM_HR_Msk) >> RTC_TALM_HR_Pos;
\r
308 g_u32hiMin = (pRTC->TALM & RTC_TALM_TENMIN_Msk) >> RTC_TALM_TENMIN_Pos;
\r
309 g_u32loMin = (pRTC->TALM & RTC_TALM_MIN_Msk) >> RTC_TALM_MIN_Pos;
\r
310 g_u32hiSec = (pRTC->TALM & RTC_TALM_TENSEC_Msk) >> RTC_TALM_TENSEC_Pos;
\r
311 g_u32loSec = (pRTC->TALM & RTC_TALM_SEC_Msk) >> RTC_TALM_SEC_Pos;
\r
313 /* Compute to 20XX year */
\r
314 u32Tmp = (g_u32hiYear * 10UL);
\r
315 u32Tmp += g_u32loYear;
\r
316 sPt->u32Year = u32Tmp + (uint32_t)RTC_YEAR2000;
\r
318 /* Compute 0~12 month */
\r
319 u32Tmp = (g_u32hiMonth * 10UL);
\r
320 sPt->u32Month = u32Tmp + g_u32loMonth;
\r
322 /* Compute 0~31 day */
\r
323 u32Tmp = (g_u32hiDay * 10UL);
\r
324 sPt->u32Day = u32Tmp + g_u32loDay;
\r
326 /* Compute 12/24 hour */
\r
327 if(sPt->u32TimeScale == (uint32_t)RTC_CLOCK_12)
\r
329 u32Tmp = (g_u32hiHour * 10UL);
\r
330 u32Tmp += g_u32loHour;
\r
331 sPt->u32Hour = u32Tmp; /* AM: 1~12. PM: 21~32. */
\r
333 if(sPt->u32Hour >= 21UL)
\r
335 sPt->u32AmPm = (uint32_t)RTC_PM;
\r
336 sPt->u32Hour -= 20UL;
\r
340 sPt->u32AmPm = (uint32_t)RTC_AM;
\r
343 u32Tmp = (g_u32hiMin * 10UL);
\r
344 u32Tmp += g_u32loMin;
\r
345 sPt->u32Minute = u32Tmp;
\r
347 u32Tmp = (g_u32hiSec * 10UL);
\r
348 u32Tmp += g_u32loSec;
\r
349 sPt->u32Second = u32Tmp;
\r
353 u32Tmp = (g_u32hiHour * 10UL);
\r
354 u32Tmp += g_u32loHour;
\r
355 sPt->u32Hour = u32Tmp;
\r
357 u32Tmp = (g_u32hiMin * 10UL);
\r
358 u32Tmp += g_u32loMin;
\r
359 sPt->u32Minute = u32Tmp;
\r
361 u32Tmp = (g_u32hiSec * 10UL);
\r
362 u32Tmp += g_u32loSec;
\r
363 sPt->u32Second = u32Tmp;
\r
368 * @brief Update Current RTC Date and Time
\r
370 * @param[in] sPt Specify the time property and current date and time. It includes: \n
\r
371 * u32Year: Year value, range between 2000 ~ 2099. \n
\r
372 * u32Month: Month value, range between 1 ~ 12. \n
\r
373 * u32Day: Day value, range between 1 ~ 31. \n
\r
374 * u32DayOfWeek: Day of the week. [RTC_SUNDAY / RTC_MONDAY / RTC_TUESDAY /
\r
375 * RTC_WEDNESDAY / RTC_THURSDAY / RTC_FRIDAY /
\r
377 * u32Hour: Hour value, range between 0 ~ 23. \n
\r
378 * u32Minute: Minute value, range between 0 ~ 59. \n
\r
379 * u32Second: Second value, range between 0 ~ 59. \n
\r
380 * u32TimeScale: [RTC_CLOCK_12 / RTC_CLOCK_24] \n
\r
381 * u8AmPm: [RTC_AM / RTC_PM] \n
\r
385 * @details This API is used to update current date and time to RTC.
\r
387 void RTC_SetDateAndTime(S_RTC_TIME_DATA_T *sPt)
\r
389 uint32_t u32RegCAL, u32RegTIME;
\r
392 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
403 ; /* No RTC date/time data */
\r
407 /*-----------------------------------------------------------------------------------------------------*/
\r
408 /* Set RTC 24/12 hour setting and Day of the Week */
\r
409 /*-----------------------------------------------------------------------------------------------------*/
\r
410 RTC_WaitAccessEnable();
\r
411 if(sPt->u32TimeScale == (uint32_t)RTC_CLOCK_12)
\r
413 pRTC->CLKFMT &= ~RTC_CLKFMT_24HEN_Msk;
\r
415 /*-------------------------------------------------------------------------------------------------*/
\r
416 /* Important, range of 12-hour PM mode is 21 up to 32 */
\r
417 /*-------------------------------------------------------------------------------------------------*/
\r
418 if(sPt->u32AmPm == (uint32_t)RTC_PM)
\r
420 sPt->u32Hour += 20UL;
\r
425 pRTC->CLKFMT |= RTC_CLKFMT_24HEN_Msk;
\r
428 /* Set Day of the Week */
\r
429 pRTC->WEEKDAY = sPt->u32DayOfWeek;
\r
431 /*-----------------------------------------------------------------------------------------------------*/
\r
432 /* Set RTC Current Date and Time */
\r
433 /*-----------------------------------------------------------------------------------------------------*/
\r
434 u32RegCAL = ((sPt->u32Year - (uint32_t)RTC_YEAR2000) / 10UL) << 20;
\r
435 u32RegCAL |= (((sPt->u32Year - (uint32_t)RTC_YEAR2000) % 10UL) << 16);
\r
436 u32RegCAL |= ((sPt->u32Month / 10UL) << 12);
\r
437 u32RegCAL |= ((sPt->u32Month % 10UL) << 8);
\r
438 u32RegCAL |= ((sPt->u32Day / 10UL) << 4);
\r
439 u32RegCAL |= (sPt->u32Day % 10UL);
\r
441 u32RegTIME = ((sPt->u32Hour / 10UL) << 20);
\r
442 u32RegTIME |= ((sPt->u32Hour % 10UL) << 16);
\r
443 u32RegTIME |= ((sPt->u32Minute / 10UL) << 12);
\r
444 u32RegTIME |= ((sPt->u32Minute % 10UL) << 8);
\r
445 u32RegTIME |= ((sPt->u32Second / 10UL) << 4);
\r
446 u32RegTIME |= (sPt->u32Second % 10UL);
\r
448 /*-----------------------------------------------------------------------------------------------------*/
\r
449 /* Set RTC Calender and Time Loading */
\r
450 /*-----------------------------------------------------------------------------------------------------*/
\r
451 RTC_WaitAccessEnable();
\r
452 pRTC->CAL = (uint32_t)u32RegCAL;
\r
453 RTC_WaitAccessEnable();
\r
454 pRTC->TIME = (uint32_t)u32RegTIME;
\r
459 * @brief Update RTC Alarm Date and Time
\r
461 * @param[in] sPt Specify the time property and alarm date and time. It includes: \n
\r
462 * u32Year: Year value, range between 2000 ~ 2099. \n
\r
463 * u32Month: Month value, range between 1 ~ 12. \n
\r
464 * u32Day: Day value, range between 1 ~ 31. \n
\r
465 * u32DayOfWeek: Day of the week. [RTC_SUNDAY / RTC_MONDAY / RTC_TUESDAY /
\r
466 * RTC_WEDNESDAY / RTC_THURSDAY / RTC_FRIDAY /
\r
468 * u32Hour: Hour value, range between 0 ~ 23. \n
\r
469 * u32Minute: Minute value, range between 0 ~ 59. \n
\r
470 * u32Second: Second value, range between 0 ~ 59. \n
\r
471 * u32TimeScale: [RTC_CLOCK_12 / RTC_CLOCK_24] \n
\r
472 * u8AmPm: [RTC_AM / RTC_PM] \n
\r
476 * @details This API is used to update alarm date and time setting to RTC.
\r
478 void RTC_SetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt)
\r
480 uint32_t u32RegCALM, u32RegTALM;
\r
483 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
494 ; /* No RTC date/time data */
\r
498 /*-----------------------------------------------------------------------------------------------------*/
\r
499 /* Set RTC 24/12 hour setting and Day of the Week */
\r
500 /*-----------------------------------------------------------------------------------------------------*/
\r
501 RTC_WaitAccessEnable();
\r
502 if(sPt->u32TimeScale == (uint32_t)RTC_CLOCK_12)
\r
504 pRTC->CLKFMT &= ~RTC_CLKFMT_24HEN_Msk;
\r
506 /*-------------------------------------------------------------------------------------------------*/
\r
507 /* Important, range of 12-hour PM mode is 21 up to 32 */
\r
508 /*-------------------------------------------------------------------------------------------------*/
\r
509 if(sPt->u32AmPm == (uint32_t)RTC_PM)
\r
511 sPt->u32Hour += 20UL;
\r
516 pRTC->CLKFMT |= RTC_CLKFMT_24HEN_Msk;
\r
519 /*-----------------------------------------------------------------------------------------------------*/
\r
520 /* Set RTC Alarm Date and Time */
\r
521 /*-----------------------------------------------------------------------------------------------------*/
\r
522 u32RegCALM = ((sPt->u32Year - (uint32_t)RTC_YEAR2000) / 10UL) << 20;
\r
523 u32RegCALM |= (((sPt->u32Year - (uint32_t)RTC_YEAR2000) % 10UL) << 16);
\r
524 u32RegCALM |= ((sPt->u32Month / 10UL) << 12);
\r
525 u32RegCALM |= ((sPt->u32Month % 10UL) << 8);
\r
526 u32RegCALM |= ((sPt->u32Day / 10UL) << 4);
\r
527 u32RegCALM |= (sPt->u32Day % 10UL);
\r
529 u32RegTALM = ((sPt->u32Hour / 10UL) << 20);
\r
530 u32RegTALM |= ((sPt->u32Hour % 10UL) << 16);
\r
531 u32RegTALM |= ((sPt->u32Minute / 10UL) << 12);
\r
532 u32RegTALM |= ((sPt->u32Minute % 10UL) << 8);
\r
533 u32RegTALM |= ((sPt->u32Second / 10UL) << 4);
\r
534 u32RegTALM |= (sPt->u32Second % 10UL);
\r
536 RTC_WaitAccessEnable();
\r
537 pRTC->CALM = (uint32_t)u32RegCALM;
\r
538 RTC_WaitAccessEnable();
\r
539 pRTC->TALM = (uint32_t)u32RegTALM;
\r
544 * @brief Update RTC Current Date
\r
546 * @param[in] u32Year The year calendar digit of current RTC setting.
\r
547 * @param[in] u32Month The month calendar digit of current RTC setting.
\r
548 * @param[in] u32Day The day calendar digit of current RTC setting.
\r
549 * @param[in] u32DayOfWeek The Day of the week. [RTC_SUNDAY / RTC_MONDAY / RTC_TUESDAY /
\r
550 * RTC_WEDNESDAY / RTC_THURSDAY / RTC_FRIDAY /
\r
555 * @details This API is used to update current date to RTC.
\r
557 void RTC_SetDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day, uint32_t u32DayOfWeek)
\r
559 uint32_t u32RegCAL;
\r
562 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
571 u32RegCAL = ((u32Year - (uint32_t)RTC_YEAR2000) / 10UL) << 20;
\r
572 u32RegCAL |= (((u32Year - (uint32_t)RTC_YEAR2000) % 10UL) << 16);
\r
573 u32RegCAL |= ((u32Month / 10UL) << 12);
\r
574 u32RegCAL |= ((u32Month % 10UL) << 8);
\r
575 u32RegCAL |= ((u32Day / 10UL) << 4);
\r
576 u32RegCAL |= (u32Day % 10UL);
\r
578 RTC_WaitAccessEnable();
\r
580 /* Set Day of the Week */
\r
581 pRTC->WEEKDAY = u32DayOfWeek & RTC_WEEKDAY_WEEKDAY_Msk;
\r
583 /* Set RTC Calender Loading */
\r
584 RTC_WaitAccessEnable();
\r
585 pRTC->CAL = (uint32_t)u32RegCAL;
\r
589 * @brief Update RTC Current Time
\r
591 * @param[in] u32Hour The hour time digit of current RTC setting.
\r
592 * @param[in] u32Minute The minute time digit of current RTC setting.
\r
593 * @param[in] u32Second The second time digit of current RTC setting.
\r
594 * @param[in] u32TimeMode The 24-Hour / 12-Hour Time Scale Selection. [RTC_CLOCK_12 / RTC_CLOCK_24]
\r
595 * @param[in] u32AmPm 12-hour time scale with AM and PM indication. Only Time Scale select 12-hour used. [RTC_AM / RTC_PM]
\r
599 * @details This API is used to update current time to RTC.
\r
601 void RTC_SetTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm)
\r
603 uint32_t u32RegTIME;
\r
606 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
615 /* Important, range of 12-hour PM mode is 21 up to 32 */
\r
616 if((u32TimeMode == (uint32_t)RTC_CLOCK_12) && (u32AmPm == (uint32_t)RTC_PM))
\r
621 u32RegTIME = ((u32Hour / 10UL) << 20);
\r
622 u32RegTIME |= ((u32Hour % 10UL) << 16);
\r
623 u32RegTIME |= ((u32Minute / 10UL) << 12);
\r
624 u32RegTIME |= ((u32Minute % 10UL) << 8);
\r
625 u32RegTIME |= ((u32Second / 10UL) << 4);
\r
626 u32RegTIME |= (u32Second % 10UL);
\r
628 /*-----------------------------------------------------------------------------------------------------*/
\r
629 /* Set RTC 24/12 hour setting and Day of the Week */
\r
630 /*-----------------------------------------------------------------------------------------------------*/
\r
631 RTC_WaitAccessEnable();
\r
632 if(u32TimeMode == (uint32_t)RTC_CLOCK_12)
\r
634 pRTC->CLKFMT &= ~RTC_CLKFMT_24HEN_Msk;
\r
638 pRTC->CLKFMT |= RTC_CLKFMT_24HEN_Msk;
\r
641 RTC_WaitAccessEnable();
\r
642 pRTC->TIME = (uint32_t)u32RegTIME;
\r
646 * @brief Update RTC Alarm Date
\r
648 * @param[in] u32Year The year calendar digit of RTC alarm setting.
\r
649 * @param[in] u32Month The month calendar digit of RTC alarm setting.
\r
650 * @param[in] u32Day The day calendar digit of RTC alarm setting.
\r
654 * @details This API is used to update alarm date setting to RTC.
\r
656 void RTC_SetAlarmDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day)
\r
658 uint32_t u32RegCALM;
\r
661 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
670 u32RegCALM = ((u32Year - (uint32_t)RTC_YEAR2000) / 10UL) << 20;
\r
671 u32RegCALM |= (((u32Year - (uint32_t)RTC_YEAR2000) % 10UL) << 16);
\r
672 u32RegCALM |= ((u32Month / 10UL) << 12);
\r
673 u32RegCALM |= ((u32Month % 10UL) << 8);
\r
674 u32RegCALM |= ((u32Day / 10UL) << 4);
\r
675 u32RegCALM |= (u32Day % 10UL);
\r
677 RTC_WaitAccessEnable();
\r
679 /* Set RTC Alarm Date */
\r
680 pRTC->CALM = (uint32_t)u32RegCALM;
\r
684 * @brief Update RTC Alarm Time
\r
686 * @param[in] u32Hour The hour time digit of RTC alarm setting.
\r
687 * @param[in] u32Minute The minute time digit of RTC alarm setting.
\r
688 * @param[in] u32Second The second time digit of RTC alarm setting.
\r
689 * @param[in] u32TimeMode The 24-Hour / 12-Hour Time Scale Selection. [RTC_CLOCK_12 / RTC_CLOCK_24]
\r
690 * @param[in] u32AmPm 12-hour time scale with AM and PM indication. Only Time Scale select 12-hour used. [RTC_AM / RTC_PM]
\r
694 * @details This API is used to update alarm time setting to RTC.
\r
696 void RTC_SetAlarmTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm)
\r
698 uint32_t u32RegTALM;
\r
701 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
710 /* Important, range of 12-hour PM mode is 21 up to 32 */
\r
711 if((u32TimeMode == (uint32_t)RTC_CLOCK_12) && (u32AmPm == (uint32_t)RTC_PM))
\r
716 u32RegTALM = ((u32Hour / 10UL) << 20);
\r
717 u32RegTALM |= ((u32Hour % 10UL) << 16);
\r
718 u32RegTALM |= ((u32Minute / 10UL) << 12);
\r
719 u32RegTALM |= ((u32Minute % 10UL) << 8);
\r
720 u32RegTALM |= ((u32Second / 10UL) << 4);
\r
721 u32RegTALM |= (u32Second % 10UL);
\r
723 /*-----------------------------------------------------------------------------------------------------*/
\r
724 /* Set RTC 24/12 hour setting and Day of the Week */
\r
725 /*-----------------------------------------------------------------------------------------------------*/
\r
726 RTC_WaitAccessEnable();
\r
727 if(u32TimeMode == (uint32_t)RTC_CLOCK_12)
\r
729 pRTC->CLKFMT &= ~RTC_CLKFMT_24HEN_Msk;
\r
733 pRTC->CLKFMT |= RTC_CLKFMT_24HEN_Msk;
\r
736 /* Set RTC Alarm Time */
\r
737 RTC_WaitAccessEnable();
\r
738 pRTC->TALM = (uint32_t)u32RegTALM;
\r
742 * @brief Set RTC Alarm Date Mask Function
\r
744 * @param[in] u8IsTenYMsk 1: enable 10-Year digit alarm mask; 0: disabled.
\r
745 * @param[in] u8IsYMsk 1: enable 1-Year digit alarm mask; 0: disabled.
\r
746 * @param[in] u8IsTenMMsk 1: enable 10-Mon digit alarm mask; 0: disabled.
\r
747 * @param[in] u8IsMMsk 1: enable 1-Mon digit alarm mask; 0: disabled.
\r
748 * @param[in] u8IsTenDMsk 1: enable 10-Day digit alarm mask; 0: disabled.
\r
749 * @param[in] u8IsDMsk 1: enable 1-Day digit alarm mask; 0: disabled.
\r
753 * @details This API is used to enable or disable RTC alarm date mask function.
\r
755 void RTC_SetAlarmDateMask(uint8_t u8IsTenYMsk, uint8_t u8IsYMsk, uint8_t u8IsTenMMsk, uint8_t u8IsMMsk, uint8_t u8IsTenDMsk, uint8_t u8IsDMsk)
\r
759 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
768 RTC_WaitAccessEnable();
\r
769 pRTC->CAMSK = ((uint32_t)u8IsTenYMsk << RTC_CAMSK_MTENYEAR_Pos) |
\r
770 ((uint32_t)u8IsYMsk << RTC_CAMSK_MYEAR_Pos) |
\r
771 ((uint32_t)u8IsTenMMsk << RTC_CAMSK_MTENMON_Pos) |
\r
772 ((uint32_t)u8IsMMsk << RTC_CAMSK_MMON_Pos) |
\r
773 ((uint32_t)u8IsTenDMsk << RTC_CAMSK_MTENDAY_Pos) |
\r
774 ((uint32_t)u8IsDMsk << RTC_CAMSK_MDAY_Pos);
\r
778 * @brief Set RTC Alarm Time Mask Function
\r
780 * @param[in] u8IsTenHMsk 1: enable 10-Hour digit alarm mask; 0: disabled.
\r
781 * @param[in] u8IsHMsk 1: enable 1-Hour digit alarm mask; 0: disabled.
\r
782 * @param[in] u8IsTenMMsk 1: enable 10-Min digit alarm mask; 0: disabled.
\r
783 * @param[in] u8IsMMsk 1: enable 1-Min digit alarm mask; 0: disabled.
\r
784 * @param[in] u8IsTenSMsk 1: enable 10-Sec digit alarm mask; 0: disabled.
\r
785 * @param[in] u8IsSMsk 1: enable 1-Sec digit alarm mask; 0: disabled.
\r
789 * @details This API is used to enable or disable RTC alarm time mask function.
\r
791 void RTC_SetAlarmTimeMask(uint8_t u8IsTenHMsk, uint8_t u8IsHMsk, uint8_t u8IsTenMMsk, uint8_t u8IsMMsk, uint8_t u8IsTenSMsk, uint8_t u8IsSMsk)
\r
795 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
804 RTC_WaitAccessEnable();
\r
805 pRTC->TAMSK = ((uint32_t)u8IsTenHMsk << RTC_TAMSK_MTENHR_Pos) |
\r
806 ((uint32_t)u8IsHMsk << RTC_TAMSK_MHR_Pos) |
\r
807 ((uint32_t)u8IsTenMMsk << RTC_TAMSK_MTENMIN_Pos) |
\r
808 ((uint32_t)u8IsMMsk << RTC_TAMSK_MMIN_Pos) |
\r
809 ((uint32_t)u8IsTenSMsk << RTC_TAMSK_MTENSEC_Pos) |
\r
810 ((uint32_t)u8IsSMsk << RTC_TAMSK_MSEC_Pos);
\r
814 * @brief Get Day of the Week
\r
820 * @retval 2 Tuesday
\r
821 * @retval 3 Wednesday
\r
822 * @retval 4 Thursday
\r
824 * @retval 6 Saturday
\r
826 * @details This API is used to get day of the week of current RTC date.
\r
828 uint32_t RTC_GetDayOfWeek(void)
\r
832 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
841 return (pRTC->WEEKDAY & RTC_WEEKDAY_WEEKDAY_Msk);
\r
845 * @brief Set RTC Tick Period Time
\r
847 * @param[in] u32TickSelection It is used to set the RTC tick period time for Periodic Time Tick request. \n
\r
849 * - \ref RTC_TICK_1_SEC : Time tick is 1 second
\r
850 * - \ref RTC_TICK_1_2_SEC : Time tick is 1/2 second
\r
851 * - \ref RTC_TICK_1_4_SEC : Time tick is 1/4 second
\r
852 * - \ref RTC_TICK_1_8_SEC : Time tick is 1/8 second
\r
853 * - \ref RTC_TICK_1_16_SEC : Time tick is 1/16 second
\r
854 * - \ref RTC_TICK_1_32_SEC : Time tick is 1/32 second
\r
855 * - \ref RTC_TICK_1_64_SEC : Time tick is 1/64 second
\r
856 * - \ref RTC_TICK_1_128_SEC : Time tick is 1/128 second
\r
860 * @details This API is used to set RTC tick period time for each tick interrupt.
\r
862 void RTC_SetTickPeriod(uint32_t u32TickSelection)
\r
866 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
875 RTC_WaitAccessEnable();
\r
877 pRTC->TICK = (pRTC->TICK & ~RTC_TICK_TICK_Msk) | u32TickSelection;
\r
881 * @brief Enable RTC Interrupt
\r
883 * @param[in] u32IntFlagMask Specify the interrupt source. It consists of:
\r
884 * - \ref RTC_INTEN_ALMIEN_Msk : Alarm interrupt
\r
885 * - \ref RTC_INTEN_TICKIEN_Msk : Tick interrupt
\r
886 * - \ref RTC_INTEN_TAMP0IEN_Msk : Tamper 0 Pin Event Detection interrupt
\r
887 * - \ref RTC_INTEN_TAMP1IEN_Msk : Tamper 1 or Pair 0 Pin Event Detection interrupt
\r
888 * - \ref RTC_INTEN_TAMP2IEN_Msk : Tamper 2 Pin Event Detection interrupt
\r
889 * - \ref RTC_INTEN_TAMP3IEN_Msk : Tamper 3 or Pair 1 Pin Event Detection interrupt
\r
890 * - \ref RTC_INTEN_TAMP4IEN_Msk : Tamper 4 Pin Event Detection interrupt
\r
891 * - \ref RTC_INTEN_TAMP5IEN_Msk : Tamper 5 or Pair 2 Pin Event Detection interrupt
\r
892 * - \ref RTC_INTEN_CLKFIEN_Msk : LXT Clock Frequency Monitor Fail interrupt
\r
893 * - \ref RTC_INTEN_CLKSPIEN_Msk : LXT Clock Frequency Monitor Stop interrupt
\r
897 * @details This API is used to enable the specify RTC interrupt function.
\r
899 void RTC_EnableInt(uint32_t u32IntFlagMask)
\r
903 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
912 pRTC->INTEN |= u32IntFlagMask;
\r
916 * @brief Disable RTC Interrupt
\r
918 * @param[in] u32IntFlagMask Specify the interrupt source. It consists of:
\r
919 * - \ref RTC_INTEN_ALMIEN_Msk : Alarm interrupt
\r
920 * - \ref RTC_INTEN_TICKIEN_Msk : Tick interrupt
\r
921 * - \ref RTC_INTEN_TAMP0IEN_Msk : Tamper 0 Pin Event Detection interrupt
\r
922 * - \ref RTC_INTEN_TAMP1IEN_Msk : Tamper 1 or Pair 0 Pin Event Detection interrupt
\r
923 * - \ref RTC_INTEN_TAMP2IEN_Msk : Tamper 2 Pin Event Detection interrupt
\r
924 * - \ref RTC_INTEN_TAMP3IEN_Msk : Tamper 3 or Pair 1 Pin Event Detection interrupt
\r
925 * - \ref RTC_INTEN_TAMP4IEN_Msk : Tamper 4 Pin Event Detection interrupt
\r
926 * - \ref RTC_INTEN_TAMP5IEN_Msk : Tamper 5 or Pair 2 Pin Event Detection interrupt
\r
927 * - \ref RTC_INTEN_CLKFIEN_Msk : LXT Clock Frequency Monitor Fail interrupt
\r
928 * - \ref RTC_INTEN_CLKSPIEN_Msk : LXT Clock Frequency Monitor Stop interrupt
\r
932 * @details This API is used to disable the specify RTC interrupt function.
\r
934 void RTC_DisableInt(uint32_t u32IntFlagMask)
\r
938 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
947 pRTC->INTEN &= ~u32IntFlagMask;
\r
948 pRTC->INTSTS = u32IntFlagMask;
\r
952 * @brief Enable Spare Registers Access
\r
958 * @details This API is used to enable the spare registers 0~19 can be accessed.
\r
960 void RTC_EnableSpareAccess(void)
\r
964 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
973 RTC_WaitAccessEnable();
\r
975 pRTC->SPRCTL |= RTC_SPRCTL_SPRRWEN_Msk;
\r
979 * @brief Disable Spare Register
\r
985 * @details This API is used to disable the spare register 0~19 cannot be accessed.
\r
987 void RTC_DisableSpareRegister(void)
\r
991 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
1000 RTC_WaitAccessEnable();
\r
1002 pRTC->SPRCTL &= ~RTC_SPRCTL_SPRRWEN_Msk;
\r
1006 * @brief Static Tamper Detect
\r
1008 * @param[in] u32TamperSelect Tamper pin select. Possible options are
\r
1009 * - \ref RTC_TAMPER5_SELECT
\r
1010 * - \ref RTC_TAMPER4_SELECT
\r
1011 * - \ref RTC_TAMPER3_SELECT
\r
1012 * - \ref RTC_TAMPER2_SELECT
\r
1013 * - \ref RTC_TAMPER1_SELECT
\r
1014 * - \ref RTC_TAMPER0_SELECT
\r
1016 * @param[in] u32DetecLevel Tamper pin detection level select. Possible options are
\r
1017 * - \ref RTC_TAMPER_HIGH_LEVEL_DETECT
\r
1018 * - \ref RTC_TAMPER_LOW_LEVEL_DETECT
\r
1020 * @param[in] u32DebounceEn Tamper pin de-bounce enable
\r
1021 * - \ref RTC_TAMPER_DEBOUNCE_ENABLE
\r
1022 * - \ref RTC_TAMPER_DEBOUNCE_DISABLE
\r
1026 * @details This API is used to enable the tamper pin detect function with specify trigger condition.
\r
1027 * User need disable dynamic tamper function before use this API.
\r
1029 void RTC_StaticTamperEnable(uint32_t u32TamperSelect, uint32_t u32DetecLevel, uint32_t u32DebounceEn)
\r
1033 uint32_t u32TmpReg;
\r
1036 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
1045 RTC_WaitAccessEnable();
\r
1046 u32Reg = pRTC->TAMPCTL;
\r
1048 u32TmpReg = (RTC_TAMPCTL_TAMP0EN_Msk | (u32DetecLevel << RTC_TAMPCTL_TAMP0LV_Pos) |
\r
1049 (u32DebounceEn << RTC_TAMPCTL_TAMP0DBEN_Pos));
\r
1051 for(i = 0UL; i < (uint32_t)MAX_TAMPER_PIN_NUM; i++)
\r
1053 if(u32TamperSelect & (0x1UL << i))
\r
1055 u32Reg &= ~((RTC_TAMPCTL_TAMP0EN_Msk | RTC_TAMPCTL_TAMP0LV_Msk | RTC_TAMPCTL_TAMP0DBEN_Msk) << (i * 4UL));
\r
1056 u32Reg |= (u32TmpReg << (i * 4UL));
\r
1060 RTC_WaitAccessEnable();
\r
1061 pRTC->TAMPCTL = u32Reg;
\r
1066 * @brief Static Tamper Disable
\r
1068 * @param[in] u32TamperSelect Tamper pin select. Possible options are
\r
1069 * - \ref RTC_TAMPER5_SELECT
\r
1070 * - \ref RTC_TAMPER4_SELECT
\r
1071 * - \ref RTC_TAMPER3_SELECT
\r
1072 * - \ref RTC_TAMPER2_SELECT
\r
1073 * - \ref RTC_TAMPER1_SELECT
\r
1074 * - \ref RTC_TAMPER0_SELECT
\r
1078 * @details This API is used to disable the static tamper pin detect.
\r
1080 void RTC_StaticTamperDisable(uint32_t u32TamperSelect)
\r
1084 uint32_t u32TmpReg;
\r
1087 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
1096 RTC_WaitAccessEnable();
\r
1097 u32Reg = pRTC->TAMPCTL;
\r
1099 u32TmpReg = (RTC_TAMPCTL_TAMP0EN_Msk);
\r
1101 for(i = 0UL; i < (uint32_t)MAX_TAMPER_PIN_NUM; i++)
\r
1103 if(u32TamperSelect & (0x1UL << i))
\r
1105 u32Reg &= ~(u32TmpReg << (i * 4UL));
\r
1109 RTC_WaitAccessEnable();
\r
1110 pRTC->TAMPCTL = u32Reg;
\r
1114 * @brief Dynamic Tamper Detect
\r
1116 * @param[in] u32PairSel Tamper pin detection enable. Possible options are
\r
1117 * - \ref RTC_PAIR0_SELECT
\r
1118 * - \ref RTC_PAIR1_SELECT
\r
1119 * - \ref RTC_PAIR2_SELECT
\r
1121 * @param[in] u32DebounceEn Tamper pin de-bounce enable
\r
1122 * - \ref RTC_TAMPER_DEBOUNCE_ENABLE
\r
1123 * - \ref RTC_TAMPER_DEBOUNCE_DISABLE
\r
1125 * @param[in] u32Pair1Source Dynamic Pair 1 Input Source Select
\r
1126 * 0: Pair 1 source select tamper 2
\r
1127 * 1: Pair 1 source select tamper 0
\r
1129 * @param[in] u32Pair2Source Dynamic Pair 2 Input Source Select
\r
1130 * 0: Pair 2 source select tamper 4
\r
1131 * 1: Pair 2 source select tamper 0
\r
1135 * @details This API is used to enable the dynamic tamper.
\r
1137 void RTC_DynamicTamperEnable(uint32_t u32PairSel, uint32_t u32DebounceEn, uint32_t u32Pair1Source, uint32_t u32Pair2Source)
\r
1141 uint32_t u32TmpReg;
\r
1142 uint32_t u32Tamper2Debounce, u32Tamper4Debounce;
\r
1145 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
1154 RTC_WaitAccessEnable();
\r
1155 u32Reg = pRTC->TAMPCTL;
\r
1156 u32Reg &= ~(RTC_TAMPCTL_TAMP0EN_Msk | RTC_TAMPCTL_TAMP1EN_Msk | RTC_TAMPCTL_TAMP2EN_Msk |
\r
1157 RTC_TAMPCTL_TAMP3EN_Msk | RTC_TAMPCTL_TAMP4EN_Msk | RTC_TAMPCTL_TAMP5EN_Msk);
\r
1159 u32Tamper2Debounce = u32Reg & RTC_TAMPCTL_TAMP2DBEN_Msk;
\r
1160 u32Tamper4Debounce = u32Reg & RTC_TAMPCTL_TAMP4DBEN_Msk;
\r
1162 u32Reg &= ~(RTC_TAMPCTL_TAMP0EN_Msk | RTC_TAMPCTL_TAMP1EN_Msk | RTC_TAMPCTL_TAMP2EN_Msk |
\r
1163 RTC_TAMPCTL_TAMP3EN_Msk | RTC_TAMPCTL_TAMP4EN_Msk | RTC_TAMPCTL_TAMP5EN_Msk);
\r
1164 u32Reg &= ~(RTC_TAMPCTL_DYN1ISS_Msk | RTC_TAMPCTL_DYN2ISS_Msk);
\r
1165 u32Reg |= ((u32Pair1Source & 0x1UL) << RTC_TAMPCTL_DYN1ISS_Pos) | ((u32Pair2Source & 0x1UL) << RTC_TAMPCTL_DYN2ISS_Pos);
\r
1169 u32TmpReg = (RTC_TAMPCTL_TAMP0EN_Msk | RTC_TAMPCTL_TAMP1EN_Msk |
\r
1170 RTC_TAMPCTL_TAMP0DBEN_Msk | RTC_TAMPCTL_TAMP1DBEN_Msk | RTC_TAMPCTL_DYNPR0EN_Msk);
\r
1174 u32TmpReg = (RTC_TAMPCTL_TAMP0EN_Msk | RTC_TAMPCTL_TAMP1EN_Msk | RTC_TAMPCTL_DYNPR0EN_Msk);
\r
1177 for(i = 0UL; i < (uint32_t)MAX_PAIR_NUM; i++)
\r
1179 if(u32PairSel & (0x1UL << i))
\r
1181 u32Reg &= ~((RTC_TAMPCTL_TAMP0DBEN_Msk | RTC_TAMPCTL_TAMP1DBEN_Msk) << (i * 8UL));
\r
1182 u32Reg |= (u32TmpReg << (i * 8UL));
\r
1186 if((u32Pair1Source) && (u32PairSel & (uint32_t)RTC_PAIR1_SELECT))
\r
1188 u32Reg &= ~RTC_TAMPCTL_TAMP2EN_Msk;
\r
1189 u32Reg |= u32Tamper2Debounce;
\r
1192 if((u32Pair2Source) && (u32PairSel & (uint32_t)RTC_PAIR2_SELECT))
\r
1194 u32Reg &= ~RTC_TAMPCTL_TAMP4EN_Msk;
\r
1195 u32Reg |= u32Tamper4Debounce;
\r
1198 RTC_WaitAccessEnable();
\r
1199 pRTC->TAMPCTL = u32Reg;
\r
1203 * @brief Dynamic Tamper Disable
\r
1205 * @param[in] u32PairSel Tamper pin detection enable. Possible options are
\r
1206 * - \ref RTC_PAIR0_SELECT
\r
1207 * - \ref RTC_PAIR1_SELECT
\r
1208 * - \ref RTC_PAIR2_SELECT
\r
1212 * @details This API is used to disable the dynamic tamper.
\r
1214 void RTC_DynamicTamperDisable(uint32_t u32PairSel)
\r
1218 uint32_t u32TmpReg;
\r
1219 uint32_t u32Tamper2En = 0UL, u32Tamper4En = 0UL;
\r
1222 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
1231 RTC_WaitAccessEnable();
\r
1232 u32Reg = pRTC->TAMPCTL;
\r
1234 if((u32Reg & (uint32_t)RTC_TAMPCTL_DYN1ISS_Msk) && (u32PairSel & (uint32_t)RTC_PAIR1_SELECT))
\r
1236 u32Tamper2En = u32Reg & RTC_TAMPCTL_TAMP2EN_Msk;
\r
1239 if((u32Reg & (uint32_t)RTC_TAMPCTL_DYN2ISS_Msk) && (u32PairSel & (uint32_t)RTC_PAIR2_SELECT))
\r
1241 u32Tamper4En = u32Reg & RTC_TAMPCTL_TAMP4EN_Msk;
\r
1244 u32TmpReg = (RTC_TAMPCTL_TAMP0EN_Msk | RTC_TAMPCTL_TAMP1EN_Msk | RTC_TAMPCTL_DYNPR0EN_Msk);
\r
1246 for(i = 0UL; i < (uint32_t)MAX_PAIR_NUM; i++)
\r
1248 if(u32PairSel & (0x1UL << i))
\r
1250 u32Reg &= ~(u32TmpReg << ((i * 8UL)));
\r
1254 u32Reg |= (u32Tamper2En | u32Tamper4En);
\r
1256 RTC_WaitAccessEnable();
\r
1257 pRTC->TAMPCTL = u32Reg;
\r
1261 * @brief Config dynamic tamper
\r
1263 * @param[in] u32ChangeRate The dynamic tamper output change rate
\r
1264 * - \ref RTC_2POW10_CLK
\r
1265 * - \ref RTC_2POW11_CLK
\r
1266 * - \ref RTC_2POW12_CLK
\r
1267 * - \ref RTC_2POW13_CLK
\r
1268 * - \ref RTC_2POW14_CLK
\r
1269 * - \ref RTC_2POW15_CLK
\r
1270 * - \ref RTC_2POW16_CLK
\r
1271 * - \ref RTC_2POW17_CLK
\r
1273 * @param[in] u32SeedReload Reload new seed or not
\r
1274 * 0: not reload new seed
\r
1275 * 1: reload new seed
\r
1277 * @param[in] u32RefPattern Reference pattern
\r
1278 * - \ref REF_RANDOM_PATTERN
\r
1279 * - \ref REF_PREVIOUS_PATTERN
\r
1282 * @param[in] u32Seed Seed Value (0x0 ~ 0xFFFFFFFF)
\r
1286 * @details This API is used to config dynamic tamper setting.
\r
1288 void RTC_DynamicTamperConfig(uint32_t u32ChangeRate, uint32_t u32SeedReload, uint32_t u32RefPattern, uint32_t u32Seed)
\r
1293 if((__PC()&NS_OFFSET) == NS_OFFSET)
\r
1302 RTC_WaitAccessEnable();
\r
1303 u32Reg = pRTC->TAMPCTL;
\r
1305 u32Reg &= ~(RTC_TAMPCTL_DYNSRC_Msk | RTC_TAMPCTL_SEEDRLD_Msk | RTC_TAMPCTL_DYNRATE_Msk);
\r
1307 u32Reg |= (u32ChangeRate) | ((u32SeedReload & 0x1UL) << RTC_TAMPCTL_SEEDRLD_Pos) |
\r
1308 ((u32RefPattern & 0x3UL) << RTC_TAMPCTL_DYNSRC_Pos);
\r
1310 RTC_WaitAccessEnable();
\r
1311 pRTC->TAMPSEED = u32Seed; /* need set seed value before re-loade seed */
\r
1312 pRTC->TAMPCTL = u32Reg;
\r
1315 /*@}*/ /* end of group RTC_EXPORTED_FUNCTIONS */
\r
1317 /*@}*/ /* end of group RTC_Driver */
\r
1319 /*@}*/ /* end of group Standard_Driver */
\r
1321 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
\r