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

📄 onenand_test.c

📁 s3c6400 ADS下官方测试程序
💻 C
📖 第 1 页 / 共 5 页
字号:
//////////
// Function Name : OneNandT_SetLatency
// Function Description : This function sets the Burst read latency in cycles
// Input : 	None
// Version : 	v0.1
void OneNandT_SetLatency(void)
{
	u32 uLatency;

	UART_Printf("[OneNandT_SetLatency]\n");
	
	UART_Printf("Input the Latency[3~7] : \n");
	uLatency = UART_GetIntNum(); 

	if(uLatency < 3)
	{
		uLatency = 3;
	}
	else if(uLatency > 10)
	{
		uLatency = 10;
	}

	if(uLatency > 7)
	{
		uLatency -= 8;
	}

	ONENAND_SetBurstLatency(g_OneNandContNum, (OneNAND_eLATENCY)uLatency);

}


//////////
// Function Name : OneNandT_SetBurstLength
// Function Description : This function sets the Burst length
// Input : 	None
// Version : 	v0.1
void OneNandT_SetBurstLength(void)
{
	u32 uBurst;

	UART_Printf("[OneNandT_SetBurstLength]\n");
	UART_Printf("Input the Burst : [0:Async, 1:Continuous, 2:Burst4, 3:Burst8, 4:Burst16, 5:Burst32 \n");
	uBurst = UART_GetIntNum(); 

	if(uBurst > 5)
		uBurst = 5;

	ONENAND_SetSyncMode(g_OneNandContNum, (OneNAND_eMODE)uBurst);
}


//////////
// Function Name : OneNandT_SetECCErrorCorrection
// Function Description : This function enables or disables the ECC Error Correction Operation
// Input : 	None
// Version : 	v0.1
void OneNandT_SetECCErrorCorrection(void)
{
	u32 uEccErrCorrect;
	
	UART_Printf("[OneNandT_SetECCErrorCorrection]\n");
	UART_Printf("ECC Error Correction[0:With Correction, 1:Without Correction]\n");
	uEccErrCorrect = UART_GetIntNum(); 

	if(uEccErrCorrect == 0)
		ONENAND_EnableECCCorrection(g_OneNandContNum, ONENAND_WITH_CORRECT);
	else if(uEccErrCorrect == 1)
		ONENAND_EnableECCCorrection(g_OneNandContNum, ONENAND_WITHOUT_CORRECT);
	else
		UART_Printf("Selection fail..retry\n");
}


//////////
// Function Name : OneNandT_SetOperationClock
// Function Description : This function sets the Operating Clock(Flash Clock divided by HCLKx2)
// Input : 	None
// Version : 	v0.1
void OneNandT_SetOperationClock(void)
{
	u32 uSelect;
	float fFlashClcok;
	
	UART_Printf("[OneNandT_SetOperationClock]\n");
	UART_Printf("0:Divide by 1,  1:Divide by 2,  2:Divide by 3, 3:Divide by 4\n");
	UART_Printf("Select : ");
	uSelect = UART_GetIntNum(); 
	
	ONENAND_SetFlashClock(g_OneNandContNum, (OneNAND_eFlashClock)uSelect);
	ONENAND_SetAccClock(g_OneNandContNum);
	
	fFlashClcok = (float)OneNand_Inform[g_OneNandContNum].uFlashClock/(float)1000000;
	
	UART_Printf("OneNand Core Clock : %.04fMHz\n", fFlashClcok);
	UART_Printf("OneNand Interface Clock : %.04fMHz\n", fFlashClcok/2);
	UART_Printf("\n");
	
}


const testFuncMenu onenand_param[] =
{
	OneNandT_SetLatency,             					"Latency Setting",
	OneNandT_SetBurstLength,						"Burst Length",
	OneNandT_SetECCErrorCorrection,				"ECC Error Correction",
	OneNandT_SetOperationClock,					"Flash Clock",
	
	0, 0
};

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

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

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




///////////////////////////////////////////////////////////////////////////////////
////////////////////                     Copy-Back   Test                /////////////////////////// 
///////////////////////////////////////////////////////////////////////////////////

