コード例 #1
0
void rtca_update_dow()
{
	uint8_t dow;

	dow = LEAPS_SINCE_YEAR(rtca_time.year);

	if ((29 == rtca_get_max_days(2, rtca_time.year)) && (rtca_time.mon < 3))
		dow--; /* if this is a leap year but before February 29 */

	/* add day of current month */
	dow += rtca_time.day;

	/* add this month's dow value */
	switch (rtca_time.mon) {
	case 5:
		dow += 1;
		break;

	case 8:
		dow += 2;
		break;

	case 2:
	case 3:
	case 11:
		dow += 3;
		break;

	case 6:
		dow += 4;
		break;

	case 9:
	case 12:
		dow += 5;
		break;

	case 4:
	case 7:
		dow += 6;
		break;
	}

	dow = dow % 7;
	rtca_time.dow = dow;
}
コード例 #2
0
ファイル: rtca.c プロジェクト: KarolTx/openchronos-ng
void rtca_set_date()
{
	uint8_t dow;

	/* Stop RTC timekeeping for a while */
	rtca_stop();

	dow = LEAPS_SINCE_YEAR(rtca_time.year);

	if ((29 == rtca_get_max_days(2, rtca_time.year)) && (rtca_time.mon < 3))
		dow--; /* if this is a leap year but before February 29 */

	/* add day of current month */
	dow += rtca_time.day;

	/* add this month's dow value */
	switch (rtca_time.mon) {
	case 5:
		dow += 1;
		break;

	case 8:
		dow += 2;
		break;

	case 2:
	case 3:
	case 11:
		dow += 3;
		break;

	case 6:
		dow += 4;
		break;

	case 9:
	case 12:
		dow += 5;
		break;

	case 4:
	case 7:
		dow += 6;
		break;
	}

	dow = dow % 7;

	/* update RTC registers and local cache */
	RTCDAY = rtca_time.day;
	RTCDOW = (rtca_time.dow = dow);
	RTCMON = rtca_time.mon;
	RTCYEARL = rtca_time.year & 0xff;
	RTCYEARH = rtca_time.year >> 8;

	/* Resume RTC time keeping */
	rtca_start();

#ifdef CONFIG_RTC_DST
	/* calculate new DST switch dates */
	rtc_dst_calculate_dates(rtca_time.year, rtca_time.mon, rtca_time.day, rtca_time.hour);
#endif
}