PR c++/11808
[official-gcc.git] / gcc / ada / i-vxwork.ads
blob1ab458558a893d35b4a09b2049a31b8224fd5b80
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
5 -- I N T E R F A C E S . V X W O R K S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1999 - 2002 Ada Core Technologies, Inc. --
10 -- --
11 -- GNARL is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNARL; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNARL was developed by the GNARL team at Florida State University. It is --
30 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
31 -- State University (http://www.gnat.com). --
32 -- --
33 ------------------------------------------------------------------------------
35 -- This package provides a limited binding to the VxWorks API
36 -- In particular, it interfaces with the VxWorks hardware interrupt
37 -- facilities, allowing the use of low-latency direct-vectored
38 -- interrupt handlers. Note that such handlers have a variety of
39 -- restrictions regarding system calls. Less restrictive, but higher-
40 -- latency handlers can be written using Ada protected procedures,
41 -- Ada 83 style interrupt entries, or by signalling an Ada task
42 -- from within an interrupt handler using a binary semaphore as
43 -- described in the VxWorks Programmer's Manual
45 -- For complete documentation of the operations in this package, please
46 -- consult the VxWorks Programmer's Manual and VxWorks Reference Manual
48 with System.VxWorks;
50 package Interfaces.VxWorks is
51 pragma Preelaborate (VxWorks);
53 ------------------------------------------------------------------------
54 -- Here is a complete example that shows how to handle the Interrupt 0x14
55 -- with a direct-vectored interrupt handler in Ada using this package:
57 -- with Interfaces.VxWorks; use Interfaces.VxWorks;
58 -- with System;
60 -- package P is
62 -- Count : Integer;
63 -- pragma Atomic (Count);
65 -- Level : constant := 1;
66 -- -- Interrupt level used by this example
68 -- procedure Handler (parameter : System.Address);
70 -- end P;
72 -- package body P is
74 -- procedure Handler (parameter : System.Address) is
75 -- S : STATUS;
76 -- begin
77 -- Count := Count + 1;
78 -- logMsg ("received an interrupt" & ASCII.LF & ASCII.Nul);
80 -- -- Acknowledge VME interrupt
81 -- S := sysBusIntAck (intLevel => Level);
82 -- end Handler;
83 -- end P;
85 -- with Interfaces.VxWorks; use Interfaces.VxWorks;
86 -- with Ada.Text_IO; use Ada.Text_IO;
88 -- with P; use P;
89 -- procedure Useint is
90 -- -- Be sure to use a reasonable interrupt number for the target
91 -- -- board!
92 -- -- This one is the unused VME graphics interrupt on the PPC MV2604
93 -- Interrupt : constant := 16#14#;
95 -- task T;
97 -- S : STATUS;
99 -- task body T is
100 -- begin
101 -- loop
102 -- Put_Line ("Generating an interrupt...");
103 -- delay 1.0;
105 -- -- Generate VME interrupt, using interrupt number
106 -- S := sysBusIntGen (1, Interrupt);
107 -- end loop;
108 -- end T;
110 -- begin
111 -- S := sysIntEnable (intLevel => Level);
112 -- S := intConnect (INUM_TO_IVEC (Interrupt), handler'Access);
114 -- loop
115 -- delay 2.0;
116 -- Put_Line ("value of count:" & P.Count'Img);
117 -- end loop;
118 -- end Useint;
119 -------------------------------------
121 subtype int is Integer;
123 type STATUS is new int;
124 -- Equivalent of the C type STATUS
126 OK : constant STATUS := 0;
127 ERROR : constant STATUS := -1;
129 type VOIDFUNCPTR is access procedure (parameter : System.Address);
130 type Interrupt_Vector is new System.Address;
131 type Exception_Vector is new System.Address;
133 function intConnect
134 (vector : Interrupt_Vector;
135 handler : VOIDFUNCPTR;
136 parameter : System.Address := System.Null_Address) return STATUS;
137 -- Binding to the C routine intConnect. Use this to set up an
138 -- user handler. The routine generates a wrapper around the user
139 -- handler to save and restore context
141 function intVecGet
142 (Vector : Interrupt_Vector) return VOIDFUNCPTR;
143 -- Binding to the C routine intVecGet. Use this to get the
144 -- existing handler for later restoral
146 procedure intVecSet
147 (Vector : Interrupt_Vector;
148 Handler : VOIDFUNCPTR);
149 -- Binding to the C routine intVecSet. Use this to restore a
150 -- handler obtained using intVecGet
152 function INUM_TO_IVEC (intNum : int) return Interrupt_Vector;
153 -- Equivalent to the C macro INUM_TO_IVEC used to convert an interrupt
154 -- number to an interrupt vector
156 function sysIntEnable (intLevel : int) return STATUS;
157 -- Binding to the C routine sysIntEnable
159 function sysIntDisable (intLevel : int) return STATUS;
160 -- Binding to the C routine sysIntDisable
162 function sysBusIntAck (intLevel : int) return STATUS;
163 -- Binding to the C routine sysBusIntAck
165 function sysBusIntGen (intLevel : int; Intnum : int) return STATUS;
166 -- Binding to the C routine sysBusIntGen. Note that the T2
167 -- documentation implies that a vector address is the proper
168 -- argument - it's not. The interrupt number in the range
169 -- 0 .. 255 (for 68K and PPC) is the correct agument.
171 procedure logMsg
172 (fmt : String; arg1, arg2, arg3, arg4, arg5, arg6 : int := 0);
173 -- Binding to the C routine logMsg. Note that it is the caller's
174 -- responsibility to ensure that fmt is a null-terminated string
175 -- (e.g logMsg ("Interrupt" & ASCII.NUL))
177 type FP_CONTEXT is private;
178 -- Floating point context save and restore. Handlers using floating
179 -- point must be bracketed with these calls. The pFpContext parameter
180 -- should be an object of type FP_CONTEXT that is
181 -- declared local to the handler.
183 procedure fppRestore (pFpContext : in out FP_CONTEXT);
184 -- Restore floating point context
186 procedure fppSave (pFpContext : in out FP_CONTEXT);
187 -- Save floating point context
189 private
191 type FP_CONTEXT is new System.VxWorks.FP_CONTEXT;
192 -- Target-dependent floating point context type
194 pragma Import (C, intConnect, "intConnect");
195 pragma Import (C, intVecGet, "intVecGet");
196 pragma Import (C, intVecSet, "intVecSet");
197 pragma Import (C, INUM_TO_IVEC, "__gnat_inum_to_ivec");
198 pragma Import (C, sysIntEnable, "sysIntEnable");
199 pragma Import (C, sysIntDisable, "sysIntDisable");
200 pragma Import (C, sysBusIntAck, "sysBusIntAck");
201 pragma Import (C, sysBusIntGen, "sysBusIntGen");
202 pragma Import (C, logMsg, "logMsg");
203 pragma Import (C, fppRestore, "fppRestore");
204 pragma Import (C, fppSave, "fppSave");
205 end Interfaces.VxWorks;