void updateTime() { uint32_t TimeVar = RTC_GetCounter(); /* Reset RTC Counter when Time is 23:59:59 */ if (RTC_GetCounter() >= 0x0001517F) { RTC_SetCounter(0x0); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); DateUpdate(); } /* Compute hours */ mHour = TimeVar / 3600; /* Compute minutes */ mMinute = (TimeVar % 3600) / 60; /* Compute seconds */ mSecond = (TimeVar % 3600) % 60; }
void save_2g_err( unsigned char force, GPRS_REASON reason) { u16 result_temp ; //force=1: save to BK reg even BKP_DR1 have data, force=0: don't save if have data //BKP_DR1, ERR index: 15~12:MCU reset // 11~8:upgrade fw failure code // 7~4:GPRS failure reason // 3~0:GSM module poweroff reason //BKP_DR4, GPRS failure time (UTC Time) high //BKP_DR5, GPRS failure time (UTC Time) low if ( (BKP_ReadBackupRegister(BKP_DR1))&0x00F0 ) {//have data if ( !force ) {//don't cover if have data return ; } } result_temp = (BKP_ReadBackupRegister(BKP_DR1))&0xFF0F; result_temp = result_temp | ((reason<<4)&0xF0) ; BKP_WriteBackupRegister(BKP_DR1, result_temp); BKP_WriteBackupRegister(BKP_DR4, ((RTC_GetCounter( ))>>16)&0xFFFF);//high BKP_WriteBackupRegister(BKP_DR5, (RTC_GetCounter( ))&0xFFFF);//low }
void rtc_gettime (RTC_t *rtc) { uint32_t t; while ( ( t = RTC_GetCounter() ) != RTC_GetCounter() ) { ; } counter_to_struct( t, rtc ); // get non DST time adjustDST( rtc ); }
timeval getTime(void) { timeval tv; #ifndef PRECISION_IN_MS tv.tv_sec = RTC_GetCounter(); #else tv.tv_sec = seconds; tv.tv_msec = RTC_GetCounter(); #endif return tv; }
void CheckForDaysElapsed(void) { uint8_t DaysElapsed; if((RTC_GetCounter() / SECONDS_IN_DAY) != 0) { for(DaysElapsed = 0; DaysElapsed < (RTC_GetCounter() / SECONDS_IN_DAY)\ ;DaysElapsed++) { DateUpdate(); } RTC_SetCounter(RTC_GetCounter() % SECONDS_IN_DAY); } }
void rtc_event(void) { if(RTC_GetITStatus(RTC_IT_SEC) != RESET) { /* Clear the RTC Second interrupt */ RTC_ClearITPendingBit(RTC_IT_SEC); /* Toggle led connected to PC.06 pin each 1s */ GPIO_WriteBit(GPIOC, GPIO_Pin_6, (BitAction)(1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_6))); /* Enable time update */ if( s_rtc_service ) { time_show(); } /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Reset RTC Counter when Time is 23:59:59 */ if(RTC_GetCounter() == 0x00015180) { RTC_SetCounter(0x0); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); } } }
/*************************************************************************** Declaration : void sleep(char wdt_prescaler) Description : Sleep until WDT interrupt controlled by wdt_prescaler ***************************************************************************/ void sleep(int data_ms, char mode) { /* Enable the RTC Alarm interrupt */ RTC_ITConfig(RTC_IT_ALR, ENABLE); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Alarm in data_ms */ // RTC_SetAlarm(RTC_GetCounter()+ data_ms<<5); RTC_SetAlarm(RTC_GetCounter()+ data_ms); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Request to enter STOP mode with regulator ON */ PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI); /* At this stage the system has resumed from STOP mode -------------------*/ /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL as system clock source (HSE and PLL are disabled in STOP mode) */ /* Enable the RTC Alarm interrupt */ SYSCLKConfig_STOP(); RTC_ITConfig(RTC_IT_ALR, DISABLE); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); }
/********************************************************************* * @fn HandleTimers * Handles the MSG_TIMER_EXPIRY messages * *********************************************************************/ static void HandleTimers(MsgTimerExpiry *pTimerExp) { uint32_t timeStamp; switch (pTimerExp->userValue) { case TIMER_REF_PRESSURE_READ: /* Schedule the next sampling */ ASFTimerStart(SENSOR_ACQ_TASK_ID, TIMER_REF_PRESSURE_READ, PRESSURE_SAMPLE_PERIOD, &sPressureTimer); timeStamp = GetCurrentTime(); SensorDataHandler(PRESSURE_INPUT_SENSOR, timeStamp); break; #ifndef INTERRUPT_BASED_SAMPLING case TIMER_REF_SENSOR_READ: /* Schedule the next sampling */ ASFTimerStart(SENSOR_ACQ_TASK_ID, TIMER_REF_SENSOR_READ, SENSOR_SAMPLE_PERIOD, &sSensorTimer); /* Call data handler for each sensors */ timeStamp = RTC_GetCounter(); SensorDataHandler(ACCEL_INPUT_SENSOR, timeStamp); SensorDataHandler(MAG_INPUT_SENSOR, timeStamp); SensorDataHandler(GYRO_INPUT_SENSOR, timeStamp); break; #endif default: D1_printf("Unknown Timer! Reference %d\r\n", pTimerExp->userValue); break; } }
/* 函数名:void Read_DATA(u8 Command) 描述: 将Command的命令数值返回到printf打印输出 输入: Command命令 输出: 由printf输出 返回: 无 */ void Read_Data(u8 Command) { switch(Command) { case 10: { //读取当前始终值 printf("%u\r\n",RTC_GetCounter()); //打印秒 break; } case 201: { printf("控制寄存器1:TIM4_CR1=0X%x\r\n",TIM4->CR1); printf("控制寄存器2:TIM4_CR2=0X%x\r\n",TIM4->CR2); printf("计数器: TIM4_CNT=0X%u\r\n",TIM4->CNT); printf("预分频器: TIM4_PSC=0X%x\r\n",TIM4->PSC); printf("重载寄存器: TIM4_ARR=0X%x\r\n",TIM4->ARR); printf("状态寄存器: TIM4_SR =0X%x\r\n",TIM4->SR); printf("事件产生器: TIM4_EGR=0X%x\r\n",TIM4->EGR); printf("从模式存器: TIM4_SMCR=0X%x\r\n",TIM4->SMCR); break; } case 202: { printf("计数器:TIM4_CNT=%u\r\n",TIM4->CNT); break; } default: { printf("无此命令,请核对!\r\n"); break; } } }
/** * @brief Resume virtual RTC * @retval : None */ void VirtualRTC_Resume(void) { SecondNumNow = RTC_GetCounter(); StartSecondNum = SecondNumNow - SecondBkp; if (VirtualRTCHandle != NULL) vTaskResume(VirtualRTCHandle); }
/******************************************************************************* * Function Name : RTC_IRQHandler * Description : This function handles RTC global interrupt request. * Input : None * Output : None * Return : None *******************************************************************************/ void RTC_IRQHandler(void) { volatile unsigned long int stanRTC; static unsigned char stanRTCTekst[17] = {"0\0"}; unsigned long int godziny, minuty, sekundy; if (RTC_GetITStatus(RTC_IT_SEC) != RESET) { // Czekaj na zakonczenie ewentualnych operacji zapisu do rejestrów RTC RTC_WaitForLastTask(); // Wyczysc flage od przerwania RTC RTC_ClearITPendingBit(RTC_IT_SEC); // Zmiana stanu wyprowadzenia PB15 co 1s GPIO_WriteBit(GPIOB, GPIO_Pin_15, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_15))); stanRTC=RTC_GetCounter(); //sprintf((char *)stanRTCTekst,"%16i\0",stanRTC); //LCD_WriteTextXY(stanRTCTekst,0,1); sekundy=stanRTC%60; //liczba sekund od ostatniej pelnej minuty minuty=(long int)(stanRTC)/60; //dzielenie calkowite, "usuniecie" sekund, czas pracy w samych minutach godziny=(long int)(minuty)/60; //dzielenie calkowite, "usuniecie" minut, czas pracy w samych godzinach minuty=minuty%60; //liczba minut od ostatniej pelnej godziny sprintf((char *)stanRTCTekst,"%3i:%02i:%02i\0",godziny,minuty,sekundy); LCD_WriteTextXY(stanRTCTekst,7,1); } }
void rtcIrqHandler(void) { if (RTC_GetITStatus(RTC_IT_SEC) != RESET) { RTC_ClearITPendingBit(RTC_FLAG_SEC); #ifdef PRECISION_IN_MS if (RTC_GetCounter() / 999 >= 1) { RTC_WaitForLastTask(); RTC_SetCounter(0); RTC_WaitForLastTask(); ++seconds; } #endif } /* ignore overflow */ //if (RTC_GetITStatus(RTC_IT_OW) != RESET) { // RTC_ClearITPendingBit(RTC_FLAG_OW); //} #ifndef PRECISION_IN_MS if (RTC_GetITStatus(RTC_IT_ALR) != RESET) { RTC_ClearITPendingBit(RTC_FLAG_ALR); if (alarm > 0 && alarm != NULL) { alarmProc(); } } #else if (alarm > 0 && alarm == seconds && alarm != NULL) { alarmProc(); } #endif }
/******************************************************************************* * Function Name : ShowMessage * Description : * Input : *Text * Return : None *******************************************************************************/ void Show_Message(char *Text) { /* */ if(TriggShowInfo.Status == DISABLE){ gMessage.Coord[1] = 206; gMessage.Coord[3] = 220; } else{ gMessage.Coord[1] = 186; gMessage.Coord[3] = 200; } /* Clear if another message now displayed */ if(gMessage.Visible == TRUE) Clear_Message(); /* Reset X1 coordinate */ gMessage.Coord[2] = gMessage.Coord[0]; memcpy(&chMessage[0], Text, strlen(Text)); /* Width message text */ LCD_Strig_PointsWidht((uint16_t*)&gMessage.Coord[2], gMessage.Text); /* устанавливаем ограничения для отрисовки */ Set_New_ClipObject(leftLimit + 1, gMessage.Coord[1], gMessage.Coord[2], gMessage.Coord[3], IN_OBJECT, Message_ClipObj); Update_Oscillogram(); // обновлем осциллограммы, для того что бы они "обрезались" по размерам отсечения /* Print message */ LCD_ClearArea(leftLimit + 1, gMessage.Coord[1], gMessage.Coord[2] + 5, gMessage.Coord[3], Active_BackColor); LCD_PutColorStrig(gMessage.Coord[0], gMessage.Coord[1], 1, gMessage.Text, gMessage.Color); gMessage.TimeOFF = RTC_GetCounter(); gMessage.TimeOFF += gMessage.TimeShow; gMessage.Visible = TRUE; }
void RTCAlarm_IRQHandler(void) { uint32_t RTC_counter; RTC->CRL &= (uint16_t)RTC_FLAG_ALR; EXTI->PR = EXTI_Line17; RTC_counter = RTC_GetCounter(); if(RTC_counter >= (sysCfg.sleepTime + sleepTimeOld)) { sleepTimeOld = RTC_counter; sysEventFlag |= MCU_WAKEUP_FLAG; InitTimeout(&MCU_WakeupTimeout,TIME_SEC(60)); } if(GET_ACC_PIN == ACC_ON) { POWER_EN_SET_OUTPUT; POWER_EN_PIN_SET; timepowerOffDelay = RTC_counter; } else if(RTC_counter >= (sysCfg.powerOffDelayTime + timepowerOffDelay)) { POWER_EN_SET_INPUT; timepowerOffDelay = RTC_counter; } RTC_SetAlarm((RTC_counter + ALARM_TIME)); sysEventFlag |= RTC_ALARM_FLAG; }
void RTC_IRQHandler(void) { /* 判断中断标志位_秒中断 是否被置位 */ if (RTC_GetITStatus(RTC_IT_SEC) != RESET) { /* Clear the RTC Second interrupt */ RTC_ClearITPendingBit(RTC_IT_SEC); /* Toggle GPIO_LED pin 6 each 1s */ //GPIO_WriteBit(GPIO_LED, GPIO_Pin_6, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIO_LED, GPIO_Pin_6))); /* Enable time update * TimeDisplay是一个标志位,只有等于1时才让串口发送时 间数据,即让串口一秒发一次时间值 */ TimeDisplay = 1; /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Reset RTC Counter when Time is 23:59:59 * 当时间走到23:59:59秒时RTC计数器中的值清零,0x00015180=23*3600+56*60+59 */ if (RTC_GetCounter() == 0x00015180) { RTC_SetCounter(0x0); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); } } }
static void __cmd_TIME_Handler(const SMSInfo *sms) { DateTime dateTime; char *pdu = NULL; int len; char __toUser[17] = {0}; // 15/06/25,13:20:28 #if defined (__EXTRTC__) readRTCTime(&dateTime); #else SecondToDateTime(&dateTime, RTC_GetCounter()); #endif __toUser[0] = (dateTime.year / 10) + '0'; __toUser[1] = (dateTime.year % 10) + '0'; __toUser[2] = '/'; __toUser[3] = (dateTime.month / 10) + '0'; __toUser[4] = (dateTime.month % 10) + '0'; __toUser[5] = '/'; __toUser[6] = (dateTime.date / 10) + '0'; __toUser[7] = (dateTime.date % 10) + '0'; __toUser[8] = ','; __toUser[9] = (dateTime.hour / 10) + '0'; __toUser[10] = (dateTime.hour % 10) + '0'; __toUser[11] = ':'; __toUser[12] = (dateTime.minute / 10) + '0'; __toUser[13] = (dateTime.minute % 10) + '0'; __toUser[14] = ':'; __toUser[15] = (dateTime.second / 10) + '0'; __toUser[16] = (dateTime.second % 10) + '0'; // __sendToNumber(sms->number, __toUser, sizeof(__toUser)); pdu = pvPortMalloc(100); len = SMSEncodePdu8bit(pdu, sms->number, (char *)__toUser); GsmTaskSendSMS(pdu, len); vPortFree(pdu); }
void RTC_IRQHandler(void) { uint32_t Curent_RTC_Counter; ITStatus bitstatus = (ITStatus)(RTC->CRL & RTC_IT_SEC); // if (RTC_GetITStatus(RTC_IT_SEC) != RESET) if (((RTC->CRH & RTC_IT_SEC) != (uint16_t)RESET) && (bitstatus != (uint16_t)RESET)) { NVIC_ClearPendingIRQ(RTC_IRQn); RTC->CRL &= (uint16_t)~RTC_IT_SEC; while ((RTC->CRL & RTC_FLAG_RTOFF) == (uint16_t)RESET) { } // RTC_ClearITPendingBit(RTC_IT_SEC); // RTC_WaitForLastTask(); /* If counter is equal to 86399 */ Curent_RTC_Counter = RTC_GetCounter(); if(Curent_RTC_Counter == 86399) { /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Reset counter value */ RTC_SetCounter(0x0); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); } RTC_Sec_Event = 1; } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /* Setup the microcontroller system. Initialize the Embedded Flash Interface, initialize the PLL and update the SystemFrequency variable. */ SystemInit(); /* Initialize LEDs and Key Button mounted on STM3210X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_PBInit(Button_KEY, Mode_EXTI); /* Enable PWR and BKP clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Configure EXTI Line to generate an interrupt on falling edge */ EXTI_Configuration(); /* Configure RTC clock source and prescaler */ RTC_Configuration(); /* NVIC configuration */ NVIC_Configuration(); /* Configure the SysTick to generate an interrupt each 1 millisecond */ SysTick_Configuration(); /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); while (1) { /* Insert 1.5 second delay */ Delay(1500); /* Wait till RTC Second event occurs */ RTC_ClearFlag(RTC_FLAG_SEC); while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET); /* Alarm in 3 second */ RTC_SetAlarm(RTC_GetCounter()+ 3); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Turn off LED1 */ STM_EVAL_LEDOff(LED1); /* Request to enter STOP mode with regulator in low power mode*/ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* At this stage the system has resumed from STOP mode -------------------*/ /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL as system clock source (HSE and PLL are disabled in STOP mode) */ SYSCLKConfig_STOP(); } }
/******************************************************************************* * Function Name : main * Description : Main program. * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { #ifdef DEBUG debug(); #endif /* Clock configuration */ RCC_Configuration(); /* Enable PWR and BKP clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* GPIO configuration */ GPIO_Configuration(); /* Configure EXTI Line to generate an interrupt on falling edge */ EXTI_Configuration(); /* Configure RTC clock source and prescaler */ RTC_Configuration(); /* NVIC configuration */ NVIC_Configuration(); /* Configure the SysTick to generate an interrupt each 1 millisecond */ SysTick_Configuration(); /* Turn on led connected to GPIO_LED Pin6 */ GPIO_SetBits(GPIO_LED, GPIO_Pin_6); while (1) { /* Insert 1.5 second delay */ Delay(1500); /* Wait till RTC Second event occurs */ RTC_ClearFlag(RTC_FLAG_SEC); while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET); /* Alarm in 3 second */ RTC_SetAlarm(RTC_GetCounter()+ 3); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Turn off led connected to GPIO_LED Pin6 */ GPIO_ResetBits(GPIO_LED, GPIO_Pin_6); /* Request to enter STOP mode with regulator in low power mode*/ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* At this stage the system has resumed from STOP mode -------------------*/ /* Turn on led connected to GPIO_LED Pin6 */ GPIO_SetBits(GPIO_LED, GPIO_Pin_6); /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL as system clock source (HSE and PLL are disabled in STOP mode) */ SYSCLKConfig_STOP(); } }
/* STD C TIME FUNC */ __time32_t __time32(__time32_t *p) { #ifndef PRECISION_IN_MS RTC_GetCounter(); #else return seconds; #endif }
/** * @brief Init virtualRTC * @retval : None */ void VirtualRTC_Init(void) { StartSecondNum = RTC_GetCounter(); if (VirtualRTCHandle != NULL) vTaskDelete(VirtualRTCHandle); xTaskCreate(VirtualRTC_Handler, "VirtualClock", 128, NULL, VIRTUAL_CLOCK_UPDATE_PRIORITY, &VirtualRTCHandle); }
/******************************************************************************* * Function Name : SetDate * Description : Sets the RTC Date(DD/MM/YYYY) * Input : DD,MM,YYYY * Output : None * Return : None *******************************************************************************/ void SetDate(u8 u8_Day, u8 u8_Month, u16 u16_Year) { u32 u32_DateTimer; //RightLeftIntExtOnOffConfig(DISABLE); //UpDownIntOnOffConfig(DISABLE); /*Check if the date entered by the user is correct or not, Displays an error message if date is incorrect */ if((( u8_Month==4 || u8_Month==6 || u8_Month==9 || u8_Month==11) && u8_Day ==31) \ || (u8_Month==2 && u8_Day==31)|| (u8_Month==2 && u8_Day==30)|| \ (u8_Month==2 && u8_Day==29 && (CheckLeap(u16_Year)==0))) { u32_DateTimer=RTC_GetCounter(); while((RTC_GetCounter()-u32_DateTimer)<2) { } } /* if date entered is correct then set the date*/ else { if(u8_AlarmDate==0) { s_DateStructVar.u16_Year = u16_Year; s_DateStructVar.u8_Month = u8_Month; s_DateStructVar.u8_Day = u8_Day; BKP_WriteBackupRegister(BKP_DR2,u8_Month); BKP_WriteBackupRegister(BKP_DR3,u8_Day); BKP_WriteBackupRegister(BKP_DR4,u16_Year); u8_DisplayDateFlag=1; } else { s_AlarmDateStructVar.u8_Day = u8_Day; s_AlarmDateStructVar.u8_Month = u8_Month; s_AlarmDateStructVar.u16_Year = u16_Year; BKP_WriteBackupRegister(BKP_DR8,u8_Month); BKP_WriteBackupRegister(BKP_DR9,u8_Day); BKP_WriteBackupRegister(BKP_DR10,u16_Year); u8_AlarmDate=0; } } }
/** * @brief Sets the RTC Date(DD/MM/YYYY) * @param DD,MM,YYYY * @retval : None */ void SetDate(uint8_t Day, uint8_t Month, uint16_t Year) { uint32_t DateTimer; RightLeftIntExtOnOffConfig(DISABLE); UpDownIntOnOffConfig(DISABLE); /*Check if the date entered by the user is correct or not, Displays an error message if date is incorrect */ if((( Month==4 || Month==6 || Month==9 || Month==11) && Day ==31) \ || (Month==2 && Day==31)|| (Month==2 && Day==30)|| \ (Month==2 && Day==29 && (CheckLeap(Year)==0))) { LCD_Clear(Red); LCD_SetBackColor(Red); LCD_DisplayString(Line3,Column2,"INCORRECT DATE"); LCD_DisplayString(Line6,Column1,"PLEASE RECONFIGURE"); DateTimer=RTC_GetCounter(); while((RTC_GetCounter()-DateTimer)<2) { } } /* if date entered is correct then set the date*/ else { if(AlarmDate==0) { BKP_WriteBackupRegister(BKP_DR2,Month); BKP_WriteBackupRegister(BKP_DR3,Day); BKP_WriteBackupRegister(BKP_DR4,Year); DisplayDateFlag=1; } else { s_AlarmDateStructVar.Day = Day; s_AlarmDateStructVar.Month = Month; s_AlarmDateStructVar.Year = Year; BKP_WriteBackupRegister(BKP_DR8,Month); BKP_WriteBackupRegister(BKP_DR9,Day); BKP_WriteBackupRegister(BKP_DR10,Year); AlarmDate=0; } } }
/******************************************************************************* * Function Name : Time_GetCalendarTime() * Description : 从RTC取当前时间的日历时间(struct tm) * Input : None * Output : None * Return : time_t t *******************************************************************************/ struct tm Time_GetCalendarTime(void) { time_t t_t; struct tm t_tm; t_t = (time_t)RTC_GetCounter(); t_tm = Time_ConvUnixToCalendar(t_t); return t_tm; }
/**************************************************************/ //程 序 名: RCC_Config() //开 发 者: MingH //入口参数: 无 //功能说明: 显示当前时间: 时分秒 //**************************************************************/ void Time_Show(void) { /* If 1s has been elapsed */ if (TimeDisplay == 1) { /* Display current time */ Time_Display(RTC_GetCounter()); TimeDisplay = 0; } }
/******************************************************************************* * Function Name : RTC_IRQHandler * Description : This function handles RTC global interrupt request. * Input : None * Output : None * Return : None *******************************************************************************/ void RTC_IRQHandler(void) { /* If counter is equal to 86339: one day was elapsed */ if((RTC_GetCounter()/3600 == 23)&&(((RTC_GetCounter()%3600)/60) == 59)&& (((RTC_GetCounter()%3600)%60) == 59)) /* 23*3600 + 59*60 + 59 = 86339 */ { /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Reset counter value */ RTC_SetCounter(0x0); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Increment the date */ // Date_Update(); } /* Clear the RTC Second Interrupt pending bit */ RTC_ClearITPendingBit(RTC_IT_SEC); }
/** * @brief This task update the virtual RTC * @retval : None */ static void VirtualRTC_Handler(void *pvParameters) { while (1) { SecondNumNow = RTC_GetCounter(); SecondNum = SecondNumNow - StartSecondNum; UpdateRTCStruct(); vTaskDelay(100 / portTICK_RATE_MS); } }
int rtc_isWork(void) { int lse,lsi; volatile int32_t count = SystemCoreClock/8; volatile uint32_t RTC_Counter_Clock; lse = RCC_GetFlagStatus(RCC_FLAG_LSERDY); lsi = RCC_GetFlagStatus(RCC_FLAG_LSIRDY); if(!(lse || lsi)) return -1; // RTC Disable RTC_Counter_Clock = RTC_GetCounter(); while(count>0) count--; if(RTC_Counter_Clock == RTC_GetCounter()) return -1; return 0; }
/******************************************************************************* * Function Name : Time_Show * Description : Shows the current time (HH:MM:SS) on the Hyperterminal. * Input : None * Output : None * Return : None ******************************************************************************/ void time_show(void) { // usart1_transmit_string("\n\r"); tim_display(RTC_GetCounter()); #if 0 /* Infinite loop */ while(1) { /* If 1s has paased */ if(time_display == 1) { /* Display current time */ tim_display(RTC_GetCounter()); time_display = 0; } } #endif }
/** * @brief Calcuate the Time (in hours, minutes and seconds derived from * COunter value * @param None * @retval :None */ void CalculateTime(void) { uint32_t TimeVar; TimeVar=RTC_GetCounter(); TimeVar=TimeVar % 86400; s_TimeStructVar.HourHigh=(uint8_t)(TimeVar/3600)/10; s_TimeStructVar.HourLow=(uint8_t)(TimeVar/3600)%10; s_TimeStructVar.MinHigh=(uint8_t)((TimeVar%3600)/60)/10; s_TimeStructVar.MinLow=(uint8_t)((TimeVar%3600)/60)%10; s_TimeStructVar.SecHigh=(uint8_t)((TimeVar%3600)%60)/10; s_TimeStructVar.SecLow=(uint8_t)((TimeVar %3600)%60)%10; }