#include "rtc.h"
|
#include "extern_rtc.h"
|
#include "system_parameter.h"
|
#include "gpio.h"
|
#include "uart.h"
|
#include "low_pwr_test.h"
|
#include "test_log.h"
|
|
__IO RTC_TimeDateTypeDef calendar_g = {0};
|
|
void RTC_IRQHandler(void)
|
{
|
if (__SYS_DELAY_SEC_FLAG_GET(sys_active_time) == SET && LargeCurrent_LimitingProcess() == 3)
|
SysWakeUp_ClockCfg();
|
if (RTC_ISR_SEC_IF_Chk() == SET) // ²éѯÃëÖӶϱêÖ¾ÊÇ·ñÖÃÆð
|
{
|
RTC_ISR_SEC_IF_Clr(); // Çå³ýÃëÖжϱêÖ¾
|
sys_time_g.sys_run_period = SET;
|
Get_Sys_Rtc_Time(&calendar_g);
|
}
|
}
|
|
void RTC_Init(void)
|
{
|
CMU_PERCLK_SetableEx(RTCCLK, ENABLE); // RTC×ÜÏßʱÖÓʹÄÜ
|
// RTCʹÓÃXTLF/RCHF£¬Éϵç×Ô¶¯ÆðÕñ£¬²»ÐèҪʹÄܹ¤×÷ʱÖÓ
|
|
RTC_ISR_SEC_IF_Clr(); // Çå³ýÃëÖжϱêÖ¾
|
RTC_IER_SEC_IE_Setable(ENABLE); // ´ò¿ªRTCÃëÖжÏ
|
|
NVIC_DisableIRQ(RTC_IRQn); // NVICÖжϿØÖÆÆ÷ÅäÖÃ
|
NVIC_SetPriority(RTC_IRQn, 3);
|
NVIC_EnableIRQ(RTC_IRQn);
|
|
RTC_CR_RTC_EN_Setable(ENABLE); // ʹÄÜRTC_A
|
}
|
|
/******************************************
|
* func: Get_Sys_Rtc_Time
|
* desc: »ñȡϵͳRTCʱ¼ä
|
* input: pOutput_timedata £º»ñȡϵͳʱ¼äÖ¸Õ루BCD¸ñʽ£©
|
* output: none
|
* return: none
|
*****************************************/
|
ErrorStatus_STM32 Get_Sys_Rtc_Time(__IO RTC_TimeDateTypeDef *pOutput_timedata)
|
{
|
uint08 n, i;
|
ErrorStatus_STM32 Result = ERROR_1;
|
|
RTC_TimeDateTypeDef TempTime1, TempTime2;
|
|
for (n = 0; n < 3; n++)
|
{
|
RTC_TimeDate_GetEx(&TempTime1); // ¶ÁÒ»´Îʱ¼ä
|
RTC_TimeDate_GetEx(&TempTime2); // ÔÙ¶ÁÒ»´Îʱ¼ä
|
|
for (i = 0; i < 7; i++) // Á½ÕßÒ»ÖÂ, ±íʾ¶ÁÈ¡³É¹¦
|
{
|
if (((uint08 *)(&TempTime1))[i] != ((uint08 *)(&TempTime2))[i])
|
break;
|
}
|
if (i == 7)
|
{
|
Result = SUCCESS_0;
|
memcpy((uint08 *)(pOutput_timedata), (uint08 *)(&TempTime1), 7); // ¶ÁÈ¡ÕýÈ·Ôò¸üÐÂеÄʱ¼ä
|
memcpy(&sys_realtime_data_g.time_para_s, &TempTime1, 7);
|
break;
|
}
|
}
|
return Result;
|
}
|
|
/******************************************
|
* func: Set_Sys_Rtc_Time
|
* desc: ÉèÖÃϵͳRTCʱ¼ä
|
* input: pInput_timedata£ºÐ´ÈëµÄϵͳʱ¼äÖ¸Õ루BCD¸ñʽ£©
|
* output: none
|
* return: none
|
*****************************************/
|
|
ErrorStatus_STM32 Set_Sys_Rtc_Time(uint8_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec, uint8_t week)
|
{
|
uint08 n, i;
|
ErrorStatus_STM32 Result;
|
RTC_TimeDateTypeDef TempTime1;
|
RTC_TimeDateTypeDef real_time = {year, month, day, hour, min, sec, week};
|
for (n = 0; n < 3; n++)
|
{
|
RTC_WER_Write(RTC_WRITE_ENABLE); // ½â³ýRTCд±£»¤
|
RTC_TimeDate_SetEx(&real_time); // ÉèÖÃRTC
|
RTC_WER_Write(RTC_WRITE_DISABLE); // ´ò¿ªRTCд±£»¤
|
|
Result = Get_Sys_Rtc_Time(&TempTime1); // ¶ÁȡȷÈÏÉèÖýá¹û
|
if (Result == SUCCESS_0)
|
{
|
Result = ERROR_1;
|
for (i = 0; i < 7; i++) // Á½ÕßÒ»ÖÂ, ±íʾÉèÖóɹ¦
|
{
|
if (((uint08 *)(&TempTime1))[i] != ((uint08 *)(&real_time))[i])
|
break;
|
}
|
if (i == 7)
|
{
|
Result = SUCCESS_0;
|
break;
|
}
|
}
|
}
|
return Result;
|
}
|
|
void rtc_setalarm(RTC_AlarmTmieTypeDef *para)
|
{
|
RTC_AlarmTime_SetEx(para); // ÉèÖÃÄÖÖÓʱ¼ä
|
|
RTC_ISR_ALARM_IF_Clr(); // Çå³ýÄÖÖÓÖжϱêÖ¾
|
RTC_IER_ALARM_IE_Setable(ENABLE); // ´ò¿ªÄÖÖÓÖжÏ
|
RTC_ALARM_ALMEN_Setable(ENABLE); // ÄÖÖÓ¹¦ÄÜʹÄÜ
|
}
|