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

📄 davmath.c

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

/* ###########################################################################
###  DAV - Direct Access Volume Enhancement for FDI
###
###  Module: dav_math.c - DAV Math module
###
###  $Workfile: davmath.c $
###  $Revision: 55 $
###  $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 "DavMath.h"

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

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

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

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

/*#############################################################################
  ### DivRoundup
  ### 
  ### DESCRIPTION:
  ###   This function will divide the numerator by the divisor and
  ###   returns the quotient.  If there is a remainder then the quotient
  ###   is incremented by one. (Ceiling Function)
  ###      
  ### PARAMETERS:   
  ###   UINT32 numerator - numerator of math function.
  ###   UINT32 divisor   - divisor of math function.
  ### 
  ### RETURNS:
  ###   UINT32 - quotient of numerator/divisor.
  ###*/
UINT32 DivRoundup(UINT32 numerator, UINT32 divisor)
{
UINT32 quotient;

   quotient = numerator / divisor;
   if (numerator % divisor)
   {
      quotient += 1;
   }
   return quotient;
}

UINT32 BlockAlign(UINT32 address)
{
UINT32 align_offset, new_address;

   align_offset = FDI_StartAddress & (FDI_BlockSize - 1);
   if (align_offset > 0)
   {
      new_address = (address - align_offset) & (~(FDI_BlockSize - 1));
      new_address += align_offset;
   }
   else
   {
      new_address = address & (~(FDI_BlockSize - 1));
   }

   return new_address;
}

/*########################################################################
  ### IsInBlock
  ###
  ### DESCRIPTION:
  ###   This function checks to see if an address range 
  ###   is within a block, given the block number and address range
  ###
  ### PARAMETERS:   
  ###   lo_addr   - lower address of range
  ###   hi_addr   - upper address of range
  ###   block_num - flash block number
  ###
  ### RETURNS:
  ###     -1   address range is below the block
  ###      0   address range is in the block
  ###     +1   address range is above the block
  ###*/
int IsInBlock(FDI_Handle lo_addr, FDI_Handle hi_addr, UINT32 block_num)
{
UINT32 block_lo_addr, block_hi_addr;

   block_lo_addr = Block2Handle(block_num);
   block_hi_addr = block_lo_addr + FDI_BlockSize - 1;
   
   /* If the begin address is at least less than the end */
   /*  then its either before or in the block.           */
   if (lo_addr < block_hi_addr)
   {
      /* Check for before */
      if (hi_addr < block_lo_addr)
      {
         return -1;
      }
   
      /* Check if in */
      if (hi_addr >= block_lo_addr)
      {
         return 0;
      }
   }
   
   /* Its not in or before, thus, it must be after. */
   return 1;
}


/*#############################################################################
  ### GetInBlockHiLoAddress
  ### 
  ### DESCRIPTION:
  ###   This function checks to see if an address range is within 
  ###   a block, given the block number. On return, the hi and lo 
  ###   addresses will contain the range that is in the block.
  ###      
  ### PARAMETERS:   
  ###   lo_addr_ptr   - lower address of range
  ###   hi_addr_ptr   - upper address of range
  ###   block_num     - flash block number
  ###
  ### RETURNS:
  ###     -1   address range is below the block
  ###      0   address range is in the block
  ###     +1   address range is above the block
  ###*/
int GetInBlockHiLoAddress(UINT32_PTR lo_addr_ptr, UINT32_PTR hi_addr_ptr, UINT32 block_num)
{
UINT32 block_lo_addr_ptr, block_hi_addr_ptr;

   block_lo_addr_ptr = Block2Handle(block_num);
   block_hi_addr_ptr = block_lo_addr_ptr + FDI_BlockSize - 1;
   
   /* If the begin address is at least less than the end */
   /*  then its either before or in the block.           */
   if (*lo_addr_ptr < block_hi_addr_ptr)
   {
      /* Check for before */
      if (*hi_addr_ptr < block_lo_addr_ptr)
      {
         *lo_addr_ptr = 0;
         *hi_addr_ptr = 0;
         return -1;
      }
   
      /* Check if in */
      if (*hi_addr_ptr >= block_lo_addr_ptr)
      {
         if (*hi_addr_ptr > block_hi_addr_ptr)
         {
            *hi_addr_ptr = block_hi_addr_ptr;
         }
         
         if (*lo_addr_ptr < block_lo_addr_ptr)
         {
            *lo_addr_ptr = block_lo_addr_ptr;
         }
         
         return 0;
      }
   }
   
   /* Its not in or before, thus, it must be after. */
   *lo_addr_ptr = 0;
   *hi_addr_ptr = 0;
   return 1;
}

#endif /* DIRECT_ACCESS_VOLUME */
                                

⌨️ 快捷键说明

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