📄 davlib.c
字号:
/* Copyright (c) 1995-2004 Intel Corporation */
/* Intel Confidential */
/* ###########################################################################
### DAV - Direct Access Volume Enhancement to FDI
###
### Module: dav_lib.c - DAV Interface Function: Library Module
###
### $Workfile: davlib.c $
### $Revision: 7 $
### $NoKeywords: $
########################################################################### */
/*
*****************************************************************
* NOTICE OF LICENSE AGREEMENT
*
* This code is provided by Intel Corp., and the use is governed
* under the terms of a license agreement. See license agreement
* for complete terms of license.
*
* YOU MAY ONLY USE THE SOFTWARE WITH INTEL FLASH PRODUCTS. YOUR
* USE OF THE SOFTWARE WITH ANY OTHER FLASH PRODUCTS IS EXPRESSLY
* PROHIBITED UNLESS AND UNTIL YOU APPLY FOR, AND ARE GRANTED IN
* INTEL'S SOLE DISCRETION, A SEPARATE WRITTEN SOFTWARE LICENSE
* FROM INTEL LICENSING ANY SUCH USE.
*****************************************************************
*/
/*### Include Files
#########################*/
#include "DavLib.h"
#if (DIRECT_ACCESS_VOLUME == TRUE)
/*### Local Declarations
#########################*/
/*### Global Declarations
#########################*/
/*### Local Functions
#########################*/
/*### Global Functions
#########################*/
/*##################################################################
### UTIL_CopyVariable
###
### DESCRIPTION:
### This function copies the contents of aSrcPtr to aDestPtr;
### the length of the copy is determined by aSizeInBytes.
###
### PARAMETERS:
### aSrcPtr - IN: source data to be copied.
### aDestPtr - IN/OUT: destination for copied data.
### aSizeInBytes - IN: amount to copy.
###
### RETURNS:
### None.
###*/
void UTIL_CopyVariable(UINT8* aSrcPtr, UINT8* aDestPtr, UINT32 aSizeInBytes)
{
UINT32 i;
for(i=1; i<=aSizeInBytes; i++)
{
/* Do the copy */
*aDestPtr = *aSrcPtr;
aSrcPtr++;
aDestPtr++;
}
}
/*##################################################################
### UTIL_ClearVariable
###
### DESCRIPTION:
### This function sets the contents of aBytePtr with aValue;
### the length of the set is determined by aSizeInBytes.
###
### PARAMETERS:
### aBytePtr - IN/OUT: ptr to data to be set (cleared).
### aSizeInBytes - IN: amount to set.
### aValue - IN: value to set with.
###
### RETURNS:
### None.
###*/
void UTIL_ClearVariable(UINT8* aBytePtr, UINT32 aSizeInBytes, UINT8 aValue)
{
UINT32 index;
for(index=1; index<=aSizeInBytes; index++)
{
*aBytePtr = aValue;
aBytePtr = aBytePtr + 1;
}
}
/*##################################################################
### UTIL_CalcOffsetOfBlocksBoundary
###
### DESCRIPTION:
### This function sets the contents of aBytePtr with aValue;
### the length of the set is determined by aSizeInBytes.
###
### PARAMETERS:
### aBlockNumber - IN: block for which offset is needed.
### aBlockBoundary - IN: top or bottom.
###
### RETURNS:
### Offset (in pages) referenced from bottom of page space.
###*/
/*Fix Start:SCR964 */
UINT32 UTIL_CalcOffsetOfBlocksBoundary(UINT16 aBlockNumber, EnTopOrBottomBoundary aBlockBoundary)
/*Fix End:SCR964 */
{
UINT32 Offset = 0;
switch(aBlockBoundary)
{
case enTopBoundary:
Offset = (aBlockNumber * FDI_BlockSizeInPages) + (FDI_BlockSizeInPages);
break;
case enBottomBoundary:
Offset = aBlockNumber * FDI_BlockSizeInPages;
break;
}
return Offset;
}
/*##################################################################
### UTIL_CalcBlockNumberForOffset
###
### DESCRIPTION:
### Given an offset (in pages from the bottom of page space),
### calculate the block number. Block numbers
### start at 0, at the bottom of page space.
###
### PARAMETERS:
### aOffsetInPages - IN: offset from bottom of page space.
###
### RETURNS:
### Block number (0-based from bottom of page space).
###*/
/*Fix Start:SCR964 */
UINT16 UTIL_CalcBlockNumberForOffset (UINT32 aOffsetInPages)
{
UINT16 BlockNumber;
/* For scheme starting with block 0, divide address by block size and round down. */
BlockNumber = (UINT16)(aOffsetInPages/FDI_BlockSizeInPages);
/*Fix End:SCR964 */
return BlockNumber;
}
/*##################################################################
### UTIL_CalcHandleOfBlockBottomBoundary
###
### DESCRIPTION:
### Return the handle to the bottom boundary of a block given
### the block number. Block numbers are 0-based starting from
### the bottom of page space.
###
### PARAMETERS:
### aBlockNumber - IN: block for which bottom boundary
### handle is needed.
###
### RETURNS:
### Handle to bottom boundary of block.
###*/
/*Fix Start:SCR964 */
FDI_Handle UTIL_CalcHandleOfBlockBottomBoundary(UINT16 aBlockNumber)
{
/*Fix End:SCR964 */
return (UTIL_CalcOffsetOfBlocksBoundary(aBlockNumber, enBottomBoundary) * FDI_PageSize)
+ FDI_PageSpaceAddressBottom;
}
/*##################################################################
### UTIL_CalcHandleOfBlockTopBoundary
###
### DESCRIPTION:
### Return the handle to the top boundary of a block given
### the block number. Block numbers are 0-based starting from
### the bottom of page space.
###
### PARAMETERS:
### aBlockNumber - IN: block for which top boundary
### handle is needed.
###
### RETURNS:
### Handle to top boundary of block.
###*/
/*Fix Start:SCR964 */
FDI_Handle UTIL_CalcHandleOfBlockTopBoundary(UINT16 aBlockNumber)
{
/*Fix End:SCR964 */
return (UTIL_CalcOffsetOfBlocksBoundary(aBlockNumber, enTopBoundary) * FDI_PageSize)
+ FDI_PageSpaceAddressBottom - 1;
}
/*##################################################################
### UTIL_Dav_Format
###
### DESCRIPTION:
### This call formats the dav memory. It is plr aware.
###
### PARAMETERS:
### None
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE UTIL_Dav_Format()
{
ERR_CODE status;
/*Fix Start:SCR964 */
UINT16 b;
/*Fix End:SCR964 */
/* Erase the reclaim block just incase there is something there */
/* That may affect power-loss */
status = FLASH_EraseBlock(FDI_ReclaimBlockAddressBottom, TRUE);
if(status != ERR_NONE)
{
return status;
}
/* Erase the remaining dav blocks. This loop insure that the */
/* paragraph space is last just incase there is a corrupt header */
/* that needs to be cleaned up last */
for(b=0; b<(DAV_BLOCKCOUNT-1); b++)
{
status = FLASH_EraseBlock(UTIL_CalcHandleOfBlockBottomBoundary(b), TRUE);
if(status != ERR_NONE)
{
return status;
}
} /* for */
return status;
}
/*########################################################################
### UTIL_UINT16_FixISF_PLR
###
### DESCRIPTION:
### This function will fix the PLR bit's bits in the plr fields of the
### object header from the indeterminate state of 01 or 10 to
### either 00 or 11. for an 16 bit value
###
### PARAMETERS:
### 16 bit pointer to status in RAM
### flash address where Init' may need to be fixed in flash if required
### restart to know wheather to fix in flash or not.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE UTIL_UINT16_FixISF_PLR(UINT16* uint16_ptr,
UINT32 flash_address,
BOOLEAN restart)
{
UINT16 temp_state;
ERR_CODE status = ERR_NONE;
if((temp_state = UTIL_GetUINT16QuasiState(*uint16_ptr)) != 0)
{
/*Fix bits to 00 or 11 depending on restart*/
if(restart)
{
/*fix quasi bits to zero*/
*uint16_ptr = UTIL_FixUINT16QuasiStateTo00(temp_state, *uint16_ptr);
/*Write the state back to flash*/
status = FLASH_WriteBuffer(flash_address, (UINT8*)uint16_ptr,
sizeof(UINT16));
}
else
{
/*fix quasi bits in RAM to 11 of the read is 10, fix it to 00 if the read is a 01*/
if(temp_state & *uint16_ptr)
{ /*this is the 10 situation*/
*uint16_ptr = UTIL_FixUINT16QuasiStateTo11(temp_state, *uint16_ptr);
}
else
{
/*this is the 01 situation*/
*uint16_ptr = UTIL_FixUINT16QuasiStateTo00(temp_state, *uint16_ptr);
}
}
}
return (status);
}
/*########################################################################
### UTIL_UINT32_FixISF_PLR
###
### DESCRIPTION:
### This function will fix the PLR bit's bits in the plr fields of the
### object header from the indeterminate state of 01 or 10 to
### either 00 or 11. for an 32 bit value
###
### PARAMETERS:
### 32 bit pointer to status in RAM
### flash address where Init' may need to be fixed in flash if required
### restart to know wheather to fix in flash or not.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE UTIL_UINT32_FixISF_PLR(UINT32 *uint32_ptr,
UINT32 flash_address,
BOOLEAN restart)
{
UINT32 temp_state;
ERR_CODE status = ERR_NONE;
if((temp_state = UTIL_GetUINT32QuasiState(*uint32_ptr)) != 0)
{
/*Fix bits to 00 or 11 depending on restart*/
if(restart)
{
/*fix quasi bits to zero*/
*uint32_ptr = UTIL_FixUINT32QuasiStateTo00(temp_state, *uint32_ptr);
/*Write the state back to flash*/
status = FLASH_WriteBuffer(flash_address, (UINT8*)uint32_ptr,
sizeof(UINT32));
}
else
{
/*fix quasi bits in RAM to 11 of the read is 10, fix it to 00 if the read is a 01*/
if(temp_state & *uint32_ptr)
{ /*this is the 10 situation*/
*uint32_ptr = UTIL_FixUINT32QuasiStateTo11(temp_state, *uint32_ptr);
}
else
{
/*this is the 01 situation*/
*uint32_ptr = UTIL_FixUINT32QuasiStateTo00(temp_state, *uint32_ptr);
}
}
}
return (status);
}
/*########################################################################
### UTIL_UINT16_HeaderFixISF_PLR
###
### DESCRIPTION:
### This function will fix the PLR bit's bits in the plr fields of the
### fixed header from the indeterminate state of 01 or 10 to
### either 00 or 11. for an 10-bit value within a 16-bit value
###
### PARAMETERS:
### 16 bit pointer to status in RAM
### flash address where Init' may need to be fixed in flash if required
### restart to know wheather to fix in flash or not.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE UTIL_UINT16_HeaderFixISF_PLR(UINT16 *uint16_ptr,
UINT32 flash_address,
BOOLEAN restart)
{
UINT16 temp_state;
ERR_CODE status = ERR_NONE;
if((temp_state = UTIL_GetUINT16HeaderQuasiState(*uint16_ptr)) != 0)
{
/*Fix bits to 00 or 11 depending on restart*/
if(restart)
{
/*fix quasi bits to zero*/
*uint16_ptr = UTIL_FixUINT16QuasiStateTo00(temp_state, *uint16_ptr);
/*Write the state back to flash*/
status = FLASH_WriteBuffer(flash_address, (UINT8*)uint16_ptr,
sizeof(UINT16));
}
else
{
/*fix quasi bits in RAM to 11 of the read is 10, fix it to 00 if the read is a 01*/
if(temp_state & *uint16_ptr)
{ /*this is the 10 situation*/
*uint16_ptr = UTIL_FixUINT16QuasiStateTo11(temp_state, *uint16_ptr);
}
else
{
/*this is the 01 situation*/
*uint16_ptr = UTIL_FixUINT16QuasiStateTo00(temp_state, *uint16_ptr);
}
}
}
return (status);
}
#endif /* DIRECT_ACCESS_VOLUME */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -