#include "config.h"

void main()

{
	
			Init_PLL();
	
			#ifdef HOST_READ
	
			Fill_Slave_Buffer();
	
			#endif
	
	
			GP_PORT_Config();
			Init_Interrupts();
			Host_Config();
	
	
	
			while(1)
			{
	
			}
	
	
}



void Init_PLL(void)

{
			*pSIC_IWR0 = 1;
			*pPLL_CTL = MSELECT;
			ssync();
			idle();
			*pPLL_DIV = CSELECT | SSELECT;
			ssync();
	
}

void Fill_Slave_Buffer(void)

{
			char data = 0x5A;	
			for(i=0;i<Transfer_Size; i++)
			{
				Slave_Buffer[i] = data;
				data = ~data;
			}
	
}

void GP_PORT_Config(void)
{
	
			// Enable HD0-HD7
	
			*pPORTD_FER = 0xFF00;
			ssync();
			*pPORTD_MUX = 0x55555555;	//2nd function
			ssync();
	
			// Enable HCE, HWR, HRD, 
	
			*pPORTG_FER = PG5 | PG6 | PG7;
			ssync();
			*pPORTG_MUX = 0x00005400;	//2nd function
			ssync();
	
			// Enable HADDR, HACK, 
			
			*pPORTH_FER = PH3 | PH4;
			ssync();
			*pPORTH_MUX = 0;		//1st function
			ssync();
	
}


void Init_Interrupts(void)
{
	

			register_handler(ik_ivg9, HOSTDP_ISR);		

			// enable HOSTDP at SIC level
	
			*pSIC_IMASK1 = 0x00000040;
			ssync();
	
}

void Host_Config(void)
{

	
			*pHOST_CONTROL = EHR | EHW | INT_MODE ; 	
	

			//enable HOSTDP
	
			*pHOST_CONTROL |= HOSTDP_EN;
	
			ssync();
	
}


EX_INTERRUPT_HANDLER(HOSTDP_ISR)
{
	
			ISR_Count++;
	
			*pDMA14_IRQ_STATUS |= DMA_DONE;
			ssync();
		
}


