| NUC472_NUC442_BSP V3.03.003 The Board Support Package for NUC472/NUC442

rtc.c
Go to the documentation of this file.
1/**************************************************************************/
14#include <stdio.h>
15#include "NUC472_442.h"
16
17/*---------------------------------------------------------------------------------------------------------*/
18/* Includes of local headers */
19/*---------------------------------------------------------------------------------------------------------*/
20
21
22
31
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;
42int32_t g_RTC_i32ErrCode = 0;
53 void RTC_WaitAccessEnable(void)
54{
55 uint32_t u32TimeOutCount = SystemCoreClock * 2; // 2 second timeout
56 uint32_t i = 0;
57
58 RTC->RWEN = RTC_WRITE_KEY;
59 while(!(RTC->RWEN & RTC_RWEN_RWENF_Msk))
60 {
61 i++;
62 if(i > u32TimeOutCount) break;
63 }
64}
65
67
81 void RTC_32KCalibration(int32_t i32FrequencyX100)
82{
83 int32_t i32RegInt,i32RegFra ;
84
85 /* Compute Integer and Fraction for RTC register*/
86 i32RegInt = (i32FrequencyX100/100) - RTC_FCR_REFERENCE;
87 i32RegFra = (((i32FrequencyX100%100)) * 60) / 100;
88
89 /* Judge Integer part is reasonable */
90 if ( (i32RegInt < 0) | (i32RegInt > 15) )
91 {
92 return;
93 }
94
95 RTC_WaitAccessEnable();
96
97 RTC->FREQADJ = (uint32_t)((i32RegInt<<8) | i32RegFra);
98
99}
100
124 void RTC_Open (S_RTC_TIME_DATA_T *sPt)
125{
126 uint32_t u32Reg;
127 uint32_t u32TimeOutCount = SystemCoreClock * 2; // 2 second timeout
128
129 volatile int32_t i32delay=1000;
130
131 if(RTC->INIT != 0x1)
132 {
133 RTC->INIT = RTC_INIT_KEY;
134
135 while(RTC->INIT != 0x1)
136 {
137 if(u32TimeOutCount == 0)
138 {
139 g_RTC_i32ErrCode = RTC_TIMEOUT_ERR;
140 return;
141 }
142 u32TimeOutCount--;
143 }
144 }
145
146 if(sPt == NULL)
147 return;
148
149 /*-----------------------------------------------------------------------------------------------------*/
150 /* Second, set RTC 24/12 hour setting */
151 /*-----------------------------------------------------------------------------------------------------*/
152 if (sPt->u32TimeScale == RTC_CLOCK_12)
153 {
154 RTC_WaitAccessEnable();
155 RTC->CLKFMT &= ~RTC_CLKFMT_24HEN_Msk;
156
157 /*-------------------------------------------------------------------------------------------------*/
158 /* important, range of 12-hour PM mode is 21 up to 32 */
159 /*-------------------------------------------------------------------------------------------------*/
160 if (sPt->u32AmPm == RTC_PM)
161 sPt->u32Hour += 20;
162 }
163 else /* RTC_CLOCK_24 */
164 {
165 RTC_WaitAccessEnable();
166 RTC->CLKFMT |= RTC_CLKFMT_24HEN_Msk;
167 }
168
169 /*-----------------------------------------------------------------------------------------------------*/
170 /* Set RTC Calender Loading */
171 /*-----------------------------------------------------------------------------------------------------*/
172 u32Reg = ((sPt->u32Year - RTC_YEAR2000) / 10) << 20;
173 u32Reg |= (((sPt->u32Year - RTC_YEAR2000) % 10) << 16);
174 u32Reg |= ((sPt->u32Month / 10) << 12);
175 u32Reg |= ((sPt->u32Month % 10) << 8);
176 u32Reg |= ((sPt->u32Day / 10) << 4);
177 u32Reg |= (sPt->u32Day % 10);
178 g_u32Reg = u32Reg;
179
180 RTC_WaitAccessEnable();
181
182 RTC->CAL = (uint32_t)g_u32Reg;
183
184 /*-----------------------------------------------------------------------------------------------------*/
185 /* Set RTC Time Loading */
186 /*-----------------------------------------------------------------------------------------------------*/
187 u32Reg = ((sPt->u32Hour / 10) << 20);
188 u32Reg |= ((sPt->u32Hour % 10) << 16);
189 u32Reg |= ((sPt->u32Minute / 10) << 12);
190 u32Reg |= ((sPt->u32Minute % 10) << 8);
191 u32Reg |= ((sPt->u32Second / 10) << 4);
192 u32Reg |= (sPt->u32Second % 10);
193 g_u32Reg = u32Reg;
194
195 RTC_WaitAccessEnable();
196
197 RTC->TIME = (uint32_t)g_u32Reg;
198
199 RTC->WEEKDAY = sPt->u32DayOfWeek;
200
201 /* Waiting for RTC settings stable */
202 while(i32delay--);
203
204}
205
224 void RTC_GetDateAndTime(S_RTC_TIME_DATA_T *sPt)
225{
226 uint32_t u32Tmp;
227
228 sPt->u32TimeScale = RTC->CLKFMT & RTC_CLKFMT_24HEN_Msk; /* 12/24-hour */
229 sPt->u32DayOfWeek = RTC->WEEKDAY & RTC_WEEKDAY_WEEKDAY_Msk; /* Day of week */
230
231 g_u32hiYear = (RTC->CAL & RTC_CAL_TENYEAR_Msk) >> RTC_CAL_TENYEAR_Pos;
232 g_u32loYear = (RTC->CAL & RTC_CAL_YEAR_Msk) >> RTC_CAL_YEAR_Pos;
233 g_u32hiMonth = (RTC->CAL & RTC_CAL_TENMON_Msk) >> RTC_CAL_TENMON_Pos;
234 g_u32loMonth = (RTC->CAL & RTC_CAL_MON_Msk) >> RTC_CAL_MON_Pos;
235 g_u32hiDay = (RTC->CAL & RTC_CAL_TENDAY_Msk) >> RTC_CAL_TENDAY_Pos;
236 g_u32loDay = (RTC->CAL & RTC_CAL_DAY_Msk);
237
238 g_u32hiHour = (RTC->TIME & RTC_TIME_TENHR_Msk) >> RTC_TIME_TENHR_Pos;
239 g_u32loHour = (RTC->TIME & RTC_TIME_HR_Msk) >> RTC_TIME_HR_Pos;
240 g_u32hiMin = (RTC->TIME & RTC_TIME_TENMIN_Msk) >> RTC_TIME_TENMIN_Pos;
241 g_u32loMin = (RTC->TIME & RTC_TIME_MIN_Msk) >> RTC_TIME_MIN_Pos;
242 g_u32hiSec = (RTC->TIME & RTC_TIME_TENSEC_Msk) >> RTC_TIME_TENSEC_Pos;
243 g_u32loSec = (RTC->TIME & RTC_TIME_SEC_Msk);
244
245 u32Tmp = (g_u32hiYear * 10); /* Compute to 20XX year */
246 u32Tmp += g_u32loYear;
247 sPt->u32Year = u32Tmp + RTC_YEAR2000;
248
249 u32Tmp = (g_u32hiMonth * 10); /* Compute 0~12 month */
250 sPt->u32Month = u32Tmp + g_u32loMonth;
251
252 u32Tmp = (g_u32hiDay * 10); /* Compute 0~31 day */
253 sPt->u32Day = u32Tmp + g_u32loDay;
254
255 if (sPt->u32TimeScale == RTC_CLOCK_12) /* Compute12/24 hour */
256 {
257 u32Tmp = (g_u32hiHour * 10);
258 u32Tmp+= g_u32loHour;
259 sPt->u32Hour = u32Tmp; /* AM: 1~12. PM: 21~32. */
260
261 if (sPt->u32Hour >= 21)
262 {
263 sPt->u32AmPm = RTC_PM;
264 sPt->u32Hour -= 20;
265 }
266 else
267 {
268 sPt->u32AmPm = RTC_AM;
269 }
270
271 u32Tmp = (g_u32hiMin * 10);
272 u32Tmp+= g_u32loMin;
273 sPt->u32Minute = u32Tmp;
274
275 u32Tmp = (g_u32hiSec * 10);
276 u32Tmp+= g_u32loSec;
277 sPt->u32Second = u32Tmp;
278
279 }
280 else
281 {
282 /* RTC_CLOCK_24 */
283 u32Tmp = (g_u32hiHour * 10);
284 u32Tmp += g_u32loHour;
285 sPt->u32Hour = u32Tmp;
286
287 u32Tmp = (g_u32hiMin * 10);
288 u32Tmp += g_u32loMin;
289 sPt->u32Minute = u32Tmp;
290
291 u32Tmp = (g_u32hiSec * 10);
292 u32Tmp += g_u32loSec;
293 sPt->u32Second = u32Tmp;
294 }
295
296}
297
298
299
318 void RTC_GetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt)
319{
320 uint32_t u32Tmp;
321
322 sPt->u32TimeScale = RTC->CLKFMT & RTC_CLKFMT_24HEN_Msk; /* 12/24-hour */
323 sPt->u32DayOfWeek = RTC->WEEKDAY & RTC_WEEKDAY_WEEKDAY_Msk; /* Day of week */
324
325 RTC_WaitAccessEnable();
326
327 g_u32hiYear = (RTC->CALM & RTC_CALM_TENYEAR_Msk) >> RTC_CALM_TENYEAR_Pos;
328 g_u32loYear = (RTC->CALM & RTC_CALM_YEAR_Msk) >> RTC_CALM_YEAR_Pos;
329 g_u32hiMonth = (RTC->CALM & RTC_CALM_TENMON_Msk) >> RTC_CALM_TENMON_Pos;
330 g_u32loMonth = (RTC->CALM & RTC_CALM_MON_Msk) >> RTC_CALM_MON_Pos;
331 g_u32hiDay = (RTC->CALM & RTC_CALM_TENDAY_Msk) >> RTC_CALM_TENDAY_Pos;
332 g_u32loDay = (RTC->CALM & RTC_CALM_DAY_Msk);
333
334 RTC_WaitAccessEnable();
335
336 g_u32hiHour = (RTC->TALM & RTC_TALM_TENHR_Msk) >> RTC_TALM_TENHR_Pos;
337 g_u32loHour = (RTC->TALM & RTC_TALM_HR_Msk) >> RTC_TALM_HR_Pos;
338 g_u32hiMin = (RTC->TALM & RTC_TALM_TENMIN_Msk) >> RTC_TALM_TENMIN_Pos;
339 g_u32loMin = (RTC->TALM & RTC_TALM_MIN_Msk) >> RTC_TALM_MIN_Pos;
340 g_u32hiSec = (RTC->TALM & RTC_TALM_TENSEC_Msk) >> RTC_TALM_TENSEC_Pos;
341 g_u32loSec = (RTC->TALM & RTC_TALM_SEC_Msk);
342
343 u32Tmp = (g_u32hiYear * 10); /* Compute to 20XX year */
344 u32Tmp += g_u32loYear;
345 sPt->u32Year = u32Tmp + RTC_YEAR2000;
346
347 u32Tmp = (g_u32hiMonth * 10); /* Compute 0~12 month */
348 sPt->u32Month = u32Tmp + g_u32loMonth;
349
350 u32Tmp = (g_u32hiDay * 10); /* Compute 0~31 day */
351 sPt->u32Day = u32Tmp + g_u32loDay;
352
353 if (sPt->u32TimeScale == RTC_CLOCK_12) /* Compute12/24 hour */
354 {
355 u32Tmp = (g_u32hiHour * 10);
356 u32Tmp += g_u32loHour;
357 sPt->u32Hour = u32Tmp; /* AM: 1~12. PM: 21~32. */
358
359 if (sPt->u32Hour >= 21)
360 {
361 sPt->u32AmPm = RTC_PM;
362 sPt->u32Hour -= 20;
363 }
364 else
365 {
366 sPt->u32AmPm = RTC_AM;
367 }
368
369 u32Tmp = (g_u32hiMin * 10);
370 u32Tmp += g_u32loMin;
371 sPt->u32Minute = u32Tmp;
372
373 u32Tmp = (g_u32hiSec * 10);
374 u32Tmp += g_u32loSec;
375 sPt->u32Second = u32Tmp;
376
377 }
378 else
379 {
380 /* RTC_CLOCK_24 */
381 u32Tmp = (g_u32hiHour * 10);
382 u32Tmp += g_u32loHour;
383 sPt->u32Hour = u32Tmp;
384
385 u32Tmp = (g_u32hiMin * 10);
386 u32Tmp+= g_u32loMin;
387 sPt->u32Minute = u32Tmp;
388
389 u32Tmp = (g_u32hiSec * 10);
390 u32Tmp += g_u32loSec;
391 sPt->u32Second = u32Tmp;
392 }
393
394}
395
396
397
420 void RTC_SetDateAndTime(S_RTC_TIME_DATA_T *sPt)
421{
422 uint32_t u32Reg;
423
424 RTC_WaitAccessEnable();
425
426 if (sPt->u32TimeScale == RTC_CLOCK_12)
427 {
428 RTC->CLKFMT &= ~RTC_CLKFMT_24HEN_Msk;
429
430 /*-----------------------------------------------------------------------------------------*/
431 /* important, range of 12-hour PM mode is 21 up to 32 */
432 /*-----------------------------------------------------------------------------------------*/
433 if (sPt->u32AmPm == RTC_PM)
434 sPt->u32Hour += 20;
435 }
436 else /* RTC_CLOCK_24 */
437 {
438 RTC->CLKFMT |= RTC_CLKFMT_24HEN_Msk;
439 }
440
441 RTC->WEEKDAY = sPt->u32DayOfWeek & RTC_WEEKDAY_WEEKDAY_Msk;
442
443 u32Reg = ((sPt->u32Year - RTC_YEAR2000) / 10) << 20;
444 u32Reg |= (((sPt->u32Year - RTC_YEAR2000) % 10) << 16);
445 u32Reg |= ((sPt->u32Month / 10) << 12);
446 u32Reg |= ((sPt->u32Month % 10) << 8);
447 u32Reg |= ((sPt->u32Day / 10) << 4);
448 u32Reg |= (sPt->u32Day % 10);
449 g_u32Reg = u32Reg;
450
451 RTC_WaitAccessEnable();
452
453 RTC->CAL = (uint32_t)g_u32Reg;
454
455 u32Reg = ((sPt->u32Hour / 10) << 20);
456 u32Reg |= ((sPt->u32Hour % 10) << 16);
457 u32Reg |= ((sPt->u32Minute / 10) << 12);
458 u32Reg |= ((sPt->u32Minute % 10) << 8);
459 u32Reg |= ((sPt->u32Second / 10) << 4);
460 u32Reg |= (sPt->u32Second % 10);
461 g_u32Reg = u32Reg;
462
463 RTC_WaitAccessEnable();
464
465 RTC->TIME = (uint32_t)g_u32Reg;
466
467}
468
489 void RTC_SetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt)
490{
491 uint32_t u32Reg;
492
493 RTC_WaitAccessEnable();
494
495 if (sPt->u32TimeScale == RTC_CLOCK_12)
496 {
497 RTC->CLKFMT &= ~RTC_CLKFMT_24HEN_Msk;
498
499 /*-----------------------------------------------------------------------------------------*/
500 /* important, range of 12-hour PM mode is 21 up to 32 */
501 /*-----------------------------------------------------------------------------------------*/
502 if (sPt->u32AmPm == RTC_PM)
503 sPt->u32Hour += 20;
504 }
505 else /* RTC_CLOCK_24 */
506 {
507 RTC->CLKFMT |= RTC_CLKFMT_24HEN_Msk;
508 }
509
510 RTC->WEEKDAY = sPt->u32DayOfWeek & RTC_WEEKDAY_WEEKDAY_Msk;
511
512
513 u32Reg = ((sPt->u32Year - RTC_YEAR2000) / 10) << 20;
514 u32Reg |= (((sPt->u32Year - RTC_YEAR2000) % 10) << 16);
515 u32Reg |= ((sPt->u32Month / 10) << 12);
516 u32Reg |= ((sPt->u32Month % 10) << 8);
517 u32Reg |= ((sPt->u32Day / 10) << 4);
518 u32Reg |= (sPt->u32Day % 10);
519 g_u32Reg = u32Reg;
520
521 RTC_WaitAccessEnable();
522
523 RTC->CALM = (uint32_t)g_u32Reg;
524
525 u32Reg = ((sPt->u32Hour / 10) << 20);
526 u32Reg |= ((sPt->u32Hour % 10) << 16);
527 u32Reg |= ((sPt->u32Minute / 10) << 12);
528 u32Reg |= ((sPt->u32Minute % 10) << 8);
529 u32Reg |= ((sPt->u32Second / 10) << 4);
530 u32Reg |= (sPt->u32Second % 10);
531 g_u32Reg = u32Reg;
532
533 RTC_WaitAccessEnable();
534
535 RTC->TALM = (uint32_t)g_u32Reg;
536
537}
538
539
553 void RTC_SetDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day, uint32_t u32DayOfWeek)
554{
555 __IO uint32_t u32Reg;
556
557 RTC_WaitAccessEnable();
558
559 RTC->WEEKDAY = u32DayOfWeek & RTC_WEEKDAY_WEEKDAY_Msk;
560
561 u32Reg = ((u32Year - RTC_YEAR2000) / 10) << 20;
562 u32Reg |= (((u32Year - RTC_YEAR2000) % 10) << 16);
563 u32Reg |= ((u32Month / 10) << 12);
564 u32Reg |= ((u32Month % 10) << 8);
565 u32Reg |= ((u32Day / 10) << 4);
566 u32Reg |= (u32Day % 10);
567 g_u32Reg = u32Reg;
568
569 RTC_WaitAccessEnable();
570
571 RTC->CAL = (uint32_t)g_u32Reg;
572
573}
574
587 void RTC_SetTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm)
588{
589 __IO uint32_t u32Reg;
590
591 RTC_WaitAccessEnable();
592
593 if (u32TimeMode == RTC_CLOCK_12)
594 {
595 RTC->CLKFMT &= ~RTC_CLKFMT_24HEN_Msk;
596
597 if (u32AmPm == RTC_PM) /* important, range of 12-hour PM mode is 21 up to 32 */
598 u32Hour += 20;
599 }
600 else if(u32TimeMode == RTC_CLOCK_24)
601 {
602 RTC->CLKFMT |= RTC_CLKFMT_24HEN_Msk;
603 }
604
605 u32Reg = ((u32Hour / 10) << 20);
606 u32Reg |= ((u32Hour % 10) << 16);
607 u32Reg |= ((u32Minute / 10) << 12);
608 u32Reg |= ((u32Minute % 10) << 8);
609 u32Reg |= ((u32Second / 10) << 4);
610 u32Reg |= (u32Second % 10);
611
612 g_u32Reg = u32Reg;
613
614 RTC_WaitAccessEnable();
615
616 RTC->TIME = (uint32_t)g_u32Reg;
617
618}
619
630 void RTC_SetAlarmDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day)
631{
632 __IO uint32_t u32Reg;
633
634 RTC_WaitAccessEnable();
635
636 u32Reg = ((u32Year - RTC_YEAR2000) / 10) << 20;
637 u32Reg |= (((u32Year - RTC_YEAR2000) % 10) << 16);
638 u32Reg |= ((u32Month / 10) << 12);
639 u32Reg |= ((u32Month % 10) << 8);
640 u32Reg |= ((u32Day / 10) << 4);
641 u32Reg |= (u32Day % 10);
642 g_u32Reg = u32Reg;
643
644 RTC_WaitAccessEnable();
645
646 RTC->CALM = (uint32_t)g_u32Reg;
647
648}
649
662 void RTC_SetAlarmTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm)
663{
664 __IO uint32_t u32Reg;
665
666 RTC_WaitAccessEnable();
667
668 if (u32TimeMode == RTC_CLOCK_12)
669 {
670 RTC->CLKFMT &= ~RTC_CLKFMT_24HEN_Msk;
671
672 if (u32AmPm == RTC_PM) /* important, range of 12-hour PM mode is 21 up to 32 */
673 u32Hour += 20;
674 }
675 else if(u32TimeMode == RTC_CLOCK_24)
676 {
677 RTC->CLKFMT |= RTC_CLKFMT_24HEN_Msk;
678 }
679
680 u32Reg = ((u32Hour / 10) << 20);
681 u32Reg |= ((u32Hour % 10) << 16);
682 u32Reg |= ((u32Minute / 10) << 12);
683 u32Reg |= ((u32Minute % 10) << 8);
684 u32Reg |= ((u32Second / 10) << 4);
685 u32Reg |= (u32Second % 10);
686
687 g_u32Reg = u32Reg;
688
689 RTC_WaitAccessEnable();
690
691 RTC->TALM = (uint32_t)g_u32Reg;
692
693}
694
695
703int32_t RTC_EnableSpareAccess(void)
704{
705 uint32_t u32TimeOutCount = SystemCoreClock * 2; // 2 second timeout
706
707 RTC_WaitAccessEnable();
708
709 RTC->SPRCTL |= RTC_SPRCTL_SPRRWEN_Msk;
710
711 while(!(RTC->SPRCTL & RTC_SPRCTL_SPRRWRDY_Msk))
712 {
713 if(u32TimeOutCount == 0)
714 {
715 return -1;
716 }
717 u32TimeOutCount--;
718 }
719
720 return 0;
721}
722
723
741 void RTC_EnableTamperDetection(uint32_t u32PinNumber, uint32_t u32PinCondition, uint32_t u32IntFlag, uint32_t u32ClearFlag, uint32_t u32DestroyEn)
742{
743 uint32_t u32Tmp;
744
745 RTC_WaitAccessEnable();
746
747 u32Tmp = RTC->TAMPCTL;
748
749 if(u32PinNumber == RTC_TAMPER_0)
750 {
751 //if(u32ClearFlag)
752 // RTC->TAMPSTS = RTC_TAMPSTS_TAMPSTS0_Msk;
753
754 if(u32PinCondition)
755 u32Tmp |= RTC_TAMPCTL_TAMPLV0_Msk;
756 else
757 u32Tmp &= ~RTC_TAMPCTL_TAMPLV0_Msk;
758
759 u32Tmp |= RTC_TAMPCTL_TAMPDBEN0_Msk;
760 u32Tmp |= RTC_TAMPCTL_TAMPEN0_Msk;
761 }
762 else if(u32PinNumber == RTC_TAMPER_1)
763 {
764 //if(u32ClearFlag)
765 // RTC->TAMPSTS = RTC_TAMPSTS_TAMPSTS1_Msk;
766
767 if(u32PinCondition)
768 u32Tmp |= RTC_TAMPCTL_TAMPLV1_Msk;
769 else
770 u32Tmp &= ~RTC_TAMPCTL_TAMPLV1_Msk;
771
772 u32Tmp |= RTC_TAMPCTL_TAMPDBEN1_Msk;
773 u32Tmp |= RTC_TAMPCTL_TAMPEN1_Msk;
774 }
775
776 if(u32IntFlag)
777 u32Tmp |= RTC_TAMPCTL_TIEN_Msk;
778 else
779 u32Tmp &= ~RTC_TAMPCTL_TIEN_Msk;
780
781 if(u32DestroyEn)
782 u32Tmp |= RTC_TAMPCTL_DESTROYEN_Msk;
783 else
784 u32Tmp &= ~RTC_TAMPCTL_DESTROYEN_Msk;
785
786 RTC_WaitAccessEnable();
787
788 RTC->TAMPCTL = u32Tmp;
789
790 RTC_WaitAccessEnable();
791
792 if(u32PinNumber == RTC_TAMPER_0)
793 {
794 if(u32ClearFlag)
795 RTC->TAMPSTS = RTC_TAMPSTS_TAMPSTS0_Msk;
796 }
797 else if(u32PinNumber == RTC_TAMPER_1)
798 {
799 if(u32ClearFlag)
800 RTC->TAMPSTS = RTC_TAMPSTS_TAMPSTS1_Msk;
801 }
802}
803
812 void RTC_DisableTamperDetection(uint32_t u32PinNumber)
813{
814 RTC_WaitAccessEnable();
815
816 if(u32PinNumber == RTC_TAMPER_0)
817 {
818 RTC->TAMPCTL &= ~RTC_TAMPCTL_TAMPEN0_Msk;
819 }
820 else if(u32PinNumber == RTC_TAMPER_1)
821 {
822 RTC->TAMPCTL &= ~RTC_TAMPCTL_TAMPEN1_Msk;
823 }
824
825}
826
835uint32_t RTC_GetDayOfWeek(void)
836{
837 return (RTC->WEEKDAY & RTC_WEEKDAY_WEEKDAY_Msk);
838}
839
858 void RTC_SetTickPeriod(uint32_t u32TickSelection)
859{
860 RTC_WaitAccessEnable();
861
862 RTC->TICK = RTC->TICK & ~RTC_TICK_TICKSEL_Msk | u32TickSelection;
863}
864
875 void RTC_EnableInt(uint32_t u32IntFlagMask)
876{
877 RTC_WaitAccessEnable();
878
879 RTC->INTEN |= u32IntFlagMask;
880}
881
892 void RTC_DisableInt(uint32_t u32IntFlagMask)
893{
894 RTC_WaitAccessEnable();
895
896 if(u32IntFlagMask & RTC_INTEN_TICKIEN_Msk)
897 {
898 RTC->INTEN &= ~RTC_INTEN_TICKIEN_Msk;
899 RTC->INTSTS |= RTC_INTSTS_TICKIF_Msk;
900 }
901
902 if(u32IntFlagMask & RTC_INTEN_ALMIEN_Msk)
903 {
904 RTC->INTEN &= ~RTC_INTEN_ALMIEN_Msk;
905 RTC->INTSTS |= RTC_INTSTS_ALMIF_Msk;
906 }
907
908}
909
916 void RTC_Close (void)
917{
918 CLK->APBCLK0 &= ~CLK_APBCLK0_RTCCKEN_Msk;
919}
920
921 /* end of group NUC472_442_RTC_EXPORTED_FUNCTIONS */
923 /* end of group NUC472_442_RTC_Driver */
925 /* end of group NUC472_442_Device_Driver */
927
928/*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
929
930
NUC472_442.h
NUC472/NUC442 peripheral access layer header file. This file contains all the peripheral register's d...
RTC_TALM_MIN_Msk
#define RTC_TALM_MIN_Msk
Definition: NUC472_442.h:20925
RTC_INTEN_TICKIEN_Msk
#define RTC_INTEN_TICKIEN_Msk
Definition: NUC472_442.h:20961
RTC_TAMPCTL_TAMPEN1_Msk
#define RTC_TAMPCTL_TAMPEN1_Msk
Definition: NUC472_442.h:20988
RTC_CAL_TENDAY_Msk
#define RTC_CAL_TENDAY_Msk
Definition: NUC472_442.h:20898
RTC_CAL_TENYEAR_Msk
#define RTC_CAL_TENYEAR_Msk
Definition: NUC472_442.h:20910
RTC_SPRCTL_SPRRWRDY_Msk
#define RTC_SPRCTL_SPRRWRDY_Msk
Definition: NUC472_442.h:20976
RTC_TIME_SEC_Msk
#define RTC_TIME_SEC_Msk
Definition: NUC472_442.h:20877
RTC_TIME_TENSEC_Msk
#define RTC_TIME_TENSEC_Msk
Definition: NUC472_442.h:20880
RTC_TALM_HR_Pos
#define RTC_TALM_HR_Pos
Definition: NUC472_442.h:20930
RTC_TALM_TENMIN_Pos
#define RTC_TALM_TENMIN_Pos
Definition: NUC472_442.h:20927
RTC_INTSTS_ALMIF_Msk
#define RTC_INTSTS_ALMIF_Msk
Definition: NUC472_442.h:20964
RTC_CAL_YEAR_Msk
#define RTC_CAL_YEAR_Msk
Definition: NUC472_442.h:20907
RTC_TIME_TENSEC_Pos
#define RTC_TIME_TENSEC_Pos
Definition: NUC472_442.h:20879
RTC_CAL_MON_Pos
#define RTC_CAL_MON_Pos
Definition: NUC472_442.h:20900
RTC_SPRCTL_SPRRWEN_Msk
#define RTC_SPRCTL_SPRRWEN_Msk
Definition: NUC472_442.h:20973
RTC_TAMPCTL_TAMPDBEN1_Msk
#define RTC_TAMPCTL_TAMPDBEN1_Msk
Definition: NUC472_442.h:20994
RTC_CALM_DAY_Msk
#define RTC_CALM_DAY_Msk
Definition: NUC472_442.h:20937
RTC_TALM_TENSEC_Pos
#define RTC_TALM_TENSEC_Pos
Definition: NUC472_442.h:20921
RTC_TIME_MIN_Msk
#define RTC_TIME_MIN_Msk
Definition: NUC472_442.h:20883
RTC_TALM_TENMIN_Msk
#define RTC_TALM_TENMIN_Msk
Definition: NUC472_442.h:20928
RTC_CALM_TENYEAR_Msk
#define RTC_CALM_TENYEAR_Msk
Definition: NUC472_442.h:20952
RTC_TIME_TENHR_Pos
#define RTC_TIME_TENHR_Pos
Definition: NUC472_442.h:20891
RTC_TAMPCTL_TAMPLV0_Msk
#define RTC_TAMPCTL_TAMPLV0_Msk
Definition: NUC472_442.h:20997
RTC_CALM_YEAR_Pos
#define RTC_CALM_YEAR_Pos
Definition: NUC472_442.h:20948
RTC_TAMPCTL_TAMPLV1_Msk
#define RTC_TAMPCTL_TAMPLV1_Msk
Definition: NUC472_442.h:21000
RTC_INTEN_ALMIEN_Msk
#define RTC_INTEN_ALMIEN_Msk
Definition: NUC472_442.h:20958
RTC_TIME_HR_Msk
#define RTC_TIME_HR_Msk
Definition: NUC472_442.h:20889
RTC_CAL_TENMON_Pos
#define RTC_CAL_TENMON_Pos
Definition: NUC472_442.h:20903
RTC_CALM_TENDAY_Pos
#define RTC_CALM_TENDAY_Pos
Definition: NUC472_442.h:20939
RTC_CLKFMT_24HEN_Msk
#define RTC_CLKFMT_24HEN_Msk
Definition: NUC472_442.h:20913
RTC_CALM_TENMON_Pos
#define RTC_CALM_TENMON_Pos
Definition: NUC472_442.h:20945
RTC_TALM_HR_Msk
#define RTC_TALM_HR_Msk
Definition: NUC472_442.h:20931
RTC_CAL_TENMON_Msk
#define RTC_CAL_TENMON_Msk
Definition: NUC472_442.h:20904
RTC_INTSTS_TICKIF_Msk
#define RTC_INTSTS_TICKIF_Msk
Definition: NUC472_442.h:20967
RTC_CALM_MON_Msk
#define RTC_CALM_MON_Msk
Definition: NUC472_442.h:20943
RTC_CAL_TENYEAR_Pos
#define RTC_CAL_TENYEAR_Pos
Definition: NUC472_442.h:20909
RTC_TIME_TENMIN_Msk
#define RTC_TIME_TENMIN_Msk
Definition: NUC472_442.h:20886
RTC_CAL_MON_Msk
#define RTC_CAL_MON_Msk
Definition: NUC472_442.h:20901
RTC_TAMPCTL_TAMPEN0_Msk
#define RTC_TAMPCTL_TAMPEN0_Msk
Definition: NUC472_442.h:20985
RTC_TALM_TENSEC_Msk
#define RTC_TALM_TENSEC_Msk
Definition: NUC472_442.h:20922
RTC_TAMPCTL_TAMPDBEN0_Msk
#define RTC_TAMPCTL_TAMPDBEN0_Msk
Definition: NUC472_442.h:20991
RTC_CAL_TENDAY_Pos
#define RTC_CAL_TENDAY_Pos
Definition: NUC472_442.h:20897
RTC_WEEKDAY_WEEKDAY_Msk
#define RTC_WEEKDAY_WEEKDAY_Msk
Definition: NUC472_442.h:20916
RTC_CAL_YEAR_Pos
#define RTC_CAL_YEAR_Pos
Definition: NUC472_442.h:20906
RTC_CALM_TENMON_Msk
#define RTC_CALM_TENMON_Msk
Definition: NUC472_442.h:20946
RTC_CALM_MON_Pos
#define RTC_CALM_MON_Pos
Definition: NUC472_442.h:20942
RTC_TIME_TENMIN_Pos
#define RTC_TIME_TENMIN_Pos
Definition: NUC472_442.h:20885
RTC_TAMPSTS_TAMPSTS1_Msk
#define RTC_TAMPSTS_TAMPSTS1_Msk
Definition: NUC472_442.h:21006
RTC_TAMPCTL_DESTROYEN_Msk
#define RTC_TAMPCTL_DESTROYEN_Msk
Definition: NUC472_442.h:20982
RTC_TIME_HR_Pos
#define RTC_TIME_HR_Pos
Definition: NUC472_442.h:20888
RTC_TIME_MIN_Pos
#define RTC_TIME_MIN_Pos
Definition: NUC472_442.h:20882
RTC_TALM_TENHR_Pos
#define RTC_TALM_TENHR_Pos
Definition: NUC472_442.h:20933
RTC_CALM_TENDAY_Msk
#define RTC_CALM_TENDAY_Msk
Definition: NUC472_442.h:20940
RTC_TALM_SEC_Msk
#define RTC_TALM_SEC_Msk
Definition: NUC472_442.h:20919
RTC_CAL_DAY_Msk
#define RTC_CAL_DAY_Msk
Definition: NUC472_442.h:20895
RTC_TAMPSTS_TAMPSTS0_Msk
#define RTC_TAMPSTS_TAMPSTS0_Msk
Definition: NUC472_442.h:21003
RTC_CALM_YEAR_Msk
#define RTC_CALM_YEAR_Msk
Definition: NUC472_442.h:20949
RTC_TIME_TENHR_Msk
#define RTC_TIME_TENHR_Msk
Definition: NUC472_442.h:20892
RTC_TAMPCTL_TIEN_Msk
#define RTC_TAMPCTL_TIEN_Msk
Definition: NUC472_442.h:20979
RTC_TALM_TENHR_Msk
#define RTC_TALM_TENHR_Msk
Definition: NUC472_442.h:20934
RTC_TALM_MIN_Pos
#define RTC_TALM_MIN_Pos
Definition: NUC472_442.h:20924
RTC_RWEN_RWENF_Msk
#define RTC_RWEN_RWENF_Msk
Definition: NUC472_442.h:20868
RTC_CALM_TENYEAR_Pos
#define RTC_CALM_TENYEAR_Pos
Definition: NUC472_442.h:20951
CLK
#define CLK
Definition: NUC472_442.h:28798
RTC
#define RTC
Definition: NUC472_442.h:28828
RTC_TAMPER_0
#define RTC_TAMPER_0
Definition: rtc.h:68
g_RTC_i32ErrCode
int32_t g_RTC_i32ErrCode
RTC_TAMPER_1
#define RTC_TAMPER_1
Definition: rtc.h:69
RTC_CLOCK_24
#define RTC_CLOCK_24
Definition: rtc.h:46
RTC_CLOCK_12
#define RTC_CLOCK_12
Definition: rtc.h:45
RTC_INIT_KEY
#define RTC_INIT_KEY
Definition: rtc.h:37
RTC_PM
#define RTC_PM
Definition: rtc.h:49
RTC_FCR_REFERENCE
#define RTC_FCR_REFERENCE
Definition: rtc.h:43
RTC_AM
#define RTC_AM
Definition: rtc.h:48
RTC_TIMEOUT_ERR
#define RTC_TIMEOUT_ERR
Definition: rtc.h:35
RTC_WRITE_KEY
#define RTC_WRITE_KEY
Definition: rtc.h:38
RTC_YEAR2000
#define RTC_YEAR2000
Definition: rtc.h:42
RTC_EnableInt
void RTC_EnableInt(uint32_t u32IntFlagMask)
The function is used to enable specified interrupt.
Definition: rtc.c:875
RTC_GetDayOfWeek
uint32_t RTC_GetDayOfWeek(void)
This function is used to get day of week.
Definition: rtc.c:835
RTC_SetDateAndTime
void RTC_SetDateAndTime(S_RTC_TIME_DATA_T *sPt)
This function is used to update date/time to RTC.
Definition: rtc.c:420
RTC_EnableTamperDetection
void RTC_EnableTamperDetection(uint32_t u32PinNumber, uint32_t u32PinCondition, uint32_t u32IntFlag, uint32_t u32ClearFlag, uint32_t u32DestroyEn)
This function is used to:
Definition: rtc.c:741
S_RTC_TIME_DATA_T::u32Month
uint32_t u32Month
Definition: rtc.h:85
S_RTC_TIME_DATA_T::u32AmPm
uint32_t u32AmPm
Definition: rtc.h:92
RTC_GetAlarmDateAndTime
void RTC_GetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt)
Read alarm date/time from RTC setting.
Definition: rtc.c:318
RTC_Open
void RTC_Open(S_RTC_TIME_DATA_T *sPt)
This function is used to:
Definition: rtc.c:124
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:489
S_RTC_TIME_DATA_T::u32Hour
uint32_t u32Hour
Definition: rtc.h:88
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:553
RTC_DisableTamperDetection
void RTC_DisableTamperDetection(uint32_t u32PinNumber)
This function is used to disable tamper detection function.
Definition: rtc.c:812
RTC_Close
void RTC_Close(void)
Disable RTC clock.
Definition: rtc.c:916
RTC_32KCalibration
void RTC_32KCalibration(int32_t i32FrequencyX100)
Set Frequency Compensation Data.
Definition: rtc.c:81
S_RTC_TIME_DATA_T::u32Minute
uint32_t u32Minute
Definition: rtc.h:89
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:587
S_RTC_TIME_DATA_T::u32Day
uint32_t u32Day
Definition: rtc.h:86
S_RTC_TIME_DATA_T::u32DayOfWeek
uint32_t u32DayOfWeek
Definition: rtc.h:87
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:662
RTC_DisableInt
void RTC_DisableInt(uint32_t u32IntFlagMask)
The function is used to disable specified interrupt.
Definition: rtc.c:892
S_RTC_TIME_DATA_T::u32Year
uint32_t u32Year
Definition: rtc.h:84
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:858
RTC_EnableSpareAccess
int32_t RTC_EnableSpareAccess(void)
The spare registers access enable.
Definition: rtc.c:703
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:630
S_RTC_TIME_DATA_T::u32Second
uint32_t u32Second
Definition: rtc.h:90
S_RTC_TIME_DATA_T::u32TimeScale
uint32_t u32TimeScale
Definition: rtc.h:91
RTC_GetDateAndTime
void RTC_GetDateAndTime(S_RTC_TIME_DATA_T *sPt)
Read current date/time from RTC setting.
Definition: rtc.c:224
NULL
#define NULL
NULL pointer.
Definition: NUC472_442.h:29018
S_RTC_TIME_DATA_T
RTC define Time Data Struct.
Definition: rtc.h:83
SystemCoreClock
uint32_t SystemCoreClock
Definition: system_NUC472_442.c:17