shell.c

来自「通过串口实现的CLI界面。在超级终端中实现界面的显示。支持命令记录和带多参数。功」· C语言 代码 · 共 1,427 行 · 第 1/3 页

C
1,427
字号
	INT32U BaudDiv[7]  = {0x28a0,	0x1440,	0xa20,	0x500,	0x280,	0x1a0,	0xd0 };
	BOOL   init0 = FAIL,init1 = FAIL;
	urt0baud = getBuf(UBRDIV0) & 0x0fff0;
	urt1baud = getBuf(UBRDIV1) & 0x0fff0;
	for(i=0; i<7; i++){
		if(urt0baud == BaudDiv[i]){
			urtPrintf("\n->:BaudRate of UART0 : %d\n",BaudTable[i]);
			init0 = PASS;
		}
		if(urt1baud == BaudDiv[i]){
			urtPrintf("\n->:BaudRate of UART1 : %d\n",BaudTable[i]);
			init0 = PASS;
		}

	}
	if(init0 == FAIL)urtPrintf("\n->UART0 not initialized!!\n");
	if(init1 == FAIL)urtPrintf("\n->UART1 not initialized!!\n");
	return PASS;
}



/*******************************************************************************************************/
INT32S SetIpAddr(INT32S argc, INT8S *argv[])
{
#if 0
	INT32S i, j, err = 0;
	INT8S *str;
	INT8S ch = '.';
	
	if(argc<2)
	{
		urtPrintf("IP address : %u.%u.%u.%u\n", (IP_ADDRESS>>24)&0xff, (IP_ADDRESS>>16)&0xff, (IP_ADDRESS>>8)&0xff, IP_ADDRESS&0xff);
		return 0;
	}
	
	str = argv[1];
	
	for(j=0; j<4; j++)
	{
		if(j==3)
			ch = 0;
		i = 0;
		if(str[++i]!=ch)
			if(str[++i]!=ch)
				if(str[++i]!=ch)
					err = 1;
		str[i] = 0;
		ip[j] = strtodec(str, i);
		if(ip[j]<0||ip[j]>254||err)
		{
			urtPrintf("IP address error\n");
			return -1;
		}			
		str += i+1;
	}
	
	urtPrintf("Set IP address : %u.%u.%u.%u\n", ip[0], ip[1], ip[2], ip[3]);					
	IP_ADDRESS = (ip[0]<<24)|(ip[1]<<16)|(ip[2]<<8)|ip[3];
	locnode.ip = IP_ADDRESS;
	ArpInit();
#endif
	urtPrintf("->Set IP address running ok!!\n");

	return 0;	
}


INT32S LoadFile2Mem(INT32S argc, INT8S *argv[])
{
#if 0
	INT8U key;

	if(argc<2)
		download_addr = DFT_DOWNLOAD_ADDR;
	else
		download_addr = strtoul((INT8U*)argv[1]);
	
	ResetNic();
	StartNic();

	urtPrintf("Now begin address for download, use address 0x%x\n", download_addr);
	urtPrintf("Load image file from host\n");
	urtPrintf("Type tftp -i %d.%d.%d.%d put filename at the host PC\n", (IP_ADDRESS>>24)&0xff, (IP_ADDRESS>>16)&0xff, (IP_ADDRESS>>8)&0xff, IP_ADDRESS&0xff);
	urtPrintf("Press ESC key to exit\n");	

	download_begin = 1;
	download_end = 0;
	
	while (1) 
	{
		NetSever();
		if ((key=urtReadyGet())==ESC_KEY)
		{
			urtPutChar('\n');
			download_begin = 0;
			return 0;
		}
		if(download_end)
		{
			download_begin = 0;
			download_end = 0;
			return 0;
		}
	}
	
	StopNic();
#endif
urtPrintf("->Loadfile2 mem running ok!!\n");
return 0; //hojin add//

}
//*****************************************************************************

/******************************************************************************
【功能说明】将目标代码通过网口下载到SDRAM的默认下载地址,然后运行下载的目标代码
******************************************************************************/
INT32S Net_Load_Run(INT32S argc, INT8S *argv[])
{
#if 0
	INT8U key;
	void (*fp)(void) = (void (*)(void))DFT_DOWNLOAD_ADDR;

	download_addr = DFT_DOWNLOAD_ADDR;

	ResetNic();
	StartNic();
	urtPrintf("Now begin address for download, use address 0x%x\n", download_addr);
	urtPrintf("Load image file from host\n");
	urtPrintf("Type tftp -i %d.%d.%d.%d put filename at the host PC\n", (IP_ADDRESS>>24)&0xff, (IP_ADDRESS>>16)&0xff, (IP_ADDRESS>>8)&0xff, IP_ADDRESS&0xff);
	urtPrintf("Press ESC key to exit\n\n");	

	download_begin = 1;
	download_end = 0;
	
	while (1) 
	{
		NetSever();
		if ((key=urtReadyGet())==ESC_KEY)
		{
			urtPutChar('\n');
			download_begin = 0;
			return 0;
		}
		if(download_end)
		{
			download_begin = 0;
			download_end = 0;
			goto NEXT_RUN_CODES ;
		}
	}

NEXT_RUN_CODES:
	urtPrintf( "Now run the received codes from address 0x%x!\n\n", DFT_DOWNLOAD_ADDR );
	(*fp)();
	
	return 0;
#endif
urtPrintf("->net_load_run running ok!!\n");
return 0; //hojin add //
}


