Use the 1/256s-resolution when reading the DraCo battery backed clock

This commit is contained in:
is 1999-03-14 22:42:12 +00:00
parent 69d2d27c1b
commit ba07737bc0
5 changed files with 76 additions and 51 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: a2kbbc.c,v 1.5 1998/01/12 10:39:04 thorpej Exp $ */
/* $NetBSD: a2kbbc.c,v 1.6 1999/03/14 22:42:12 is Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@ -64,8 +64,8 @@ struct cfattach a2kbbc_ca = {
};
void *a2kclockaddr;
time_t a2gettod __P((void));
int a2settod __P((time_t));
int a2kugettod __P((struct timeval *));
int a2kusettod __P((struct timeval *));
int
a2kbbc_match(pdp, cfp, auxp)
@ -87,7 +87,7 @@ a2kbbc_match(pdp, cfp, auxp)
return (0);
a2kclockaddr = (void *)ztwomap(0xdc0000);
if (a2gettod() == 0)
if (a2kugettod(0) == 0)
return (0);
return (1);
@ -104,12 +104,13 @@ a2kbbc_attach(pdp, dp, auxp)
printf("\n");
a2kclockaddr = (void *)ztwomap(0xdc0000);
gettod = a2gettod;
settod = a2settod;
ugettod = a2kugettod;
usettod = a2kusettod;
}
time_t
a2gettod()
int
a2kugettod(tvp)
struct timeval *tvp;
{
struct rtclock2000 *rt;
struct clock_ymdhms dt;
@ -176,17 +177,21 @@ a2gettod()
return (0);
secs = clock_ymdhms_to_secs(&dt);
return (secs);
tvp->tv_sec = secs;
tvp->tv_usec = 0;
return (1);
}
int
a2settod(secs)
time_t secs;
a2kusettod(tvp)
struct timeval *tvp;
{
struct rtclock2000 *rt;
struct clock_ymdhms dt;
int ampm, i;
time_t secs;
secs = tvp->tv_sec;
rt = a2kclockaddr;
/*
* there seem to be problems with the bitfield addressing

View File

@ -1,4 +1,4 @@
/* $NetBSD: a34kbbc.c,v 1.2 1998/01/12 10:39:05 thorpej Exp $ */
/* $NetBSD: a34kbbc.c,v 1.3 1999/03/14 22:42:12 is Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@ -64,8 +64,8 @@ struct cfattach a34kbbc_ca = {
};
void *a34kclockaddr;
time_t a3gettod __P((void));
int a3settod __P((time_t));
int a34kugettod __P((struct timeval *));
int a34kusettod __P((struct timeval *));
int
a34kbbc_match(pdp, cfp, auxp)
@ -83,7 +83,7 @@ a34kbbc_match(pdp, cfp, auxp)
return(0);
a34kclockaddr = (void *)ztwomap(0xdc0000);
if (a3gettod() == 0)
if (a34kugettod(0) == 0)
return(0);
return(1);
@ -100,12 +100,13 @@ a34kbbc_attach(pdp, dp, auxp)
printf("\n");
a34kclockaddr = (void *)ztwomap(0xdc0000);
gettod = a3gettod;
settod = a3settod;
ugettod = a34kugettod;
usettod = a34kusettod;
}
time_t
a3gettod()
int
a34kugettod(tvp)
struct timeval *tvp;
{
struct rtclock3000 *rt;
struct clock_ymdhms dt;
@ -138,17 +139,21 @@ a3gettod()
return (0);
secs = clock_ymdhms_to_secs(&dt);
return (secs);
if (tvp)
tvp->tv_sec = secs;
return (1);
}
int
a3settod(secs)
time_t secs;
a34kusettod(tvp)
struct timeval *tvp;
{
struct rtclock3000 *rt;
struct clock_ymdhms dt;
time_t secs;
rt = a34kclockaddr;
secs = tvp->tv_sec;
/*
* there seem to be problems with the bitfield addressing
* currently used..

View File

@ -1,4 +1,4 @@
/* $NetBSD: clock.c,v 1.33 1998/07/26 06:45:18 is Exp $ */
/* $NetBSD: clock.c,v 1.34 1999/03/14 22:42:12 is Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@ -649,25 +649,38 @@ void
inittodr(base)
time_t base;
{
time_t timbuf = base; /* assume no battery clock exists */
if (gettod == NULL)
printf("WARNING: no battery clock\n");
else
timbuf = gettod() + rtc_offset * 60;
struct timeval tvbuf;
if (timbuf < base) {
tvbuf.tv_usec = 0;
tvbuf.tv_sec = base; /* assume no battery clock exists */
if (ugettod == NULL)
printf("WARNING: no battery clock\n");
else {
ugettod(&tvbuf);
tvbuf.tv_sec += rtc_offset * 60;
}
if (tvbuf.tv_sec < base) {
printf("WARNING: bad date in battery clock\n");
timbuf = base;
tvbuf.tv_sec = base;
}
/* Battery clock does not store usec's, so forget about it. */
time.tv_sec = timbuf;
time = tvbuf;
}
void
resettodr()
{
if (settod && settod(time.tv_sec - rtc_offset * 60) == 0)
struct timeval tvbuf;
if (!usettod)
return;
tvbuf = time;
tvbuf.tv_sec -= rtc_offset * 60;
if (!usettod(&tvbuf))
printf("Cannot set battery backed clock\n");
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: drbbc.c,v 1.4 1999/02/16 23:34:11 is Exp $ */
/* $NetBSD: drbbc.c,v 1.5 1999/03/14 22:42:12 is Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -59,9 +59,9 @@ void draco_ds_reset __P((void *));
void drbbc_attach __P((struct device *, struct device *, void *));
int drbbc_match __P((struct device *, struct cfdata *, void *));
time_t dracogettod __P((void));
int dracougettod __P((struct timeval *));
#ifdef __NOTYET__
int dracosettod __P((time_t));
int dracousettod __P((struct timeval *));
#endif
struct drbbc_softc {
@ -119,8 +119,8 @@ drbbc_attach(pdp, dp, auxp)
rombuf[3], rombuf[2], rombuf[1], rombuf[0],
hostid);
gettod = dracogettod;
settod = (void *)0;
ugettod = dracougettod;
usettod = (void *)0;
drbbc_sc = sc;
}
@ -169,24 +169,23 @@ draco_ds_reset(p)
draco_ioct->io_clockrst = 0;
}
/*
* We could return 1/256 of a seconds, but would need to change the interface
*/
time_t
dracogettod()
int
dracougettod(tvp)
struct timeval *tvp;
{
u_int32_t clkbuf;
u_int32_t usecs;
drbbc_sc->sc_dsh.ds_reset(drbbc_sc->sc_dsh.ds_hw_handle);
ds_write_byte(&drbbc_sc->sc_dsh, DS_ROM_SKIP);
ds_write_byte(&drbbc_sc->sc_dsh, DS_MEM_READ_MEMORY);
/* address of full seconds: */
ds_write_byte(&drbbc_sc->sc_dsh, 0x03);
/* address of seconds/256: */
ds_write_byte(&drbbc_sc->sc_dsh, 0x02);
ds_write_byte(&drbbc_sc->sc_dsh, 0x02);
usecs = (ds_read_byte(&drbbc_sc->sc_dsh) * 1000000) / 256;
clkbuf = ds_read_byte(&drbbc_sc->sc_dsh)
+ (ds_read_byte(&drbbc_sc->sc_dsh)<<8)
+ (ds_read_byte(&drbbc_sc->sc_dsh)<<16)
@ -196,5 +195,8 @@ dracogettod()
clkbuf += (8*365 + 2) * 86400;
return ((time_t)clkbuf);
tvp->tv_sec = clkbuf;
tvp->tv_usec = usecs;
return (1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtc.h,v 1.5 1997/07/17 23:29:28 is Exp $ */
/* $NetBSD: rtc.h,v 1.6 1999/03/14 22:42:12 is Exp $ */
/*
* Copyright (c) 1994 Christian E. Hopps
@ -38,8 +38,8 @@
/* this is a hook set by a clock driver for the configured realtime clock,
returning plain current unix-time */
time_t (*gettod) __P((void));
int (*settod) __P((time_t));
int (*ugettod) __P((struct timeval *));
int (*usettod) __P((struct timeval *));
struct rtclock2000 {
u_int :28, second2:4; /* lower digit */