nhpib.c revision 1.2 1 /* $NetBSD: nhpib.c,v 1.2 2003/08/07 16:27:42 agc Exp $ */
2
3 /*
4 * Copyright (c) 1982, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * @(#)nhpib.c 8.1 (Berkeley) 6/10/93
32 */
33
34 /*
35 * Internal/98624 HPIB driver
36 */
37
38 #include <sys/param.h>
39
40 #include <hp300/dev/nhpibreg.h>
41
42 #include <hp300/stand/common/hpibvar.h>
43 #include <hp300/stand/common/samachdep.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 }
204