1 | Signal Manager |
---|
2 | ############## |
---|
3 | |
---|
4 | .. index:: signals |
---|
5 | |
---|
6 | Introduction |
---|
7 | ============ |
---|
8 | |
---|
9 | The signal manager provides the capabilities required |
---|
10 | for asynchronous communication. The directives provided by the |
---|
11 | signal manager are: |
---|
12 | |
---|
13 | - ``rtems_signal_catch`` - Establish an ASR |
---|
14 | |
---|
15 | - ``rtems_signal_send`` - Send signal set to a task |
---|
16 | |
---|
17 | Background |
---|
18 | ========== |
---|
19 | |
---|
20 | Signal Manager Definitions |
---|
21 | -------------------------- |
---|
22 | .. index:: asynchronous signal routine |
---|
23 | .. index:: ASR |
---|
24 | |
---|
25 | The signal manager allows a task to optionally define |
---|
26 | an asynchronous signal routine (ASR). An ASR is to a task what |
---|
27 | an ISR is to an application's set of tasks. When the processor |
---|
28 | is interrupted, the execution of an application is also |
---|
29 | interrupted and an ISR is given control. Similarly, when a |
---|
30 | signal 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 |
---|
32 | effect on the receiving task's current execution state... index:: rtems_signal_set |
---|
33 | |
---|
34 | A signal flag is used by a task (or ISR) to inform |
---|
35 | another task of the occurrence of a significant situation. |
---|
36 | Thirty-two signal flags are associated with each task. A |
---|
37 | collection of one or more signals is referred to as a signal |
---|
38 | set. The data type ``rtems_signal_set`` |
---|
39 | is used to manipulate signal sets. |
---|
40 | |
---|
41 | A signal set is posted when it is directed (or sent) to a |
---|
42 | task. A pending signal is a signal that has been sent to a task |
---|
43 | with a valid ASR, but has not been processed by that task's ASR. |
---|
44 | |
---|
45 | A Comparison of ASRs and ISRs |
---|
46 | ----------------------------- |
---|
47 | .. index:: ASR vs. ISR |
---|
48 | .. index:: ISR vs. ASR |
---|
49 | |
---|
50 | The format of an ASR is similar to that of an ISR |
---|
51 | with 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 | |
---|
68 | Building a Signal Set |
---|
69 | --------------------- |
---|
70 | .. index:: signal set, building |
---|
71 | |
---|
72 | A signal set is built by a bitwise OR of the desired |
---|
73 | signals. The set of valid signals is ``RTEMS_SIGNAL_0`` through``RTEMS_SIGNAL_31``. If a signal is not explicitly specified in the |
---|
74 | signal set, then it is not present. Signal values are |
---|
75 | specifically designed to be mutually exclusive, therefore |
---|
76 | bitwise OR and addition operations are equivalent as long as |
---|
77 | each signal appears exactly once in the component list. |
---|
78 | |
---|
79 | This example demonstrates the signal parameter used |
---|
80 | when sending the signal set consisting of``RTEMS_SIGNAL_6``,``RTEMS_SIGNAL_15``, and``RTEMS_SIGNAL_31``. The signal parameter provided |
---|
81 | to the ``rtems_signal_send`` directive should be``RTEMS_SIGNAL_6 | |
---|
82 | RTEMS_SIGNAL_15 | RTEMS_SIGNAL_31``. |
---|
83 | |
---|
84 | Building an ASR Mode |
---|
85 | -------------------- |
---|
86 | .. index:: ASR mode, building |
---|
87 | |
---|
88 | In general, an ASR's mode is built by a bitwise OR of |
---|
89 | the desired mode components. The set of valid mode components |
---|
90 | is the same as those allowed with the task_create and task_mode |
---|
91 | directives. A complete list of mode options is provided in the |
---|
92 | following 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 | |
---|
110 | Mode values are specifically designed to be mutually |
---|
111 | exclusive, therefore bitwise OR and addition operations are |
---|
112 | equivalent as long as each mode appears exactly once in the |
---|
113 | component list. A mode component listed as a default is not |
---|
114 | required to appear in the mode list, although it is a good |
---|
115 | programming practice to specify default components. If all |
---|
116 | defaults are desired, the mode DEFAULT_MODES should be specified |
---|
117 | on this call. |
---|
118 | |
---|
119 | This example demonstrates the mode parameter used |
---|
120 | with the ``rtems_signal_catch`` |
---|
121 | to establish an ASR which executes at |
---|
122 | interrupt level three and is non-preemptible. The mode should |
---|
123 | be set to``RTEMS_INTERRUPT_LEVEL(3) | RTEMS_NO_PREEMPT`` |
---|
124 | to indicate the |
---|
125 | desired processor mode and interrupt level. |
---|
126 | |
---|
127 | Operations |
---|
128 | ========== |
---|
129 | |
---|
130 | Establishing an ASR |
---|
131 | ------------------- |
---|
132 | |
---|
133 | The ``rtems_signal_catch`` directive establishes an ASR for the |
---|
134 | calling task. The address of the ASR and its execution mode are |
---|
135 | specified to this directive. The ASR's mode is distinct from |
---|
136 | the task's mode. For example, the task may allow preemption, |
---|
137 | while that task's ASR may have preemption disabled. Until a |
---|
138 | task calls ``rtems_signal_catch`` the first time, |
---|
139 | its ASR is invalid, and no signal sets can be sent to the task. |
---|
140 | |
---|
141 | A task may invalidate its ASR and discard all pending |
---|
142 | signals by calling ``rtems_signal_catch`` |
---|
143 | with a value of NULL for the ASR's address. When a task's |
---|
144 | ASR is invalid, new signal sets sent to this task are discarded. |
---|
145 | |
---|
146 | A task may disable ASR processing (``RTEMS_NO_ASR``) via the |
---|
147 | task_mode directive. When a task's ASR is disabled, the signals |
---|
148 | sent to it are left pending to be processed later when the ASR |
---|
149 | is enabled. |
---|
150 | |
---|
151 | Any directive that can be called from a task can also |
---|
152 | be called from an ASR. A task is only allowed one active ASR. |
---|
153 | Thus, each call to ``rtems_signal_catch`` |
---|
154 | replaces the previous one. |
---|
155 | |
---|
156 | Normally, signal processing is disabled for the ASR's |
---|
157 | execution mode, but if signal processing is enabled for the ASR, |
---|
158 | the ASR must be reentrant. |
---|
159 | |
---|
160 | Sending a Signal Set |
---|
161 | -------------------- |
---|
162 | |
---|
163 | The ``rtems_signal_send`` directive allows both |
---|
164 | tasks and ISRs to send signals to a target task. The target task and |
---|
165 | a set of signals are specified to the``rtems_signal_send`` directive. The sending |
---|
166 | of a signal to a task has no effect on the execution state of |
---|
167 | that task. If the task is not the currently running task, then |
---|
168 | the signals are left pending and processed by the task's ASR the |
---|
169 | next time the task is dispatched to run. The ASR is executed |
---|
170 | immediately before the task is dispatched. If the currently |
---|
171 | running task sends a signal to itself or is sent a signal from |
---|
172 | an ISR, its ASR is immediately dispatched to run provided signal |
---|
173 | processing is enabled. |
---|
174 | |
---|
175 | If an ASR with signals enabled is preempted by |
---|
176 | another task or an ISR and a new signal set is sent, then a new |
---|
177 | copy of the ASR will be invoked, nesting the preempted ASR. |
---|
178 | Upon completion of processing the new signal set, control will |
---|
179 | return to the preempted ASR. In this situation, the ASR must be |
---|
180 | reentrant. |
---|
181 | |
---|
182 | Like events, identical signals sent to a task are not |
---|
183 | queued. In other words, sending the same signal multiple times |
---|
184 | to a task (without any intermediate signal processing occurring |
---|
185 | for the task), has the same result as sending that signal to |
---|
186 | that task once. |
---|
187 | |
---|
188 | Processing an ASR |
---|
189 | ----------------- |
---|
190 | |
---|
191 | Asynchronous signals were designed to provide the |
---|
192 | capability to generate software interrupts. The processing of |
---|
193 | software interrupts parallels that of hardware interrupts. As a |
---|
194 | result, the differences between the formats of ASRs and ISRs is |
---|
195 | limited to the meaning of the single argument passed to an ASR. |
---|
196 | The ASR should have the following calling sequence and adhere to |
---|
197 | C calling conventions:.. index:: rtems_asr |
---|
198 | |
---|
199 | .. code:: c |
---|
200 | |
---|
201 | rtems_asr user_routine( |
---|
202 | rtems_signal_set signals |
---|
203 | ); |
---|
204 | |
---|
205 | When the ASR returns to RTEMS the mode and execution |
---|
206 | path of the interrupted task (or ASR) is restored to the context |
---|
207 | prior to entering the ASR. |
---|
208 | |
---|
209 | Directives |
---|
210 | ========== |
---|
211 | |
---|
212 | This section details the signal manager's directives. |
---|
213 | A subsection is dedicated to each of this manager's directives |
---|
214 | and describes the calling sequence, related constants, usage, |
---|
215 | and status codes. |
---|
216 | |
---|
217 | SIGNAL_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 | |
---|
239 | This directive establishes an asynchronous signal |
---|
240 | routine (ASR) for the calling task. The asr_handler parameter |
---|
241 | specifies the entry point of the ASR. If asr_handler is NULL, |
---|
242 | the ASR for the calling task is invalidated and all pending |
---|
243 | signals are cleared. Any signals sent to a task with an invalid |
---|
244 | ASR are discarded. The mode parameter specifies the execution |
---|
245 | mode for the ASR. This execution mode supersedes the task's |
---|
246 | execution mode while the ASR is executing. |
---|
247 | |
---|
248 | **NOTES:** |
---|
249 | |
---|
250 | This directive will not cause the calling task to be |
---|
251 | preempted. |
---|
252 | |
---|
253 | The 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 | |
---|
271 | SIGNAL_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 | |
---|
295 | This directive sends a signal set to the task |
---|
296 | specified in id. The signal_set parameter contains the signal |
---|
297 | set to be sent to the task. |
---|
298 | |
---|
299 | If a caller sends a signal set to a task with an |
---|
300 | invalid ASR, then an error code is returned to the caller. If a |
---|
301 | caller sends a signal set to a task whose ASR is valid but |
---|
302 | disabled, then the signal set will be caught and left pending |
---|
303 | for the ASR to process when it is enabled. If a caller sends a |
---|
304 | signal set to a task with an ASR that is both valid and enabled, |
---|
305 | then the signal set is caught and the ASR will execute the next |
---|
306 | time the task is dispatched to run. |
---|
307 | |
---|
308 | **NOTES:** |
---|
309 | |
---|
310 | Sending a signal set to a task has no effect on that |
---|
311 | task's state. If a signal set is sent to a blocked task, then |
---|
312 | the task will remain blocked and the signals will be processed |
---|
313 | when the task becomes the running task. |
---|
314 | |
---|
315 | Sending a signal set to a global task which does not |
---|
316 | reside on the local node will generate a request telling the |
---|
317 | remote 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 | |
---|