FreeBSD/sys/dev/mk48txx/mk48txx.c
/*
 * Get time-of-day and convert to a `struct timespec'
 * Return 0 on success; an error number otherwise.
 */
Get time-of-day and convert to a `struct timespec'
Return 0 on success; an error number otherwise.
Get time - of - day and convert to a ` struct timespec ' Return 0 on success ; an error number otherwise .
int
mk48txx_gettime(device_t dev, struct timespec *ts)
{
	struct mk48txx_softc *sc;
	bus_size_t clkoff;
	struct clocktime ct;
	int year;
	uint8_t csr;
	sc = device_get_softc(dev);
	clkoff = sc->sc_clkoffset;
	mtx_lock(&sc->sc_mtx);
	csr = (*sc->sc_nvrd)(dev, clkoff + MK48TXX_ICSR);
	csr |= MK48TXX_CSR_READ;
	(*sc->sc_nvwr)(dev, clkoff + MK48TXX_ICSR, csr);
#define	FROMREG(reg, mask)	((*sc->sc_nvrd)(dev, clkoff + (reg)) & (mask))
	ct.nsec = 0;
	ct.sec = FROMBCD(FROMREG(MK48TXX_ISEC, MK48TXX_SEC_MASK));
	ct.min = FROMBCD(FROMREG(MK48TXX_IMIN, MK48TXX_MIN_MASK));
	ct.hour = FROMBCD(FROMREG(MK48TXX_IHOUR, MK48TXX_HOUR_MASK));
	ct.day = FROMBCD(FROMREG(MK48TXX_IDAY, MK48TXX_DAY_MASK));
#if 0
	ct.dow = FROMREG(MK48TXX_IWDAY, MK48TXX_WDAY_MASK) - 1;
#else
	ct.dow = -1;
#endif
	ct.mon = FROMBCD(FROMREG(MK48TXX_IMON, MK48TXX_MON_MASK));
	year = FROMBCD(FROMREG(MK48TXX_IYEAR, MK48TXX_YEAR_MASK));
	year += sc->sc_year0;
	if (sc->sc_flag & MK48TXX_NO_CENT_ADJUST)
		year += (FROMREG(MK48TXX_IWDAY, MK48TXX_WDAY_CB) >>
		    MK48TXX_WDAY_CB_SHIFT) * 100;
	else if (year < POSIX_BASE_YEAR)
		year += 100;
#undef FROMREG
	ct.year = year;
	csr = (*sc->sc_nvrd)(dev, clkoff + MK48TXX_ICSR);
	csr &= ~MK48TXX_CSR_READ;
	(*sc->sc_nvwr)(dev, clkoff + MK48TXX_ICSR, csr);
	mtx_unlock(&sc->sc_mtx);
	return (clock_ct_to_ts(&ct, ts));
}
int mk48txx_gettime ( device_t dev , struct timespec * ts ) { struct mk48txx_softc * sc ; bus_size_t clkoff ; struct clocktime ct ; int year ; uint8_t csr ; sc = device_get_softc ( dev ) ; clkoff = sc -> sc_clkoffset ; mtx_lock ( & sc -> sc_mtx ) ; csr = ( * sc -> sc_nvrd ) ( dev , clkoff + MK48TXX_ICSR ) ; csr |= MK48TXX_CSR_READ ; ( * sc -> sc_nvwr ) ( dev , clkoff + MK48TXX_ICSR , csr ) ; #define FROMREG ( reg , mask ) 	((*sc->sc_nvrd)(dev, clkoff + (reg)) & (mask)) ct . nsec = 0 ; ct . sec = FROMBCD ( FROMREG ( MK48TXX_ISEC , MK48TXX_SEC_MASK ) ) ; ct . min = FROMBCD ( FROMREG ( MK48TXX_IMIN , MK48TXX_MIN_MASK ) ) ; ct . hour = FROMBCD ( FROMREG ( MK48TXX_IHOUR , MK48TXX_HOUR_MASK ) ) ; ct . day = FROMBCD ( FROMREG ( MK48TXX_IDAY , MK48TXX_DAY_MASK ) ) ; #if 0 ct . dow = FROMREG ( MK48TXX_IWDAY , MK48TXX_WDAY_MASK ) - 1 ; #else ct . dow = -1 ; #endif ct . mon = FROMBCD ( FROMREG ( MK48TXX_IMON , MK48TXX_MON_MASK ) ) ; year = FROMBCD ( FROMREG ( MK48TXX_IYEAR , MK48TXX_YEAR_MASK ) ) ; year += sc -> sc_year0 ; if ( sc -> sc_flag & MK48TXX_NO_CENT_ADJUST ) year += ( FROMREG ( MK48TXX_IWDAY , MK48TXX_WDAY_CB ) >> MK48TXX_WDAY_CB_SHIFT ) * 100 ; else if ( year < POSIX_BASE_YEAR ) year += 100 ; #undef  FROMREG ct . year = year ; csr = ( * sc -> sc_nvrd ) ( dev , clkoff + MK48TXX_ICSR ) ; csr &= ~ MK48TXX_CSR_READ ; ( * sc -> sc_nvwr ) ( dev , clkoff + MK48TXX_ICSR , csr ) ; mtx_unlock ( & sc -> sc_mtx ) ; return ( clock_ct_to_ts ( & ct , ts ) ) ; }
Get time-of-day and convert to a `struct timespec'
 Return 0 on success; an error number otherwise.
Get time - of - day and convert to a ` struct timespec ' Return 0 on success ; an error number otherwise .
/* enable read (stop time) */ /* Map dow from 1 - 7 to 0 - 6; FROMBCD() isn't necessary here. */ /*
	 * Set dow = -1 because some drivers (for example the NetBSD and
	 * OpenBSD mk48txx(4)) don't set it correctly.
	 */ /* time wears on */