📄 davrecip.c
字号:
return status;
}
status = CFGHDR_WriteReclaimComplete(cfg_entry_index);
return status;
}
/* Combine Bottom and Top section statuses */
bottom_status_top_status =
RECINPLC_CombineStatus(RECINPLC_BottomStatus,
RECINPLC_TopStatus);
RECINPLC_BottomStatus = 0x0;
RECINPLC_TopStatus = 0x0;
/* Find restart state */
switch(bottom_status_top_status)
{
case RECINPLC_RAT_NoStatus_NoStatus:
rip_restart_state = RECINPLC_STEP_BottomSection_RecoveryState1;
/* Starting point in block processing */
bottom_block = RECINPLC_BottomSectionAddr;
break;
case RECINPLC_RAT_EIP_NoStatus:
rip_restart_state = RECINPLC_STEP_BottomSection_RecoveryState2;
/* Starting point in block processing */
bottom_block = RECINPLC_BottomSectionAddr;
break;
case RECINPLC_RAT_EC_NoStatus:
rip_restart_state = RECINPLC_STEP_BottomSection_RecoveryState3;
/* Starting point in block processing */
bottom_block = RECINPLC_BottomSectionAddr;
break;
case RECINPLC_RAT_CC_NoStatus:
rip_restart_state = RECINPLC_STEP_BottomSection_RecoveryState4;
/* Starting point in block processing */
bottom_block = RECINPLC_BottomSectionAddr;
break;
case RECINPLC_RAT_Done_NoStatus:
rip_restart_state = RECINPLC_STEP_MiddleSection;
/* Starting point in block processing */
bottom_block = RECINPLC_BottomSectionAddr + FDI_BlockSize;
break;
case RECINPLC_RAT_Done_EIP:
rip_restart_state = RECINPLC_STEP_TopSection_RecoveryState2;
/* Starting point in block processing */
bottom_block = RECINPLC_TopSectionAddr;
break;
case RECINPLC_RAT_Done_EC:
rip_restart_state = RECINPLC_STEP_TopSection_RecoveryState3;
/* Starting point in block processing */
bottom_block = RECINPLC_TopSectionAddr;
break;
case RECINPLC_RAT_Done_CC:
rip_restart_state = RECINPLC_STEP_TopSection_RecoveryState4;
/* Starting point in block processing */
bottom_block = RECINPLC_TopSectionAddr;
break;
case RECINPLC_RAT_Done_Done:
rip_restart_state = RECINPLC_STEP_DeallocateRAT;
/* Starting point in block processing */
bottom_block = RECINPLC_TopSectionAddr + FDI_BlockSize;
break;
default:
/* Unknown State produce fatal error */
return(ERR_SYSTEM);
}
/* DAV - check for valid value */
if (bottom_block != 0xffffffff)
{
bottom_block = Handle2Block(bottom_block);
}
}
else
{
/* SEARCH FOR RAT */
compare_info.CompareValue = FDI_HT_ReAllocateTable;
status = GetNextHeader(&FDI_GlobalInfo, HDR_ByValidType,
&compare_info, restart);
if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) &&
(status != ERR_PARAM))
{
return(status);
}
if (status == ERR_NONE)
{
rip_restart_state = RECINPLC_STEP_DeallocateRAT;
}
else
{
rip_restart_state = RECINPLC_STEP_MarkCfgEntryDone;
}
}
}
else
{
rip_restart_state = RECINPLC_STEP_NoRestart;
}
switch (rip_restart_state)
{
case RECINPLC_STEP_NoRestart:
#ifdef ENABLE_REALLOCATE_TESTS
EVT_TestEvent(EVT_RECINPLC_NoRestart);
#endif
/* Allocate Cfg Entry */
status = CFGHDR_AllocateConfigurationEntry(&cfg_entry_index,
&cfg_entry,
CFGHDR_TYPE_ReAllocateTable, restart);
if (status)
{
return(status);
}
/* Allocate a RAT */
status = RECINPLC_AllocateRAT(&FDI_GlobalInfo, restart);
if (status)
{
return(status);
}
/* Initialize RAT */
status = RECINPLC_InitRAT(&FDI_GlobalInfo, obj_info_ptr);
if (status)
{
return(status);
}
/* Mark Offset */
status = CFGHDR_WriteTableOffset(cfg_entry_index,
FDI_GlobalInfo.CurrObj.HeaderAddress);
if (status)
{
return(status);
}
bottom_block = Handle2Block(RECINPLC_BottomSectionAddr);
/*lint -fallthrough*/
case RECINPLC_STEP_BottomSection_RecoveryState1:
case RECINPLC_STEP_BottomSection_RecoveryState2:
case RECINPLC_STEP_BottomSection_RecoveryState3:
case RECINPLC_STEP_BottomSection_RecoveryState4:
case RECINPLC_STEP_MiddleSection:
case RECINPLC_STEP_TopSection_RecoveryState1:
case RECINPLC_STEP_TopSection_RecoveryState2:
case RECINPLC_STEP_TopSection_RecoveryState3:
case RECINPLC_STEP_TopSection_RecoveryState4:
#ifdef ENABLE_REALLOCATE_TESTS
EVT_TestEvent(EVT_RECINPLC_ProcessBlocks);
#endif
top_block = Handle2Block(RECINPLC_TopSectionAddr);
for (block = bottom_block; block <= top_block; block++ )
{
start_addr_in_block = RECINPLC_BottomSectionAddr;
end_addr_in_block = RECINPLC_TopSectionAddr;
GetInBlockHiLoAddress(&start_addr_in_block,
&end_addr_in_block, block);
status = RECINPLC_ProcessBlock(
FDI_GlobalInfo.CurrObj.ObjectAddress,
start_addr_in_block,
end_addr_in_block,
rip_restart_state);
if (status)
{
return(status);
}
if (restart)
{
/* Continue processing blocks from normal restart state */
rip_restart_state = RECINPLC_STEP_NoRestart;
}
}
/*lint -fallthrough*/
case RECINPLC_STEP_DeallocateRAT:
#ifdef ENABLE_REALLOCATE_TESTS
EVT_TestEvent(EVT_RECINPLC_DeallocateRAT);
#endif
/* Init Attr to a Erased State */
/* Deallocate Table */
HDR_InitHeaderAttr16(FDI_GlobalInfo.HeaderPtr->Attr16);
HDR_InitHeaderAttr8(FDI_GlobalInfo.HeaderPtr->Attr8);
status = HDR_InvalidateHeader(FDI_GlobalInfo.CurrObj.HeaderAddress,
FDI_GlobalInfo.HeaderPtr);
if (status != ERR_NONE)
{
return(status);
}
/*lint -fallthrough*/
case RECINPLC_STEP_MarkCfgEntryDone:
#ifdef ENABLE_REALLOCATE_TESTS
EVT_TestEvent(EVT_RECINPLC_MarkCFGDone);
#endif
status = CFGHDR_WriteReclaimComplete(cfg_entry_index);
if (status)
{
return status;
}
}
#ifdef ENABLE_REALLOCATE_TESTS
EVT_TestEvent(EVT_RECINPLC_ReclaimInPlace_End);
#endif
return(status);
}
/*#################################################################
### RECINPLC_AllocateRAT
###
### DESCRIPTION:
### This function will allocate a Reallocate table and
### return its header and data location within the obj_info
### structure.
###
### PARAMETERS:
### obj_info_ptr - IN: Nothing.
### - OUT: The location of the new RAT and its header.
###
### 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 RECINPLC_AllocateRAT(HDR_SearchInfoPtr obj_info_ptr, BOOLEAN restart)
{
ERR_CODE status;
/* Table uses reclaim space reserves, so there must be space available */
obj_info_ptr->HeaderPtr->Attr8 =
HDR_SetReliableAttr(obj_info_ptr->HeaderPtr->Attr8, HDR_HA_NonReliable);
obj_info_ptr->HeaderPtr->Attr8 =
HDR_SetReservesAttr(obj_info_ptr->HeaderPtr->Attr8, HDR_HA_NoReserves);
obj_info_ptr->HeaderPtr->Attr16 =
HDR_SetAlignmentAttr(obj_info_ptr->HeaderPtr->Attr16, HDR_HA_AlignPara);
obj_info_ptr->HeaderPtr->Attr16 = (UINT16)
HDR_SetPrivilegeAttr(obj_info_ptr->HeaderPtr->Attr16, 0);
obj_info_ptr->HeaderPtr->Attr16 =
HDR_SetStatusAttr(obj_info_ptr->HeaderPtr->Attr16, HDR_HA_Valid);
obj_info_ptr->HeaderPtr->Attr16 =
HDR_SetAbsorbedAttr(obj_info_ptr->HeaderPtr->Attr16, HDR_HA_Exists);
HDR_SetObjectSize(obj_info_ptr->HeaderPtr,
RECINPLC_ReAllocateTableSize/FDI_ParagraphLength);
obj_info_ptr->HeaderPtr->NameSize = 0;
obj_info_ptr->HeaderPtr->ObjectType = FDI_HT_ReAllocateTable;
obj_info_ptr->HeaderPtr->SecurityKey = 0;
/* Write the header to flash */
status = HDR_CreateHeaderEntry(&obj_info_ptr->CurrObj.HeaderAddress,
obj_info_ptr->HeaderPtr);
obj_info_ptr->CurrObj.ObjectSize = RECINPLC_ReAllocateTableSize;
obj_info_ptr->CurrObj.ObjectAddress = obj_info_ptr->CurrObj.HeaderAddress -
obj_info_ptr->CurrObj.ObjectSize;
if (status)
{
return(status);
}
status = HDR_CalcMemoryStatistics(restart);
return(status);
}
/*#################################################################
### RECINPLC_InitRAT
###
### DESCRIPTION:
### This function will initialize the RAT described by the
### table_info structure with data from obj_info structure.
###
### PARAMETERS:
### table_info_ptr - IN: Correct table_info object address.
### - OUT: No change.
### obj_info_ptr - IN: Correct object size and start address
### to be loaded into the RAT
###
### 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 RECINPLC_InitRAT(const HDR_SearchInfo *table_info_ptr,
const HDR_SearchInfo *obj_info_ptr )
{
UINT16 unique_id = 0xF0F0;
ERR_CODE status;
FDI_Handle table_handle;
table_handle = table_info_ptr->CurrObj.ObjectAddress;
/* Write Bottom Entry */
RECINPLC_BottomSectionAddr = obj_info_ptr->CurrObj.ObjectAddress;
status = FLASH_WriteBuffer((table_handle + RECINPLC_OffsetToBottomAddress),
(MemBufferPtr)(& RECINPLC_BottomSectionAddr),
sizeof(RECINPLC_BottomSectionAddr));
if (status)
{
return(status);
}
/* Write Top Entry */
RECINPLC_TopSectionAddr = obj_info_ptr->CurrObj.ObjectAddress +
obj_info_ptr->CurrObj.ObjectSize;
status = FLASH_WriteBuffer((table_handle + RECINPLC_OffsetToTopAddress),
(MemBufferPtr)(&RECINPLC_TopSectionAddr),
sizeof(RECINPLC_TopSectionAddr));
if (status)
{
return(status);
}
/* Write Unique Id 2 */
status = FLASH_WriteBuffer((table_handle + RECINPLC_OffsetToUniqueId2),
(MemBufferPtr)(&unique_id), sizeof(unique_id));
if (status)
{
return(status);
}
/* Write Unique Id 1 */
status = FLASH_WriteBuffer((table_handle + RECINPLC_OffsetToUniqueId1),
(MemBufferPtr)(&unique_id), sizeof(unique_id));
return(status);
}
/*#################################################################
### RECINPLC_ProcessBlock
###
### DESCRIPTION:
### This function will process the blocks for reclaim in place,
### and mark each step within the RAT as necessary.
###
### PARAMETERS:
### table_base_addr - Handle to the RAT base address.
### start_addr_in_block - Handle to the start address within
### the block to be processed.
### end_addr_in_block - Handle to the end address within
### the block to be processed.
### rip_restart_state - The starting point to process the block
### for the purpose of restarting.
###
### 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 RECINPLC_ProcessBlock(FDI_Handle table_base_addr,
FDI_Handle start_addr_in_block,
FDI_Handle end_addr_in_block,
RECINPLC_RestartStates rip_restart_state)
{
UINT32 block; /*Block currently being processed */
BOOLEAN RAT_in_block = FALSE; /*Indicates if RAT in block */
BOOLEAN in_top_block = FALSE; /*Indicates if block is in top block */
BOOLEAN in_bottom_block = FALSE; /*Indicates if block is in bottom block */
BOOLEAN in_middle_block = FALSE; /*Indicates if block is a middle block */
FDI_Handle block_status_handle; /*Handle to the status in RAT */
ERR_CODE status; /*Return status */
FDI_Handle block_status_handle_rb, /*Handle to RAT status in reclaim block */
block_status_handle_ht, /*Handle to RAT status in header table */
top_data_size, /*Total bytes from top address to */
/* upper block boundary */
bottom_data_size, /*Total bytes from lower block boundary */
/* to the bottom address */
start_handle_ht, /*Base address for copying bottom section*/
/* in the header table block */
start_handle_rb, /*Base address for copying bottom section*/
/* in the reclaim block */
end_handle_ht, /*Base address for copying top section */
/* in header table block */
end_handle_rb; /*Base address for copying top section */
/* in reclaim block */
#ifdef ENABLE_EVENT_TESTS
#ifdef DISABLE_RECINPLC_FLASH_FAIL
EVT_EventElement tmp_event_value;
#endif
#endif
UINT16 unique_id = 0x0000; /*Invalid Id state */
UINT8 table_entry = 0xFF; /*Table entry for marking the status */
/* Determine Initial States of boolean variables */
block = Handle2Block(start_addr_in_block);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -