|
|
1.1 root 1: /*
2: * Copyright (c) 1982, 1990 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution is only permitted until one year after the first shipment
6: * of 4.4BSD by the Regents. Otherwise, redistribution and use in source and
7: * binary forms are permitted provided that: (1) source distributions retain
8: * this entire copyright notice and comment, and (2) distributions including
9: * binaries display the following acknowledgement: This product includes
10: * software developed by the University of California, Berkeley and its
11: * contributors'' in the documentation or other materials provided with the
12: * distribution and in all advertising materials mentioning features or use
13: * of this software. Neither the name of the University nor the names of
14: * its contributors may be used to endorse or promote products derived from
15: * this software without specific prior written permission.
16: * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19: *
20: * @(#)hpib.c 7.2 (Berkeley) 6/24/90
21: */
22:
23: /*
24: * HPIB driver
25: */
26: #include "reboot.h"
27: #include "../hpdev/device.h"
28: #include "hpibvar.h"
29:
30: #include "saio.h"
31: #include "samachdep.h"
32:
33: int internalhpib = 0x478000;
34: int fhpibppoll(), nhpibppoll();
35:
36: struct hpib_softc hpib_softc[NHPIB];
37:
38: #define hpibunit(x) ((x) >> 3)
39: #define hpibslave(x) ((x) & 7)
40:
41: hpibinit()
42: {
43: extern struct hp_hw sc_table[];
44: register struct hp_hw *hw;
45: register struct hpib_softc *hs;
46: register int i, addr;
47: static int first = 1;
48:
49: i = 0;
50: for (hw = sc_table; i < NHPIB && hw < &sc_table[MAX_CTLR]; hw++) {
51: if (hw->hw_type != HPIB)
52: continue;
53: hs = &hpib_softc[i];
54: hs->sc_addr = hw->hw_addr;
55: if (nhpibinit(i) == 0)
56: if (fhpibinit(i) == 0)
57: continue;
58: if (howto & RB_ASKNAME)
59: printf("hpib%d at sc%d\n", i, hw->hw_sc);
60: /*
61: * Adjust devtype on first call. This routine assumes that
62: * adaptor is in the high byte of devtype.
63: */
64: if (first && ((devtype >> 24) & 0xff) == hw->hw_sc) {
65: devtype = (devtype & 0x00ffffff) | (i << 24);
66: first = 0;
67: }
68: hs->sc_alive = 1;
69: i++;
70: }
71: }
72:
73: hpibalive(unit)
74: register int unit;
75: {
76: unit = hpibunit(unit);
77: if (unit >= NHPIB || hpib_softc[unit].sc_alive == 0)
78: return (0);
79: return (1);
80: }
81:
82: hpibid(unit)
83: register int unit;
84: {
85: register struct hpib_softc *hs = &hpib_softc[hpibunit(unit)];
86: register int slave;
87: short id;
88:
89: slave = hpibslave(unit);
90: unit = hpibunit(unit);
91: if (hs->sc_type == HPIBC)
92: slave = fhpibrecv(unit, 31, slave, &id, 2);
93: else
94: slave = nhpibrecv(unit, 31, slave, &id, 2);
95: if (slave != 2)
96: return (0);
97: return (id);
98: }
99:
100: hpibsend(unit, sec, buf, cnt)
101: register char *buf;
102: register int cnt;
103: {
104: register struct hpib_softc *hs = &hpib_softc[hpibunit(unit)];
105: register int slave;
106:
107: slave = hpibslave(unit);
108: unit = hpibunit(unit);
109: if (hs->sc_type == HPIBC)
110: return (fhpibsend(unit, slave, sec, buf, cnt));
111: else
112: return (nhpibsend(unit, slave, sec, buf, cnt));
113: }
114:
115: hpibrecv(unit, sec, buf, cnt)
116: register char *buf;
117: register int cnt;
118: {
119: register struct hpib_softc *hs = &hpib_softc[hpibunit(unit)];
120: register int slave;
121:
122: slave = hpibslave(unit);
123: unit = hpibunit(unit);
124: if (hs->sc_type == HPIBC)
125: return (fhpibrecv(unit, slave, sec, buf, cnt));
126: else
127: return (nhpibrecv(unit, slave, sec, buf, cnt));
128: }
129:
130: hpibswait(unit)
131: register int unit;
132: {
133: register int timo = 1000000;
134: register int slave = 0x80 >> hpibslave(unit);
135: register int (*poll)();
136:
137: unit = hpibunit(unit);
138: if (hpib_softc[unit].sc_type == HPIBC)
139: poll = fhpibppoll;
140: else
141: poll = nhpibppoll;
142: while (((*poll)(unit) & slave) == 0)
143: if (--timo == 0)
144: break;
145: if (timo == 0)
146: return (-1);
147: return (0);
148: }
149:
150: hpibgo(unit, sec, addr, count, flag)
151: register int unit;
152: char *addr;
153: {
154: register int slave;
155:
156: slave = hpibslave(unit);
157: unit = hpibunit(unit);
158: if (hpib_softc[unit].sc_type == HPIBC)
159: if (flag == READ)
160: fhpibrecv(unit, slave, sec, addr, count);
161: else
162: fhpibsend(unit, slave, sec, addr, count);
163: else
164: if (flag == READ)
165: nhpibrecv(unit, slave, sec, addr, count);
166: else
167: nhpibsend(unit, slave, sec, addr, count);
168: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.