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

📄 main_entry.c

📁 三星4510 BOOTLOADER全部源代码
💻 C
字号:
/************************************************************************/
/*                       Revision History                               */
/************************************************************************/
/*Date of Revision   Version         Description                        */
/************************************************************************/
/*2002/10/20          001        Original Version.                      */
/*2003/05/20          002        Added Flash operation.                 */      
/*2005/06/01          003        Added Boot Selection.                  */ 
/************************************************************************/


/************************************************************************/
/*Institute of automation, Chinese Academy of Sciences                  */
/*Beijing Hyesco Technology CO.,Ltd                                     */
/*Title:    Bootloader for H4510EM                                      */
/*Author:   Lee JuGuang                                                 */
/*All Rights Reserved                                                   */
/************************************************************************/

#include "s3c4510b_add.h"
#include "uart.h"
#include "isr.h"
#include "ether.h"
//#include "iic.h"
#include "led.h"
#include "DAC.h"
#include "ADC.h"
#include "Key.h"
#include "RTC.h"
#include "LCD.h"
#include "Flash.h"

/********************** Function define. *******************************/
void InitUART(int Port,int Baudrate);
void PrintUART(int Port,char *s);
void Delay(int i);
void extern FIQ(void);
extern void download(void);
void Sys_Info(void);
void Test_GPIO(void);
extern void Update_Bootloader(void);
void Para_Save(void);
unsigned Install_Handle(unsigned routine,unsigned *vector);
void Flash_Unlock(void);
/************************************************************************/

#define 	SYSCFG			0x03ff0000
#define 	INT_GLOBAL		(21)
#define 	COUNTDOWN		0x01effff0

/*
************************************************************************
* Function Name:	C_Entry()						
* Description:		Main Function .					
* Date:			2003-12-9					
************************************************************************
*/
void extern C_Entry(void)
{
	char    ch;
	IOPMOD=0xff;		//GPIO设置为输出低电平
	IOPDATA=0x0;	
	LED_Close();		//关闭LED显示
	InitUART(0,0x500);  	//初始化UART0,波特率:19200bps  50MHz 0=COM1;1=COM2
	i_printf("\r\n\r\n\r\n\r\n\r\n");	//输出主菜单信息
	i_printf("*******************************************************************************\n\r");
	i_printf("*                                                                             *\n\r");
	i_printf("*                   BootLoader for H4510E/M (Version:050601)                  *\n\r");
	i_printf("*                                                                             *\n\r");
	i_printf("*                    Beijing Hyesco Technology Co. Ltd                        *\n\r");
	i_printf("*                          http://www.hyesco.com                              *\n\r");
	i_printf("*                          Tel: (86-10) 62121051                              *\n\r");
	i_printf("*                                                                             *\n\r");
	i_printf("*              Room539,B Building, No.48 Zhongguancun South Street            *\n\r");
	i_printf("*                 Haidian District,Beijing 100085,P.R.China                   *\n\r");
	i_printf("*                                                                             *\n\r");
	i_printf("*                               All Rights Reserved                           *\n\r");
	i_printf("*                                                                             *\n\r");
Loop:
	i_printf("*******************************************************************************\n\r");
	i_printf("*  Please Input the Item Number:                                              *\n\r");
	i_printf("*  [0]    System Information            [1]    GPIO Test                      *\n\r");
	i_printf("*  [2]    LED Test (H4510M Only)        [3]    Set IP Address                 *\n\r");
	i_printf("*  [4]    ADC Test (H4510M Only)        [5]    DAC Test      (H4510M Only)    *\n\r");
	i_printf("*  [6]    RTC Test                      [7]    Keyboard Test (H4510M Only)    *\n\r");
	i_printf("*  [8]    LCD Test (H4510M Only)        [9]    Download OS/User Program       *\n\r");
	i_printf("*  [a]    Update Bootloader             [b]    Reserved                       *\n\r");
	i_printf("*  [c]    Reserved                      [d]    Reserved                       *\n\r");	
	i_printf("*******************************************************************************\n\r");
	while(1)
	{                         

		put_char(0, 0x0d);			//等待用户按键输入
		ch=get_char(0);
		switch(ch)
			{
			case '0':Sys_Info();
				break;	
			case '1':Test_GPIO();		//调用GPIO测试子程序
				goto Loop;
			case '2':LED_test();		//调用LED测试子程序
				goto Loop;
			case '3':Para_Save();	//调用IIC测试子程序
				break;
			case '4':ADC_test();		//调用ADC测试子程序
				goto Loop;
			case '5':DAC_test();		//调用DAC测试子程序
				goto Loop;
			case '6':Test_RTC();		//调用RTC测试子程序
				goto Loop;
			case '7':KeyTest();		//调用键盘测试子程序
				goto Loop;
			case '8':LCD_Test();		//调用LCD测试子程序
				goto Loop;
			case '9':download();		//调用用户程序下载子程序
				break;
			case 'a':
				Update_Bootloader();	//调用BootLoader自更新子程序
				break;
			default:
				{i_printf("\r\n");
				goto Loop;}   
			}	
	}    
}

