⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2443mon_u.cpp

📁 S3C2443的Bootloader程序
💻 CPP
字号:
/**
* Project Name : S3C2443 verification project
*
* Copyright 2006 by Samsung Electronics, Inc.
* All rights reserved.
*
* Project Description :
* This software is only for verifying functions of the S3C2443. 
* Anybody can use this code without our permission.
*/

/**
* File Name    : 2443mon.cpp
* Description  : S3C2443 USB monitor main code
* Author       : Cha gyu hwan
* Dept         : Mobile solution, AP
* Created Date : 2006.09.16
* Version      : 0.0
* History
*   R0.0 (2006.06.): Cha gyu hwan draft
*   R0.1 (2006.09.): Cha gyu hwan draft
*   R0.2 (2006.12.): Cha gyu hwan draft
*/


#include "System.h"
#include "memtest.h"
#include "profile.h"
#include "usbdev.h"
#include "uartdown.h" // add 060626


void Lcd_Off(void);
void WaitDownload(void);
void Menu(void);

void ClearMemory(void);

void UsbMon(void);

void Clk0_Enable(int clock_sel);	
void Clk1_Enable(int clock_sel);
void Clk0_Disable(void);
void Clk1_Disable(void);
void TestDownLoading(void);

volatile U32 downloadAddress; 

void (*restart)(void)=(void (*)(void))0x0;
void (*run)(void);

volatile U8 dma_done=0;

int download_run=0;
volatile U32 tempDownloadAddress;
int menuUsed=0;

extern char Image$$RW$$Limit[];
U32 *pMagicNum=(U32 *)Image$$RW$$Limit;
int consoleNum;

//static USB_OP eOpMode = USB_CPU;
static USB_OP eOpMode = USB_DMA;

static void __irq Isr_Usb(void)
{
	HandleEvent();
	ClearPending(BIT_USBD);
}

void WhichMemory(void)
{
	
	if(rBANKCFG & 0x4)
	{
		printf("mSDR\n");	
	}else{
		printf("mDDR\n");	
	}
}

void Reset_Status_Check(void)
{
	printf("reset status register = %08x\n", rRSTSTAT);
	

	
	if( rRSTSTAT & (1<<0) )
	{
		printf("Power-on Reset\n");
	}

	else if( rRSTSTAT & (1<<2) )
	{
		printf("\nWatch-dog Reset\n\n");
		run=(void (*)(void))0x30000000;
		run();
	}
	else if( rRSTSTAT & (1<<3) )//Sleep mode wake-up
	{
		printf("\nSLEEP mode Wake-up\n\n");
		run=(void (*)(void))0x30000000;
		run();
	}
	else if( rRSTSTAT & (1<<4) )
	{
		printf("\nEsleep mode Wake-up\n\n");
		run=(void (*)(void))0x30000000;
		run();
	}
	else if( rRSTSTAT & (1<<5) )
	{
		printf("\nSoft Reset\n\n");
		run=(void (*)(void))0x30000000;
		run();
	}
}

int main(void)
{
	SystemCLK(0);
	Console();
	Isr_Init();
	UsbMon();
}

void Usb_power_en(void)
{
	rGPHUDP|=(0x3<<28); // for usb power enable....
	rGPHCON|=(0x1<<28); // for usb power enable....
	rGPHDAT|=(0x1<<14); // for usb power enable....
}

void Usb_Reset(void)
{
	rUSB_RSTCON = (0x0<<2)|(0x0<<1)|(0x1<<0);//Function 2.0 S/W reset, Host 1.1 S/W reset,PHY 2.0 S/W reset
    Delay(2); // phy reset must be asserted for at 10us 
    rUSB_RSTCON = (0x1<<2)|(0x1<<1)|(0x0<<0);//Function 2.0 S/W reset, Host 1.1 S/W reset,PHY 2.0 S/W reset
    rUSB_RSTCON = (0x0<<2)|(0x0<<1)|(0x0<<0);//Function 2.0 S/W reset, Host 1.1 S/W reset,PHY 2.0 S/W reset
	Delay(20); 
}

