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

📄 fdi_ext.c

📁 FDI Intel开发的FLASH文件系统,功能很强大
💻 C
📖 第 1 页 / 共 5 页
字号:
/* ###########################################################################
###  Intel Confidential
###  Copyright (c) Intel Corporation 1995-2002
###  All Rights Reserved.
###  -------------------------------------------------------------------------
###  Project: Flash Data Integrator
###
###  Module: FDI_EXT.C - This module is a collection of all the FDI
###                      API functions.
###
###  $Archive: /FDI/SRC/FDI/fdi_ext.c $
###  $Revision: 232 $
###  $Date: 10/21/04 11:39a $
###  $Author: Pcmcgint $
###  $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.                             
 *****************************************************************
 */


#define CURRENT_FILE_BEING_COMPILED FDI_EXT

/* ### Include Files
######################## */
/* ################################# */
/* E.5.0.690 Begin */ 
/*remove include  fdi_type.h*/
/*#include "fdi_type.h"*/
/* E.5.0.690 End */ 
#include "fdi_ext.h"
#include "fdi_lowl.h"
#ifdef CUSTOM_SEM_MTX
   #include "fdi_mutx.h"
#endif

/* E.5.0.690 Begin */ 
/*remove include  fdi_int.h*/
/*#include "fdi_ext.h"
#include "fdi_int.h"*/
/* E.5.0.690 End */ 
#include "fdi_que.h"
#ifdef TIMING
   #include "comm.h"
   #include "logLib.h"
#else
   #ifdef TEST_MSGS
      #include "logLib.h"
   #endif
#endif

/* E.5.1.513 */

#if (PACKET_DATA == TRUE)
   #include "fdi_pckt.h"
#endif /* PACKET_DATA */
extern SEM_MTX_ID  SEM_AccumSize_Mutex;

#ifdef writeToFile
extern FILE *rw;
#endif


/* ### Local Declarations
######################## */
#define SEM_ERROR          -1

/* E5.0.587 START */
#define LOCK_BITMASK                 CREATE_COMMAND(0x03)
#define BLOCK_UNLOCKED               CREATE_COMMAND(0x00)
#define BLOCK_LOCKED                 CREATE_COMMAND(0x01)

/* E.5.1.812 START */
#define BLOCK_LOCKEDDOWN_UNLOCKED   CREATE_COMMAND(0x02)

/* E.5.1.812 END */
#define BLOCK_LOCKEDDOWN             CREATE_COMMAND(0x03)

/* E5.0.587 END */


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


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

DWORD FDI_OpenTotalSize[OPEN_ARRAY_SIZE]; /* tracks open fragmented size for all open params*/

SEM_MTX_ID  SEM_TotalSize = SEM_NULL;  /* protects the FDI_OpenTotalSize var */
SEM_MTX_ID  SEM_APIMutexSemaphore;
SEM_MTX_ID  SEM_OpenStream;            /* semaphore for Open Stream structure
                                        * access */
extern SEM_MTX_ID  SEM_LookupTable;    /* semaphore for lookup table access */
extern SEM_ID RECL_Enable; /* RECL_Request, RECL_Done; */

#if (PERF_TEST == TRUE)
extern SEM_ID PERF_SEM_Bkgd;
#endif

OPEN_PARAM FDI_OpenParam[OPEN_ARRAY_SIZE];
extern DATA_LOCATION FDI_GetDataFound;
/* Array of MAX ID values used for determining number of allowable data
 * items (identifiers) for each data type.
 */
WORD NUM_PARMS[MAX_TYPE+1] =
{
   NUM_TYPE0_PARMS,  /* max IDs, type 0  */
   NUM_TYPE1_PARMS,  /* max IDs, type 1  */
   NUM_TYPE2_PARMS,  /* max IDs, type 2  */
   NUM_TYPE3_PARMS,  /* max IDs, type 3  */
   NUM_TYPE4_PARMS,  /* max IDs, type 4  */
   NUM_TYPE5_PARMS,  /* max IDs, type 5  */
   NUM_TYPE6_PARMS,  /* max IDs, type 6  */
   NUM_TYPE7_PARMS,  /* max IDs, type 7  */
   NUM_TYPE8_PARMS,  /* max IDs, type 8  */
   NUM_TYPE9_PARMS,  /* max IDs, type 9  */
   NUM_TYPE10_PARMS, /* max IDs, type 10 */
   NUM_TYPE11_PARMS, /* max IDs, type 11 */
   NUM_TYPE12_PARMS, /* max IDs, type 12 */
   NUM_TYPE13_PARMS, /* max IDs, type 13 */
   (NUM_TYPE14_PARMS + 1) /* max IDs, type 14 */
};

/* Each array definition below is an array of identifiers.
 * There is one array for each data type.
 */
