clock.c revision 1.2
1/*	$OpenBSD: clock.c,v 1.2 1999/02/07 20:24:51 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	extern u_int cpu_hzticks;
66	u_int time_inval;
67#ifdef USELEDS
68	static u_int hbcnt = 0;
69
70	if (!(hbcnt % 50)) {
71		register u_int r = (hbcnt / 50) % 6;
72
73		heartbeat(r < 4 && !(r % 2));
74	}
75#endif
76	/* Start the interval timer. */
77	mfctl(CR_ITMR, time_inval);
78	mtctl(time_inval + cpu_hzticks, CR_ITMR);
79}
80
81
82/*
83 * initialize the system time from the time of day clock
84 */
85void
86inittodr(t)
87	time_t t;
88{
89	static struct pdc_tod tod;
90
91	pdc_call((iodcio_t)PAGE0->mem_pdc, 1, PDC_TOD, PDC_TOD_READ,
92		&tod, 0, 0, 0, 0, 0);
93
94	time = *(struct timeval *)&tod;
95
96	if ((long)time.tv_sec < 0) {
97		time.tv_sec = SECYR * (1990 - 1970);
98		printf("WARNING: clock not initialized -- check and reset\n");
99	}
100}
101
102/*
103 * reset the time of day clock to the value in time
104 */
105void
106resettodr()
107{
108	static struct pdc_tod tod;
109
110	tod.sec = time.tv_sec;
111	tod.usec = time.tv_usec;
112
113	pdc_call((iodcio_t)PAGE0->mem_pdc, 1, PDC_TOD, PDC_TOD_WRITE, &tod);
114}
115
116void
117setstatclockrate(newhz)
118	int newhz;
119{
120	/* nothing we can do */
121}
122
123