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

📄 shell.c

📁 杭州立宇泰ARMsys-P型ARM开发板BIOS代码
💻 C
📖 第 1 页 / 共 3 页
字号:
		puts("Get System Clock Fail\n");
		return -1;
	}
	for(j=0; j<i; j++)
		printf("%s Clock  : %dHz\n", clk[j].name, clk[j].freq);
	return 0;
}

/*******************************************************************************************************/
#ifdef	RTC_TIMER_SUPPORT

int GetTime(int argc, char *argv[])
{
	int i, error = 0;
	char *str;
	unsigned int hour, min, sec;
	
	RtcGetTime(&SysTime);
	printf("ARMSYS Time: %2x:%2x:%2x\n", SysTime.hour, SysTime.min, SysTime.sec);
	str = argv[1];
	if(argc == 2 && str[0] == '?')
	{
		puts("Display time : time \n");
		puts("Set new time : time 12:1:10 \n");	
		return 0;
	}
	
	if(argc>1) 
	{
		str = argv[1];
		i = 0;
		if(str[++i]!=':')
			if(str[++i]!=':')
				error = 1;
		str[i] = 0;		
		hour = strtobcd(str);
		if(hour>0x23||error) 
		{
			printf("hour error!\n");
			return -1;
		}
		
		str	+= i+1;
		i = 0;
		if(str[++i]!=':')
			if(str[++i]!=':')
				error = 1;
		str[i] = 0;
		min = strtobcd(str);
		if(min>0x59||error) 
		{
			printf("minute error!\n");
			return -1;
		}
		
		str	+= i+1;
		i = 0;
		if(str[++i]!=0)
			if(str[++i]!=0)
				error = 1;
		str[i] = 0;
		sec = strtobcd(str);
		if(sec>0x59||error) 
		{
			printf("second error!\n");
			return -1;
		}
		
		SysTime.hour = hour;
		SysTime.min  = min;
		SysTime.sec = sec;		
		RtcSetTime(&SysTime);

		printf("Set ");
		GetTime(0, NULL);
	}	
	return 0;
}

/*******************************************************************************************************/
int GetDate(int argc, char *argv[])
{
	int i, error = 0;
	char *str;
	unsigned int year, month, day;
	
	RtcGetTime(&SysTime);
	printf("ARMSYS Date: %x-%x-%x [%s]\n", SysTime.year, SysTime.month, SysTime.day, WeekDay[(SysTime.weekday-1U)%7U]);

	if(argc<2)
		return 0;
	str = argv[1];
	if(argc==2 && str[0] == '?')
	{
		puts("Display date : date \n");
		puts("Set new date : date 2005-1-1 \n");	
		return 0;
	}
	
	str = argv[1];
	if(str[4]!='-')
		error=1;
	str[4]=0;
	year = strtobcd(str);	
	if((year<0x2000)||(year>0x2099)||error) 
	{
		printf("year error!\n");
		return -1;
	}
				
	str += 5;
	i = 0;		
	if(str[++i]!='-')
		if(str[++i]!='-')
			error = 1;
	str[i] = 0;					
	month = strtobcd(str);
	if((month-1)>0x11||error) 
	{
		printf("month error!\n");
		return -1;
	}		
		
	str += i+1;		
	i = 0;
	if(str[++i]!=0)
		if(str[++i]!=0)
			error = 1;
	str[i] = 0;		
	day = strtobcd(str);
	if((day-1)>0x30||error) 
	{
		printf("day error!\n");
		return -1;
	}	
	
	SysTime.year  = year;
	SysTime.month = month;
	SysTime.day   = day;		
	RtcSetDay(&SysTime);

	printf("Set ");
	GetDate(0, NULL);
	
	return 0;
}

/*******************************************************************************************************/
int SetWeek(int argc, char *argv[])
{
	unsigned int i;
	int error = 0;	
	
	if(argc<2)
		error = 1;	
	
	i = strtodec(argv[1], 1);
	if((i-1)>6)		//0-1 = 0xffffffff
		error = 1;
	
	if(!error) 
	{
		SysTime.weekday = i;	//1~7
		RtcSetWeek(&SysTime);
		//printf("Set to %s\n", WeekDay[i-1]);
		GetDate(0, NULL);
	} 
	else 
	{
		puts("Please enter a number to set weekday\n");
		for(i=1; i<=7; i++) 
		{
			printf("%d : %s\n", i, WeekDay[i-1]);
		}
	}
	
	return 0;	
}

#endif		//RTC_TIMER_SUPPORT
/*******************************************************************************************************/
#ifdef	SET_SYSCLK_SUPPORT

int ChgSysClk(int argc, char *argv[])
{	
	
	puts("This function is for adjust system running clock!!!\n");

	ShowSysClock(0, NULL);	
	
	if(!SetSysClock()) 
	{
		GetSysClockPara(Env.clk_para);	
		TimerInit(TIMER_FREQ);		
		SerialChgBaud(Env.baud);
		Delay(100);
		ShowSysClock(0, NULL);
	}
	
	return 0;
}

#endif		//SET_SYSCLK_SUPPORT
/*******************************************************************************************************/
int ChgBaudRate(int argc, char *argv[])
{
	int i;
	
	for(i=0; BaudSet[i]; i++)
		printf("%d : %d\n", i, BaudSet[i]);
		
	puts("Please enter choice : ");
	
	while(1)
	{
		int ch = getch();
		
		if(ch<='6'||ch>='0')
		{
			Env.baud = BaudSet[ch-'0'];
			printf("Baud rate set to : %d\nPress any key to continue\n", Env.baud);
			i = 0x4000;
			while(i--);		//wait transmit end
			SerialChgBaud(Env.baud);
			getch();
			break;
		}
			
	}	

	return 0;
}


/*******************************************************************************************************/
#ifdef	TFTP_DOWNLOAD_SUPPORT

int SetIpAddr(int argc, char *argv[])
{
	int i, j, err = 0;
	char *str;
	char ch = '.';
	U32 ip[4];
	
	if(argc<2) 
	{
		printf("IP address : %u.%u.%u.%u\n", (Env.nic_cfg.ip>>24)&0xff, (Env.nic_cfg.ip>>16)&0xff, (Env.nic_cfg.ip>>8)&0xff, Env.nic_cfg.ip&0xff);
		return 0;
	}
	str = argv[1];
	if(argc==2 && str[0] == '?')
	{
		puts("Display IP : ipcfg \n");
		puts("Set new IP : ipcfg 192.168.253.2 \n");	
		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]>=255)||err) 
		{
			printf("IP address error\n");
			return -1;
		}					
		str += i+1;
	}
	
	printf("Set IP address : %u.%u.%u.%u\n", ip[0], ip[1], ip[2], ip[3]);					
	Env.nic_cfg.ip = (ip[0]<<24)|(ip[1]<<16)|(ip[2]<<8)|ip[3];	
	return 0;	
}

int LoadFromNet(int argc, char *argv[])
{
	char *str;
	str = argv[1];
	if(argc==2 && str[0] == '?')
	{
		puts("Default download address : netload \n");
		puts("Set new download address : netload destination_address \n");	
		return 0;
	}
	if(argc<2)
		download_addr = DFT_DOWNLOAD_ADDR;
	else 
	{
		unsigned long tmp;
		tmp = strtoul((char*)argv[1]);
		download_addr = (tmp==-1)? download_addr:tmp;
	}
	
	printf("Now download file from net to 0x%x...\n", download_addr);
	
	download_len = -1;
	//CacheDisable() ;		//
	tftp_main(download_addr, Env.nic_cfg.ip);
	//CacheFlush();		//
	//CacheEnable();		//
	if(download_len==-1) 
	{
		puts("Tftp Download Aborted!\n");
	} else
		printf("\nReceived %u[0x%x] bytes success\n", download_len,download_len);
		
	return download_len;
}

int NetLoadRun(int argc, char *argv[])
{	
	if(LoadFromNet(argc, argv)>0) 
	{
		RunProgram(0, NULL);
	}
	return 0;	
}

#endif	/*TFTP_DOWNLOAD_SUPPORT*/



