void rt_hw_rtc_init(void)
{
rt_time_t now;
rtc.type = RT_Device_Class_RTC;
if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
{
rt_kprintf("rtc is not configured\n");
rt_kprintf("please configure with set_date and set_time\n");
date.hour = 0;
date.min = 0;
date.ss = 0;
if ( RTC_Configuration() != 0)
{
rt_kprintf("rtc configure fail...\r\n");
return ;
}
} else {
now = RTC_GetCounter();
/* Wait for RTC registers synchronization */
RTC_WaitForSynchro();
date.hour = (now/3600)%24;
now %= 3600;
date.min = now/60;
date.ss = now%60;
RCC_ClearFlag();
RCC_RTCCLKCmd(ENABLE);
RTC_WaitForSynchro();
RTC_ITConfig(RTC_IT_SEC, ENABLE);
RTC_WaitForLastTask();
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
PWR_BackupAccessCmd(ENABLE);
RTC_ExitConfigMode();
RTC_NVIC_Config();
}
......
}
|