/****************************************************************************/
/* Copyright 1991 to 1993, MBARI                                            */
/****************************************************************************/
/* Summary  : VME CAN Data Concentrator - Main C Source file                */
/* Filename : vme_ibc.h                                                     */
/* Author   : Andrew Pearce                                                 */
/* Project  : New ROV IBC CPU Board Rev 1.0                                 */
/* Version  : 1.0                                                           */
/* Created  : 10/01/91                                                      */
/* Modified : 04/07/93                                                      */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/* $Header: /usr/tiburon/.cvsroot/micro/h/vme_ibc.h,v 1.1.1.1 1997/05/02 17:15:42 pean Exp $
 * $Log: vme_ibc.h,v $
 * Revision 1.1.1.1  1997/05/02 17:15:42  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.5  96/02/16  10:48:47  10:48:47  pean (Andrew Pearce)
 * Revised GF/5V Selftest, scan update features
 * Fixed timer_cancel library function
 * Revised Quad Serial Board Overrun Error reporting
 *
 * Revision 1.5  95/11/10  08:44:39  08:44:39  pean (Andrew Pearce)
 * Added support for VME Video Switcher using upgraded PIO Board Library
 *
 * Revision 1.4  95/09/13  17:28:57  17:28:57  pean (Andrew Pearce)
 * Minor changes to LPS Board for voltage measurement
 * Tested KVH Compass modifications
 *
 * Revision 1.3  93/10/11  08:57:11  08:57:11  pean (Andrew Pearce)
 * Added Accelerometer support and fixed PIC problem
 *
 * Revision 1.2  93/07/14  12:10:28  12:10:28  pean (Andrew Pearce)
 * Removed serial board open left in by accident.
 * Updated ground fault, LPS and HPS board libraries
 *
 * Revision 1.1  93/07/02  09:43:24  09:43:24  pean (Andrew Pearce)
 * Initial revision
 *
 *
*/
/****************************************************************************/

                                        /* VME IBC A/D Channel Assignments  */
#define YAW_RATE_SENSOR_CHAN    0       /* Gyro Yaw rate sensor channel     */
#define ROLL_SENSOR_CHAN        1       /* Roll Sensor channel              */
#define PITCH_SENSOR_CHAN       2       /* Pitch Sensor channel             */
#define VME_SPARE_ATOD_CHAN     3       /* Spare A/D channel                */

                                        /* VME IBC Quad Serial Channels     */
#define KVH_COMPASS_CHAN        0       /* Kvh compass channel              */
#define VIDEO_TELEM_CHAN        1       /* Video telemetery status          */

#define WATER_ALARM_CHAN_0      1       /* Water Alarm 0 Analog Channel     */
#define WATER_ALARM_CHAN_1      2       /* Water Alarm 1 Analog Channel     */

#define WATER_ALARM0_BIT     0x01       /* Water Alarm 0 Status Bit         */
#define WATER_ALARM1_BIT     0x02       /* Water Alarm 1 Status Bit         */

#define VME_IBC_MAX_PITCH   65536
#define VME_IBC_MAX_ROLL    65536
#define VME_IBC_MAX_YAW     65536

                                        /* Water Alarm Threshold is 0.5V    */
#define WATER_ALARM_THRESHOLD 103       /* 103 = 2^10 * 0.5/5.0             */
#define WATER_ALARM_HYSTERESIS 10       /* 10 counts = 0.049 volts          */

#define NUM_VME_VIDEO_RELAYS   12       /* Number of Video Control Relays   */

                                        /* Parallel IO Board Port Assignment*/
                                        /* PORT A (Output) Assignments      */
#define VIDEO_RELAY_E1       0x01       /* Video Switch Relay E1 Control    */
#define VIDEO_RELAY_E2       0x02       /* Video Switch Relay E2 Control    */
#define VIDEO_RELAY_F1       0x04       /* Video Switch Relay F1 Control    */
#define VIDEO_RELAY_F2       0x08       /* Video Switch Relay F2 Control    */


#define VME_PSU_MODULE_1     0x00       /* Select Mask for VME PSU 1        */
#define VME_PSU_MODULE_2     0x40       /* Select Mask for VME PSU 2        */
#define VME_PSU_MODULE_3     0x80       /* Select Mask for VME PSU 3        */
#define VME_PSU_MODULE_4     0xc0       /* Select Mask for VME PSU 4        */
#define VME_PSU_BIT_MASK     0xc0       /* Masks off VME PSU Select Bits    */

                                        /* PORT B (Input) Assignments       */
                                        /* Power Supply Status Bit Fields   */
