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

📄 fdi_pckt.c

📁 FDI Intel开发的FLASH文件系统,功能很强大
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ###########################################################################
###  Intel Confidential
###  Copyright (c) Intel Corporation 1995-2002
###  All Rights Reserved.
###  -------------------------------------------------------------------------
###  Project: Flash Data Integrator
###
###  Module: FDI_Pckt.C - This module is a collection of packet processin
###                       related functions.
###
###  $Archive: /FDI/SRC/FDI/fdi_pckt.c $
###  $Revision: 86 $
###  $Date: 10/14/04 1:57p $
###  $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.                             
 *****************************************************************
 */
 

#define CURRENT_FILE_BEING_COMPILED FDI_PCKT

/* ### Include Files
 * ################################# */

#include "fdi_type.h"
#ifdef CUSTOM_SEM_MTX
#include "fdi_mutx.h"
#endif
#include "fdi_err.h"
#include "fdi_que.h"
#include "fdi_ext.h"
#include "fdi_int.h"
#ifdef TEST_MSGS
#include "logLib.h"
#endif
#ifdef TIMING
#include "comm.h"
#endif
#ifdef writeToFile

   extern FILE *rw;
#endif

/********************************************/

#if (PACKET_DATA == TRUE)

#include "fdi_pckt.h"
#include "fdi_lowl.h"

extern BYTE FDI_InitComplete;
extern WORD NUM_PARMS[];
extern SEM_MTX_ID SEM_APIMutexSemaphore;
extern SEM_MTX_ID  SEM_LookupTable;
extern DATA_LOOKUP_PTR FDI_DataLookupPtrTable[];

/* E.5.0.652 Begin */
/* E.5.0.591 Begin */
extern ERR_CODE ScanEntryTables(UNIT_HEADER * new_tbl_hdr_ptr,
                DWORD new_tbl_hdr_addr,
                WORD current_index,
                WORD index,
                WORD seq_tbl_number);
/* E.5.0.591 End */
/* E.5.0.652 End */

#ifdef TIMING
COMM_TIMESTAMP Pckt_Start;
COMM_TIMESTAMP Pckt_End;
#endif


/*
 * Defines for local use
 */

/* #define   PCKTDBG_INJECTION_1 */
             /* for error handling debug in FDI_InitPacket, use to simulate
                the FDI_Write error */

/* define global variable for FDI_OPEN_PACKET struct */
FDI_OPEN_PACKET  FDI_Pckt;
static ERR_CODE  ScanPcktDataEntryTable (WORD identifier,BYTE type);
static ERR_CODE  DeletePcktData (WORD identifier,BYTE type);

#if (OPTIMAL_TASKDELAY == TRUE) /* OPTIMAL_TASKDELAY */
SEM_ID SEM_QueueEmpty=SEM_NULL;
#endif /* OPTIMAL_TASKDELAY */

/*
#############################################################################
### FDI_WritePacket()
###
### DESCRIPTION:
###    Wrapper function for FDI_LowLevelWritePacket in FDI_Lowl.c.
###    FDI_LowLevelWritePacket gets downloaded to RAM like the other LowLevel
###    functions, however, since it is a foreground API function, this
###    wrapper is provided to remove the burden from the customer of
###    creating the function pointer.
###
### PARAMETERS:
###    IN:
###        flash_p:     Flash data fragment start address for the write
###                     (retrieved from the tag-RAM).
###                     For ERR_PARAM checking, validate that it is
###                     within the FDI Flash address range.
###        buf_p:       Source buffer pointer of the data to be written.
###                     For ERR_PARAM cheking, validate for non-NULL
###                     pointer and that it is word-aligned.
###        size:        Size of the buffer to be written, in bytes.
###                     For ERR_PARAM checking, validate it is non-zero,
###                     a word-multiple and not greater than size of a packet.
###        FDI_Pckt:    Check ID and InProg for ensuring in packet data processing,
###                     and ensure that size must not be greater than FragSize
###
###    OUT:
###
###
### RETURNS:
###        ERR_NONE   ERR_SYSTEM   ERR_PARAM   ERR_WRITE
###
#############################################################################
*/
ERR_CODE
FDI_WritePacket(volatile WORD_PTR flash_p, WORD_PTR buf_p, WORD size)
{
   return (ERR_CODE)FlashDevWritePacket((BYTE_PTR) buf_p, (DWORD) flash_p, (DWORD) size);
}

/*
#############################################################################
### FDI_InitPacket()
###
### DESCRIPTION:
###    This function reclaim adequate Flash space in preparation for 'count'
###    writes whose packet size is 'size' or less. Once Flash space is
###    available, the function reserve this space for 'count' packets by
###    invoking multiple FDI_Write. Background task performs reservation and
###    stores the flash data fragment pointers in a taf-RAM referenced by
###    'buf_p'. The object to be written is represented by 'identifier' and
###    'type'. A global structure FDI_Pckt is used for sharing variables.
###
###
### PARAMETERS:
###    IN:
###        buf_p:        pointer to tag-RAM, which will be loaded with an
###                      array of Flash data fragment pointers. For ERR_PARAM
###                      checking, validate it's a non-NULL pointer. This
###                      pointer is stored in the FDI_Pckt structure.
###
###        size:         maximum size of the flash packets, in bytes. For
###                      ERR_PARAM checking, validate that it is a multiple
###                      of unit granularity not greater than MAX_UNITS_PER_FRAG.
###                      This value represents the data fragment size and is
###                      stored in the FDI_Pckt structure.
###
###        count:        number of packets to be written for the object and is
###                      stored in the FDI_Pckt structure. For ERR_PARAM checking,
###                      validate it is non-zero.
###
###        identifier:   the user identifier of the object to be written. If
###                      the identifier exists, it is deleted and recreated.
###                      For ERR_PARAM checking, validate appropriate range.
###                      The value is stored in the FDI_Pckt structure.
###
###        type:         the user type of the object to be written. For
###                      ERR_PARAM checking, validate appropriate range.
###
###    OUT:
###        error:        a descriptive error code
###        FDI_Pckt:     a global structure to be accessed by the API,
###                      Background and Reclaim tasks.
###
### RETURNS:
###        ERR_NONE  ERR_INIT  ERR_PARAM  ERR_OPEN  ERR_FLASH_FULL
###        ERR_SYSTEM
###
#############################################################################
*/

