/****************************************************************************/
/* Copyright 2010 MBARI.                                                    */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
#ifndef SYS_DEFS_H
#define SYS_DEFS_H

/* general defs */
#define TRUE    1
#define FALSE   0

#define HI      1
#define LO      0

/* serial I/O defs */
#define SER_CONSOLE     1
#define SER_SPARE       2
#define SER_ELMO        3
#define SER_DIG_PH      4

/* digital I/O defs */

#define TOTAL_OUT_BITS  19

#define PIC_DIO_01_RST LATFbits.LATF4 	//PIC_DIO_01_RST
#define PIC_DIO_02_RST LATFbits.LATF5	//PIC_DIO_02_RST	*NOT USED ON CURRENT BOARD*
#define PIC_DIO_03_RST LATFbits.LATF6	//PIC_DIO_03_RST	*NOT USED ON CURRENT BOARD*
#define PIC_DIO_04_RST LATGbits.LATG2	//PIC_DIO_O4_RST	*NOT USED ON CURRENT BOARD*
#define PIC_DIO_05_RST LATEbits.LATE6	//PIC_DIO_05_RST
#define PIC_ADC_01_SHDN LATFbits.LATF0	//PIC_ADC_01_SHDN
#define PIC_ADC_02_SHDN LATFbits.LATF1	//PIC_ADC_02_SHDN
#define PIC_ADC_03_SHDN LATFbits.LATF2	//PIC_ADC_03_SHDN	*NOT USED ON CURRENT BOARD*
#define PIC_ADC_04_SHDN LATFbits.LATF3	//PIC_ADC_04_SHDN	*NOT USED ON CURRENT BOARD*
#define PIC_DIO_05_CS LATEbits.LATE5	//PIC_DIO_05_CS
#define CS_ADD_EN LATEbits.LATE4		//CS_ADD_EN
#define CS_ADD_A0 LATEbits.LATE3		//CS_ADD_A0
#define CS_ADD_A1 LATEbits.LATE2		//CS_ADD_A1
#define CS_ADD_A2 LATEbits.LATE1		//CS_ADD_A2
#define CS_ADD_A3 LATEbits.LATE0		//CS_ADD_A3
#define BD_ADD_0 LATDbits.LATD0			//BD_ADD_0
#define BD_ADD_1 LATDbits.LATD1			//BD_ADD_1
#define BD_ADD_2 LATDbits.LATD2			//BD_ADD_2
#define PIC_INT_OE LATDbits.LATD11		//PIC_INT_OE 

#define TOTAL_IN_BITS  16

#define PIC_DIO_01_INT PORTDbits.RD3	//PIC_DIO_01_INT
#define PIC_DIO_02_INT PORTDbits.RD4	//PIC_DIO_02_INT	*NOT USED ON CURRENT BOARD*
#define PIC_DIO_03_INT PORTDbits.RD5	//PIC_DIO_03_INT	*NOT USED ON CURRENT BOARD*
#define PIC_DIO_04_INT PORTDbits.RD6	//PIC_DIO_04_INT	*NOT USED ON CURRENT BOARD*
#define PIC_DIO_05_INT PORTEbits.RE7	//PIC_DIO_05_INT 
#define IN_BIT_5 dummyBit				//SPI1_CS 
#define	IN_BIT_6 dummyBit
#define IN_BIT_7 dummyBit 
#define IN_BIT_8 dummyBit 

#define IN_BIT_9 dummyBit 
#define IN_BIT_10 dummyBit 
#define IN_BIT_11 dummyBit 
#define IN_BIT_12 dummyBit 
#define IN_BIT_13 dummyBit 
#define IN_BIT_14 dummyBit 
#define IN_BIT_15 dummyBit 

/* Daughterboard Type defs */
#define TYPE_OPEN    0
#define TYPE_CPU     1
#define TYPE_PS      2
#define TYPE_LVLS    3
#define TYPE_HVLS    4
#define TYPE_ENVIRON 5
#define TYPE_GFDET   6
#define TYPE_UNASS1	 7
#define TYPE_UNASS2  8
#define TYPE_UNASS3  9

/*Chip Select Defs ( for CSAddSet() ) */

#define DIO_01_CS	0
#define DIO_02_CS	1
#define	DIO_03_CS	2
#define DIO_04_CS	3
#define DIO_05_CS	4
#define ADC_01_CS	5
#define POT_01_CS	6
#define	POT_02_CS	7
#define	ADC_02_CS	8
#define POT_03_CS	9
#define POT_04_CS	10
#define ADC_03_CS	11
#define ADC_04_CS	12
#define DESELECT	99

/*I/O Expander Defs*/

#define GPIOA	0x09
#define GPIOB	0x19
#define GP0	0b00000001		
#define GP1	0b00000010		
#define GP2	0b00000100		
#define GP3	0b00001000		
#define GP4	0b00010000
#define GP5	0b00100000
#define GP6	0b01000000
#define GP7	0b10000000

extern int expPrevState[5][2];	//holds previous state of the I/O expanders
extern int int1_state;

/*Potentiometer Defs*/

#define POT_01_RST	0b00000010
#define POT_02_RST	0b00001000
#define READ		0b00000011
#define	WRITE		0b00000000
#define INCREMENT	0b00000001
#define DECREMENT	0b00000010
#define WIPER_0		0x02	//non-volatile wiper
#define WIPER_1		0x03
#define WIPER_2		0x08
#define WIPER_3		0x09

/*Instrument Channel Defs*/
//only channels 1 and 2 used on proto board

#define CHAN1	1
#define CHAN2	2
#define CHAN3	3	//*not used*
#define CHAN4	4	//*not used*
#define CHAN5	5	//*not used*
#define CHAN6	6	//*not used*
#define CHAN7	7	//*not used*
#define CHAN8	8	//*not used*

/*ADC Defs*/

#define ADC_CON_S  		0b10000000 	//Start bit of the control byte 
#define ADC_CON_A2 		0b01000000	//Channel select MSB of the control byte 
#define ADC_CON_A1 		0b00100000	//Channel select middle bit of the control byte
#define ADC_CON_A0 		0b00010000 	//Channel select LSB of the control byte
#define ADC_CON_SGLDIF	0b00000100	//Single-Ended/Differential Select Bit
#define ADC_CON_PD1    	0b00000010	//Power-down mode MSB of the control byte
#define ADC_CON_PD0    	0b00000001	//Power-down mode LSB of the control byte

#define CHAN_01_VOLT	1
#define CHAN_01_CURR	2
#define CHAN_02_VOLT	3
#define CHAN_02_CURR	4

#define CHAN_03_VOLT	5 	//*not used*
#define CHAN_03_CURR	6	//*not used*
#define CHAN_04_VOLT	7	//*not used*
#define CHAN_04_CURR	8	//*not used*

#define CHAN_05_VOLT	9	//*not used*
#define CHAN_05_CURR	10	//*not used*
#define CHAN_06_VOLT	11	//*not used*	
#define CHAN_06_CURR	12	//*not used*

#define CHAN_07_VOLT	13	//*not used*
#define CHAN_07_CURR	14	//*not used*
#define CHAN_08_VOLT	15	//*not used*
#define CHAN_08_CURR	16	//*not used*

#endif
