Contiki-NG
Data Structures | Functions
Seconds timer library

The stimer library provides functions for setting, resetting and restarting timers, and for checking if a timer has expired. More...

Data Structures

struct  stimer
 A timer. More...
 

Functions

void stimer_set (struct stimer *t, unsigned long interval)
 Set a timer. More...
 
void stimer_reset (struct stimer *t)
 Reset the timer with the same interval. More...
 
void stimer_restart (struct stimer *t)
 Restart the timer from the current point in time. More...
 
int stimer_expired (struct stimer *t)
 Check if a timer has expired. More...
 
unsigned long stimer_remaining (struct stimer *t)
 The time until the timer expires. More...
 
unsigned long stimer_elapsed (struct stimer *t)
 The time elapsed since the timer started. More...
 

Detailed Description

The stimer library provides functions for setting, resetting and restarting timers, and for checking if a timer has expired.

An application must "manually" check if its timers have expired; this is not done automatically.

A timer is declared as a struct stimer and all access to the timer is made by a pointer to the declared timer.

Note
The stimer library is not able to post events when a timer expires. The Event timers should be used for this purpose.
The stimer library uses the Clock library to measure time. Intervals should be specified in the seconds.
See also
Event timers

Function Documentation

◆ stimer_elapsed()

unsigned long stimer_elapsed ( struct stimer t)

The time elapsed since the timer started.

This function returns the time elapsed.

Parameters
tA pointer to the timer
Returns
The time elapsed since the last start of the timer

Definition at line 159 of file stimer.c.

◆ stimer_expired()

int stimer_expired ( struct stimer t)

Check if a timer has expired.

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

Parameters
tA pointer to the timer
Returns
Non-zero if the timer has expired, zero otherwise.

Definition at line 127 of file stimer.c.

◆ stimer_remaining()

unsigned long stimer_remaining ( struct stimer t)

The time until the timer expires.

This function returns the time until the timer expires.

Parameters
tA pointer to the timer
Returns
The time until the timer expires

Definition at line 143 of file stimer.c.

◆ stimer_reset()

void stimer_reset ( struct stimer t)

Reset the timer with the same interval.

This function resets the timer with the same interval that was given to the stimer_set() function. The start point of the interval is the exact time that the timer last expired. Therefore, this function will cause the timer to be stable over time, unlike the stimer_restart() function. If this is executed before the timer expired, this function has no effect.

Parameters
tA pointer to the timer.
See also
stimer_restart()

Definition at line 88 of file stimer.c.

◆ stimer_restart()

void stimer_restart ( struct stimer t)

Restart the timer from the current point in time.

This function restarts a timer with the same interval that was given to the stimer_set() function. The 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 stimer_reset() function instead.
Parameters
tA pointer to the timer.
See also
stimer_reset()

Definition at line 110 of file stimer.c.

◆ stimer_set()

void stimer_set ( struct stimer t,
unsigned long  interval 
)

Set a timer.

This function is used to set a timer for a time sometime in the future. The function stimer_expired() will evaluate to true after the timer has expired.

Parameters
tA pointer to the timer
intervalThe interval before the timer expires.

Definition at line 67 of file stimer.c.