新聞中心

s3c2440的簡(jiǎn)單BOOTLOADER

作者: 時(shí)間:2016-11-10 來(lái)源:網(wǎng)絡(luò) 收藏
調(diào)試了很久終于成功啟動(dòng)了板子,這個(gè)程序分兩個(gè)部分,一個(gè)是啟動(dòng)代碼boot.s負(fù)責(zé)初始化硬件并拷貝前4k的程序到內(nèi)存中執(zhí)行。另外一個(gè)是主程序文件main.c,main設(shè)置UART并使用串口循環(huán)輸出打印一個(gè)類(lèi)似于shell的界面,可以接收命令,但暫時(shí)沒(méi)做命令解釋,功能還不全,主要是為了看看能不能實(shí)現(xiàn)基本的BOOTLOADER功能。

本文引用地址:http://m.butianyuan.cn/article/201611/317181.htm

mian.c
#define BUF_SIZE 100
#define GPHCON (*(volatile unsigned long *)0x56000070)
#define GPHUP (*(volatile unsigned long *)0x56000078)

#define ULCON0 (*(volatile unsigned long *)0x50000000)
#define UCON0 (*(volatile unsigned long *)0x50000004)
#define UFCON0 (*(volatile unsigned long *)0x50000008)
#define UTRSTAT0 (*(volatile unsigned long *)0x50000010)
#define UTXH0 (*(volatile unsigned long *)0x50000020)
#define URXH0 (*(volatile unsigned long *)0x50000024)
#define UBRDIV0 (*(volatile unsigned long *)0x50000028)

void init_uart();
void newline();
void bzero(char *buf,int size);
void do_cmd(char *s);
void send_char(char ch);
void send_msg(char *s);
void get_msg(char *buf,int size);
void print_shell();
void delay(int i);

void main(void)
{
init_uart();

char msg[BUF_SIZE];

while(1)
{
bzero(msg,BUF_SIZE);
newline();
print_shell();
get_msg(msg,BUF_SIZE - 2);
do_cmd(msg);
// delay(4);
}
}


void init_uart()
{
GPHCON &= ~(0xf0);
GPHCON |= 0xa0;
GPHUP = 0xc;

ULCON0 = 0x03;
UCON0 = 0x05;
UFCON0 = 0;
UBRDIV0 = 27;
}

void newline()
{
send_char(r);
send_char(n);
}

void bzero(char *buf,int size)
{
int i;

for(i = 0;i < size;i++)
buf[i] = 0;
}

void send_char(char ch)
{
while(!((UTRSTAT0 >> 1) & 1));
UTXH0 = ch;
}

void send_msg(char *s)
{
while(*s !=