source: rtems-docs/c_user/signal_manager.rst @ 8ef6ea8

4.115
Last change on this file since 8ef6ea8 was 8ef6ea8, checked in by Chris Johns <chrisj@…>, on 01/27/16 at 06:50:19

Clean ups.

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