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