Example #1
0
void init_cache(void)
{
	CSL_sysInit();
	MDMA_PRIARB_REG = 0x00000000;
	CACHE_wbInvAllL2(CACHE_WAIT);
#ifdef _CAMERA_PIXEL_500W_
	InitEMIF_32M();
#else
	InitEMIF();
#endif
	CACHE_setL1dSize(CACHE_L1_32KCACHE);
	CACHE_setL1pSize(CACHE_L1_32KCACHE);
	CACHE_setL2Size(CACHE_32KCACHE);
	CACHE_wbInvAllL2(CACHE_WAIT);
}
UINT8 main(void)
{ 
	volatile UINT8 	errflag = 0;
	volatile UINT32 nFlashID = 0;
	volatile UINT8  nRetLoadSts = 0;

	//Disable the L1D and L1P cache before loading the sections
	#ifdef DEBUG
	printf("L1D and L1P cache disabled\n");
	#endif
	CACHE_setL1pSize(CACHE_L1_0KCACHE);
	CACHE_setL1dSize(CACHE_L1_0KCACHE);
		
	//Initialize the swPLL Controller 
	Loader_InitPLL();

	Gpo_Init(&oBootGreenLED, BOOT_GREEN_LED);
	Gpo_Init(&oBootRedLED, BOOT_RED_LED);

	Gpo_Clear(&oBootRedLED);
	Gpo_Clear(&oBootGreenLED);

	#ifdef DEBUG
	printf("Boot Loader program running...\n");
	#endif

	//Initialize the DDR2
	#ifdef DEBUG
	printf("Initializing the DDR2...\n");
	#endif
	Loader_InitDDR2();
	
	//Init the 16 Mbyte Flash
	SpiFlash_Init(&oFlash, NUMONYX_16MB);

    //FlashImage_check();

	nFlashID = SpiFlash_GetFlashID( &oFlash );

	while(nFlashID != FLASH_ID )
	{
		volatile UINT32	nCounter = 0;
		while((nCounter++) <= 0x1000 );

		nFlashID = SpiFlash_GetFlashID( &oFlash );
		nFlashReadCount++;

		if(nFlashReadCount > 10 ) 
			break;
	}

	if(nFlashID != FLASH_ID )
	{
		volatile UINT32	nCounter = 0;

		while(1)
		{
			while((nCounter++) <= 0xCC0000 );
			Gpo_Toggle(&oBootRedLED);
			nCounter = 0;
		}
		
	}

	#ifdef FILE_USAGE

	if(errflag = Loader_GetImage((UINT8 *)"AppC2.hex",APP_DDR_START_ADDR_CORE2 ,APP_SIZE_CORE2))
	{	
		showErr(errflag);		
	}

	if(errflag = Loader_GetImage((UINT8 *)"AppC1.hex",APP_DDR_START_ADDR_CORE1,APP_SIZE_CORE1))
	{	
		showErr(errflag);		
	}
			
	if(errflag = Loader_GetImage((UINT8 *)"AppC0.hex",APP_DDR_START_ADDR_CORE0,APP_SIZE_CORE0))
	{	
		showErr(errflag);
		return 0;		
	}

	//Write the Downloaded Images to Flash
	Loader_WriteImagesToFlash(); 

	#endif
	
	#ifdef ETHERNET_USAGE

	#ifdef DEBUG
	printf("sizeof BootPkt -> %d\n", sizeof(BootPkt));
	#endif

	//Init the Mac interface
	bInEthernetScope = TRUE;
	EVM_init();

	if(TRUE == Ethernet_Init())
	{
	  	//Download the Images to DDR
		if(TRUE == BootPkt_Download())
		{
			//Write the Downloaded Images to Flash
			Loader_WriteImagesToFlash();
		}
	}
	bInEthernetScope = FALSE;
	Gpo_Clear(&oBootGreenLED);

	#endif

	#ifdef FLASH_BOOT 
	
	#ifdef DEBUG
	printf("Reading the images from flash\n");
	#endif

	SpiFlash_Read(&oFlash, 
				  (UINT8 *)APP_DDR_START_ADDR_CORE2, 
				  APP_FLASH_START_ADDR_CORE2, 
				  APP_SIZE_CORE2); 

	SpiFlash_Read(&oFlash, 
				  (UINT8 *)APP_DDR_START_ADDR_CORE1, 
				  APP_FLASH_START_ADDR_CORE1, 
				  APP_SIZE_CORE1);
	
	SpiFlash_Read(&oFlash, 
				  (UINT8 *)APP_DDR_START_ADDR_CORE0, 
				  APP_FLASH_START_ADDR_CORE0, 
				  APP_SIZE_CORE0);	

	#endif

	nRetLoadSts = Loader_LoadApp((UINT32)APP_DDR_START_ADDR_CORE2, APP_SIZE_CORE2);
	
	if(nRetLoadSts)
	{
		Gpo_Set(&oBootRedLED);
		while(1);
	}

	nRetLoadSts = Loader_LoadApp((UINT32)APP_DDR_START_ADDR_CORE1, APP_SIZE_CORE1); 

	if(nRetLoadSts)
	{
		Gpo_Set(&oBootRedLED);
		while(1);
	}
	//it should be last ....
	nRetLoadSts = Loader_LoadApp((UINT32)APP_DDR_START_ADDR_CORE0, APP_SIZE_CORE0);

	if(nRetLoadSts)
	{
		Gpo_Set(&oBootRedLED);
		while(1);
	}

	Gpo_Set(&oBootGreenLED);
	{
		volatile UINT32	nCounter = 0;
		while(nCounter++ < (0xCC0000*4));
	}

	if(errflag = Loader_SetAppLoadCompleteFlag((UINT32 *)APPC1_LOAD_COMPLETE_FLAG_ADDR))
	{
		showErr(errflag);
	}

	if(errflag = Loader_SetAppLoadCompleteFlag((UINT32 *)APPC2_LOAD_COMPLETE_FLAG_ADDR))
	{
		showErr(errflag);
	}
	
	#ifdef DEBUG
	printf("Starting Application program ...\n");
	#endif

	Loader_ExecuteAppC0();

	return 0;  
}