📄 davwrcmp.c
字号:
/*### Local Declarations
#########################*/
#if (DIRECT_ACCESS_VOLUME == TRUE)
/*### Global Declarations
#########################*/
extern HDR_SearchInfo FDI_SearchInfo;
extern HDR_Header FDI_SearchHeader;
/*### Local Functions
#########################*/
/*### Global Functions
#########################*/
/*###################################################################
### WriteComplete
###
### DESCRIPTION:
### This function tells the DAV that the object has been updated
### and the user is done with the old object. It modifies the
### status field of the header entry specified by by obj_name
### and obj_type. It must detect whether an allocate or re-allocate
### was being performed. When one header entry exists, an allocate
### was being performed and WriteComplete will modify the status
### from WriteInProgress to Valid. If two header entries are found
### with the same name and type, a reallocate was being performed
### and the second entry is modified from WriteInProgress to Invalid.
###
### PARAMETERS:
### obj_name - Name of object.
### name_size - Length of the name field in bytes.
### obj_type - Type of the object
###
### 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 FDI_WriteComplete( const UINT8 *obj_name,
UINT8 name_size, UINT32 obj_type )
{
UINT16 header_attr16;
UINT16 first_hdr_attr16;
UINT16 header_size;
BOOLEAN two_copies = FALSE;
ERR_CODE status = ERR_NONE;
FDI_Handle first_hdr_handle;
FDI_Handle handle;
HDR_CompareInfo compare_info;
/* Check range of ObjectType and select value*/
if( obj_type < MIN_DAV_TYPE )
{
return ERR_PARAM;
}
/* Multitasking API exclusivity. (This may not be necessary to the
full extent as it is done here, but for now it is the safest way.) */
FDI_APILock();
/* Clear Global flag for System State */
ClrSystemState(FDI_SystemState, FDI_ST_ReclaimFlag);
/* Start from the beginning of the header table and */
/* search for the first occurrence of the header. There */
/* may be two headers or only one header. */
HDR_InitSearchInfo((&FDI_SearchInfo), (&FDI_SearchHeader));
/* Search for the object and calculate the base address. */
compare_info.NamePtr = (HDR_NamePtr)(obj_name);
compare_info.CompareValue = obj_type;
compare_info.NameSize = name_size;
status = GetNextHeader(&FDI_SearchInfo, HDR_ByNameType, &compare_info, FALSE);
if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) &&
(status != ERR_PARAM))
{
FDI_APIUnlock();
return(status);
}
if (status != ERR_NONE)
{
/* If any error occurs, then no headers with the name and */
/* type exist; exit. */
FDI_APIUnlock();
return ERR_NOTEXISTS;
}
/* Save the location of the first occurrence in case a */
/* second occurrence is found. If one is found, then a */
/* reallocation was done, otherwise it was an allocate. */
first_hdr_handle = FDI_SearchInfo.CurrObj.HeaderAddress;
first_hdr_attr16 = FDI_SearchHeader.Attr16;
status = GetNextHeader(&FDI_SearchInfo, HDR_ByNameType, &compare_info, FALSE);
if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) &&
(status != ERR_PARAM))
{
FDI_APIUnlock();
return(status);
}
/* If the end of the header table is reached (ERR_NO_MORE_ENTRIES), */
/* then only one occurrence of the object was found and the */
/* handle should be updated to point to the first. */
if (status == ERR_NO_MORE_ENTRIES)
{
handle = first_hdr_handle;
header_attr16 = first_hdr_attr16;
}
else
{
two_copies = TRUE;
handle = FDI_SearchInfo.CurrObj.HeaderAddress;
header_attr16 = FDI_SearchInfo.HeaderPtr->Attr16;
}
/* Only operate and update bits if they are marked as */
/* WriteInProgress. */
if (HDR_GetStatusAttr(header_attr16) == HDR_HA_WriteInProgress)
{
/* If there are two headers with the same name and same type */
/* a reallocate was in progress and the second header should */
/* be deallocated. If only one header exists, then the single */
/* header should be modified from WIP to valid. */
if (two_copies)
{
/* This means all information is valid in FDI_SearchInfo */
header_attr16 = HDR_SetStatusAttr(header_attr16, HDR_HA_Invalid);
header_size = HDR_CalcHeaderSize(&FDI_SearchHeader);
switch (HDR_GetAlignmentAttr(header_attr16))
{
/* Update the global variables based on alignment. */
case HDR_HA_AlignPage:
FDI_MemUsage.PageSpace.Invalid +=
FDI_SearchInfo.CurrObj.ObjectSize;
FDI_MemUsage.PageSpace.Valid -=
FDI_SearchInfo.CurrObj.ObjectSize;
FDI_MemUsage.PageOverhead.Invalid += header_size;
FDI_MemUsage.PageOverhead.Valid -= header_size;
break;
case HDR_HA_AlignPara:
/* If enough paragraphs are modified to affect page counts, */
/* then the page variables must also be updated. */
FDI_MemUsage.ParaSpace.Invalid +=
FDI_SearchInfo.CurrObj.ObjectSize;
FDI_MemUsage.ParaSpace.Valid -=
FDI_SearchInfo.CurrObj.ObjectSize;
FDI_MemUsage.ParaOverhead.Invalid += header_size;
FDI_MemUsage.ParaOverhead.Valid -= header_size;
break;
case HDR_HA_AlignRFU1:
case HDR_HA_AlignRFU2:
/* Hooks for future alignments. */
break;
default:
{};
}
}
else
{
/* There are not two entries in the header table */
header_attr16 = HDR_SetStatusAttr(header_attr16, HDR_HA_Valid);
}
/* Mark attributes according to set values in the header. */
status = FLASH_WriteBuffer((handle + ((UINT32)HDR_Attrib16Offset)),
(MemBufferPtr)&header_attr16, HDR_Attrib16Size);
if (status == ERR_NONE)
{
/* if a lockout of the WIP object was in place, we can now */
/* remove it and return any reserved memory to the system. */
if (FDI_LockoutObjectAllocation)
{
FDI_LockoutObjectAllocation = FALSE;
}
/* Put Page reserves back, if they were considered, in use */
FDI_MemUsage.PageSpace.Reserves +=
FDI_MemUsage.PageSpace.ReservesInUse;
FDI_MemUsage.PageSpace.ReservesInUse = 0;
/* Put Para reserves back, if they were considered, in use */
FDI_MemUsage.ParaSpace.Reserves +=
FDI_MemUsage.ParaSpace.ReservesInUse;
FDI_MemUsage.ParaSpace.ReservesInUse = 0;
}
else
{
FDI_APIUnlock();
return status;
}
/* If there are two headers with the same name and same type */
/* a reallocate was in progress and the second header should */
/* be deallocated. If only one header exists, then the single */
/* header should be modified from WIP to valid. */
if (two_copies)
{
/* Add PLR State Recording Support */
RECOVER_MarkDatabaseBusy();
/* Erase the space associated with the new object. */
status = RECINPLC_ReclaimObjectInPlace(&FDI_SearchInfo, FALSE);
if (status)
{
FDI_APIUnlock();
return status;
}
/* Add PLR State Recording Support */
RECOVER_MarkDatabaseReady();
/* Mark the new object header to absorbed. */
status = HDR_AbsorbHeader(FDI_SearchInfo.CurrObj.HeaderAddress,
FDI_SearchInfo.HeaderPtr);
if (status)
{
FDI_APIUnlock();
return(status);
}
}
}
FDI_APIUnlock();
return status;
}
#endif /* DIRECT_ACCESS_VOLUME */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -