Home | History | Annotate | Line # | Download | only in common
hpib.c revision 1.1
      1 /*	$NetBSD: hpib.c,v 1.1 1997/02/04 03:52:26 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 1990, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  *	@(#)hpib.c	8.1 (Berkeley) 6/10/93
     36  */
     37 
     38 /*
     39  * HPIB driver
     40  */
     41 #include <sys/param.h>
     42 #include <sys/reboot.h>
     43 
     44 #include <lib/libsa/stand.h>
     45 
     46 #include <hp300/stand/common/device.h>
     47 #include <hp300/stand/common/hpibvar.h>
     48 #include <hp300/stand/common/samachdep.h>
     49 
     50 int	internalhpib = IIOV(0x478000);
     51 int	fhpibppoll(), nhpibppoll();
     52 
     53 struct	hpib_softc hpib_softc[NHPIB];
     54 
     55 hpibinit()
     56 {
     57 	extern struct hp_hw sc_table[];
     58 	register struct hp_hw *hw;
     59 	register struct hpib_softc *hs;
     60 	register int i, addr;
     61 
     62 	i = 0;
     63 	for (hw = sc_table; i < NHPIB && hw < &sc_table[MAXCTLRS]; hw++) {
     64 		if (!HW_ISHPIB(hw))
     65 			continue;
     66 		hs = &hpib_softc[i];
     67 		hs->sc_addr = hw->hw_kva;
     68 		if (nhpibinit(i) == 0)
     69 			if (fhpibinit(i) == 0)
     70 				continue;
     71 		if (howto & RB_ASKNAME)
     72 			printf("hpib%d at sc%d\n", i, hw->hw_sc);
     73 		hw->hw_pa = (caddr_t) i;	/* XXX for autoconfig */
     74 		hs->sc_alive = 1;
     75 		i++;
     76 	}
     77 }
     78 
     79 hpibalive(unit)
     80 	register int unit;
     81 {
     82 	if (unit >= NHPIB || hpib_softc[unit].sc_alive == 0)
     83 		return (0);
     84 	return (1);
     85 }
     86 
     87 hpibid(unit, slave)
     88 	int unit, slave;
     89 {
     90 	short id;
     91 	int rv;
     92 
     93 	if (hpib_softc[unit].sc_type == HPIBC)
     94 		rv = fhpibrecv(unit, 31, slave, &id, 2);
     95 	else
     96 		rv = nhpibrecv(unit, 31, slave, &id, 2);
     97 	if (rv != 2)
     98 		return (0);
     99 	return (id);
    100 }
    101 
    102 hpibsend(unit, slave, sec, buf, cnt)
    103 	int unit, slave;
    104 	char *buf;
    105 	int cnt;
    106 {
    107 	if (hpib_softc[unit].sc_type == HPIBC)
    108 		return (fhpibsend(unit, slave, sec, buf, cnt));
    109 	return (nhpibsend(unit, slave, sec, buf, cnt));
    110 }
    111 
    112 hpibrecv(unit, slave, sec, buf, cnt)
    113 	int unit, slave;
    114 	char *buf;
    115 	int cnt;
    116 {
    117 	if (hpib_softc[unit].sc_type == HPIBC)
    118 		return (fhpibrecv(unit, slave, sec, buf, cnt));
    119 	return (nhpibrecv(unit, slave, sec, buf, cnt));
    120 }
    121 
    122 hpibswait(unit, slave)
    123 	register int unit, slave;
    124 {
    125 	register int timo = 1000000;
    126 	register int (*poll)();
    127 
    128 	slave = 0x80 >> slave;
    129 	if (hpib_softc[unit].sc_type == HPIBC)
    130 		poll = fhpibppoll;
    131 	else
    132 		poll = nhpibppoll;
    133 	while (((*poll)(unit) & slave) == 0)
    134 		if (--timo == 0)
    135 			break;
    136 	if (timo == 0)
    137 		return (-1);
    138 	return (0);
    139 }
    140 
    141 hpibgo(unit, slave, sec, addr, count, flag)
    142 	int unit, slave;
    143 	char *addr;
    144 {
    145 	if (hpib_softc[unit].sc_type == HPIBC)
    146 		if (flag == F_READ)
    147 			fhpibrecv(unit, slave, sec, addr, count);
    148 		else
    149 			fhpibsend(unit, slave, sec, addr, count);
    150 	else
    151 		if (flag == F_READ)
    152 			nhpibrecv(unit, slave, sec, addr, count);
    153 		else
    154 			nhpibsend(unit, slave, sec, addr, count);
    155 }
    156