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

📄 nand_test.c

📁 s3c6410基于USB OTG下载内核至NORFLASH的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	uBlock = GetIntNum();
	printf("Input the Page Number to write[0~%d] : ", NAND_Inform[g_NandContNum].uPageNum-1);
	uPage = GetIntNum();
	printf("Input the srand() offset data : ");
	uOffset = (u8)GetIntNum();
	printf("\n");

	srand(uOffset);
	for(i=0 ; i<NAND_Inform[g_NandContNum].uPageSize ; i++)
	{
		aBuffer[i] = rand()%0xFF;
	}
	for(i=0 ; i<NAND_Inform[g_NandContNum].uSpareSize ; i++)
		aSpareBuffer[i] = 0xFF;	
	
	eError = NAND_WritePage(g_NandContNum, uBlock, uPage, aBuffer, aSpareBuffer);

	if(eError != eNAND_NoError)
	{
		NANDT_PrintErrorType(eError);
		getchar();
	}
	else
	{
		printf("[Main Area]");
		for(i=0 ; i<NAND_Inform[g_NandContNum].uPageSize ; i++)
		{
			if(i%16==0)
	    			printf("\n%04xh:",i);
			
        		printf("%02x ", aBuffer[i]);
		}
		printf("\n");
		
		printf("[Spare Area]");
		for(i=0 ; i<NAND_Inform[g_NandContNum].uSpareSize ; i++)
		{
			if(i%16==0)
	    			printf("\n%04xh:",i);
			
        		printf("%02x ", aSpareBuffer[i]);
		}
		printf("\n\n");
		
		printf("NAND Write Page : Success\n");
	}
	printf("\n");
}


//////////
// Function Name : NANDT_EraseSingleBlock
// Function Description : Erase 1 block
// Input : 	None
// Output : 	None
void NANDT_EraseSingleBlock(void)
{
	u32 uBlock;
	NAND_eERROR eError;

	printf("[NANDT_EraseSingleBlock]\n");
	
	printf("Input the Block Number to erase[0~%d]", NAND_Inform[g_NandContNum].uBlockNum-1);
	uBlock = GetIntNum();

	eError = NAND_EraseSingleBlock(g_NandContNum, uBlock);

	if(eError != eNAND_NoError)
		NANDT_PrintErrorType(eError);
	else
		printf("NAND Erase Block : Success\n\n");	
}


//////////
// Function Name : NANDT_EraseMultiBlock
// Function Description : Erase Multi block
// Input : 	None
// Output : 	None
void NANDT_EraseMultiBlock(void)
{
	u32 uBlock, uBlockNum;
	NAND_eERROR eError;

	printf("[NANDT_EraseMultiBlock]\n");
	

	if(NAND_Inform[g_NandContNum].uNandType == NAND_Normal8bit)	
	{
		printf("Input the Start Block Number to erase the multi-block[0~%d]", NAND_Inform[g_NandContNum].uBlockNum-1);
		uBlock = GetIntNum();		
		printf("Input the Block Number to erase[multiples of 4 : 0~%d]", NAND_Inform[g_NandContNum].uBlockNum-uBlock-1);
		uBlockNum = GetIntNum();
		
		//make the multiples of 4
		if(uBlockNum%4)
			uBlockNum += (4-(uBlockNum%4));		
	}
	else
	{
		printf("Input the Start Block Number to erase the multi-block[multiples of 2 : 0~%d]", NAND_Inform[g_NandContNum].uBlockNum-1);
		uBlock = GetIntNum();
		if(uBlock%2)		//uBlock is must be multiples of 2
			uBlock++;		
		printf("Input the Block Number to erase[multiples of 2 : 2~%d]", NAND_Inform[g_NandContNum].uBlockNum-uBlock);
		uBlockNum = GetIntNum();

		//make the multiples of 2
		if(uBlockNum%2)
			uBlockNum += (2-(uBlockNum%2));		
	}		
	
	eError = NAND_EraseMultiBlock(g_NandContNum, uBlock, uBlockNum);

	if(eError != eNAND_NoError)
		NANDT_PrintErrorType(eError);
	else
		printf("NAND Erase Block[%d ~ %d Block] : Success\n\n", uBlock, uBlock+uBlockNum-1);
}


