BLE_BlueNRG for Nucleo board

Dependents:   Nucleo_BLE_HeartRate Nucleo_BLE_UART Nucleo_BLE_UART

Warning: Deprecated!

Supported drivers and applications can be found at this link.

Committer:
sjallouli
Date:
Fri Dec 19 18:56:07 2014 +0000
Revision:
0:a948f5f3904c
BLE_BlueNRG for Nucleo board

Who changed what in which revision?

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