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

📄 fdi_bkgd.c

📁 Flash file system
💻 C
📖 第 1 页 / 共 5 页
字号:
               }
#endif  /* PACKET_DATA */
               SEM_POST(RECL_Enable);     /* enable reclaim to begin */
#ifdef TEST_MSGS
               logMsg("Reclaim ENABLED before, needed %d, free %d, "
                      "spare %d\n", needed_space, (int) total_free,
                      FDI_SpareBlock, 0, 0, 0);
#endif
               /* Check if free space enough to hold all
                * objects of this queue item
                */
               if( status == HW_ERR_FLASH_FULL )
               {
                  prev_free = 0;
                  /*
                   * simulate write sub functions to
                   * make sure there is enough free space
                   */
                  status=BKGD_CheckFreeSpace(cmd_ptr);

                  /* Reclaim untill there is enought free space to write */
                  while( status != HW_ERR_NONE )
                  {
                     SEM_WAIT(RECL_Done);
                     total_free = BKGD_GetTotalSpace(FREE_UNITS);
                     total_dirty = BKGD_GetTotalSpace(DIRTY_UNITS);

                     /* Check again thereis enough free space */
                     status=BKGD_CheckFreeSpace(cmd_ptr);
                     if( status == HW_ERR_NONE )
                     {
                        break;
                     }

                     /*
                      * If the total_dirty is zero and nothing
                      * to be reclaimed, return  flash full error.
                      */
                     if ((total_free == prev_free) &&
                        ((total_dirty == (UNIT_GRANULARITY+sizeof(UNIT_HEADER)))||
                        (total_dirty == 0)))
                     {
                        FDI_HandleError(HW_ERR_FLASH_FULL);
                        /*BKGD_TaskId = 0;*//*commented by jjs*/
                        return;
                     }
                     prev_free = total_free;
#if (PACKET_DATA == TRUE)              /* PACKET_DATA */
                     if( FDI_Pckt.ID != WORDMAX )
                     {
                        FDI_RESET_RECLMSTATE;      /* for reclaim solution */
                     }
#endif  /* PACKET_DATA */
                     SEM_POST(RECL_Enable);     /* enable reclaim to begin */
                  }
               } /* End of status == ERR_FLASH_FULL */
            }                             /* ENDIF total_free < SYSTEM_THRESH */
            else
            {
               prev_free = 0;
               while ((total_free < SYSTEM_THRESHOLD) ||
                      (status == HW_ERR_FLASH_FULL))
               {
#if (PACKET_DATA == TRUE)      /* PACKET_DATA */
                  if( FDI_Pckt.ID != WORDMAX )
                  {
                     FDI_WAIT_FORRECLM_DONE;    /* for reclaim solution */
                  }
#endif /* PACKET_DATA */
                  SEM_TRY_WAIT(RECL_Done);   /* reset RECL_Done semaphore */
#if (PACKET_DATA == TRUE)                 /* PACKET_DATA */
                  if( FDI_Pckt.ID != WORDMAX )
                  {
                     FDI_RESET_RECLMSTATE;      /* for reclaim solution */
                  }
#endif /* PACKET_DATA */
                  SEM_POST(RECL_Enable);     /* enable reclaim to begin */
#ifdef TEST_MSGS
                  logMsg("Reclaim ENABLED before, needed %d, free %d, "
                         "spare %d\n", needed_space, (int) total_free,
                         FDI_SpareBlock, 0, 0, 0);
#endif
                  /* IF there is not THEN */
                  if (total_free < FDI_THRESHOLD)
                  {
                     SEM_WAIT(RECL_Done);
                     total_free = BKGD_GetTotalSpace(FREE_UNITS);
                     total_dirty = BKGD_GetTotalSpace(DIRTY_UNITS);

                     /*
                      * If the total_dirty is zero and nothing to be reclaimed,
                      * return  flash full error.
                      */
                     if ((total_free == prev_free) &&
                         ((total_dirty == (UNIT_GRANULARITY+sizeof(UNIT_HEADER)))||
                          (total_dirty == 0)))
                     {
#ifdef TEST_MSGS
                        logMsg("FDI_THRESHOLD free = %d, thres = %d\n",
                               (int) total_free, FDI_THRESHOLD, 0, 0, 0, 0);
#endif
                        FDI_HandleError(HW_ERR_FLASH_FULL);
                        /*BKGD_TaskId = 0;*//*commented by jjs*/
#ifdef TEST_MSGS
                        logMsg("BKGD Task Bailed!\n", 0, 0, 0, 0, 0, 0);
#endif
                        return;
                     }
                  }
                  else if (status == HW_ERR_FLASH_FULL)
                  {
#ifdef TEST_MSGS
                     logMsg("Pending on RECL_Done, needed %d, free %d, dirty %d\n",
                            needed_space, (int) total_free, (int) total_dirty, 0,
                            0, 0);
#endif
                     SEM_WAIT(RECL_Done);
                     total_free = BKGD_GetTotalSpace(FREE_UNITS);
                     total_dirty = BKGD_GetTotalSpace(DIRTY_UNITS);

                     /*
                      * If the total_dirty is zero and nothing to be reclaimed,
                      * return  flash full error.
                      */
                     if ((total_free == prev_free) &&
                         (total_dirty == (UNIT_GRANULARITY+sizeof(UNIT_HEADER))))
                     {
#ifdef TEST_MSGS
                        logMsg("ERR_FLASH_FULL free = %d\n", (int) total_free, 0,
                               0, 0, 0, 0);
#endif
#if (FREE_SPACE_FUNCTIONS == TRUE)
                        status = BKGD_CheckForSpace(cmd_ptr, data_size,
                                                    FALSE,NORMAL_CALCCHK);
#else   /* !FREE_SPACE_FUNCTIONS */
                        status = BKGD_CheckForSpace(cmd_ptr, data_size, FALSE);
#endif   /* FREE_SPACE_FUNCTIONS */
                        FDI_HandleError(HW_ERR_FLASH_FULL);
                        /*BKGD_TaskId = 0;*//*commented by jjs*/
#ifdef TEST_MSGS
                        logMsg("BKGD Task Bailed!\n", 0, 0, 0, 0, 0, 0);
#endif
                        return;
                     }
                     status = HW_ERR_NONE;
                  }
                  else if (status == HW_ERR_NONE)
                  {
                     break;
                  }
                  total_free = BKGD_GetTotalSpace(FREE_UNITS);

                  prev_free = total_free;
#if (FREE_SPACE_FUNCTIONS == TRUE)
                  status = BKGD_CheckForSpace(cmd_ptr, data_size,
                                              FALSE,NORMAL_CALCCHK);
#else   /* !FREE_SPACE_FUNCTIONS */
                  status = BKGD_CheckForSpace(cmd_ptr, data_size, FALSE);
#endif   /* FREE_SPACE_FUNCTIONS */

               }                          /* ENDDO WHILE free <SYSTEM_THRESHOLD */
            }                             /* ENDELSE NOT data streaming */

