1 | /** |
---|
2 | * @file rtems/rtems/event.h |
---|
3 | * |
---|
4 | * This include file contains the information pertaining to the Event |
---|
5 | * Manager. This manager provides a high performance method of communication |
---|
6 | * and synchronization. |
---|
7 | * |
---|
8 | * Directives provided are: |
---|
9 | * |
---|
10 | * - send an event set to a task |
---|
11 | * - receive event condition |
---|
12 | * |
---|
13 | */ |
---|
14 | |
---|
15 | /* COPYRIGHT (c) 1989-2008. |
---|
16 | * On-Line Applications Research Corporation (OAR). |
---|
17 | * |
---|
18 | * The license and distribution terms for this file may be |
---|
19 | * found in the file LICENSE in this distribution or at |
---|
20 | * http://www.rtems.com/license/LICENSE. |
---|
21 | */ |
---|
22 | |
---|
23 | #ifndef _RTEMS_RTEMS_EVENT_H |
---|
24 | #define _RTEMS_RTEMS_EVENT_H |
---|
25 | |
---|
26 | /** |
---|
27 | * This constant is defined to extern most of the time when using |
---|
28 | * this header file. However by defining it to nothing, the data |
---|
29 | * declared in this header file can be instantiated. This is done |
---|
30 | * in a single per manager file. |
---|
31 | */ |
---|
32 | #ifndef RTEMS_EVENT_EXTERN |
---|
33 | #define RTEMS_EVENT_EXTERN extern |
---|
34 | #endif |
---|
35 | |
---|
36 | #ifdef __cplusplus |
---|
37 | extern "C" { |
---|
38 | #endif |
---|
39 | |
---|
40 | #include <rtems/score/object.h> |
---|
41 | #include <rtems/rtems/status.h> |
---|
42 | #include <rtems/rtems/types.h> |
---|
43 | #include <rtems/rtems/options.h> |
---|
44 | #include <rtems/score/thread.h> |
---|
45 | #include <rtems/score/threadsync.h> |
---|
46 | #include <rtems/score/watchdog.h> |
---|
47 | #include <rtems/rtems/eventset.h> |
---|
48 | |
---|
49 | /** |
---|
50 | * @defgroup ClassicEvent Events |
---|
51 | * |
---|
52 | * @ingroup ClassicRTEMS |
---|
53 | * |
---|
54 | * @brief The event manager provides a high performance method of intertask |
---|
55 | * communication and synchronization. |
---|
56 | * |
---|
57 | * An event flag is used by a task (or ISR) to inform another task of the |
---|
58 | * occurrence of a significant situation. Thirty-two event flags are |
---|
59 | * associated with each task. A collection of one or more event flags is |
---|
60 | * referred to as an event set. The data type rtems_event_set is used to |
---|
61 | * manage event sets. |
---|
62 | * |
---|
63 | * The application developer should remember the following key characteristics |
---|
64 | * of event operations when utilizing the event manager: |
---|
65 | * |
---|
66 | * - Events provide a simple synchronization facility. |
---|
67 | * - Events are aimed at tasks. |
---|
68 | * - Tasks can wait on more than one event simultaneously. |
---|
69 | * - Events are independent of one another. |
---|
70 | * - Events do not hold or transport data. |
---|
71 | * - Events are not queued. In other words, if an event is sent more than once |
---|
72 | * to a task before being received, the second and subsequent send |
---|
73 | * operations to that same task have no effect. |
---|
74 | * |
---|
75 | * An event set is posted when it is directed (or sent) to a task. A pending |
---|
76 | * event is an event that has been posted but not received. An event condition |
---|
77 | * is used to specify the event set which the task desires to receive and the |
---|
78 | * algorithm which will be used to determine when the request is satisfied. An |
---|
79 | * event condition is satisfied based upon one of two algorithms which are |
---|
80 | * selected by the user. The @ref RTEMS_EVENT_ANY algorithm states that an |
---|
81 | * event condition is satisfied when at least a single requested event is |
---|
82 | * posted. The @ref RTEMS_EVENT_ALL algorithm states that an event condition |
---|
83 | * is satisfied when every requested event is posted. |
---|
84 | * |
---|
85 | * An event set or condition is built by a bitwise or of the desired events. |
---|
86 | * The set of valid events is @ref RTEMS_EVENT_0 through @ref RTEMS_EVENT_31. |
---|
87 | * If an event is not explicitly specified in the set or condition, then it is |
---|
88 | * not present. Events are specifically designed to be mutually exclusive, |
---|
89 | * therefore bitwise or and addition operations are equivalent as long as each |
---|
90 | * event appears exactly once in the event set list. |
---|
91 | * |
---|
92 | * For example, when sending the event set consisting of @ref RTEMS_EVENT_6, |
---|
93 | * @ref RTEMS_EVENT_15, and @ref RTEMS_EVENT_31, the event parameter to the |
---|
94 | * rtems_event_send() directive should be @ref RTEMS_EVENT_6 | |
---|
95 | * @ref RTEMS_EVENT_15 | @ref RTEMS_EVENT_31. |
---|
96 | * |
---|
97 | * @{ |
---|
98 | */ |
---|
99 | |
---|
100 | /** |
---|
101 | * @brief Sends an event set to the target task. |
---|
102 | * |
---|
103 | * This directive sends an event set @a event_in to the task specified by |
---|
104 | * @a id. |
---|
105 | * |
---|
106 | * Based upon the state of the target task, one of the following situations |
---|
107 | * applies. The target task is |
---|
108 | * - blocked waiting for events. |
---|
109 | * If the waiting task's input event condition is |
---|
110 | * - satisfied, then the task is made ready for execution. |
---|
111 | * - not satisfied, then the event set is posted but left pending and the |
---|
112 | * task remains blocked. |
---|
113 | * - not waiting for events. |
---|
114 | * - The event set is posted and left pending. |
---|
115 | * |
---|
116 | * Identical events sent to a task are not queued. In other words, the second, |
---|
117 | * and subsequent, posting of an event to a task before it can perform an |
---|
118 | * rtems_event_receive() has no effect. |
---|
119 | * |
---|
120 | * The calling task will be preempted if it has preemption enabled and a |
---|
121 | * higher priority task is unblocked as the result of this directive. |
---|
122 | * |
---|
123 | * Sending an event set to a global task which does not reside on the local |
---|
124 | * node will generate a request telling the remote node to send the event set |
---|
125 | * to the appropriate task. |
---|
126 | * |
---|
127 | * @param[in] id Identifier of the target task. Specifying @ref RTEMS_SELF |
---|
128 | * results in the event set being sent to the calling task. |
---|
129 | * @param[in] event_in Event set sent to the target task. |
---|
130 | * |
---|
131 | * @retval RTEMS_SUCCESSFUL Successful operation. |
---|
132 | * @retval RTEMS_INVALID_ID Invalid task identifier. |
---|
133 | */ |
---|
134 | rtems_status_code rtems_event_send ( |
---|
135 | rtems_id id, |
---|
136 | rtems_event_set event_in |
---|
137 | ); |
---|
138 | |
---|
139 | /** |
---|
140 | * @brief Receives pending events. |
---|
141 | * |
---|
142 | * This directive attempts to receive the event condition specified in |
---|
143 | * @a event_in. If @a event_in is set to @ref RTEMS_PENDING_EVENTS, then the |
---|
144 | * current pending events are returned in @a event_out and left pending. The |
---|
145 | * @aref RTEMS_WAIT and @aref RTEMS_NO_WAIT options in the @a option_set |
---|
146 | * parameter are used to specify whether or not the task is willing to wait |
---|
147 | * for the event condition to be satisfied. The @ref RTEMS_EVENT_ANY and @ref |
---|
148 | * RTEMS_EVENT_ALL are used in the @a option_set parameter to specify whether |
---|
149 | * at least a single event or the complete event set is necessary to satisfy |
---|
150 | * the event condition. The @a event_out parameter is returned to the calling |
---|
151 | * task with the value that corresponds to the events in @a event_in that were |
---|
152 | * satisfied. |
---|
153 | * |
---|
154 | * A task can determine the pending event set by using a value of |
---|
155 | * @ref RTEMS_PENDING_EVENTS for the input event set @a event_in. The pending |
---|
156 | * events are returned to the calling task but the event set is left |
---|
157 | * unaltered. |
---|
158 | * |
---|
159 | * A task can receive all of the currently pending events by using the a value |
---|
160 | * of @ref RTEMS_ALL_EVENTS for the input event set @a event_in and |
---|
161 | * @ref RTEMS_NO_WAIT | @ref RTEMS_EVENT_ANY for the option set @a option_set. |
---|
162 | * The pending events are returned to the calling task and the event set is |
---|
163 | * cleared. If no events are pending then the @ref RTEMS_UNSATISFIED status |
---|
164 | * code will be returned. |
---|
165 | * |
---|
166 | * If pending events satisfy the event condition, then @a event_out is set to |
---|
167 | * the satisfied events and the pending events in the event condition are |
---|
168 | * cleared. If the event condition is not satisfied and @ref RTEMS_NO_WAIT is |
---|
169 | * specified, then @a event_out is set to the currently satisfied events. If |
---|
170 | * the calling task chooses to wait, then it will block waiting for the event |
---|
171 | * condition. |
---|
172 | * |
---|
173 | * If the calling task must wait for the event condition to be satisfied, then |
---|
174 | * the timeout parameter is used to specify the maximum interval to wait. If |
---|
175 | * it is set to @ref RTEMS_NO_TIMEOUT, then the calling task will wait forever. |
---|
176 | * |
---|
177 | * This directive only affects the events specified in @a event_in. Any |
---|
178 | * pending events that do not correspond to any of the events specified in |
---|
179 | * @a event_in will be left pending. |
---|
180 | * |
---|
181 | * A clock tick is required to support the wait with time out functionality of |
---|
182 | * this directive. |
---|
183 | * |
---|
184 | * @param[in] event_in Set of requested events (input events). |
---|
185 | * @param[in] option_set Use a bitwise or of the following options |
---|
186 | * - @ref RTEMS_WAIT - task will wait for event (default), |
---|
187 | * - @ref RTEMS_NO_WAIT - task should not wait, |
---|
188 | * - @ref RTEMS_EVENT_ALL - return after all events (default), and |
---|
189 | * - @ref RTEMS_EVENT_ANY - return after any events. |
---|
190 | * @param[in] ticks Time out in ticks. Use @ref RTEMS_NO_TIMEOUT to wait |
---|
191 | * without a time out (potentially forever). |
---|
192 | * @param[out] event_out Set of received events (output events). |
---|
193 | * |
---|
194 | * @retval RTEMS_SUCCESSFUL Successful operation. |
---|
195 | * @retval RTEMS_UNSATISFIED Input events not satisfied (only with the |
---|
196 | * @ref RTEMS_NO_WAIT option). |
---|
197 | * @retval RTEMS_INVALID_ADDRESS The @a event_out pointer is @c NULL. |
---|
198 | * @retval RTEMS_TIMEOUT Timed out waiting for events. |
---|
199 | */ |
---|
200 | rtems_status_code rtems_event_receive ( |
---|
201 | rtems_event_set event_in, |
---|
202 | rtems_option option_set, |
---|
203 | rtems_interval ticks, |
---|
204 | rtems_event_set *event_out |
---|
205 | ); |
---|
206 | |
---|
207 | /** @} */ |
---|
208 | |
---|
209 | /** |
---|
210 | * @defgroup ScoreEvent Event Handler |
---|
211 | * |
---|
212 | * @ingroup Score |
---|
213 | * |
---|
214 | * @{ |
---|
215 | */ |
---|
216 | |
---|
217 | /** |
---|
218 | * This constant is passed as the event_in to the |
---|
219 | * rtems_event_receive directive to determine which events are pending. |
---|
220 | */ |
---|
221 | #define EVENT_CURRENT 0 |
---|
222 | |
---|
223 | /** |
---|
224 | * @brief Event_Manager_initialization |
---|
225 | * |
---|
226 | * This routine performs the initialization necessary for this manager. |
---|
227 | */ |
---|
228 | void _Event_Manager_initialization( void ); |
---|
229 | |
---|
230 | /** |
---|
231 | * @brief Event_Seize |
---|
232 | * |
---|
233 | * This routine determines if the event condition event_in is |
---|
234 | * satisfied. If so or if the no_wait option is enabled in option_set, |
---|
235 | * then the procedure returns immediately. If neither of these |
---|
236 | * conditions is true, then the calling task is blocked with an |
---|
237 | * optional timeout of ticks clock ticks. |
---|
238 | */ |
---|
239 | void _Event_Seize ( |
---|
240 | rtems_event_set event_in, |
---|
241 | rtems_option option_set, |
---|
242 | rtems_interval ticks, |
---|
243 | rtems_event_set *event_out |
---|
244 | ); |
---|
245 | |
---|
246 | /** |
---|
247 | * @brief Event_Surrender |
---|
248 | * |
---|
249 | * This routine determines if the event condition of the_thread |
---|
250 | * has been satisfied. If so, it unblocks the_thread. |
---|
251 | */ |
---|
252 | void _Event_Surrender ( |
---|
253 | Thread_Control *the_thread |
---|
254 | ); |
---|
255 | |
---|
256 | /** |
---|
257 | * @brief Event_Timeout |
---|
258 | * |
---|
259 | * This routine is invoked when a task's event receive request |
---|
260 | * has not been satisfied after the specified timeout interval. |
---|
261 | * The task represented by ID will be unblocked and its status |
---|
262 | * code will be set in it's control block to indicate that a timeout |
---|
263 | * has occurred. |
---|
264 | */ |
---|
265 | void _Event_Timeout ( |
---|
266 | Objects_Id id, |
---|
267 | void *ignored |
---|
268 | ); |
---|
269 | |
---|
270 | /** |
---|
271 | * @brief he following defines the synchronization flag used by the |
---|
272 | */ |
---|
273 | RTEMS_EVENT_EXTERN volatile Thread_blocking_operation_States _Event_Sync_state; |
---|
274 | |
---|
275 | /** @} */ |
---|
276 | |
---|
277 | #if defined(RTEMS_MULTIPROCESSING) |
---|
278 | #include <rtems/rtems/eventmp.h> |
---|
279 | #endif |
---|
280 | #ifndef __RTEMS_APPLICATION__ |
---|
281 | #include <rtems/rtems/event.inl> |
---|
282 | #endif |
---|
283 | |
---|
284 | #ifdef __cplusplus |
---|
285 | } |
---|
286 | #endif |
---|
287 | |
---|
288 | #endif |
---|
289 | /* end of include file */ |
---|