Annotation of 43BSDReno/sys/hpdev/hpib.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1982, 1990 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution is only permitted until one year after the first shipment
                      6:  * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
                      7:  * binary forms are permitted provided that: (1) source distributions retain
                      8:  * this entire copyright notice and comment, and (2) distributions including
                      9:  * binaries display the following acknowledgement:  This product includes
                     10:  * software developed by the University of California, Berkeley and its
                     11:  * contributors'' in the documentation or other materials provided with the
                     12:  * distribution and in all advertising materials mentioning features or use
                     13:  * of this software.  Neither the name of the University nor the names of
                     14:  * its contributors may be used to endorse or promote products derived from
                     15:  * this software without specific prior written permission.
                     16:  * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
                     17:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
                     18:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     19:  *
                     20:  *     @(#)hpib.c      7.1 (Berkeley) 5/8/90
                     21:  */
                     22: 
                     23: /*
                     24:  * HPIB driver
                     25:  */
                     26: #include "hpib.h"
                     27: #if NHPIB > 0
                     28: 
                     29: #include "param.h"
                     30: #include "systm.h"
                     31: #include "buf.h"
                     32: #include "device.h"
                     33: #include "hpibvar.h"
                     34: #include "dmavar.h"
                     35: 
                     36: #include "machine/cpu.h"
                     37: #include "machine/isr.h"
                     38: 
                     39: int    internalhpib = IOV(0x478000);
                     40: 
                     41: int    hpibinit(), hpibstart(), hpibgo(), hpibintr(), hpibdone();
                     42: struct driver hpibdriver = {
                     43:        hpibinit, "hpib", hpibstart, hpibgo, hpibintr, hpibdone,
                     44: };
                     45: 
                     46: struct hpib_softc hpib_softc[NHPIB];
                     47: struct isr hpib_isr[NHPIB];
                     48: int    nhpibppoll(), fhpibppoll();
                     49: 
                     50: int    hpibtimeout = 100000;   /* # of status tests before we give up */
                     51: int    hpibidtimeout = 20000;  /* # of status tests for hpibid() calls */
                     52: 
                     53: hpibinit(hc)
                     54:        register struct hp_ctlr *hc;
                     55: {
                     56:        register struct hpib_softc *hs = &hpib_softc[hc->hp_unit];
                     57:        
                     58:        if (!nhpibtype(hc) && !fhpibtype(hc))
                     59:                return(0);
                     60:        hs->sc_hc = hc;
                     61:        hs->sc_dq.dq_unit = hc->hp_unit;
                     62:        hs->sc_dq.dq_driver = &hpibdriver;
                     63:        hs->sc_sq.dq_forw = hs->sc_sq.dq_back = &hs->sc_sq;
                     64:        hpib_isr[hc->hp_unit].isr_intr = hpibintr;
                     65:        hpib_isr[hc->hp_unit].isr_ipl = hc->hp_ipl;
                     66:        hpib_isr[hc->hp_unit].isr_arg = hc->hp_unit;
                     67:        isrlink(&hpib_isr[hc->hp_unit]);
                     68:        hpibreset(hc->hp_unit);
                     69:        return(1);
                     70: }
                     71: 
                     72: hpibreset(unit)
                     73:        register int unit;
                     74: {
                     75:        if (hpib_softc[unit].sc_type == HPIBC)
                     76:                fhpibreset(unit);
                     77:        else
                     78:                nhpibreset(unit);
                     79: }
                     80: 
                     81: hpibreq(dq)
                     82:        register struct devqueue *dq;
                     83: {
                     84:        register struct devqueue *hq;
                     85: 
                     86:        hq = &hpib_softc[dq->dq_ctlr].sc_sq;
                     87:        insque(dq, hq->dq_back);
                     88:        if (dq->dq_back == hq)
                     89:                return(1);
                     90:        return(0);
                     91: }
                     92: 
                     93: hpibfree(dq)
                     94:        register struct devqueue *dq;
                     95: {
                     96:        register struct devqueue *hq;
                     97: 
                     98:        hq = &hpib_softc[dq->dq_ctlr].sc_sq;
                     99:        remque(dq);
                    100:        if ((dq = hq->dq_forw) != hq)
                    101:                (dq->dq_driver->d_start)(dq->dq_unit);
                    102: }
                    103: 
                    104: hpibid(unit, slave)
                    105: {
                    106:        short id;
                    107:        int ohpibtimeout;
                    108: 
                    109:        /*
                    110:         * XXX: shorten timeout value (so autoconfig doesn't take forever)
                    111:         */
                    112:        ohpibtimeout = hpibtimeout;
                    113:        hpibtimeout = hpibidtimeout;
                    114:        if (hpibrecv(unit, 31, slave, &id, 2) != 2)
                    115:                id = 0;
                    116:        hpibtimeout = ohpibtimeout;
                    117:        return(id);
                    118: }
                    119: 
                    120: hpibsend(unit, slave, sec, addr, cnt)
                    121:        register int unit;
                    122: {
                    123:        if (hpib_softc[unit].sc_type == HPIBC)
                    124:                return(fhpibsend(unit, slave, sec, addr, cnt));
                    125:        else
                    126:                return(nhpibsend(unit, slave, sec, addr, cnt));
                    127: }
                    128: 
                    129: hpibrecv(unit, slave, sec, addr, cnt)
                    130:        register int unit;
                    131: {
                    132:        if (hpib_softc[unit].sc_type == HPIBC)
                    133:                return(fhpibrecv(unit, slave, sec, addr, cnt));
                    134:        else
                    135:                return(nhpibrecv(unit, slave, sec, addr, cnt));
                    136: }
                    137: 
                    138: hpibpptest(unit, slave)
                    139:        register int unit;
                    140: {
                    141:        int (*ppoll)();
                    142: 
                    143:        ppoll = (hpib_softc[unit].sc_type == HPIBC) ? fhpibppoll : nhpibppoll;
                    144:        return((*ppoll)(unit) & (0x80 >> slave));
                    145: }
                    146: 
                    147: hpibawait(unit)
                    148: {
                    149:        register struct hpib_softc *hs = &hpib_softc[unit];
                    150: 
                    151:        hs->sc_flags |= HPIBF_PPOLL;
                    152:        if (hs->sc_type == HPIBC)
                    153:                fhpibppwatch(unit);
                    154:        else
                    155:                nhpibppwatch(unit);
                    156: }
                    157: 
                    158: hpibswait(unit, slave)
                    159:        register int unit;
                    160: {
                    161:        register int timo = hpibtimeout;
                    162:        register int mask, (*ppoll)();
                    163: 
                    164:        ppoll = (hpib_softc[unit].sc_type == HPIBC) ? fhpibppoll : nhpibppoll;
                    165:        mask = 0x80 >> slave;
                    166:        while (((ppoll)(unit) & mask) == 0)
                    167:                if (--timo == 0) {
                    168:                        printf("hpib%d: swait timeout\n", unit);
                    169:                        return(-1);
                    170:                }
                    171:        return(0);
                    172: }
                    173: 
                    174: hpibustart(unit)
                    175: {
                    176:        register struct hpib_softc *hs = &hpib_softc[unit];
                    177: 
                    178:        if (hs->sc_type == HPIBA)
                    179:                hs->sc_dq.dq_ctlr = DMA0;
                    180:        else
                    181:                hs->sc_dq.dq_ctlr = DMA0 | DMA1;
                    182:        if (dmareq(&hs->sc_dq))
                    183:                return(1);
                    184:        return(0);
                    185: }
                    186: 
                    187: hpibstart(unit)
                    188: {
                    189:        register struct devqueue *dq;
                    190:        
                    191:        dq = hpib_softc[unit].sc_sq.dq_forw;
                    192:        (dq->dq_driver->d_go)(dq->dq_unit);
                    193: }
                    194: 
                    195: hpibgo(unit, slave, sec, addr, count, rw)
                    196:        register int unit;
                    197: {
                    198:        if (hpib_softc[unit].sc_type == HPIBC)
                    199:                fhpibgo(unit, slave, sec, addr, count, rw);
                    200:        else
                    201:                nhpibgo(unit, slave, sec, addr, count, rw);
                    202: }
                    203: 
                    204: hpibdone(unit)
                    205:        register int unit;
                    206: {
                    207:        if (hpib_softc[unit].sc_type == HPIBC)
                    208:                fhpibdone(unit);
                    209:        else
                    210:                nhpibdone(unit);
                    211: }
                    212: 
                    213: hpibintr(unit)
                    214:        register int unit;
                    215: {
                    216:        int found;
                    217: 
                    218:        if (hpib_softc[unit].sc_type == HPIBC)
                    219:                found = fhpibintr(unit);
                    220:        else
                    221:                found = nhpibintr(unit);
                    222:        return(found);
                    223: }
                    224: #endif

unix.superglobalmegacorp.com

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