📄 davcfgtbl.c
字号:
### state field.
###
### PARAMETERS:
### aPtr - Pointer to the paragraph entry
### aPtr - Handle to the progress state field
###
### RETURNS:
### The recovered progress status
###*/
/* E5.5.969 Start */
UINT16 CFGTBL_GetRecoveredCtProgressState( CFGTBL_EntryPtr aPtr,
FDI_Handle aHandle,
ERR_CODE * statusPtr)
{
/* Do a Quasi that will read and write */
/* We assume this will work */
/* E5.5.970 Start */
*statusPtr = UTIL_UINT16_FixISF_PLR((UINT16*)&aPtr->ProgressState, aHandle, TRUE);
/* E5.5.970 End */
/* Read the status bit */
return CFGTBL_GetCtProgressState(aPtr);
}
/* E5.5.969 End */
/*########################################################################
### CFGTBL_CalcPageReclaimHandle
###
### DESCRIPTION:
### This function calculates the page entry handle with respect to the
### top of the cfgtbl.
###
### PARAMETERS:
### aTableHandlePtr - Handle for the top of the cfgtbl.
###
### RETURNS:
### When this function passes with no errors a value of 0 is
### returned otherwise, it returns a status of type ERR_CODE.
###*/
FDI_Handle CFGTBL_CalcPageReclaimHandle(FDI_Handle* aTableHandlePtr)
{
CFGTBL_ObjectTablePtr tablePtr = 0; /* Zero, is used to compute offset */
UINT32 offset = (UINT32)&tablePtr->PgReclaimStatus - (UINT32)tablePtr;
return (UINT32)*aTableHandlePtr + offset;
}
/*=================== Paragraph ====================*/
/*########################################################################
### CFGTBL_ModifyPaProgressState
###
### DESCRIPTION:
### This function writes the paragraph progress state to flash.
### It first verifies that the state transistion is correct.
###
### PARAMETERS:
### aNewState - The transision state
###
### 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 CFGTBL_ModifyPaProgressState(UINT16 aNewState)
{
ERR_CODE status;
CFGTBL_PaReclaimEntry cfgEntry;
FDI_Handle tableHandle;
FDI_Handle entryHandle;
UINT8 offset;
/*
## We determine what table to read by looking at the new state
## There are some states we can transistion from, however, never
## transistion to.
*/
switch(aNewState)
{
case CFGTBL_PaProgressState_EraseRBInProgress:
case CFGTBL_PaProgressState_ReclaimComplete:
case CFGTBL_PaProgressState_Normal:
case CFGTBL_PaProgressState_ReclaimInProgress:
case CFGTBL_PaProgressState_RelocateInProgress:
case CFGTBL_PaProgressState_CopyOutComplete:
tableHandle = FDI_ParaSpaceAddressBottom;
break;
case CFGTBL_PaProgressState_ErasePSInProgress:
case CFGTBL_PaProgressState_CopyBackInProgress:
tableHandle = FDI_ReclaimBlockAddressBottom;
break;
default:
return ERR_STATE;
}
/* Get the handle to the paragraph reclaim entry */
entryHandle = CFGTBL_CalcPaReclaimHandle(&tableHandle);
/* Read the current entry */
status = FLASH_ReadBuffer(entryHandle, (UINT8*)&cfgEntry, sizeof(CFGTBL_PaReclaimEntry));
if(status != ERR_NONE)
{
return status;
}
/* Insure what we read was valid */
if(CFGTBL_IsValidPaEntry(&cfgEntry) == TRUE)
{
/* It is valid to changes to the same state (PLR) */
if(CFGTBL_GetPaProgressState(&cfgEntry) == aNewState)
{
return ERR_NONE;
}
/* Validate the state change */
switch(CFGTBL_GetPaProgressState(&cfgEntry))
{
case CFGTBL_PaProgressState_PreliminaryCopy:
if(aNewState == CFGTBL_PaProgressState_EraseRBInProgress)
break;
return ERR_STATE;
case CFGTBL_PaProgressState_EraseRBInProgress:
if(aNewState == CFGTBL_PaProgressState_ReclaimComplete)
break;
return ERR_STATE;
case CFGTBL_PaProgressState_ReclaimComplete:
if(aNewState == CFGTBL_PaProgressState_Normal)
break;
return ERR_STATE;
case CFGTBL_PaProgressState_Normal:
if(aNewState == CFGTBL_PaProgressState_ReclaimInProgress)
break;
else if(aNewState == CFGTBL_PaProgressState_RelocateInProgress)
break;
return ERR_STATE;
case CFGTBL_PaProgressState_ReclaimInProgress:
if(aNewState == CFGTBL_PaProgressState_CopyOutComplete)
break;
return ERR_STATE;
case CFGTBL_PaProgressState_RelocateInProgress:
if(aNewState == CFGTBL_PaProgressState_CopyOutComplete)
break;
return ERR_STATE;
/* For reclaim only */
case CFGTBL_PaProgressState_ErasePSInProgress:
if(aNewState == CFGTBL_PaProgressState_CopyBackInProgress)
break;
return ERR_STATE;
default:
return ERR_STATE;
}
}
else
{
return ERR_STATE;
}
/* Write the status */
CFGTBL_SetPaProgressState(&cfgEntry, aNewState);
offset = (UINT32)(&cfgEntry.ProgressState) - (UINT32)(&cfgEntry);
status = FLASH_WriteBuffer(entryHandle+offset, (UINT8*)((UINT32)&cfgEntry+offset), sizeof(cfgEntry.ProgressState));
if(status != ERR_NONE)
{
return status;
}
return status;
}
/*########################################################################
### CFGTBL_WriteTableEntryPage
###
### DESCRIPTION:
### This function writes the paragraph entry portion of the
### cfgtbl into flash.
###
### PARAMETERS:
### aHandle - Handle to the page entry
### aTableCopy - Flag to note if the write is for a entry copy.
###
### 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 CFGTBL_WriteTableEntryPara(FDI_Handle aHandle, BOOLEAN aTableCopy)
{
ERR_CODE status;
UINT32 offset = 0;
CFGTBL_PaReclaimEntry entryPa;
/* Insure that this was not tampered with */
CFGTBL_SetPaUniqueId1(&entryPa, 0xFFFF);
/* Set the first unique Id*/
CFGTBL_SetPaUniqueId1(&entryPa, CFGTBL_UniqueId1);
offset = (UINT32)(&entryPa.UniqueId1) - (UINT32)(&entryPa);
status = FLASH_WriteBuffer(aHandle+offset, (UINT8*)((UINT32)&entryPa+offset), sizeof(entryPa.UniqueId1));
if(status != ERR_NONE)
{
return status;
}
if(aTableCopy == FALSE)
{
CFGTBL_SetPaProgressState(&entryPa, CFGTBL_PaProgressState_Normal);
}
else
{
CFGTBL_SetPaProgressState(&entryPa, CFGTBL_PaProgressState_ErasePSInProgress); /* CFGTBL_PaProgressState_CopyBackInProgress */
}
offset = (UINT32)(&entryPa.ProgressState) - (UINT32)(&entryPa);
status = FLASH_WriteBuffer(aHandle+offset, (UINT8*)((UINT32)&entryPa+offset), sizeof(entryPa.ProgressState));
if(status != ERR_NONE)
{
return status;
}
/* Insure that this was not tampered with */
CFGTBL_SetPaUniqueId2(&entryPa, 0xFFFF);
/* Set the first unique Id*/
CFGTBL_SetPaUniqueId2(&entryPa, CFGTBL_UniqueId2);
offset = (UINT32)(&entryPa.UniqueId2) - (UINT32)(&entryPa);
status = FLASH_WriteBuffer(aHandle+offset, (UINT8*)((UINT32)&entryPa+offset), sizeof(entryPa.UniqueId2));
if(status != ERR_NONE)
{
return status;
}
return ERR_NONE;
}
/*#################################################################
### CFGTBL_GetPaProgressState
###
### DESCRIPTION:
### This function will extract the paragraph progress state
### field.
###
### PARAMETERS:
### aPtr - Pointer to the paragraph entry
###
### RETURNS:
### The progress status
###*/
UINT16 CFGTBL_GetPaProgressState(CFGTBL_PaReclaimEntryPtr aPtr)
{
return aPtr->ProgressState;
}
/*#################################################################
### CFGTBL_SetPaProgressState
###
### DESCRIPTION:
### This function will set the paragraph progress state
### field.
###
### PARAMETERS:
### aPtr - Pointer to the paragraph entry
### aWord - New value of the progress state
###
### RETURNS:
### None
###*/
void CFGTBL_SetPaProgressState(CFGTBL_PaReclaimEntryPtr aPtr, UINT16 aWord)
{
aPtr->ProgressState = aWord & CFGTBL_MASK_PaProgressState;
}
/*#################################################################
### CFGTBL_GetRecoveredPaProgressState
###
### DESCRIPTION:
### This function will extract the paragraph progress state
### right after the recovery is performed on the progress
### state field.
###
### PARAMETERS:
### aPtr - Pointer to the paragraph entry
### aPtr - Handle to the progress state field
###
### RETURNS:
### The recovered progress status
###*/
/* E5.5.969 Start */
UINT16 CFGTBL_GetRecoveredPaProgressState( CFGTBL_PaReclaimEntryPtr aPtr,
FDI_Handle aHandle,
ERR_CODE * statusPtr )
{
/* Do a Quasi that will read and write */
/* We assume this will work */
*statusPtr = UTIL_UINT16_FixISF_PLR((UINT16*)&aPtr->ProgressState, aHandle, TRUE);
/* Read the status bit */
return CFGTBL_GetPaProgressState(aPtr);
}
/* E5.5.969 End */
/*#################################################################
### CFGTBL_GetPaUniqueId1
###
### DESCRIPTION:
### This function will extract the first unique id from the
### paragraph entry in the cfgtable.
###
### PARAMETERS:
### aPtr - Pointer to the paragraph entry
###
### RETURNS:
### The first unique id
###*/
UINT16 CFGTBL_GetPaUniqueId1(CFGTBL_PaReclaimEntryPtr aPtr)
{
return aPtr->UniqueId1;
}
/*#################################################################
### RATTBL_SetUniqueId1
###
### DESCRIPTION:
### This function will set the first unique id from the
### paragraph entry in the cfgtable.
###
### PARAMETERS:
### aPtr - Pointer to the paragraph entry
### aWord - The value of the unique id
###
### RETURNS:
### None.
###*/
void CFGTBL_SetPaUniqueId1(CFGTBL_PaReclaimEntryPtr aPtr, UINT16 aWord)
{
aPtr->UniqueId1 = aWord;
}
/*#################################################################
### CFGTBL_GetPaUniqueId2
###
### DESCRIPTION:
### This function will extract the second unique id from the
### paragraph entry in the cfgtable.
###
### PARAMETERS:
### aPtr - Pointer to the paragraph entry
###
### RETURNS:
### The second unique id
###*/
UINT16 CFGTBL_GetPaUniqueId2(CFGTBL_PaReclaimEntryPtr aPtr)
{
return aPtr->UniqueId2;
}
/*#################################################################
### CFGTBL_SetPaUniqueId2
###
### DESCRIPTION:
### This function will set the second unique id from the
### paragraph entry in the cfgtable.
###
### PARAMETERS:
### aPtr - Pointer to the paragraph entry
### aWord - The value of the unique id
###
### RETURNS:
### None.
###*/
void CFGTBL_SetPaUniqueId2(CFGTBL_PaReclaimEntry* aPtr, UINT16 aWord)
{
aPtr->UniqueId2 = aWord;
}
/*#################################################################
### CFGTBL_CalcPaReclaimHandle
###
### DESCRIPTION:
### This function will computes the handle to the paragraph
### entry into the cfgtbl with repsect to the handle to the
### top of the cfgtbl.
###
### PARAMETERS:
### aPtr - Pointer to the top of the cfgtbl
###
### RETURNS:
### A handle
###*/
FDI_Handle CFGTBL_CalcPaReclaimHandle(FDI_Handle* aTableHandlePtr)
{
CFGTBL_ObjectTablePtr tablePtr = 0; /* Zero, is used to compute offset */
UINT32 offset = (UINT32)&tablePtr->PaReclaimStatus;
return (UINT32)*aTableHandlePtr + offset;
}
/*=================== Utilities ====================*/
/*########################################################################
### CFGTBL_IsValidPgEntry
###
### DESCRIPTION:
### This function validates a cfgtable page entry by searching
### for the unique identifiers that are in a predescribed location.
###
### PARAMETERS:
### aPtr - A pointer to the cfgtbl page entry to validate
###
### RETURNS:
### When this function passes with no errors a value of 0 is
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -