source: ada-examples/irq_test/interrupt_pkg.adb @ 92f495a

ada-examples-4-10-branch
Last change on this file since 92f495a was 68645f0, checked in by Joel Sherrill <joel.sherrill@…>, on 07/08/08 at 15:34:14

2008-07-08 Joel Sherrill <joel.sherrill@…>

  • interrupt_pkg.adb: Force an RTEMS shutdown when we are done.
  • ChangeLog?: New file.
  • Property mode set to 100644
File size: 2.8 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;
28with RTEMS;
29
30package body Interrupt_pkg is
31
32   type T_SEM is (HIGH, LOW);
33
34   Protected_Priority : constant System.Interrupt_Priority :=
35     System.Interrupt_Priority'First;
36
37   Start_Time       : Ada.Real_Time.Time;
38   Stop_Time        : Ada.Real_Time.Time;
39
40-- Protected object, including interrupt handler (Signal) and conditional entry.
41
42   protected Handler is
43      procedure Signal;
44      entry Wait;
45      pragma Attach_Handler (Signal, 17);  -- Signal 17 equals irq 1 on ERC32
46      pragma Priority (Protected_Priority);
47   private
48      BARRIER : T_SEM := HIGH;
49   end Handler;
50
51   protected body Handler is
52      procedure Signal is
53      begin
54         BARRIER := LOW;
55      end Signal;
56
57      entry Wait when (BARRIER = LOW) is
58         Took : Time_Span;
59      begin
60         Stop_Time := Ada.Real_Time.Clock;       
61         BARRIER := HIGH;
62
63         Took := Stop_Time - Start_Time;
64         
65         Ada.Text_IO.Put_line ( "Interrupt took: " &
66          Duration'Image(To_Duration(Took)));
67      end Wait;
68   end Handler;
69
70-- Sporadic task, waiting on entry (Wait) for the interrupt.
71
72   task sporadic is
73      pragma Priority (100);
74   end sporadic;
75
76   task body sporadic is
77      Message : constant STRING := "sporadic activated";
78   begin
79      loop
80         Handler.Wait;
81
82      end loop;
83   end sporadic;
84
85-- Test program, generating interrupt 1 on ERC32
86
87   procedure itest is
88      procedure irqforce(irq : integer);
89      pragma Import (C, irqforce, "irqforce");
90   begin
91     
92     Start_Time := Ada.Real_Time.Clock;       
93     Stop_Time := Ada.Real_Time.Clock;       
94     
95     Ada.Text_IO.Put_line ( "Timer Overhead: " &
96      Duration'Image(To_Duration(Stop_Time - Start_Time)));
97
98     for i in 1..10 loop
99       Start_Time := Ada.Real_Time.Clock;       
100       irqforce(1);
101       delay(0.05);
102     end loop;
103
104     -- Have to kill sporadic to exit since it is has an infinite loop
105     abort sporadic;
106     RTEMS.Shutdown_Executive (0);
107   end;
108
109begin
110
111  --  itest;
112  NULL;
113
114end Interrupt_pkg;
115
116
Note: See TracBrowser for help on using the repository browser.