summaryrefslogtreecommitdiffstats
path: root/irq_test
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1999-04-20 13:05:42 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1999-04-20 13:05:42 +0000
commit7efcefa510d143c7bd7e4fceb6f9fb428720decc (patch)
treecbbc26153da1cd9d301f208f75a0b70f13211a90 /irq_test
downloadada-examples-7efcefa510d143c7bd7e4fceb6f9fb428720decc.tar.bz2
base GNAT/RTEMS examplesADA-EXAMPLES-BASEOAR
Diffstat (limited to 'irq_test')
-rw-r--r--irq_test/interrupt_pkg.adb87
-rw-r--r--irq_test/interrupt_pkg.ads3
-rw-r--r--irq_test/irqforce.c7
-rw-r--r--irq_test/irqtest.adb7
4 files changed, 104 insertions, 0 deletions
diff --git a/irq_test/interrupt_pkg.adb b/irq_test/interrupt_pkg.adb
new file mode 100644
index 0000000..2097ba8
--- /dev/null
+++ b/irq_test/interrupt_pkg.adb
@@ -0,0 +1,87 @@
+
+-- 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;
+
+
diff --git a/irq_test/interrupt_pkg.ads b/irq_test/interrupt_pkg.ads
new file mode 100644
index 0000000..6bc597e
--- /dev/null
+++ b/irq_test/interrupt_pkg.ads
@@ -0,0 +1,3 @@
+package Interrupt_pkg is
+ procedure itest;
+end Interrupt_pkg;
diff --git a/irq_test/irqforce.c b/irq_test/irqforce.c
new file mode 100644
index 0000000..78ae91a
--- /dev/null
+++ b/irq_test/irqforce.c
@@ -0,0 +1,7 @@
+#include <bsp.h>
+
+irqforce(int irq)
+{
+ ERC32_Unmask_interrupt(irq);
+ ERC32_Force_interrupt(irq);
+}
diff --git a/irq_test/irqtest.adb b/irq_test/irqtest.adb
new file mode 100644
index 0000000..1a9dfad
--- /dev/null
+++ b/irq_test/irqtest.adb
@@ -0,0 +1,7 @@
+with Interrupt_pkg;
+
+procedure irqtest is
+begin
+ null;
+end irqtest;
+