const testFuncMenu nand_erase_menu[] =
{
	NANDT_EraseSingleBlock,					"Single Block Erase       ",
	NANDT_EraseMultiBlock,                				"Multi Block Erase        ",		
	0, 0
};


void NANDT_Erase(void)
{
	u32 i;
	s32 uSel;

	printf("\n[NANDT_Erase]\n");
	
	while(1)
	{
		printf("\n");
		for (i=0; (u32)(nand_erase_menu[i].desc)!=0; i++)
			printf("%2d: %s\n", i, nand_erase_menu[i].desc);

		printf("\nSelect the function to test : ");
		uSel =GetIntNum();
		printf("\n");
		if(uSel == -1) 
			break;

		if (uSel>=0 && uSel<(sizeof(nand_erase_menu)/8-1))
			(nand_erase_menu[uSel].func) ();
	}
}


//////////
// Function Name : NANDT_ProgramBinary
// Function Description : Write the Binary file to NAND Memory(ex. Boot Code)
// Input : 	None
// Output : 	None
void NANDT_ProgramBinary(void)
{
	u32 j, uBlock, uPage, uSize;
	u8 *uSourceAddr;
	u32 uWriteBlock, uWritePage, uPageNumToWrite, uRemainedPage;
	bool bWriteEnd;
	u8 aSpareBuffer[NAND_SPARE_MAX];	
	NAND_eERROR eError;
	
	printf("[NANDT_ProgramBinary]\n\n");

	uSourceAddr = (u8 *)(_DRAM_BaseAddress+0x01000000);
	
	printf("Caution : You must put BINARY file into 0x%08x before programming\n",uSourceAddr);

	printf("Input the Block Number to write[0~%d]", NAND_Inform[g_NandContNum].uBlockNum-1);
	uBlock = GetIntNum();
	printf("Input the Page Number to write[0~%d]", NAND_Inform[g_NandContNum].uPageNum-1);
	uPage = GetIntNum();
	printf("Input the Size to program[Bytes] : ");
	uSize = GetIntNum();

	uPageNumToWrite = uSize/NAND_Inform[g_NandContNum].uPageSize;
	if(uSize%NAND_Inform[g_NandContNum].uPageSize)
		uPageNumToWrite++;	
	uRemainedPage = uPageNumToWrite;
	uWriteBlock = uBlock;
	uWritePage = uPage;
	bWriteEnd = FALSE;
	
	while(1)
	{
	/*
		// Invalid Block Check
		eError = NAND_CheckInvalidBlock(g_NandContNum, uWriteBlock);
		while(eError != eNAND_NoError)
		{
			NANDT_PrintErrorType(eError);
			printf("Block Number: %d\n", uWriteBlock);
			uWriteBlock++;   // for next block
			eError = NAND_CheckInvalidBlock(g_NandContNum, uWriteBlock);
		}
	*/

		// Erase Block
		eError = NAND_EraseSingleBlock(g_NandContNum, uWriteBlock);
		while(eError != eNAND_NoError)
		{
			NANDT_PrintErrorType(eError);
			printf("Block Number: %d\n", uWriteBlock);
			uWriteBlock++;   // for next block
			eError = NAND_CheckInvalidBlock(g_NandContNum, uWriteBlock);
		}		

		// Write Block
		for(j=uWritePage ; j<NAND_Inform[g_NandContNum].uPageNum ; j++)
		{
			eError = NAND_WritePage(g_NandContNum, uWriteBlock, j, uSourceAddr, aSpareBuffer);

			if(eError != eNAND_NoError)
			{
				NANDT_PrintErrorType(eError);
				break;
			}
			
			uRemainedPage--;
			if(uRemainedPage == 0)
			{
				bWriteEnd = TRUE;
				break;
			}
			uSourceAddr += NAND_Inform[g_NandContNum].uPageSize;
		}

		if(bWriteEnd == TRUE)
			break;
		
		uWritePage = 0;
		uWriteBlock++;
		printf(".");
	}

	printf("\n");
	printf("NAND Program Complete\n\n");
}


