source: rtems-docs/c_user/signal_manager.rst @ 489740f

4.115
Last change on this file since 489740f was 489740f, checked in by Chris Johns <chrisj@…>, on 05/20/16 at 02:47:09

Set SPDX License Identifier in each source file.

  • Property mode set to 100644
File size: 11.6 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
7Signal Manager
8##############
9
10.. index:: signals
11
12Introduction
13============
14
15The signal manager provides the capabilities required for asynchronous
16communication.  The directives provided by the signal manager are:
17
18- rtems_signal_catch_ - Establish an ASR
19
20- rtems_signal_send_ - Send signal set to a task
21
22Background
23==========
24
25Signal Manager Definitions
26--------------------------
27.. index:: asynchronous signal routine
28.. index:: ASR
29
30The signal manager allows a task to optionally define an asynchronous signal
31routine (ASR).  An ASR is to a task what an ISR is to an application's set of
32tasks.  When the processor is interrupted, the execution of an application is
33also interrupted and an ISR is given control.  Similarly, when a signal is sent
34to a task, that task's execution path will be "interrupted" by the ASR.
35Sending a signal to a task has no effect on the receiving task's current
36execution state.
37
38.. index:: rtems_signal_set
39
40A signal flag is used by a task (or ISR) to inform another task of the
41occurrence of a significant situation.  Thirty-two signal flags are associated
42with each task.  A collection of one or more signals is referred to as a signal
43set.  The data type ``rtems_signal_set`` is used to manipulate signal sets.
44
45A signal set is posted when it is directed (or sent) to a task. A pending
46signal is a signal that has been sent to a task with a valid ASR, but has not
47been processed by that task's ASR.
48
49A Comparison of ASRs and ISRs
50-----------------------------
51.. index:: ASR vs. ISR
52.. index:: ISR vs. ASR
53
54The format of an ASR is similar to that of an ISR with the following
55exceptions:
56
57- ISRs are scheduled by the processor hardware.  ASRs are scheduled by RTEMS.
58
59- ISRs do not execute in the context of a task and may invoke only a subset of
60  directives.  ASRs execute in the context of a task and may execute any
61  directive.
62
63- When an ISR is invoked, it is passed the vector number as its argument.  When
64  an ASR is invoked, it is passed the signal set as its argument.
65
66- An ASR has a task mode which can be different from that of the task.  An ISR
67  does not execute as a task and, as a result, does not have a task mode.
68
69Building a Signal Set
70---------------------
71.. index:: signal set, building
72
73A signal set is built by a bitwise OR of the desired signals.  The set of valid
74signals is ``RTEMS_SIGNAL_0`` through ``RTEMS_SIGNAL_31``.  If a signal is not
75explicitly specified in the signal set, then it is not present.  Signal values
76are specifically designed to be mutually exclusive, therefore bitwise OR and
77addition operations are equivalent as long as each signal appears exactly once
78in the component list.
79
80This example demonstrates the signal parameter used when sending the signal set
81consisting of ``RTEMS_SIGNAL_6``, ``RTEMS_SIGNAL_15``, and ``RTEMS_SIGNAL_31``.
82The signal parameter provided to the ``rtems_signal_send`` directive should be
83``RTEMS_SIGNAL_6 | RTEMS_SIGNAL_15 | RTEMS_SIGNAL_31``.
84
85Building an ASR Mode
86--------------------
87.. index:: ASR mode, building
88
89In general, an ASR's mode is built by a bitwise OR of the desired mode
90components.  The set of valid mode components is the same as those allowed with
91the task_create and task_mode directives.  A complete list of mode options is
92provided in the following table:
93
94.. list-table::
95 :class: rtems-table
96
97 * - ``RTEMS_PREEMPT``
98   - is masked by ``RTEMS_PREEMPT_MASK`` and enables preemption
99 * - ``RTEMS_NO_PREEMPT``
100   - is masked by ``RTEMS_PREEMPT_MASK`` and disables preemption
101 * - ``RTEMS_NO_TIMESLICE``
102   - is masked by ``RTEMS_TIMESLICE_MASK`` and disables timeslicing
103 * - ``RTEMS_TIMESLICE``
104   - is masked by ``RTEMS_TIMESLICE_MASK`` and enables timeslicing
105 * - ``RTEMS_ASR``
106   - is masked by ``RTEMS_ASR_MASK`` and enables ASR processing
107 * - ``RTEMS_NO_ASR``
108   - is masked by ``RTEMS_ASR_MASK`` and disables ASR processing
109 * - ``RTEMS_INTERRUPT_LEVEL(0)``
110   - is masked by ``RTEMS_INTERRUPT_MASK`` and enables all interrupts
111 * - ``RTEMS_INTERRUPT_LEVEL(n)``
112   - is masked by ``RTEMS_INTERRUPT_MASK`` and sets interrupts level n
113
114Mode values are specifically designed to be mutually exclusive, therefore
115bitwise OR and addition operations are equivalent as long as each mode appears
116exactly once in the component list.  A mode component listed as a default is
117not required to appear in the mode list, although it is a good programming
118practice to specify default components.  If all defaults are desired, the mode
119``DEFAULT_MODES`` should be specified on this call.
120
121This example demonstrates the mode parameter used with the
122``rtems_signal_catch`` to establish an ASR which executes at interrupt level
123three and is non-preemptible.  The mode should be set to
124``RTEMS_INTERRUPT_LEVEL(3) | RTEMS_NO_PREEMPT`` to indicate the desired
125processor mode and interrupt level.
126
127Operations
128==========
129
130Establishing an ASR
131-------------------
132
133The ``rtems_signal_catch`` directive establishes an ASR for the calling task.
134The address of the ASR and its execution mode are specified to this directive.
135The ASR's mode is distinct from the task's mode.  For example, the task may
136allow preemption, while that task's ASR may have preemption disabled.  Until a
137task calls ``rtems_signal_catch`` the first time, its ASR is invalid, and no
138signal sets can be sent to the task.
139
140A task may invalidate its ASR and discard all pending signals by calling
141``rtems_signal_catch`` with a value of NULL for the ASR's address.  When a
142task's ASR is invalid, new signal sets sent to this task are discarded.
143
144A task may disable ASR processing (``RTEMS_NO_ASR``) via the task_mode
145directive.  When a task's ASR is disabled, the signals sent to it are left
146pending to be processed later when the ASR is enabled.
147
148Any directive that can be called from a task can also be called from an ASR.  A
149task is only allowed one active ASR.  Thus, each call to ``rtems_signal_catch``
150replaces the previous one.
151
152Normally, signal processing is disabled for the ASR's execution mode, but if
153signal processing is enabled for the ASR, the ASR must be reentrant.
154
155Sending a Signal Set
156--------------------
157
158The ``rtems_signal_send`` directive allows both tasks and ISRs to send signals
159to a target task.  The target task and a set of signals are specified to the
160``rtems_signal_send`` directive.  The sending of a signal to a task has no
161effect on the execution state of that task.  If the task is not the currently
162running task, then the signals are left pending and processed by the task's ASR
163the next time the task is dispatched to run.  The ASR is executed immediately
164before the task is dispatched.  If the currently running task sends a signal to
165itself or is sent a signal from an ISR, its ASR is immediately dispatched to
166run provided signal processing is enabled.
167
168If an ASR with signals enabled is preempted by another task or an ISR and a new
169signal set is sent, then a new copy of the ASR will be invoked, nesting the
170preempted ASR.  Upon completion of processing the new signal set, control will
171return to the preempted ASR.  In this situation, the ASR must be reentrant.
172
173Like events, identical signals sent to a task are not queued.  In other words,
174sending the same signal multiple times to a task (without any intermediate
175signal processing occurring for the task), has the same result as sending that
176signal to that task once.
177
178Processing an ASR
179-----------------
180
181Asynchronous signals were designed to provide the capability to generate
182software interrupts.  The processing of software interrupts parallels that of
183hardware interrupts.  As a result, the differences between the formats of ASRs
184and ISRs is limited to the meaning of the single argument passed to an ASR.
185The ASR should have the following calling sequence and adhere to C calling
186conventions:
187
188.. index:: rtems_asr
189
190.. code-block:: c
191
192    rtems_asr user_routine(
193        rtems_signal_set signals
194    );
195
196When the ASR returns to RTEMS the mode and execution path of the interrupted
197task (or ASR) is restored to the context prior to entering the ASR.
198
199Directives
200==========
201
202This section details the signal manager's directives.  A subsection is
203dedicated to each of this manager's directives and describes the calling
204sequence, related constants, usage, and status codes.
205
206.. _rtems_signal_catch:
207
208SIGNAL_CATCH - Establish an ASR
209-------------------------------
210.. index:: establish an ASR
211.. index:: install an ASR
212
213**CALLING SEQUENCE:**
214
215.. index:: rtems_signal_catch
216
217.. code-block:: c
218
219    rtems_status_code rtems_signal_catch(
220        rtems_asr_entry  asr_handler,
221        rtems_mode       mode
222    );
223
224**DIRECTIVE STATUS CODES:**
225
226.. list-table::
227 :class: rtems-table
228
229 * - ``RTEMS_SUCCESSFUL``
230   - always successful
231
232**DESCRIPTION:**
233
234This directive establishes an asynchronous signal routine (ASR) for the calling
235task.  The asr_handler parameter specifies the entry point of the ASR.  If
236asr_handler is NULL, the ASR for the calling task is invalidated and all
237pending signals are cleared.  Any signals sent to a task with an invalid ASR
238are discarded.  The mode parameter specifies the execution mode for the ASR.
239This execution mode supersedes the task's execution mode while the ASR is
240executing.
241
242**NOTES:**
243
244This directive will not cause the calling task to be preempted.
245
246The following task mode constants are defined by RTEMS:
247
248.. list-table::
249 :class: rtems-table
250
251 * - ``RTEMS_PREEMPT``
252   - is masked by ``RTEMS_PREEMPT_MASK`` and enables preemption
253 * - ``RTEMS_NO_PREEMPT``
254   - is masked by ``RTEMS_PREEMPT_MASK`` and disables preemption
255 * - ``RTEMS_NO_TIMESLICE``
256   - is masked by ``RTEMS_TIMESLICE_MASK`` and disables timeslicing
257 * - ``RTEMS_TIMESLICE``
258   - is masked by ``RTEMS_TIMESLICE_MASK`` and enables timeslicing
259 * - ``RTEMS_ASR``
260   - is masked by ``RTEMS_ASR_MASK`` and enables ASR processing
261 * - ``RTEMS_NO_ASR``
262   - is masked by ``RTEMS_ASR_MASK`` and disables ASR processing
263 * - ``RTEMS_INTERRUPT_LEVEL(0)``
264   - is masked by ``RTEMS_INTERRUPT_MASK`` and enables all interrupts
265 * - ``RTEMS_INTERRUPT_LEVEL(n)``
266   - is masked by ``RTEMS_INTERRUPT_MASK`` and sets interrupts level n
267
268.. _rtems_signal_send:
269
270SIGNAL_SEND - Send signal set to a task
271---------------------------------------
272.. index:: send signal set
273
274**CALLING SEQUENCE:**
275
276.. index:: rtems_signal_send
277
278.. code-block:: c
279
280    rtems_status_code rtems_signal_send(
281        rtems_id         id,
282        rtems_signal_set signal_set
283    );
284
285**DIRECTIVE STATUS CODES:**
286
287.. list-table::
288 :class: rtems-table
289
290 * - ``RTEMS_SUCCESSFUL``
291   - signal sent successfully
292 * - ``RTEMS_INVALID_ID``
293   - task id invalid
294 * - ``RTEMS_INVALID_NUMBER``
295   - empty signal set
296 * - ``RTEMS_NOT_DEFINED``
297   - ASR invalid
298
299**DESCRIPTION:**
300
301This directive sends a signal set to the task specified in id.  The signal_set
302parameter contains the signal set to be sent to the task.
303
304If a caller sends a signal set to a task with an invalid ASR, then an error
305code is returned to the caller.  If a caller sends a signal set to a task whose
306ASR is valid but disabled, then the signal set will be caught and left pending
307for the ASR to process when it is enabled. If a caller sends a signal set to a
308task with an ASR that is both valid and enabled, then the signal set is caught
309and the ASR will execute the next time the task is dispatched to run.
310
311**NOTES:**
312
313Sending a signal set to a task has no effect on that task's state.  If a signal
314set is sent to a blocked task, then the task will remain blocked and the
315signals will be processed when the task becomes the running task.
316
317Sending a signal set to a global task which does not reside on the local node
318will generate a request telling the remote node to send the signal set to the
319specified task.
Note: See TracBrowser for help on using the repository browser.