Annotation of coherent/b/STREAMS/coh.386/clocked.c, revision 1.1

1.1     ! root        1: /* $Header: /src386/STREAMS/coh.386/RCS/clocked.c,v 2.2 93/08/09 13:35:17 bin Exp Locker: bin $ */
        !             2: /*
        !             3:  * clocked.c - support routines for alternate clock rate
        !             4:  *
        !             5:  *  altclk_in(hz, fn) - install routine with specified rate
        !             6:  *                      "hz" should be a multiple of system rate of 100 Hz
        !             7:  *                     return 0 if completed ok, -1 otherwise
        !             8:  *
        !             9:  *  altclk_out()      - uninstall alternate clock routine and restore system rate
        !            10:  *                     return old value of "altclk"
        !            11:  *
        !            12:  *  altclk_rate(hz)   - set clock interrupt rate
        !            13:  *                     new rate must be an even multiple of system rate "HZ"
        !            14:  *                     return 0 if completed ok, -1 otherwise
        !            15:  *
        !            16:  *  History:
        !            17:  *    90/08/08 hws     initial version, works with hs.c modified for com[1-4]
        !            18:  *    90/08/14 hws     make it more like a Unix system call
        !            19:  *
        !            20:  * $Log:       clocked.c,v $
        !            21:  * Revision 2.2  93/08/09  13:35:17  bin
        !            22:  * Kernel 82 changes
        !            23:  * 
        !            24:  * Revision 2.2  93/07/26  15:22:04  nigel
        !            25:  * Nigel's R80
        !            26:  * 
        !            27:  */
        !            28: 
        !            29: #include       <sys/coherent.h>                /* altclk */
        !            30: 
        !            31: #ifdef _I386
        !            32: #include       <kernel/param.h>                /* HZ */
        !            33: #else
        !            34: #include       <kernel/const.h>                /* HZ */
        !            35: #endif
        !            36: 
        !            37: #define        PIT     0x40            /* 8253 port */
        !            38: #define        TMR0_M3 0x36            /* timer 0, mode 3 */
        !            39: #define        SYS_HZ  1193200L        /* rate of input clock to timer 0 */
        !            40: 
        !            41: typedef int (*PFI)();          /* pointer to function returning int */
        !            42: 
        !            43: altclk_rate(hz)
        !            44: unsigned int hz;
        !            45: {
        !            46:        int s;                  /* to save CPU irpt flag */
        !            47:        unsigned int interval;  /* period for hz, in units of 1.19 MHz ticks */
        !            48:        int ret;
        !            49: 
        !            50:        if (hz >= HZ && hz % HZ == 0) {         /* can't go slower than HZ! */
        !            51:                interval = SYS_HZ/hz;
        !            52:                s = sphi();                     /* disable irpts */
        !            53:                outb(PIT+3, TMR0_M3);
        !            54:                outb(PIT, interval & 0xff);
        !            55:                outb(PIT, interval >> 8);       /* unsigned shift */
        !            56:                spl(s);                         /* restore previous irpt state */
        !            57:                ret = 0;
        !            58:        } else {
        !            59:                ret = -1;
        !            60:        }
        !            61:        return ret;
        !            62: }
        !            63: 
        !            64: int altclk_in(hz, fn)
        !            65: int hz;
        !            66: PFI fn;
        !            67: {
        !            68:        int ret;
        !            69: 
        !            70:        if ((ret = altclk_rate(hz)) == 0)
        !            71:                altclk = fn;
        !            72:        return ret;
        !            73: }
        !            74: 
        !            75: PFI altclk_out()
        !            76: {
        !            77:        PFI ret;
        !            78: 
        !            79:        ret = altclk;
        !            80:        if (ret) {
        !            81:                altclk_rate(HZ);
        !            82:                altclk = 0;
        !            83:        }
        !            84:        return ret;
        !            85: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.