BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / hp300 / stand / nhpib.c
CommitLineData
a8fd2d0d
KM
1/*
2 * Copyright (c) 1982, 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
af359dea
C
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.
a8fd2d0d 20 *
af359dea
C
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 *
33 * @(#)nhpib.c 7.2 (Berkeley) 12/16/90
a8fd2d0d
KM
34 */
35
36/*
37 * Internal/98624 HPIB driver
38 */
39
b28b3a13
KB
40#include "sys/param.h"
41#include "../dev/nhpibreg.h"
a8fd2d0d
KM
42#include "hpibvar.h"
43
44nhpibinit(unit)
45{
46 register struct hpib_softc *hs = &hpib_softc[unit];
47 register struct nhpibdevice *hd = (struct nhpibdevice *)hs->sc_addr;
48 extern int internalhpib;
49
50 if ((int)hd == internalhpib) {
51 hs->sc_type = HPIBA;
52 hs->sc_ba = HPIBA_BA;
53 }
54 else if (hd->hpib_cid == HPIBB) {
55 hs->sc_type = HPIBB;
56 hs->sc_ba = hd->hpib_csa & CSA_BA;
57 }
58 else
59 return(0);
60 nhpibreset(unit);
61 return(1);
62}
63
64nhpibreset(unit)
65{
66 register struct hpib_softc *hs = &hpib_softc[unit];
67 register struct nhpibdevice *hd;
68
69 hd = (struct nhpibdevice *)hs->sc_addr;
70 hd->hpib_acr = AUX_SSWRST;
71 hd->hpib_ar = hs->sc_ba;
72 hd->hpib_lim = 0;
73 hd->hpib_mim = 0;
74 hd->hpib_acr = AUX_CDAI;
75 hd->hpib_acr = AUX_CSHDW;
76 hd->hpib_acr = AUX_SSTD1;
77 hd->hpib_acr = AUX_SVSTD1;
78 hd->hpib_acr = AUX_CPP;
79 hd->hpib_acr = AUX_CHDFA;
80 hd->hpib_acr = AUX_CHDFE;
81 hd->hpib_acr = AUX_RHDF;
82 hd->hpib_acr = AUX_CSWRST;
83 hd->hpib_acr = AUX_TCA;
84 hd->hpib_acr = AUX_CSRE;
85 hd->hpib_acr = AUX_SSIC;
86 DELAY(100);
87 hd->hpib_acr = AUX_CSIC;
88 hd->hpib_acr = AUX_SSRE;
89 hd->hpib_data = C_DCL;
90 DELAY(100000);
91}
92
93nhpibsend(unit, slave, sec, buf, cnt)
94 register char *buf;
95 register int cnt;
96{
97 register struct hpib_softc *hs = &hpib_softc[unit];
98 register struct nhpibdevice *hd;
99 register int origcnt = cnt;
100
101 hd = (struct nhpibdevice *)hs->sc_addr;
102 hd->hpib_acr = AUX_TCA;
103 hd->hpib_data = C_UNL;
104 nhpibowait(hd);
105 hd->hpib_data = C_TAG + hs->sc_ba;
106 hd->hpib_acr = AUX_STON;
107 nhpibowait(hd);
108 hd->hpib_data = C_LAG + slave;
109 nhpibowait(hd);
110 if (sec != -1) {
111 hd->hpib_data = C_SCG + sec;
112 nhpibowait(hd);
113 }
114 hd->hpib_acr = AUX_GTS;
115 if (cnt) {
116 while (--cnt) {
117 hd->hpib_data = *buf++;
118 if (nhpibowait(hd) < 0)
119 break;
120 }
121 hd->hpib_acr = AUX_EOI;
122 hd->hpib_data = *buf;
123 if (nhpibowait(hd) < 0)
124 cnt++;
125 hd->hpib_acr = AUX_TCA;
126 }
127 return(origcnt - cnt);
128}
129
130nhpibrecv(unit, slave, sec, buf, cnt)
131 register char *buf;
132 register int cnt;
133{
134 register struct hpib_softc *hs = &hpib_softc[unit];
135 register struct nhpibdevice *hd;
136 register int origcnt = cnt;
137
138 hd = (struct nhpibdevice *)hs->sc_addr;
139 hd->hpib_acr = AUX_TCA;
140 hd->hpib_data = C_UNL;
141 nhpibowait(hd);
142 hd->hpib_data = C_LAG + hs->sc_ba;
143 hd->hpib_acr = AUX_SLON;
144 nhpibowait(hd);
145 hd->hpib_data = C_TAG + slave;
146 nhpibowait(hd);
147 if (sec != -1) {
148 hd->hpib_data = C_SCG + sec;
149 nhpibowait(hd);
150 }
151 hd->hpib_acr = AUX_RHDF;
152 hd->hpib_acr = AUX_GTS;
153 if (cnt) {
154 while (--cnt >= 0) {
155 if (nhpibiwait(hd) < 0)
156 break;
157 *buf++ = hd->hpib_data;
158 }
159 cnt++;
160 hd->hpib_acr = AUX_TCA;
161 }
162 return(origcnt - cnt);
163}
164
165nhpibppoll(unit)
166 register int unit;
167{
168 register struct hpib_softc *hs = &hpib_softc[unit];
169 register struct nhpibdevice *hd;
170 register int ppoll;
171
172 hd = (struct nhpibdevice *)hs->sc_addr;
173 hd->hpib_acr = AUX_SPP;
174 DELAY(25);
175 ppoll = hd->hpib_cpt;
176 hd->hpib_acr = AUX_CPP;
177 return(ppoll);
178}
179
180nhpibowait(hd)
181 register struct nhpibdevice *hd;
182{
183 register int timo = 100000;
184
185 while ((hd->hpib_mis & MIS_BO) == 0 && --timo)
186 ;
187 if (timo == 0)
188 return(-1);
189 return(0);
190}
191
192nhpibiwait(hd)
193 register struct nhpibdevice *hd;
194{
195 register int timo = 100000;
196
197 while ((hd->hpib_mis & MIS_BI) == 0 && --timo)
198 ;
199 if (timo == 0)
200 return(-1);
201 return(0);
202}