Interface: moteiv.tos.lib.timer.Alarm

interface Alarm<typedef precision_tag, typedef size_type>

An Alarm is a low-level interface intended for precise timing.

An Alarm 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.

An Alarm's second parameter is its "width", i.e., the number of bits used to represent time values. Width is indicated by including the appropriate size integer type as an Alarm parameter.

See TEP102 for more details.

Parameters:
precision_tag - A type indicating the precision of this Alarm.
size_type - An integer type representing time values for this Alarm.
Author:
Cory Sharp <cssharp@eecs.berkeley.edu>

Commands
command size_type getAlarm() Return the time the currently running alarm will fire or the time that the previously running alarm was set to fire.
command size_type getNow() Return the current time.
command bool isRunning() Check if alarm is running.
command void start(size_type dt) Set a single-short alarm to some time units in the future.
command void startAt(size_type t0, size_type dt) Set a single-short alarm to time t0+dt.
command void stop() Cancel an alarm.

Events
event void fired() Signaled when the alarm expires.

Commands - Details

getAlarm

command size_type getAlarm()

Return the time the currently running alarm will fire or the time that the previously running alarm was set to fire.

Returns:
Alarm time.

getNow

command size_type getNow()

Return the current time.

Returns:
Current time.

isRunning

command bool isRunning()

Check if alarm is running. Note that a FALSE return does not indicate that the fired event will not be signaled (it may have already started executing, but not reached your code yet).

Returns:
TRUE if the alarm is still running.

start

command void start(size_type dt)

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

Parameters:
dt - Time until the alarm fires.

startAt

command void startAt(size_type t0, size_type dt)

Set a single-short alarm to time t0+dt. Replaces any current alarm time. The fired will be signaled when the alarm expires. Alarms 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 alarm.
dt - Alarm time as offset from t0.

stop

command void stop()

Cancel an alarm. Note that the fired event may have already been signaled (even if your code has not yet started executing).

Events - Details

fired

event void fired()

Signaled when the alarm expires.