clock.c (700) | clock.c (798) |
---|---|
1/*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * William Jolitz and Don Ahn. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 20 unchanged lines hidden (view full) --- 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * from: @(#)clock.c 7.2 (Berkeley) 5/12/91 | 1/*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * William Jolitz and Don Ahn. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 20 unchanged lines hidden (view full) --- 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * from: @(#)clock.c 7.2 (Berkeley) 5/12/91 |
37 * $Id: clock.c,v 1.2 1993/10/16 13:45:44 rgrimes Exp $ | 37 * $Id: clock.c,v 1.3 1993/11/04 01:56:31 ache Exp $ |
38 */ 39 40/* 41 * Primitive clock interrupt routines. 42 */ 43#include "param.h" 44#include "systm.h" 45#include "time.h" --- 5 unchanged lines hidden (view full) --- 51#include "i386/isa/timerreg.h" 52 53/* X-tals being what they are, it's nice to be able to fudge this one... */ 54/* Note, the name changed here from XTALSPEED to TIMER_FREQ rgrimes 4/26/93 */ 55#ifndef TIMER_FREQ 56#define TIMER_FREQ 1193182 /* XXX - should be in isa.h */ 57#endif 58 | 38 */ 39 40/* 41 * Primitive clock interrupt routines. 42 */ 43#include "param.h" 44#include "systm.h" 45#include "time.h" --- 5 unchanged lines hidden (view full) --- 51#include "i386/isa/timerreg.h" 52 53/* X-tals being what they are, it's nice to be able to fudge this one... */ 54/* Note, the name changed here from XTALSPEED to TIMER_FREQ rgrimes 4/26/93 */ 55#ifndef TIMER_FREQ 56#define TIMER_FREQ 1193182 /* XXX - should be in isa.h */ 57#endif 58 |
59startrtclock() { | 59static void findcpuspeed(void); 60 61void 62startrtclock() 63{ |
60 int s; 61 62 findcpuspeed(); /* use the clock (while it's free) 63 to find the cpu speed */ 64 /* initialize 8253 clock */ 65 outb(TIMER_MODE, TIMER_SEL0|TIMER_RATEGEN|TIMER_16BIT); 66 67 /* Correct rounding will buy us a better precision in timekeeping */ --- 11 unchanged lines hidden (view full) --- 79 printf("RTC BIOS diagnostic error %b\n", s, RTCDG_BITS); 80 outb (IO_RTC, RTC_DIAG); 81 outb (IO_RTC+1, 0); 82} 83 84unsigned int delaycount; /* calibrated loop variable (1 millisecond) */ 85 86#define FIRST_GUESS 0x2000 | 64 int s; 65 66 findcpuspeed(); /* use the clock (while it's free) 67 to find the cpu speed */ 68 /* initialize 8253 clock */ 69 outb(TIMER_MODE, TIMER_SEL0|TIMER_RATEGEN|TIMER_16BIT); 70 71 /* Correct rounding will buy us a better precision in timekeeping */ --- 11 unchanged lines hidden (view full) --- 83 printf("RTC BIOS diagnostic error %b\n", s, RTCDG_BITS); 84 outb (IO_RTC, RTC_DIAG); 85 outb (IO_RTC+1, 0); 86} 87 88unsigned int delaycount; /* calibrated loop variable (1 millisecond) */ 89 90#define FIRST_GUESS 0x2000 |
91static void |
|
87findcpuspeed() 88{ 89 unsigned char low; 90 unsigned int remainder; 91 92 /* Put counter in count down mode */ 93 outb(IO_TIMER1+3, 0x34); 94 outb(IO_TIMER1, 0xff); --- 7 unchanged lines hidden (view full) --- 102 /* Formula for delaycount is : 103 * (loopcount * timer clock speed)/ (counter ticks * 1000) 104 */ 105 delaycount = (FIRST_GUESS * (TIMER_FREQ/1000)) / (0xffff-remainder); 106} 107 108 109/* convert 2 digit BCD number */ | 92findcpuspeed() 93{ 94 unsigned char low; 95 unsigned int remainder; 96 97 /* Put counter in count down mode */ 98 outb(IO_TIMER1+3, 0x34); 99 outb(IO_TIMER1, 0xff); --- 7 unchanged lines hidden (view full) --- 107 /* Formula for delaycount is : 108 * (loopcount * timer clock speed)/ (counter ticks * 1000) 109 */ 110 delaycount = (FIRST_GUESS * (TIMER_FREQ/1000)) / (0xffff-remainder); 111} 112 113 114/* convert 2 digit BCD number */ |
115int |
|
110bcd(i) | 116bcd(i) |
111int i; | 117 int i; |
112{ 113 return ((i/16)*10 + (i%16)); 114} 115 116/* convert years to seconds (from 1970) */ 117unsigned long 118ytos(y) 119int y; --- 32 unchanged lines hidden (view full) --- 152 return ret; 153} 154 155 156/* 157 * Initialize the time of day register, based on the time base which is, e.g. 158 * from a filesystem. 159 */ | 118{ 119 return ((i/16)*10 + (i%16)); 120} 121 122/* convert years to seconds (from 1970) */ 123unsigned long 124ytos(y) 125int y; --- 32 unchanged lines hidden (view full) --- 158 return ret; 159} 160 161 162/* 163 * Initialize the time of day register, based on the time base which is, e.g. 164 * from a filesystem. 165 */ |
166void |
|
160inittodr(base) 161 time_t base; 162{ 163 unsigned long sec; 164 int leap,day_week,t,yd; 165 int sa,s; 166 167 /* do we have a realtime clock present? (otherwise we loop below) */ --- 44 unchanged lines hidden (view full) --- 212 213 time.tv_sec = base; 214} 215#endif 216 217/* 218 * Restart the clock. 219 */ | 167inittodr(base) 168 time_t base; 169{ 170 unsigned long sec; 171 int leap,day_week,t,yd; 172 int sa,s; 173 174 /* do we have a realtime clock present? (otherwise we loop below) */ --- 44 unchanged lines hidden (view full) --- 219 220 time.tv_sec = base; 221} 222#endif 223 224/* 225 * Restart the clock. 226 */ |
227void |
|
220resettodr() 221{ 222} 223 224/* 225 * Wire clock interrupt in. 226 */ 227#define V(s) __CONCAT(V, s) 228extern V(clk)(); | 228resettodr() 229{ 230} 231 232/* 233 * Wire clock interrupt in. 234 */ 235#define V(s) __CONCAT(V, s) 236extern V(clk)(); |
229enablertclock() { | 237 238void 239enablertclock() 240{ |
230 setidt(ICU_OFFSET+0, &V(clk), SDT_SYS386IGT, SEL_KPL); 231 INTREN(IRQ0); 232} 233 234/* 235 * Delay for some number of milliseconds. 236 */ 237void 238spinwait(millisecs) 239 int millisecs; 240{ 241 DELAY(1000 * millisecs); 242} | 241 setidt(ICU_OFFSET+0, &V(clk), SDT_SYS386IGT, SEL_KPL); 242 INTREN(IRQ0); 243} 244 245/* 246 * Delay for some number of milliseconds. 247 */ 248void 249spinwait(millisecs) 250 int millisecs; 251{ 252 DELAY(1000 * millisecs); 253} |