blob: 914b2018e63868800f291475f7dad4681ee0e733 [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
6-- the Free Software Foundation; version 2 of the License.
7--
8-- This program is distributed in the hope that it will be useful,
9-- but WITHOUT ANY WARRANTY; without even the implied warranty of
10-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11-- GNU General Public License for more details.
12--
13
14with Interfaces.C;
15
16use type Interfaces.C.long;
17
18package body HW.Time.Timer
19with
20 Refined_State => (Timer_State => null,
21 Abstract_Time => null)
22is
23 CLOCK_MONOTONIC_RAW : constant := 4;
24
25 subtype Clock_ID_T is Interfaces.C.int;
26 subtype Time_T is Interfaces.C.long;
27
28 type Struct_Timespec is record
29 TV_Sec : aliased Time_T;
30 TV_NSec : aliased Interfaces.C.long;
31 end record;
32 pragma Convention (C_Pass_By_Copy, Struct_Timespec);
33
34 function Clock_Gettime
35 (Clock_ID : Clock_ID_T;
36 Timespec : access Struct_Timespec)
37 return Interfaces.C.int;
38 pragma Import (C, Clock_Gettime, "clock_gettime");
39
40 function Raw_Value_Min return T
41 is
42 Ignored : Interfaces.C.int;
43 Timespec : aliased Struct_Timespec;
44 begin
45 Ignored := Clock_Gettime (CLOCK_MONOTONIC_RAW, Timespec'Access);
46 return T (Timespec.TV_Sec * 1_000_000_000 + Timespec.TV_NSec);
47 end Raw_Value_Min;
48
49 function Raw_Value_Max return T
50 is
51 begin
52 return Raw_Value_Min + 1;
53 end Raw_Value_Max;
54
55 function Hz return T
56 is
57 begin
58 return 1_000_000_000; -- clock_gettime(2) is fixed to nanoseconds
59 end Hz;
60
61end HW.Time.Timer;