Interface: moteiv.tos.lib.timer.Timer2

interface Timer2<typedef precision_tag>

A Timer is TinyOS's general purpose timing interface. For more precise timing, you may wish to use a (platform-specific) component offering an Alarm interface.

A Timer is parameterised by its "precision" (milliseconds, microseconds, etc), identified by a type. This prevents, e.g., unintentionally mixing components expecting milliseconds with those expecting microseconds as those interfaces have a different type.

See TEP102 for more details.

Parameters:
precision_tag - A type indicating the precision of this Alarm.
Author:
Cory Sharp, Moteiv Corporation <info@moteiv.com>

Commands
command uint32_t getdt() Return the delay or period for the previously started timer.
command uint32_t getNow() Return the current time.
command uint32_t gett0() Return the time anchor for the previously started timer or the time of the previous event for periodic timers.
command bool isOneShot() Check if this is a one-shot timer.
command bool isRunning() Check if timer is running.
command void startOneShot(uint32_t dt) Set a single-short timer to some time units in the future.
command void startOneShotAt(uint32_t t0, uint32_t dt) Set a single-short timer to time t0+dt.
command void startPeriodic(uint32_t dt) Set a periodic timer to repeat every dt time units.
command void startPeriodicAt(uint32_t t0, uint32_t dt) Set a periodic timer to repeat every dt time units.
command void stop() Cancel a timer.

Events
event void fired() Signaled when the timer expires (one-shot) or repeats (periodic).

Commands - Details

getdt

command uint32_t getdt()

Return the delay or period for the previously started timer. The next fired event will occur at gett0() + getdt().

Returns:
Timer's interval.

getNow

command uint32_t getNow()

Return the current time.

Returns:
Current time.

gett0

command uint32_t gett0()

Return the time anchor for the previously started timer or the time of the previous event for periodic timers. The next fired event will occur at gett0() + getdt().

Returns:
Timer's base time.

isOneShot

command bool isOneShot()

Check if this is a one-shot timer.

Returns:
TRUE for one-shot timers, FALSE for periodic timers.

isRunning

command bool isRunning()

Check if timer is running. Periodic timers run until stopped or replaced, one-shot timers run until their deadline expires.

Returns:
TRUE if the timer is still running.

startOneShot

command void startOneShot(uint32_t dt)

Set a single-short timer to some time units in the future. Replaces any current timer settings. Equivalent to startOneShotAt(getNow(), dt). The fired will be signaled when the timer expires.

Parameters:
dt - Time until the timer fires.

startOneShotAt

command void startOneShotAt(uint32_t t0, uint32_t dt)

Set a single-short timer to time t0+dt. Replaces any current timer settings. The fired will be signaled when the timer expires. Timers set in the past will fire "soon".

Because the current time may wrap around, it is possible to use values of t0 greater than the getNow's result. These values represent times in the past, i.e., the time at which getNow() would last of returned that value.

Parameters:
t0 - Base time for timer.
dt - Time until the timer fires.

startPeriodic

command void startPeriodic(uint32_t dt)

Set a periodic timer to repeat every dt time units. Replaces any current timer settings. Equivalent to startPeriodicAt(getNow(), dt). The fired will be signaled every dt units (first event in dt units).

Parameters:
dt - Time until the timer fires.

startPeriodicAt

command void startPeriodicAt(uint32_t t0, uint32_t dt)

Set a periodic timer to repeat every dt time units. Replaces any current timer settings. The fired will be signaled every dt units (first event at t0+dt units). Periodic timers set in the past will get a bunch of events in succession, until the timer "catches up".

Because the current time may wrap around, it is possible to use values of t0 greater than the getNow's result. These values represent times in the past, i.e., the time at which getNow() would last of returned that value.

Parameters:
t0 - Base time for timer.
dt - Time until the timer fires.

stop

command void stop()

Cancel a timer.

Events - Details

fired

event void fired()

Signaled when the timer expires (one-shot) or repeats (periodic).