#else                                  /* !DATA_STREAM */
            prev_free = 0;
            while ((total_free < SYSTEM_THRESHOLD) ||
                   (status == HW_ERR_FLASH_FULL))
            {
#if (PACKET_DATA == TRUE)              /* PACKET_DATA */
               FDI_WAIT_FORRECLM_DONE;    /* for reclaim solution */
#endif /* PACKET_DATA */
               SEM_TRY_WAIT(RECL_Done);   /* reset RECL_Done semaphore */
#if (PACKET_DATA == TRUE)              /* PACKET_DATA */
               FDI_RESET_RECLMSTATE;      /* for reclaim solution */
#endif /* PACKET_DATA */
               SEM_POST(RECL_Enable);     /* enable reclaim to begin */
#ifdef TEST_MSGS
               logMsg("Reclaim ENABLED before, needed %d, free %d, "
                      "spare %d\n", needed_space, (int) total_free,
                      FDI_SpareBlock, 0, 0, 0);
#endif
               /* IF there is not THEN */
               if (total_free < FDI_THRESHOLD)
               {
                  SEM_WAIT(RECL_Done);
                  total_free = BKGD_GetTotalSpace(FREE_UNITS);
                  total_dirty = BKGD_GetTotalSpace(DIRTY_UNITS);

                  /*
                   * If the total_dirty is zero and nothing to be reclaimed,
                   * return  flash full error.
                   */
                  if ((total_free == prev_free) &&
                      (total_dirty == (UNIT_GRANULARITY+sizeof(UNIT_HEADER))))
                  {
#ifdef TEST_MSGS
                     logMsg("FDI_THRESHOLD free = %d, thres = %d\n",
                            (int) total_free, FDI_THRESHOLD, 0, 0, 0, 0);
#endif
                     FDI_HandleError(HW_ERR_FLASH_FULL);
                     /*BKGD_TaskId = 0;*//*commented by jjs*/
#ifdef TEST_MSGS
                        logMsg("BKGD Task Bailed!\n", 0, 0, 0, 0, 0, 0);
#endif
                     return;
                  }
               }
               else if (status == HW_ERR_FLASH_FULL)
               {
#ifdef TEST_MSGS
                  logMsg("Pending on RECL_Done, needed %d, free %d, dirty %d\n",
                         needed_space, (int) total_free, (int) total_dirty, 0, 0,
                         0);
#endif
                  SEM_WAIT(RECL_Done);
                  total_free = BKGD_GetTotalSpace(FREE_UNITS);
                  total_dirty = BKGD_GetTotalSpace(DIRTY_UNITS);

                  /*
                   * If the total_dirty is zero and nothing to be reclaimed,
                   * return  flash full error.
                   */
                  if ((total_free == prev_free) &&
                      (total_dirty == (UNIT_GRANULARITY+sizeof(UNIT_HEADER))))
                  {
#ifdef TEST_MSGS
                     logMsg("ERR_FLASH_FULL free = %d\n", (int) total_free, 0, 0,
                            0, 0, 0);
#endif
                     FDI_HandleError(HW_ERR_FLASH_FULL);
                     /*BKGD_TaskId = 0;*//*commented by jjs*/
#ifdef TEST_MSGS
                        logMsg("BKGD Task Bailed!\n", 0, 0, 0, 0, 0, 0);
#endif
                     return;
                  }
                  status = HW_ERR_NONE;
               }
               else if (status == HW_ERR_NONE)
               {
                  break;
               }
               total_free = BKGD_GetTotalSpace(FREE_UNITS);

               prev_free = total_free;
#if( FREE_SPACE_FUNCTIONS == TRUE)
               status = BKGD_CheckForSpace(cmd_ptr, data_size,
                                           FALSE,NORMAL_CALCCHK);
#else    /* !FREE_SPACE_FUNCTIONS */
               status = BKGD_CheckForSpace(cmd_ptr, data_size, FALSE);
#endif   /* FREE_SPACE_FUNCTIONS */

            }                       /* ENDDO WHILE free <SYSTEM_THRESHOLD */
