| Nano102_112 Series BSP V3.03.002 The Board Support Package for Nano102_112 Series

rtc.c
Go to the documentation of this file.
1 /**************************************************************************/
14 #include <stdio.h>
15 #include "Nano1X2Series.h"
16
17 /*---------------------------------------------------------------------------------------------------------*/
18 /* Includes of local headers */
19 /*---------------------------------------------------------------------------------------------------------*/
20
21
22
30
32 /*---------------------------------------------------------------------------------------------------------*/
33 /* Macro, type and constant definitions */
34 /*---------------------------------------------------------------------------------------------------------*/
35 #define RTC_GLOBALS
36
37 /*---------------------------------------------------------------------------------------------------------*/
38 /* Global file scope (static) variables */
39 /*---------------------------------------------------------------------------------------------------------*/
40 static volatile uint32_t g_u32Reg, g_u32Reg1,g_u32hiYear,g_u32loYear,g_u32hiMonth,g_u32loMonth,g_u32hiDay,g_u32loDay;
41 static volatile uint32_t g_u32hiHour,g_u32loHour,g_u32hiMin,g_u32loMin,g_u32hiSec,g_u32loSec;
42
44
58 void RTC_32KCalibration(int32_t i32FrequencyX10000)
59 {
60 uint64_t u64Compensate;
61
62 //u64Compensate = (uint64_t)(0x64000000000);
63 u64Compensate = (uint64_t)(0x2710000000000);
64 u64Compensate = (uint64_t)(u64Compensate / (uint64_t)i32FrequencyX10000);
65
66 if(u64Compensate >= 0x400000)
67 {
68 u64Compensate = 0x3FFFFF;
69 }
70
71 RTC->AER = RTC_WRITE_KEY;
72 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
73
74 RTC->FCR = (uint32_t)u64Compensate;
75
76 }
77
101 void RTC_Open (S_RTC_TIME_DATA_T *sPt)
102 {
103 uint32_t u32Reg;
104
105 RTC->INIR = RTC_INIT_KEY;
106
107 if(RTC->INIR != 0x1)
108 {
109 RTC->INIR = RTC_INIT_KEY;
110
111 while(RTC->INIR != 0x1);
112 }
113
114 if(sPt == NULL)
115 return;
116
117 /*-----------------------------------------------------------------------------------------------------*/
118 /* Second, set RTC 24/12 hour setting */
119 /*-----------------------------------------------------------------------------------------------------*/
120 if (sPt->u32TimeScale == RTC_CLOCK_12)
121 {
122 RTC->AER = RTC_WRITE_KEY;
123 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
124 RTC->TSSR &= ~RTC_TSSR_24H_12H_Msk;
125
126 /*-------------------------------------------------------------------------------------------------*/
127 /* important, range of 12-hour PM mode is 21 up to 32 */
128 /*-------------------------------------------------------------------------------------------------*/
129 if (sPt->u32AmPm == RTC_PM)
130 sPt->u32Hour += 20;
131 }
132 else
133 {
134 RTC->AER = RTC_WRITE_KEY;
135 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
136 RTC->TSSR |= RTC_TSSR_24H_12H_Msk;
137 }
138
139 /*-----------------------------------------------------------------------------------------------------*/
140 /* Set RTC Calender Loading */
141 /*-----------------------------------------------------------------------------------------------------*/
142 u32Reg = ((sPt->u32Year - RTC_YEAR2000) / 10) << 20;
143 u32Reg |= (((sPt->u32Year - RTC_YEAR2000) % 10) << 16);
144 u32Reg |= ((sPt->u32Month / 10) << 12);
145 u32Reg |= ((sPt->u32Month % 10) << 8);
146 u32Reg |= ((sPt->u32Day / 10) << 4);
147 u32Reg |= (sPt->u32Day % 10);
148 g_u32Reg = u32Reg;
149
150 RTC->AER = RTC_WRITE_KEY;
151 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
152
153 RTC->CLR = (uint32_t)g_u32Reg;
154
155 /*-----------------------------------------------------------------------------------------------------*/
156 /* Set RTC Time Loading */
157 /*-----------------------------------------------------------------------------------------------------*/
158 u32Reg = ((sPt->u32Hour / 10) << 20);
159 u32Reg |= ((sPt->u32Hour % 10) << 16);
160 u32Reg |= ((sPt->u32Minute / 10) << 12);
161 u32Reg |= ((sPt->u32Minute % 10) << 8);
162 u32Reg |= ((sPt->u32Second / 10) << 4);
163 u32Reg |= (sPt->u32Second % 10);
164 g_u32Reg = u32Reg;
165
166 RTC->AER = RTC_WRITE_KEY;
167 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
168
169 RTC->TLR = (uint32_t)g_u32Reg;
170
171 RTC->DWR = sPt->u32DayOfWeek;
172
173 }
174
193 void RTC_GetDateAndTime(S_RTC_TIME_DATA_T *sPt)
194 {
195 uint32_t u32Tmp;
196
197 sPt->u32TimeScale = RTC->TSSR & RTC_TSSR_24H_12H_Msk; /* 12/24-hour */
198 sPt->u32DayOfWeek = RTC->DWR & RTC_DWR_DWR_Msk; /* Day of week */
199
200 g_u32hiYear = (RTC->CLR & RTC_CLR_10YEAR_Msk) >> RTC_CLR_10YEAR_Pos;
201 g_u32loYear = (RTC->CLR & RTC_CLR_1YEAR_Msk) >> RTC_CLR_1YEAR_Pos;
202 g_u32hiMonth = (RTC->CLR & RTC_CLR_10MON_Msk) >> RTC_CLR_10MON_Pos;
203 g_u32loMonth = (RTC->CLR & RTC_CLR_1MON_Msk) >> RTC_CLR_1MON_Pos;
204 g_u32hiDay = (RTC->CLR & RTC_CLR_10DAY_Msk) >> RTC_CLR_10DAY_Pos;
205 g_u32loDay = (RTC->CLR & RTC_CLR_1DAY_Msk);
206
207 g_u32hiHour = (RTC->TLR & RTC_TLR_10HR_Msk) >> RTC_TLR_10HR_Pos;
208 g_u32loHour = (RTC->TLR & RTC_TLR_1HR_Msk) >> RTC_TLR_1HR_Pos;
209 g_u32hiMin = (RTC->TLR & RTC_TLR_10MIN_Msk) >> RTC_TLR_10MIN_Pos;
210 g_u32loMin = (RTC->TLR & RTC_TLR_1MIN_Msk) >> RTC_TLR_1MIN_Pos;
211 g_u32hiSec = (RTC->TLR & RTC_TLR_10SEC_Msk) >> RTC_TLR_10SEC_Pos;
212 g_u32loSec = (RTC->TLR & RTC_TLR_1SEC_Msk);
213
214 u32Tmp = (g_u32hiYear * 10); /* Compute to 20XX year */
215 u32Tmp += g_u32loYear;
216 sPt->u32Year = u32Tmp + RTC_YEAR2000;
217
218 u32Tmp = (g_u32hiMonth * 10); /* Compute 0~12 month */
219 sPt->u32Month = u32Tmp + g_u32loMonth;
220
221 u32Tmp = (g_u32hiDay * 10); /* Compute 0~31 day */
222 sPt->u32Day = u32Tmp + g_u32loDay;
223
224 if (sPt->u32TimeScale == RTC_CLOCK_12) /* Compute12/24 hour */
225 {
226 u32Tmp = (g_u32hiHour * 10);
227 u32Tmp+= g_u32loHour;
228 sPt->u32Hour = u32Tmp; /* AM: 1~12. PM: 21~32. */
229
230 if (sPt->u32Hour >= 21)
231 {
232 sPt->u32AmPm = RTC_PM;
233 sPt->u32Hour -= 20;
234 }
235 else
236 {
237 sPt->u32AmPm = RTC_AM;
238 }
239
240 u32Tmp = (g_u32hiMin * 10);
241 u32Tmp+= g_u32loMin;
242 sPt->u32Minute = u32Tmp;
243
244 u32Tmp = (g_u32hiSec * 10);
245 u32Tmp+= g_u32loSec;
246 sPt->u32Second = u32Tmp;
247
248 }
249 else
250 {
251 u32Tmp = (g_u32hiHour * 10);
252 u32Tmp += g_u32loHour;
253 sPt->u32Hour = u32Tmp;
254
255 u32Tmp = (g_u32hiMin * 10);
256 u32Tmp += g_u32loMin;
257 sPt->u32Minute = u32Tmp;
258
259 u32Tmp = (g_u32hiSec * 10);
260 u32Tmp += g_u32loSec;
261 sPt->u32Second = u32Tmp;
262 }
263
264 }
265
266
267
286 void RTC_GetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt)
287 {
288 uint32_t u32Tmp;
289
290 sPt->u32TimeScale = RTC->TSSR & RTC_TSSR_24H_12H_Msk; /* 12/24-hour */
291 sPt->u32DayOfWeek = RTC->DWR & RTC_DWR_DWR_Msk; /* Day of week */
292
293 RTC->AER = RTC_WRITE_KEY;
294 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
295
296 g_u32hiYear = (RTC->CAR & RTC_CAR_10YEAR_Msk) >> RTC_CAR_10YEAR_Pos;
297 g_u32loYear = (RTC->CAR & RTC_CAR_1YEAR_Msk) >> RTC_CAR_1YEAR_Pos;
298 g_u32hiMonth = (RTC->CAR & RTC_CAR_10MON_Msk) >> RTC_CAR_10MON_Pos;
299 g_u32loMonth = (RTC->CAR & RTC_CAR_1MON_Msk) >> RTC_CAR_1MON_Pos;
300 g_u32hiDay = (RTC->CAR & RTC_CAR_10DAY_Msk) >> RTC_CAR_10DAY_Pos;
301 g_u32loDay = (RTC->CAR & RTC_CAR_1DAY_Msk);
302
303 RTC->AER = RTC_WRITE_KEY;
304 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
305
306 g_u32hiHour = (RTC->TAR & RTC_TAR_10HR_Msk) >> RTC_TAR_10HR_Pos;
307 g_u32loHour = (RTC->TAR & RTC_TAR_1HR_Msk) >> RTC_TAR_1HR_Pos;
308 g_u32hiMin = (RTC->TAR & RTC_TAR_10MIN_Msk) >> RTC_TAR_10MIN_Pos;
309 g_u32loMin = (RTC->TAR & RTC_TAR_1MIN_Msk) >> RTC_TAR_1MIN_Pos;
310 g_u32hiSec = (RTC->TAR & RTC_TAR_10SEC_Msk) >> RTC_TAR_10SEC_Pos;
311 g_u32loSec = (RTC->TAR & RTC_TAR_1SEC_Msk);
312
313 u32Tmp = (g_u32hiYear * 10); /* Compute to 20XX year */
314 u32Tmp += g_u32loYear;
315 sPt->u32Year = u32Tmp + RTC_YEAR2000;
316
317 u32Tmp = (g_u32hiMonth * 10); /* Compute 0~12 month */
318 sPt->u32Month = u32Tmp + g_u32loMonth;
319
320 u32Tmp = (g_u32hiDay * 10); /* Compute 0~31 day */
321 sPt->u32Day = u32Tmp + g_u32loDay;
322
323 if (sPt->u32TimeScale == RTC_CLOCK_12) /* Compute12/24 hour */
324 {
325 u32Tmp = (g_u32hiHour * 10);
326 u32Tmp += g_u32loHour;
327 sPt->u32Hour = u32Tmp; /* AM: 1~12. PM: 21~32. */
328
329 if (sPt->u32Hour >= 21)
330 {
331 sPt->u32AmPm = RTC_PM;
332 sPt->u32Hour -= 20;
333 }
334 else
335 {
336 sPt->u32AmPm = RTC_AM;
337 }
338
339 u32Tmp = (g_u32hiMin * 10);
340 u32Tmp += g_u32loMin;
341 sPt->u32Minute = u32Tmp;
342
343 u32Tmp = (g_u32hiSec * 10);
344 u32Tmp += g_u32loSec;
345 sPt->u32Second = u32Tmp;
346
347 }
348 else
349 {
350 u32Tmp = (g_u32hiHour * 10);
351 u32Tmp += g_u32loHour;
352 sPt->u32Hour = u32Tmp;
353
354 u32Tmp = (g_u32hiMin * 10);
355 u32Tmp+= g_u32loMin;
356 sPt->u32Minute = u32Tmp;
357
358 u32Tmp = (g_u32hiSec * 10);
359 u32Tmp += g_u32loSec;
360 sPt->u32Second = u32Tmp;
361 }
362
363 }
364
365
366
389 void RTC_SetDateAndTime(S_RTC_TIME_DATA_T *sPt)
390 {
391 uint32_t u32Reg;
392
393 RTC->AER = RTC_WRITE_KEY;
394 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
395
396 if (sPt->u32TimeScale == RTC_CLOCK_12)
397 {
398 RTC->TSSR &= ~RTC_TSSR_24H_12H_Msk;
399
400 /*-----------------------------------------------------------------------------------------*/
401 /* important, range of 12-hour PM mode is 21 upto 32 */
402 /*-----------------------------------------------------------------------------------------*/
403 if (sPt->u32AmPm == RTC_PM)
404 sPt->u32Hour += 20;
405 }
406 else
407 {
408 RTC->TSSR |= RTC_TSSR_24H_12H_Msk;
409 }
410
411 RTC->DWR = sPt->u32DayOfWeek & RTC_DWR_DWR_Msk;
412
413 u32Reg = ((sPt->u32Year - RTC_YEAR2000) / 10) << 20;
414 u32Reg |= (((sPt->u32Year - RTC_YEAR2000) % 10) << 16);
415 u32Reg |= ((sPt->u32Month / 10) << 12);
416 u32Reg |= ((sPt->u32Month % 10) << 8);
417 u32Reg |= ((sPt->u32Day / 10) << 4);
418 u32Reg |= (sPt->u32Day % 10);
419 g_u32Reg = u32Reg;
420
421 RTC->AER = RTC_WRITE_KEY;
422 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
423
424 RTC->CLR = (uint32_t)g_u32Reg;
425
426 u32Reg = ((sPt->u32Hour / 10) << 20);
427 u32Reg |= ((sPt->u32Hour % 10) << 16);
428 u32Reg |= ((sPt->u32Minute / 10) << 12);
429 u32Reg |= ((sPt->u32Minute % 10) << 8);
430 u32Reg |= ((sPt->u32Second / 10) << 4);
431 u32Reg |= (sPt->u32Second % 10);
432 g_u32Reg = u32Reg;
433
434 RTC->AER = RTC_WRITE_KEY;
435 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
436
437 RTC->TLR = (uint32_t)g_u32Reg;
438
439 }
440
461 void RTC_SetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt)
462 {
463 uint32_t u32Reg;
464
465 RTC->AER = RTC_WRITE_KEY;
466 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
467
468 if (sPt->u32TimeScale == RTC_CLOCK_12)
469 {
470 RTC->TSSR &= ~RTC_TSSR_24H_12H_Msk;
471
472 /*-----------------------------------------------------------------------------------------*/
473 /* important, range of 12-hour PM mode is 21 up to 32 */
474 /*-----------------------------------------------------------------------------------------*/
475 if (sPt->u32AmPm == RTC_PM)
476 sPt->u32Hour += 20;
477 }
478 else
479 {
480 RTC->TSSR |= RTC_TSSR_24H_12H_Msk;
481 }
482
483 RTC->DWR = sPt->u32DayOfWeek & RTC_DWR_DWR_Msk;
484
485
486 u32Reg = ((sPt->u32Year - RTC_YEAR2000) / 10) << 20;
487 u32Reg |= (((sPt->u32Year - RTC_YEAR2000) % 10) << 16);
488 u32Reg |= ((sPt->u32Month / 10) << 12);
489 u32Reg |= ((sPt->u32Month % 10) << 8);
490 u32Reg |= ((sPt->u32Day / 10) << 4);
491 u32Reg |= (sPt->u32Day % 10);
492 g_u32Reg = u32Reg;
493
494 RTC->AER = RTC_WRITE_KEY;
495 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
496
497 RTC->CAR = (uint32_t)g_u32Reg;
498
499 u32Reg = ((sPt->u32Hour / 10) << 20);
500 u32Reg |= ((sPt->u32Hour % 10) << 16);
501 u32Reg |= ((sPt->u32Minute / 10) << 12);
502 u32Reg |= ((sPt->u32Minute % 10) << 8);
503 u32Reg |= ((sPt->u32Second / 10) << 4);
504 u32Reg |= (sPt->u32Second % 10);
505 g_u32Reg = u32Reg;
506
507 RTC->AER = RTC_WRITE_KEY;
508 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
509
510 RTC->TAR = (uint32_t)g_u32Reg;
511
512 }
513
514
528 void RTC_SetDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day, uint32_t u32DayOfWeek)
529 {
530 __IO uint32_t u32Reg;
531
532 RTC->AER = RTC_WRITE_KEY;
533 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
534
535 RTC->DWR = u32DayOfWeek & RTC_DWR_DWR_Msk;
536
537 u32Reg = ((u32Year - RTC_YEAR2000) / 10) << 20;
538 u32Reg |= (((u32Year - RTC_YEAR2000) % 10) << 16);
539 u32Reg |= ((u32Month / 10) << 12);
540 u32Reg |= ((u32Month % 10) << 8);
541 u32Reg |= ((u32Day / 10) << 4);
542 u32Reg |= (u32Day % 10);
543 g_u32Reg = u32Reg;
544
545 RTC->AER = RTC_WRITE_KEY;
546 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
547
548 RTC->CLR = (uint32_t)g_u32Reg;
549
550 }
551
564 void RTC_SetTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm)
565 {
566 __IO uint32_t u32Reg;
567
568 RTC->AER = RTC_WRITE_KEY;
569 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
570
571 if (u32TimeMode == RTC_CLOCK_12)
572 {
573 RTC->TSSR &= ~RTC_TSSR_24H_12H_Msk;
574
575 if (u32AmPm == RTC_PM) /* important, range of 12-hour PM mode is 21 upto 32 */
576 u32Hour += 20;
577 }
578 else if(u32TimeMode == RTC_CLOCK_24)
579 {
580 RTC->TSSR |= RTC_TSSR_24H_12H_Msk;
581 }
582
583 u32Reg = ((u32Hour / 10) << 20);
584 u32Reg |= ((u32Hour % 10) << 16);
585 u32Reg |= ((u32Minute / 10) << 12);
586 u32Reg |= ((u32Minute % 10) << 8);
587 u32Reg |= ((u32Second / 10) << 4);
588 u32Reg |= (u32Second % 10);
589
590 g_u32Reg = u32Reg;
591
592 RTC->AER = RTC_WRITE_KEY;
593 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
594
595 RTC->TLR = (uint32_t)g_u32Reg;
596
597 }
598
609 void RTC_SetAlarmDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day)
610 {
611 __IO uint32_t u32Reg;
612
613 RTC->AER = RTC_WRITE_KEY;
614 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
615
616 u32Reg = ((u32Year - RTC_YEAR2000) / 10) << 20;
617 u32Reg |= (((u32Year - RTC_YEAR2000) % 10) << 16);
618 u32Reg |= ((u32Month / 10) << 12);
619 u32Reg |= ((u32Month % 10) << 8);
620 u32Reg |= ((u32Day / 10) << 4);
621 u32Reg |= (u32Day % 10);
622 g_u32Reg = u32Reg;
623
624 RTC->AER = RTC_WRITE_KEY;
625 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
626
627 RTC->CAR = (uint32_t)g_u32Reg;
628
629 }
630
643 void RTC_SetAlarmTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm)
644 {
645 __IO uint32_t u32Reg;
646
647 RTC->AER = RTC_WRITE_KEY;
648 while(!(RTC->AER & RTC_AER_ENF_Msk));
649
650 if (u32TimeMode == RTC_CLOCK_12)
651 {
652 RTC->TSSR &= ~RTC_TSSR_24H_12H_Msk;
653
654 if (u32AmPm == RTC_PM) /* important, range of 12-hour PM mode is 21 up to 32 */
655 u32Hour += 20;
656 }
657 else if(u32TimeMode == RTC_CLOCK_24)
658 {
659 RTC->TSSR |= RTC_TSSR_24H_12H_Msk;
660 }
661
662 u32Reg = ((u32Hour / 10) << 20);
663 u32Reg |= ((u32Hour % 10) << 16);
664 u32Reg |= ((u32Minute / 10) << 12);
665 u32Reg |= ((u32Minute % 10) << 8);
666 u32Reg |= ((u32Second / 10) << 4);
667 u32Reg |= (u32Second % 10);
668
669 g_u32Reg = u32Reg;
670
671 RTC->AER = RTC_WRITE_KEY;
672 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
673
674 RTC->TAR = (uint32_t)g_u32Reg;
675
676 }
677
678
689 void RTC_EnableTamperDetection(uint32_t u32PinCondition)
690 {
691 RTC->AER = RTC_WRITE_KEY;
692 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
693
694 /* detection edge select */
695 if(u32PinCondition)
696 RTC->SPRCTL |= RTC_SPRCTL_SNOOPEDGE_Msk;
697 else
698 RTC->SPRCTL &= ~RTC_SPRCTL_SNOOPEDGE_Msk;
699
700 /* enable snooper pin event detection */
701 RTC->SPRCTL |= RTC_SPRCTL_SNOOPEN_Msk;
702 }
703
712 void RTC_DisableTamperDetection(void)
713 {
714 RTC->AER = RTC_WRITE_KEY;
715 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
716
717 RTC->SPRCTL &= ~RTC_SPRCTL_SNOOPEN_Msk;
718 }
719
728 uint32_t RTC_GetDayOfWeek(void)
729 {
730 return (RTC->DWR & RTC_DWR_DWR_Msk);
731 }
732
733
752 void RTC_SetTickPeriod(uint32_t u32TickSelection)
753 {
754 RTC->AER = RTC_WRITE_KEY;
755 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
756
757 RTC->TTR = RTC->TTR & ~RTC_TTR_TTR_Msk | u32TickSelection;
758 }
759
771 void RTC_EnableInt(uint32_t u32IntFlagMask)
772 {
773 RTC->AER = RTC_WRITE_KEY;
774 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
775
776 RTC->RIER |= u32IntFlagMask;
777 }
778
790 void RTC_DisableInt(uint32_t u32IntFlagMask)
791 {
792 RTC->AER = RTC_WRITE_KEY;
793 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
794
795 if(u32IntFlagMask & RTC_RIER_TIER_Msk)
796 {
797 RTC->RIER &= ~RTC_RIER_TIER_Msk;
798 RTC->RIIR = RTC_RIIR_TIF_Msk;
799 }
800
801 if(u32IntFlagMask & RTC_RIER_AIER_Msk)
802 {
803 RTC->RIER &= ~RTC_RIER_AIER_Msk;
804 RTC->RIIR = RTC_RIIR_AIF_Msk;
805 }
806
807 if(u32IntFlagMask & RTC_RIER_SNOOPIER_Msk)
808 {
809 RTC->RIER &= ~RTC_RIER_SNOOPIER_Msk;
810 RTC->RIIR = RTC_RIIR_SNOOPIF_Msk;
811 }
812
813 }
814
821 void RTC_Close (void)
822 {
823 CLK->APBCLK &= ~CLK_APBCLK_RTC_EN_Msk;
824 }
825
826 /* end of group NANO1X2_RTC_EXPORTED_FUNCTIONS */
828 /* end of group NANO1X2_RTC_Driver */
830 /* end of group NANO1X2_Device_Driver */
832
833 /*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/
834
835
RTC_GetAlarmDateAndTime
void RTC_GetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt)
Read alarm date/time from RTC setting.
Definition: rtc.c:286
RTC_SetDate
void RTC_SetDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day, uint32_t u32DayOfWeek)
This function is used to update date to RTC.
Definition: rtc.c:528
RTC_TLR_10HR_Msk
#define RTC_TLR_10HR_Msk
Definition: Nano1X2Series.h:7378
RTC_SPRCTL_SNOOPEN_Msk
#define RTC_SPRCTL_SNOOPEN_Msk
Definition: Nano1X2Series.h:7468
RTC_CAR_10MON_Pos
#define RTC_CAR_10MON_Pos
Definition: Nano1X2Series.h:7431
RTC_CAR_1YEAR_Msk
#define RTC_CAR_1YEAR_Msk
Definition: Nano1X2Series.h:7435
RTC_EnableTamperDetection
void RTC_EnableTamperDetection(uint32_t u32PinCondition)
This function is used to: .
Definition: rtc.c:689
RTC_TLR_1HR_Pos
#define RTC_TLR_1HR_Pos
Definition: Nano1X2Series.h:7374
CLK
#define CLK
Pointer to CLK register structure.
Definition: Nano1X2Series.h:10651
RTC_DisableInt
void RTC_DisableInt(uint32_t u32IntFlagMask)
The function is used to disable specified interrupt.
Definition: rtc.c:790
S_RTC_TIME_DATA_T::u32Hour
uint32_t u32Hour
Definition: rtc.h:86
RTC_WRITE_KEY
#define RTC_WRITE_KEY
Definition: rtc.h:36
RTC_CLR_10YEAR_Msk
#define RTC_CLR_10YEAR_Msk
Definition: Nano1X2Series.h:7396
RTC
#define RTC
Pointer to RTC register structure.
Definition: Nano1X2Series.h:10632
RTC_CLOCK_12
#define RTC_CLOCK_12
Definition: rtc.h:43
RTC_TLR_1MIN_Msk
#define RTC_TLR_1MIN_Msk
Definition: Nano1X2Series.h:7369
RTC_CLR_10DAY_Pos
#define RTC_CLR_10DAY_Pos
Definition: Nano1X2Series.h:7383
RTC_DWR_DWR_Msk
#define RTC_DWR_DWR_Msk
Definition: Nano1X2Series.h:7402
RTC_TAR_10SEC_Msk
#define RTC_TAR_10SEC_Msk
Definition: Nano1X2Series.h:7408
RTC_RIIR_AIF_Msk
#define RTC_RIIR_AIF_Msk
Definition: Nano1X2Series.h:7453
S_RTC_TIME_DATA_T::u32Year
uint32_t u32Year
Definition: rtc.h:82
RTC_TLR_1MIN_Pos
#define RTC_TLR_1MIN_Pos
Definition: Nano1X2Series.h:7368
RTC_TAR_10HR_Pos
#define RTC_TAR_10HR_Pos
Definition: Nano1X2Series.h:7419
RTC_TAR_1MIN_Msk
#define RTC_TAR_1MIN_Msk
Definition: Nano1X2Series.h:7411
CLK_APBCLK_RTC_EN_Msk
#define CLK_APBCLK_RTC_EN_Msk
Definition: Nano1X2Series.h:1493
RTC_TLR_10HR_Pos
#define RTC_TLR_10HR_Pos
Definition: Nano1X2Series.h:7377
NULL
#define NULL
NULL pointer.
Definition: Nano1X2Series.h:10812
RTC_CLR_10DAY_Msk
#define RTC_CLR_10DAY_Msk
Definition: Nano1X2Series.h:7384
RTC_TAR_1SEC_Msk
#define RTC_TAR_1SEC_Msk
Definition: Nano1X2Series.h:7405
RTC_CLR_10YEAR_Pos
#define RTC_CLR_10YEAR_Pos
Definition: Nano1X2Series.h:7395
RTC_TLR_1SEC_Msk
#define RTC_TLR_1SEC_Msk
Definition: Nano1X2Series.h:7363
RTC_SetTickPeriod
void RTC_SetTickPeriod(uint32_t u32TickSelection)
The function is used to set time tick period for periodic time tick Interrupt.
Definition: rtc.c:752
RTC_SetAlarmTime
void RTC_SetAlarmTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm)
This function is used to set alarm date to RTC.
Definition: rtc.c:643
RTC_CAR_1MON_Msk
#define RTC_CAR_1MON_Msk
Definition: Nano1X2Series.h:7429
RTC_CAR_10DAY_Msk
#define RTC_CAR_10DAY_Msk
Definition: Nano1X2Series.h:7426
RTC_TSSR_24H_12H_Msk
#define RTC_TSSR_24H_12H_Msk
Definition: Nano1X2Series.h:7399
RTC_RIER_SNOOPIER_Msk
#define RTC_RIER_SNOOPIER_Msk
Definition: Nano1X2Series.h:7450
RTC_CAR_1YEAR_Pos
#define RTC_CAR_1YEAR_Pos
Definition: Nano1X2Series.h:7434
RTC_SetDateAndTime
void RTC_SetDateAndTime(S_RTC_TIME_DATA_T *sPt)
This function is used to update date/time to RTC.
Definition: rtc.c:389
RTC_CLR_1YEAR_Msk
#define RTC_CLR_1YEAR_Msk
Definition: Nano1X2Series.h:7393
Nano1X2Series.h
Nano102/112 peripheral access layer header file. This file contains all the peripheral register's def...
RTC_CLOCK_24
#define RTC_CLOCK_24
Definition: rtc.h:44
RTC_TAR_1HR_Msk
#define RTC_TAR_1HR_Msk
Definition: Nano1X2Series.h:7417
RTC_RIER_AIER_Msk
#define RTC_RIER_AIER_Msk
Definition: Nano1X2Series.h:7444
RTC_SetTime
void RTC_SetTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm)
This function is used to update time to RTC.
Definition: rtc.c:564
RTC_CLR_10MON_Msk
#define RTC_CLR_10MON_Msk
Definition: Nano1X2Series.h:7390
RTC_TAR_1MIN_Pos
#define RTC_TAR_1MIN_Pos
Definition: Nano1X2Series.h:7410
RTC_TLR_10SEC_Pos
#define RTC_TLR_10SEC_Pos
Definition: Nano1X2Series.h:7365
RTC_CLR_10MON_Pos
#define RTC_CLR_10MON_Pos
Definition: Nano1X2Series.h:7389
RTC_CAR_1DAY_Msk
#define RTC_CAR_1DAY_Msk
Definition: Nano1X2Series.h:7423
S_RTC_TIME_DATA_T::u32Minute
uint32_t u32Minute
Definition: rtc.h:87
RTC_RIER_TIER_Msk
#define RTC_RIER_TIER_Msk
Definition: Nano1X2Series.h:7447
S_RTC_TIME_DATA_T::u32AmPm
uint32_t u32AmPm
Definition: rtc.h:90
RTC_CAR_1MON_Pos
#define RTC_CAR_1MON_Pos
Definition: Nano1X2Series.h:7428
RTC_CLR_1MON_Msk
#define RTC_CLR_1MON_Msk
Definition: Nano1X2Series.h:7387
RTC_TLR_10SEC_Msk
#define RTC_TLR_10SEC_Msk
Definition: Nano1X2Series.h:7366
RTC_GetDateAndTime
void RTC_GetDateAndTime(S_RTC_TIME_DATA_T *sPt)
Read current date/time from RTC setting.
Definition: rtc.c:193
RTC_RIIR_SNOOPIF_Msk
#define RTC_RIIR_SNOOPIF_Msk
Definition: Nano1X2Series.h:7459
RTC_TLR_10MIN_Pos
#define RTC_TLR_10MIN_Pos
Definition: Nano1X2Series.h:7371
RTC_PM
#define RTC_PM
Definition: rtc.h:47
RTC_SetAlarmDateAndTime
void RTC_SetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt)
This function is used to set alarm date/time to RTC.
Definition: rtc.c:461
RTC_32KCalibration
void RTC_32KCalibration(int32_t i32FrequencyX100)
Set Frequency Compensation Data.
Definition: rtc.c:58
RTC_RIIR_TIF_Msk
#define RTC_RIIR_TIF_Msk
Definition: Nano1X2Series.h:7456
RTC_INIT_KEY
#define RTC_INIT_KEY
Definition: rtc.h:35
RTC_CLR_1MON_Pos
#define RTC_CLR_1MON_Pos
Definition: Nano1X2Series.h:7386
RTC_CAR_10YEAR_Pos
#define RTC_CAR_10YEAR_Pos
Definition: Nano1X2Series.h:7437
RTC_DisableTamperDetection
void RTC_DisableTamperDetection(void)
This function is used to disable tamper detection function.
Definition: rtc.c:712
RTC_SPRCTL_SNOOPEDGE_Msk
#define RTC_SPRCTL_SNOOPEDGE_Msk
Definition: Nano1X2Series.h:7471
RTC_Close
void RTC_Close(void)
Disable RTC clock.
Definition: rtc.c:821
S_RTC_TIME_DATA_T
RTC define Time Data Struct.
Definition: rtc.h:81
RTC_AM
#define RTC_AM
Definition: rtc.h:46
RTC_CLR_1DAY_Msk
#define RTC_CLR_1DAY_Msk
Definition: Nano1X2Series.h:7381
S_RTC_TIME_DATA_T::u32Day
uint32_t u32Day
Definition: rtc.h:84
RTC_CAR_10YEAR_Msk
#define RTC_CAR_10YEAR_Msk
Definition: Nano1X2Series.h:7438
RTC_TAR_10HR_Msk
#define RTC_TAR_10HR_Msk
Definition: Nano1X2Series.h:7420
S_RTC_TIME_DATA_T::u32DayOfWeek
uint32_t u32DayOfWeek
Definition: rtc.h:85
RTC_CAR_10MON_Msk
#define RTC_CAR_10MON_Msk
Definition: Nano1X2Series.h:7432
RTC_TAR_10MIN_Pos
#define RTC_TAR_10MIN_Pos
Definition: Nano1X2Series.h:7413
RTC_TAR_10MIN_Msk
#define RTC_TAR_10MIN_Msk
Definition: Nano1X2Series.h:7414
RTC_GetDayOfWeek
uint32_t RTC_GetDayOfWeek(void)
This function is used to get day of week.
Definition: rtc.c:728
RTC_SetAlarmDate
void RTC_SetAlarmDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day)
This function is used to set alarm date to RTC.
Definition: rtc.c:609
RTC_Open
void RTC_Open(S_RTC_TIME_DATA_T *sPt)
This function is used to: .
Definition: rtc.c:101
RTC_YEAR2000
#define RTC_YEAR2000
Definition: rtc.h:40
S_RTC_TIME_DATA_T::u32Month
uint32_t u32Month
Definition: rtc.h:83
RTC_TTR_TTR_Msk
#define RTC_TTR_TTR_Msk
Definition: Nano1X2Series.h:7462
RTC_EnableInt
void RTC_EnableInt(uint32_t u32IntFlagMask)
The function is used to enable specified interrupt.
Definition: rtc.c:771
RTC_AER_ENF_Msk
#define RTC_AER_ENF_Msk
Definition: Nano1X2Series.h:7357
RTC_TLR_1HR_Msk
#define RTC_TLR_1HR_Msk
Definition: Nano1X2Series.h:7375
S_RTC_TIME_DATA_T::u32Second
uint32_t u32Second
Definition: rtc.h:88
RTC_TLR_10MIN_Msk
#define RTC_TLR_10MIN_Msk
Definition: Nano1X2Series.h:7372
RTC_CLR_1YEAR_Pos
#define RTC_CLR_1YEAR_Pos
Definition: Nano1X2Series.h:7392
RTC_TAR_10SEC_Pos
#define RTC_TAR_10SEC_Pos
Definition: Nano1X2Series.h:7407
RTC_CAR_10DAY_Pos
#define RTC_CAR_10DAY_Pos
Definition: Nano1X2Series.h:7425
S_RTC_TIME_DATA_T::u32TimeScale
uint32_t u32TimeScale
Definition: rtc.h:89
RTC_TAR_1HR_Pos
#define RTC_TAR_1HR_Pos
Definition: Nano1X2Series.h:7416