/****************************************************************************/
/* Copyright 2009 - 2015 MBARI                                              */
/****************************************************************************/
/* Summary  : Definitions for Instrument Ports on Oasis5 Expander Board     */
/* Filename : inst_port.h                                                   */
/* Author   : Mike Risi (mrisi), Robert Herlien (rah)                       */
/* Project  : OASIS Mooring Replacement (OASIS5)                            */
/* Revision: 1.0                                                            */
/* Created  : 2009 by Mike Risi, Adapted for Oasis5 10/29/2015 by Bob Herlien*/
/*                                                                          */
/* MBARI provides this documentation and code "as is", with no warranty,    */
/* express or implied, of its quality or consistency. It is provided without*/
/* support and without obligation on the part of the Monterey Bay Aquarium  */
/* Research Institute to assist in its use, correction, modification, or    */
/* enhancement. This information should not be published or distributed to  */
/* third parties without specific written permission from MBARI.            */
/*                                                                          */
/****************************************************************************/
/* Modification History:                                                    */
/* 29oct2015 rah - adapted from Respirometer chamber controller             */
/****************************************************************************/

#ifndef INST_PORT_H
#define INST_PORT_H

#include <Generic.h>
#include "serial.h"

#define INST_PORT_TOTAL	SER_PORT_TOTAL
#define PWR_PORT_TOTAL	SER_PORT_TOTAL
#define PWR_PORT_MASK 	((1 << PWR_PORT_TOTAL) - 1)
#define RELAY_MS	30

/* SERIAL_TX_STAT bits */
#define TX_DATA_BIT    1
#define ERR_STAT_BIT   2

/* Bit definitions for RX_CONFIG_2 */
#define STOP_BIT        0x0001
#define DATA_PAR_BIT    0x0006
#define ENABLE_BIT      0x0008

/* Bit definitions for RX_CONFIG_3 */
#define FLUSH_RX_BIT    0x20
#define PERR_BIT        0x10
#define FERR_BIT        0x08
#define OERR_BIT        0x04
#define XERR_BIT        0x02
//#define YERR_BIT        0x01		/* FG overflow no longer possible */

/* Bit definitions for TX_CONFIG_1 */
#define FLUSH_TX_BIT    0x20
#define BREAK_TX_BIT    0x01


/********************************/
/*  Function Prototypes         */
/********************************/

void instPortInit();
void instPwrInit(int leaveAlone);
int instPortTxTask();

void instPortPwrSet(int port, int state);
int  instPortPwrGet(int port);
int  instPwrGet(void);

void instPortClearWriteReq();

void instSnapshotRxAvail();
unsigned int instPortReadReg(unsigned int address);
void instPortWriteReg(unsigned int address, unsigned int reg);

#endif

