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

📄 fdi_ext.c

📁 FDI Intel开发的FLASH文件系统,功能很强大
💻 C
📖 第 1 页 / 共 5 页
字号:
   {
      data_found = 1;
   }


   if (data_found == 1)
   {
      /*
       * the data offset into the data stream(file) being accessed to begin
       * next access
       */

      status = GetDataSize(&size,
                           cmd_cntrl->identifier,
                           cmd_cntrl->type, cmd_cntrl->priority);
      if (status != ERR_NONE)
      {
         /*
          * unlock the global_sem_cntrl_mutex to give others access to the
          * globals
          */
         /* Unlock the API_sem_cntrl_mutex. */
         SEM_MTX_POST(SEM_APIMutexSemaphore);

         return status;
      }

/* E.5.3.878 Start */
      if (cmd_cntrl->sub_command == WRITE_TRUNCATE)
      {
         cmd_cntrl->count = size - cmd_cntrl->offset;
      }
/* E.5.3.878 End */

      if ((cmd_cntrl->sub_command == WRITE_APPEND) ||
#if (PACKET_DATA == TRUE)
          (cmd_cntrl->sub_command == WRITE_RSRVPCKT) ||
#endif /* PACKET_DATA */
          (cmd_cntrl->sub_command == WRITE_RESERVED))
      {

         if ((cmd_cntrl->offset > size) || ((cmd_cntrl->offset == 0) &&
                                            (size != 0)))
         {
            /*
             * unlock the global_sem_cntrl_mutex to give others access to the
             * globals
             */
            /* Unlock the API_sem_cntrl_mutex. */
            SEM_MTX_POST(SEM_APIMutexSemaphore);
            return ERR_PARAM;
         }
         if (size > UNIT_GRANULARITY)
         {

            if (cmd_cntrl->offset <
                ((size - UNIT_GRANULARITY) + ((((size / UNIT_GRANULARITY) +
                                                ((size % UNIT_GRANULARITY != 0) ? 1 : 0)) *
                                               UNIT_GRANULARITY) - size)))
            {
               /*
                * unlock the global_sem_cntrl_mutex to give others access to
                * the globals
                */
               /* Unlock the API_sem_cntrl_mutex. */
               SEM_MTX_POST(SEM_APIMutexSemaphore);

               return ERR_PARAM;
            }
         }
      } else
      {
         if ((cmd_cntrl->offset > size) ||
             ((cmd_cntrl->offset + cmd_cntrl->count) > size))
         {
            /*
             * unlock the global_sem_cntrl_mutex to give others access to the
             * globals
             */
            /* Unlock the API_sem_cntrl_mutex. */
            SEM_MTX_POST(SEM_APIMutexSemaphore);

            return ERR_PARAM;
         }
      }

      if (cmd_cntrl->sub_command == WRITE_TRUNCATE)
      {
         /* Not allow the truncate on multi-instance */
         if (INSTANCES(UNIT_GRANULARITY, size) >= MIN_INSTANCES)
         {
            SEM_MTX_POST(SEM_APIMutexSemaphore);
/* E.5.2.872 Begin */
            return ERR_TRUNCATE;
/* E.5.2.872 End */
         }

         /* Truncating from beginning results in deleting this data */
         if (cmd_cntrl->offset == 0)
         {
            SEM_MTX_POST(SEM_APIMutexSemaphore);

            status = FDI_Delete(cmd_cntrl);

            return status;
         }

         /* If truncted point is inside the last fragment, do nothing */
         temp_size = TO_BYTES(TO_SIZE(cmd_cntrl->offset, UNIT_GRANULARITY));
         if (temp_size == size)
         {
            SEM_MTX_POST(SEM_APIMutexSemaphore);
            return ERR_NONE;
         }

      }
   }


   /*
    * Fillup the local command and data structure buffers to be added in the
    * queue.
    */
   command_buffer.identifier = cmd_cntrl->identifier;
   command_buffer.data_offset = cmd_cntrl->offset;
   command_buffer.sub_command = cmd_cntrl->sub_command;
   command_buffer.priority = cmd_cntrl->priority;
   command_buffer.type = cmd_cntrl->type;
   /* change the truncate offset & size to the UG boundary */
   if ((command_buffer.sub_command == WRITE_TRUNCATE) &&
       ((command_buffer.data_offset % UNIT_GRANULARITY) != 0))
   {
      shift_offset = UNIT_GRANULARITY - (command_buffer.data_offset % UNIT_GRANULARITY);
      command_buffer.data_offset += shift_offset;
   } else
   {
      shift_offset = 0;
   }


   /*
    * if this is not a new data parameter and we are doing an append, but the
    * size is not changing, we are effectively doing a replace which will
    * dirty as much  as it uses. This means we don't need to account for
    * threshold
    */

   if (((command_buffer.sub_command == WRITE_APPEND) ||
#if (PACKET_DATA == TRUE)
        (command_buffer.sub_command == WRITE_RSRVPCKT) ||
#endif /* PACKET_DATA */
        (command_buffer.sub_command == WRITE_RESERVED)) &&
       (command_buffer.data_offset != 0))
   {
      initial_gran = TO_SIZE(command_buffer.data_offset, UNIT_GRANULARITY);
      new_gran = TO_SIZE((command_buffer.data_offset + cmd_cntrl->count), \
                         UNIT_GRANULARITY);
      if (new_gran <= initial_gran)
      {
         append_to_replace_flag = TRUE;
      }
   }

   /*
    * IF there is not enough space available to write this data THEN return
    * ERR_FLASH_FULL immediately
    */

   /* 
    * For truncate operation, we don't need to check space in foreground
    * because after truncate we should have more dirtied space than the 
    * free space needed
    */
   if (command_buffer.sub_command != WRITE_TRUNCATE)
   {
#if (FREE_SPACE_FUNCTIONS == TRUE)
      hw_status = BKGD_CheckForSpace(&command_buffer, (WORD) cmd_cntrl->count,
                                     TRUE,NORMAL_CALCCHK);
#else   /* !FREE_SPACE_FUNCTIONS */
      hw_status = BKGD_CheckForSpace(&command_buffer, (WORD) cmd_cntrl->count,
                                     TRUE);
#endif   /* FREE_SPACE_FUNCTIONS */

      if ( hw_status != HW_ERR_NONE)
      {
         /*
          * unlock the global_sem_cntrl_mutex to give others access to the
          * globals
          */
         SEM_MTX_POST(SEM_APIMutexSemaphore); /* Unlock the API_sem_cntrl_mutex. */
         /* test for different error conditions from CheckForSpace */
         if (hw_status == HW_ERR_PARAM)
         {
            return ERR_PARAM;
         } else if (hw_status == HW_ERR_FLASH_FULL)
         {
            return ERR_FLASH_FULL;
         } else if (hw_status == HW_ERR_WRITE)
         {
            return ERR_MAXITEMSIZE;
         } else
            return ERR_SYSTEM;
      }
   }
   /* Calculate the space need to be updated for the queue */
   else
   {
      command_buffer.gran_needed.frag_needed = 
      TO_SIZE(size, UNIT_GRANULARITY) - TO_SIZE(cmd_cntrl->offset, UNIT_GRANULARITY);
/* E.5.5.993 Start */
      command_buffer.gran_needed.grp_needed = 
          TO_SIZE(TO_SIZE(size, UNIT_GRANULARITY), FDI_ONEGRANGRP_MAX_FRAGS) - 
          TO_SIZE(TO_SIZE(cmd_cntrl->offset, UNIT_GRANULARITY), 
                  FDI_ONEGRANGRP_MAX_FRAGS);
      command_buffer.gran_needed.seq_needed = 
          TO_SIZE(command_buffer.gran_needed.frag_needed, MAX_SEQ_ENTRY);
/* E.5.5.993 End */
   }

   SEM_MTX_WAIT(SEM_LookupTable);

   /*
    * Pass the pointer to command control structure, through the q_add routine
    * that adds the structure to the queue.
    */
   q_status = Q_Add((Q_ID) FDI_QueueIdentifier, (VOID_PTR) & command_buffer,
                    (VOID_PTR) cmd_cntrl->buffer_ptr, (WORD) sizeof(COMMAND),
                    (WORD) (cmd_cntrl->count-shift_offset), cmd_cntrl->priority,
                    append_to_replace_flag);

   if(cmd_cntrl->sub_command == WRITE_TRUNCATE)
   {
      cmd_cntrl->count = truncate_count;
   }

   if (q_status != Q_ERR_NONE)
   {
      /*
       * unlock the global_sem_cntrl_mutex to give others access to the
       * globals
       */
      SEM_MTX_POST(SEM_LookupTable);
      /* Unlock the API_sem_cntrl_mutex. */
      SEM_MTX_POST(SEM_APIMutexSemaphore);
      if (q_status != Q_ERR_NO_MEMORY)
      {

         if (q_status == Q_ERR_PARAM)
         {

            return ERR_PARAM;
         }
         return ERR_Q_FULL;
      } else
      {

         return ERR_SYSTEM;
      }
   }

   if ((cmd_cntrl->sub_command == WRITE_APPEND) ||
#if (PACKET_DATA == TRUE)
       (cmd_cntrl->sub_command == WRITE_RSRVPCKT) ||
#endif /* PACKET_DATA */
       (cmd_cntrl->sub_command == WRITE_TRUNCATE) ||
       (cmd_cntrl->sub_command == WRITE_RESERVED))
   {
      /*
       * IF we are using open
       * THEN set the FDI_OpenTotalSize global variable
       */
      SEM_MTX_WAIT(SEM_LookupTable);
      size =
      (DWORD)LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->identifier);

      SEM_MTX_POST(SEM_LookupTable);
      if ((BYTE)size != BYTEMAX)
      {
         SEM_MTX_WAIT(SEM_TotalSize);

         if((cmd_cntrl->sub_command == WRITE_TRUNCATE))
         {
            FDI_OpenTotalSize[LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->identifier)]
            = cmd_cntrl->offset;
         }
         else
         {
         FDI_OpenTotalSize[LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->identifier)]
         = cmd_cntrl->offset + cmd_cntrl->count;
/* E.5.0.629 Begin */
         /* 
          * For multi-instance, FDI_OpenTotalSize would be the acutal data size,
          * for single instance/fragment data, it should be UG aligned
          */
         if (((cmd_cntrl->offset != 0) ||
              (INSTANCES(UNIT_GRANULARITY, cmd_cntrl->count) < MIN_INSTANCES)) &&
             (((cmd_cntrl->offset + cmd_cntrl->count) % UNIT_GRANULARITY) != 0))
         /* E.5.0.629 End */
         {
            FDI_OpenTotalSize[LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->identifier)] +=
            GRAN_REMAINING(cmd_cntrl->offset +
                           cmd_cntrl->count);
         }
         }
         SEM_MTX_POST(SEM_TotalSize);
      }
   }

   /*
    * are there any race conditions by incrementing q sizes after releasing
    * the queue semaphore
    */
   /* as above then changing to FType? */
   if (((cmd_cntrl->sub_command == WRITE_APPEND) ||
#if (PACKET_DATA == TRUE)
        (cmd_cntrl->sub_command == WRITE_RSRVPCKT ) ||
#endif /* PACKET_DATA */
        (cmd_cntrl->sub_command == WRITE_RESERVED)) && (cmd_cntrl->offset == 0))
   {
      /*
       * use the DLT_FIELD macro to set the lookupTable field
       */

#if (CONSISTENT_ACCESS_TIME == TRUE)
      SET_LOOKUP_TABLE(cmd_cntrl->type, cmd_cntrl->identifier, WORDMAX,\
                       DWORDMAX,\
                       LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->\
                                            identifier));
#else
      SET_LOOKUP_TABLE(cmd_cntrl->identifier, WORDMAX,\
                       LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->\
                                            identifier), cmd_cntrl->type);
#endif

   }

   SEM_MTX_POST(SEM_LookupTable);

   /* unlock the global_sem_cntrl_mutex to give others access to the globals */
   /* 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 write data of size %d is %1.0f usecs \n",
           (int)cmd_cntrl->count,
           ((float)(FDI_APIend.low - FDI_API.low)) * 163.84);

#endif
   logMsg("time to write data of size %d is %d ticks\n",
          (int) cmd_cntrl->count,
          (int) (FDI_APIend.low - FDI_API.low), 0, 0, 0, 0);
#endif

   return ERR_NONE;
}                                      /* END OF FDI_Write */

/*
#############################################################################
### FDI_Delete
###
### DESCRIPTION:
###   FDI_Delete invalidates a data stream or parameter in the flash media.
###   FDI_Delete checks the Open_Param structure to verify that the data
###   has not been opened. FDI_Delete then calls DataFind routine to verify the
###   existence of the data. FDI_Delete calls Q_Add to queue the command
###   information into the RAM buffer.
###
### 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 0xF.
###        cmd_cntrl->priority:
###                         This field is used to indicate the data priority.
###
###    OUT:
###        error                : a descriptiv

⌨️ 快捷键说明

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