#include "config.h"

void main()

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


void Init_PLL(void)

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

void Fill_buffer(void)

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

void GP_PORT_Config(void)
{
	
		// Enable HD0-HD15
	
		*pPORTH_FER = 0xFFFF;
		ssync();
		*pPORTH_MUX = 0x2A;	
		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_STATUS = 0;
		ssync();
	
		*pHOST_CONTROL = EHR | EHW | INT_MODE | HOSTDP_DATA_SIZE;
	
		//enable HOSTDP
	
		*pHOST_CONTROL |= HOSTDP_EN;
	
	
		ssync();
	
}

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

	
