Adapted to OBCP ENSMM

Dependents:   SimpleBLE-ObCP_ENSMM_V2019_Test_BLE_S SimpleBLE-ObCp_test-BLE_envoi SimpleBLE-ObCp_test-BLE Roller_catcher_Envoi ... more

Committer:
jimbaud
Date:
Tue Dec 17 14:20:20 2019 +0000
Revision:
308:8886c0252544
Parent:
297:c26445716704
Test BLE ENSMM simplify

Who changed what in which revision?

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