Main Page | Modules | Data Structures | File List | Data Fields | Globals | Examples

Event timer library


Detailed Description

This library provides a way to generate timed events. The library maintins a list of all active event timers, and posts an event to the owning process when the timer expires.

An event timer is declared as a struct etimer and all access to the event timer is made by a pointer to the declared event timer.

Example:

static struct etimer periodic; EK_EVENTHANDLER(eventhandler, ev, data); EK_PROCESS(p, "Example process", EK_PRIO_NORMAL, eventhandler, NULL, NULL); LOADER_INIT_FUNC(example_init, arg) { ek_start(&p); } EK_EVENTHANDLER(eventhandler, ev, data) { if(ev == EK_EVENT_INIT) { etimer_set(&periodic, CLOCK_SECOND); } else if(ev == EK_EVENT_TIMER) { etimer_restart(&periodic); do_timed_processing(); } }

Note:
The event timer library uses the timer library to measure time. Intervals should be specified in the same format as the timer library uses.
See also:
Timer library

Clock library (used by the timer library)


Files

file  etimer.h
 Event timer library header file.

file  etimer.c
 Event timer library implementation.


Data Structures

struct  etimer
 A timer. More...


Functions

void etimer_set (struct etimer *t, clock_time_t interval)
 Set an event timer.

void etimer_reset (struct etimer *t)
 Reset an event timer with the same interval as was previously set.

void etimer_restart (struct etimer *t)
 Restart an event timer from the current point in time.

int etimer_expired (struct etimer *t)
 Check if an event timer has expired.

int etimer_pending (void)
 Check if there are any non-expired event timers.


Function Documentation

int etimer_expired struct etimer et  ) 
 

Check if an event timer has expired.

This function tests if an event timer has expired and returns true or false depending on its status.

Parameters:
et A pointer to the event timer
Returns:
Non-zero if the timer has expired, zero otherwise.
Examples:
example-program.c, example-service.c, and example-use-service.c.

int etimer_pending void   ) 
 

Check if there are any non-expired event timers.

This function checks if there are any active event timers that have not expired.

Returns:
True if there are active event timers, false if there are no active timers.

void etimer_reset struct etimer et  ) 
 

Reset an event timer with the same interval as was previously set.

This function resets the event timer with the same interval that was given to the event timer with the etimer_set() function. The start point of the interval is the exact time that the event timer last expired. Therefore, this function will cause the timer to be stable over time, unlike the etimer_restart() function.

Parameters:
et A pointer to the event timer.
See also:
etimer_restart()

void etimer_restart struct etimer et  ) 
 

Restart an event timer from the current point in time.

This function restarts the event timer with the same interval that was given to the etimer_set() function. The event timer will start at the current time.

Note:
A periodic timer will drift if this function is used to reset it. For preioric timers, use the etimer_reset() function instead.
Parameters:
et A pointer to the event timer.
See also:
etimer_reset()

void etimer_set struct etimer et,
clock_time_t  interval
 

Set an event timer.

This function is used to set an event timer for a time sometime in the future. When the event timer expires, the event EK_EVENT_TIMER will be posted to the process that called the etimer_set() function.

Parameters:
et A pointer to the event timer
interval The interval before the timer expires.
Examples:
example-program.c, example-service.c, and example-use-service.c.


Generated on Wed Jul 6 01:19:06 2005 for Contiki/ESB by doxygen 1.3.6