1------------------------------------------------------------------------------ 2-- -- 3-- GNAT 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-2021, AdaCore -- 10-- -- 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. -- 17-- -- 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. -- 21-- -- 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/>. -- 26-- -- 27-- GNARL was developed by the GNARL team at Florida State University. -- 28-- Extensive contributions were provided by Ada Core Technologies, Inc. -- 29-- -- 30------------------------------------------------------------------------------ 31 32-- This package provides a limited binding to the VxWorks API 33 34-- In particular, it interfaces with the VxWorks hardware interrupt 35-- facilities, allowing the use of low-latency direct-vectored interrupt 36-- handlers. Note that such handlers have a variety of restrictions regarding 37-- system calls and language constructs. In particular, the use of exception 38-- handlers and functions returning variable-length objects cannot be used. 39-- Less restrictive, but higher-latency handlers can be written using Ada 40-- protected procedures, Ada 83 style interrupt entries, or by signalling 41-- an Ada task from within an interrupt handler using a binary semaphore 42-- as described in the VxWorks Programmer's Manual. 43-- 44-- For complete documentation of the operations in this package, please 45-- consult the VxWorks Programmer's Manual and VxWorks Reference Manual. 46 47pragma Warnings (Off, "*foreign convention*"); 48pragma Warnings (Off, "*add Convention pragma*"); 49-- These are temporary pragmas to suppress warnings about mismatching 50-- conventions, which will be a problem when we get rid of trampolines ??? 51 52with System.VxWorks; 53 54package Interfaces.VxWorks is 55 pragma Preelaborate; 56 57 ------------------------------------------------------------------------ 58 -- Here is a complete example that shows how to handle the Interrupt 0x14 59 -- with a direct-vectored interrupt handler in Ada using this package: 60 61 -- with Interfaces.VxWorks; use Interfaces.VxWorks; 62 -- with System; 63 -- 64 -- package P is 65 -- 66 -- Count : Integer; 67 -- pragma Atomic (Count); 68 -- 69 -- Level : constant := 1; 70 -- -- Interrupt level used by this example 71 -- 72 -- procedure Handler (parameter : System.Address); 73 -- 74 -- end P; 75 -- 76 -- package body P is 77 -- 78 -- procedure Handler (parameter : System.Address) is 79 -- S : STATUS; 80 -- begin 81 -- Count := Count + 1; 82 -- logMsg ("received an interrupt" & ASCII.LF & ASCII.NUL); 83 -- 84 -- -- Acknowledge VME interrupt 85 -- 86 -- S := sysBusIntAck (intLevel => Level); 87 -- end Handler; 88 -- end P; 89 -- 90 -- with Interfaces.VxWorks; use Interfaces.VxWorks; 91 -- with Ada.Text_IO; use Ada.Text_IO; 92 -- 93 -- with P; use P; 94 -- procedure Useint is 95 -- 96 -- -- Be sure to use a reasonable interrupt number for board. 97 -- -- This one is the unused VME graphics interrupt on the PPC MV2604 98 -- 99 -- Interrupt : constant := 16#14#; 100 -- 101 -- task T; 102 -- 103 -- S : STATUS; 104 -- 105 -- task body T is 106 -- begin 107 -- loop 108 -- Put_Line ("Generating an interrupt..."); 109 -- delay 1.0; 110 -- 111 -- -- Generate VME interrupt, using interrupt number 112 -- 113 -- S := sysBusIntGen (1, Interrupt); 114 -- end loop; 115 -- end T; 116 -- 117 -- begin 118 -- S := sysIntEnable (intLevel => Level); 119 -- S := intConnect (INUM_TO_IVEC (Interrupt), handler'Access); 120 -- 121 -- loop 122 -- delay 2.0; 123 -- Put_Line ("value of count:" & P.Count'Img); 124 -- end loop; 125 -- end Useint; 126 ------------------------------------- 127 128 subtype int is Integer; 129 130 type STATUS is new int; 131 -- Equivalent of the C type STATUS 132 133 OK : constant STATUS := 0; 134 ERROR : constant STATUS := -1; 135 136 type BOOL is new int; 137 -- Equivalent of the C type BOOL 138 139 type VOIDFUNCPTR is access procedure (parameter : System.Address); 140 type Interrupt_Vector is new System.Address; 141 type Exception_Vector is new System.Address; 142 143 function intConnect 144 (vector : Interrupt_Vector; 145 handler : VOIDFUNCPTR; 146 parameter : System.Address := System.Null_Address) return STATUS; 147 -- Binding to the C routine intConnect. Use this to set up an user handler. 148 -- The routine generates a wrapper around the user handler to save and 149 -- restore context 150 151 function intContext return BOOL; 152 -- Binding to the C routine intContext. This function returns 1 (TRUE) 153 -- only if the current execution state is in interrupt context. 154 155 function intVecGet 156 (Vector : Interrupt_Vector) return VOIDFUNCPTR; 157 -- Binding to the C routine intVecGet. Use this to get the existing handler 158 -- for later restoral 159 160 procedure intVecSet 161 (Vector : Interrupt_Vector; 162 Handler : VOIDFUNCPTR); 163 -- Binding to the C routine intVecSet. Use this to restore a handler 164 -- obtained using intVecGet 165 166 function INUM_TO_IVEC (intNum : int) return Interrupt_Vector; 167 -- Equivalent to the C macro INUM_TO_IVEC used to convert an interrupt 168 -- number to an interrupt vector 169 170 function sysIntEnable (intLevel : int) return STATUS; 171 -- Binding to the C routine sysIntEnable 172 173 function sysIntDisable (intLevel : int) return STATUS; 174 -- Binding to the C routine sysIntDisable 175 176 function sysBusIntAck (intLevel : int) return STATUS; 177 -- Binding to the C routine sysBusIntAck 178 179 function sysBusIntGen (intLevel : int; Intnum : int) return STATUS; 180 -- Binding to the C routine sysBusIntGen. Note that the T2 documentation 181 -- implies that a vector address is the proper argument - it's not. The 182 -- interrupt number in the range 0 .. 255 (for 68K and PPC) is the correct 183 -- argument. 184 185 procedure logMsg 186 (fmt : String; arg1, arg2, arg3, arg4, arg5, arg6 : int := 0); 187 -- Binding to the C routine logMsg. Note that it is the caller's 188 -- responsibility to ensure that fmt is a null-terminated string 189 -- (e.g logMsg ("Interrupt" & ASCII.NUL)) 190 191 type FP_CONTEXT is private; 192 -- Floating point context save and restore. Handlers using floating point 193 -- must be bracketed with these calls. The pFpContext parameter should be 194 -- an object of type FP_CONTEXT that is declared local to the handler. 195 196 procedure fppRestore (pFpContext : in out FP_CONTEXT); 197 -- Restore floating point context 198 199 procedure fppSave (pFpContext : in out FP_CONTEXT); 200 -- Save floating point context 201 202private 203 204 type FP_CONTEXT is new System.VxWorks.FP_CONTEXT; 205 -- Target-dependent floating point context type 206 207 pragma Import (C, intConnect, "intConnect"); 208 pragma Import (C, intContext, "intContext"); 209 pragma Import (C, intVecGet, "intVecGet"); 210 pragma Import (C, intVecSet, "intVecSet"); 211 pragma Import (C, INUM_TO_IVEC, "__gnat_inum_to_ivec"); 212 pragma Import (C, sysIntEnable, "sysIntEnable"); 213 pragma Import (C, sysIntDisable, "sysIntDisable"); 214 pragma Import (C, sysBusIntAck, "sysBusIntAck"); 215 pragma Import (C, sysBusIntGen, "sysBusIntGen"); 216 pragma Import (C, logMsg, "logMsg"); 217 pragma Import (C, fppRestore, "fppRestore"); 218 pragma Import (C, fppSave, "fppSave"); 219end Interfaces.VxWorks; 220