1 /*
2 * Copyright (c) 1982, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 *
7 * @(#)fhpib.c 8.1 (Berkeley) 06/10/93
8 */
9
10 /*
11 * 98625A/B HPIB driver
12 */
13
14 #include <sys/param.h>
15 #include <hp300/dev/fhpibreg.h>
16 #include <hp300/stand/hpibvar.h>
17
fhpibinit(unit)18 fhpibinit(unit)
19 register int unit;
20 {
21 register struct hpib_softc *hs = &hpib_softc[unit];
22 register struct fhpibdevice *hd = (struct fhpibdevice *)hs->sc_addr;
23
24 if (hd->hpib_cid != HPIBC)
25 return(0);
26 hs->sc_type = HPIBC;
27 hs->sc_ba = HPIBC_BA;
28 fhpibreset(unit);
29 return(1);
30 }
31
fhpibreset(unit)32 fhpibreset(unit)
33 {
34 register struct hpib_softc *hs = &hpib_softc[unit];
35 register struct fhpibdevice *hd;
36
37 hd = (struct fhpibdevice *)hs->sc_addr;
38 hd->hpib_cid = 0xFF;
39 DELAY(100);
40 hd->hpib_cmd = CT_8BIT;
41 hd->hpib_ar = AR_ARONC;
42 hd->hpib_cmd |= CT_IFC;
43 hd->hpib_cmd |= CT_INITFIFO;
44 DELAY(100);
45 hd->hpib_cmd &= ~CT_IFC;
46 hd->hpib_cmd |= CT_REN;
47 hd->hpib_stat = ST_ATN;
48 hd->hpib_data = C_DCL;
49 DELAY(100000);
50 }
51
fhpibsend(unit,slave,sec,buf,cnt)52 fhpibsend(unit, slave, sec, buf, cnt)
53 register char *buf;
54 register int cnt;
55 {
56 register struct hpib_softc *hs = &hpib_softc[unit];
57 register struct fhpibdevice *hd;
58 int origcnt = cnt;
59
60 hd = (struct fhpibdevice *)hs->sc_addr;
61 hd->hpib_stat = 0;
62 hd->hpib_imask = IM_IDLE | IM_ROOM;
63 fhpibwait(hd, IM_IDLE);
64 hd->hpib_stat = ST_ATN;
65 hd->hpib_data = C_UNL;
66 hd->hpib_data = C_TAG + hs->sc_ba;
67 hd->hpib_data = C_LAG + slave;
68 if (sec != -1)
69 hd->hpib_data = C_SCG + sec;
70 fhpibwait(hd, IM_IDLE);
71 hd->hpib_stat = ST_WRITE;
72 if (cnt) {
73 while (--cnt) {
74 hd->hpib_data = *buf++;
75 if (fhpibwait(hd, IM_ROOM) < 0)
76 break;
77 }
78 hd->hpib_stat = ST_EOI;
79 hd->hpib_data = *buf;
80 if (fhpibwait(hd, IM_ROOM) < 0)
81 cnt++;
82 hd->hpib_stat = ST_ATN;
83 /* XXX: HP-UX claims bug with CS80 transparent messages */
84 if (sec == 0x12)
85 DELAY(150);
86 hd->hpib_data = C_UNL;
87 fhpibwait(hd, IM_IDLE);
88 }
89 hd->hpib_imask = 0;
90 return(origcnt - cnt);
91 }
92
fhpibrecv(unit,slave,sec,buf,cnt)93 fhpibrecv(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 fhpibdevice *hd;
99 int origcnt = cnt;
100
101 hd = (struct fhpibdevice *)hs->sc_addr;
102 hd->hpib_stat = 0;
103 hd->hpib_imask = IM_IDLE | IM_ROOM | IM_BYTE;
104 fhpibwait(hd, IM_IDLE);
105 hd->hpib_stat = ST_ATN;
106 hd->hpib_data = C_UNL;
107 hd->hpib_data = C_LAG + hs->sc_ba;
108 hd->hpib_data = C_TAG + slave;
109 if (sec != -1)
110 hd->hpib_data = C_SCG + sec;
111 fhpibwait(hd, IM_IDLE);
112 hd->hpib_stat = ST_READ0;
113 hd->hpib_data = 0;
114 if (cnt) {
115 while (--cnt >= 0) {
116 if (fhpibwait(hd, IM_BYTE) < 0)
117 break;
118 *buf++ = hd->hpib_data;
119 }
120 cnt++;
121 fhpibwait(hd, IM_ROOM);
122 hd->hpib_stat = ST_ATN;
123 hd->hpib_data = (slave == 31) ? C_UNA : C_UNT;
124 fhpibwait(hd, IM_IDLE);
125 }
126 hd->hpib_imask = 0;
127 return(origcnt - cnt);
128 }
129
fhpibppoll(unit)130 fhpibppoll(unit)
131 register int unit;
132 {
133 register struct hpib_softc *hs = &hpib_softc[unit];
134 register struct fhpibdevice *hd;
135 register int ppoll;
136
137 hd = (struct fhpibdevice *)hs->sc_addr;
138 hd->hpib_stat = 0;
139 hd->hpib_psense = 0;
140 hd->hpib_pmask = 0xFF;
141 hd->hpib_imask = IM_PPRESP | IM_PABORT;
142 DELAY(25);
143 hd->hpib_intr = IM_PABORT;
144 ppoll = hd->hpib_data;
145 if (hd->hpib_intr & IM_PABORT)
146 ppoll = 0;
147 hd->hpib_imask = 0;
148 hd->hpib_pmask = 0;
149 hd->hpib_stat = ST_IENAB;
150 return(ppoll);
151 }
152
fhpibwait(hd,x)153 fhpibwait(hd, x)
154 register struct fhpibdevice *hd;
155 {
156 register int timo = 100000;
157
158 while ((hd->hpib_intr & x) == 0 && --timo)
159 ;
160 if (timo == 0)
161 return(-1);
162 return(0);
163 }
164