DATA_LOOKUP FDI_DataLookupTable_0[NUM_TYPE0_PARMS+1];
DATA_LOOKUP FDI_DataLookupTable_1[NUM_TYPE1_PARMS+1];
DATA_LOOKUP FDI_DataLookupTable_2[NUM_TYPE2_PARMS+1];
DATA_LOOKUP FDI_DataLookupTable_3[NUM_TYPE3_PARMS+1];
DATA_LOOKUP FDI_DataLookupTable_4[NUM_TYPE4_PARMS+1];
DATA_LOOKUP FDI_DataLookupTable_5[NUM_TYPE5_PARMS+1];
DATA_LOOKUP FDI_DataLookupTable_6[NUM_TYPE6_PARMS+1];
DATA_LOOKUP FDI_DataLookupTable_7[NUM_TYPE7_PARMS+1];
DATA_LOOKUP FDI_DataLookupTable_8[NUM_TYPE8_PARMS+1];
DATA_LOOKUP FDI_DataLookupTable_9[NUM_TYPE9_PARMS+1];
DATA_LOOKUP FDI_DataLookupTable_10[NUM_TYPE10_PARMS+1];
DATA_LOOKUP FDI_DataLookupTable_11[NUM_TYPE11_PARMS+1];
DATA_LOOKUP FDI_DataLookupTable_12[NUM_TYPE12_PARMS+1];
DATA_LOOKUP FDI_DataLookupTable_13[NUM_TYPE13_PARMS+1];
DATA_LOOKUP FDI_DataLookupTable_14[NUM_TYPE14_PARMS+2];


/* Array of pointers.  Each pointer points to an array of identifiers. */
DATA_LOOKUP_PTR FDI_DataLookupPtrTable[MAX_TYPE+1] =
{
   FDI_DataLookupTable_0,
   FDI_DataLookupTable_1,
   FDI_DataLookupTable_2,
   FDI_DataLookupTable_3,
   FDI_DataLookupTable_4,
   FDI_DataLookupTable_5,
   FDI_DataLookupTable_6,
   FDI_DataLookupTable_7,
   FDI_DataLookupTable_8,
   FDI_DataLookupTable_9,
   FDI_DataLookupTable_10,
   FDI_DataLookupTable_11,
   FDI_DataLookupTable_12,
   FDI_DataLookupTable_13,
   FDI_DataLookupTable_14
};

Q_ID FDI_QueueIdentifier;
BYTE FDI_InitComplete = FALSE;


SEM_MTX_ID  SEM_FDIErrorMutex;
SEM_ID SEM_FDIErrorIndicator;
SEM_MTX_ID  SEM_FlashWrite;

/* E5.1.806 START */
/*E5.3.875 START */
/*#if(DIRECT_ACCESS_VOLUME == TRUE)*/
SEM_MTX_ID        SEM_FlashErase; /* Moved from davinit.c */
#if(DIRECT_ACCESS_VOLUME == TRUE)
/*E5.3.875  END */
/* E5.1.811 START */
extern SEM_MTX_ID SEM_DAVReclLock;
extern SEM_MTX_ID SEM_DAVAPILock;
extern SEM_ID     SEM_DAVReclRequest;
/* E5.1.811 END */
#endif /* DIRECT_ACCESS_VOLUME */

/* E5.1.806 END */
/* E5.1.811 START */
#if (FILE_MANAGER == TRUE)
extern SEM_MTX_ID FileAPIMutexSemaphore;
#endif /* FILE_MANAGER */

/* E5.1.811 END */

ERROR_INFO FDI_Error;

#if (FREE_SPACE_FUNCTIONS == TRUE) /* FREE_SPACE_FUNCTIONS */
extern SEM_MTX_ID SEM_BlockTable;
extern LOGICAL_BLOCK FDI_LogicalBlockTable[];
#endif /* FREE_SPACE_FUNCTIONS */

#ifdef TIMING
COMM_TIMESTAMP FDI_API;
COMM_TIMESTAMP FDI_APIend;
#endif


/*
 * If needed (based on configuration options), create space needed by
 * low-level to store the relocated code.
 */
#if (RELOCATE_CODE == TRUE)
   #if (FDI_RAM_START == 0)
      #if (PARTITIONS != SINGLE)
         #define DOWNLOAD_SIZE         3800
      #else /* PARTITIONS == SINGLE */
         #define DOWNLOAD_SIZE         9850
      #endif /* PATITIONS */
static DWORD lowlvlRAMLocation[(DOWNLOAD_SIZE / sizeof(DWORD)) + 1];
   #else /* FDI_RAM_START != 0 */
      #define lowlvlRAMLocation     FDI_RAM_START
   #endif /* FDI_RAM_START */
#endif /* RELOCATE_CODE */



