Imported Upstream version 1.2.0
[platform/upstream/iotivity.git] / resource / c_common / oic_time / include / oic_time.h
1 //******************************************************************
2 //
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef OIC_TIME_H_
22 #define OIC_TIME_H_
23
24 #include <stdint.h>
25
26 #define MS_PER_SEC  (1000)
27 #define US_PER_SEC  (1000000)
28 #define US_PER_MS   (1000)
29 #define NS_PER_US   (1000)
30 #define NS_PER_MS   (1000000)
31 #define HNS_PER_US  (10)
32
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #endif // __cplusplus
38
39 typedef enum
40 {
41     TIME_IN_MS = 0,
42     TIME_IN_US,
43 }OICTimePrecision;
44
45 /*
46  * If monotonic coarse/monotonic clock supported then gets current time as monotonic time
47  * in milliseconds or microseconds as the elapsed time since some unspecified starting point
48  * else gets current time in milliseconds or microseconds as the elapsed time since the epoch.
49  *
50  * For Arduino gets current time in milliseconds or microseconds since Arduino board begin
51  * running this program.
52  *
53  * @param     precision   based on this parameter, current time is returned in milliseconds or
54  *                        microseconds
55  *
56  * @warning   This function may be sensitive to system time changes on some platforms.
57  *
58  * @note
59  *            On Arduino platform:
60  *            if the time precision is in milliseconds then the function will overflow
61  *            (go back to 0) after approximately 50 days.
62  *            if the time precision is in microseconds then the function will overflow
63  *            (go back to 0) after approximately 70minutes.
64  *
65  * @return
66  *         returns current time in milliseconds or microseconds.
67  */
68 uint64_t OICGetCurrentTime(OICTimePrecision precision);
69
70 #ifdef __cplusplus
71 }
72 #endif // __cplusplus
73 #endif // OIC_TIME_H_