source: rtems-docs/c-user/event_manager.rst @ 6c56401

5
Last change on this file since 6c56401 was 6c56401, checked in by Chris Johns <chrisj@…>, on 11/12/17 at 03:34:48

c-user: Fix index locations.

Update #3229.

  • Property mode set to 100644
File size: 11.0 KB
Line 
1.. comment SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. COMMENT: COPYRIGHT (c) 1988-2008.
4.. COMMENT: On-Line Applications Research Corporation (OAR).
5.. COMMENT: All rights reserved.
6
7.. index:: events
8
9Event Manager
10*************
11
12Introduction
13============
14
15The event manager provides a high performance method of intertask communication
16and synchronization.  The directives provided by the event manager are:
17
18- rtems_event_send_ - Send event set to a task
19- rtems_event_receive_ - Receive event condition
20
21Background
22==========
23
24.. index:: event flag, definition
25.. index:: event set, definition
26.. index:: rtems_event_set
27
28Event Sets
29----------
30
31An event flag is used by a task (or ISR) to inform another task of the
32occurrence of a significant situation.  Thirty-two event flags are associated
33with each task.  A collection of one or more event flags is referred to as an
34event set.  The data type ``rtems_event_set`` is used to manage event sets.
35
36The application developer should remember the following key characteristics of
37event operations when utilizing the event manager:
38
39- Events provide a simple synchronization facility.
40
41- Events are aimed at tasks.
42
43- Tasks can wait on more than one event simultaneously.
44
45- Events are independent of one another.
46
47- Events do not hold or transport data.
48
49- Events are not queued.  In other words, if an event is sent more than once to
50  a task before being received, the second and subsequent send operations to
51  that same task have no effect.
52
53An event set is posted when it is directed (or sent) to a task.  A pending
54event is an event that has been posted but not received.  An event condition is
55used to specify the event set which the task desires to receive and the
56algorithm which will be used to determine when the request is satisfied. An
57event condition is satisfied based upon one of two algorithms which are
58selected by the user.  The ``RTEMS_EVENT_ANY`` algorithm states that an event
59condition is satisfied when at least a single requested event is posted.  The
60``RTEMS_EVENT_ALL`` algorithm states that an event condition is satisfied when
61every requested event is posted.
62
63.. index:: event condition, building
64.. index:: event set, building
65
66Building an Event Set or Condition
67----------------------------------
68
69An event set or condition is built by a bitwise OR of the desired events.  The
70set of valid events is ``RTEMS_EVENT_0`` through ``RTEMS_EVENT_31``.  If an
71event is not explicitly specified in the set or condition, then it is not
72present.  Events are specifically designed to be mutually exclusive, therefore
73bitwise OR and addition operations are equivalent as long as each event appears
74exactly once in the event set list.
75
76For example, when sending the event set consisting of ``RTEMS_EVENT_6``,
77``RTEMS_EVENT_15``, and ``RTEMS_EVENT_31``, the event parameter to the
78``rtems_event_send`` directive should be ``RTEMS_EVENT_6 | RTEMS_EVENT_15 |
79RTEMS_EVENT_31``.
80
81Building an EVENT_RECEIVE Option Set
82------------------------------------
83
84In general, an option is built by a bitwise OR of the desired option
85components.  The set of valid options for the ``rtems_event_receive`` directive
86are listed in the following table:
87
88.. list-table::
89 :class: rtems-table
90
91 * - ``RTEMS_WAIT``
92   - task will wait for event (default)
93 * - ``RTEMS_NO_WAIT``
94   - task should not wait
95 * - ``RTEMS_EVENT_ALL``
96   - return after all events (default)
97 * - ``RTEMS_EVENT_ANY``
98   - return after any events
99
100Option values are specifically designed to be mutually exclusive, therefore
101bitwise OR and addition operations are equivalent as long as each option
102appears exactly once in the component list.  An option listed as a default is
103not required to appear in the option list, although it is a good programming
104practice to specify default options.  If all defaults are desired, the option
105``RTEMS_DEFAULT_OPTIONS`` should be specified on this call.
106
107This example demonstrates the option parameter needed to poll for all events in
108a particular event condition to arrive.  The option parameter passed to the
109``rtems_event_receive`` directive should be either ``RTEMS_EVENT_ALL |
110RTEMS_NO_WAIT`` or ``RTEMS_NO_WAIT``.  The option parameter can be set to
111``RTEMS_NO_WAIT`` because ``RTEMS_EVENT_ALL`` is the default condition for
112``rtems_event_receive``.
113
114Operations
115==========
116
117Sending an Event Set
118--------------------
119
120The ``rtems_event_send`` directive allows a task (or an ISR) to direct an event
121set to a target task.  Based upon the state of the target task, one of the
122following situations applies:
123
124- Target Task is Blocked Waiting for Events
125
126  - If the waiting task's input event condition is satisfied, then the task is
127    made ready for execution.
128
129  - If the waiting task's input event condition is not satisfied, then the
130    event set is posted but left pending and the task remains blocked.
131
132- Target Task is Not Waiting for Events
133
134  - The event set is posted and left pending.
135
136Receiving an Event Set
137----------------------
138
139The ``rtems_event_receive`` directive is used by tasks to accept a specific
140input event condition.  The task also specifies whether the request is
141satisfied when all requested events are available or any single requested event
142is available.  If the requested event condition is satisfied by pending events,
143then a successful return code and the satisfying event set are returned
144immediately.  If the condition is not satisfied, then one of the following
145situations applies:
146
147- By default, the calling task will wait forever for the event condition to be
148  satisfied.
149
150- Specifying the ``RTEMS_NO_WAIT`` option forces an immediate return with an
151  error status code.
152
153- Specifying a timeout limits the period the task will wait before returning
154  with an error status code.
155
156Determining the Pending Event Set
157---------------------------------
158
159A task can determine the pending event set by calling the
160``rtems_event_receive`` directive with a value of ``RTEMS_PENDING_EVENTS`` for
161the input event condition.  The pending events are returned to the calling task
162but the event set is left unaltered.
163
164Receiving all Pending Events
165----------------------------
166
167A task can receive all of the currently pending events by calling the
168``rtems_event_receive`` directive with a value of ``RTEMS_ALL_EVENTS`` for the
169input event condition and ``RTEMS_NO_WAIT | RTEMS_EVENT_ANY`` for the option
170set.  The pending events are returned to the calling task and the event set is
171cleared.  If no events are pending then the ``RTEMS_UNSATISFIED`` status code
172will be returned.
173
174Directives
175==========
176
177This section details the event manager's directives.  A subsection is dedicated
178to each of this manager's directives and describes the calling sequence,
179related constants, usage, and status codes.
180
181.. raw:: latex
182
183   \clearpage
184
185.. _rtems_event_send:
186.. index:: send event set to a task
187.. index:: rtems_event_send
188
189EVENT_SEND - Send event set to a task
190-------------------------------------
191
192CALLING SEQUENCE:
193    .. code-block:: c
194
195        rtems_status_code rtems_event_send (
196            rtems_id         id,
197            rtems_event_set  event_in
198        );
199
200DIRECTIVE STATUS CODES:
201    .. list-table::
202     :class: rtems-table
203
204     * - ``RTEMS_SUCCESSFUL``
205       - event set sent successfully
206     * - ``RTEMS_INVALID_ID``
207       - invalid task id
208
209DESCRIPTION:
210    This directive sends an event set, event_in, to the task specified by id.
211    If a blocked task's input event condition is satisfied by this directive,
212    then it will be made ready.  If its input event condition is not satisfied,
213    then the events satisfied are updated and the events not satisfied are left
214    pending.  If the task specified by id is not blocked waiting for events,
215    then the events sent are left pending.
216
217NOTES:
218    Specifying ``RTEMS_SELF`` for id results in the event set being sent to the
219    calling task.
220
221    Identical events sent to a task are not queued.  In other words, the
222    second, and subsequent, posting of an event to a task before it can perform
223    an ``rtems_event_receive`` has no effect.
224
225    The calling task will be preempted if it has preemption enabled and a
226    higher priority task is unblocked as the result of this directive.
227
228    Sending an event set to a global task which does not reside on the local
229    node will generate a request telling the remote node to send the event set
230    to the appropriate task.
231
232.. raw:: latex
233
234   \clearpage
235
236.. _rtems_event_receive:
237.. index:: receive event condition
238.. index:: rtems_event_receive
239
240EVENT_RECEIVE - Receive event condition
241---------------------------------------
242
243CALLING SEQUENCE:
244    .. code-block:: c
245
246        rtems_status_code rtems_event_receive (
247            rtems_event_set  event_in,
248            rtems_option     option_set,
249            rtems_interval   ticks,
250            rtems_event_set *event_out
251        );
252
253DIRECTIVE STATUS CODES:
254    .. list-table::
255     :class: rtems-table
256
257     * - ``RTEMS_SUCCESSFUL``
258       - event received successfully
259     * - ``RTEMS_UNSATISFIED``
260       - input event not satisfied (``RTEMS_NO_WAIT``)
261     * - ``RTEMS_INVALID_ADDRESS``
262       - ``event_out`` is NULL
263     * - ``RTEMS_TIMEOUT``
264       - timed out waiting for event
265
266DESCRIPTION:
267
268    This directive attempts to receive the event condition specified in
269    event_in.  If event_in is set to ``RTEMS_PENDING_EVENTS``, then the current
270    pending events are returned in event_out and left pending.  The
271    ``RTEMS_WAIT`` and ``RTEMS_NO_WAIT`` options in the option_set parameter
272    are used to specify whether or not the task is willing to wait for the
273    event condition to be satisfied. ``RTEMS_EVENT_ANY`` and
274    ``RTEMS_EVENT_ALL`` are used in the option_set parameter are used to
275    specify whether a single event or the complete event set is necessary to
276    satisfy the event condition.  The event_out parameter is returned to the
277    calling task with the value that corresponds to the events in event_in that
278    were satisfied.
279
280    If pending events satisfy the event condition, then event_out is set to the
281    satisfied events and the pending events in the event condition are cleared.
282    If the event condition is not satisfied and ``RTEMS_NO_WAIT`` is specified,
283    then event_out is set to the currently satisfied events.  If the calling
284    task chooses to wait, then it will block waiting for the event condition.
285
286    If the calling task must wait for the event condition to be satisfied, then
287    the timeout parameter is used to specify the maximum interval to wait.  If
288    it is set to ``RTEMS_NO_TIMEOUT``, then the calling task will wait forever.
289
290NOTES:
291    This directive only affects the events specified in event_in.  Any pending
292    events that do not correspond to any of the events specified in event_in
293    will be left pending.
294
295    The following event receive option constants are defined by RTEMS:
296
297    .. list-table::
298     :class: rtems-table
299
300     * - ``RTEMS_WAIT``
301       - task will wait for event (default)
302     * - ``RTEMS_NO_WAIT``
303       - task should not wait
304     * - ``RTEMS_EVENT_ALL``
305       - return after all events (default)
306     * - ``RTEMS_EVENT_ANY``
307       - return after any events
308
309    A clock tick is required to support the functionality of this directive.
Note: See TracBrowser for help on using the repository browser.