File : a-reatim-c.ads
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . R E A L _ T I M E --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2001-2015, AdaCore --
10 -- --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the contents of the part following the private keyword. --
14 -- --
15 -- GNAT is free software; you can redistribute it and/or modify it under --
16 -- terms of the GNU General Public License as published by the Free Soft- --
17 -- ware Foundation; either version 3, or (at your option) any later ver- --
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE. --
21 -- --
22 -- --
23 -- --
24 -- --
25 -- --
26 -- You should have received a copy of the GNU General Public License and --
27 -- a copy of the GCC Runtime Library Exception along with this program; --
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
29 -- <http://www.gnu.org/licenses/>. --
30 -- --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
33 -- --
34 ------------------------------------------------------------------------------
35
36 -- This is the Ravenscar/HI-E version of this package for C targets
37
38 package Ada.Real_Time with
39 SPARK_Mode,
40 Abstract_State => (Clock_Time with Synchronous,
41 External => (Async_Readers,
42 Async_Writers)),
43 Initializes => Clock_Time
44 is
45 type Time is private;
46 Time_First : constant Time;
47 Time_Last : constant Time;
48 Time_Unit : constant := 10#1.0#E-4;
49
50 type Time_Span is private;
51 Time_Span_First : constant Time_Span;
52 Time_Span_Last : constant Time_Span;
53 Time_Span_Zero : constant Time_Span;
54 Time_Span_Unit : constant Time_Span;
55
56 Tick : constant Time_Span;
57 function Clock return Time with
58 Volatile_Function,
59 Global => Clock_Time;
60
61 function "+" (Left : Time; Right : Time_Span) return Time;
62 function "+" (Left : Time_Span; Right : Time) return Time;
63 function "-" (Left : Time; Right : Time_Span) return Time;
64 function "-" (Left : Time; Right : Time) return Time_Span;
65
66 function "<" (Left, Right : Time) return Boolean;
67 function "<=" (Left, Right : Time) return Boolean;
68 function ">" (Left, Right : Time) return Boolean;
69 function ">=" (Left, Right : Time) return Boolean;
70
71 function "+" (Left, Right : Time_Span) return Time_Span;
72 function "-" (Left, Right : Time_Span) return Time_Span;
73 function "-" (Right : Time_Span) return Time_Span;
74 function "*" (Left : Time_Span; Right : Integer) return Time_Span;
75 function "*" (Left : Integer; Right : Time_Span) return Time_Span;
76 function "/" (Left, Right : Time_Span) return Integer;
77 function "/" (Left : Time_Span; Right : Integer) return Time_Span;
78
79 function "abs" (Right : Time_Span) return Time_Span;
80
81 function "<" (Left, Right : Time_Span) return Boolean;
82 function "<=" (Left, Right : Time_Span) return Boolean;
83 function ">" (Left, Right : Time_Span) return Boolean;
84 function ">=" (Left, Right : Time_Span) return Boolean;
85
86 function To_Duration (TS : Time_Span) return Duration;
87 function To_Time_Span (D : Duration) return Time_Span;
88
89 function Nanoseconds (NS : Integer) return Time_Span;
90 function Microseconds (US : Integer) return Time_Span;
91 function Milliseconds (MS : Integer) return Time_Span;
92
93 function Seconds (S : Integer) return Time_Span;
94 pragma Ada_05 (Seconds);
95
96 function Minutes (M : Integer) return Time_Span;
97 pragma Ada_05 (Minutes);
98
99 -- 32 bits is enough for representing Seconds_Count. Time is a 32-bit
100 -- unsigned integer, and it then gets divided by the system clock rate.
101
102 type Seconds_Count is range 0 .. 2 ** 31 - 1;
103
104 procedure Split (T : Time; SC : out Seconds_Count; TS : out Time_Span);
105 function Time_Of (SC : Seconds_Count; TS : Time_Span) return Time;
106
107 private
108 pragma SPARK_Mode (Off);
109
110 type Time is mod 2 ** Long_Integer'Size;
111
112 Time_First : constant Time := Time'First;
113
114 Time_Last : constant Time := Time'Last;
115
116 type Time_Span is new Long_Integer;
117
118 Time_Span_First : constant Time_Span := Time_Span'First;
119
120 Time_Span_Last : constant Time_Span := Time_Span'Last;
121
122 Time_Span_Zero : constant Time_Span := 0;
123
124 Time_Span_Unit : constant Time_Span := 1;
125
126 Tick : constant Time_Span := 1;
127
128 pragma Import (Intrinsic, "<");
129 pragma Import (Intrinsic, "<=");
130 pragma Import (Intrinsic, ">");
131 pragma Import (Intrinsic, ">=");
132 pragma Import (Intrinsic, "abs");
133
134 pragma Inline_Always (Clock);
135 pragma Inline_Always ("+");
136 pragma Inline_Always ("-");
137 pragma Inline_Always ("*");
138 pragma Inline_Always ("/");
139 pragma Inline_Always (To_Duration);
140 pragma Inline_Always (To_Time_Span);
141 pragma Inline_Always (Microseconds);
142 pragma Inline_Always (Milliseconds);
143 pragma Inline_Always (Nanoseconds);
144 pragma Inline_Always (Seconds);
145 pragma Inline_Always (Minutes);
146 pragma Inline_Always (Split);
147 pragma Inline_Always (Time_Of);
148
149 end Ada.Real_Time;