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