INT32S LoadFromUart(INT32S argc, INT8S *argv[])
{
#if 0
	if(argc<2)
		download_addr = DFT_DOWNLOAD_ADDR;
	else
		download_addr = strtoul((INT8U*)argv[1]);

	urtPrintf("Now begin address for download, use address 0x%x\n", download_addr);
	urtPrintf("Use Xmodem Protocol\n");

	XmodemClient();
#endif
	urtPrintf("->LoadFromUrt running ok!!\n");

	return 0;
}
//*****************************************************************************

/******************************************************************************
【功能说明】将目标代码通过串口下载到SDRAM,然后运行下载的目标代码
******************************************************************************/
INT32S Uart_Load_Run(INT32S argc, INT8S *argv[])
{
#if 0
	void (*fp)(void) = (void (*)(void))DFT_DOWNLOAD_ADDR;

	download_addr = DFT_DOWNLOAD_ADDR;

	urtPrintf("Now begin address for download, use address 0x%x\n", download_addr);
	urtPrintf("Use Xmodem Protocol\n");

	if(XmodemClient() == 1)
	{
		urtPrintf( "Now run the received codes from address 0x%x!\n\n", DFT_DOWNLOAD_ADDR );
		(*fp)();
	}
#endif
	urtPrintf("->urt load run running ok!!\n");

	return 0;
}
//*****************************************************************************

INT32S RunProgram(INT32S argc, INT8S *argv[])
{
#if 0
	INT8U key;
	
	void (*fp)(void) = (void (*)(void))DFT_DOWNLOAD_ADDR;
	
	if(argc>1)
	{
		INT32S	p = strtoul((INT8U *)argv[1]);
		if(p>0)
			fp = (void (*)(void))p;			
	}
	
	urtPrintf("Run program from 0x%x, are you sure? [y/n]", fp);
	
	while(1)
	{
		key = urtReadyGet();
		if(key)
		{
			if(key=='y'||key=='Y')
			{
				urtPutChar(key);
				urtPutChar('\n');
				break;
			}
			if(key=='n'||key=='N')
			{
				urtPutChar(key);
				urtPutChar('\n');
				return 0;
			}				
		}
	}
	
	(*fp)();
#endif
	urtPrintf("->runPorgram running ok!!\n");

	return 0;		
}


INT32S ProgFlash(INT32S argc, INT8S *argv[])
{
#if 0
	INT8U key;
	INT32U size = ~0;
	INT32U data_begin = ~0;
	INT32U prog_begin = ~0;
	INT32U cache_cfg;

	if(argc!=4)
	{		
		urtPrintf("Arguments error!\n");
		urtPrintf("Usage:	prog a1 a2 size\na1 = program begin address\na2 = data poINT32Ser to ram\nsize = program size(Bytes)\n");
		return -1;
	}	
		
	prog_begin = strtoul((INT8U *)argv[1]);			
	data_begin = strtoul((INT8U *)argv[2]);
	size       = strtoul((INT8U *)argv[3]);
	
	if(size==0)
	{
		urtPrintf("Write 0 Bytes!\n");
		return -1;
	}
	
	if(prog_begin==-1||data_begin==-1)		//
	{
		urtPrintf("Arguments error\n");
		return -1;
	}	
	
	urtPrintf("program flash begin @0x%x, from ram data @0x%x, size = %dBytes\nAre you sure? [y/n]", prog_begin, data_begin, size);
	while(1)
	{
		key = urtReadyGet();
		if(key)
		{
			if(key=='y'||key=='Y')
			{
				urtPutChar(key);
				urtPutChar('\n');
				break;
			}
			if(key=='n'||key=='N')
			{
				urtPutChar(key);
				urtPutChar('\n');
				return 0;
			}				
		}
	}		

	cache_cfg = rNCACHBE0;
	rNCACHBE0 = 0x20000000;
	SectorProg(prog_begin, (INT16U *)data_begin, size);
	
	rNCACHBE0 = cache_cfg;
#endif
	urtPrintf("->PorgFlash running ok!!\n");

	return 0;
}
//*****************************************************************************

