Программа считывает показания датчиков и управляет сервомашинками.
Fork of NUCLEO_BLUENRG by
gp_timer.c
00001 /* 00002 * Copyright (c) 2004, Swedish Institute of Computer Science. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the Institute nor the names of its contributors 00014 * may be used to endorse or promote products derived from this software 00015 * without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00018 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00023 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00024 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00027 * SUCH DAMAGE. 00028 * 00029 * This file is part of the Contiki operating system. 00030 * 00031 * Author: Adam Dunkels <adam@sics.se> 00032 * 00033 */ 00034 00035 #include "clock.h" 00036 #include "gp_timer.h" 00037 00038 /*---------------------------------------------------------------------------*/ 00039 /** 00040 * Set a timer. 00041 * 00042 * This function sets a timer for a time sometime in the 00043 * future. The function timer_expired() will evaluate to true after 00044 * the timer has expired. 00045 * 00046 * @param[in] t A pointer to the timer 00047 * @param[in] interval The interval before the timer expires. 00048 * 00049 */ 00050 void 00051 Timer_Set(struct timer *t, tClockTime interval) 00052 { 00053 t->interval = interval; 00054 t->start = Clock_Time(); 00055 } 00056 /*---------------------------------------------------------------------------*/ 00057 /** 00058 * Reset the timer with the same interval. 00059 * 00060 * This function resets the timer with the same interval that was 00061 * given to the timer_set() function. The start point of the interval 00062 * is the exact time that the timer last expired. Therefore, this 00063 * function will cause the timer to be stable over time, unlike the 00064 * timer_restart() function. 00065 * 00066 * \param t A pointer to the timer. 00067 * 00068 * \sa timer_restart() 00069 */ 00070 void 00071 Timer_Reset(struct timer *t) 00072 { 00073 t->start += t->interval; 00074 } 00075 /*---------------------------------------------------------------------------*/ 00076 /** 00077 * Restart the timer from the current point in time 00078 * 00079 * This function restarts a timer with the same interval that was 00080 * given to the timer_set() function. The timer will start at the 00081 * current time. 00082 * 00083 * \note A periodic timer will drift if this function is used to reset 00084 * it. For preioric timers, use the timer_reset() function instead. 00085 * 00086 * \param t A pointer to the timer. 00087 * 00088 * \sa timer_reset() 00089 */ 00090 void 00091 Timer_Restart(struct timer *t) 00092 { 00093 t->start = Clock_Time(); 00094 } 00095 /*---------------------------------------------------------------------------*/ 00096 /** 00097 * Check if a timer has expired. 00098 * 00099 * This function tests if a timer has expired and returns true or 00100 * false depending on its status. 00101 * 00102 * \param t A pointer to the timer 00103 * 00104 * \return Non-zero if the timer has expired, zero otherwise. 00105 * 00106 */ 00107 int 00108 Timer_Expired(struct timer *t) 00109 { 00110 /* Note: Can not return diff >= t->interval so we add 1 to diff and return 00111 t->interval < diff - required to avoid an internal error in mspgcc. */ 00112 tClockTime diff = (Clock_Time() - t->start) + 1; 00113 return t->interval < diff; 00114 00115 } 00116 /*---------------------------------------------------------------------------*/ 00117 /** 00118 * The time until the timer expires 00119 * 00120 * This function returns the time until the timer expires. 00121 * 00122 * \param t A pointer to the timer 00123 * 00124 * \return The time until the timer expires 00125 * 00126 */ 00127 tClockTime 00128 Timer_Remaining(struct timer *t) 00129 { 00130 return t->start + t->interval - Clock_Time(); 00131 } 00132 /*---------------------------------------------------------------------------*/ 00133 00134 /** @} */ 00135 00136 00137
Generated on Tue Jul 12 2022 22:44:50 by 1.7.2