Timer service
[Generic system services]


Detailed Description

This module provides timeout callbacks.


Files

file  timer.c
 Timer implementation (license: GPLv2).
file  timer.h
 Timer header (license: GPLv2).

Modules

 Timer service configuration

Typedefs

typedef void(* timer_callback )(int timer)
 The type of callback function executed when a timer expires.

Functions

void timer_interval ()
 Global timeout handling function.
int timer_alloc (timer_callback callback, uintptr_t user)
 Allocates a timer.
void timer_free (int timer)
 Deallocates a timer.
bool timer_set (int timer, uint32_t millis)
 Starts or restarts a timer.
bool timer_stop (int timer)
 Stops the timer.
bool timer_expired (int timer)
 Checks wether a timer has expired or was stopped manually.
uintptr_t timer_get_user (int timer)
 Retrieves the user-defined data attached to a timer.
bool timer_set_user (int timer, uintptr_t user)
 Assigns user-defined data to a timer.


Function Documentation

void timer_interval (  ) 

Global timeout handling function.

This function must be continuously called once for every time slice. This is usually done from the application main loop. However, it should not be done from an interrupt service routine to avoid race conditions.

The accuracy of the timer service is principally dependent on the accuracy of the timer interval between calls of this function. So do your best to guarantee constant intervals.

The length of the time slice is configured with TIMER_MS_PER_TICK.

int timer_alloc ( timer_callback  callback,
uintptr_t  user 
)

Allocates a timer.

The given callback function is executed whenever the timer expires. The user value is attached to the timer and given as an extra argument to the callback function. It is not used by the timer module in any way.

Parameters:
[in] callback The function to execute whenever the timer expires.
[in] user The user-defined value.
Returns:
A non-negative timer identifier on success, -1 on failure.

void timer_free ( int  timer  ) 

Deallocates a timer.

The timer being deallocated is stopped and marked as free.

Parameters:
[in] timer The identifier of the timer which to deallocate.

bool timer_set ( int  timer,
uint32_t  millis 
)

Starts or restarts a timer.

The timer expires after millis milliseconds.

Note:
Timers do not automatically restart. Call this function from the timeout callback function to restart the timer.
Parameters:
[in] timer The identifier of the timer which to start.
[in] millis The number of milliseconds after which the timer will expire.
Returns:
true if the timer has successfully been started, false on failure.

bool timer_stop ( int  timer  ) 

Stops the timer.

Parameters:
[in] timer The identifier of the timer which to stop.
Returns:
true if the timer has been stopped, false on failure.

bool timer_expired ( int  timer  ) 

Checks wether a timer has expired or was stopped manually.

Parameters:
[in] timer The identifier of the timer which to check.
Returns:
true if the timer is not running, false otherwise.

uintptr_t timer_get_user ( int  timer  ) 

Retrieves the user-defined data attached to a timer.

Parameters:
[in] timer The identifier of the timer of which to retrieve the data.
Returns:
The user-defined data of the timer on success, 0 on failure.

bool timer_set_user ( int  timer,
uintptr_t  user 
)

Assigns user-defined data to a timer.

Parameters:
[in] timer The identifier of the timer which to assign the data to.
[in] user The data which to assign to the timer.
Returns:
true on success, false on failure.


Generated on Thu May 22 18:12:37 2008 for mega-eth by  doxygen 1.5.5