void Usb_Init(void)
{
	rUSB_PHYCTRL =(0x0<<3)|(0x0<<2)|(0x1<<1)|(0x0<<0);  //48Mhz,x-tal,External X-tal,device
    rUSB_PHYPWR = (0x0<<31)|(0x3<<4)|(0x0<<3)|(0x0<<2)|(0x0<<1)|(0x0<<0); 
    //48Mhz clock on ,PHY2.0 analog block power on,XO block power on,XO block power in suspend mode,PHY 2.0 Pll power on ,suspend signal for save mode disable 
     
	rUSB_CLKCON = (0x0<<31)|(0x1<<2)|(0x0<<1)|(0x0<<0); // vbus detect enable...
    //D+ pull up , USB2.0 Function clock Enable, USB1.1 HOST disable,USB2.0 PHY test enable

	pISR_USBD =(unsigned)Isr_Usb;
	MMU_EnableICache();  
	
	ClearPending(BIT_USBD);
	rINTMSK&=~(BIT_USBD);   // usb interrupt enable 


}

void UsbMon(void)
{

	rGPACDH = rdGPACDH & ~(1<<5) | (0<<5); // RDATA_OEN : enable
	Usb_power_en();
	
	if (rRSTSTAT&0x8) rRSTCON|=(1<<16); //if reset by sleep wakeup, control the retention I/O cell
	//USB Port is Normal mode
	rMISCCR=rMISCCR&~(1<<12);  // USBD is 0 ,normal mode ,1 is suspend mode /
	rPWRCFG |= (0x1<<4); // phy power enable 

	Usb_Reset();
	Usb_Init();
	
	Delay(0);  //calibrate Delay()
	Led_Display(0x6);

	rUSB_CLKCON = (0x1<<31)|(0x1<<2)|(0x0<<1)|(0x1<<0); // vbus detect enable...
    //D+ pull up , USB2.0 Function clock Enable, USB1.1 HOST disable,USB2.0 PHY test enable

	// CLKOUT0/1 select.
	printf("CLKOUT0:MPLL in, CLKOUT1:RTC clock.\n");
   	printf("\n\n");
   	printf("+-----------------------------------------------+\n");
   	printf("| S3C2443X USB Downloader ver R0.2  	        +\n");
   	printf("+-----------------------------------------------+\n");
   	WhichMemory();
   	printf("MPLL=%.2fMHz, ARMCLK=%.2fMHz (%d:%d:%d), HCLK=%.2fMHz, PCLK=%.2fMHz\n\n",
   		(float)MPLL/1000000,(float)ARMCLK/1000000,ARMCLKdiv+1,(ARMCLKdiv+1)*(HCLKdiv+1),(ARMCLKdiv+1)*(HCLKdiv+1)*(PCLKdiv+1),(float)HCLK/1000000,(float)PCLK/1000000);
   	printf("USB: IN_ENDPOINT:1 OUT_ENDPOINT:3\n"); 
   	printf("FORMAT: <ADDR(DATA):4>+<SIZE(n+10):4>+<DATA:n>+<CS:2>\n");
   	printf("NOTE: 1. Power off/on or press the reset button for 1 sec\n");
   	printf("         in order to get a valid USB device address.\n");
   	printf("      2. For additional menu, Press any key. \n");
   	printf("\n");

	download_run=1; //The default menu is the Download & Run mode.
	
	Reset_Status_Check();
	AllocateUSBDEV();
	while(1)
	{
	
		eOpMode =USB_DMA; 
		UsbdMain(); 
		if(menuUsed==1)Menu();
		WaitDownload();
	}
	FreeUSBDEV();
	

}

void UsbdMain(void)
{
    SetOpMode(eOpMode);
    Init();
}


