1 | @c |
---|
2 | @c COPYRIGHT (c) 1988-1998. |
---|
3 | @c On-Line Applications Research Corporation (OAR). |
---|
4 | @c All rights reserved. |
---|
5 | @c |
---|
6 | @c $Id$ |
---|
7 | @c |
---|
8 | |
---|
9 | @chapter Interrupt Manager |
---|
10 | |
---|
11 | @section Introduction |
---|
12 | |
---|
13 | Any real-time executive must provide a mechanism for |
---|
14 | quick response to externally generated interrupts to satisfy the |
---|
15 | critical time constraints of the application. The interrupt |
---|
16 | manager provides this mechanism for RTEMS. This manager permits |
---|
17 | quick interrupt response times by providing the critical ability |
---|
18 | to alter task execution which allows a task to be preempted upon |
---|
19 | exit from an ISR. The interrupt manager includes the following |
---|
20 | directive: |
---|
21 | |
---|
22 | @itemize @bullet |
---|
23 | @item @code{@value{DIRPREFIX}interrupt_catch} - Establish an ISR |
---|
24 | @item @code{@value{DIRPREFIX}interrupt_disable} - Disable Interrupts |
---|
25 | @item @code{@value{DIRPREFIX}interrupt_enable} - Enable Interrupts |
---|
26 | @item @code{@value{DIRPREFIX}interrupt_flash} - Flash Interrupt |
---|
27 | @item @code{@value{DIRPREFIX}interrupt_is_in_progress} - Is an ISR in Progress |
---|
28 | @end itemize |
---|
29 | |
---|
30 | @section Background |
---|
31 | |
---|
32 | @subsection Processing an Interrupt |
---|
33 | |
---|
34 | The interrupt manager allows the application to |
---|
35 | connect a function to a hardware interrupt vector. When an |
---|
36 | interrupt occurs, the processor will automatically vector to |
---|
37 | RTEMS. RTEMS saves and restores all registers which are not |
---|
38 | preserved by the normal @value{LANGUAGE} calling convention |
---|
39 | for the target |
---|
40 | processor and invokes the user's ISR. The user's ISR is |
---|
41 | responsible for processing the interrupt, clearing the interrupt |
---|
42 | if necessary, and device specific manipulation. |
---|
43 | |
---|
44 | The @code{@value{DIRPREFIX}interrupt_catch} |
---|
45 | directive connects a procedure to |
---|
46 | an interrupt vector. The interrupt service routine is assumed |
---|
47 | to abide by these conventions and have a prototype similar to |
---|
48 | the following: |
---|
49 | |
---|
50 | @ifset is-C |
---|
51 | @example |
---|
52 | rtems_isr user_isr( |
---|
53 | rtems_vector_number vector |
---|
54 | ); |
---|
55 | @end example |
---|
56 | @end ifset |
---|
57 | |
---|
58 | @ifset is-Ada |
---|
59 | @example |
---|
60 | procedure User_ISR ( |
---|
61 | vector : in RTEMS.Vector_Number |
---|
62 | ); |
---|
63 | @end example |
---|
64 | @end ifset |
---|
65 | |
---|
66 | The vector number argument is provided by RTEMS to |
---|
67 | allow the application to identify the interrupt source. This |
---|
68 | could be used to allow a single routine to service interrupts |
---|
69 | from multiple instances of the same device. For example, a |
---|
70 | single routine could service interrupts from multiple serial |
---|
71 | ports and use the vector number to identify which port requires |
---|
72 | servicing. |
---|
73 | |
---|
74 | To minimize the masking of lower or equal priority |
---|
75 | level interrupts, the ISR should perform the minimum actions |
---|
76 | required to service the interrupt. Other non-essential actions |
---|
77 | should be handled by application tasks. Once the user's ISR has |
---|
78 | completed, it returns control to the RTEMS interrupt manager |
---|
79 | which will perform task dispatching and restore the registers |
---|
80 | saved before the ISR was invoked. |
---|
81 | |
---|
82 | The RTEMS interrupt manager guarantees that proper |
---|
83 | task scheduling and dispatching are performed at the conclusion |
---|
84 | of an ISR. A system call made by the ISR may have readied a |
---|
85 | task of higher priority than the interrupted task. Therefore, |
---|
86 | when the ISR completes, the postponed dispatch processing must |
---|
87 | be performed. No dispatch processing is performed as part of |
---|
88 | directives which have been invoked by an ISR. |
---|
89 | |
---|
90 | Applications must adhere to the following rule if |
---|
91 | proper task scheduling and dispatching is to be performed: |
---|
92 | |
---|
93 | @itemize @b{ } |
---|
94 | |
---|
95 | @item @b{The interrupt manager must be used for all ISRs which |
---|
96 | may be interrupted by the highest priority ISR which invokes an |
---|
97 | RTEMS directive.} |
---|
98 | |
---|
99 | @end itemize |
---|
100 | |
---|
101 | |
---|
102 | Consider a processor which allows a numerically low |
---|
103 | interrupt level to interrupt a numerically greater interrupt |
---|
104 | level. In this example, if an RTEMS directive is used in a |
---|
105 | level 4 ISR, then all ISRs which execute at levels 0 through 4 |
---|
106 | must use the interrupt manager. |
---|
107 | |
---|
108 | Interrupts are nested whenever an interrupt occurs |
---|
109 | during the execution of another ISR. RTEMS supports efficient |
---|
110 | interrupt nesting by allowing the nested ISRs to terminate |
---|
111 | without performing any dispatch processing. Only when the |
---|
112 | outermost ISR terminates will the postponed dispatching occur. |
---|
113 | |
---|
114 | @subsection RTEMS Interrupt Levels |
---|
115 | |
---|
116 | Many processors support multiple interrupt levels or |
---|
117 | priorities. The exact number of interrupt levels is processor |
---|
118 | dependent. RTEMS internally supports 256 interrupt levels which |
---|
119 | are mapped to the processor's interrupt levels. For specific |
---|
120 | information on the mapping between RTEMS and the target |
---|
121 | processor's interrupt levels, refer to the Interrupt Processing |
---|
122 | chapter of the Applications Supplement document for a specific |
---|
123 | target processor. |
---|
124 | |
---|
125 | @subsection Disabling of Interrupts by RTEMS |
---|
126 | |
---|
127 | During the execution of directive calls, critical |
---|
128 | sections of code may be executed. When these sections are |
---|
129 | encountered, RTEMS disables all maskable interrupts before the |
---|
130 | execution of the section and restores them to the previous level |
---|
131 | upon completion of the section. RTEMS has been optimized to |
---|
132 | insure that interrupts are disabled for a minimum length of |
---|
133 | time. The maximum length of time interrupts are disabled by |
---|
134 | RTEMS is processor dependent and is detailed in the Timing |
---|
135 | Specification chapter of the Applications Supplement document |
---|
136 | for a specific target processor. |
---|
137 | |
---|
138 | Non-maskable interrupts (NMI) cannot be disabled, and |
---|
139 | ISRs which execute at this level MUST NEVER issue RTEMS system |
---|
140 | calls. If a directive is invoked, unpredictable results may |
---|
141 | occur due to the inability of RTEMS to protect its critical |
---|
142 | sections. However, ISRs that make no system calls may safely |
---|
143 | execute as non-maskable interrupts. |
---|
144 | |
---|
145 | @section Operations |
---|
146 | |
---|
147 | @subsection Establishing an ISR |
---|
148 | |
---|
149 | The @code{@value{DIRPREFIX}interrupt_catch} |
---|
150 | directive establishes an ISR for |
---|
151 | the system. The address of the ISR and its associated CPU |
---|
152 | vector number are specified to this directive. This directive |
---|
153 | installs the RTEMS interrupt wrapper in the processor's |
---|
154 | Interrupt Vector Table and the address of the user's ISR in the |
---|
155 | RTEMS' Vector Table. This directive returns the previous |
---|
156 | contents of the specified vector in the RTEMS' Vector Table. |
---|
157 | |
---|
158 | @subsection Directives Allowed from an ISR |
---|
159 | |
---|
160 | Using the interrupt manager insures that RTEMS knows |
---|
161 | when a directive is being called from an ISR. The ISR may then |
---|
162 | use system calls to synchronize itself with an application task. |
---|
163 | The synchronization may involve messages, events or signals |
---|
164 | being passed by the ISR to the desired task. Directives invoked |
---|
165 | by an ISR must operate only on objects which reside on the local |
---|
166 | node. The following is a list of RTEMS system calls that may be |
---|
167 | made from an ISR: |
---|
168 | |
---|
169 | @itemize @bullet |
---|
170 | @item Task Management |
---|
171 | |
---|
172 | @itemize - |
---|
173 | @item task_get_note, task_set_note, task_suspend, task_resume |
---|
174 | @end itemize |
---|
175 | |
---|
176 | @item Clock Management |
---|
177 | |
---|
178 | @itemize - |
---|
179 | @item clock_get, clock_tick |
---|
180 | @end itemize |
---|
181 | |
---|
182 | @item Message, Event, and Signal Management |
---|
183 | |
---|
184 | @itemize - |
---|
185 | @item message_queue_send, message_queue_urgent |
---|
186 | @item event_send |
---|
187 | @item signal_send |
---|
188 | @end itemize |
---|
189 | |
---|
190 | @item Semaphore Management |
---|
191 | |
---|
192 | @itemize - |
---|
193 | @item semaphore_release |
---|
194 | @end itemize |
---|
195 | |
---|
196 | @item Dual-Ported Memory Management |
---|
197 | |
---|
198 | @itemize - |
---|
199 | @item port_external_to_internal, port_internal_to_external |
---|
200 | @end itemize |
---|
201 | |
---|
202 | @item IO Management |
---|
203 | |
---|
204 | @itemize - |
---|
205 | @item io_initialize, io_open, io_close, io_read, io_write, io_control |
---|
206 | @end itemize |
---|
207 | |
---|
208 | @item Fatal Error Management |
---|
209 | |
---|
210 | @itemize - |
---|
211 | @item fatal_error_occurred |
---|
212 | @end itemize |
---|
213 | |
---|
214 | @item Multiprocessing |
---|
215 | |
---|
216 | @itemize - |
---|
217 | @item multiprocessing_announce |
---|
218 | @end itemize |
---|
219 | @end itemize |
---|
220 | |
---|
221 | @section Directives |
---|
222 | |
---|
223 | This section details the interrupt manager's |
---|
224 | directives. A subsection is dedicated to each of this manager's |
---|
225 | directives and describes the calling sequence, related |
---|
226 | constants, usage, and status codes. |
---|
227 | |
---|
228 | @page |
---|
229 | @subsection INTERRUPT_CATCH - Establish an ISR |
---|
230 | |
---|
231 | @subheading CALLING SEQUENCE: |
---|
232 | |
---|
233 | @ifset is-C |
---|
234 | @example |
---|
235 | rtems_status_code rtems_interrupt_catch( |
---|
236 | rtems_isr_entry new_isr_handler, |
---|
237 | rtems_vector_number vector, |
---|
238 | rtems_isr_entry *old_isr_handler |
---|
239 | ); |
---|
240 | @end example |
---|
241 | @end ifset |
---|
242 | |
---|
243 | @ifset is-Ada |
---|
244 | @example |
---|
245 | procedure Interrupt_Catch ( |
---|
246 | New_ISR_handler : in RTEMS.Address; |
---|
247 | Vector : in RTEMS.Vector_Number; |
---|
248 | Old_ISR_Handler : out RTEMS.Address; |
---|
249 | Result : out RTEMS.Status_Codes |
---|
250 | ); |
---|
251 | @end example |
---|
252 | @end ifset |
---|
253 | |
---|
254 | @subheading DIRECTIVE STATUS CODES: |
---|
255 | @code{@value{RPREFIX}SUCCESSFUL} - ISR established successfully@* |
---|
256 | @code{@value{RPREFIX}INVALID_NUMBER} - illegal vector number@* |
---|
257 | @code{@value{RPREFIX}INVALID_ADDRESS} - illegal ISR entry point or invalid old_isr_handler |
---|
258 | |
---|
259 | @subheading DESCRIPTION: |
---|
260 | |
---|
261 | This directive establishes an interrupt service |
---|
262 | routine (ISR) for the specified interrupt vector number. The |
---|
263 | @code{new_isr_handler} parameter specifies the entry point of the ISR. |
---|
264 | The entry point of the previous ISR for the specified vector is |
---|
265 | returned in @code{old_isr_handler}. |
---|
266 | |
---|
267 | @subheading NOTES: |
---|
268 | |
---|
269 | This directive will not cause the calling task to be preempted. |
---|
270 | |
---|
271 | @page |
---|
272 | @subsection INTERRUPT_DISABLE - Disable Interrupts |
---|
273 | |
---|
274 | @subheading CALLING SEQUENCE: |
---|
275 | |
---|
276 | @ifset is-C |
---|
277 | @example |
---|
278 | void rtems_interrupt_disable( |
---|
279 | rtems_isr_level level |
---|
280 | ); |
---|
281 | @end example |
---|
282 | @end ifset |
---|
283 | |
---|
284 | @ifset is-Ada |
---|
285 | @example |
---|
286 | function Interrupt_Disable |
---|
287 | return RTEMS.ISR_Level; |
---|
288 | @end example |
---|
289 | @end ifset |
---|
290 | |
---|
291 | @subheading DIRECTIVE STATUS CODES: |
---|
292 | |
---|
293 | NONE |
---|
294 | |
---|
295 | @subheading DESCRIPTION: |
---|
296 | |
---|
297 | This directive disables all maskable interrupts and returns |
---|
298 | the previous @code{level}. A later invocation of the |
---|
299 | @code{@value{DIRPREFIX}interrupt_enable} directive should be used to |
---|
300 | restore the interrupt level. |
---|
301 | |
---|
302 | @subheading NOTES: |
---|
303 | |
---|
304 | This directive will not cause the calling task to be preempted. |
---|
305 | |
---|
306 | @ifset is-C |
---|
307 | @b{This directive is implemented as a macro which modifies the @code{level} |
---|
308 | parameter.} |
---|
309 | @end ifset |
---|
310 | |
---|
311 | @page |
---|
312 | @subsection INTERRUPT_ENABLE - Enable Interrupts |
---|
313 | |
---|
314 | @subheading CALLING SEQUENCE: |
---|
315 | |
---|
316 | @ifset is-C |
---|
317 | @example |
---|
318 | void rtems_interrupt_enable( |
---|
319 | rtems_isr_level level |
---|
320 | ); |
---|
321 | @end example |
---|
322 | @end ifset |
---|
323 | |
---|
324 | @ifset is-Ada |
---|
325 | @example |
---|
326 | procedure Interrupt_Enable ( |
---|
327 | Level : in RTEMS.ISR_Level |
---|
328 | ); |
---|
329 | @end example |
---|
330 | @end ifset |
---|
331 | |
---|
332 | @subheading DIRECTIVE STATUS CODES: |
---|
333 | |
---|
334 | NONE |
---|
335 | |
---|
336 | @subheading DESCRIPTION: |
---|
337 | |
---|
338 | This directive enables maskable interrupts to the @code{level} |
---|
339 | which was returned by a previous call to |
---|
340 | @code{@value{DIRPREFIX}interrupt_disable}. |
---|
341 | Immediately prior to invoking this directive, maskable interrupts should |
---|
342 | be disabled by a call to @code{@value{DIRPREFIX}interrupt_disable} |
---|
343 | and will be enabled when this directive returns to the caller. |
---|
344 | |
---|
345 | @subheading NOTES: |
---|
346 | |
---|
347 | This directive will not cause the calling task to be preempted. |
---|
348 | |
---|
349 | |
---|
350 | @page |
---|
351 | @subsection INTERRUPT_FLASH - Flash Interrupts |
---|
352 | |
---|
353 | @subheading CALLING SEQUENCE: |
---|
354 | |
---|
355 | @ifset is-C |
---|
356 | @example |
---|
357 | void rtems_interrupt_flash( |
---|
358 | rtems_isr_level level |
---|
359 | ); |
---|
360 | @end example |
---|
361 | @end ifset |
---|
362 | |
---|
363 | @ifset is-Ada |
---|
364 | @example |
---|
365 | procedure Interrupt_Flash ( |
---|
366 | Level : in RTEMS.ISR_Level |
---|
367 | ); |
---|
368 | @end example |
---|
369 | @end ifset |
---|
370 | |
---|
371 | @subheading DIRECTIVE STATUS CODES: |
---|
372 | |
---|
373 | NONE |
---|
374 | |
---|
375 | @subheading DESCRIPTION: |
---|
376 | |
---|
377 | This directive temporarily enables maskable interrupts to the @code{level} |
---|
378 | which was returned by a previous call to |
---|
379 | @code{@value{DIRPREFIX}interrupt_disable}. |
---|
380 | Immediately prior to invoking this directive, maskable interrupts should |
---|
381 | be disabled by a call to @code{@value{DIRPREFIX}interrupt_disable} |
---|
382 | and will be redisabled when this directive returns to the caller. |
---|
383 | |
---|
384 | @subheading NOTES: |
---|
385 | |
---|
386 | This directive will not cause the calling task to be preempted. |
---|
387 | |
---|
388 | @page |
---|
389 | @subsection INTERRUPT_IS_IN_PROGRESS - Is an ISR in Progress |
---|
390 | |
---|
391 | @subheading CALLING SEQUENCE: |
---|
392 | |
---|
393 | @ifset is-C |
---|
394 | @example |
---|
395 | rtems_boolean rtems_interrupt_is_in_progress( void ); |
---|
396 | @end example |
---|
397 | @end ifset |
---|
398 | |
---|
399 | @ifset is-Ada |
---|
400 | @example |
---|
401 | function Interrupt_Is_In_Progress |
---|
402 | return RTEMS.Boolean; |
---|
403 | @end example |
---|
404 | @end ifset |
---|
405 | |
---|
406 | @subheading DIRECTIVE STATUS CODES: |
---|
407 | |
---|
408 | NONE |
---|
409 | |
---|
410 | @subheading DESCRIPTION: |
---|
411 | |
---|
412 | This directive returns @code{TRUE} if the processor is currently |
---|
413 | servicing an interrupt and @code{FALSE} otherwise. A return value |
---|
414 | of @code{TRUE} indicates that the caller is an interrupt service |
---|
415 | routine, @b{NOT} a task. The directives available to an interrupt |
---|
416 | service routine are restricted. |
---|
417 | |
---|
418 | @subheading NOTES: |
---|
419 | |
---|
420 | This directive will not cause the calling task to be preempted. |
---|
421 | |
---|