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

📄 secnand.c

📁 samsung 最新芯片2450 的测试程序.
💻 C
📖 第 1 页 / 共 3 页
字号:

void TestReadPage(void)
{
	unsigned int block=0, page=0;
	unsigned int i;
	unsigned char * downPt;
	
	downPt=(unsigned char *)_NONCACHE_STARTADDRESS;
	for(i=0;i<128;i++)
		g_uSpareData[i]=0xFF;	
	printf(" NAND(xD-Picture Card) Page Read.\n");

	printf("Block # to read: ");
	block = GetIntNum();
	printf("Page # to read: ");
	page = GetIntNum();

	if(ReadPage((unsigned char *)downPt, block, page )) 		printf("Read error.\n");
	else												 		printf("Read OK.\n");	
	
	// Print data.
	printf("Read data(%d-block,%d-page)\n", block, page);
	printf("NFMECC0: 0x%x\n", rNFMECC0);
	
	for(i=0; i<sNandInfo.uPageSize; i++) {
		if((i%16)==0) printf("\n%4x: ", i);
		printf("%02x ", *(unsigned char *)downPt++);
		}
	
	printf("\nSpare:");
	for(i=0; i<sNandInfo.uRedundantAreaSize*sNandInfo.u512BytesPerPage; i++) 
	{
		if((i%16)==0) 
			printf("\n%4x: ", i);
	 	printf("%02x ", g_uSpareData[i]);
	}
	printf("\n");

}

int WritePage(unsigned char* pWBuf,unsigned int  uBlock, unsigned int uPage)
{
	int i=0,m=0,n=0;	
	unsigned char *pWriteBuffer=pWBuf;	
	unsigned int u8BitECC[64], uResult[8], uCurPageAddr;
	unsigned char *p8BitECC = NULL;	
	
	p8BitECC = (unsigned char*)u8BitECC;
	
	rNFCONF = (rNFCONF & ~(1<<30))|(1<<23); // System Clock is more than 66Mhz, ECC type is MLC.
	rNFCONT |= (1<<18)|(1<<13)|(1<<12)|(1<<11)|(1<<10)|(1<<9); //ECC for programming.// Enable RnB Interrupt 
	rNFSTAT |= ((1<<6)|(1<<5)|(1<<4));
	// Enable Illegal Access Interrupt  // Enable ECC encoding & decoding conpletion interrupt enable  // Enable ECC encoding & decoding conpletion interrupt enable	
        	
	uCurPageAddr =  uBlock*sNandInfo.uPagesPerBlock + uPage;
	
#if		__POLLING

#else
	NFConDone=0;		
	NFECCEncDone=0;
    rNFCONT|=(1<<9);
    rNFCONT|=(1<<10);
    rNFCONT|=(1<<12);
    pISR_NFCON= (unsigned)IsrNFC;
    rSRCPND=BIT_NFCON;
    rINTMSK=~(BIT_NFCON);	
#endif	
	
	
	NF_nFCE_L(); 			
	NF_CMD(CMD_PAGEPROG);	// Write command		
	for(m=0; m<sNandInfo.uColCycle; m++) //Addr Cycle
		NF_ADDR(0);
	for(m=0; m<sNandInfo.uRowCycle; m++)
		NF_ADDR((uCurPageAddr>>(m<<3))&0xFF);

	
	for(i=0; i<sNandInfo.u512BytesPerPage; i++)
	{		    
	    NF_MECC_UnLock();
	    NF_RSTECC();    
	    	
	    for(m=0;m<512;m++) 
			NF_WRDATA8(*pWriteBuffer++);	// Write one page to NFM from buffer	    
			
	    NF_MECC_Lock();
#if		__POLLING	    
	    while(!(rNFSTAT&(1<<7))) ;
	    rNFSTAT|=(1<<7);	    	    
#else	    
	    while(!NFECCEncDone);
	    NFECCEncDone=0;
#endif

	       
	    u8BitECC[n++] = rNFM8ECC0;   		u8BitECC[n++] = rNFM8ECC1;
   		u8BitECC[n++] = rNFM8ECC2;   		u8BitECC[n++] = rNFM8ECC3;   		
	}

	for(i=0, n=0; i<sNandInfo.u512BytesPerPage; i++)//Write Spare Area for 8Bit ECC
	{		
		for(m=0; m<VAL_LEN_ECC8; m++)
		{
			g_uSpareData[m + VAL_LEN_ECC8*i]= p8BitECC[n];			
			NF_WRDATA8(p8BitECC[n++]);
		}
		n+=3;			
	}			

 	NF_CLEAR_RB();
	NF_CMD(CMD_PAGEPROG_2CYCLE);	 // Write 2nd command

#if __POLLING	
	NF_DETECT_RB();
	if(rNFSTAT&0x20) 
	{	
		rNFSTAT|=0x20;
		return FAIL;
	}
#else
while(NFConDone==0);
	NFConDone=0;
		
	rNFCONT&=~(1<<9);
	rNFCONT&=~(1<<10); // Disable Illegal Access Interrupt
	rNFCONT&=~(1<<12); // Disable Encoding Done Interrupt
#endif
	
	NF_CMD(CMD_STATUS);   // Read status command       
	for(i=0;i<3;i++);  //twhr=60ns
    
    if (NF_RDDATA()&0x1) 
    {// Page write error
        NF_nFCE_H();
		printf("[PROGRAM_ERROR:block#=%d]\n",uBlock);		//NF8_MarkBadBlock(block);
		return FAIL;
    } 
    else 
    {
        NF_nFCE_H();
	    return OK;
	}
}



