📄 nand_test.c
字号:
printf("Input the Third Bit Postion[0 ~ 7]");
NAND_EccError.uEccErrBit3 = GetIntNum()%8;
printf("Input the Fourth Byte Postion[0 ~ 2075]");
NAND_EccError.uEccErrByte4 = GetIntNum()%2076;
printf("Input the Fourth Bit Postion[0 ~ 7]");
NAND_EccError.uEccErrBit4 = GetIntNum()%8;
printf("Input the Fifth Byte Postion[0 ~ 2075]");
NAND_EccError.uEccErrByte5 = GetIntNum()%2076;
printf("Input the Fifth Bit Postion[0 ~ 7]");
NAND_EccError.uEccErrBit5 = 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;
printf("\n");
NAND_Inform[g_NandContNum].uECCtest = 1;
NAND_Inform[g_NandContNum].uAllBitEccCheck = 1;
// Erase Block for test
//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] )
//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;
}
//printf("\n");
// Test Start......!!
if(uErrorType == NAND_ECCERR_1BIT)
{
printf("[%d byte : %d bit]\n", NAND_EccError.uEccErrByte1, NAND_EccError.uEccErrBit1);
}
else if(uErrorType == NAND_ECCERR_2BIT)
{
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)
{
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)
{
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)
{
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
//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] )
//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
//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)
{
if( (NAND_EccError.uEccErrByte1 != aNANDT_EccError[0][0]) || (NAND_EccError.uEccErrBit1 != aNANDT_EccError[0][1]) )
{
printf("Ecc Error Check Error[%d byte:%d bit] != [%d byte:%d bit] \n", NAND_EccError.uEccErrByte1, NAND_EccError.uEccErrBit1,
aNANDT_EccError[0][0], aNANDT_EccError[0][1]);
getchar();
NAND_Inform[g_NandContNum].uECCtest = 0;
NAND_Inform[g_NandContNum].uAllBitEccCheck = 0;
return;
}
}
else if(uErrorType == NAND_ECCERR_2BIT)
{
if( ((NAND_EccError.uEccErrByte1 != aNANDT_EccError[0][0]) || (NAND_EccError.uEccErrBit1 != aNANDT_EccError[0][1])) ||
((NAND_EccError.uEccErrByte2 != aNANDT_EccError[1][0]) || (NAND_EccError.uEccErrBit2 != aNANDT_EccError[1][1])) )
{
printf("Ecc Error Check Error[%d byte:%d bit] != [%d byte:%d bit] \n", NAND_EccError.uEccErrByte1, NAND_EccError.uEccErrBit1,
aNANDT_EccError[0][0], aNANDT_EccError[0][1]);
printf(" [%d byte:%d bit] != [%d byte:%d bit] \n", NAND_EccError.uEccErrByte2, NAND_EccError.uEccErrBit2,
aNANDT_EccError[1][0], aNANDT_EccError[1][1]);
getchar();
NAND_Inform[g_NandContNum].uECCtest = 0;
NAND_Inform[g_NandContNum].uAllBitEccCheck = 0;
return;
}
}
else if(uErrorType == NAND_ECCERR_3BIT)
{
if( ((NAND_EccError.uEccErrByte1 != aNANDT_EccError[0][0]) || (NAND_EccError.uEccErrBit1 != aNANDT_EccError[0][1])) ||
((NAND_EccError.uEccErrByte2 != aNANDT_EccError[1][0]) || (NAND_EccError.uEccErrBit2 != aNANDT_EccError[1][1])) ||
((NAND_EccError.uEccErrByte3 != aNANDT_EccError[2][0]) || (NAND_EccError.uEccErrBit3 != aNANDT_EccError[2][1])) )
{
printf("Ecc Error Check Error[%d byte:%d bit] != [%d byte:%d bit] \n", NAND_EccError.uEccErrByte1, NAND_EccError.uEccErrBit1,
aNANDT_EccError[0][0], aNANDT_EccError[0][1]);
printf(" [%d byte:%d bit] != [%d byte:%d bit] \n", NAND_EccError.uEccErrByte2, NAND_EccError.uEccErrBit2,
aNANDT_EccError[1][0], aNANDT_EccError[1][1]);
printf(" [%d byte:%d bit] != [%d byte:%d bit] \n", NAND_EccError.uEccErrByte3, NAND_EccError.uEccErrBit3,
aNANDT_EccError[2][0], aNANDT_EccError[2][1]);
getchar();
NAND_Inform[g_NandContNum].uECCtest = 0;
NAND_Inform[g_NandContNum].uAllBitEccCheck = 0;
return;
}
}
else if(uErrorType == NAND_ECCERR_4BIT)
{
if( ((NAND_EccError.uEccErrByte1 != aNANDT_EccError[0][0]) || (NAND_EccError.uEccErrBit1 != aNANDT_EccError[0][1])) ||
((NAND_EccError.uEccErrByte2 != aNANDT_EccError[1][0]) || (NAND_EccError.uEccErrBit2 != aNANDT_EccError[1][1])) ||
((NAND_EccError.uEccErrByte3 != aNANDT_EccError[2][0]) || (NAND_EccError.uEccErrBit3 != aNANDT_EccError[2][1])) ||
((NAND_EccError.uEccErrByte4 != aNANDT_EccError[3][0]) || (NAND_EccError.uEccErrBit4 != aNANDT_EccError[3][1])) )
{
printf("Ecc Error Check Error[%d byte:%d bit] != [%d byte:%d bit] \n", NAND_EccError.uEccErrByte1, NAND_EccError.uEccErrBit1,
aNANDT_EccError[0][0], aNANDT_EccError[0][1]);
printf(" [%d byte:%d bit] != [%d byte:%d bit] \n", NAND_EccError.uEccErrByte2, NAND_EccError.uEccErrBit2,
aNANDT_EccError[1][0], aNANDT_EccError[1][1]);
printf(" [%d byte:%d bit] != [%d byte:%d bit] \n", NAND_EccError.uEccErrByte3, NAND_EccError.uEccErrBit3,
aNANDT_EccError[2][0], aNANDT_EccError[2][1]);
printf(" [%d byte:%d bit] != [%d byte:%d bit] \n", NAND_EccError.uEccErrByte4, NAND_EccError.uEccErrBit4,
aNANDT_EccError[3][0], aNANDT_EccError[3][1]);
getchar();
NAND_Inform[g_NandContNum].uECCtest = 0;
NAND_Inform[g_NandContNum].uAllBitEccCheck = 0;
return;
}
}
else if(uErrorType == NAND_ECCERR_UNCORRECT)
{
if( aNANDT_EccError[0][0] != NAND_ECC_UNCORRECT_ERROR)
{
printf("Uncorrectable Ecc Error Check Error\n");
aNANDT_EccError[0][0] = 0;
getchar();
NAND_Inform[g_NandContNum].uECCtest = 0;
NAND_Inform[g_NandContNum].uAllBitEccCheck = 0;
return;
}
aNANDT_EccError[0][0] = 0;
}
NAND_Inform[g_NandContNum].uECCtest = 0;
NAND_Inform[g_NandContNum].uAllBitEccCheck = 0;
printf("MLC Nand ECC test complete & OK...!!\n");
printf("\n");
}
//////////
// Function Name : NANDT_SLCECC_All
// Function Description : This function checks the ECC operation (all bit of SLC Nand Device 1 page)
// Input : None
// Output : None
void NANDT_SLCECC_All(void)
{
u32 i, j, uBlock, uPage, uError, uErrorType;
u8 aBuffer[NAND_PAGE_MAX];
u8 aSpareBuffer[NAND_SPARE_MAX];
NAND_eERROR eError;
u8 aReadBuffer[NAND_PAGE_MAX];
printf("[NANDT_SLCECC_All]\n");
if(NAND_Inform[g_NandContNum].uNandType == NAND_MLC8bit)
{
printf("The current Nand Memory is MLC type.....!!\n\n");
return;
}
printf("Input the Block Number to test[0~%d]", NAND_Inform[g_NandContNum].uBlockNum-1);
uBlock = GetIntNum();
printf("Input the Page Number to test[0~%d]", NAND_Inform[g_NandContNum].uPageNum-1);
uPage = GetIntNum();
printf("Input the ECC Error Type\n");
printf("1: 1bit error(D), 2: multiple error\n");
uError = 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;
printf("\n");
printf("The all bit ecc check of %dBlock:%dPage\n", uBlock, uPage);
printf("\n");
NAND_EccError.uEccErrByte1 = 0;
NAND_EccError.uEccErrBit1 = 0;
NAND_EccError.uEccErrByte2 = (NAND_EccError.uEccErrByte1+1)%NAND_Inform[g_NandContNum].uPageSize;
NAND_EccError.uEccErrBit2 = 0;
NAND_Inform[g_NandContNum].uECCtest = 1;
NAND_Inform[g_NandContNum].uAllBitEccCheck = 1;
// uBlock+1[Block] Erase & Write to generate the accurate ECC code(aNand_Spare_Data_Temp[i])
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;
}
eError = NAND_WritePage(g_NandContNum, uBlock, 0, aBuffer, aSpareBuffer); // write to 0th page
if(eError != eNAND_NoError)
{
NANDT_PrintErrorType(eError);
NAND_Inform[g_NandContNum].uECCtest = 0;
NAND_Inform[g_NandContNum].uAllBitEccCheck = 0;
return;
}
// Test Start......!!
for(j=0 ; j<NAND_Inform[g_NandContNum].uPageSize ; j++)
{
for(i=0 ; i<8 ; i++)
{
if(uErrorType == NAND_ECCERR_1BIT)
{
printf("[%d byte : %d bit]\n", NAND_EccError.uEccErrByte1, NAND_EccError.uEccErrBit1);
}
else if(uErrorType == NAND_ECCERR_MULTI)
{
printf("[%d byte : %d bit] & [%d byte : %d bit] \n", NAND_EccError.uEccErrByte1, NAND_EccError.uEccErrBit1,
NAND_EccError.uEccErrByte2, NAND_EccError.uEccErrBit2);
}
// Erase Block for test
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] )
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
eError = NAND_ReadPage(g_NandContNum, uBlock, uPage, aReadBuffer, aSpareBuffer);
NANDT_PrintErrorType(eError);
if(uErrorType == NAND_ECCERR_1BIT)
{
if( (NAND_EccError.uEccErrByte1 != aNANDT_EccError[0][0]) || (NAND_EccError.uEccErrBit1 != aNANDT_EccError[0][1]) )
{
printf("Ecc Error Check Error[%d byte:%d bit] != [%d byte:%d bit] \n", NAND_EccError.uEccErrByte1, NAND_EccError.uEccErrBit1,
aNANDT_EccError[0][0], aNANDT_EccError[0][1]);
getchar();
NAND_Inform[g_NandContNum].uECCtest = 0;
NAND_Inform[g_NandContNum].uAllBitEccCheck = 0;
return;
}
}
else if(uErrorType == NAND_ECCERR_MULTI)
{
if( aNANDT_EccError[0][0] != NAND_ECC_MULTI_ERROR)
{
printf("Multi Ecc Error Check Error\n");
aNANDT_EccError[0][0] = 0;
getchar();
NAND_Inform[g_NandContNum].uECCtest = 0;
NAND_Inform[g_NandContNum].uAllBitEccCheck = 0;
return;
}
aNANDT_EccError[0][0] = 0;
}
NAND_EccError.uEccErrBit1++;
NAND_EccError.uEccErrBit2++;
}
NAND_EccError.uEccErrBit1 = 0;
NAND_EccError.uEccErrBit2 = 0;
NAND_EccError.uEccErrByte1++;
NAND_EccError.uEccErrByte2 = (NAND_EccError.uEccErrByte1+1)%NAND_Inform[g_NandContNum].uPageSize;
}
NAND_EccError.uEccErrByte1 = 0;
NAND_EccError.uEccErrByte2 = 0;
NAND_Inform[g_NandContNum].uECCtest = 0;
NAND_Inform[g_NandContNum].uAllBitEccCheck = 0;
printf("SLC Nand All bit ECC test complete\n");
printf("\n");
}
//////////
// Function Name : NANDT_SLCSpareECC_All
// Function Description : This function checks the ECC operation (all bit of Nand Device Spare Area)
// Input : None
// Output : None
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -