]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/rtos/rtx/TARGET_CORTEX_A/rt_Event.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / rtos / rtx / TARGET_CORTEX_A / rt_Event.c
1 /*----------------------------------------------------------------------------
2 * RL-ARM - RTX
3 *----------------------------------------------------------------------------
4 * Name: RT_EVENT.C
5 * Purpose: Implements waits and wake-ups for event flags
6 * Rev.: V4.60
7 *----------------------------------------------------------------------------
8 *
9 * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
10 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 * - Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * - Neither the name of ARM nor the names of its contributors may be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *---------------------------------------------------------------------------*/
34
35 #include "rt_TypeDef.h"
36 #include "RTX_Config.h"
37 #include "rt_System.h"
38 #include "rt_Event.h"
39 #include "rt_List.h"
40 #include "rt_Task.h"
41 #ifdef __CORTEX_A9
42 #include "rt_HAL_CA.h"
43 #else
44 #include "rt_HAL_CM.h"
45 #endif
46
47
48 /*----------------------------------------------------------------------------
49 * Functions
50 *---------------------------------------------------------------------------*/
51
52
53 /*--------------------------- rt_evt_wait -----------------------------------*/
54
55 OS_RESULT rt_evt_wait (U16 wait_flags, U16 timeout, BOOL and_wait) {
56 /* Wait for one or more event flags with optional time-out. */
57 /* "wait_flags" identifies the flags to wait for. */
58 /* "timeout" is the time-out limit in system ticks (0xffff if no time-out) */
59 /* "and_wait" specifies the AND-ing of "wait_flags" as condition to be met */
60 /* to complete the wait. (OR-ing if set to 0). */
61 U32 block_state;
62
63 if (and_wait) {
64 /* Check for AND-connected events */
65 if ((os_tsk.run->events & wait_flags) == wait_flags) {
66 os_tsk.run->events &= ~wait_flags;
67 return (OS_R_EVT);
68 }
69 block_state = WAIT_AND;
70 }
71 else {
72 /* Check for OR-connected events */
73 if (os_tsk.run->events & wait_flags) {
74 os_tsk.run->waits = os_tsk.run->events & wait_flags;
75 os_tsk.run->events &= ~wait_flags;
76 return (OS_R_EVT);
77 }
78 block_state = WAIT_OR;
79 }
80 /* Task has to wait */
81 os_tsk.run->waits = wait_flags;
82 rt_block (timeout, (U8)block_state);
83 return (OS_R_TMO);
84 }
85
86
87 /*--------------------------- rt_evt_set ------------------------------------*/
88
89 void rt_evt_set (U16 event_flags, OS_TID task_id) {
90 /* Set one or more event flags of a selectable task. */
91 P_TCB p_tcb;
92
93 p_tcb = os_active_TCB[task_id-1];
94 if (p_tcb == NULL) {
95 return;
96 }
97 p_tcb->events |= event_flags;
98 event_flags = p_tcb->waits;
99 /* If the task is not waiting for an event, it should not be put */
100 /* to ready state. */
101 if (p_tcb->state == WAIT_AND) {
102 /* Check for AND-connected events */
103 if ((p_tcb->events & event_flags) == event_flags) {
104 goto wkup;
105 }
106 }
107 if (p_tcb->state == WAIT_OR) {
108 /* Check for OR-connected events */
109 if (p_tcb->events & event_flags) {
110 p_tcb->waits &= p_tcb->events;
111 wkup: p_tcb->events &= ~event_flags;
112 rt_rmv_dly (p_tcb);
113 p_tcb->state = READY;
114 #ifdef __CMSIS_RTOS
115 rt_ret_val2(p_tcb, 0x08/*osEventSignal*/, p_tcb->waits);
116 #else
117 rt_ret_val (p_tcb, OS_R_EVT);
118 #endif
119 rt_dispatch (p_tcb);
120 }
121 }
122 }
123
124
125 /*--------------------------- rt_evt_clr ------------------------------------*/
126
127 void rt_evt_clr (U16 clear_flags, OS_TID task_id) {
128 /* Clear one or more event flags (identified by "clear_flags") of a */
129 /* selectable task (identified by "task"). */
130 P_TCB task = os_active_TCB[task_id-1];
131
132 if (task == NULL) {
133 return;
134 }
135 task->events &= ~clear_flags;
136 }
137
138
139 /*--------------------------- isr_evt_set -----------------------------------*/
140
141 void isr_evt_set (U16 event_flags, OS_TID task_id) {
142 /* Same function as "os_evt_set", but to be called by ISRs. */
143 P_TCB p_tcb = os_active_TCB[task_id-1];
144
145 if (p_tcb == NULL) {
146 return;
147 }
148 rt_psq_enq (p_tcb, event_flags);
149 rt_psh_req ();
150 }
151
152
153 /*--------------------------- rt_evt_get ------------------------------------*/
154
155 U16 rt_evt_get (void) {
156 /* Get events of a running task after waiting for OR connected events. */
157 return (os_tsk.run->waits);
158 }
159
160
161 /*--------------------------- rt_evt_psh ------------------------------------*/
162
163 void rt_evt_psh (P_TCB p_CB, U16 set_flags) {
164 /* Check if task has to be waken up */
165 U16 event_flags;
166
167 p_CB->events |= set_flags;
168 event_flags = p_CB->waits;
169 if (p_CB->state == WAIT_AND) {
170 /* Check for AND-connected events */
171 if ((p_CB->events & event_flags) == event_flags) {
172 goto rdy;
173 }
174 }
175 if (p_CB->state == WAIT_OR) {
176 /* Check for OR-connected events */
177 if (p_CB->events & event_flags) {
178 p_CB->waits &= p_CB->events;
179 rdy: p_CB->events &= ~event_flags;
180 rt_rmv_dly (p_CB);
181 p_CB->state = READY;
182 #ifdef __CMSIS_RTOS
183 rt_ret_val2(p_CB, 0x08/*osEventSignal*/, p_CB->waits);
184 #else
185 rt_ret_val (p_CB, OS_R_EVT);
186 #endif
187 rt_put_prio (&os_rdy, p_CB);
188 }
189 }
190 }
191
192 /*----------------------------------------------------------------------------
193 * end of file
194 *---------------------------------------------------------------------------*/
Imprint / Impressum