Cast constants to hptime_t.
[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 #include "hptime.h"
14
15 #if defined(_WIN32)
16
17 #include <windows.h>
18
19 hptime_t hptime_get(void)
20 {
21         FILETIME ft;
22
23         /*
24          * La precisione dei FileTime sarebbe 100ns, ma il
25          * valore viene ottenuto convertendo una struttura
26          * SYSTEMTIME, che ha precisione di 1ms. Il numero
27          * che otteniamo e' quindi sempre un multiplo di
28          * 100000.
29          */
30         GetSystemTimeAsFileTime(&ft);
31
32         /* Copy the upper/lower into a quadword. */
33         return (((hptime_t)ft.dwHighDateTime) << 32) + (hptime_t)ft.dwLowDateTime;
34 }
35
36 #elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
37
38 #include <sys/time.h>
39
40 hptime_t hptime_get(void)
41 {
42         struct timeval tv;
43
44         gettimeofday(&tv, 0);
45         return (hptime_t)tv.tv_sec * HPTIME_TICKS_PER_SECOND
46                 + (hptime_t)tv.tv_usec;
47 }
48
49 #else /* !__unix__ */
50         #error OS dependent support code missing for this OS
51 #endif /* !__unix__ */
52