📄 davrecl.c
字号:
### in the reclaim table.
###
### PARAMETERS:
### paragraph_reclaim - Indicates special processing depending
### on the method of reclaim.
###
### RETURNS:
### ERR_NONE - When operation is successful.
###
*/
ERR_CODE RECLAIM_MarkBlockDone(BOOLEAN paragraph_reclaim, BOOLEAN restart)
{
BOOLEAN mark_it_done;
ERR_CODE status = ERR_NONE;
RECTBL_TableEntry done_block_status;
mark_it_done = FALSE;
/* Mark the block done once the target is full */
if(paragraph_reclaim)
{
if(Handle2Block(MemMap.FreeBlk.BaseAddr) <
ReclaimState.CurrentDoneBlock)
{
mark_it_done = TRUE;
}
}
else
{
if(Handle2Block(MemMap.FreeBlk.BaseAddr) >
ReclaimState.CurrentDoneBlock)
{
mark_it_done = TRUE;
}
}
if(mark_it_done)
{
EVT_Test4Crash(EVT_RECLAIM_StateF_4a);
/* Mark the current block to DONE */
RECTBL_ReadTable(ReclaimState.RecTblBaseAddr,
ReclaimState.CurrentDoneBlock, &done_block_status,
paragraph_reclaim, restart);
RECTBL_MarkBlockDone(done_block_status);
status = RECTBL_WriteTable(ReclaimState.RecTblBaseAddr,
ReclaimState.CurrentDoneBlock, &done_block_status,
paragraph_reclaim, restart);
if(status)
{
return status;
}
EVT_Test4Crash(EVT_RECLAIM_StateF_4b);
if(paragraph_reclaim)
{
ReclaimState.CurrentDoneBlock--;
}
else
{
ReclaimState.CurrentDoneBlock++;
}
}
return ERR_NONE;
}
/*########################################################################
### RECLAIM_ReLocateReclaimTable
###
### DESCRIPTION:
### This function will create a new reclaim table in the reclaim
### block, where the table only contains information about the
### remaining blocks that have not been reclaimed. The unreclaimed
### blocks should only be those blocks associated with the reclaim
### table.
###
### The following must be done to support recovery:
### Mark target TableId to 0xFFFF before copying entries.
### Mark target TableId to 0xF0F0 after done copying.
### Mark original TableId to 0x0000.
###
### PARAMETERS:
### paragraph_reclaim - Indicates special processing depending
### on the method of reclaim.
###
### RETURNS:
### ERR_NONE - When operation is successful.
###
*/
ERR_CODE RECLAIM_ReLocateReclaimTable(BOOLEAN paragraph_reclaim, BOOLEAN restart)
{
UINT32 ii;
UINT32 first_block, last_block;
UINT32 remaining_blocks;
FDI_Handle new_table_address;
ERR_CODE status = ERR_NONE;
/* First and Last blocks, and the table address are different */
/* depending on the type of reclaim. */
if(paragraph_reclaim)
{
first_block = Handle2Block(ReclaimState.RecTblBaseAddr);
last_block = ReclaimState.CurrentBlock2Reclaim;
new_table_address = RECTBL_RBAddrInParaReclaim;
}
else
{
first_block = ReclaimState.CurrentBlock2Reclaim;
last_block = Handle2Block((ReclaimState.RecTblBaseAddr +
RECTBL_PageRecTblSize - 1));
new_table_address = RECTBL_RBAddrInPageReclaim;
}
remaining_blocks = (last_block - first_block) + 1;
/* Write new table info to the reclaim block */
ReclaimState.TableInfo.FirstBlock = (UINT16)
ReclaimState.CurrentBlock2Reclaim;
ReclaimState.TableInfo.TotalBlocks = (UINT16)remaining_blocks;
ReclaimState.TableInfo.TableId = RECTBL_TableDataInit;
status = RECTBL_WriteTableInfo(new_table_address,
&ReclaimState.TableInfo, paragraph_reclaim);
if(status)
{
return status;
}
EVT_Test4Crash(EVT_RECLAIM_StateG);
/* Copy the current block entries to the reclaim block. */
for(ii = first_block; ii <= last_block; ii++)
{
RECTBL_ReadTable(ReclaimState.RecTblBaseAddr, ii,
&ReclaimState.RecTblEntry,
paragraph_reclaim, restart);
status = RECTBL_WriteTable(new_table_address, ii,
&ReclaimState.RecTblEntry,
paragraph_reclaim, restart);
if(status)
{
return status;
}
}
EVT_Test4Crash(EVT_RECLAIM_StateH);
/* Tell recovery that the new table is created in the reclaim */
/* block but, since there is no header don't worry about marking */
/* the HeaderId. */
status = RECTBL_MarkTableComplete((FDI_Handle)0, new_table_address, FALSE, restart);
if(status)
{
return status;
}
EVT_Test4Crash(EVT_RECLAIM_StateI_SP1);
/* Marking the original TableId to 0x0000 indicates that the */
/* table should no longer be used (for recovery). */
ReclaimState.TableInfo.TableId = RECTBL_TableDataInvalid;
status = FLASH_WriteBuffer((ReclaimState.RecTblBaseAddr +
RECTBL_TableIdOffset),
(MemBufferPtr)&ReclaimState.TableInfo.TableId,
sizeof(ReclaimState.TableInfo.TableId));
EVT_Test4Crash(EVT_RECLAIM_StateI);
/* Officially move the reclaim table address. */
ReclaimState.RecTblBaseAddr = new_table_address;
return status;
}
/*########################################################################
### RECLAIM_EraseBlock
###
### DESCRIPTION:
### This function will erase a block in accordance to the recovery
### methods described in the CSPEC.
###
### PARAMETERS:
### block_number - Block number (0..n) to erase.
### copy_complete - TRUE: Will mark the block copy complete
### before it erases the block.
### paragraph_reclaim - Indicates special processing depending
### on the method of reclaim.
###
### RETURNS:
### ERR_NONE - When operation is successful.
###
*/
ERR_CODE RECLAIM_EraseBlock(UINT32 block_number,
BOOLEAN copy_complete,
BOOLEAN paragraph_reclaim,
BOOLEAN restart)
{
ERR_CODE status = ERR_NONE;
/* Read the contents of the current block information in */
/* the reclaim table. */
RECTBL_ReadTable(ReclaimState.RecTblBaseAddr,
block_number, &ReclaimState.RecTblEntry,
paragraph_reclaim, restart);
if(copy_complete)
{
EVT_Test4Crash(EVT_RECLAIM_StateF_5a);
/* Mark the block as CopyComplete in the reclaim table. */
RECTBL_MarkCopyComplete((ReclaimState.RecTblEntry));
status = RECTBL_WriteTable(ReclaimState.RecTblBaseAddr,
block_number, &ReclaimState.RecTblEntry,
paragraph_reclaim, restart);
if(status)
{
return status;
}
EVT_Test4Crash(EVT_RECLAIM_StateF_5b);
}
/* Mark the block EraseInProgress in the reclaim table */
RECTBL_MarkEraseInProgress((ReclaimState.RecTblEntry));
status = RECTBL_WriteTable(ReclaimState.RecTblBaseAddr,
block_number, &ReclaimState.RecTblEntry,
paragraph_reclaim, restart);
if(status)
{
return status;
}
EVT_Test4Crash(EVT_RECLAIM_StateF_5c);
if(!RECTBL_IsEraseComplete(ReclaimState.RecTblEntry))
{
/* Finally, erase the current block. */
status = FLASH_EraseBlock(Block2Handle(block_number), FALSE);
if(status)
{
return status;
}
EVT_Test4Crash(EVT_RECLAIM_StateF_5d);
}
/* Add erased block memory to the free space tracking var. */
MemMap.FreeBlk.BytesFree += FDI_BlockSize;
/* Mark the block EraseComplete in the reclaim table. */
RECTBL_MarkEraseComplete((ReclaimState.RecTblEntry));
status = RECTBL_WriteTable(ReclaimState.RecTblBaseAddr,
block_number, &ReclaimState.RecTblEntry,
paragraph_reclaim, restart);
if(status)
{
return status;
}
EVT_Test4Crash(EVT_RECLAIM_StateF_5e);
return status;
}
/*########################################################################
### RECLAIM_FinishBlock
###
### DESCRIPTION:
### This function is responsible for eraseing a block and
### copying any data back from the reclaim block.
###
### PARAMETERS:
### paragraph_reclaim - Indicates special processing depending
### on the method of reclaim.
###
### RETURNS:
### ERR_NONE - When operation is successful.
###
*/
ERR_CODE RECLAIM_FinishBlock(UINT32 block_number,
BOOLEAN paragraph_reclaim,
BOOLEAN ok_2_erase_rb,
BOOLEAN restart)
{
ERR_CODE status = ERR_NONE;
#ifdef ENABLE_RECLAIM_TESTS
if(EVT_TestEvent(EVT_RECLAIM_StateF_5))
{
/* Supported Crashes: 5a...5e */
EVT_SetEnabled(EVT_RECLAIM_StateF_5a);
/* EVT_SetEnabled(EVT_RECLAIM_StateF_5b); */
/* EVT_SetEnabled(EVT_RECLAIM_StateF_5c); */
/* EVT_SetEnabled(EVT_RECLAIM_StateF_5d); */
/* EVT_SetEnabled(EVT_RECLAIM_StateF_5e); */
}
#endif
/* Erase the current block */
status = RECLAIM_EraseBlock(block_number,
(BOOLEAN)(MemMap.RecBlk.BytesUsed == 0), paragraph_reclaim, restart);
if(status)
{
return status;
}
/* Delay erasing of the reclaim block until we can copy */
/* out the paragraph objects that are stored in it. */
if(MemMap.RecBlk.BytesUsed)
{
if(paragraph_reclaim)
{
MemMap.FreeBlk.BaseAddr -= MemMap.RecBlk.BytesUsed;
MemMap.FreeBlk.BytesFree -= MemMap.RecBlk.BytesUsed;
/* Copy data from the reclaim block, back to the */
/* top of the current block. */
status = FLASH_CopyFlash(MemMap.RecBlk.BaseAddr + 1,
MemMap.FreeBlk.BaseAddr + 1,
MemMap.RecBlk.BytesUsed);
}
else
{
/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -