/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 CFE_ES_ListResources(int32 fd)
{
    OS_task_prop_t          TaskProp;
    OS_queue_prop_t         QueueProp;
    OS_bin_sem_prop_t       SemProp;
    OS_count_sem_prop_t     CountSemProp;
    OS_mut_sem_prop_t       MutProp;
    OS_FDTableEntry         FileProp;
    
    int32 Result = CFE_SUCCESS;
    int32 NumSemaphores = 0;
    int32 NumCountSems =0;
    int32 NumMutexes = 0;
    int32 NumQueues = 0;
    int32 NumTasks = 0;
    int32 NumFiles = 0;
    uint32 i;
    char Line[35];


    for ( i= 0; i < OS_MAX_TASKS; i++)
    {
        if (OS_TaskGetInfo(i, &TaskProp) == OS_SUCCESS)
        {
            NumTasks++;
        }
    }

    for ( i= 0; i < OS_MAX_QUEUES; i++)
    {
        if (OS_QueueGetInfo(i, &QueueProp) == OS_SUCCESS)
        {
            NumQueues++;
        }
    }


    for ( i= 0; i < OS_MAX_COUNT_SEMAPHORES; i++)
    {
       if (OS_CountSemGetInfo(i, &CountSemProp) == OS_SUCCESS)
        {
            NumCountSems++;
        }
    }
    for ( i= 0; i < OS_MAX_BIN_SEMAPHORES; i++)
    {
        if (OS_BinSemGetInfo(i, &SemProp) == OS_SUCCESS)
        {
            NumSemaphores++;
        }
    }


    for ( i= 0; i < OS_MAX_MUTEXES; i++)
    {
        if (OS_MutSemGetInfo(i, &MutProp) == OS_SUCCESS)
        {
            NumMutexes++;
        }
    }

    for ( i= 0; i < OS_MAX_NUM_OPEN_FILES; i++)
    {
        if (OS_FDGetInfo(i, &FileProp) == OS_FS_SUCCESS)
        {
            NumFiles++;
        }
    }

    sprintf(Line,"OS Resources in Use:\n");
    Result = OS_write(fd, Line, strlen(Line));
    
    if( Result == strlen(Line))
    {   
        sprintf(Line,"Number of Tasks: %d\n", (int) NumTasks);
        Result = OS_write(fd, Line, strlen(Line));

        if (Result == strlen(Line))
        {
            sprintf(Line,"Number of Queues: %d\n", (int) NumQueues);
            Result = OS_write(fd, Line, strlen(Line));
            
            if (Result == strlen(Line))
            {
                sprintf(Line,"Number of Binary Semaphores: %d\n",(int) NumSemaphores);
                Result = OS_write(fd, Line, strlen(Line));
                if (Result == strlen(Line))
                {
                
                   
                    sprintf(Line,"Number of Counting Semaphores: %d\n",(int) NumCountSems);
                    Result = OS_write(fd, Line, strlen(Line));
                 
                    if (Result == strlen(Line))
                    {
                        sprintf(Line,"Number of Mutexes: %d\n", (int) NumMutexes);
                        Result = OS_write(fd, Line, strlen(Line));
                        if (Result == strlen(Line))
                        {
                            sprintf(Line,"Number of Open Files: %d\n",(int) NumFiles);
                            Result = OS_write(fd, Line, strlen(Line));
                            if ( Result == strlen(Line))
                            {
                               Result = CFE_SUCCESS;
                            }
                        }
                    }
                }   
            }
        }
    }
            
    /* 
    ** If any of the writes failed, return the OS_write 
    **  failure 
    */
    return Result;
}
Ejemplo n.º 2
0
void OS_Application_Startup(void)
{
   uint32             status;
   OS_bin_sem_prop_t  bin_sem_prop;

   OS_printf("OS Application Startup\n");

   /*
   ** Create the binary semaphore
   */
   status = OS_BinSemCreate( &bin_sem_id, "BinSem1", 1, 0);
   if ( status != OS_SUCCESS )
   {
      OS_printf("Error creating Binary Sem\n");
   }
   else
   {
      status = OS_BinSemGetInfo (bin_sem_id, &bin_sem_prop);
      OS_printf("Binary Sem ID = %d, value = %d\n", (int)bin_sem_id, (int)bin_sem_prop.value);
   }

   /*
   ** Create a timer
   */
   status = OS_TimerCreate(&timer_id, "Timer 1", &timer_accuracy, &(TimerFunction));
   if ( status != OS_SUCCESS )
   {
      OS_printf("Error creating OS Timer\n");
   }
   else
   {
      OS_printf("Timer ID = %d\n", (int)bin_sem_id);
      OS_printf("Timer Accuracy = %d microseconds \n",(int)timer_accuracy);
   }

   /*
   ** Take the semaphore so the value is 0 and the next SemTake call should block
   */
   status = OS_BinSemTake(bin_sem_id);
   if ( status != OS_SUCCESS )
   {
      OS_printf("Error calling OS_BinSemTake with bin_sem_id = %d\n",(int)bin_sem_id);
   }
   else
   {
      status = OS_BinSemGetInfo (bin_sem_id, &bin_sem_prop);
      OS_printf("Initial Binary Sem Take: value = %d\n", (int)bin_sem_prop.value);
   }

   /*
   ** Create the "consumer" task.
   */
   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 )
   {
      OS_printf("Error creating Task 1\n");
   }
   else
   {
      OS_printf("Created Task 1\n");
   }

   /*
   ** Start the timer
   */
   status  =  OS_TimerSet(timer_id, timer_start, timer_interval);
   if ( status != OS_SUCCESS )
   {
       OS_printf("Error calling OS_TimerSet: ID = %d\n", (int)timer_id);
   }
   else
   {
       OS_printf("Timer programmed\n");
   }

}