コード例 #1
0
void DiaTimer :: startTimer(int eventTime) {
#ifdef POSIX
	int addressParam = (int)this;
	VOIDFUNCPTR callback = (VOIDFUNCPTR) timerCallbackFUNC;
	eventTime = eventTime - 1000/sysClkRateGet();
	long nSeconds = eventTime/1000;
	long nNanoSeconds = (eventTime % 1000)*1000000;
	myTimerSpec.it_interval.tv_sec = 0;
	myTimerSpec.it_interval.tv_nsec = 0;
	myTimerSpec.it_value.tv_sec = nSeconds;
	myTimerSpec.it_value.tv_nsec = nNanoSeconds;
	timer_connect(myTimer, (TIMER_CONNECT_FUNC) callback, addressParam);
	// added the new type-cast (TIMER_CONNECT_FUNC) due to error message in WB33!
	timer_settime(myTimer, CLOCK_REALTIME, &myTimerSpec, NULL);
#else
	wdStart(timerId, eventTime, (FUNCPTR) timerCallbackFUNC, addressParam); // Start the VxWorks Watchdog timer
#endif
	return;
}
コード例 #2
0
ファイル: ostimer.c プロジェクト: TomCrowley-ME/me_sim_test
/******************************************************************************
**  Function:  OS_TimerCreate
**
**  Purpose:  Create a new OSAL Timer
**
**  Arguments:
**
**  Return:
*/
int32 OS_TimerCreate(uint32 *timer_id, const char *timer_name, uint32 *clock_accuracy, OS_TimerCallback_t  callback_ptr)
{
   uint32   possible_tid;
   int32    i;
   int      status;

   if ( timer_id == NULL || timer_name == NULL || clock_accuracy == NULL )
   {
        return OS_INVALID_POINTER;
   }

   /*
   ** we don't want to allow names too long
   ** if truncated, two names might be the same
   */
   if (strlen(timer_name) > OS_MAX_API_NAME)
   {
      return OS_ERR_NAME_TOO_LONG;
   }

   /*
   ** Check Parameters
   */
   semTake(OS_timer_table_sem,WAIT_FOREVER);

   for(possible_tid = 0; possible_tid < OS_MAX_TIMERS; possible_tid++)
   {
      if (OS_timer_table[possible_tid].free == TRUE)
         break;
   }


   if( possible_tid >= OS_MAX_TIMERS || OS_timer_table[possible_tid].free != TRUE)
   {
        semGive(OS_timer_table_sem);
        return OS_ERR_NO_FREE_IDS;
   }

   /*
   ** Check to see if the name is already taken
   */
   for (i = 0; i < OS_MAX_TIMERS; i++)
   {
       if ((OS_timer_table[i].free == FALSE) &&
            strcmp ((char*) timer_name, OS_timer_table[i].name) == 0)
       {
            semGive(OS_timer_table_sem);
            return OS_ERR_NAME_TAKEN;
       }
   }

   /*
   ** Verify callback parameter
   */
   if (callback_ptr == NULL )
   {
      semGive(OS_timer_table_sem);
      return OS_TIMER_ERR_INVALID_ARGS;
   }

   /*
   ** Set the possible timer Id to not free so that
   ** no other task can try to use it
   */
   OS_timer_table[possible_tid].free = FALSE;
   semGive(OS_timer_table_sem);

   OS_timer_table[possible_tid].creator = OS_FindCreator();
   strncpy(OS_timer_table[possible_tid].name, timer_name, OS_MAX_API_NAME);
   OS_timer_table[possible_tid].start_time = 0;
   OS_timer_table[possible_tid].interval_time = 0;
   OS_timer_table[possible_tid].callback_ptr = callback_ptr;

   /*
   ** Create the timer
   */
   status = timer_create(CLOCK_REALTIME, NULL, (timer_t *)&(OS_timer_table[possible_tid].host_timerid));
   if (status < 0)
   {
      OS_timer_table[possible_tid].free = TRUE;
      return ( OS_TIMER_ERR_UNAVAILABLE);
   }

   /*
   ** Connect the timer to the callback function. This is non-posix, but it make the timer
   ** setup easier.
   */
   status = timer_connect((timer_t)(OS_timer_table[possible_tid].host_timerid), OS_TimerSignalHandler, possible_tid );
   if (status < 0 )
   {
      status = timer_delete((timer_t)(OS_timer_table[possible_tid].host_timerid));
      return(OS_TIMER_ERR_UNAVAILABLE);
   }

   /*
   ** Return the clock accuracy to the user
   */
   *clock_accuracy = os_clock_accuracy;

   /*
   ** Return timer ID
   */
   *timer_id = possible_tid;

   return OS_SUCCESS;
}