📄 davfhdr.c
字号:
sizeof(aHeaderPtr->Attr1));
ExitOnError(status);
/* At this point, entire header has been written, so only write
the necessary bytes to flash */
/* Set header status to HeaderValid */
FHDR_SetHeaderStatus(aHeaderPtr, HDR_HEADER_VALID);
/* 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 allocation status to WriteInProgress */
FHDR_SetAllocationStatus(aHeaderPtr, HDR_ALLOC_WRITE_IN_PROGRESS);
/* E5.5.979 START */
status = FLASH_WriteBuffer((UINT32)&(((HDR_FixedHeaderPtr)aHandle)->Attr1),
(UINT8*)&(aHeaderPtr->Attr1),
sizeof(aHeaderPtr->Attr1));
/* E5.5.979 END */
ExitOnError(status);
return(status);
}
/*#################################################################
### FHDR_CreateInternalObjectHeader
###
### DESCRIPTION:
### This function creates a user-object fixed header in flash at
### the specified handle location.
###
### PARAMETERS:
### aHandle - Address of where to write the fixed
### header.
### offsetInBytes - Offset (in bytes).
### sizeInBytes - Size (in bytes).
###
### RETURNS:
### When this function passes with no errors a value of 0 is
### returned otherwise, it returns a status of type ERR_CODE.
###*/
ERR_CODE FHDR_CreateInternalObjectHeader(FDI_Handle aHandle,
FDI_HT_ObjectTypeEnum aType,
UINT32 offsetInBytes,
UINT32 sizeInBytes)
{
ERR_CODE status = ERR_NONE;
HDR_FixedHeader newHeader;
if (aType == FDI_HT_NormalObject || aType == FDI_HT_RecoveredHeader)
{
status = ERR_PARAM;
ExitOnError(status);
}
HDR_InitHeaderAttr1(newHeader.Attr1);
HDR_InitHeaderAttr2(newHeader.Attr2);
FHDR_SetHeaderIndexOffset(&newHeader, offsetInBytes);
FHDR_SetSize(&newHeader, sizeInBytes);
FHDR_SetType(&newHeader, aType);
status = FHDR_CreateFixedHeader(aHandle, &newHeader);
ExitOnError(status);
status = FHDR_ValidateHeaderInFlash(aHandle, &newHeader);
ExitOnError(status);
return(status);
}
/*#################################################################
### FHDR_CreateUserObjectHeader
###
### DESCRIPTION:
### This function creates a user-object fixed header in flash at
### the specified handle location.
###
### PARAMETERS:
### aHandle - Address of where to write the fixed
### header.
### offsetInPages - Offset (in pages).
### sizeInPages - Size (in pages).
###
### RETURNS:
### When this function passes with no errors a value of 0 is
### returned otherwise, it returns a status of type ERR_CODE.
###*/
ERR_CODE FHDR_CreateUserObjectHeader(FDI_Handle aHandle,
UINT32 offsetInPages,
UINT32 sizeInPages)
{
ERR_CODE status = ERR_NONE;
HDR_FixedHeader newHeader;
HDR_InitHeaderAttr1(newHeader.Attr1);
HDR_InitHeaderAttr2(newHeader.Attr2);
FHDR_SetHeaderIndexOffset(&newHeader, offsetInPages);
FHDR_SetSize(&newHeader, sizeInPages);
FHDR_SetType(&newHeader, FDI_HT_NormalObject);
status = FHDR_CreateFixedHeader(aHandle, &newHeader);
ExitOnError(status);
status = FHDR_ValidateHeaderInFlash(aHandle, &newHeader);
ExitOnError(status);
return(status);
}
/*#################################################################
### FHDR_CreateFreeChunkHeader
###
### DESCRIPTION:
### This function creates a free-chunk fixed header in flash at
### the specified handle location.
###
### PARAMETERS:
### aHandle - Address of where to write the fixed
### header.
### offsetInPages - Offset (in pages).
### sizeInPages - Size (in pages).
###
### RETURNS:
### When this function passes with no errors a value of 0 is
### returned otherwise, it returns a status of type ERR_CODE.
###*/
ERR_CODE FHDR_CreateFreeChunkHeader(FDI_Handle aHandle,
UINT32 offsetInPages,
UINT32 sizeInPages)
{
ERR_CODE status = ERR_NONE;
HDR_FixedHeader newHeader;
HDR_InitHeaderAttr1(newHeader.Attr1);
HDR_InitHeaderAttr2(newHeader.Attr2);
FHDR_SetHeaderIndexOffset(&newHeader, offsetInPages);
FHDR_SetSize(&newHeader, sizeInPages);
FHDR_SetType(&newHeader, FDI_HT_NormalObject);
FHDR_SetHeaderStatus(&newHeader, HDR_HEADER_VALID);
/* Set header status to HeaderAllocating */
FHDR_SetHeaderStatus(&newHeader, HDR_HEADER_ALLOCATING);
status = FLASH_WriteBuffer((UINT32)&(((HDR_FixedHeaderPtr)aHandle)->Attr2),
(UINT8*)&(newHeader.Attr2),
sizeof(newHeader.Attr2));
ExitOnError(status);
/* Set offset; size and type already set; size and type already written, */
/* so write offset and allocation status only to flash */
FHDR_SetAllocationStatus(&newHeader, HDR_ALLOC_EMPTY);
status = FLASH_WriteBuffer((UINT32)&(((HDR_FixedHeaderPtr)aHandle)->Attr1),
(UINT8*)&(newHeader.Attr1),
sizeof(newHeader.Attr1));
ExitOnError(status);
/* Set header status to HeaderValid */
FHDR_SetHeaderStatus(&newHeader, HDR_HEADER_VALID);
/* E5.5.979 START */
status = FLASH_WriteBuffer((UINT32)&(((HDR_FixedHeaderPtr)aHandle)->Attr2),
(UINT8*)&(newHeader.Attr2),
sizeof(newHeader.Attr2));
/* E5.5.979 END */
ExitOnError(status);
return(status);
}
/*#################################################################
### FHDR_CreateDirtyChunkHeader
###
### DESCRIPTION:
### This function creates a dirty-chunk fixed header in flash at
### the specified handle location.
###
### PARAMETERS:
### aHandle - Address of where to write the fixed
### header.
### offsetInPages - Offset (in pages).
### sizeInPages - Size (in pages).
###
### RETURNS:
### When this function passes with no errors a value of 0 is
### returned otherwise, it returns a status of type ERR_CODE.
###*/
ERR_CODE FHDR_CreateDirtyChunkHeader(FDI_Handle aHandle,
UINT32 offsetInPages,
UINT32 sizeInPages)
{
ERR_CODE status = ERR_NONE;
HDR_FixedHeader newHeader;
HDR_InitHeaderAttr1(newHeader.Attr1);
HDR_InitHeaderAttr2(newHeader.Attr2);
FHDR_SetHeaderIndexOffset(&newHeader, offsetInPages);
FHDR_SetSize(&newHeader, sizeInPages);
FHDR_SetType(&newHeader, FDI_HT_NormalObject);
/* Set header status to HeaderAllocating */
FHDR_SetHeaderStatus(&newHeader, HDR_HEADER_ALLOCATING);
status = FLASH_WriteBuffer((UINT32)&(((HDR_FixedHeaderPtr)aHandle)->Attr2),
(UINT8*)&(newHeader.Attr2),
sizeof(newHeader.Attr2));
ExitOnError(status);
/* Set offset; size and type already set; size and type already written, */
/* so write offset and allocation status to flash */
FHDR_SetAllocationStatus(&newHeader, HDR_ALLOC_INVALID);
status = FLASH_WriteBuffer((UINT32)&(((HDR_FixedHeaderPtr)aHandle)->Attr1),
(UINT8*)&(newHeader.Attr1),
sizeof(newHeader.Attr1));
ExitOnError(status);
/* Set header status to HeaderValid */
FHDR_SetHeaderStatus(&newHeader, HDR_HEADER_VALID);
/* E5.5.979 START */
status = FLASH_WriteBuffer((UINT32)&(((HDR_FixedHeaderPtr)aHandle)->Attr2),
(UINT8*)&(newHeader.Attr2),
sizeof(newHeader.Attr2));
/* E5.5.979 END */
ExitOnError(status);
return(status);
}
/*#################################################################
### FHDR_ReadFixedHeader
###
### DESCRIPTION:
### This function will load "aHeaderPtr" with fixed part of header
### data
### PARAMETERS:
### aHandle - Contains handle(address) of header to
### read from flash.
### aHeaderPtr - IN: Must point to a valid header structure.
### OUT: Header is loaded with fixed header information.
###
### RETURNS:
### ERR_CODE.
###*/
/* E5.5.979 START */
ERR_CODE FHDR_ReadFixedHeader(FDI_Handle aHandle,
HDR_FixedHeaderPtr aHeaderPtr,
BOOLEAN restart)
{
ERR_CODE status = ERR_NONE;
UINT32 offset;
/* Read fixed header from flash */
FLASH_ReadBuffer(aHandle, (UINT8*)aHeaderPtr, sizeof(HDR_FixedHeader));
/* Modify as necessary for PLR, Attr1 */
status = FHDR_Attr1_FixISF_PLR(&(aHeaderPtr->Attr1),
aHandle,
restart);
ExitOnError(status);
offset = (UINT32)(&aHeaderPtr->Attr2) - (UINT32)aHeaderPtr;
/* Modify as necessary for PLR, Attr2 */
status = FHDR_Attr2_FixISF_PLR(&(aHeaderPtr->Attr2),
aHandle+offset,
restart);
ExitOnError(status);
return status;
}
/* E5.5.979 END */
/*#################################################################
### FHDR_ValidateHeaderInFlash
###
### DESCRIPTION:
### This function will change the header in flash, pointed to
### by handle, to valid.
###
### PARAMETERS:
### aHandle - Handle to a header in flash.
### aHeaderPtr - IN: Pointer to a header that must have the
### valid existing attributes field.
### OUT: The allocation status will be modified to
### valid.
###
### RETURNS:
### None.
###*/
ERR_CODE FHDR_ValidateHeaderInFlash(FDI_Handle aHandle,
HDR_FixedHeaderPtr aHeaderPtr)
{
ERR_CODE status = ERR_NONE;
/* read the entire fixed header from flash */
status = FLASH_ReadBuffer((UINT32)aHandle,
(UINT8*)aHeaderPtr,
sizeof(HDR_FixedHeader));
ExitOnError(status);
/* Set allocation status to Valid in returned fixed header */
FHDR_SetAllocationStatus(aHeaderPtr, HDR_ALLOC_VALID);
/* 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);
return status;
}
/*#################################################################
### FHDR_InvalidateHeaderInFlash
###
### DESCRIPTION:
### This function will change the header in flash, pointed to
### by handle, to invalid.
###
### PARAMETERS:
### aHandle - Handle to a header in flash.
### aHeaderPtr - IN: Pointer to a header that must have the
### valid existing attributes field.
### OUT: The allocation status will be modified to
### invalid.
###
### RETURNS:
### When this function passes with no errors a value of 0 is
### returned otherwise, it returns a status of type ERR_CODE.
###*/
ERR_CODE FHDR_InvalidateHeaderInFlash(FDI_Handle aHandle,
HDR_FixedHeaderPtr aHeaderPtr)
{
ERR_CODE status = ERR_NONE;
/* read the entire fixed header from flash */
status = FLASH_ReadBuffer((UINT32)aHandle,
(UINT8*)aHeaderPtr,
sizeof(HDR_FixedHeader));
ExitOnError(status);
/* First 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);
/* Next, set header allocation status to invalid */
FHDR_SetAllocationStatus(aHeaderPtr, HDR_ALLOC_INVALID);
/* 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);
return status;
}
/*#################################################################
### FHDR_AbsorbingHeaderInFlash
###
### DESCRIPTION:
### This function will change the header in flash, pointed to
### by handle, to absorbing.
###
### PARAMETERS:
### aHandle - Handle to a header in flash.
### aHeaderPtr - IN: Pointer to a header that must have the
### valid existing attributes field.
### OUT: The absorb status will be modified to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -