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

rtc.c
Go to the documentation of this file.
1 /**************************************************************************/
14 #include <stdio.h>
15 #include "Nano100Series.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 i32FrequencyX100)
59 {
60 int32_t i32RegInt,i32RegFra ;
61
62 /* Compute Integer and Fraction for RTC register*/
63 i32RegInt = (i32FrequencyX100/100) - RTC_FCR_REFERENCE;
64 i32RegFra = (((i32FrequencyX100%100)) * 60) / 100;
65
66 /* Judge Integer part is reasonable */
67 if ( (i32RegInt < 0) | (i32RegInt > 15) )
68 {
69 return;
70 }
71
72 RTC->AER = RTC_WRITE_KEY;
73 while(!(RTC->AER & RTC_AER_ENF_Msk));
74
75 RTC->FCR = (uint32_t)((i32RegInt<<8) | i32RegFra);
76
77 }
78
100 void RTC_Open (S_RTC_TIME_DATA_T *sPt)
101 {
102 uint32_t u32Reg;
103
104 volatile int32_t i32delay=1000;
105
106 RTC->INIR = RTC_INIT_KEY;
107
108 if(RTC->INIR != 0x1)
109 {
110 RTC->INIR = RTC_INIT_KEY;
111
112 while(RTC->INIR != 0x1);
113 }
114
115 if(sPt == NULL)
116 return;
117
118 /*-----------------------------------------------------------------------------------------------------*/
119 /* Second, set RTC 24/12 hour setting */
120 /*-----------------------------------------------------------------------------------------------------*/
121 if (sPt->u32TimeScale == RTC_CLOCK_12)
122 {
123 RTC->AER = RTC_WRITE_KEY;
124 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
125 RTC->TSSR &= ~RTC_TSSR_24H_12H_Msk;
126
127 /*-------------------------------------------------------------------------------------------------*/
128 /* important, range of 12-hour PM mode is 21 upto 32 */
129 /*-------------------------------------------------------------------------------------------------*/
130 if (sPt->u32AmPm == RTC_PM)
131 sPt->u32Hour += 20;
132 }
133 else
134 {
135 RTC->AER = RTC_WRITE_KEY;
136 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
137 RTC->TSSR |= RTC_TSSR_24H_12H_Msk;
138 }
139
140 /*-----------------------------------------------------------------------------------------------------*/
141 /* Set RTC Calender Loading */
142 /*-----------------------------------------------------------------------------------------------------*/
143 u32Reg = ((sPt->u32Year - RTC_YEAR2000) / 10) << 20;
144 u32Reg |= (((sPt->u32Year - RTC_YEAR2000) % 10) << 16);
145 u32Reg |= ((sPt->u32Month / 10) << 12);
146 u32Reg |= ((sPt->u32Month % 10) << 8);
147 u32Reg |= ((sPt->u32Day / 10) << 4);
148 u32Reg |= (sPt->u32Day % 10);
149 g_u32Reg = u32Reg;
150
151 RTC->AER = RTC_WRITE_KEY;
152 while(!(RTC->AER & RTC_AER_ENF_Msk));
153
154 RTC->CLR = (uint32_t)g_u32Reg;
155
156 /*-----------------------------------------------------------------------------------------------------*/
157 /* Set RTC Time Loading */
158 /*-----------------------------------------------------------------------------------------------------*/
159 u32Reg = ((sPt->u32Hour / 10) << 20);
160 u32Reg |= ((sPt->u32Hour % 10) << 16);
161 u32Reg |= ((sPt->u32Minute / 10) << 12);
162 u32Reg |= ((sPt->u32Minute % 10) << 8);
163 u32Reg |= ((sPt->u32Second / 10) << 4);
164 u32Reg |= (sPt->u32Second % 10);
165 g_u32Reg = u32Reg;
166
167 RTC->AER = RTC_WRITE_KEY;
168 while(!(RTC->AER & RTC_AER_ENF_Msk));
169
170 RTC->TLR = (uint32_t)g_u32Reg;
171
172 RTC->DWR = sPt->u32DayOfWeek;
173
174 /* Waiting for RTC settings stable */
175 while(i32delay--);
176
177 }
178
197 void RTC_GetDateAndTime(S_RTC_TIME_DATA_T *sPt)
198 {
199 uint32_t u32Tmp;
200
201 sPt->u32TimeScale = RTC->TSSR & RTC_TSSR_24H_12H_Msk; /* 12/24-hour */
202 sPt->u32DayOfWeek = RTC->DWR & RTC_DWR_DWR_Msk; /* Day of week */
203
204 g_u32hiYear = (RTC->CLR & RTC_CLR_10YEAR_Msk) >> RTC_CLR_10YEAR_Pos;
205 g_u32loYear = (RTC->CLR & RTC_CLR_1YEAR_Msk) >> RTC_CLR_1YEAR_Pos;
206 g_u32hiMonth = (RTC->CLR & RTC_CLR_10MON_Msk) >> RTC_CLR_10MON_Pos;
207 g_u32loMonth = (RTC->CLR & RTC_CLR_1MON_Msk) >> RTC_CLR_1MON_Pos;
208 g_u32hiDay = (RTC->CLR & RTC_CLR_10DAY_Msk) >> RTC_CLR_10DAY_Pos;
209 g_u32loDay = (RTC->CLR & RTC_CLR_1DAY_Msk);
210
211 g_u32hiHour = (RTC->TLR & RTC_TLR_10HR_Msk) >> RTC_TLR_10HR_Pos;
212 g_u32loHour = (RTC->TLR & RTC_TLR_1HR_Msk) >> RTC_TLR_1HR_Pos;
213 g_u32hiMin = (RTC->TLR & RTC_TLR_10MIN_Msk) >> RTC_TLR_10MIN_Pos;
214 g_u32loMin = (RTC->TLR & RTC_TLR_1MIN_Msk) >> RTC_TLR_1MIN_Pos;
215 g_u32hiSec = (RTC->TLR & RTC_TLR_10SEC_Msk) >> RTC_TLR_10SEC_Pos;
216 g_u32loSec = (RTC->TLR & RTC_TLR_1SEC_Msk);
217
218 u32Tmp = (g_u32hiYear * 10); /* Compute to 20XX year */
219 u32Tmp += g_u32loYear;
220 sPt->u32Year = u32Tmp + RTC_YEAR2000;
221
222 u32Tmp = (g_u32hiMonth * 10); /* Compute 0~12 month */
223 sPt->u32Month = u32Tmp + g_u32loMonth;
224
225 u32Tmp = (g_u32hiDay * 10); /* Compute 0~31 day */
226 sPt->u32Day = u32Tmp + g_u32loDay;
227
228 if (sPt->u32TimeScale == RTC_CLOCK_12) /* Compute12/24 hour */
229 {
230 u32Tmp = (g_u32hiHour * 10);
231 u32Tmp+= g_u32loHour;
232 sPt->u32Hour = u32Tmp; /* AM: 1~12. PM: 21~32. */
233
234 if (sPt->u32Hour >= 21)
235 {
236 sPt->u32AmPm = RTC_PM;
237 sPt->u32Hour -= 20;
238 }
239 else
240 {
241 sPt->u32AmPm = RTC_AM;
242 }
243
244 u32Tmp = (g_u32hiMin * 10);
245 u32Tmp+= g_u32loMin;
246 sPt->u32Minute = u32Tmp;
247
248 u32Tmp = (g_u32hiSec * 10);
249 u32Tmp+= g_u32loSec;
250 sPt->u32Second = u32Tmp;
251
252 }
253 else
254 {
255 u32Tmp = (g_u32hiHour * 10);
256 u32Tmp += g_u32loHour;
257 sPt->u32Hour = u32Tmp;
258
259 u32Tmp = (g_u32hiMin * 10);
260 u32Tmp += g_u32loMin;
261 sPt->u32Minute = u32Tmp;
262
263 u32Tmp = (g_u32hiSec * 10);
264 u32Tmp += g_u32loSec;
265 sPt->u32Second = u32Tmp;
266 }
267
268 }
269
270
271
290 void RTC_GetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt)
291 {
292 uint32_t u32Tmp;
293
294 sPt->u32TimeScale = RTC->TSSR & RTC_TSSR_24H_12H_Msk; /* 12/24-hour */
295 sPt->u32DayOfWeek = RTC->DWR & RTC_DWR_DWR_Msk; /* Day of week */
296
297 RTC->AER = RTC_WRITE_KEY;
298 while(!(RTC->AER & RTC_AER_ENF_Msk));
299
300 g_u32hiYear = (RTC->CAR & RTC_CAR_10YEAR_Msk) >> RTC_CAR_10YEAR_Pos;
301 g_u32loYear = (RTC->CAR & RTC_CAR_1YEAR_Msk) >> RTC_CAR_1YEAR_Pos;
302 g_u32hiMonth = (RTC->CAR & RTC_CAR_10MON_Msk) >> RTC_CAR_10MON_Pos;
303 g_u32loMonth = (RTC->CAR & RTC_CAR_1MON_Msk) >> RTC_CAR_1MON_Pos;
304 g_u32hiDay = (RTC->CAR & RTC_CAR_10DAY_Msk) >> RTC_CAR_10DAY_Pos;
305 g_u32loDay = (RTC->CAR & RTC_CAR_1DAY_Msk);
306
307 RTC->AER = RTC_WRITE_KEY;
308 while(!(RTC->AER & RTC_AER_ENF_Msk));
309
310 g_u32hiHour = (RTC->TAR & RTC_TAR_10HR_Msk) >> RTC_TAR_10HR_Pos;
311 g_u32loHour = (RTC->TAR & RTC_TAR_1HR_Msk) >> RTC_TAR_1HR_Pos;
312 g_u32hiMin = (RTC->TAR & RTC_TAR_10MIN_Msk) >> RTC_TAR_10MIN_Pos;
313 g_u32loMin = (RTC->TAR & RTC_TAR_1MIN_Msk) >> RTC_TAR_1MIN_Pos;
314 g_u32hiSec = (RTC->TAR & RTC_TAR_10SEC_Msk) >> RTC_TAR_10SEC_Pos;
315 g_u32loSec = (RTC->TAR & RTC_TAR_1SEC_Msk);
316
317 u32Tmp = (g_u32hiYear * 10); /* Compute to 20XX year */
318 u32Tmp += g_u32loYear;
319 sPt->u32Year = u32Tmp + RTC_YEAR2000;
320
321 u32Tmp = (g_u32hiMonth * 10); /* Compute 0~12 month */
322 sPt->u32Month = u32Tmp + g_u32loMonth;
323
324 u32Tmp = (g_u32hiDay * 10); /* Compute 0~31 day */
325 sPt->u32Day = u32Tmp + g_u32loDay;
326
327 if (sPt->u32TimeScale == RTC_CLOCK_12) /* Compute12/24 hour */
328 {
329 u32Tmp = (g_u32hiHour * 10);
330 u32Tmp += g_u32loHour;
331 sPt->u32Hour = u32Tmp; /* AM: 1~12. PM: 21~32. */
332
333 if (sPt->u32Hour >= 21)
334 {
335 sPt->u32AmPm = RTC_PM;
336 sPt->u32Hour -= 20;
337 }
338 else
339 {
340 sPt->u32AmPm = RTC_AM;
341 }
342
343 u32Tmp = (g_u32hiMin * 10);
344 u32Tmp += g_u32loMin;
345 sPt->u32Minute = u32Tmp;
346
347 u32Tmp = (g_u32hiSec * 10);
348 u32Tmp += g_u32loSec;
349 sPt->u32Second = u32Tmp;
350
351 }
352 else
353 {
354 u32Tmp = (g_u32hiHour * 10);
355 u32Tmp += g_u32loHour;
356 sPt->u32Hour = u32Tmp;
357
358 u32Tmp = (g_u32hiMin * 10);
359 u32Tmp+= g_u32loMin;
360 sPt->u32Minute = u32Tmp;
361
362 u32Tmp = (g_u32hiSec * 10);
363 u32Tmp += g_u32loSec;
364 sPt->u32Second = u32Tmp;
365 }
366
367 }
368
369
370
393 void RTC_SetDateAndTime(S_RTC_TIME_DATA_T *sPt)
394 {
395 uint32_t u32Reg;
396
397 RTC->AER = RTC_WRITE_KEY;
398 while(!(RTC->AER & RTC_AER_ENF_Msk));
399
400 if (sPt->u32TimeScale == RTC_CLOCK_12)
401 {
402 RTC->TSSR &= ~RTC_TSSR_24H_12H_Msk;
403
404 /*-----------------------------------------------------------------------------------------*/
405 /* important, range of 12-hour PM mode is 21 upto 32 */
406 /*-----------------------------------------------------------------------------------------*/
407 if (sPt->u32AmPm == RTC_PM)
408 sPt->u32Hour += 20;
409 }
410 else
411 {
412 RTC->TSSR |= RTC_TSSR_24H_12H_Msk;
413 }
414
415 RTC->DWR = sPt->u32DayOfWeek & RTC_DWR_DWR_Msk;
416
417 u32Reg = ((sPt->u32Year - RTC_YEAR2000) / 10) << 20;
418 u32Reg |= (((sPt->u32Year - RTC_YEAR2000) % 10) << 16);
419 u32Reg |= ((sPt->u32Month / 10) << 12);
420 u32Reg |= ((sPt->u32Month % 10) << 8);
421 u32Reg |= ((sPt->u32Day / 10) << 4);
422 u32Reg |= (sPt->u32Day % 10);
423 g_u32Reg = u32Reg;
424
425 RTC->AER = RTC_WRITE_KEY;
426 while(!(RTC->AER & RTC_AER_ENF_Msk));
427
428 RTC->CLR = (uint32_t)g_u32Reg;
429
430 u32Reg = ((sPt->u32Hour / 10) << 20);
431 u32Reg |= ((sPt->u32Hour % 10) << 16);
432 u32Reg |= ((sPt->u32Minute / 10) << 12);
433 u32Reg |= ((sPt->u32Minute % 10) << 8);
434 u32Reg |= ((sPt->u32Second / 10) << 4);
435 u32Reg |= (sPt->u32Second % 10);
436 g_u32Reg = u32Reg;
437
438 RTC->AER = RTC_WRITE_KEY;
439 while(!(RTC->AER & RTC_AER_ENF_Msk));
440
441 RTC->TLR = (uint32_t)g_u32Reg;
442
443 }
444
465 void RTC_SetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt)
466 {
467 uint32_t u32Reg;
468
469 RTC->AER = RTC_WRITE_KEY;
470 while(!(RTC->AER & RTC_AER_ENF_Msk));
471
472 if (sPt->u32TimeScale == RTC_CLOCK_12)
473 {
474 RTC->TSSR &= ~RTC_TSSR_24H_12H_Msk;
475
476 /*-----------------------------------------------------------------------------------------*/
477 /* important, range of 12-hour PM mode is 21 upto 32 */
478 /*-----------------------------------------------------------------------------------------*/
479 if (sPt->u32AmPm == RTC_PM)
480 sPt->u32Hour += 20;
481 }
482 else
483 {
484 RTC->TSSR |= RTC_TSSR_24H_12H_Msk;
485 }
486
487 RTC->DWR = sPt->u32DayOfWeek & RTC_DWR_DWR_Msk;
488
489
490 u32Reg = ((sPt->u32Year - RTC_YEAR2000) / 10) << 20;
491 u32Reg |= (((sPt->u32Year - RTC_YEAR2000) % 10) << 16);
492 u32Reg |= ((sPt->u32Month / 10) << 12);
493 u32Reg |= ((sPt->u32Month % 10) << 8);
494 u32Reg |= ((sPt->u32Day / 10) << 4);
495 u32Reg |= (sPt->u32Day % 10);
496 g_u32Reg = u32Reg;
497
498 RTC->AER = RTC_WRITE_KEY;
499 while(!(RTC->AER & RTC_AER_ENF_Msk));
500
501 RTC->CAR = (uint32_t)g_u32Reg;
502
503 u32Reg = ((sPt->u32Hour / 10) << 20);
504 u32Reg |= ((sPt->u32Hour % 10) << 16);
505 u32Reg |= ((sPt->u32Minute / 10) << 12);
506 u32Reg |= ((sPt->u32Minute % 10) << 8);
507 u32Reg |= ((sPt->u32Second / 10) << 4);
508 u32Reg |= (sPt->u32Second % 10);
509 g_u32Reg = u32Reg;
510
511 RTC->AER = RTC_WRITE_KEY;
512 while(!(RTC->AER & RTC_AER_ENF_Msk));
513
514 RTC->TAR = (uint32_t)g_u32Reg;
515
516 }
517
518
532 void RTC_SetDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day, uint32_t u32DayOfWeek)
533 {
534 __IO uint32_t u32Reg;
535
536 RTC->AER = RTC_WRITE_KEY;
537 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
538
539 RTC->DWR = u32DayOfWeek & RTC_DWR_DWR_Msk;
540
541 u32Reg = ((u32Year - RTC_YEAR2000) / 10) << 20;
542 u32Reg |= (((u32Year - RTC_YEAR2000) % 10) << 16);
543 u32Reg |= ((u32Month / 10) << 12);
544 u32Reg |= ((u32Month % 10) << 8);
545 u32Reg |= ((u32Day / 10) << 4);
546 u32Reg |= (u32Day % 10);
547 g_u32Reg = u32Reg;
548
549 RTC->AER = RTC_WRITE_KEY;
550 while(!(RTC->AER & RTC_AER_ENF_Msk));
551
552 RTC->CLR = (uint32_t)g_u32Reg;
553
554 }
555
568 void RTC_SetTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm)
569 {
570 __IO uint32_t u32Reg;
571
572 RTC->AER = RTC_WRITE_KEY;
573 while(!(RTC->AER & RTC_AER_ENF_Msk));
574
575 if (u32TimeMode == RTC_CLOCK_12)
576 {
577 RTC->TSSR &= ~RTC_TSSR_24H_12H_Msk;
578
579 if (u32AmPm == RTC_PM) /* important, range of 12-hour PM mode is 21 upto 32 */
580 u32Hour += 20;
581 }
582 else if(u32TimeMode == RTC_CLOCK_24)
583 {
584 RTC->TSSR |= RTC_TSSR_24H_12H_Msk;
585 }
586
587 u32Reg = ((u32Hour / 10) << 20);
588 u32Reg |= ((u32Hour % 10) << 16);
589 u32Reg |= ((u32Minute / 10) << 12);
590 u32Reg |= ((u32Minute % 10) << 8);
591 u32Reg |= ((u32Second / 10) << 4);
592 u32Reg |= (u32Second % 10);
593
594 g_u32Reg = u32Reg;
595
596 RTC->AER = RTC_WRITE_KEY;
597 while(!(RTC->AER & RTC_AER_ENF_Msk));
598
599 RTC->TLR = (uint32_t)g_u32Reg;
600
601 }
602
613 void RTC_SetAlarmDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day)
614 {
615 __IO uint32_t u32Reg;
616
617 RTC->AER = RTC_WRITE_KEY;
618 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
619
620 u32Reg = ((u32Year - RTC_YEAR2000) / 10) << 20;
621 u32Reg |= (((u32Year - RTC_YEAR2000) % 10) << 16);
622 u32Reg |= ((u32Month / 10) << 12);
623 u32Reg |= ((u32Month % 10) << 8);
624 u32Reg |= ((u32Day / 10) << 4);
625 u32Reg |= (u32Day % 10);
626 g_u32Reg = u32Reg;
627
628 RTC->AER = RTC_WRITE_KEY;
629 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
630
631 RTC->CAR = (uint32_t)g_u32Reg;
632
633 }
634
647 void RTC_SetAlarmTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm)
648 {
649 __IO uint32_t u32Reg;
650
651 RTC->AER = RTC_WRITE_KEY;
652 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
653
654 if (u32TimeMode == RTC_CLOCK_12)
655 {
656 RTC->TSSR &= ~RTC_TSSR_24H_12H_Msk;
657
658 if (u32AmPm == RTC_PM) /* important, range of 12-hour PM mode is 21 upto 32 */
659 u32Hour += 20;
660 }
661 else if(u32TimeMode == RTC_CLOCK_24)
662 {
663 RTC->TSSR |= RTC_TSSR_24H_12H_Msk;
664 }
665
666 u32Reg = ((u32Hour / 10) << 20);
667 u32Reg |= ((u32Hour % 10) << 16);
668 u32Reg |= ((u32Minute / 10) << 12);
669 u32Reg |= ((u32Minute % 10) << 8);
670 u32Reg |= ((u32Second / 10) << 4);
671 u32Reg |= (u32Second % 10);
672
673 g_u32Reg = u32Reg;
674
675 RTC->AER = RTC_WRITE_KEY;
676 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
677
678 RTC->TAR = (uint32_t)g_u32Reg;
679
680 }
681
682
691 void RTC_EnableTamperDetection(uint32_t u32PinCondition)
692 {
693 RTC->AER = RTC_WRITE_KEY;
694 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
695
696 /* detection edge select */
697 if(u32PinCondition)
698 RTC->SPRCTL |= RTC_SPRCTL_SNOOPEDGE_Msk;
699 else
700 RTC->SPRCTL &= ~RTC_SPRCTL_SNOOPEDGE_Msk;
701
702 while(!(RTC->SPRCTL & RTC_SPRCTL_SPRRDY_Msk));
703
704 /* enable snooper pin event detection */
705 RTC->SPRCTL |= RTC_SPRCTL_SNOOPEN_Msk;
706 while(!(RTC->SPRCTL & RTC_SPRCTL_SPRRDY_Msk));
707 }
708
717 void RTC_DisableTamperDetection(void)
718 {
719 RTC->AER = RTC_WRITE_KEY;
720 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
721
722 RTC->SPRCTL &= ~RTC_SPRCTL_SNOOPEN_Msk;
723 }
724
733 uint32_t RTC_GetDayOfWeek(void)
734 {
735 return (RTC->DWR & RTC_DWR_DWR_Msk);
736 }
737
738
757 void RTC_SetTickPeriod(uint32_t u32TickSelection)
758 {
759 RTC->AER = RTC_WRITE_KEY;
760 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
761
762 RTC->TTR = RTC->TTR & ~RTC_TTR_TTR_Msk | u32TickSelection;
763 }
764
776 void RTC_EnableInt(uint32_t u32IntFlagMask)
777 {
778 RTC->AER = RTC_WRITE_KEY;
779 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
780
781 RTC->RIER |= u32IntFlagMask;
782 }
783
795 void RTC_DisableInt(uint32_t u32IntFlagMask)
796 {
797 RTC->AER = RTC_WRITE_KEY;
798 while(!(RTC->AER & RTC_AER_ENF_Msk)) RTC->AER = RTC_WRITE_KEY;
799
800 if(u32IntFlagMask & RTC_RIER_TIER_Msk)
801 {
802 RTC->RIER &= ~RTC_RIER_TIER_Msk;
803 RTC->RIIR = RTC_RIIR_TIF_Msk;
804 }
805
806 if(u32IntFlagMask & RTC_RIER_AIER_Msk)
807 {
808 RTC->RIER &= ~RTC_RIER_AIER_Msk;
809 RTC->RIIR = RTC_RIIR_AIF_Msk;
810 }
811
812 if(u32IntFlagMask & RTC_RIER_SNOOPIER_Msk)
813 {
814 RTC->RIER &= ~RTC_RIER_SNOOPIER_Msk;
815 RTC->RIIR = RTC_RIIR_SNOOPIF_Msk;
816 }
817 }
818
825 void RTC_Close (void)
826 {
827 CLK->APBCLK &= ~CLK_APBCLK_RTC_EN_Msk;
828 }
829
830 /* end of group NANO100_RTC_EXPORTED_FUNCTIONS */
832 /* end of group NANO100_RTC_Driver */
834 /* end of group NANO100_Device_Driver */
836
837 /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
838
839
RTC_TTR_TTR_Msk
#define RTC_TTR_TTR_Msk
Definition: Nano100Series.h:8189
RTC_DisableTamperDetection
void RTC_DisableTamperDetection(void)
This function is used to disable tamper detection function.
Definition: rtc.c:717
RTC_RIIR_SNOOPIF_Msk
#define RTC_RIIR_SNOOPIF_Msk
Definition: Nano100Series.h:8186
RTC_RIER_AIER_Msk
#define RTC_RIER_AIER_Msk
Definition: Nano100Series.h:8171
RTC_TAR_10MIN_Pos
#define RTC_TAR_10MIN_Pos
Definition: Nano100Series.h:8140
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:647
RTC_GetDayOfWeek
uint32_t RTC_GetDayOfWeek(void)
This function is used to get day of week.
Definition: rtc.c:733
RTC_CAR_1MON_Pos
#define RTC_CAR_1MON_Pos
Definition: Nano100Series.h:8155
RTC_RIER_SNOOPIER_Msk
#define RTC_RIER_SNOOPIER_Msk
Definition: Nano100Series.h:8177
RTC_TAR_1HR_Msk
#define RTC_TAR_1HR_Msk
Definition: Nano100Series.h:8144
RTC_TLR_10MIN_Pos
#define RTC_TLR_10MIN_Pos
Definition: Nano100Series.h:8098
RTC_GetAlarmDateAndTime
void RTC_GetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt)
Read alarm date/time from RTC setting.
Definition: rtc.c:290
S_RTC_TIME_DATA_T::u32Hour
uint32_t u32Hour
Definition: rtc.h:87
CLK
#define CLK
Pointer to CLK register structure.
Definition: Nano100Series.h:11693
RTC_CLR_10DAY_Msk
#define RTC_CLR_10DAY_Msk
Definition: Nano100Series.h:8111
RTC
#define RTC
Pointer to RTC register structure.
Definition: Nano100Series.h:11668
RTC_SPRCTL_SNOOPEN_Msk
#define RTC_SPRCTL_SNOOPEN_Msk
Definition: Nano100Series.h:8195
RTC_CAR_10YEAR_Pos
#define RTC_CAR_10YEAR_Pos
Definition: Nano100Series.h:8164
RTC_TAR_1MIN_Msk
#define RTC_TAR_1MIN_Msk
Definition: Nano100Series.h:8138
RTC_CAR_10DAY_Msk
#define RTC_CAR_10DAY_Msk
Definition: Nano100Series.h:8153
RTC_TSSR_24H_12H_Msk
#define RTC_TSSR_24H_12H_Msk
Definition: Nano100Series.h:8126
RTC_TLR_1MIN_Pos
#define RTC_TLR_1MIN_Pos
Definition: Nano100Series.h:8095
RTC_TAR_10SEC_Msk
#define RTC_TAR_10SEC_Msk
Definition: Nano100Series.h:8135
S_RTC_TIME_DATA_T::u32Year
uint32_t u32Year
Definition: rtc.h:83
Nano100Series.h
Nano100 series peripheral access layer header file. This file contains all the peripheral register's ...
RTC_EnableTamperDetection
void RTC_EnableTamperDetection(uint32_t u32PinCondition)
This function is used to enable tamper detection function and set tamper control register,...
Definition: rtc.c:691
RTC_SetDateAndTime
void RTC_SetDateAndTime(S_RTC_TIME_DATA_T *sPt)
This function is used to update date/time to RTC.
Definition: rtc.c:393
NULL
#define NULL
NULL pointer.
Definition: Nano100Series.h:11859
RTC_CLR_1YEAR_Msk
#define RTC_CLR_1YEAR_Msk
Definition: Nano100Series.h:8120
RTC_CLR_1MON_Pos
#define RTC_CLR_1MON_Pos
Definition: Nano100Series.h:8113
RTC_GetDateAndTime
void RTC_GetDateAndTime(S_RTC_TIME_DATA_T *sPt)
Read current date/time from RTC setting.
Definition: rtc.c:197
RTC_TLR_1MIN_Msk
#define RTC_TLR_1MIN_Msk
Definition: Nano100Series.h:8096
RTC_CLR_10YEAR_Pos
#define RTC_CLR_10YEAR_Pos
Definition: Nano100Series.h:8122
RTC_PM
#define RTC_PM
Definition: rtc.h:47
RTC_TAR_10HR_Pos
#define RTC_TAR_10HR_Pos
Definition: Nano100Series.h:8146
RTC_Close
void RTC_Close(void)
Disable RTC clock.
Definition: rtc.c:825
RTC_RIIR_AIF_Msk
#define RTC_RIIR_AIF_Msk
Definition: Nano100Series.h:8180
RTC_TAR_10SEC_Pos
#define RTC_TAR_10SEC_Pos
Definition: Nano100Series.h:8134
RTC_TAR_1HR_Pos
#define RTC_TAR_1HR_Pos
Definition: Nano100Series.h:8143
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:757
RTC_CLOCK_24
#define RTC_CLOCK_24
Definition: rtc.h:44
RTC_CLR_1MON_Msk
#define RTC_CLR_1MON_Msk
Definition: Nano100Series.h:8114
RTC_CLR_10MON_Pos
#define RTC_CLR_10MON_Pos
Definition: Nano100Series.h:8116
RTC_CLR_1DAY_Msk
#define RTC_CLR_1DAY_Msk
Definition: Nano100Series.h:8108
RTC_CLR_10DAY_Pos
#define RTC_CLR_10DAY_Pos
Definition: Nano100Series.h:8110
RTC_32KCalibration
void RTC_32KCalibration(int32_t i32FrequencyX100)
Set Frequency Compensation Data.
Definition: rtc.c:58
RTC_AM
#define RTC_AM
Definition: rtc.h:46
RTC_TLR_10SEC_Pos
#define RTC_TLR_10SEC_Pos
Definition: Nano100Series.h:8092
RTC_TAR_1MIN_Pos
#define RTC_TAR_1MIN_Pos
Definition: Nano100Series.h:8137
S_RTC_TIME_DATA_T::u32Minute
uint32_t u32Minute
Definition: rtc.h:88
RTC_SPRCTL_SNOOPEDGE_Msk
#define RTC_SPRCTL_SNOOPEDGE_Msk
Definition: Nano100Series.h:8198
RTC_EnableInt
void RTC_EnableInt(uint32_t u32IntFlagMask)
The function is used to enable specified interrupt.
Definition: rtc.c:776
RTC_CAR_1YEAR_Pos
#define RTC_CAR_1YEAR_Pos
Definition: Nano100Series.h:8161
S_RTC_TIME_DATA_T::u32AmPm
uint32_t u32AmPm
Definition: rtc.h:91
RTC_CAR_10YEAR_Msk
#define RTC_CAR_10YEAR_Msk
Definition: Nano100Series.h:8165
RTC_AER_ENF_Msk
#define RTC_AER_ENF_Msk
Definition: Nano100Series.h:8081
RTC_CAR_10MON_Msk
#define RTC_CAR_10MON_Msk
Definition: Nano100Series.h:8159
RTC_CAR_1MON_Msk
#define RTC_CAR_1MON_Msk
Definition: Nano100Series.h:8156
RTC_CAR_1DAY_Msk
#define RTC_CAR_1DAY_Msk
Definition: Nano100Series.h:8150
RTC_INIT_KEY
#define RTC_INIT_KEY
Definition: rtc.h:35
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:532
RTC_TLR_1HR_Msk
#define RTC_TLR_1HR_Msk
Definition: Nano100Series.h:8102
CLK_APBCLK_RTC_EN_Msk
#define CLK_APBCLK_RTC_EN_Msk
Definition: Nano100Series.h:1267
RTC_TLR_1SEC_Msk
#define RTC_TLR_1SEC_Msk
Definition: Nano100Series.h:8090
RTC_CLR_10YEAR_Msk
#define RTC_CLR_10YEAR_Msk
Definition: Nano100Series.h:8123
RTC_CAR_1YEAR_Msk
#define RTC_CAR_1YEAR_Msk
Definition: Nano100Series.h:8162
RTC_TLR_10SEC_Msk
#define RTC_TLR_10SEC_Msk
Definition: Nano100Series.h:8093
RTC_CLOCK_12
#define RTC_CLOCK_12
Definition: rtc.h:43
RTC_CAR_10MON_Pos
#define RTC_CAR_10MON_Pos
Definition: Nano100Series.h:8158
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:465
RTC_FCR_REFERENCE
#define RTC_FCR_REFERENCE
Definition: rtc.h:41
S_RTC_TIME_DATA_T
RTC define Time Data Struct.
Definition: rtc.h:81
S_RTC_TIME_DATA_T::u32Day
uint32_t u32Day
Definition: rtc.h:85
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:613
S_RTC_TIME_DATA_T::u32DayOfWeek
uint32_t u32DayOfWeek
Definition: rtc.h:86
RTC_TAR_10HR_Msk
#define RTC_TAR_10HR_Msk
Definition: Nano100Series.h:8147
RTC_TLR_10HR_Msk
#define RTC_TLR_10HR_Msk
Definition: Nano100Series.h:8105
RTC_WRITE_KEY
#define RTC_WRITE_KEY
Definition: rtc.h:36
RTC_CAR_10DAY_Pos
#define RTC_CAR_10DAY_Pos
Definition: Nano100Series.h:8152
RTC_DWR_DWR_Msk
#define RTC_DWR_DWR_Msk
Definition: Nano100Series.h:8129
RTC_YEAR2000
#define RTC_YEAR2000
Definition: rtc.h:40
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:568
S_RTC_TIME_DATA_T::u32Month
uint32_t u32Month
Definition: rtc.h:84
RTC_TLR_10HR_Pos
#define RTC_TLR_10HR_Pos
Definition: Nano100Series.h:8104
S_RTC_TIME_DATA_T::u32Second
uint32_t u32Second
Definition: rtc.h:89
RTC_SPRCTL_SPRRDY_Msk
#define RTC_SPRCTL_SPRRDY_Msk
Definition: Nano100Series.h:8201
RTC_TAR_1SEC_Msk
#define RTC_TAR_1SEC_Msk
Definition: Nano100Series.h:8132
RTC_CLR_10MON_Msk
#define RTC_CLR_10MON_Msk
Definition: Nano100Series.h:8117
RTC_Open
void RTC_Open(S_RTC_TIME_DATA_T *sPt)
This function is used to write initial key to let RTC start count and set current time.
Definition: rtc.c:100
RTC_RIIR_TIF_Msk
#define RTC_RIIR_TIF_Msk
Definition: Nano100Series.h:8183
S_RTC_TIME_DATA_T::u32TimeScale
uint32_t u32TimeScale
Definition: rtc.h:90
RTC_TLR_1HR_Pos
#define RTC_TLR_1HR_Pos
Definition: Nano100Series.h:8101
RTC_TAR_10MIN_Msk
#define RTC_TAR_10MIN_Msk
Definition: Nano100Series.h:8141
RTC_TLR_10MIN_Msk
#define RTC_TLR_10MIN_Msk
Definition: Nano100Series.h:8099
RTC_DisableInt
void RTC_DisableInt(uint32_t u32IntFlagMask)
The function is used to disable specified interrupt.
Definition: rtc.c:795
RTC_RIER_TIER_Msk
#define RTC_RIER_TIER_Msk
Definition: Nano100Series.h:8174
RTC_CLR_1YEAR_Pos
#define RTC_CLR_1YEAR_Pos
Definition: Nano100Series.h:8119