fdi_int.h

来自「FDI Intel开发的FLASH文件系统,功能很强大」· C头文件 代码 · 共 1,171 行 · 第 1/4 页

H
1,171
字号
/* ###########################################################################
###  Intel Confidential 
###  Copyright (c) Intel Corporation 1995-2002
###  All Rights Reserved.
###  -------------------------------------------------------------------------
###  Project: Flash Data Integrator
###
###  Module: FDI_INT.H - This module consists of all the internal FDI control 
###                      struct definitions and function prototypes required.
###
###  $Archive: /FDI/SRC/INCLUDE/fdi_int.h $
###  $Revision: 172 $
###  $Date: 10/15/04 12:06p $
###  $Author: Wtiso $
###  $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.                             
 *****************************************************************
 */
 

#ifndef __FDI_INT_H                   /* sentry header */
#define __FDI_INT_H

/* ### Include Files
 * ################################# */
/* E.5.0.690 Begin */ 
/*remove fdi_lowl.h,fdi_que.h,fdi_err.h, add fdi_type,h */
#include "FDI_type.h"
/* E.5.0.690 End */ 
/* ### Definitions
 * ################################# */

typedef WORD            IDTYPE;          /* data identifier type used in FDI */

#define  BYTEMAX        0xff
#define  WORDMAX        0xffff
#define  DWORDMAX       0xffffffff
#define  NOTUSED        WORDMAX
/* number of bytes from the bottom of flash that the FDV resides in */
#define  FDV_RELATIVE_ADDRESS       ((DWORD)(FDV_START_ADDRESS - \
                                             FLASH_START_ADDRESS))

/* 
 * maximum number of UNIT_GRANULARITY before data is broken up into
 * smaller fragments
 */
#define MAX_NUM_UNITS_PER_FRAG         1
 
#if (PACKET_DATA == TRUE)
#define PACKETNPLRTEST               FALSE
#endif
/*
 * Use this define in the TO_BYTE() macro
 * "<< GRAN_SHIFT" rather than "* UNIT_GRANULARITY"
 */
#if (UNIT_GRANULARITY ==     16)
#define GRAN_SHIFT    4
#elif (UNIT_GRANULARITY ==   32)
#define GRAN_SHIFT    5
#elif (UNIT_GRANULARITY ==   64)
#define GRAN_SHIFT    6
#elif (UNIT_GRANULARITY ==  128)
#define GRAN_SHIFT    7       
#elif (UNIT_GRANULARITY ==  256)
#define GRAN_SHIFT    8
#elif (UNIT_GRANULARITY ==  512)
#define GRAN_SHIFT    9
#elif (UNIT_GRANULARITY == 1024)
#define GRAN_SHIFT   10
#elif (UNIT_GRANULARITY == 2048)
#define GRAN_SHIFT   11
#elif (UNIT_GRANULARITY == 4096)
#define GRAN_SHIFT   12
#elif (UNIT_GRANULARITY == 8192)
#define GRAN_SHIFT   13
#else
#error UNIT_GRANULARITY > 8192 OR < 16 OR not 2**n !!
#endif /* UNIT_GRANULARITY */

#define  SEM_NULL             NULL     /* change for semaphore type SEM_ID */

#define  NIBBLE               4   
#define  BADSTUFF             -1
#define  EVEN_NIBBLE(x)       ((x) % 2 == 0)
#define  ODD_NIBBLE(x)        ((x) % 2 == 1)
#define  NIBBLE_LOW(x)        (BYTE)((x)&0x0f)
#define  NIBBLE_HIGH(x)       (BYTE)(((x)>>NIBBLE)&0x0f)
#define  BYTE_HIGH(x)         (BYTE)(((x)>>8)&0xff)
#define  BYTE_LOW(x)          (BYTE)((x) & 0xff)
#define  WORD_HIGH(x)         (WORD)(((x)>>16)&0xffff))
#define  WORD_LOW(x)          (WORD)((x)&0xffff)
#define  BYTEMASK(high,low)   (BYTE)(((high)<<NIBBLE) | ((low)&0x0f))
#define  WORDMASK(high,low)   (WORD)(((high)<<8)|((low)&0xff))
#define  DWORDMASK(high,low)  (DWORD)(((high)<<16)|((low)&0xffff))
#define  BLOCK_ADDRESS(x)     ((DWORD)(x)*(DWORD)FDV_BLOCK_SIZE+\
                                FDV_RELATIVE_ADDRESS)
#define  TO_BYTES(a)          ((a)<<GRAN_SHIFT)
/* E 5.1.849 START */
#define  TO_GRAN(a)           ((WORD)((WORD)((a)>>GRAN_SHIFT)+\
                               ((((a)&(UNIT_GRANULARITY-1))!=0)?1:0)))
/* E 5.1.849 END */                               
#define  TO_SIZE(a,b)         ((WORD)(((a)/(b))+((((a)%(b))!=0)?1:0)))

#define  OPEN_STREAM_FLAG     2 /* bitmask value for OpenStream use */

/* E.5.1.759 Begin */
#define FDI_MAX_FRAG_SIZE            (UNIT_GRANULARITY*MAX_NUM_UNITS_PER_FRAG)
/* E.5.1.759 End */

/*E.5.5.946 Begin*/
#ifdef  INCLUDE_FRAGMENTED_DATA
#error  "Please remove the definition in FDI_type.h" 
#endif
#undef  INCLUDE_FRAGMENTED_DATA 
#define INCLUDE_FRAGMENTED_DATA     TRUE
/*E.5.5.946 END*/
/*
 * For data streaming we must use the include fragmented data define
 */
#if (DATA_STREAM == TRUE)
#undef INCLUDE_FRAGMENTED_DATA
#define INCLUDE_FRAGMENTED_DATA  TRUE
#endif /* DATA_STREAM */

/* 
 * The following is used to increase the allowable open params array size
 * to the sum of OPEN_ARRAY_SIZE and NUM_OPEN_FILES to guarantee the
 * File Open operations from the file manager as well as the direct FDI calls
 */

#ifndef FILE_MANAGER
  #define FILE_MANAGER    FALSE
#endif

#if(FILE_MANAGER == TRUE)
  #define   OPEN_ARRAY_SIZE  (NUM_OPEN_PARAMS + NUM_OPEN_FILES)
#else
  #define   OPEN_ARRAY_SIZE   NUM_OPEN_PARAMS
#endif

#define SET_LAST_HEADER_OFFSET(block, hdr_addr)   \
      (FDI_LogicalBlockTable[(block)].last_header_offset = \
      (WORD)(((hdr_addr)-FIRST_HEADER_OFFSET)/(sizeof(UNIT_HEADER))))

#define LAST_HEADER_OFFSET(block)  \
      (((DWORD)(FDI_LogicalBlockTable[(block)].last_header_offset) * \
      (DWORD)(sizeof(UNIT_HEADER))) + FIRST_HEADER_OFFSET)

/* Used to set all fields of a DLT entry. */
#if (CONSISTENT_ACCESS_TIME == TRUE)

/* if the input header offset is DWORDMAX, the header index will be set to
 * WORDMAX, which means the index is empty */
 
#define SET_LOOKUP_TABLE( type, id,  block, hdr_offset, stream ) \
        { \
           (FDI_DataLookupPtrTable[(type)]+(id))->logical_blk_num = (block);\
           if((hdr_offset) != DWORDMAX)\
           {\
              (FDI_DataLookupPtrTable[(type)] + (id))->hdr_index = \
              (WORD)(((hdr_offset)-FIRST_HEADER_OFFSET)/sizeof(UNIT_HEADER));\
           }\
           else\
           {\
              (FDI_DataLookupPtrTable[(type)] + (id))->hdr_index = WORDMAX;\
           }\
           (FDI_DataLookupPtrTable[(type)]+(id))->open_stream_index=(stream);\
           (FDI_DataLookupPtrTable[(type)]+(id))->paraExist = 0; \
           (FDI_DataLookupPtrTable[(type)]+(id))->delete_pending = BYTEMAX; \
        }
#else
#define SET_LOOKUP_TABLE(id, block, stream, type) \
        { \
           (FDI_DataLookupPtrTable[(type)]+(id))->logical_blk_num = (block); \
           (FDI_DataLookupPtrTable[(type)]+(id))->open_stream_index=(stream);\
           (FDI_DataLookupPtrTable[(type)]+(id))->paraExist = 0; \
           (FDI_DataLookupPtrTable[(type)]+(id))->delete_pending = BYTEMAX; \
        }
#endif

/* Used to get the logical block number from a DLT entry. */
#define LOOKUP_TABLE_BLOCK(type, id) \
          ((WORD)((FDI_DataLookupPtrTable[(type)] + (id))->logical_blk_num))

/* Used to initialize all fields of a DLT entry. */
#if (CONSISTENT_ACCESS_TIME == TRUE)
#define INIT_LOOKUP_TABLE(type, id) \
        { \
           (FDI_DataLookupPtrTable[(type)]+(id))->logical_blk_num = WORDMAX;\
           (FDI_DataLookupPtrTable[(type)]+(id))->hdr_index = WORDMAX; \
           (FDI_DataLookupPtrTable[(type)]+(id))->open_stream_index=BYTEMAX;\
           (FDI_DataLookupPtrTable[(type)]+(id))->paraExist = BYTEMAX; \
           (FDI_DataLookupPtrTable[(type)]+(id))->delete_pending = BYTEMAX; \
        }
