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

📄 k9k2g16.c

📁 三星公司S3c2443的测试程序源码
💻 C
📖 第 1 页 / 共 2 页
字号:
//====================================================================
// File Name : K9k2g16.c
// Function  : S3C2440 16-bit interface Nand Test program(this program used by nand.c).
// Date      : May xx, 2003
// Version   : 0.0
// History
//   R0.0 (200305xx): Modified for 2440 from 2410. -> DonGo
//====================================================================


/**************** K9s1206 NAND flash ********************/
// 1block=(NF8_PAGE_BYTE+16)bytes x 32pages
// 4096block
// Block: A[23:14], Page: [13:9]
/**************** K9K2G16 NAND flash *******************/
// 1block=(2048+64)bytes x 64pages
// 2048block
// Block: A[23:14], page: [13:9]
/*****************************************************/

#include <string.h>
#include <stdlib.h>
#include "def.h"
#include "option.h"
#include "2443addr.h"


#include "K9K2G16.h"
#include "nand.h"
#define BAD_CHECK	(0)
#define ECC_CHECK	(0)

#define C_LANG	1
#define DMA		2
#define TRANS_MODE16  1


extern void Nand_Reset(void);

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

U32 NF16_Spare_Data[32/2];
volatile int NFConDone16;


void __irq NFCon_Int16(void);


void * n16_func[][2]=
{
	(void *)NF16_Print_Id,			"Read ID             ",
	(void *)Test_NF16_Block_Erase,	"Block erase         ",
	(void *)Test_NF16_Page_Read,	"Page read           ",
	(void *)Test_NF16_Page_Write,	"Page write          ",
	(void *)Test_NF16_Rw,			"Nand R/W test       ",	
	(void *)K9K2G16_PrintBadBlockNum,			"Check bad block     ",
	(void *)Test_NF16_Lock,         "Nand Block lock test",
	(void *)Test_NF16_SoftUnLock,         "Soft Unlock test      ",
	(void *)NF16_Program,			"K9K2G16_Program     ",
	0,0
};




void Test_K9K2G16(void)
{
	int i;
	U32 blocknum, pagenum;

	printf("\nK9K2G16 Nand flash test start.\n");

	NF16_Init();
	
	while(1) {
		Print16SubMessage();
		printf("\nSelect(-1 to exit): ");
		i = GetIntNum();
		if(i==-1) break;
		
		if(i>=0 && (i<(sizeof(n16_func)/8)) ) 
	    	( (void (*)(void)) (n16_func[i][0]) )();	// execute selected function.
	}

}

void Print16SubMessage(void)
{
	int i;
	
	i=0;	
	printf("\n\n");
	while(1)
	{   //display menu
		printf("%2d:%s",i,n16_func[i][1]);
	    i++;
	    if((int)(n16_func[i][0])==0)
	    {
			printf("\n");
			break;
	    }
	    if((i%4)==0) printf("\n");
	}
}



void NF16_Print_Id(void)
{
	U32 id;
	U8 maker, device, id4th;

	NF16_Init();
	
	id = NF16_CheckId();
	maker = (U8)id;
	device = (U8)(id>>8);
	
	printf(" Maker:%x, Device:%x\n", maker, device);
}



void Test_NF16_Block_Erase(void)
{
	U32 block=0;

	printf("SOP(K9K2G160UM) NAND Block erase\n");

	printf("Block # to erase: ");
	block = GetIntNum();

	if(NF16_EraseBlock(block)==FAIL) return;

	printf("%d-block erased.\n", block);

}

void Test_NF16_Lock(void)
{
       U32 num;
       U32 S_block, E_block;
	printf("SOP(K9K2G16U0M) NAND Lock Test !!!\n");
	printf("Select Lock type, Softlock(1)/Lock-tight(2) : ");

	num=GetIntNum();;
			
	printf("\nEnter programmable start block address ");
	S_block = GetIntNum();
	printf("Enter programmable end block address ");
       E_block = GetIntNum();

	rNFSBLK=(S_block<<6);
	rNFEBLK=(E_block<<6);

	
	if(num==1){
		rNFCONT|=(1<<16);
              printf("Software Locked\n ");
	}
	if(num==2){
		rNFCONT|=(1<<17);
              printf("Lock-tight: To clear Lock-tight, reset S3C2413!!!\n ");
	}
      printf("%d block ~ %d block are Programmable\n ", S_block, (E_block-1));
}


