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