#else
#define INIT_LOOKUP_TABLE(type, id) \
        { \
           (FDI_DataLookupPtrTable[(type)]+(id))->logical_blk_num = WORDMAX;\
           (FDI_DataLookupPtrTable[(type)]+(id))->open_stream_index=BYTEMAX;\
           (FDI_DataLookupPtrTable[(type)]+(id))->paraExist = BYTEMAX; \
           (FDI_DataLookupPtrTable[(type)]+(id))->delete_pending = BYTEMAX; \
        }
#endif

/* Used to test if a DLT entry is empty, it returns TRUE if a DLT entry empty.
 * Can't check just the paramexists field because fdi_delete fails if only
 * exists field is checked.  Not sure why. This needs to be investigated.
*/
#define EMPTY_LOOKUP_TABLE(type, id) \
       (((FDI_DataLookupPtrTable[(type)]+(id))->paraExist == BYTEMAX ) &&\
       ((FDI_DataLookupPtrTable[(type)]+(id))->logical_blk_num==WORDMAX) &&\
       ((FDI_DataLookupPtrTable[(type)]+(id))->open_stream_index==BYTEMAX) &&\
       ((FDI_DataLookupPtrTable[(type)]+(id))->delete_pending==BYTEMAX)) 


/* Used to test if the logical block number field of a DLT entry is empty,
 * it returns TRUE if logical block entry is empty. i.e. WORDMAX */
#define NO_LOOKUP_TABLE_BLOCK(type, id) \
          ((FDI_DataLookupPtrTable[(type)] + (id))->logical_blk_num == WORDMAX)

/* Used to test if a DLT entry is not empty, it returns TRUE if the entry
 * is not empty. */
#define NOT_EMPTY_LOOKUP_TABLE(type, id) \
          (((FDI_DataLookupPtrTable[(type)]+(id))->paraExist == 0 ) || \
          ((FDI_DataLookupPtrTable[(type)]+(id))->logical_blk_num != WORDMAX))
        
/* Used to get the open stream field of a DLT entry. */
#define LOOKUP_TABLE_OSFIELD(type, id) \
          ((BYTE)((FDI_DataLookupPtrTable[(type)] + (id))->open_stream_index))

/* Used to set the open stream field of a DLT entry. */
#define SET_LOOKUP_TABLE_OSFIELD(type, id, open) \
          (FDI_DataLookupPtrTable[(type)] + (id))->open_stream_index = (open)

/* Used to clear the open stream field of a DLT entry. */
#define CLEAR_LOOKUP_TABLE_OSFIELD(type, id) \
          (FDI_DataLookupPtrTable[(type)] + (id))->open_stream_index = BYTEMAX

/*Used to check if the OSFIELD of a DLT entry is empty */
#define EMPTY_LOOKUP_TABLE_OSFIELD(type, id) \
    ((FDI_DataLookupPtrTable[(type)] + (id))->open_stream_index == BYTEMAX)

/* Used to set the PE field( i.e. 0: valid; 
 *                           other value: invalid )
 */
#define SET_LOOKUP_TABLE_PEBIT(type, id)  \
          (FDI_DataLookupPtrTable[(type)] + (id))->paraExist = 0

#if (CONSISTENT_ACCESS_TIME == TRUE)
/* Used to set the hdr index field of a DLT entry */
#define SET_LOOKUP_TABLE_HDR(type, id, hdr_offset) \
        if((hdr_offset) != DWORDMAX)\
        {\
           (FDI_DataLookupPtrTable[(type)] + (id))->hdr_index = \
           (WORD)(((hdr_offset)-FIRST_HEADER_OFFSET)/sizeof(UNIT_HEADER));\
        }\
        else\
        {\
           (FDI_DataLookupPtrTable[(type)] + (id))->hdr_index = WORDMAX;\
        }

/* Used to get the hdr offset from a DLT entry */
#define LOOKUP_TABLE_HDR(type, id) \
           (((FDI_DataLookupPtrTable[(type)] + \
           (id))->hdr_index ) * sizeof(UNIT_HEADER) + FIRST_HEADER_OFFSET)

#endif /* end of CONSISTENT_ACCESS_TIME == TRUE */

/* Used to set the delete_pending flag in the lookup table */
#define SET_LOOKUP_TABLE_DELETE_PENDING(type,id) \
	        ((FDI_DataLookupPtrTable[(type)]+(id))->delete_pending = 0)

/* Used to test the delete_pending flag in the lookup table */
/* macro will return TRUE if flag has be set and file is being deleted */
#define TEST_LOOKUP_TABLE_DELETE_PENDING(type,id) \
	        ((FDI_DataLookupPtrTable[(type)]+(id))->delete_pending == 0)

/*
 * calculate the number of instances that fit in this unit: (unit size

⌨️ 快捷键说明

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