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