/****************************************************************************/
/* Copyright 2009-2013 MBARI.                                               */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Written by Mike Risi for Respirometer project in 2009                    */
/* Modified by Bob Herlien for SensorNode for xFOCE, May 2013               */
/****************************************************************************/
#ifndef INST_PORT_H
#define INST_PORT_H

#define INST_HOLDING_START  0x00FF
#define INST_HOLDING_END    0x03FF

#define PWR_PORT_0     0
#define PWR_PORT_1     1
#define PWR_PORT_2     2
#define PWR_PORT_3     3

#define PWR_PORT_TOTAL	4
#define PWR_PORT_MASK 	0xf
#define RELAY_MS	20

#define SERIAL_NUM	0x0010
#define SOFTWARE_REV	0x0011
#define CONFIG_REG_H	0x0012
#define CONFIG_REG_L	0x0013
#define RELAY_STATE	0x0014
#define HW_CONFIG_BITS	0x0015

#define MISC_START	SERIAL_NUM
#define MISC_END	HW_CONFIG_BITS

#define SERIAL_STAT     0x00FF
#define SER_HOLDING_0   0x0100
#define SER_HOLDING_1   0x0200
#define SER_HOLDING_2   0x0300
/* note: the registers below don't exist, just used for offset calcs */
#define SER_HOLDING_3   0x0400  


/* SERIAL_STAT bits */
#define ERR_2_BIT       0x0400
#define RX2_DATA_BIT    0x0200
#define TX2_DATA_BIT    0x0100

#define ERR_1_BIT       0x0040
#define RX1_DATA_BIT    0x0020
#define TX1_DATA_BIT    0x0010

#define ERR_0_BIT       0x0004
#define RX0_DATA_BIT    0x0002
#define TX0_DATA_BIT    0x0001



void instPortInit();
void instPwrInit(int leaveAlone);
void instPortRxTask();
void instPortTxTask();

void instPortPwrSet(int port, int state);
int  instPortPwrGet(int port);
int  instPwrGet(void);
void instSetDCalwaysOn(BOOL state);
BOOL instGetDCalwaysOn(void);

void instPortClearWriteReq();

unsigned int instPortReadReg(unsigned int address);
void instPortWriteReg(unsigned int address, unsigned int reg);

#endif

