Annotation of 43BSDReno/sys/hpdev/nhpib.c, revision 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:  *     @(#)nhpib.c     7.1 (Berkeley) 5/8/90
        !            21:  */
        !            22: 
        !            23: /*
        !            24:  * Internal/98624 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 "nhpibreg.h"
        !            34: #include "hpibvar.h"
        !            35: #include "dmavar.h"
        !            36: 
        !            37: nhpibtype(hc)
        !            38:        register struct hp_ctlr *hc;
        !            39: {
        !            40:        register struct hpib_softc *hs = &hpib_softc[hc->hp_unit];
        !            41:        register struct nhpibdevice *hd = (struct nhpibdevice *)hc->hp_addr;
        !            42: 
        !            43:        if ((int)hc->hp_addr == internalhpib) {
        !            44:                hs->sc_type = HPIBA;
        !            45:                hs->sc_ba = HPIBA_BA;
        !            46:                hc->hp_ipl = HPIBA_IPL;
        !            47:        }
        !            48:        else if (hd->hpib_cid == HPIBB) {
        !            49:                hs->sc_type = HPIBB;
        !            50:                hs->sc_ba = hd->hpib_csa & CSA_BA;
        !            51:                hc->hp_ipl = HPIB_IPL(hd->hpib_ids);
        !            52:        }
        !            53:        else
        !            54:                return(0);
        !            55:        return(1);
        !            56: }
        !            57: 
        !            58: nhpibreset(unit)
        !            59: {
        !            60:        register struct hpib_softc *hs = &hpib_softc[unit];
        !            61:        register struct nhpibdevice *hd;
        !            62: 
        !            63:        hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
        !            64:        hd->hpib_acr = AUX_SSWRST;
        !            65:        hd->hpib_ar = hs->sc_ba;
        !            66:        hd->hpib_lim = LIS_ERR;
        !            67:        hd->hpib_mim = 0;
        !            68:        hd->hpib_acr = AUX_CDAI;
        !            69:        hd->hpib_acr = AUX_CSHDW;
        !            70:        hd->hpib_acr = AUX_SSTD1;
        !            71:        hd->hpib_acr = AUX_SVSTD1;
        !            72:        hd->hpib_acr = AUX_CPP;
        !            73:        hd->hpib_acr = AUX_CHDFA;
        !            74:        hd->hpib_acr = AUX_CHDFE;
        !            75:        hd->hpib_acr = AUX_RHDF;
        !            76:        hd->hpib_acr = AUX_CSWRST;
        !            77:        nhpibifc(hd);
        !            78:        hd->hpib_ie = IDS_IE;
        !            79:        hd->hpib_data = C_DCL;
        !            80:        DELAY(100000);
        !            81: }
        !            82: 
        !            83: nhpibifc(hd)
        !            84:        register struct nhpibdevice *hd;
        !            85: {
        !            86:        hd->hpib_acr = AUX_TCA;
        !            87:        hd->hpib_acr = AUX_CSRE;
        !            88:        hd->hpib_acr = AUX_SSIC;
        !            89:        DELAY(100);
        !            90:        hd->hpib_acr = AUX_CSIC;
        !            91:        hd->hpib_acr = AUX_SSRE;
        !            92: }
        !            93: 
        !            94: nhpibsend(unit, slave, sec, addr, cnt)
        !            95:        register char *addr;
        !            96:        register int cnt;
        !            97: {
        !            98:        register struct hpib_softc *hs = &hpib_softc[unit];
        !            99:        register struct nhpibdevice *hd;
        !           100:        register int origcnt = cnt;
        !           101: 
        !           102:        hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
        !           103:        hd->hpib_acr = AUX_TCA;
        !           104:        hd->hpib_data = C_UNL;
        !           105:        nhpibowait(hd);
        !           106:        hd->hpib_data = C_TAG + hs->sc_ba;
        !           107:        hd->hpib_acr = AUX_STON;
        !           108:        nhpibowait(hd);
        !           109:        hd->hpib_data = C_LAG + slave;
        !           110:        nhpibowait(hd);
        !           111:        if (sec != -1) {
        !           112:                hd->hpib_data = C_SCG + sec;
        !           113:                nhpibowait(hd);
        !           114:        }
        !           115:        hd->hpib_acr = AUX_GTS;
        !           116:        if (cnt) {
        !           117:                while (--cnt) {
        !           118:                        hd->hpib_data = *addr++;
        !           119:                        if (nhpibowait(hd) < 0) {
        !           120:                                nhpibifc(hd);
        !           121:                                cnt++;
        !           122:                                goto out;
        !           123:                        }
        !           124:                }
        !           125:                hd->hpib_acr = AUX_EOI;
        !           126:                hd->hpib_data = *addr;
        !           127:                if (nhpibowait(hd) < 0) {
        !           128:                        nhpibifc(hd);
        !           129:                        cnt++;
        !           130:                }
        !           131:                else
        !           132:                        hd->hpib_acr = AUX_TCA;
        !           133:        }
        !           134: out:
        !           135:        return(origcnt - cnt);
        !           136: }
        !           137: 
        !           138: nhpibrecv(unit, slave, sec, addr, cnt)
        !           139:        register char *addr;
        !           140:        register int cnt;
        !           141: {
        !           142:        register struct hpib_softc *hs = &hpib_softc[unit];
        !           143:        register struct nhpibdevice *hd;
        !           144:        register int origcnt = cnt;
        !           145: 
        !           146:        hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
        !           147:        hd->hpib_acr = AUX_TCA;
        !           148:        hd->hpib_data = C_UNL;
        !           149:        nhpibowait(hd);
        !           150:        hd->hpib_data = C_LAG + hs->sc_ba;
        !           151:        hd->hpib_acr = AUX_SLON;
        !           152:        nhpibowait(hd);
        !           153:        hd->hpib_data = C_TAG + slave;
        !           154:        nhpibowait(hd);
        !           155:        if (sec != -1) {
        !           156:                hd->hpib_data = C_SCG + sec;
        !           157:                nhpibowait(hd);
        !           158:        }
        !           159:        hd->hpib_acr = AUX_RHDF;
        !           160:        hd->hpib_acr = AUX_GTS;
        !           161:        if (cnt) {
        !           162:                while (--cnt >= 0) {
        !           163:                        if (nhpibiwait(hd) < 0) {
        !           164:                                nhpibifc(hd);
        !           165:                                break;
        !           166:                        }
        !           167:                        *addr++ = hd->hpib_data;
        !           168:                }
        !           169:                cnt++;
        !           170:                hd->hpib_acr = AUX_TCA;
        !           171:        }
        !           172:        return(origcnt - cnt);
        !           173: }
        !           174: 
        !           175: nhpibgo(unit, slave, sec, addr, count, rw)
        !           176:        register int unit, slave;
        !           177:        char *addr;
        !           178: {
        !           179:        register struct hpib_softc *hs = &hpib_softc[unit];
        !           180:        register struct nhpibdevice *hd;
        !           181: 
        !           182:        hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
        !           183:        hs->sc_flags |= HPIBF_IO;
        !           184:        if (rw == B_READ)
        !           185:                hs->sc_flags |= HPIBF_READ;
        !           186: #ifdef DEBUG
        !           187:        else if (hs->sc_flags & HPIBF_READ) {
        !           188:                printf("nhpibgo: HPIBF_READ still set\n");
        !           189:                hs->sc_flags &= ~HPIBF_READ;
        !           190:        }
        !           191: #endif
        !           192:        hs->sc_count = count;
        !           193:        hs->sc_addr = addr;
        !           194:        if (hs->sc_flags & HPIBF_READ) {
        !           195:                hs->sc_curcnt = count;
        !           196:                dmago(hs->sc_dq.dq_ctlr, addr, count, DMAGO_BYTE|DMAGO_READ);
        !           197:                nhpibrecv(unit, slave, sec, 0, 0);
        !           198:                hd->hpib_mim = MIS_END;
        !           199:        }
        !           200:        else {
        !           201:                if (count == 1) {
        !           202:                        hs->sc_curcnt = 1;
        !           203:                        dmago(hs->sc_dq.dq_ctlr, addr, 1, DMAGO_BYTE);
        !           204:                        nhpibsend(unit, slave, sec, 0, 0);
        !           205:                        hd->hpib_acr = AUX_EOI;
        !           206:                }
        !           207:                else {
        !           208:                        hs->sc_curcnt = count - 1;
        !           209:                        dmago(hs->sc_dq.dq_ctlr, addr, count - 1, DMAGO_BYTE);
        !           210:                        nhpibsend(unit, slave, sec, 0, 0);
        !           211:                }
        !           212:        }
        !           213:        hd->hpib_ie = IDS_IE | IDS_DMA(hs->sc_dq.dq_ctlr);
        !           214: }
        !           215: 
        !           216: nhpibdone(unit)
        !           217:        register int unit;
        !           218: {
        !           219:        register struct hpib_softc *hs = &hpib_softc[unit];
        !           220:        register struct nhpibdevice *hd;
        !           221:        register int cnt;
        !           222: 
        !           223:        hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
        !           224:        cnt = hs->sc_curcnt;
        !           225:        hs->sc_addr += cnt;
        !           226:        hs->sc_count -= cnt;
        !           227:        if (hs->sc_flags & HPIBF_READ) {
        !           228:                hs->sc_flags |= HPIBF_DONE;
        !           229:                hd->hpib_ie = IDS_IE;
        !           230:        } else {
        !           231:                if (hs->sc_count == 1) {
        !           232:                        hs->sc_curcnt = 1;
        !           233:                        hd->hpib_acr = AUX_EOI;
        !           234:                        dmago(hs->sc_dq.dq_ctlr, hs->sc_addr, 1, DMAGO_BYTE);
        !           235:                        return;
        !           236:                }
        !           237:                hs->sc_flags |= HPIBF_DONE;
        !           238:                hd->hpib_ie = IDS_IE;
        !           239:                hd->hpib_mim = MIS_BO;
        !           240:        }
        !           241: }
        !           242: 
        !           243: nhpibintr(unit)
        !           244:        register int unit;
        !           245: {
        !           246:        register struct hpib_softc *hs = &hpib_softc[unit];
        !           247:        register struct nhpibdevice *hd;
        !           248:        register struct devqueue *dq = hs->sc_sq.dq_forw;
        !           249:        register int stat0;
        !           250:        int stat1;
        !           251: 
        !           252: #ifdef lint
        !           253:        if (stat1 = unit) return(1);
        !           254: #endif
        !           255:        hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
        !           256:        if ((hd->hpib_ids & IDS_IR) == 0)
        !           257:                return(0);
        !           258:        stat0 = hd->hpib_mis;
        !           259:        stat1 = hd->hpib_lis;
        !           260:        if (hs->sc_flags & HPIBF_IO) {
        !           261:                hd->hpib_mim = 0;
        !           262:                if ((hs->sc_flags & HPIBF_DONE) == 0)
        !           263:                        dmastop(hs->sc_dq.dq_ctlr);
        !           264:                hd->hpib_acr = AUX_TCA;
        !           265:                hs->sc_flags &= ~(HPIBF_DONE|HPIBF_IO|HPIBF_READ);
        !           266:                dmafree(&hs->sc_dq);
        !           267:                (dq->dq_driver->d_intr)(dq->dq_unit);
        !           268:                return(1);
        !           269:        }
        !           270:        if (hs->sc_flags & HPIBF_PPOLL) {
        !           271:                hd->hpib_mim = 0;
        !           272:                stat0 = nhpibppoll(unit);
        !           273:                if (stat0 & (0x80 >> dq->dq_slave)) {
        !           274:                        hs->sc_flags &= ~HPIBF_PPOLL;
        !           275:                        (dq->dq_driver->d_intr)(dq->dq_unit);
        !           276:                }
        !           277:                return(1);
        !           278:        }
        !           279:        return(1);
        !           280: }
        !           281: 
        !           282: nhpibppoll(unit)
        !           283:        register int unit;
        !           284: {
        !           285:        register struct hpib_softc *hs = &hpib_softc[unit];
        !           286:        register struct nhpibdevice *hd;
        !           287:        register int ppoll;
        !           288: 
        !           289:        hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
        !           290:        hd->hpib_acr = AUX_SPP;
        !           291:        DELAY(25);
        !           292:        ppoll = hd->hpib_cpt;
        !           293:        hd->hpib_acr = AUX_CPP;
        !           294:        return(ppoll);
        !           295: }
        !           296: 
        !           297: nhpibowait(hd)
        !           298:        register struct nhpibdevice *hd;
        !           299: {
        !           300:        extern int hpibtimeout;
        !           301:        register int timo = hpibtimeout;
        !           302: 
        !           303:        while ((hd->hpib_mis & MIS_BO) == 0 && --timo)
        !           304:                ;
        !           305:        if (timo == 0)
        !           306:                return(-1);
        !           307:        return(0);
        !           308: }
        !           309: 
        !           310: nhpibiwait(hd)
        !           311:        register struct nhpibdevice *hd;
        !           312: {
        !           313:        extern int hpibtimeout;
        !           314:        register int timo = hpibtimeout;
        !           315: 
        !           316:        while ((hd->hpib_mis & MIS_BI) == 0 && --timo)
        !           317:                ;
        !           318:        if (timo == 0)
        !           319:                return(-1);
        !           320:        return(0);
        !           321: }
        !           322: 
        !           323: nhpibppwatch(unit)
        !           324:        register int unit;
        !           325: {
        !           326:        register struct hpib_softc *hs = &hpib_softc[unit];
        !           327:        register struct devqueue *dq = hs->sc_sq.dq_forw;
        !           328:        register int slave = 0x80 >> dq->dq_slave;
        !           329: 
        !           330:        if ((hs->sc_flags & HPIBF_PPOLL) == 0)
        !           331:                return;
        !           332:        if (nhpibppoll(unit) & slave)
        !           333:                        ((struct nhpibdevice *)hs->sc_hc->hp_addr)->hpib_mim = MIS_BO;
        !           334:        else
        !           335:                timeout(nhpibppwatch, unit, 1);
        !           336: }
        !           337: #endif

unix.superglobalmegacorp.com

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