mbed OS5

Fork of UIPEthernet by Zoltan Hudak

Committer:
pilotak
Date:
Sun Aug 06 16:01:26 2017 +0000
Revision:
9:e55652bed36c
Parent:
8:4acb22344932
mBed OS5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 3:5b17e4656dd0 1 /**
hudakz 3:5b17e4656dd0 2 * \addtogroup timer
hudakz 3:5b17e4656dd0 3 * @{
hudakz 3:5b17e4656dd0 4 */
hudakz 3:5b17e4656dd0 5 /**
hudakz 3:5b17e4656dd0 6 * \file
hudakz 3:5b17e4656dd0 7 * Timer library implementation.
hudakz 3:5b17e4656dd0 8 * \author
hudakz 3:5b17e4656dd0 9 * Adam Dunkels <adam@sics.se>
hudakz 3:5b17e4656dd0 10 */
hudakz 3:5b17e4656dd0 11 /*
hudakz 3:5b17e4656dd0 12 * Copyright (c) 2004, Swedish Institute of Computer Science.
hudakz 3:5b17e4656dd0 13 * All rights reserved.
hudakz 3:5b17e4656dd0 14 *
hudakz 3:5b17e4656dd0 15 * Redistribution and use in source and binary forms, with or without
hudakz 3:5b17e4656dd0 16 * modification, are permitted provided that the following conditions
hudakz 3:5b17e4656dd0 17 * are met:
hudakz 3:5b17e4656dd0 18 * 1. Redistributions of source code must retain the above copyright
hudakz 3:5b17e4656dd0 19 * notice, this list of conditions and the following disclaimer.
hudakz 3:5b17e4656dd0 20 * 2. Redistributions in binary form must reproduce the above copyright
hudakz 3:5b17e4656dd0 21 * notice, this list of conditions and the following disclaimer in the
hudakz 3:5b17e4656dd0 22 * documentation and/or other materials provided with the distribution.
hudakz 3:5b17e4656dd0 23 * 3. Neither the name of the Institute nor the names of its contributors
hudakz 3:5b17e4656dd0 24 * may be used to endorse or promote products derived from this software
hudakz 3:5b17e4656dd0 25 * without specific prior written permission.
hudakz 3:5b17e4656dd0 26 *
hudakz 3:5b17e4656dd0 27 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
hudakz 3:5b17e4656dd0 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
hudakz 3:5b17e4656dd0 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
hudakz 3:5b17e4656dd0 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
hudakz 3:5b17e4656dd0 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
hudakz 3:5b17e4656dd0 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
hudakz 3:5b17e4656dd0 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
hudakz 3:5b17e4656dd0 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
hudakz 3:5b17e4656dd0 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
hudakz 3:5b17e4656dd0 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
hudakz 3:5b17e4656dd0 37 * SUCH DAMAGE.
hudakz 3:5b17e4656dd0 38 *
hudakz 8:4acb22344932 39 * This file is part of the UIP TCP/IP stack
hudakz 3:5b17e4656dd0 40 *
hudakz 3:5b17e4656dd0 41 * Author: Adam Dunkels <adam@sics.se>
hudakz 3:5b17e4656dd0 42 *
hudakz 3:5b17e4656dd0 43 * $Id: timer.c,v 1.2 2006/06/12 08:00:30 adam Exp $
hudakz 3:5b17e4656dd0 44 */
hudakz 3:5b17e4656dd0 45 #include "uip_clock.h"
hudakz 3:5b17e4656dd0 46 #include "uip_timer.h"
hudakz 3:5b17e4656dd0 47
hudakz 3:5b17e4656dd0 48 /*---------------------------------------------------------------------------*/
hudakz 3:5b17e4656dd0 49
hudakz 3:5b17e4656dd0 50 /**
hudakz 3:5b17e4656dd0 51 * Set a timer.
hudakz 3:5b17e4656dd0 52 *
hudakz 3:5b17e4656dd0 53 * This function is used to set a timer for a time sometime in the
hudakz 3:5b17e4656dd0 54 * future. The function timer_expired() will evaluate to true after
hudakz 3:5b17e4656dd0 55 * the timer has expired.
hudakz 3:5b17e4656dd0 56 *
hudakz 3:5b17e4656dd0 57 * \param t A pointer to the timer
hudakz 3:5b17e4656dd0 58 * \param interval The interval before the timer expires.
hudakz 3:5b17e4656dd0 59 *
hudakz 3:5b17e4656dd0 60 */
hudakz 3:5b17e4656dd0 61 void uip_timer_set(struct uip_timer* t, clock_time_t interval) {
hudakz 3:5b17e4656dd0 62 t->interval = interval;
hudakz 3:5b17e4656dd0 63 t->start = clock_time();
hudakz 3:5b17e4656dd0 64 }
hudakz 3:5b17e4656dd0 65
hudakz 3:5b17e4656dd0 66 /*---------------------------------------------------------------------------*/
hudakz 3:5b17e4656dd0 67
hudakz 3:5b17e4656dd0 68 /**
hudakz 3:5b17e4656dd0 69 * Reset the timer with the same interval.
hudakz 3:5b17e4656dd0 70 *
hudakz 3:5b17e4656dd0 71 * This function resets the timer with the same interval that was
hudakz 3:5b17e4656dd0 72 * given to the timer_set() function. The start point of the interval
hudakz 3:5b17e4656dd0 73 * is the exact time that the timer last expired. Therefore, this
hudakz 3:5b17e4656dd0 74 * function will cause the timer to be stable over time, unlike the
hudakz 3:5b17e4656dd0 75 * timer_rester() function.
hudakz 3:5b17e4656dd0 76 *
hudakz 3:5b17e4656dd0 77 * \param t A pointer to the timer.
hudakz 3:5b17e4656dd0 78 *
hudakz 3:5b17e4656dd0 79 * \sa timer_restart()
hudakz 3:5b17e4656dd0 80 */
hudakz 3:5b17e4656dd0 81 void uip_timer_reset(struct uip_timer* t) {
hudakz 3:5b17e4656dd0 82 t->start += t->interval;
hudakz 3:5b17e4656dd0 83 }
hudakz 3:5b17e4656dd0 84
hudakz 3:5b17e4656dd0 85 /*---------------------------------------------------------------------------*/
hudakz 3:5b17e4656dd0 86
hudakz 3:5b17e4656dd0 87 /**
hudakz 3:5b17e4656dd0 88 * Restart the timer from the current point in time
hudakz 3:5b17e4656dd0 89 *
hudakz 3:5b17e4656dd0 90 * This function restarts a timer with the same interval that was
hudakz 3:5b17e4656dd0 91 * given to the timer_set() function. The timer will start at the
hudakz 3:5b17e4656dd0 92 * current time.
hudakz 3:5b17e4656dd0 93 *
hudakz 3:5b17e4656dd0 94 * \note A periodic timer will drift if this function is used to reset
hudakz 3:5b17e4656dd0 95 * it. For preioric timers, use the timer_reset() function instead.
hudakz 3:5b17e4656dd0 96 *
hudakz 3:5b17e4656dd0 97 * \param t A pointer to the timer.
hudakz 3:5b17e4656dd0 98 *
hudakz 3:5b17e4656dd0 99 * \sa timer_reset()
hudakz 3:5b17e4656dd0 100 */
hudakz 3:5b17e4656dd0 101 void uip_timer_restart(struct uip_timer* t) {
hudakz 3:5b17e4656dd0 102 t->start = clock_time();
hudakz 3:5b17e4656dd0 103 }
hudakz 3:5b17e4656dd0 104
hudakz 3:5b17e4656dd0 105 /*---------------------------------------------------------------------------*/
hudakz 3:5b17e4656dd0 106
hudakz 3:5b17e4656dd0 107 /**
hudakz 3:5b17e4656dd0 108 * Check if a timer has expired.
hudakz 3:5b17e4656dd0 109 *
hudakz 3:5b17e4656dd0 110 * This function tests if a timer has expired and returns true or
hudakz 3:5b17e4656dd0 111 * false depending on its status.
hudakz 3:5b17e4656dd0 112 *
hudakz 3:5b17e4656dd0 113 * \param t A pointer to the timer
hudakz 3:5b17e4656dd0 114 *
hudakz 3:5b17e4656dd0 115 * \return Non-zero if the timer has expired, zero otherwise.
hudakz 3:5b17e4656dd0 116 *
hudakz 3:5b17e4656dd0 117 */
hudakz 3:5b17e4656dd0 118 int uip_timer_expired(struct uip_timer* t) {
hudakz 3:5b17e4656dd0 119 return(clock_time_t) (clock_time() - t->start) >= (clock_time_t) t->interval;
hudakz 3:5b17e4656dd0 120 }
hudakz 3:5b17e4656dd0 121
hudakz 3:5b17e4656dd0 122 /*---------------------------------------------------------------------------*/
hudakz 3:5b17e4656dd0 123 /** @} */