📄 shell.c
字号:
i = strtodec(argv[1], 1);
if((i-1)>5)
error = 1;
if(!error)
{
SysTime.weekday = i;
RtcSetWeek(&SysTime);
printf("Set to %s\n", WeekDay[i]);
}
else
{
printf("Please enter weekday\n");
printf("0 : Sunday\n");
printf("1 : Monday\n");
printf("2 : Tuesday\n");
printf("3 : Wednesday\n");
printf("4 : Thursday\n");
printf("5 : Friday\n");
printf("6 : Satday\n");
}
return 0;
}
#endif
/*******************************************************************************************************/
#if 0
int GetTime(int argc, char *argv[])
{
int i, error = 0;
char *str;
unsigned int hour, min, sec;
RtcGetTime(&SysTime);
printf("Current time is %2.2x:%2.2x:%2.2x\n", SysTime.hour, SysTime.min, SysTime.sec);
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 error;
}
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 error;
}
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 error;
}
SysTime.hour = hour;
SysTime.min = min;
SysTime.sec = sec;
RtcSetTime(&SysTime);
printf("Set time %x:%x:%x\n", hour, min, sec);
}
return error;
}
#endif
/*******************************************************************************************************/
#if 0
int ChgSysMclk(int argc, char *argv[])
{
int i, mdiv, pdiv, sdiv;
char tmp[4];
printf("This function is for adjust system running clock!!!\n");
printf("Current clock is %dHz\n", MCLK);
printf("Please enter the PLL parameter to use, mdiv[0-255], pdiv[0-63], sdiv[0-3]\n");
printf("mdiv: ");
if((mdiv=strtodec(tmp, GetParameter(tmp, 3)))<0)
{
printf("\nget mdiv Error!\n");
return 0;
}
printf("\npdiv: ");
if((pdiv=strtodec(tmp, GetParameter(tmp, 3)))<0)
{
printf("\nget pdiv Error!\n");
return 0;
}
printf("\nsdiv: ");
if((sdiv=strtodec(tmp, GetParameter(tmp, 3)))<0)
{
printf("\nget sdiv Error!\n");
return 0;
}
printf("\nYou set System clock mdiv = %d, pdiv = %d, sdiv = %d\n", mdiv, pdiv, sdiv);
i = 8000;
while(i--);
ChangePllValue(mdiv, pdiv, sdiv);
i = 8000;
while(i--);
Uart_Init(0,SERIAL_BAUD);
printf("Current clock is %dHz\n", MCLK);
return 0;
}
#endif
/*******************************************************************************************************/
#if 0
int ChgBaudRate(int argc, char *argv[])
{
int i;
unsigned int BaudSet [6] = {4800, 9600, 19200, 38400, 57600, 115200};
for(i=0; i<6; i++)
printf("%d : %d\n", i, BaudSet[i]);
printf("Please enter choice : ");
while(1)
{
int ch = UartGetch();
if(ch<='6'||ch>='0')
{
SERIAL_BAUD = BaudSet[ch-'0'];
printf("Baud rate set to : %d\nPress any key to continue\n", SERIAL_BAUD);
i = 0x4000;
while(i--); //wait transmit end
Uart_Init(0,SERIAL_BAUD);
UartGetch();
break;
}
}
return 0;
}
#endif
/*******************************************************************************************************/
int SetIpAddr(int argc, char *argv[])
{
int i, j, err = 0;
char *str;
char ch = '.';
if(argc<2)
{
printf("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)
{
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]);
IP_ADDRESS = (ip[0]<<24)|(ip[1]<<16)|(ip[2]<<8)|ip[3];
locnode.ip = IP_ADDRESS;
ArpInit();
return 0;
}
int LoadFile2Mem(int argc, char *argv[])
{
unsigned char key;
if(argc<2)
download_addr = DFT_DOWNLOAD_ADDR;
else
download_addr = strtoul((unsigned char*)argv[1]);
ResetNic();
printf("No begin address for download, use address 0x%x\n", download_addr);
printf("Load image file from host\n");
printf("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);
printf("Press ESC key to exit\n");
download_begin = 1;
download_end = 0;
while (1)
{
NetSever();
if ((key=Uart_GetKey())==ESC_KEY)
{
Uart_SendByte('\n');
download_begin = 0;
return 0;
}
if(download_end)
{
download_begin = 0;
download_end = 0;
return 0;
}
}
}
int LoadFromUart(int argc, char *argv[])
{
int start, time_out;
int load_addr = DFT_DOWNLOAD_ADDR;
if(argc>1)
{
start = strtoul((unsigned char*)argv[1]);
if(load_addr>0)
load_addr = start;
}
start = load_addr;
time_out = WAIT_TIME;
do{
if(rUTRSTAT0&0x1)
{
*((unsigned char *)load_addr++) = Uart_GetKey();
time_out = WAIT_TIME;
}
}while(--time_out);
printf("Received 0x%x bytes from serial port.\n", load_addr-start);
return 0;
}
int RunProgram(int argc, char *argv[])
{
unsigned char key;
void (*fp)(void) = (void (*)(void))DFT_DOWNLOAD_ADDR;
if(argc>1)
{
int p = strtoul((unsigned char *)argv[1]);
if(p>0)
fp = (void (*)(void))p;
}
printf("Run program from 0x%x, are you aure? [y/n]", fp);
while(1)
{
key = Uart_GetKey();
if(key)
{
if(key=='y'||key=='Y')
{
Uart_SendByte(key);
Uart_SendByte('\n');
break;
}
if(key=='n'||key=='N')
{
Uart_SendByte(key);
Uart_SendByte('\n');
return 0;
}
}
}
(*fp)();
return 0;
}
#if 0
int ProgFlash(int argc, char *argv[])
{
unsigned char key;
unsigned int size = ~0;
unsigned int data_begin = ~0;
unsigned int prog_begin = ~0;
unsigned int cache_cfg;
int overwrite0 = 1;
int modify_a0 = 0;
unsigned int bios_load_addr;
if(argc<4)
{
printf("Arguments error!\n");
printf("Usage: prog a1 a2 size [-no0]\na1 = program begin address\na2 = data pointer to ram\nsize = program size(Bytes)\n-no0 = don't overwrite address 0\n");
return -1;
}
prog_begin = strtoul((unsigned char *)argv[1]);
data_begin = strtoul((unsigned char *)argv[2]);
size = strtoul((unsigned char *)argv[3]);
if(size==0)
{
printf("Write 0 Bytes!\n");
return -1;
}
if(prog_begin==-1||data_begin==-1) //
{
printf("Arguments error\n");
return -1;
}
printf("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 = Uart_GetKey();
if(key)
{
if(key=='y'||key=='Y')
{
Uart_SendByte(key);
Uart_SendByte('\n');
break;
}
if(key=='n'||key=='N')
{
Uart_SendByte(key);
Uart_SendByte('\n');
return 0;
}
}
}
if(argc>4)
if(strncmp(argv[4], "-no0", 4)==0)
overwrite0 = 0;
if((prog_begin==0)&&overwrite0)
{
unsigned int ins;
ins = *(unsigned int *)data_begin;
if((ins>>24)==0xea) // instruction: b xxxx, now just support b instruction!!!
bios_load_addr = ((ins&0xffffff)<<2)+8;
else
bios_load_addr = 4; // other instruction, jump to 4
bios_load_addr = (bios_load_addr-BIOS_LOAD-8)/4;
bios_load_addr = (bios_load_addr&0xffffff)|0xea000000;
*(unsigned int *)data_begin = 0xea000000+(BIOS_BASE-8)/4;
modify_a0 = 1;
}
cache_cfg = rNCACHBE0;
rNCACHBE0 = 0x20000000;
SectorProg(prog_begin, (unsigned short *)data_begin, size);
if(modify_a0)
{
size = FlashSector(size-1)+SECTOR_SIZE;
FlashRead(FlashSector(BIOS_LOAD), (unsigned short *)(DFT_DOWNLOAD_ADDR+size), SECTOR_SIZE);
*(unsigned int *)(DFT_DOWNLOAD_ADDR+size+SECTOR_SIZE-4) = bios_load_addr;
SectorProg(FlashSector(BIOS_LOAD), (unsigned short *)(DFT_DOWNLOAD_ADDR+size), SECTOR_SIZE);
}
rNCACHBE0 = cache_cfg;
return 0;
}
#endif
#if 0
int CopyFlash(int argc, char *argv[])
{
unsigned int src, dst, size;
unsigned int cache_cfg;
char tmp[10];
if(argc<4)
{
printf("Usage : copy a1 a2 size\n");
printf("a1 = src address, a2 = dst address, size = copy bytes (all in hex)\n");
return -1;
}
src = strtoul((unsigned char *)argv[1]);
dst = strtoul((unsigned char *)argv[2]);
size = strtoul((unsigned char *)argv[3]);
if(src==-1||dst==-1||size==-1)
{
printf("give error address\n");
return -1;
}
cache_cfg = rNCACHBE0;
rNCACHBE0 = 0x20000000;
FlashRead(src, (unsigned short *)DFT_DOWNLOAD_ADDR, size);
rNCACHBE0 = cache_cfg;
argv[1] = argv[2];
argv[2] = tmp;
ultostr((unsigned char *)tmp, DFT_DOWNLOAD_ADDR);
ProgFlash(4, argv);
return 0;
}
#endif
int BootLoader(int argc, char *argv[])
{
unsigned char key;
printf("boot from flash, are you sure? [y/n]");
while(1)
{
key = Uart_GetKey();
if(key)
{
if(key=='y'||key=='Y')
{
void (*fp)(void) =(void (*)(void))BIOS_LOAD;
Uart_SendByte(key);
Uart_SendByte('\n');
(*fp)();
}
if(key=='n'||key=='N')
{
Uart_SendByte(key);
Uart_SendByte('\n');
break;
}
}
}
return 0;
}
#if 0
int BackupBios(int argc, char *argv[])
{
unsigned char key;
unsigned int cache_cfg;
printf("move bios to the top of rom,are you sure? [y/n]");
while(1)
{
key = Uart_GetKey();
if(key)
{
if(key=='y'||key=='Y')
{
Uart_SendByte(key);
Uart_SendByte('\n');
break;
}
if(key=='n'||key=='N')
{
Uart_SendByte(key);
Uart_SendByte('\n');
return 0;
}
}
}
cache_cfg = rNCACHBE0;
rNCACHBE0 = 0x20000000;
FlashRead(0, (unsigned short *)DFT_DOWNLOAD_ADDR, 0xf000);
SectorProg(BIOS_BASE, (unsigned short *)DFT_DOWNLOAD_ADDR, 0xf000);
rNCACHBE0 = cache_cfg;
return 0;
}
#endif
int MemoryDisplay(int argc, char*argv[])
{
unsigned int sys_cfg;
unsigned int src;
unsigned int i, j;
unsigned int *data;
if(argc < 2)
src = 0;
else
{
src = strtoul((unsigned char *)argv[1]);
if(src%4 != 0) src-=src%4;
}
data = (unsigned int *)src;
printf("0x%8.8x: ",data);
sys_cfg = rSYSCFG;
rSYSCFG = 0x08;
for(i=0;i<22;i++)
{
for(j=0;j<4;j++)
printf("%8.8x ",*data++);
if(i<21)
printf("\n0x%8.8x: ",data);
}
Uart_SendByte('\n');
rSYSCFG = sys_cfg;
return 0;
}
int Flash2Mem(int argc, char*argv[])
{
unsigned int src, dst, size, i;
unsigned int cache_cfg;
unsigned int *data_src, *data_dst;
if(argc<4)
{
printf("Usage : move a1 a2 size\n");
printf("a1 = src address, a2 = dst address, size = copy bytes (all in hex)\n");
return -1;
}
src = strtoul((unsigned char *)argv[1]);
dst = strtoul((unsigned char *)argv[2]);
size = strtoul((unsigned char *)argv[3]);
if(src==-1||dst==-1||size==-1||(dst-size)<src)
{
printf("give error address\n");
return -1;
}
data_src = (unsigned int *)src;
data_dst = (unsigned int *)dst;
cache_cfg = rNCACHBE0;
rNCACHBE0 = 0x20000000;
size = size%4 ? size/4+1 : size/4;
for(i=0;i<size;i++)
*data_dst++ = *data_src++;
rNCACHBE0 = cache_cfg;
printf("move finished!\n");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -