⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 davrattbl.c

📁 FDI Intel开发的FLASH文件系统,功能很强大
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) 1995-2004 Intel Corporation */
/* Intel Confidential                        */

/* ###########################################################################
###  REALLOCATE TABLE (RAT)
###
###  Module: DavRatTbl.c - RAT table module
###
###  $Workfile: DavRatTbl.c $
###  $Revision: 12 $
###  $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 "DavRatTbl.h"
#include "DavMem.h"

/*### Local Declarations
#########################*/

/*### Global Declarations
#########################*/

/*### Local Functions
#########################*/

/*### Global Functions
#########################*/

/*########################################################################
  ### RATTBL_AllocateFlash
  ###
  ### DESCRIPTION:
  ###    This function create a RAT table in paragraph space. It creates
  ###    a fixed header and writes the table (leader and entries)
  ###    
  ### PARAMETERS:
  ###   aObjHandle    - Handle (in paragraph space) to where the table is to be
  ###      written
  ###   aNumRows      - The number of rows to allocate in the rat table.
  ###   aBackupOffset - The backup's offset
  ###   aBackupSize   - The backup size (in pages)
  ###
  ### 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 RATTBL_AllocateFlash(FDI_Handle aObjHandle, UINT16 aNumRows, UINT32 aBackupOffset, UINT32 aBackupSize)
{
   ERR_CODE status;

   HDR_FixedHeader fixHeader;
   FDI_Handle      hdrHandle = 0;
   RATTBL_Leader   objLeader;

   /* The CT table has already validated available space */

   /* Create the table fixed header */
   FHDR_SetSize(&fixHeader, RATTBL_CalcTableSize(aNumRows));
   FHDR_SetType(&fixHeader, FDI_HT_ReAllocateTable);
   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_ReAllocateTable)
            {
               /* Create the table data using the passed array */
               /* Write the leader */
               UTIL_ClearVariable((UINT8*)&objLeader, sizeof(RATTBL_Leader), 0xFF);

               RATTBL_SetUniqueId1(&objLeader, RATTBL_UniqueId1);
               RATTBL_SetUniqueId2(&objLeader, RATTBL_UniqueId2);
               RATTBL_SetNumRows(&objLeader, aNumRows);
               RATTBL_SetBackupOffset(&objLeader, aBackupOffset);
               RATTBL_SetBackupSize(&objLeader, aBackupSize);
               status = FLASH_WriteBuffer(FHDR_CalcObjectHandle(&fixHeader), 
                  (UINT8*)&objLeader, sizeof(RATTBL_Leader));
               if(status != ERR_NONE)
               {
                  return status;
               }
            }
         }
      }
   }
   /* E5.5.970 Start */ 
   mDEBUG_CHECK_ERRCODE(status);
   /* E5.5.970 End */ 

   /* Change the state of the header */
   status = FHDR_ValidateHeaderInFlash(hdrHandle, &fixHeader);
   if(status != ERR_NONE)
   {
     return status;
   }

   return status;
}

/* ======================== Table Functions =================================*/
/*########################################################################
  ### RATTBL_WriteRatEntry
  ###
  ### DESCRIPTION:
  ###    This function changes the state of the RAT table entry. The state
  ###    The state is related to a the modify object step of a page reclaim.
  ###    
  ### PARAMETERS:
  ###   aHandle   - Handle to a specific rt entry in flash.
  ###   aEntryPtr - Pointer to a specific rt entry in sram.
  ###
  ### 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 RATTBL_WriteRatEntry(FDI_Handle aHandle, RATTBL_EntryPtr aEntryPtr)
{
   ERR_CODE status;

   status = FLASH_WriteBuffer(aHandle, (UINT8*)aEntryPtr, sizeof(RATTBL_Entry));
   if(status != ERR_NONE)
   {
      return status;
   }

   return status;
}

/*#################################################################
  ### RATTBL_GetNumRows
  ###
  ### DESCRIPTION:
  ###   This function will extract the number of rows/entries in the
  ###   rat table.
  ###
  ### PARAMETERS:
  ###   aPtr - Pointer to the rat leader
  ###
  ### RETURNS:
  ###   The number of rows
  ###*/
UINT16 RATTBL_GetNumRows(RATTBL_LeaderPtr aPtr)
{
   return aPtr->NumRows;
}
/*#################################################################
  ### RATTBL_SetNumRows
  ###
  ### DESCRIPTION:
  ###   This function will set the number of rows the rat table
  ###   contains. It is not unusual to have zero as a value.
  ###
  ### PARAMETERS:
  ###   aPtr  - Pointer to the rat leader
  ###   aByte - The value of the number of rows
  ###
  ### RETURNS:
  ###   None
  ###*/
void RATTBL_SetNumRows(RATTBL_LeaderPtr aPtr, UINT16 aDWord)
{
   aPtr->NumRows = aDWord & DWORDMAX;
}

/*#################################################################
  ### RATTBL_SetUniqueId1
  ###
  ### DESCRIPTION:
  ###   This function will set the first unique id for the
  ###   rat table leader.
  ###
  ### PARAMETERS:
  ###   aPtr  -  Pointer to the rat leader
  ###   aWord -  The value of the unique id
  ###
  ### RETURNS:
  ###   None.
  ###*/
void RATTBL_SetUniqueId1(RATTBL_LeaderPtr aPtr, UINT16 aDWord)
{
   aPtr->UniqueId1 = aDWord;
}
/*#################################################################
  ### RATTBL_GetUniqueId1
  ###
  ### DESCRIPTION:
  ###   This function will extract the first unique id from the rat
  ###   table leader
  ###
  ### PARAMETERS:
  ###   aPtr - Pointer to the rat leader
  ###
  ### RETURNS:
  ###   The first unique id
  ###*/
UINT16 RATTBL_GetUniqueId1(RATTBL_LeaderPtr aPtr)
{
   return aPtr->UniqueId1 & DWORDMAX;
}


/*#################################################################
  ### RATTBL_SetUniqueId2
  ###
  ### DESCRIPTION:
  ###   This function will set the second unique id from the
  ###   rat table leader.
  ###
  ### PARAMETERS:
  ###   aPtr  -  Pointer to the rat leader
  ###   aWord -  The value of the unique id
  ###
  ### RETURNS:
  ###   None.
  ###*/
void RATTBL_SetUniqueId2(RATTBL_LeaderPtr aPtr, UINT16 aDWord)
{
   aPtr->UniqueId2 = aDWord;

}
/*#################################################################
  ### RATTBL_GetUniqueId2
  ###
  ### DESCRIPTION:
  ###   This function will extract the second unique id from the rat
  ###   table leader
  ###
  ### PARAMETERS:
  ###   aPtr - Pointer to the rat leader
  ###
  ### RETURNS:
  ###   The second unique id
  ###*/
UINT16 RATTBL_GetUniqueId2(RATTBL_LeaderPtr aPtr)
{
   return aPtr->UniqueId2 & DWORDMAX;
}

/*#################################################################
  ### RATTBL_SetBackupOffset
  ###
  ### DESCRIPTION:
  ###   This function will set the location of the backup area
  ###
  ### PARAMETERS:
  ###   aPtr   - Pointer to the rat leader
  ###   aDWord - The location of the backup
  ###
  ### RETURNS:
  ###   None
  ###*/
void RATTBL_SetBackupOffset(RATTBL_LeaderPtr aPtr, UINT32 aDWord)
{
   aPtr->BackupOffset = aDWord;

}
/*#################################################################
  ### RATTBL_GetBackupOffset
  ###
  ### DESCRIPTION:
  ###   This function will extract the offset where the backup of
  ###   the objects will occur.
  ###
  ### PARAMETERS:
  ###   aPtr - Pointer to the rat leader
  ###
  ### RETURNS:
  ###   The backup offset
  ###*/
UINT32 RATTBL_GetBackupOffset(RATTBL_LeaderPtr aPtr)
{
   return aPtr->BackupOffset;
}

/*#################################################################
  ### RATTBL_SetBackupSize
  ###
  ### DESCRIPTION:
  ###   This function will set the sizeof the backup area
  ###
  ### PARAMETERS:
  ###   aPtr   - Pointer to the rat leader
  ###   aDWord - The size of the backup
  ###
  ### RETURNS:
  ###   None
  ###*/
