93 lines
1.9 KiB
C
93 lines
1.9 KiB
C
#include "common.h"
|
|
#include "rtc_task.h"
|
|
#include "filei2c.h"
|
|
|
|
//include/linux/time.h
|
|
//ÄÚºËÖеÄmktime()º¯ÊýλÓÚkernel/time.cÄÚ
|
|
|
|
|
|
unsigned long mktime (unsigned int year, unsigned int mon,
|
|
unsigned int day, unsigned int hour,
|
|
unsigned int min, unsigned int sec)
|
|
{
|
|
if (0 >= (int) (mon -= 2)) { /* 1..12 -> 11,12,1..10 */
|
|
mon += 12; /* Puts Feb last since it has leap day */
|
|
year -= 1;
|
|
}
|
|
|
|
return (((
|
|
(unsigned long) (year/4 - year/100 + year/400 + 367*mon/12 + day) +
|
|
year*365 - 719499
|
|
)*24 + hour /* now have hours */
|
|
)*60 + min /* now have minutes */
|
|
)*60 + sec; /* finally seconds */
|
|
}
|
|
|
|
uint8_t bcd_to_dec(uint8_t val)
|
|
{
|
|
return ((((val)>>4)*10) + ((val)&0x0F));
|
|
}
|
|
|
|
uint8_t get_space_day(uint32_t oldtime,uint32_t newtime)
|
|
{
|
|
uint8_t day = 0;
|
|
if(newtime>oldtime)
|
|
{
|
|
day = (newtime - oldtime)/(3600*24);
|
|
}
|
|
return day;
|
|
}
|
|
|
|
uint32_t get_curtime(uint8_t *curyear,uint8_t *curmon,uint8_t *curday)
|
|
{
|
|
RTC_TimeDateTypeDef rtctime;
|
|
uint32_t time = 0;
|
|
uint32_t year = 0;
|
|
uint8_t mon = 0;
|
|
uint8_t day = 0;
|
|
rtc_getRTC(&rtctime);
|
|
|
|
year = bcd_to_dec(rtctime.Year);
|
|
mon = bcd_to_dec(rtctime.Month);
|
|
day = bcd_to_dec(rtctime.Date);
|
|
|
|
year = year + DEC_YEAR;
|
|
time = mktime(year,mon,day,0,0,0);
|
|
|
|
*curyear = year;
|
|
*curmon = mon;
|
|
*curday = day;
|
|
|
|
#ifdef DEBUG_FILEI2C
|
|
HT_PRINT("time = %d year = %d mon = %d day = %d\r\n",time,year,mon,day);
|
|
#endif
|
|
return time;
|
|
}
|
|
|
|
|
|
void get_complete_curtime(uint32_t *curyear,uint8_t *curmon,uint8_t *curday,uint8_t *curhour,uint8_t *curmin)
|
|
{
|
|
RTC_TimeDateTypeDef rtctime;
|
|
uint32_t year = 0;
|
|
uint8_t mon = 0;
|
|
uint8_t day = 0;
|
|
uint8_t hour = 0;
|
|
uint8_t min = 0;
|
|
rtc_getRTC(&rtctime);
|
|
|
|
year = bcd_to_dec(rtctime.Year);
|
|
mon = bcd_to_dec(rtctime.Month);
|
|
day = bcd_to_dec(rtctime.Date);
|
|
hour = bcd_to_dec(rtctime.Hour);
|
|
min = bcd_to_dec(rtctime.Minute);
|
|
|
|
year = year + DEC_YEAR;
|
|
|
|
*curyear = year;
|
|
*curmon = mon;
|
|
*curday = day;
|
|
*curhour = hour;
|
|
*curmin = min;
|
|
}
|
|
|