1 /****************************************************************************** 2 * 3 * Copyright(c) 2007 - 2017 Realtek Corporation. 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of version 2 of the GNU General Public License as 7 * published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 * more details. 13 * 14 * The full GNU General Public License is included in this distribution in the 15 * file called LICENSE. 16 * 17 * Contact Information: 18 * wlanfae <wlanfae@realtek.com> 19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, 20 * Hsinchu 300, Taiwan. 21 * 22 * Larry Finger <Larry.Finger@lwfinger.net> 23 * 24 *****************************************************************************/ 25 26 #ifndef __PHYDM_MATH_LIB_H__ 27 #define __PHYDM_MATH_LIB_H__ 28 29 /* @2019.01.24 remove linear2db debug log*/ 30 #define AUTO_MATH_LIB_VERSION "1.2" 31 32 /*@ 33 * 1 ============================================================ 34 * 1 Definition 35 * 1 ============================================================ 36 */ 37 38 #define PHYDM_DIV(a, b) ((b) ? ((a) / (b)) : 0) 39 #define DIVIDED_2(X) ((X) >> 1) 40 /*@1/3 ~ 11/32*/ 41 #if defined(DM_ODM_CE_MAC80211) 42 #define DIVIDED_3(X) ({ \ 43 u32 div_3_tmp = (X); \ 44 (((div_3_tmp) + ((div_3_tmp) << 1) + ((div_3_tmp) << 3)) >> 5); }) 45 #else 46 #define DIVIDED_3(X) (((X) + ((X) << 1) + ((X) << 3)) >> 5) 47 #endif 48 #define DIVIDED_4(X) ((X) >> 2) 49 50 /*Store Ori Value*/ 51 #if defined(DM_ODM_CE_MAC80211) 52 #define WEIGHTING_AVG(v1, w1, v2, w2) \ 53 __WEIGHTING_AVG(v1, w1, v2, w2, typeof(v1), typeof(w1), typeof(v2), \ 54 typeof(w2)) 55 #define __WEIGHTING_AVG(v1, w1, v2, w2, t1, t2, t3, t4) ({ \ 56 t1 __w_a_v1 = (v1); \ 57 t2 __w_a_w1 = (w1); \ 58 t3 __w_a_v2 = (v2); \ 59 t4 __w_a_w2 = (w2); \ 60 ((__w_a_v1) * (__w_a_w1) + (__w_a_v2) * (__w_a_w2)) \ 61 / ((__w_a_w2) + (__w_a_w1)); }) 62 #else 63 #define WEIGHTING_AVG(v1, w1, v2, w2) \ 64 (((v1) * (w1) + (v2) * (w2)) / ((w2) + (w1))) 65 #endif 66 67 /*Store 2^ma x Value*/ 68 #if defined(DM_ODM_CE_MAC80211) 69 #define MA_ACC(old, new_val, ma) ({ \ 70 s16 __ma_acc_o = (old); \ 71 (__ma_acc_o) - ((__ma_acc_o) >> (ma)) + (new_val); }) 72 #define GET_MA_VAL(val, ma) ({ \ 73 s16 __get_ma_tmp = (ma);\ 74 ((val) + (1 << ((__get_ma_tmp) - 1))) >> (__get_ma_tmp); }) 75 #else 76 #define MA_ACC(old, new_val, ma) ((old) - ((old) >> (ma)) + (new_val)) 77 #define GET_MA_VAL(val, ma) (((val) + (1 << ((ma) - 1))) >> (ma)) 78 #endif 79 #define FRAC_BITS 3 80 /*@ 81 * 1 ============================================================ 82 * 1 enumeration 83 * 1 ============================================================ 84 */ 85 86 /*@ 87 * 1 ============================================================ 88 * 1 structure 89 * 1 ============================================================ 90 */ 91 92 /*@ 93 * 1 ============================================================ 94 * 1 function prototype 95 * 1 ============================================================ 96 */ 97 98 s32 odm_pwdb_conversion(s32 X, u32 total_bit, u32 decimal_bit); 99 100 s32 odm_sign_conversion(s32 value, u32 total_bit); 101 102 u16 phydm_find_intrvl(void *dm_void, u16 val, u16 *threshold, u16 th_len); 103 104 void phydm_seq_sorting(void *dm_void, u32 *value, u32 *rank_idx, u32 *idx_out, 105 u8 seq_length); 106 107 u32 odm_convert_to_db(u64 value); 108 109 u64 phydm_db_2_linear(u32 value); 110 111 u16 phydm_show_fraction_num(u32 frac_val, u8 bit_num); 112 113 u16 phydm_ones_num_in_bitmap(u64 val, u8 size); 114 115 u64 phydm_gen_bitmask(u8 mask_num); 116 117 s32 phydm_cnvrt_2_sign(u32 val, u8 bit_num); 118 119 s64 phydm_cnvrt_2_sign_64(u64 val, u8 bit_num); 120 #endif 121