Go to the first, previous, next, last section, table of contents.


C.3.2 The Package Interrupts

Static Semantics

  1. The following language-defined packages exist:
  2. with System;
    package Ada.Interrupts is
       type Interrupt_ID is implementation-defined;
       type Parameterless_Handler is
          access protected procedure;
    

  1.    function Is_Reserved (Interrupt : Interrupt_ID)
          return Boolean;
    
  2.    function Is_Attached (Interrupt : Interrupt_ID)
          return Boolean;
    
  3.    function Current_Handler (Interrupt : Interrupt_ID)
          return Parameterless_Handler;
    
  4.    procedure Attach_Handler
          (New_Handler : in Parameterless_Handler;
           Interrupt   : in Interrupt_ID);
    
  5.    procedure Exchange_Handler
          (Old_Handler : out Parameterless_Handler;
           New_Handler : in Parameterless_Handler;
           Interrupt   : in Interrupt_ID);
    
  6.    procedure Detach_Handler
          (Interrupt : in Interrupt_ID);
    
  7.    function Reference(Interrupt : Interrupt_ID)
          return System.Address;
    
  8. private
       ... -- not specified by the language
    end Ada.Interrupts;
    
  9. package Ada.Interrupts.Names is
       implementation-defined : constant Interrupt_ID :=
         implementation-defined;
          . . .
       implementation-defined : constant Interrupt_ID :=
         implementation-defined;
    end Ada.Interrupts.Names;
    

    Dynamic Semantics

  10. The Interrupt_ID type is an implementation-defined discrete type used to identify interrupts.
  11. The Is_Reserved function returns True if and only if the specified interrupt is reserved.
  12. The Is_Attached function returns True if and only if a user-specified interrupt handler is attached to the interrupt.
  13. The Current_Handler function returns a value that represents the attached handler of the interrupt. If no user-defined handler is attached to the interrupt, Current_Handler returns a value that designates the default treatment; calling Attach_Handler or Exchange_Handler with this value restores the default treatment.
  14. The Attach_Handler procedure attaches the specified handler to the interrupt, overriding any existing treatment (including a user handler) in effect for that interrupt. If New_Handler is null, the default treatment is restored. If New_Handler designates a protected procedure to which the pragma Interrupt_Handler does not apply, Program_Error is raised. In this case, the operation does not modify the existing interrupt treatment.
  15. The Exchange_Handler procedure operates in the same manner as Attach_Handler with the addition that the value returned in Old_Handler designates the previous treatment for the specified interrupt.
  16. The Detach_Handler procedure restores the default treatment for the specified interrupt.
  17. For all operations defined in this package that take a parameter of type Interrupt_ID, with the exception of Is_Reserved and Reference, a check is made that the specified interrupt is not reserved. Program_Error is raised if this check fails.
  18. If, by using the Attach_Handler, Detach_Handler, or Exchange_Handler procedures, an attempt is made to detach a handler that was attached statically (using the pragma Attach_Handler), the handler is not detached and Program_Error is raised.
  19. The Reference function returns a value of type System.Address that can be used to attach a task entry, via an address clause, See section J.7.1 Interrupt Entries, to theinterrupt specified by Interrupt. This function raises Program_Error if attaching task entries to interrupts (or to this particular interrupt) is not supported.

    Implementation Requirements

  20. At no time during attachment or exchange of handlers shall the current handler of the corresponding interrupt be undefined.

    Documentation Requirements

  21. If the Ceiling_Locking policy, See section D.3 Priority Ceiling Locking, is in effect the implementation shall document the default ceiling priority assigned to a protected object that contains either the Attach_Handler or Interrupt_Handler pragmas, but not the Interrupt_Priority pragma. This default need not be the same for all interrupts.

    Implementation Advice

  22. If implementation-defined forms of interrupt handler procedures are supported, such as protected procedures with parameters, then for each such form of a handler, a type analogous to Parameterless_Handler should be specified in a child package of Interrupts, with the same operations as in the predefined package Interrupts.

    NOTES

  23. (8) The package Interrupts.Names contains implementation-defined names (and constant values) for the interrupts that are supported by the implementation.

    Examples

  24. Example of interrupt handlers:
  25. Device_Priority : constant
      array (1..5) of System.Interrupt_Priority := ( ... );
    protected type Device_Interface
      (Int_ID : Ada.Interrupts.Interrupt_ID) is
      procedure Handler;
      pragma Attach_Handler(Handler, Int_ID);
      ...
      pragma Interrupt_Priority(Device_Priority(Int_ID));
    end Device_Interface;
      ...
    Device_1_Driver : Device_Interface(1);
      ...
    Device_5_Driver : Device_Interface(5);
      ...
    


Go to the first, previous, next, last section, table of contents.