Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of UIPEthernet by
uip_timer.c
00001 /** 00002 * \addtogroup timer 00003 * @{ 00004 */ 00005 /** 00006 * \file 00007 * Timer library implementation. 00008 * \author 00009 * Adam Dunkels <adam@sics.se> 00010 */ 00011 /* 00012 * Copyright (c) 2004, Swedish Institute of Computer Science. 00013 * All rights reserved. 00014 * 00015 * Redistribution and use in source and binary forms, with or without 00016 * modification, are permitted provided that the following conditions 00017 * are met: 00018 * 1. Redistributions of source code must retain the above copyright 00019 * notice, this list of conditions and the following disclaimer. 00020 * 2. Redistributions in binary form must reproduce the above copyright 00021 * notice, this list of conditions and the following disclaimer in the 00022 * documentation and/or other materials provided with the distribution. 00023 * 3. Neither the name of the Institute nor the names of its contributors 00024 * may be used to endorse or promote products derived from this software 00025 * without specific prior written permission. 00026 * 00027 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00028 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00029 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00030 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00031 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00032 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00033 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00034 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00035 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00036 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00037 * SUCH DAMAGE. 00038 * 00039 * This file is part of the UIP TCP/IP stack 00040 * 00041 * Author: Adam Dunkels <adam@sics.se> 00042 * 00043 * $Id: timer.c,v 1.2 2006/06/12 08:00:30 adam Exp $ 00044 */ 00045 #include "uip_clock.h" 00046 #include "uip_timer.h" 00047 00048 /*---------------------------------------------------------------------------*/ 00049 00050 /** 00051 * Set a timer. 00052 * 00053 * This function is used to set a timer for a time sometime in the 00054 * future. The function timer_expired() will evaluate to true after 00055 * the timer has expired. 00056 * 00057 * \param t A pointer to the timer 00058 * \param interval The interval before the timer expires. 00059 * 00060 */ 00061 void uip_timer_set(struct uip_timer* t, clock_time_t interval) { 00062 t->interval = interval; 00063 t->start = clock_time(); 00064 } 00065 00066 /*---------------------------------------------------------------------------*/ 00067 00068 /** 00069 * Reset the timer with the same interval. 00070 * 00071 * This function resets the timer with the same interval that was 00072 * given to the timer_set() function. The start point of the interval 00073 * is the exact time that the timer last expired. Therefore, this 00074 * function will cause the timer to be stable over time, unlike the 00075 * timer_rester() function. 00076 * 00077 * \param t A pointer to the timer. 00078 * 00079 * \sa timer_restart() 00080 */ 00081 void uip_timer_reset(struct uip_timer* t) { 00082 t->start += t->interval; 00083 } 00084 00085 /*---------------------------------------------------------------------------*/ 00086 00087 /** 00088 * Restart the timer from the current point in time 00089 * 00090 * This function restarts a timer with the same interval that was 00091 * given to the timer_set() function. The timer will start at the 00092 * current time. 00093 * 00094 * \note A periodic timer will drift if this function is used to reset 00095 * it. For preioric timers, use the timer_reset() function instead. 00096 * 00097 * \param t A pointer to the timer. 00098 * 00099 * \sa timer_reset() 00100 */ 00101 void uip_timer_restart(struct uip_timer* t) { 00102 t->start = clock_time(); 00103 } 00104 00105 /*---------------------------------------------------------------------------*/ 00106 00107 /** 00108 * Check if a timer has expired. 00109 * 00110 * This function tests if a timer has expired and returns true or 00111 * false depending on its status. 00112 * 00113 * \param t A pointer to the timer 00114 * 00115 * \return Non-zero if the timer has expired, zero otherwise. 00116 * 00117 */ 00118 int uip_timer_expired(struct uip_timer* t) { 00119 return(clock_time_t) (clock_time() - t->start) >= (clock_time_t) t->interval; 00120 } 00121 00122 /*---------------------------------------------------------------------------*/ 00123 /** @} */
Generated on Tue Jul 12 2022 18:10:58 by
