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

5
Last change on this file since c65aeed was 3384994, checked in by Chris Johns <chrisj@…>, on 11/13/17 at 02:25:18

Clean up sphinx warnings.

  • Fix minor formatting issues.
  • Fix reference the gloassary TLS using ':term:'.
  • Make sure nothing is between an anchor and the heading where ':ref:' references the anchor. This meant moving all the recently added '.. index::' entries.

Update #3232.
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.. index:: send event set to a task
186.. index:: rtems_event_send
187
188.. _rtems_event_send:
189
190EVENT_SEND - Send event set to a task
191-------------------------------------
192
193CALLING SEQUENCE:
194    .. code-block:: c
195
196        rtems_status_code rtems_event_send (
197            rtems_id         id,
198            rtems_event_set  event_in
199        );
200
201DIRECTIVE STATUS CODES:
202    .. list-table::
203     :class: rtems-table
204
205     * - ``RTEMS_SUCCESSFUL``
206       - event set sent successfully
207     * - ``RTEMS_INVALID_ID``
208       - invalid task id
209
210DESCRIPTION:
211    This directive sends an event set, event_in, to the task specified by id.
212    If a blocked task's input event condition is satisfied by this directive,
213    then it will be made ready.  If its input event condition is not satisfied,
214    then the events satisfied are updated and the events not satisfied are left
215    pending.  If the task specified by id is not blocked waiting for events,
216    then the events sent are left pending.
217
218NOTES:
219    Specifying ``RTEMS_SELF`` for id results in the event set being sent to the
220    calling task.
221
222    Identical events sent to a task are not queued.  In other words, the
223    second, and subsequent, posting of an event to a task before it can perform
224    an ``rtems_event_receive`` has no effect.
225
226    The calling task will be preempted if it has preemption enabled and a
227    higher priority task is unblocked as the result of this directive.
228
229    Sending an event set to a global task which does not reside on the local
230    node will generate a request telling the remote node to send the event set
231    to the appropriate task.
232
233.. raw:: latex
234
235   \clearpage
236
237.. index:: receive event condition
238.. index:: rtems_event_receive
239
240.. _rtems_event_receive:
241
242EVENT_RECEIVE - Receive event condition
243---------------------------------------
244
245CALLING SEQUENCE:
246    .. code-block:: c
247
248        rtems_status_code rtems_event_receive (
249            rtems_event_set  event_in,
250            rtems_option     option_set,
251            rtems_interval   ticks,
252            rtems_event_set *event_out
253        );
254
255DIRECTIVE STATUS CODES:
256    .. list-table::
257     :class: rtems-table
258
259     * - ``RTEMS_SUCCESSFUL``
260       - event received successfully
261     * - ``RTEMS_UNSATISFIED``
262       - input event not satisfied (``RTEMS_NO_WAIT``)
263     * - ``RTEMS_INVALID_ADDRESS``
264       - ``event_out`` is NULL
265     * - ``RTEMS_TIMEOUT``
266       - timed out waiting for event
267
268DESCRIPTION:
269
270    This directive attempts to receive the event condition specified in
271    event_in.  If event_in is set to ``RTEMS_PENDING_EVENTS``, then the current
272    pending events are returned in event_out and left pending.  The
273    ``RTEMS_WAIT`` and ``RTEMS_NO_WAIT`` options in the option_set parameter
274    are used to specify whether or not the task is willing to wait for the
275    event condition to be satisfied. ``RTEMS_EVENT_ANY`` and
276    ``RTEMS_EVENT_ALL`` are used in the option_set parameter are used to
277    specify whether a single event or the complete event set is necessary to
278    satisfy the event condition.  The event_out parameter is returned to the
279    calling task with the value that corresponds to the events in event_in that
280    were satisfied.
281
282    If pending events satisfy the event condition, then event_out is set to the
283    satisfied events and the pending events in the event condition are cleared.
284    If the event condition is not satisfied and ``RTEMS_NO_WAIT`` is specified,
285    then event_out is set to the currently satisfied events.  If the calling
286    task chooses to wait, then it will block waiting for the event condition.
287
288    If the calling task must wait for the event condition to be satisfied, then
289    the timeout parameter is used to specify the maximum interval to wait.  If
290    it is set to ``RTEMS_NO_TIMEOUT``, then the calling task will wait forever.
291
292NOTES:
293    This directive only affects the events specified in event_in.  Any pending
294    events that do not correspond to any of the events specified in event_in
295    will be left pending.
296
297    The following event receive option constants are defined by RTEMS:
298
299    .. list-table::
300     :class: rtems-table
301
302     * - ``RTEMS_WAIT``
303       - task will wait for event (default)
304     * - ``RTEMS_NO_WAIT``
305       - task should not wait
306     * - ``RTEMS_EVENT_ALL``
307       - return after all events (default)
308     * - ``RTEMS_EVENT_ANY``
309       - return after any events
310
311    A clock tick is required to support the functionality of this directive.
Note: See TracBrowser for help on using the repository browser.