📄 main_entry.c.bak
字号:
Delay(50000);
Delay(50000);
Delay(50000);
}
i_printf("\b\b\b\b\b\b 1792k");
}
if(CNT>0x1792)
{
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_DATA_UNLOCK1; //0xaaaa
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK2) = AM_DATA_UNLOCK2; //0x5555
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_SETUP_ERASE; //0x8080
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_DATA_UNLOCK1; //0xaaaa
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK2) = AM_DATA_UNLOCK2; //0x5555
//*((volatile UINT16 *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_CHIP_ERASE; //0x1010
*((volatile unsigned short *)AM_SECTOR_ADDR_29) = AM_SECTOR_ERASE; //0x3030
for(i=0;i<50;i++)
{
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
}
i_printf("\b\b\b\b\b\b 1856k");
}
if(CNT>0x1856)
{
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_DATA_UNLOCK1; //0xaaaa
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK2) = AM_DATA_UNLOCK2; //0x5555
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_SETUP_ERASE; //0x8080
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_DATA_UNLOCK1; //0xaaaa
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK2) = AM_DATA_UNLOCK2; //0x5555
//*((volatile UINT16 *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_CHIP_ERASE; //0x1010
*((volatile unsigned short *)AM_SECTOR_ADDR_29) = AM_SECTOR_ERASE; //0x3030
for(i=0;i<50;i++)
{
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
}
i_printf("\b\b\b\b\b\b 1920k");
}
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
}
void flash_prg(int CNT)
{
volatile unsigned short *from_add,*to_add;
int i;
int j;
to_add= (unsigned short*)0x1010000;
from_add=(unsigned short *)0x00900000;
for(i=0;i<CNT*1024/2;i++)
{
*((volatile unsigned short *)AM_START_ADDR + AM_ADDR_UNLOCK1) = AM_DATA_UNLOCK1;
*((volatile unsigned short *)AM_START_ADDR + AM_ADDR_UNLOCK2) = AM_DATA_UNLOCK2;
*((volatile unsigned short *)AM_START_ADDR + AM_ADDR_UNLOCK1) = AM_SETUP_WRITE;
*to_add++ =*from_add++ ;
Delay(500);
}
}
void download()
{
char size[10];
char i,j;
static int length;
char flag;
static int CNT;
flag=1;
length=0;
i=0;
j=0;
i_printf(">>input the size of program\n");
put_char(0, 0x0d);
i_printf(">>0x");
size[0]=get_char(0);
do{
i_printf("%c",size[i]);
i++;
/*if(i>9)
{
i_printf("too big\n");
put_char(0, 0x0d);
flag=0;
}*/
size[i]=get_char(0);
}while(size[i]!=0x0d);
if(flag)
{
for(j=0;j<i;j++)
{
if(is_xdigit(size[j]))
{
if(size[j]>='0'&&size[j]<='9')
length = length * 16 + size[j]-'0';
else if(size[j]>='a'&&size[j]<='f') /* 'A' - 'F' */
length = length * 16 + 10+size[j]-'a';
else if(size[j]>='A'&&size[j]<='F') /* 'A' - 'F' */
length = length * 16 + 10+size[j]-'A';
}
}
CNT=length;
length=0;
put_char(0, 0x0d);
i_printf(">>waiting for receiveing........................\n");
put_char(0, 0x0d);
if (XModemReceive((char *)0x900000, 0xfffff) == -1)
i_printf("\nTRANSFER FAILURE");
i_printf(">>Transmit success");
put_char(0, 0x0d);
i_printf(">>Erase flash........................\n");
put_char(0, 0x0d);
flash_erase(CNT);
i_printf("\r>>Burn to flash........................\n");
put_char(0, 0x0d);
flash_prg(CNT);
}
}
void InitUART(int Port,int Baudrate)
{
if(Port==0)
{
ULCON0=0x03;
UCON0=0x09;
UBRDIV0=Baudrate;
}
if(Port==1)
{
ULCON1=0x03;
UCON1=0x09;
UBRDIV1=Baudrate;
}
}
void flash_erase_Bootloader()
{
int i;
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_DATA_UNLOCK1; //0xaaaa
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK2) = AM_DATA_UNLOCK2; //0x5555
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_SETUP_ERASE; //0x8080
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_DATA_UNLOCK1; //0xaaaa
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK2) = AM_DATA_UNLOCK2; //0x5555
//*((volatile UINT16 *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_CHIP_ERASE; //0x1010
*((volatile unsigned short *)AM_SECTOR_ADDR_01) = AM_SECTOR_ERASE; //0x3030
for(i=0;i<50;i++)
{
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
}
i_printf("erase 64k");
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_DATA_UNLOCK1; //0xaaaa
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK2) = AM_DATA_UNLOCK2; //0x5555
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_SETUP_ERASE; //0x8080
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_DATA_UNLOCK1; //0xaaaa
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK2) = AM_DATA_UNLOCK2; //0x5555
//*((volatile UINT16 *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_CHIP_ERASE; //0x1010
*((volatile unsigned short *)AM_SECTOR_ADDR_02) = AM_SECTOR_ERASE; //0x3030
for(i=0;i<50;i++)
{
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
}
i_printf("\b\b\b\b 128k");
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_DATA_UNLOCK1; //0xaaaa
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK2) = AM_DATA_UNLOCK2; //0x5555
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_SETUP_ERASE; //0x8080
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_DATA_UNLOCK1; //0xaaaa
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK2) = AM_DATA_UNLOCK2; //0x5555
//*((volatile UINT16 *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_CHIP_ERASE; //0x1010
*((volatile unsigned short *)AM_SECTOR_ADDR_03) = AM_SECTOR_ERASE; //0x3030
for(i=0;i<50;i++)
{
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
}
i_printf("\b\b\b\b 196k");
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_DATA_UNLOCK1; //0xaaaa
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK2) = AM_DATA_UNLOCK2; //0x5555
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_SETUP_ERASE; //0x8080
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_DATA_UNLOCK1; //0xaaaa
*((volatile unsigned short *)AM_START_ADDR+ AM_ADDR_UNLOCK2) = AM_DATA_UNLOCK2; //0x5555
//*((volatile UINT16 *)AM_START_ADDR+ AM_ADDR_UNLOCK1) = AM_CHIP_ERASE; //0x1010
*((volatile unsigned short *)AM_SECTOR_ADDR_04) = AM_SECTOR_ERASE; //0x3030
for(i=0;i<50;i++)
{
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
Delay(50000);
}
i_printf("\b\b\b\b 256k");
}
void flash_prg_bootloader(int CNT)
{
volatile unsigned short *from_add,*to_add;
int i;
int j;
to_add= (unsigned short*)0x1000000;
from_add=(unsigned short *)0x00900000;
Delay(50000);
i=*to_add;
Delay(50000);
for(i=0;i<CNT*1024/2;i++)
{
*((volatile unsigned short *)AM_START_ADDR + AM_ADDR_UNLOCK1) = AM_DATA_UNLOCK1;
*((volatile unsigned short *)AM_START_ADDR + AM_ADDR_UNLOCK2) = AM_DATA_UNLOCK2;
*((volatile unsigned short *)AM_START_ADDR + AM_ADDR_UNLOCK1) = AM_SETUP_WRITE;
*to_add++ =*from_add++ ;
Delay(500);
}
}
void Update_Bootloader()
{
i_printf("\r\n>>>Please Send the Data to Board by Xmodem Protocol...");
//put_char(0, 0x0d);
if (XModemReceive((char *)0x900000, 0xfffff) == -1)
i_printf("\nTRANSFER FAILURE");
i_printf(",OK!\r\n");
//put_char(0, 0x0d);
i_printf(">>>Flash Erase,Please Wait...");
flash_erase_Bootloader();
i_printf(">>>Flash Program,Please Wait...");
flash_prg_bootloader(100);
}
void extern C_Entry(void)
{
char ch;
IOPMOD=0xff;
InitUART(0,0x500); //19200bps 50MHz 0=COM1;1=COM2
counter = 0;
i_printf("\r\n\r\n\r\n\r\n\r\n");
i_printf("*******************************************************************************\n\r");
i_printf("* *\n\r");
i_printf("* BootLoader for S3C4510B (Version: 2.0) *\n\r");
i_printf("* *\n\r");
i_printf("* Beijing Winsilicon Technology Co., Ltd *\n\r");
i_printf("* *\n\r");
i_printf("* http://www.winsilicon.com *\n\r");
i_printf("* *\n\r");
i_printf("* Tel: (86-10) 62968004 62969543-26 *\n\r");
i_printf("* *\n\r");
i_printf("* Room420,zhongguancun Chuangye Tower *\n\r");
i_printf("* No.26 Shangdi Information Middle Road *\n\r");
i_printf("* Haidian District,Beijing 100085,China *\n\r");
i_printf("* *\n\r");
Loop:
i_printf("*******************************************************************************\n\r");
i_printf("* Please Input the Item Number: *\n\r");
i_printf("* [0] Test Led *\n\r");
i_printf("* [1] Test SDRAM *\n\r");
i_printf("* [2] Test FLASH *\n\r");
i_printf("* [3] Test UART *\n\r");
i_printf("* [4] Download to Flash *\n\r");
i_printf("* [5] Update Bootloader *\n\r");
i_printf("*******************************************************************************\n\r");
while(1)
{
put_char(0, 0x0d);
ch=get_char(0);
switch(ch)
{
case '4':download();
i_printf("\r\nDownload Successfully, Thank you!\r\n");
break;
case '5':
Update_Bootloader();
break;
default:
{i_printf("\r\n");
goto Loop;}
}
}
}
unsigned Install_Handle(unsigned routine,unsigned *vector)
{
unsigned vec,oldvect;
vec=((routine-(unsigned)vector-0x8)>>2);
if(vec&0xff000000)
{
}
vec=0xea000000|vec;
oldvect=*vector;
*vector=vec;
return(oldvect);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -