📄 davotttbl.c
字号:
/* Copyright (c) 1995-2004 Intel Corporation */
/* Intel Confidential */
/* ###########################################################################
### OBJECT TRACKING TABLE (OTT)
###
### Module: DavOttTbl.c - OTT table module
###
### $Workfile: DavOttTbl.c $
### $Revision: 13 $
### $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)
#include "DavOttTbl.h"
#include "DavMem.h"
/*### Local Declarations
#########################*/
/*### Global Declarations
#########################*/
/*### Local Functions
#########################*/
/*### Global Functions
#########################*/
/*########################################################################
### OTTTBL_AllocateFlash
###
### DESCRIPTION:
### This function create a OTT table in paragraph space. It creates
### a fixed header, writes the table (leader and entries), and
### validates the fixed header.
###
### PARAMETERS:
### aObjHandle - Handle to where the table is to be written
### aEntryArrayPtr - Pointer to the first entry (in the sram array)
### aArraySize - Number of entries in the sram array
### aReclaimType - Type of reclaim being performed
### aEndBlock - Ending work block (there may not be any entries in the sram ottlist for this block)
### aStartBlock - Starting work block
###
### 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 OTTTBL_AllocateFlash(FDI_Handle aObjHandle, OTTTBL_EntryPtr aEntryArrayPtr, UINT16 aArraySize, UINT8 aReclaimType, UINT16 aEndBlock, UINT16 aStartBlock)
{
ERR_CODE status;
HDR_FixedHeader fixHeader;
FDI_Handle hdrHandle = 0;
OTTTBL_Leader objLeader;
FDI_Handle entryHandle;
UINT16 i;
/* The CT table has already validated available space */
/* Create the table fixed header */
FHDR_SetSize(&fixHeader, OTTTBL_CalcTableSize(aArraySize));
FHDR_SetType(&fixHeader, FDI_HT_ObjTrkTable);
FHDR_SetHeaderIndexOffset(&fixHeader, FHDR_CalcObjectOffset(aObjHandle));
status = HDR_CreateNextFixedHeaderEntry(&hdrHandle, &fixHeader);
if(status != ERR_NONE)
{
return status;
}
/* Read in the header just written to flash */
status = FHDR_ReadFixedHeader(hdrHandle, &fixHeader, FALSE);
if(status == ERR_NONE)
{
/* The header must be Valid and WriteInProgress */
if(FHDR_GetHeaderStatus(&fixHeader) == HDR_HEADER_VALID)
{
if(FHDR_GetAllocationStatus(&fixHeader) == HDR_ALLOC_WRITE_IN_PROGRESS)
{
if(FHDR_GetType(&fixHeader) == FDI_HT_ObjTrkTable)
{
UTIL_ClearVariable((UINT8*)&objLeader, sizeof(OTTTBL_Leader), 0xFF);
entryHandle = FHDR_CalcObjectHandle(&fixHeader);
entryHandle = entryHandle + sizeof(OTTTBL_Leader);
/* Write each row in the array */
for(i=1; i<=aArraySize; i++)
{
/* Write the entry */
status = FLASH_WriteBuffer(entryHandle, (UINT8*)aEntryArrayPtr, sizeof(OTTTBL_Entry));
if(status != ERR_NONE)
{
return status;
}
aEntryArrayPtr = aEntryArrayPtr + 1;
entryHandle = entryHandle + sizeof(OTTTBL_Entry);
} /* for */
entryHandle = FHDR_CalcObjectHandle(&fixHeader);
OTTTBL_SetNumRows(&objLeader, (UINT8)aArraySize);
OTTTBL_SetReclaimType(&objLeader, aReclaimType);
OTTTBL_SetUniqueId1(&objLeader, OTTTBL_UniqueId1);
OTTTBL_SetUniqueId2(&objLeader, OTTTBL_UniqueId2);
OTTTBL_SetEndWorkBlockNumber(&objLeader, aEndBlock);
OTTTBL_SetStartWorkBlockNumber (&objLeader, aStartBlock);
status = FLASH_WriteBuffer(entryHandle, (UINT8*)&objLeader, sizeof(OTTTBL_Leader));
if(status != ERR_NONE)
{
return status;
}
}
}
}
}
/* E5.5.970 Start */
else
{
return status;
}
/* E5.5.70 End */
/* Change the state of the header */
status = FHDR_ValidateHeaderInFlash(hdrHandle, &fixHeader);
if(status != ERR_NONE)
{
return status;
}
return status;
}
/* ======================== Table Functions =================================*/
/*#################################################################
### OTTTBL_GetEndWorkBlockNumber
###
### DESCRIPTION:
### This function will extract the ending work block range
### for the ott table. It is possible that there is no ott
### entry for the ending work block number.
###
### PARAMETERS:
### aPtr - Pointer to the ott leader
###
### RETURNS:
### The ending work block range
###*/
/*Fix Start:SCR964 */
UINT16 OTTTBL_GetEndWorkBlockNumber(OTTTBL_LeaderPtr aPtr)
{
return aPtr->EndBlockNumber;
}
/*Fix End:SCR964 */
/*#################################################################
### OTTTBL_SetEndWorkBlockNumber
###
### DESCRIPTION:
### This function will set the ending work block range
### in the leader for the ott table.
###
### PARAMETERS:
### aPtr - Pointer to the ott leader
### aByte - The value of the starting work block range
###
### RETURNS:
### None
###*/
/*Fix Start:SCR964 */
void OTTTBL_SetEndWorkBlockNumber(OTTTBL_LeaderPtr aPtr, UINT16 aByte)
{
aPtr->EndBlockNumber = aByte & WORDMAX;
}
/*Fix End:SCR964 */
/*#################################################################
### OTTTBL_GetStartWorkBlockNumber
###
### DESCRIPTION:
### This function will extract the starting work block range
### for the ott table.
###
### PARAMETERS:
### aPtr - Pointer to the ott leader
###
### RETURNS:
### The starting work block range
###*/
/*Fix Start:SCR964 */
UINT16 OTTTBL_GetStartWorkBlockNumber(OTTTBL_LeaderPtr aPtr)
{
return aPtr->StartBlockNumber & WORDMAX;
}
/*Fix End:SCR964 */
/*#################################################################
### OTTTBL_SetStartWorkBlockNumber
###
### DESCRIPTION:
### This function will set the starting work block range
### in the leader for the ott table.
###
### PARAMETERS:
### aPtr - Pointer to the ott leader
### aByte - The value of the starting work block range
###
### RETURNS:
### None
###*/
/*Fix Start:SCR964 */
void OTTTBL_SetStartWorkBlockNumber(OTTTBL_LeaderPtr aPtr, UINT16 aByte)
{
aPtr->StartBlockNumber = aByte & WORDMAX;
}
/*Fix End:SCR964 */
/*#################################################################
### OTTTBL_GetNumRows
###
### DESCRIPTION:
### This function will extract the number of rows/entries in the
### ott table.
###
### PARAMETERS:
### aPtr - Pointer to the ott leader
###
### RETURNS:
### The number of rows
###*/
/*Fix Start:SCR964 */
UINT16 OTTTBL_GetNumRows(OTTTBL_LeaderPtr aPtr)
{
return aPtr->NumRows & WORDMAX;
}
/*Fix End:SCR964 */
/*#################################################################
### OTTTBL_SetNumRows
###
### DESCRIPTION:
### This function will set the number of rows the ott table
### contains. It is not unusual to have zero as a value.
###
### PARAMETERS:
### aPtr - Pointer to the ott leader
### aByte - The value of the number of rows
###
### RETURNS:
### None
###*/
/*Fix Start:SCR964 */
void OTTTBL_SetNumRows(OTTTBL_LeaderPtr aPtr, UINT16 aWord)
{
aPtr->NumRows = aWord & WORDMAX;
}
/*Fix End:SCR964 */
/*#################################################################
### OTTTBL_GetReclaimType
###
### DESCRIPTION:
### This function will extract the page reclaim type specified
### by the user.
###
### PARAMETERS:
### aPtr - Pointer to the ott leader
###
### RETURNS:
### The page reclaim type (full page reclaim, partial page
### reclaim, reallocate reclaim, etc.)
###*/
UINT8 OTTTBL_GetReclaimType(OTTTBL_LeaderPtr aPtr)
{
return aPtr->ReclaimType & BYTEMAX;
}
/*#################################################################
### OTTTBL_SetReclaimType
###
### DESCRIPTION:
### This function will set the reclaim type for ott table.
###
### PARAMETERS:
### aPtr - Pointer to the ott leader
### aByte - The value of the reclaim type
###
### RETURNS:
### None
###*/
void OTTTBL_SetReclaimType(OTTTBL_LeaderPtr aPtr, UINT8 aByte)
{
aPtr->ReclaimType = aByte & BYTEMAX;
}
/*#################################################################
### OTTTBL_GetUniqueId1
###
### DESCRIPTION:
### This function will extract the first unique id from the ott
### table leader
###
### PARAMETERS:
### aPtr - Pointer to the ott leader
###
### RETURNS:
### The first unique id
###*/
UINT16 OTTTBL_GetUniqueId1(OTTTBL_LeaderPtr aPtr)
{
return aPtr->UniqueId1;
}
/*#################################################################
### OTTTBL_SetUniqueId1
###
### DESCRIPTION:
### This function will set the first unique id from the
### ott table leader.
###
### PARAMETERS:
### aPtr - Pointer to the ott leader
### aWord - The value of the unique id
###
### RETURNS:
### None.
###*/
void OTTTBL_SetUniqueId1(OTTTBL_LeaderPtr aPtr, UINT16 aWord)
{
aPtr->UniqueId1 = aWord & WORDMAX;
}
/*#################################################################
### OTTTBL_GetUniqueId2
###
### DESCRIPTION:
### This function will extract the second unique id from the ott
### table leader
###
### PARAMETERS:
### aPtr - Pointer to the ott leader
###
### RETURNS:
### The first unique id
###*/
UINT16 OTTTBL_GetUniqueId2(OTTTBL_LeaderPtr aPtr)
{
return aPtr->UniqueId2;
}
/*#################################################################
### OTTTBL_SetUniqueId2
###
### DESCRIPTION:
### This function will set the second unique id from the
### ott table leader.
###
### PARAMETERS:
### aPtr - Pointer to the ott leader
### aWord - The value of the unique id
###
### RETURNS:
### None.
###*/
void OTTTBL_SetUniqueId2(OTTTBL_LeaderPtr aPtr, UINT16 aWord)
{
aPtr->UniqueId2 = aWord & WORDMAX;
}
/*#################################################################
### OTTTBL_GetOttEntrySource
###
### DESCRIPTION:
### This function will extract the source offset for the page
### object from the ott entry.
###
### PARAMETERS:
### aPtr - Pointer to the ott entry
###
### RETURNS:
### A object's source offset in the page space
###*/
UINT32 OTTTBL_GetOttEntrySource(OTTTBL_EntryPtr aPtr)
{
return aPtr->Source;
}
/*#################################################################
### OTTTBL_SetOttEntrySource
###
### DESCRIPTION:
### This function will set the source offset for the page
### object entry.
###
### PARAMETERS:
### aPtr - Pointer to the ott leader
### aDWord - The value of the offset
###
### RETURNS:
### None
###*/
void OTTTBL_SetOttEntrySource(OTTTBL_EntryPtr aPtr, UINT32 aDWord)
{
aPtr->Source = aDWord & DWORDMAX;
}
/*#################################################################
### OTTTBL_GetOttEntryDestination
###
### DESCRIPTION:
### This function will extract the destination offset for the
### page object from the ott entry.
###
### PARAMETERS:
### aPtr - Pointer to the ott entry
###
### RETURNS:
### A object's destination offset in the page space
###*/
UINT32 OTTTBL_GetOttEntryDestination(OTTTBL_EntryPtr aPtr)
{
return aPtr->Destination;
}
/*#################################################################
### OTTTBL_SetOttEntryDestination
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -