📄 nand_test.c
字号:
UART_Printf("[NANDT_SLCSpareECC]\n");
if(NAND_Inform[g_NandContNum].uNandType == NAND_MLC8bit)
{
UART_Printf("The current Nand Memory is MLC type.....!!\n\n");
return;
}
UART_Printf("Input the Block Number to test[0~%d]", NAND_Inform[g_NandContNum].uBlockNum-1);
uBlock = UART_GetIntNum();
UART_Printf("Input the Page Number to test[0~%d]", NAND_Inform[g_NandContNum].uPageNum-1);
uPage = UART_GetIntNum();
UART_Printf("Input the ECC Error Type\n");
UART_Printf("1: 1bit error(D), 2: multiple error\n");
uError = UART_GetIntNum();
switch(uError)
{
case 1 : uErrorType = NAND_ECCERR_1BIT;
break;
case 2 : uErrorType = NAND_ECCERR_MULTI;
break;
default : uErrorType = NAND_ECCERR_1BIT;
break;
}
srand(0);
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;
if(NAND_Inform[g_NandContNum].uNandType == NAND_Normal8bit)
{
// Spare Area 0~3 byte : Main ECC Value
// Spare Area 8~9 byte : Spare ECC Value
NAND_EccError.uEccErrByte1 = 0;
NAND_EccError.uEccErrBit1 = 0;
NAND_EccError.uEccErrByte2 = (NAND_EccError.uEccErrByte1+1)%4;
NAND_EccError.uEccErrBit2 = 0;
}
else if(NAND_Inform[g_NandContNum].uNandType == NAND_Advanced8bit)
{
// Spare Area 1~4 byte : Main ECC Value
// Spare Area 8~9 byte : Spare ECC Value
NAND_EccError.uEccErrByte1 = 1;
NAND_EccError.uEccErrBit1 = 0;
NAND_EccError.uEccErrByte2 = (NAND_EccError.uEccErrByte1%4) + 1;
NAND_EccError.uEccErrBit2 = 0;
}
UART_Printf("\n");
UART_Printf("The specific bit ecc check : [%dByte : %dBit]\n", NAND_EccError.uEccErrByte1, NAND_EccError.uEccErrBit1);
if(uErrorType == NAND_ECCERR_MULTI)
UART_Printf("The specific bit ecc check : [%dByte : %dBit]\n", NAND_EccError.uEccErrByte2, NAND_EccError.uEccErrBit2);
UART_Printf("\n");
// Erase Block for test
UART_Printf("Erase the block ( %d[block] )\n", uBlock);
eError = NAND_EraseSingleBlock(g_NandContNum, uBlock);
if(eError != eNAND_NoError)
{
NANDT_PrintErrorType(eError);
UART_Getc();
return;
}
NAND_Inform[g_NandContNum].uECCtest = 1;
NAND_Inform[g_NandContNum].uAllBitEccCheck = 0;
NAND_Inform[g_NandContNum].uSpareECCtest = 1;
// Write the valid data to page 0 ( uBlock[block] 0[page] )
UART_Printf("Write the valid data to page ( %d[block] %d[page] )\n", uBlock, uPage);
eError = NAND_WritePage(g_NandContNum, uBlock, uPage, aBuffer, aSpareBuffer);
if(eError != eNAND_NoError)
{
NANDT_PrintErrorType(eError);
UART_Getc();
NAND_Inform[g_NandContNum].uECCtest = 0;
NAND_Inform[g_NandContNum].uSpareECCtest = 0;
return;
}
UART_Printf("Erase the block ( %d[block] )\n", uBlock);
eError = NAND_EraseSingleBlock(g_NandContNum, uBlock);
if(eError != eNAND_NoError)
{
NANDT_PrintErrorType(eError);
UART_Getc();
NAND_Inform[g_NandContNum].uECCtest = 0;
NAND_Inform[g_NandContNum].uSpareECCtest = 0;
return;
}
// Write the invalid data to page( uBlock[block] 1[page] )
UART_Printf("Write the invalid data to page ( %d[block] %d[page] )\n", uBlock, uPage);
eError = NAND_WritePageWithInvalidSpareData(g_NandContNum, uBlock, uPage, aBuffer, uErrorType);
if(eError != eNAND_NoError)
{
NANDT_PrintErrorType(eError);
UART_Getc();
NAND_Inform[g_NandContNum].uECCtest = 0;
NAND_Inform[g_NandContNum].uSpareECCtest = 0;
return;
}
// Read the invalid data to detect the ECC error
UART_Printf("Read the invalid data to page ( %d[block] %d[page] )\n", uBlock, uPage);
eError = NAND_ReadPage(g_NandContNum, uBlock, uPage, aBuffer, aSpareBuffer);
UART_Printf("\n");
if(eError != eNAND_NoError)
{
NANDT_PrintErrorType(eError);
}
NAND_Inform[g_NandContNum].uECCtest = 0;
NAND_Inform[g_NandContNum].uSpareECCtest = 0;
UART_Printf("SLC Nand ECC test complete\n");
UART_Printf("\n");
}
//////////
// Function Name : NANDT_MLCECC
// Function Description : MLC ECC function test
// Input : None
// Output : None
void NANDT_MLCECC(void)
{
u32 i, m, n, uBlock, uPage, uError, uErrorType;
u8 aBuffer[NAND_PAGE_MAX];
u8 aSpareBuffer[NAND_SPARE_MAX];
u8 aReadBuffer[NAND_PAGE_MAX];
NAND_eERROR eError;
UART_Printf("[NANDT_MLCECC_All]\n");
if(NAND_Inform[g_NandContNum].uNandType != NAND_MLC8bit)
{
UART_Printf("The current Nand Memory is not MLC type.....!!\n\n");
return;
}
UART_Printf("Input the Block Number to test[0~%d]", NAND_Inform[g_NandContNum].uBlockNum-1);
uBlock = UART_GetIntNum();
UART_Printf("Input the Page Number to test[0~%d]", NAND_Inform[g_NandContNum].uPageNum-1);
uPage = UART_GetIntNum();
UART_Printf("Input the ECC Error Type\n");
UART_Printf("1: 1bit error(D), 2: 2bit error, 3: 3bit error, 4: 4bit error, 5: Uncorrectable\n");
uError = UART_GetIntNum();
switch(uError)
{
case 1 : uErrorType = NAND_ECCERR_1BIT;
UART_Printf("Input the First Byte Postion[0 ~ 2075]");
NAND_EccError.uEccErrByte1 = UART_GetIntNum()%2076;
UART_Printf("Input the First Bit Postion[0 ~ 7]");
NAND_EccError.uEccErrBit1 = UART_GetIntNum()%8;
NAND_Inform[g_NandContNum].uMLCECCPageWriteSector =
NAND_EccError.uEccErrByte1/(NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE);
NAND_Inform[g_NandContNum].uMLCECCErrBytePos[0] = NAND_EccError.uEccErrByte1 -
(NAND_Inform[g_NandContNum].uMLCECCPageWriteSector * (NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE));
break;
case 2 : uErrorType = NAND_ECCERR_2BIT;
UART_Printf("Input the First Byte Postion[0 ~ 2075]");
NAND_EccError.uEccErrByte1 = UART_GetIntNum()%2076;
UART_Printf("Input the First Bit Postion[0 ~ 7]");
NAND_EccError.uEccErrBit1 = UART_GetIntNum()%8;
UART_Printf("Input the Second Byte Postion[0 ~ 2075]");
NAND_EccError.uEccErrByte2 = UART_GetIntNum()%2076;
UART_Printf("Input the Second Bit Postion[0 ~ 7]");
NAND_EccError.uEccErrBit2 = UART_GetIntNum()%8;
NAND_Inform[g_NandContNum].uMLCECCPageWriteSector =
NAND_EccError.uEccErrByte1/(NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE);
NAND_Inform[g_NandContNum].uMLCECCErrBytePos[0] = NAND_EccError.uEccErrByte1 -
(NAND_Inform[g_NandContNum].uMLCECCPageWriteSector * (NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE));
NAND_Inform[g_NandContNum].uMLCECCErrBytePos[1] = NAND_EccError.uEccErrByte2 -
(NAND_Inform[g_NandContNum].uMLCECCPageWriteSector * (NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE));
break;
case 3 : uErrorType = NAND_ECCERR_3BIT;
UART_Printf("Input the First Byte Postion[0 ~ 2075]");
NAND_EccError.uEccErrByte1 = UART_GetIntNum()%2076;
UART_Printf("Input the First Bit Postion[0 ~ 7]");
NAND_EccError.uEccErrBit1 = UART_GetIntNum()%8;
UART_Printf("Input the Second Byte Postion[0 ~ 2075]");
NAND_EccError.uEccErrByte2 = UART_GetIntNum()%2076;
UART_Printf("Input the SecondBit Postion[0 ~ 7]");
NAND_EccError.uEccErrBit2 = UART_GetIntNum()%8;
UART_Printf("Input the Third Byte Postion[0 ~ 2075]");
NAND_EccError.uEccErrByte3 = UART_GetIntNum()%2076;
UART_Printf("Input the Third Bit Postion[0 ~ 7]");
NAND_EccError.uEccErrBit3 = UART_GetIntNum()%8;
NAND_Inform[g_NandContNum].uMLCECCPageWriteSector =
NAND_EccError.uEccErrByte1/(NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE);
NAND_Inform[g_NandContNum].uMLCECCErrBytePos[0] = NAND_EccError.uEccErrByte1 -
(NAND_Inform[g_NandContNum].uMLCECCPageWriteSector * (NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE));
NAND_Inform[g_NandContNum].uMLCECCErrBytePos[1] = NAND_EccError.uEccErrByte2 -
(NAND_Inform[g_NandContNum].uMLCECCPageWriteSector * (NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE));
NAND_Inform[g_NandContNum].uMLCECCErrBytePos[2] = NAND_EccError.uEccErrByte3 -
(NAND_Inform[g_NandContNum].uMLCECCPageWriteSector * (NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE));
break;
case 4 : uErrorType = NAND_ECCERR_4BIT;
UART_Printf("Input the First Byte Postion[0 ~ 2075]");
NAND_EccError.uEccErrByte1 = UART_GetIntNum()%2076;
UART_Printf("Input the First Bit Postion[0 ~ 7]");
NAND_EccError.uEccErrBit1 = UART_GetIntNum()%8;
UART_Printf("Input the Second Byte Postion[0 ~ 2075]");
NAND_EccError.uEccErrByte2 = UART_GetIntNum()%2076;
UART_Printf("Input the SecondBit Postion[0 ~ 7]");
NAND_EccError.uEccErrBit2 = UART_GetIntNum()%8;
UART_Printf("Input the Third Byte Postion[0 ~ 2075]");
NAND_EccError.uEccErrByte3 = UART_GetIntNum()%2076;
UART_Printf("Input the Third Bit Postion[0 ~ 7]");
NAND_EccError.uEccErrBit3 = UART_GetIntNum()%8;
UART_Printf("Input the Fourth Byte Postion[0 ~ 2075]");
NAND_EccError.uEccErrByte4 = UART_GetIntNum()%2076;
UART_Printf("Input the Fourth Bit Postion[0 ~ 7]");
NAND_EccError.uEccErrBit4 = UART_GetIntNum()%8;
NAND_Inform[g_NandContNum].uMLCECCPageWriteSector =
NAND_EccError.uEccErrByte1/(NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE);
NAND_Inform[g_NandContNum].uMLCECCErrBytePos[0] = NAND_EccError.uEccErrByte1 -
(NAND_Inform[g_NandContNum].uMLCECCPageWriteSector * (NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE));
NAND_Inform[g_NandContNum].uMLCECCErrBytePos[1] = NAND_EccError.uEccErrByte2 -
(NAND_Inform[g_NandContNum].uMLCECCPageWriteSector * (NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE));
NAND_Inform[g_NandContNum].uMLCECCErrBytePos[2] = NAND_EccError.uEccErrByte3 -
(NAND_Inform[g_NandContNum].uMLCECCPageWriteSector * (NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE));
NAND_Inform[g_NandContNum].uMLCECCErrBytePos[3] = NAND_EccError.uEccErrByte4 -
(NAND_Inform[g_NandContNum].uMLCECCPageWriteSector * (NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE));
break;
case 5 : uErrorType = NAND_ECCERR_UNCORRECT;
UART_Printf("Input the First Byte Postion[0 ~ 2075]");
NAND_EccError.uEccErrByte1 = UART_GetIntNum()%2076;
UART_Printf("Input the First Bit Postion[0 ~ 7]");
NAND_EccError.uEccErrBit1 = UART_GetIntNum()%8;
UART_Printf("Input the Second Byte Postion[0 ~ 2075]");
NAND_EccError.uEccErrByte2 = UART_GetIntNum()%2076;
UART_Printf("Input the SecondBit Postion[0 ~ 7]");
NAND_EccError.uEccErrBit2 = UART_GetIntNum()%8;
UART_Printf("Input the Third Byte Postion[0 ~ 2075]");
NAND_EccError.uEccErrByte3 = UART_GetIntNum()%2076;
UART_Printf("Input the Third Bit Postion[0 ~ 7]");
NAND_EccError.uEccErrBit3 = UART_GetIntNum()%8;
UART_Printf("Input the Fourth Byte Postion[0 ~ 2075]");
NAND_EccError.uEccErrByte4 = UART_GetIntNum()%2076;
UART_Printf("Input the Fourth Bit Postion[0 ~ 7]");
NAND_EccError.uEccErrBit4 = UART_GetIntNum()%8;
UART_Printf("Input the Fifth Byte Postion[0 ~ 2075]");
NAND_EccError.uEccErrByte5 = UART_GetIntNum()%2076;
UART_Printf("Input the Fifth Bit Postion[0 ~ 7]");
NAND_EccError.uEccErrBit5 = UART_GetIntNum()%8;
NAND_Inform[g_NandContNum].uMLCECCPageWriteSector =
NAND_EccError.uEccErrByte1/(NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE);
NAND_Inform[g_NandContNum].uMLCECCErrBytePos[0] = NAND_EccError.uEccErrByte1 -
(NAND_Inform[g_NandContNum].uMLCECCPageWriteSector * (NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE));
NAND_Inform[g_NandContNum].uMLCECCErrBytePos[1] = NAND_EccError.uEccErrByte2 -
(NAND_Inform[g_NandContNum].uMLCECCPageWriteSector * (NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE));
NAND_Inform[g_NandContNum].uMLCECCErrBytePos[2] = NAND_EccError.uEccErrByte3 -
(NAND_Inform[g_NandContNum].uMLCECCPageWriteSector * (NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE));
NAND_Inform[g_NandContNum].uMLCECCErrBytePos[3] = NAND_EccError.uEccErrByte4 -
(NAND_Inform[g_NandContNum].uMLCECCPageWriteSector * (NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE));
NAND_Inform[g_NandContNum].uMLCECCErrBytePos[4] = NAND_EccError.uEccErrByte5 -
(NAND_Inform[g_NandContNum].uMLCECCPageWriteSector * (NAND_MLC_TRANS_SIZE+NAND_MLC_ECC_SIZE));
break;
default :
return;
}
srand(1);
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;
for(m=0 ; m<4 ; m++)
for(n=0 ; n<2 ; n++)
aNANDT_EccError[m][n] = 0xFFFFFFFE;
UART_Printf("\n");
NAND_Inform[g_NandContNum].uECCtest = 1;
NAND_Inform[g_NandContNum].uAllBitEccCheck = 1;
// Erase Block for test
//UART_Printf("Erase the Block ( %d[block])\n", uBlock);
eError = NAND_EraseSingleBlock(g_NandContNum, uBlock);
if(eError != eNAND_NoError)
{
NANDT_PrintErrorType(eError);
NAND_Inform[g_NandContNum].uECCtest = 0;
NAND_Inform[g_NandContNum].uAllBitEccCheck = 0;
return;
}
// Write the valid data to page ( uBlock[block] 0[page] )
//UART_Printf("Write the valid data to page for ECC generation ( %d[block] %d[page] )\n", uBlock, uPage);
NAND_Inform[g_NandContNum].uECCtest = 1;
eError = NAND_WritePage(g_NandContNum, uBlock, uPage, aBuffer, aSpareBuffer);
if(eError != eNAND_NoError)
{
NANDT_PrintErrorType(eError);
NAND_Inform[g_NandContNum].uECCtest = 0;
NAND_Inform[g_NandContNum].uAllBitEccCheck = 0;
return;
}
//UART_Printf("\n");
// Test Start......!!
if(uErrorType == NAND_ECCERR_1BIT)
{
UART_Printf("[%d byte : %d bit]\n", NAND_EccError.uEccErrByte1, NAND_EccError.uEccErrBit1);
}
else if(uErrorType == NAND_ECCERR_2BIT)
{
UART_Printf("[%d byte : %d bit] & [%d byte : %d bit] \n", NAND_EccError.uEccErrByte1, NAND_EccError.uEccErrBit1,
NAND_EccError.uEccErrByte2, NAND_EccError.uEccErrBit2);
}
else if(uErrorType == NAND_ECCERR_3BIT)
{
UART_Printf("[%d byte : %d bit] & [%d byte : %d bit] & [%d byte : %d bit]\n",
NAND_EccError.uEccErrByte1, NAND_EccError.uEccErrBit1,
NAND_EccError.uEccErrByte2, NAND_EccError.uEccErrBit2,
NAND_EccError.uEccErrByte3, NAND_EccError.uEccErrBit3);
}
else if(uErrorType == NAND_ECCERR_4BIT)
{
UART_Printf("[%d byte : %d bit] & [%d byte : %d bit] & [%d byte : %d bit] & [%d byte : %d bit]\n",
NAND_EccError.uEccErrByte1, NAND_EccError.uEccErrBit1,
NAND_EccError.uEccErrByte2, NAND_EccError.uEccErrBit2,
NAND_EccError.uEccErrByte3, NAND_EccError.uEccErrBit3,
NAND_EccError.uEccErrByte4, NAND_EccError.uEccErrBit4);
}
else if(uErrorType == NAND_ECCERR_UNCORRECT)
{
UART_Printf("[%d byte : %d bit] & [%d byte : %d bit] & [%d byte : %d bit] & [%d byte : %d bit] & [%d byte : %d bit]\n",
NAND_EccError.uEccErrByte1, NAND_EccError.uEccErrBit1,
NAND_EccError.uEccErrByte2, NAND_EccError.uEccErrBit2,
NAND_EccError.uEccErrByte3, NAND_EccError.uEccErrBit3,
NAND_EccError.uEccErrByte4, NAND_EccError.uEccErrBit4,
NAND_EccError.uEccErrByte5, NAND_EccError.uEccErrBit5);
}
// Erase Block for test
//UART_Printf("Erase the Block ( %d[block])\n", uBlock);
eError = NAND_EraseSingleBlock(g_NandContNum, uBlock);
if(eError != eNAND_NoError)
{
NANDT_PrintErrorType(eError);
NAND_Inform[g_NandContNum].uECCtest = 0;
NAND_Inform[g_NandContNum].uAllBitEccCheck = 0;
return;
}
// Write the invalid data to page( uBlock[block] 1[page] )
//UART_Printf("Write the INVALID data to page for ECC generation ( %d[block] %d[page] )\n", uBlock, uPage);
eError = NAND_WritePageWithInvalidData(g_NandContNum, uBlock, uPage, aBuffer, uErrorType);
if(eError != eNAND_NoError)
{
NANDT_PrintErrorType(eError);
NAND_Inform[g_NandContNum].uECCtest = 0;
NAND_Inform[g_NandContNum].uAllBitEccCheck = 0;
return;
}
// Read the invalid data to detect the ECC error
//UART_Printf("Read the INVALID page ( %d[block] %d[page])\n", uBlock, uPage);
eError = NAND_ReadPage(g_NandContNum, uBlock, uPage, aReadBuffer, aSpareBuffer);
NANDT_PrintErrorType(eError);
if(uErrorType == NAND_ECCERR_1BIT)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -