Example #1
0
static void test_003_005_setup(void) {
    uint32 accuracy;

    cnt = 0;
    tmid = 0;
    (void) OS_TimerCreate(&tmid, "test timer", &accuracy, tmr_callback);
}
void OS_Application_Startup(void)
{
   uint32             status;

   OS_API_Init();

   OS_printf("OS Application Startup\n");

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

   /*
   ** 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)timer_id);
      OS_printf("Timer Accuracy = %d microseconds \n",(int)timer_accuracy);
   }

   /*
   ** 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");
   }

}
Example #3
0
void OS_Application_Startup(void)
{
   
   int              i = 0;
   int32            TimerStatus;
   uint32           TimerID[NUMBER_OF_TIMERS];
   char             TimerName[NUMBER_OF_TIMERS][20] = {"TIMER1","TIMER2","TIMER3","TIMER4"};
   uint32           TimerStart[NUMBER_OF_TIMERS] = {1000, 2000000, 3000000, 4000000 };
   uint32           TimerInterval[NUMBER_OF_TIMERS] = {500000, 4000000, 4000000, 4000000 }; 
   uint32           ClockAccuracy;

   for ( i = 0; i < NUMBER_OF_TIMERS; i++ )
   {
      TimerStatus = OS_TimerCreate(&TimerID[i], TimerName[i], &ClockAccuracy, &(test_func));
      if ( TimerStatus != OS_SUCCESS )
      {
         printf("Error creating timer# %d: %d\n",i ,(int)TimerStatus);       
      }   
      else
      {
         printf("Timer %d Created\n", i);
      }

      printf("Timer %d Accuracy = %d microseconds \n",i ,(int)ClockAccuracy);

      TimerStatus  =  OS_TimerSet(TimerID[i], TimerStart[i], TimerInterval[i]);
      if ( TimerStatus != OS_SUCCESS )
      {
         printf("Error calling OS_TimerSet: ID = %d\n", (int)TimerID[i]);
      }
      else
      {  
         printf("Timer %d programmed\n", i);
      }

   }


   /*
   ** Let the main thread sleep 
   */     
   printf("Starting Delay loop. Linux/OSX/Cygwin will be faster, because sleep call is interrupted by timer\n");
   for (i = 0 ; i < 15; i++ )
   {
      /* 
      ** Even though this sleep call is for 1 second,
      ** the sigalarm timer for the 1hz will keep waking
      ** it up. Keep that in mind when setting the timer down
      ** to something very small.
      */
      sleep(1);
   }

   for ( i = 0; i < NUMBER_OF_TIMERS; i++ )
   {
                 
      TimerStatus =  OS_TimerDelete(TimerID[i]);
      if ( TimerStatus != OS_SUCCESS )
      {
         printf("Error calling OS_TimerDelete for timer %d: ID = %d\n", i, (int)TimerID[i]);
      }
      else
      {
         printf("Timer %d deleted. Count total = %d\n",i, (int)timer_counter[i]);
      }
 
   }
   printf("Hit control-c to end test on a desktop system.\n");

}
Example #4
0
static void test_003_001_execute(void) {

    /* [3.1.1] OS_TimerCreate() is invoked with timer_id set to NULL, an
       error is expected.*/
    test_set_step(1);
    {
        int32 err;
        uint32 accuracy;

        err = OS_TimerCreate(NULL,                      /* Error.*/
                             "failing timer",
                             &accuracy,
                             tmr_callback);
        test_assert(err == OS_INVALID_POINTER, "NULL not detected");
    }

    /* [3.1.2] OS_TimerCreate() is invoked with timer_name set to NULL,
       an error is expected.*/
    test_set_step(2);
    {
        int32 err;
        uint32 tmid;
        uint32 accuracy;

        err = OS_TimerCreate(&tmid,
                             NULL,                      /* Error.*/
                             &accuracy,
                             tmr_callback);
        test_assert(err == OS_INVALID_POINTER, "NULL not detected");
    }

    /* [3.1.3] OS_TimerCreate() is invoked with accuracy set to NULL, an
       error is expected.*/
    test_set_step(3);
    {
        int32 err;
        uint32 tmid;

        err = OS_TimerCreate(&tmid,
                             "failing timer",
                             NULL,                      /* Error.*/
                             tmr_callback);
        test_assert(err == OS_INVALID_POINTER, "NULL not detected");
    }

    /* [3.1.4] OS_TimerCreate() is invoked with callback_ptr set to NULL,
       an error is expected.*/
    test_set_step(4);
    {
        int32 err;
        uint32 tmid;
        uint32 accuracy;

        err = OS_TimerCreate(&tmid,
                             "failing timer",
                             &accuracy,
                             NULL);                     /* Error.*/
        test_assert(err == OS_TIMER_ERR_INVALID_ARGS, "NULL not detected");
    }

    /* [3.1.5] OS_TimerCreate() is invoked with a very long timer name,
       an error is expected.*/
    test_set_step(5);
    {
        int32 err;
        uint32 tmid;
        uint32 accuracy;

        err = OS_TimerCreate(&tmid,
                             "very very long timer name",   /* Error.*/
                             &accuracy,
                             tmr_callback);
        test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");
    }

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

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

    /* [3.1.7] OS_TimerCreate() is invoked twice with duplicated name, an
       error is expected, then the queue is deleted using
       OS_TimerDelete().*/
    test_set_step(7);
    {
        int32 err;
        uint32 tmid1, tmid2;
        uint32 accuracy;

        err = OS_TimerCreate(&tmid1, "my timer", &accuracy, tmr_callback);
        test_assert(err == OS_SUCCESS, "timer creation failed");

        err = OS_TimerCreate(&tmid2, "my timer", &accuracy, tmr_callback);
        test_assert(err == OS_ERR_NAME_TAKEN, "name conflict not detected");

        err = OS_TimerDelete(tmid1);
        test_assert(err == OS_SUCCESS, "timer deletion failed");
    }
}
Example #5
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");
   }

}