00001 /** \addtogroup sys 00002 * @{ */ 00003 00004 /** 00005 * \defgroup timer Timer library 00006 * 00007 * The Contiki kernel does not provide support for timed 00008 * events. Rather, an application that wants to use timers needs to 00009 * explicitly use the timer library. 00010 * 00011 * The timer library provides functions for setting, resetting and 00012 * restarting timers, and for checking if a timer has expired. An 00013 * application must "manually" check if its timers have expired; this 00014 * is not done automatically. 00015 * 00016 * A timer is declared as a \c struct \c timer and all access to the 00017 * timer is made by a pointer to the declared timer. 00018 * 00019 * \note The timer library is not able to post events when a timer 00020 * expires. The \ref etimer "Event timers" should be used for this 00021 * purpose. 00022 * 00023 * \note The timer library uses the \ref clock "Clock library" to 00024 * measure time. Intervals should be specified in the format used by 00025 * the clock library. 00026 * 00027 * \sa \ref etimer "Event timers" 00028 * 00029 * @{ 00030 */ 00031 00032 00033 /** 00034 * \file 00035 * Timer library header file. 00036 * \author 00037 * Adam Dunkels <adam@sics.se> 00038 */ 00039 00040 /* 00041 * Copyright (c) 2004, Swedish Institute of Computer Science. 00042 * All rights reserved. 00043 * 00044 * Redistribution and use in source and binary forms, with or without 00045 * modification, are permitted provided that the following conditions 00046 * are met: 00047 * 1. Redistributions of source code must retain the above copyright 00048 * notice, this list of conditions and the following disclaimer. 00049 * 2. Redistributions in binary form must reproduce the above copyright 00050 * notice, this list of conditions and the following disclaimer in the 00051 * documentation and/or other materials provided with the distribution. 00052 * 3. Neither the name of the Institute nor the names of its contributors 00053 * may be used to endorse or promote products derived from this software 00054 * without specific prior written permission. 00055 * 00056 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00057 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00058 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00059 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00060 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00061 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00062 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00063 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00064 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00065 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00066 * SUCH DAMAGE. 00067 * 00068 * This file is part of the Contiki operating system. 00069 * 00070 * Author: Adam Dunkels <adam@sics.se> 00071 * 00072 * $Id: timer.h,v 1.2 2008/09/21 08:58:05 adamdunkels Exp $ 00073 */ 00074 #ifndef __TIMER_H__ 00075 #define __TIMER_H__ 00076 00077 #include "sys/clock.h" 00078 00079 /** 00080 * A timer. 00081 * 00082 * This structure is used for declaring a timer. The timer must be set 00083 * with timer_set() before it can be used. 00084 * 00085 * \hideinitializer 00086 */ 00087 struct timer { 00088 clock_time_t start; 00089 clock_time_t interval; 00090 }; 00091 00092 void timer_set(struct timer *t, clock_time_t interval); 00093 void timer_reset(struct timer *t); 00094 void timer_restart(struct timer *t); 00095 int timer_expired(struct timer *t); 00096 clock_time_t timer_remaining(struct timer *t); 00097 00098 00099 #endif /* __TIMER_H__ */ 00100 00101 /** @} */ 00102 /** @} */