bigtime_t arch_get_rtc_delta(void) { //int oldsec int sec, min, hour; int day, month, year, century; bigtime_t val; isa_rtc_nmi_off(); check_update_in_progress(); //retry: min = readrtc(RTC_MIN); if(min < 0 || min > 59) min = 0; hour = readrtc(RTC_HOUR); if(hour < 0 || hour > 23) hour = 0; month = readrtc(RTC_MONTH); if(month < 1 || month > 12) month = 1; day = readrtc(RTC_DAY); if(day < 1 || day > month_days[month-1]) day = 1; year = readrtc(RTC_YEAR); century = readrtc(RTC_CENTURY); if(century > 0) { year += century * 100; } else { if(year < 80) year += 2000; else year += 1900; } /* // keep reading the second counter until it changes oldsec = readrtc(RTC_SEC); while((sec = readrtc(RTC_SEC)) == oldsec) ; if(sec == 0) { // we just wrapped around, and potentially changed // all of the other counters, retry everything goto retry; }*/ sec = readrtc(RTC_SEC); isa_rtc_nmi_on(); // convert these values into usecs since Jan 1, 1 AD val = (365 * (year - 1) - (year / 4) + (year / 400)) * usecs_per_day; val += ((day - 1) + months[month - 1] + ((month > 2) ? is_leap_year(year) : 0)) * usecs_per_day; val += (((hour * 60) + min) * 60 + sec) * 1000000; printf("arch_get_rtc_delta: GMT %d:%d:%d %d.%d.%d\n", hour, min, sec, day, month, year ); return val; }
void rtc_read_tm( struct tm *out ) { isa_rtc_nmi_off(); check_update_in_progress(); //retry: out->tm_min = readrtc(RTC_MIN); out->tm_hour = readrtc(RTC_HOUR); out->tm_mon = readrtc(RTC_MONTH); out->tm_mday = readrtc(RTC_DAY); int year = readrtc(RTC_YEAR); int century = readrtc(RTC_CENTURY); if(century > 0) { year += century * 100; } else { if(year < 80) year += 2000; else year += 1900; } out->tm_year = year - 1900; out->tm_yday = 0; // TODO calc me out->tm_wday = readrtc(RTC_WDAY); /* // keep reading the second counter until it changes int sec; int oldsec = readrtc(RTC_SEC); while((sec = readrtc(RTC_SEC)) == oldsec) ; if(sec == 0) { // we just wrapped around, and potentially changed // all of the other counters, retry everything goto retry; } out->tm_sec=sec; */ out->tm_sec = readrtc(RTC_SEC); isa_rtc_nmi_on(); }
static int atrtc_gettime(device_t dev, struct timespec *ts) { struct clocktime ct; int s; /* Look if we have a RTC present and the time is valid */ if (!(rtcin(RTC_STATUSD) & RTCSD_PWR)) { device_printf(dev, "WARNING: Battery failure indication\n"); return (EINVAL); } /* wait for time update to complete */ /* If RTCSA_TUP is zero, we have at least 244us before next update */ s = splhigh(); while (rtcin(RTC_STATUSA) & RTCSA_TUP) { splx(s); s = splhigh(); } ct.nsec = 0; ct.sec = readrtc(RTC_SEC); ct.min = readrtc(RTC_MIN); ct.hour = readrtc(RTC_HRS); ct.day = readrtc(RTC_DAY); ct.dow = readrtc(RTC_WDAY) - 1; ct.mon = readrtc(RTC_MONTH); ct.year = readrtc(RTC_YEAR); #ifdef USE_RTC_CENTURY ct.year += readrtc(RTC_CENTURY) * 100; #else ct.year += 2000; #endif /* Set dow = -1 because some clocks don't set it correctly. */ ct.dow = -1; return (clock_ct_to_ts(&ct, ts)); }