#define PSU_5V_A1_OK         0x01       /* +5 Volt PSU A1 (0=Fail, 1=OK)    */
#define PSU_5V_B1_OK         0x02       /* +5 Volt PSU B1 (0=Fail, 1=OK)    */
#define PSU_5V_A2_OK         0x04       /* +5 Volt PSU A2 (0=Fail, 1=OK)    */
#define PSU_5V_B2_OK         0x08       /* +5 Volt PSU B2 (0=Fail, 1=OK)    */

#define PSU_12V_A1_OK        0x10       /* +12 Volt PSU A1 (0=Fail, 1=OK)   */
#define PSU_12V_B1_OK        0x20       /* +12 Volt PSU B1 (0=Fail, 1=OK)   */
#define PSU_12V_A2_OK        0x40       /* +12 Volt PSU A2 (0=Fail, 1=OK)   */
#define PSU_12V_B2_OK        0x80       /* +12 Volt PSU B2 (0=Fail, 1=OK)   */

                                        /* PORT C (Output) Assignments      */
#define VIDEO_RELAY_A1       0x0100     /* Video Switch Relay A1 Control    */
#define VIDEO_RELAY_A2       0x0200     /* Video Switch Relay A2 Control    */
#define VIDEO_RELAY_B1       0x0400     /* Video Switch Relay B1 Control    */
#define VIDEO_RELAY_B2       0x0800     /* Video Switch Relay B2 Control    */
#define VIDEO_RELAY_C1       0x1000     /* Video Switch Relay C1 Control    */
#define VIDEO_RELAY_C2       0x2000     /* Video Switch Relay C2 Control    */
#define VIDEO_RELAY_D1       0x4000     /* Video Switch Relay D1 Control    */
#define VIDEO_RELAY_D2       0x8000     /* Video Switch Relay D2 Control    */


typedef enum
{
    KVH_CAL_START,
    KVH_CAL_RUNNING,
    KVH_CAL_END
} kvhCalState;

#define KVH_STRING_LEN   64

                                        /* *** VME IBC Serial Commands **** */
#define GET_VME_WATER_ALARM        0x01 /* Get Water Alarm Status Word      */
#define GET_VME_WATER_ALARM_THRESH 0x02 /* Get Water Alarm Threshold Value  */
#define SET_VME_WATER_ALARM_THRESH 0x03 /* Set Water Alarm Threshold Value  */
#define GET_VME_SENSOR_DATA        0x04 /* Get sensor data                  */
#define GET_VME_CAN_PSU_STATUS     0x05 /* Get VME Can PSU Status Word      */
#define SET_VIDEO_SWITCH           0x06 /* Set VME Can Video Switch         */
#define GET_VIDEO_SWITCH           0x07 /* Get VME Can Video Switch         */
#define CALIBRATE_KVH_COMPASS      0x08 /* Calibrate KVH Compass            */
#define SEND_KVH_COMPASS_STRING    0x09 /* Send KVH Compass a string        */

#define WATER_ALARM0_ON_SRQ      APPLIC_SRQ_BASE | 0xC0
#define WATER_ALARM0_OFF_SRQ     APPLIC_SRQ_BASE | 0xC1

#define WATER_ALARM1_ON_SRQ      APPLIC_SRQ_BASE | 0xC2
#define WATER_ALARM1_OFF_SRQ     APPLIC_SRQ_BASE | 0xC3
#define VME_CAN_PSU_ERROR_SRQ    APPLIC_SRQ_BASE | 0xC4

#define VIDEO_TELEM_XXX0_SRQ     APPLIC_SRQ_BASE | 0xC5
#define VIDEO_TELEM_XXX1_SRQ     APPLIC_SRQ_BASE | 0xC6
#define VIDEO_TELEM_XXX2_SRQ     APPLIC_SRQ_BASE | 0xC7
#define VIDEO_TELEM_XXX3_SRQ     APPLIC_SRQ_BASE | 0xC9
#define VIDEO_TELEM_XXX4_SRQ     APPLIC_SRQ_BASE | 0xCA
#define VIDEO_TELEM_XXX5_SRQ     APPLIC_SRQ_BASE | 0xCB

#define KVH_COMPASS_CAL_SRQ      APPLIC_SRQ_BASE | 0xD0
#define KVH_COMPASS_CAL_DATA_SRQ APPLIC_SRQ_BASE | 0xD1
