phydm_math_lib.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #ifndef __PHYDM_MATH_LIB_H__
  26. #define __PHYDM_MATH_LIB_H__
  27. #define AUTO_MATH_LIB_VERSION "1.0" /* @2017.06.06*/
  28. /*@
  29. * 1 ============================================================
  30. * 1 Definition
  31. * 1 ============================================================
  32. */
  33. #define DIVIDED_2(X) ((X) >> 1)
  34. /*@1/3 ~ 11/32*/
  35. #if defined(DM_ODM_CE_MAC80211)
  36. #define DIVIDED_3(X) ({ \
  37. u32 div_3_tmp = (X); \
  38. (((div_3_tmp) + ((div_3_tmp) << 1) + ((div_3_tmp) << 3)) >> 5); })
  39. #else
  40. #define DIVIDED_3(X) (((X) + ((X) << 1) + ((X) << 3)) >> 5)
  41. #endif
  42. #define DIVIDED_4(X) ((X) >> 2)
  43. /*Store Ori Value*/
  44. #if defined(DM_ODM_CE_MAC80211)
  45. #define WEIGHTING_AVG(v1, w1, v2, w2) \
  46. __WEIGHTING_AVG(v1, w1, v2, w2, typeof(v1), typeof(w1), typeof(v2), \
  47. typeof(w2))
  48. #define __WEIGHTING_AVG(v1, w1, v2, w2, t1, t2, t3, t4) ({ \
  49. t1 __w_a_v1 = (v1); \
  50. t2 __w_a_w1 = (w1); \
  51. t3 __w_a_v2 = (v2); \
  52. t4 __w_a_w2 = (w2); \
  53. ((__w_a_v1) * (__w_a_w1) + (__w_a_v2) * (__w_a_w2)) \
  54. / ((__w_a_w2) + (__w_a_w1)); })
  55. #else
  56. #define WEIGHTING_AVG(v1, w1, v2, w2) \
  57. (((v1) * (w1) + (v2) * (w2)) / ((w2) + (w1)))
  58. #endif
  59. /*Store 2^ma x Value*/
  60. #if defined(DM_ODM_CE_MAC80211)
  61. #define MA_ACC(old, new_val, ma) ({ \
  62. s16 __ma_acc_o = (old); \
  63. (__ma_acc_o) - ((__ma_acc_o) >> (ma)) + (new_val); })
  64. #define GET_MA_VAL(val, ma) ({ \
  65. s16 __get_ma_tmp = (ma);\
  66. ((val) + (1 << ((__get_ma_tmp) - 1))) >> (__get_ma_tmp); })
  67. #else
  68. #define MA_ACC(old, new_val, ma) ((old) - ((old) >> (ma)) + (new_val))
  69. #define GET_MA_VAL(val, ma) (((val) + (1 << ((ma) - 1))) >> (ma))
  70. #endif
  71. /*@
  72. * 1 ============================================================
  73. * 1 enumeration
  74. * 1 ============================================================
  75. */
  76. /*@
  77. * 1 ============================================================
  78. * 1 structure
  79. * 1 ============================================================
  80. */
  81. /*@
  82. * 1 ============================================================
  83. * 1 function prototype
  84. * 1 ============================================================
  85. */
  86. s32 odm_pwdb_conversion(s32 X, u32 total_bit, u32 decimal_bit);
  87. s32 odm_sign_conversion(s32 value, u32 total_bit);
  88. u16 phydm_find_intrvl(void *dm_void, u16 val, u16 *threshold, u16 th_len);
  89. void phydm_seq_sorting(void *dm_void, u32 *value, u32 *rank_idx, u32 *idx_out,
  90. u8 seq_length);
  91. u32 odm_convert_to_db(u32 value);
  92. u32 phydm_db_2_linear(u32 value);
  93. u16 phydm_show_fraction_num(u32 frac_val, u8 bit_num);
  94. u32 phydm_gen_bitmask(u8 mask_num);
  95. s32 phydm_cnvrt_2_sign(u32 val, u8 bit_num);
  96. #endif