3 /* "Copyright (c) 2000-2003 The Regents of the University of California.
6 * Permission to use, copy, modify, and distribute this software and its
7 * documentation for any purpose, without fee, and without written agreement
8 * is hereby granted, provided that the above copyright notice, the following
9 * two paragraphs and the author appear in all copies of this software.
11 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
12 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
13 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY
14 * OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
17 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
19 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
20 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
26 * A Timer is TinyOS's general purpose timing interface. For more precise
27 * timing, you may wish to use a (platform-specific) component offering
30 * <p>A Timer is parameterised by its "precision" (milliseconds,
31 * microseconds, etc), identified by a type. This prevents, e.g.,
32 * unintentionally mixing components expecting milliseconds with those
33 * expecting microseconds as those interfaces have a different type.
35 * <p>See TEP102 for more details.
37 * @param precision_tag A type indicating the precision of this Alarm.
39 * @author Cory Sharp <cssharp@eecs.berkeley.edu>
42 interface Timer<precision_tag>
46 * Set a periodic timer to repeat every dt time units. Replaces any
47 * current timer settings. Equivalent to startPeriodicAt(getNow(),
48 * dt). The <code>fired</code> will be signaled every dt units (first
51 * @param dt Time until the timer fires.
53 command void startPeriodic(uint32_t dt);
56 * Set a single-short timer to some time units in the future. Replaces
57 * any current timer settings. Equivalent to startOneShotAt(getNow(),
58 * dt). The <code>fired</code> will be signaled when the timer expires.
60 * @param dt Time until the timer fires.
62 command void startOneShot(uint32_t dt);
70 * Signaled when the timer expires (one-shot) or repeats (periodic).
76 * Check if timer is running. Periodic timers run until stopped or
77 * replaced, one-shot timers run until their deadline expires.
79 * @return TRUE if the timer is still running.
81 command bool isRunning();
84 * Check if this is a one-shot timer.
85 * @return TRUE for one-shot timers, FALSE for periodic timers.
87 command bool isOneShot();
90 * Set a periodic timer to repeat every dt time units. Replaces any
91 * current timer settings. The <code>fired</code> will be signaled every
92 * dt units (first event at t0+dt units). Periodic timers set in the past
93 * will get a bunch of events in succession, until the timer "catches up".
95 * <p>Because the current time may wrap around, it is possible to use
96 * values of t0 greater than the <code>getNow</code>'s result. These
97 * values represent times in the past, i.e., the time at which getNow()
98 * would last of returned that value.
100 * @param t0 Base time for timer.
101 * @param dt Time until the timer fires.
103 command void startPeriodicAt(uint32_t t0, uint32_t dt);
106 * Set a single-short timer to time t0+dt. Replaces any current timer
107 * settings. The <code>fired</code> will be signaled when the timer
108 * expires. Timers set in the past will fire "soon".
110 * <p>Because the current time may wrap around, it is possible to use
111 * values of t0 greater than the <code>getNow</code>'s result. These
112 * values represent times in the past, i.e., the time at which getNow()
113 * would last of returned that value.
115 * @param t0 Base time for timer.
116 * @param dt Time until the timer fires.
118 command void startOneShotAt(uint32_t t0, uint32_t dt);
122 * Return the current time.
123 * @return Current time.
125 command uint32_t getNow();
128 * Return the time anchor for the previously started timer or the time of
129 * the previous event for periodic timers. The next fired event will occur
130 * at gett0() + getdt().
131 * @return Timer's base time.
133 command uint32_t gett0();
136 * Return the delay or period for the previously started timer. The next
137 * fired event will occur at gett0() + getdt().
138 * @return Timer's interval.
140 command uint32_t getdt();