#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-HD15
	
			*pPORTH_FER = 0x00FF;
			ssync();
			*pPORTH_MUX = 0x2;	
			ssync();
	
			// Enable HCE, HWR, HRD,HADDR, HACK,  
	
			*pPORTG_FER = PG15 | PG14 | PG13 | PG12 | PG11;
			ssync();
			*pPORTG_MUX = 0x2800;
			ssync();
	
}


void Init_Interrupts(void)
{
	

			register_handler(ik_ivg12, HOSTDP_ISR);		

			// enable HOSTDP at SIC level
	
			*pSIC_IMASK0 = 0x10000000 ;
			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++;
	
			*pDMA1_IRQ_STATUS |= DMA_DONE;
			ssync();
		
}


