• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
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  * Description: 时间适配层接口cmsis2实现源文件(此文件为DEMO,需集成方适配修改)
15  */
16 
17 #include "hilink_time_adapter.h"
18 #include "cmsis_os2.h"
19 #include "hilink_sal_defines.h"
20 
21 #ifndef MS_PER_SECOND
22 #define MS_PER_SECOND   1000
23 #endif
24 #ifndef US_PER_MS
25 #define US_PER_MS       1000
26 #endif
27 
HILINK_GetOsTime(HiLinkTimeval * time)28 int HILINK_GetOsTime(HiLinkTimeval *time)
29 {
30     if (time == NULL) {
31         HILINK_SAL_WARN("invalid param\r\n");
32         return HILINK_SAL_PARAM_INVALID;
33     }
34 
35     if (osKernelGetTickFreq() == 0) {
36         HILINK_SAL_CRIT("invalid tick freq\r\n");
37         return HILINK_SAL_PARAM_INVALID;
38     }
39 
40     uint64_t ms = ((uint64_t)osKernelGetTickCount() * MS_PER_SECOND / osKernelGetTickFreq());
41     time->sec = ms / MS_PER_SECOND;
42     time->usec = ms % MS_PER_SECOND * US_PER_MS;
43 
44     return HILINK_SAL_OK;
45 }
46 
HILINK_GetUtcTime(HiLinkTimeval * time)47 int HILINK_GetUtcTime(HiLinkTimeval *time)
48 {
49     (void)time;
50     return HILINK_SAL_NOT_SUPPORT;
51 }