📄 romnandflash.c
字号:
//;==============================================================================
//; Function: RomOpenNandFlash
//; Input: none
//; Output: none
//; Description: Initialize hardware
void RomOpenNFlash(void)
{
enable_module_clk(PMC_NAND);
clear_int_mask(INTR_NAND_READY);
enable_mcu_int(INTR_NAND_READY,INT_PRIORITY);
P_NAND_CFG = NANDFLASH_CFG;
P_NAND_CMD = 0xff;
mzEventFlag = ClearBit(mzEventFlag,NAND_EVENT);
return;
}
//;==============================================================================
//; Function: RomCloseNandFlash
//; Input: none
//; Output: none
//; Description:
void RomCloseNFlash(void)
{
disable_module_clk(PMC_NAND);
set_int_mask(INT_PRIORITY);
disable_mcu_int(INTR_NAND_READY);
mzEventFlag = SetBit(mzEventFlag,NAND_EVENT);
return;
}
//;==============================================================================
//; Function: NFlsh_EraseBlock
//; Input: mBlockID --- the erased block ID
//; Output: TRUE:success FALSE:unsuccessful
//; Description: Initialize hardware
BOOL NFlsh_EraseBlock(UINT16 mBlockID)
{
UINT8 aReg;
UINT32 mNandAddr;
if( mBlockID > MAX_BLOCK)
return FALSE;
mNandAddr = mBlockID*NFlashBlockSize;
RomOpenNFlash();
P_NAND_CMD = 0x60;
aReg = (UINT8)(0x0ff&(mNandAddr>>12));
P_NAND_ADD = aReg;
aReg = (UINT8)(0x0ff&(mNandAddr>>20));
P_NAND_ADD = aReg;
aReg = (UINT8)(0x001&(mNandAddr>>28));
P_NAND_ADD = aReg;
P_NAND_CMD = 0xD0;
while(CheckBit(mzEventFlag,NAND_FLAG)==FALSE);
P_NAND_CMD = 0x70;
aReg = P_NAND_DATA;
RomCloseNFlash();
if( (aReg&0x01) == 1 )
return FALSE;
else
return TRUE;
}
//;==============================================================================
//; Function: NFlsh_WritePageAll
//; Input: mBlockID --- the write block ID
//; wPageID --- the write Page ID
//; Output: TRUE:success FALSE:unsuccessful
//; Description: Initialize hardware
BOOL NFlsh_WritePage(UINT16 mBlockID, UINT16 mPageID, UINT8 *pBuffer)
{
UINT8 aReg;
UINT16 mNum;
UINT32 mNandAddr;
if( mBlockID > MAX_BLOCK )
return FALSE;
if( mPageID > MAX_PAGE )
mNandAddr = mBlockID*NFlashBlockSize + mPageID*NFlashPageSize;
RomOpenNFlash();
P_NAND_CMD = 0x80;
aReg = (UINT8)(0x0ff&(mNandAddr>>0));
P_NAND_ADD = aReg;
aReg = (UINT8)(0x00f&(mNandAddr>>8));
P_NAND_ADD = aReg;
aReg = (UINT8)(0x0ff&(mNandAddr>>12));
P_NAND_ADD = aReg;
aReg = (UINT8)(0x0ff&(mNandAddr>>20));
P_NAND_ADD = aReg;
aReg = (UINT8)(0x001&(mNandAddr>>28));
P_NAND_ADD = aReg;
for(mNum=0;mNum<NFlashPageSize;mNum++)
P_NAND_DATA = *(pBuffer+mNum);
P_NAND_CMD = 0x10;
while(CheckBit(mzEventFlag,NAND_FLAG)==FALSE);
P_NAND_CMD = 0x70;
aReg = P_NAND_DATA;
RomCloseNFlash();
if( (aReg&0x01) == 1 )
return FALSE;
else
return TRUE;
}
//;==============================================================================
//; Function: RomOpenNandFlash
//; Input: none
//; Output: none
//; Description: Initialize hardware
UINT8 NFlash_ReadByte(UINT32 *mNandFlashAddr)
{
UINT8 aReg;
UINT32 mNandAddr;
mNandAddr = (UINT32)mNandFlashAddr;
RomOpenNFlash();
P_NAND_CMD = 0x00;
aReg = (UINT8)(0x0ff&(mNandAddr>>0));
P_NAND_ADD = aReg;
aReg = (UINT8)(0x00f&(mNandAddr>>8));
P_NAND_ADD = aReg;
aReg = (UINT8)(0x0ff&(mNandAddr>>12));
P_NAND_ADD = aReg;
aReg = (UINT8)(0x0ff&(mNandAddr>>20));
P_NAND_ADD = aReg;
aReg = (UINT8)(0x001&(mNandAddr>>28));
P_NAND_ADD = aReg;
P_NAND_CMD = 0x30;
while(CheckBit(mzEventFlag,NAND_FLAG)==FALSE);
aReg = P_NAND_DATA;
RomCloseNFlash();
return aReg;
}
BOOL NFlsh_ReadPage(UINT16 mBlockID, UINT16 mPageID, UINT8 *pBuffer)
{
UINT8 aReg;
UINT16 mNum;
UINT32 mNandAddr;
if( mBlockID > MAX_BLOCK )
return FALSE;
if( mPageID > MAX_PAGE )
mNandAddr = mBlockID*NFlashBlockSize + mPageID*NFlashPageSize;
RomOpenNFlash();
P_NAND_CMD = 0x00;
aReg = (UINT8)(0x0ff&(mNandAddr>>0));
P_NAND_ADD = aReg;
aReg = (UINT8)(0x00f&(mNandAddr>>8));
P_NAND_ADD = aReg;
aReg = (UINT8)(0x0ff&(mNandAddr>>12));
P_NAND_ADD = aReg;
aReg = (UINT8)(0x0ff&(mNandAddr>>20));
P_NAND_ADD = aReg;
aReg = (UINT8)(0x001&(mNandAddr>>28));
P_NAND_ADD = aReg;
P_NAND_CMD = 0x30;
while(CheckBit(mzEventFlag,NAND_FLAG)==FALSE);
for(mNum=0;mNum<NFlashPageSize;mNum++)
*(pBuffer+mNum) = P_NAND_DATA;
RomCloseNFlash();
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -