387 lines
9.4 KiB
C
387 lines
9.4 KiB
C
|
|
#include "includes.h"
|
|||
|
|
|
|||
|
|
#include "drv_dtu.h"
|
|||
|
|
#include "drv_gps.h"
|
|||
|
|
|
|||
|
|
extern RTC_HandleTypeDef hrtc;
|
|||
|
|
|
|||
|
|
// ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>INITIAL_YEAR<41><52><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>GPS<50><53>λ<EFBFBD><CEBB>GPRS<52><53><EFBFBD>ӻ<EFBFBD>վ<EFBFBD>Ժ<EFBFBD><D4BA><EFBFBD><EFBFBD>ã<EFBFBD>
|
|||
|
|
volatile uint32_t RTC_offsetSeconds = 0;
|
|||
|
|
|
|||
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ʱ<EFBFBD>䣺<EFBFBD><E4A3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽΪNuvotonоƬ<D0BE><C6AC>ʽ
|
|||
|
|
void RTC_GetDateAndTime(S_RTC_TIME_DATA_T *sRTC)
|
|||
|
|
{
|
|||
|
|
RTC_TimeTypeDef sTime = {0};
|
|||
|
|
RTC_DateTypeDef sDate = {0};
|
|||
|
|
|
|||
|
|
HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN);
|
|||
|
|
HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN);
|
|||
|
|
|
|||
|
|
sRTC->u32Year = sDate.Year + RTC_YEAR2000;
|
|||
|
|
sRTC->u32Month = sDate.Month;
|
|||
|
|
sRTC->u32Day = sDate.Date;
|
|||
|
|
if(sDate.WeekDay == RTC_WEEKDAY_SUNDAY)
|
|||
|
|
sRTC->u32DayOfWeek = 0;
|
|||
|
|
else
|
|||
|
|
sRTC->u32DayOfWeek = sDate.WeekDay;
|
|||
|
|
sRTC->u32Hour = sTime.Hours;
|
|||
|
|
sRTC->u32Minute = sTime.Minutes;
|
|||
|
|
sRTC->u32Second = sTime.Seconds;
|
|||
|
|
sRTC->u32TimeScale = RTC_CLOCK_24;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>䣺<EFBFBD><E4A3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽΪNuvotonоƬ<D0BE><C6AC>ʽ
|
|||
|
|
void RTC_SetDateAndTime(S_RTC_TIME_DATA_T *sRTC)
|
|||
|
|
{
|
|||
|
|
RTC_TimeTypeDef sTime = {0};
|
|||
|
|
RTC_DateTypeDef sDate = {0};
|
|||
|
|
|
|||
|
|
sDate.Year = sRTC->u32Year - RTC_YEAR2000;
|
|||
|
|
sDate.Month = sRTC->u32Month;
|
|||
|
|
sDate.Date = sRTC->u32Day;
|
|||
|
|
if(sRTC->u32DayOfWeek == RTC_SUNDAY)
|
|||
|
|
sDate.WeekDay = RTC_WEEKDAY_SUNDAY;
|
|||
|
|
else
|
|||
|
|
sDate.WeekDay = sRTC->u32DayOfWeek;
|
|||
|
|
sTime.Hours = sRTC->u32Hour;
|
|||
|
|
sTime.Minutes = sRTC->u32Minute;
|
|||
|
|
sTime.Seconds = sRTC->u32Second;
|
|||
|
|
sTime.SubSeconds = 0;
|
|||
|
|
sTime.TimeFormat = RTC_HOURFORMAT_24;
|
|||
|
|
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
|
|||
|
|
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
|
|||
|
|
|
|||
|
|
HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN);
|
|||
|
|
HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void RTC_SetAlarmDateAndTime(S_RTC_TIME_DATA_T *sRTC)
|
|||
|
|
{
|
|||
|
|
uint8_t try_count = 3;
|
|||
|
|
|
|||
|
|
RTC_AlarmTypeDef sAlarm = {0};
|
|||
|
|
|
|||
|
|
sAlarm.AlarmTime.Hours = sRTC->u32Hour;
|
|||
|
|
sAlarm.AlarmTime.Minutes = sRTC->u32Minute;
|
|||
|
|
sAlarm.AlarmTime.Seconds = sRTC->u32Second;
|
|||
|
|
sAlarm.AlarmTime.SubSeconds = 0;
|
|||
|
|
sAlarm.AlarmTime.TimeFormat = RTC_HOURFORMAT_24;
|
|||
|
|
sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
|
|||
|
|
sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
|
|||
|
|
|
|||
|
|
sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;
|
|||
|
|
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
|
|||
|
|
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
|
|||
|
|
sAlarm.AlarmDateWeekDay = sRTC->u32Day;
|
|||
|
|
sAlarm.Alarm = RTC_ALARM_A;
|
|||
|
|
|
|||
|
|
while(try_count--)
|
|||
|
|
{
|
|||
|
|
if(HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BIN) == HAL_OK)
|
|||
|
|
break;
|
|||
|
|
delay_ms(10);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void RTC_SetAlarmDateAndTime_B(S_RTC_TIME_DATA_T *sRTC)
|
|||
|
|
{
|
|||
|
|
uint8_t try_count = 3;
|
|||
|
|
|
|||
|
|
RTC_AlarmTypeDef sAlarm = {0};
|
|||
|
|
|
|||
|
|
sAlarm.AlarmTime.Hours = sRTC->u32Hour;
|
|||
|
|
sAlarm.AlarmTime.Minutes = sRTC->u32Minute;
|
|||
|
|
sAlarm.AlarmTime.Seconds = sRTC->u32Second;
|
|||
|
|
sAlarm.AlarmTime.SubSeconds = 0;
|
|||
|
|
sAlarm.AlarmTime.TimeFormat = RTC_HOURFORMAT_24;
|
|||
|
|
sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
|
|||
|
|
sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
|
|||
|
|
|
|||
|
|
sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;
|
|||
|
|
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
|
|||
|
|
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
|
|||
|
|
sAlarm.AlarmDateWeekDay = sRTC->u32Day;
|
|||
|
|
sAlarm.Alarm = RTC_ALARM_B;
|
|||
|
|
|
|||
|
|
while(try_count--)
|
|||
|
|
{
|
|||
|
|
if(HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BIN) == HAL_OK)
|
|||
|
|
break;
|
|||
|
|
delay_ms(10);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void Wakeup_ShowTime(char *preStr, S_RTC_TIME_DATA_T *pRTC)
|
|||
|
|
{
|
|||
|
|
S_RTC_TIME_DATA_T sRTC;
|
|||
|
|
|
|||
|
|
uint32_t totalSeconds = Calc_SecondsFromYear(INITIAL_YEAR, pRTC->u32Year, pRTC->u32Month, pRTC->u32Day,
|
|||
|
|
pRTC->u32Hour, pRTC->u32Minute, pRTC->u32Second);
|
|||
|
|
totalSeconds += RTC_offsetSeconds;
|
|||
|
|
Wakeup_CalcUTCTime(totalSeconds, &sRTC);
|
|||
|
|
printf("\n%s%04d-%02d-%02d %02d:%02d:%02d\n", preStr, sRTC.u32Year, sRTC.u32Month,
|
|||
|
|
sRTC.u32Day, sRTC.u32Hour, sRTC.u32Minute, sRTC.u32Second);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
uint8_t IsLeapYear(uint16_t year)
|
|||
|
|
{
|
|||
|
|
if(year % 4)
|
|||
|
|
return 0;
|
|||
|
|
if(year % 100 == 0 && year % 400)
|
|||
|
|
return 0;
|
|||
|
|
return 1;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD>꿪ʼ<EABFAA><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
uint32_t Calc_SecondsFromYear(uint16_t startYear, uint16_t year, uint8_t mon, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec)
|
|||
|
|
{
|
|||
|
|
uint32_t totalSeconds = 0ul;
|
|||
|
|
uint16_t i;
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
for(i = startYear; i < year; i++)
|
|||
|
|
{
|
|||
|
|
totalSeconds += 31536000ul; // 365 * 86400
|
|||
|
|
if(IsLeapYear(i)) // <20><><EFBFBD><EFBFBD>+1<><31>
|
|||
|
|
totalSeconds += 86400ul;
|
|||
|
|
}
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>
|
|||
|
|
for(i = 1; i < mon; i++)
|
|||
|
|
{
|
|||
|
|
totalSeconds += 2678400ul; // 31 * 86400
|
|||
|
|
if(i == 4 || i == 6 || i == 9 || i == 11)
|
|||
|
|
totalSeconds -= 86400ul;
|
|||
|
|
else if(i == 2)
|
|||
|
|
{
|
|||
|
|
totalSeconds -= 259200ul; // 3 * 86400
|
|||
|
|
if(IsLeapYear(year)) // <20><><EFBFBD><EFBFBD>+1<><31>
|
|||
|
|
totalSeconds += 86400ul;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
totalSeconds += (day - 1) * 86400ul;
|
|||
|
|
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
totalSeconds += hour * 3600ul;
|
|||
|
|
totalSeconds += min * 60ul;
|
|||
|
|
totalSeconds += sec;
|
|||
|
|
|
|||
|
|
return totalSeconds;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
uint16_t get_year_days(uint16_t year)
|
|||
|
|
{
|
|||
|
|
if(IsLeapYear(year))
|
|||
|
|
return 366;
|
|||
|
|
return 365;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
uint16_t get_month_days(uint16_t year, uint8_t month)
|
|||
|
|
{
|
|||
|
|
if(month == 4 || month == 6 || month == 9 || month == 11)
|
|||
|
|
return 30;
|
|||
|
|
if(month == 2)
|
|||
|
|
{
|
|||
|
|
if(IsLeapYear(year))
|
|||
|
|
return 29;
|
|||
|
|
return 28;
|
|||
|
|
}
|
|||
|
|
return 31;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>INITIAL_YEAR<41><52>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
void Wakeup_CalcUTCTime(uint32_t totalSeconds, S_RTC_TIME_DATA_T *pRTC)
|
|||
|
|
{
|
|||
|
|
uint32_t totalDays, days;
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>´λ<C2B4><CEBB>ѵ<EFBFBD><D1B5>ꡢ<EFBFBD>¡<EFBFBD><C2A1><EFBFBD>
|
|||
|
|
pRTC->u32Year = INITIAL_YEAR;
|
|||
|
|
pRTC->u32Month = 1;
|
|||
|
|
pRTC->u32Day = 1;
|
|||
|
|
totalDays = totalSeconds / 86400ul;
|
|||
|
|
while(totalDays >= 1)
|
|||
|
|
{
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
days = get_year_days(pRTC->u32Year);
|
|||
|
|
if(totalDays >= days)
|
|||
|
|
{
|
|||
|
|
pRTC->u32Year++;
|
|||
|
|
totalDays -= days;
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>
|
|||
|
|
days = get_month_days(pRTC->u32Year, pRTC->u32Month);
|
|||
|
|
if(totalDays >= days)
|
|||
|
|
{
|
|||
|
|
pRTC->u32Month++;
|
|||
|
|
totalDays -= days;
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
pRTC->u32Day += totalDays;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>´λ<C2B4><CEBB>ѵ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>֡<EFBFBD><D6A1><EFBFBD>
|
|||
|
|
totalSeconds %= 86400ul;
|
|||
|
|
pRTC->u32Hour = totalSeconds / 3600ul;
|
|||
|
|
totalSeconds %= 3600;
|
|||
|
|
pRTC->u32Minute = totalSeconds / 60ul;
|
|||
|
|
totalSeconds %= 60ul;
|
|||
|
|
pRTC->u32Second = totalSeconds;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>´λ<C2B4><CEBB>ѵ<EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
void Wakeup_CalcWakeupTime(S_RTC_TIME_DATA_T *pRTC)
|
|||
|
|
{
|
|||
|
|
uint32_t period = 300; //dcBuff.configData.intervalSample;
|
|||
|
|
|
|||
|
|
// <20>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD>ӳ<EFBFBD>ʼʱ<CABC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
uint32_t totalSeconds = Calc_SecondsFromYear(INITIAL_YEAR, pRTC->u32Year, pRTC->u32Month, pRTC->u32Day,
|
|||
|
|
pRTC->u32Hour, pRTC->u32Minute, pRTC->u32Second);
|
|||
|
|
|
|||
|
|
printf("dcBuff.configData.intervalSample = %d, period = %d\n", dcBuff.configData.intervalSample, period);
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>´λ<C2B4><CEBB><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뵽<EFBFBD><EBB5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵı<DAB5><C4B1><EFBFBD>
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ÿ<EFBFBD>θ<EFBFBD>λ<EFBFBD>Ժ<EFBFBD><D4BA><EFBFBD>Ȼʱ<C8BB><CAB1><EFBFBD>Ǽ<EFBFBD><C7BC><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
uint32_t sec = totalSeconds + period;
|
|||
|
|
sec -= sec % period;
|
|||
|
|
// <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>̫<EFBFBD><CCAB>
|
|||
|
|
if(sec <= totalSeconds + 2)
|
|||
|
|
totalSeconds = sec + period;
|
|||
|
|
else
|
|||
|
|
totalSeconds = sec;
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>´λ<C2B4><CEBB>ѵ<EFBFBD><D1B5>ꡢ<EFBFBD>¡<EFBFBD><C2A1><EFBFBD>
|
|||
|
|
Wakeup_CalcUTCTime(totalSeconds, pRTC);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>´λ<C2B4><CEBB>ѵ<EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
void Wakeup_CalcWakeupTime_B(S_RTC_TIME_DATA_T *pRTC)
|
|||
|
|
{
|
|||
|
|
// <20>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD>ӳ<EFBFBD>ʼʱ<CABC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
uint32_t totalSeconds = Calc_SecondsFromYear(INITIAL_YEAR, pRTC->u32Year, pRTC->u32Month, pRTC->u32Day,
|
|||
|
|
pRTC->u32Hour, pRTC->u32Minute, pRTC->u32Second);
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>´λ<C2B4><CEBB><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
totalSeconds += 15;
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>´λ<C2B4><CEBB>ѵ<EFBFBD><D1B5>ꡢ<EFBFBD>¡<EFBFBD><C2A1><EFBFBD>
|
|||
|
|
Wakeup_CalcUTCTime(totalSeconds, pRTC);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20>趨<EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
void Wakeup_SetAlarm()
|
|||
|
|
{
|
|||
|
|
S_RTC_TIME_DATA_T sRTC;
|
|||
|
|
|
|||
|
|
// <20>趨<EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
RTC_GetDateAndTime(&sRTC);
|
|||
|
|
// <20><>ʾ<EFBFBD><CABE>ǰʱ<C7B0><CAB1>
|
|||
|
|
Wakeup_ShowTime("RTC time is: ", &sRTC);
|
|||
|
|
Wakeup_CalcWakeupTime(&sRTC);
|
|||
|
|
RTC_SetAlarmDateAndTime(&sRTC);
|
|||
|
|
// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
Wakeup_ShowTime("***********************************************\nWakeup time is: ", &sRTC);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20>趨<EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
void Wakeup_SetAlarm_B()
|
|||
|
|
{
|
|||
|
|
S_RTC_TIME_DATA_T sRTC;
|
|||
|
|
|
|||
|
|
// <20>趨<EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
RTC_GetDateAndTime(&sRTC);
|
|||
|
|
Wakeup_CalcWakeupTime_B(&sRTC);
|
|||
|
|
RTC_SetAlarmDateAndTime_B(&sRTC);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief Alarm A callback.
|
|||
|
|
* @param hrtc RTC handle
|
|||
|
|
* @retval None
|
|||
|
|
*/
|
|||
|
|
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
|
|||
|
|
{
|
|||
|
|
BaseType_t xHigherPriorityTaskWoken;
|
|||
|
|
S_RTC_TIME_DATA_T sRTC;
|
|||
|
|
static uint32_t upgSeconds = 0;
|
|||
|
|
uint32_t totalSeconds;
|
|||
|
|
|
|||
|
|
// <20><>ȡ<EFBFBD><C8A1>ǰʱ<C7B0><CAB1>
|
|||
|
|
RTC_GetDateAndTime(&sRTC);
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴβ<CFB4>ѯ<EFBFBD>̼<EFBFBD><CCBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
totalSeconds = Calc_SecondsFromYear(INITIAL_YEAR, sRTC.u32Year, sRTC.u32Month, sRTC.u32Day,
|
|||
|
|
sRTC.u32Hour, sRTC.u32Minute, sRTC.u32Second);
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32>Сʱδ<CAB1><CEB4><EFBFBD>ͳɹ<CDB3><C9B9><EFBFBD><EFBFBD><EFBFBD>λ
|
|||
|
|
if(totalSeconds >= DTU_succTime + 7200)
|
|||
|
|
NVIC_SystemReset();
|
|||
|
|
|
|||
|
|
// ÿ<><C3BF>20<32><30><EFBFBD>Ӳ<EFBFBD>ѯһ<D1AF><D2BB><EFBFBD>Ƿ<EFBFBD><C7B7>̼<EFBFBD><CCBC><EFBFBD><EFBFBD><EFBFBD>(3<><33><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
|
|||
|
|
if(totalSeconds + 3 >= upgSeconds + 300)
|
|||
|
|
{
|
|||
|
|
// <20><><EFBFBD>¼<EFBFBD>ʱ
|
|||
|
|
upgSeconds = totalSeconds;
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD><CCBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
xSemaphoreGiveFromISR(DTU_semUpgrade, &xHigherPriorityTaskWoken);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20>趨<EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
Wakeup_CalcWakeupTime(&sRTC);
|
|||
|
|
Wakeup_SetAlarm();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief Alarm B callback.
|
|||
|
|
* @param hrtc RTC handle
|
|||
|
|
* @retval None
|
|||
|
|
*/
|
|||
|
|
void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc)
|
|||
|
|
{
|
|||
|
|
DTU_CheckSleep();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void Wakeup_InitializeTime(S_RTC_TIME_DATA_T *pRTC)
|
|||
|
|
{
|
|||
|
|
pRTC->u32Year = INITIAL_YEAR;
|
|||
|
|
pRTC->u32Month = 1;
|
|||
|
|
pRTC->u32Day = 1;
|
|||
|
|
pRTC->u32DayOfWeek = RTC_WEEKDAY_FRIDAY;
|
|||
|
|
pRTC->u32Hour = 0;
|
|||
|
|
pRTC->u32Minute = 0;
|
|||
|
|
pRTC->u32Second = 0;
|
|||
|
|
pRTC->u32TimeScale = RTC_CLOCK_24;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void Wakeup_Open()
|
|||
|
|
{
|
|||
|
|
S_RTC_TIME_DATA_T sRTC;
|
|||
|
|
|
|||
|
|
/** Initialize RTC Only
|
|||
|
|
*/
|
|||
|
|
hrtc.Instance = RTC;
|
|||
|
|
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
|
|||
|
|
hrtc.Init.AsynchPrediv = 127;
|
|||
|
|
hrtc.Init.SynchPrediv = 255;
|
|||
|
|
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
|
|||
|
|
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
|
|||
|
|
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
|
|||
|
|
if (HAL_RTC_Init(&hrtc) != HAL_OK)
|
|||
|
|
{
|
|||
|
|
Error_Handler();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/* Set RTC date and time */
|
|||
|
|
Wakeup_InitializeTime(&sRTC);
|
|||
|
|
RTC_SetDateAndTime(&sRTC);
|
|||
|
|
|
|||
|
|
printf("\n*******************************\n");
|
|||
|
|
printf("system reseted ...\n");
|
|||
|
|
|
|||
|
|
// <20>趨<EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
Wakeup_SetAlarm();
|
|||
|
|
}
|