/******************************************************************************
【功能说明】通过TFTP软件,将目标代码通过以太网下载到SDRAM,然后
将下载的目标代码原原本本烧写到Flash中去,不对代码进行任何修改,适合于烧写BIOS
******************************************************************************/
INT32S Bios_Auto_Prog_Flash(INT32S argc, INT8S *argv[])
{
#if 0
	INT8U key;
	INT8S ch_tmp[4][10];
	INT8S *para_ptr[4];	

	download_addr = DFT_DOWNLOAD_ADDR;

	ResetNic();
	StartNic();
	urtPrintf("Now begin address for download, use address 0x%x\n", download_addr);
	urtPrintf("Load image file from host\n");
	urtPrintf("Type tftp -i %d.%d.%d.%d put filename at the host PC\n", (IP_ADDRESS>>24)&0xff, (IP_ADDRESS>>16)&0xff, (IP_ADDRESS>>8)&0xff, IP_ADDRESS&0xff);
	urtPrintf("Press ESC key to exit\n");	

	download_begin = 1;
	download_end = 0;
	
	while (1) 
	{
		NetSever();
		if ((key=urtReadyGet())==ESC_KEY)
		{
			urtPutChar('\n');
			download_begin = 0;
			return 0 ;
		}
		if(download_end)
		{
			download_begin = 0;
			download_end = 0;
			goto Next_Program_Flash ;
		}
	}
		
	//*********************************************************************
Next_Program_Flash:
	ultostr((INT8U *)ch_tmp[0], 0);	
	ultostr((INT8U *)ch_tmp[1], DFT_DOWNLOAD_ADDR);	 	
	ultostr((INT8U *)ch_tmp[2], download_len);		


	para_ptr[1] = ch_tmp[0];
	para_ptr[2] = ch_tmp[1];
	para_ptr[3] = ch_tmp[2];	
	//将直接将下载的目标代码原原本本烧写到Flash中去,不作任何改动
	
	ProgFlash(4, para_ptr);
#endif 
	urtPrintf("->Bios_Auto_Prog_Flash running ok!!\n");

	return	0;	
}
//*****************************************************************************

/******************************************************************************
【功能说明】通过TFTP软件,将目标代码通过以太网下载的SDRAM,然后将下载的代码烧写
到Flash中去,不过在Flash最低地址放置了跳转到BIOS的跳转指令,适合于烧写应用程序
******************************************************************************/
INT32S APP_Auto_Prog_Flash(INT32S argc, INT8S *argv[])
{
#if 0
	INT8U key;
	INT8S ch_tmp[3][10];
	INT8S *para_ptr[4];	

	download_addr = DFT_DOWNLOAD_ADDR;

	ResetNic();
	StartNic();

	urtPrintf("Now begin address for download, use address 0x%x\n", download_addr);
	urtPrintf("Load image file from host\n");
	urtPrintf("Type tftp -i %d.%d.%d.%d put filename at the host PC\n", (IP_ADDRESS>>24)&0xff, (IP_ADDRESS>>16)&0xff, (IP_ADDRESS>>8)&0xff, IP_ADDRESS&0xff);
	urtPrintf("Press ESC key to exit\n");	

	download_begin = 1;
	download_end = 0;
	
	while (1) 
	{
		NetSever();
		if ((key=urtReadyGet())==ESC_KEY)
		{
			urtPutChar('\n');
			download_begin = 0;
			return 0 ;
		}
		if(download_end)
		{
			download_begin = 0;
			download_end = 0;
			goto Next_Program_Flash ;
		}
	}
		
	//*********************************************************************
Next_Program_Flash:
	ultostr((INT8U *)ch_tmp[0], 0x10000);	
	ultostr((INT8U *)ch_tmp[1], DFT_DOWNLOAD_ADDR);	 	
	ultostr((INT8U *)ch_tmp[2], download_len);		

	para_ptr[1] = ch_tmp[0];
	para_ptr[2] = ch_tmp[1];
	para_ptr[3] = ch_tmp[2];	
	
	ProgFlash(4, para_ptr);
#endif
	urtPrintf("->APP_AutoProg_Flash running ok!!\n");

	return	0;	
	
}
//*****************************************************************************

INT32S CopyFlash(INT32S argc, INT8S *argv[])
{
#if 0
	INT32U src, dst, size;
	INT32U cache_cfg;
	INT8S tmp[10];
	
	if(argc<4)
	{
		urtPrintf("Usage : copy a1 a2 size\n");
		urtPrintf("a1 = src address, a2 = dst address, size = copy bytes (all in hex)\n");
		return -1;
	}
	
	src  = strtoul((INT8U *)argv[1]);
	dst  = strtoul((INT8U *)argv[2]);
	size = strtoul((INT8U *)argv[3]);
	if(src==-1||dst==-1||size==-1)
	{
		urtPrintf("give error address\n");
		return	-1;
	}	

	cache_cfg = rNCACHBE0;
	rNCACHBE0 = 0x20000000;
	FlashRead(src, (INT16U *)DFT_DOWNLOAD_ADDR, size);
	rNCACHBE0 = cache_cfg;

	argv[1] = argv[2];
	argv[2] = tmp;
	ultostr((INT8U *)tmp, DFT_DOWNLOAD_ADDR);
	
	ProgFlash(4, argv);
#endif 
	urtPrintf("->Copy Flash running ok!!\n");

	return 0;
}


⌨️ 快捷键说明

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