📄 shell.c.bak
字号:
#include "common.h"
#define Sequential_Data_Input_cmd 0x80
#define Read1_cmd 0x00
#define Read2_cmd 0x50
#define ReadID_cmd 0x90
#define Reset_cmd 0xff
#define Page_Program_cmd 0x10
#define Block_Erase_cmd 0x60
#define Block_Erase_Confirm_cmd 0xd0
#define Read_Status_cmd 0x70
#define NAND_BUSY (*((volatile unsigned short*)0x1d20014)&0x0100?1:0)
#define NAND_CE(x) (x?(*((volatile unsigned short*)0x1d2000c)|=0x0200):(*((volatile unsigned short*)0x1d2000c)&=0xFDFF))
#define NAND_ADDR(x) (*(volatile unsigned char*)0xa000008=(unsigned char)x)
#define NAND_CMD(x) (*(volatile unsigned char*)0xa000004=(unsigned char)x)
#define NAND_DATA(x) (*(volatile unsigned char*)0xa000000=(unsigned char)x)
#define NAND_RDATA (*(volatile unsigned char*)0xa000000)
#define Uart_Printf OutPut
#define Uart_GetKey GetKey
int GetLine(char *Str)
{
char c;
int i;
i = 0;
Output(0,">");
while (1) {
do {
c = Uart_GetKey(0);
} while (!c) ;
if (c==0x0a || c==0x0d) {
*(Str+i)=0;
Output(0,"\n");
return i;
}
if (c==0x7f) {
if (i>0) {
Output(0,"\b \b");
i--;
}
continue;
}
Output(0,"%c",c);
*(Str+i) = c;
i++;
if (i>32) {
Output(0,"\nCommand line is too long!\n");
return 0;
}
}
return 0;
}
void WriteMem(uint cmd, uint addr,uint value,int arg)
{
volatile unsigned char *pb;
volatile unsigned short *pw;
volatile unsigned int *pd;
if (cmd==0) {pb = (volatile unsigned char *)addr; *pb =(unsigned char)value;}
else if (cmd==1) {pw = (volatile unsigned short *)(addr&0xFFFFFFFE); *pw =(unsigned short)value;}
else if (cmd==2) {pd = (volatile unsigned int *)(addr&0xFFFFFFFC); *pd =(unsigned int )value;}
else return;
}
void ReadMem(uint cmd, uint addr,uint len,int arg)
{
volatile unsigned char *pb;
volatile unsigned short *pw;
volatile unsigned int *pd;
uint addrstart,oldaddr,i,j;
if (cmd==0) {pb = (volatile unsigned char *)addr; oldaddr=(uint)pb;}
else if (cmd==1) {pw = (volatile unsigned short *)(addr&0xFFFFFFFE); oldaddr=(uint)pw;}
else if (cmd==2) {pd = (volatile unsigned int *)(addr&0xFFFFFFFC); oldaddr=(uint)pd;}
else return;
addrstart = addr & 0xFFFFFFF0;
if (arg==1) len = 16;
Output(0,"%08X: ",addrstart);
for (i=0;i<len;i+=0) {
if (cmd == 0) {
if ((addrstart+i)>=oldaddr) Output(0,"%02X ",*pb++);
else {
Output(0," ");
len+=1;
}
j=1;
}
else if (cmd == 1) {
if ((addrstart+i)>=oldaddr) Output(0,"%04X ",*pw++);
else {
Output(0," ");
len+=2;
}
j=2;
} else {
if ((addrstart+i)>=oldaddr) Output(0,"%08X ",*pd++);
else {
Output(0," ");
len+=4;
}
j=4;
}
i+=j;
addr+=j;
if (!(i&0xf) && (i<len)) Output(0,"\n%08X: ",addrstart+i);
}
Output(0,"\n");
}
void ledout(uint8 ch, uint8 flag)
{
char chmod1[]={0x48,0xeb,0x52, 0x62,0xe1,0x64,0x44,0xea,0x40,0x60,0xC0,0x45,0x5c,0x43,0x54,0xd4};
unsigned short value;
volatile short *p = (volatile short *)0x6080000;
if (flag) {
value = chmod1[ch/16];
value <<= 8;
value |= chmod1[ch%16];
} else {
if (ch>99) ch = ch % 100;
value = chmod1[ch/10];
value <<= 8;
value |= chmod1[ch%10];
}
*p = value;
}
uint StatusCheck() //status check
{
uint i;
uchar status;
NAND_CE(0);
//NAND_SCMD;
NAND_CMD(0x90);
//NAND_SDATA;
//NAND_SADDR;
NAND_ADDR(0x00);
//NAND_ADDR(0x00);
//NAND_ADDR(0x00);
//NAND_SDATA;
Delay(5);
Output(0,"%x ",NAND_RDATA);
Output(0,"%x\n",NAND_RDATA);
Delay(25);
NAND_CE(0);
}
int NandTest(void)
{
NAND_CE(0);
while(1) {
StatusCheck();
}
NAND_CE(1);
return 1;
}
int ParseCommand(char *Str)
{
int cmd,n,arg;
uint addr,len;
while (*Str==' ' || *Str=='\t') Str++;
strlow(Str);
if (!strncmp(Str,"rb",2)) {Str+=2;cmd=0;}
else if (!strncmp(Str,"rw",2)) {Str+=2;cmd=1;}
else if (!strncmp(Str,"rd",2)) {Str+=2;cmd=2;}
else if (!strncmp(Str,"wb",2)) {Str+=2;cmd=3;}
else if (!strncmp(Str,"ww",2)) {Str+=2;cmd=4;}
else if (!strncmp(Str,"wd",2)) {Str+=2;cmd=5;}
else {
Output(0,"Unknown command!\n");
return 0;
}
if (*Str==0) {
Output(0,"Arguments are needed!\n");
return 0;
}
if (*Str==' ' || *Str=='\b') {
while (*Str==' ' || *Str=='\b') Str++;
addr = xtoi(Str,&n);
Str+=n;
if (*Str==' ' || *(Str-1)==' ' ) arg=2;
else arg=1;
len = xtoi(Str,&n);
switch(cmd) {
case 0:
case 1:
case 2:
ReadMem(cmd,addr,len,arg);
break;
case 3:
case 4:
case 5:
if (arg==1) {
Output(0,"More arguments are requried!\n");
return 0;
}
WriteMem(cmd-3,addr,len,arg);
break;
}
return 1;
}
Output(0,"Unknown command!\n");
return 0;
}
void Shell()
{
char Buf[32];
Output(0,"\nWelcome to Shell!\n\n");
while(1) {
if (GetLine(Buf)) {
ParseCommand(Buf);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -