📄 davfhdr.c
字号:
###
### RETURNS:
### None.
###*/
HDR_HeaderStatusEnum FHDR_GetHeaderStatus(HDR_FixedHeaderPtr aHeaderPtr)
{
return HDR_GetHeaderStatus(aHeaderPtr->Attr2);
}
/*#################################################################
### FHDR_CalcObjectHandle
###
### DESCRIPTION:
### Computes the handle from the offset/type stored in the header.
###
### PARAMETERS:
### aHeaderPtr - IN: fixed header with offset/type.
###
### RETURNS:
### A handle to the object.
###*/
FDI_Handle FHDR_CalcObjectHandle(HDR_FixedHeaderPtr aHeaderPtr)
{
FDI_Handle aHandle;
switch( FHDR_GetType(aHeaderPtr))
{
case FDI_HT_NormalObject:
/* object is in page space, so offset is stored in pages */
aHandle = FDI_PageSpaceAddressBottom + (FHDR_GetHeaderIndexOffset(aHeaderPtr) * FDI_PageSize);
break;
default:
/* object is in paragraph space, so offset is stored in bytes */
aHandle = FDI_ParaSpaceAddressBottom + FHDR_GetHeaderIndexOffset(aHeaderPtr);
break;
}
return aHandle;
}
/*#################################################################
### FHDR_CalcObjectOffset
###
### DESCRIPTION:
### This function will compute the object offset, taking into
### account paragraph and page space objects.
###
### PARAMETERS:
### aHandle - IN: Handle to object.
### OUT: Same as in.
###
### RETURNS:
### The status of the header based on the attribute and header id.
###*/
UINT32 FHDR_CalcObjectOffset(FDI_Handle aHandle)
{
UINT32 offset;
if ((aHandle>=FDI_PageSpaceAddressBottom) && (aHandle<=FDI_PageSpaceAddressTop))
{
/* A offset from a handle in page space */
offset = (aHandle - FDI_PageSpaceAddressBottom) / FDI_PageSize;
if ((aHandle - FDI_PageSpaceAddressBottom) % FDI_PageSize) offset++;
}
else if((aHandle>=FDI_ReclaimBlockAddressBottom) && (aHandle<=FDI_ReclaimBlockAddressTop))
{
/* A offset from a handle in reclaim block */
offset = aHandle - FDI_ReclaimBlockAddressBottom;
}
else
{
/* A offset from a handle in paragraph space */
offset = aHandle - FDI_ParaSpaceAddressBottom;
}
return offset;
}
/*#################################################################
### FHDR_CalcObjectSize
###
### DESCRIPTION:
### This function will return the size of the object, including
### the object header and name, in bytes. It will take into
### account page space and paragraph space objects.
###
### PARAMETERS:
### aHeaderPtr - IN: fixed header with offset/type.
###
### RETURNS:
### Size of the object in bytes.
###*/
UINT32 FHDR_CalcObjectSize(HDR_FixedHeaderPtr aHeaderPtr)
{
UINT32 sizeInBytes;
switch(FHDR_GetType(aHeaderPtr))
{
case FDI_HT_NormalObject:
/* object is in page space, so size is stored in pages */
sizeInBytes = FHDR_GetSize(aHeaderPtr) * FDI_PageSize;
break;
default:
/* object is in paragraph space, so size is stored in bytes */
sizeInBytes = FHDR_GetSize(aHeaderPtr);
break;
}
return sizeInBytes;
}
/*#################################################################
### FHDR_IsParaObject
###
### DESCRIPTION:
### Returns true if object resides in paragraph space.
###
### PARAMETERS:
### aHeaderPtr - IN: the fixed header for the object.
### OUT: not used.
###
### RETURNS:
### True if object resides in paragraph space; false otherwise.
###*/
BOOLEAN FHDR_IsParaObject(HDR_FixedHeaderPtr aHeaderPtr)
{
return ((FHDR_CalcObjectHandle(aHeaderPtr) >= FDI_ParaSpaceAddressBottom) &&
(FHDR_CalcObjectHandle(aHeaderPtr) <= FDI_ParaSpaceAddressTop));
}
/*#################################################################
### FHDR_IsPageObject
###
### DESCRIPTION:
### Returns true if object resides in page space.
###
### PARAMETERS:
### aHeaderPtr - IN: the fixed header for the object.
### OUT: not used.
###
### RETURNS:
### None.
###*/
BOOLEAN FHDR_IsPageObject(HDR_FixedHeaderPtr aHeaderPtr)
{
return ((FHDR_CalcObjectHandle(aHeaderPtr) >= FDI_PageSpaceAddressBottom) &&
(FHDR_CalcObjectHandle(aHeaderPtr) <= FDI_PageSpaceAddressTop));
}
/*Fix Start:SCR964 */
UINT16 FHDR_CalcStartBlock(HDR_FixedHeaderPtr aHeaderPtr)
/*Fix End:SCR964 */
{
return UTIL_CalcBlockNumberForOffset(FHDR_GetHeaderIndexOffset(aHeaderPtr));
}
/*Fix Start:SCR964 */
UINT16 FHDR_CalcEndBlock(HDR_FixedHeaderPtr aHeaderPtr)
{
UINT16 result = 0;
/*Fix End:SCR964 */
if (
(FHDR_CalcObjectHandle(aHeaderPtr)>=FDI_PageSpaceAddressBottom) &&
(FHDR_CalcObjectHandle(aHeaderPtr)<=FDI_PageSpaceAddressTop)
)
{
/* A handle in page space */
result = UTIL_CalcBlockNumberForOffset(FHDR_GetHeaderIndexOffset(aHeaderPtr) + FHDR_GetSize(aHeaderPtr) - 1);
}
else if (
(FHDR_CalcObjectHandle(aHeaderPtr)>=FDI_ParaSpaceAddressBottom) &&
(FHDR_CalcObjectHandle(aHeaderPtr)<=FDI_ParaSpaceAddressTop)
)
{
/* A handle in paragraph space */
result = 0;
}
else
{
result = 0;
}
return result;
}
/*#################################################################
### FHDR_IsDirtyChunk
###
### DESCRIPTION:
### Returns true if dirty chunk residing in page space.
###
### PARAMETERS:
### aHeaderPtr - IN: the fixed header for the object.
### OUT: not used.
###
### RETURNS:
### None.
###*/
BOOLEAN FHDR_IsDirtyChunk(HDR_FixedHeaderPtr aPtr)
{
if(FHDR_GetHeaderStatus(aPtr) == HDR_HEADER_VALID)
{
if(FHDR_GetType(aPtr) == FDI_HT_NormalObject)
{
if(FHDR_GetAllocationStatus(aPtr) == HDR_ALLOC_INVALID)
{
return TRUE;
}
}
}
return FALSE;
}
/*#################################################################
### FHDR_IsFreeChunk
###
### DESCRIPTION:
### Returns true if free chunk residing in page space.
###
### PARAMETERS:
### aHeaderPtr - IN: the fixed header for the object.
### OUT: not used.
###
### RETURNS:
### None.
###*/
BOOLEAN FHDR_IsFreeChunk(HDR_FixedHeaderPtr aPtr)
{
if(FHDR_GetHeaderStatus(aPtr) == HDR_HEADER_VALID)
{
if(FHDR_GetType(aPtr) == FDI_HT_NormalObject)
{
if(FHDR_GetAllocationStatus(aPtr) == HDR_ALLOC_EMPTY)
{
return TRUE;
}
}
}
return FALSE;
}
/*#################################################################
### FHDR_IsUserChunk
###
### DESCRIPTION:
### Returns true if user object residing in page space.
###
### PARAMETERS:
### aHeaderPtr - IN: the fixed header for the object.
### OUT: not used.
###
### RETURNS:
### None.
###*/
BOOLEAN FHDR_IsUserChunk(HDR_FixedHeaderPtr aPtr)
{
if(FHDR_GetHeaderStatus(aPtr) == HDR_HEADER_VALID)
{
if(FHDR_GetType(aPtr) == FDI_HT_NormalObject)
{
if(FHDR_GetAllocationStatus(aPtr) == HDR_ALLOC_VALID)
{
return TRUE;
}
}
}
return FALSE;
}
/*#################################################################
### FHDR_IsSystemChunk
###
### DESCRIPTION:
### Returns true if object residing in paragraph space
###
### PARAMETERS:
### aHeaderPtr - IN: the fixed header for the object.
### OUT: not used.
###
### RETURNS:
### None.
###*/
BOOLEAN FHDR_IsSystemChunk(HDR_FixedHeaderPtr aPtr)
{
if(FHDR_GetHeaderStatus(aPtr) == HDR_HEADER_VALID)
{
if(
FHDR_GetType(aPtr) != FDI_HT_NormalObject &&
FHDR_GetType(aPtr) != FDI_HT_RecoveredHeader
)
{
if(FHDR_GetAllocationStatus(aPtr) == HDR_ALLOC_VALID)
{
return TRUE;
}
}
}
return FALSE;
}
/*#################################################################
### HDR_RepairHeader
###
### DESCRIPTION:
### This function will write the header referenced in the
### obj_info structure to a known but unused state. This
### is done by checking its status and finishing the header.
###
###
### PARAMETERS:
### aHandle - Handle to fixed header in flash..
### aHeaderPtr - IN: Pointer to fixed header
### OUT: new recovered header.
###
### RETURNS:
### The status of the header based on the attribute and header id.
###*/
ERR_CODE FHDR_RepairHeader(FDI_Handle aHandle,
HDR_FixedHeaderPtr aHeaderPtr)
{
ERR_CODE status = ERR_NONE;
#ifdef ENABLE_HDR_TESTS
EVT_TestEvent(EVT_HDR_RepairHdr_Start);
#endif
/* Set Global flag for System State */
SetSystemState(FDI_SystemState, FDI_ST_RepairHeader);
/* CASE: power was interrupted during header allocation, no page space was written */
if (FHDR_GetHeaderStatus(aHeaderPtr) == HDR_HEADER_ALLOCATING)
{
/* Mark header as valid but absorbed */
FHDR_SetAbsorbStatus(aHeaderPtr, HDR_ABSORBED);
FHDR_SetHeaderStatus(aHeaderPtr, HDR_HEADER_VALID);
/* Write the absorb and header status back to flash */
/* E5.5.979 START */
status = FLASH_WriteBuffer((UINT32)&(((HDR_FixedHeaderPtr)aHandle)->Attr2),
(UINT8*)&(aHeaderPtr->Attr2),
sizeof(aHeaderPtr->Attr2));
/* E5.5.979 END */
ExitOnError(status);
/* set header allocation status to bad */
FHDR_SetAllocationStatus(aHeaderPtr, HDR_ALLOC_BAD);
/* Write the allocation status back to flash */
/* E5.5.979 START */
status = FLASH_WriteBuffer((UINT32)&(((HDR_FixedHeaderPtr)aHandle)->Attr1),
(UINT8*)&(aHeaderPtr->Attr1),
sizeof(aHeaderPtr->Attr1));
/* E5.5.979 END */
ExitOnError(status);
}
/* Set the allocation status to invalid if bad*/
if (FHDR_GetAllocationStatus(aHeaderPtr) == HDR_ALLOC_BAD)
{
#ifdef ENABLE_HDR_TESTS
EVT_TestEvent(EVT_HDR_RepairHdr_BAD_WIP);
#endif
status = FHDR_InvalidateHeaderInFlash(aHandle, aHeaderPtr);
ExitOnError(status);
}
#ifdef ENABLE_HDR_TESTS
EVT_TestEvent(EVT_HDR_RepairHdr_End);
#endif
return(status);
}
#endif /* DIRECT_ACCESS_VOLUME */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -