File : a-calclo-vxworks-cert.adb


   1 ------------------------------------------------------------------------------
   2 --                                                                          --
   3 --                         GNAT RUN-TIME COMPONENTS                         --
   4 --                                                                          --
   5 --                    A D A . C A L E N D A R . C L O C K                   --
   6 --                                                                          --
   7 --                                 B o d y                                  --
   8 --                                                                          --
   9 --                     Copyright (C) 2004-2012, AdaCore                     --
  10 --                                                                          --
  11 -- GNAT 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.                                     --
  17 --                                                                          --
  18 --                                                                          --
  19 --                                                                          --
  20 --                                                                          --
  21 --                                                                          --
  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/>.                                          --
  26 --                                                                          --
  27 -- GNAT was originally developed  by the GNAT team at  New York University. --
  28 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
  29 --                                                                          --
  30 ------------------------------------------------------------------------------
  31 
  32 --  This is the VxWorks AE653 Level A cert version of this package
  33 
  34 separate (Ada.Calendar)
  35 
  36 -----------
  37 -- Clock --
  38 -----------
  39 
  40 function Clock return Time is
  41    --  VxWorks Time Definitions
  42 
  43    type time_t is new unsigned_long;
  44 
  45    type timespec is record
  46       ts_sec  : time_t;
  47       ts_nsec : long;
  48    end record;
  49    pragma Convention (C, timespec);
  50 
  51    type clockid_t is new int;
  52    CLOCK_REALTIME : constant clockid_t := 0;
  53 
  54    function clock_gettime
  55      (clock_id : clockid_t;
  56       tp       : not null access timespec) return int;
  57    pragma Import (C, clock_gettime, "clock_gettime");
  58    --  Time elapsed since the epoch (0H UT 1/1/1970)
  59 
  60    TS     : aliased timespec;
  61    Result : int;
  62 
  63    Elapsed_Seconds : Duration;
  64    Elapsed_Days    : Time;
  65 
  66 begin
  67    Result := clock_gettime (CLOCK_REALTIME, TS'Unchecked_Access);
  68    pragma Assert (Result = 0);
  69 
  70    Elapsed_Seconds :=
  71      Duration (TS.ts_sec) + Duration (TS.ts_nsec) / 10#1#E9;
  72    Elapsed_Days := Elapsed_Seconds / Secs_Per_Day;
  73 
  74    return Radix_Time + Elapsed_Days;
  75 end Clock;