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

📄 davrattbl.c

📁 FDI Intel开发的FLASH文件系统,功能很强大
💻 C
📖 第 1 页 / 共 2 页
字号:
UINT32 RATTBL_GetRecoveredRatEntryTopProgressState(RATTBL_EntryPtr aPtr, FDI_Handle aHandle)
{
   ERR_CODE status;

   /* Do a Quasi that will read and write */
   /* We assume this will work */
   status = UTIL_UINT32_FixISF_PLR((UINT32*)&aPtr->TopState, aHandle, FALSE);
   if(status != ERR_NONE)
   {
      status = ERR_STATE;
   }

   /* Read the status bit */
   return RATTBL_GetRatEntryTopProgressState(aPtr);
   
}

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

/*#################################################################
  ### RATTBL_GetRecoveredRatEntryBtmProgressState
  ###
  ### DESCRIPTION:
  ###   This function will extract the bottom progress state from the 
  ###   passed rat entry. However, it will rereads 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
  ###*/
UINT32 RATTBL_GetRecoveredRatEntryBtmProgressState(RATTBL_EntryPtr aPtr, FDI_Handle aHandle)
{
   ERR_CODE status;

   /* Do a Quasi that will read and write */
   /* We assume this will work */
   status = UTIL_UINT32_FixISF_PLR((UINT32*)&aPtr->BtmState, aHandle, FALSE);
   if(status != ERR_NONE)
   {
      status = ERR_STATE;
   }

   /* Read the status bit */
   return RATTBL_GetRatEntryBtmProgressState(aPtr);
   
}


/*#################################################################
  ### RATTBL_GetRatEntryOperation
  ###
  ### DESCRIPTION:
  ###   This function will extract the current entry operation from 
  ###   the passed rat entry.
  ###
  ### PARAMETERS:
  ###   aPtr - Pointer to the rat entry
  ###
  ### RETURNS:
  ###   The current entry operation
  ###*/
UINT8 RATTBL_GetRatEntryOperation(RATTBL_EntryPtr aPtr)
{
   return aPtr->Operation;

}
/*#################################################################
  ### RATTBL_SetRatEntryOperation
  ###
  ### DESCRIPTION:
  ###   This function will set the rat operation to be performed on
  ###   a group.
  ###
  ### PARAMETERS:
  ###   aPtr  -  Pointer to the rat entry
  ###   aByte -  New value of the operation
  ###
  ### RETURNS:
  ###   None.
  ###*/
void RATTBL_SetRatEntryOperation(RATTBL_EntryPtr aPtr, UINT8 aByte)
{
   aPtr->Operation = aByte & BYTEMAX;

}

/*=============================== SEARCH =============================*/
/*#################################################################
  ### RATTBL_GetFirstRatEntry2 (THIS IS A SPECIAL CASE FUNCTION)
  ###
  ### DESCRIPTION:
  ###   This function will retreive the first rat entry along with
  ###   rat table leader. The difference with GetFirstRatEntry is
  ###   that the entry is allocating, while the GetFirstRatEntry's
  ###   entry is valid.
  ###
  ### PARAMETERS:
  ###   aHandlePtr - Handle to the rat entry
  ###   aEntryPtr  - Pointer to the rat entry
  ###   aLeaderPtr - Pointer to the rat leader
  ###
  ### 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_GetFirstRatEntry2(FDI_Handle* aHandlePtr, RATTBL_EntryPtr aEntryPtr, RATTBL_LeaderPtr aLeaderPtr)
{
   ERR_CODE status;

   HDR_FixedHeaderPtr     fixHeaderPtr;
   HDR_Header             allHeaders;
   SEARCH_SearchInfo      result;
   SEARCH_CompareInfo     compare_info;

   RATTBL_ObjectTablePtr  tablePtr = 0; /* Zero, is used to compute offset */
   UINT32                 offset;

   CFGTBL_PgReclaimEntry  cfgPageEntry;
   FDI_Handle             cfgPageHandle;
   UINT8                  ctIndex;
   FDI_Handle             ctEntryHandle;

   /* Find the fixed header for the table */
   result.HeaderPtr                   = &allHeaders;
   result.CurrObj.HeaderAddress       = 0;
   result.CurrObj.ObjectAddress       = 0;
   result.CurrObj.ObjectSize          = 0;
   compare_info.CompareValue          = FDI_HT_ReAllocateTable; /* RAT */
   status = SEARCH_GetNextHeader(&result, SEARCH_ByValidType/*SEARCH_ByTypeOnly*/, &compare_info, FALSE);
   if(status != ERR_NONE)
   {
      if(status == ERR_NO_MORE_ENTRIES)
      {
         /* Fixed Header does not exists */
         fixHeaderPtr = 0;
         UTIL_ClearVariable((UINT8*)aLeaderPtr, sizeof(RATTBL_Leader), 0xFF);
      }
      else
      {
         return status;
      }
   }
   else
   {
      /* A fixed header exists */
      /* PERF_FIX Need to find a more efficent means */
      fixHeaderPtr = (HDR_FixedHeaderPtr)result.CurrObj.HeaderAddress;
      UTIL_CopyVariable((UINT8*)&result.HeaderPtr->OHdr, (UINT8*)aLeaderPtr, sizeof(RATTBL_Leader));
   }


   /* Find a valid Ct Entry for the table */
   if(CFGTBL_GetCtEntryByStatus(FDI_ParaSpaceAddressBottom, CFGTBL_CtEntryType_RAT, CFGTBL_CtEntryStatus_EntryAllocating,
      &cfgPageEntry, &cfgPageHandle, &ctIndex, &ctEntryHandle) == FALSE)
   {
      /* Ct entry does not exist */
      /* No ct entry handle or first entry to copy */
      UTIL_ClearVariable((UINT8*)aEntryPtr,  sizeof(RATTBL_Entry),  0xFF);
      *aHandlePtr = 0;
      status      = ERR_NOTEXISTS;
   }
   else
   {
      if(CFGTBL_GetCtAllocationStatus(&cfgPageEntry.CtEntry[ctIndex]) == CFGTBL_CtAllocationStatus_WriteInProgress)
      {
         /* Compute and copy the ct entry handle */
         offset       = (UINT32)&tablePtr->RatEntry[0] - (UINT32)tablePtr;
         *aHandlePtr  = (UINT32)result.CurrObj.ObjectAddress + (UINT32)offset;

         /* Read in the first entry */
         status = FLASH_ReadBuffer(*aHandlePtr, (UINT8*)aEntryPtr, sizeof(RATTBL_Entry));
         if(status != ERR_NONE)
         {
            return status;
         }
      }
      else
      {
         /* Ct entry does not exist */
         /* No ct entry handle or first entry to copy */
         UTIL_ClearVariable((UINT8*)aEntryPtr,  sizeof(RATTBL_Entry),  0xFF);
         *aHandlePtr = 0;
         status      = ERR_NOTEXISTS;
      }
   }

   /* Status of a ct entry that is valid */
   /* If a powerloss, it is possible that the ct entry exists, however, the fixed header does not */
   return status;
}
/*#################################################################
  ### RATTBL_GetFirstRatEntry
  ###
  ### DESCRIPTION:
  ###   This function will retreive the first rat entry along with
  ###   rat table leader.
  ###
  ### PARAMETERS:
  ###   aHandlePtr - Handle to the rat entry
  ###   aEntryPtr  - Pointer to the rat entry
  ###   aLeaderPtr - Pointer to the rat leader
  ###
  ### 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_GetFirstRatEntry(FDI_Handle* aHandlePtr, RATTBL_EntryPtr aEntryPtr, RATTBL_LeaderPtr aLeaderPtr)
{
   ERR_CODE status;

   HDR_Header             allHeaders;
   SEARCH_SearchInfo      result;
   SEARCH_CompareInfo     compare_info;

   RATTBL_ObjectTablePtr  tablePtr = 0; /* Zero, is used to compute offset */
   UINT32                 offset;

   CFGTBL_PgReclaimEntry  cfgPageEntry;
   FDI_Handle             cfgPageHandle;
   UINT8                  ctIndex;
   FDI_Handle             ctEntryHandle;
   FDI_Handle*            aFHDRHandlePtr;

   /* Find the fixed header for the table */
   result.HeaderPtr                   = &allHeaders;
   result.CurrObj.HeaderAddress       = 0;
   result.CurrObj.ObjectAddress       = 0;
   result.CurrObj.ObjectSize          = 0;
   compare_info.CompareValue          = FDI_HT_ReAllocateTable; /* RAT */
   status = SEARCH_GetNextHeader(&result, SEARCH_ByValidType/*SEARCH_ByTypeOnly*/, &compare_info, FALSE);
   if(status != ERR_NONE)
   {
      if(status == ERR_NO_MORE_ENTRIES)
      {
         /* Fixed Header does not exists */
         aFHDRHandlePtr = 0;
         UTIL_ClearVariable((UINT8*)aLeaderPtr, sizeof(RATTBL_Leader), 0xFF);
      }
      else
      {
         return status;
      }
   }
   else
   {
      /* A fixed header exists */
      /* PERF_FIX Need to find a more efficent means */
      aFHDRHandlePtr = (FDI_Handle*)result.CurrObj.HeaderAddress;
      UTIL_CopyVariable((UINT8*)&result.HeaderPtr->OHdr, (UINT8*)aLeaderPtr, sizeof(RATTBL_Leader));
   }


   /* Find a valid Ct Entry for the table */
   if(CFGTBL_GetCtEntryByStatus(FDI_ParaSpaceAddressBottom, CFGTBL_CtEntryType_RAT, CFGTBL_CtEntryStatus_EntryValid,
      &cfgPageEntry, &cfgPageHandle, &ctIndex, &ctEntryHandle) == FALSE)
   {
      /* Ct entry does not exist */
      /* No ct entry handle or first entry to copy */
      UTIL_ClearVariable((UINT8*)aEntryPtr,  sizeof(RATTBL_Entry),  0xFF);
      *aHandlePtr = 0;
      status      = ERR_NOTEXISTS;
   }
   else
   {
      if(CFGTBL_GetCtAllocationStatus(&cfgPageEntry.CtEntry[ctIndex]) == CFGTBL_CtAllocationStatus_Valid)
      {
         /* Compute and copy the ct entry handle */
         offset       = (UINT32)&tablePtr->RatEntry[0] - (UINT32)tablePtr;
         *aHandlePtr  = (UINT32)result.CurrObj.ObjectAddress + (UINT32)offset;

         /* Read in the first entry */
         status = FLASH_ReadBuffer(*aHandlePtr, (UINT8*)aEntryPtr, sizeof(RATTBL_Entry));
         if(status != ERR_NONE)
         {
            return status;
         }
      }
      else
      {
         /* Ct entry does not exist */
         /* No ct entry handle or first entry to copy */
         UTIL_ClearVariable((UINT8*)aEntryPtr,  sizeof(RATTBL_Entry),  0xFF);
         *aHandlePtr = 0;
         status      = ERR_NOTEXISTS;
      }
   }

   /* Status of a ct entry that is valid */
   /* If a powerloss, it is possible that the ct entry exists, however, the fixed header does not */
   return status;
}

/*#################################################################
  ### RATTBL_GetNextRatEntry
  ###
  ### DESCRIPTION:
  ###   This function will retreive the next rat entry with respect
  ###   to the current rat entry handle.
  ###
  ### PARAMETERS:
  ###   aFlashNextPtr    - Upon return, handle to the next rat entry
  ###   aEntryPtr        - Upon return, pointer to the rat entry
  ###   aFlashCurrentPtr - Handle to the a rat entry
  ###
  ### 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_GetNextRatEntry(FDI_Handle* aFlashNextPtr, RATTBL_EntryPtr aEntry, FDI_Handle* aFlashCurrentPtr)
{
   ERR_CODE status;

   /* Compute the next entry address*/
   *aFlashNextPtr = ((FDI_Handle)*aFlashCurrentPtr + (FDI_Handle)sizeof(RATTBL_Entry));

   /* Read the next entry */
   status = FLASH_ReadBuffer((UINT32)*aFlashNextPtr, (UINT8*)aEntry, sizeof(RATTBL_Entry));
   if(status != ERR_NONE)
   {
      return status;
   }

   return status;
}

/*########################################################################
  ### RATTBL_WriteRatEntryBtmProgressState
  ###
  ### 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.
  ###    These start are the first group of state. Not all of the stes
  ###    fit into the 4 byte restriction, therefore, they were split into
  ###    to groups.
  ###    
  ### PARAMETERS:
  ###   aHandlePtr - Handle to a specific rat entry in flash.
  ###   aEntryPtr  - Pointer to rat 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_WriteRatEntryBtmProgressState(FDI_HandlePtr aHandlePtr, RATTBL_EntryPtr aEntryPtr)
{
   ERR_CODE status = ERR_NONE;

   RATTBL_Entry entry;
   UINT32       offset;

   /* Read the current entry */
   status = FLASH_ReadBuffer(*aHandlePtr, (UINT8*)&entry, sizeof(RATTBL_Entry));
   if(status != ERR_NONE)
   {
      return status;
   }

   /* Transistion to the same state */
   if(RATTBL_GetRatEntryBtmProgressState(aEntryPtr) == RATTBL_GetRatEntryBtmProgressState(&entry))
   {
      return ERR_NONE;
   }

   /* Write the status */
   offset = (UINT32)(&entry.BtmState) - (UINT32)(&entry);
   status = FLASH_WriteBuffer(*aHandlePtr+offset, (UINT8*)((UINT32)aEntryPtr+offset), sizeof(entry.BtmState));
   if(status != ERR_NONE)
   {
     return status;
   }

   return status;
}

/*########################################################################
  ### RATTBL_WriteRatEntryTopProgressState
  ###
  ### 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.
  ###    These start are the second group of state. Not all of the stes
  ###    fit into the 4 byte restriction, therefore, they were split into
  ###    to groups.
  ###    
  ### PARAMETERS:
  ###   aHandlePtr - Handle to a specific rat entry in flash.
  ###   aEntryPtr  - Pointer to rat 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_WriteRatEntryTopProgressState(FDI_HandlePtr aHandlePtr, RATTBL_EntryPtr aEntryPtr)
{
   ERR_CODE status = ERR_NONE;

   RATTBL_Entry entry;
   UINT32       offset;

   /* Read the current entry */
   status = FLASH_ReadBuffer(*aHandlePtr, (UINT8*)&entry, sizeof(RATTBL_Entry));
   if(status != ERR_NONE)
   {
      return status;
   }

   /* Transistion to the same state */
   if(RATTBL_GetRatEntryTopProgressState(aEntryPtr) == RATTBL_GetRatEntryTopProgressState(&entry))
   {
      return ERR_NONE;
   }

   /* Write the status */
   offset = (UINT32)(&entry.TopState) - (UINT32)(&entry);
   status = FLASH_WriteBuffer(*aHandlePtr+offset, (UINT8*)((UINT32)aEntryPtr+offset), sizeof(entry.TopState));
   if(status != ERR_NONE)
   {
     return status;
   }

   return status;
}


#endif /* DIRECT_ACCESS_VOLUME */

⌨️ 快捷键说明

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