📄 davcghdr.c
字号:
FDI_Handle base_address_of_entry_array,
BOOLEAN restart)
{
ERR_CODE status = ERR_NONE;
/* Scan for a free entry */
for (*entry_index_ptr = 0;
*entry_index_ptr < CFGHDR_MaxConfigurationEntries;
(*entry_index_ptr)++)
{
/* Read State from flash */
FLASH_ReadBuffer(base_address_of_entry_array,
(MemBufferPtr)(cfg_entry_ptr),
CFGHDR_ConfigurationEntrySize);
status = UINT32_FixISF_PLR( &(cfg_entry_ptr->Status),
base_address_of_entry_array, restart);
if(status)
{
return (status);
}
/* if empty entry break loop */
if (CFGHDR_IsUnusedConfigurationEntry(*cfg_entry_ptr))
{
/* Found an empty state entry */
break;
}
else
{
if (CFGHDR_GetReclaimComplete(*cfg_entry_ptr) !=
CFGHDR_STATUS_ReclaimComplete)
{
/* Entry is still in use */
break;
}
else
{
/* Try Next entry */
base_address_of_entry_array += CFGHDR_ConfigurationEntrySize;
}
}
}
if (*entry_index_ptr == CFGHDR_MaxConfigurationEntries)
{
/* No entries available */
*entry_index_ptr = 0xFF;
}
return status;
}
/*########################################################################
### CFGHDR_AllocateConfigurationEntry
###
### DESCRIPTION:
### This function finds the next available reclaim state entry,
### and performs CfgHeader reclaim if no more are available.
### It is assumed that configuration header is always in the
### header table at the top of object space. This function also
### marks the allocated entry with the selected type of reclaim
### and the reclaim in progress bit.
###
### PARAMETERS:
### entry_index_ptr - On return, this is the index to the config.
### entry in use.
### cfg_entry_ptr - On return, this is the actual config. entry
### indicating the type and reclaim in progress.
### reclaim_table_type - On input, this is used to determine type
### of entry that should be allocated (reallocate
### or paragraph reclaim).
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE CFGHDR_AllocateConfigurationEntry(UINT8_PTR entry_index_ptr,
CFGHDR_ConfigurationEntryPtr cfg_entry_ptr,
UINT32 reclaim_table_type,
BOOLEAN restart)
{
ERR_CODE status;
FDI_Handle config_entry_handle;
/* Set handle to point to entry array in header table block */
config_entry_handle = ((FDI_LastObjectAddress - CFGHDR_ConfigHeaderSize) +
CFGHDR_EntryArrayOffset) + 1;
/* This will point return the next free entry. */
status = CFGHDR_ScanConfigurationEntry(entry_index_ptr, cfg_entry_ptr,
config_entry_handle, restart);
if(status)
{
return status;
}
if (*entry_index_ptr == 0xFF)
{
/* No More free entries, need to do a config reclaim */
status = CFGHDR_ConfigurationHeaderReclaim(FALSE);
if (status != ERR_NONE)
{
return(status);
}
*entry_index_ptr = 0;
CFGHDR_SetUnusedConfigurationEntry(*cfg_entry_ptr);
}
if (!CFGHDR_IsUnusedConfigurationEntry(*cfg_entry_ptr))
{
/* There is an entry in use. */
return(ERR_SYSTEM);
}
/* Write Entry to Reclaim In Progress with specified type */
CFGHDR_SetReclaimTableType((*cfg_entry_ptr), reclaim_table_type);
status = CFGHDR_WriteConfigurationEntry(*entry_index_ptr,
*cfg_entry_ptr);
if (status)
{
return(status);
}
CFGHDR_SetReclaimInProgress((*cfg_entry_ptr),
CFGHDR_STATUS_ReclaimInProgress);
status = CFGHDR_WriteConfigurationEntry(*entry_index_ptr,
*cfg_entry_ptr);
return(status);
}
/*########################################################################
### CFGHDR_WriteReclaimComplete
###
### DESCRIPTION:
### This function uses entry_index to select the
### configuration entry to mark Reclaim Complete; therefore
### indicating reclaim completion.
###
### PARAMETERS:
### entry_index - Selects the entry that should be marked to
### reclaim entry. This should be the entry
### returned during allocation of the config. entry.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE CFGHDR_WriteReclaimComplete(UINT8 entry_index)
{
CFGHDR_ConfigurationEntry cfg_entry;
ERR_CODE status;
CFGHDR_SetUnusedConfigurationEntry(cfg_entry);
CFGHDR_SetReclaimComplete(cfg_entry, CFGHDR_STATUS_ReclaimComplete);
status = CFGHDR_WriteConfigurationEntry(entry_index, cfg_entry);
return(status);
}
/*########################################################################
### CFGHDR_WriteTableOffset
###
### DESCRIPTION:
### This function writes the passed in offset to the selected
### config. entry and then marks the entry as having a valid offset.
###
### PARAMETERS:
### entry_index - Selects the entry that should be marked to
### reclaim entry. This should be the entry
### returned during allocation of the config. entry.
### offset - The offset to be stored into the configuration entry.
### This should be the offset from the top of paragraph
### space to the reclaim table header.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE CFGHDR_WriteTableOffset(UINT8 entry_index, UINT32 offset)
{
CFGHDR_ConfigurationEntry cfg_entry;
ERR_CODE status;
CFGHDR_SetUnusedConfigurationEntry(cfg_entry);
CFGHDR_SetOffset(cfg_entry, offset);
status = CFGHDR_WriteConfigurationEntry(entry_index, cfg_entry);
if (status)
{
return(status);
}
CFGHDR_SetOffsetStatus(cfg_entry, CFGHDR_STATUS_ValidOffset);
status = CFGHDR_WriteConfigurationEntry(entry_index, cfg_entry);
return(status);
}
/*########################################################################
### CFGHDR_WriteConfigurationEntry
###
### DESCRIPTION:
### This function writes the reclaim entry to the config header entries
### at the specified index. This actually writes the entry to flash.
### Before writing the entry, it authenticates the configuration header
### to ensure it is writing to config. header's object space.
###
### PARAMETERS:
### entry_index - Selects the entry that should be marked to
### reclaim entry. This should be the entry
### returned during allocation of the config. entry.
### reclaim_entry - The actual entry to be written to flash. This
### includes the status and offset.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE CFGHDR_WriteConfigurationEntry(UINT8 entry_index,
CFGHDR_ConfigurationEntry reclaim_entry)
{
ERR_CODE status;
FDI_Handle reclaim_entry_handle;
/* Calculate base handle of entries */
reclaim_entry_handle = ((FDI_LastObjectAddress - CFGHDR_ConfigHeaderSize) +
CFGHDR_EntryArrayOffset) + 1;
/* Increment handle to correct entry */
reclaim_entry_handle += CFGHDR_ConfigurationEntrySize * entry_index;
status = FLASH_WriteBuffer(reclaim_entry_handle,
(MemBufferPtr)&reclaim_entry,
CFGHDR_ConfigurationEntrySize);
return(status);
}
/*######################################################################*/
/*### CONFIGURATION HEADER RECLAIM ###*/
/*######################################################################*/
/*########################################################################
### CFGHDR_ConfigurationHeaderReclaim
###
### DESCRIPTION:
### This function will reclaim in place the first block,
### in order to make reclaim entries available.
###
### PARAMETERS:
### restart - Allows a configuration header reclaim to be restarted.
### based on the status of the header id of the config.
### header.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE CFGHDR_ConfigurationHeaderReclaim(BOOLEAN restart)
{
FDI_Handle rb_header_handle,
ht_header_handle,
unique_id_handle1,
unique_id_handle2;
ERR_CODE status = ERR_NONE;
UINT16 unique_id = 0,
ht_header_id, rb_header_id;
CFGHDR_RestartState restart_state = NoRestart;
CFGHDR_InitialState header_id_state;
HDR_SearchInfo cfg_entry_info;
#ifdef ENABLE_CONFIG_HDR_TESTS
EVT_TestEvent(EVT_CONFIG_HDR_Reclaim_Start);
#endif
/* Handles to configuration header in header table block and reclaim block */
ht_header_handle = ParagraphAlign(FDI_LastObjectAddress);
rb_header_handle = ParagraphAlign(FDI_ReclaimBlockAddress +
FDI_BlockSize - 1);
unique_id_handle1 = (FDI_LastObjectAddress - CFGHDR_ConfigHeaderSize) + 1;
unique_id_handle2 = unique_id_handle1 + CFGHDR_UniqueId2Offset;
if (restart)
{
/* ##Determine starting point, based on entries */
#ifdef ENABLE_CONFIG_HDR_TESTS
EVT_TestEvent(EVT_CONFIG_HDR_ReclaimRestart);
#endif
/* Authenticate header in header table block */
status = HDR_ReadFullHeader(ht_header_handle, &FDI_GlobalHeader,
restart);
if(status)
{
return status;
}
cfg_entry_info.HeaderPtr = &FDI_GlobalHeader;
if (HDR_AuthenticateHeader(&cfg_entry_info))
{
/* Found a good header */
if (FDI_GlobalHeader.ObjectType != FDI_HT_ConfigHeader)
{
/* Configuration Header was not found */
FDI_GlobalHeader.HeaderId = 0xFFFF;
}
}
ht_header_id = FDI_GlobalHeader.HeaderId;
/* Authenticate header in reclaim block */
status = HDR_ReadFullHeader(rb_header_handle, &FDI_GlobalHeader,
restart);
if(status)
{
return status;
}
if (HDR_AuthenticateHeader(&cfg_entry_info))
{
/* Found a good header */
if (FDI_GlobalHeader.ObjectType != FDI_HT_ConfigHeader)
{
/* Configuration Header was not found */
FDI_GlobalHeader.HeaderId = 0xFFFF;
}
}
rb_header_id = FDI_GlobalHeader.HeaderId;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -