Программа считывает показания датчиков и управляет сервомашинками.

Dependencies:   mbed-src

Fork of NUCLEO_BLUENRG by Ostap Ostapsky

Committer:
Sergeev
Date:
Mon Aug 25 09:45:34 2014 +0000
Revision:
1:fb307cfca15c
Parent:
0:aa1e012ec210
Final

Who changed what in which revision?

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