#include <MSP430Fx.h>

/*
C File created automatically by AQ430 tools
*/

void AQ430_Init_HW(void)
{
	/*
	// Hardware initializations
	//
	
	//         DIR  OUT  SEL  IES  IE
	// Port 1  x00  x00  x00  x00  x00	All bits are inputs with interrupts disabled
	//                                  P1.0 is RADIO1_PWR_N
	//                                  P1.1 is RADIO2_PWR_N
	//                                  P1.2 is LIGHT_N
	//                                  P1.7 through P1.3 are spare
	//
	// Port 2  x00  x00  x00  x00  x00  All bits are inputs with interrupts disabled
	//                                  P2.7 through P2.0 are spare
	//
	// Port 3  x07  x00  x30			Three LSBs are outputs, Two LSBs are peripherals(why??)
	//                                  P3.0 is ENABLE_GFD
	//                                  P3.1 is TEST_GFI_CIRCUIT
	//									P3.2 is CHECK_HIGH_SIDE
	//                                  P3.3 is spare
	//                                  P3.4 is MSP430_TX  (???)
	//                                  P3.5 is MSP430_RX  (???)
	//                                  P3.7 through P3.6 are spare
	// 
	// Port 4  xFF  x01  x00			All bits are outputs, Intially Off (Low)
	//                                  P4.0 is ISOLATE_PRADIO_N
	//                                  P4.1 is ISOLATE_SRADIO       (Latching)
	//                                  P4.2 is ISOLATE_PAGER        (Latching)
	//                                  P4.3 is ISOLATE_CONSOLE      (Latching)
	//                                  P4.4 is ENABLE_CONSOLE_POWER
	//                                  P4.5 is UNISOLATE_SRADIO     (Latching)
	//                                  P4.6 is UNISOLATE_PAGER      (Latching)
	//                                  P4.7 is UNISOLATE_CONSOLE    (Latching)
	//
	// Port 5  x00  x00  x00            All bits are inputs, use of SPI not supported by code
	//                                  P5.0 is MSP_SPI_CS_N  (??)
	//                                  P5.1 is MSP_SPI_MOSI  (??)
	//                                  P5.2 is MSP_SPI_MISO  (??)
	//                                  P5.3 is MSP_SPI_CLOCK (??)
	//                                  P5.6 through P5.4 are spare
	//                                  P5.7 is MSP_SPI_INTR_N
	//
	// Port 6  x00  x00  xFF            All bits devoted to A/D converter
	//                                  P6.7 through P6.0 are spare A/D channels
	*/
	_DINT();// Disable Interrupts
	/*
	// [Ports]
	*/
	P1DIR=0x00;
	P1OUT=0x00;
	P1SEL=0x00;
	P1IES=0x00;
	P1IE=0x00;
	
	P2DIR=0x00;
	P2OUT=0x00;
	P2SEL=0x00;
	P2IES=0x00;
	P2IE=0x00;
	
	P3DIR=0x07;
	P3OUT=0x00;
	P3SEL=0x30;
	
	P4DIR=0xFF;
	P4OUT=0x01;
	P4SEL=0x00;
	
	/*
	// Currently, the SPI interface between the SideARM and RFIO boards is not used. If the 
	// RFIO board the drives the SPI interrupt signal low continuously, the DPAs or the Medusa 
	// board will not be able wakeup the SideARM controller.
	//
	// A pullup for the SPI interrupt line exists on the SideARM board.  Setting the 
	// MSP_SPI_INTR_N signal as an input is benign and will prevent the RFIO from 
	// interfering with the operation of the SPI interrupt.  The pullup on the SideARM
	// guarantees the SPI interrupt will not be asserted.
	*/  
	
	P5DIR=0x00;
	P5OUT=0x00; 
	P5SEL=0x00;
	
	P6DIR=0x00;
	P6OUT=0x00;
	P6SEL=0xFF;
	
	_EINT();// Enable Interrupts
}

void main(void)
{
  	int i;
  	
	/*
	// Call hardware initialization function
	*/
	AQ430_Init_HW();

	
	/* 
	// Assert
	// UnIsolate_Console, UnIsolate_Pager, UnIsolate_SRadio, Isolate_Radio_N
	*/ 
	
	P4OUT = 0xE1;
	
	/* Delay for 3 secs to let relays stabilize */
	for(i=0; i < 5000; i++) {
	  _NOP();
	}  
	/* 
	// Negate
	// UnIsolate_Console, UnIsolate_Pager, UnIsolate_SRadio, Isolate_Radio_N
	*/	  
	  
	P4OUT = 0x01;
	
	_NOP(); // debug breakpoint
	_BIS_SR(LPM4_bits + GIE); // deep sleep (no clocks)
}