[BACK]Return to nhpib.c CVS log [TXT][DIR] Up to [local] / sys / arch / hp300 / stand / common

Annotation of sys/arch/hp300/stand/common/nhpib.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: nhpib.c,v 1.4 2006/08/17 06:31:10 miod Exp $  */
                      2: /*     $NetBSD: nhpib.c,v 1.5 1995/08/05 16:47:46 thorpej Exp $        */
                      3:
                      4: /*
                      5:  * Copyright (c) 1982, 1990, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. Neither the name of the University nor the names of its contributors
                     17:  *    may be used to endorse or promote products derived from this software
                     18:  *    without specific prior written permission.
                     19:  *
                     20:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     21:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     22:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     23:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     24:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     25:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     26:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     28:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     29:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     30:  * SUCH DAMAGE.
                     31:  *
                     32:  *     @(#)nhpib.c     8.1 (Berkeley) 6/10/93
                     33:  */
                     34:
                     35: /*
                     36:  * Internal/98624 HPIB driver
                     37:  */
                     38:
                     39: #include <sys/param.h>
                     40:
                     41: #include <hp300/dev/nhpibreg.h>
                     42:
                     43: #include "samachdep.h"
                     44: #include "hpibvar.h"
                     45:
                     46: int    nhpibiwait(struct nhpibdevice *);
                     47: int    nhpibowait(struct nhpibdevice *);
                     48: void   nhpibreset(int);
                     49:
                     50: int
                     51: nhpibinit(int unit)
                     52: {
                     53:        struct hpib_softc *hs = &hpib_softc[unit];
                     54:        struct nhpibdevice *hd = (struct nhpibdevice *)hs->sc_addr;
                     55:        extern int internalhpib;
                     56:
                     57:        if ((int)hd == internalhpib) {
                     58:                hs->sc_type = HPIBA;
                     59:                hs->sc_ba = HPIBA_BA;
                     60:        }
                     61:        else if (hd->hpib_cid == HPIBB) {
                     62:                hs->sc_type = HPIBB;
                     63:                hs->sc_ba = hd->hpib_csa & CSA_BA;
                     64:        }
                     65:        else
                     66:                return(0);
                     67:        nhpibreset(unit);
                     68:        return(1);
                     69: }
                     70:
                     71: void
                     72: nhpibreset(int unit)
                     73: {
                     74:        struct hpib_softc *hs = &hpib_softc[unit];
                     75:        struct nhpibdevice *hd;
                     76:
                     77:        hd = (struct nhpibdevice *)hs->sc_addr;
                     78:        hd->hpib_acr = AUX_SSWRST;
                     79:        hd->hpib_ar = hs->sc_ba;
                     80:        hd->hpib_lim = 0;
                     81:        hd->hpib_mim = 0;
                     82:        hd->hpib_acr = AUX_CDAI;
                     83:        hd->hpib_acr = AUX_CSHDW;
                     84:        hd->hpib_acr = AUX_SSTD1;
                     85:        hd->hpib_acr = AUX_SVSTD1;
                     86:        hd->hpib_acr = AUX_CPP;
                     87:        hd->hpib_acr = AUX_CHDFA;
                     88:        hd->hpib_acr = AUX_CHDFE;
                     89:        hd->hpib_acr = AUX_RHDF;
                     90:        hd->hpib_acr = AUX_CSWRST;
                     91:        hd->hpib_acr = AUX_TCA;
                     92:        hd->hpib_acr = AUX_CSRE;
                     93:        hd->hpib_acr = AUX_SSIC;
                     94:        DELAY(100);
                     95:        hd->hpib_acr = AUX_CSIC;
                     96:        hd->hpib_acr = AUX_SSRE;
                     97:        hd->hpib_data = C_DCL;
                     98:        DELAY(100000);
                     99: }
                    100:
                    101: int
                    102: nhpibsend(int unit, int slave, int sec, char *buf, int cnt)
                    103: {
                    104:        struct hpib_softc *hs = &hpib_softc[unit];
                    105:        struct nhpibdevice *hd;
                    106:        int origcnt = cnt;
                    107:
                    108:        hd = (struct nhpibdevice *)hs->sc_addr;
                    109:        hd->hpib_acr = AUX_TCA;
                    110:        hd->hpib_data = C_UNL;
                    111:        nhpibowait(hd);
                    112:        hd->hpib_data = C_TAG + hs->sc_ba;
                    113:        hd->hpib_acr = AUX_STON;
                    114:        nhpibowait(hd);
                    115:        hd->hpib_data = C_LAG + slave;
                    116:        nhpibowait(hd);
                    117:        if (sec != -1) {
                    118:                hd->hpib_data = C_SCG + sec;
                    119:                nhpibowait(hd);
                    120:        }
                    121:        hd->hpib_acr = AUX_GTS;
                    122:        if (cnt) {
                    123:                while (--cnt) {
                    124:                        hd->hpib_data = *buf++;
                    125:                        if (nhpibowait(hd) < 0)
                    126:                                break;
                    127:                }
                    128:                hd->hpib_acr = AUX_EOI;
                    129:                hd->hpib_data = *buf;
                    130:                if (nhpibowait(hd) < 0)
                    131:                        cnt++;
                    132:                hd->hpib_acr = AUX_TCA;
                    133:        }
                    134:        return(origcnt - cnt);
                    135: }
                    136:
                    137: int
                    138: nhpibrecv(int unit, int slave, int sec, char *buf, int cnt)
                    139: {
                    140:        struct hpib_softc *hs = &hpib_softc[unit];
                    141:        struct nhpibdevice *hd;
                    142:        int origcnt = cnt;
                    143:
                    144:        hd = (struct nhpibdevice *)hs->sc_addr;
                    145:        hd->hpib_acr = AUX_TCA;
                    146:        hd->hpib_data = C_UNL;
                    147:        nhpibowait(hd);
                    148:        hd->hpib_data = C_LAG + hs->sc_ba;
                    149:        hd->hpib_acr = AUX_SLON;
                    150:        nhpibowait(hd);
                    151:        hd->hpib_data = C_TAG + slave;
                    152:        nhpibowait(hd);
                    153:        if (sec != -1) {
                    154:                hd->hpib_data = C_SCG + sec;
                    155:                nhpibowait(hd);
                    156:        }
                    157:        hd->hpib_acr = AUX_RHDF;
                    158:        hd->hpib_acr = AUX_GTS;
                    159:        if (cnt) {
                    160:                while (--cnt >= 0) {
                    161:                        if (nhpibiwait(hd) < 0)
                    162:                                break;
                    163:                        *buf++ = hd->hpib_data;
                    164:                }
                    165:                cnt++;
                    166:                hd->hpib_acr = AUX_TCA;
                    167:        }
                    168:        return(origcnt - cnt);
                    169: }
                    170:
                    171: int
                    172: nhpibppoll(int unit)
                    173: {
                    174:        struct hpib_softc *hs = &hpib_softc[unit];
                    175:        struct nhpibdevice *hd;
                    176:        int ppoll;
                    177:
                    178:        hd = (struct nhpibdevice *)hs->sc_addr;
                    179:        hd->hpib_acr = AUX_SPP;
                    180:        DELAY(25);
                    181:        ppoll = hd->hpib_cpt;
                    182:        hd->hpib_acr = AUX_CPP;
                    183:        return(ppoll);
                    184: }
                    185:
                    186: int
                    187: nhpibowait(struct nhpibdevice *hd)
                    188: {
                    189:        int timo = 100000;
                    190:
                    191:        while ((hd->hpib_mis & MIS_BO) == 0 && --timo)
                    192:                ;
                    193:        if (timo == 0)
                    194:                return(-1);
                    195:        return(0);
                    196: }
                    197:
                    198: int
                    199: nhpibiwait(struct nhpibdevice *hd)
                    200: {
                    201:        int timo = 100000;
                    202:
                    203:        while ((hd->hpib_mis & MIS_BI) == 0 && --timo)
                    204:                ;
                    205:        if (timo == 0)
                    206:                return(-1);
                    207:        return(0);
                    208: }

CVSweb