📄 davcghdr.c
字号:
/* Combine Header Id (HTHID<<16 || RBHID) */
header_id_state = CFGHDR_GetInitialState(ht_header_id, rb_header_id);
switch (header_id_state)
{
case Normal_Garbage:
/* Need to check status of entries to determine if this is the */
/* beginning of the process or the end. */
FLASH_ReadBuffer(unique_id_handle1, (MemBufferPtr)&unique_id,
sizeof(unique_id));
status = UINT16_FixISF_PLR(&unique_id, unique_id_handle1,
restart);
if(status)
{
return(status);
}
if (unique_id == 0xFFFF)
{
/* In an erased state (almost done) */
restart_state = RecoverState5;
}
else
{
/* Not an erased state (beginning of cfg reclaim) */
restart_state = RecoverState1;
}
break;
case RIP_Garbage:
case RIP_CIP:
restart_state = RecoverState2;
break;
case Garbage_Normal:
case COC_Normal:
case COC_CIP:
restart_state = RecoverState3;
break;
case Garbage_RIP:
case CIP_RIP:
restart_state = RecoverState4;
break;
case Normal_COC:
case CIP_COC:
restart_state = RecoverState5;
break;
default:
return(ERR_SYSTEM);
}
}
switch (restart_state)
{
case NoRestart:
#ifdef ENABLE_CONFIG_HDR_TESTS
EVT_TestEvent(EVT_CONFIG_HDR_ClearUniqueIds);
#endif
/* Mark Identifier1 to 0x0000 */
status = FLASH_WriteBuffer(unique_id_handle1,
(MemBufferPtr)&unique_id,
sizeof(unique_id));
if (status)
{
break;
}
/*lint -fallthrough*/
case RecoverState1:
case RecoverState2:
case RecoverState3:
#ifdef ENABLE_CONFIG_HDR_TESTS
EVT_TestEvent(EVT_CONFIG_HDR_MoveToRecBlock);
#endif
/* Move header table header to reclaim block */
status = CFGHDR_MoveHeader(ht_header_handle,
rb_header_handle,
restart_state, restart);
if (status)
{
break;
}
/* Need to start move of reclaim block header to header table block */
/* at step 1 of the move. */
restart_state = NoRestart;
/*lint -fallthrough*/
case RecoverState4:
case RecoverState5:
#ifdef ENABLE_CONFIG_HDR_TESTS
EVT_TestEvent(EVT_CONFIG_HDR_MoveFromRecBlock);
#endif
/* Move reclaim block header to header table block */
status = CFGHDR_MoveHeader(rb_header_handle,
ht_header_handle,
restart_state, restart);
if (status)
{
break;
}
#ifdef ENABLE_CONFIG_HDR_TESTS
EVT_TestEvent(EVT_CONFIG_HDR_SetUniqueIds);
#endif
/* Mark Identifier2 */
unique_id = CFGHDR_UniqueIdentifierValue;
status = FLASH_WriteBuffer(unique_id_handle2,
(MemBufferPtr)&unique_id,
sizeof(unique_id));
if (status)
{
break;
}
/* Mark Identifier1 */
status = FLASH_WriteBuffer(unique_id_handle1,
(MemBufferPtr)&unique_id,
sizeof(unique_id));
if (status)
{
break;
}
}
return(status);
}
/*########################################################################
### CFGHDR_MoveHeader
###
### DESCRIPTION:
### This function will move the configuration header and the data
### within the block from one block to another. During this move,
### the status will be marked into the header id of the config. header.
###
### PARAMETERS:
### source_header - handle to the source config header.
### dest_header - handle to the destination config header.
### restart_state - starting point within the move function (used for
### restarting).
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE CFGHDR_MoveHeader(FDI_Handle source_header,
FDI_Handle dest_header,
CFGHDR_RestartState restart_state,
BOOLEAN restart)
{
ERR_CODE status = ERR_NONE;
FDI_Handle copy_handle_to,
copy_handle_from;
status = HDR_ReadFullHeader(source_header , &FDI_GlobalHeader, restart);
if(status)
{
return status;
}
switch (restart_state)
{
case NoRestart:
case RecoverState1:
#ifdef ENABLE_CONFIG_HDR_TESTS
EVT_TestEvent(EVT_CONFIG_HDR_MoveHdrState1);
#endif
/* Mark source header Id to RIP */
FDI_GlobalHeader.HeaderId = HDR_ID_ReclaimInProgress;
/* Write header id to source header. */
status = FLASH_WriteBuffer(source_header,
(MemBufferPtr)&FDI_GlobalHeader.HeaderId,
sizeof(FDI_GlobalHeader.HeaderId));
if (status)
{
break;
}
/*lint -fallthrough*/
case RecoverState2:
case RecoverState4:
#ifdef ENABLE_CONFIG_HDR_TESTS
EVT_TestEvent(EVT_CONFIG_HDR_MoveHdrState2);
#endif
/* Copy source header to destination (HID=CIP) */
FDI_GlobalHeader.HeaderId = HDR_ID_CopyInProgress;
/* Write fixed header to destination header. */
status = FLASH_WriteBuffer(dest_header,
(MemBufferPtr)&FDI_GlobalHeader,
HDR_FixedSize);
if (status)
{
break;
}
/* Copy data (less entries) */
/* Setup handles of what data to copy. */
copy_handle_to = BlockAlign(dest_header);
copy_handle_from = BlockAlign(source_header);
status = FLASH_CopyFlash(copy_handle_from, copy_handle_to,
(FDI_BlockSize - CFGHDR_ConfigHeaderSize));
if (status)
{
break;
}
/* Mark source header Id to CopyOutComplete */
FDI_GlobalHeader.HeaderId = HDR_ID_CopyOutComplete;
status = FLASH_WriteBuffer(source_header,
(MemBufferPtr)&FDI_GlobalHeader.HeaderId,
sizeof(FDI_GlobalHeader.HeaderId));
if (status)
{
break;
}
/*lint -fallthrough*/
case RecoverState3:
case RecoverState5:
#ifdef ENABLE_CONFIG_HDR_TESTS
EVT_TestEvent(EVT_CONFIG_HDR_MoveHdrState3);
#endif
/* Mark destination header Id to Normal */
FDI_GlobalHeader.HeaderId = HDR_ID_Normal;
status = FLASH_WriteBuffer(dest_header,
(MemBufferPtr)&FDI_GlobalHeader.HeaderId,
sizeof(FDI_GlobalHeader.HeaderId));
if (status)
{
break;
}
status = FLASH_EraseBlock(source_header, FALSE);
if (status)
{
break;
}
}
return(status);
}
/*########################################################################
### CFGHDR_MoveHeader
###
### DESCRIPTION:
### This function will create a configuration header at the top of
### object space. It assumes the space has been erased.
###
### PARAMETERS:
### None.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE CFGHDR_CreateConfigurationHeader(void)
{
ERR_CODE status;
FDI_Handle handle, unique_id_handle1, unique_id_handle2;
UINT16 unique_id;
UINT32 size;
FDI_GlobalHeader.NameSize = 0;
FDI_GlobalHeader.ObjectType = FDI_HT_ConfigHeader;
FDI_GlobalHeader.SecurityKey = 0;
/* Calculate the size of the data space for the configuration
* table and make sure it is aligned on a paragraph boundary.
*/
size = DivRoundup(CFGHDR_ConfigTableSize, FDI_ParagraphLength);
FDI_GlobalHeader.Attr16 = 0xFFFF;
FDI_GlobalHeader.Attr8 = 0xFF;
HDR_SetObjectSize(&FDI_GlobalHeader, size);
FDI_GlobalHeader.Attr8 = HDR_SetReliableAttr(FDI_GlobalHeader.Attr8,
HDR_HA_NonReliable);
FDI_GlobalHeader.Attr8 = HDR_SetReservesAttr(FDI_GlobalHeader.Attr8,
HDR_HA_NoReserves);
FDI_GlobalHeader.Attr16 = HDR_SetAlignmentAttr(FDI_GlobalHeader.Attr16,
HDR_HA_AlignPara);
FDI_GlobalHeader.Attr16 = HDR_SetStatusAttr(FDI_GlobalHeader.Attr16,
HDR_HA_Valid);
status = HDR_CreateHeaderEntry(&handle, &FDI_GlobalHeader);
if (status)
{
return status;
}
unique_id_handle1 = CFGHDR_UniqueId1Offset;
unique_id_handle2 = unique_id_handle1 + CFGHDR_UniqueId2Offset;
/* Mark Identifier2 */
unique_id = CFGHDR_UniqueIdentifierValue;
status = FLASH_WriteBuffer(unique_id_handle2, (MemBufferPtr)&unique_id,
sizeof(unique_id));
if (status)
{
return status;
}
/* Mark Identifier1 */
status = FLASH_WriteBuffer(unique_id_handle1, (MemBufferPtr)&unique_id,
sizeof(unique_id));
return status;
}
#endif /* DIRECT_ACCESS_VOLUME */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -