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