source: ada-examples/irq_test/interrupt_pkg.adb @ 8c02d47

ada-examples-4-10-branchada-examples-4-6-branchada-examples-4-7-branchada-examples-4-8-branchada-examples-4-9-branch
Last change on this file since 8c02d47 was 7efcefa, checked in by Joel Sherrill <joel.sherrill@…>, on 04/20/99 at 13:05:42

base GNAT/RTEMS examples

  • Property mode set to 100644
File size: 2.0 KB
Line 
1
2--  This is an example of how to attach and handle interrupts in Ada 95.
3--  Interrupt handling is done as follows:
4--
5--  1. A protected procedure is attached to the interrupt
6--  2. When activated, the procedure enables a conditional entry
7--  3. A task waiting on the entry will carry out the work.
8--
9--  In this way, we spend minimum amount of time in the protected
10--  procedure. Many other schemes are of course possible...
11--
12--  Written by Tullio Vardanega and Jiri Gaisler
13--  European Space Agency, 1999.
14--
15
16
17with Ada.Interrupts;
18with System;
19with Ada.Text_IO;
20
21package body Interrupt_pkg is
22
23   type T_SEM is (HIGH, LOW);
24
25   Protected_Priority : constant System.Interrupt_Priority :=
26     System.Interrupt_Priority'First;
27
28-- Protected object, including interrupt handler (Signal) and conditional entry.
29
30   protected Handler is
31      procedure Signal;
32      entry Wait;
33      pragma Attach_Handler (Signal, 17);  -- Signal 17 equals irq 1 on ERC32
34      pragma Priority (Protected_Priority);
35   private
36      BARRIER : T_SEM := HIGH;
37   end Handler;
38
39   protected body Handler is
40      procedure Signal is
41      begin
42         BARRIER := LOW;
43      end Signal;
44      entry Wait when (BARRIER = LOW) is
45      begin
46         BARRIER := HIGH;
47      end Wait;
48   end Handler;
49
50-- Sporadic task, waiting on entry (Wait) for the interrupt.
51
52   task sporadic is
53      pragma Priority (8);
54   end sporadic;
55
56   task body sporadic is
57      Message : constant STRING :=
58        "sporadic activated";
59   begin
60      loop
61         Handler.Wait;
62         Ada.Text_IO.Put_line (Message);
63      end loop;
64   end sporadic;
65
66-- Test program, generating interrupt 1 on ERC32
67
68   procedure itest is
69      procedure irqforce(irq : integer);
70      pragma Import (C, irqforce, "irqforce");
71   begin
72     for i in 1..10 loop
73       irqforce(1);
74       delay(0.05);
75     end loop;
76
77     -- Have to kill sporadic to exit since it is has an infinite loop
78     abort sporadic;
79   end;
80
81begin
82
83  itest;
84
85end Interrupt_pkg;
86
87
Note: See TracBrowser for help on using the repository browser.