source: rtems/doc/user/intr.t @ 219298ad

4.9
Last change on this file since 219298ad was 219298ad, checked in by Joel Sherrill <joel.sherrill@…>, on 06/16/10 at 19:34:19

2010-06-16 Joel Sherrill <joel.sherrilL@…>

PR 1568/doc

  • user/intr.t: Fix list of services callable from ISR.
  • Property mode set to 100644
File size: 13.2 KB
Line 
1@c
2@c  COPYRIGHT (c) 1988-2008.
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
13Any real-time executive must provide a mechanism for
14quick response to externally generated interrupts to satisfy the
15critical time constraints of the application.  The interrupt
16manager provides this mechanism for RTEMS.  This manager permits
17quick interrupt response times by providing the critical ability
18to alter task execution which allows a task to be preempted upon
19exit from an ISR.  The interrupt manager includes the following
20directive:
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@cindex interrupt processing
35
36The interrupt manager allows the application to
37connect a function to a hardware interrupt vector.  When an
38interrupt occurs, the processor will automatically vector to
39RTEMS.  RTEMS saves and restores all registers which are not
40preserved by the normal @value{LANGUAGE} calling convention
41for the target
42processor and invokes the user's ISR.  The user's ISR is
43responsible for processing the interrupt, clearing the interrupt
44if necessary, and device specific manipulation.
45
46@findex rtems_vector_number
47
48The @code{@value{DIRPREFIX}interrupt_catch}
49directive connects a procedure to
50an interrupt vector.  The vector number is managed using
51the @code{@value{DIRPREFIX}vector_number} data type.
52
53The interrupt service routine is assumed
54to abide by these conventions and have a prototype similar to
55the following:
56
57@ifset is-C
58@findex rtems_isr
59
60@example
61rtems_isr user_isr(
62  rtems_vector_number vector
63);
64@end example
65@end ifset
66
67@ifset is-Ada
68@example
69NOT SUPPORTED FROM Ada BINDING
70@end example
71@end ifset
72
73The vector number argument is provided by RTEMS to
74allow the application to identify the interrupt source.  This
75could be used to allow a single routine to service interrupts
76from multiple instances of the same device.  For example, a
77single routine could service interrupts from multiple serial
78ports and use the vector number to identify which port requires
79servicing.
80
81To minimize the masking of lower or equal priority
82level interrupts, the ISR should perform the minimum actions
83required to service the interrupt.  Other non-essential actions
84should be handled by application tasks.  Once the user's ISR has
85completed, it returns control to the RTEMS interrupt manager
86which will perform task dispatching and restore the registers
87saved before the ISR was invoked.
88
89The RTEMS interrupt manager guarantees that proper
90task scheduling and dispatching are performed at the conclusion
91of an ISR.  A system call made by the ISR may have readied a
92task of higher priority than the interrupted task.  Therefore,
93when the ISR completes, the postponed dispatch processing must
94be performed.  No dispatch processing is performed as part of
95directives which have been invoked by an ISR.
96
97Applications must adhere to the following rule if
98proper task scheduling and dispatching is to be performed:
99
100@itemize @b{ }
101
102@item @b{The interrupt manager must be used for all ISRs which
103may be interrupted by the highest priority ISR which invokes an
104RTEMS directive.}
105
106@end itemize
107
108Consider a processor which allows a numerically low
109interrupt level to interrupt a numerically greater interrupt
110level.  In this example, if an RTEMS directive is used in a
111level 4 ISR, then all ISRs which execute at levels 0 through 4
112must use the interrupt manager.
113
114Interrupts are nested whenever an interrupt occurs
115during the execution of another ISR.  RTEMS supports efficient
116interrupt nesting by allowing the nested ISRs to terminate
117without performing any dispatch processing.  Only when the
118outermost ISR terminates will the postponed dispatching occur.
119
120@subsection RTEMS Interrupt Levels
121
122@cindex interrupt levels
123
124Many processors support multiple interrupt levels or
125priorities.  The exact number of interrupt levels is processor
126dependent.  RTEMS internally supports 256 interrupt levels which
127are mapped to the processor's interrupt levels.  For specific
128information on the mapping between RTEMS and the target
129processor's interrupt levels, refer to the Interrupt Processing
130chapter of the Applications Supplement document for a specific
131target processor.
132
133@subsection Disabling of Interrupts by RTEMS
134
135@cindex disabling interrupts
136
137During the execution of directive calls, critical
138sections of code may be executed.  When these sections are
139encountered, RTEMS disables all maskable interrupts before the
140execution of the section and restores them to the previous level
141upon completion of the section.  RTEMS has been optimized to
142ensure that interrupts are disabled for a minimum length of
143time.  The maximum length of time interrupts are disabled by
144RTEMS is processor dependent and is detailed in the Timing
145Specification chapter of the Applications Supplement document
146for a specific target processor.
147
148Non-maskable interrupts (NMI) cannot be disabled, and
149ISRs which execute at this level MUST NEVER issue RTEMS system
150calls.  If a directive is invoked, unpredictable results may
151occur due to the inability of RTEMS to protect its critical
152sections.  However, ISRs that make no system calls may safely
153execute as non-maskable interrupts.
154
155@section Operations
156
157@subsection Establishing an ISR
158
159The @code{@value{DIRPREFIX}interrupt_catch}
160directive establishes an ISR for
161the system.  The address of the ISR and its associated CPU
162vector number are specified to this directive.  This directive
163installs the RTEMS interrupt wrapper in the processor's
164Interrupt Vector Table and the address of the user's ISR in the
165RTEMS' Vector Table.  This directive returns the previous
166contents of the specified vector in the RTEMS' Vector Table.
167
168@subsection Directives Allowed from an ISR
169
170Using the interrupt manager ensures that RTEMS knows
171when a directive is being called from an ISR.  The ISR may then
172use system calls to synchronize itself with an application task.
173The synchronization may involve messages, events or signals
174being passed by the ISR to the desired task.  Directives invoked
175by an ISR must operate only on objects which reside on the local
176node.  The following is a list of RTEMS system calls that may be
177made from an ISR:
178
179@itemize @bullet
180@item Task Management
181
182Although it is acceptable to operate on the RTEMS_SELF task (e.g.
183the currently executing task), while in an ISR, this will refer
184to the interrupted task.  Most of the time, it is an application
185implementation error to use RTEMS_SELF from an ISR.
186
187@itemize -
188@item rtems_task_get_note
189@item rtems_task_set_note
190@item rtems_task_suspend
191@item rtems_task_resume
192@end itemize
193
194@item Interrupt Management
195
196@itemize -
197@item rtems_interrupt_enable
198@item rtems_interrupt_disable
199@item rtems_interrupt_flash
200@item rtems_interrupt_is_in_progress
201@item rtems_interrupt_catch
202@end itemize
203
204@item Clock Management
205
206@itemize
207@item rtems_clock_set
208@item rtems_clock_get
209@item rtems_clock_get_tod
210@item rtems_clock_get_tod_timeval
211@item rtems_clock_get_seconds_since_epoch
212@item rtems_clock_get_ticks_per_second
213@item rtems_clock_get_ticks_since_boot
214@item rtems_clock_get_uptime
215@item rtems_clock_set_nanoseconds_extension
216@item rtems_clock_tick
217@end itemize
218
219@item Message, Event, and Signal Management
220
221@itemize -
222@item rtems_message_queue_send
223@item rtems_message_queue_urgent
224@item rtems_event_send
225@item rtems_signal_send
226@end itemize
227
228@item Semaphore Management
229
230@itemize -
231@item rtems_semaphore_release
232@end itemize
233
234@item Dual-Ported Memory Management
235
236@itemize -
237@item rtems_port_external_to_internal
238@item rtems_port_internal_to_external
239@end itemize
240
241@item IO Management
242
243The following services are safe to call from an ISR if and only if
244the device driver service invoked is also safe.  The IO Manager itself
245is safe but the invoked driver entry point may or may not be.
246@itemize -
247@item rtems_io_initialize
248@item rtems_io_open
249@item rtems_io_close
250@item rtems_io_read
251@item rtems_io_write
252@item rtems_io_control
253@end itemize
254
255@item Fatal Error Management
256
257@itemize -
258@item rtems_fatal_error_occurred
259@end itemize
260
261@item Multiprocessing
262
263@itemize -
264@item rtems_multiprocessing_announce
265@end itemize
266@end itemize
267
268@section Directives
269
270This section details the interrupt manager's
271directives.  A subsection is dedicated to each of this manager's
272directives and describes the calling sequence, related
273constants, usage, and status codes.
274
275@c
276@c
277@c
278@page
279@subsection INTERRUPT_CATCH - Establish an ISR
280
281@cindex establish an ISR
282@cindex install an ISR
283
284@subheading CALLING SEQUENCE:
285
286@ifset is-C
287@findex rtems_interrupt_catch
288@example
289rtems_status_code rtems_interrupt_catch(
290  rtems_isr_entry      new_isr_handler,
291  rtems_vector_number  vector,
292  rtems_isr_entry     *old_isr_handler
293);
294@end example
295@end ifset
296
297@ifset is-Ada
298@example
299NOT SUPPORTED FROM Ada BINDING
300@end example
301@end ifset
302
303@subheading DIRECTIVE STATUS CODES:
304@code{@value{RPREFIX}SUCCESSFUL} - ISR established successfully@*
305@code{@value{RPREFIX}INVALID_NUMBER} - illegal vector number@*
306@code{@value{RPREFIX}INVALID_ADDRESS} - illegal ISR entry point or invalid @code{old_isr_handler}
307
308@subheading DESCRIPTION:
309
310This directive establishes an interrupt service
311routine (ISR) for the specified interrupt vector number.  The
312@code{new_isr_handler} parameter specifies the entry point of the ISR.
313The entry point of the previous ISR for the specified vector is
314returned in @code{old_isr_handler}.
315
316To release an interrupt vector, pass the old handler's address obtained
317when the vector was first capture.
318
319@subheading NOTES:
320
321This directive will not cause the calling task to be preempted.
322
323@c
324@c
325@c
326@page
327@subsection INTERRUPT_DISABLE - Disable Interrupts
328
329@cindex disable interrupts
330
331@subheading CALLING SEQUENCE:
332
333@ifset is-C
334@findex rtems_interrupt_disable
335@example
336void rtems_interrupt_disable(
337  rtems_interrupt_level  level
338);
339
340/* this is implemented as a macro and sets level as a side-effect */
341@end example
342@end ifset
343
344@ifset is-Ada
345@example
346function Interrupt_Disable return RTEMS.ISR_Level;
347@end example
348@end ifset
349
350@subheading DIRECTIVE STATUS CODES:
351
352NONE
353
354@subheading DESCRIPTION:
355
356This directive disables all maskable interrupts and returns
357the previous @code{level}.  A later invocation of the
358@code{@value{DIRPREFIX}interrupt_enable} directive should be used to
359restore the interrupt level.
360
361@subheading NOTES:
362
363This directive will not cause the calling task to be preempted.
364
365@ifset is-C
366@b{This directive is implemented as a macro which modifies the @code{level}
367parameter.}
368@end ifset
369
370@c
371@c
372@c
373@page
374@subsection INTERRUPT_ENABLE - Enable Interrupts
375
376@cindex enable interrupts
377
378@subheading CALLING SEQUENCE:
379
380@ifset is-C
381@findex rtems_interrupt_enable
382@example
383void rtems_interrupt_enable(
384  rtems_interrupt_level  level
385);
386@end example
387@end ifset
388
389@ifset is-Ada
390@example
391procedure Interrupt_Enable (
392   Level : in     RTEMS.ISR_Level
393);
394@end example
395@end ifset
396
397@subheading DIRECTIVE STATUS CODES:
398
399NONE
400
401@subheading DESCRIPTION:
402
403This directive enables maskable interrupts to the @code{level}
404which was returned by a previous call to
405@code{@value{DIRPREFIX}interrupt_disable}.
406Immediately prior to invoking this directive, maskable interrupts should
407be disabled by a call to @code{@value{DIRPREFIX}interrupt_disable}
408and will be enabled when this directive returns to the caller.
409
410@subheading NOTES:
411
412This directive will not cause the calling task to be preempted.
413
414
415@c
416@c
417@c
418@page
419@subsection INTERRUPT_FLASH - Flash Interrupts
420
421@cindex flash interrupts
422
423@subheading CALLING SEQUENCE:
424
425@ifset is-C
426@findex rtems_interrupt_flash
427@example
428void rtems_interrupt_flash(
429  rtems_interrupt_level level
430);
431@end example
432@end ifset
433
434@ifset is-Ada
435@example
436procedure Interrupt_Flash (
437   Level : in     RTEMS.ISR_Level
438);
439@end example
440@end ifset
441
442@subheading DIRECTIVE STATUS CODES:
443
444NONE
445
446@subheading DESCRIPTION:
447
448This directive temporarily enables maskable interrupts to the @code{level}
449which was returned by a previous call to
450@code{@value{DIRPREFIX}interrupt_disable}. 
451Immediately prior to invoking this directive, maskable interrupts should
452be disabled by a call to @code{@value{DIRPREFIX}interrupt_disable}
453and will be redisabled when this directive returns to the caller.
454
455@subheading NOTES:
456
457This directive will not cause the calling task to be preempted.
458
459@c
460@c
461@c
462@page
463@subsection INTERRUPT_IS_IN_PROGRESS - Is an ISR in Progress
464
465@cindex is interrupt in progress
466
467@subheading CALLING SEQUENCE:
468
469@ifset is-C
470@findex rtems_interrupt_is_in_progress
471@example
472bool rtems_interrupt_is_in_progress( void );
473@end example
474@end ifset
475
476@ifset is-Ada
477@example
478function Interrupt_Is_In_Progress return RTEMS.Boolean;
479@end example
480@end ifset
481
482@subheading DIRECTIVE STATUS CODES:
483
484NONE
485
486@subheading DESCRIPTION:
487
488This directive returns @code{TRUE} if the processor is currently
489servicing an interrupt and @code{FALSE} otherwise.  A return value
490of @code{TRUE} indicates that the caller is an interrupt service
491routine, @b{NOT} a task.  The directives available to an interrupt
492service routine are restricted.
493
494@subheading NOTES:
495
496This directive will not cause the calling task to be preempted.
497
Note: See TracBrowser for help on using the repository browser.