source: rtems-docs/c_user/signal_manager.rst @ d389819

4.115
Last change on this file since d389819 was d389819, checked in by Amar Takhar <amar@…>, on 01/18/16 at 05:37:40

Convert all Unicode to ASCII(128)

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