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

📄 command.c

📁 基于arm7s3c2410开发板的bootloader的设计与实现源代码 采用汇编语言和C语言编写
💻 C
字号:
/* *	command.c   -   shell command implementation *	 *	Author: 	yu feng <progeryf@gmail.com> *	Date:		2007-5-27 */#include "my_string.h"#include "my_printf.h"#include "shell.h"#include "command.h"#include "flash_39vf160.h"/* the file will be downloader here*/#define  DOWNLOAD_BIN_ADDR	0x00008000/* first 64K (0x10000) is used for bootloader * from 0x10000(64K) - 0x200000(2M) is used for user boot image */#define	__ROM_SIZE	0x200000/* the size of bootloader you can read and write from here*/#define	BIOS_BASE	(__ROM_SIZE-0x1f0000)/* the address where user can use*/#define	BIOS_LOAD	(__ROM_SIZE-0x10000)int offset = 0;void help( void ){	my_printf( "\rhelp     - list of commands in this shell \n" );		my_printf( "\rdown     - download uue file to 0x8000  \n" );	my_printf( "\rgo       - run program at 0x8000  \n" );		return;}int go( void ){	unsigned current_pc;		my_printf( "\r<go>: to run code from 0x%x. \r\n", DOWNLOAD_BIN_ADDR );		current_pc = DOWNLOAD_BIN_ADDR;		((void (*)(void))(current_pc))();	return 1;}int cistreq(char *s, char *t, int term){	for ( ; ((*s | 0x20) == (*t | 0x20)) || (*s <= term && *t <= term); s++, t++)	if (*s <= term)		return 1;    	return 0;}char *nextword(char *word){	while (*word > ' ') word++;	while (*word == ' ') word++;	return word;}void SetLEDs(unsigned status){	volatile unsigned int * leds = (volatile unsigned int *)0x03ff5008;	*leds = status;}#define BEGIN "begin"#define END   "end"int download(void){	char *buffer = (char *)DOWNLOAD_BIN_ADDR;	char *s;	int errs = 0;	int i;	unsigned c, w;	int len; 	unsigned led_status = 0x20070;		char command_line[256];	char gpbuff[256];	SetLEDs(0);	my_printf("\rReady to download. Use 'transmit' option on terminal emulator to download file. \n");	s = command_line;	do 	{    			if (shell_readline(s) == -1)			return -1;		} while (!cistreq(s, BEGIN, ' '));	s = nextword(s);	s = nextword(s);	my_strcpy(gpbuff, s);		do 	{		s = command_line;		len = shell_readline( s );		led_status ^= 0x20070;		SetLEDs(led_status);				if (len == -1 || cistreq(s, END, ' '))			break;		c = *s++;				if (!c) 			continue;		len = c - 0x20;			if (len == 0) 			continue;		if (len > 45) 		{			errs++;			continue;		}		i = 0;				while (1) 		{			c = *s;			if (c)			{				c -= 0x20;				if (c >= 0x40) 				{					errs++;					break;				}				s++;			}			w = (w << 6) + c;			/* judge the last two bits is 00			 * if the last two bits is 00			 * deal it			 */			if ((++i & 3) == 0) 			{				buffer[offset++] = w >> 16;				if (--len == 0) 					break;				buffer[offset++] = w >> 8;				if (--len == 0) 					break;				buffer[offset++] = w;				if (--len == 0)					break;				}		}	} while (1);		SetLEDs( 0x20070 );	if (errs)		my_printf("\rError: %d errors encountered during download. \n", errs);	my_printf("\rLoaded file %s at address %x, size = %x <%d> \n", gpbuff, (int)buffer, offset, offset);	return 0;}int dump(void){	int i = 0;	unsigned char * address;//	address = (unsigned char *)DOWNLOAD_BIN_ADDR;	address = (unsigned char *)0x1010000;	for( i = 0; i < 0x1000; i++)	{		if(i%16 == 0)			my_printf("0x%x: ", i+address);		my_printf("%x ",*(address+i));		if((i+1)%16 == 0 )			my_printf("\r\n");	}}int flashw(int argc, char *argv[]){	my_printf( "write memory program to flash, size = 0x%x \r\n", offset );		SectorProg(BIOS_BASE, (unsigned short *)DOWNLOAD_BIN_ADDR, offset);		return 0;}int flashl(int argc, char *argv[]){	my_printf( "load flash program to mem, size = 0x%x \r\n", offset );	FlashRead(BIOS_BASE, (unsigned short *)DOWNLOAD_BIN_ADDR, offset );	return 0;}

⌨️ 快捷键说明

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