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

📄 davrectb.c

📁 Flash file system
💻 C
📖 第 1 页 / 共 2 页
字号:

      status = UINT16_HeaderFixISF_PLR(&hdr_attr16, 
                                       (tbl_hdr_addr + HDR_Attrib16Offset),
                                       restart);
      if(status)
      {
         return status;
      }

      /* Marking the Reclaim Table Header status to Valid indicates  */
      /*  that the table has been initialized (mainly for page       */
      /*  reclaim).                                                  */
      hdr_attr16 = HDR_SetStatusAttr(hdr_attr16, HDR_HA_Valid);
               
      status = FLASH_WriteBuffer((tbl_hdr_addr + HDR_Attrib16Offset), 
                               (MemBufferPtr)&hdr_attr16, sizeof(hdr_attr16));
   }
   
   return status;
}

/*########################################################################
  ### RECTBL_WriteTableInfo
  ###
  ### DESCRIPTION:
  ###   This function writes the TableInfo structure to the first
  ###   location in the reclaim table.
  ###
  ### PARAMETERS:
  ###   table_address    - Base address of the reclaim table object.
  ###   table_info_ptr   - Table information struct.
  ###   para_reclaim_tbl - Adjusts written table info according to
  ###                      the type of reclaim table.
  ###
  ### RETURNS:
  ###   ERR_NONE  - When operation is successful.
  ###
*/
ERR_CODE RECTBL_WriteTableInfo(FDI_Handle          table_address,
                                 RECTBL_TableInfoPtr table_info_ptr,
                                 BOOLEAN             para_reclaim_tbl)
{
UINT16       first_block;
ERR_CODE status = ERR_NONE;

   first_block = table_info_ptr->FirstBlock;
      
   /* Use the same reference point as page reclaim which */
   /*  is the bottom of memory.                          */
   if (para_reclaim_tbl)
   {
      table_info_ptr->FirstBlock -= table_info_ptr->TotalBlocks - 1;
   }
   
   table_info_ptr->TableId = RECTBL_TableDataInit;
   
   /* Write the actual table info following the TableId. */
   status = FLASH_WriteBuffer(table_address,
                   (MemBufferPtr)table_info_ptr, RECTBL_TableInfoSize);
                
   table_info_ptr->FirstBlock = first_block;
   
   return status;                              
}


/*########################################################################
  ### RECTBL_GetTableInfo
  ###
  ### DESCRIPTION:
  ###   This function does the proper translation of the FirstBlock
  ###   for paragraph vs. page reclaim and returns the table info
  ###   structure for the specified type of reclaim table.
  ###
  ### PARAMETERS:
  ###   table_address    - Base address of the reclaim table object.
  ###   table_info_ptr   - Table info structure for returning table info.
  ###   para_reclaim_tbl - TRUE:  Translate FirstBlock for para reclaim.
  ###                      FALSE: Use table values as they are.
  ###
  ### RETURNS:
  ###   ERR_NONE  - When operation completes successfully.
  ###
*/
ERR_CODE RECTBL_GetTableInfo(FDI_Handle          table_address,
                               RECTBL_TableInfoPtr table_info_ptr,
                               BOOLEAN             para_reclaim_tbl,
                               BOOLEAN restart)
{
   ERR_CODE status = ERR_NONE;
   /* The TableInfo structure is the first item in the reclaim table. */
   FLASH_ReadBuffer(table_address, 
                (MemBufferPtr)table_info_ptr, RECTBL_TableInfoSize);

   status = UINT16_FixISF_PLR( &(table_info_ptr->TableId), 
                  table_address + RECTBL_TableIdOffset, restart); 
   if(status)
   {
      return status;
   }
   
   /* Use the same reference point as page reclaim which */
   /*  is the bottom of memory.                          */
   if (para_reclaim_tbl)
   {
      table_info_ptr->FirstBlock += table_info_ptr->TotalBlocks - 1;
   }
   
   return status;
}                               

/*########################################################################
  ### RECTBL_WriteTable
  ###
  ### DESCRIPTION:
  ###   This function will write a reclaim status entry to the specified
  ###   block entry in the reclaim table.
  ###
  ### PARAMETERS:
  ###   table_handle     - Base address of the reclaim table object.
  ###   block            - Block number for table entry index.
  ###   status_ptr       - Desired reclaim status to write.
  ###   para_reclaim_tbl - TRUE:  Translate FirstBlock for para reclaim.
  ###                      FALSE: Use table values as they are.
  ###
  ### RETURNS:
  ###   ERR_NONE  - When operation completes successfully.
  ###
*/
ERR_CODE RECTBL_WriteTable(FDI_Handle           table_handle, 
                             UINT32                block, 
                             RECTBL_TableEntryPtr status_ptr,
                             BOOLEAN              para_reclaim_tbl,
                             BOOLEAN restart)
{
/* his should only be enabled for debug */
ERR_CODE status = ERR_NONE;
#ifdef ENABLE_BLOCK_RANGE_CHECK
RECTBL_TableInfo table_info;
   /* Read the FirstBlock and TotalBlocks fields from  */
   /*  the reclaim table.                              */
   FLASH_ReadBuffer(table_handle, (MemBufferPtr)&table_info,
                                         RECTBL_TableInfoSize);

   status = UINT16_FixISF_PLR( &(table_info.TableId), 
                  table_handle + RECTBL_TableIdOffset, restart);
   if(status)
   {
      return status;
   }
                                      
   if (para_reclaim_tbl)
   {
      table_info.FirstBlock += table_info.TotalBlocks - 1;
      if ((block > table_info.FirstBlock) || (block <
         (table_info.FirstBlock - (table_info.TotalBlocks - 1))))
      {
         return ERR_SYSTEM;
      }
   }
   else
   {
      if ((block < table_info.FirstBlock) || (block >
           (table_info.FirstBlock + table_info.TotalBlocks - 1)))
      {
         return ERR_SYSTEM;
      }
   }
#endif
      
   status = 
      CalculateTableEntryOffset(&table_handle, block, para_reclaim_tbl, restart);
   if(status)
   {
      return status;
   }
   return FLASH_WriteBuffer(table_handle, 
                      (MemBufferPtr)status_ptr, RECTBL_TableEntrySize);
}                                 

/*########################################################################
//### RECTBL_ReadTable
//###
  ### DESCRIPTION:
  ###   This function will read a reclaim status entry to the specified
  ###   block entry in the reclaim table.
  ###
  ### PARAMETERS:
  ###   table_handle     - Base address of the reclaim table object.
  ###   block            - Block number for table entry index.
  ###   status_ptr       - Desired reclaim status to write.
  ###   para_reclaim_tbl - TRUE:  Translate FirstBlock for para reclaim.
  ###                      FALSE: Use table values as they are.
  ###
  ### RETURNS:
  ###   ERR_NONE  - When operation completes successfully.
  ###
*/
ERR_CODE RECTBL_ReadTable(FDI_Handle           table_handle, 
                            UINT32                block, 
                            RECTBL_TableEntryPtr status_ptr,
                            BOOLEAN              para_reclaim_tbl,
                            BOOLEAN restart)
{

ERR_CODE status = ERR_NONE;
#ifdef ENABLE_BLOCK_RANGE_CHECK
RECTBL_TableInfo table_info;

   /* Read the FirstBlock and TotalBlocks fields from  */
   /*  the reclaim table.                              */
   FLASH_ReadBuffer(table_handle, (MemBufferPtr)&table_info,
                                         RECTBL_TableInfoSize);
   status = UINT16_FixISF_PLR( &(table_info.TableId), 
                  table_handle + RECTBL_TableIdOffset, restart);
   if(status)
   {
      return status;
   }
                                                                               
   if (para_reclaim_tbl)
   {
      table_info.FirstBlock += table_info.TotalBlocks - 1;
      if ((block > table_info.FirstBlock) || (block <
         (table_info.FirstBlock - (table_info.TotalBlocks - 1))))
      {
         return ERR_SYSTEM;
      }
   }
   else
   {
      if ((block < table_info.FirstBlock) || (block >
           (table_info.FirstBlock + table_info.TotalBlocks - 1)))
      {
         return ERR_SYSTEM;
      }
   }
#endif

   status = 
      CalculateTableEntryOffset(&table_handle, block, para_reclaim_tbl, restart);
   if(status)
   {
      return status;
   }
   FLASH_ReadBuffer(table_handle, (MemBufferPtr)status_ptr, 
                                                RECTBL_TableEntrySize);

   status = UINT32_FixISF_PLR( &(status_ptr->Status), 
                      table_handle + RECTBL_EntryStatusOffset, restart);                                             

   return status;
}