int LoadFromUart(int argc, char *argv[])
{
	int i, size;
	unsigned short dnCS, CheckSum;
	unsigned char *buf = (unsigned char *)DFT_DOWNLOAD_ADDR;
	unsigned char RxTmp[8];
	char *str;
	
	str = argv[1];
	if(argc==2 && str[0] == '?')
	{
		puts("Default download address : comload \n");
		puts("Set new download address : comload destination_address \n");	
		return 0;
	}
	if(argc<2)
		download_addr = DFT_DOWNLOAD_ADDR;
	else 
	{
		unsigned long tmp;
		tmp = strtoul((char*)argv[1]);
		download_addr = (tmp==-1)? download_addr:tmp;
	}
	
	buf = (unsigned char *)download_addr;
	
	printf("Now download file from uart0 to 0x%x...\n", download_addr);
	
	i = 0;
	while(i<4)
		RxTmp[i++] = getch();
    
    i = 0;
    size = *(unsigned long *)RxTmp - 4;
	while(i<size)
		buf[i++] = getch();
	
	download_len = size-2;	
	
	dnCS = (buf[size-1]<<8)|buf[size-2];
	CheckSum = 0;
	for(size -= 3; size>=0; size--)
		CheckSum += buf[size];
	if(dnCS!=CheckSum) 
	{
		puts("\nCheckSum error!\n");
		download_len = -1;
	} 
	else
		printf("\nReceived %u[0x%x] bytes success\n", download_len,download_len);
		
	return download_len;
}

int UartLoadRun(int argc, char *argv[])
{
	if(LoadFromUart(argc, argv)>0) 
	{
		RunProgram(0, NULL);
	}
	return 0;
}

//*****************************************************************************
int RunProgram(int argc, char *argv[])
{
	void (*fp)(U32, U32) = (void (*)(U32, U32))download_addr;
	char *str;
	
	str = argv[1];
	if(argc==2 && str[0] == '?')
	{
		puts("Run download program    : run \n");
		puts("Run new address program : run source_address \n");	
		return 0;
	}
	
	if(argc>1) 
	{
		unsigned int p = strtoul((char *)argv[1]);
		if((p!=-1)&&!(p&3))
			fp = (void (*)(U32, U32))p;			
	}	
	
	printf("Run program from 0x%x\n", fp);
	if(argc) 
	{
		printf("are you sure?");
		if(!getyorn())
			return 0;
	}
		
	DisableInt();	
	CacheFlush();
	CacheDisable();		//先clean DCache, 再Disable DCache
	BoardPrepareRun();	
	printf("Plese wait a moment to start running...\n");
	Delay(100);		//it should be delay a long time for pc software stable
	(*fp)(0, Env.machine);
	return 0;
}

int MoveMem(int argc, char*argv[])
{
	unsigned int src, dst, size;
	
	if(argc<4) 
	{
		puts("Usage : move a1 a2 size\n");
		puts("a1 = src address, a2 = dst address, size = copy bytes (all in hex)\n");
		return -1;
	}

	src  = strtoul((char *)argv[1]);
	dst  = strtoul((char *)argv[2]);
	size = strtoul((char *)argv[3]);

	if(src==-1||dst==-1||size==-1) 
	{
		puts("give error address\n");
		return	-1;
	}
		
	Memcpy((char *)dst, (char *)src, size);

	puts("move finished!\n");
	return 0;
}

int MemoryDisplay(int argc, char*argv[])
{
	static unsigned int src_addr;
	unsigned int src;
	unsigned int i, j;
	//unsigned int tmp_data[64];
	
	if(argc > 1) 
	{
		unsigned int tmp = strtoul((char *)argv[1]);
		src_addr  = (tmp==-1)?src_addr:tmp;
		src_addr &= ~0xf;
	}
	
	printf("Press ESC key to exit, other key to continue...\n");

	do 
	{
		src = src_addr;
		src_addr += 0x100;
		
//		CacheDisable();
		CacheFlush();		//防止tmp_data被cache
//		CacheEnable();
		
		//for(i=0; i<64; i++)
		//	tmp_data[i] = ((unsigned int *)src)[i];

		for(i=0; i<16; i++) 
		{
			unsigned char ch;
			
			printf("0x%-8x:", src+(i<<4));
			for(j=0; j<16; j++) 
			{
				//ch = ((unsigned char *)tmp_data)[(i<<4)+j];
				ch = ((U8 *)src)[(i<<4)+j];
				printf("%3x", ch);
			}
			putch(' ');
			putch(' ');

⌨️ 快捷键说明

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