Ejemplo n.º 1
0
/******************************************************************************
**  Function:  CFE_FS_EarlyInit()
**
**  Purpose:
**    Initialize the FS data structures before the cFE runs.
**
**  Arguments:
**
**  Notes:
**    This function MUST be called before any FS API's are called.
**
**  Return:
**    CFE_SUCCESS
*/
int32 CFE_FS_EarlyInit (void) 
{
    int32 Stat = CFE_SUCCESS;

    Stat = OS_MutSemCreate(&CFE_FS.SharedDataMutexId, "CFE_FS_SharedMutex", 0);
    if( Stat != OS_SUCCESS )
    {
      CFE_ES_WriteToSysLog("FS Shared Data Mutex creation failed! RC=0x%08x\n",Stat);
      return Stat;
    }/* end if */

    return Stat;

}/* end CFE_FS_EarlyInit */
Ejemplo n.º 2
0
/******************************************************************************
**  Function:  CFE_SB_EarlyInit()
**
**  Purpose:
**    Initialize the Software Bus routing tables.
**
**  Arguments:
**
**  Notes:
**    This function MUST be called before any SB API's are called.
**
**  Return:
**    CFE_SUCCESS
*/
int32 CFE_SB_EarlyInit (void) {

    int32 Stat = CFE_SUCCESS;

    CFE_SB_Default_Qos.Priority    = CFE_SB_QOS_LOW_PRIORITY;
    CFE_SB_Default_Qos.Reliability = CFE_SB_QOS_LOW_RELIABILITY;

    Stat = OS_MutSemCreate(&CFE_SB.SharedDataMutexId, "CFE_SB_DataMutex", 0);
    if(Stat != OS_SUCCESS){
      CFE_ES_WriteToSysLog("SB shared data mutex creation failed! RC=0x%08x\n",(unsigned int)Stat);
      return Stat;
    }/* end if */
    
    /* Initialize the state of susbcription reporting */
    CFE_SB.SubscriptionReporting = CFE_SB_DISABLE;

    /* Initialize the state of sender reporting */
    CFE_SB.SenderReporting = CFE_SB_DEFAULT_REPORT_SENDER;

     /* Initialize memory partition. */
    Stat = CFE_SB_InitBuffers();
    if(Stat != CFE_SUCCESS){
      /* error reported in CFE_SB_InitBuffers */
      return Stat;
    }/* end if */

    /* Initialize the pipe table. */
    CFE_SB_InitPipeTbl();

    /* Initialize the routing index look up table */
    CFE_SB_InitMsgMap();

    /* Initialize the routing table. */
    CFE_SB_InitRoutingTbl();
    
    /* Initialize the SB Statistics Pkt */
    CFE_SB_InitMsg(&CFE_SB.StatTlmMsg.Hdr.Pri,
                   CFE_SB_STATS_TLM_MID,
                   sizeof(CFE_SB_StatMsg_t),
                   TRUE);    

   CFE_SB.ZeroCopyTail = NULL;

    return Stat;

}/* end CFE_SB_EarlyInit */
Ejemplo n.º 3
0
/*
** CFE_ES_CreateCDSPool will initialize a pre-allocated memory pool.
*/
int32 CFE_ES_CreateCDSPool(uint32  CDSPoolSize, uint32  StartOffset)
{
    char MutexName[10] = {"CDS_POOL"};
    uint32  i = 0;
    uint32  Size = (CDSPoolSize & 0xfffffffc);

    /* create a semphore to protect this memory pool */
    OS_MutSemCreate(&(CFE_ES_CDSMemPool.MutexId), MutexName, 0);

    /* Take the semaphore to ensure the mem pool is not being used during it's creation */
    OS_MutSemTake(CFE_ES_CDSMemPool.MutexId);

    CFE_ES_CDSMemPool.Start        = StartOffset;
    CFE_ES_CDSMemPool.End          = StartOffset + Size;
    CFE_ES_CDSMemPool.Size         = Size;
    CFE_ES_CDSMemPool.Current      = StartOffset;
    CFE_ES_CDSMemPool.SizeIndex    = -1;

    CFE_ES_CDSMemPool.CheckErrCntr = 0;
    CFE_ES_CDSMemPool.RequestCntr  = 0;

    for (i=0; i<CFE_ES_CDS_NUM_BLOCK_SIZES; i++)
    {
        CFE_ES_CDSMemPool.SizeDesc[i].Top = 0;
        CFE_ES_CDSMemPool.SizeDesc[i].NumCreated = 0;
        CFE_ES_CDSMemPool.SizeDesc[i].MaxSize = CFE_ES_CDSMemPoolDefSize[i];
    }

    if (CDSPoolSize < (CFE_ES_CDSMemPool.MinBlockSize + sizeof(CFE_ES_CDSBlockDesc_t)))
    {
        /* Must be able make Pool verification, block descriptor and at least one of the smallest blocks  */
        CFE_ES_WriteToSysLog("CFE_ES:CreateCDSPool-Pool size(%u) too small for one CDS Block, need >=%u\n",
                             CDSPoolSize, (CFE_ES_CDSMemPool.MinBlockSize + sizeof(CFE_ES_CDSBlockDesc_t)));
                        
        /* Give and delete semaphore since CDS Pool creation failed */     
        OS_MutSemGive(CFE_ES_CDSMemPool.MutexId);
        OS_MutSemDelete(CFE_ES_CDSMemPool.MutexId);
        return(CFE_ES_BAD_ARGUMENT);
    }
    
    OS_MutSemGive(CFE_ES_CDSMemPool.MutexId);

    return(CFE_SUCCESS);
}
Ejemplo n.º 4
0
void OS_Application_Startup(void)
{
  uint32 status;
  printf("********If You see this, we got into OS_Application_Startup****\n");

  status = OS_QueueCreate( &msgq_id, "MsgQ", MSGQ_DEPTH, MSGQ_SIZE, 0);
  if ( status != OS_SUCCESS )
  {
     printf("Error creating Message Queue\n");
  }

  status = OS_MutSemCreate( &mutex_id, "Mutex", 0);
  if ( status != OS_SUCCESS )
  {
     printf("Error creating mutex\n");
  }
  else
  {
     printf("MutexSem ID = %d\n",mutex_id);
  }

  status = OS_TaskCreate( &task_1_id, "Task 1", task_1, task_1_stack, TASK_1_STACK_SIZE, TASK_1_PRIORITY, 0);
  if ( status != OS_SUCCESS )
  {
     printf("Error creating Task 1\n");
  }

  status = OS_TaskCreate( &task_2_id, "Task 2", task_2, task_2_stack, TASK_2_STACK_SIZE, TASK_2_PRIORITY, 0);
  if ( status != OS_SUCCESS )
  {
     printf("Error creating Task 2\n");
  }

  status = OS_TaskCreate( &task_3_id, "Task 3", task_3, task_3_stack, TASK_3_STACK_SIZE, TASK_3_PRIORITY, 0);
  if ( status != OS_SUCCESS )
  {
     printf("Error creating Task 3\n");
  }


}
Ejemplo n.º 5
0
/**
** \brief Initializes CDS data constructs
**
** \par Description
**        Locates and validates any pre-existing CDS memory or initializes the
**        memory as a fresh CDS.
**
** \par Assumptions, External Events, and Notes:
**          None
**
** \par SysLog Messages
**
**
** \return None
**
******************************************************************************/
int32 CFE_ES_CDS_EarlyInit(void)
{
    uint32  MinRequiredSize = 0;
    int32   Status = CFE_SUCCESS;
    
    /* Compute the minimum size required for the CDS with the current configuration of the cFE */
    MinRequiredSize = (sizeof(CFE_ES_Global.CDSVars.ValidityField) * 2) +            /* Minimum size for validity fields */
                      (CFE_ES_CDS_MAX_NUM_ENTRIES * sizeof(CFE_ES_CDS_RegRec_t)) +   /* Minimum size for CDS Registry contents */
                      CFE_ES_CDSReqdMinSize(CFE_ES_CDS_MAX_NUM_ENTRIES);             /* Max # of Min Sized Blocks */
    
    /* Get CDS size from OS BSP */
    Status = CFE_PSP_GetCDSSize(&CFE_ES_Global.CDSVars.CDSSize);
    
    /* If the size was obtained successfully and meets the minimum requirements, then check its contents */
    if (Status == OS_SUCCESS)
    {
        /* Always truncate the size to the nearest 4 byte boundary */
        CFE_ES_Global.CDSVars.CDSSize &= 0xfffffffc;
        
        if (CFE_ES_Global.CDSVars.CDSSize >= MinRequiredSize)
        {
            Status = CFE_ES_ValidateCDS();
            
            /* If the CDS is accessible but invalid, then create a new one */
            if (Status == CFE_ES_CDS_INVALID)
            {
                Status = CFE_ES_InitializeCDS(CFE_ES_Global.CDSVars.CDSSize);
            }
            else if (Status == CFE_SUCCESS)
            {
                /* If a valid CDS was found, rebuild the memory pool */
                Status = CFE_ES_RebuildCDS();
                
                /* If rebuilding is not possible, then create a new one from scratch */
                if (Status == CFE_ES_CDS_INVALID)
                {
                    Status = CFE_ES_InitializeCDS(CFE_ES_Global.CDSVars.CDSSize);
                }
            }
            else /* Unrecoverable error while reading the CDS */
            {
                CFE_ES_WriteToSysLog("CFE_CDS:EarlyInit-Read error validating CDS (Err=0x%08X)\n", Status);
                CFE_ES_Global.CDSVars.MemPoolSize = 0;
                return Status;
            }

            if (Status == CFE_SUCCESS)
            {
                /* Create CDS registry access mutex */
                OS_MutSemCreate(&CFE_ES_Global.CDSVars.RegistryMutex,
                                 CFE_ES_CDS_MUT_REG_NAME,
                                 CFE_ES_CDS_MUT_REG_VALUE);
            }     
        }
        else /* Size < MinRequiredSize */
        {
            CFE_ES_WriteToSysLog("CFE_CDS:EarlyInit-CDS Size (%d) less than required (%d)\n", 
	                         CFE_ES_Global.CDSVars.CDSSize, MinRequiredSize);
            CFE_ES_Global.CDSVars.MemPoolSize = 0;
            return Status;
        }
    }
    else /* Error getting the size of the CDS from the BSP */
    {
        CFE_ES_WriteToSysLog("CFE_CDS:EarlyInit-Unable to obtain CDS Size from BSP (Err=0x%08X)\n", Status);
        CFE_ES_Global.CDSVars.MemPoolSize = 0;
        return Status;
    }
    
    
    return(CFE_SUCCESS);
    
}   /* End of CFE_ES_CDS_EarlyInit() */
Ejemplo n.º 6
0
static void test_006_001_execute(void) {

  /* OS_MutSemCreate() is invoked with sem_id set to NULL, an error is
     expected.*/
  test_set_step(1);
  {
    int32 err;

    err = OS_MutSemCreate(NULL,                     /* Error.*/
                         "failing semaphore",
                         0);
    test_assert(err == OS_INVALID_POINTER, "NULL not detected");
  }

  /* OS_MutSemCreate() is invoked with sem_name set to NULL, an error
     is expected.*/
  test_set_step(2);
  {
    int32 err;

    err = OS_MutSemCreate(&msid,
                         NULL,                      /* Error.*/
                         0);
    test_assert(err == OS_INVALID_POINTER, "NULL not detected");
  }

  /* OS_MutSemCreate() is invoked with a very long timer name, an error
     is expected.*/
  test_set_step(3);
  {
    #if 0 /* Semaphore name currently not implemented.*/
    int32 err;

    err = OS_MutSemCreate(&msid,
                         "very very long semaphore name",   /* Error.*/
                         0);
    test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");
    #endif
  }

  /* OS_MutSemDelete() is invoked with timer_id set to -1, an error is
     expected.*/
  test_set_step(4);
  {
    int32 err;

    err = OS_MutSemDelete((uint32)-1);
    test_assert(err == OS_ERR_INVALID_ID, "wrong semaphore id not detected");
  }

  /* OS_MutSemCreate() is invoked twice with duplicated name, an error
     is expected, then the queue is deleted using OS_MutSemDelete().*/
  test_set_step(5);
  {
    int32 err;
    uint32 msid1; /*, msid2;*/

    err = OS_MutSemCreate(&msid1, "my semaphore", 0);
    test_assert(err == OS_SUCCESS, "semaphore creation failed");

    #if 0 /* Semaphore name currently not implemented.*/
    err = OS_MutSemCreate(&msid2, "my semaphore", 0);
    test_assert(err == OS_ERR_NAME_TAKEN, "name conflict not detected");
    #endif

    err = OS_MutSemDelete(msid1);
    test_assert(err == OS_SUCCESS, "semaphore deletion failed");
  }
}
Ejemplo n.º 7
0
int32 CFE_ES_PoolCreateEx(CFE_ES_MemHandle_t  *HandlePtr,
                          uint8               *MemPtr,
                          uint32               Size,
                          uint32               NumBlockSizes,
                          uint32              *BlockSizes,
                          uint16               UseMutex )
{
    char     MutexName[10];
    uint32   i;
    uint32   j;
    uint32   k;
    uint32  *BlockSizeArrayPtr;
    uint32   BlockSizeArraySize;
    uint32   MinBlockSize;

   /*
   ** Local Variables
   */
   Pool_t *PoolPtr = (Pool_t *)MemPtr;
   *HandlePtr      = (uint32)MemPtr;

   /* Force the size given to be 32 bit aligned */
   Size &= 0xFFFFFFFC;

#ifdef CFE_ES_MEMPOOL_ALIGNED
   /* Determine if the memory pool address is 32-bit aligned */
   if ((((uint32)MemPtr) & 0x00000003) != 0)
   {
      CFE_ES_WriteToSysLog("CFE_ES:poolCreate Pool Address(0x%08X) is not 32-bit aligned.\n", (uint32)MemPtr);
      return(CFE_ES_BAD_ARGUMENT);
   }
#endif
   
   /* If too many sizes are specified, return an error */
   if (NumBlockSizes > CFE_ES_MAX_MEMPOOL_BLOCK_SIZES)
   {
      CFE_ES_WriteToSysLog("CFE_ES:poolCreate Num Block Sizes (%d) greater than max (%d)\n",
                           NumBlockSizes, CFE_ES_MAX_MEMPOOL_BLOCK_SIZES);
      return(CFE_ES_BAD_ARGUMENT);
   }

   if ((UseMutex != CFE_ES_USE_MUTEX) && (UseMutex != CFE_ES_NO_MUTEX))
   {
      CFE_ES_WriteToSysLog("CFE_ES:poolCreate Invalid Mutex Usage Option (%d), must be %d or %d\n",
                           UseMutex, CFE_ES_NO_MUTEX, CFE_ES_USE_MUTEX);
      return(CFE_ES_BAD_ARGUMENT);
   }
   
   if (UseMutex == CFE_ES_USE_MUTEX)
   {
      /*
      ** Construct a name for the Mutex from the address
      ** This is needed only because OS_MutSemCreate requires
      ** a unique name for each semaphore created.
      */
      sprintf(MutexName, "%08X", (unsigned int)MemPtr);

      /* create a semphore to protect this memory pool */
      OS_MutSemCreate(&(PoolPtr->MutexId), MutexName, 0);

      /* Take the semaphore to ensure the mem pool is not being used during its creation */
      OS_MutSemTake(PoolPtr->MutexId);
   }
   
   PoolPtr->Start        = (uint32 *)*HandlePtr;
   PoolPtr->End          = (uint32)((uint8 *)PoolPtr->Start + Size);
   PoolPtr->Size         = Size;
   PoolPtr->Current      = (uint32 *)(MemPtr + sizeof(Pool_t));
   PoolPtr->SizeDescPtr  = NULL;

   PoolPtr->CheckErrCntr = 0;
   PoolPtr->RequestCntr  = 0;
   
   PoolPtr->UseMutex     = UseMutex;

   for (i=0; i<CFE_ES_MAX_MEMPOOL_BLOCK_SIZES; i++)
   {
      PoolPtr->SizeDesc[i].NumCreated = 0;
      PoolPtr->SizeDesc[i].NumFree = 0;
      PoolPtr->SizeDesc[i].MaxSize = 0;
      PoolPtr->SizeDesc[i].Top = NULL;
   }

   /* Use default block sizes if none or too many sizes are specified */
   if ((NumBlockSizes == 0) || (BlockSizes == NULL))
   {
       BlockSizeArrayPtr = &CFE_ES_MemPoolDefSize[0];
       BlockSizeArraySize = CFE_ES_MAX_MEMPOOL_BLOCK_SIZES;
   }
   else
   {
       BlockSizeArrayPtr = BlockSizes;
       BlockSizeArraySize = NumBlockSizes;
   }
   
   /* Use specified block sizes but make sure they are ordered largest to smallest */
   MinBlockSize = 0xffffffff;
   for (i=0; i<BlockSizeArraySize; i++)
   {
        if ((BlockSizeArrayPtr[i] < MinBlockSize) && (BlockSizeArrayPtr[i] != 0))
        {
            MinBlockSize = BlockSizeArrayPtr[i];
        }
        
        j = 0;
        while (j<CFE_ES_MAX_MEMPOOL_BLOCK_SIZES)
        {
            if (BlockSizeArrayPtr[i] > PoolPtr->SizeDesc[j].MaxSize)
            {
                /* Make space for new size */
                for (k=i; k>j; k--)
                {
                    PoolPtr->SizeDesc[k].MaxSize = PoolPtr->SizeDesc[k-1].MaxSize;
                }
                
                /* Insert the size in the correct location */
                PoolPtr->SizeDesc[j].MaxSize = BlockSizeArrayPtr[i];
                j = CFE_ES_MAX_MEMPOOL_BLOCK_SIZES;
            }
            else
            {
                j++;
            }
        }
   }

   if (Size <= (sizeof(Pool_t) + MinBlockSize + sizeof(BD_t) ) )
   {  /* must be able make Pool management structure and at least one of the smallest blocks  */
      CFE_ES_WriteToSysLog("CFE_ES:poolCreate Pool size(%d) too small for management structure, need >=(%d)\n",
                            (int)Size,
                            (int)(sizeof(Pool_t) + MinBlockSize + sizeof(BD_t)) );
                            
      if (UseMutex == CFE_ES_USE_MUTEX)
      {
         /* Mutex is no longer needed with error in initialization.  Give it and delete it */        
         OS_MutSemGive(PoolPtr->MutexId);
         OS_MutSemDelete(PoolPtr->MutexId);
      }        
      return(CFE_ES_BAD_ARGUMENT);
   }

   if (UseMutex == CFE_ES_USE_MUTEX)
   {
       OS_MutSemGive(PoolPtr->MutexId);
   }

   return(CFE_SUCCESS);
}
Ejemplo n.º 8
0
/*
** Name: CFE_ES_Main
** Purpose: This is the entry point to the cFE application code.
**
*/
void CFE_ES_Main(uint32 StartType, uint32 StartSubtype, uint32 ModeId, uint8 *StartFilePath )
{
   int   i;
   int32 ReturnCode;

   /*
   ** Initialize the Reset variables. This call is required
   ** Before most of the ES functions can be used including the 
   ** ES System log.
   */
   CFE_ES_SetupResetVariables(StartType, StartSubtype, ModeId);

   /*
   ** Initialize the Logic Perf variables
   ** Because this is in the ES Reset area, it must be called after
   ** CFE_ES_SetupResetVariables.
   */
   CFE_ES_SetupPerfVariables(StartType);

   /*
   ** Announce the startup
   */
   CFE_ES_WriteToSysLog("ES Startup: CFE_ES_Main started\n");

   /*
   ** Create and Mount the filesystems needed
   */
   CFE_ES_InitializeFileSystems(StartType);
   
   /*
   ** Install exception Handlers ( Placeholder )
   */
   CFE_PSP_AttachExceptions();

   /*
   ** Initialize the ES Application Table
   ** to mark all entries as unused.
   */
   for ( i = 0; i < CFE_ES_MAX_APPLICATIONS; i++ )
   {
      CFE_ES_Global.AppTable[i].RecordUsed = FALSE;
   }
   
   /*
   ** Initialize the ES Task Table
   ** to mark all entries as unused.
   */
   for ( i = 0; i < OS_MAX_TASKS; i++ )
   {
      CFE_ES_Global.TaskTable[i].RecordUsed = FALSE;
   }

   /*
   ** Initialize the ES Generic Counter Table
   ** to mark all entries as unused.
   */
   for ( i = 0; i < CFE_ES_MAX_GEN_COUNTERS; i++ )
   {
      CFE_ES_Global.CounterTable[i].RecordUsed = FALSE;
   }

   /*
   ** Create the ES Shared Data Mutex
   */
   ReturnCode = OS_MutSemCreate(&(CFE_ES_Global.SharedDataMutex), "ES_DATA_MUTEX", 0 );
   if(ReturnCode != OS_SUCCESS)
   {
      CFE_ES_WriteToSysLog("ES Startup: Error: ES Shared Data Mutex could not be created. RC=0x%08X\n",
                            ReturnCode);
         
      /*
      ** Delay to allow the message to be read
      */
      OS_TaskDelay(CFE_ES_PANIC_DELAY);
      
      /* 
      ** cFE Cannot continue to start up. 
      */
      CFE_PSP_Panic(CFE_PSP_PANIC_STARTUP_SEM);
         
   } /* end if */

   /*
   ** Create the ES Startup Sync Semaphore
   */
   ReturnCode = OS_BinSemCreate(&(CFE_ES_Global.StartupSyncSemaphore),"ES_SYNC_SEM", 0, 0 );
   if(ReturnCode != OS_SUCCESS)
   {
      CFE_ES_WriteToSysLog("ES Startup: Error: ES Startup Sync Semaphore could not be created. RC=0x%08X\n",
                            ReturnCode);
         
      /*
      ** Delay to allow the message to be read
      */
      OS_TaskDelay(CFE_ES_PANIC_DELAY);
      
      /* 
      ** cFE Cannot continue to start up. 
      */
      CFE_PSP_Panic(CFE_PSP_PANIC_STARTUP_SEM);
         
   } /* end if */


   /*
   ** Create the tasks, OS objects, and initialize hardware
   */
   CFE_ES_CreateObjects();

   /*
   ** Before the Applications are loaded, set up the state
   ** variables that allow the startup syncronization to work.
   ** This depends on a couple of things:
   **  1. The fact that the cFE applications all use the CFE_ES_RunLoop Call
   **  2. The StartupSyncSemaphore has been created ( see above )
   **  3. The App(s) that wish to wait calls CFE_ES_WaitForStartupSync
   */
   CFE_ES_Global.AppStartupCounter = 0;
   CFE_ES_Global.StartupFileComplete = FALSE;
   CFE_ES_Global.StartupSemaphoreReleased = FALSE;
   
   /*
   ** Start the cFE Applications from the disk using the file
   ** specified in the CFE_ES_NONVOL_STARTUP_FILE or CFE_ES_VOLATILE_STARTUP_FILE 
   ** ( defined in the cfe_platform_cfg.h file )
   */   
   CFE_ES_StartApplications(StartType, StartFilePath );

   /*
   ** Indicate that the startup file is complete. This avoids
   ** certain race conditions.
   */
   CFE_ES_Global.StartupFileComplete = TRUE;
   

   /*
   ** Startup is complete
   */
   CFE_ES_WriteToSysLog("ES Startup: CFE Core Startup Complete\n");
}
Ejemplo n.º 9
0
/*
** Function:
**   CFE_ES_RebuildCDSPool
**
** Purpose:
**
*/
int32 CFE_ES_RebuildCDSPool(uint32 CDSPoolSize, uint32 StartOffset)
{
    char MutexName[10] = {"CDS_POOL"};
    uint32 i = 0;
    uint32 Size = (CDSPoolSize & 0xfffffffc);
    int32  Status = OS_SUCCESS;
    uint32 Offset = StartOffset;
    int32  BinIndex = 0;

    /* create a semphore to protect this memory pool */
    OS_MutSemCreate(&(CFE_ES_CDSMemPool.MutexId), MutexName, 0);

    /* Take the semaphore to ensure the mem pool is not being used during it's creation */
    OS_MutSemTake(CFE_ES_CDSMemPool.MutexId);

    CFE_ES_CDSMemPool.Start        = StartOffset;
    CFE_ES_CDSMemPool.End          = StartOffset + Size;
    CFE_ES_CDSMemPool.Size         = Size;
    CFE_ES_CDSMemPool.Current      = 0;
    CFE_ES_CDSMemPool.SizeIndex    = -1;

    CFE_ES_CDSMemPool.CheckErrCntr = 0;
    CFE_ES_CDSMemPool.RequestCntr  = 0;

    for (i=0; i<CFE_ES_CDS_NUM_BLOCK_SIZES; i++)
    {
        CFE_ES_CDSMemPool.SizeDesc[i].Top = 0;
        CFE_ES_CDSMemPool.SizeDesc[i].NumCreated = 0;
        CFE_ES_CDSMemPool.SizeDesc[i].MaxSize = CFE_ES_CDSMemPoolDefSize[i];
    }
    
    if (CDSPoolSize < (CFE_ES_CDSMemPool.MinBlockSize + sizeof(CFE_ES_CDSBlockDesc_t)))
    {
        /* Must be able make Pool verification, block descriptor and at least one of the smallest blocks  */
        CFE_ES_WriteToSysLog("CFE_ES:RebuildCDSPool-Pool size(%u) too small for one CDS Block, need >=%u\n",
                             CDSPoolSize, (CFE_ES_CDSMemPool.MinBlockSize + sizeof(CFE_ES_CDSBlockDesc_t)));

        /* Give and delete semaphore since CDS Pool rebuild failed */     
        OS_MutSemGive(CFE_ES_CDSMemPool.MutexId);
        OS_MutSemDelete(CFE_ES_CDSMemPool.MutexId);
        return(CFE_ES_BAD_ARGUMENT);
    }

    /* Scan the CDS memory trying to find blocks that were created but are now free */
    while ((Status == OS_SUCCESS) && 
           (Offset < (CFE_ES_CDSMemPool.End - sizeof(CFE_ES_CDSBlockDesc_t))) &&
           (CFE_ES_CDSMemPool.Current == 0))
    {
        /* Read the block descriptor for the first block in the memory pool */
        Status = CFE_PSP_ReadFromCDS(&CFE_ES_CDSBlockDesc, Offset, sizeof(CFE_ES_CDSBlockDesc_t));
        
        if (Status == OS_SUCCESS)
        {
            /* First, determine if the block is being or has been used */
            if (CFE_ES_CDSBlockDesc.CheckBits == CFE_ES_CDS_CHECK_PATTERN)
            {
                /* See if the block is currently being used */
                if (CFE_ES_CDSBlockDesc.AllocatedFlag != CFE_ES_CDS_BLOCK_USED)
                {
                    /* If the block is not currently being used, */
                    /* then add it to the appropriate linked list in the memory pool */
                    BinIndex = CFE_ES_CDSGetBinIndex(CFE_ES_CDSBlockDesc.SizeUsed);
                    
                    /* Sanity-check the block descriptor */
                    if (BinIndex >= 0)
                    {
                        CFE_ES_CDSBlockDesc.Next = CFE_ES_CDSMemPool.SizeDesc[BinIndex].Top;
                        CFE_ES_CDSBlockDesc.AllocatedFlag = CFE_ES_CDS_BLOCK_UNUSED;
                        CFE_ES_CDSMemPool.SizeDesc[BinIndex].Top = Offset;

                        /* Store the new CDS Block Descriptor in the CDS */
                        Status = CFE_PSP_WriteToCDS(&CFE_ES_CDSBlockDesc, Offset, sizeof(CFE_ES_CDSBlockDesc_t));

                        if (Status != OS_SUCCESS)
                        {
                            CFE_ES_WriteToSysLog("CFE_ES:RebuildCDS-Err writing to CDS (Stat=0x%08x)\n", Status);
                            Status = CFE_ES_CDS_ACCESS_ERROR;
                        }
                    }
                    else
                    {
                        CFE_ES_CDSMemPool.CheckErrCntr++;
                        CFE_ES_WriteToSysLog("CFE_ES:RebuildCDS-Invalid Block Descriptor \n");
                        Status = CFE_ES_CDS_ACCESS_ERROR;
                    }
                }
                
                /* Skip to the next block of memory */
                Offset = Offset + CFE_ES_CDSBlockDesc.ActualSize + sizeof(CFE_ES_CDSBlockDesc_t);
            }
            else
            {
                /* If the block has never been used, then we should save the offset as the current offset */
                /* which in turn will finish the scan of the CDS memory */
                CFE_ES_CDSMemPool.Current = Offset;
            }
        }
        else
        {
            CFE_ES_WriteToSysLog("CFE_ES:RebuildCDS-Err reading from CDS (Stat=0x%08x)\n", Status);
            Status = CFE_ES_CDS_ACCESS_ERROR;
        }
    }  /* end while */
    
    OS_MutSemGive(CFE_ES_CDSMemPool.MutexId);

    return Status;
}