/******************************************************************************
 * GPIO and MUX prototypes for Spray2008 SPI control
 * CS assignment = CS_GPIO is done in spi_cmd.h
 * created Oct2008
 * updated:
 *****************************************************************************/


void        gp_menu         ( struct spi_param *ss );
short       spi_mux         ( short on, short chan, struct spi_param *ss );

short       spi_wdog        ( char  c  );
short       spi_set_wdog    ( short w, short a );
void        display_wdog    ( struct spi_param *ss );
void        reset_gpio      ( void );
short       try_update_wdog ( void );
short       service_wdog    ( void );

void        gp_flash_menu   ( struct spi_param *ss );
short       init_gpio_iparam( void  );
void        display_gpflash ( void  );
void        display_gp_query( short rstat, struct spi_param *ss );
void        display_aux_pwr ( struct spi_param *ss );
void        display_spi_mux ( struct spi_param *ss );
void        gp_set_default  ( void  );

void        ant_switch      ( short unit, short wing);

void        test_gpio       ( void  );

#define Update_Wdog ( spi_wdog ( WDT_RESET ) ) // reset the watchdog 
#define Query_Wdog  ( spi_wdog ( WDT_QUERY ) ) // query the watchdog for settings

//****   specific constants to the pitch/roll SPI module **********************
//****   These values must agree with the compiled msp430 code !!!

// define the a/d channels

// flash addr locations in msp430
// !!!WARNING!!! THESE MUST AGREE WITH MSP430 VALUES !!!!!
//#define F_SER_NO       0    // serial # of this peripheral
#define F_VERSION      2    // flash version
// assignment past the version is specific to each type of module
// these are the assignments for watchdog
#define F_WDT_MULT     4    // default multiplier for increase tmo's below
#define F_MAX_ATTN     6    // max counter before setting CF2_ATTN low
#define F_MAX_RST      8    // max counter before resetting the CF2 
#define F_MAX_MAX     10    // max counter before resetting itself
#define F_WDT_ACT     12    // default action mask to decide what is enabled

#define F_G_C2U_V14   14    // gain for 14V channel
#define F_G_C2U_V07   16    // gain for 07V channel
#define F_G_C2VAC     18    // gain for vacuum channel
#define F_G_VOFF      20    // offset for vacuum
#define F_G_C2MV      22    // counts to milliV: mV=cnt*C2MV/10000



//*****************************************************************************
// AUX_PWR Command (spi_cmd.h) passes the aux_sensor_id to control
//		range = 1..127
// If it passes a #>0, it is turned on (set high).
// If it is <0, it will be turned off (set low)
// !!!THIS LIST MUST AGREE WITH MSP430 CODE !!!!!!!!
//*****************************************************************************

// following are used by low-level calls to spi_aux_pwr
#define AUX_ON_AD        1  // turn on needed circuitry to sample a/d value
#define AUX_ON_SBD       2  // turn on SBD Modem
#define AUX_ON_GPS       3  // turn on GPS module
#define AUX_ON_ARGOS     4  // turn on argos module
#define AUX_ON_BURN      5  // turn on the burn wire
#define AUX_ON_ALT       6  // turn on the altimeter/ADP
#define AUX_ON_OPT       7  // turn on the optical sensor
#define AUX_ON_COMP      8  // turn on the compass module
#define AUX_ON_SPARE1    9  // turn on the spare port 1
#define AUX_ON_ZCAM   AUX_ON_SPARE1 // apr15, use this one for the ZooCam

#define AUX_ON_SBE_PMP  10  // turn on the SBE pump
#define AUX_ON_SBE_HI   11  // turn on the SBE to high-speed mode
#define AUX_OFF_SBE_HI  12  // turn on the SBE to high-speed mode
// antenna switch control will be a separate command
#define AUX_ON_SPARE2   13  // turn on the spare port 2
#define AUX_ON_SPARE3   14  // turn on the spare port 3

#define AUX_ON 1   // used by power_on_off to tell it to turn it on
#define AUX_OFF 0  // used by power_on_off to tell it to turn it off

// CF2 reset and attn will be separate

// serial mux control  MUST AGREE WITH THE MSP430 CODE !!!
//      SER_SBE requires NO mux control: it goes straight to the CF2

#define SER_SBD          1 // configure mux/rs232 for Iridium SBD comms
#define SER_ADP          2 // configure mux/rs232 for ADP/ALT comms
#define SER_GPS          3 // configure mux/rs232 for GPS comms
#define SER_COMPASS      4 // configure mux/rs232 for compass comms
#define SER_ISUS         5 // configure mux/rs232 for ISUS comms
#define SER_AUX1         6 // configure mux/rs232 for AUX1 comms (cmos)
#define SER_AUX2         7 // configure mux/rs232 for AUX2 comms (cmos)
#define SER_AUX3         8 // configure mux/rs232 for AUX3 comms (rs232)
#define SER_AUX4         9 // configure mux/rs232 for AUX4 comms (rs232)

#define SER_OFF_ALL     11 // turn off all serial converters
#define SER_OFF1        12 // turn off rs232#1 (ADP, SAT)
#define SER_OFF2        13 // turn off rs232#2 (ISUS, COMPASS)
#define SER_OFF3        14 // turn off rs232#3 ( AUX3, AUX4 )

// define the a/d channels
#define AD_AUX_V_14 0 // chan0 = 14v battery
#define AD_AUX_V_07 1 // chan1 = 7v battery
#define AD_AUX_VAC  2 // chan2 = vacuum sensor
#define AD_AUX_ALT  3 // chan3 = altimeter sensor
#define AD_AUX_OPT  4 // chan4 = optical sensor


//***mask bits for the watchdog action, set in spi_set_wdog
#define DO_ATTN     0x01  // bit 0 set=1 says control the CF2_ATTN line
#define DO_CF2_RST  0x02  // bit 1 set=1 says Reset CF2 is OK
#define DO_430_RST  0x04  // bit 2 set=1 says self-reset is OK
#define DO_ARGOS    0x08  // bit 3 set=1: turn on argos if complete failure 3x
#define DO_BURN     0x10  // bit 4 set=1: turn on  burn if complete failure 3x


