예제 #1
0
void rtca_set_date()
{
	/* Stop RTC timekeeping for a while */
	rtca_stop();

	rtca_update_dow();

	/* update RTC registers and local cache */
	RTCDAY = rtca_time.day;
	RTCDOW = rtca_time.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
}
예제 #2
0
void rtc_dst_init(void)
{
	/* Calculate when to switch dates */
	rtc_dst_calculate_dates(rtca_time.year, rtca_time.mon, rtca_time.day, rtca_time.hour);
}
예제 #3
0
파일: rtc.c 프로젝트: glocklueng/tracy
void RTC_A_ISR(void)
{
    /* the IV is cleared after a read, so we store it */
    uint16_t iv = RTCIV;

    /* copy register values */
    rtca_time.sec = RTCSEC;

    /* count system time */
    rtca_time.sys++;

    enum rtca_tevent ev = 0;

    /* second event (from the read ready interrupt flag) */
    if (iv == RTCIV_RTCRDYIFG) {
        ev = RTCA_EV_SECOND;
        goto finish;
    }

    if (iv == RTCIV_RTCAIFG) {
        ev = RTCA_EV_ALARM;
        goto finish;
    }

    {
        if (iv != RTCIV_RTCTEVIFG)      /* Minute changed! */
            goto finish;

        ev |= RTCA_EV_MINUTE;
        rtca_time.min = RTCMIN;

        if (rtca_time.min != 0) /* Hour changed */
            goto finish;

        ev |= RTCA_EV_HOUR;
        rtca_time.hour = RTCHOUR;

#ifdef CONFIG_RTC_DST
        rtc_dst_hourly_update();
#endif

        if (rtca_time.hour != 0)        /* Day changed */
            goto finish;

        ev |= RTCA_EV_DAY;
        rtca_time.day = RTCDAY;
        rtca_time.dow = RTCDOW;

        if (rtca_time.day != 1) /* Month changed */
            goto finish;

        ev |= RTCA_EV_MONTH;
        rtca_time.mon = RTCMON;

        if (rtca_time.mon != 1) /* Year changed */
            goto finish;

        ev |= RTCA_EV_YEAR;
        rtca_time.year = RTCYEARL | (RTCYEARH << 8);
#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
    }

 finish:
    /* append events, since ISR could be triggered
       multipe times until rtca_last_event gets parsed */
    rtca_last_event |= ev;

    /* exit from LPM3, give execution back to mainloop */
    _BIC_SR_IRQ(LPM3_bits);
}
예제 #4
0
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
}