blob: 33c49b671e08d3616e09cd7abccda923694e4aa4 (
plain) (
tree)
|
|
-- 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.
--
-- The license and distribution terms for this file may be
-- found in the file LICENSE in this distribution or at
-- http://www.rtems.com/license/LICENSE.
--
-- $Id$
--
with Ada.Interrupts;
with System;
with Ada.Text_IO;
with Ada.Real_Time; use Ada.Real_Time;
with RTEMS;
package body Interrupt_pkg is
type T_SEM is (HIGH, LOW);
Protected_Priority : constant System.Interrupt_Priority :=
System.Interrupt_Priority'First;
Start_Time : Ada.Real_Time.Time;
Stop_Time : Ada.Real_Time.Time;
-- 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
Took : Time_Span;
begin
Stop_Time := Ada.Real_Time.Clock;
BARRIER := HIGH;
Took := Stop_Time - Start_Time;
Ada.Text_IO.Put_line ( "Interrupt took: " &
Duration'Image(To_Duration(Took)));
end Wait;
end Handler;
-- Sporadic task, waiting on entry (Wait) for the interrupt.
task sporadic is
pragma Priority (100);
end sporadic;
task body sporadic is
Message : constant STRING := "sporadic activated";
begin
loop
Handler.Wait;
end loop;
end sporadic;
-- Test program, generating interrupt 1 on ERC32
procedure itest is
procedure irqforce(irq : integer);
pragma Import (C, irqforce, "irqforce");
begin
Start_Time := Ada.Real_Time.Clock;
Stop_Time := Ada.Real_Time.Clock;
Ada.Text_IO.Put_line ( "Timer Overhead: " &
Duration'Image(To_Duration(Stop_Time - Start_Time)));
for i in 1..10 loop
Start_Time := Ada.Real_Time.Clock;
irqforce(1);
delay(0.05);
end loop;
-- Have to kill sporadic to exit since it is has an infinite loop
abort sporadic;
RTEMS.Shutdown_Executive (0);
end;
begin
-- itest;
NULL;
end Interrupt_pkg;
|