00001 00013 /* 00014 * Copyright (c) 2004, Swedish Institute of Computer Science. 00015 * All rights reserved. 00016 * 00017 * Redistribution and use in source and binary forms, with or without 00018 * modification, are permitted provided that the following conditions 00019 * are met: 00020 * 1. Redistributions of source code must retain the above copyright 00021 * notice, this list of conditions and the following disclaimer. 00022 * 2. Redistributions in binary form must reproduce the above copyright 00023 * notice, this list of conditions and the following disclaimer in the 00024 * documentation and/or other materials provided with the distribution. 00025 * 3. Neither the name of the Institute nor the names of its contributors 00026 * may be used to endorse or promote products derived from this software 00027 * without specific prior written permission. 00028 * 00029 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00030 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00031 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00032 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00033 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00034 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00035 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00036 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00037 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00038 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00039 * SUCH DAMAGE. 00040 * 00041 * This file is part of the uIP TCP/IP stack 00042 * 00043 * Author: Adam Dunkels <adam@sics.se> 00044 * 00045 * $Id: timer.c,v 1.2 2006/06/12 08:00:30 adam Exp $ 00046 */ 00047 00048 #include "clock.h" 00049 #include "timer.h" 00050 00051 /*---------------------------------------------------------------------------*/ 00063 void 00064 timer_set(struct timer *t, clock_time_t interval) 00065 { 00066 t->interval = interval; 00067 t->start = clock_time(); 00068 } 00069 /*---------------------------------------------------------------------------*/ 00083 void 00084 timer_reset(struct timer *t) 00085 { 00086 t->start += t->interval; 00087 } 00088 /*---------------------------------------------------------------------------*/ 00103 void 00104 timer_restart(struct timer *t) 00105 { 00106 t->start = clock_time(); 00107 } 00108 /*---------------------------------------------------------------------------*/ 00120 int 00121 timer_expired(struct timer *t) 00122 { 00123 return (clock_time_t)(clock_time() - t->start) >= (clock_time_t)t->interval; 00124 } 00125 /*---------------------------------------------------------------------------*/ 00126