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