/** * This file is part of license combination gpl version 3 license and eCos. * The corresponding license terms are below. * * gpl version 3 Licence: * * The file were developed during the student thesis "Datensammlung in Wireless * Sensor Networks fuer Autonomic Home NetworkingÒ of Thomas Kothmayr and is * included in the dissertation "Secure Data Transmission in Wireless * Sensor Networks" by Corinna Schmitt during employment at the Technische * UniversitŠt MŸnchen, Department Computer Science, Chair Network * Architectures and Services (Germany). * Copyright (C) 2013 * Authors: Thomas Kothmayr and Corinna Schmitt (schmitt[at]net.in.tum.de) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3 of the License * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * * eCos Licence: (http://ecos.sourceware.org) * * This file is part of eCos, the Embedded Configurable Operating System. * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, * 2007, 2008, 2009 Free Software Foundation, Inc. * * eCos is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free * Software Foundation; either version 3 any later version. * * eCos is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with eCos; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * As a special exception, if other files instantiate templates or use * macros or inline functions from this file, or you compile this file and * link it with other works to produce a work based on this file, this file * does not by itself cause the resulting work to be covered by the GNU * General Public License. However the source code for this file must still * be made available in accordance with section (3) of the GNU General * Public License v2. * * This exception does not invalidate any other reasons why a work based on * this file might be covered by the GNU General Public License. * */ Interface: tos.lib.timer.Timer

Interface: tos.lib.timer.Timer

interface Timer<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 <cssharp@eecs.berkeley.edu>

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).