Port-atari archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Time counter and generic TODR patch for testing
Hi all,
please try the attached patch.
(a) It should read the correct time from the hardware.
(b) It should write back the time on halt/reboot, e.g. try changing it.
(c) date; sleep 10; date should show a diff of 10 seconds.
(d) Please run src/regress/sys/kern/time and report issues.
CC me on replies, please.
Joerg
Index: atari/atari/machdep.c
===================================================================
RCS file: /data/repo/netbsd/src/sys/arch/atari/atari/machdep.c,v
retrieving revision 1.148
diff -u -p -r1.148 machdep.c
--- atari/atari/machdep.c 3 Jan 2008 00:31:28 -0000 1.148
+++ atari/atari/machdep.c 3 Jan 2008 18:23:04 -0000
@@ -629,38 +629,6 @@ dumpsys(void)
delay(5000000); /* 5 seconds */
}
-/*
- * Return the best possible estimate of the time in the timeval
- * to which tvp points. We do this by returning the current time
- * plus the amount of time since the last clock interrupt (clock.c:clkread).
- *
- * Check that this time is no less than any previously-reported time,
- * which could happen around the time of a clock adjustment. Just for fun,
- * we guarantee that the time will be greater than the value obtained by a
- * previous call.
- */
-void
-microtime(struct timeval *tvp)
-{
- int s = splhigh();
- static struct timeval lasttime;
-
- *tvp = time;
- tvp->tv_usec += clkread();
- while (tvp->tv_usec >= 1000000) {
- tvp->tv_sec++;
- tvp->tv_usec -= 1000000;
- }
- if (tvp->tv_sec == lasttime.tv_sec &&
- tvp->tv_usec <= lasttime.tv_usec &&
- (tvp->tv_usec = lasttime.tv_usec + 1) >= 1000000) {
- tvp->tv_sec++;
- tvp->tv_usec -= 1000000;
- }
- lasttime = *tvp;
- splx(s);
-}
-
void
straytrap(int pc, u_short evec)
{
Index: atari/dev/clock.c
===================================================================
RCS file: /data/repo/netbsd/src/sys/arch/atari/dev/clock.c,v
retrieving revision 1.39
diff -u -p -r1.39 clock.c
--- atari/dev/clock.c 3 Jan 2008 01:02:04 -0000 1.39
+++ atari/dev/clock.c 3 Jan 2008 21:39:02 -0000
@@ -87,6 +87,7 @@ __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.
#include <sys/conf.h>
#include <sys/proc.h>
#include <sys/event.h>
+#include <sys/timetc.h>
#include <dev/clock_subr.h>
@@ -101,6 +102,9 @@ __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.
#include <machine/profile.h>
#endif
+static int atari_rtc_get(todr_chip_handle_t, struct clock_ymdhms *);
+static int atari_rtc_set(todr_chip_handle_t, struct clock_ymdhms *);
+
/*
* The MFP clock runs at 2457600Hz. We use a {system,stat,prof}clock divider
* of 200. Therefore the timer runs at an effective rate of:
@@ -108,6 +112,19 @@ __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.
*/
#define CLOCK_HZ 12288
+static u_int clk_getcounter(struct timecounter *);
+
+static struct timecounter clk_timecounter = {
+ clk_getcounter, /* get_timecount */
+ 0, /* no poll_pps */
+ ~0u, /* counter_mask */
+ CLOCK_HZ, /* frequency */
+ "clock", /* name, overriden later */
+ 100, /* quality */
+ NULL, /* prev */
+ NULL, /* next */
+};
+
/*
* Machine-dependent clock routines.
*
@@ -147,7 +164,6 @@ const struct cdevsw rtc_cdevsw = {
void statintr __P((struct clockframe));
-static u_long gettod __P((void));
static int twodigits __P((char *, int));
static int divisor; /* Systemclock divisor */
@@ -186,12 +202,6 @@ void *auxp;
MFP->mf_tbdr = 0;
MFP->mf_tbcr = T_Q004; /* Start timer */
- /*
- * Initialize the time structure
- */
- time.tv_sec = 0;
- time.tv_usec = 0;
-
return 0;
}
if(!strcmp("clock", auxp))
@@ -207,6 +217,13 @@ struct device *pdp, *dp;
void *auxp;
{
struct clock_softc *sc = (void *)dp;
+ static struct todr_chip_handle tch;
+
+ tch.todr_gettime_ymdhms = atari_rtc_get;
+ tch.todr_settime_ymdhms = atari_rtc_set;
+ tch.todr_setwen = NULL;
+
+ todr_attach(&tch);
sc->sc_flags = 0;
@@ -221,6 +238,9 @@ void *auxp;
MFP->mf_iera &= ~IA_TIMA; /* Disable timer interrupts */
MFP->mf_tadr = divisor; /* Set divisor */
+ clk_timecounter.tc_frequency = CLOCK_HZ;
+ tc_init(&clk_timecounter);
+
if (hz != 48 && hz != 64 && hz != 96) { /* XXX */
printf (": illegal value %d for systemclock, reset to %d\n\t",
hz, 64);
@@ -296,32 +316,24 @@ statintr(frame)
}
#endif /* STATCLOCK */
-/*
- * Returns number of usec since last recorded clock "tick"
- * (i.e. clock interrupt).
- */
-long
-clkread()
+static u_int
+clk_getcounter(struct timecounter *tc)
{
- u_int delta;
- u_char ipra, tadr;
+ u_int delta;
+ u_char ipra, tadr;
+ int s, cur_hardclock;
- /*
- * Note: Order is important!
- * By reading 'ipra' before 'tadr' and caching the data, I try to avoid
- * the situation that very low value in 'tadr' is read (== a big delta)
- * while also acccounting for a full 'tick' because the counter went
- * through zero during the calculations.
- */
- ipra = MFP->mf_ipra; tadr = MFP->mf_tadr;
+ s = splhigh();
+ ipra = MFP->mf_ipra;
+ tadr = MFP->mf_tadr;
+ delta = divisor - tadr;
+
+ if (ipra & IA_TIMA)
+ delta += divisor;
+ cur_hardclock = hardclock_ticks;
+ splx(s);
- delta = ((divisor - tadr) * tick) / divisor;
- /*
- * Account for pending clock interrupts
- */
- if(ipra & IA_TIMA)
- return(delta + tick);
- return(delta);
+ return (divisor - tadr) + divisor * cur_hardclock;
}
#define TIMB_FREQ 614400
@@ -426,38 +438,12 @@ u_int regno, value;
((struct rtc *)rtc)->rtc_data = value;
}
-/*
- * Initialize the time of day register, assuming the RTC runs in UTC.
- * Since we've got the 'rtc' device, this functionality should be removed
- * from the kernel. The only problem to be solved before that can happen
- * is the possibility of init(1) providing a way (rc.boot?) to set
- * the RTC before single-user mode is entered.
- */
-void
-inittodr(base)
-time_t base;
-{
- /* Battery clock does not store usec's, so forget about it. */
- time.tv_sec = gettod();
- time.tv_usec = 0;
-}
-
-/*
- * Function turned into a No-op. Use /dev/rtc to update the RTC.
- */
-void
-resettodr()
-{
- return;
-}
-
-static u_long
-gettod()
+static int
+atari_rtc_get(todr_chip_handle_t todr, struct clock_ymdhms *dtp)
{
int sps;
mc_todregs clkregs;
u_int regb;
- struct clock_ymdhms dt;
sps = splhigh();
regb = mc146818_read(RTC, MC_REGB);
@@ -472,27 +458,48 @@ gettod()
return(0);
}
if(clkregs[MC_SEC] > 59)
- return(0);
+ return -1;
if(clkregs[MC_MIN] > 59)
- return(0);
+ return -1;
if(clkregs[MC_HOUR] > 23)
- return(0);
+ return -1;
if(range_test(clkregs[MC_DOM], 1, 31))
- return(0);
+ return -1;
if (range_test(clkregs[MC_MONTH], 1, 12))
- return(0);
+ return -1;
if(clkregs[MC_YEAR] > 99)
- return(0);
+ return -1;
+
+ dtp->dt_year = clkregs[MC_YEAR] + GEMSTARTOFTIME;
+ dtp->dt_mon = clkregs[MC_MONTH];
+ dtp->dt_day = clkregs[MC_DOM];
+ dtp->dt_hour = clkregs[MC_HOUR];
+ dtp->dt_min = clkregs[MC_MIN];
+ dtp->dt_sec = clkregs[MC_SEC];
+
+ return 0;
+}
+
+static int
+atari_rtc_set(todr_chip_handle_t todr, struct clock_ymdhms *dtp)
+{
+ int s;
+ mc_todregs clkregs;
- dt.dt_year = clkregs[MC_YEAR] + GEMSTARTOFTIME;
- dt.dt_mon = clkregs[MC_MONTH];
- dt.dt_day = clkregs[MC_DOM];
- dt.dt_hour = clkregs[MC_HOUR];
- dt.dt_min = clkregs[MC_MIN];
- dt.dt_sec = clkregs[MC_SEC];
+ clkregs[MC_YEAR] = dtp->dt_year - GEMSTARTOFTIME;
+ clkregs[MC_MONTH] = dtp->dt_mon;
+ clkregs[MC_DOM] = dtp->dt_day;
+ clkregs[MC_HOUR] = dtp->dt_hour;
+ clkregs[MC_MIN] = dtp->dt_min;
+ clkregs[MC_SEC] = dtp->dt_sec;
- return(clock_ymdhms_to_secs(&dt));
+ s = splclock();
+ MC146818_PUTTOD(RTC, &clkregs);
+ splx(s);
+
+ return 0;
}
+
/***********************************************************************
* RTC-device support *
***********************************************************************/
Index: atari/dev/kbd.c
===================================================================
RCS file: /data/repo/netbsd/src/sys/arch/atari/dev/kbd.c,v
retrieving revision 1.30
diff -u -p -r1.30 kbd.c
--- atari/dev/kbd.c 4 Mar 2007 05:59:40 -0000 1.30
+++ atari/dev/kbd.c 3 Jan 2008 18:58:49 -0000
@@ -535,7 +535,7 @@ void *junk1, *junk2;
}
fe->id = KBD_SCANCODE(code);
fe->value = KBD_RELEASED(code) ? VKEY_UP : VKEY_DOWN;
- fe->time = time;
+ getmicrotime(&fe->time);
k->k_events.ev_put = put;
EV_WAKEUP(&k->k_events);
splx(s);
Index: atari/dev/ms.c
===================================================================
RCS file: /data/repo/netbsd/src/sys/arch/atari/dev/ms.c,v
retrieving revision 1.19
diff -u -p -r1.19 ms.c
--- atari/dev/ms.c 17 Oct 2007 19:53:48 -0000 1.19
+++ atari/dev/ms.c 3 Jan 2008 19:00:10 -0000
@@ -214,7 +214,7 @@ int size, type;
}
fe->id = LOC_X_DELTA;
fe->value = rel_ms->dx;
- fe->time = time;
+ getmicrotime(&fe->time);
if (put >= EV_QSIZE) {
put = 0;
fe = &ms->ms_events.ev_q[0];
@@ -228,7 +228,7 @@ int size, type;
}
fe->id = LOC_Y_DELTA;
fe->value = rel_ms->dy;
- fe->time = time;
+ getmicrotime(&fe->time);
if (put >= EV_QSIZE) {
put = 0;
fe = &ms->ms_events.ev_q[0];
@@ -246,7 +246,7 @@ int size, type;
fe2->id = MS_LEFT;
else fe2->id = MS_MIDDLE;
fe2->value = rel_ms->id & bmask ? VKEY_DOWN : VKEY_UP;
- fe2->time = time;
+ getmicrotime(&fe2->time);
}
}
Index: atari/dev/zs.c
===================================================================
RCS file: /data/repo/netbsd/src/sys/arch/atari/dev/zs.c,v
retrieving revision 1.54
diff -u -p -r1.54 zs.c
--- atari/dev/zs.c 19 Nov 2007 18:51:39 -0000 1.54
+++ atari/dev/zs.c 3 Jan 2008 19:09:40 -0000
@@ -726,9 +726,10 @@ int unit;
long *ptime;
const char *what;
{
+ time_t cur_sec = time_second;
- if(*ptime != time.tv_sec) {
- *ptime = time.tv_sec;
+ if(*ptime != cur_sec) {
+ *ptime = cur_sec;
log(LOG_WARNING, "zs%d%c: %s overrun\n", unit >> 1,
(unit & 1) + 'a', what);
}
Index: atari/include/cpu.h
===================================================================
RCS file: /data/repo/netbsd/src/sys/arch/atari/include/cpu.h,v
retrieving revision 1.59
diff -u -p -r1.59 cpu.h
--- atari/include/cpu.h 17 Oct 2007 19:53:57 -0000 1.59
+++ atari/include/cpu.h 3 Jan 2008 18:24:08 -0000
@@ -221,11 +221,6 @@ int cpu_dumpsize __P((void));
void config_console __P((void));
/*
- * Prototypes from clock.c
- */
-long clkread __P((void));
-
-/*
* Prototypes from fpu.c
*/
const char *fpu_describe __P((int));
Index: atari/include/types.h
===================================================================
RCS file: /data/repo/netbsd/src/sys/arch/atari/include/types.h,v
retrieving revision 1.11
diff -u -p -r1.11 types.h
--- atari/include/types.h 17 Oct 2007 19:53:57 -0000 1.11
+++ atari/include/types.h 3 Jan 2008 21:46:35 -0000
@@ -5,4 +5,7 @@
#include <m68k/types.h>
+#define __HAVE_TIMECOUNTER
+#define __HAVE_GENERIC_TODR
+
#endif
Home |
Main Index |
Thread Index |
Old Index