1 /*
2 * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 /* ****************************************************************************
20 1 头文件包含
21 **************************************************************************** */
22 #include "hmac_cali_dpd.h"
23 #include "oam_ext_if.h"
24
25 #ifdef __cplusplus
26 #if __cplusplus
27 extern "C" {
28 #endif
29 #endif
30
31 /* ****************************************************************************
32 2 函数声明
33 **************************************************************************** */
34 #define get2comp(a) (((a) >= 1024) ? ((a) - 2048) : (a))
35 #define set2comp(a) (((a) >= 0) ? (a) : (2048 + (a)))
36
37 hi_s64 g_ll_mk1_32[3][128] = {
38 /* 3 128 元素个数 */
39 {
40 297, 869, 1414, 1931, 2423, 2888, 3328, 3742, 4132, 4498, 4840, 5158,\
41 5454, 5727, 5979, 6209, 6418, 6607, 6775, 6924, 7054, 7165, 7258, 7333,\
42 7391, 7432, 7457, 7466, 7459, 7437, 7401, 7351, 7287, 7210, 7121, 7019,\
43 6906, 6781, 6645, 6499, 6343, 6178, 6004, 5821, 5630, 5431, 5226, 5014,\
44 4795, 4571, 4341, 4107, 3868, 3626, 3380, 3131, 2879, 2626, 2370, 2114,\
45 1857, 1600, 1343, 1087, 832, 578, 327, 78, -167, -410, -648, -882, -1111,\
46 -1334, -1552, -1764, -1969, -2166, -2357, -2539, -2712, -2876, -3031, -3176,\
47 -3311, -3434, -3547, -3647, -3736, -3811, -3874, -3922, -3957, -3977, -3982,\
48 -3972, -3946, -3903, -3843, -3766, -3671, -3558, -3427, -3276, -3105, -2915,\
49 -2703, -2471, -2217, -1942, -1644, -1323, -978, -610, -218, 199, 641, 1109,\
50 1603, 2124, 2671, 3246, 3849, 4481, 5141, 5830, 6550, 7300,
51 },
52 {
53 -889, -2600, -4224, -5761, -7214, -8584, -9872, -11080, -12209, -13262, -14239,\
54 -15142, -15973, -16733, -17424, -18047, -18605, -19097, -19526, -19894, -20202,\
55 -20451, -20643, -20780, -20863, -20894, -20873, -20804, -20687, -20524, -20316,\
56 -20065, -19772, -19440, -19068, -18660, -18217, -17740, -17230, -16690, -16120,\
57 -15523, -14899, -14251, -13579, -12887, -12174, -11442, -10694, -9930, -9153,\
58 -8363, -7562, -6752, -5935, -5111, -4282, -3451, -2618, -1785, -953, -124,\
59 699, 1517, 2327, 3128, 3918, 4696, 5460, 6209, 6941, 7654, 8347, 9019,\
60 9668, 10292, 10890, 11461, 12002, 12512, 12990, 13434, 13843, 14215, 14549,\
61 14842, 15094, 15303, 15468, 15586, 15656, 15678, 15648, 15566, 15431, 15240,\
62 14992, 14686, 14319, 13891, 13400, 12845, 12223, 11534, 10775, 9946, 9045,\
63 8069, 7018, 5891, 4684, 3398, 2030, 580, -956, -2577, -4286, -6085, -7974,\
64 -9956, -12031, -14202, -16469, -18835, -21301, -23869, -26540, -29315,
65 },
66 {
67 622, 1817, 2949, 4017, 5025, 5971, 6859, 7688, 8460, 9176, 9838, 10446,\
68 11002, 11506, 11961, 12366, 12724, 13035, 13301, 13522, 13701, 13837, 13932,\
69 13988, 14005, 13985, 13929, 13837, 13712, 13554, 13364, 13144, 12895, 12617,\
70 12312, 11982, 11627, 11248, 10847, 10425, 9983, 9522, 9043, 8547, 8036, 7511,\
71 6973, 6422, 5861, 5290, 4710, 4124, 3531, 2933, 2331, 1726, 1119, 513,\
72 -94, -698, -1299, -1896, -2488, -3073, -3651, -4219, -4778, -5326, -5862,\
73 -6384, -6891, -7383, -7858, -8315, -8753, -9171, -9567, -9940, -10290, -10614,\
74 -10913, -11184, -11427, -11640, -11823, -11974, -12092, -12175, -12223, -12235,\
75 -12209, -12145, -12040, -11894, -11706, -11475, -11199, -10877, -10509, -10092,\
76 -9627, -9111, -8543, -7923, -7249, -6520, -5735, -4893, -3992, -3032, -2011,\
77 -928, 218, 1428, 2703, 4045, 5454, 6933, 8481, 10100, 11792, 13557, 15396,\
78 17312, 19304, 21374, 23523, 25753,
79 },
80 };
81
82 hi1131_complex_stru g_ll_pa_val[128] = {
83 /* 128 元素个数 */
84 {1, 0},
85 {5, -1},
86 {8, -3},
87 {12, -4},
88 {15, -5},
89 {18, -6},
90 {22, -7},
91 {26, -8},
92 {29, -9},
93 {33, -11},
94 {36, -12},
95 {40, -13},
96 {43, -14},
97 {46, -15},
98 {50, -16},
99 {53, -18},
100 {57, -19},
101 {60, -20},
102 {64, -21},
103 {67, -22},
104 {71, -24},
105 {74, -25},
106 {77, -26},
107 {81, -27},
108 {84, -28},
109 {88, -29},
110 {91, -31},
111 {94, -32},
112 {98, -33},
113 {101, -34},
114 {105, -35},
115 {108, -37},
116 {111, -38},
117 {115, -39},
118 {118, -40},
119 {121, -42},
120 {124, -43},
121 {128, -44},
122 {131, -45},
123 {135, -46},
124 {138, -47},
125 {141, -49},
126 {144, -50},
127 {147, -51},
128 {151, -52},
129 {154, -53},
130 {157, -55},
131 {160, -56},
132 {164, -57},
133 {167, -58},
134 {170, -59},
135 {173, -60},
136 {176, -61},
137 {180, -63},
138 {183, -64},
139 {187, -65},
140 {190, -66},
141 {193, -67},
142 {196, -68},
143 {200, -69},
144 {203, -70},
145 {206, -71},
146 {210, -72},
147 {213, -73},
148 {216, -75},
149 {220, -75},
150 {223, -76},
151 {227, -78},
152 {230, -79},
153 {234, -80},
154 {238, -81},
155 {241, -82},
156 {245, -83},
157 {248, -84},
158 {251, -85},
159 {255, -86},
160 {259, -87},
161 {262, -89},
162 {266, -90},
163 {270, -91},
164 {273, -92},
165 {277, -93},
166 {281, -94},
167 {284, -96},
168 {288, -97},
169 {292, -98},
170 {296, -100},
171 {300, -101},
172 {304, -102},
173 {307, -103},
174 {311, -104},
175 {316, -105},
176 {319, -107},
177 {323, -108},
178 {327, -109},
179 {331, -111},
180 {335, -112},
181 {339, -114},
182 {343, -115},
183 {347, -116},
184 {351, -118},
185 {355, -119},
186 {359, -121},
187 {363, -122},
188 {367, -123},
189 {371, -125},
190 {375, -126},
191 {380, -128},
192 {384, -129},
193 {388, -131},
194 {392, -132},
195 {396, -134},
196 {400, -135},
197 {404, -137},
198 {409, -138},
199 {413, -140},
200 {417, -142},
201 {421, -143},
202 {425, -144},
203 {429, -146},
204 {433, -148},
205 {437, -149},
206 {441, -151},
207 {445, -153},
208 {449, -154},
209 {453, -156},
210 {457, -157},
211 {460, -159},
212 };
213
214 hi_u16 g_us_max_pos = 128;
215 hi_u32 g_dpd_data[128]; /* dpd calibration data 128: 元素个数 */
216
217 /* ****************************************************************************
218 函 数 名 : hi1131_cali_get_phase
219 功能描述 : 两整数相除结果四舍五入
220 输入参数 : 无
221 输出参数 : 无
222 返 回 值 :
223 调用函数 :
224 被调函数 :
225
226 修改历史 :
227 1.日 期 : 2014年12月16日
228 作 者 : HiSilicon
229 修改内容 : 新生成函数
230
231 **************************************************************************** */
hmac_cali_div_round_closest(hi_s64 ll_a,hi_s64 ll_b)232 hi_s64 hmac_cali_div_round_closest(hi_s64 ll_a, hi_s64 ll_b)
233 {
234 hi_s64 ll_result = 0;
235 if ((ll_b == 0) || ((ll_b << 1) == 0)) {
236 ll_result = (hi_s64)ll_a;
237 } else {
238 if (((ll_a >= 0) && (ll_b > 0)) || ((ll_a <= 0) && (ll_b < 0))) {
239 ll_result = (hi_s64)(((ll_a << 1) + ll_b) / (ll_b << 1));
240 } else {
241 ll_result = (hi_s64)(((ll_a << 1) - ll_b) / (ll_b << 1));
242 }
243 }
244
245 return ll_result;
246 }
247
248 /* ****************************************************************************
249 函 数 名 : hi1131_cali_get_phase
250 功能描述 : 复数除以整数结果四舍五入
251 输入参数 : 无
252 输出参数 : 无
253 返 回 值 :
254 调用函数 :
255 被调函数 :
256
257 修改历史 :
258 1.日 期 : 2014年12月16日
259 作 者 : HiSilicon
260 修改内容 : 新生成函数
261
262 **************************************************************************** */
complex_div_round_closest(hi1131_complex_stru a,hi_s64 ll_b)263 hi1131_complex_stru complex_div_round_closest(hi1131_complex_stru a, hi_s64 ll_b)
264 {
265 hi1131_complex_stru result;
266
267 result.ll_real = hmac_cali_div_round_closest(a.ll_real, ll_b);
268 result.ll_imag = hmac_cali_div_round_closest(a.ll_imag, ll_b);
269
270 return result;
271 }
272
273 /* ****************************************************************************
274 函 数 名 : dpd_cordic
275 功能描述 : DPD Calibration Data Cordic
276 输入参数 : 无
277 输出参数 : 无
278 返 回 值 :
279 调用函数 :
280 被调函数 :
281
282 修改历史 :
283 1.日 期 : 2014年12月31日
284 作 者 : HiSilicon
285 修改内容 : 新生成函数
286
287 **************************************************************************** */
hmac_dpd_cordic(hi_s64 ll_real,hi_s64 ll_image,hi_s64 * pll_amp,hi_s64 * pll_theta1,hi_s64 * pll_theta2)288 hi_void hmac_dpd_cordic(hi_s64 ll_real, hi_s64 ll_image, hi_s64 *pll_amp, hi_s64 *pll_theta1, hi_s64 *pll_theta2)
289 {
290 hi_u8 us_idx = 0;
291 hi_s64 ll_x[13] = {0}; /* 13 元素个数 */
292 hi_s64 ll_y[13] = {0}; /* 13 元素个数 */
293 hi_s64 ll_flag;
294
295 hi_s64 ll_real_table[13] = {1447, 1891, 2008, 2037, 2045, 2046, 2047, 2047, 2047, 2047, 2047, 2047, 2047}; /* 13 */
296 hi_s64 ll_imag_table[13] = {1447, 783, 399, 201, 100, 50, 25, 13, 6, 3, 2, 1, 0}; /* 元素个数为13 */
297
298 hi_s64 ll_theta1 = 2047;
299 hi_s64 ll_theta2 = 0;
300 hi_s64 ll_temp1 = 0;
301 hi_s64 ll_temp2 = 0; /* real and image */
302 hi_s64 ll_thetatmp1;
303 hi_s64 ll_thetatmp2; /* real and image */
304 hi_s64 ll_divider = 2048;
305
306 ll_x[0] = oal_abs(ll_real);
307 ll_y[0] = oal_abs(ll_image);
308 ll_flag = oal_abs(ll_image);
309
310 for (us_idx = 0; us_idx < 10; us_idx++) { /* 循环次数为10 */
311 if (ll_flag > 0) {
312 ll_temp1 = ll_real_table[us_idx];
313 ll_temp2 = -ll_imag_table[us_idx];
314 } else if (ll_flag < 0) {
315 ll_temp1 = ll_real_table[us_idx];
316 ll_temp2 = ll_imag_table[us_idx];
317 } else { /* y = 0 */
318 break;
319 }
320
321 ll_x[us_idx + 1] = hmac_cali_div_round_closest((ll_x[us_idx] * ll_temp1 - ll_y[us_idx] * ll_temp2), ll_divider);
322 ll_y[us_idx + 1] = hmac_cali_div_round_closest((ll_y[us_idx] * ll_temp1 + ll_x[us_idx] * ll_temp2), ll_divider);
323
324 ll_thetatmp1 = hmac_cali_div_round_closest((ll_theta1 * ll_temp1 - ll_theta2 * ll_temp2), ll_divider);
325 ll_thetatmp2 = hmac_cali_div_round_closest((ll_theta2 * ll_temp1 + ll_theta1 * ll_temp2), ll_divider);
326 ll_theta1 = ll_thetatmp1;
327 ll_theta2 = ll_thetatmp2;
328
329 ll_flag = ll_y[us_idx + 1];
330 }
331
332 if (ll_real < 0) {
333 ll_theta1 = -ll_theta1;
334 }
335 if (ll_image < 0) {
336 ll_theta2 = -ll_theta2;
337 }
338
339 *pll_amp = (hi_u32)ll_x[us_idx];
340 *pll_theta1 = (hi_s32)ll_theta1;
341 *pll_theta2 = (hi_s32)ll_theta2;
342 }
343
344 /* ****************************************************************************
345 功能描述 : 对复数求共轭
346 输入参数 : 无
347 输出参数 : 无
348 返 回 值 :
349 调用函数 :
350 被调函数 :
351
352 修改历史 :
353 1.日 期 : 2014年12月18日
354 作 者 : HiSilicon
355 修改内容 : 新生成函数
356
357 **************************************************************************** */
hmac_dpd_cali_conj(hi1131_complex_stru a)358 hi1131_complex_stru hmac_dpd_cali_conj(hi1131_complex_stru a)
359 {
360 a.ll_imag = -a.ll_imag;
361
362 return a;
363 }
364
365 /* ****************************************************************************
366 函 数 名 : hmac_dpd_complex_add
367 功能描述 : 复数相乘
368 输入参数 : 无
369 输出参数 : 无
370 返 回 值 :
371 调用函数 :
372 被调函数 :
373
374 修改历史 :
375 1.日 期 : 2014年12月18日
376 作 者 : HiSilicon
377 修改内容 : 新生成函数
378
379 **************************************************************************** */
hmac_dpd_complex_add(hi1131_complex_stru a,hi1131_complex_stru b)380 hi1131_complex_stru hmac_dpd_complex_add(hi1131_complex_stru a, hi1131_complex_stru b)
381 {
382 hi1131_complex_stru return_code;
383
384 return_code.ll_real = (hi_s64)(a.ll_real + b.ll_real);
385 return_code.ll_imag = (hi_s64)(a.ll_imag + b.ll_imag);
386
387 return return_code;
388 }
389
390 /* ****************************************************************************
391 函 数 名 : hmac_dpd_complex_multiply_const
392 功能描述 : 复数相乘
393 输入参数 : 无
394 输出参数 : 无
395 返 回 值 :
396 调用函数 :
397 被调函数 :
398
399 修改历史 :
400 1.日 期 : 2014年12月18日
401 作 者 : HiSilicon
402 修改内容 : 新生成函数
403
404 **************************************************************************** */
hmac_dpd_complex_multiply_const(hi1131_complex_stru a,hi_s64 ll_b)405 hi1131_complex_stru hmac_dpd_complex_multiply_const(hi1131_complex_stru a, hi_s64 ll_b)
406 {
407 hi1131_complex_stru return_code;
408
409 return_code.ll_real = (hi_s64)(a.ll_real * ll_b);
410 return_code.ll_imag = (hi_s64)(a.ll_imag * ll_b);
411
412 return return_code;
413 }
414
415 /* ****************************************************************************
416 函 数 名 : hi1131_cali_complex_multiply
417 功能描述 : 复数相乘
418 输入参数 : 无
419 输出参数 : 无
420 返 回 值 :
421 调用函数 :
422 被调函数 :
423
424 修改历史 :
425 1.日 期 : 2014年12月18日
426 作 者 : HiSilicon
427 修改内容 : 新生成函数
428
429 **************************************************************************** */
hmac_dpd_complex_multiply(hi1131_complex_stru a,hi1131_complex_stru b)430 hi1131_complex_stru hmac_dpd_complex_multiply(hi1131_complex_stru a, hi1131_complex_stru b)
431 {
432 hi1131_complex_stru return_code;
433
434 return_code.ll_real = (hi_s64)((hi_s64)(a.ll_real) * (hi_s64)(b.ll_real) -
435 (hi_s64)(a.ll_imag) * (hi_s64)(b.ll_imag));
436 return_code.ll_imag = (hi_s64)((hi_s64)(a.ll_real) * (hi_s64)(b.ll_imag) +
437 (hi_s64)(a.ll_imag) * (hi_s64)(b.ll_real));
438
439 return return_code;
440 }
441
442 /* ****************************************************************************
443 函 数 名 : hi1131_cali_complex_div
444 功能描述 : 复数除法
445 输入参数 : 无
446 输出参数 : 无
447 返 回 值 :
448 调用函数 :
449 被调函数 :
450
451 修改历史 :
452 1.日 期 : 2016年3月24日
453 作 者 : HiSilicon
454 修改内容 : 新生成函数
455
456 **************************************************************************** */
hmac_dpd_complex_div(hi1131_complex_stru complex_num,hi1131_complex_stru complex_denom)457 hi1131_complex_stru hmac_dpd_complex_div(hi1131_complex_stru complex_num, hi1131_complex_stru complex_denom)
458 {
459 hi1131_complex_stru mul_res;
460 hi1131_complex_stru conj_res;
461 hi_s64 ll_power;
462 hi_s64 ll_real;
463 hi_s64 ll_imag;
464 hi_s64 ll_temp;
465
466 /* 除数取共轭 */
467 conj_res = hmac_dpd_cali_conj(complex_denom);
468
469 /* 复数乘法 被除数*conj(除数) */
470 mul_res = hmac_dpd_complex_multiply(complex_num, conj_res);
471
472 /* 计算Power */
473 ll_real = complex_denom.ll_real;
474 ll_imag = complex_denom.ll_imag;
475 ll_power = ll_real * ll_real + ll_imag * ll_imag;
476
477 /* 如果分母为0,则上报错误 */
478 if (ll_power == 0) {
479 oam_warning_log0(0, OAM_SF_CALIBRATE, "hi1131_cali_complex_div: l_power is zero!\n");
480 return mul_res;
481 } else {
482 /* 实部 四舍五入 */
483 ll_temp = (((mul_res.ll_real) % ll_power) << 1);
484 mul_res.ll_real = ((mul_res.ll_real) / ll_power);
485 if (ll_power < oal_abs(ll_temp)) {
486 if (ll_temp > 0) {
487 mul_res.ll_real = mul_res.ll_real + 1;
488 } else {
489 mul_res.ll_real = mul_res.ll_real - 1;
490 }
491 }
492 /* 虚部 四舍五入 */
493 ll_temp = (((mul_res.ll_imag) % ll_power) << 1);
494 mul_res.ll_imag = ((mul_res.ll_imag) / ll_power);
495 if (ll_power < oal_abs(ll_temp)) {
496 if (ll_temp > 0) {
497 mul_res.ll_imag = mul_res.ll_imag + 1;
498 } else {
499 mul_res.ll_imag = mul_res.ll_imag - 1;
500 }
501 }
502 }
503
504 /* 返回结果 */
505 return mul_res;
506 }
507
508 /* ****************************************************************************
509 函 数 名 : hmac_dpd_complex_div_const
510 功能描述 : 复数除以整数
511 输入参数 : 无
512 输出参数 : 无
513 返 回 值 :
514 调用函数 :
515 被调函数 :
516
517 修改历史 :
518 1.日 期 : 2014年12月18日
519 作 者 : HiSilicon
520 修改内容 : 新生成函数
521
522 **************************************************************************** */
hmac_dpd_complex_div_const(hi1131_complex_stru a,hi_s64 ll_b)523 hi1131_complex_stru hmac_dpd_complex_div_const(hi1131_complex_stru a, hi_s64 ll_b)
524 {
525 hi1131_complex_stru return_code;
526
527 return_code.ll_real = (hi_s64)(a.ll_real >> ll_b);
528 return_code.ll_imag = (hi_s64)(a.ll_imag >> ll_b);
529
530 return return_code;
531 }
532
533 /* ****************************************************************************
534 函 数 名 : hmac_dpd_complex_div_const
535 功能描述 : 复数相乘
536 输入参数 : 无
537 输出参数 : 无
538 返 回 值 :
539 调用函数 :
540 被调函数 :
541
542 修改历史 :
543 1.日 期 : 2014年12月18日
544 作 者 : HiSilicon
545 修改内容 : 新生成函数
546
547 **************************************************************************** */
hmac_dpd_complex_pow(hi1131_complex_stru a)548 inline hi_s64 hmac_dpd_complex_pow(hi1131_complex_stru a)
549 {
550 return (hi_s64)((hi_s64)(a.ll_real) * (hi_s64)(a.ll_real) + (hi_s64)(a.ll_imag) * (hi_s64)(a.ll_imag));
551 }
552
hmac_init_ll_pa_val(const hi_u32 * hi1131_dpd_cali_data_read)553 hi_void hmac_init_ll_pa_val(const hi_u32 *hi1131_dpd_cali_data_read)
554 {
555 hi_u16 us_idx;
556 hi_s32 l_real, l_imag;
557
558 for (us_idx = 0; us_idx < DPD_CALI_LUT_LENGTH; us_idx++) {
559 l_real = get2comp((((hi_u32)(*(hi1131_dpd_cali_data_read + us_idx))) & 0x7ff));
560 l_imag = get2comp(((((hi_u32)(*(hi1131_dpd_cali_data_read + us_idx))) >> 11) & 0x7ff));
561
562 oam_warning_log2(0, OAM_SF_CALIBRATE, "{hi1131_dpd_cali_data_read:: l_real = %d, l_imag = %d}", l_real, l_imag);
563
564 g_ll_pa_val[us_idx].ll_real = (hi_s64)l_real;
565 g_ll_pa_val[us_idx].ll_imag = (hi_s64)l_imag;
566 }
567 }
568
hmac_init_dpd_sum(hi1131_complex_stru * sum,hi_u16 us_j)569 static inline hi_void hmac_init_dpd_sum(hi1131_complex_stru *sum, hi_u16 us_j)
570 {
571 hi_u16 us_idx;
572
573 sum->ll_real = 0;
574 sum->ll_imag = 0;
575 for (us_idx = 0; us_idx < DPD_CALI_LUT_LENGTH ; us_idx++) {
576 *sum = hmac_dpd_complex_add(*sum, hmac_dpd_complex_multiply_const(g_ll_pa_val[us_idx],
577 g_ll_mk1_32[us_j][us_idx]));
578 }
579 }
580
581 /* 规则5.1 避免函数过长,函数不超过50行(非空非注释),申请例外: 算法函数,功能内聚,建议屏蔽 */
hmac_rf_cali_dpd_corr_calc(const hi_u32 * hi1131_dpd_cali_data_read,hi_u32 * hi1131_dpd_cali_data_calc)582 hi_u32 hmac_rf_cali_dpd_corr_calc(const hi_u32 *hi1131_dpd_cali_data_read, hi_u32 *hi1131_dpd_cali_data_calc)
583 {
584 hi_u16 us_idx, us_j;
585 hi_s64 ll_amp = 0;
586 hi1131_complex_stru vv1_32, vv0_32, xll_32, yll_32, dpd_lut_fixed, tmp1, tmp2, y_opt_32, sum;
587 hi1131_complex_stru ak_16[3]; /* 3:元素个数 */
588 hi_u32 vo_fixed;
589 hi_s64 ll_theta0, ll_theta1;
590 hi_s64 ll_dpd_base = 0;
591
592 /* 初始化g_ll_pa_val */
593 hmac_init_ll_pa_val(hi1131_dpd_cali_data_read);
594 /* g_ll_pa_val上报值, g_ll_mk1_32给定矩阵值 */
595 for (us_j = 0; us_j < 3; us_j++) { /* 循环3次 */
596 hmac_init_dpd_sum(&sum, us_j);
597 ak_16[us_j] = complex_div_round_closest(sum, 1 << 11); /* round(oal_sum/BIT28); 11: 左移11位 */
598
599 oam_warning_log3(0, OAM_SF_CALIBRATE, "st_ak_16[%d]=%d+j%d\n", us_j, ak_16[us_j].ll_real, ak_16[us_j].ll_imag);
600 }
601
602 for (us_idx = 0; us_idx < DPD_CALI_LUT_LENGTH; us_idx++) {
603 vv1_32.ll_real = 512 * (1 << 5); /* 512 用于计算 左移5位 */
604 vv1_32.ll_imag = 0;
605
606 vo_fixed = 4 + 8 * us_idx; /* 4 8 用于计算 */
607
608 for (us_j = 0; us_j < 10; us_j++) { /* 10 循环次数 */
609 xll_32 = complex_div_round_closest(hmac_dpd_complex_multiply_const(vv1_32, vo_fixed), 1 << 7); /* 7:bits */
610 hmac_dpd_cordic(xll_32.ll_real, xll_32.ll_imag, &ll_amp, &ll_theta0, &ll_theta1);
611
612 tmp1 = complex_div_round_closest(hmac_dpd_complex_multiply_const(ak_16[1], ll_amp), 1 << 17); /* 17:bits */
613 tmp1 = hmac_dpd_complex_add(ak_16[0], tmp1);
614 tmp2 = hmac_dpd_complex_multiply_const(ak_16[2], hmac_dpd_complex_pow(xll_32)); /* 2 元素索引 */
615 tmp2 = complex_div_round_closest(tmp2, ((hi_s64)1 << 34)); /* 左移34位 */
616 vv0_32 = hmac_dpd_complex_add(tmp1, tmp2);
617 yll_32 = complex_div_round_closest(hmac_dpd_complex_multiply(xll_32, vv0_32), 1 << 9); /* 9 */
618 y_opt_32 = hmac_dpd_complex_multiply_const(g_ll_pa_val[127], ((hi_s64)(vo_fixed) << 2)); /* 127 左移2 */
619 vv1_32 = hmac_dpd_complex_div(hmac_dpd_complex_multiply(y_opt_32, vv1_32), yll_32);
620
621 vv1_32.ll_real = oal_max(-((1 << 15) - 1), oal_min((1 << 15) - 1, vv1_32.ll_real)); /* 左移15 */
622 vv1_32.ll_imag = oal_max(-((1 << 15) - 1), oal_min((1 << 15) - 1, vv1_32.ll_imag)); /* 左移15 */
623 }
624
625 dpd_lut_fixed = complex_div_round_closest(vv1_32, 1 << 5); /* 左移5位 round(vv1_32/BIT5); */
626 if (us_idx == 0) {
627 ll_dpd_base = dpd_lut_fixed.ll_real;
628 if (ll_dpd_base == 0) {
629 oam_error_log0(0, OAM_SF_CALIBRATE, " dpd: the first dpd lut elements if zero!!!\r\n");
630 }
631 }
632 dpd_lut_fixed = complex_div_round_closest(hmac_dpd_complex_multiply_const(dpd_lut_fixed, 512),
633 ll_dpd_base); /* 512 函数入参 */
634 *(hi1131_dpd_cali_data_calc + us_idx) =
635 (set2comp((hi_s32)dpd_lut_fixed.ll_real)) | ((set2comp((hi_s32)dpd_lut_fixed.ll_imag)) << 11); /* 左移11 */
636 oam_warning_log2(0, OAM_SF_CALIBRATE, "hi1131_dpd_cali_data_calc::real = %d, imag = %d\r\n",
637 (hi_s32)dpd_lut_fixed.ll_real, (hi_s32)dpd_lut_fixed.ll_imag);
638 }
639
640 return HI_SUCCESS;
641 }
642
643 #ifdef __cplusplus
644 #if __cplusplus
645 }
646 #endif
647 #endif
648