/* This function is used to calculate day of week according to date.  */
static void rtc_calculate_wday(int year, int mon, int mday, int *wday)
/* This function is used to calculate day of week according to date.  */
static void rtc_calculate_wday(int year, int mon, int mday, int *wday)
{
	int t_year = year + 1900, t_mon = mon + 1;
	if(t_mon == 1 || t_mon == 2){
		t_year --;
		t_mon += 12;
	}
	int c = t_year / 100;
	int y = t_year % 100;
	int week = (c / 4) - 2 * c + (y + y / 4) + (26 * (t_mon + 1) / 10) + mday -1;
	while(week < 0){
		week += 7;
	}
	week %= 7;
	*wday = week;
}