📄 davrecpr.c
字号:
if (process_next_block)
{
exit_state_machine = TRUE;
/* goto ExitParaReclaimStateMachine; */
}
break;
case RECLAIM_ST_ProcessInvalidObj:
if (Handle2Block((ReclaimState.ObjectBaseAddr)) < block_number)
{
exit_state_machine = TRUE;
break;
/* goto ExitParaReclaimStateMachine; */
}
/* If the header is in the current block, then mark it */
/* to CopyOutComplete. */
if (Handle2Block((SearchInfo.CurrObj.HeaderAddress)) ==
ReclaimState.CurrentBlock2Reclaim)
{
EVT_Test4Crash(EVT_RECLAIM_StateF_2a);
HDR_ID_MarkCopyOutComplete(SearchHeader.HeaderId);
status = FLASH_WriteBuffer(SearchInfo.CurrObj.HeaderAddress,
(MemBufferPtr)&SearchHeader.HeaderId,
sizeof(SearchHeader.HeaderId));
EVT_Test4Crash(EVT_RECLAIM_StateF_2b);
if (status)
{
return status;
}
}
ReclaimState.NextState = (UINT16)RECLAIM_ST_ReadNextObj;
if (ReclaimState.ObjectBaseAddr == Block2Handle(block_number))
{
exit_state_machine = TRUE;
/* goto ExitParaReclaimStateMachine; */
}
break;
case RECLAIM_ST_CalcParameters:
ReclaimState.NextState = (UINT16)RECLAIM_ST_CopyOut;
ReclaimState.ObjectHiAddr = ReclaimState.ObjectEndAddr;
ReclaimState.ObjectLoAddr = ReclaimState.ObjectBaseAddr;
/*lint -fallthrough*/
case RECLAIM_ST_CopyOut:
/* Locate section of the object that is in this block. */
/* Set the bytes_in_block variable accordingly. */
in_blk = GetInBlockHiLoAddress(&ReclaimState.ObjectLoAddr,
&ReclaimState.ObjectHiAddr, block_number);
if (in_blk != 0)
{
exit_state_machine = TRUE;
break;
/* goto ExitParaReclaimStateMachine; */
}
bytes_in_block = (ReclaimState.ObjectHiAddr -
ReclaimState.ObjectLoAddr) + 1;
/* Locate a place to copy this portion of the object to. */
/* Either the reclaim block or free space or both. */
/* This will attempt to fill free space first, if there's */
/* not enough free space it will split it into two */
/* transactions, the first to free space, the second */
/* to the reclaim block. */
if (MemMap.FreeBlk.BytesFree > 0)
{
/* Use Free Space (cause its available) */
if (bytes_in_block >= MemMap.FreeBlk.BytesFree)
{
bytes_in_free_block = MemMap.FreeBlk.BytesFree;
}
else
{
bytes_in_free_block = bytes_in_block;
}
bytes_in_block -= bytes_in_free_block;
}
else
{
/* No free space is available. */
bytes_in_free_block = 0;
}
/* If there is any data left to copy out, use the */
/* reclaim block. */
if (bytes_in_block > 0)
{
bytes_in_reclaim_block = bytes_in_block;
bytes_in_block -= bytes_in_reclaim_block;
}
else
{
bytes_in_reclaim_block = 0;
}
/* Copy the fixed portion of the header with a reclaim */
/* status of CopyInProgress. */
if (!ReclaimState.HeaderCopied)
{
bytes_in_header = HDR_FixedSizeP;
ReclaimState.HeaderCopied = TRUE;
ReclaimState.MarkHeaderCopyComplete = TRUE;
/* Copy the buffer to the appropriate area in flash. */
if (bytes_in_free_block > 0)
{
/* Update tracking vars. */
MemMap.FreeBlk.BaseAddr -= bytes_in_header;
MemMap.FreeBlk.BytesFree -= bytes_in_header;
bytes_in_free_block -= bytes_in_header;
/* Calculate the address to copy to */
ReclaimState.ObjectHiAddr -= bytes_in_header;
ReclaimState.TargetHeaderAddress = MemMap.FreeBlk.BaseAddr + 1;
ReclaimState.HeaderInRecBlk = FALSE;
}
else
{
/* Update tracking vars. */
MemMap.RecBlk.BaseAddr -= bytes_in_header;
MemMap.RecBlk.BytesUsed += bytes_in_header;
bytes_in_reclaim_block -= bytes_in_header;
/* Calculate the address to copy to */
ReclaimState.TargetHeaderAddress = MemMap.RecBlk.BaseAddr + 1;
ReclaimState.HeaderInRecBlk = TRUE;
}
/* Read the fixed portion of the header into a buffer. */
/* NOTE: This is only done because the search routines */
/* do not read the entire header. */
FLASH_ReadBuffer(SearchInfo.CurrObj.HeaderAddress,
(MemBufferPtr)&SearchHeader, HDR_FixedSize);
status = UINT16_HeaderFixISF_PLR( &(SearchHeader.Attr16),
(SearchInfo.CurrObj.HeaderAddress+HDR_OffsetToAttr16), restart);
if(status)
{
return status;
}
/*fix header ID*/
status = UINT16_FixISF_PLR( &(SearchHeader.HeaderId),
(SearchInfo.CurrObj.HeaderAddress+HDR_OffsetToHeaderId), restart);
if(status)
{
return status;
}
status = CopyFixedHeader(ReclaimState.TargetHeaderAddress,
(HDR_HeaderPtr)&SearchHeader);
if (status)
{
return status;
}
}
/* Copy the body of the current object out of the current */
/* block. */
ReclaimState.NextState = (UINT16)RECLAIM_ST_CalcParameters;
/* Copy the free block portion to free space. */
if (bytes_in_free_block > 0)
{
MemMap.FreeBlk.BaseAddr -= bytes_in_free_block;
MemMap.FreeBlk.BytesFree -= bytes_in_free_block;
/* Must copy the hi portion of the object to free space. */
ReclaimState.ObjectHiAddr -= bytes_in_free_block - 1;
status = FLASH_CopyFlash(ReclaimState.ObjectHiAddr,
(MemMap.FreeBlk.BaseAddr + 1),
bytes_in_free_block);
if (status)
{
return status;
}
}
#ifdef ENABLE_RECLAIM_TESTS
if (EVT_TestEvent(EVT_RECLAIM_StateF_4))
{
EVT_SetEnabled(EVT_RECLAIM_StateF_4a);
/*
EVT_SetEnabled(EVT_RECLAIM_StateF_4b);
*/
}
#endif
/* Must mark the block done before copying to the */
/* reclaim block if the TO block gets filled. */
status = RECLAIM_MarkBlockDone(TRUE, restart);
/* Copy any remaining data to the reclaim block. */
if ((bytes_in_reclaim_block > 0) && !status)
{
/* The recblk.baseaddr always points to the first */
/* free byte from the top of the block. */
MemMap.RecBlk.BaseAddr -= bytes_in_reclaim_block;
MemMap.RecBlk.BytesUsed += bytes_in_reclaim_block;
status = FLASH_CopyFlash(ReclaimState.ObjectLoAddr,
(MemMap.RecBlk.BaseAddr + 1),
bytes_in_reclaim_block);
}
if (status)
{
return status;
}
/* Detect when entire object is copied out. */
if (Handle2Block((ReclaimState.ObjectBaseAddr)) >=
ReclaimState.CurrentBlock2Reclaim)
{
/* We have finished this object so get the next one */
/* if there are more blocks to go. */
ReclaimState.NextState = (UINT16)RECLAIM_ST_ReadNextObj;
/* If the header is in the current block, then mark it */
/* to CopyOutComplete. */
if (Handle2Block(SearchInfo.CurrObj.HeaderAddress) ==
ReclaimState.CurrentBlock2Reclaim)
{
EVT_Test4Crash(EVT_RECLAIM_StateF_3d);
HDR_ID_MarkCopyOutComplete(SearchHeader.HeaderId);
status = FLASH_WriteBuffer(SearchInfo.CurrObj.HeaderAddress,
(MemBufferPtr)&SearchHeader.HeaderId,
sizeof(SearchHeader.HeaderId));
if (status)
{
return status;
}
EVT_Test4Crash(EVT_RECLAIM_StateF_3e);
}
if (ReclaimState.MarkHeaderCopyComplete)
{
HDR_ID_MarkCopyComplete((SearchHeader.HeaderId));
status = FLASH_WriteBuffer(ReclaimState.TargetHeaderAddress,
(MemBufferPtr)&SearchHeader.HeaderId,
sizeof(SearchHeader.HeaderId));
if (status)
{
return status;
}
EVT_Test4Crash(EVT_RECLAIM_StateF_3f);
}
/* Check to see if the base address of the object */
/* falls just at the edge of the block. */
if (ReclaimState.ObjectBaseAddr ==
Block2Handle(ReclaimState.CurrentBlock2Reclaim))
{
exit_state_machine = TRUE;
break;
/* goto ExitParaReclaimStateMachine; */
}
}
else
{
/* Not done with the object, finish this block */
/* and continue with this object. */
ReclaimState.NextState = (UINT16)RECLAIM_ST_CalcParameters;
if (ReclaimState.HeaderInRecBlk)
{
ReclaimState.HeaderInRecBlk = FALSE;
/* Calculate the address of the header */
ReclaimState.TargetHeaderAddress =
(ReclaimState.TargetHeaderAddress -
BlockAlign(ReclaimState.TargetHeaderAddress)) +
Block2Handle(ReclaimState.CurrentBlock2Reclaim);
}
exit_state_machine = TRUE;
/* goto ExitParaReclaimStateMachine; */
}
break;
default:
exit_state_machine = TRUE;
/* goto ExitParaReclaimStateMachine; */
}
/* goto ParaReclaimStateMachine; */
} while (!exit_state_machine);
/* Erase the current block (if its not the last one!) */
if ((ReclaimState.NextState != (UINT16)RECLAIM_ST_ReclaimComplete) &&
!status)
{
#ifdef ENABLE_RECLAIM_TESTS
if (EVT_TestEvent(EVT_RECLAIM_StateF_6))
{
/* Supported Crashes: 6a...6c */
EVT_SetEnabled(EVT_RECLAIM_StateF_6a);
/*
EVT_SetEnabled(EVT_RECLAIM_StateF_6b);
EVT_SetEnabled(EVT_RECLAIM_StateF_6c);
*/
}
#endif
status = RECLAIM_FinishBlock(ReclaimState.CurrentBlock2Reclaim,
TRUE, TRUE, restart);
}
return status;
}
#endif /* DIRECT_ACCESS_VOLUME */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -