📄 davhdr.c
字号:
obj_info_ptr->RecoveryLevel = FDI_PLR_Level0;
}
else
{
obj_info_ptr->RecoveryLevel = FDI_PLR_Level1;
}
}
else
{
/* Must be level 2 */
obj_info_ptr->RecoveryLevel = FDI_PLR_Level2;
}
/* Ability to detect WIP vs. Valid object
*/
if (HDR_GetStatusAttr(search_info_ptr->HeaderPtr->Attr16) ==
HDR_HA_Valid)
{
obj_info_ptr->WriteStatus = FDI_WriteStatusValid;
}
else
{
/* DAV Interface will not allow user to see invalid */
/* objects, therefore, it must be WIP. */
obj_info_ptr->WriteStatus = FDI_WriteStatusWIP;
}
}
/*#################################################################
### HDR_AuthenticateHeader
###
### DESCRIPTION:
### This function will check the header referenced in the
### obj_info structure, check it, and determine its state to
### see if it is header.
###
### PARAMETERS:
### obj_info_ptr - IN: Object info structure with the
### header information to authenticate
### OUT: Same as in.
###
### RETURNS:
### The status of the header based on the attribute and header id.
###*/
HDR_Status HDR_AuthenticateHeader(const HDR_SearchInfo *obj_info_ptr)
{
HDR_Status status = HDR_STATUS_NoHeader;
/* Check HeaderID for 0xFXF0 type status */
if (HDR_ID_GetHeaderId((obj_info_ptr->HeaderPtr->HeaderId)) ==
HDR_ID_HeaderId)
{
if (HDR_IsFixedHeaderComplete((obj_info_ptr->HeaderPtr->Attr16)))
{
status = HDR_STATUS_FixedHeaderComplete;
if ((HDR_GetStatusAttr((obj_info_ptr->HeaderPtr->Attr16)) !=
HDR_HA_Available))
{
status = HDR_STATUS_Authentic;
}
}
}
return(status);
}
/*#################################################################
### 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:
### obj_info_ptr - IN: Object info structure with the
### header information to authenticate
### OUT: Object info structure will return
### the new recovered header.
###
### RETURNS:
### The status of the header based on the attribute and header id.
###*/
ERR_CODE HDR_RepairHeader(const HDR_SearchInfo *obj_info_ptr)
{
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);
/* Is header Complete */
switch (HDR_GetStatusAttr((obj_info_ptr->HeaderPtr->Attr16)))
{
case HDR_HA_Available:
#ifdef ENABLE_HDR_TESTS
EVT_TestEvent(EVT_HDR_RepairHdr_AVAIL);
#endif
if (!HDR_IsFixedHeaderComplete((obj_info_ptr->HeaderPtr->Attr16)))
{
obj_info_ptr->HeaderPtr->NameSize = 0;
}
/* Load Header With repaired state information */
obj_info_ptr->HeaderPtr->HeaderId = HDR_ID_Normal;
obj_info_ptr->HeaderPtr->ObjectType = FDI_HT_RecoveredHeader;
obj_info_ptr->HeaderPtr->SecurityKey = 0;
HDR_SetObjectSize(obj_info_ptr->HeaderPtr, 0);
HDR_InitHeaderAttr16((obj_info_ptr->HeaderPtr->Attr16));
HDR_InitHeaderAttr8((obj_info_ptr->HeaderPtr->Attr8));
obj_info_ptr->HeaderPtr->Attr8 =
HDR_SetReliableAttr(obj_info_ptr->HeaderPtr->Attr8,
HDR_HA_Reliable);
obj_info_ptr->HeaderPtr->Attr8 =
HDR_SetReservesAttr(obj_info_ptr->HeaderPtr->Attr8,
HDR_HA_NoReserves);
obj_info_ptr->HeaderPtr->Attr16 = (UINT16)
HDR_SetPrivilegeAttr(obj_info_ptr->HeaderPtr->Attr16, 0);
obj_info_ptr->HeaderPtr->Attr16 =
HDR_SetAlignmentAttr(obj_info_ptr->HeaderPtr->Attr16,
HDR_HA_AlignPage);
obj_info_ptr->HeaderPtr->Attr16 =
HDR_SetAbsorbedAttr(obj_info_ptr->HeaderPtr->Attr16,
HDR_HA_Absorbed);
status = HDR_CreateFixedHeader(obj_info_ptr->CurrObj.HeaderAddress,
obj_info_ptr->HeaderPtr);
if (status)
{
return(status);
}
/* Write header status to Bad */
obj_info_ptr->HeaderPtr->Attr16 = HDR_SetStatusAttr(
(obj_info_ptr->HeaderPtr->Attr16), HDR_HA_Bad);
/* Cast handle as a header_ptr and write attr as word */
status = FLASH_WriteBuffer( (UINT32)&(((HDR_HeaderPtr)(obj_info_ptr->CurrObj.HeaderAddress))->Attr16),
(MemBufferPtr)&(obj_info_ptr->HeaderPtr->Attr16),
sizeof(obj_info_ptr->HeaderPtr->Attr16) );
if (status)
{
return(status);
}
/*lint -fallthrough*/
case HDR_HA_Bad:
#ifdef ENABLE_HDR_TESTS
EVT_TestEvent(EVT_HDR_RepairHdr_BAD_WIP);
#endif
status = HDR_InvalidateHeader(obj_info_ptr->CurrObj.HeaderAddress,
obj_info_ptr->HeaderPtr);
break;
default:
#ifdef ENABLE_HDR_TESTS
EVT_TestEvent(EVT_HDR_RepairHdr_Unknown);
#else
{};
#endif
}
#ifdef ENABLE_HDR_TESTS
EVT_TestEvent(EVT_HDR_RepairHdr_End);
#endif
return(status);
}
/*########################################################################
### UINT8_FixISF_PLR
###
### DESCRIPTION:
### This function will fix the PLR bit's bits in the plr fields of the
### object header from the indeterminate state of 01 or 10 to
### either 00 or 11. for an 8 bit value
###
### PARAMETERS:
### 8 bit pointer to status in RAM
### flash address where Init' may need to be fixed in flash if required
### restart to know wheather to fix in flash or not.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE UINT8_FixISF_PLR(UINT8 *uint8_ptr, UINT32 flash_address,
BOOLEAN restart)
{
ERR_CODE status = ERR_NONE;
UINT8 temp_state;
if((temp_state = GetUINT8QuasiState(*uint8_ptr)) != 0)
{
/*Fix bits to 00 or 11 depending on restart*/
if(restart)
{
/*fix quasi bits to zero*/
*uint8_ptr = FixUINT8QuasiStateTo00(temp_state, *uint8_ptr);
/*Write the state back to flash*/
status = FLASH_WriteBuffer(flash_address, (MemBufferPtr) uint8_ptr,
sizeof(UINT8));
}
else
{
/*fix quasi bits in RAM to 11 of the read is 10, fix it to 00 if the read is a 01*/
if(temp_state & *uint8_ptr)
{ /*this is the 10 situation*/
*uint8_ptr = FixUINT8QuasiStateTo11(temp_state, *uint8_ptr);
}
else
{
/*this is the 01 situation*/
*uint8_ptr = FixUINT8QuasiStateTo00(temp_state, *uint8_ptr);
}
}
}
return (status);
}
/*########################################################################
### UINT16_FixISF_PLR
###
### DESCRIPTION:
### This function will fix the PLR bit's bits in the plr fields of the
### object header from the indeterminate state of 01 or 10 to
### either 00 or 11. for an 16 bit value
###
### PARAMETERS:
### 16 bit pointer to status in RAM
### flash address where Init' may need to be fixed in flash if required
### restart to know wheather to fix in flash or not.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE UINT16_FixISF_PLR(UINT16 *uint16_ptr, UINT32 flash_address,
BOOLEAN restart)
{
UINT16 temp_state;
ERR_CODE status = ERR_NONE;
if((temp_state = GetUINT16QuasiState(*uint16_ptr)) != 0)
{
/*Fix bits to 00 or 11 depending on restart*/
if(restart)
{
/*fix quasi bits to zero*/
*uint16_ptr = FixUINT16QuasiStateTo00(temp_state, *uint16_ptr);
/*Write the state back to flash*/
status = FLASH_WriteBuffer(flash_address, (MemBufferPtr) uint16_ptr,
sizeof(UINT16));
}
else
{
/*fix quasi bits in RAM to 11 of the read is 10, fix it to 00 if the read is a 01*/
if(temp_state & *uint16_ptr)
{ /*this is the 10 situation*/
*uint16_ptr = FixUINT16QuasiStateTo11(temp_state, *uint16_ptr);
}
else
{
/*this is the 01 situation*/
*uint16_ptr = FixUINT16QuasiStateTo00(temp_state, *uint16_ptr);
}
}
}
return (status);
}
/*########################################################################
### UINT32_FixISF_PLR
###
### DESCRIPTION:
### This function will fix the PLR bit's bits in the plr fields of the
### object header from the indeterminate state of 01 or 10 to
### either 00 or 11. for an 32 bit value
###
### PARAMETERS:
### 32 bit pointer to status in RAM
### flash address where Init' may need to be fixed in flash if required
### restart to know wheather to fix in flash or not.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE UINT32_FixISF_PLR(UINT32 *uint32_ptr, UINT32 flash_address,
BOOLEAN restart)
{
UINT32 temp_state;
ERR_CODE status = ERR_NONE;
if((temp_state = GetUINT32QuasiState(*uint32_ptr)) != 0)
{
/*Fix bits to 00 or 11 depending on restart*/
if(restart)
{
/*fix quasi bits to zero*/
*uint32_ptr = FixUINT32QuasiStateTo00(temp_state, *uint32_ptr);
/*Write the state back to flash*/
status = FLASH_WriteBuffer(flash_address, (MemBufferPtr) uint32_ptr,
sizeof(UINT32));
}
else
{
/*fix quasi bits in RAM to 11 of the read is 10, fix it to 00 if the read is a 01*/
if(temp_state & *uint32_ptr)
{ /*this is the 10 situation*/
*uint32_ptr = FixUINT32QuasiStateTo11(temp_state, *uint32_ptr);
}
else
{
/*this is the 01 situation*/
*uint32_ptr = FixUINT32QuasiStateTo00(temp_state, *uint32_ptr);
}
}
}
return (status);
}
/*########################################################################
### UINT16_FixISF_PLR
###
### DESCRIPTION:
### This function will fix the PLR bit's bits in the plr fields of the
### object header from the indeterminate state of 01 or 10 to
### either 00 or 11. for an 16 bit value
###
### PARAMETERS:
### 16 bit pointer to status in RAM
### flash address where Init' may need to be fixed in flash if required
### restart to know wheather to fix in flash or not.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE UINT16_HeaderFixISF_PLR(UINT16 *uint16_ptr, UINT32 flash_address,
BOOLEAN restart)
{
UINT16 temp_state;
ERR_CODE status = ERR_NONE;
if((temp_state = GetUINT16HeaderQuasiState(*uint16_ptr)) != 0)
{
/*Fix bits to 00 or 11 depending on restart*/
if(restart)
{
/*fix quasi bits to zero*/
*uint16_ptr = FixUINT16QuasiStateTo00(temp_state, *uint16_ptr);
/*Write the state back to flash*/
status = FLASH_WriteBuffer(flash_address, (MemBufferPtr) uint16_ptr,
sizeof(UINT16));
}
else
{
/*fix quasi bits in RAM to 11 of the read is 10, fix it to 00 if the read is a 01*/
if(temp_state & *uint16_ptr)
{ /*this is the 10 situation*/
*uint16_ptr = FixUINT16QuasiStateTo11(temp_state, *uint16_ptr);
}
else
{
/*this is the 01 situation*/
*uint16_ptr = FixUINT16QuasiStateTo00(temp_state, *uint16_ptr);
}
}
}
return (status);
}
#endif /* DIRECT_ACCESS_VOLUME */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -