WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
载入中...
搜索中...
未找到
wlan_util_common_rom.h
浏览该文件的文档.
1/*
2 * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2020-2022. All rights reserved.
3 * Description: oam log printing interface
4 */
5
6#ifndef __WLAN_UTIL_COMMON_ROM_H__
7#define __WLAN_UTIL_COMMON_ROM_H__
8
9#include "securec.h"
10#include "td_type.h"
11
12#include "osal_types.h"
13
14#include "soc_osal.h"
16#ifdef __cplusplus
17#if __cplusplus
18extern "C" {
19#endif
20#endif
21
22#define OAL_RSSI_INIT_MARKER 0x320 /* RSSI平滑值初始值 */
23#define OAL_RSSI_MAX_DELTA 24 /* 最大步长 24/8 = 3 */
24#define OAL_RSSI_FRACTION_BITS 3
25#define OAL_RSSI_SIGNAL_MIN (-103) /* 上报RSSI下边界 */
26#define OAL_RSSI_SIGNAL_MAX 5 /* 上报RSSI上边界 */
27#define OAL_SNR_INIT_VALUE 0x7F /* SNR上报的初始值 */
28#define OAL_RSSI_INIT_VALUE (-128) /* RSSI的初始值 */
29
30/* 位数定义 */
31#define NUM_1_BITS 1
32#define NUM_2_BITS 2
33#define NUM_3_BITS 3
34#define NUM_4_BITS 4
35#define NUM_5_BITS 5
36#define NUM_8_BITS 8
37#define NUM_16_BITS 16
38#define NUM_20_BITS 20
39#define NUM_26_BITS 26
40
41
42/* 位偏移定义 */
43#define BIT_OFFSET_0 0
44#define BIT_OFFSET_1 1
45#define BIT_OFFSET_2 2
46#define BIT_OFFSET_4 4
47#define BIT_OFFSET_5 5
48#define BIT_OFFSET_6 6
49#define BIT_OFFSET_7 7
50#define BIT_OFFSET_8 8
51#define BIT_OFFSET_9 9
52#define BIT_OFFSET_10 10
53#define BIT_OFFSET_11 11
54#define BIT_OFFSET_12 12
55#define BIT_OFFSET_13 13
56#define BIT_OFFSET_14 14
57#define BIT_OFFSET_15 15
58#define BIT_OFFSET_16 16
59#define BIT_OFFSET_17 17
60#define BIT_OFFSET_18 18
61#define BIT_OFFSET_19 19
62#define BIT_OFFSET_20 20
63#define BIT_OFFSET_21 21
64#define BIT_OFFSET_24 24
65#define BIT_OFFSET_26 26
66
67#ifdef BUILD_UT
68#define OSAL_STATIC
69#else
70#define OSAL_STATIC static
71#endif
72
73#ifndef unref_param
74#define unref_param(P) ((P) = (P))
75#endif
76
77#ifndef unref_param_prv
78#define unref_param_prv(P) ((P) = (P))
79#endif
80
81/* 获取数组大小 */
82#define oal_array_size(_ast_array) (sizeof(_ast_array) / sizeof((_ast_array)[0]))
83
84#define OAL_BITS_PER_BYTE 8 /* 一个字节中包含的bit数目 */
85
86#define SWAP_BYTEORDER_MSAK_8 8
87#define SWAP_BYTEORDER_MSAK_24 24
88#define SWAP_BYTEORDER_MSAK_40 40
89#define SWAP_BYTEORDER_MSAK_56 56
90
91/* 大小端转换 */
92#define oal_swap_byteorder_16(value) ((((value) & 0xFF) << 8) + (((value) & 0xFF00) >> 8))
93
94#define oal_swap_byteorder_32(value) \
95 ((osal_u32)(((value) & 0x000000FF) << 24) + \
96 (osal_u32)(((value) & 0x0000FF00) << 8) + \
97 (osal_u32)(((value) & 0x00FF0000) >> 8) + \
98 (osal_u32)(((value) & 0xFF000000) >> 24))
99
100static INLINE__ osal_u64 oal_swap_byteorder_64(osal_u64 value)
101{
102 return ((((value) & 0x00000000000000ffULL) << SWAP_BYTEORDER_MSAK_56) +
103 (((value) & 0x000000000000ff00ULL) << SWAP_BYTEORDER_MSAK_40) +
104 (((value) & 0x0000000000ff0000ULL) << SWAP_BYTEORDER_MSAK_24) +
105 (((value) & 0x00000000ff000000ULL) << SWAP_BYTEORDER_MSAK_8) +
106 (((value) & 0x000000ff00000000ULL) >> SWAP_BYTEORDER_MSAK_8) +
107 (((value) & 0x0000ff0000000000ULL) >> SWAP_BYTEORDER_MSAK_24) +
108 (((value) & 0x00ff000000000000ULL) >> SWAP_BYTEORDER_MSAK_40) +
109 (((value) & 0xff00000000000000ULL) >> SWAP_BYTEORDER_MSAK_56));
110}
111
112/* 修改_PRE_BIG_CPU_ENDIAN保持HMAC&DMAC统一 */
113#if defined(_PRE_BIG_CPU_ENDIAN) && defined(_PRE_BIG_CPU_ENDIAN) && defined(_PRE_CPU_ENDIAN) \
114 && (_PRE_BIG_CPU_ENDIAN == _PRE_CPU_ENDIAN) /* BIG_ENDIAN */
115#define oal_byteorder_to_le32(_val) oal_swap_byteorder_32(_val)
116#define oal_byteorder_to_le16(_val) oal_swap_byteorder_16(_val)
117#define oal_mask_inverse(_len, _offset) ((osal_u32)(oal_swap_byteorder_32(~(((1 << (_len)) - 1) << (_offset)))))
118#define oal_mask(_len, _offset) ((osal_u32)(oal_swap_byteorder_32(((1 << (_len)) - 1) << (_offset))))
119#else /* LITTLE_ENDIAN */
120#define oal_byteorder_to_le32(_val) (_val)
121#define oal_byteorder_to_le16(_val) (_val)
122#define oal_mask_inverse(_len, _offset) ((osal_u32)(~(((1UL << (_len)) - 1) << (_offset))))
123#define oal_mask(_len, _offset) ((osal_u32)(((1UL << (_len)) - 1) << (_offset)))
124#endif
125
126/* 位操作 */
127#define oal_set_bit(_val) (1 << (_val))
128#define oal_left_shift(_data, _num) (osal_s64)((osal_u64)(_data) << (_num))
129#define oal_rght_shift(_data, _num) ((_data) >> (_num))
130#define oal_get_bits(_data, _bits, _pos) (((_data) >> (_pos)) & (((osal_u32)1 << (_bits)) - 1))
131
132/* ****************************************************************************
133 函 数 名 : oal_sub
134 功能描述 : 求两数之差,限定差值大于0
135**************************************************************************** */
136static INLINE__ osal_u8 oal_sub(osal_u16 a, osal_u16 b)
137{
138 return (a > b) ? (a - b) : 0;
139}
140
141/* ****************************************************************************
142 函 数 名 : oal_make_word16
143 功能描述 : 将两个8bit数拼接为16bit数
144**************************************************************************** */
145static INLINE__ osal_u16 oal_make_word16(osal_u8 lsb, osal_u8 msb)
146{
147 return ((((osal_u16)msb << 8) & 0xFF00) | lsb); /* msb 左移 8位 */
148}
149
150/* ****************************************************************************
151 函 数 名 : oal_make_word32
152 功能描述 : 将两个16bit数拼接为32bit数
153**************************************************************************** */
154static INLINE__ osal_u32 oal_make_word32(osal_u16 lsw, osal_u16 msw)
155{
156 return ((((osal_u32)msw << 16) & 0xFFFF0000) | lsw); /* msw 左移 16位 */
157}
158
159/* ****************************************************************************
160 函 数 名 : oal_join_word32
161 功能描述 : 将四个8bit数拼接为32bit数
162**************************************************************************** */
163static INLINE__ osal_u32 oal_join_word32(osal_u8 lsb, osal_u8 ssb, osal_u8 asb, osal_u8 msb)
164{
165 return (((osal_u32)msb << 24) | ((osal_u32)asb << 16) | ((osal_u32)ssb << 8) | lsb); /* 分别左移24 16 8 位 */
166}
167
168/* ****************************************************************************
169 函 数 名 : oal_absolute_sub
170 功能描述 : 返回两数之差的绝对值
171**************************************************************************** */
172static INLINE__ osal_u32 oal_absolute_sub(osal_u32 num_a, osal_u32 num_b)
173{
174 return ((num_a > num_b) ? (num_a - num_b) : (num_b - num_a));
175}
176
177/* ****************************************************************************
178 函 数 名 : round_pos
179 功能描述 : 定点数四舍五入,并取整数部分, fract_bits为小数位数
180**************************************************************************** */
181static INLINE__ osal_s32 round_pos(osal_s32 fix_num, osal_s32 fract_bits)
182{
183 return ((fix_num + (1 << (fract_bits - 1))) >> fract_bits);
184}
185
186/* ****************************************************************************
187 函 数 名 : round_neg
188 功能描述 : 定点数四舍五入,并取整数部分, fract_bits为小数位数
189**************************************************************************** */
190static INLINE__ osal_s32 round_neg(osal_s32 fix_num, osal_s32 fract_bits)
191{
192 return (osal_s32)(0 - round_pos(0 - fix_num, fract_bits));
193}
194
195/* ****************************************************************************
196 函 数 名 : oal_round
197 功能描述 : 定点数四舍五入,并取整数部分, fract_bits为小数位数
198**************************************************************************** */
199static INLINE__ osal_s32 oal_round(osal_s32 fix_num, osal_s32 fract_bits)
200{
201 return (fix_num > 0 ? round_pos(fix_num, fract_bits) : round_neg(fix_num, fract_bits));
202}
203
204static INLINE__ osal_s32 oal_pow(osal_s32 x, osal_u32 n)
205{
206 osal_s32 result = 1, pow_x = x;
207 osal_u32 pow_n = n;
208 while (pow_n != 0) {
209 if ((pow_n & 0x1) != 0) {
210 result *= pow_x;
211 }
212 pow_n >>= 1;
213 pow_x *= pow_x;
214 }
215 return result;
216}
217
218/* ****************************************************************************
219 函 数 名 : oal_bit_get_num_four_byte
220 功能描述 : 获取4字节中bit1的个数
221**************************************************************************** */
222static INLINE__ osal_u32 oal_bit_get_num_four_byte(osal_u32 byte)
223{
224 osal_u32 byte_data = byte;
225
226 byte_data = (byte_data & 0x55555555) + ((byte_data >> 1) & 0x55555555); /* 0x55555555掩码, 1移位数 */
227 byte_data = (byte_data & 0x33333333) + ((byte_data >> 2) & 0x33333333); /* 0x33333333掩码, 2移位数 */
228 byte_data = (byte_data & 0x0F0F0F0F) + ((byte_data >> 4) & 0x0F0F0F0F); /* 0x0F0F0F0F掩码, 4移位数 */
229 byte_data = (byte_data & 0x00FF00FF) + ((byte_data >> 8) & 0x00FF00FF); /* 0x00FF00FF掩码, 8移位数 */
230 byte_data = (byte_data & 0x0000FFFF) + ((byte_data >> 16) & 0x0000FFFF); /* 0x0000FFFF掩码, 16移位数 */
231
232 return byte_data;
233}
234
235/* ****************************************************************************
236 函 数 名 : oal_bit_set_bit_one_byte
237 功能描述 : 对1字节的指定位置一
238**************************************************************************** */
239static INLINE__ osal_void oal_bit_set_bit_one_byte(osal_u8 *byte, osal_u32 nr)
240{
241 *byte |= ((osal_u8)(1 << nr));
242}
243
244/* ****************************************************************************
245 函 数 名 : oal_bit_clear_bit_one_byte
246 功能描述 : 对1字节的指定位置零
247**************************************************************************** */
248static INLINE__ osal_void oal_bit_clear_bit_one_byte(osal_u8 *byte, osal_u32 nr)
249{
250 *byte &= (~((osal_u8)(1 << nr)));
251}
252
253static INLINE__ osal_u8 oal_bit_get_bit_one_byte(osal_u8 byte, osal_u32 nr)
254{
255 return ((byte >> nr) & 0x1);
256}
257
258/* ****************************************************************************
259 函 数 名 : oal_bit_set_bit_eight_byte
260 功能描述 : 对8字节的指定位置一
261**************************************************************************** */
262static INLINE__ osal_void oal_bit_set_bit_eight_byte(osal_u64 *pull_byte, osal_u32 nr)
263{
264 *pull_byte |= ((osal_u64)1 << nr);
265}
266
267/* ****************************************************************************
268 函 数 名 : oal_bit_find_first_bit_one_byte
269 功能描述 : 找到1字节右数第一个是1的位数
270**************************************************************************** */
271static INLINE__ osal_u8 oal_bit_find_first_bit_one_byte(osal_u8 byte)
272{
273 osal_u8 ret = 0, byte_data = byte;
274
275 byte_data = byte_data & (-byte_data);
276
277 while (byte_data != 1) {
278 ret++;
279 byte_data = (byte_data >> 1);
280
281 if (ret > 7) { /* 7表示超过字节最大bit数。退出循环 */
282 return ret;
283 }
284 }
285
286 return ret;
287}
288
289/*****************************************************************************
290 函 数 名 : oal_set_mac_addr
291 功能描述 : 将第二个mac地址 赋值给第一个mac地址
292**************************************************************************** */
293static INLINE__ osal_void oal_set_mac_addr(osal_u8 *addr1, const osal_u8 *addr2)
294{
295 const osal_u32 mac_len = 6; /* 6字节mac地址长度 */
296 (osal_void)memcpy_s(addr1, mac_len, addr2, mac_len);
297}
298
299/*****************************************************************************
300 函 数 名 : oal_compare_mac_addr
301 功能描述 : 比较两个mac地址是否相等
302**************************************************************************** */
303static INLINE__ osal_u32 oal_compare_mac_addr(const osal_u8 *mac_addr1, const osal_u8 *mac_addr2)
304{
305 const osal_u32 mac_len = 6; /* 6字节mac地址长度 */
306 return (osal_u32)(memcmp(mac_addr1, mac_addr2, mac_len));
307}
308
309/* ****************************************************************************
310 函 数 名 : oal_byteorder_host_to_net_uint16
311 功能描述 : 将16位本地字节序转换为网络字节序
312**************************************************************************** */
313static INLINE__ osal_u16 oal_byteorder_host_to_net_uint16(osal_u16 byte)
314{
315 osal_u16 byte_data = byte;
316 byte_data = ((byte_data & 0x00FF) << 8) + ((byte_data & 0xFF00) >> 8); /* 0x00FF,0xFF00高低字节掩码,8高低字节移位 */
317 return byte_data;
318}
319
320/* ****************************************************************************
321 函 数 名 : oal_del_lut_index
322 功能描述 : 在LUT index bitmap表中,删除一个LUT index (注:%可以作为优化项)
323**************************************************************************** */
324static INLINE__ osal_void oal_del_lut_index(osal_u8 *lut_index_table, osal_u8 idx)
325{
326 osal_u8 byte = idx / NUM_8_BITS;
327 osal_u8 bit = idx % NUM_8_BITS;
328
329 lut_index_table[byte] &= ~(osal_u8)(1 << bit); /* 1bit移位 */
330}
331
332static INLINE__ osal_s32 oal_memcmp(const osal_void *buf1, const osal_void *buf2, osal_u32 count)
333{
334 return memcmp(buf1, buf2, count);
335}
336
338osal_u8 oal_get_lut_index(osal_u8 *lut_index_table, osal_u8 bmap_len, osal_u16 max_lut_size,
339 osal_u16 start, osal_u16 stop);
340
341/* rssi平滑函数改为非内联函数,内联版本仅保证rom编译通过 */
344
345#ifdef __cplusplus
346#if __cplusplus
347}
348#endif
349#endif
350
351#endif /* end of wlan_util_common.h */
#define bit(x)
Definition common_def.h:71
#define INLINE__
Definition osal_list.h:25
int osal_s32
Definition osal_types.h:19
unsigned char osal_u8
Definition osal_types.h:11
signed char osal_s8
Definition osal_types.h:17
unsigned long long osal_u64
Definition osal_types.h:14
short osal_s16
Definition osal_types.h:18
void osal_void
Definition osal_types.h:29
unsigned int osal_u32
Definition osal_types.h:13
unsigned short osal_u16
Definition osal_types.h:12
errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count)
osal_void oal_rssi_smooth(osal_s16 *old_rssi, osal_s8 new_rssi)
osal_s8 oal_get_real_rssi(osal_s16 s_scaled_rssi)
osal_u8 oal_get_lut_index(osal_u8 *lut_index_table, osal_u8 bmap_len, osal_u16 max_lut_size, osal_u16 start, osal_u16 stop)
#define NUM_8_BITS
Definition wlan_util_common_rom.h:36
#define SWAP_BYTEORDER_MSAK_8
Definition wlan_util_common_rom.h:86
#define SWAP_BYTEORDER_MSAK_40
Definition wlan_util_common_rom.h:88
#define SWAP_BYTEORDER_MSAK_24
Definition wlan_util_common_rom.h:87
#define SWAP_BYTEORDER_MSAK_56
Definition wlan_util_common_rom.h:89
osal_u8 oal_bit_find_first_bit_four_byte(osal_u32 byte)