|
|
coherent
/* clockedf.c - support routines for alternate clock rate
- this is the FAR version of clocked.c for loadable drivers
altclk_in(hz, fn) - install routine with specified rate
"hz" should be a multiple of system rate of 100 Hz
altclk_out() - uninstall alternate clock routine and restore system rate
return old value of "altclk"
altclk_rate(hz) - set clock interrupt rate
new rate must be an even multiple of system rate "HZ"
return 0 if completed ok, -1 otherwise
History:
90/08/08 hws initial version, works with hs.c modified for com[1-4]
90/08/14 hws make it more like a Unix system call
90/09/12 hws add far version
*/
#include <sys/coherent.h> /* altclk */
#include <sys/const.h> /* HZ */
#define PIT 0x40 /* 8253 port */
#define TMR0_M3 0x36 /* timer 0, mode 3 */
#if 0
/* nominal IBM rate is 1.1900 MHz */
#define SYS_HZ 1190000L /* rate of input clock to timer 0 */
#else
/* current kernel rate is 1.1932 MHz */
#define SYS_HZ 1193200L /* rate of input clock to timer 0 */
#endif
typedef int (*PFI)(); /* pointer to function returning int */
extern saddr_t ucs;
static int altclk_rate(hz)
unsigned int hz;
{
int s; /* to save CPU irpt flag */
unsigned int interval; /* period for hz, in units of 1.19 MHz ticks */
int ret;
if (hz >= HZ && hz % HZ == 0) { /* can't go slower than HZ! */
interval = SYS_HZ/hz;
s = sphi(); /* disable irpts */
outb(PIT+3, TMR0_M3);
outb(PIT, interval & 0xff);
outb(PIT, interval >> 8); /* unsigned shift */
spl(s); /* restore previous irpt state */
ret = 0;
}
else {
ret = -1;
}
return ret;
}
int altclk_in(hz, fn)
int hz;
PFI fn;
{
int ret;
int s;
if ((ret = altclk_rate(hz)) == 0) {
s = sphi();
altclk = fn;
altsel = cs_sel();
spl(s);
}
return ret;
}
PFI altclk_out()
{
PFI ret;
int s;
ret = altclk;
if (ret) {
altclk_rate(HZ);
s = sphi();
altclk = 0;
altsel = 0;
spl(s);
}
return ret;
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.