1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . O S _ I N T E R F A C E --
9 -- Copyright (C) 1997-2024, Free Software Foundation, Inc. --
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 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 is the VxWorks version
34 -- This package encapsulates all direct interfaces to OS services that are
35 -- needed by children of System.
37 package body System
.OS_Interface
is
39 use type Interfaces
.C
.int
;
41 Low_Priority
: constant := 255;
42 -- VxWorks native (default) lowest scheduling priority
48 function To_Duration
(TS
: timespec
) return Duration is
50 return Duration (TS
.ts_sec
) + Duration (TS
.ts_nsec
) / 10#
1#E9
;
57 function To_Timespec
(D
: Duration) return timespec
is
62 S
:= time_t
(Long_Long_Integer (D
));
63 F
:= D
- Duration (S
);
65 -- If F is negative due to a round-up, adjust for positive F value
72 return timespec
'(ts_sec => S,
73 ts_nsec => long (Long_Long_Integer (F * 10#1#E9)));
76 -------------------------
77 -- To_VxWorks_Priority --
78 -------------------------
80 function To_VxWorks_Priority (Priority : int) return int is
82 return Low_Priority - Priority;
83 end To_VxWorks_Priority;
89 -- ??? - For now, we'll always get the system clock rate since it is
90 -- allowed to be changed during run-time in VxWorks. A better method would
91 -- be to provide an operation to set it that so we can always know its
94 -- Another thing we should probably allow for is a resultant tick count
95 -- greater than int'Last. This should probably be a procedure with two
96 -- output parameters, one in the range 0 .. int'Last, and another
97 -- representing the overflow count.
99 function To_Clock_Ticks (D : Duration) return int is
100 Ticks : Long_Long_Integer;
101 Rate_Duration : Duration;
102 Ticks_Duration : Duration;
103 IERR : constant int := -1;
110 -- Ensure that the duration can be converted to ticks
111 -- at the current clock tick rate without overflowing.
113 Rate_Duration := Duration (sysClkRateGet);
115 if D > (Duration'Last / Rate_Duration) then
116 Ticks := Long_Long_Integer (int'Last);
118 Ticks_Duration := D * Rate_Duration;
119 Ticks := Long_Long_Integer (Ticks_Duration);
121 if Ticks_Duration > Duration (Ticks) then
125 if Ticks > Long_Long_Integer (int'Last) then
126 Ticks := Long_Long_Integer (int'Last);
133 -----------------------------
134 -- Binary_Semaphore_Create --
135 -----------------------------
137 function Binary_Semaphore_Create return Binary_Semaphore_Id is
139 return Binary_Semaphore_Id (semBCreate (SEM_Q_FIFO, SEM_EMPTY));
140 end Binary_Semaphore_Create;
142 -----------------------------
143 -- Binary_Semaphore_Delete --
144 -----------------------------
146 function Binary_Semaphore_Delete (ID : Binary_Semaphore_Id)
149 return semDelete (SEM_ID (ID));
150 end Binary_Semaphore_Delete;
152 -----------------------------
153 -- Binary_Semaphore_Obtain --
154 -----------------------------
156 function Binary_Semaphore_Obtain (ID : Binary_Semaphore_Id)
159 return semTake (SEM_ID (ID), WAIT_FOREVER);
160 end Binary_Semaphore_Obtain;
162 ------------------------------
163 -- Binary_Semaphore_Release --
164 ------------------------------
166 function Binary_Semaphore_Release (ID : Binary_Semaphore_Id)
169 return semGive (SEM_ID (ID));
170 end Binary_Semaphore_Release;
172 ----------------------------
173 -- Binary_Semaphore_Flush --
174 ----------------------------
176 function Binary_Semaphore_Flush (ID : Binary_Semaphore_Id) return STATUS is
178 return semFlush (SEM_ID (ID));
179 end Binary_Semaphore_Flush;
185 function kill (pid : t_id; sig : Signal) return int is
187 return System.VxWorks.Ext.kill (pid, int (sig));
190 -----------------------
191 -- Interrupt_Connect --
192 -----------------------
194 function Interrupt_Connect
195 (Vector : Interrupt_Vector;
196 Handler : Interrupt_Handler;
197 Parameter : System.Address := System.Null_Address) return STATUS is
200 System.VxWorks.Ext.Interrupt_Connect
201 (System.VxWorks.Ext.Interrupt_Vector (Vector),
202 System.VxWorks.Ext.Interrupt_Handler (Handler),
204 end Interrupt_Connect;
206 -----------------------
207 -- Interrupt_Context --
208 -----------------------
210 function Interrupt_Context return BOOL is
212 return System.VxWorks.Ext.Interrupt_Context;
213 end Interrupt_Context;
215 --------------------------------
216 -- Interrupt_Number_To_Vector --
217 --------------------------------
219 function Interrupt_Number_To_Vector
220 (intNum : int) return Interrupt_Vector
223 return Interrupt_Vector
224 (System.VxWorks.Ext.Interrupt_Number_To_Vector (intNum));
225 end Interrupt_Number_To_Vector;
231 function Current_CPU return Multiprocessors.CPU is
233 -- ??? Should use vxworks multiprocessor interface
235 return Multiprocessors.CPU'First;
238 end System.OS_Interface;