void TestWritePage(void)
{
	unsigned int block=0, page=0;
	int i, offset;
	unsigned char * srcPt;
	unsigned int uRet=0;
	srcPt=(unsigned char *)0x31100000;	
	
	rGPHCON=rGPHCON&~(0xf<<26)|(0x5<<26);  // GPH13, 14 => OUTPUT
	rGPHDAT&=~(0x3<<13);		
	for(i=0;i<128;i++)
		g_uSpareData[i]=0xFF;
	printf("SMC(K9K2G08U) NAND Page Write.\n");	
	
	printf("You must erase block before you write data!!! \n");	
	printf("Block # to write: ");
	block = GetIntNum();
	printf("Page # to write: ");
	page = GetIntNum();
	printf("offset data(-1:random): ");
	offset = GetIntNum();

#if 0
	srand(0);
#endif

	// Init wdata.
	for(i=0; i<sNandInfo.uPageSize; i++) {
	#if ADS10==TRUE
		if(offset==-1) *srcPt++ = rand()%0xff;
	#else
		if(offset==-1) *srcPt++ = i%0xff;
	#endif
		else *srcPt++ =  i+offset;
	}
    srcPt=(unsigned char *)0x31100000;
	printf("Write data[%d block, %d page].\n", block, page);
	
	uRet = WritePage(srcPt, block, page);
	
	if(uRet==FAIL) {
		printf("Write Error.\n");
	} else {
		printf("Write OK.\n");
	}

 	printf("Write data is");
	for(i=0; i<sNandInfo.uPageSize; i++) {
		if((i%16)==0) printf("\n%4x: ", i);
		printf("%02x ", *srcPt++);
	}
	printf("\n");

	printf("Spare:");
	for(i=0; i<sNandInfo.uRedundantAreaSize*sNandInfo.u512BytesPerPage; i++) {
		if((i%16)==0) printf("\n%4x: ", i);
	 	printf("%02x ", g_uSpareData[i]);
	}
	printf("\n\n");


}


unsigned int SetLock(unsigned int uStartBlock, unsigned int uEndBlock, unsigned int uIsSoftLock)
{
	rNFSBLK=(uStartBlock<<sNandInfo.uBlockShift);
	rNFEBLK=(uEndBlock<<sNandInfo.uBlockShift);
	if(uIsSoftLock)
	{
		rNFCONT|=(1<<16);
        printf("Software Locked\n ");
	}
	else
	{
		rNFCONT|=(1<<17);
        printf("Lock-tight: To clear Lock-tight, reset S3C2450!!!\n ");
	}
}

void Test_Lock(void)
{
    unsigned int uOption;
    unsigned int uSBlock, uEBlock;
	printf("(x-D Card) NAND Lock Test !!!\n");
	printf("Select Lock type, Lock-tight(0)/Softlock(1) : ");

	uOption=GetIntNum();
			
	printf("\nEnter programmable start block address ");
	uSBlock = GetIntNum();
	printf("Enter programmable end block address ");
    uEBlock = GetIntNum();

	SetLock(uSBlock, uEBlock, uOption);		
    printf("%d block ~ %d block are Programmable\n ", uSBlock, (uEBlock));
}








unsigned int uTargetBlock;
unsigned int uTargetSize;
unsigned int uSrcAddr;

void GetTargetInfo(void)
{
	unsigned int no_block, no_page, no_byte;
	
	printf("\nAvailable target block number: 0~2047\n");
	printf("Input target block number:");
    uTargetBlock=GetIntNum();	// Block number(0~4095)
    //if(uTargetSize==0)
    {
 #if 0
    	printf("Input target size(0x4000*n):");
    	uTargetSize=GetIntNum();	// Total byte size
#else
 	  	printf("Input program file size(bytes): ");
    	uTargetSize=GetIntNum();	// Total byte size
    	#endif
    }
	
	no_block = (unsigned int)((uTargetSize/sNandInfo.uPageSize)/sNandInfo.uPagesPerBlock);
	no_page = (unsigned int)((uTargetSize/sNandInfo.uPageSize)%sNandInfo.uPagesPerBlock);
	no_byte = (unsigned int)(uTargetSize%sNandInfo.uPageSize);
	printf("File:%d[%d-block,%d-page,%d-bytes].\n", uTargetSize, no_block, no_page, no_byte);
}

