Home | History | Annotate | Line # | Download | only in gpib
      1 /*	$NetBSD: gpibvar.h,v 1.5 2012/10/27 17:18:16 chs Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2003 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Gregory McGarry.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/queue.h>
     33 
     34 #define GPIB_NDEVS		30	/* max address */
     35 #define GPIB_ADDRMASK		0x1f	/* address mask */
     36 #define GPIB_BROADCAST_ADDR	31	/* GPIB broadcast address */
     37 
     38 /*
     39  * GPIB commands
     40  */
     41 
     42 /* Universal command group (UCG) [0x10] */
     43 #define GPIBCMD_LLO		0x11	/* local lockout */
     44 #define	GPIBCMD_DCL		0x14	/* universal device clear */
     45 #define GPIBCMD_PPU		0x15	/* parallel poll unconfigure */
     46 #define GPIBCMD_SPE		0x18
     47 #define GPIBCMD_SPD		0x19
     48 
     49 /* Addressed command group (ACG) [0x00] */
     50 #define GPIBCMD_GTL		0x01
     51 #define	GPIBCMD_SDC		0x04	/* selected device clear */
     52 #define GPIBCMD_PPC		0x05 	/* parallel poll clear */
     53 #define GPIBCMD_GET		0x08
     54 #define GPIBCMD_TCT		0x09
     55 
     56 #define	GPIBCMD_LAG		0x20	/* listener address group commands */
     57 #define	GPIBCMD_UNL		0x3f	/* universal unlisten */
     58 #define	GPIBCMD_TAG		0x40	/* talker address group commands */
     59 #define	GPIBCMD_UNA		0x5e	/* unaddress (master talk address?) */
     60 #define	GPIBCMD_UNT		0x5f	/* universal untalk */
     61 #define	GPIBCMD_SCG		0x60	/* secondary group commands */
     62 #define GPIBCMD_PPD		0x70
     63 #define GPIBCMD_DEL		0x7f
     64 
     65 struct gpib_softc;
     66 
     67 struct gpib_chipset_tag {
     68 	void	(*reset)(void *);
     69 	int	(*send)(void *, int, int, void *, int);
     70 	int	(*recv)(void *, int, int, void *, int);
     71 	int	(*pptest)(void *, int);
     72 	void	(*ppwatch)(void *, int);
     73 	void	(*ppclear)(void *);
     74 	void	(*xfer)(void *, int, int, void *, int, int, int);
     75 	int	(*tc)(void *, int);
     76 	int	(*gts)(void *);
     77 	void	(*ifc)(void *);
     78 	int	(*sendcmds)(void *, void *, int);
     79 	int	(*senddata)(void *, void *, int);
     80 	int	(*recvdata)(void *, void *, int);
     81 	void	*cookie;
     82 	struct gpib_softc *bus;
     83 };
     84 typedef struct gpib_chipset_tag *gpib_chipset_tag_t;
     85 
     86 /*
     87  * Wrapper functions that go directly to the hardware driver.
     88  */
     89 #define gpibreset(ic)							\
     90 	(*((ic)->reset))((ic)->cookie)
     91 #define gpibpptest(ic, slave)						\
     92 	(*((ic)->pptest))((ic)->cookie, (slave))
     93 #define gpibppclear(ic)							\
     94 	(*((ic)->ppclear))((ic)->cookie)
     95 #define gpibxfer(ic, slave, sec, buf, cnt, rw, timo)			\
     96 	(*((ic)->xfer))((ic)->cookie, (slave), (sec), (buf), (cnt),	\
     97 	    (rw), (timo))
     98 
     99 /*
    100  * An GPIB job queue entry.  Slave drivers have one of these used
    101  * to queue requests with the controller.
    102  */
    103 typedef void (*gpib_callback_t)(void *, int);
    104 struct gpibqueue {
    105 	TAILQ_ENTRY(gpibqueue) hq_list;	/* entry on queue */
    106 	void	*hq_softc;		/* slave's softc */
    107 	int	hq_slave;		/* slave on bus */
    108 	gpib_callback_t hq_callback;	/* slave's callback function */
    109 };
    110 typedef struct gpibqueue *gpib_handle_t;
    111 
    112 int	_gpibregister(struct gpib_softc *, int, void (*cb)(void *, int),
    113 	    void *, gpib_handle_t *);
    114 int	_gpibrequest(struct gpib_softc *, gpib_handle_t);
    115 void	_gpibrelease(struct gpib_softc *, gpib_handle_t);
    116 int	_gpibswait(struct gpib_softc *, int);
    117 void	_gpibawait(struct gpib_softc *);
    118 int	_gpibsend(struct gpib_softc *, int, int, void *, int);
    119 int	_gpibrecv(struct gpib_softc *, int, int, void *, int);
    120 
    121 #define gpibsend(ic, slave, sec, addr, cnt)				\
    122 	_gpibsend((ic)->bus, (slave), (sec), (addr), (cnt))
    123 #define gpibrecv(ic, slave, sec, addr, cnt)				\
    124 	_gpibrecv((ic)->bus, (slave), (sec), (addr), (cnt))
    125 #define gpibregister(ic, slave, callback, arg, hdlp)		\
    126 	_gpibregister((ic)->bus, (slave), (callback), (arg), (hdlp))
    127 #define gpibrequest(ic, hdl)					\
    128 	_gpibrequest((ic)->bus, hdl)
    129 #define gpibrelease(ic, hdl)					\
    130 	_gpibrelease((ic)->bus, hdl)
    131 #define gpibawait(ic)						\
    132 	_gpibawait((ic)->bus)
    133 #define gpibswait(ic, slave)					\
    134 	_gpibswait((ic)->bus, (slave))
    135 
    136 int	gpib_alloc(struct gpib_softc *, u_int8_t);
    137 int	gpib_isalloc(struct gpib_softc *, u_int8_t);
    138 void	gpib_dealloc(struct gpib_softc *, u_int8_t);
    139 
    140 /* called from controller drivers only */
    141 int	gpibintr(void *);
    142 int	gpibdevprint(void *, const char *);
    143 
    144 /* callback flags */
    145 #define GPIBCBF_START		1
    146 #define GPIBCBF_INTR		2
    147 
    148 /* gpibxfer dir(ection) parameter */
    149 #define GPIB_READ		1
    150 #define GPIB_WRITE		2
    151 
    152 /*
    153  * Attach devices
    154  */
    155 struct gpib_attach_args {
    156 	gpib_chipset_tag_t ga_ic;		/* GPIB chipset tag */
    157 	int ga_address;				/* device GPIB address */
    158 };
    159 
    160 /*
    161  * Attach a GPIB to controller.
    162  */
    163 struct gpibdev_attach_args {
    164 	gpib_chipset_tag_t ga_ic;		/* GPIB chipset tag */
    165 	int ga_address;				/* host GPIB address */
    166 };
    167 
    168 /*
    169  * Software state per GPIB bus.
    170  */
    171 struct gpib_softc {
    172 	device_t sc_dev;			/* generic device glue */
    173 	gpib_chipset_tag_t sc_ic;		/* GPIB chipset tag */
    174 	u_int8_t sc_myaddr;			/* my (host) GPIB address */
    175 	int sc_flags;
    176 #define GPIBF_ACTIVE	0x01
    177 	u_int32_t sc_rmap;			/* resource map */
    178 	TAILQ_HEAD(, gpibqueue) sc_queue;	/* GPIB job queue */
    179 };
    180