Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/hpcsh new hpcsh clock module.



details:   https://anonhg.NetBSD.org/src/rev/9d3d8af4095e
branches:  trunk
changeset: 508961:9d3d8af4095e
user:      uch <uch%NetBSD.org@localhost>
date:      Mon Apr 23 11:22:19 2001 +0000

description:
new hpcsh clock module.

diffstat:

 sys/arch/hpcsh/conf/GENERIC     |    5 +-
 sys/arch/hpcsh/conf/files.hpcsh |    3 +-
 sys/arch/hpcsh/hpcsh/autoconf.c |    5 +-
 sys/arch/hpcsh/hpcsh/clock.c    |  401 ++++++++++++++++++++++++++++++++++++++++
 sys/arch/hpcsh/hpcsh/machdep.c  |   27 +-
 5 files changed, 421 insertions(+), 20 deletions(-)

diffs (truncated from 544 to 300 lines):

diff -r 7f7a8d43082b -r 9d3d8af4095e sys/arch/hpcsh/conf/GENERIC
--- a/sys/arch/hpcsh/conf/GENERIC       Mon Apr 23 11:20:41 2001 +0000
+++ b/sys/arch/hpcsh/conf/GENERIC       Mon Apr 23 11:22:19 2001 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: GENERIC,v 1.1 2001/03/20 16:05:42 uch Exp $
+#      $NetBSD: GENERIC,v 1.2 2001/04/23 11:22:19 uch Exp $
 #
 #      GENERIC kernel for SH3+HD64461 based machines.
 #
@@ -17,12 +17,9 @@
 options        KTRACE                  # system call tracing support
 options                MSGBUFSIZE=65534
 
-#options               USE_RTCCLK
-
 # Standard system options
 
 options        RTC_OFFSET=-540 # hardware clock is this many mins. west of GMT
-options        HZ=50           # clock interrupt generates every 1/HZ sec 
 
 # Compatibility options
 options        COMPAT_43
diff -r 7f7a8d43082b -r 9d3d8af4095e sys/arch/hpcsh/conf/files.hpcsh
--- a/sys/arch/hpcsh/conf/files.hpcsh   Mon Apr 23 11:20:41 2001 +0000
+++ b/sys/arch/hpcsh/conf/files.hpcsh   Mon Apr 23 11:22:19 2001 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.hpcsh,v 1.10 2001/03/20 16:05:42 uch Exp $
+#      $NetBSD: files.hpcsh,v 1.11 2001/04/23 11:22:19 uch Exp $
 #
 maxpartitions 8
 
@@ -6,6 +6,7 @@
 
 file   arch/hpcsh/hpcsh/conf.c
 file   arch/hpcsh/hpcsh/machdep.c
+file   arch/hpcsh/hpcsh/clock.c
 file   arch/hpcsh/hpcsh/console.c
 file   arch/hpcsh/hpcsh/autoconf.c
 file   arch/hpcsh/hpcsh/bus_space.c
diff -r 7f7a8d43082b -r 9d3d8af4095e sys/arch/hpcsh/hpcsh/autoconf.c
--- a/sys/arch/hpcsh/hpcsh/autoconf.c   Mon Apr 23 11:20:41 2001 +0000
+++ b/sys/arch/hpcsh/hpcsh/autoconf.c   Mon Apr 23 11:22:19 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: autoconf.c,v 1.3 2001/02/24 20:17:45 uch Exp $ */
+/*     $NetBSD: autoconf.c,v 1.4 2001/04/23 11:22:19 uch Exp $ */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -61,7 +61,6 @@
 #include <sys/reboot.h>
 #include <sys/device.h>
 
-#include <machine/cpu.h>
 #include <machine/bus.h>
 
 #include <machine/config_hook.h>
@@ -87,8 +86,6 @@
 
        config_hook_init();
 
-       startrtclock();
-
        if (config_rootfound("mainbus", "mainbus") == NULL)
                panic("no mainbus found");
 