//////////
// Function Name : OneNandT_CopyBackTest
// Function Description : Memory Copy Back Test
// Input : 	None
// Version : v0.1
void OneNandT_CopyBackTest(void)
{
	bool uError;
	u32 i, uSourceBlkAddr, uVerifyBlock, uPageSize, uReadPageCnt; 
	u8 uSourcePageAddr, uVerifyPage;
	u32 uDestinationBlkAddr;
	u8 uDestinationPageAddr;
	u32 aWriteData[ONENAND_PAGESIZE/4] = {0, };
	u32 aReadData[ONENAND_PAGESIZE/4] = {0, };	

	UART_Printf("[OneNandT_CopyBackTest]\n");
	UART_Printf("Input the Source block number to Copy-back[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfBlock-1);
	uSourceBlkAddr = UART_GetIntNum(); 
	UART_Printf("Input the Source block page to Copy-back[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfPage-1);
	uSourcePageAddr = (u8)UART_GetIntNum();
	UART_Printf("Input the page size to Copy-back[0~0xFF] : \n");
	uPageSize = UART_GetIntNum();

	UART_Printf("Input the Destination block number to Copy-back[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfBlock-1);
	uDestinationBlkAddr = UART_GetIntNum(); 
	UART_Printf("Input the Destination block page to Copy-back[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfPage-1);
	uDestinationPageAddr = (u8)UART_GetIntNum();	

	UART_Printf("1. Copy-Back\n");
	uError = FALSE;
	ONENAND_CopyBack(g_OneNandContNum, uSourceBlkAddr, uSourcePageAddr, uDestinationBlkAddr, uDestinationPageAddr, uPageSize);

	//rb1004 : must be added...Compare data
	UART_Printf("2. Read & Verify\n");
	uReadPageCnt = 0;
	while(uReadPageCnt < uPageSize)
	{
		//Source data read
		uVerifyBlock = uSourceBlkAddr + ((u32)uSourcePageAddr + uReadPageCnt)/OneNand_Inform[g_OneNandContNum].uNumOfPage;
		uVerifyPage = (uSourcePageAddr + (u8)uReadPageCnt)%(u8)OneNand_Inform[g_OneNandContNum].uNumOfPage;
		ONENAND_ReadPage(g_OneNandContNum, uVerifyBlock, uVerifyPage, (u32*)aWriteData);
	
		//Destination data read
		uVerifyBlock = uDestinationBlkAddr + ((u32)uDestinationPageAddr + uReadPageCnt)/OneNand_Inform[g_OneNandContNum].uNumOfPage;
		uVerifyPage = (uDestinationPageAddr + (u8)uReadPageCnt)%(u8)OneNand_Inform[g_OneNandContNum].uNumOfPage;
		ONENAND_ReadPage(g_OneNandContNum, uVerifyBlock, uVerifyPage, (u32*)aReadData);
		
		for(i=0 ; i<ONENAND_PAGESIZE/4 ; i++)
		{
			if(aReadData[i] != aWriteData[i])
			{
				UART_Printf("Write&Read Verify Error [%d Block : %d Page(Destination Address)] :  \n", uVerifyBlock, uVerifyPage);
				UART_Printf("\t [Write data : Read data] = [0x%08x  : 0x%08x ]  \n", aWriteData[i], aReadData[i]);
				uError = TRUE;
				break;
			}		
		}
	
		uReadPageCnt++;

		for(i=0; i<ONENAND_PAGESIZE/4; i++)
		{
			aReadData[i] = 0;
			aWriteData[i] = 0;
		}			
	}
	
	if (uError==TRUE) 
	{
		UART_Printf("\nOneNAND Copy-back FAILED!!!\n");	
		UART_Printf("\n");
	}
	else if (uError==FALSE) 
	{
		UART_Printf("\n");
		UART_Printf("Write&Read Verify OK\n");
		UART_Printf("OneNAND Copy-back SUCCESS\n");
		UART_Printf("\n");
	}
}



///////////////////////////////////////////////////////////////////////////////////
////////////////////                  OneNand Program Test              ///////////////////////// 
///////////////////////////////////////////////////////////////////////////////////

//////////
// Function Name : OneNandT_MemoryWriteRead
// Function Description : Memory Write & Read(Verify) Test
// Input : 	None
// Version : v0.1
void OneNandT_MemoryWriteRead(eFunction_Test eTest, oFunctionT_AutoVar oAutoVar)
{
	bool uError;
	u32 uStartBlkAddr, uPageSize; 
	u32 uBlkAddr, uWritePageCnt, uReadPageCnt, i;	
	u8 uStartPageAddr, uPageAddr;
	//u32 aWriteData[ONENAND_PAGESIZE/4] = {0, };
	//u32 aReadData[ONENAND_PAGESIZE/4] = {0, };
	u32 *aWriteData, *aReadData;

	uError = FALSE;

	aWriteData = (u32 *)malloc(ONENAND_PAGESIZE);
	aReadData = (u32 *)malloc(ONENAND_PAGESIZE);

	if((aWriteData == 0) || (aReadData == 0))
	{
		UART_Printf("Memory Allocation Error...\n");
		return;
	}
	
	if(eTest == eTest_Manual)
	{
		UART_Printf("[OneNandT_MemoryWriteRead]\n");

		//	srand(0x3);
		//	for(i=0; i<ONENAND_PAGESIZE/4; i++)
		//		aWriteData[i] = rand();

		UART_Printf("Input the Start block number to write[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfBlock-1);
		uStartBlkAddr = UART_GetIntNum(); 
		UART_Printf("Input the Start page number to write[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfPage-1);
		uStartPageAddr = (u8)UART_GetIntNum();
		UART_Printf("Input the page size to write : \n");
		uPageSize = UART_GetIntNum();
	}
	else
	{
		uStartBlkAddr = oAutoVar.Test_Parameter[0];
		uStartPageAddr = oAutoVar.Test_Parameter[1];
		uPageSize = oAutoVar.Test_Parameter[2];	
	}
	
	//Data Write
	if(eTest == eTest_Manual)
		UART_Printf("1. Memory Write\n");
	uWritePageCnt = 0;
	uBlkAddr = uStartBlkAddr;
	uPageAddr = uStartPageAddr;
	while(uWritePageCnt < uPageSize)
	{
		for(i=0; i<ONENAND_PAGESIZE/4; i++)
			aWriteData[i] = i + (uPageAddr<<12) + ((uBlkAddr)<<20);
		
		ONENAND_WritePage(g_OneNandContNum, uBlkAddr, uPageAddr, (u32*)aWriteData);
		uPageAddr++;
		if(uPageAddr == OneNand_Inform[g_OneNandContNum].uNumOfPage)
		{
			uPageAddr = 0;
			uBlkAddr++;
		}
		uWritePageCnt++;
	}

	// Data Read
	if(eTest == eTest_Manual)
		UART_Printf("2. Memory Read & Verify\n");
	uReadPageCnt = 0;
	uBlkAddr = uStartBlkAddr;
	uPageAddr = uStartPageAddr;	
	while(uReadPageCnt < uPageSize)
	{
		ONENAND_ReadPage(g_OneNandContNum, uBlkAddr, uPageAddr, (u32*)aReadData);

		for(i=0; i<ONENAND_PAGESIZE/4; i++)
			aWriteData[i] = i +  (uPageAddr<<12) + ((uBlkAddr)<<20);
		
		for(i=0 ; i<ONENAND_PAGESIZE/4 ; i++)
		{
			if(aReadData[i] != aWriteData[i])
			{
				UART_Printf("Write&Read Verify Error [%d Block : %d Page] :  \n", uBlkAddr, uPageAddr);
				UART_Printf("\t [Write data : Read data] = [0x%08x  : 0x%08x ]  \n", aWriteData[i], aReadData[i]);
				UART_Getc();
				uError = TRUE;
				break;
			}
		}

		uPageAddr++;
		if(uPageAddr == OneNand_Inform[g_OneNandContNum].uNumOfPage)
		{
			uPageAddr = 0;
			uBlkAddr++;
		}
		uReadPageCnt++;

		for(i=0; i<ONENAND_PAGESIZE/4; i++)
			aReadData[i] = 0; 
		
		if(eTest == eTest_Auto)
		{
			UART_Printf(".");
			if(!(uReadPageCnt%10))
				UART_Printf("\b\b\b\b\b\b\b\b\b\b");
		}
			
	}

	if(eTest == eTest_Manual)
	{
		if(uError == FALSE)
			UART_Printf("Write&Read Verify OK\n");
		UART_Printf("\n");
	}

	free(aWriteData);
	free(aReadData);
}


//////////
// Function Name : OneNandT_MemoryRead
// Function Description : Memory Read & Display Test
// Input : 	None
// Version : v0.1
void OneNandT_MemoryRead(eFunction_Test eTest, oFunctionT_AutoVar oAutoVar)
{
	u32 uStartBlkAddr, uPageSize; 
	u32 uBlkAddr, uReadPageCnt, i;	
	u8 uStartPageAddr, uPageAddr;
	//u32 aReadData[ONENAND_PAGESIZE/4] = {0, };
	u32 *aReadData;

	//aReadData = (u32 *)0x0c000000;
	if(eTest == eTest_Manual)
	{	
		UART_Printf("[OneNandT_MemoryRead]\n");
		
		UART_Printf("Input the Start block number to read[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfBlock-1);
		uStartBlkAddr = UART_GetIntNum(); 
		UART_Printf("Input the Start page number to read[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfPage-1);
		uStartPageAddr = (u8)UART_GetIntNum();
		UART_Printf("Input the page size to read : \n");
		uPageSize = UART_GetIntNum();
	}
	else
	{
		uStartBlkAddr = oAutoVar.Test_Parameter[0];
		uStartPageAddr= oAutoVar.Test_Parameter[1];
		uPageSize = oAutoVar.Test_Parameter[2];
	}
	
	aReadData = (u32 *)malloc(ONENAND_PAGESIZE);

	if(aReadData == 0)
	{
		UART_Printf("Memory Allocation Error...\n");
		return;
	}
	
	// Data Read
	uReadPageCnt = 0;
	uBlkAddr = uStartBlkAddr;
	uPageAddr = uStartPageAddr;	
	while(uReadPageCnt < uPageSize)
	{
		ONENAND_ReadPage(g_OneNandContNum, uBlkAddr, uPageAddr, (u32*)aReadData);

		if(eTest == eTest_Manual)
		{	
			UART_Printf("\n");
			UART_Printf("[%d block, %d page]", uBlkAddr, uPageAddr);
			for(i=0 ; i<ONENAND_PAGESIZE/4 ; i++)
			{
				if(!(i%4))
				{
					UART_Printf("\n");
					UART_Printf("0x%04x : ",i*4);
				}
				UART_Printf("0x%08x  ", aReadData[i]);
			}
			UART_Printf("\n");
		}
		
		uPageAddr++;
		if(uPageAddr == OneNand_Inform[g_OneNandContNum].uNumOfPage)
		{
			uPageAddr = 0;
			uBlkAddr++;
		}
		uReadPageCnt++;

		for(i=0; i<ONENAND_PAGESIZE/4; i++)
			aReadData[i] = 0;
			
	}

	free(aReadData);	
}


//////////
// Function Name : OneNandT_ReadModifyWrite
// Function Description : Memory Read/Modify/Write Test
// Input : 	None
// Version : v0.1
void OneNandT_ReadModifyWrite(eFunction_Test eTest, oFunctionT_AutoVar oAutoVar)
{
	u32 uBlkAddr;
	u32 uModifysize, i;
	//u32 aWriteData[ONENAND_PAGESIZE/4] = {0, };
	//u32 aReadData[ONENAND_PAGESIZE/4] = {0, };
	u32 *aWriteData, *aReadData;
	u8 uPageAddr;
	bool uError;

	uError = FALSE;

	aWriteData = (u32 *)malloc(ONENAND_PAGESIZE);
	aReadData = (u32 *)malloc(ONENAND_PAGESIZE);

	if((aWriteData == 0) || (aReadData == 0))
	{
		UART_Printf("Memory Allocation Error...\n");
		return;
	}
	
	if(eTest == eTest_Manual)
	{
		UART_Printf("[OneNandT_ReadModifyWrite]\n");
		
		UART_Printf("Input the block number to modify[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfBlock-1);
		uBlkAddr = UART_GetIntNum(); 
		UART_Printf("Input the page number to modify[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfPage-1);

⌨️ 快捷键说明

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