void Test_NF16_SoftUnLock(void)
{
       U32 S_block, E_block;
	printf("SOP(K9K2G16U0M) 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>>6), ((rNFEBLK>>6)-1));
	}
       else printf("All blocks are Programmable\n ");
}


void Test_NF16_Page_Read(void)
{
	U32 block=0, page=0;
	U32 i;

       unsigned int * srcPt;
	srcPt=(unsigned int *)0x31000000;
		
	printf("SOP(K9K2G16U0M) NAND Page Read.\n");

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

	if(NF16_ReadPage(block, page, srcPt)==FAIL) {
		printf("Read error.\n");
	} else {
		printf("Read OK.\n");
	};

	// Print data.
	printf("Read data(%d-block,%d-page)\n", block, page);
	for(i=0; i<512; i++) {
		if((i%4)==0) printf("\n%2x: ", i);
		printf("%08x ", *srcPt++);
	}
	printf("\n");
	printf("Spare:");
	for(i=0; i<16; i++) {
	 	printf("%08x ", NF16_Spare_Data[i]);
	}
	printf("\n");

}



void Test_NF16_Page_Write(void)
{
	U32 block=0, page=0;
	int i, offset;
	unsigned int *srcPt;
	srcPt=(unsigned int *)0x31100000;
	
		
	printf("SOP(K9K2G16U0M) NAND Page Write.\n");

	printf("Block # to write: ");
	block = GetIntNum();
	printf("Page # to write: ");
	page = GetIntNum();
	printf("offset data(-1:random): ");
	offset = GetIntNum();

#if ADS10==TRUE	
	srand(0);
#endif

	
	// Init wdata.
	for(i=0; i<512; i++) {
	#if ADS10==TRUE
		if(offset==-1) *srcPt++ = rand()%0xffffffff;
	#else
		if(offset==-1) *srcPt++ = i;
	#endif
		else *srcPt++ =i+offset;
	}
     
       srcPt=(unsigned int *)0x31100000;
	printf("Write data[%d block, %d page].\n", block, page);
	if(NF16_WritePage(block, page, srcPt)==FAIL) {
		printf("Write Error.\n");
	} else {
		printf("Write OK.\n");
	
		printf("Write data is");
		for(i=0; i<512; i++) {
			if((i%4)==0) printf("\n%2x: ", i);
			printf("%08x ", *srcPt++);
		}
		printf("\n");

		printf("Spare:");
		for(i=0; i<32/2; i++) {
		 	printf("%08x ", NF16_Spare_Data[i]);
			}
		printf("\n\n");
	}
}



void Test_NF16_Rw(void)
{
	U32 block=0, page=0;
	U32 i, status=FAIL, error, offset;

	unsigned int *srcPt, *dstPt;
	srcPt=(unsigned int *)0x31100000;
	dstPt=(unsigned int *)0x31200000;
		
	printf("SOP(K9K2G16U0M) NAND Flash R/W test.\n");

	printf("Block number: ");
	block = GetIntNum();
	printf("Page nember: ");
	page = GetIntNum();
	printf("offset data(-1:random): ");
	offset = GetIntNum();

#if ADS10==TRUE 
	srand(0); 
#endif
	
	// Init R/W data.
	for(i=0; i<512; i++) *dstPt++=0x0;

	for(i=0; i<512; i++) {
	#if ADS10==TRUE	
		if(offset==-1) *srcPt++= rand()%0xffffffff;
	#else
		if(offset==-1) *srcPt++= i;
	#endif
		else *srcPt++ = i+offset;
	}

       srcPt=(unsigned int *)0x31100000;
	dstPt=(unsigned int *)0x31200000;
	// Block erase
	printf("%d block erase.\n", block);
	if(NF16_EraseBlock(block)==FAIL) return;

	printf("Write data[%d block, %d page].\n", block, page);
	if(NF16_WritePage(block, page, srcPt)==FAIL) return;
	
	printf("Read data.\n");
	if(NF16_ReadPage(block, page, dstPt)==FAIL) return;

	printf("Checking data.\n");
	for(error=0, i=0; i<512; i++) {
		if(*srcPt++!=*dstPt++) {
			printf("Error:%d[W:%x,R:%x]\n", i, *srcPt, *dstPt);
			error++;
		}
	}
	if(error!=0) 
		printf("Fail to R/W test(%d).\n", error);
	else
		printf("R/W test OK.\n");
}