//*************************************************************************************************
//*Function Name:		Para_Save(void)							  		
//*Function Description:	将系统参数保存到Flash的最后一个扇区,此处为系统的IP地址  	                          
//*Date:			2004-01-04					                          
//*************************************************************************************************
void Para_Save(void)
{
	char size[10],ch,Flag;
	
	unsigned short a[4],i,temp,k,Byte;
	volatile unsigned short *address;
	
//****************************************************************
//**** 	从Flash的最后一个扇区读取IP地址,以ASCII码格式显示 
//****  #define AM_SECTOR_ADDR_31   0x11f0000  (在Flash.h中定义)
//****************************************************************
	address=(unsigned short *)AM_SECTOR_ADDR_31;
	for(i=0;i<4;i++)
		{
		a[i]=(*address)&0xff;			//仅保留低字节;
		address++;
		}
	i_printf("\r\n>>>IP Address: ");

	for(i=0;i<4;i++)
		{
		Flag='0';	
		temp=a[i];
		temp=temp/100;
		if(temp!=0)
			{
			put_char(0,temp+0x30);
			Flag='1';
			}
		a[i]=a[i]-temp*100;
		temp=a[i];
		temp=temp/10;
		if((temp==0)&&(Flag=='0'))
			;
		else
			put_char(0,temp+0x30);
		a[i]=a[i]-temp*10;
		temp=a[i];
		put_char(0,temp+0x30);
		if(i<3)
			put_char(0,'.');
		}

//*********************************************************
//****	chioce to change IP address
//*********************************************************
	i_printf("\r\n\r\n>>>Do You Want to Change IP Address?(Y/N)---");
	ch=get_char(0);
	if((ch!='Y')&&(ch!='y'))
		{
		i_printf("\r\n");
		return;
		}
	put_char(0, ch);

//*********************************************************
//****	Here,We input the new IP address and change it 
//****	into binary format.
//*********************************************************
	i_printf("\r\n>>>Please Input New IP Address:");
	a[0]=a[1]=a[2]=a[3]=0;
	for(Byte=0;Byte<4;Byte++)
		{
		i_printf("\r\n>>>Byte ");
		put_char(0,Byte+0x31);
		i_printf(": ");
		i=0;
		size[0]=get_char(0);
		do
		{
			i_printf("%c",size[i]);
			if(size[i]>'9'||size[i]<'0')
				{
				i_printf("\r\n\r\nSorry,IP Addres Error!\r\n\r\n");
				return;
				}
			i++;
			size[i]=get_char(0);
		}while(size[i]!=0x0d);
		for(k=0;k<i;k++)	
			a[Byte]=a[Byte]*10+size[k]-'0';
		if(a[Byte]>255)
			{
			i_printf("\r\n\r\nSorry,IP Addres Out of Range!\r\n\r\n");
			return;
			}
		}

	i_printf("\r\n\r\n>>>Change IP Address?(Y/N)---");
	ch=get_char(0);
	if((ch!='Y')&&(ch!='y'))
		{
		i_printf("\r\n");
		return;
		}
	put_char(0, ch);

//*********************************************************
//****	首先擦除Flash的最后一个扇区;
//*********************************************************
	//i_printf("\r\n>>>Erase Parameter Area,Please Wait...");
	Flash_Unlock();
	*((volatile unsigned short *)AM_SECTOR_ADDR_31) = AM_SECTOR_ERASE;	//0x3030	
	//i_printf(",Blank Check...");
aaa1:	
	Delay(50000);		         
	for(address=(unsigned short *)AM_SECTOR_ADDR_31;address<(unsigned short *)AM_SECTOR_ADDR_31+ 0xff;address++)
		{
		if(*address!=0xffff)
			{
			goto aaa1;
			}
		}
	//i_printf(", OK!\r\n");    	
//*********************************************************
//****	然后写入新的IP地址;
//*********************************************************	
	address=(unsigned short *)AM_SECTOR_ADDR_31;
	for(i=0;i<4;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; 
  		*address = a[i];
		Delay(10);
		while(*address!=a[i])
			{
			Delay(10);
			}
		address++;
	}
	i_printf("\r\n\r\n>>>IP Address Changed!\r\n");	
}

