📄 davrecip.c
字号:
if (block == Handle2Block(table_base_addr))
{
RAT_in_block = TRUE;
}
if (block == Handle2Block(RECINPLC_BottomSectionAddr))
{
in_bottom_block = TRUE;
}
if (block == Handle2Block(RECINPLC_TopSectionAddr))
{
in_top_block = TRUE;
}
if (!in_bottom_block && !in_top_block)
{
in_middle_block = TRUE;
}
if (in_bottom_block)
{
block_status_handle_ht = table_base_addr +
RECINPLC_OffsetToBottomStatus;
}
else
{
block_status_handle_ht = table_base_addr + RECINPLC_OffsetToTopStatus;
}
block_status_handle_rb = (block_status_handle_ht -
BlockAlign(block_status_handle_ht)) +
FDI_ReclaimBlockAddress;
/* Determine initial values of address variables */
start_handle_ht = BlockAlign(start_addr_in_block);
start_handle_rb = FDI_ReclaimBlockAddress;
top_data_size = RoundUp(end_addr_in_block, FDI_BlockSize) -
end_addr_in_block;
bottom_data_size = start_addr_in_block - start_handle_ht;
end_handle_ht = end_addr_in_block;
end_handle_rb = FDI_ReclaimBlockAddress +
FDI_BlockSize - top_data_size;
if (RAT_in_block)
{
/* Use RAT in RB */
block_status_handle = block_status_handle_rb;
}
else
{
/* Use RAT in Header block */
block_status_handle = block_status_handle_ht;
}
switch (rip_restart_state)
{
case RECINPLC_STEP_NoRestart:
case RECINPLC_STEP_MiddleSection:
case RECINPLC_STEP_TopSection_RecoveryState1:
case RECINPLC_STEP_BottomSection_RecoveryState1:
#ifdef ENABLE_REALLOCATE_TESTS
EVT_TestEvent(EVT_RECINPLC_ProcessBlockState1);
#endif
/* Process middle block if needed */
if (in_middle_block)
{
status = FLASH_EraseBlock(start_addr_in_block, TRUE);
return(status);
}
/* Check if any processing is needed */
if (FLASH_IsAreaErased(start_addr_in_block,
end_addr_in_block))
{
break;
}
#ifdef ENABLE_EVENT_TESTS
#ifdef DISABLE_RECINPLC_FLASH_FAIL
/* Get Current State of Random Powerloss */
tmp_event_value = EVT_EventList[EVT_FLASH_RandomFail];
/* Disable PowerLoss */
EVT_ClrEnabled(EVT_FLASH_RandomFail);
#endif
#endif
if (in_bottom_block)
{
/* Copy bottom data to reclaim block */
status = FLASH_CopyFlash(start_handle_ht,
start_handle_rb,
bottom_data_size);
if (status != ERR_NONE)
{
return(status);
}
}
if (in_top_block)
{
/* Copy top data to reclaim block */
status = FLASH_CopyFlash(end_handle_ht,
end_handle_rb,
top_data_size);
if (status != ERR_NONE)
{
return(status);
}
}
#ifdef ENABLE_EVENT_TESTS
#ifdef DISABLE_RECINPLC_FLASH_FAIL
/* Restore original event state */
EVT_EventList[EVT_FLASH_RandomFail] = tmp_event_value;
#endif
#endif
/* Mark Status at handle to EIP */
RECINPLC_SetReAllocateTableEntryStatus(table_entry,
RECINPLC_ST_EraseInProgress);
status = FLASH_WriteBuffer(block_status_handle,
(MemBufferPtr)&table_entry, sizeof(table_entry));
if (status)
{
return(status);
}
if (RAT_in_block)
{
/* Invalidate RAT in block */
status = FLASH_WriteBuffer(table_base_addr,
(MemBufferPtr)&unique_id, sizeof(UINT16));
if (status)
{
return(status);
}
}
/*lint -fallthrough*/
case RECINPLC_STEP_BottomSection_RecoveryState2:
case RECINPLC_STEP_TopSection_RecoveryState2:
#ifdef ENABLE_REALLOCATE_TESTS
EVT_TestEvent(EVT_RECINPLC_ProcessBlockState2);
#endif
status = FLASH_EraseBlock(start_addr_in_block, FALSE);
if (status)
{
return(status);
}
/* Mark Status at handle to EC */
RECINPLC_SetReAllocateTableEntryStatus(table_entry,
RECINPLC_ST_EraseComplete);
status = FLASH_WriteBuffer(block_status_handle,
(MemBufferPtr)&table_entry, sizeof(table_entry));
if (status)
{
return(status);
}
/*lint -fallthrough*/
case RECINPLC_STEP_BottomSection_RecoveryState3:
case RECINPLC_STEP_TopSection_RecoveryState3:
#ifdef ENABLE_REALLOCATE_TESTS
EVT_TestEvent(EVT_RECINPLC_ProcessBlockState3);
#endif
#ifdef ENABLE_EVENT_TESTS
#ifdef DISABLE_RECINPLC_FLASH_FAIL
/* Get Current State of Random Powerloss */
tmp_event_value = EVT_EventList[EVT_FLASH_RandomFail];
/* Disable PowerLoss */
EVT_ClrEnabled(EVT_FLASH_RandomFail);
#endif
#endif
if (in_bottom_block)
{
/* Copy bottom data back from reclaim block */
status = FLASH_CopyFlash(start_handle_rb,
start_handle_ht,
bottom_data_size);
if (status != ERR_NONE)
{
return(status);
}
}
if (in_top_block)
{
/* Copy top data back from reclaim block */
status = FLASH_CopyFlash(end_handle_rb,
end_handle_ht,
top_data_size);
if (status != ERR_NONE)
{
return(status);
}
}
#ifdef ENABLE_EVENT_TESTS
#ifdef DISABLE_RECINPLC_FLASH_FAIL
/* Restore original event state */
EVT_EventList[EVT_FLASH_RandomFail] = tmp_event_value;
#endif
#endif
/* Use RAT in block (may have been using one in rb) */
block_status_handle = block_status_handle_ht;
/* Mark Status at handle to CC */
RECINPLC_SetReAllocateTableEntryStatus(table_entry,
RECINPLC_ST_CopyComplete);
status = FLASH_WriteBuffer(block_status_handle,
(MemBufferPtr)&table_entry, sizeof(table_entry));
if (status)
{
return(status);
}
/*lint -fallthrough*/
case RECINPLC_STEP_BottomSection_RecoveryState4:
case RECINPLC_STEP_TopSection_RecoveryState4:
#ifdef ENABLE_REALLOCATE_TESTS
EVT_TestEvent(EVT_RECINPLC_ProcessBlockState4);
#endif
status = FLASH_EraseBlock(FDI_ReclaimBlockAddress, FALSE);
if (status)
{
return(status);
}
break;
case RECINPLC_STEP_DeallocateRAT:
case RECINPLC_STEP_MarkCfgEntryDone:
default:
return(ERR_SYSTEM);
}
/* Use RAT in block (may have been using one in rb) */
block_status_handle = block_status_handle_ht;
/* Mark Status at handle to Done */
RECINPLC_SetReAllocateTableEntryStatus(table_entry,
RECINPLC_ST_BlockDone);
status = FLASH_WriteBuffer(block_status_handle,
(MemBufferPtr)&table_entry, sizeof(table_entry));
return(status);
}
/*#################################################################
### RECINPLC_AuthenticateRAT
###
### DESCRIPTION:
### This function will authentic the RAT by verifying that the
### unique IDs are are valid. If a table is not found in the
### header table, it it will check in the reclaim block.
### If an authentic RAT is not found 1 will be returned,
### otherwise 0.
###
### PARAMETERS:
### table_address - Handle to the RAT base address.
### top_address_ptr - On return, this will contain the
### top address in the RAT.
### bottom_address_ptr - On return, this will contain the
### bottom address in the RAT.
### top_status - On return, this will contain the
### bottom status in the RAT.
### bottom_status - On return this will contain the
### top status in the RAT.
###
### RETURNS:
### 0 - Authentic RAT table found.
### 1 - Authentic RAT not found.
### ERR_CODE
###*/
ERR_CODE RECINPLC_AuthenticateRAT(FDI_Handle table_address,
UINT32_PTR top_address_ptr,
UINT32_PTR bottom_address_ptr,
UINT8_PTR top_status,
UINT8_PTR bottom_status,
BOOLEAN restart)
{
RECINPLC_ReAllocateTable table;
ERR_CODE status = ERR_NONE;
FLASH_ReadBuffer(table_address, (MemBufferPtr)&table, sizeof(table));
status = RECINPLC_EntryFixISF_PLR(&table, table_address, restart);
if(status)
{
return status;
}
if (!((table.UniqueId1 == 0xF0F0) && (table.UniqueId2 == 0xF0F0)))
{
/* Not an authentic table in ht block,*/
/* try the one that may be in the rb. */
table_address = (table_address - BlockAlign(table_address)) +
FDI_ReclaimBlockAddress;
FLASH_ReadBuffer(table_address, (MemBufferPtr)&table, sizeof(table));
status = RECINPLC_EntryFixISF_PLR(&table, table_address, restart);
if(status)
{
return status;
}
if (!((table.UniqueId1 == 0xF0F0) && (table.UniqueId2 == 0xF0F0)))
{
/* Not an authentic table in rb */
return (ERR_CODE)(1);
}
}
*top_address_ptr = table.TopAddress;
*bottom_address_ptr = table.BottomAddress;
*top_status = table.TopStatus;
*bottom_status = table.BottomStatus;
return ERR_NONE;
}
/*########################################################################
### RECINPLC_EntryFixISF_PLR
###
### DESCRIPTION:
### This function will fix the PLR bit's bits in the plr fields of the
### ReAllocate table entry from the indeterminate state of
### 01 or 10 to either 00 or 11.
###
### PARAMETERS:
### RAT struct pointer in RAM
### flash address where Init' may need to fix in flash if required
### size of the structure
### restart to know whether to fix in flash or not.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE RECINPLC_EntryFixISF_PLR(RECINPLC_ReAllocateTable *rat_table_ptr,
UINT32 flash_address,
BOOLEAN restart)
{
ERR_CODE status = ERR_NONE;
/*Bottom Status*/
if ((status = UINT8_FixISF_PLR( &(rat_table_ptr->BottomStatus),
flash_address + RECINPLC_OffsetToBottomStatus,
restart)) != ERR_NONE)
{
return status;
}
/*Top Status*/
if ((status = UINT8_FixISF_PLR( &(rat_table_ptr->TopStatus),
flash_address + RECINPLC_OffsetToTopStatus,
restart)) != ERR_NONE)
{
return status;
}
/*UniqueID 1*/
if ((status = UINT16_FixISF_PLR(&(rat_table_ptr->UniqueId1),
flash_address + RECINPLC_OffsetToUniqueId1,
restart)) != ERR_NONE)
{
return status;
}
/*Unique ID 2*/
status = UINT16_FixISF_PLR(&(rat_table_ptr->UniqueId2),
flash_address + RECINPLC_OffsetToUniqueId2,
restart);
return status;
}
#endif /* DIRECT_ACCESS_VOLUME */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -