Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/x68k/x68k - Use HZ mechanism.



details:   https://anonhg.NetBSD.org/src/rev/88c8247413db
branches:  trunk
changeset: 534015:88c8247413db
user:      isaki <isaki%NetBSD.org@localhost>
date:      Sat Jul 13 05:55:26 2002 +0000

description:
- Use HZ mechanism.
  Pointed out by Perry E. Metzger <perry%piermont.com@localhost> on port-x68k.
- Correct microtime() value.

diffstat:

 sys/arch/x68k/x68k/clock.c |  25 ++++++++++++++++++-------
 1 files changed, 18 insertions(+), 7 deletions(-)

diffs (56 lines):

diff -r bcb0a10f0af8 -r 88c8247413db sys/arch/x68k/x68k/clock.c
--- a/sys/arch/x68k/x68k/clock.c        Sat Jul 13 01:23:27 2002 +0000
+++ b/sys/arch/x68k/x68k/clock.c        Sat Jul 13 05:55:26 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: clock.c,v 1.11 2001/03/15 06:10:53 chs Exp $   */
+/*     $NetBSD: clock.c,v 1.12 2002/07/13 05:55:26 isaki Exp $ */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -98,10 +98,14 @@
 }
 
 
-/* We're using a 100 Hz clock. */
+/*
+ * MFP of X68k uses 4MHz clock always and we use 1/200 prescaler here.
+ * Therefore, clock interval is 50 usec.
+ */
+#define CLK_RESOLUTION (50)
+#define CLOCKS_PER_SEC (1000000 / CLK_RESOLUTION)
 
-#define CLK_INTERVAL 200
-#define CLOCKS_PER_SEC 100
+static int clkint;             /* clock interval */
 
 static int clkread __P((void));
 
@@ -130,10 +134,17 @@
 void
 cpu_initclocks()
 {
+       if (CLOCKS_PER_SEC % hz ||
+           hz <= (CLOCKS_PER_SEC / 256) || hz > CLOCKS_PER_SEC) {
+               printf("cannot set %d Hz clock. using 100 Hz\n", hz);
+               hz = 100;
+       }
+       clkint = CLOCKS_PER_SEC / hz;
+
        mfp_set_tcdcr(mfp_get_tcdcr() & 0x0f); /* stop timer C */
-       mfp_set_tcdr(CLK_INTERVAL);
+       mfp_set_tcdcr(mfp_get_tcdcr() | 0x70); /* 1/200 delay mode */
 
-       mfp_set_tcdcr(mfp_get_tcdcr() | 0x70); /* 1/200 delay mode */
+       mfp_set_tcdr(clkint);
        mfp_bit_set_ierb(MFP_INTR_TIMER_C);
 }
 
@@ -155,7 +166,7 @@
 int
 clkread()
 {
-       return (mfp_get_tcdr() * CLOCKS_PER_SEC) / CLK_INTERVAL;
+       return (clkint - mfp_get_tcdr()) * CLK_RESOLUTION;
 }
 
 



Home | Main Index | Thread Index | Old Index