blob: 5f12db7b43450f90275be290c08db29ba6dc4e98 [file] [log] [blame]
Nico Huber5e9b1b52016-10-08 22:09:33 +02001--
2-- Copyright (C) 2016 secunet Security Networks AG
3--
4-- This program is free software; you can redistribute it and/or modify
5-- it under the terms of the GNU General Public License as published by
Nico Huberaab715f2016-10-18 00:22:25 +02006-- the Free Software Foundation; either version 2 of the License, or
7-- (at your option) any later version.
Nico Huber5e9b1b52016-10-08 22:09:33 +02008--
9-- This program is distributed in the hope that it will be useful,
10-- but WITHOUT ANY WARRANTY; without even the implied warranty of
11-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-- GNU General Public License for more details.
13--
14
15with Interfaces.C;
16
17use type Interfaces.C.long;
18
19package body HW.Time.Timer
20with
21 Refined_State => (Timer_State => null,
22 Abstract_Time => null)
23is
24 CLOCK_MONOTONIC_RAW : constant := 4;
25
26 subtype Clock_ID_T is Interfaces.C.int;
27 subtype Time_T is Interfaces.C.long;
28
29 type Struct_Timespec is record
30 TV_Sec : aliased Time_T;
31 TV_NSec : aliased Interfaces.C.long;
32 end record;
33 pragma Convention (C_Pass_By_Copy, Struct_Timespec);
34
35 function Clock_Gettime
36 (Clock_ID : Clock_ID_T;
37 Timespec : access Struct_Timespec)
38 return Interfaces.C.int;
39 pragma Import (C, Clock_Gettime, "clock_gettime");
40
41 function Raw_Value_Min return T
42 is
43 Ignored : Interfaces.C.int;
44 Timespec : aliased Struct_Timespec;
45 begin
46 Ignored := Clock_Gettime (CLOCK_MONOTONIC_RAW, Timespec'Access);
47 return T (Timespec.TV_Sec * 1_000_000_000 + Timespec.TV_NSec);
48 end Raw_Value_Min;
49
50 function Raw_Value_Max return T
51 is
52 begin
53 return Raw_Value_Min + 1;
54 end Raw_Value_Max;
55
56 function Hz return T
57 is
58 begin
59 return 1_000_000_000; -- clock_gettime(2) is fixed to nanoseconds
60 end Hz;
61
62end HW.Time.Timer;