9d9336ed3657eb9ff90c3547c5a34bf9d2510185
[bertos.git] / os / hptime.h
1 /**
2  * \file
3  * <!--
4  * Copyright 2003, 2004 Develer S.r.l. (http://www.develer.com/)
5  * This file is part of DevLib - See README.devlib for information.
6  * -->
7  *
8  * \brief Portable abstraction for high-resolution time handling (interface)
9  *
10  * \author Bernardo Innocenti <bernie@develer.com>
11  */
12 #ifndef HPTIME_H
13 #define HPTIME_H
14
15 /* sparse? */
16 #ifdef __CHECKER__
17         /* Any random OS would do */
18         #define __unix__
19 #endif
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif /* __cplusplus */
24
25 #ifdef _WIN32
26
27         /** our type for "high precision absolute time" */
28         typedef __int64 hptime_t;
29
30         #define HPTIME_TICKS_PER_SECOND         (10000000I64)
31         #define HPTIME_TICKS_PER_MILLISEC       (10000I64)
32         #define HPTIME_TICKS_PER_MICRO          (10I64)
33
34 #elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
35
36         #include <stdint.h> /* int64_t */
37
38         #ifndef DEVLIB_MTIME_DEFINED
39                 #define DEVLIB_MTIME_DEFINED 1 /* Resolve conflict with <cfg/compiler.h> */
40                 typedef int32_t mtime_t;
41                 #define SIZEOF_MTIME_T (32 / CPU_BITS_PER_CHAR)
42                 #define MTIME_INFINITE 0x7FFFFFFFL
43         #endif
44
45         /** Type for "high precision absolute time". */
46         typedef int64_t hptime_t;
47
48         #define HPTIME_TICKS_PER_SECOND         (1000000LL)
49         #define HPTIME_TICKS_PER_MILLISEC       (1000LL)
50         #define HPTIME_TICKS_PER_MICRO          (1LL)
51
52 #else /* !__unix__ */
53         #error OS dependent support code missing for this OS
54 #endif /* !__unix__ */
55
56 /**
57  * Return the current time with the maximum precision made available from the hosting OS
58  */
59 extern hptime_t hptime_get(void);
60
61 #ifdef __cplusplus
62 }
63 #endif /* __cplusplus */
64
65 #endif /* HPTIME_H */