/************************************************************************/
/*Function Description:	Flash解锁					*/
/*Date:			2003-12-2					*/
/************************************************************************/
void Flash_Unlock(void)
{
	*((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	
}


/************************************************************************/
/*Function Description:	System Information			*/
/*Date:			2003-12-2				*/
/************************************************************************/
void Sys_Info()
{
	//输出系统基本信息
	i_printf("\r\n\r\n\r\n\r\n\r\n");
	i_printf("*******************************************************************************\n\r");
	i_printf("*                       System    Information                                 *\n\r");
	i_printf("*                                                                             *\n\r");
	i_printf("*        CPU:       S3C4510B            Ope Fre:     50MHz                    *\n\r");
	i_printf("*        Flash:     2MB                 SDRAM:       16MB                     *\n\r");
	i_printf("*        Ethernet:  10M/100M            Input Volt:  AC 220V                  *\n\r");
	i_printf("*                                                                             *\n\r");
	i_printf("*******************************************************************************\n\r");
	i_printf("*                         After     Remap                                     *\n\r");
	i_printf("*                                                                             *\n\r");
	i_printf("*          SDRAM Address:     0x0000,0000~0x0100,0000-1                       *\n\r");
	i_printf("*          Flash Address:     0x0100,0000~0x0120,0000-1                       *\n\r");
	i_printf("*******************************************************************************\n\r");
	i_printf("\n\rPress Any Key to Continue...\r\n");

}

/************************************************************************/
/*Function Description:	Test GPIO          			*/
/*Date:			2004-7-12				*/
/************************************************************************/
void Test_GPIO(void)
{
	i_printf("\r\n\r\nGPIO Test,Press any Key to Continue...\r\n\r\n");
	IOPMOD=0xff;			//设置GPIO为输出模式
	while(1){
		IOPDATA=0x1;		//GPIO0~GPIO7轮流点亮
		Delay(500000);
		IOPDATA=0x2;
		Delay(500000);
		IOPDATA=0x4;
		Delay(500000);
		IOPDATA=0x8;
		Delay(500000);
		IOPDATA=0x10;
		Delay(500000);
		IOPDATA=0x20;
		Delay(500000);
		IOPDATA=0x40;
		Delay(500000);
		IOPDATA=0x80;
		Delay(500000);
		if(kbd_hit())		//如有用户按键,退出该GPIO测试程序
			{
			IOPDATA=0x0;
			return;
			}
		}
	return;
}

void Delay(int i)
{	int j,k;
	for(j=0;j<i;j++)
		{
		k=0;
		}
}


/****************************************************************/
/*Function Description:	Initial UART				*/
/*Date:			2003-12-2				*/
/****************************************************************/
void InitUART(int Port,int Baudrate)
{
	if(Port==0)
		{
		ULCON0=0x03;
		UCON0=0x09;
		UBRDIV0=Baudrate;   
		}
	if(Port==1)
		{
		ULCON1=0x03;
		UCON1=0x09;
		UBRDIV1=Baudrate;   
		}

}

/****************************************************************/
/*Function Description:	Install interrupt handler		*/
/*Date:			2003-12-2				*/
/****************************************************************/
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 + -