📄 davgetnh.c
字号:
if ((HDR_GetHdrState(srch_info_ptr->HeaderPtr->Attr16) ==
HDR_HA_STATE_Valid) &&
(HDR_GetStatusAttr(srch_info_ptr->HeaderPtr->Attr16) ==
HDR_HA_Valid))
{
found = 1;
}
break;
case HDR_ByNextPageObject:
if (HDR_GetAlignmentAttr((srch_info_ptr->HeaderPtr->Attr16)) ==
HDR_HA_AlignPage)
{
found = 1;
}
break;
case HDR_ByNameType:
/* Check for matching type and non-invalid object before */
/* checking the name. */
if ((HDR_GetStatusAttr((srch_info_ptr->HeaderPtr->Attr16))
!= HDR_HA_Invalid) &&
(srch_info_ptr->HeaderPtr->ObjectType ==
compare_info_ptr->CompareValue))
{
found = 1;
}
else
{
break;
}
/*lint -fallthrough*/
case HDR_ByName:
/* Read in the header name. */
status = HDR_ReadFullHeader(srch_info_ptr->CurrObj.HeaderAddress,
srch_info_ptr->HeaderPtr, restart);
if(status)
{
return status;
}
/* If the name lengths don't match obviously the names themselves */
/* cannot match. This prevents the problem of a name with */
/* aaaa matching with a name of aaaaa. */
if ((srch_info_ptr->HeaderPtr->NameSize ==
compare_info_ptr->NameSize) &&
((HDR_GetStatusAttr((srch_info_ptr->HeaderPtr->Attr16))
!= HDR_HA_Invalid)))
{
found = 1;
for (ii = 0; ii < compare_info_ptr->NameSize; ii++)
{
if (srch_info_ptr->HeaderPtr->Name[ii] !=
((UINT8_PTR)compare_info_ptr->NamePtr)[ii])
{
found = 0;
break;
}
}
}
else
{
found = 0;
}
break;
case HDR_ByNextParaObject:
default: {};
}
*found_val_ptr = found;
return status;
}
/*#################################################################
### GetNextHeaderHandle
###
### DESCRIPTION:
### This function provides the search routines with a fast method
### of scanning the header table. It only returns only the
### HeaderId and Attributes. The FDI_ReadFullHeader function
### can then be used along with the handle of the header, to
### read the entire header. This loads the srch_info_ptr
### header(partial), object size, and header address.
###
### PARAMETERS:
### srch_info_ptr - Structure containing search information.
### IN: - CurrObj.HeaderAddress references a valid header
### and value of 0 will start the search from the
### beginning of the header table.
### - HeaderPtr points to a valid header for temporary
### use.
###
### OUT: - CurrObj.HeaderAddress will reference the header
### address of the next header matching the type of
### search performed.
### - CurrObj.ObjectSize will contain the size in bytes,
### of the object.
### - HeaderPtr will contain the contents of the
### minimum information necessary to locate any
### one object in memory space.
###
### RETURNS:
### When this function passes with no errors a value of 0 is
### returned otherwise, it returns a status of type ERR_CODE.
###
### ERR_NONE - Entry was found and the search_info_ptr
### contains valid header information.
###
### ERR_NO_MORE_ENTRIES - The entry was not found after searching
### the entire header table.
###*/
ERR_CODE GetNextHeaderHandle(HDR_SearchInfoPtr srch_info_ptr,
int special_condition, BOOLEAN restart)
{
FDI_Handle next_header = 0xffffffff; /* DAV - init to invalid value */
ERR_CODE status = ERR_NONE;
UINT16 this_id;
/* Set start_addr to either the top of Flash memory or to *handle_ptr */
if ((srch_info_ptr->CurrObj.HeaderAddress == 0) ||
(special_condition == GNH_SP_StartAtCurrent))
{
if (srch_info_ptr->CurrObj.HeaderAddress == 0)
{
/* Read the first header entry. */
next_header = srch_info_ptr->CurrObj.HeaderAddress =
HDR_FirstHeaderAddr;
}
}
else
{
if (special_condition == GNH_SP_Normal)
{
/* Might want to make this an option to read from the */
/* flash first! */
HDR_GetObjectSize(srch_info_ptr->HeaderPtr,
(&srch_info_ptr->CurrObj.ObjectSize));
next_header = HDR_CalcNextHdrAddr(srch_info_ptr->CurrObj.HeaderAddress,
(UINT16)HDR_GetAlignmentAttr((srch_info_ptr->HeaderPtr->Attr16)),
srch_info_ptr->HeaderPtr->NameSize,
srch_info_ptr->CurrObj.ObjectSize);
}
}
if (special_condition == GNH_SP_StartAtCurrent)
{
next_header = srch_info_ptr->CurrObj.HeaderAddress;
}
/* Read the header */
FLASH_ReadBuffer(next_header, (MemBufferPtr)srch_info_ptr->HeaderPtr,
HDR_SearchFieldLength);
/*fix Header status*/
status = UINT16_HeaderFixISF_PLR( &(srch_info_ptr->HeaderPtr->Attr16),
(next_header+HDR_OffsetToAttr16), restart);
if(status)
{
return status;
}
/*fix header ID*/
status = UINT16_FixISF_PLR( &(srch_info_ptr->HeaderPtr->HeaderId),
(next_header+HDR_OffsetToHeaderId), restart);
if(status)
{
return status;
}
/* Calculate Next Header's Header Base Address */
srch_info_ptr->CurrObj.HeaderAddress = next_header;
this_id = srch_info_ptr->HeaderPtr->HeaderId;
if (this_id == HDR_ID_Empty)
{
return ERR_NO_MORE_ENTRIES;
}
/* Authenticate that the header is in a good state. */
if (HDR_AuthenticateHeader(srch_info_ptr) != HDR_STATUS_Authentic)
{
return (ERR_PARAM);
}
/* Store object size */
HDR_GetObjectSize(srch_info_ptr->HeaderPtr,
(&srch_info_ptr->CurrObj.ObjectSize));
return ERR_NONE;
}
/*### Global Functions
#########################*/
/*#################################################################
### GetNextHeader
###
### DESCRIPTION:
### This function will return information about the next object
### in the header table, calculate the address of the object and
### keep track of the search state using the search_info_ptr.
### Header information is returned in its raw state.
###
### The start point is determined by the HeaderAddress in the
### search_info_ptr. This value can be from a previous call
### or from previous knowledge of the location of a particular
### header entry. The next object that matches (depends on
### search method) will be returned in the search_info_ptr.
### The restart parameter is used to start from and includes the
### first object in the header table without knowing the address
### of the first entry.
###
### PARAMETERS:
### search_info_ptr - Structure containing detailed information
### about the desired object.
### IN: The CurrObj.HeaderAddress field must contain a valid
### start address to begin searching from. A value of 0
### will start the search from the beginning of the header
### table.
###
### OUT: The state of the search will be completely stored
### in this structure upon return. This will allow
### the caller to return to a previous search state
### no matter what other functions might have called
### it (this function is re-entrant).
###
### All information about an object is returned including
### the entire contents of the header (minus name). The
### HDR_ReadFullHeader function must be used to get the
### name and any other fields that are not essential to
### the search algorithm.
###
### compare_method - Search for the next object with the
### following qualities:
###
### HDR_ByNextObject //Return next object in the header
### // table.
### HDR_ByNextValidObject //Return the next valid object in
### // the header table.
### HDR_ByNextParaObject //Return next para object in the
### // header table.
### HDR_ByNextPageObject //Return next page object in the
### // header table.
### HDR_ByValidType //Return the next valid object with
### // the specified type.
### HDR_ByHeaderAddress //Return the next object that matches the
### // specified header address (fast search).
### HDR_ByTypeOnly //Return the next object of the specified
### // type.
### HDR_ByNameType //Return the next object with the specified
### // name + type.
### HDR_ByName //Return the next object with the specified
### // name.
###
### compare_value - Used to compare header values based
### on the method chosen.
### e.g. Using the SearchByHeaderAddress,
### the calling function would place
### the desired header address in the
### compare_value parameter.
###
### RETURNS:
### When this function passes with no errors a value of 0 is
### returned otherwise, it returns a status of type ERR_CODE.
###
### ERR_NONE - Entry was found and the search_info_ptr
### contains valid header information.
###
### ERR_NO_MORE_ENTRIES - The entry was not found after searching
### the entire header table.
###*/
ERR_CODE GetNextHeader(HDR_SearchInfoPtr search_info_ptr,
HDR_SearchMethod compare_method,
const HDR_CompareInfo *compare_info_ptr,
BOOLEAN restart)
{
UINT32 header_size;
UINT8 found_val = 0;
ERR_CODE status = ERR_NONE;
if (search_info_ptr->CurrObj.HeaderAddress == 0)
{
/* Starting from beginning of header table */
search_info_ptr->PageAccum = 0;
}
while (!status)
{
status = GetNextHeaderHandle(search_info_ptr, FALSE, restart);
if (!status)
{
status = IsFound(search_info_ptr, compare_method, compare_info_ptr,
&found_val, restart);
if(status)
{
return(status);
}
/* If the object is absorbed, don't calculate the object address.*/
if (HDR_GetAbsorbedAttr(search_info_ptr->HeaderPtr->Attr16) ==
HDR_HA_Exists)
{
/* Header is not absorbed */
/* Calculate Next Header's Object Base Address */
if (HDR_GetAlignmentAttr(search_info_ptr->HeaderPtr->Attr16) ==
HDR_HA_AlignPage)
{
/* Header is page aligned */
/* Accumulate if it is a Page object. */
search_info_ptr->CurrObj.ObjectAddress =
FDI_StartAddress + (search_info_ptr->PageAccum *
FDI_PageSize);
search_info_ptr->PageAccum +=
search_info_ptr->CurrObj.ObjectSize /
FDI_PageSize;
}
else
{
/* Header is a paragraph aligned object */
header_size = HDR_CalcHeaderSize((search_info_ptr->HeaderPtr));
search_info_ptr->CurrObj.ObjectAddress = FDI_ParagraphLength +
((search_info_ptr->CurrObj.HeaderAddress -
header_size) -
search_info_ptr->CurrObj.ObjectSize);
}
}
else
{
/* Header is absorbed */
search_info_ptr->CurrObj.ObjectAddress = FDI_InvalidObjAddress;
search_info_ptr->CurrObj.ObjectSize = 0;
}
if (found_val)
{
return ERR_NONE;
}
}
}
return status;
}
#endif /* DIRECT_ACCESS_VOLUME */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -