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

📄 davpagerecl.c

📁 FDI Intel开发的FLASH文件系统,功能很强大
💻 C
📖 第 1 页 / 共 4 页
字号:
      else if(ottBytesCurrent > 0  && ottBytesRemaining == 0)
      {
         /* REMAINING OBJECT */
         *aOttIndexPtr = *aOttIndexPtr + 1;
      }
      else
      {
         /* NEXT BLOCK */
         break;
      }

      /* Is there any data left in the ottEntry? */
      if(*aOttIndexPtr > aOttIndexLast)
      {
         /* No more OTT entries */
         break;
      }

      /* Compute the bytes used in the RB */
      blockBytesSent = blockBytesSent + ottBytesCurrent;

   } /* while */

   /* Block complete */
   return ERR_NONE;
}

 /*#################################################################
  ### RECLAIM_PAGE_EraseFullPageBlocks
  ###
  ### DESCRIPTION:
  ###    This function handles a special case move object operation.
  ###    The case is where there are no ott entries, however, the
  ###    leader contains one or more working blocks. This is an
  ###    indication that all working blocks need to be deleted.
  ###
  ### PARAMETERS:
  ###   aRef          - IN: Parameter used throughout the page reclaim.
  ###   aOttLeaderPtr - IN: Pointer to the leader of the ott table.
  ###
  ### 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 RECLAIM_PAGE_EraseFullPageBlocks(PAGE_RECLAIM_Address* aRef, OTTTBL_LeaderPtr aOttLeaderPtr)
{
   ERR_CODE status;

   FDI_Handle   rtEntryHandle;
   RTTBL_Entry  rtEntry;
   RTTBL_Leader rtLeader;
   /*Fix Start:SCR964 */
   UINT16        rtIndex;
   UINT16        rtReads;
   UINT16        rtStartBlock;
   UINT16        rtEndBlock;
   /*Fix End:SCR964 */

   /* Get the first RT entry */
   status = RTTBL_GetFirstRtEntry(&rtEntryHandle, &rtEntry, &rtLeader);
   if(status != ERR_NONE)
   {
      return status;
   }
   rtReads = 1;

   /* Compute the range of blocks to process */
   rtEndBlock   = RTTBL_GetLastBlock(&rtLeader);
   rtStartBlock = RTTBL_GetLastBlock(&rtLeader) - RTTBL_GetNumRows(&rtLeader)+1;
   for(rtIndex=rtStartBlock; rtIndex<=rtEndBlock; rtIndex++)
   {
      switch(RTTBL_GetRtEntryProgressState(&rtEntry))
      {
      case RTTBL_RtEntryProgressState_NoOperationInProgress:

      case RTTBL_RtEntryProgressState_CopyOutInProgress:
         RTTBL_SetRtEntryProgressState(&rtEntry, RTTBL_RtEntryProgressState_CopyOutInProgress);
         status = RTTBL_WriteRtEntryProgressState(&rtEntryHandle, &rtEntry);
         if(status != ERR_NONE)
         {
            return status;
         }

         /* Insure that the sub operation is not to copy */
         if(RTTBL_GetRtEntryOpr(&rtEntry) == RTTBL_RtEntryOpr_BlockCopy)
         {
            /* This routine was called when the ott table is empty. */
            return ERR_STATE;
         }

      case RTTBL_RtEntryProgressState_ErasePageBlockInProgress:
         RTTBL_SetRtEntryProgressState(&rtEntry, RTTBL_RtEntryProgressState_ErasePageBlockInProgress);
         status = RTTBL_WriteRtEntryProgressState(&rtEntryHandle, &rtEntry);
         if(status != ERR_NONE)
         {
            return status;
         }

         /* Erase the page block */
         status = FLASH_EraseBlock(
            UTIL_CalcHandleOfBlockBottomBoundary(rtIndex),
            TRUE);
         if(status != ERR_NONE)
         {
            return status;
         }

      case RTTBL_RtEntryProgressState_OperationComplete:
         RTTBL_SetRtEntryProgressState(&rtEntry, RTTBL_RtEntryProgressState_OperationComplete);
         status = RTTBL_WriteRtEntryProgressState(&rtEntryHandle, &rtEntry);
         if(status != ERR_NONE)
         {
            return status;
         }

         break;

      /* We should never see these state */
      case RTTBL_RtEntryProgressState_NoOperationRequired:
      case RTTBL_RtEntryProgressState_CopyBackInProgress:
      case RTTBL_RtEntryProgressState_EraseReclaimBlockInProgress:
         return ERR_STATE;
         break;
      default:
         return ERR_STATE;
         break;
      } /* switch */

      /* Get the next block */
      if(rtReads < RTTBL_GetNumRows(&rtLeader))
      {
         status = RTTBL_GetNextRtEntry(&rtEntryHandle, &rtEntry, &rtEntryHandle);
         if(status != ERR_NONE)
         {
            return status;
         }
         rtReads++;
      }

   } /* for */

   return ERR_NONE;
}

 /*#################################################################
  ### RECLAIM_PAGE_MoveUserObjects
  ###
  ### DESCRIPTION:
  ###    This function copies objects from its old location to its
  ###    new. Instructions are based on what is defined in the
  ###    ott table.
  ###
  ### PARAMETERS:
  ###   aRef          - IN: Parameter used throughout the page reclaim.
  ###
  ### 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 RECLAIM_PAGE_MoveUserObjects(PAGE_RECLAIM_Address* aRef)
{
   ERR_CODE status;

   FDI_Handle      unusedHandle;

   /*Fix Start:SCR964 */
   UINT16           rtStartBlock;
   UINT16           rtEndBlock;
   /*Fix End:SCR964 */
   FDI_Handle      rtEntryHandle = 0;
   RTTBL_Entry     rtEntry;
   RTTBL_Leader    rtLeader;
   /*Fix Start:SCR964 */
   UINT16           rtIndex;
   UINT16           rtWriteCnt;
   UINT16           rtReads;
   /*Fix End:SCR964 */

   BOOLEAN         ottPowerlossReset;
   OTTTBL_Leader   ottLeader;
   /*Fix Start:SCR964 */
   UINT16          ottIndex;
   UINT16           ottIndexLast;
   /*Fix End:SCR964 */
   
   UINT16          progress_state;

   /* REALLOCATE OPERATION */
   if(aRef->reclaimType == enPageReallocate)
   {
      /* We do not bother to look at the state of each block */
      /* The rt table should already have been fill with no operation required */
      return ERR_NONE;
   }

   /* FULL-DEFRAG/PARTIAL-DEFRAG/RECLAIM-IN-PLACE OPERATIONS */
   /* Is the OTT list in sram? */
   if(aRef->sramOttEntries == 0)
   {
      /* No. Read it in */
      status = OTTTBL_ReadTableIntoSRAM(&ottLeader, &unusedHandle, 
         &aRef->sramOttEntriesList[0], sizeof(aRef->sramOttEntriesList), &aRef->sramOttEntries);
      if(status != ERR_NONE)
      {
         return status;
      }
   }
   else
   {
      /* Yes. We need the header information for the OTT table */
      status = OTTTBL_GetFirstOttEntry(&unusedHandle, &aRef->sramOttEntriesList[0], &ottLeader);
      if(status != ERR_NONE)
      {
         return status;
      }
   }

   /* Do we have objects to move? */
   if(OTTTBL_GetNumRows(&ottLeader) == 0)
   {
      /* No. Then we must have full page blocks to erase */
      status = RECLAIM_PAGE_EraseFullPageBlocks(aRef, &ottLeader);
      if(status != ERR_NONE)
      {
         return status;
      }

      /* Nothing more to do */
      return status;
   }

   /* We have objects to move.*/
   /* Process block by block, get the starting block */
   status = RTTBL_GetFirstRtEntry(&rtEntryHandle, &rtEntry, &rtLeader);
   if(status != ERR_NONE)
   {
      return status;
   }

   rtReads           = 1;
   rtEndBlock        =  RTTBL_GetLastBlock(&rtLeader);
   rtStartBlock      = (RTTBL_GetLastBlock(&rtLeader)+1) - RTTBL_GetNumRows(&rtLeader);
   ottIndexLast      = OTTTBL_GetNumRows(&ottLeader)-1;
   ottIndex          = 0;
   ottPowerlossReset = FALSE;

   /* MOVE USER OBJECTS */
   /* For each block in the RT */
   for(rtIndex=rtStartBlock; rtIndex<=rtEndBlock; rtIndex++)
   {
      /* E5.5.969 Start */    
      progress_state = RTTBL_GetRecoveredRtEntryProgressState( &rtEntry,
                                                               rtEntryHandle,
                                                               &status );
      switch(progress_state)
      /* E5.5.969 End */ 
      {
      case RTTBL_RtEntryProgressState_NoOperationInProgress:
         /* Possible operations (copy, erase, and none) */
         /* Only copy and erase, start here             */
      case RTTBL_RtEntryProgressState_CopyOutInProgress:

         RTTBL_SetRtEntryProgressState(&rtEntry, RTTBL_RtEntryProgressState_CopyOutInProgress);
         status = RTTBL_WriteRtEntryProgressState(&rtEntryHandle, &rtEntry);
         if(status != ERR_NONE)
         {
            return status;
         }
       
         /* Is our task to copy? */
         if(RTTBL_GetRtEntryOpr(&rtEntry) == RTTBL_RtEntryOpr_BlockCopy)
         {
            /* Yes. Then perform copy operation */

            /* POWER-LOSS: Recovery index position */
            if(aRef->plrRestart == TRUE  &&  ottPowerlossReset == FALSE)
            {
               status = OTTTBL_CalcOttIndexToBlock(rtIndex,
                  &aRef->sramOttEntriesList[0], aRef->sramOttEntries, &ottIndex);
               if(status != ERR_NONE)
               {
                  if(status != ERR_NO_MORE_ENTRIES)
                  {
                     return status;
                  }
                  status = ERR_NONE;
               }
               ottPowerlossReset = TRUE;
            }

            /* Do we have more ott entries? */
            if(ottIndex <= ottIndexLast)
            {
               /* Track how many objects were copied for this block */
               rtWriteCnt   = 0;

               /* Yes. Then copy out only those that are related to the current block */
               status = RECLAIM_PAGE_CopyOutObjectsToBlock(aRef, rtIndex, FDI_ReclaimBlockAddressBottom,
                  &ottIndex, ottIndexLast, &rtWriteCnt);
               if(status != ERR_NONE)
               {
                  return status;
               }

               /* Something is strange, we did not do anything */
               if(rtWriteCnt == 0)
               {
                  return ERR_STATE;
               }
            }
         }


      case RTTBL_RtEntryProgressState_ErasePageBlockInProgress:
         RTTBL_SetRtEntryProgressState(&rtEntry, RTTBL_RtEntryProgressState_ErasePageBlockInProgress);
         status = RTTBL_WriteRtEntryProgressState(&rtEntryHandle, &rtEntry);
         if(status != ERR_NONE)
         {
            return status;
         }

         /* Erase the page block */
         status = FLASH_EraseBlock(UTIL_CalcHandleOfBlockBottomBoundary(rtIndex), TRUE);
         if(status != ERR_NONE)
         {
            return status;
         }

         /* Do we have object to write back? */
         if(RTTBL_GetRtEntryOpr(&rtEntry) == RTTBL_RtEntryOpr_BlockErase)
         {
            /* No. A erase only, therefore, proceed to completion */
            RTTBL_SetRtEntryProgressState(&rtEntry, RTTBL_RtEntryProgressState_OperationComplete);
            status = RTTBL_WriteRtEntryProgressState(&rtEntryHandle, &rtEntry);
            if(status != ERR_NONE)
            {
               return status;
            }
            break;
         }

      case RTTBL_RtEntryProgressState_CopyBackInProgress:
         RTTBL_SetRtEntryProgressState(&rtEntry, RTTBL_RtEntryProgressState_CopyBackInProgress);
         status = RTTBL_WriteRtEntryProgressState(&rtEntryHandle, &rtEntry);
         if(status != ERR_NONE)
         {

⌨️ 快捷键说明

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