/*########################################################################
  ### RECTBL_CreateTable
  ###
  ### DESCRIPTION:
  ###   This function will create a reclaim table object on the
  ###   proper "power loss" recovery order.
  ###
  ### PARAMETERS:
  ###   table_info_ptr  - Used to return the table object information
  ###                     back to the caller.
  ###   use_page_space  - TRUE: Creates a page reclaim table.
  ###                     FALSE: Creates a paragraph reclaim table.
  ###
  ### RETURNS:
  ###   ERR_NONE  - When operation is successful.
  ###
*/
ERR_CODE RECTBL_CreateTable(HDR_SearchInfoPtr table_info_ptr,
                              BOOLEAN           use_page_space,
                              BOOLEAN restart)
{
UINT32            ii;
UINT8_PTR         tchar_ptr;
ERR_CODE          status;
FDI_Handle        rec_tbl_handle;
HDR_CompareInfo   compare_info;

   /* All is well on the memory space front, so create the header. */
   /* Set up Power Loss Recovery Options                           */
   table_info_ptr->HeaderPtr->Attr16 = WORDMAX;
   table_info_ptr->HeaderPtr->Attr8 = BYTEMAX;
   
   table_info_ptr->HeaderPtr->Attr8 = 
        HDR_SetReliableAttr((table_info_ptr->HeaderPtr->Attr8), HDR_HA_Reliable);
        
   table_info_ptr->HeaderPtr->Attr8 = 
        HDR_SetReservesAttr((table_info_ptr->HeaderPtr->Attr8), HDR_HA_NoReserves);
        
   /* NOTE: Must write status to Valid after TableInfo is written. */
   table_info_ptr->HeaderPtr->Attr16 = 
        HDR_SetStatusAttr((table_info_ptr->HeaderPtr->Attr16), HDR_HA_WriteInProgress);
   
   /* Copy the name to the header */
   ii = 0;
/* DAV - type cast */
   tchar_ptr = (UINT8_PTR)RECTBL_HeaderName;
   while (*(tchar_ptr + ii) != 0)
   {
      table_info_ptr->HeaderPtr->Name[ii] = *(tchar_ptr + ii);
      ii++;
   }
   table_info_ptr->HeaderPtr->NameSize = (UINT8)ii;
   
   /* Translate page or paragraph alignment to the header entry. */
   if (use_page_space)
   {
      FDI_MemUsage.PageOverhead.Valid +=
                       HDR_CalcHdrSize(table_info_ptr->HeaderPtr->NameSize);
      FDI_MemUsage.PageSpace.Valid += RECTBL_PageRecTblSize;
      
      table_info_ptr->HeaderPtr->Attr16 = 
         HDR_SetAlignmentAttr((table_info_ptr->HeaderPtr->Attr16), HDR_HA_AlignPage);
   
      /* Calculate the size of the header and place it in the */
      /*  proper fields.                                      */
      HDR_SetObjectSize((table_info_ptr->HeaderPtr), 
                                    (RECTBL_PageRecTblSize / FDI_PageSize));
   }
   else
   {
      /* Update tracking vars. */
      FDI_MemUsage.ParaOverhead.Valid += 
                         RoundUp((ii + HDR_FixedSize), FDI_ParagraphLength);
      FDI_MemUsage.ParaSpace.Valid += RECTBL_ParaRecTblSize;
      
      table_info_ptr->HeaderPtr->Attr16 = 
         HDR_SetAlignmentAttr((table_info_ptr->HeaderPtr->Attr16), 
                                                          HDR_HA_AlignPara);
         
      /* Calculate the size of the header and place it in the */
      /*  proper fields.                                      */
      HDR_SetObjectSize((table_info_ptr->HeaderPtr), 
                             (RECTBL_ParaRecTblSize / FDI_ParagraphLength));
   }
   
   table_info_ptr->HeaderPtr->Attr16 = 
      HDR_SetAbsorbedAttr((table_info_ptr->HeaderPtr->Attr16), HDR_HA_Exists);
      
   table_info_ptr->HeaderPtr->Attr16 = (UINT16)
      HDR_SetPrivilegeAttr((table_info_ptr->HeaderPtr->Attr16), 0);
   
   table_info_ptr->HeaderPtr->SecurityKey = 0xfeedbeef;
   table_info_ptr->HeaderPtr->ObjectType  = FDI_HT_ReclaimTable;

   /* Write the header to flash! */
   status = HDR_CreateHeaderEntry((FDI_HandlePtr)&rec_tbl_handle,
                                            table_info_ptr->HeaderPtr);
   if (status)
   {
      return status;
   }
   
   /* Locate the physical address of the reclaim table for use by  */
   /*  the WriteReclaimTable function, starting from the beginning */
   /*  of the header table.                                        */
   table_info_ptr->CurrObj.HeaderAddress = 0;
   table_info_ptr->CurrObj.ConfigEntry.Offset = 0;
   table_info_ptr->CurrObj.ConfigEntry.Status = 0;
   
   compare_info.CompareValue = rec_tbl_handle;
   status = GetNextHeader(table_info_ptr, HDR_ByHeaderAddress, &compare_info, restart);
   
   return status;
}

#endif /* DIRECT_ACCESS_VOLUME */

⌨️ 快捷键说明

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