/*
#############################################################################
### FDI_Open
###
### DESCRIPTION:
###   FDI_Open opens a data parameter or stream for reading, editing, or
###   creates a data stream for writing. Only one data parameter
###   or stream can be opened at any given time. FDI_open improves
###   performance when accessing a data stream multiple times by maintaining
###   open stream information in RAM. FDI_open stores the opened data
###   information in the global open_param structure.
###   FDI_open returns an error if the system attempts to open multiple data
###   parameters or streams. FDI_open calls dataFind to determine the
###   existence of data with a matching identifier and type. If data
###   already exists and is being opened for reading or modification, FDI_open
###   updates the open_param structure to point to the beginning or the end of
###   the data stream, based on the operation to be performed. Successive calls
###   to FDI_read or FDI_write by pass the call to dataFind, and thus reducing
###   overhead.
###
### PARAMETERS:
###    IN:
###        cmd_cntrl->sub_command   : This field contains a command to indicate
###                               the data stream opening method:
###                               OPEN_READ: Open for read only.
###                               OPEN_MODIFY: Open for parameter data
###                                            modification.
###                               OPEN_CREATE: Open for writing a new
###                                            parameter.
###        cmd_cntrl->identifier: This is a unique data parameter or stream
###           identifier.
###        cmd_cntrl->type      : This field indicates a data type_attribute.
###           The options are:
###                          any value between 0x00 to 0x0F.
###
###    OUT:
###        error                : a descriptive error code
###
### RETURNS:
###        ERR_NONE   ERR_OPEN   ERR_EXISTS   ERR_NOTEXISTS   ERR_PARAM
###
*/

ERR_CODE
FDI_Open(CMD_CNTRL_PTR cmd_cntrl)
{

   UNIT_HEADER unit_header_information;
#if (INCLUDE_FRAGMENTED_DATA == TRUE)
   ENTRY_TABLE table;
#endif
   DWORD unit_address;
   BYTE MOF_index;
   /*E.5.0.718.START*/
   WORD id_index;
   /*E.5.0.718.END*/
#if (INCLUDE_FRAGMENTED_DATA == TRUE)
   WORD table_size;
   WORD dummy_word;
   WORD block;
   DWORD index;
#endif
   ERR_CODE status;
   HW_ERROR hw_status;

   BYTE start;

#ifdef TIMING

   /* Get timestamp for start of update */
   COMM_getTimestamp((COMM_TIMESTAMP *) & FDI_API);
#endif

   /*
    * Check for completion of Initialization and if not yet complete return
    * the proper error code.
    */
   if (FDI_InitComplete != TRUE)
   {
      return ERR_INIT;
   }
   /*
    * Check to see if the passed in parameters are valid. Otherwise return
    * proper error code.
    */
   if (((cmd_cntrl->identifier == NEW_DATA_STREAM_ID) &&
        (cmd_cntrl->sub_command != OPEN_CREATE)) ||
       (cmd_cntrl->type > MAX_TYPE) ||
       ( NUM_PARMS[cmd_cntrl->type] == 0 ) ||
       ((cmd_cntrl->identifier >= NUM_PARMS[cmd_cntrl->type])&&
        (cmd_cntrl->identifier != NEW_DATA_STREAM_ID)) ||
       ((cmd_cntrl->identifier == ERASE_COUNT_ID) &&
        (cmd_cntrl->type == ERASE_COUNT_TYPE))||
       ((cmd_cntrl->sub_command != OPEN_CREATE) &&
        (cmd_cntrl->sub_command != OPEN_MODIFY) &&
        (cmd_cntrl->sub_command != OPEN_READ)) ||
       (cmd_cntrl->priority < FDI_MIN_PRIORITY) ||
       (cmd_cntrl->priority > FDI_MAX_PRIORITY)
#if (DATA_STREAM == TRUE)
       ||
       ((cmd_cntrl->aux != TRUE ) &&
        (cmd_cntrl->aux != FALSE))
#endif
      )
   {
      return ERR_PARAM;
   }
   /* lock the API_sem_cntrl_mutex. */
   SEM_MTX_WAIT(SEM_APIMutexSemaphore);

   /* lock the global_sem_cntrl_mutex. */
   SEM_MTX_WAIT(SEM_OpenStream);

   /*
    * Check to see if a data parameter or stream is already open and return
    * proper error code.
    */

   if (cmd_cntrl->identifier != NEW_DATA_STREAM_ID)
   {
      if (!EMPTY_LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->identifier) )
      {
         /*
          * unlock the global_sem_cntrl_mutex to give others access to the
          * globals
          */
         SEM_MTX_POST(SEM_OpenStream);
         /* Unlock the API_sem_cntrl_mutex. */
         SEM_MTX_POST(SEM_APIMutexSemaphore);
         return ERR_OPEN;
      }
   }




#if (PACKET_DATA == TRUE)
   /* when packet data is in progress give PCKTID_MUTEX error */
   if ( FDI_Pckt.ID != WORDMAX && FDI_Pckt.ID == cmd_cntrl->identifier &&
        FDI_Pckt.type == cmd_cntrl->type)
   {
      SEM_MTX_POST(SEM_OpenStream);
      SEM_MTX_POST(SEM_APIMutexSemaphore);
      return ERR_PCKTID_MUTEX;
   }

⌨️ 快捷键说明

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