/************************************************************************* * Function Name: RTC_SetDateTime * Parameters: LPC_Rtc_DateTime_t *pDateTime * Return: int * 0: sucess * 1: fail * Description: Set your specifying date and time * *************************************************************************/ int RTC_SetDateTime (LPC_Rtc_DateTime_t *pDateTime) { /* Valid Judge */ if (IsValidDay(pDateTime->year, pDateTime->month, pDateTime->day) == 0){ return 1; } if ( pDateTime->hour > 23 || pDateTime->minute > 59 ||pDateTime->second > 59){ return 1; } /* Calulate DOW, DOY */ pDateTime->doy = GetDOY(pDateTime->year, pDateTime->month, pDateTime->day); pDateTime->dow = GetDOW(pDateTime->year, pDateTime->month, pDateTime->day); RTC_DOM = pDateTime->day; RTC_MONTH = pDateTime->month; RTC_YEAR = pDateTime->year; RTC_DOW = pDateTime->dow; RTC_DOY = pDateTime->doy; RTC_HOUR = pDateTime->hour; RTC_MIN = pDateTime->minute; RTC_SEC = pDateTime->second; RTC_datetime_to_unix( &unix_time, pDateTime); return 0; }
extern "C" void RTC_IRQHandler(void){ // RTC_ClearIntPending(LPC_RTC, RTC_INT_COUNTER_INCREASE); // secondlyCheck(); // return; uint32_t secval; // This is increment counter interrupt if (RTC_GetIntPending(LPC_RTC, RTC_INT_COUNTER_INCREASE)){ // Clear pending interrupt RTC_ClearIntPending(LPC_RTC, RTC_INT_COUNTER_INCREASE); _60th_SEC_COUNT=0; time2.second_inc=1; //run checks at xx:xx:00 if(!GetSS()){ //run checks at xx:00:00 if(!GetMM()){ //run daily checks at 00:00:00 if(!GetHH()){ //run weekly checks at Mon 00:00:00 if(1 == GetDOW()){ //run weekly checks at 1st Mon 00:00:00 if(1 == GetDOM()){ //run weekly checks at Jan 1st Mon 00:00:00 if(1 == GetM()){ yearlyCheck(); } monthlyCheck(); } weeklyCheck(); } dailyCheck(); } hourlyCheck(); } minutelyCheck(); } secondlyCheck(); } // Continue to check the Alarm match if (RTC_GetIntPending(LPC_RTC, RTC_INT_ALARM)){ // Clear pending interrupt RTC_ClearIntPending(LPC_RTC, RTC_INT_ALARM); set_next_alarm(); sort_alarms(); /* Send debug information */ // _DBG_ ("ALARM 10s matched!"); } }
/************************************************************************* * Function Name: RTC_SetDate * Parameters: LPC_Rtc_Date_t *pDate * Return: int * 0: sucess * 1: fail * Description: Set your specifying date * *************************************************************************/ int RTC_SetDate (LPC_Rtc_Date_t *pDate) { /* Valid Judge */ if (IsValidDay(pDate->year, pDate->month, pDate->day) == 0) return 1; /* Calulate DOW, DOY */ pDate->doy = GetDOY(pDate->year, pDate->month, pDate->day); pDate->dow = GetDOW(pDate->year, pDate->month, pDate->day); RTC_DOM=pDate->day; RTC_MONTH=pDate->month; RTC_YEAR=pDate->year; RTC_DOW=pDate->dow; RTC_DOY=pDate->doy; return 0; }