void RATTBL_SetBackupSize(RATTBL_LeaderPtr aPtr, UINT32 aDWord)
{
   aPtr->BackupSize = aDWord;

}
/*#################################################################
  ### RATTBL_GetBackupSize
  ###
  ### DESCRIPTION:
  ###   This function will extract the sizeof the backup area
  ###
  ### PARAMETERS:
  ###   aPtr - Pointer to the rat leader
  ###
  ### RETURNS:
  ###   The backup size
  ###*/
UINT32 RATTBL_GetBackupSize(RATTBL_LeaderPtr aPtr)
{
   return aPtr->BackupSize;
}

/*#################################################################
  ### RATTBL_GetRatEntryTopIndex
  ###
  ### DESCRIPTION:
  ###   This function the top index into the ott table
  ###
  ### PARAMETERS:
  ###   aPtr - Pointer to the rat leader
  ###
  ### RETURNS:
  ###   The top ott index
  ###*/
UINT8 RATTBL_GetRatEntryTopIndex(RATTBL_EntryPtr aPtr)
{
   return aPtr->TopIndex;
}
/*#################################################################
  ### RATTBL_SetRatEntryTopIndex
  ###
  ### DESCRIPTION:
  ###   This function will set the top index into the ott table
  ###   for the object group
  ###
  ### PARAMETERS:
  ###   aPtr   - Pointer to the rat leader
  ###   aDWord - The ott index
  ###
  ### RETURNS:
  ###   None
  ###*/
void RATTBL_SetRatEntryTopIndex(RATTBL_EntryPtr aPtr, UINT8 aWord)
{
   aPtr->TopIndex = aWord & WORDMAX;
}

/*#################################################################
  ### RATTBL_GetRatEntryBtmIndex
  ###
  ### DESCRIPTION:
  ###   This function the bottom index into the ott table
  ###
  ### PARAMETERS:
  ###   aPtr - Pointer to the rat leader
  ###
  ### RETURNS:
  ###   The bottom ott index
  ###*/
UINT8 RATTBL_GetRatEntryBtmIndex(RATTBL_EntryPtr aPtr)
{
   return aPtr->BtmIndex;
}
/*#################################################################
  ### RATTBL_SetRatEntryBtmIndex
  ###
  ### DESCRIPTION:
  ###   This function will set the bottom index into the ott table
  ###   for the object group
  ###
  ### PARAMETERS:
  ###   aPtr   - Pointer to the rat leader
  ###   aDWord - The ott index
  ###
  ### RETURNS:
  ###   None
  ###*/
void RATTBL_SetRatEntryBtmIndex(RATTBL_EntryPtr aPtr, UINT8 aWord)
{
   aPtr->BtmIndex = aWord & WORDMAX;
}

/*#################################################################
  ### RATTBL_GetRatEntryTopProgressState
  ###
  ### DESCRIPTION:
  ###   This function will extract the top progress state from the 
  ###   passed rat entry.
  ###
  ### PARAMETERS:
  ###   aPtr - Pointer to the rat entry
  ###
  ### RETURNS:
  ###   The progress state
  ###*/
UINT32 RATTBL_GetRatEntryTopProgressState(RATTBL_EntryPtr aPtr)
{
   return aPtr->TopState;
}

/*#################################################################
  ### RATTBL_SetRatEntryTopProgressState
  ###
  ### DESCRIPTION:
  ###   This function will set the top progress state in the
  ###   passed rat entry.
  ###
  ### PARAMETERS:
  ###   aPtr   - Pointer to the rat entry
  ####  aDWord - The new value
  ###
  ### RETURNS:
  ###   The progress state
  ###*/
void RATTBL_SetRatEntryTopProgressState(RATTBL_EntryPtr aPtr, UINT32 aDWord)
{
   aPtr->TopState = aDWord & DWORDMAX;
}

/*#################################################################
  ### RATTBL_GetRecoveredRatEntryTopProgressState
  ###
  ### DESCRIPTION:
  ###   This function will extract the top progress state from the 
  ###   passed rat entry. However, it will reread the entry from 
  ###   passed handle and perform a recovery.
  ###
  ### PARAMETERS:
  ###   aPtr    - Pointer to the rat entry
  ###   aHandle - Handle to the rat entry
  ###
  ### RETURNS:
  ###   The progress state
  ###*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -