Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard. Support for nucleo F401RE
Dependents: rtos_basic_stm32_F401
Fork of mbed-rtos by
rt_Event.c
00001 /*---------------------------------------------------------------------------- 00002 * RL-ARM - RTX 00003 *---------------------------------------------------------------------------- 00004 * Name: RT_EVENT.C 00005 * Purpose: Implements waits and wake-ups for event flags 00006 * Rev.: V4.60 00007 *---------------------------------------------------------------------------- 00008 * 00009 * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH 00010 * All rights reserved. 00011 * Redistribution and use in source and binary forms, with or without 00012 * modification, are permitted provided that the following conditions are met: 00013 * - Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * - Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in the 00017 * documentation and/or other materials provided with the distribution. 00018 * - Neither the name of ARM nor the names of its contributors may be used 00019 * to endorse or promote products derived from this software without 00020 * specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00023 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00025 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 00026 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00027 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00028 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00029 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00030 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00031 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 *---------------------------------------------------------------------------*/ 00034 00035 #include "rt_TypeDef.h" 00036 #include "RTX_Conf.h" 00037 #include "rt_System.h" 00038 #include "rt_Event.h" 00039 #include "rt_List.h" 00040 #include "rt_Task.h" 00041 #include "rt_HAL_CM.h" 00042 00043 00044 /*---------------------------------------------------------------------------- 00045 * Functions 00046 *---------------------------------------------------------------------------*/ 00047 00048 00049 /*--------------------------- rt_evt_wait -----------------------------------*/ 00050 00051 OS_RESULT rt_evt_wait (U16 wait_flags, U16 timeout, BOOL and_wait) { 00052 /* Wait for one or more event flags with optional time-out. */ 00053 /* "wait_flags" identifies the flags to wait for. */ 00054 /* "timeout" is the time-out limit in system ticks (0xffff if no time-out) */ 00055 /* "and_wait" specifies the AND-ing of "wait_flags" as condition to be met */ 00056 /* to complete the wait. (OR-ing if set to 0). */ 00057 U32 block_state; 00058 00059 if (and_wait) { 00060 /* Check for AND-connected events */ 00061 if ((os_tsk.run->events & wait_flags) == wait_flags) { 00062 os_tsk.run->events &= ~wait_flags; 00063 return (OS_R_EVT); 00064 } 00065 block_state = WAIT_AND; 00066 } 00067 else { 00068 /* Check for OR-connected events */ 00069 if (os_tsk.run->events & wait_flags) { 00070 os_tsk.run->waits = os_tsk.run->events & wait_flags; 00071 os_tsk.run->events &= ~wait_flags; 00072 return (OS_R_EVT); 00073 } 00074 block_state = WAIT_OR; 00075 } 00076 /* Task has to wait */ 00077 os_tsk.run->waits = wait_flags; 00078 rt_block (timeout, (U8)block_state); 00079 return (OS_R_TMO); 00080 } 00081 00082 00083 /*--------------------------- rt_evt_set ------------------------------------*/ 00084 00085 void rt_evt_set (U16 event_flags, OS_TID task_id) { 00086 /* Set one or more event flags of a selectable task. */ 00087 P_TCB p_tcb; 00088 00089 p_tcb = os_active_TCB[task_id-1]; 00090 if (p_tcb == NULL) { 00091 return; 00092 } 00093 p_tcb->events |= event_flags; 00094 event_flags = p_tcb->waits; 00095 /* If the task is not waiting for an event, it should not be put */ 00096 /* to ready state. */ 00097 if (p_tcb->state == WAIT_AND) { 00098 /* Check for AND-connected events */ 00099 if ((p_tcb->events & event_flags) == event_flags) { 00100 goto wkup; 00101 } 00102 } 00103 if (p_tcb->state == WAIT_OR) { 00104 /* Check for OR-connected events */ 00105 if (p_tcb->events & event_flags) { 00106 p_tcb->waits &= p_tcb->events; 00107 wkup: p_tcb->events &= ~event_flags; 00108 rt_rmv_dly (p_tcb); 00109 p_tcb->state = READY; 00110 #ifdef __CMSIS_RTOS 00111 rt_ret_val2(p_tcb, 0x08/*osEventSignal*/, p_tcb->waits); 00112 #else 00113 rt_ret_val (p_tcb, OS_R_EVT); 00114 #endif 00115 rt_dispatch (p_tcb); 00116 } 00117 } 00118 } 00119 00120 00121 /*--------------------------- rt_evt_clr ------------------------------------*/ 00122 00123 void rt_evt_clr (U16 clear_flags, OS_TID task_id) { 00124 /* Clear one or more event flags (identified by "clear_flags") of a */ 00125 /* selectable task (identified by "task"). */ 00126 P_TCB task = os_active_TCB[task_id-1]; 00127 00128 if (task == NULL) { 00129 return; 00130 } 00131 task->events &= ~clear_flags; 00132 } 00133 00134 00135 /*--------------------------- isr_evt_set -----------------------------------*/ 00136 00137 void isr_evt_set (U16 event_flags, OS_TID task_id) { 00138 /* Same function as "os_evt_set", but to be called by ISRs. */ 00139 P_TCB p_tcb = os_active_TCB[task_id-1]; 00140 00141 if (p_tcb == NULL) { 00142 return; 00143 } 00144 rt_psq_enq (p_tcb, event_flags); 00145 rt_psh_req (); 00146 } 00147 00148 00149 /*--------------------------- rt_evt_get ------------------------------------*/ 00150 00151 U16 rt_evt_get (void) { 00152 /* Get events of a running task after waiting for OR connected events. */ 00153 return (os_tsk.run->waits); 00154 } 00155 00156 00157 /*--------------------------- rt_evt_psh ------------------------------------*/ 00158 00159 void rt_evt_psh (P_TCB p_CB, U16 set_flags) { 00160 /* Check if task has to be waken up */ 00161 U16 event_flags; 00162 00163 p_CB->events |= set_flags; 00164 event_flags = p_CB->waits; 00165 if (p_CB->state == WAIT_AND) { 00166 /* Check for AND-connected events */ 00167 if ((p_CB->events & event_flags) == event_flags) { 00168 goto rdy; 00169 } 00170 } 00171 if (p_CB->state == WAIT_OR) { 00172 /* Check for OR-connected events */ 00173 if (p_CB->events & event_flags) { 00174 p_CB->waits &= p_CB->events; 00175 rdy: p_CB->events &= ~event_flags; 00176 rt_rmv_dly (p_CB); 00177 p_CB->state = READY; 00178 #ifdef __CMSIS_RTOS 00179 rt_ret_val2(p_CB, 0x08/*osEventSignal*/, p_CB->waits); 00180 #else 00181 rt_ret_val (p_CB, OS_R_EVT); 00182 #endif 00183 rt_put_prio (&os_rdy, p_CB); 00184 } 00185 } 00186 } 00187 00188 /*---------------------------------------------------------------------------- 00189 * end of file 00190 *---------------------------------------------------------------------------*/
Generated on Tue Jul 12 2022 20:53:01 by 1.7.2