source: rtems/doc/user/intr.t @ d5154d0f

5
Last change on this file since d5154d0f was d5154d0f, checked in by Aun-Ali Zaidi <admin@…>, on 12/23/15 at 20:44:02

api: Remove deprecated Notepads

Notepads where a feature of RTEMS' tasks that simply functioned in
the same way as POSIX keys or threaded local storage (TLS). They were
introduced well before per task variables, which are also deprecated,
and were barely used in favor of their POSIX alternatives.

In addition to their scarce usage, Notepads took up unnecessary memory.
For each task:

  • 16 32-bit integers were allocated.
  • A total of 64 bytes per task per thread.

This is especially critical in low memory and safety-critical applications.

They are also defined as uint32_t, and therefore are not guaranteed to
hold a pointer.

Lastly, they are not portable solutions for SMP and uniprocessor systems,
like POSIX keys and TLS.

updates #2493.

  • Property mode set to 100644
File size: 19.5 KB
Line 
1@c
2@c  COPYRIGHT (c) 1988-2008.
3@c  On-Line Applications Research Corporation (OAR).
4@c  All rights reserved.
5
6@chapter Interrupt Manager
7
8@section Introduction
9
10Any real-time executive must provide a mechanism for
11quick response to externally generated interrupts to satisfy the
12critical time constraints of the application.  The interrupt
13manager provides this mechanism for RTEMS.  This manager permits
14quick interrupt response times by providing the critical ability
15to alter task execution which allows a task to be preempted upon
16exit from an ISR.  The interrupt manager includes the following
17directive:
18
19@itemize @bullet
20@item @code{@value{DIRPREFIX}interrupt_catch} - Establish an ISR
21@item @code{@value{DIRPREFIX}interrupt_disable} - Disable Interrupts
22@item @code{@value{DIRPREFIX}interrupt_enable} - Enable Interrupts
23@item @code{@value{DIRPREFIX}interrupt_flash} - Flash Interrupt
24@item @code{@value{DIRPREFIX}interrupt_local_disable} - Disable Interrupts on Current Processor
25@item @code{@value{DIRPREFIX}interrupt_local_enable} - Enable Interrupts on Current Processor
26@item @code{@value{DIRPREFIX}interrupt_lock_initialize} - Initialize an ISR Lock
27@item @code{@value{DIRPREFIX}interrupt_lock_acquire} - Acquire an ISR Lock
28@item @code{@value{DIRPREFIX}interrupt_lock_release} - Release an ISR Lock
29@item @code{@value{DIRPREFIX}interrupt_lock_acquire_isr} - Acquire an ISR Lock from ISR
30@item @code{@value{DIRPREFIX}interrupt_lock_release_isr} - Release an ISR Lock from ISR
31@item @code{@value{DIRPREFIX}interrupt_is_in_progress} - Is an ISR in Progress
32@end itemize
33
34@section Background
35
36@subsection Processing an Interrupt
37
38@cindex interrupt processing
39
40The interrupt manager allows the application to
41connect a function to a hardware interrupt vector.  When an
42interrupt occurs, the processor will automatically vector to
43RTEMS.  RTEMS saves and restores all registers which are not
44preserved by the normal @value{LANGUAGE} calling convention
45for the target
46processor and invokes the user's ISR.  The user's ISR is
47responsible for processing the interrupt, clearing the interrupt
48if necessary, and device specific manipulation.
49
50@findex rtems_vector_number
51
52The @code{@value{DIRPREFIX}interrupt_catch}
53directive connects a procedure to
54an interrupt vector.  The vector number is managed using
55the @code{@value{DIRPREFIX}vector_number} data type.
56
57The interrupt service routine is assumed
58to abide by these conventions and have a prototype similar to
59the following:
60
61@ifset is-C
62@findex rtems_isr
63
64@example
65rtems_isr user_isr(
66  rtems_vector_number vector
67);
68@end example
69@end ifset
70
71@ifset is-Ada
72@example
73NOT SUPPORTED FROM Ada BINDING
74@end example
75@end ifset
76
77The vector number argument is provided by RTEMS to
78allow the application to identify the interrupt source.  This
79could be used to allow a single routine to service interrupts
80from multiple instances of the same device.  For example, a
81single routine could service interrupts from multiple serial
82ports and use the vector number to identify which port requires
83servicing.
84
85To minimize the masking of lower or equal priority
86level interrupts, the ISR should perform the minimum actions
87required to service the interrupt.  Other non-essential actions
88should be handled by application tasks.  Once the user's ISR has
89completed, it returns control to the RTEMS interrupt manager
90which will perform task dispatching and restore the registers
91saved before the ISR was invoked.
92
93The RTEMS interrupt manager guarantees that proper
94task scheduling and dispatching are performed at the conclusion
95of an ISR.  A system call made by the ISR may have readied a
96task of higher priority than the interrupted task.  Therefore,
97when the ISR completes, the postponed dispatch processing must
98be performed.  No dispatch processing is performed as part of
99directives which have been invoked by an ISR.
100
101Applications must adhere to the following rule if
102proper task scheduling and dispatching is to be performed:
103
104@itemize @b{ }
105
106@item @b{The interrupt manager must be used for all ISRs which
107may be interrupted by the highest priority ISR which invokes an
108RTEMS directive.}
109
110@end itemize
111
112Consider a processor which allows a numerically low
113interrupt level to interrupt a numerically greater interrupt
114level.  In this example, if an RTEMS directive is used in a
115level 4 ISR, then all ISRs which execute at levels 0 through 4
116must use the interrupt manager.
117
118Interrupts are nested whenever an interrupt occurs
119during the execution of another ISR.  RTEMS supports efficient
120interrupt nesting by allowing the nested ISRs to terminate
121without performing any dispatch processing.  Only when the
122outermost ISR terminates will the postponed dispatching occur.
123
124@subsection RTEMS Interrupt Levels
125
126@cindex interrupt levels
127
128Many processors support multiple interrupt levels or
129priorities.  The exact number of interrupt levels is processor
130dependent.  RTEMS internally supports 256 interrupt levels which
131are mapped to the processor's interrupt levels.  For specific
132information on the mapping between RTEMS and the target
133processor's interrupt levels, refer to the Interrupt Processing
134chapter of the Applications Supplement document for a specific
135target processor.
136
137@subsection Disabling of Interrupts by RTEMS
138
139@cindex disabling interrupts
140
141During the execution of directive calls, critical
142sections of code may be executed.  When these sections are
143encountered, RTEMS disables all maskable interrupts before the
144execution of the section and restores them to the previous level
145upon completion of the section.  RTEMS has been optimized to
146ensure that interrupts are disabled for a minimum length of
147time.  The maximum length of time interrupts are disabled by
148RTEMS is processor dependent and is detailed in the Timing
149Specification chapter of the Applications Supplement document
150for a specific target processor.
151
152Non-maskable interrupts (NMI) cannot be disabled, and
153ISRs which execute at this level MUST NEVER issue RTEMS system
154calls.  If a directive is invoked, unpredictable results may
155occur due to the inability of RTEMS to protect its critical
156sections.  However, ISRs that make no system calls may safely
157execute as non-maskable interrupts.
158
159@section Operations
160
161@subsection Establishing an ISR
162
163The @code{@value{DIRPREFIX}interrupt_catch}
164directive establishes an ISR for
165the system.  The address of the ISR and its associated CPU
166vector number are specified to this directive.  This directive
167installs the RTEMS interrupt wrapper in the processor's
168Interrupt Vector Table and the address of the user's ISR in the
169RTEMS' Vector Table.  This directive returns the previous
170contents of the specified vector in the RTEMS' Vector Table.
171
172@subsection Directives Allowed from an ISR
173
174Using the interrupt manager ensures that RTEMS knows
175when a directive is being called from an ISR.  The ISR may then
176use system calls to synchronize itself with an application task.
177The synchronization may involve messages, events or signals
178being passed by the ISR to the desired task.  Directives invoked
179by an ISR must operate only on objects which reside on the local
180node.  The following is a list of RTEMS system calls that may be
181made from an ISR:
182
183@itemize @bullet
184@item Task Management
185
186Although it is acceptable to operate on the RTEMS_SELF task (e.g.
187the currently executing task), while in an ISR, this will refer
188to the interrupted task.  Most of the time, it is an application
189implementation error to use RTEMS_SELF from an ISR.
190
191@itemize
192@item rtems_task_suspend
193@item rtems_task_resume
194@end itemize
195
196@item Interrupt Management
197
198@itemize
199@item rtems_interrupt_enable
200@item rtems_interrupt_disable
201@item rtems_interrupt_flash
202@item rtems_interrupt_lock_acquire
203@item rtems_interrupt_lock_release
204@item rtems_interrupt_lock_acquire_isr
205@item rtems_interrupt_lock_release_isr
206@item rtems_interrupt_is_in_progress
207@item rtems_interrupt_catch
208@end itemize
209
210@item Clock Management
211
212@itemize
213@item rtems_clock_set
214@item rtems_clock_get
215@item rtems_clock_get_tod
216@item rtems_clock_get_tod_timeval
217@item rtems_clock_get_seconds_since_epoch
218@item rtems_clock_get_ticks_per_second
219@item rtems_clock_get_ticks_since_boot
220@item rtems_clock_get_uptime
221@item rtems_clock_set_nanoseconds_extension
222@item rtems_clock_tick
223@end itemize
224
225@item Timer Management
226
227@itemize
228@item rtems_timer_cancel
229@item rtems_timer_reset
230@item rtems_timer_fire_after
231@item rtems_timer_fire_when
232@item rtems_timer_server_fire_after
233@item rtems_timer_server_fire_when
234@end itemize
235
236@item Event Management
237
238@itemize
239@item rtems_event_send
240@item rtems_event_system_send
241@item rtems_event_transient_send
242@end itemize
243
244@item Semaphore Management
245
246@itemize
247@item rtems_semaphore_release
248@end itemize
249
250@item Message Management
251
252@itemize
253@item rtems_message_queue_send
254@item rtems_message_queue_urgent
255@end itemize
256
257@item Signal Management
258
259@itemize
260@item rtems_signal_send
261@end itemize
262
263@item Dual-Ported Memory Management
264
265@itemize
266@item rtems_port_external_to_internal
267@item rtems_port_internal_to_external
268@end itemize
269
270@item IO Management
271
272The following services are safe to call from an ISR if and only if
273the device driver service invoked is also safe.  The IO Manager itself
274is safe but the invoked driver entry point may or may not be.
275@itemize
276@item rtems_io_initialize
277@item rtems_io_open
278@item rtems_io_close
279@item rtems_io_read
280@item rtems_io_write
281@item rtems_io_control
282@end itemize
283
284@item Fatal Error Management
285
286@itemize
287@item rtems_fatal
288@item rtems_fatal_error_occurred
289@end itemize
290
291@item Multiprocessing
292
293@itemize
294@item rtems_multiprocessing_announce
295@end itemize
296@end itemize
297
298@section Directives
299
300This section details the interrupt manager's
301directives.  A subsection is dedicated to each of this manager's
302directives and describes the calling sequence, related
303constants, usage, and status codes.
304
305@c
306@c
307@c
308@page
309@subsection INTERRUPT_CATCH - Establish an ISR
310
311@cindex establish an ISR
312@cindex install an ISR
313
314@subheading CALLING SEQUENCE:
315
316@ifset is-C
317@findex rtems_interrupt_catch
318@example
319rtems_status_code rtems_interrupt_catch(
320  rtems_isr_entry      new_isr_handler,
321  rtems_vector_number  vector,
322  rtems_isr_entry     *old_isr_handler
323);
324@end example
325@end ifset
326
327@ifset is-Ada
328@example
329NOT SUPPORTED FROM Ada BINDING
330@end example
331@end ifset
332
333@subheading DIRECTIVE STATUS CODES:
334@code{@value{RPREFIX}SUCCESSFUL} - ISR established successfully@*
335@code{@value{RPREFIX}INVALID_NUMBER} - illegal vector number@*
336@code{@value{RPREFIX}INVALID_ADDRESS} - illegal ISR entry point or invalid @code{old_isr_handler}
337
338@subheading DESCRIPTION:
339
340This directive establishes an interrupt service
341routine (ISR) for the specified interrupt vector number.  The
342@code{new_isr_handler} parameter specifies the entry point of the ISR.
343The entry point of the previous ISR for the specified vector is
344returned in @code{old_isr_handler}.
345
346To release an interrupt vector, pass the old handler's address obtained
347when the vector was first capture.
348
349@subheading NOTES:
350
351This directive will not cause the calling task to be preempted.
352
353@c
354@c
355@c
356@page
357@subsection INTERRUPT_DISABLE - Disable Interrupts
358
359@cindex disable interrupts
360
361@subheading CALLING SEQUENCE:
362
363@ifset is-C
364@findex rtems_interrupt_disable
365@example
366void rtems_interrupt_disable(
367  rtems_interrupt_level  level
368);
369
370/* this is implemented as a macro and sets level as a side-effect */
371@end example
372@end ifset
373
374@ifset is-Ada
375@example
376function Interrupt_Disable return RTEMS.ISR_Level;
377@end example
378@end ifset
379
380@subheading DIRECTIVE STATUS CODES:
381
382NONE
383
384@subheading DESCRIPTION:
385
386This directive disables all maskable interrupts and returns
387the previous @code{level}.  A later invocation of the
388@code{@value{DIRPREFIX}interrupt_enable} directive should be used to
389restore the interrupt level.
390
391@subheading NOTES:
392
393This directive will not cause the calling task to be preempted.
394
395@ifset is-C
396@b{This directive is implemented as a macro which modifies the @code{level}
397parameter.}
398@end ifset
399
400This directive is only available on uni-processor configurations.  The
401directive @code{@value{DIRPREFIX}interrupt_local_disable} is available on all
402configurations.
403
404@c
405@c
406@c
407@page
408@subsection INTERRUPT_ENABLE - Enable Interrupts
409
410@cindex enable interrupts
411
412@subheading CALLING SEQUENCE:
413
414@ifset is-C
415@findex rtems_interrupt_enable
416@example
417void rtems_interrupt_enable(
418  rtems_interrupt_level  level
419);
420@end example
421@end ifset
422
423@ifset is-Ada
424@example
425procedure Interrupt_Enable (
426   Level : in     RTEMS.ISR_Level
427);
428@end example
429@end ifset
430
431@subheading DIRECTIVE STATUS CODES:
432
433NONE
434
435@subheading DESCRIPTION:
436
437This directive enables maskable interrupts to the @code{level}
438which was returned by a previous call to
439@code{@value{DIRPREFIX}interrupt_disable}.
440Immediately prior to invoking this directive, maskable interrupts should
441be disabled by a call to @code{@value{DIRPREFIX}interrupt_disable}
442and will be enabled when this directive returns to the caller.
443
444@subheading NOTES:
445
446This directive will not cause the calling task to be preempted.
447
448This directive is only available on uni-processor configurations.  The
449directive @code{@value{DIRPREFIX}interrupt_local_enable} is available on all
450configurations.
451
452@c
453@c
454@c
455@page
456@subsection INTERRUPT_FLASH - Flash Interrupts
457
458@cindex flash interrupts
459
460@subheading CALLING SEQUENCE:
461
462@ifset is-C
463@findex rtems_interrupt_flash
464@example
465void rtems_interrupt_flash(
466  rtems_interrupt_level level
467);
468@end example
469@end ifset
470
471@ifset is-Ada
472@example
473procedure Interrupt_Flash (
474   Level : in     RTEMS.ISR_Level
475);
476@end example
477@end ifset
478
479@subheading DIRECTIVE STATUS CODES:
480
481NONE
482
483@subheading DESCRIPTION:
484
485This directive temporarily enables maskable interrupts to the @code{level}
486which was returned by a previous call to
487@code{@value{DIRPREFIX}interrupt_disable}. 
488Immediately prior to invoking this directive, maskable interrupts should
489be disabled by a call to @code{@value{DIRPREFIX}interrupt_disable}
490and will be redisabled when this directive returns to the caller.
491
492@subheading NOTES:
493
494This directive will not cause the calling task to be preempted.
495
496This directive is only available on uni-processor configurations.  The
497directives @code{@value{DIRPREFIX}interrupt_local_disable} and
498@code{@value{DIRPREFIX}interrupt_local_enable} is available on all
499configurations.
500
501@c
502@c
503@c
504@page
505@subsection INTERRUPT_LOCAL_DISABLE - Disable Interrupts on Current Processor
506
507@cindex disable interrupts
508
509@subheading CALLING SEQUENCE:
510
511@ifset is-C
512@findex rtems_interrupt_local_disable
513@example
514void rtems_interrupt_local_disable(
515  rtems_interrupt_level  level
516);
517
518/* this is implemented as a macro and sets level as a side-effect */
519@end example
520@end ifset
521
522@subheading DIRECTIVE STATUS CODES:
523
524NONE
525
526@subheading DESCRIPTION:
527
528This directive disables all maskable interrupts and returns
529the previous @code{level}.  A later invocation of the
530@code{@value{DIRPREFIX}interrupt_local_enable} directive should be used to
531restore the interrupt level.
532
533@subheading NOTES:
534
535This directive will not cause the calling task to be preempted.
536
537@ifset is-C
538@b{This directive is implemented as a macro which modifies the @code{level}
539parameter.}
540@end ifset
541
542On SMP configurations this will not ensure system wide mutual exclusion.  Use
543interrupt locks instead.
544
545@c
546@c
547@c
548@page
549@subsection INTERRUPT_LOCAL_ENABLE - Enable Interrupts on Current Processor
550
551@cindex enable interrupts
552
553@subheading CALLING SEQUENCE:
554
555@ifset is-C
556@findex rtems_interrupt_local_enable
557@example
558void rtems_interrupt_local_enable(
559  rtems_interrupt_level  level
560);
561@end example
562@end ifset
563
564@subheading DIRECTIVE STATUS CODES:
565
566NONE
567
568@subheading DESCRIPTION:
569
570This directive enables maskable interrupts to the @code{level}
571which was returned by a previous call to
572@code{@value{DIRPREFIX}interrupt_local_disable}.
573Immediately prior to invoking this directive, maskable interrupts should
574be disabled by a call to @code{@value{DIRPREFIX}interrupt_local_disable}
575and will be enabled when this directive returns to the caller.
576
577@subheading NOTES:
578
579This directive will not cause the calling task to be preempted.
580
581@c
582@c
583@c
584@page
585@subsection INTERRUPT_LOCK_INITIALIZE - Initialize an ISR Lock
586
587@subheading CALLING SEQUENCE:
588
589@ifset is-C
590@findex rtems_interrupt_lock_initialize
591@example
592void rtems_interrupt_lock_initialize(
593  rtems_interrupt_lock *lock
594);
595@end example
596@end ifset
597
598@subheading DIRECTIVE STATUS CODES:
599
600NONE
601
602@subheading DESCRIPTION:
603
604Initializes an interrupt lock.
605
606@subheading NOTES:
607
608Concurrent initialization leads to unpredictable results.
609
610@c
611@c
612@c
613@page
614@subsection INTERRUPT_LOCK_ACQUIRE - Acquire an ISR Lock
615
616@subheading CALLING SEQUENCE:
617
618@ifset is-C
619@findex rtems_interrupt_lock_acquire
620@example
621void rtems_interrupt_lock_acquire(
622  rtems_interrupt_lock *lock,
623  rtems_interrupt_level level
624);
625@end example
626@end ifset
627
628@subheading DIRECTIVE STATUS CODES:
629
630NONE
631
632@subheading DESCRIPTION:
633
634Interrupts will be disabled.  On SMP configurations this directive acquires a
635SMP lock.
636
637@subheading NOTES:
638
639This directive will not cause the calling thread to be preempted.  This
640directive can be used in thread and interrupt context.
641
642@c
643@c
644@c
645@page
646@subsection INTERRUPT_LOCK_RELEASE - Release an ISR Lock
647
648@subheading CALLING SEQUENCE:
649
650@ifset is-C
651@findex rtems_interrupt_lock_release
652@example
653void rtems_interrupt_lock_release(
654  rtems_interrupt_lock *lock,
655  rtems_interrupt_level level
656);
657@end example
658@end ifset
659
660@subheading DIRECTIVE STATUS CODES:
661
662NONE
663
664@subheading DESCRIPTION:
665
666The interrupt status will be restored.  On SMP configurations this directive
667releases a SMP lock.
668
669@subheading NOTES:
670
671This directive will not cause the calling thread to be preempted.  This
672directive can be used in thread and interrupt context.
673
674@c
675@c
676@c
677@page
678@subsection INTERRUPT_LOCK_ACQUIRE_ISR - Acquire an ISR Lock from ISR
679
680@subheading CALLING SEQUENCE:
681
682@ifset is-C
683@findex rtems_interrupt_lock_acquire_isr
684@example
685void rtems_interrupt_lock_acquire_isr(
686  rtems_interrupt_lock *lock,
687  rtems_interrupt_level level
688);
689@end example
690@end ifset
691
692@subheading DIRECTIVE STATUS CODES:
693
694NONE
695
696@subheading DESCRIPTION:
697
698The interrupt status will remain unchanged.  On SMP configurations this
699directive acquires a SMP lock.
700
701In case the corresponding interrupt service routine can be interrupted by
702higher priority interrupts and these interrupts enter the critical section
703protected by this lock, then the result is unpredictable.
704
705@subheading NOTES:
706
707This directive should be called from the corresponding interrupt service
708routine.
709
710@c
711@c
712@c
713@page
714@subsection INTERRUPT_LOCK_RELEASE_ISR - Release an ISR Lock from ISR
715
716@subheading CALLING SEQUENCE:
717
718@ifset is-C
719@findex rtems_interrupt_lock_release_isr
720@example
721void rtems_interrupt_lock_release_isr(
722  rtems_interrupt_lock *lock,
723  rtems_interrupt_level level
724);
725@end example
726@end ifset
727
728@subheading DIRECTIVE STATUS CODES:
729
730NONE
731
732@subheading DESCRIPTION:
733
734The interrupt status will remain unchanged.  On SMP configurations this
735directive releases a SMP lock.
736
737@subheading NOTES:
738
739This directive should be called from the corresponding interrupt service
740routine.
741
742@c
743@c
744@c
745@page
746@subsection INTERRUPT_IS_IN_PROGRESS - Is an ISR in Progress
747
748@cindex is interrupt in progress
749
750@subheading CALLING SEQUENCE:
751
752@ifset is-C
753@findex rtems_interrupt_is_in_progress
754@example
755bool rtems_interrupt_is_in_progress( void );
756@end example
757@end ifset
758
759@ifset is-Ada
760@example
761function Interrupt_Is_In_Progress return RTEMS.Boolean;
762@end example
763@end ifset
764
765@subheading DIRECTIVE STATUS CODES:
766
767NONE
768
769@subheading DESCRIPTION:
770
771This directive returns @code{TRUE} if the processor is currently
772servicing an interrupt and @code{FALSE} otherwise.  A return value
773of @code{TRUE} indicates that the caller is an interrupt service
774routine, @b{NOT} a task.  The directives available to an interrupt
775service routine are restricted.
776
777@subheading NOTES:
778
779This directive will not cause the calling task to be preempted.
780
Note: See TracBrowser for help on using the repository browser.