-- This is an example of how to attach and handle interrupts in Ada 95. -- Interrupt handling is done as follows: -- -- 1. A protected procedure is attached to the interrupt -- 2. When activated, the procedure enables a conditional entry -- 3. A task waiting on the entry will carry out the work. -- -- In this way, we spend minimum amount of time in the protected -- procedure. Many other schemes are of course possible... -- -- Written by Tullio Vardanega and Jiri Gaisler -- European Space Agency, 1999. -- with Ada.Interrupts; with System; with Ada.Text_IO; package body Interrupt_pkg is type T_SEM is (HIGH, LOW); Protected_Priority : constant System.Interrupt_Priority := System.Interrupt_Priority'First; -- Protected object, including interrupt handler (Signal) and conditional entry. protected Handler is procedure Signal; entry Wait; pragma Attach_Handler (Signal, 17); -- Signal 17 equals irq 1 on ERC32 pragma Priority (Protected_Priority); private BARRIER : T_SEM := HIGH; end Handler; protected body Handler is procedure Signal is begin BARRIER := LOW; end Signal; entry Wait when (BARRIER = LOW) is begin BARRIER := HIGH; end Wait; end Handler; -- Sporadic task, waiting on entry (Wait) for the interrupt. task sporadic is pragma Priority (8); end sporadic; task body sporadic is Message : constant STRING := "sporadic activated"; begin loop Handler.Wait; Ada.Text_IO.Put_line (Message); end loop; end sporadic; -- Test program, generating interrupt 1 on ERC32 procedure itest is procedure irqforce(irq : integer); pragma Import (C, irqforce, "irqforce"); begin for i in 1..10 loop irqforce(1); delay(0.05); end loop; -- Have to kill sporadic to exit since it is has an infinite loop abort sporadic; end; begin itest; end Interrupt_pkg;