#endif                              /* !DATA_STREAM */
         }
         else
         {
            status = HW_ERR_NONE;
         }

         if ((status == HW_ERR_NONE) || (status == HW_ERR_SPACE))
         {
#ifdef TEST_MSGS
#if (DATA_STREAM == FALSE)
            logMsg("WriteData siz %d fre %d dty %d id %d off %d\n",
                   data_size, (int) total_free, (int) total_dirty,
                   (int) cmd_ptr->identifier, (int) cmd_ptr->data_offset, 0);
#else
            logMsg("WriteData siz %d fre %d id %d off %d\n",
                   data_size, (int) total_free, (int) cmd_ptr->identifier,
                   (int) cmd_ptr->data_offset, 0, 0);
#endif
#endif
         /* call WriteData to put data into FDI system */
         /* Take the SEM_AccumSize_Mutex semaphore so that there is no foreground access
            to dirty and free space between the time that the logical block table free
            and dirty space is updated and the time that the item is removed from the
            queue, which is when the accum_dirty and accum_free are updated. This will
            ensure that the dirty space is not counted both in the logical block table
            and the accum_dirty field.
         */
            SEM_MTX_WAIT(SEM_AccumSize_Mutex);
            status = WriteData(data_ptr, cmd_ptr->data_offset,
                               cmd_ptr->identifier, data_size, cmd_ptr->type,
                               cmd_ptr->sub_command);
            if (status != HW_ERR_NONE)
            {
               FDI_HandleError(status);

               if ((status != HW_ERR_FLASH_FULL) && (status != HW_ERR_SPACE))
               {
#ifdef TEST_MSGS
                  logMsg("*Write Failed err %d id %d type %d size %d off %d\n",
                         (int) status, cmd_ptr->identifier, cmd_ptr->type,
                         data_size, (int) cmd_ptr->data_offset, 0);
#endif
                  break;               /* must be a hardware error */
               }
               else
               {
#ifdef TEST_MSGS
#if (DATA_STREAM == FALSE)
                  if (status == HW_ERR_FLASH_FULL)
                     logMsg("FLASH FULL, need %d, free %d, dirty %d,"
                            " id %d, type %d\n", needed_space,
                            (int) total_free, (int) total_dirty,
                            cmd_ptr->identifier, cmd_ptr->type, 0);
                  else
                     logMsg("FLASH SPACE, need %d, "
                            "free %d, dirty %d, id %d, type %d\n",
                            needed_space, (int) total_free,
                            (int) total_dirty, cmd_ptr->identifier,
                            cmd_ptr->type, 0);
#else
                  if (status == HW_ERR_FLASH_FULL)
                     logMsg("FLASH FULL, need %d, free %d id %d, type %d\n",
                            needed_space, (int) total_free,
                            cmd_ptr->identifier, cmd_ptr->type, 0, 0);
                  else
                     logMsg("FLASH SPACE, need %d, free %d, id %d, type %d\n",
                            needed_space, (int) total_free,
                            cmd_ptr->identifier, cmd_ptr->type, 0, 0);
#endif
#endif
                  if (status == HW_ERR_FLASH_FULL)
                  {
                     break;
                  }
                  status = HW_ERR_NONE;
               }
            }

            if ((total_free = BKGD_GetTotalSpace(FREE_UNITS)) <
                SYSTEM_THRESHOLD)
            {
#if (PACKET_DATA == TRUE)                 /* PACKET_DATA */
               if( FDI_Pckt.ID != WORDMAX )
               {
                  FDI_WAIT_FORRECLM_DO

⌨️ 快捷键说明

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