merge in hp300 support from Utah
[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 *
5 * %sccs.include.redist.c%
6 *
7 * @(#)nhpib.c 7.1 (Berkeley) %G%
8 */
9
10/*
11 * Internal/98624 HPIB driver
12 */
13
14#include "param.h"
15#include "../hpdev/nhpibreg.h"
16#include "hpibvar.h"
17
18nhpibinit(unit)
19{
20 register struct hpib_softc *hs = &hpib_softc[unit];
21 register struct nhpibdevice *hd = (struct nhpibdevice *)hs->sc_addr;
22 extern int internalhpib;
23
24 if ((int)hd == internalhpib) {
25 hs->sc_type = HPIBA;
26 hs->sc_ba = HPIBA_BA;
27 }
28 else if (hd->hpib_cid == HPIBB) {
29 hs->sc_type = HPIBB;
30 hs->sc_ba = hd->hpib_csa & CSA_BA;
31 }
32 else
33 return(0);
34 nhpibreset(unit);
35 return(1);
36}
37
38nhpibreset(unit)
39{
40 register struct hpib_softc *hs = &hpib_softc[unit];
41 register struct nhpibdevice *hd;
42
43 hd = (struct nhpibdevice *)hs->sc_addr;
44 hd->hpib_acr = AUX_SSWRST;
45 hd->hpib_ar = hs->sc_ba;
46 hd->hpib_lim = 0;
47 hd->hpib_mim = 0;
48 hd->hpib_acr = AUX_CDAI;
49 hd->hpib_acr = AUX_CSHDW;
50 hd->hpib_acr = AUX_SSTD1;
51 hd->hpib_acr = AUX_SVSTD1;
52 hd->hpib_acr = AUX_CPP;
53 hd->hpib_acr = AUX_CHDFA;
54 hd->hpib_acr = AUX_CHDFE;
55 hd->hpib_acr = AUX_RHDF;
56 hd->hpib_acr = AUX_CSWRST;
57 hd->hpib_acr = AUX_TCA;
58 hd->hpib_acr = AUX_CSRE;
59 hd->hpib_acr = AUX_SSIC;
60 DELAY(100);
61 hd->hpib_acr = AUX_CSIC;
62 hd->hpib_acr = AUX_SSRE;
63 hd->hpib_data = C_DCL;
64 DELAY(100000);
65}
66
67nhpibsend(unit, slave, sec, buf, cnt)
68 register char *buf;
69 register int cnt;
70{
71 register struct hpib_softc *hs = &hpib_softc[unit];
72 register struct nhpibdevice *hd;
73 register int origcnt = cnt;
74
75 hd = (struct nhpibdevice *)hs->sc_addr;
76 hd->hpib_acr = AUX_TCA;
77 hd->hpib_data = C_UNL;
78 nhpibowait(hd);
79 hd->hpib_data = C_TAG + hs->sc_ba;
80 hd->hpib_acr = AUX_STON;
81 nhpibowait(hd);
82 hd->hpib_data = C_LAG + slave;
83 nhpibowait(hd);
84 if (sec != -1) {
85 hd->hpib_data = C_SCG + sec;
86 nhpibowait(hd);
87 }
88 hd->hpib_acr = AUX_GTS;
89 if (cnt) {
90 while (--cnt) {
91 hd->hpib_data = *buf++;
92 if (nhpibowait(hd) < 0)
93 break;
94 }
95 hd->hpib_acr = AUX_EOI;
96 hd->hpib_data = *buf;
97 if (nhpibowait(hd) < 0)
98 cnt++;
99 hd->hpib_acr = AUX_TCA;
100 }
101 return(origcnt - cnt);
102}
103
104nhpibrecv(unit, slave, sec, buf, cnt)
105 register char *buf;
106 register int cnt;
107{
108 register struct hpib_softc *hs = &hpib_softc[unit];
109 register struct nhpibdevice *hd;
110 register int origcnt = cnt;
111
112 hd = (struct nhpibdevice *)hs->sc_addr;
113 hd->hpib_acr = AUX_TCA;
114 hd->hpib_data = C_UNL;
115 nhpibowait(hd);
116 hd->hpib_data = C_LAG + hs->sc_ba;
117 hd->hpib_acr = AUX_SLON;
118 nhpibowait(hd);
119 hd->hpib_data = C_TAG + slave;
120 nhpibowait(hd);
121 if (sec != -1) {
122 hd->hpib_data = C_SCG + sec;
123 nhpibowait(hd);
124 }
125 hd->hpib_acr = AUX_RHDF;
126 hd->hpib_acr = AUX_GTS;
127 if (cnt) {
128 while (--cnt >= 0) {
129 if (nhpibiwait(hd) < 0)
130 break;
131 *buf++ = hd->hpib_data;
132 }
133 cnt++;
134 hd->hpib_acr = AUX_TCA;
135 }
136 return(origcnt - cnt);
137}
138
139nhpibppoll(unit)
140 register int unit;
141{
142 register struct hpib_softc *hs = &hpib_softc[unit];
143 register struct nhpibdevice *hd;
144 register int ppoll;
145
146 hd = (struct nhpibdevice *)hs->sc_addr;
147 hd->hpib_acr = AUX_SPP;
148 DELAY(25);
149 ppoll = hd->hpib_cpt;
150 hd->hpib_acr = AUX_CPP;
151 return(ppoll);
152}
153
154nhpibowait(hd)
155 register struct nhpibdevice *hd;
156{
157 register int timo = 100000;
158
159 while ((hd->hpib_mis & MIS_BO) == 0 && --timo)
160 ;
161 if (timo == 0)
162 return(-1);
163 return(0);
164}
165
166nhpibiwait(hd)
167 register struct nhpibdevice *hd;
168{
169 register int timo = 100000;
170
171 while ((hd->hpib_mis & MIS_BI) == 0 && --timo)
172 ;
173 if (timo == 0)
174 return(-1);
175 return(0);
176}