/****************************************************************************/
/* Copyright 1992, 1993 MBARI                                               */
/****************************************************************************/
/* Summary  : IBC Quad 16 bit A to D Board Functions                        */
/* Filename : atod.h                                                        */
/* Author   : Andrew Pearce                                                 */
/* Project  : New ROV Data Concentrator                                     */
/* Version  : 1.0                                                           */
/* Created  : 09/17/92                                                      */
/* Modified : 03/25/93                                                      */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/* $Header: /usr/tiburon/.cvsroot/micro/h/atod.h,v 1.1.1.1 1997/05/02 17:15:37 pean Exp $
 * $Log: atod.h,v $
 * Revision 1.1.1.1  1997/05/02 17:15:37  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:20:53  09:20:53  pean (Andrew Pearce)
 * Minor bug fixes and enhancements for Prototype Vehicle Testing
 *
 * Revision 1.1  93/03/26  15:43:11  15:43:11  pean (Andrew Pearce)
 * Initial revision
 *
 *
*/
/****************************************************************************/

                                        /* A/D Board Register Offsets       */
#define AtoD_AtoD_REG   0               /* A/D Command and Data Register    */

#define AtoD_MAX_CHANS  4               /* Number of A/D channels per board */
                                        /* A/D Convertor Command Words      */
#define AtoD_POWER_DOWN 0               /* Power Down Convertor Command     */
#define AtoD_CHAN_0     1               /* Start conversion for channel 0   */
#define AtoD_CHAN_1     2               /* Start conversion for channel 1   */
#define AtoD_CHAN_2     3               /* Start conversion for channel 2   */
#define AtoD_CHAN_3     4               /* Start conversion for channel 3   */
#define AtoD_DISABLE    7               /* Disable Convertor Command        */

                                        /* Convert unipolar to bipolar      */
#define ATOD_BIPOLAR(bits) (Int16) (bits - 0x8000)


typedef struct                          /* A/D Board Data Structure         */
{
    IBC_BoardEntry IBC_Board;           /* IBC Board Entry structure        */

    Byte  AtoDChannel;                  /* Channel presently being measured */
    Byte  convertorBusy;                /* A/D Conversion in progress       */
    Word  raw_AtoD[AtoD_MAX_CHANS];     /* Raw A/D readings for all channels*/
} AtoD_BoardEntry;


#ifdef __STDC__

Int16 AtoD_BoardSearch( IBC_BoardEntry *IBC_Boards[], Int16 maxCards );

                                          /* A to D Board Initialize routine*/
AtoD_BoardEntry* AtoD_BoardInit( Byte *boardBaseAddr );

Int16 AtoD_BoardCommand( AtoD_BoardEntry *AtoD_Board, Byte command );

Void AtoD_BoardInterruptOn( AtoD_BoardEntry *AtoD_Board );

Void AtoD_BoardInterruptOff( AtoD_BoardEntry *AtoD_Board );

Void AtoD_BoardIsr( AtoD_BoardEntry *AtoD_Board );

Nat16 AtoD_RawAtoDValue( AtoD_BoardEntry *AtoD_Board, Int16 channel );

Void AtoD_RawAtoDValuesCmd( IBC_BoardEntry* IBC_CardTable[],
     Int16 IBC_CardCount, Byte *commandBuf );

Void AtoD_RawAtoDCmd( IBC_BoardEntry* IBC_CardTable[], Int16 IBC_CardCount,
         Byte *commandBuf );

Void AtoD_ConvertorEnableCmd( IBC_BoardEntry* IBC_CardTable[],
         Int16 IBC_CardCount, Byte *commandBuf );

Void AtoD_ConvertorDisableCmd( IBC_BoardEntry* IBC_CardTable[],
         Int16 IBC_CardCount, Byte *commandBuf );

Void AtoD_StartConversions( AtoD_BoardEntry *AtoD_Board );

Void AtoD_BoardFunctions( AtoD_BoardEntry *AtoD_Board );

#endif

