• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "adaptor_time.h"
17 
18 #include <time.h>
19 #include "adaptor_log.h"
20 
21 #define MS_OF_S 1000
22 #define NS_OF_MS 1000000
23 
GetRtcTime(void)24 uint64_t GetRtcTime(void)
25 {
26     struct timespec curTime;
27     int res = clock_gettime(CLOCK_MONOTONIC, &curTime);
28     if (res != 0) {
29         LOG_ERROR("get time fail");
30         return 0;
31     }
32     return curTime.tv_sec * MS_OF_S + curTime.tv_nsec / NS_OF_MS;
33 }
34 
GetSystemTime(void)35 uint64_t GetSystemTime(void)
36 {
37     struct timespec curTime;
38     int res = clock_gettime(CLOCK_MONOTONIC, &curTime);
39     if (res != 0) {
40         LOG_ERROR("get time fail");
41         return 0;
42     }
43     return curTime.tv_sec * MS_OF_S + curTime.tv_nsec / NS_OF_MS;
44 }