source: ada-examples/irq_test/interrupt_pkg.adb @ 36fcd41

ada-examples-4-10-branchada-examples-4-9-branch
Last change on this file since 36fcd41 was 14f44a3, checked in by Joel Sherrill <joel.sherrill@…>, on 10/17/07 at 20:55:06

2007-10-17 Joel Sherrill <joel.sherrill@…>

  • Makefile, Makefile.shared, rtems_init.c, irq_test/interrupt_pkg.adb, irq_test/interrupt_pkg.ads, irq_test/irqforce.c, irq_test/irqtest.adb, rootfs/etc/hosts: Adding new tests as improvements are made to the RTEMS port of the GNAT run-time.
  • empty/Makefile, empty/README, empty/empty.adb, hello_via_task/.cvsignore, hello_via_task/Makefile, hello_via_task/hello.adb, irq_test/.cvsignore, irq_test/Makefile, irq_test/README, irq_test_c/.cvsignore, irq_test_c/Makefile, irq_test_c/README, irq_test_c/init.c, irq_test_c/irqforce.c: New files.
  • Property mode set to 100644
File size: 2.7 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--  The license and distribution terms for this file may be
16--  found in the file LICENSE in this distribution or at
17--  http://www.rtems.com/license/LICENSE.
18--
19--  $Id$
20--
21
22
23
24with Ada.Interrupts;
25with System;
26with Ada.Text_IO;
27with Ada.Real_Time; use Ada.Real_Time;
28
29package body Interrupt_pkg is
30
31   type T_SEM is (HIGH, LOW);
32
33   Protected_Priority : constant System.Interrupt_Priority :=
34     System.Interrupt_Priority'First;
35
36   Start_Time       : Ada.Real_Time.Time;
37   Stop_Time        : Ada.Real_Time.Time;
38
39-- Protected object, including interrupt handler (Signal) and conditional entry.
40
41   protected Handler is
42      procedure Signal;
43      entry Wait;
44      pragma Attach_Handler (Signal, 17);  -- Signal 17 equals irq 1 on ERC32
45      pragma Priority (Protected_Priority);
46   private
47      BARRIER : T_SEM := HIGH;
48   end Handler;
49
50   protected body Handler is
51      procedure Signal is
52      begin
53         BARRIER := LOW;
54      end Signal;
55
56      entry Wait when (BARRIER = LOW) is
57         Took : Time_Span;
58      begin
59         Stop_Time := Ada.Real_Time.Clock;       
60         BARRIER := HIGH;
61
62         Took := Stop_Time - Start_Time;
63         
64         Ada.Text_IO.Put_line ( "Interrupt took: " &
65          Duration'Image(To_Duration(Took)));
66      end Wait;
67   end Handler;
68
69-- Sporadic task, waiting on entry (Wait) for the interrupt.
70
71   task sporadic is
72      pragma Priority (100);
73   end sporadic;
74
75   task body sporadic is
76      Message : constant STRING := "sporadic activated";
77   begin
78      loop
79         Handler.Wait;
80
81      end loop;
82   end sporadic;
83
84-- Test program, generating interrupt 1 on ERC32
85
86   procedure itest is
87      procedure irqforce(irq : integer);
88      pragma Import (C, irqforce, "irqforce");
89   begin
90     
91     Start_Time := Ada.Real_Time.Clock;       
92     Stop_Time := Ada.Real_Time.Clock;       
93     
94     Ada.Text_IO.Put_line ( "Timer Overhead: " &
95      Duration'Image(To_Duration(Stop_Time - Start_Time)));
96
97     for i in 1..10 loop
98       Start_Time := Ada.Real_Time.Clock;       
99       irqforce(1);
100       delay(0.05);
101     end loop;
102
103     -- Have to kill sporadic to exit since it is has an infinite loop
104     abort sporadic;
105   end;
106
107begin
108
109  --  itest;
110  NULL;
111
112end Interrupt_pkg;
113
114
Note: See TracBrowser for help on using the repository browser.