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_EVENT.C
flo__ 0:b435eadf76b4 5 * Purpose: Implements waits and wake-ups for event flags
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_System.h"
flo__ 0:b435eadf76b4 38 #include "rt_Event.h"
flo__ 0:b435eadf76b4 39 #include "rt_List.h"
flo__ 0:b435eadf76b4 40 #include "rt_Task.h"
flo__ 0:b435eadf76b4 41 #include "rt_HAL_CM.h"
flo__ 0:b435eadf76b4 42
flo__ 0:b435eadf76b4 43
flo__ 0:b435eadf76b4 44 /*----------------------------------------------------------------------------
flo__ 0:b435eadf76b4 45 * Functions
flo__ 0:b435eadf76b4 46 *---------------------------------------------------------------------------*/
flo__ 0:b435eadf76b4 47
flo__ 0:b435eadf76b4 48
flo__ 0:b435eadf76b4 49 /*--------------------------- rt_evt_wait -----------------------------------*/
flo__ 0:b435eadf76b4 50
flo__ 0:b435eadf76b4 51 OS_RESULT rt_evt_wait (U16 wait_flags, U16 timeout, BOOL and_wait) {
flo__ 0:b435eadf76b4 52 /* Wait for one or more event flags with optional time-out. */
flo__ 0:b435eadf76b4 53 /* "wait_flags" identifies the flags to wait for. */
flo__ 0:b435eadf76b4 54 /* "timeout" is the time-out limit in system ticks (0xffff if no time-out) */
flo__ 0:b435eadf76b4 55 /* "and_wait" specifies the AND-ing of "wait_flags" as condition to be met */
flo__ 0:b435eadf76b4 56 /* to complete the wait. (OR-ing if set to 0). */
flo__ 0:b435eadf76b4 57 U32 block_state;
flo__ 0:b435eadf76b4 58
flo__ 0:b435eadf76b4 59 if (and_wait) {
flo__ 0:b435eadf76b4 60 /* Check for AND-connected events */
flo__ 0:b435eadf76b4 61 if ((os_tsk.run->events & wait_flags) == wait_flags) {
flo__ 0:b435eadf76b4 62 os_tsk.run->events &= ~wait_flags;
flo__ 0:b435eadf76b4 63 return (OS_R_EVT);
flo__ 0:b435eadf76b4 64 }
flo__ 0:b435eadf76b4 65 block_state = WAIT_AND;
flo__ 0:b435eadf76b4 66 }
flo__ 0:b435eadf76b4 67 else {
flo__ 0:b435eadf76b4 68 /* Check for OR-connected events */
flo__ 0:b435eadf76b4 69 if (os_tsk.run->events & wait_flags) {
flo__ 0:b435eadf76b4 70 os_tsk.run->waits = os_tsk.run->events & wait_flags;
flo__ 0:b435eadf76b4 71 os_tsk.run->events &= ~wait_flags;
flo__ 0:b435eadf76b4 72 return (OS_R_EVT);
flo__ 0:b435eadf76b4 73 }
flo__ 0:b435eadf76b4 74 block_state = WAIT_OR;
flo__ 0:b435eadf76b4 75 }
flo__ 0:b435eadf76b4 76 /* Task has to wait */
flo__ 0:b435eadf76b4 77 os_tsk.run->waits = wait_flags;
flo__ 0:b435eadf76b4 78 rt_block (timeout, (U8)block_state);
flo__ 0:b435eadf76b4 79 return (OS_R_TMO);
flo__ 0:b435eadf76b4 80 }
flo__ 0:b435eadf76b4 81
flo__ 0:b435eadf76b4 82
flo__ 0:b435eadf76b4 83 /*--------------------------- rt_evt_set ------------------------------------*/
flo__ 0:b435eadf76b4 84
flo__ 0:b435eadf76b4 85 void rt_evt_set (U16 event_flags, OS_TID task_id) {
flo__ 0:b435eadf76b4 86 /* Set one or more event flags of a selectable task. */
flo__ 0:b435eadf76b4 87 P_TCB p_tcb;
flo__ 0:b435eadf76b4 88
flo__ 0:b435eadf76b4 89 p_tcb = os_active_TCB[task_id-1];
flo__ 0:b435eadf76b4 90 if (p_tcb == NULL) {
flo__ 0:b435eadf76b4 91 return;
flo__ 0:b435eadf76b4 92 }
flo__ 0:b435eadf76b4 93 p_tcb->events |= event_flags;
flo__ 0:b435eadf76b4 94 event_flags = p_tcb->waits;
flo__ 0:b435eadf76b4 95 /* If the task is not waiting for an event, it should not be put */
flo__ 0:b435eadf76b4 96 /* to ready state. */
flo__ 0:b435eadf76b4 97 if (p_tcb->state == WAIT_AND) {
flo__ 0:b435eadf76b4 98 /* Check for AND-connected events */
flo__ 0:b435eadf76b4 99 if ((p_tcb->events & event_flags) == event_flags) {
flo__ 0:b435eadf76b4 100 goto wkup;
flo__ 0:b435eadf76b4 101 }
flo__ 0:b435eadf76b4 102 }
flo__ 0:b435eadf76b4 103 if (p_tcb->state == WAIT_OR) {
flo__ 0:b435eadf76b4 104 /* Check for OR-connected events */
flo__ 0:b435eadf76b4 105 if (p_tcb->events & event_flags) {
flo__ 0:b435eadf76b4 106 p_tcb->waits &= p_tcb->events;
flo__ 0:b435eadf76b4 107 wkup: p_tcb->events &= ~event_flags;
flo__ 0:b435eadf76b4 108 rt_rmv_dly (p_tcb);
flo__ 0:b435eadf76b4 109 p_tcb->state = READY;
flo__ 0:b435eadf76b4 110 #ifdef __CMSIS_RTOS
flo__ 0:b435eadf76b4 111 rt_ret_val2(p_tcb, 0x08/*osEventSignal*/, p_tcb->waits);
flo__ 0:b435eadf76b4 112 #else
flo__ 0:b435eadf76b4 113 rt_ret_val (p_tcb, OS_R_EVT);
flo__ 0:b435eadf76b4 114 #endif
flo__ 0:b435eadf76b4 115 rt_dispatch (p_tcb);
flo__ 0:b435eadf76b4 116 }
flo__ 0:b435eadf76b4 117 }
flo__ 0:b435eadf76b4 118 }
flo__ 0:b435eadf76b4 119
flo__ 0:b435eadf76b4 120
flo__ 0:b435eadf76b4 121 /*--------------------------- rt_evt_clr ------------------------------------*/
flo__ 0:b435eadf76b4 122
flo__ 0:b435eadf76b4 123 void rt_evt_clr (U16 clear_flags, OS_TID task_id) {
flo__ 0:b435eadf76b4 124 /* Clear one or more event flags (identified by "clear_flags") of a */
flo__ 0:b435eadf76b4 125 /* selectable task (identified by "task"). */
flo__ 0:b435eadf76b4 126 P_TCB task = os_active_TCB[task_id-1];
flo__ 0:b435eadf76b4 127
flo__ 0:b435eadf76b4 128 if (task == NULL) {
flo__ 0:b435eadf76b4 129 return;
flo__ 0:b435eadf76b4 130 }
flo__ 0:b435eadf76b4 131 task->events &= ~clear_flags;
flo__ 0:b435eadf76b4 132 }
flo__ 0:b435eadf76b4 133
flo__ 0:b435eadf76b4 134
flo__ 0:b435eadf76b4 135 /*--------------------------- isr_evt_set -----------------------------------*/
flo__ 0:b435eadf76b4 136
flo__ 0:b435eadf76b4 137 void isr_evt_set (U16 event_flags, OS_TID task_id) {
flo__ 0:b435eadf76b4 138 /* Same function as "os_evt_set", but to be called by ISRs. */
flo__ 0:b435eadf76b4 139 P_TCB p_tcb = os_active_TCB[task_id-1];
flo__ 0:b435eadf76b4 140
flo__ 0:b435eadf76b4 141 if (p_tcb == NULL) {
flo__ 0:b435eadf76b4 142 return;
flo__ 0:b435eadf76b4 143 }
flo__ 0:b435eadf76b4 144 rt_psq_enq (p_tcb, event_flags);
flo__ 0:b435eadf76b4 145 rt_psh_req ();
flo__ 0:b435eadf76b4 146 }
flo__ 0:b435eadf76b4 147
flo__ 0:b435eadf76b4 148
flo__ 0:b435eadf76b4 149 /*--------------------------- rt_evt_get ------------------------------------*/
flo__ 0:b435eadf76b4 150
flo__ 0:b435eadf76b4 151 U16 rt_evt_get (void) {
flo__ 0:b435eadf76b4 152 /* Get events of a running task after waiting for OR connected events. */
flo__ 0:b435eadf76b4 153 return (os_tsk.run->waits);
flo__ 0:b435eadf76b4 154 }
flo__ 0:b435eadf76b4 155
flo__ 0:b435eadf76b4 156
flo__ 0:b435eadf76b4 157 /*--------------------------- rt_evt_psh ------------------------------------*/
flo__ 0:b435eadf76b4 158
flo__ 0:b435eadf76b4 159 void rt_evt_psh (P_TCB p_CB, U16 set_flags) {
flo__ 0:b435eadf76b4 160 /* Check if task has to be waken up */
flo__ 0:b435eadf76b4 161 U16 event_flags;
flo__ 0:b435eadf76b4 162
flo__ 0:b435eadf76b4 163 p_CB->events |= set_flags;
flo__ 0:b435eadf76b4 164 event_flags = p_CB->waits;
flo__ 0:b435eadf76b4 165 if (p_CB->state == WAIT_AND) {
flo__ 0:b435eadf76b4 166 /* Check for AND-connected events */
flo__ 0:b435eadf76b4 167 if ((p_CB->events & event_flags) == event_flags) {
flo__ 0:b435eadf76b4 168 goto rdy;
flo__ 0:b435eadf76b4 169 }
flo__ 0:b435eadf76b4 170 }
flo__ 0:b435eadf76b4 171 if (p_CB->state == WAIT_OR) {
flo__ 0:b435eadf76b4 172 /* Check for OR-connected events */
flo__ 0:b435eadf76b4 173 if (p_CB->events & event_flags) {
flo__ 0:b435eadf76b4 174 p_CB->waits &= p_CB->events;
flo__ 0:b435eadf76b4 175 rdy: p_CB->events &= ~event_flags;
flo__ 0:b435eadf76b4 176 rt_rmv_dly (p_CB);
flo__ 0:b435eadf76b4 177 p_CB->state = READY;
flo__ 0:b435eadf76b4 178 #ifdef __CMSIS_RTOS
flo__ 0:b435eadf76b4 179 rt_ret_val2(p_CB, 0x08/*osEventSignal*/, p_CB->waits);
flo__ 0:b435eadf76b4 180 #else
flo__ 0:b435eadf76b4 181 rt_ret_val (p_CB, OS_R_EVT);
flo__ 0:b435eadf76b4 182 #endif
flo__ 0:b435eadf76b4 183 rt_put_prio (&os_rdy, p_CB);
flo__ 0:b435eadf76b4 184 }
flo__ 0:b435eadf76b4 185 }
flo__ 0:b435eadf76b4 186 }
flo__ 0:b435eadf76b4 187
flo__ 0:b435eadf76b4 188 /*----------------------------------------------------------------------------
flo__ 0:b435eadf76b4 189 * end of file
flo__ 0:b435eadf76b4 190 *---------------------------------------------------------------------------*/