Annotation of sys/arch/hp300/stand/common/fhpib.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: fhpib.c,v 1.4 2006/08/17 06:31:10 miod Exp $ */
2: /* $NetBSD: fhpib.c,v 1.5 1995/08/05 16:47:42 thorpej Exp $ */
3:
4: /*
5: * Copyright (c) 1982, 1990, 1993
6: * The Regents of the University of California. All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. Neither the name of the University nor the names of its contributors
17: * may be used to endorse or promote products derived from this software
18: * without specific prior written permission.
19: *
20: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30: * SUCH DAMAGE.
31: *
32: * @(#)fhpib.c 8.1 (Berkeley) 6/10/93
33: */
34:
35: /*
36: * 98625A/B HPIB driver
37: */
38:
39: #include <sys/param.h>
40:
41: #include <hp300/dev/fhpibreg.h>
42:
43: #include "samachdep.h"
44: #include "hpibvar.h"
45:
46: int fhpibinit(int);
47: void fhpibreset(int);
48: int fhpibwait(struct fhpibdevice *, int);
49:
50: int
51: fhpibinit(int unit)
52: {
53: struct hpib_softc *hs = &hpib_softc[unit];
54: struct fhpibdevice *hd = (struct fhpibdevice *)hs->sc_addr;
55:
56: if (hd->hpib_cid != HPIBC)
57: return(0);
58: hs->sc_type = HPIBC;
59: hs->sc_ba = HPIBC_BA;
60: fhpibreset(unit);
61: return(1);
62: }
63:
64: void
65: fhpibreset(int unit)
66: {
67: struct hpib_softc *hs = &hpib_softc[unit];
68: struct fhpibdevice *hd;
69:
70: hd = (struct fhpibdevice *)hs->sc_addr;
71: hd->hpib_cid = 0xFF;
72: DELAY(100);
73: hd->hpib_cmd = CT_8BIT;
74: hd->hpib_ar = AR_ARONC;
75: hd->hpib_cmd |= CT_IFC;
76: hd->hpib_cmd |= CT_INITFIFO;
77: DELAY(100);
78: hd->hpib_cmd &= ~CT_IFC;
79: hd->hpib_cmd |= CT_REN;
80: hd->hpib_stat = ST_ATN;
81: hd->hpib_data = C_DCL;
82: DELAY(100000);
83: }
84:
85: int
86: fhpibsend(int unit, int slave, int sec, char *buf, int cnt)
87: {
88: struct hpib_softc *hs = &hpib_softc[unit];
89: struct fhpibdevice *hd;
90: int origcnt = cnt;
91:
92: hd = (struct fhpibdevice *)hs->sc_addr;
93: hd->hpib_stat = 0;
94: hd->hpib_imask = IM_IDLE | IM_ROOM;
95: fhpibwait(hd, IM_IDLE);
96: hd->hpib_stat = ST_ATN;
97: hd->hpib_data = C_UNL;
98: hd->hpib_data = C_TAG + hs->sc_ba;
99: hd->hpib_data = C_LAG + slave;
100: if (sec != -1)
101: hd->hpib_data = C_SCG + sec;
102: fhpibwait(hd, IM_IDLE);
103: hd->hpib_stat = ST_WRITE;
104: if (cnt) {
105: while (--cnt) {
106: hd->hpib_data = *buf++;
107: if (fhpibwait(hd, IM_ROOM) < 0)
108: break;
109: }
110: hd->hpib_stat = ST_EOI;
111: hd->hpib_data = *buf;
112: if (fhpibwait(hd, IM_ROOM) < 0)
113: cnt++;
114: hd->hpib_stat = ST_ATN;
115: /* XXX: HP-UX claims bug with CS80 transparent messages */
116: if (sec == 0x12)
117: DELAY(150);
118: hd->hpib_data = C_UNL;
119: fhpibwait(hd, IM_IDLE);
120: }
121: hd->hpib_imask = 0;
122: return(origcnt - cnt);
123: }
124:
125: int
126: fhpibrecv(int unit, int slave, int sec, char *buf, int cnt)
127: {
128: struct hpib_softc *hs = &hpib_softc[unit];
129: struct fhpibdevice *hd;
130: int origcnt = cnt;
131:
132: hd = (struct fhpibdevice *)hs->sc_addr;
133: hd->hpib_stat = 0;
134: hd->hpib_imask = IM_IDLE | IM_ROOM | IM_BYTE;
135: fhpibwait(hd, IM_IDLE);
136: hd->hpib_stat = ST_ATN;
137: hd->hpib_data = C_UNL;
138: hd->hpib_data = C_LAG + hs->sc_ba;
139: hd->hpib_data = C_TAG + slave;
140: if (sec != -1)
141: hd->hpib_data = C_SCG + sec;
142: fhpibwait(hd, IM_IDLE);
143: hd->hpib_stat = ST_READ0;
144: hd->hpib_data = 0;
145: if (cnt) {
146: while (--cnt >= 0) {
147: if (fhpibwait(hd, IM_BYTE) < 0)
148: break;
149: *buf++ = hd->hpib_data;
150: }
151: cnt++;
152: fhpibwait(hd, IM_ROOM);
153: hd->hpib_stat = ST_ATN;
154: hd->hpib_data = (slave == 31) ? C_UNA : C_UNT;
155: fhpibwait(hd, IM_IDLE);
156: }
157: hd->hpib_imask = 0;
158: return(origcnt - cnt);
159: }
160:
161: int
162: fhpibppoll(int unit)
163: {
164: struct hpib_softc *hs = &hpib_softc[unit];
165: struct fhpibdevice *hd;
166: int ppoll;
167:
168: hd = (struct fhpibdevice *)hs->sc_addr;
169: hd->hpib_stat = 0;
170: hd->hpib_psense = 0;
171: hd->hpib_pmask = 0xFF;
172: hd->hpib_imask = IM_PPRESP | IM_PABORT;
173: DELAY(25);
174: hd->hpib_intr = IM_PABORT;
175: ppoll = hd->hpib_data;
176: if (hd->hpib_intr & IM_PABORT)
177: ppoll = 0;
178: hd->hpib_imask = 0;
179: hd->hpib_pmask = 0;
180: hd->hpib_stat = ST_IENAB;
181: return(ppoll);
182: }
183:
184: int
185: fhpibwait(struct fhpibdevice *hd, int x)
186: {
187: int timo = 100000;
188:
189: while ((hd->hpib_intr & x) == 0 && --timo)
190: ;
191: if (timo == 0)
192: return(-1);
193: return(0);
194: }
CVSweb