Convert to new Doxygen style.
[bertos.git] / os / hptime.c
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 (implementation)
9  *
10  * \version $Id$
11  * \author Bernardo Innocenti <bernie@develer.com>
12  */
13
14 /*#*
15  *#* $Log$
16  *#* Revision 1.8  2006/07/19 12:56:28  bernie
17  *#* Convert to new Doxygen style.
18  *#*
19  *#* Revision 1.7  2006/07/19 12:53:58  bernie
20  *#* Documentation fixes.
21  *#*
22  *#* Revision 1.6  2006/02/20 01:46:46  bernie
23  *#* Port to MacOSX.
24  *#*
25  *#* Revision 1.5  2005/11/04 16:20:02  bernie
26  *#* Fix reference to README.devlib in header.
27  *#*
28  *#* Revision 1.4  2004/08/25 14:12:09  rasky
29  *#* Aggiornato il comment block dei log RCS
30  *#*
31  *#* Revision 1.3  2004/08/10 05:45:04  bernie
32  *#* Fix spacing in header.
33  *#*
34  *#* Revision 1.2  2004/06/03 11:27:09  bernie
35  *#* Add dual-license information.
36  *#*
37  *#* Revision 1.1  2004/06/03 09:01:06  bernie
38  *#* Import into DevLib.
39  *#*
40  *#*/
41
42 #include "hptime.h"
43
44 #if defined(_WIN32)
45
46 #include <windows.h>
47
48 hptime_t hptime_get(void)
49 {
50         FILETIME ft;
51
52         /*
53          * La precisione dei FileTime sarebbe 100ns, ma il
54          * valore viene ottenuto convertendo una struttura
55          * SYSTEMTIME, che ha precisione di 1ms. Il numero
56          * che otteniamo e' quindi sempre un multiplo di
57          * 100000.
58          */
59         GetSystemTimeAsFileTime(&ft);
60
61         /* Copy the upper/lower into a quadword. */
62         return (((hptime_t)ft.dwHighDateTime) << 32) + (hptime_t)ft.dwLowDateTime;
63 }
64
65 #elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
66
67 #include <sys/time.h>
68
69 hptime_t hptime_get(void)
70 {
71         struct timeval tv;
72
73         gettimeofday(&tv, 0);
74         return (hptime_t)tv.tv_sec * HPTIME_TICKS_PER_SECOND
75                 + (hptime_t)tv.tv_usec;
76 }
77
78 #else /* !__unix__ */
79         #error OS dependent support code missing for this OS
80 #endif /* !__unix__ */
81