📄 onenand_test.c
字号:
else if(uInterrupt & (eOND_RDYACT))
{
OneNandT_ISR_RdyAct(uController);
}
else if(uInterrupt & (eOND_RSTCMP))
{
OneNandT_ISR_RstCmp(uController);
}
else if(uInterrupt & (eOND_CACHEOPERR))
{
OneNandT_ISR_CacheOpErr(uController);
}
}
//////////
// Function Name : OneNandT_SetISRHandler
// Function Description : Register Interrupt Handler
// Input : None
// Version : v0.1
void OneNandT_SetISRHandler(u32 Controller)
{
if(Controller == ONENAND0)
{
INTC_Enable(NUM_ONENAND0);
INTC_SetVectAddr(NUM_ONENAND0, ONENAND_ISR);
}
else if(Controller == ONENAND1)
{
INTC_Enable(NUM_ONENAND1);
INTC_SetVectAddr(NUM_ONENAND1, ONENAND_ISR);
}
OneNandT_ISRCallBack = (void *)OneNandT_ISR_Handler;
ONENAND_SetISRHandler(OneNandT_ISRCallBack);
}
///////////////////////////////////////////////////////////////////////////////////
//////////////////////// Lock Test //////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
//////////
// Function Name : OneNandT_UnlockBlock
// Function Description : Memory Block Unlock Test
// Input : None
// Version : v0.1
void OneNandT_UnlockBlock(void)
{
bool uError = FALSE;
u32 i, uStartBlkAddr, uEndBlkAddr, uData;
UART_Printf("[OneNandT_UnlockBlock]\n");
UART_Printf("Input the Start block to unlock[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfBlock-1);
uStartBlkAddr = UART_GetIntNum();
UART_Printf("Input the End block to unlock[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfBlock-1);
uEndBlkAddr = UART_GetIntNum();
ONENAND_UnlockBlock(g_OneNandContNum, uStartBlkAddr, uEndBlkAddr);
for(i=uStartBlkAddr ; i<=uEndBlkAddr ; i++)
{
uError = FALSE;
ONENAND_DirectWrite(g_OneNandContNum, OND_STARTADDR1, i);
ONENAND_DirectRead(g_OneNandContNum, OND_WPROT_STATUS, &uData);
if ((uData&0xFFFF) != 0x4)
{
UART_Printf(" Failed unlock block, locked status (0x%x) : %d Block\n", uData, i);
uError = TRUE;
UART_Getc();
break;
}
}
if (uError==TRUE)
{
UART_Printf("\nOneNAND unlock block FAILED!!!\n");
}
else
{
UART_Printf("\nOneNAND unlock block SUCCESS\n");
}
}
//////////
// Function Name : OneNandT_UnlockAllBlock
// Function Description : Memory All Block Unlock Test
// Input : None
// Version : v0.1
void OneNandT_UnlockAllBlock(void)
{
OneNAND_eINTERROR uError;
bool bError = FALSE;
u32 i, uData;
UART_Printf("[OneNandT_UnlockAllBlock]\n");
uError = ONENAND_UnlockAllBlock(g_OneNandContNum);
if (uError==eOND_UNSUPCMD)
{
UART_Printf("\nError : OneNAND Unsupported Command(All Block Erase[0x0E command])\n");
// OneNand unlock using 0x08/0x09 command
UART_Printf("OneNAND unlock block will be retry using 0x08/0x09 command\n");
//ONENAND_UnlockBlock(g_OneNandContNum, 0, OneNand_Inform[g_OneNandContNum].uNumOfBlock-1);
if(OneNand_Inform[g_OneNandContNum].uDbsDfs == 0)
ONENAND_UnlockBlock(g_OneNandContNum, 0, OneNand_Inform[g_OneNandContNum].uNumOfBlock-1);
else
{
ONENAND_UnlockBlock(g_OneNandContNum, 0, (OneNand_Inform[g_OneNandContNum].uNumOfBlock/2)-1);
ONENAND_UnlockBlock(g_OneNandContNum, OneNand_Inform[g_OneNandContNum].uNumOfBlock/2, OneNand_Inform[g_OneNandContNum].uNumOfBlock-1);
}
for(i=0 ; i<=OneNand_Inform[g_OneNandContNum].uNumOfBlock ; i++)
{
bError = FALSE;
ONENAND_DirectWrite(g_OneNandContNum, OND_STARTADDR1, i);
ONENAND_DirectRead(g_OneNandContNum, OND_WPROT_STATUS, &uData);
if ((uData&0xFFFF) != 0x4)
{
UART_Printf(" Failed unlock block, locked status (0x%x) : %d Block\n", uData, i);
bError = TRUE;
UART_Getc();
break;
}
}
if (bError==TRUE)
{
UART_Printf("\nOneNAND unlock block FAILED!!!\n");
}
else
{
UART_Printf("\nOneNAND unlock block SUCCESS\n");
}
}
else
{
UART_Printf("\nOneNAND unlock all block SUCCESS\n");
}
}
//////////
// Function Name : OneNandT_LockBlock
// Function Description : Memory Block Lock Test
// Input : None
// Version : v0.1
void OneNandT_LockBlock(void)
{
bool uError = FALSE;
u32 i, uStartBlkAddr, uEndBlkAddr, uData;
UART_Printf("[OneNandT_LockBlock]\n");
UART_Printf("Input the Start block to lock[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfBlock-1);
uStartBlkAddr = UART_GetIntNum();
UART_Printf("Input the End block to lock[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfBlock-1);
uEndBlkAddr = UART_GetIntNum();
ONENAND_LockBlock(g_OneNandContNum, uStartBlkAddr, uEndBlkAddr);
for(i=uStartBlkAddr ; i<=uEndBlkAddr ; i++)
{
uError = FALSE;
ONENAND_DirectWrite(g_OneNandContNum, OND_STARTADDR1, uStartBlkAddr);
ONENAND_DirectRead(g_OneNandContNum, OND_WPROT_STATUS, &uData);
if ((uData&0xFFFF) != 0x2)
{
UART_Printf(" Failed lock block, locked status (0x%x) : %d Block\n", uData, i);
uError = TRUE;
UART_Getc();
break;
}
}
if (uError==TRUE)
{
UART_Printf("\nOneNAND lock block FAILED!!!\n");
}
else
{
UART_Printf("\nOneNAND lock block SUCCESS\n");
}
UART_Printf("\n");
}
//////////
// Function Name : OneNandT_LockTight
// Function Description : Memory Block Lock-Tight Test
// Input : None
// Version : v0.1
void OneNandT_LockTight(void)
{
//bool bError;
bool bError_Temp = FALSE;
u32 i, uStartBlkAddr, uEndBlkAddr, uData;
UART_Printf("[OneNandT_LockTight]\n");
UART_Printf("Input the Start block to lock-tight[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfBlock-1);
uStartBlkAddr = UART_GetIntNum();
UART_Printf("Input the End block to lock-tight[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfBlock-1);
uEndBlkAddr = UART_GetIntNum();
#if 0
bError = ONENAND_LockBlock(g_OneNandContNum, uStartBlkAddr, uEndBlkAddr);
if (bError==FALSE)
UART_Printf("\nOneNAND lock block FAILED!!!\n");
else
UART_Printf("\nOneNAND lock block SUCCESS\n");
#endif
ONENAND_LockTightBlock(g_OneNandContNum, uStartBlkAddr, uEndBlkAddr);
for(i=uStartBlkAddr ; i<=uEndBlkAddr ; i++)
{
ONENAND_DirectWrite(g_OneNandContNum, OND_STARTADDR1, uStartBlkAddr);
ONENAND_DirectRead(g_OneNandContNum, OND_WPROT_STATUS, &uData);
if ((uData&0xFFFF) != 0x1)
{
UART_Printf(" Failed lock-tight block, locked status (0x%x) : %d Block\n", uData, i);
bError_Temp = TRUE;
UART_Getc();
//break;
}
}
if (bError_Temp==TRUE)
{
UART_Printf("\nOneNAND lock block FAILED!!!\n");
}
else
{
UART_Printf("\nOneNAND lock block SUCCESS\n");
}
}
const testFuncMenu onenand_lock[] =
{
OneNandT_UnlockBlock, "Unlock Block",
OneNandT_UnlockAllBlock, "Unlock All Block",
OneNandT_LockBlock, "Lock Block",
OneNandT_LockTight, "Lock-tight Block",
0, 0
};
void OneNandT_LockTest(void)
{
u32 i;
s32 uSel;
while(1)
{
for (i=0; (u32)(onenand_lock[i].desc)!=0; i++)
UART_Printf("%2d: %s\n", i, onenand_lock[i].desc);
UART_Printf("\nSelect the function to test : \n");
uSel =UART_GetIntNum();
UART_Printf("\n");
if(uSel == -1)
break;
if (uSel>=0 && uSel<(sizeof(onenand_lock)/8-1))
(onenand_lock[uSel].func) ();
}
}
///////////////////////////////////////////////////////////////////////////////////
//////////////////////// Erase Test //////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
//////////
// Function Name : OneNandT_EraseBlock
// Function Description : Memory Block Erase Test
// Input : None
// Version : v0.1
void OneNandT_EraseBlock(eFunction_Test eTest, oFunctionT_AutoVar oAutoVar)
{
OneNAND_eINTERROR uError;
u32 i, uStartBlkAddr, uEndBlkAddr;
//bool bVerify;
UART_Printf("[OneNandT_EraseBlock]\n");
if(eTest == eTest_Manual)
{
UART_Printf("Input the Start block to erase[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfBlock-1);
uStartBlkAddr = UART_GetIntNum();
UART_Printf("Input the End block to erase[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfBlock-1);
uEndBlkAddr = UART_GetIntNum();
}
else
{
uStartBlkAddr = oAutoVar.Test_Parameter[0];
uEndBlkAddr = oAutoVar.Test_Parameter[1];
}
#if (ONENANDT_FULLBLOCKERASE == TRUE) //Full Block Erase
{
u32 j;
for(j=0 ; j<OneNand_Inform[g_OneNandContNum].uNumOfBlock ; j++)
{
uStartBlkAddr = uEndBlkAddr = j;
#endif
for(i=0 ; i<200 ; i++)
{
uError = ONENAND_EraseBlock(g_OneNandContNum, uStartBlkAddr, uEndBlkAddr);
if (uError&eOND_ERSFAIL)
{
UART_Printf("\nOneNAND erase block FAILED!!!\n");
if(uError&eOND_LOCKEDBLK)
{
UART_Printf(" =>The address to erase is in a protected block\n");
UART_Getc();
return;
}
}
else if (uError==eOND_NOERROR)
{
if(uStartBlkAddr == uEndBlkAddr)
UART_Printf("\nOneNAND erase block SUCCESS : %d Block\n", uStartBlkAddr);
else
UART_Printf("\nOneNAND erase block SUCCESS : %d Block ~ %d Block\n", uStartBlkAddr, uEndBlkAddr);
}
UART_Printf("\nCount : %d\n", i);
}
#if 0
bVerify = TRUE;
for(i=uStartBlkAddr ; i<=uEndBlkAddr ; i++)
{
uError = ONENAND_EraseVerify(g_OneNandContNum, i);
if (uError&eOND_ERSFAIL)
{
UART_Printf("\nOneNAND erase block verify FAILED[Block : %d]\n", i);
bVerify = FALSE;
//break;
}
}
if(bVerify)
UART_Printf("OneNAND erase block Verify OK\n");
else
{
UART_Printf("OneNAND erase block Verify FAIL\n");
UART_Getc();
}
#endif
#if (ONENANDT_FULLBLOCKERASE == TRUE)
}
}
#endif
UART_Printf("\n");
}
//////////
// Function Name : OneNandT_EraseVerify
// Function Description : Memory Block Erase Verify Test
// Input : None
// Version : v0.1
void OneNandT_EraseVerify(eFunction_Test eTest, oFunctionT_AutoVar oAutoVar)
{
OneNAND_eINTERROR uError;
u32 uStartBlkAddr, uEndBlkAddr; //, i;
if(eTest == eTest_Manual)
{
UART_Printf("[OneNandT_EraseVerify]\n");
UART_Printf("Input the Start block to erase[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfBlock-1);
uStartBlkAddr = UART_GetIntNum();
UART_Printf("Input the End block to erase[0~%d] : \n", OneNand_Inform[g_OneNandContNum].uNumOfBlock-1);
uEndBlkAddr = UART_GetIntNum();
}
else
{
uStartBlkAddr = oAutoVar.Test_Parameter[0];
uEndBlkAddr = oAutoVar.Test_Parameter[1];
}
uError = ONENAND_EraseBlock(g_OneNandContNum, uStartBlkAddr, uEndBlkAddr);
if (uError&eOND_ERSFAIL)
{
UART_Printf("OneNAND erase block FAILED!!!\n");
UART_Getc();
}
else if (uError==eOND_NOERROR)
{
UART_Printf("OneNAND erase block SUCCESS : %d ~ %d Block\n", uStartBlkAddr, uEndBlkAddr);
}
#if 0
for(i=uStartBlkAddr ; i<=uEndBlkAddr ; i++)
{
uError = ONENAND_EraseVerify(g_OneNandContNum, i);
if (uError&eOND_ERSFAIL)
{
UART_Printf("\nOneNAND erase block verify FAILED[Block : %d]\n", i);
break;
}
}
if (uError==eOND_NOERROR)
{
UART_Printf("\nOneNAND erase block verify SUCCESS\n");
}
#endif
}
const AutotestFuncMenu onenand_erase[] =
{
OneNandT_EraseBlock, "Erase Block",
OneNandT_EraseVerify, "Erase Verify",
0, 0
};
void OneNandT_EraseTest(void)
{
u32 i;
s32 uSel;
oFunctionT_AutoVar oParameter;
while(1)
{
for (i=0; (u32)(onenand_erase[i].desc)!=0; i++)
UART_Printf("%2d: %s\n", i, onenand_erase[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_erase)/8-1))
(onenand_erase[uSel].func) (eTest_Manual, oParameter);
}
}
///////////////////////////////////////////////////////////////////////////////////
///////////////////// Parameter Setting ///////////////////////////
///////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -