Time and timer operations.


Compounds

struct  timer
struct  timeval

Typedefs

typedef void(* timer_overflow_handler )(void)
typedef void __attribute__ ((noreturn))(*func)()

Functions

void timer_initialize (void)
void timer_create (struct timer *t, unsigned long timeout, timer_handler handler, unsigned char flags)
void timer_insert (struct timer *t)
void timer_remove (struct timer *t)
int timer_is_active (struct timer *t)
void timer_gettime (struct timeval *tv)
 Get the current time.

void timer_settime (struct timeval *tv)
long timer_adjtime (long adj_usec)
void timevalsub (struct timeval *to, struct timeval *val)
void timevaladd (struct timeval *to, struct timeval *val)
unsigned long usec_to_tcnt (unsigned long)
 Translate microseconds into a timer counter value.

void __attribute__ ((interrupt)) timer_overflow_interrupt(void)
void set_timer_overflow_handler (timer_overflow_handler handler)

Typedef Documentation

void __attribute__ (noreturn)   
 

Real time interrupt handler.

This is the real time interrupt handler that must be installed in RTI_VECTOR to process real time interrupts and process the fast timers.

Definition at line 78 of file booter.c.

typedef void(* timer_overflow_handler)(void)
 

Timer overflow handler.

Definition at line 62 of file include/gel/timer.h.

Referenced by set_timer_overflow_handler().

Function Documentation

void __attribute__ (interrupt)   
 

Timer overflow interrupt handler

Definition at line 125 of file freqmeter.c.

void set_timer_overflow_handler timer_overflow_handler    handler [inline, static]
 

Install the timer overflow handler.

Definition at line 268 of file include/gel/timer.h.

References timer_overflow_handler.

long timer_adjtime long    adj_usec
 

Adjust the time smoothly.

This function has a similar functionality as the standard adjtime function (see RFC 1589). It adjust the current time by advancing or retarding it by the amount specified in adj_usec.

Parameters:
adj_usec  the adjustment in microseconds
Returns:
the adjustment that remains with repect to previous call

void timer_create struct timer   t,
unsigned long    timeout,
timer_handler    handler,
unsigned char    flags
 

Create and register a timer.

Initializes the timer object t and register the timer handler handler to be called after the time specified by timeout. The timeout is rounded up to a multiple of the timer resolution. The flags controls various aspects of the timer management.

The timer module has two timer lists with different resolutions. A first list is connected to the real time interrupt; it is called the fast timers. The second list is connected to the timer overflow interrupt; it is called the slow timers.

The timer object is inserted in one of the two timer list. The choice of the list is made by the TIMER_SLOW bit of the flags parameter. This flag also controls the unit in which the timeout is expressed. The two lists have different resolutions:

slow timers
When TIMER_SLOW is set, the timer is inserted in the slow list. The slow timers have a resolution of 1 second. The timeout value is expressed in seconds.

fast timers
When TIMER_SLOW is cleared, the timer is inserted in the fast list. The resolution is that of the real time interrupt. The timeout value is expressed in milliseconds. It is rounded up to a multiple of real time interrupt resolution.
Parameters:
t  the timer object
timeout  the timeout in seconds or milliseconds
handler  the handler to invoke when the timer fires
flags  the flags to control the timer object
See also:
timer_insert, timer_remove

void timer_gettime struct timeval *    tv
 

Get the current time.

Get the current time.

Returns in the tv parameter the current time. The current time is expressed in seconds and microseconds.

The current time is computed by taking a snapshot of a timer overflow counter and the free running counter. A boot time is added to the second portion to obtain the current time. Accurracy of the result depends on the resolution of the free running counter. The value returned is also a snapshot of the time within timer_gettime.

This function is intended to be close to the Unix gettimeofday operation.

Parameters:
tv  pointer to the timeval structure for the result
See also:
timer_settime, timer_adjtime

void timer_initialize void   
 

Initialize the timer module.

This function initializes the timer module and setup everything to handle timer overflow and real time interrupts. It must be called only once before using any other timer operation.

When using the single or extending bootstrap mode, the following vectors must be installed in the vector table:

RTI_VECTOR timer_interrupt TIMER_OVERFLOW_VECTOR timer_overflow_interrupt

See also:
timer_create, timer_remove

void timer_insert struct timer   t
 

Register a timer.

This operation is similar to timer_create but it only registers the timer by inserting the object in the good list. The timer object pointed to by t must have its member initialized with the same values as timer_create.

As for timer_create, the timer object is inserted in the slow or fast timers list depending on the flags member.

Parameters:
t  the timer object
See also:
timer_create, timer_remove

int timer_is_active struct timer   t [inline]
 

Return the status of a timer.

Returns 1 if the timer object t is active and will be fired. Returns 0 if it is not inserted in one of the two timer lists.

Parameters:
t  the timer object
See also:
timer_create, timer_insert, timer_remove

Definition at line 329 of file include/gel/timer.h.

References next.

void timer_remove struct timer   t
 

Remove a timer.

Removes the timer object t from the timer list.

When the last fast timer is removed, the real time interrupts are disabled. They are enabled again when the first fast timer is inserted.

Parameters:
t  the timer object
See also:
timer_create, timer_insert

void timer_settime struct timeval *    tv
 

Set the current time.

Set the current time to tv.

This function is intended to be close to the Unix settimeofday operation.

Parameters:
tv  pointer to the timeval structure holding the new time
See also:
timer_gettime, timer_adjtime

void timevaladd struct timeval *    to,
struct timeval *    val
 

Add a timeval.

Add in to the time in val.

Parameters:
to  result and value to add
val  value to add
See also:
timevalsub

void timevalsub struct timeval *    to,
struct timeval *    val
 

Subtract a timeval.

Subtract from to the time in val. The result time can become negative.

Parameters:
to  result and value from which to subtract
val  value to subtract
See also:
timevaladd