clock.c revision 1.1
1/*	$OpenBSD: clock.c,v 1.1 1998/12/29 21:35:42 mickey Exp $	*/
2
3/*
4 * Copyright (c) 1998 Michael Shalayeff
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *	This product includes software developed by Michael Shalayeff.
18 * 4. The name of the author may not be used to endorse or promote products
19 *    derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/kernel.h>
36#include <sys/time.h>
37
38#include <dev/clock_subr.h>
39
40#include <machine/pdc.h>
41#include <machine/iomod.h>
42#include <machine/psl.h>
43#include <machine/intr.h>
44#include <machine/reg.h>
45#include <machine/cpufunc.h>
46#include <machine/autoconf.h>
47
48struct timeval time;
49
50void startrtclock __P((void));
51
52/*
53 * Return the best possible estimate of the current time.
54 */
55void
56microtime(tvp)
57	struct timeval *tvp;
58{
59
60}
61
62void
63cpu_initclocks()
64{
65	u_int time_inval;
66#ifdef USELEDS
67	static u_int hbcnt = 0;
68
69	if (!(hbcnt % 50)) {
70		register u_int r = (hbcnt / 50) % 6;
71
72		heartbeat(r < 4 && !(r % 2));
73	}
74#endif
75	/* Start the interval timer. */
76	mfctl(CR_ITMR, time_inval);
77	mtctl(time_inval + cpu_hzticks, CR_ITMR);
78}
79
80
81/*
82 * initialize the system time from the time of day clock
83 */
84void
85inittodr(t)
86	time_t t;
87{
88	static struct pdc_tod tod;
89
90	pdc_call((iodcio_t)PAGE0->mem_pdc, 1, PDC_TOD, PDC_TOD_READ,
91		&tod, 0, 0, 0, 0, 0);
92
93	time = *(struct timeval *)&tod;
94
95	if ((long)time.tv_sec < 0) {
96		time.tv_sec = SECYR * (1990 - 1970);
97		printf("WARNING: clock not initialized -- check and reset\n");
98	}
99}
100
101/*
102 * reset the time of day clock to the value in time
103 */
104void
105resettodr()
106{
107	static struct pdc_tod tod;
108
109	tod.sec = time.tv_sec;
110	tod.usec = time.tv_usec;
111
112	pdc_call((iodcio_t)PAGE0->mem_pdc, 1, PDC_TOD, PDC_TOD_WRITE, &tod);
113}
114
115void
116setstatclockrate(newhz)
117	int newhz;
118{
119	/* nothing we can do */
120}
121
122