merge in hp300 support from Utah
[unix-history] / usr / src / sys / hp300 / stand / hpib.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 * @(#)hpib.c 7.1 (Berkeley) %G%
8 */
9
10/*
11 * HPIB driver
12 */
13#include "../h/reboot.h"
14#include "../hpdev/device.h"
15#include "hpibvar.h"
16
17#include "saio.h"
18#include "samachdep.h"
19
20int internalhpib = 0x478000;
21int fhpibppoll(), nhpibppoll();
22
23struct hpib_softc hpib_softc[NHPIB];
24
25#define hpibunit(x) ((x) >> 3)
26#define hpibslave(x) ((x) & 7)
27
28hpibinit()
29{
30 extern struct hp_hw sc_table[];
31 register struct hp_hw *hw;
32 register struct hpib_softc *hs;
33 register int i, addr;
34 static int first = 1;
35
36 i = 0;
37 for (hw = sc_table; i < NHPIB && hw < &sc_table[MAX_CTLR]; hw++) {
38 if (hw->hw_type != HPIB)
39 continue;
40 hs = &hpib_softc[i];
41 hs->sc_addr = hw->hw_addr;
42 if (nhpibinit(i) == 0)
43 if (fhpibinit(i) == 0)
44 continue;
45 if (howto & RB_ASKNAME)
46 printf("hpib%d at sc%d\n", i, hw->hw_sc);
47 /*
48 * Adjust devtype on first call. This routine assumes that
49 * adaptor is in the high byte of devtype.
50 */
51 if (first && ((devtype >> 24) & 0xff) == hw->hw_sc) {
52 devtype = (devtype & 0x00ffffff) | (i << 24);
53 first = 0;
54 }
55 hs->sc_alive = 1;
56 i++;
57 }
58}
59
60hpibalive(unit)
61 register int unit;
62{
63 unit = hpibunit(unit);
64 if (unit >= NHPIB || hpib_softc[unit].sc_alive == 0)
65 return (0);
66 return (1);
67}
68
69hpibid(unit)
70 register int unit;
71{
72 register struct hpib_softc *hs = &hpib_softc[hpibunit(unit)];
73 register int slave;
74 short id;
75
76 slave = hpibslave(unit);
77 unit = hpibunit(unit);
78 if (hs->sc_type == HPIBC)
79 slave = fhpibrecv(unit, 31, slave, &id, 2);
80 else
81 slave = nhpibrecv(unit, 31, slave, &id, 2);
82 if (slave != 2)
83 return (0);
84 return (id);
85}
86
87hpibsend(unit, sec, buf, cnt)
88 register char *buf;
89 register int cnt;
90{
91 register struct hpib_softc *hs = &hpib_softc[hpibunit(unit)];
92 register int slave;
93
94 slave = hpibslave(unit);
95 unit = hpibunit(unit);
96 if (hs->sc_type == HPIBC)
97 return (fhpibsend(unit, slave, sec, buf, cnt));
98 else
99 return (nhpibsend(unit, slave, sec, buf, cnt));
100}
101
102hpibrecv(unit, sec, buf, cnt)
103 register char *buf;
104 register int cnt;
105{
106 register struct hpib_softc *hs = &hpib_softc[hpibunit(unit)];
107 register int slave;
108
109 slave = hpibslave(unit);
110 unit = hpibunit(unit);
111 if (hs->sc_type == HPIBC)
112 return (fhpibrecv(unit, slave, sec, buf, cnt));
113 else
114 return (nhpibrecv(unit, slave, sec, buf, cnt));
115}
116
117hpibswait(unit)
118 register int unit;
119{
120 register int timo = 1000000;
121 register int slave = 0x80 >> hpibslave(unit);
122 register int (*poll)();
123
124 unit = hpibunit(unit);
125 if (hpib_softc[unit].sc_type == HPIBC)
126 poll = fhpibppoll;
127 else
128 poll = nhpibppoll;
129 while (((*poll)(unit) & slave) == 0)
130 if (--timo == 0)
131 break;
132 if (timo == 0)
133 return (-1);
134 return (0);
135}
136
137hpibgo(unit, sec, addr, count, flag)
138 register int unit;
139 char *addr;
140{
141 register int slave;
142
143 slave = hpibslave(unit);
144 unit = hpibunit(unit);
145 if (hpib_softc[unit].sc_type == HPIBC)
146 if (flag == READ)
147 fhpibrecv(unit, slave, sec, addr, count);
148 else
149 fhpibsend(unit, slave, sec, addr, count);
150 else
151 if (flag == READ)
152 nhpibrecv(unit, slave, sec, addr, count);
153 else
154 nhpibsend(unit, slave, sec, addr, count);
155}