Commit | Line | Data |
---|---|---|
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 | * | |
35d92d0e | 7 | * @(#)hpib.c 7.8 (Berkeley) %G% |
a8fd2d0d KM |
8 | */ |
9 | ||
10 | /* | |
11 | * HPIB driver | |
12 | */ | |
38a01dbe KB |
13 | #include <sys/param.h> |
14 | #include <sys/reboot.h> | |
15 | #include <hp/dev/device.h> | |
16 | #include <hp300/stand/hpibvar.h> | |
a8fd2d0d | 17 | |
35d92d0e | 18 | #include <stand.att/saio.h> |
38a01dbe | 19 | #include <hp300/stand/samachdep.h> |
a8fd2d0d | 20 | |
2bb0988c | 21 | int internalhpib = IIOV(0x478000); |
a8fd2d0d KM |
22 | int fhpibppoll(), nhpibppoll(); |
23 | ||
24 | struct hpib_softc hpib_softc[NHPIB]; | |
25 | ||
a8fd2d0d KM |
26 | hpibinit() |
27 | { | |
28 | extern struct hp_hw sc_table[]; | |
29 | register struct hp_hw *hw; | |
30 | register struct hpib_softc *hs; | |
31 | register int i, addr; | |
33583b53 | 32 | |
a8fd2d0d | 33 | i = 0; |
2bb0988c MH |
34 | for (hw = sc_table; i < NHPIB && hw < &sc_table[MAXCTLRS]; hw++) { |
35 | if (!HW_ISHPIB(hw)) | |
a8fd2d0d KM |
36 | continue; |
37 | hs = &hpib_softc[i]; | |
2bb0988c | 38 | hs->sc_addr = hw->hw_kva; |
a8fd2d0d KM |
39 | if (nhpibinit(i) == 0) |
40 | if (fhpibinit(i) == 0) | |
41 | continue; | |
42 | if (howto & RB_ASKNAME) | |
43 | printf("hpib%d at sc%d\n", i, hw->hw_sc); | |
33583b53 | 44 | hw->hw_pa = (caddr_t) i; /* XXX for autoconfig */ |
a8fd2d0d KM |
45 | hs->sc_alive = 1; |
46 | i++; | |
47 | } | |
48 | } | |
49 | ||
50 | hpibalive(unit) | |
51 | register int unit; | |
52 | { | |
a8fd2d0d KM |
53 | if (unit >= NHPIB || hpib_softc[unit].sc_alive == 0) |
54 | return (0); | |
55 | return (1); | |
56 | } | |
57 | ||
33583b53 MH |
58 | hpibid(unit, slave) |
59 | int unit, slave; | |
a8fd2d0d | 60 | { |
a8fd2d0d | 61 | short id; |
33583b53 | 62 | int rv; |
a8fd2d0d | 63 | |
33583b53 MH |
64 | if (hpib_softc[unit].sc_type == HPIBC) |
65 | rv = fhpibrecv(unit, 31, slave, &id, 2); | |
a8fd2d0d | 66 | else |
33583b53 MH |
67 | rv = nhpibrecv(unit, 31, slave, &id, 2); |
68 | if (rv != 2) | |
a8fd2d0d KM |
69 | return (0); |
70 | return (id); | |
71 | } | |
72 | ||
33583b53 MH |
73 | hpibsend(unit, slave, sec, buf, cnt) |
74 | int unit, slave; | |
75 | char *buf; | |
76 | int cnt; | |
a8fd2d0d | 77 | { |
33583b53 | 78 | if (hpib_softc[unit].sc_type == HPIBC) |
a8fd2d0d | 79 | return (fhpibsend(unit, slave, sec, buf, cnt)); |
33583b53 | 80 | return (nhpibsend(unit, slave, sec, buf, cnt)); |
a8fd2d0d KM |
81 | } |
82 | ||
33583b53 MH |
83 | hpibrecv(unit, slave, sec, buf, cnt) |
84 | int unit, slave; | |
85 | char *buf; | |
86 | int cnt; | |
a8fd2d0d | 87 | { |
33583b53 | 88 | if (hpib_softc[unit].sc_type == HPIBC) |
a8fd2d0d | 89 | return (fhpibrecv(unit, slave, sec, buf, cnt)); |
33583b53 | 90 | return (nhpibrecv(unit, slave, sec, buf, cnt)); |
a8fd2d0d KM |
91 | } |
92 | ||
33583b53 MH |
93 | hpibswait(unit, slave) |
94 | register int unit, slave; | |
a8fd2d0d KM |
95 | { |
96 | register int timo = 1000000; | |
a8fd2d0d KM |
97 | register int (*poll)(); |
98 | ||
33583b53 | 99 | slave = 0x80 >> slave; |
a8fd2d0d KM |
100 | if (hpib_softc[unit].sc_type == HPIBC) |
101 | poll = fhpibppoll; | |
102 | else | |
103 | poll = nhpibppoll; | |
104 | while (((*poll)(unit) & slave) == 0) | |
105 | if (--timo == 0) | |
106 | break; | |
107 | if (timo == 0) | |
108 | return (-1); | |
109 | return (0); | |
110 | } | |
111 | ||
33583b53 MH |
112 | hpibgo(unit, slave, sec, addr, count, flag) |
113 | int unit, slave; | |
a8fd2d0d KM |
114 | char *addr; |
115 | { | |
a8fd2d0d | 116 | if (hpib_softc[unit].sc_type == HPIBC) |
8aceccb5 | 117 | if (flag == F_READ) |
a8fd2d0d KM |
118 | fhpibrecv(unit, slave, sec, addr, count); |
119 | else | |
120 | fhpibsend(unit, slave, sec, addr, count); | |
121 | else | |
8aceccb5 | 122 | if (flag == F_READ) |
a8fd2d0d KM |
123 | nhpibrecv(unit, slave, sec, addr, count); |
124 | else | |
125 | nhpibsend(unit, slave, sec, addr, count); | |
126 | } |