/****************************************************************************/
/* Copyright 1992, 1993 MBARI                                               */
/****************************************************************************/
/* Summary  : IBC High Power Switch Board Definitions                       */
/* Filename : high_pwr.h                                                    */
/* Author   : Andrew Pearce                                                 */
/* Project  : New ROV Data Concentrator                                     */
/* Version  : 1.0                                                           */
/* Created  : 09/17/92                                                      */
/* Modified : 03/05/93                                                      */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/* $Header: /usr/tiburon/.cvsroot/micro/h/high_pwr.h,v 1.1.1.1 1997/05/02 17:15:38 pean Exp $
 * $Log: high_pwr.h,v $
 * Revision 1.1.1.1  1997/05/02 17:15:38  pean
 * Initial release of the microcontroller software after Tiburon
 * Moolpool Dive to test IView, Lapboxes, modified Power can
 * GF/5V using bus capacitance mode.
 *
 * Revision 1.2  93/07/02  09:32:20  09:32:20  pean (Andrew Pearce)
 * Minor bug fixes and enhancements for Prototype Vehicle Tests
 *
 * Revision 1.1  93/03/05  14:23:37  14:23:37  pean (Andrew Pearce)
 * Initial revision
 *
*/
/****************************************************************************/

                                /* High Power Switch Board Register Offsets */
#define HPS_COMMAND_REG   0x00  /* Command Register                         */
#define HPS_STATUS_REG    0x00  /* Status Register                          */

#define HPS_ADC_HIGH      0x00  /* A to D Result High Byte                  */
#define HPS_ADC_LOW       0x01  /* A to D Result Low Byte                   */

#define HPS_TIMEOUT          2  /* A to D conversion timeout (20 msec)      */
#define HPS_NO_ADC_BOARD     0  /* Value returned if A to D not installed   */

                                /* High Power Switch Command Register Bits  */
#define HPS_INTERRUPT_ON  0x01  /* Set Interrupt Request bit ON             */
#define HPS_ADC_SELECT    0x02  /* Select A to D convertor for reading      */
#define HPS_SWITCH_ON     0x04  /* Switch State to ON Command               */

                                /* High Power Switch Status Register Bits   */
#define HPS_RELAY_ON      0x01  /* Relay State Bit                          */
#define HPS_ADC_DONE      0x02  /* A/D Conversion Done Bit                  */
#define HPS_SWITCH_STATE  0x04  /* Switch State Bit                         */

#define HPS_CURRENT_WARNING      20000  /* Default current warning 20 amps  */
#define HPS_CURRENT_ALARM        30000  /* Default current alarm 30 amps    */
#define HPS_CURRENT_HYSTERESIS    1000  /* Current hysteresis: 1 amp        */

#define HPS_MAX_CURRENT          32000  /* Maximum current measurement      */

                                        /* Current(mA) = raw A/D * 7.6mA/bit*/
#define HPS_MILLIAMPS(bits)    (( (Nat32) bits * 76) / 10)

typedef struct                          /* High Power Switch Data Structure */
{
    IBC_BoardEntry IBC_Board;           /* IBC Board Entry structure        */
    Nat16   currentWarning;             /* Current Warning Threshold mA     */
    Nat16   currentAlarm;               /* Current Alarm Threshold mA       */
    Int16   filteredCurrent;            /* Filtered Current Measurement mA  */
    filterParam filter;                 /* Current Filter Parameters        */

    Byte    cmdReg;                     /* Copy of command register         */

    struct
    {
        unsigned adcInstalled   : 1;    /* A to D option installed flag     */
        unsigned tripDetected   : 1;    /* Hardware trip detected flag      */
        unsigned switchState    : 1;    /* Software copy of switch state    */
        unsigned currentAlarm   : 2;    /* Current Alarm Status             */
    } status;
} HPS_BoardEntry;

#ifdef __STDC__

Int16 HPS_BoardSearch( IBC_BoardEntry *IBC_Boards[], Int16 maxCards );

                           /* High Power Switch Board Initialization Routine*/
HPS_BoardEntry* HPS_BoardInit( Byte *boardBaseAddr );

Int16 HPS_BoardSwitch( HPS_BoardEntry *HPS_Board, Boolean state );

Int16 HPS_BoardSwitchState( HPS_BoardEntry *HPS_Board );

Int16 HPS_BoardSwitchCurrent( HPS_BoardEntry *HPS_Board );

Void HPS_BoardInterruptOn( HPS_BoardEntry *HPS_Board );

Void HPS_BoardInterruptOff( HPS_BoardEntry *HPS_Board );

Void HPS_BoardIsr( HPS_BoardEntry *HPS_Board );

Void HPS_SwitchControlCmd( IBC_BoardEntry* IBC_CardTable[],
    Int16 IBC_CardCount, Byte *commandBuf );

Void HPS_SwitchStatusCmd( IBC_BoardEntry* IBC_CardTable[],
    Int16 IBC_CardCount, Byte *commandBuf );

Void HPS_ReadCurrentCmd( IBC_BoardEntry* IBC_CardTable[],
    Int16 IBC_CardCount, Byte *commandBuf );

Void HPS_SetCurrentThreshCmd( IBC_BoardEntry* IBC_CardTable[],
    Int16 IBC_CardCount, Byte *commandBuf );

Void HPS_GetCurrentThreshCmd( IBC_BoardEntry* IBC_CardTable[],
    Int16 IBC_CardCount, Byte *commandBuf );

Void HPS_GetAlarmStatusCmd( IBC_BoardEntry* IBC_CardTable[],
    Int16 IBC_CardCount, Byte *commandBuf );

Void HPS_BoardFunctions( HPS_BoardEntry *HPS_Board );

#endif

