/******************************************************************************
 *
 * drvHwGpibInterface.h,v
 *
 ******************************************************************************/
/***********************************************************************
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory, and the Regents of the University of
* California, as Operator of Los Alamos National Laboratory, and
* Berliner Elektronenspeicherring-Gesellschaft m.b.H. (BESSY).
* gpibCore is distributed subject to a Software License Agreement
* found in file LICENSE that is included with this distribution.
***********************************************************************/
/*
 *    Low level interface between generic and hardware GPIB drivers
 *
 * Author: Benjamin Franksen
 * Original Author: John Winans
 */
#ifndef DRVHWGPIBINTERFACE_H
#define DRVHWGPIBINTERFACE_H
#include "drvGpib.h"
#include "ellLib.h"
#include "epicsEvent.h"
#include "epicsMutex.h"
#include "epicsRingBytes.h"
#include "epicsThread.h"
#ifdef __cplusplus
extern "C" {
#endif	/* __cplusplus */

#define TADBASE    0x40	/* offset to GPIB listen address 0 */
#define LADBASE    0x20	/* offset to GPIB talk address 0 */
#define SADBASE    0x60	/* offset to GPIB secondary address 0 */
typedef struct ibLinkDevice ibLinkDevice;
typedef struct drvHwGpibEt drvHwGpibEt;
/******************************************************************************
 * The ibLink structure holds all the required link-specific data.
 ******************************************************************************/
struct ibLink {
    struct ibLink *next;	/* chain pointer */
    int link;
    int secToDeath;	        /* call probe after this number of seconds */
    epicsEventId linkEvent;	/* given when this link requires service */
    ELLLIST hiPriList;	        /* list head for high priority queue */
    epicsMutexId hiPriLock;	/* semaphore for high priority queue */
    ELLLIST loPriList;	        /* list head for low priority queue */
    epicsMutexId loPriLock;	/* semaphore for low priority queue */
    epicsRingBytesId srqRing;	/* srq event queue */
    char srqIntFlag;	        /* set to 1 if an SRQ interrupt has occurred */
    epicsEventId waitLinkTask;	/* drvGpibLinkStart waits for linkTask */
    epicsEventId waitRestart;	/* linkTask is waiting for a restart request */
    int ctrlAddr;	        /* gpib address of the controller */
    epicsMutexId mutex;	        /* lock the pollInhibit array */
    char disabled;	        /* link is disabled */
    /* pprimaryDevice is a array of pointers to ibLinkDevice */
    /* storage only allocated if a device is referenced */
    ibLinkDevice *pprimaryDevice[IBAPERLINK];
    drvHwGpibEt *pdrvHwGpibEt;	/* interface to low-level driver */
};
/******************************************************************************
 *
 * Call interface of low level drivers.
 *
 ******************************************************************************/
struct drvHwGpibEt {
    long (*genLink) (ibLink * pibLink, int pass);
    long (*destroyLink) (ibLink * pibLink);
    long (*reportLink) (ibLink * pibLink, int level);
    long (*probe) (ibLink * pibLink);
    long (*read) (ibLink * pibLink, int gpibAddr, int secondary,
        char *data, int length, int timeout, int eos);
    long (*write) (ibLink * pibLink, int gpibAddr, int secondary,
        char *data, int length, int timeout);
    long (*addressedCmd) (ibLink * pibLink, int gpibAddr, int secondary,
        char *data, int length, int timeout);
    long (*universalCmd) (ibLink * pibLink, int cmd);
    long (*ifc) (ibLink * pibLink);
    long (*ren) (ibLink * pibLink, int onOff);
    long (*srqStatus) (ibLink * pibLink);
    long (*srqEnable) (ibLink * pibLink);
    long (*srqDisable) (ibLink * pibLink);
    long (*serialPollBegin) (ibLink * pibLink);
    long (*serialPoll) (ibLink * pibLink, int gpibAddr, int secondary,
        int timeout);
    long (*serialPollEnd) (ibLink * pibLink);
};

#ifdef __cplusplus
}
#endif	/* __cplusplus */
/*
 * drvHwGpibInterface.h,v
 * Revision 1.8  2003/04/10 15:17:04  mrk
 * open source license
 *
 * Revision 1.7  2003/03/14 16:46:55  mrk
 * Changes for March 2003 version
 *
 * Revision 1.6  2003/02/13 14:13:29  mrk
 * changes for automatic registration
 *
 * Revision 1.5  2002/11/05 20:41:09  norume
 * Change the drvHwGpibEt serialPoll function to return a long instead of
 * an unsigned char.  This allows for the possibility of returning an
 * error status (-1) should the device not respond to the serial poll request.
 *
 * Revision 1.4  2002/11/05 19:38:11  norume
 * Back out previous change for now.
 *
 * Revision 1.3  2002/11/05 18:15:24  norume
 * Change the drvHwGpibEt serialPoll function to return a long instead of
 * an unsigned char.  This allows for the possibility of returning an
 * error status (-1) should the device not respond to the serial poll request.
 *
 * Revision 1.2  2002/11/01 19:29:58  mrk
 * More changes for ioctl replacement
 *
 * Revision 1.1  2002/10/18 17:21:08  mrk
 * moved to here
 *
 * Revision 1.6  2001/10/24 15:49:38  mrk
 * changes for baseR3.14.0beta1
 *
 * Revision 1.5  2001/10/22 19:24:01  mrk
 * loPriLock is mutex; pollInhibit must be signed
 *
 * Revision 1.4  2001/04/17 18:40:07  mrk
 * Changes to get ready for bitBus support which will be implemented with bitBus
 *
 * Revision 1.3  2001/03/05 21:54:27  mrk
 * hiPriEvent=>hiPriLock, loPriEvent=>loPriLock
 * moved shell callable routines to the end of drvGpib.c
 * Added files drvGpibRegister.c and gpibInteract.c
 *
 * Revision 1.2  2001/02/22 19:57:19  norume
 * Many, many R3.14 changes.  Driver tested on RTEMS-gen68360 and Linux.
 *
 * Revision 1.1.1.1  2001/02/15 14:52:51  mrk
 * Import sources
 *
 * Revision 1.2  2000/05/19 20:37:37  franksen
 * fixed debug messages; overhauled report functions; fixed bug in HiDEOSGpibInit;
 * adapted everything to upper/lower interface seperation
 *
 * Revision 1.1  2000/05/19 20:19:03  franksen
 * added drvGpib.h, drvHwGpibInterface.h to separate lower from upper interface
 *
 * Revision 1.2  2000/05/19 12:57:42  franksen
 * use errlogPrintf; fixed bug in drvGpibGetLink;
 * changed type of link/gpibAddr from short to int
 *
 * Revision 1.1.1.1  2000/03/21 18:06:35  franksen
 * unbundled gpib first version
 *
 *****************************************************************************/
#endif	/* DRVHWGPIBINTERFACE_H */