extern volatile U32 srcAddress;
extern volatile U32 targetBlock;	    // Block number (0 ~ 4095)
extern volatile U32 targetSize;	    // Total byte size 


void WriteDramImage2Nand(void)
{

//    unsigned long interrupt_reservoir;
    int i;
    int programError=0;
	U8 *srcPt,*saveSrcPt;
	U32 blockIndex;

  	printf("\n[x-D Card NAND Flash writing program]\n");
    printf("The program buffer: 0x30100000~0x31ffffff\n");

//	NF8_Init();

    rINTMSK = BIT_ALLMSK; 	
    srcAddress=0x30100000; 

    InputTargetBlock();
	
    srcPt=(U8 *)srcAddress;
    blockIndex=targetBlock;
    
    

     while(1) {
        saveSrcPt=srcPt;	

#if 0
		if(NF8_IsBadBlock(blockIndex)==FAIL) {
		    blockIndex++;   // for next block
		    continue;
		}
#endif

		if(EraseBlock(blockIndex)==FAIL) {
		    blockIndex++;   // for next block
		    continue;
		}

		// After 1-Block erase, Write 1-Block(32 pages).
		for(i=0;i<sNandInfo.uPagesPerBlock;i++) {
		
		    if(WritePage(srcPt,blockIndex,i)==FAIL) {// block num, page num, buffer
		        programError=1;
		        break;
		    }

#if 0
		    if(ReadPage(srcPt, blockIndex,i)) {
				printf("ECC Error(block=%d,page=%d!!!\n",blockIndex,i);
		    }
#endif
			
		srcPt+=sNandInfo.uPageSize;	// Increase buffer addr one pase size
		if(i==0)  printf(".");
			//printf("\b\b\b\b\b\b\b\b%04d,%02d]", blockIndex, i);
		if((U32)srcPt>=(srcAddress+targetSize)) // Check end of buffer
		break;	// Exit for loop
		}
		
		if(programError==1) {
		    blockIndex++;
		    srcPt=saveSrcPt;
		    programError=0;
		    continue;
		}

		if((U32)srcPt>=(srcAddress+targetSize)) break;	// Exit while loop

		blockIndex++;
		
    }
}


void ReadNandImage2Dram(void)
{

//    unsigned long interrupt_reservoir;
    int i;
    int programError=0;
	U8 *srcPt,*saveSrcPt;
	U32 blockIndex;

  	printf("\n[x-D Card NAND Flash writing program]\n");
    printf("The program buffer: 0x30400000~0x31ffffff\n");

//	NF8_Init();

    rINTMSK = BIT_ALLMSK; 	
    srcAddress=0x30400000; 

    InputTargetBlock();
	
    srcPt=(U8 *)srcAddress;
    blockIndex=targetBlock;
    
    

     while(1) {
        saveSrcPt=srcPt;	


		// After 1-Block erase, Write 1-Block(32 pages).
		for(i=0;i<sNandInfo.uPagesPerBlock;i++) 
		{		
		    

#if 1
		    if(ReadPage(srcPt, blockIndex,i)) {
				//printf("ECC Error(block=%d,page=%d!!!\n",blockIndex,i);
		    }
#endif
			
		srcPt+=sNandInfo.uPageSize;	// Increase buffer addr one pase size
		if(i==0)  printf("*");
			//printf("\b\b\b\b\b\b\b\b%04d,%02d]", blockIndex, i);
		if((U32)srcPt>=(srcAddress+targetSize)) // Check end of buffer
		break;	// Exit for loop
		}
		
		if(programError==1) {
		    blockIndex++;
		    srcPt=saveSrcPt;
		    programError=0;
		    continue;
		}

		if((U32)srcPt>=(srcAddress+targetSize)) break;	// Exit while loop

		blockIndex++;
		}
    
}


void ClearSoftLock(void)
{
    	printf("xD-Card NAND SoftUnLock Test !!!\n");
	
	rNFSBLK=0x0;
	rNFEBLK=0x0;

	rNFCONT&=~(1<<16);
	if(rNFCONT&(1<<17)){
		rNFCONT&=~(1<<17);
		printf("Lock-tight\n ");
		printf("You can't unlock Protected blocks !!!\n ");
		printf("%d block ~ %d block are Programmable\n ", (rNFSBLK>>5), ((rNFEBLK>>5)-1));
	}
       else printf("All blocks are Programmable\n ");
}

⌨️ 快捷键说明

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