void NF16_Program(void)
{
    int i, page_num;
    int programError=0;
    U32 *srcPt,*saveSrcPt;
    U32 blockIndex;

    printf("\n[SOP(K9K2G16U0M) NAND Flash writing program]\n");
    printf("The program buffer: 0x30100000~0x31ffffff\n");

//     NF16_Init();

     rINTMSK = BIT_ALLMSK; 	
     srcAddress=0x30100000; 

     InputTargetBlock16();

     srcPt=(U32 *)srcAddress;
     blockIndex=targetBlock;

     while(1) {
             saveSrcPt=srcPt;	
              
     	#if BAD_CHECK
     	  if(NF16_IsBadBlock(blockIndex)==FAIL) {
		    blockIndex++;   // for next block
		    continue;
	  }
     	#endif
		
     	if(NF16_EraseBlock(blockIndex)==FAIL) {
		    blockIndex++;   // for next block
		    continue;
     	}
   	// After 1-Block erase, Write 1-Block(64 pages).
	for(i=0;i<64;i++) {
		    if(NF16_WritePage(blockIndex,i,srcPt)==FAIL) {// block num, page num, buffer
		        programError=1;
		        break;
		    }

	#if ECC_CHECK
		    if(NF16_ReadPage(blockIndex,i,srcPt)==FAIL) {
			printf("ECC Error(block=%d,page=%d!!!\n",blockIndex,i);
		    }
	#endif

	srcPt+=512;	// Increase buffer addr one pase size
    	if(i==0)  printf(".");
	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 K9K2G16_PrintBadBlockNum(void)
{
    int i;
    U32 id;

    printf("\n[SMC(K9S1208V0M) NAND Flash bad block check]\n");
    
//    NF16_Init();

    for(i=0;i<2048;i++)
    {
	NF16_IsBadBlock(i);   // Print bad block
    }
}






//*************************************************
//*************************************************
//**           H/W dependent functions           **
//************************************************* 
//*************************************************

//The code is made for bi-endian mode

// block0: reserved for boot strap
// block1~4095: used for OS image
// badblock SE: xx xx xx xx xx 00 ....
// good block SE: ECC0 ECC1 ECC2 FF FF FF ....

/*
#define NF_MECC_UnLock()         {rNFCONT&=~(1<<7);}
#define NF_MECC_Lock()         {rNFCONT|=(1<<7);}
#define NF_SECC_UnLock()         {rNFCONT&=~(1<<6);}
#define NF_SECC_Lock()         {rNFCONT|=(1<<6);}

#define NF_CMD(cmd)			{rNFCMD=cmd;}
#define NF_ADDR(addr)		{rNFADDR=addr;}	
#define NF_nFCE_L()			{rNFCONT&=~(1<<2);}
#define NF_nFCE_H()			{rNFCONT|=(1<<2);}

#define NF_RSTECC()			{rNFCONT|=(1<<5|1<<4);}
#define NF_RDDATA() 		(rNFDATA)
#define NF_RDDATA16() 		((*(volatile unsigned short*)0x4E000010) )

#define NF_WRDATA(data) 	{rNFDATA=data;}

⌨️ 快捷键说明

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