florent ollivier / Mbed 2 deprecated Gyro

Dependencies:   mbed

Committer:
flo__
Date:
Mon Mar 28 15:54:19 2022 +0000
Revision:
0:b435eadf76b4
28/03/2022

Who changed what in which revision?

UserRevisionLine numberNew contents of line
flo__ 0:b435eadf76b4 1 /*----------------------------------------------------------------------------
flo__ 0:b435eadf76b4 2 * RL-ARM - RTX
flo__ 0:b435eadf76b4 3 *----------------------------------------------------------------------------
flo__ 0:b435eadf76b4 4 * Name: RT_TIME.C
flo__ 0:b435eadf76b4 5 * Purpose: Delay and interval wait functions
flo__ 0:b435eadf76b4 6 * Rev.: V4.60
flo__ 0:b435eadf76b4 7 *----------------------------------------------------------------------------
flo__ 0:b435eadf76b4 8 *
flo__ 0:b435eadf76b4 9 * Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
flo__ 0:b435eadf76b4 10 * All rights reserved.
flo__ 0:b435eadf76b4 11 * Redistribution and use in source and binary forms, with or without
flo__ 0:b435eadf76b4 12 * modification, are permitted provided that the following conditions are met:
flo__ 0:b435eadf76b4 13 * - Redistributions of source code must retain the above copyright
flo__ 0:b435eadf76b4 14 * notice, this list of conditions and the following disclaimer.
flo__ 0:b435eadf76b4 15 * - Redistributions in binary form must reproduce the above copyright
flo__ 0:b435eadf76b4 16 * notice, this list of conditions and the following disclaimer in the
flo__ 0:b435eadf76b4 17 * documentation and/or other materials provided with the distribution.
flo__ 0:b435eadf76b4 18 * - Neither the name of ARM nor the names of its contributors may be used
flo__ 0:b435eadf76b4 19 * to endorse or promote products derived from this software without
flo__ 0:b435eadf76b4 20 * specific prior written permission.
flo__ 0:b435eadf76b4 21 *
flo__ 0:b435eadf76b4 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
flo__ 0:b435eadf76b4 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
flo__ 0:b435eadf76b4 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
flo__ 0:b435eadf76b4 25 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
flo__ 0:b435eadf76b4 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
flo__ 0:b435eadf76b4 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
flo__ 0:b435eadf76b4 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
flo__ 0:b435eadf76b4 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
flo__ 0:b435eadf76b4 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
flo__ 0:b435eadf76b4 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
flo__ 0:b435eadf76b4 32 * POSSIBILITY OF SUCH DAMAGE.
flo__ 0:b435eadf76b4 33 *---------------------------------------------------------------------------*/
flo__ 0:b435eadf76b4 34
flo__ 0:b435eadf76b4 35 #include "rt_TypeDef.h"
flo__ 0:b435eadf76b4 36 #include "RTX_Conf.h"
flo__ 0:b435eadf76b4 37 #include "rt_Task.h"
flo__ 0:b435eadf76b4 38 #include "rt_Time.h"
flo__ 0:b435eadf76b4 39
flo__ 0:b435eadf76b4 40 /*----------------------------------------------------------------------------
flo__ 0:b435eadf76b4 41 * Global Variables
flo__ 0:b435eadf76b4 42 *---------------------------------------------------------------------------*/
flo__ 0:b435eadf76b4 43
flo__ 0:b435eadf76b4 44 /* Free running system tick counter */
flo__ 0:b435eadf76b4 45 U32 os_time;
flo__ 0:b435eadf76b4 46
flo__ 0:b435eadf76b4 47
flo__ 0:b435eadf76b4 48 /*----------------------------------------------------------------------------
flo__ 0:b435eadf76b4 49 * Functions
flo__ 0:b435eadf76b4 50 *---------------------------------------------------------------------------*/
flo__ 0:b435eadf76b4 51
flo__ 0:b435eadf76b4 52
flo__ 0:b435eadf76b4 53 /*--------------------------- rt_time_get -----------------------------------*/
flo__ 0:b435eadf76b4 54
flo__ 0:b435eadf76b4 55 U32 rt_time_get (void) {
flo__ 0:b435eadf76b4 56 /* Get system time tick */
flo__ 0:b435eadf76b4 57 return (os_time);
flo__ 0:b435eadf76b4 58 }
flo__ 0:b435eadf76b4 59
flo__ 0:b435eadf76b4 60
flo__ 0:b435eadf76b4 61 /*--------------------------- rt_dly_wait -----------------------------------*/
flo__ 0:b435eadf76b4 62
flo__ 0:b435eadf76b4 63 void rt_dly_wait (U16 delay_time) {
flo__ 0:b435eadf76b4 64 /* Delay task by "delay_time" */
flo__ 0:b435eadf76b4 65 rt_block (delay_time, WAIT_DLY);
flo__ 0:b435eadf76b4 66 }
flo__ 0:b435eadf76b4 67
flo__ 0:b435eadf76b4 68
flo__ 0:b435eadf76b4 69 /*--------------------------- rt_itv_set ------------------------------------*/
flo__ 0:b435eadf76b4 70
flo__ 0:b435eadf76b4 71 void rt_itv_set (U16 interval_time) {
flo__ 0:b435eadf76b4 72 /* Set interval length and define start of first interval */
flo__ 0:b435eadf76b4 73 os_tsk.run->interval_time = interval_time;
flo__ 0:b435eadf76b4 74 os_tsk.run->delta_time = interval_time + (U16)os_time;
flo__ 0:b435eadf76b4 75 }
flo__ 0:b435eadf76b4 76
flo__ 0:b435eadf76b4 77
flo__ 0:b435eadf76b4 78 /*--------------------------- rt_itv_wait -----------------------------------*/
flo__ 0:b435eadf76b4 79
flo__ 0:b435eadf76b4 80 void rt_itv_wait (void) {
flo__ 0:b435eadf76b4 81 /* Wait for interval end and define start of next one */
flo__ 0:b435eadf76b4 82 U16 delta;
flo__ 0:b435eadf76b4 83
flo__ 0:b435eadf76b4 84 delta = os_tsk.run->delta_time - (U16)os_time;
flo__ 0:b435eadf76b4 85 os_tsk.run->delta_time += os_tsk.run->interval_time;
flo__ 0:b435eadf76b4 86 if ((delta & 0x8000) == 0) {
flo__ 0:b435eadf76b4 87 rt_block (delta, WAIT_ITV);
flo__ 0:b435eadf76b4 88 }
flo__ 0:b435eadf76b4 89 }
flo__ 0:b435eadf76b4 90
flo__ 0:b435eadf76b4 91 /*----------------------------------------------------------------------------
flo__ 0:b435eadf76b4 92 * end of file
flo__ 0:b435eadf76b4 93 *---------------------------------------------------------------------------*/
flo__ 0:b435eadf76b4 94