source: rtems-docs/c-user/signal_manager.rst @ 12dccfe

5
Last change on this file since 12dccfe was 12dccfe, checked in by Sebastian Huber <sebastian.huber@…>, on 01/09/19 at 15:14:05

Remove superfluous "All rights reserved."

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