コード例 #1
0
static void test_004_001_execute(void) {

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

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

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

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

  /* [4.1.3] OS_BinSemCreate() is invoked with an invalid
     sem_initial_value, an error is expected.*/
  test_set_step(3);
  {
    int32 err;

    err = OS_BinSemCreate(&bsid,
                         "failing semaphore",
                         2,                         /* Error.*/
                         0);
    test_assert(err == OS_INVALID_INT_NUM, "counter error not detected");
  }

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

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

  /* [4.1.5] OS_BinSemDelete() is invoked with timer_id set to -1, an
     error is expected.*/
  test_set_step(5);
  {
    int32 err;

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

  /* [4.1.6] OS_BinSemCreate() is invoked twice with duplicated name,
     an error is expected, then the queue is deleted using
     OS_BinSemDelete().*/
  test_set_step(6);
  {
    int32 err;
    uint32 bsid1; /*, bsid2;*/

    err = OS_BinSemCreate(&bsid1, "my semaphore", 0, 0);
    test_assert(err == OS_SUCCESS, "semaphore creation failed");

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

    err = OS_BinSemDelete(bsid1);
    test_assert(err == OS_SUCCESS, "semaphore deletion failed");
  }
}
コード例 #2
0
static void test_004_007_setup(void) {
  bsid = 0;
  (void) OS_BinSemCreate(&bsid, "test semaphore", 0, 0);
}
コード例 #3
0
int32 CFE_TIME_TaskInit(void)
{
    int32 Status = CFE_SUCCESS;

    Status = CFE_ES_RegisterApp();
    if(Status != CFE_SUCCESS)
    {
      CFE_ES_WriteToSysLog("TIME:Call to CFE_ES_RegisterApp Failed:RC=0x%08X\n",Status);
      return Status;
    }/* end if */
    
    Status = CFE_EVS_Register(NULL, 0, 0);
    if(Status != CFE_SUCCESS)
    {
      CFE_ES_WriteToSysLog("TIME:Call to CFE_EVS_Register Failed:RC=0x%08X\n",Status);
      return Status;
    }/* end if */
    
    Status = OS_BinSemCreate(&CFE_TIME_TaskData.ToneSemaphore,
                              CFE_TIME_SEM_TONE_NAME,
                              CFE_TIME_SEM_VALUE,
                              CFE_TIME_SEM_OPTIONS);
    if(Status != CFE_SUCCESS)
    {
      CFE_ES_WriteToSysLog("TIME:Error creating tone semaphore:RC=0x%08X\n",Status);
      return Status;
    }/* end if */        
    
    Status = OS_BinSemCreate(&CFE_TIME_TaskData.LocalSemaphore,
                              CFE_TIME_SEM_1HZ_NAME,
                              CFE_TIME_SEM_VALUE,
                              CFE_TIME_SEM_OPTIONS);
    if(Status != CFE_SUCCESS)
    {
      CFE_ES_WriteToSysLog("TIME:Error creating local semaphore:RC=0x%08X\n",Status);
      return Status;
    }/* end if */
    
    
    Status = CFE_ES_CreateChildTask(&CFE_TIME_TaskData.ToneTaskID,
                                     CFE_TIME_TASK_TONE_NAME,
                                     CFE_TIME_Tone1HzTask,
                                     CFE_TIME_TASK_STACK_PTR,
                                     CFE_TIME_TONE_TASK_STACK_SIZE,
                                     CFE_TIME_TONE_TASK_PRIORITY,
                                     CFE_TIME_TASK_FLAGS);
    if(Status != CFE_SUCCESS)
    {
      CFE_ES_WriteToSysLog("TIME:Error creating tone 1Hz child task:RC=0x%08X\n",Status);
      return Status;
    }/* end if */
    
        
    Status = CFE_ES_CreateChildTask(&CFE_TIME_TaskData.LocalTaskID,
                                     CFE_TIME_TASK_1HZ_NAME,
                                     CFE_TIME_Local1HzTask,
                                     CFE_TIME_TASK_STACK_PTR,
                                     CFE_TIME_1HZ_TASK_STACK_SIZE,
                                     CFE_TIME_1HZ_TASK_PRIORITY,
                                     CFE_TIME_TASK_FLAGS);
    if(Status != CFE_SUCCESS)
    {
      CFE_ES_WriteToSysLog("TIME:Error creating local 1Hz child task:RC=0x%08X\n",Status);
      return Status;
    }/* end if */


    Status = CFE_SB_CreatePipe(&CFE_TIME_TaskData.CmdPipe,
                                CFE_TIME_TaskData.PipeDepth,
                                CFE_TIME_TaskData.PipeName);
    if(Status != CFE_SUCCESS)
    {
      CFE_ES_WriteToSysLog("TIME:Error creating cmd pipe:RC=0x%08X\n",Status);
      return Status;
    }/* end if */


    Status = CFE_SB_Subscribe(CFE_TIME_SEND_HK_MID,
                              CFE_TIME_TaskData.CmdPipe);
    if(Status != CFE_SUCCESS)
    {
      CFE_ES_WriteToSysLog("TIME:Error subscribing to HK Request:RC=0x%08X\n",Status);
      return Status;
    }/* end if */


    /*
    ** Subscribe to time at the tone "signal" commands...
    */
    #if (CFE_TIME_CFG_CLIENT == TRUE)
    Status = CFE_SB_Subscribe(CFE_TIME_TONE_CMD_MID,
                              CFE_TIME_TaskData.CmdPipe);
    #endif
    
    #if (CFE_TIME_CFG_SERVER == TRUE)
    Status = CFE_SB_SubscribeLocal(CFE_TIME_TONE_CMD_MID,
                              CFE_TIME_TaskData.CmdPipe,4);
    #endif
    if(Status != CFE_SUCCESS)
    {
      CFE_ES_WriteToSysLog("TIME:Error subscribing to tone cmd:RC=0x%08X\n",Status);
      return Status;
    }/* end if */


    /*
    ** Subscribe to time at the tone "data" commands...
    */
    #if (CFE_TIME_CFG_CLIENT == TRUE)
    Status = CFE_SB_Subscribe(CFE_TIME_DATA_CMD_MID,
                              CFE_TIME_TaskData.CmdPipe);
    #endif
    
    #if (CFE_TIME_CFG_SERVER == TRUE)
    Status = CFE_SB_SubscribeLocal(CFE_TIME_DATA_CMD_MID,
                              CFE_TIME_TaskData.CmdPipe,4);
    #endif
    if(Status != CFE_SUCCESS)
    {
      CFE_ES_WriteToSysLog("TIME:Error subscribing to time data cmd:RC=0x%08X\n",Status);
      return Status;
    }/* end if */
    
    
    /*
    ** Subscribe to "fake" tone signal commands...
    */
    #if (CFE_TIME_CFG_FAKE_TONE == TRUE)

    #if (CFE_TIME_CFG_CLIENT == TRUE)
    Status = CFE_SB_Subscribe(CFE_TIME_FAKE_CMD_MID,
                              CFE_TIME_TaskData.CmdPipe);
    #endif
    
    #if (CFE_TIME_CFG_SERVER == TRUE)
    Status = CFE_SB_SubscribeLocal(CFE_TIME_FAKE_CMD_MID,
                                   CFE_TIME_TaskData.CmdPipe,4);
    #endif
    
    if(Status != CFE_SUCCESS)
    {
      CFE_ES_WriteToSysLog("TIME:Error subscribing to fake tone signal cmds:RC=0x%08X\n",Status);
      return Status;
    }/* end if */    
    #endif    
    
    
    /*
    ** Subscribe to time at the tone "request data" commands...
    */
    #if (CFE_TIME_CFG_SERVER == TRUE)
      #if (CFE_TIME_CFG_SOURCE != TRUE)
        #if (CFE_TIME_CFG_FAKE_TONE != TRUE)

        
   Status = CFE_SB_Subscribe(CFE_TIME_SEND_CMD_MID,
                                  CFE_TIME_TaskData.CmdPipe);
        if(Status != CFE_SUCCESS)
        {
          CFE_ES_WriteToSysLog("TIME:Error subscribing to time at the tone request data cmds:RC=0x%08X\n",Status);
          return Status;
        }/* end if */

        #endif
      #endif
    #endif

    /*
    ** Subscribe to Time task ground command packets...
    */
    Status = CFE_SB_Subscribe(CFE_TIME_CMD_MID,
                              CFE_TIME_TaskData.CmdPipe);
    if(Status != CFE_SUCCESS)
    {
      CFE_ES_WriteToSysLog("TIME:Error subscribing to time task gnd cmds:RC=0x%08X\n",Status);
      return Status;
    }/* end if */  


    Status = CFE_EVS_SendEvent(CFE_TIME_INIT_EID,
                               CFE_EVS_INFORMATION,
                               "cFE TIME Initialized");
    if(Status != CFE_SUCCESS)
    {
      CFE_ES_WriteToSysLog("TIME:Error sending init event:RC=0x%08X\n",Status);
      return Status;
    }/* end if */

    /*
    ** Select primary vs redundant tone interrupt signal...
    */
    #if (CFE_TIME_CFG_SIGNAL == TRUE)
    OS_SelectTone(CFE_TIME_TaskData.ClockSignal);
    #endif

    return CFE_SUCCESS;

} /* End of CFE_TIME_TaskInit() */
コード例 #4
0
/*
** Main function
*/
void OS_Application_Startup(void)
{
   uint32 status;
   OS_bin_sem_prop_t  bin_sem_prop;

   OS_API_Init();

   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);
   }

   /*
   ** 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 tasks
   */
   status = OS_TaskCreate( &task_1_id, "Task 1", task_1, task_1_stack, TASK_STACK_SIZE, TASK_1_PRIORITY, 0);
   if ( status != OS_SUCCESS )
   {
      OS_printf("Error creating Task 1\n");
   }
   else
   {
      OS_printf("Created Task 1\n");
   }

   status = OS_TaskCreate( &task_2_id, "Task 2", task_2, task_2_stack, TASK_STACK_SIZE, TASK_2_PRIORITY, 0);
   if ( status != OS_SUCCESS )
   {
      OS_printf("Error creating Task 2\n");
   }
   else
   {
      OS_printf("Created Task 2\n");
   }
 
   status = OS_TaskCreate( &task_3_id, "Task 3", task_3, task_3_stack, TASK_STACK_SIZE, TASK_3_PRIORITY, 0);
   if ( status != OS_SUCCESS )
   {
      OS_printf("Error creating Task 3\n");
   }
   else
   {
      OS_printf("Created Task 3\n");
   }

   /* 
   ** Delay, then release the semaphore
   */
   OS_TaskDelay(2000); 

   status = OS_BinSemFlush(bin_sem_id);

   OS_printf("Main done!\n");

}
コード例 #5
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");
}
コード例 #6
0
ファイル: bin-sem-test.c プロジェクト: felipeprov/osal
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");
   }

}