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

📄 nflash.c

📁 s3c44box 的远程序~!很有价值的啊!!!包括地层硬件编程!
💻 C
字号:
#include <string.h>
#include <stdlib.h>
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\def.h"
#include "..\inc\km29ux.h"

unsigned int lastPage;

void RdWrTest(void);


void Test_Nflash(void)
{
    int i,savePcona,savePcone;
    U8 buffer[528];
    char string[20];
    unsigned int page,block,data;
    
    rSYSCFG=rSYSCFG&(~0x48); //write buffer has to be off for proper timing.
    savePcona=rPCONA;
    rPDATA|=(1<<2)|(1<<4)|(1<<7);
    //PA4,PA7,PA2=output port ,PA3=input port
    rPCONA=rPCONA &~( (3<<4)|(3<<6)|(3<<8)|(7<<15) ) | (1<<4)|(1<<8)|(1<<15);	
    savePcone=rPCONE;
    rPCONE|=(1<<1); //nGCS3
    rNCACHBE0=((0x8000000>>12)<<16)|((0x6000000)>>12);
    
    Uart_Printf("[NAND Flash Test]\n");

    Uart_Printf("Loading the good block information from BLOCK 0.\n");
    lastPage=Nf_Open();
    Uart_Printf("The last logical page = 0 ~ %d\n",lastPage);

    while(1)
    {
	Uart_Printf("\n[F]ormat [E]rase_blk [W]r_pg [R]d_pg [P]hy_rd P[h]y_wr Rep_[B]ad [A]dd_pg [T]est e[X]it\n");
	Uart_Printf("Which function do you want?\n");

	switch(Uart_Getch())
	{
	case 'f':
	    Uart_Printf("Flash Format Test.\n");
	    if(Nf_Format(32000))Uart_Printf("Flash format completed!!!\n");
	    else Uart_Printf("Flash had been formatted.\n");
	    
	    lastPage=Nf_Open(); //After format, you must call Nf_Open().
	    Uart_Printf("Last page number=%d\n",lastPage);
	    break;

	case 'e':
	    Uart_Printf("Flash Block Erase Test.\n");
    
	    Uart_Printf("Input page number [-1,0~%d](bit[4:0] must be 0):",lastPage);
	    Uart_GetString(string); 
	    page=atoi(string);
	    if(page==-1)
	    {
		Uart_Printf("Erase all physical 1024 blocks\n");
		Uart_Printf("Are you sure? [y/n]\n");
		if(Uart_Getch()!='y')break;
		Uart_Printf("Wait a moment!\n");
		for(i=0;i<1024;i++)
		    if(_EraseBlock(i)!=1)Uart_Printf("E%d\n",i);
	    }
	    else
	    {
		Nf_EraseBlock(page); 
	    }
	    break;

	case 'w':
	    Uart_Printf("Flash Page Write Test.\n");
	    Uart_Printf("page[0~%d]:",lastPage);
	    Uart_GetString(string);
	    page=atoi(string);
	    Uart_Printf("Test key Data[0-255]:");
	    Uart_GetString(string);
	    data=atoi(string);

	    for(i=0;i<528;i++)
		buffer[i]=(U8)(data+i);
	    Nf_WritePage(page,1,buffer); 
	    break;

	case 'r':
	    Uart_Printf("Flash Page Read Test.\n");
	    Uart_Printf("page[0~%d]:",lastPage);
	    Uart_GetString(string);
	    page=atoi(string);
    
	    Nf_ReadPage(page,1,buffer);
	    Uart_Printf("Read Data of page %d.\n",page);
	    for(i=0;i<528;i++)
	    {
		if((i%32)==0)Uart_Printf("%3d:",i);
		Uart_Printf("%02x",buffer[i]);
		if((i%4)==3)Uart_Printf(" ");
		if((i%32)==31)Uart_Printf("\n");
	    }
	    break;

	case 'p':
	    Uart_Printf("Flash Page Read Test by physical block,page information.\n");
	    Uart_Printf("physical block[0~1023]:");
	    Uart_GetString(string);
	    block=atoi(string);
    
	    Uart_Printf("physical page[0~31]:");
	    Uart_GetString(string);
	    page=atoi(string);
    
	    _RdPage(block,page,buffer);
	    Uart_Printf("Read Data of phy.block=%d, phy.page=%d\n",block,page);
	    for(i=0;i<528;i++)
	    {
		if((i%32)==0)Uart_Printf("%3d:",i);
		Uart_Printf("%02x",buffer[i]);
		if((i%4)==3)Uart_Printf(" ");
		if((i%32)==31)Uart_Printf("\n");
	    }
	    break;

	case 'h':
	    Uart_Printf("Flash Page Write Test by physical block,page information.\n");
	    Uart_Printf("physical block[0~1023]:");
	    Uart_GetString(string);
	    block=atoi(string);
    
	    Uart_Printf("physical page[0~31]:");
	    Uart_GetString(string);
	    page=atoi(string);

	    Uart_Printf("Write Data(i%%256) of phy.block=%d, phy.page=%d\n",block,page);
	    for(i=0;i<528;i++)
		buffer[i]=i%256;
	    if(_WrPage(block,page,buffer))Uart_Printf("O.K.\n");
	    else Uart_Printf("WRITE ERROR!!!\n");
	    break;

	case 'b':
	    Uart_Printf("Replace Bad block Test.\n");
	    Uart_Printf("Input bad block page number [0~%d](bit[4:0] must be 0):",lastPage);
	    Uart_GetString(string);
	    page=atoi(string);
	
	    lastPage=Nf_Replace1Block(page);
	    break;

	case 'a':
	    Uart_Printf("Add New block Test.\n");

	    Uart_Printf("The last page # is %d.\n",lastPage=Nf_Add1Block());
	    break;

	case 't':
	    RdWrTest();
	    break;

	case 'x':
	    rPCONA=savePcona;
	    rPCONE=savePcone;
	    return;

	default:
	    break;
	}
    }
    rPCONA=savePcona;
    rPCONE=savePcone;
}



