UIPEthernet library for Arduino IDE, Eclipse with arduino plugin and MBED/SMeshStudio (AVR,STM32F,ESP8266,Intel ARC32,Nordic nRF51,Teensy boards,Realtek Ameba(RTL8195A,RTL8710)), ENC28j60 network chip. Compatible with Wiznet W5100 Ethernet library API. Compiled and tested on Nucleo-F302R8. Master repository is: https://github.com/UIPEthernet/UIPEthernet/

Committer:
cassyarduino
Date:
Tue Jan 23 15:08:43 2018 +0100
Revision:
39:deeb00b81cc9
Parent:
0:e3fb1267e3c3
Release: 2.0.4

Who changed what in which revision?

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