Platform/ECM3532/M3/hw/hal/common/rtc/src/rtc_hal.c
/*
 * Convert RTC to epoch time format
 */
Convert RTC to epoch time format
Convert RTC to epoch time format
uint32_t RtcToEpoch(struct RtcTm *sTm)
{
	uint8_t  a;
	uint16_t y;
	uint8_t  m;
	uint32_t JDN;
	a = (14 - sTm->month) / 12;
	y = (sTm->year) + 4800 - a; 
	m = sTm->month + (12 * a) - 3; 
    JDN  = sTm->date;
    JDN += (153 * m + 2) / 5;
    JDN += 365 * y;
    JDN += y / 4;
    JDN += -y / 100;
    JDN += y / 400;
    JDN  = JDN - 32045;
    JDN  = JDN - JULIAN_DATE_BASE;    
    JDN *= 86400;                     
    JDN += sTm->hour * 3600;    
    JDN += sTm->min * 60;
    JDN += sTm->sec;
	return JDN;
}
uint32_t RtcToEpoch ( struct RtcTm * sTm ) { uint8_t a ; uint16_t y ; uint8_t m ; uint32_t JDN ; a = ( 14 - sTm -> month ) / 12 ; y = ( sTm -> year ) + 4800 - a ; m = sTm -> month + ( 12 * a ) - 3 ; JDN = sTm -> date ; JDN += ( 153 * m + 2 ) / 5 ; JDN += 365 * y ; JDN += y / 4 ; JDN += - y / 100 ; JDN += y / 400 ; JDN = JDN - 32045 ; JDN = JDN - JULIAN_DATE_BASE ; JDN *= 86400 ; JDN += sTm -> hour * 3600 ; JDN += sTm -> min * 60 ; JDN += sTm -> sec ; return JDN ; }
Convert RTC to epoch time format
Convert RTC to epoch time format
// These hardcore math's are taken from http://en.wikipedia.org/wiki/Julian_day // Calculate some coefficients //y = (sTm->year + 2000) + 4800 - a; // years since 1 March, 4801 BC // years since 1 March, 4801 BC // since 1 March, 4801 BC // Gregorian calendar date compute // Calculate from base date // Days to seconds // ... and today seconds