//////////
// Function Name : NANDT_SoftLock
// Function Description : Soft-lock the NAND Memory
// Input : 	None
// Output : 	None
void NANDT_SoftLock(void)
{
	u32 uStartBlock, uEndBlock;
	NAND_eERROR eError;
	
	printf("[NANDT_SoftLock]\n\n");

	printf("Input the Start Block Number to soft-lock[0~%d]", NAND_Inform[g_NandContNum].uBlockNum-1);
	uStartBlock = GetIntNum();
	printf("Input the End Block Number to soft-lock[%d~%d]", uStartBlock, NAND_Inform[g_NandContNum].uBlockNum-1);
	uEndBlock = GetIntNum();

	eError = NAND_SoftLockingBlock(g_NandContNum, uStartBlock, uEndBlock);

	if(eError != eNAND_NoError)
	{
		printf("NAND Soft-Lock Block Error.....!!\n\n");
		getchar();
	}
	else
		printf("NAND Soft-Lock Block Complete[except %d ~ %d Block]\n\n", uStartBlock, uEndBlock);
}


//////////
// Function Name : NANDT_LockTight
// Function Description : Lock-tight the NAND Memory
// Input : 	None
// Output : 	None
void NANDT_LockTight(void)
{
	u32 uStartBlock, uEndBlock;
	NAND_eERROR eError;
	
	printf("[NANDT_LockTight]\n\n");

	printf("Input the Start Block Number to lock-tight[0~%d]", NAND_Inform[g_NandContNum].uBlockNum-1);
	uStartBlock = GetIntNum();
	printf("Input the End Block Number to lock-tight[%d~%d]", uStartBlock, NAND_Inform[g_NandContNum].uBlockNum-1);
	uEndBlock = GetIntNum();

	eError = NAND_LockTightBlock(g_NandContNum, uStartBlock, uEndBlock);

	if(eError != eNAND_NoError)
	{
		printf("NAND Lock-tight Block Error.....!!\n\n");
		getchar();
	}
	else
		printf("NAND Lock-tight Block Complete[except %d ~ %d Block]\n\n", uStartBlock, uEndBlock);
}


//////////
// Function Name : NANDT_DisableSoftLock
// Function Description : Disable Soft-lock of the NAND Memory
// Input : 	None
// Output : 	None
void NANDT_DisableSoftLock(void)
{
	NAND_eERROR eError;
	
	printf("[NANDT_DisableSoftLock]\n\n");

	eError = NAND_UnLockBlock(g_NandContNum);

	if(eError != eNAND_NoError)
	{
		printf("UnLock the Soft-locked Block Error.....!!\n\n");
		getchar();
	}
	else
		printf("UnLock the Soft-locked Block Complete\n\n");
}


//////////
// Function Name : NANDT_DisableLockTight
// Function Description : Disable Lock-tight of the NAND Memory
// Input : 	None
// Output : 	None
void NANDT_DisableLockTight(void)
{
	NAND_eERROR eError;
	
	printf("[NANDT_DisableLockTight]\n\n");

	eError = NAND_UnLockTightBlock(g_NandContNum);

	if(eError != eNAND_NoError)
	{
		printf("Fail - cleared Lock-tight bit by software\n\n");
		getchar();
	}
	else
		printf("Success - not cleared Lock-tight bit by software\n\n");
}


const testFuncMenu nandlock_menu[] =
{
	NANDT_SoftLock,					"Soft Lock        ",
	NANDT_LockTight,					"Lock Tight       ",
	NANDT_DisableSoftLock,				"Soft Unlock      ",
	NANDT_DisableLockTight,				"Lock-tight Unlock     ",	
	0, 0
};


void NANDT_LockUnlock(void)
{
	u32 i;
	s32 uSel;
	
	while(1)
	{
		for (i=0; (u32)(nandlock_menu[i].desc)!=0; i++)
			printf("%2d: %s\n", i, nandlock_menu[i].desc);

		printf("\nSelect the function to test : ");
		uSel =GetIntNum();
		printf("\n");
		if(uSel == -1) 
			break;

		if (uSel>=0 && uSel<(sizeof(nandlock_menu)/8-1))
			(nandlock_menu[uSel].func) ();
	}
}


//////////
// Function Name : NANDT_SLCECC
// Function Description : SLC ECC function test
// Input : 	None
// Output : 	None
void NANDT_SLCECC(void)
{
	u32 i, uBlock, uPage, uError, uErrorType;
	u8 aBuffer[NAND_PAGE_MAX];
	u8 aSpareBuffer[NAND_SPARE_MAX];
	NAND_eERROR eError;

⌨️ 快捷键说明

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