/****************************************************************************/
/* Copyright 1992, 1993 MBARI                                               */
/****************************************************************************/
/* Summary  : IBC Board Interface Functions for VxWorks                     */
/* Filename : switch.h                                                      */
/* Author   : Andrew Pearce                                                 */
/* Project  : New ROV                                                       */
/* Version  : Version 1.0                                                   */
/* Created  : 10/01/92                                                      */
/* Modified : 10/04/92                                                      */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/* $Header: switch.h,v 1.1 93/07/01 14:38:17 pean Exp $
 * $Log:        switch.h,v $
 * Revision 1.1  93/07/01  14:38:17  14:38:17  pean (Andrew Pearce)
 * Initial revision
 *
 *
 */
/****************************************************************************/

#define MAX_SWITCH_NAME         32      /* Maxium length of switch name      */

struct switchEntry
{
    Char          name[MAX_SWITCH_NAME];/* Switch Device Name               */

                                        /* These items map a device to the  */
                                        /* actual IBC hardware              */
    sio32Chan     *ibcSerialChan;       /* IBC Micro Serial Channel         */
    IBC_BoardType boardType;            /* IBC Board Type                   */
    Word          boardAddr;            /* IBC Board Address                */
    Nat16         channel;              /* IBC Board Channel Number         */

    powerRequest  power;                /* Device or Bus power requirement  */

    DM_Item switchRequestDm;            /* Switch Request Data Manager Item */
    DM_Item switchStatusDm;             /* Switch Status Data Manager Item  */
    DM_Item powerRequestDm;             /* Power Request Data Manager Item  */
    DM_Item powerOkDm;                  /* Power Request Status DM Item     */

    DM_Item currentDm;                  /* Current Alarm Data Manager Items */
    DM_Item currentWarnThreshDm;
    DM_Item currentAlarmThreshDm;
    DM_Item currentAlarmDm;

    DM_Item temperatureDm;              /* Temperature Alarm DM Items       */
    DM_Item tempWarnThreshDm;
    DM_Item tempAlarmThreshDm;
    DM_Item tempAlarmDm;

    DM_Item tripAlarmDm;                /* Trip Alarm for HPS boards        */
    Word    gfBoardAddr;                /* GF Board connected to this device*/
                                        /* This optional item allows the GF */
                                        /* scanning to be restarted when the*/
                                        /* device is switched on            */

    SEM_ID switchReqSem;                /* Wakeup sem for switch request    */
    SEM_ID powerReqSem;                 /* Wakeup sem for power request     */

    struct switchEntry  *busHead;       /* 1st switch on switch output bus  */
    struct switchEntry  *busNext;       /* next peer switch on switch bus   */
    struct switchEntry  *seriesSwitch;  /* previous switch that is in series*/
};

typedef struct switchEntry switchEntry; /* Switch entry data structure      */

#define NO_SWITCH  (switchEntry *) NULL /* No switch in series with switch  */

#ifdef __STDC__

STATUS initIbcSwitchEntry(Reg switchEntry *devSwitch, sio32Chan *ibcSerialChan,
        Nat16 power,    systemBus bus,   loadDivision division,
        IBC_BoardType boardType,  Word   boardAddr,  Nat16 channel,
        char* switchReqName, char* switchStatusName, SEM_ID switchReqSem,
        char* powerReqName,  char* powerOkName,      SEM_ID powerReqSem,
        const char *dataConName, const char* itemName);

Void ibcAddSwitchInSeries( switchEntry *prevSwitch, switchEntry *thiswitch );
Void ibcConnectSwitchInSeries( switchEntry *seriesSwitch, switchEntry *sw );
Void ibcSetSwitchState( Reg switchEntry *sw, switchStatus switchState );
Void ibcSwitchPowerError( Reg switchEntry *sw );

switchStatus ibcProcessSwitchRequest( Reg switchEntry *sw );
switchStatus ibcSwitchDmState( Reg switchEntry *sw );
switchStatus ibcSwitchRequestDmState( Reg switchEntry *sw );

STATUS ibcSwitchControl( sio32Chan *ibcSerialChan, IBC_BoardType boardType,
    Word boardAddr, Nat16 channel, MBool desiredState );

STATUS staticPowerMgrRequest( char* powerReqName, char *powerOkName,
    Nat16 power, systemBus bus, loadDivision division );

STATUS duplicateIbcSwitchEntry( Reg switchEntry *devSwitch,
    char* switchReqName,     char* switchStatusName,  SEM_ID switchReqSem,
    const char *dataConName, const char* itemName);

STATUS ibcSwitchGangOutputs( Reg switchEntry *devSwitch );

STATUS ibcSwitchSetCurrentThresh( Reg switchEntry *devSwitch,
    Nat16 warnThresh, Nat16 alarmThresh );

Void ibcProcessDupSwitchRequest( Reg switchEntry *sw );

STATUS ibcSetSwitchStateOff( Reg switchEntry *sw );

#endif /* __STDC__ */

