These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

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