source: pacpusframework/branches/0.2.x/include/Pacpus/kernel/road_time.h

Last change on this file was 89, checked in by morasjul, 11 years ago

PACPUS 2.0 Beta deployed in new branch

Major changes:
-Add communication interface between components
-Add examples for communications interface (TestComponents)
-Move to Qt5 support

  • Property svn:executable set to *
File size: 3.5 KB
Line 
1// %pacpus:license{
2// This file is part of the PACPUS framework distributed under the
3// CECILL-C License, Version 1.0.
4// %pacpus:license}
5/// @file
6/// @author Gerald Dherbomez <firstname.surname@utc.fr>
7/// @date January, 2006
8/// @version $Id: road_time.h 76 2013-01-10 17:05:10Z kurdejma $
9/// @copyright Copyright (c) UTC/CNRS Heudiasyc 2006 - 2013. All rights reserved.
10/// @brief Brief description.
11///
12/// Detailed description.
13
14// FIXME: update this note.
15// NOTE:
16// This DLL was compiled as a Standard C Language Dynamic Link Libtrary.
17// So in order to be compatible with C++ program, we must add the command extern "C"
18// for the whole include file.
19
20#ifndef DEF_PACPUS_ROAD_TIME_H
21#define DEF_PACPUS_ROAD_TIME_H
22
23#ifdef __cplusplus
24extern "C" {
25#endif // __cplusplus
26
27#include <stddef.h> // defines: NULL
28
29#include <Pacpus/kernel/cstdint.h>
30
31/// Export macro for ROAD_TIME DLL for Windows only
32#ifdef WIN32
33# ifdef ROAD_TIME_EXPORTS
34# define ROAD_TIME_API __declspec(dllexport)
35# else
36# define ROAD_TIME_API __declspec(dllimport)
37# endif
38#else
39# define ROAD_TIME_API /* nothing */
40#endif
41
42/// Timestamp type
43typedef uint64_t road_time_t;
44/// Timerange type
45typedef int32_t road_timerange_t;
46
47/// Timestamp difference type
48typedef int64_t road_time_diff_t;
49/// Timerange difference type
50typedef int32_t road_timerange_diff_t;
51
52#ifdef WIN32
53
54/// Structure exchanged to give the Initialization parameters. All these fields are filled when the
55/// first process attached to the DLL. It gives the Real Time and the value of the Performance Counter
56/// at the same time.
57/// Description of each field is provided inside the structure
58struct Initialisation_Time
59{
60 /// Time (extended to micro seconds precision)
61 /// that was given by the Real Time Clock of
62 /// windows (using ftime()) at the first time the DLL was called.
63 road_time_t Real_Time;
64
65 /// Correpsonding number of cycles of the CPU Performance Counter,
66 /// if it is available. Normally it is the Multimedia Counter.
67 /// If the Performance Counter is not availaible, normally it
68 /// should return the Real Time Counter Value (accuracy of 10 ms)..
69 uint64_t Multimedia_Counter;
70
71 /// Frequency of the Performance Counter, if it is available
72 /// This Frequency is given in Hertz.
73 uint64_t Multimedia_Counter_Frequency;
74
75 /// Delta_t is used to have less work when asking time.
76 /// Delta_t is equal to Real_Time - (Multimedia_Counter/Multimedia_Counter_Frequancy)/1000000
77 road_time_t delta_t;
78};
79
80/// This method just return the actual time using a method based on delta_t (1 less operation).
81/// Return a road_time_t: ellapsed time in microseconds since the 1/01/1970
82road_time_t ROAD_TIME_API road_time(void);
83
84/// This method just return the actual time using all the fields of the Initiaiztion_Time Structure.
85/// Return a road_time_t: ellapsed time in microseconds since the 1/01/1970
86road_time_t ROAD_TIME_API road_time2(void);
87
88/// This method just return the Initialization Parameter
89/// Return an Initialization_Time structure (see below)
90struct Initialisation_Time ROAD_TIME_API road_time_init(void);
91
92#else // WIN32
93
94// UNIX
95
96#include <sys/time.h>
97
98static road_time_t road_time(void)
99{
100 struct timeval t;
101 gettimeofday(&t, NULL);
102 return(road_time_t)((road_time_t)(t.tv_sec)*1000000 + (road_time_t)(t.tv_usec));
103}
104
105#endif // WIN32
106
107#ifdef __cplusplus
108}
109#endif // __cplusplus
110
111#endif // DEF_PACPUS_ROAD_TIME_H
Note: See TracBrowser for help on using the repository browser.