FreeBSD/sys/arm/at91/at91_rtc.c
/*
 * Get the time of day clock and return it in ts.
 * Return 0 on success, an error number otherwise.
 */
Get the time of day clock and return it in ts.
Return 0 on success, an error number otherwise.
Get the time of day clock and return it in ts . Return 0 on success an error number otherwise .
static int
at91_rtc_gettime(device_t dev, struct timespec *ts)
{
	struct clocktime ct;
	uint32_t calr, calr2, timr, timr2;
	struct at91_rtc_softc *sc;
	sc = device_get_softc(dev);
	if (RD4(sc, RTC_VER) & (RTC_VER_NVTIM | RTC_VER_NVCAL))
		return EINVAL;
	do {
		timr = RD4(sc, RTC_TIMR);
		calr = RD4(sc, RTC_CALR);
		timr2 = RD4(sc, RTC_TIMR);
		calr2 = RD4(sc, RTC_CALR);
	} while (timr != timr2 || calr != calr2);
	ct.nsec = 0;
	ct.sec = RTC_TIMR_SEC(timr);
	ct.min = RTC_TIMR_MIN(timr);
	ct.hour = RTC_TIMR_HR(timr);
	ct.year = RTC_CALR_CEN(calr) * 100 + RTC_CALR_YEAR(calr);
	ct.mon = RTC_CALR_MON(calr);
	ct.day = RTC_CALR_DAY(calr);
	ct.dow = -1;
	return clock_ct_to_ts(&ct, ts);
}
static int at91_rtc_gettime ( device_t dev , struct timespec * ts ) { struct clocktime ct ; uint32_t calr , calr2 , timr , timr2 ; struct at91_rtc_softc * sc ; sc = device_get_softc ( dev ) ; if ( RD4 ( sc , RTC_VER ) & ( RTC_VER_NVTIM | RTC_VER_NVCAL ) ) return EINVAL ; do { timr = RD4 ( sc , RTC_TIMR ) ; calr = RD4 ( sc , RTC_CALR ) ; timr2 = RD4 ( sc , RTC_TIMR ) ; calr2 = RD4 ( sc , RTC_CALR ) ; } while ( timr != timr2 || calr != calr2 ) ; ct . nsec = 0 ; ct . sec = RTC_TIMR_SEC ( timr ) ; ct . min = RTC_TIMR_MIN ( timr ) ; ct . hour = RTC_TIMR_HR ( timr ) ; ct . year = RTC_CALR_CEN ( calr ) * 100 + RTC_CALR_YEAR ( calr ) ; ct . mon = RTC_CALR_MON ( calr ) ; ct . day = RTC_CALR_DAY ( calr ) ; ct . dow = -1 ; return clock_ct_to_ts ( & ct , ts ) ; }
Get the time of day clock and return it in ts.
Get the time of day clock and return it in ts .
/* If the error bits are set we can't return useful values. */ /*
	 * The RTC hardware can update registers while the CPU is reading them.
	 * The manual advises reading until you obtain the same values twice.
	 * Interleaving the reads (rather than timr, timr2, calr, calr2 order)
	 * also ensures we don't miss a midnight rollover/carry between reads.
	 */