adiStartTimer

Starts (or restarts) a timer on the board.

Supported board types

Prototype

DWORD adiStartTimer ( CTAHD ctahd, unsigned timeout, unsigned count)

Argument

Description

ctahd

Context handle returned by ctaCreateContext or ctaAttachContext.

timeout

Timeout value (in milliseconds).

count

Number of events.

Return values

Return value

Description

SUCCESS

 

CTAERR_INVALID_CTAHD

Context handle is invalid.

CTAERR_SVR_COMM

Server communication error.

Events

Event

Description

ADIEVN_TIMER_DONE

After the timer completes (expires), the ADI service generates a DONE event with the value field set to CTA_REASON_FINISHED. If the board is in error, there is an error in the value field. The value is CTA_REASON_STOPPED if the timer is halted with adiStopTimer.

ADIEVN_TIMER_TICK

If count is greater than 1, the ADI service generates a tick event for the first (count-1) expirations. On the final expiration, ADIEVN_TIMER_DONE is generated.

Details

The ADI service supports one application timer per port. This on-board timer has 10 ms resolution. The timer can be used when the application is controlling the protocol from application space. The timer generates periodic events. Specify both the period (timeout) and number of events (count).

Stop the timer by calling adiStopTimer. Reset or restart the timer with another call to adiStartTimer. When the timer is restarted, previous timer definitions are discarded and the timer begins with the new parameters.

Note: Unlike most other ADI service asynchronous functions, the timer function is not stopped automatically when a call is released.

For more information, refer to Using on-board timers.

Example

int myTimer( CTAHD ctahd, unsigned ms )
{
  CTA_EVENT event;

  if( adiStartTimer( ctahd, ms, 1 /*count*/ ) != SUCCESS )
      return MYFAILURE;

  while( 1 )
  {
      myGetEvent( &event );                 /* see ctaWaitEvent example */

      switch( event.id )
      {
         case ADIEVN_TIMER_DONE:
             if( CTA_IS_ERROR( event.value ) )
                 return MYFAILURE;                         /* API error */
             else
                 return SUCCESS;                    /* stopped normally */
                 break;

         /* might include cases to handle disconnect event, DTMFs, etc. */
      }
  }
}