File : a-reatim-xi.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-2016, 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 -- Ravenscar version of this package for generic bare board targets
37
38 with System.OS_Interface;
39 pragma Elaborate_All (System.OS_Interface);
40
41 package Ada.Real_Time with
42 SPARK_Mode,
43 Abstract_State => (Clock_Time with Synchronous,
44 External => (Async_Readers,
45 Async_Writers)),
46 Initializes => Clock_Time
47 is
48 pragma Assert
49 (System.OS_Interface.Ticks_Per_Second >= 50_000,
50 "Ada RM D.8 (30) requires " &
51 "that Time_Unit shall be less than or equal to 20 microseconds");
52
53 type Time is private;
54 Time_First : constant Time;
55 Time_Last : constant Time;
56
57 Time_Unit : constant :=
58 1.0 / Duration (System.OS_Interface.Ticks_Per_Second);
59 -- The BB platforms use a time stamp counter driven by the system clock,
60 -- where the duration of the clock tick (Time_Unit) depends on the speed
61 -- of the underlying hardware. The system clock frequency is used here to
62 -- determine Time_Unit.
63
64 type Time_Span is private;
65 Time_Span_First : constant Time_Span;
66 Time_Span_Last : constant Time_Span;
67 Time_Span_Zero : constant Time_Span;
68 Time_Span_Unit : constant Time_Span;
69
70 Tick : constant Time_Span;
71 function Clock return Time with
72 Volatile_Function,
73 Global => Clock_Time;
74
75 function "+" (Left : Time; Right : Time_Span) return Time;
76 function "-" (Left : Time; Right : Time_Span) return Time;
77 function "-" (Left : Time; Right : Time) return Time_Span;
78
79 function "+" (Left : Time_Span; Right : Time) return Time is
80 (Right + Left);
81
82 function "<" (Left, Right : Time) return Boolean;
83 function "<=" (Left, Right : Time) return Boolean;
84 function ">" (Left, Right : Time) return Boolean;
85 function ">=" (Left, Right : Time) return Boolean;
86
87 function "+" (Left, Right : Time_Span) return Time_Span;
88 function "-" (Left, Right : Time_Span) return Time_Span;
89 function "-" (Right : Time_Span) return Time_Span;
90 function "*" (Left : Time_Span; Right : Integer) return Time_Span;
91 function "*" (Left : Integer; Right : Time_Span) return Time_Span;
92 function "/" (Left, Right : Time_Span) return Integer;
93 function "/" (Left : Time_Span; Right : Integer) return Time_Span;
94
95 function "abs" (Right : Time_Span) return Time_Span;
96
97 function "<" (Left, Right : Time_Span) return Boolean;
98 function "<=" (Left, Right : Time_Span) return Boolean;
99 function ">" (Left, Right : Time_Span) return Boolean;
100 function ">=" (Left, Right : Time_Span) return Boolean;
101
102 function To_Duration (TS : Time_Span) return Duration;
103 function To_Time_Span (D : Duration) return Time_Span;
104
105 function Nanoseconds (NS : Integer) return Time_Span;
106 function Microseconds (US : Integer) return Time_Span;
107 function Milliseconds (MS : Integer) return Time_Span;
108
109 function Seconds (S : Integer) return Time_Span;
110 pragma Ada_05 (Seconds);
111
112 function Minutes (M : Integer) return Time_Span;
113 pragma Ada_05 (Minutes);
114
115 -- Seconds_Count needs 64 bits. Time is a 64-bits unsigned integer
116 -- representing clock ticks, and if the clock frequency is lower than
117 -- 2 ** 32 Hz (~ 4 GHz), which is the case so far, we need more than 32
118 -- bits to represent the number of seconds. Additionally, Time is
119 -- unsigned, so Seconds_Count is always positive.
120
121 type Seconds_Count is range 0 .. 2 ** 63 - 1;
122
123 procedure Split (T : Time; SC : out Seconds_Count; TS : out Time_Span);
124 function Time_Of (SC : Seconds_Count; TS : Time_Span) return Time;
125
126 private
127 pragma SPARK_Mode (Off);
128
129 type Time is new System.OS_Interface.Time;
130
131 Time_First : constant Time := Time'First;
132 Time_Last : constant Time := Time'Last;
133
134 type Time_Span is new System.OS_Interface.Time_Span;
135
136 Time_Span_First : constant Time_Span := Time_Span'First;
137 Time_Span_Last : constant Time_Span := Time_Span'Last;
138
139 Time_Span_Zero : constant Time_Span := 0;
140 Time_Span_Unit : constant Time_Span := 1;
141
142 Tick : constant Time_Span := 1;
143
144 pragma Import (Intrinsic, "<");
145 pragma Import (Intrinsic, "<=");
146 pragma Import (Intrinsic, ">");
147 pragma Import (Intrinsic, ">=");
148 pragma Import (Intrinsic, "abs");
149
150 pragma Inline (Microseconds);
151 pragma Inline (Milliseconds);
152 pragma Inline (Nanoseconds);
153 pragma Inline (Seconds);
154 pragma Inline (Minutes);
155
156 end Ada.Real_Time;