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

📄 fdi_ext.c

📁 FDI Intel开发的FLASH文件系统,功能很强大
💻 C
📖 第 1 页 / 共 5 页
字号:
                  MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
                            (DWORD)sizeof(OPEN_PARAM));
                  /*
                   * 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_READ;
               }
               /* need to read the first sequence table's entry for the
                  b_remaining_in_unit value */
               /*
                * the data offset into the sequence table unit being accessed
                * to begin next access
                */
               FDI_OpenParamPtr->b_begin_tabl_offset = index;
               FDI_OpenParamPtr->b_seq_table_entry_offset = index;

               /* Read the sequence table's first entry. */
               hw_status =
               FlashDevRead((BYTE_PTR) & table,
                            FDI_OpenParamPtr->tabl_block_addr + index,
                            sizeof(ENTRY_TABLE));
               if (hw_status != HW_ERR_NONE)
               {

                  /* Clear the Open_Param structure. */
                  MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
                            (DWORD)sizeof(OPEN_PARAM));
                  /*
                   * 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_READ;
               }
               /* the size of the data left remaining in the data unit bytes */
               FDI_OpenParamPtr->b_remaining_in_unit =
               TO_BYTES(table.entry_size);
            } else                       /* OPEN_MODIFY */
            {

               table_size = TO_BYTES(unit_header_information.g_unit_size);
               block = FDI_OpenParamPtr->logical_block;

               /*
                * fill in the group table, sequence table variables
                */

               hw_status = BKGD_GetTableEntry(FDI_OpenParamPtr,
                                              &dummy_word,
                                              (BYTE_PTR) & dummy_word,
                                              &dummy_word,
                                              (BYTE_PTR) & dummy_word,
                                              DWORDMAX,
                                              table_size /
                                              sizeof(ENTRY_TABLE));

               if (hw_status != HW_ERR_NONE)
               {
                  /* Clear the Open_Param structure. */
                  MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
                            (DWORD)sizeof(OPEN_PARAM));
                  /*
                   * 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_READ;
               }

               /* restore the logical_block and b_unit_size fields */
               FDI_OpenParamPtr->logical_block = block;
               FDI_OpenParamPtr->b_unit_size = table_size;

               /* read back last sequence table entry */
               hw_status =
               FlashDevRead((BYTE_PTR) & table,
                            FDI_OpenParamPtr->tabl_block_addr +
                            FDI_OpenParamPtr->b_seq_table_entry_offset,
                            sizeof(ENTRY_TABLE));
               if (hw_status != HW_ERR_NONE)
               {
                  /* Clear the Open_Param structure. */
                  MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
                            (DWORD)sizeof(OPEN_PARAM));
                  /*
                   * 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_READ;
               }
               /* open at the end of the file... */
               FDI_OpenParamPtr->b_current_file_offset =
               FDI_OpenParamPtr->b_total_size;
            }                          /* ENDELSE !OPEN_READ */
         }                             /* ENDIF attribute == ATTR_GRP_TABLE */
#endif                                 /* INCLUDE_FRAGMENTED_DATA */
      }

      else if (hw_status != HW_ERR_EMPTY_LKUP)
      {

         /* Clear the Open_Param structure. */
         MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
                   (DWORD)sizeof(OPEN_PARAM));
         /*
          * 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);
         if (hw_status == HW_ERR_PARAM)
         {
            return ERR_PARAM;
         } else
         {
            return ERR_SYSTEM;
         }
      } else
      {
      	
         /* E.5.3.873 - Begin */
         status = GetDataSize(&(FDI_OpenParamPtr->b_current_file_offset),
                              cmd_cntrl->identifier,
                              cmd_cntrl->type, cmd_cntrl->priority);
         if (status != ERR_NONE)
         {

            /* Clear the Open_Param structure. */
            MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
                      (DWORD)(sizeof(OPEN_PARAM)));
            /*
             * 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 status;
         }

         SEM_MTX_WAIT(SEM_TotalSize);
         FDI_OpenTotalSize[MOF_index] = FDI_OpenParamPtr->b_current_file_offset;
         SEM_MTX_POST(SEM_TotalSize);
         /* E.5.3.873 - End */
         FDI_OpenParamPtr->b_current_file_offset = 0;
         FDI_OpenParamPtr->type_attribute =
         BYTEMASK(cmd_cntrl->type, BYTEMAX);

      }

   }                                   /* end of else. */
   /*
    * Set the OpenStream bit in the DLT.  This bit reserves the associated ID
    * for this open stream in case the DLT is scanned in write.
    */
   SEM_MTX_WAIT(SEM_LookupTable);

   SET_LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->identifier, MOF_index);

   SEM_MTX_POST(SEM_LookupTable);
   SEM_MTX_POST(SEM_OpenStream);

   /* Unlock the API_sem_cntrl_mutex. */
   SEM_MTX_POST(SEM_APIMutexSemaphore);

#ifdef TIMING

   /* Get timestamp for start of update */
   COMM_getTimestamp(&FDI_APIend);
#ifdef writeToFile
   fprintf(rw,"time to open data sub command %d of type %d is %1.0f usecs \n",
           cmd_cntrl->sub_command,cmd_cntrl->type,
           ((float)(FDI_APIend.low - FDI_API.low)) * 163.84);
#endif
   logMsg("time for opening data sub command %d, of type %d is %d ticks\n",
          cmd_cntrl->sub_command, cmd_cntrl->type, (int) (FDI_APIend.low -
                                                          FDI_API.low), 0, 0, 0);
#endif

   /*
    * Opened to create a non_existing data or to read/edit an existing data.
    * Hence, indicate successfull completion of data open to the system
    * function
    */
   return ERR_NONE;

}                                      /* END OF FDI_Open */


/*
#############################################################################
### FDI_Close
###
### DESCRIPTION:
###   FDI_Close closes an open data parameter or stream. FDI_close determines
###   if a data stream or parameter is open.  FDI_close returns an error if
###   no data stream or parameter is open.  FDI_close clears the open_param
###   structure to indicate closing a data stream or parameter.
###
### PARAMETERS:
###    IN:
###        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_CLOSE   ERR_NOTOPEN   ERR_NOTEXISTS   ERR_PARAM
###
*/

/* E.5.0.652 Begin */
ERR_CODE
FDI_Close(COMMAND_CONTROL * cmd_cntrl)
/* E.5.0.652 End */
{
   ERR_CODE status = ERR_NOTOPEN;

#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->type > MAX_TYPE) ||
       (cmd_cntrl->identifier >= NUM_PARMS[cmd_cntrl->type]) ||
       ((cmd_cntrl->identifier == ERASE_COUNT_ID) &&
        (cmd_cntrl->type == ERASE_COUNT_TYPE))||
       (cmd_cntrl->priority < FDI_MIN_PRIORITY) ||
       (cmd_cntrl->priority > FDI_MAX_PRIORITY))
   {
      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. */
   if (!(EMPTY_LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->identifier)))
   {


      status = ERR_NONE;
      /* E.5.3.873 - Begin */
      SEM_MTX_WAIT(SEM_TotalSize);
      FDI_OpenTotalSize[LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, \
                                          cmd_cntrl->identifier)] = 0;
      SEM_MTX_POST(SEM_TotalSize);
      /* E.5.3.873 - End */

      /* Clear the Open_Param structure. */
      FDI_OpenParamPtr =
      &FDI_OpenParam[LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, \
                                          cmd_cntrl->identifier)];
      MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
                (DWORD)sizeof(OPEN_PARAM));
      /*
       * Clear the OpenStream bit in the DLT.  This bit reserves the
       * associated ID for this open stream in case the DLT is scanned in
       * write.
       */
      SEM_MTX_WAIT(SEM_LookupTable);

      CLEAR_LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->identifier);

      SEM_MTX_POST(SEM_LookupTable);
   }


   /* return error if data was not opened previously. */

   /* 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);

#ifdef TIMING

   /* Get timestamp for start of update */
   COMM_getTimestamp(&FDI_APIend);
#ifdef writeToFile
   fprintf(rw,"time to close data %1.0f usecs \n",
           ((float)(FDI_APIend.low - FDI_API.low)) * 163.84);

#endif
   logMsg("time for closing data is %d ticks\n", (int) (FDI_APIend.low -
                                                        FDI_API.low), 0, 0, 0, 0, 0);
#endif

   return status;
}                                      /* END OF FDI_Close */


/*
#############################################################################
### FDI_Get
###
### DESCRIPTION:
###   FDI_Get locates the first or next data parameter or stream of the
###   specified type or it will find a matched data parameter or stream
###   using the type and identifier fields. FDI_get updates theFDI_GetDataFound
###   structure.  FDI_get calls the DataFind routine and fills in
###   the structure FDI_GetDataFound defined from the Data Location
###   structure type. FDI_get uses FDI_GetDataFound to find the next data item
###   of the same type if the input sub-command is GET_NEXT. Once found,FDI_Get
###   calls GetDataSize function, to get the data size and fills in the
###   type_attribute information into the cmd_cntrl->type field and the total
###   data size in the cmd_cntrl->count field.
###
### PARAMETERS:
###    IN:
###        cmd_cntrl->sub_cmd : GET_FIRST:
###                                      finds the first data parameter of
###                                      a given type
###                             GET_NEXT:
###                                      finds the matching  data parameter of
###                                      a given type, priority and identifier
###                             GET_MATCHED: finds the matching  data parameter
###                                      of a given type, priority and
###                                      identifier
###        cmd_cntrl->identifier:   unique data parameter identifier
###        cmd_cntrl->type      : This field indicates a data type_attribute.
###                               The options are:
###                               any value between 0x00 to 0xF.
###
###    OUT:
###        cmd_cntrl->type:  type and attribute
###        cmd_cntrl->count: total data size
###        error:            a descriptive error code
###
### RETURNS:
###        ERR_NONE   ERR_CLOSE   ERR_NOTOPEN   ERR_NOTEXISTS   ERR_PARAM
###
*/

ERR_CODE
FDI_Get(CMD_CNTRL_PTR cmd_cntrl)
{
   BYTE priority;
   ERR_CODE status;

#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.

⌨️ 快捷键说明

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