ERR_CODE
FDI_InitPacket(WORD_PTR *buf_p,
               WORD fragsize,
               WORD count,
               WORD_PTR id,
               BYTE type
              )
{
   BYTE    queuestatus;
   DWORD   TotalPacketObjSize;     /* total size of this packet object */
   DWORD   b_needed_Space;         /* space needed by this packet object */
   DWORD   cur_count;       /* used as dirtyspace's stub in FDI_Statistics
                               and for multiple FDI_Write calls */
   DWORD   MaxWriteBytes;
   DWORD freespace;
/*   DWORD oldfreespace;  */
   COMMAND_CONTROL  cmd_cntrl;
   ERR_CODE status;
   WORD    grp_entries;     /* used to count the sequence table number */
   WORD    g_needed_grpsize;    /* the last GRP header's size */
   WORD    identifier = *id;

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

   /*
    * Check for completion of Initialization and if not yet complete return
    * the proper error code.
    */

   if (FDI_InitComplete != TRUE)
      return ERR_INIT;

#if (PARAM_CHECK == TRUE)
   /*
    * Check to see if the passed in parameters (buf_p count size) are valid.
    * Otherwise return proper error code. Here only check its range and in
    * FDI_Write check in detailed.
    */
   /* E.5.1.759 Begin */
   if ( buf_p == NULL || count == 0 ||
        fragsize > FDI_MAX_FRAG_SIZE  ||
        ((fragsize % UNIT_GRANULARITY) != 0) || (fragsize == 0))
   /* E.5.1.759 End */
      return ERR_PARAM;
  /*
   * Check to see if the passed in parameters ( identifier and type) are valid.
   * Otherwise return proper error code. Here only check its range and in
   * FDI_Write check in detailed.
   */
   if (((identifier >= NUM_PARMS[type]) && (identifier != NEW_DATA_STREAM_ID))||
       (type > MAX_TYPE))
   {
      return ERR_PARAM;
   }
#endif

   /* lock the SEM_APIMutexSemaphore */
   SEM_MTX_WAIT(SEM_APIMutexSemaphore);

   /*
    * Check the FDI_OPEN_PACKET structure only has one instance. If ID is not
    * WORDMAX, then FDI_Pckt is being used by former caller.
    */
   if (FDI_Pckt.ID != WORDMAX )
   {
      SEM_MTX_POST(SEM_APIMutexSemaphore);
      return ERR_OPEN;
   }

   /* Initilize the PacketData Command */
   cmd_cntrl.identifier = identifier ;
   cmd_cntrl.type = type ;
   cmd_cntrl.priority = FDI_PACKETDATA_PRIORITY ;
   TotalPacketObjSize = count * fragsize ;
   b_needed_Space = count * ( fragsize + sizeof(UNIT_HEADER) );
   /* need to add sequence table and GRP table and invalided GRP header */
   grp_entries = TO_SIZE (count,MAX_SEQ_ENTRY);
   /* add the sequence table occupied space */
   b_needed_Space += (grp_entries*(UNIT_GRANULARITY+sizeof(UNIT_HEADER)));
   g_needed_grpsize = TO_SIZE (grp_entries,MAX_SEQ_ENTRY);
   /* add the group table occupied space(include dirtied GRP) */
   /* in fact, we can skip the dirtied space due to auto-reclaim,
      but it can only save less space and we have BKGD_CheckForSpace to do
      more accurancy, so in 2.5 we don't conside it */
   /* we have changed the BKGD_CheckForSpace and now it can gurantee that
      every time the FDI_Write will only need 1 more granularity for GRP
      table, so the dirtied GRP can be reclaimed.

   for (cur_count=1; cur_count<=g_needed_grpsize; cur_count++) {
      b_needed_Space += (cur_count*UNIT_GRANULARITY+sizeof(UNIT_HEADER));
   }
   */
   b_needed_Space += (g_needed_grpsize*UNIT_GRANULARITY+sizeof(UNIT_HEADER));

   /*
    * Verify the Packetdata with the same identifier and type exists. If
    * existing, Delete it.
    */
   status = DataFind(identifier, type, GET_MATCHED);
   if ( status == ERR_NONE)
   {
      /*
       * Check FDI Queue status. If Queue status is empty, then continue;
       * or else wait for Queue become empty using the TaskDelay function in
       * Tornado lib.
       */
      /* to prevent FDI_Delete encounter ERR_Q_FULL */
      FDI_WAIT_FORQUEUE_EMPTY(queuestatus);
      /*
       * Parameters needed for FDI_Delete:
        *      cmd_cntrl.identifier
        *      cmd_cntrl.type
        *      cmd_cntrl.priority
        */
      status = FDI_Delete(&cmd_cntrl);
      if (status != ERR_NONE)
      {
       /* Unlock the SEM_APIMutexSemaphore. */
       SEM_MTX_POST(SEM_APIMutexSemaphore);
       return status;
      }
   }

   /*
    * Check FDI Queue status. If Queue status is empty, then continue;
    * or else wait for Queue become empty using the TaskDelay function in
    * Tornado lib.
    */
   FDI_WAIT_FORQUEUE_EMPTY(queuestatus);
   /* may have reclaim task actived by background task , wait for its done*/
   FDI_WAIT_FORRECLM_DONE;

   /*
    * Check if has enough space for PacketData to write. If not, reclaim and
    * check again. If not available space to reclaim, then return ERR_FLASH_FULL.
    */

   FDI_Statistics(&freespace, &cur_count);
   if ( freespace + cur_count < b_needed_Space )
   {
       /* Unlock the SEM_APIMutexSemaphore. */
       SEM_MTX_POST(SEM_APIMutexSemaphore);
       return ERR_FLASH_FULL;
   }

   /* invoke the FDI_open */
   cmd_cntrl.sub_command = OPEN_CREATE ;
   cmd_cntrl.aux = FALSE ;
   /* force DATA_STREAMING = TRUE, for loose threshold decision in BKGD_Task */

   /*
    * Parameters needed for FDI_Open:
    *      cmd_cntrl.identifier
    *      cmd_cntrl.type
    *      cmd_cntrl.sub_command
    */
   status = FDI_Open(&cmd_cntrl);
   if (status != ERR_NONE)
   {
      /* Unlock the SEM_APIMutexSemaphore. */
      SEM_MTX_POST(SEM_APIMutexSemaphore);
      return status;
   }

   /* Initilize the FDI_Pckt structure */
   FDI_Pckt.ID = cmd_cntrl.identifier ;
   FDI_Pckt.type = cmd_cntrl.type;
   FDI_Pckt.FragSize = fragsize ;
   FDI_Pckt.TagRAMp = buf_p ;
   FDI_Pckt.Count = 0 ;

   *id = cmd_cntrl.identifier;

   /* Add WRITE_RSRVPCKT subcommand into queue to let background task to execute */

   /*
    * Parameters needed for FDI_Write:
    *      cmd_cntrl.identifier
    *      cmd_cntrl.type
    *      cmd_cntrl.sub_command
    *      cmd_cntrl.buffer_ptr
    *      cmd_cntrl.count
    *      cmd_cntrl.offset
    *      cmd_cntrl.priority
    */

   /* call FDI_Write several times for allocating space for packet object greater than 64KB */
   cmd_cntrl.sub_command = WRITE_RSRVPCKT ;

⌨️ 快捷键说明

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