/****************************************************************************/
/* Copyright 1992 to 1994, MBARI                                            */
/****************************************************************************/
/* Summary  : IBC Isolated I/O Board Interface for VxWorks                  */
/* Filename : iso_io.c                                                      */
/* Author   : Andrew Pearce                                                 */
/* Project  : New ROV                                                       */
/* Version  : Version 1.0                                                   */
/* Created  : 04/08/93                                                      */
/* Modified : 06/08/93                                                      */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/* $Header: $
 * $Log: $
 */
/****************************************************************************/

#include <vxWorks.h>                /* vxWorks system declarations          */
#include <semLib.h>                 /* vxWorks semaphore functions          */
#include <wdLib.h>                  /* vxWorks watch dog timer support decls*/
#include <msgQLib.h>                /* vxWorks Message Queue Library        */

#include <mbariTypes.h>             /* mbari style guide type declarations  */
#include <mbariConst.h>             /* Miscellaneous constants              */

#include "sio32.h"                  /* SIO32 hardware and driver information*/
#include <sio32Server.h>            /* Sio32 server communication services  */
#include <sio32Client.h>            /* Sio32 client communication services  */
#include <microCmd.h>               /* Microcontoller command functions     */

#include "microdef.h"               /* Microcontroller definitions          */
#include "applic.h"                 /* Microcontroller applications         */
#include "microcmd.h"               /* Microcontroller commands             */
#include "ibc_card.h"               /* IBC Card Types                       */
#include "filter.h"                 /* General Filter Routines              */
#include "ibc_cmd.h"                /* IBC Card Serial Commands             */

#include "iso_io.h"                 /* Application Function Prototypes      */

/****************************************************************************/
/* Function    : IBC_ISO_IO_OutputCtrl                                      */
/* Purpose     : Sets state of IBC ISO IO Output Bit                        */
/* Inputs      : Sio32 channel, IBC Board Address, Channel, Desired state   */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    STATUS
IBC_ISO_IO_OutputCtrl( sio32Chan *IBC_SerialChan, Word boardAddr,
                Nat16 channel, MBool desiredState )
{
    Word    status;                 /* Command Result from microcontroller  */

                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( IBC_SerialChan, &status, sizeof(status),
         4, IBC_CPU_APP | ISO_IO_WRITE_PORT_BIT, boardAddr,
         channel, desiredState) == ERROR ) return(ERROR);

                                    /* Check command result                  */
    return (wordFromBuf(&status, 0) == CMD_OK ? OK : ERROR);
} /* IBC_ISO_IO_OutputCtrl() */

/****************************************************************************/
/* Function    : IBC_ISO_IO_WritePort                                       */
/* Purpose     : Sets state of IBC ISO IO Output Port                       */
/* Inputs      : Sio32 channel, IBC Board Address, Desired Port Value       */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    STATUS
IBC_ISO_IO_WritePort( sio32Chan *IBC_SerialChan, Word boardAddr, Byte portVal )
{
    Word    status;                 /* Command Result from microcontroller  */

                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( IBC_SerialChan, &status, sizeof(status),
         4, IBC_CPU_APP | ISO_IO_WRITE_PORT, boardAddr, (Word) portVal)
         == ERROR ) return(ERROR);

                                    /* Check command result                  */
    return (wordFromBuf(&status, 0) == CMD_OK ? OK : ERROR);
} /* IBC_ISO_IO_WritePort() */

/****************************************************************************/
/* Function    : IBC_ISO_IO_SetDacLevel                                     */
/* Purpose     : Sets state of IBC ISO IO DAC Output Channel                */
/* Inputs      : Sio32 channel, IBC Board Address, Channel, Desired state   */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    STATUS
IBC_ISO_IO_SetDacLevel( sio32Chan *IBC_SerialChan, Word boardAddr,
                Nat16 channel, Byte level )
{
    Word    status;                 /* Command Result from microcontroller  */

                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( IBC_SerialChan, &status, sizeof(status),
         4, IBC_CPU_APP | ISO_IO_WRITE_DAC, boardAddr,
         channel, (Word) level ) == ERROR ) return(ERROR);

                                    /* Check command result                  */
    return (wordFromBuf(&status, 0) == CMD_OK ? OK : ERROR);
} /* IBC_ISO_IO_SetDacLevel() */


