1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- I N T E R F A C E S . V X W O R K S --
11 -- Copyright (C) 1999 - 2001 Ada Core Technologies, Inc. --
13 -- GNARL is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNARL; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNARL was developed by the GNARL team at Florida State University. It is --
32 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
33 -- State University (http://www.gnat.com). --
35 ------------------------------------------------------------------------------
37 -- This package provides a limited binding to the VxWorks API
38 -- In particular, it interfaces with the VxWorks hardware interrupt
39 -- facilities, allowing the use of low-latency direct-vectored
40 -- interrupt handlers. Note that such handlers have a variety of
41 -- restrictions regarding system calls. Less restrictive, but higher-
42 -- latency handlers can be written using Ada protected procedures,
43 -- Ada 83 style interrupt entries, or by signalling an Ada task
44 -- from within an interrupt handler using a binary semaphore as
45 -- described in the VxWorks Programmer's Manual
47 -- For complete documentation of the operations in this package, please
48 -- consult the VxWorks Programmer's Manual and VxWorks Reference Manual
52 package Interfaces
.VxWorks
is
53 pragma Preelaborate
(VxWorks
);
55 ------------------------------------------------------------------------
56 -- Here is a complete example that shows how to handle the Interrupt 0x14
57 -- with a direct-vectored interrupt handler in Ada using this package:
59 -- with Interfaces.VxWorks; use Interfaces.VxWorks;
65 -- pragma Atomic (Count);
67 -- Level : constant := 1;
68 -- -- Interrupt level used by this example
70 -- procedure Handler (parameter : System.Address);
76 -- procedure Handler (parameter : System.Address) is
79 -- Count := Count + 1;
80 -- logMsg ("received an interrupt" & ASCII.LF & ASCII.Nul);
82 -- -- Acknowledge VME interrupt
83 -- S := sysBusIntAck (intLevel => Level);
87 -- with Interfaces.VxWorks; use Interfaces.VxWorks;
88 -- with Ada.Text_IO; use Ada.Text_IO;
91 -- procedure Useint is
92 -- -- Be sure to use a reasonable interrupt number for the target
94 -- -- This one is the unused VME graphics interrupt on the PPC MV2604
95 -- Interrupt : constant := 16#14#;
104 -- Put_Line ("Generating an interrupt...");
107 -- -- Generate VME interrupt, using interrupt number
108 -- S := sysBusIntGen (1, Interrupt);
113 -- S := sysIntEnable (intLevel => Level);
114 -- S := intConnect (INUM_TO_IVEC (Interrupt), handler'Access);
118 -- Put_Line ("value of count:" & P.Count'Img);
121 -------------------------------------
123 subtype int
is Integer;
125 type STATUS
is new int
;
126 -- Equivalent of the C type STATUS
128 OK
: constant STATUS
:= 0;
129 ERROR
: constant STATUS
:= -1;
131 type VOIDFUNCPTR
is access procedure (parameter
: System
.Address
);
132 type Interrupt_Vector
is new System
.Address
;
133 type Exception_Vector
is new System
.Address
;
136 (vector
: Interrupt_Vector
;
137 handler
: VOIDFUNCPTR
;
138 parameter
: System
.Address
:= System
.Null_Address
) return STATUS
;
139 -- Binding to the C routine intConnect. Use this to set up an
140 -- user handler. The routine generates a wrapper around the user
141 -- handler to save and restore context
144 (Vector
: Interrupt_Vector
) return VOIDFUNCPTR
;
145 -- Binding to the C routine intVecGet. Use this to get the
146 -- existing handler for later restoral
149 (Vector
: Interrupt_Vector
;
150 Handler
: VOIDFUNCPTR
);
151 -- Binding to the C routine intVecSet. Use this to restore a
152 -- handler obtained using intVecGet
154 function INUM_TO_IVEC
(intNum
: int
) return Interrupt_Vector
;
155 -- Equivalent to the C macro INUM_TO_IVEC used to convert an interrupt
156 -- number to an interrupt vector
158 function sysIntEnable
(intLevel
: int
) return STATUS
;
159 -- Binding to the C routine sysIntEnable
161 function sysIntDisable
(intLevel
: int
) return STATUS
;
162 -- Binding to the C routine sysIntDisable
164 function sysBusIntAck
(intLevel
: int
) return STATUS
;
165 -- Binding to the C routine sysBusIntAck
167 function sysBusIntGen
(intLevel
: int
; Intnum
: int
) return STATUS
;
168 -- Binding to the C routine sysBusIntGen. Note that the T2
169 -- documentation implies that a vector address is the proper
170 -- argument - it's not. The interrupt number in the range
171 -- 0 .. 255 (for 68K and PPC) is the correct agument.
174 (fmt
: String; arg1
, arg2
, arg3
, arg4
, arg5
, arg6
: int
:= 0);
175 -- Binding to the C routine logMsg. Note that it is the caller's
176 -- responsibility to ensure that fmt is a null-terminated string
177 -- (e.g logMsg ("Interrupt" & ASCII.NUL))
179 type FP_CONTEXT
is private;
180 -- Floating point context save and restore. Handlers using floating
181 -- point must be bracketed with these calls. The pFpContext parameter
182 -- should be an object of type FP_CONTEXT that is
183 -- declared local to the handler.
185 procedure fppRestore
(pFpContext
: in out FP_CONTEXT
);
186 -- Restore floating point context
188 procedure fppSave
(pFpContext
: in out FP_CONTEXT
);
189 -- Save floating point context
193 type FP_CONTEXT
is new System
.VxWorks
.FP_CONTEXT
;
194 -- Target-dependent floating point context type
196 pragma Import
(C
, intConnect
, "intConnect");
197 pragma Import
(C
, intVecGet
, "intVecGet");
198 pragma Import
(C
, intVecSet
, "intVecSet");
199 pragma Import
(C
, INUM_TO_IVEC
, "__gnat_inum_to_ivec");
200 pragma Import
(C
, sysIntEnable
, "sysIntEnable");
201 pragma Import
(C
, sysIntDisable
, "sysIntDisable");
202 pragma Import
(C
, sysBusIntAck
, "sysBusIntAck");
203 pragma Import
(C
, sysBusIntGen
, "sysBusIntGen");
204 pragma Import
(C
, logMsg
, "logMsg");
205 pragma Import
(C
, fppRestore
, "fppRestore");
206 pragma Import
(C
, fppSave
, "fppSave");
207 end Interfaces
.VxWorks
;