62 #if (defined(PDL_PERIPHERAL_RTC_ACTIVE))
74 #define RTC_YEAR_1900 (1900)
75 #define RTC_YEAR_2000 (2000)
76 #define RTC_SEC_MAX (59u)
77 #define RTC_MIN_MAX (59u)
78 #define RTC_HOUR_MAX (23u)
79 #define RTC_DAY_MAX (31u)
80 #define RTC_MONTH_MAX (12u)
81 #define RTC_DAYOFWEEK_MAX (6u)
82 #define RTC_YEAR_MAX (99u)
87 #define RTC_16BIT (16u)
88 #define RTC_DIGIT_10 (10u)
89 #define RTC_2BYTES (2u)
90 #define RTC_4BYTES (4u)
93 #define RTC_WTCR20_PWRITE (0x20u)
94 #define RTC_WTCR20_PREAD (0x10u)
95 #define RTC_WTCR20_BWRITE (0x08u)
96 #define RTC_WTCR20_BREAD (0x04u)
97 #define RTC_WTCR20_CWRITE (0x02u)
98 #define RTC_WTCR20_CREAD (0x01u)
101 #define RTC_MASK_LOW4BIT (0x0Fu)
102 #define RTC_MASK_HIGH4BIT (0xF0u)
119 struct tm* pstcTime);
144 u32NvicData = NVIC->ISER[(uint32_t)((int32_t)RTC_IRQn) >> 5];
145 NVIC->ICER[((uint32_t)(RTC_IRQn) >> 5)] = (1 << ((uint32_t)(RTC_IRQn) & 0x1F));
154 NVIC->ISER[(uint32_t)((int32_t)RTC_IRQn) >> 5] =
u32NvicData;
170 pstcTime->tm_mon = (int)(pstcRtcTime->
u8Month - 1);
171 pstcTime->tm_mday = (int)(pstcRtcTime->
u8Day);
172 pstcTime->tm_sec = (int)(pstcRtcTime->
u8Second);
173 pstcTime->tm_min = (int)(pstcRtcTime->
u8Minute);
174 pstcTime->tm_hour = (int)(pstcRtcTime->
u8Hour);
175 pstcTime->tm_isdst = 0;
230 #if (PDL_PERIPHERAL_ENABLE_RTC0 == PDL_ON)
231 NVIC_ClearPendingIRQ(RTC_IRQn);
232 NVIC_EnableIRQ(RTC_IRQn);
245 #if (PDL_PERIPHERAL_ENABLE_RTC0 == PDL_ON)
246 NVIC_ClearPendingIRQ(RTC_IRQn);
247 NVIC_DisableIRQ(RTC_IRQn);
263 uint32_t u32WaitCompleteTimeout;
266 while ((
TRUE == FM4_RTC->WTCR10_f.TRANS)
267 && (0 != u32WaitCompleteTimeout)
271 u32WaitCompleteTimeout--;
274 if (0 == u32WaitCompleteTimeout)
297 FM4_RTC->WTCR20 = u8Control;
311 stc_rtc_wtcr12_field_t stcWtcr12;
323 stcWtcr12 = FM4_RTC->WTCR12_f;
326 if (
TRUE == stcWtcr12.INTCRI)
329 stcWtcr12.INTCRI =
FALSE;
357 if (
TRUE == stcWtcr12.INTERI)
360 stcWtcr12.INTERI =
FALSE;
370 if (
TRUE == stcWtcr12.INTALI)
373 stcWtcr12.INTALI =
FALSE;
383 if (
TRUE == stcWtcr12.INTTMI)
386 stcWtcr12.INTTMI =
FALSE;
396 if (
TRUE == stcWtcr12.INTSSI)
399 stcWtcr12.INTSSI =
FALSE;
409 if (
TRUE == stcWtcr12.INTSI)
412 stcWtcr12.INTSI =
FALSE;
422 if (
TRUE == stcWtcr12.INTMI)
425 stcWtcr12.INTMI =
FALSE;
435 if (
TRUE == stcWtcr12.INTHI)
438 stcWtcr12.INTHI =
FALSE;
447 FM4_RTC->WTCR12_f = stcWtcr12;
491 if((
TRUE == bResetNoReInit) && (
TRUE == FM4_RTC->WTCR10_f.ST))
499 if (
TRUE == bTouchNvic)
517 else if (NULL == pstcConfig)
544 if (NULL != pstcAlarm)
569 FM4_RTC->WTCALEN = 1;
573 FM4_RTC->WTCALEN = 0;
608 FM4_RTC->WTDIVEN_f.WTDIVEN =
TRUE;
612 FM4_RTC->WTDIVEN_f.WTDIVEN =
FALSE;
616 if (RTC_MAX_FREQ_CORR_CYCLE_SET_VALUE < pstcConfig->u8FreqCorrCycle)
630 FM4_RTC->WTCOSEL_f.WTCOSEL =
FALSE;
633 FM4_RTC->WTCOSEL_f.WTCOSEL =
TRUE;
672 if (
TRUE == bTouchNvic)
689 FM4_RTC->WTCR10_f.ST =
TRUE;
734 uint32_t u32BusyTimeout;
735 stc_rtc_wtcr12_field_t stcWtcr12;
736 stc_rtc_wtcr13_field_t stcWtcr13;
739 if ((NULL == pstcRtcTime)
741 || (RTC_SEC_MAX < pstcRtcTime->u8Second)
743 || (RTC_MIN_MAX < pstcRtcTime->u8Minute)
745 || (RTC_HOUR_MAX < pstcRtcTime->u8Hour)
747 || ((RTC_DAY_MAX < pstcRtcTime->u8Day) || (0 == pstcRtcTime->
u8Day))
749 || (RTC_DAYOFWEEK_MAX < pstcRtcTime->u8DayOfWeek)
751 || ((RTC_MONTH_MAX < pstcRtcTime->u8Month) || (0 == pstcRtcTime->
u8Month))
753 || ((RTC_YEAR_MAX < pstcRtcTime->u8Year) || (0 == pstcRtcTime->
u8Year)))
765 if (
TRUE == FM4_RTC->WTCR10_f.ST)
768 stcWtcr13 = FM4_RTC->WTCR13_f;
772 while (((
TRUE == FM4_RTC->WTCR10_f.BUSY) || (
TRUE == FM4_RTC->WTCR10_f.SCST)) &&
773 (0 != u32BusyTimeout)
780 if (0 == u32BusyTimeout)
794 stcWtcr12 = FM4_RTC->WTCR12_f;
795 stcWtcr12.INTSI =
FALSE;
796 FM4_RTC->WTCR12_f = stcWtcr12;
799 FM4_RTC->WTCR13_f.INTSIE =
TRUE;
804 stcWtcr12 = FM4_RTC->WTCR12_f;
805 }
while (0 == stcWtcr12.INTSI);
808 FM4_RTC->WTCR12_f.INTSI = 0;
811 FM4_RTC->WTCR10_f.SCST =
TRUE;
814 FM4_RTC->WTCR13_f = stcWtcr13;
836 if (
TRUE == FM4_RTC->WTCR10_f.ST)
839 FM4_RTC->WTCR10_f.SCST =
FALSE;
871 stc_rtc_wtcr10_field_t stcWtcr10;
872 stc_rtc_wtcr12_field_t stcWtcr12;
873 stc_rtc_wtcr13_field_t stcWtcr13;
876 if ((NULL == pstcRtcAlarm)
878 || ((RTC_DAY_MAX < pstcRtcAlarm->u8AlarmDay) || (0 == pstcRtcAlarm->
u8AlarmDay))
880 || (RTC_HOUR_MAX < pstcRtcAlarm->u8AlarmHour)
882 || (RTC_MIN_MAX < pstcRtcAlarm->u8AlarmMinute)
884 || ((RTC_YEAR_MAX < pstcRtcAlarm->u8AlarmYear) || (0 == pstcRtcAlarm->
u8AlarmYear))
886 || ((RTC_MONTH_MAX < pstcRtcAlarm->u8AlarmMonth) || (0 == pstcRtcAlarm->
u8AlarmMonth)))
901 if (
TRUE == FM4_RTC->WTCR10_f.ST)
903 stcWtcr10 = FM4_RTC->WTCR10_f;
904 stcWtcr13 = FM4_RTC->WTCR13_f;
906 FM4_RTC->WTCR10_f.ST =
FALSE;
915 stcWtcr12 = FM4_RTC->WTCR12_f;
916 stcWtcr12.INTCRI =
FALSE;
917 FM4_RTC->WTCR12_f = stcWtcr12;
920 FM4_RTC->WTCR13_f.INTCRIE =
TRUE;
925 FM4_RTC->WTCR13_f = stcWtcr13;
926 if (
TRUE == stcWtcr10.ST)
928 FM4_RTC->WTCR10_f.ST =
TRUE;
942 stcWtcr12 = FM4_RTC->WTCR12_f;
943 stcWtcr12.INTCRI =
FALSE;
944 stcWtcr12.INTSI =
FALSE;
945 FM4_RTC->WTCR12_f = stcWtcr12;
955 FM4_RTC->WTCR13_f.INTSIE =
TRUE;
960 stcWtcr12 = FM4_RTC->WTCR12_f;
961 }
while (
FALSE == stcWtcr12.INTSI);
967 FM4_RTC->WTCR10_f.ST =
TRUE;
971 FM4_RTC->WTCR13_f = stcWtcr13;
1008 stc_rtc_wtcr13_field_t stcWtcr13 = { 0 };
1014 if (NULL != pstcConfig)
1019 stcWtcr13.INTCRIE =
TRUE;
1025 stcWtcr13.INTERIE =
TRUE;
1031 stcWtcr13.INTALIE =
TRUE;
1037 stcWtcr13.INTTMIE =
TRUE;
1043 stcWtcr13.INTHIE =
TRUE;
1049 stcWtcr13.INTMIE =
TRUE;
1055 stcWtcr13.INTSIE =
TRUE;
1061 stcWtcr13.INTSSIE =
TRUE;
1064 FM4_RTC->WTCR13_f = stcWtcr13;
1089 stc_rtc_wtcr11_field_t stcWtcr11 = { 0 };
1095 if (NULL != pstcRtcAlarmEn)
1100 stcWtcr11.YEN =
TRUE;
1106 stcWtcr11.MOEN =
TRUE;
1112 stcWtcr11.DEN =
TRUE;
1118 stcWtcr11.HEN =
TRUE;
1124 stcWtcr11.MIEN =
TRUE;
1127 FM4_RTC->WTCR11_f = stcWtcr11;
1163 if (NULL != pstcRtcTime)
1165 u8Wtcr13 = FM4_RTC->WTCR13;
1166 FM4_RTC->WTCR13_f.INTCRIE =
FALSE;
1173 FM4_RTC->WTCR13 = u8Wtcr13;
1182 FM4_RTC->WTCR13 = u8Wtcr13;
1189 u8Wtcr12 = FM4_RTC->WTCR12;
1191 FM4_RTC->WTCR12 = u8Wtcr12;
1203 FM4_RTC->WTCR13 = u8Wtcr13;
1230 if (
TRUE == FM4_RTC->WTCR10_f.TRANS)
1266 uint32_t u32WaitPollingTimeout;
1267 stc_rtc_wtcr12_field_t stcWtcr12;
1268 stc_rtc_wtcr13_field_t stcWtcr13;
1269 stc_rtc_wtcr21_field_t stcWtcr21;
1272 if ((NULL == pstcConfig)
1274 || (RTC_MAX_TIMER_SET_VALUE < pstcConfig->u32TimerValue)
1285 stcWtcr21 = FM4_RTC->WTCR21_f;
1287 FM4_RTC->WTCR21_f.TMST =
FALSE;
1295 FM4_RTC->WTCR21_f.TMEN =
TRUE;
1300 FM4_RTC->WTCR21_f.TMEN =
FALSE;
1307 FM4_RTC->WTCR21_f = stcWtcr21;
1316 while((
TRUE == FM4_RTC->WTCR21_f.TMRUN) && (0 != u32WaitPollingTimeout))
1319 u32WaitPollingTimeout--;
1321 if (0 == u32WaitPollingTimeout)
1329 stcWtcr13 = FM4_RTC->WTCR13_f;
1330 if (
TRUE == FM4_RTC->WTCR10_f.RUN)
1333 FM4_RTC->WTCR13 = 0;
1336 stcWtcr12 = FM4_RTC->WTCR12_f;
1337 stcWtcr12.INTSI =
FALSE;
1338 FM4_RTC->WTCR12_f = stcWtcr12;
1341 FM4_RTC->WTCR13_f.INTSIE =
TRUE;
1346 stcWtcr12 = FM4_RTC->WTCR12_f;
1347 }
while (0 == stcWtcr12.INTSI);
1350 FM4_RTC->WTCR12_f.INTSI = 0;
1361 FM4_RTC->WTCR13_f = stcWtcr13;
1386 stc_rtc_wtcr21_field_t stcWtcr21;
1389 stcWtcr21 = FM4_RTC->WTCR21_f;
1391 FM4_RTC->WTCR21_f.TMST =
TRUE;
1397 FM4_RTC->WTCR21_f = stcWtcr21;
1421 stc_rtc_wtcr21_field_t stcWtcr21;
1424 stcWtcr21 = FM4_RTC->WTCR21_f;
1426 FM4_RTC->WTCR21_f.TMST =
FALSE;
1432 FM4_RTC->WTCR21_f = stcWtcr21;
1452 stc_rtc_wtcr21_field_t stcWtcr21;
1455 stcWtcr21 = FM4_RTC->WTCR21_f;
1457 if (
FALSE == stcWtcr21.TMRUN)
1483 if (
FALSE == FM4_RTC->WTCR10_f.TRANS)
1516 FM4_RTC->WTCR10 = 0;
1517 FM4_RTC->WTCR11 = 0;
1518 FM4_RTC->WTCR12 = 0;
1519 FM4_RTC->WTCR13 = 0;
1520 FM4_RTC->WTCR20 = 0;
1521 FM4_RTC->WTCR21 = 0;
1539 FM4_RTC->WTCAL0 = 0;
1540 FM4_RTC->WTCAL1 = 0;
1541 FM4_RTC->WTCALEN = 0;
1543 FM4_RTC->WTDIVEN = 0;
1544 FM4_RTC->WTCALPRD = 0;
1545 FM4_RTC->WTCOSEL = 0;
1571 if (NULL == pstcRtcTime)
1578 RtcToTm(pstcRtcTime, &stcTime);
1579 uiTime = mktime(&stcTime);
1607 if (NULL != pstcRtcTime)
1611 RtcToTm(pstcRtcTime, &stcTime);
1614 if ((time_t)
RTC_ERR == mktime(&stcTime))
1622 pstcRtcTime->
u8DayOfWeek = (uint8_t)(stcTime.tm_wday);
1648 struct tm* pstcTime;
1653 if (NULL != pstcRtcTime)
1656 pstcTime = localtime((
const time_t*) &tRawTime);
1659 if (NULL == pstcTime)
1666 pstcRtcTime->
u8Month = (uint8_t)(pstcTime->tm_mon + 1);
1667 pstcRtcTime->
u8Day = (uint8_t)(pstcTime->tm_mday);
1668 pstcRtcTime->
u8Second = (uint8_t)(pstcTime->tm_sec);
1669 pstcRtcTime->
u8Minute = (uint8_t)(pstcTime->tm_min);
1670 pstcRtcTime->
u8Hour = (uint8_t)(pstcTime->tm_hour);
1671 pstcRtcTime->
u8DayOfWeek = (uint8_t)(pstcTime->tm_wday);
1697 volatile uint8_t* pu8BkupRegAddr;
1710 *pu8BkupRegAddr = u8Data;
1739 volatile uint16_t* pu16BkupRegAddr;
1756 *pu16BkupRegAddr = u16Data;
1785 volatile uint32_t* pu32BkupRegAddr;
1802 *pu32BkupRegAddr = u32Data;
1826 uint8_t u8RetVal = 0;
1827 volatile uint8_t* pu8BkupRegAddr;
1839 u8RetVal = *pu8BkupRegAddr;
1861 uint16_t u16RetVal = 0;
1862 volatile uint16_t* pu16BkupRegAddr;
1877 u16RetVal = *pu16BkupRegAddr;
1899 uint32_t u32RetVal = 0;
1900 volatile uint32_t* pu32BkupRegAddr;
1915 u32RetVal = *pu32BkupRegAddr;