|
|
1.1 root 1: /* clockedf.c - support routines for alternate clock rate
2: - this is the FAR version of clocked.c for loadable drivers
3:
4: altclk_in(hz, fn) - install routine with specified rate
5: "hz" should be a multiple of system rate of 100 Hz
6:
7: altclk_out() - uninstall alternate clock routine and restore system rate
8: return old value of "altclk"
9:
10: altclk_rate(hz) - set clock interrupt rate
11: new rate must be an even multiple of system rate "HZ"
12: return 0 if completed ok, -1 otherwise
13:
14: History:
15: 90/08/08 hws initial version, works with hs.c modified for com[1-4]
16: 90/08/14 hws make it more like a Unix system call
17: 90/09/12 hws add far version
18: */
19:
20: #include <sys/coherent.h> /* altclk */
21: #include <sys/const.h> /* HZ */
22:
23: #define PIT 0x40 /* 8253 port */
24: #define TMR0_M3 0x36 /* timer 0, mode 3 */
25: #if 0
26: /* nominal IBM rate is 1.1900 MHz */
27: #define SYS_HZ 1190000L /* rate of input clock to timer 0 */
28: #else
29: /* current kernel rate is 1.1932 MHz */
30: #define SYS_HZ 1193200L /* rate of input clock to timer 0 */
31: #endif
32:
33: typedef int (*PFI)(); /* pointer to function returning int */
34:
35: extern saddr_t ucs;
36:
37: static int altclk_rate(hz)
38: unsigned int hz;
39: {
40: int s; /* to save CPU irpt flag */
41: unsigned int interval; /* period for hz, in units of 1.19 MHz ticks */
42: int ret;
43:
44: if (hz >= HZ && hz % HZ == 0) { /* can't go slower than HZ! */
45: interval = SYS_HZ/hz;
46: s = sphi(); /* disable irpts */
47: outb(PIT+3, TMR0_M3);
48: outb(PIT, interval & 0xff);
49: outb(PIT, interval >> 8); /* unsigned shift */
50: spl(s); /* restore previous irpt state */
51: ret = 0;
52: }
53: else {
54: ret = -1;
55: }
56: return ret;
57: }
58:
59: int altclk_in(hz, fn)
60: int hz;
61: PFI fn;
62: {
63: int ret;
64: int s;
65:
66: if ((ret = altclk_rate(hz)) == 0) {
67: s = sphi();
68: altclk = fn;
69: altsel = cs_sel();
70: spl(s);
71: }
72: return ret;
73: }
74:
75: PFI altclk_out()
76: {
77: PFI ret;
78: int s;
79:
80: ret = altclk;
81: if (ret) {
82: altclk_rate(HZ);
83: s = sphi();
84: altclk = 0;
85: altsel = 0;
86: spl(s);
87: }
88: return ret;
89: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.