Subject: Re: could this get cleaned up...
To: None <port-x68k@netbsd.org, perry@piermont.com>
From: Tetsuya Isaki <isaki@NetBSD.org>
List: port-x68k
Date: 07/13/2002 15:03:06
I've just commited it.
If you find some problem, please send-pr or let me know.
---
Tetsuya Isaki <isaki@par.odn.ne.jp / isaki@NetBSD.org>
On Sun, 07 Jul 2002 11:08:29 +0900,
In Re: could this get cleaned up...,
Tetsuya Isaki <isaki@par.odn.ne.jp> wrote:
> > sys/arch/x68k/x68k/clock.c uses
> > #define CLOCKS_PER_SEC 100
> > instead of the usual HZ mechanisms to set up the port clock
> > rate. At the very least, the name of the #define is ill advised -- it
> > is also used by a standard #define in userland that is about to be
> > changed to be more standards conformant.
>
> I rewrote it.
> The kernel with default HZ(100) seems to work. Also the
> kernel with 'options HZ=200' seems to work. Can I commit?
> Please review.
>
> By the way, clkread() has returned unusable value.
> 1) clkread() should return the time in microseconds unit.
> But it returns something else (clock unit ?).
> 2) clkread() should return the time since last tick. It
> however does not, because mfp_get_tcdr() is decremented by
> each clock.
>
> Index: clock.c
> ===================================================================
> RCS file: /cvsroot/syssrc/sys/arch/x68k/x68k/clock.c,v
> retrieving revision 1.11
> diff -u -r1.11 clock.c
> --- clock.c 2001/03/15 06:10:53 1.11
> +++ clock.c 2002/07/07 02:06:48
> @@ -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()
> {
> - mfp_set_tcdcr(mfp_get_tcdcr() & 0x0f); /* stop timer C */
> - mfp_set_tcdr(CLK_INTERVAL);
> + 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_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;
> }
>
>
> ---
> Tetsuya Isaki <isaki@par.odn.ne.jp / isaki@NetBSD.org>