diff -r 7f7a8d43082b -r 9d3d8af4095e sys/arch/hpcsh/hpcsh/clock.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/hpcsh/hpcsh/clock.c      Mon Apr 23 11:22:19 2001 +0000
@@ -0,0 +1,401 @@
+/*     $NetBSD: clock.c,v 1.1 2001/04/23 11:22:19 uch Exp $    */
+
+/*-
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+
+#include <dev/clock_subr.h>
+
+#include <sh3/rtcreg.h>
+#include <sh3/tmureg.h>
+
+#include <machine/shbvar.h>
+
+#include <hpcsh/hpcsh/clockvar.h>
+
+#ifndef HZ
+#define HZ             64
+#endif
+#define MINYEAR                2001    /* "today" */
+#define RTC_CLOCK      16384   /* Hz */
+
+/*
+ * hpcsh clock module
+ *  + default 64Hz
+ *  + use TMU channel 0 as clock interrupt source.
+ *  + TMU channel 0 input source is SH internal RTC output. (1.6384kHz)
+ */
+/* TMU */
+static int clockintr(void *);
+/* RTC */
+static void rtc_init(void);
+static int rtc_gettime(struct clock_ymdhms *);
+static int rtc_settime(struct clock_ymdhms *);
+
+static int __todr_inited;
+static int __cnt_delay;                /* calibrated loop variable (1 us) */
+static u_int32_t __cnt_clock;  /* clock interrupt interval count */
+static int __cpuclock;
+static int __pclock;
+
+/*
+ * [...]
+ * add    IF ID EX MA WB
+ * nop       IF ID EX MA WB
+ * cmp/pl       IF ID EX MA WB -  -
+ * nop             IF ID EX MA -  -  WB
+ * bt                 IF ID EX .  .  MA WB
+ * nop                   IF ID -  -  EX MA WB
+ * nop                      IF -  -  ID EX MA WB
+ * nop                      -  -  -  IF ID EX MA WB
+ * add                                  IF ID EX MA WB
+ * nop                                     IF ID EX MA WB
+ * cmp/pl                                     IF ID EX MA WB -  -
+ * nop                                           IF ID EX MA -  - WB
+ * bt                                               IF ID EX .  . MA
+ * [...]
+ */
+#define DELAY_LOOP(x)                                                  \
+       __asm__ __volatile__("                                          \
+               mov.l   r0, @-r15;                                      \
+               mov     %0, r0;                                         \
+               nop;nop;nop;nop;                                        \
+       1:      nop;                    /* 1 */                         \
+               nop;                    /* 2 */                         \
+               nop;                    /* 3 */                         \
+               add     #-1, r0;        /* 4 */                         \
+               nop;                    /* 5 */                         \
+               cmp/pl  r0;             /* 6 */                         \
+               nop;                    /* 7 */                         \
+               bt      1b;             /* 8, 9, 10 */                  \
+               mov.l   @r15+, r0;                                      \
+       " :: "r"(x))
+
+/*
+ * Estimate CPU and Peripheral clock.
+ */
+void
+clock_init()
+{
+#define TMU_START(x)                                                   \
+({                                                                     \
+       SHREG_TSTR &= ~TSTR_STR ## x;                                   \
+       SHREG_TCNT ## x = 0xffffffff;                                   \
+       SHREG_TSTR |= TSTR_STR ## x;                                    \
+})
+#define TMU_ELAPSED(x)                                                 \
+       (0xffffffff - SHREG_TCNT ## x)
+
+       u_int32_t t0, t1;
+
+       /* initialize TMU */
+       SHREG_TCR0 = 0;
+       SHREG_TCR1 = 0;
+       SHREG_TCR2 = 0;
+
+       /* stop all counter */
+       SHREG_TSTR = 0;
+       /* set TMU channel 0 source to RTC counter clock (16.384kHz) */
+       SHREG_TCR0 = TCR_TPSC_RTC;
+
+       /*
+        * estimate CPU clock.
+        */
+       TMU_START(0);
+       DELAY_LOOP(10000000);
+       t0 = TMU_ELAPSED(0);
+       __cpuclock = (100000000 / t0) * RTC_CLOCK;
+       __cnt_delay = (RTC_CLOCK * 10) / t0;
+
+       /*
+        * estimate PCLOCK
+        */
+       /* set TMU channel 1 source to PCLOCK / 4 */
+       SHREG_TCR1 = TCR_TPSC_P4;
+       TMU_START(0);
+       TMU_START(1);
+       delay(1000000);
+       t0 = TMU_ELAPSED(0);
+       t1 = TMU_ELAPSED(1);
+
+       __pclock = (t1 / t0) * RTC_CLOCK * 4;
+
+       /* stop all counter */
+       SHREG_TSTR = 0;
+
+       /* Initialize RTC */
+       rtc_init();
+#undef TMU_START
+#undef TMU_ELAPSED
+}
+
+int
+clock_get_cpuclock()
+{
+       return __cpuclock;
+}
+
+int
+clock_get_pclock()
+{
+       return __pclock;
+}
+
+/*
+ * Return the best possible estimate of the time in the timeval to
+ * which tv points.
+ */
+void
+microtime(struct timeval *tv)
+{
+       static struct timeval lasttime;
+
+       int s = splclock();
+       *tv = time;
+       splx(s);
+
+       tv->tv_usec += ((__cnt_clock - SHREG_TCNT0) * 1000000) / RTC_CLOCK;
+       while (tv->tv_usec >= 1000000) {
+               tv->tv_usec -= 1000000;
+               tv->tv_sec++;
+       }
+
+       if (tv->tv_sec == lasttime.tv_sec &&
+           tv->tv_usec <= lasttime.tv_usec &&
+           (tv->tv_usec = lasttime.tv_usec + 1) >= 1000000) {
+               tv->tv_usec -= 1000000;
+               tv->tv_sec++;
+       }
+       lasttime = *tv;
+}
+
+/*
+ *  Wait at least `n' usec.
+ */
+void
+delay(int n)
+{
+       DELAY_LOOP(__cnt_delay * n);
+}
+
+/*
+ * Start the clock interrupt.
+ */
+void
+cpu_initclocks()
+{
+       /* set global variables. */
+       hz = HZ;
+       tick = 1000000 / hz;
+
+       /* use TMU channel 0 as clock source. */
+       SHREG_TSTR &= ~TSTR_STR1;
+       SHREG_TCR1 = TCR_UNIE | TCR_TPSC_RTC;
+       __cnt_clock = RTC_CLOCK / hz - 1;
+       SHREG_TCOR1 = __cnt_clock;
+       SHREG_TCNT1 = __cnt_clock;
+       SHREG_TSTR |= TSTR_STR1;



Home | Main Index | Thread Index | Old Index