|
|
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: @(#)fhpib.c 7.2 (Berkeley) 12/16/90
! 34: * fhpib.c,v 1.2 1993/05/22 07:58:53 cgd Exp
1.1 root 35: */
36:
37: /*
38: * 98625A/B HPIB driver
39: */
40:
41: #include "sys/param.h"
42: #include "../dev/fhpibreg.h"
43: #include "hpibvar.h"
44:
45: fhpibinit(unit)
46: register int unit;
47: {
48: register struct hpib_softc *hs = &hpib_softc[unit];
49: register struct fhpibdevice *hd = (struct fhpibdevice *)hs->sc_addr;
50:
51: if (hd->hpib_cid != HPIBC)
52: return(0);
53: hs->sc_type = HPIBC;
54: hs->sc_ba = HPIBC_BA;
55: fhpibreset(unit);
56: return(1);
57: }
58:
59: fhpibreset(unit)
60: {
61: register struct hpib_softc *hs = &hpib_softc[unit];
62: register struct fhpibdevice *hd;
63:
64: hd = (struct fhpibdevice *)hs->sc_addr;
65: hd->hpib_cid = 0xFF;
66: DELAY(100);
67: hd->hpib_cmd = CT_8BIT;
68: hd->hpib_ar = AR_ARONC;
69: hd->hpib_cmd |= CT_IFC;
70: hd->hpib_cmd |= CT_INITFIFO;
71: DELAY(100);
72: hd->hpib_cmd &= ~CT_IFC;
73: hd->hpib_cmd |= CT_REN;
74: hd->hpib_stat = ST_ATN;
75: hd->hpib_data = C_DCL;
76: DELAY(100000);
77: }
78:
79: fhpibsend(unit, slave, sec, buf, cnt)
80: register char *buf;
81: register int cnt;
82: {
83: register struct hpib_softc *hs = &hpib_softc[unit];
84: register struct fhpibdevice *hd;
85: int origcnt = cnt;
86:
87: hd = (struct fhpibdevice *)hs->sc_addr;
88: hd->hpib_stat = 0;
89: hd->hpib_imask = IM_IDLE | IM_ROOM;
90: fhpibwait(hd, IM_IDLE);
91: hd->hpib_stat = ST_ATN;
92: hd->hpib_data = C_UNL;
93: hd->hpib_data = C_TAG + hs->sc_ba;
94: hd->hpib_data = C_LAG + slave;
95: if (sec != -1)
96: hd->hpib_data = C_SCG + sec;
97: fhpibwait(hd, IM_IDLE);
98: hd->hpib_stat = ST_WRITE;
99: if (cnt) {
100: while (--cnt) {
101: hd->hpib_data = *buf++;
102: if (fhpibwait(hd, IM_ROOM) < 0)
103: break;
104: }
105: hd->hpib_stat = ST_EOI;
106: hd->hpib_data = *buf;
107: if (fhpibwait(hd, IM_ROOM) < 0)
108: cnt++;
109: hd->hpib_stat = ST_ATN;
110: /* XXX: HP-UX claims bug with CS80 transparent messages */
111: if (sec == 0x12)
112: DELAY(150);
113: hd->hpib_data = C_UNL;
114: fhpibwait(hd, IM_IDLE);
115: }
116: hd->hpib_imask = 0;
117: return(origcnt - cnt);
118: }
119:
120: fhpibrecv(unit, slave, sec, buf, cnt)
121: register char *buf;
122: register int cnt;
123: {
124: register struct hpib_softc *hs = &hpib_softc[unit];
125: register struct fhpibdevice *hd;
126: int origcnt = cnt;
127:
128: hd = (struct fhpibdevice *)hs->sc_addr;
129: hd->hpib_stat = 0;
130: hd->hpib_imask = IM_IDLE | IM_ROOM | IM_BYTE;
131: fhpibwait(hd, IM_IDLE);
132: hd->hpib_stat = ST_ATN;
133: hd->hpib_data = C_UNL;
134: hd->hpib_data = C_LAG + hs->sc_ba;
135: hd->hpib_data = C_TAG + slave;
136: if (sec != -1)
137: hd->hpib_data = C_SCG + sec;
138: fhpibwait(hd, IM_IDLE);
139: hd->hpib_stat = ST_READ0;
140: hd->hpib_data = 0;
141: if (cnt) {
142: while (--cnt >= 0) {
143: if (fhpibwait(hd, IM_BYTE) < 0)
144: break;
145: *buf++ = hd->hpib_data;
146: }
147: cnt++;
148: fhpibwait(hd, IM_ROOM);
149: hd->hpib_stat = ST_ATN;
150: hd->hpib_data = (slave == 31) ? C_UNA : C_UNT;
151: fhpibwait(hd, IM_IDLE);
152: }
153: hd->hpib_imask = 0;
154: return(origcnt - cnt);
155: }
156:
157: fhpibppoll(unit)
158: register int unit;
159: {
160: register struct hpib_softc *hs = &hpib_softc[unit];
161: register struct fhpibdevice *hd;
162: register int ppoll;
163:
164: hd = (struct fhpibdevice *)hs->sc_addr;
165: hd->hpib_stat = 0;
166: hd->hpib_psense = 0;
167: hd->hpib_pmask = 0xFF;
168: hd->hpib_imask = IM_PPRESP | IM_PABORT;
169: DELAY(25);
170: hd->hpib_intr = IM_PABORT;
171: ppoll = hd->hpib_data;
172: if (hd->hpib_intr & IM_PABORT)
173: ppoll = 0;
174: hd->hpib_imask = 0;
175: hd->hpib_pmask = 0;
176: hd->hpib_stat = ST_IENAB;
177: return(ppoll);
178: }
179:
180: fhpibwait(hd, x)
181: register struct fhpibdevice *hd;
182: {
183: register int timo = 100000;
184:
185: while ((hd->hpib_intr & x) == 0 && --timo)
186: ;
187: if (timo == 0)
188: return(-1);
189: return(0);
190: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.