1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- I N T E R F A C E S . V X W O R K S --
9 -- Copyright (C) 1999-2010, AdaCore --
11 -- GNAT 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 3, or (at your option) any later ver- --
14 -- sion. GNAT 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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
30 ------------------------------------------------------------------------------
32 -- This package provides a limited binding to the VxWorks API
33 -- In particular, it interfaces with the VxWorks hardware interrupt
34 -- facilities, allowing the use of low-latency direct-vectored
35 -- interrupt handlers. Note that such handlers have a variety of
36 -- restrictions regarding system calls and language constructs. In particular,
37 -- the use of exception handlers and functions returning variable-length
38 -- objects cannot be used. Less restrictive, but higher-latency handlers can
39 -- be written using Ada protected procedures, Ada 83 style interrupt entries,
40 -- or by signalling an Ada task from within an interrupt handler using a
41 -- binary semaphore as described in the VxWorks Programmer's Manual.
43 -- For complete documentation of the operations in this package, please
44 -- consult the VxWorks Programmer's Manual and VxWorks Reference Manual.
46 pragma Warnings
(Off
, "*foreign convention*");
47 pragma Warnings
(Off
, "*add Convention pragma*");
48 -- These are temporary pragmas to suppress warnings about mismatching
49 -- conventions, which will be a problem when we get rid of trampolines ???
53 package Interfaces
.VxWorks
is
56 ------------------------------------------------------------------------
57 -- Here is a complete example that shows how to handle the Interrupt 0x14
58 -- with a direct-vectored interrupt handler in Ada using this package:
60 -- with Interfaces.VxWorks; use Interfaces.VxWorks;
66 -- pragma Atomic (Count);
68 -- Level : constant := 1;
69 -- -- Interrupt level used by this example
71 -- procedure Handler (parameter : System.Address);
77 -- procedure Handler (parameter : System.Address) is
80 -- Count := Count + 1;
81 -- logMsg ("received an interrupt" & ASCII.LF & ASCII.NUL);
83 -- -- Acknowledge VME interrupt
84 -- S := sysBusIntAck (intLevel => Level);
88 -- with Interfaces.VxWorks; use Interfaces.VxWorks;
89 -- with Ada.Text_IO; use Ada.Text_IO;
92 -- procedure Useint is
93 -- -- Be sure to use a reasonable interrupt number for the target
95 -- -- This one is the unused VME graphics interrupt on the PPC MV2604
96 -- Interrupt : constant := 16#14#;
105 -- Put_Line ("Generating an interrupt...");
108 -- -- Generate VME interrupt, using interrupt number
109 -- S := sysBusIntGen (1, Interrupt);
114 -- S := sysIntEnable (intLevel => Level);
115 -- S := intConnect (INUM_TO_IVEC (Interrupt), handler'Access);
119 -- Put_Line ("value of count:" & P.Count'Img);
122 -------------------------------------
124 subtype int
is Integer;
126 type STATUS
is new int
;
127 -- Equivalent of the C type STATUS
129 OK
: constant STATUS
:= 0;
130 ERROR
: constant STATUS
:= -1;
132 type VOIDFUNCPTR
is access procedure (parameter
: System
.Address
);
133 type Interrupt_Vector
is new System
.Address
;
134 type Exception_Vector
is new System
.Address
;
137 (vector
: Interrupt_Vector
;
138 handler
: VOIDFUNCPTR
;
139 parameter
: System
.Address
:= System
.Null_Address
) return STATUS
;
140 -- Binding to the C routine intConnect. Use this to set up an
141 -- user handler. The routine generates a wrapper around the user
142 -- handler to save and restore context
144 function intContext
return int
;
145 -- Binding to the C routine intContext. This function returns 1 only
146 -- if the current execution state is in interrupt context.
149 (Vector
: Interrupt_Vector
) return VOIDFUNCPTR
;
150 -- Binding to the C routine intVecGet. Use this to get the
151 -- existing handler for later restoral
154 (Vector
: Interrupt_Vector
;
155 Handler
: VOIDFUNCPTR
);
156 -- Binding to the C routine intVecSet. Use this to restore a
157 -- handler obtained using intVecGet
159 function INUM_TO_IVEC
(intNum
: int
) return Interrupt_Vector
;
160 -- Equivalent to the C macro INUM_TO_IVEC used to convert an interrupt
161 -- number to an interrupt vector
163 function sysIntEnable
(intLevel
: int
) return STATUS
;
164 -- Binding to the C routine sysIntEnable
166 function sysIntDisable
(intLevel
: int
) return STATUS
;
167 -- Binding to the C routine sysIntDisable
169 function sysBusIntAck
(intLevel
: int
) return STATUS
;
170 -- Binding to the C routine sysBusIntAck
172 function sysBusIntGen
(intLevel
: int
; Intnum
: int
) return STATUS
;
173 -- Binding to the C routine sysBusIntGen. Note that the T2
174 -- documentation implies that a vector address is the proper
175 -- argument - it's not. The interrupt number in the range
176 -- 0 .. 255 (for 68K and PPC) is the correct argument.
179 (fmt
: String; arg1
, arg2
, arg3
, arg4
, arg5
, arg6
: int
:= 0);
180 -- Binding to the C routine logMsg. Note that it is the caller's
181 -- responsibility to ensure that fmt is a null-terminated string
182 -- (e.g logMsg ("Interrupt" & ASCII.NUL))
184 type FP_CONTEXT
is private;
185 -- Floating point context save and restore. Handlers using floating
186 -- point must be bracketed with these calls. The pFpContext parameter
187 -- should be an object of type FP_CONTEXT that is
188 -- declared local to the handler.
190 procedure fppRestore
(pFpContext
: in out FP_CONTEXT
);
191 -- Restore floating point context
193 procedure fppSave
(pFpContext
: in out FP_CONTEXT
);
194 -- Save floating point context
198 type FP_CONTEXT
is new System
.VxWorks
.FP_CONTEXT
;
199 -- Target-dependent floating point context type
201 pragma Import
(C
, intConnect
, "intConnect");
202 pragma Import
(C
, intContext
, "intContext");
203 pragma Import
(C
, intVecGet
, "intVecGet");
204 pragma Import
(C
, intVecSet
, "intVecSet");
205 pragma Import
(C
, INUM_TO_IVEC
, "__gnat_inum_to_ivec");
206 pragma Import
(C
, sysIntEnable
, "sysIntEnable");
207 pragma Import
(C
, sysIntDisable
, "sysIntDisable");
208 pragma Import
(C
, sysBusIntAck
, "sysBusIntAck");
209 pragma Import
(C
, sysBusIntGen
, "sysBusIntGen");
210 pragma Import
(C
, logMsg
, "logMsg");
211 pragma Import
(C
, fppRestore
, "fppRestore");
212 pragma Import
(C
, fppSave
, "fppSave");
213 end Interfaces
.VxWorks
;