void RdWrTest(void)
{
    float time;
    U8 buffer[528];
    int i;

    Timer_Start(4); // 33 sec
    for(i=0;i<lastPage;i+=32)
    {
	Nf_EraseBlock(i);  //0x0~0xxxxx is the test data.
	if((i%1024)==0)Uart_Printf(".");
    }
    time=Timer_Stop()/(float)ONESEC4;
    Uart_Printf("\nErase time of %d pages=%f\n",lastPage+1,time);


    for(i=0;i<528;i++)buffer[i]=0;
    Timer_Start(4); 
    for(i=0;i<=lastPage;i++)
    {
	buffer[0]=i&0xff;
	buffer[1]=(i>>8)&0xff;
	Nf_WritePage(i,1,buffer);  //0x0~0xxxxx is the test data.
	if((i%1024)==0)Uart_Printf(".");
    }
    time=Timer_Stop()/(float)ONESEC4;
    Uart_Printf("\nWriting time of %d pages(%d byte)=%f\n",lastPage+1,(lastPage+1)*528,time);


    Timer_Start(4); 
    for(i=0;i<=lastPage;i++)
    {
	Nf_ReadPage(i,1,buffer);  //0x0~0xxxxx is the test data.
	if( buffer[0]!=(i&0xff) || buffer[1]!=((i>>8)&0xff) )Uart_Printf("ERROR@%d\n",i);
	if((i%1024)==0)Uart_Printf(".");
    }
	
    time=Timer_Stop()/(float)ONESEC4;
    Uart_Printf("\nReading time of %d pages(%d byte)=%f\n",lastPage+1,(lastPage+1)*528,time);
}

⌨️ 快捷键说明

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