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: oal util interface
15 * Author:
16 * Create: 2021-08-06
17 */
18 #ifndef __FRW_UTIL_H__
19 #define __FRW_UTIL_H__
20
21 #include "oal_plat_type.h"
22 #include "osal_adapt.h"
23 #include "securec.h"
24 #include "frw_util_common.h"
25
26 #undef osal_max
27 #define osal_max(a, b) (((a) > (b)) ? (a) : (b))
28
29 #undef osal_min
30 #define osal_min(a, b) (((a) < (b)) ? (a) : (b))
31
32 #define EXT_TIME_US_MAX_LEN_U64 (0xFFFFFFFFFFFFFFFF)
33
34 #define frw_debug(fmt, arg...) wifi_printf("[FRW] "fmt, ##arg)
35
osal_get_timeofday_us(osal_void)36 static INLINE__ osal_u64 osal_get_timeofday_us(osal_void)
37 {
38 osal_timeval tv;
39 osal_gettimeofday(&tv);
40 return (((osal_u64)tv.tv_sec) * 1000000 + tv.tv_usec);
41 }
42
43 /* 获取毫秒级时间戳 */
osal_get_time_stamp_ms(osal_void)44 static INLINE__ osal_u64 osal_get_time_stamp_ms(osal_void)
45 {
46 return (osal_get_timeofday_us() >> 10); /* 用1024换算ms */
47 }
48
49 /* 获取31.25微秒级时间戳 */
osal_get_time_stamp_ts(osal_void)50 static INLINE__ osal_u64 osal_get_time_stamp_ts(osal_void)
51 {
52 return osal_get_timeofday_us();
53 }
54
osal_get_runtime_u64(osal_u64 _start,osal_u64 _end)55 static INLINE__ osal_u64 osal_get_runtime_u64(osal_u64 _start, osal_u64 _end)
56 {
57 return ((_start > _end) ? (EXT_TIME_US_MAX_LEN_U64 - _start + _end + 1) : (_end - _start));
58 }
59
60 /* 需要osal层统一提供mb()函数 */
osal_bus_idle(void)61 static INLINE__ void osal_bus_idle(void)
62 {
63 #ifndef LOSCFG_PLATFORM_BSP_RISCV_PLIC
64 #ifndef BUILD_UT
65 __asm ("dsb\n");
66 #endif
67 #endif
68 }
69
osal_get_trng_bytes(osal_u8 * data,osal_u32 size)70 static INLINE__ osal_u32 osal_get_trng_bytes(osal_u8 *data, osal_u32 size)
71 {
72 osal_u32 ret = 0;
73 #if defined(_PRE_OS_VERSION) && defined(_PRE_OS_VERSION_LITEOS) && (_PRE_OS_VERSION == _PRE_OS_VERSION_LITEOS)
74 #if !defined(_PRE_WLAN_FEATURE_WS73) || defined(_PRE_LITEOS_SDK_) // 等待CFBB适配
75 // not implemented
76 #else
77 ret = uapi_drv_cipher_trng_get_random_bytes(data, size);
78 #endif
79 #endif
80 unref_param(data);
81 unref_param(size);
82 return ret;
83 }
84 #endif /* end of frw_util.h */