void Menu(void)
{
	U8 key;
	menuUsed=1;
	while(1)
	{
		printf("\n###### Select Menu ######\n");
		printf(" [0] Download & Run\n");
		printf(" [1] Download Only\n");
		printf(" [2] Test SDRAM \n");
		printf(" [3] Clear SDRAM \n");
		printf(" [4] Change The Console UART Ch.\n");
 		printf(" [5] Download with UART\n");
		printf(" [6] Upload with USB 2.0 device \n");
		key=getchar();
		
		switch(key)
		{
		case '0':
			printf("\nDownload&Run is selected.\n\n");
			download_run=1;
			return;
		case '1':
			printf("\nDownload Only is selected.\n");
			printf("Enter a new temporary download address(0x3...):");
			
			tempDownloadAddress=GetIntNum();
			download_run=0;
			printf("The temporary download address is 0x%x.\n\n",tempDownloadAddress);
			return;
		case '2':
			printf("\nMemory Test is selected.\n");
			MemoryTest();
			Menu();
			return;
		case '3':
			printf("\nMemory Clear is selected.\n");
			ClearMemory();
			Menu();
			return;
		case '4':
			printf("\nWhich UART channel do you want to use for the console?[0/1]\n");
			if(getchar()!='1')
			{
				*pMagicNum=0x0;
				printf("UART ch.0 will be used for console at next boot.\n");					
			}
			else
			{
				*pMagicNum=0x12345678;
 				printf("UART ch.1 will be used for console at next boot.\n");		
				printf("UART ch.0 will be used after long power-off.\n");
			}
			printf("System is waiting for a reset. Please, Reboot!!!\n");
			while(1);
		case '5':  // add 060626
			printf("\nDownload with UART\n");
			UartMON();
			return;
		case '6':  // add 060626
			printf("\nUpload file !!\n");
			SetOpMode(eOpMode); 
			getchar();
			return;
	
		default:
			break;
		}	
	}		

}

extern U32 checkTest;

void WaitDownload(void)
{
	U32 i;
	U32 j;
	U16 cs;
	U32 temp;
	U16 dnCS;
	int first=1;
	float time;
	U8 tempMem[16];
	U8 key;


	g_uDownloadAddress=(U32)tempMem; //_RAM_STARTADDRESS; 
	g_uDownloadFileSize=0;
	
	/*******************************/
	/*	Test program download	*/
	/*******************************/
	j=0;

	if(IsEnumerationDone()==false)
	{
	printf("USB host is not connected yet.\n");
	}
	
	while(g_uDownloadFileSize==0)
	{
		if(first==1 && IsEnumerationDone()==true)
		{
			printf("USB host is connected. Waiting a download.\n");
			first=0;
		}

		if(j%0x50000==0)Led_Display(0x6);
		if(j%0x50000==0x28000)Led_Display(0x9);
		j++;
		key=Uart_GetKey();
		if(key!=0)
		{
		
			Menu();
			first=1; //To display the message,"USB host ...."
		}

	}

	
	StartStopwatch();  

	printf("\nNow, Downloading [ADDRESS:%xh,TOTAL:%d]\n",
			g_uDownloadAddress,g_uDownloadFileSize);
	printf("RECEIVED FILE SIZE:%12d",0);
 
	while(((U32)g_pDownPt-g_uDownloadAddress)<(g_uDownloadFileSize-8))
	{
		if(dma_done ==1)break;
	}
	dma_done=0;
	
	time=EndStopwatch();
	printf("\b\b\b\b\b\b\b\b%8d",g_uDownloadFileSize);	
	
	printf("\n(%5.1fKB/S,%3.1fS)\n",(float)(g_uDownloadFileSize/time*1000.),time/1000000);
	printf("RECEIVE FILE DONE !! \n");
	
	if(download_run==1)
	{
		rINTMSK=BIT_ALLMSK;
		run=(void (*)(void))g_uDownloadAddress;
	run();
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -