📄 hardwareadaptationlayer.c
字号:
}
Handler.BlockErase = EraseBlock;
return SUCCESS;
}
//********************************************************************************
// BlockErase *
//********************************************************************************
// Erase a block *
//-------------------------------------------------------------------------------*
//PARAMETERS : *
// BlockNumber : physical block number of block to erase *
//RETURN VALUE *
// SUCCESS : erase completed *
// FAILURE : erase failed *
//********************************************************************************
NFTL_Return EraseBlock(UINT16 BlockNumber)
{
UINT32 returnAddress;
//CalculateAddress(BlockNumber,0,&returnAddress) ;
returnAddress = mCalculateAddress(BlockNumber,0) ;
if (NAND_BlockErase(returnAddress) != NAND_PASS)
{
return FAILURE;
}
return SUCCESS;
}
//********************************************************************************
// Write528 *
//********************************************************************************
// Execute page program in device with 528 bytes page size when write buffering *
// is disabled *
//-------------------------------------------------------------------------------*
// PARAMETERS: *
// BlockNumber : number of bloc where write *
// PageNumber : page offset where write *
// buffer : data that must be write *
// RETURN VALUES: *
// SUCCESS : write completed *
// FAILURE : write failed *
// WRONG_ADDRESS : address not valid *
//********************************************************************************
NFTL_Return Write528(UINT16 BlockNumber, UINT8 PageNumber, UINT8 *buffer)
{
UINT32 returnAddress;
//CalculateAddress(BlockNumber,PageNumber,&returnAddress) ;
returnAddress=mCalculateAddress(BlockNumber,PageNumber) ;
return NAND_PageProgramWithEcc(returnAddress,buffer,currentDevice->pageSize);
}
//********************************************************************************
// IsSamePlan *
//********************************************************************************
// Test if two addresses are on the same plan on device *
//-------------------------------------------------------------------------------*
// PARAMETERS: *
// sourceAddress : first address *
// destinationAddress : second address *
// RETURN VALUES: *
// 1 : addresses are on the same plan *
// 0 : addresses are on different plans *
//********************************************************************************
UINT8 IsSamePlan(UINT32 sourceAddress, UINT32 destinationAddress)
{
UINT32 bitpos;
if ((currentDevice->deviceFamily == 512) && (currentDevice->busWidth == 8))
{
bitpos = 0x3000000;
}//mask (bits 24&25)
//if same plan
if ((sourceAddress & bitpos) == (destinationAddress & bitpos))
{
return 1;
}
else
{
return 0;
}
}
//********************************************************************************
// CopyWithCopyBack *
//********************************************************************************
// Copy a page in another page in device using copyback feature. *
//When source and destination addresses are on different plan the source page *
//is read in ram and later written in flash *
//-------------------------------------------------------------------------------*
// PARAMETERS: *
// sourceBlock : number of physical block containing the source page *
// sourcePage : source page offest *
// destinationBlock : number of physical block where write the page *
// destinationPage : destination page offser *
// RETURN VALUES: *
// 1 : addresses are on the same plan *
// 0 : addresses are on different plans *
//********************************************************************************
NFTL_Return CopyWithCopyBack(UINT16 sourceBlock, UINT8 sourcePage,
UINT16 destinationBlock, UINT8 destinationPage)
{
//single plan or same plan , copy back is always executed
UINT32 sourceAddress;
UINT32 destinationAddress;
//CalculateAddress(sourceBlock,sourcePage,&sourceAddress);
//CalculateAddress(destinationBlock,destinationPage,&destinationAddress) ;
sourceAddress =mCalculateAddress(sourceBlock,sourcePage);
destinationAddress =mCalculateAddress(destinationBlock,destinationPage) ;
{
NAND_Ret ret;
if (IsSamePlan(sourceAddress,destinationAddress))
{
ret = NAND_CopyBack(sourceAddress,destinationAddress);
if (ret != NAND_PASS)
{
return FAILURE;
}
return SUCCESS;
}
else
{
return CopyWithoutCopyBack(sourceBlock,sourcePage,destinationBlock,
destinationPage);
}
}
return SUCCESS;
}
//********************************************************************************
// CopyWithoutCopyBack *
//********************************************************************************
// Copy a page in another page in device without using copyback feature. *
//The source page is read in ram and later written in flash *
//-------------------------------------------------------------------------------*
// PARAMETERS: *
// sourceBlock : number of physical block containing the source page *
// sourcePage : source page offest *
// destinationBlock : number of physical block where write the page *
// destinationPage : destination page offser *
// RETURN VALUES: *
// 1 : addresses are on the same plan *
// 0 : addresses are on different plans *
//********************************************************************************
NFTL_Return CopyWithoutCopyBack(UINT16 sourceBlock, UINT8 sourcePage,
UINT16 destinationBlock, UINT8 destinationPage)
{
//same page
if ((sourceBlock == destinationBlock) && (sourcePage == destinationPage))
{
return FAILURE;
}
if (currentDevice->pageSize == 528)
{
UINT8 buffer[CHUNK_SIZE];
UINT32 sourceAddress;
UINT32 destinationAddress;
//CalculateAddress(sourceBlock,sourcePage,&sourceAddress);
sourceAddress = mCalculateAddress(sourceBlock,sourcePage);
if (NAND_PageRead(sourceAddress,buffer,CHUNK_SIZE) != NAND_PASS)
{
return FAILURE;
}
//CalculateAddress(destinationBlock,destinationPage,&destinationAddress);
destinationAddress =mCalculateAddress(destinationBlock,destinationPage);
return NAND_PageProgram(destinationAddress,buffer,CHUNK_SIZE);
}
return SUCCESS;
}
//********************************************************************************
// Read
//********************************************************************************
// Execute the read of page in device with page size 528 or 2112(cache read disable)
//****************************************************************************** *
// PARAMETERS: *
// blockNumber: block number where the page to read is *
// pageNumber: the number of page to read *
// buffer: will contains read data *
// RETURN VALUES: *
// SUCCESS : read executed correctly *
// FAILURE : error during read *
// WRONG_ADDRESS: addren not valid *
//********************************************************************************
NFTL_Return Read(UINT16 blockNumber, UINT8 pageNumber, UINT8 *buffer)
{
UINT32 sourceAddress;
if (WDBuffer != NULL)
if (WDBuffer->NoOfSequentialWrite > 0)
{
NFTL_Return ret;
ret = FlushBuffer();
if (ret != SUCCESS)
return ret;
}
//CalculateAddress(blockNumber,pageNumber,&sourceAddress);
sourceAddress =mCalculateAddress(blockNumber,pageNumber);
if (NAND_PageReadWithEcc(sourceAddress,buffer,currentDevice->pageSize) != NAND_PASS)
{
return FAILURE;
}
return SUCCESS;
}
NFTL_Return Read512(UINT16 blockNumber, UINT8 pageNumber, UINT8 *buffer)
{
UINT32 sourceAddress;
//CalculateAddress(blockNumber,pageNumber,&sourceAddress);
sourceAddress =mCalculateAddress(blockNumber,pageNumber);
if (NAND_PageRead512(sourceAddress,buffer) != NAND_PASS)
{
return FAILURE;
}
return SUCCESS;
}
INT8 IsPageInBuffer(UINT8 pageNumber)
{
UINT8 i;
for(i=0;i<WDBuffer->NoOfPages;i++)
{
if(WDBuffer->PageNumber[i]==pageNumber)
return i;
}
return -1;
}
//********************************************************************************
// ReadSpare528 *
//********************************************************************************
// Exexute the read of spare area in page of 528 bytes size *
//--------------------------------------------------------------------------------
// PARAMETERS: *
// blockNumber: block number where the spare to read is *
// pageNumber: the number of page to read *
// buffer: will contains read data *
// RETURN VALUES: *
// SUCCESS : read executed correctly *
// FAILURE : error during read *
//********************************************************************************
NFTL_Return ReadSpare528(UINT16 BlockNumber, UINT8 PageNumber, UINT8 *buffer)
{
INT8 pageInBuffer;
UINT32 returnAddress;
//if cache program enabled
#if 0
if(UD_BUFFER_ENABLED)
{
if(WDBuffer->LastBlock==BlockNumber)
{
pageInBuffer=IsPageInBuffer(PageNumber);
//is in write buffer
if(pageInBuffer!=-1)
{
OS_MemCopy(buffer,(WDBuffer->Buffer[pageInBuffer])+currentDevice->mainSize,CHUNK_SPARE_SIZE);
return SUCCESS;
}
}
}
#endif
//CalculateAddress(BlockNumber,PageNumber,&returnAddress);
returnAddress=mCalculateAddress(BlockNumber,PageNumber);
if (NAND_SpareRead(returnAddress,buffer,CHUNK_SPARE_SIZE) != NAND_PASS)
return FAILURE ;
return SUCCESS;
}
void WriteChunkInBuffer(UINT8 pagePos, UINT8 PageNum, UINT16 BlockNumber, UINT8 *buffer,
UINT16 bufferLength, UINT16 offsetInBuffer, UINT16 chunkPosition)
{
WDBuffer->PageNumber[pagePos] = PageNum;
WDBuffer->LastBlock = BlockNumber;
WDBuffer->ChunkStatus[chunkPosition] = 1;
OS_MemCopy((WDBuffer->Buffer[chunkPosition]) + offsetInBuffer, buffer, bufferLength);
WDBuffer->NoOfSequentialWrite++;
}
NFTL_Return RecognizeDevice()
{
//read the man code and id of device and autoset the device details
if (currentDevice != NULL)
{
return SUCCESS;
}
currentDevice = (DeviceArchitecture *) OS_DRIVER_Malloc(sizeof(DeviceArchitecture));
if (currentDevice == NULL)
{
return FAILURE;
}
currentDevice->blockSize = 16 * 1024;/*16k*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -