comparison L1/cfile/l1_ctl.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children b36540edb046
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
1 /************* Revision Controle System Header *************
2 * GSM Layer 1 software
3 * L1_CTL.C
4 *
5 * Filename l1_ctl.c
6 * Copyright 2003 (C) Texas Instruments
7 *
8 ************* Revision Controle System Header *************/
9
10 #define L1_CTL_C
11
12 #include "config.h"
13 #include "l1_confg.h"
14 #include "l1_macro.h"
15
16 #if (CODE_VERSION == SIMULATION)
17 #include <string.h>
18 #include "l1_types.h"
19 #include "sys_types.h"
20 #include "l1_const.h"
21 #include "l1_time.h"
22 #include "l1_signa.h"
23
24 #if TESTMODE
25 #include "l1tm_defty.h"
26 #endif
27 #if (AUDIO_TASK == 1)
28 #include "l1audio_const.h"
29 #include "l1audio_cust.h"
30 #include "l1audio_signa.h"
31 #include "l1audio_defty.h"
32 #include "l1audio_msgty.h"
33 #endif
34 #if (L1_GTT == 1)
35 #include "l1gtt_const.h"
36 #include "l1gtt_defty.h"
37 #endif
38 #if (L1_MP3 == 1)
39 #include "l1mp3_defty.h"
40 #endif
41 #if (L1_MIDI == 1)
42 #include "l1midi_defty.h"
43 #endif
44 //ADDED FOR AAC
45 #if (L1_AAC == 1)
46 #include "l1aac_defty.h"
47 #endif
48 #include "l1_defty.h"
49 #include "cust_os.h"
50 #include "l1_msgty.h"
51 #include "l1_varex.h"
52 #include "l1_proto.h"
53 #include "l1_mftab.h"
54 #include "l1_tabs.h"
55 #include "l1_ver.h"
56 #if L2_L3_SIMUL
57 #include "hw_debug.h"
58 #endif
59
60 #if TESTMODE
61 #include "l1tm_msgty.h"
62 #include "l1tm_varex.h"
63 #endif
64
65 #include "l1_ctl.h"
66
67 #ifdef _INLINE
68 #define INLINE static inline // Inline functions when -v option is set
69 #else // when the compiler is ivoked.
70 #define INLINE
71 #endif
72 #else
73 #include <string.h>
74 #include "l1_types.h"
75 #include "sys_types.h"
76 #include "l1_const.h"
77 #include "l1_time.h"
78 #include "l1_signa.h"
79
80 #if (RF_FAM == 61)
81 #include "tpudrv61.h"
82 #endif
83
84 #if TESTMODE
85 #include "l1tm_defty.h"
86 #endif
87 #if (AUDIO_TASK == 1)
88 #include "l1audio_const.h"
89 #include "l1audio_cust.h"
90 #include "l1audio_defty.h"
91 #endif
92 #if (L1_GTT == 1)
93 #include "l1gtt_const.h"
94 #include "l1gtt_defty.h"
95 #endif
96 #if (L1_MP3 == 1)
97 #include "l1mp3_defty.h"
98 #endif
99 #if (L1_MIDI == 1)
100 #include "l1midi_defty.h"
101 #endif
102 //ADDED FOR AAC
103 #if (L1_AAC == 1)
104 #include "l1aac_defty.h"
105 #endif
106 #include "l1_defty.h"
107 #include "../../gpf/inc/cust_os.h"
108 #include "l1_msgty.h"
109 #include "l1_varex.h"
110 #include "l1_proto.h"
111 #include "l1_tabs.h"
112 #include "l1_ctl.h"
113 #if L2_L3_SIMUL
114 #include "hw_debug.h"
115 #endif
116
117 #if TESTMODE
118 #include "l1tm_msgty.h"
119 #include "l1tm_varex.h"
120 #endif
121 #ifdef _INLINE
122 #define INLINE static inline // Inline functions when -v option is set
123 #else // when the compiler is ivoked.
124 #define INLINE
125 #endif
126 #endif
127
128 #if(RF_FAM == 61)
129 #include "l1_rf61.h"
130 #endif
131
132 #if (TRACE_TYPE == 1) || (TRACE_TYPE == 4)
133 #include "l1_trace.h"
134 #endif
135
136 extern SYS_UWORD16 Convert_l1_radio_freq(SYS_UWORD16 radio_freq);
137 #if(RF_FAM == 61)
138 extern WORD16 drp_gain_correction(UWORD16 arfcn, UWORD8 lna_off, UWORD16 agc);
139 #endif
140
141 #define LNA_OFF 1
142 #define LNA_ON 0
143
144
145
146
147 /************************************/
148 /* Automatic frequency compensation */
149 /************************************/
150
151 #define L1_WORD16_POS_MAX (32767)
152 #define L1_WORD16_NEG_MAX (-32768)
153 #define L1_WORD32_POS_MAX ((unsigned long)(1<<31)-1)
154 #define L1_WORD32_NEG_MAX (-(unsigned long)(1<<31))
155
156 INLINE WORD16 Add_Sat_sign_16b(WORD16 val1, WORD16 val2)
157 {
158 WORD32 temp;
159 WORD16 result;
160
161 temp = (WORD32)((WORD32)val1 + (WORD32)val2);
162 if(temp > L1_WORD16_POS_MAX)
163 {
164 temp = L1_WORD16_POS_MAX;
165 }
166 if(temp < L1_WORD16_NEG_MAX)
167 {
168 temp = L1_WORD16_NEG_MAX;
169 }
170 result = (WORD16)((temp)&(0x0000FFFF));
171 return(result);
172 }
173
174 INLINE WORD32 Add_Sat_sign_32b(WORD32 val1, WORD32 val2)
175 {
176 WORD32 temp_high_high;
177 UWORD32 temp_low_low;
178 UWORD16 carry;
179 WORD32 result;
180 WORD16 high_val1, high_val2;
181 UWORD16 low_val1, low_val2;
182
183 high_val1 = (WORD16)(val1>>16);
184 high_val2 = (WORD16)(val2>>16);
185 low_val1 = (UWORD16)(val1&0x0000FFFF);
186 low_val2 = (UWORD16)(val2&0x0000FFFF);
187
188 temp_high_high = (WORD32)high_val1 + (WORD32)high_val2;
189 temp_low_low = (UWORD32)low_val1 + (UWORD32)low_val2;
190 carry = (UWORD16)(temp_low_low >> 16);
191 temp_high_high = temp_high_high + (UWORD32)(carry);
192
193
194 result = val1 + val2;
195 if(temp_high_high > L1_WORD16_POS_MAX)
196 {
197 result = L1_WORD32_POS_MAX;
198 }
199 if(temp_high_high < L1_WORD16_NEG_MAX)
200 {
201 result = L1_WORD32_NEG_MAX;
202 }
203
204 return(result);
205 }
206
207 INLINE WORD32 Sat_Mult_20sign_16unsign(WORD32 val1, UWORD32 val2)
208 {
209 WORD32 result;
210
211 result = val1 * val2;
212 if(val1>0) /* val2 is > 0*/
213 {
214 if(result < 0) /* overflow */
215 {
216 result = L1_WORD32_POS_MAX;
217 }
218 }
219 if(val1<0) /* val2 is > 0*/
220 {
221 if(result > 0) /* overflow */
222 {
223 result = L1_WORD32_NEG_MAX;
224 }
225 }
226 return(result);
227 }
228
229
230 INLINE WORD32 Add_40b( WORD32 guard1guard2, WORD32 lvar1, WORD32 lvar2, WORD16 *guardout )
231 {
232 WORD32 result, temp, carry, Lvar1, Lvar2;
233 WORD16 guard1,guard2;
234
235 guard1=(WORD16) ((WORD32) guard1guard2>>16);
236 guard2=(WORD16) guard1guard2;
237
238 /* lvar1 and lvar2 are both 48 bits variables */
239 /* We 1st add the low parts of lvar1 and lvar2 and we give */
240 /* a 32 bits result and a carry if needed */
241 Lvar1 = (UWORD16)lvar1;
242 Lvar2 = (UWORD16)lvar2;
243
244 temp = Lvar1 + Lvar2;
245
246 carry = temp >> 16;
247
248 result = temp & 0x0000ffffL;
249
250 /* We now add the two high parts of var1 and var2 (scaled */
251 /* to a 16 bits format) and carry (if any) and we give a */
252 /* 48 bits results. */
253 Lvar1 = (UWORD32)lvar1 >> 16;
254 Lvar2 = (UWORD32)lvar2 >> 16;
255
256 temp = Lvar1 + Lvar2 + carry;
257
258 carry = (UWORD32)temp >> 16;
259
260 temp = (UWORD32)temp << 16;
261
262 result = result | temp;
263
264 temp = guard1 + guard2 + carry;
265
266 *guardout = (WORD16)temp;
267
268 return( result );
269 }
270
271
272 INLINE WORD32 Mult_40b(WORD32 var1, WORD16 var2, WORD16 *guardout)
273 {
274 WORD32 mult,guard1guard2;
275 WORD32 aux1;
276 UWORD32 aux2;
277 WORD16 neg_flag=0;
278 WORD32 var1_low_nosign,var2_nosign;
279
280 if (var2<0)
281 {
282 var2=-var2;
283 neg_flag=1;
284 }
285
286 /*aux1 = AccHigh(var1)*var2 */
287 aux1 = (WORD32)(var1>>16) * (WORD32)var2;
288 /* 16 bits * 16 bits -> 32 bits result */
289
290 /*aux2 = AccLow(var1)*var2 (unsigned multiplication) */
291 /* Performs the sign suppression of the words */
292 var1_low_nosign = (UWORD16)var1;
293 var2_nosign = (UWORD16) var2;
294
295 aux2 = (UWORD32)var1_low_nosign * (UWORD32)var2_nosign;
296
297 /*Shift aux1=F48 of 16 bit left */
298 guard1guard2=aux1&0xFFFF0000L;/*guard1=(WORD16)(aux1>>16)*/
299 /*guard2=0x0000 */
300 aux1=aux1<<16;
301
302
303 /* ((var1_high*var2)<<16) +(var1_low*var2) = aux1 + aux2 */
304 /* aux1 and aux2 are both 48 bits variables */
305 /* We first add the low pats of aux1 and aux2 and we give*/
306 /* a 32 bits result and a carry if needed */
307 mult=Add_40b(guard1guard2,aux1,aux2,guardout );
308
309 if (neg_flag)
310 {
311 mult=-mult;
312 if (*guardout!=0)
313 *guardout=-(*guardout)-1;
314 else
315 *guardout=-1;
316 }
317
318 return(mult);
319 }
320
321
322 /***********************************************************************/
323 /* This function allows to multiply a WORD32 and a WORD16, both POSITIVE, */
324 /* variables. Result is WORD32. */
325 /***********************************************************************/
326 INLINE WORD32 UMult_40b(WORD32 var1, WORD16 var2, WORD16 *guardout)
327 {
328 WORD32 mult,guard1guard2;
329 UWORD32 aux1,aux2;
330 WORD32 var1_high_nosign,var1_low_nosign,var2_nosign;
331
332
333 /*aux1 = AccHigh(var1)*var2 (unsigned multiplication) */
334 /* Performs the sign suppression of the words */
335 var1_high_nosign = (UWORD32)var1>>16;
336 var2_nosign = (UWORD16) var2;
337
338 aux1 = (UWORD32)var1_high_nosign * (UWORD32)var2_nosign;
339
340 /*aux2 = AccLow(var1)*var2 (unsigned multiplication) */
341 /* Performs the sign suppression of the words */
342 var1_low_nosign = (WORD32)((UWORD16)var1);
343
344 aux2 = (UWORD32)var1_low_nosign * (UWORD32)var2_nosign;
345
346 /*Shift aux1=F48 of 16 bit left */
347 guard1guard2=aux1&0xFFFF0000L;/*guard1=(WORD16)(aux1>>16)*/
348 /*guard2=0x0000 */
349 aux1=aux1<<16;
350
351
352 /* ((var1_high*var2)<<16) +(var1_low*var2) = aux1 + aux2 */
353 mult=Add_40b(guard1guard2,aux1,aux2,guardout);
354
355 return(mult);
356 }
357
358
359 /*-------------------------------------------------------*/
360 /* l1ctl_afc() */
361 /*-------------------------------------------------------*/
362 /* Parameters : */
363 /* Return : */
364 /* Functionality : */
365 /*-------------------------------------------------------*/
366 #if (VCXO_ALGO == 0)
367 WORD16 l1ctl_afc (UWORD8 phase, UWORD32 *frame_count, WORD16 angle, WORD32 snr, UWORD16 radio_freq)
368 #else
369 WORD16 l1ctl_afc (UWORD8 phase, UWORD32 *frame_count, WORD16 angle, WORD32 snr, UWORD16 radio_freq, UWORD32 l1_mode)
370 #endif
371 {
372 /*************************/
373 /* Variables declaration */
374 /*************************/
375 WORD16 i=0;
376 UWORD32 denom; /* F12.20 */
377 WORD32 var_32,num,Phi_32=0,var1,var2,guard1guard2;
378 static UWORD32 P=C_cov_start; /* F12.20 */
379 static WORD32 Psi=0; /* F13.19 */
380 static WORD16 Psi_quant[C_N_del+1]; /* F13.3 */
381 WORD16 var_16;
382 WORD16 Phi=0; /* F1.15 */
383 WORD16 quotient,guard1,guard2,guardout;
384 UWORD32 LGuard;
385 WORD16 denomH,denomH_3msb;
386 UWORD32 K=0; /* algo 1 */
387
388 static WORD16 old_Psi_quant[C_N_del+1];
389 static WORD32 old_Psi=0;
390
391 #if (VCXO_ALGO == 1)
392 static WORD32 psi_past[C_N_del+1]; /* F13.19 */
393 static WORD16 psi_quant; /* F13.3 */
394 static WORD16 quant_avg;
395 static UWORD32 M_Count;
396 static WORD32 psi_avg[C_PSI_AVG_SIZE_D+1]; // Data history array
397 static WORD16 B_Count; // Counter for consecutive SNR below C_thr_snr
398 UWORD16 L = 10433; // Gain algo2
399 static UWORD16 first_avg;
400 static UWORD16 good_snr;
401
402 /* to be able to keep in memory the old AFC variables in case of spurious
403 FB detection */
404 static WORD32 old_psi_past[C_N_del+1]; /* F13.19 */
405 static WORD16 old_psi_quant; /* F13.3 */
406
407 #endif
408 #if (L1_FF_MULTIBAND == 1)
409 UWORD8 physical_band_id;
410 #endif
411
412
413 //Set AFC close loop gain for ALGO_AFC_LQG_PREDICTOR.
414 if(l1_mode==I_MODE)//MS is in Idle mode
415 L = 41732; //F0.20 L=41732/2^20 = 0.04
416 else //All other modes than Idle
417 L = 10433; //F0.20 L=10433/2^20 = 0.01
418
419
420 #if (L1_FF_MULTIBAND == 0)
421
422 if (((l1_config.std.id == DUAL) || (l1_config.std.id == DUALEXT) || (l1_config.std.id == DUAL_US)) &&
423 #if (VCXO_ALGO == 1)
424 ((phase != AFC_INIT_CENTER) || (phase != AFC_INIT_MIN) || (phase != AFC_INIT_MAX)))
425 #else
426 (phase != AFC_INIT))
427 #endif
428 {
429 if (radio_freq >= l1_config.std.first_radio_freq_band2)
430 {
431 angle = (angle + 1) >> 1;
432 }
433 }
434
435 else if (((l1_config.std.id == DCS1800) || (l1_config.std.id == PCS1900)) &&
436 #if (VCXO_ALGO == 1)
437 ((phase != AFC_INIT_CENTER) || (phase != AFC_INIT_MIN) || (phase != AFC_INIT_MAX)))
438 #else
439 (phase != AFC_INIT))
440 #endif
441 {
442 angle = (angle + 1) >> 1;
443 }
444
445 #else // L1_FF_MULTIBAND = 1 below
446
447 #if (VCXO_ALGO == 1)
448 if((phase != AFC_INIT_CENTER) || (phase != AFC_INIT_MIN) || (phase != AFC_INIT_MAX))
449 #else
450 if(phase != AFC_INIT)
451 #endif
452 {
453 physical_band_id = l1_multiband_radio_freq_convert_into_physical_band_id(radio_freq);
454
455 if( (multiband_rf[physical_band_id].gsm_band_identifier == DCS1800) || (multiband_rf[physical_band_id].gsm_band_identifier == PCS1900))
456 {
457 angle = (angle + 1) >> 1;
458 }
459 }
460
461 #endif // #if (L1_FF_MULTIBAND == 1) else
462
463
464
465 /*********************************/
466 /* frequency offset compensation */
467 /*********************************/
468 /* Initialization */
469
470 #if (VCXO_ALGO == 1)
471 switch (l1_config.params.afc_algo)
472 {
473
474 /* algo1 only: */
475 case ALGO_AFC_KALMAN:
476 {
477 #endif
478 #if (VCXO_ALGO == 0)
479 if (phase==AFC_INIT)
480 {
481 // WARNING
482 // In this case, "angle" variable contains EEPROM_AFC initialization value
483 // directly loaded from EEPROM, and "snr" variable is not meaningful.
484 /* Static variables initialisation */
485 P=C_cov_start;
486 Psi=0;
487 if (angle>C_max_step)
488 Psi_quant[C_N_del]=C_max_step;
489 else
490 if(angle<C_min_step)
491 Psi_quant[C_N_del]=C_min_step;
492 else Psi_quant[C_N_del]=angle;
493
494 Psi=l1_config.params.psi_st*Psi_quant[C_N_del]; /* F0.16 * F13.3 = F13.19 */
495 } /* end AFC_INIT*/
496 else
497 {
498 if (phase==AFC_OPEN_LOOP)
499 {
500 /* delay line for Psi_quant values */
501 for (i=1;i<=C_N_del;i++)
502 Psi_quant[i-1]=Psi_quant[i];
503
504 var_32=(WORD32)((WORD32)angle*l1_config.params.psi_sta_inv)<<4;
505 /*(F16.0 * F1.15 = F17.15) << 4 = F13.19 */
506
507 #if(RF_FAM == 61)
508 /* In order to implement the NINT function for a F16.0, we check */
509 /* if var_32 + 0.5*2**18 is a multiple of 2**18 */
510 quotient=(WORD16)((WORD32)(((WORD32)(var_32+(1<<17)))/(1<<18)));
511 var_16=quotient*4;
512 #else
513 /* In order to implement the NINT function for a F16.0, we check */
514 /* if var_32 + 0.5*2**19 is a multiple of 2**19 */
515 quotient=(WORD16)((WORD32)(((WORD32)(var_32+(1<<18)))/(1<<19)));
516 var_16=quotient*8;
517 #endif
518 if (var_16>C_max_step)
519 Psi_quant[C_N_del]=Add_Sat_sign_16b(Psi_quant[C_N_del],C_max_step);
520 else
521 if(var_16<C_min_step)
522 Psi_quant[C_N_del]=Add_Sat_sign_16b(Psi_quant[C_N_del],C_min_step);
523 else Psi_quant[C_N_del]=Add_Sat_sign_16b(Psi_quant[C_N_del],var_16); /* F13.3 */
524
525 Psi=l1_config.params.psi_st*Psi_quant[C_N_del]; /* F0.16 * F13.3 = F13.19 */
526 }/*end if AFC_OPEN_LOOP*/
527
528 else
529 {
530 /* delay line for Psi_quant values */
531 for (i=1;i<=C_N_del;i++)
532 Psi_quant[i-1]=Psi_quant[i];
533
534 /********************/
535 /* Filter algorithm */
536 /********************/
537
538 /* Covariance error is increased of C_Q */
539 P=P+(*frame_count)*C_Q;
540
541 /* Clipping of P */
542 if (P>C_thr_P) P=C_thr_P;
543
544 if (snr>=C_thr_snr)
545 {
546 /* Clipping of error angle */
547 if (angle>C_thr_phi)
548 angle=C_thr_phi;
549 if (angle<-C_thr_phi)
550 angle=-C_thr_phi;
551
552 /* Kalman gain */
553 /*K=P*(1/(P+C_a0_kalman+(C_g_kalman*RNS))) */
554 /*C_a0_kalman=0.01 */
555 /*C_g_kalman =0.05 */
556 num=(C_g_kalman/snr)+P+C_a0_kalman;
557 /* (F2.30 / F6.10) = F 12.20 */
558
559 /* denom = P << 19 = F 1.39 */
560 /* extension of denom=P to a 40 bits variable */
561 /* denom (F12.20) << 16 = F 4.36 */
562 guard1=(WORD16)((WORD32)P>>16);
563 /* denom = P<<16 = (F4.36) << 3 = F 1.39 */
564 denomH=(UWORD16)P;
565 /* Low part of denom is equal to 0, because P has been 16 */
566 /* bits left shifted previously. */
567 denomH_3msb=(denomH>>13)&0x0007;
568 guard1=(guard1<<3)|denomH_3msb;
569 denomH<<=3;
570 denom=(UWORD32)denomH<<16;
571 /* num + guard1 are a 40 bits representation of P */
572 /* In order to compute P(F1.39)/num, we sample P in guard1 */
573 /* (scaled to a 32 bits number) and num (32 bits number) */
574 /* K = ((guard1<<24)/num)<<8 + (denom/num) */
575 var1=(WORD32)guard1<<24;
576 var1=var1/num;
577 var1=(WORD32)var1<<8;
578 /* var2 is an unsigned variable, var1 contains signed guard*/
579 /* bits. */
580 var2=denom/num;
581 K = (var1+var2)<<1; /* F1.39 / F12.20 = F13.19 */
582 /* F13.19 << 1 = F12.20 */
583
584 /* Clipping of the Kalman gain */
585 if (K>=C_thr_K)
586 K=C_thr_K;
587
588 /*******************************************************/
589 /* P=(1-K)*P = 0.8 * 0.5 at maximum */
590 /*******************************************************/
591 /* Perform a positive variable F12.20 multiplication by*/
592 /* positive variable F12.20 */
593 var_16=(WORD16)(1048576L-K); /* acclow(1-K) = F12.20 */
594 guard1=0; /* positive variable */
595 var1=UMult_40b(P,var_16,&guard1);
596 var_16=(WORD16)((1048576L-K)>>16);
597 /* acchigh(1-K) = F12.20 */
598 var2=P*var_16; /* var2 = 0x80000 * 0xc */
599 /* at maximum, so result */
600 /* is 32 bits WORD32 and */
601 /* equal 0x600000 */
602 /* extension of var2 to a 40 bits variable : var2<<16 */
603 guard2=(WORD16)((WORD32)var2>>16);
604 guard1guard2=((WORD32)guard1<<16) |((WORD32) guard2&0x0000FFFFL);
605 var2=var2<<16;
606 var_32=Add_40b(guard1guard2,var1,var2,&guardout);
607 /* var_32 (F8.40) >> 16 = F8.24 */
608 LGuard=(WORD32)guardout<<16;
609 var1=(UWORD32)var_32>>16;
610 /* var_32 >> 4 = F12.20 */
611 P=(var1+LGuard)>>4;
612
613 Phi_32=Mult_40b(l1_config.params.psi_st_32,Psi_quant[0],&guardout);
614 /* F0.32 * F13.3 = F5.35 */
615 LGuard=(WORD32)guardout<<16; /* var_32 (F5.35) >> 16 */
616 /* F13.19 */
617 var1=(UWORD32)Phi_32>>16;
618 Phi_32=Psi-(LGuard+var1); /* F13.19 */
619
620 /*Phi=angle-Phi_32*/
621 Phi_32=((WORD32)angle<<4)-Phi_32;
622 /* F1.15 * 4 = F13.19 */
623 Phi=(WORD16)(Phi_32>>4); /* F17.15 */
624 /*var1=K*Phi F12.20 * F1.15 = 13.35 */
625 guard1=0;
626 var1=Mult_40b(K,Phi,&guard1);
627 /* var1 (F13.35) >> 16 */
628 /* F13.19 */
629 LGuard=(WORD32)guard1<<16;
630 var1=(UWORD32)var1>>16;
631 Psi+=var1+LGuard;
632 }/*if snr */
633
634 var_32=Mult_40b(Psi,l1_config.params.psi_st_inv,&guardout);
635 /* F13.19 * C = F13.19 */
636
637 #if(RF_FAM == 61)
638 /* In order to implement the NINT function for a F13.3, we check */
639 /* if var_32 + 0.5*2**18 is a multiple of 2**18 */
640 quotient=(WORD16)((WORD32)(((WORD32)(var_32+(1<<17)))/(1<<18)));
641 var_16=quotient*4;
642 #else
643 /* In order to implement the NINT function for a F13.3, we check */
644 /* if var_32 + 0.5*2**19 is a multiple of 2**19 */
645 quotient=(WORD16)((WORD32)(((WORD32)(var_32+(1<<18)))/(1<<19)));
646 var_16=quotient*8;
647 #endif
648 if (var_16>C_max_step)
649 Psi_quant[C_N_del]=C_max_step;
650 else
651 if(var_16<C_min_step)
652 Psi_quant[C_N_del]=C_min_step;
653 else Psi_quant[C_N_del]=var_16; /* F13.3 */
654
655 }/*end AFC_CLOSE_LOOP*/
656 } /* end else AFC_INIT*/
657
658 *frame_count=0;
659 //Locosto
660 // return(Psi_quant[C_N_del]>>3); /* F16.0 */
661 return(CONVERT_PSI_QUANT(Psi_quant[C_N_del])); /* F16.0 to 14.2 or 13.3 */
662
663 #else
664
665 } /* end case algo 1 */
666
667
668 /* algo2 + init + estimator/predictor */
669 case ALGO_AFC_LQG_PREDICTOR:
670 {
671 /******************************************************************/
672 /* (New) VCXO Algorithm */
673 /******************************************************************/
674
675 switch (phase) {
676 case AFC_INIT_CENTER :
677 case AFC_INIT_MAX :
678 case AFC_INIT_MIN :
679 quant_avg = 0;
680 M_Count = 0;
681 for (i = 0; i <= C_PSI_AVG_SIZE_D ; i++) //omaps00090550
682 psi_avg[i] = 0;
683 first_avg = 1;
684 good_snr = 0;
685
686 // DAC search algorithm is as follows - up to 12 attempts are made
687 // DAC search algorithm uses three values : DAC_center -> DAC_max -> DAC_min ->
688 // The first four attempts are made on DAC_center
689 // The next four attempts are made on DAC_max
690 // The last four attempts are made on DAC_min
691 // There are statistical reasons for trying four times
692
693 switch (phase)
694 {
695 case AFC_INIT_CENTER:
696 psi_quant = l1_config.params.afc_dac_center;
697 break;
698 case AFC_INIT_MAX:
699 psi_quant = l1_config.params.afc_dac_max;
700 break;
701 case AFC_INIT_MIN:
702 psi_quant = l1_config.params.afc_dac_min;
703 break;
704 default :
705 break;
706 }
707
708 /* F0.32 * F13.3 = F5.35 */
709 psi_past[C_N_del]=Mult_40b(l1_config.params.psi_st_32,psi_quant, &guardout);
710 /* (F13.3<<16 )+(F5.35>>16) = F13.19 */
711 psi_past[C_N_del]=((WORD32)guardout<<16)+((UWORD32)psi_past[C_N_del]>>16);
712
713 break;
714
715 case AFC_OPEN_LOOP :
716 {
717 /* VCXO changes for spurious FB detection */
718 if (l1s.spurious_fb_detected == TRUE)
719 {
720 psi_quant = old_psi_quant;
721
722 for(i=0;i<C_N_del+1;i++)
723 psi_past[i] = old_psi_past[i];
724
725 /* reset the spurious_fb_detected_flag */
726 l1s.spurious_fb_detected = FALSE;
727 } /* end of spuriousFB detected */
728
729 /* save in memory the old AFC related values */
730 old_psi_quant = psi_quant;
731
732 for(i=0;i<C_N_del+1;i++)
733 old_psi_past[i] = psi_past[i];
734
735 /* delay line for psi_quant values */
736 for (i = 1; i <= C_N_del; i++)
737 psi_past[i-1] = psi_past[i];
738
739 /* (F16.0 * F1.15 = F17.15) << 4 = F13.19 */
740 var_32 = (WORD32) ((WORD32)angle * l1_config.params.psi_sta_inv) << 4;
741
742 #if(RF_FAM == 61)
743 /* In order to implement the NINT function for a F16.0,*/
744 /*we check if var_32 + 0.5*2**18 is a multiple of 2**18 */
745 var_16 = (WORD16)
746 ((WORD32) (((WORD32)(var_32 + (1<<17))) / (1<<18)));
747 var_16 = var_16 * 4;
748 #else
749 /* In order to implement the NINT function for a F16.0,*/
750 /*we check if var_32 + 0.5*2**19 is a multiple of 2**19 */
751 var_16 = (WORD16)
752 ((WORD32) (((WORD32)(var_32 + (1<<18))) / (1<<19)));
753 var_16 = var_16 * 8;
754 #endif
755 if (var_16 > C_max_step)
756 psi_quant = Add_Sat_sign_16b(psi_quant,C_max_step);
757 else if (var_16 < C_min_step)
758 psi_quant = Add_Sat_sign_16b(psi_quant,C_min_step);
759 else psi_quant = Add_Sat_sign_16b(psi_quant,var_16); /* F13.3 */
760 /* F0.32 * F13.3 = F5.35 */
761 psi_past[C_N_del]=Mult_40b(l1_config.params.psi_st_32,psi_quant, &guardout);
762 /* (F13.3<<16 )+(F5.35>>16) = F13.19 */
763 psi_past[C_N_del]=((WORD32)guardout<<16)+((UWORD32)psi_past[C_N_del]>>16);
764
765 }
766 break;
767
768 case AFC_CLOSED_LOOP :
769
770 /* delay line for psi_quant values */
771 for (i = 1; i <= C_N_del; i++)
772 psi_past[i-1] = psi_past[i];
773
774 /************************************/
775 /* Estimation */
776 /************************************/
777 if ( (l1_config.params.rgap_algo != 0) &&
778 ((l1_mode==CON_EST_MODE2)||(l1_mode==DEDIC_MODE)
779 #if L1_GPRS
780 || l1_mode==PACKET_TRANSFER_MODE
781 #endif
782 ))
783 {
784
785 M_Count += *frame_count;
786 if (snr >= l1_config.params.afc_snr_thr) {
787 // Accumulate average over N TDMA frames
788 psi_avg[0] += psi_past[C_N_del];
789 // Count number of good snr's within window_avg_size chunks
790 good_snr++;
791 }
792 // M_Count >= M ?
793 if (M_Count >= l1_config.params.afc_win_avg_size_M) {
794 // M_Count counts how far we have reached in the window_avg_size blocks
795
796 // Scale estimate relative to good snr - Don't divide by zero in case of bad measurements
797 if (good_snr > 0)
798 psi_avg[0] /= good_snr;
799
800 // We now have an estimation over window_avg_size TDMA frames in psi_avg[0]
801 if (first_avg == 1) {
802 first_avg = 0;
803 // Use first estimation as best guess for the other avg values
804 // This is used both at initialisation and when returning from reception gap
805 for (i = 1; i <= C_PSI_AVG_SIZE_D ; i++)
806 psi_avg[i] = psi_avg[0];
807 }
808
809 // Estimation 1st order
810 // Use biggest window to reduce noise effects signal in psi values
811 // NOTE: Due to performance issues division by MSIZE is in predictor
812 if (l1_config.params.rgap_algo >= 1) {
813 quant_avg = (WORD16) (psi_avg[0] - psi_avg[C_PSI_AVG_SIZE_D]);
814 }
815
816 for (i = C_PSI_AVG_SIZE_D - 1; i >= 0 ; i--)
817 psi_avg[i+1] = psi_avg[i];
818 psi_avg[0] = 0;
819 M_Count = 0;
820 good_snr = 0;
821 }
822
823 } else {
824 // No estmation when in Idle mode (DEEP or BIG SLEEP) => Reset!
825 first_avg = 1;
826 M_Count = 0;
827 good_snr = 0;
828 psi_avg[0] = 0;
829 }
830
831 if (snr >= l1_config.params.afc_snr_thr) {
832 /********************/
833 /* Filter algorithm */
834 /********************/
835
836 /* No prediction during normal operation */
837 B_Count= 0;
838
839 /* Clip error angle */
840 if (angle > C_thr_phi)
841 angle = C_thr_phi;
842 if (angle < -C_thr_phi)
843 angle = -C_thr_phi;
844
845 Phi_32 = psi_past[C_N_del] - psi_past[0]; /* F13.19 */
846 /* Phi = angle - Phi_32*/
847 Phi_32 = ((WORD32) angle << 4) - Phi_32;
848 /* F1.15 * 4 = F13.19 */
849 Phi = (WORD16)((WORD32)((WORD32)(Phi_32 + (1<<3)))/ (1<<4)); /* F17.15 */
850 /* (F0.20 * F1.15) >> 16 = F13.19 */
851 var_32 = (L * Phi + (1<<15)) >> 16;
852 psi_past[C_N_del] = Add_Sat_sign_32b(psi_past[C_N_del],var_32);
853
854
855 }
856 else
857 {
858 /************************************/
859 /* Prediction */
860 /************************************/
861
862 // Only predict in dedicated mode
863 // NO prediction in idle mode
864 // l1a_l1s_com.dedic_set.SignalCode = NULL
865 if ( (l1_config.params.rgap_algo != 0) &&
866 ((l1_mode==CON_EST_MODE2)||(l1_mode==DEDIC_MODE)
867 #if L1_GPRS
868 || l1_mode==PACKET_TRANSFER_MODE
869 #endif
870 ))
871 {
872 /* Prediction of psi during reception gaps */
873 B_Count
874 += *frame_count;
875
876 /* Predict psi ONLY when we have sufficient measurements available */
877 /* If we don't have enough measurements we don't do anything (= 0th order estimation)*/
878
879 // Was the consecutive bad SNRs threshold value exceeded?
880 if (B_Count>= l1_config.params.rgap_bad_snr_count_B) {
881
882 // Predict with 0th order estimation is the default
883
884 // Predict with 1st order estimation
885 if (l1_config.params.rgap_algo >= 1)
886 {
887 psi_past[C_N_del] = Add_Sat_sign_32b(psi_past[C_N_del],
888 ((quant_avg * (l1_config.params.rgap_bad_snr_count_B))/(C_MSIZE))
889 );
890 }
891
892 B_Count= B_Count - l1_config.params.rgap_bad_snr_count_B;
893
894 // Indicate by raising first_avg flag that a reception gap has occurred
895 // I.e. the psi_avg table must be reinitialised after leaving reception gap
896 first_avg = 1;
897
898 // Counters in estimation part must also be reset
899 M_Count = 0;
900 good_snr = 0;
901 psi_avg[0] = 0;
902 }
903 }
904 }
905
906 /* Quantize psi value */
907
908 /* F0.19 * 16.0 = F16.19 */
909 var_32 = Sat_Mult_20sign_16unsign(psi_past[C_N_del],l1_config.params.psi_st_inv);
910
911 #if(RF_FAM == 61)
912 /* In order to implement the NINT function for a F13.3,*/
913 /*we check if var_32 + 0.5*2**18 is a multiple of 2**18 */
914 var_16 = (WORD16)
915 ((WORD32)((WORD32)(var_32 + (1<<17))) / (1<<18));
916 var_16 = var_16 * 4;
917 #else
918 /* In order to implement the NINT function for a F13.3,*/
919 /*we check if var_32 + 0.5*2**19 is a multiple of 2**19 */
920 var_16 = (WORD16)
921 ((WORD32)((WORD32)(var_32 + (1<<18))) / (1<<19));
922 var_16 = var_16 * 8;
923 #endif
924 if (var_16 > C_max_step)
925 psi_quant = C_max_step;
926 else if (var_16 < C_min_step)
927 psi_quant = C_min_step;
928 else
929 psi_quant = var_16; /* F13.3 */
930 break;
931 } // switch phase
932
933 *frame_count = 0;
934
935 //Locosto
936 // return (psi_quant >> 3); /* F16.0 */
937 return(CONVERT_PSI_QUANT(psi_quant)); /* F16.0 to 14.2 or 13.3 */
938 } /* end case algo 2 */
939
940 /* algo1 + init + estimator/predictor */
941 case ALGO_AFC_KALMAN_PREDICTOR:
942 {
943 if ((phase==AFC_INIT_CENTER) || (phase==AFC_INIT_MAX) || (phase==AFC_INIT_MIN))
944 {
945 // WARNING
946 // In this case, "angle" variable contains EEPROM_AFC initialization value
947 // directly loaded from EEPROM, and "snr" variable is not meaningful.
948 /* Static variables initialisation */
949
950 quant_avg = 0;
951 M_Count = 0;
952 for (i = 0; i <=C_PSI_AVG_SIZE_D ; i++) //omaps00090550
953 psi_avg[i] = 0;
954 first_avg = 1;
955 good_snr = 0;
956
957 // DAC search algorithm is as follows - up to 12 attempts are made
958 // DAC search algorithm uses three values : DAC_center -> DAC_max -> DAC_min ->
959 // The first four attempts are made on DAC_center
960 // The next four attempts are made on DAC_max
961 // The last four attempts are made on DAC_min
962 // There are statistical reasons for trying four times
963
964 switch (phase) {
965 case AFC_INIT_CENTER:
966 Psi_quant[C_N_del] = l1_config.params.afc_dac_center;
967 break;
968 case AFC_INIT_MAX:
969 Psi_quant[C_N_del] = l1_config.params.afc_dac_max;
970 break;
971 case AFC_INIT_MIN:
972 Psi_quant[C_N_del] = l1_config.params.afc_dac_min;
973 break;
974 default :
975 break;
976 }
977
978 P=C_cov_start;
979 Psi=0;
980 if (angle>C_max_step)
981 Psi_quant[C_N_del]=C_max_step;
982 else
983 if(angle<C_min_step)
984 Psi_quant[C_N_del]=C_min_step;
985 else Psi_quant[C_N_del]=angle;
986
987 /* F0.32 * F13.3 = F5.35 */
988 Psi=Mult_40b(l1_config.params.psi_st_32,Psi_quant[C_N_del], &guardout);
989 /* (F13.3<<16 )+(F5.35>>16) = F13.19 */
990 Psi=((WORD32)guardout<<16)+((UWORD32)Psi>>16);
991
992 } /* end AFC_INIT*/
993 else
994 {
995 if (phase==AFC_OPEN_LOOP)
996 {
997 /* relaod last good values in the ALGO */
998 if (l1s.spurious_fb_detected == TRUE)
999 {
1000 for(i=0;i<C_N_del+1;i++)
1001 Psi_quant[i] = old_Psi_quant[i];
1002
1003 Psi = old_Psi;
1004 l1s.spurious_fb_detected = FALSE;
1005 }
1006
1007 /* Save the old values in memory */
1008 for(i=0;i<C_N_del+1;i++)
1009 old_Psi_quant[i] = Psi_quant[i];
1010 old_Psi = Psi;
1011
1012 /* delay line for Psi_quant values */
1013 for (i=1;i<=C_N_del;i++)
1014 Psi_quant[i-1]=Psi_quant[i];
1015
1016 var_32=(WORD32)((WORD32)angle*l1_config.params.psi_sta_inv)<<4;
1017 /*(F16.0 * F1.15 = F17.15) << 4 = F13.19 */
1018
1019 #if(RF_FAM == 61)
1020 /* In order to implement the NINT function for a F16.0, we check */
1021 /* if var_32 + 0.5*2**18 is a multiple of 2**18 */
1022 quotient=(WORD16)((WORD32)(((WORD32)(var_32+(1<<17)))/(1<<18)));
1023 var_16=quotient*4;
1024 #else
1025 /* In order to implement the NINT function for a F16.0, we check */
1026 /* if var_32 + 0.5*2**19 is a multiple of 2**19 */
1027 quotient=(WORD16)((WORD32)(((WORD32)(var_32+(1<<18)))/(1<<19)));
1028 var_16=quotient*8;
1029 #endif
1030 if (var_16>C_max_step)
1031 Psi_quant[C_N_del]=Add_Sat_sign_16b(Psi_quant[C_N_del],C_max_step);
1032 else
1033 if(var_16<C_min_step)
1034 Psi_quant[C_N_del]=Add_Sat_sign_16b(Psi_quant[C_N_del],C_min_step);
1035 else Psi_quant[C_N_del]=Add_Sat_sign_16b(Psi_quant[C_N_del],var_16); /* F13.3 */
1036
1037
1038
1039 /* F0.32 * F13.3 = F5.35 */
1040 Psi=Mult_40b(l1_config.params.psi_st_32,Psi_quant[C_N_del], &guardout);
1041 /* (F13.3<<16 )+(F5.35>>16) = F13.19 */
1042 Psi=((WORD32)guardout<<16)+((UWORD32)Psi>>16);
1043
1044 }/*end if AFC_OPEN_LOOP*/
1045 else
1046 {
1047
1048 /* delay line for Psi_quant values */
1049 for (i=1;i<=C_N_del;i++)
1050 Psi_quant[i-1]=Psi_quant[i];
1051
1052 /************************************/
1053 /* Estimation */
1054 /************************************/
1055 if ( (l1_config.params.rgap_algo != 0) &&
1056 ((l1_mode==CON_EST_MODE2)||(l1_mode==DEDIC_MODE)
1057 #if L1_GPRS
1058 || l1_mode==PACKET_TRANSFER_MODE
1059 #endif
1060 ))
1061 {
1062
1063 M_Count += *frame_count;
1064 if (snr >= l1_config.params.afc_snr_thr) {
1065 // Accumulate average over N TDMA frames
1066 psi_avg[0] += psi_past[C_N_del];
1067 // Count number of good snr's within window_avg_size chunks
1068 good_snr++;
1069 }
1070
1071 // M_Count >= M ?
1072 if (M_Count >= l1_config.params.afc_win_avg_size_M) {
1073 // M_Count counts how far we have reached in the window_avg_size blocks
1074
1075 // Scale estimate relative to good snr - Don't divide by zero in case of bad measurements
1076 if (good_snr > 0)
1077 psi_avg[0] /= good_snr;
1078
1079 // We now have an estimation over window_avg_size TDMA frames in psi_avg[0]
1080 if (first_avg == 1) {
1081 first_avg = 0;
1082 // Use first estimation as best guess for the other avg values
1083 // This is used both at initialisation and when returning from reception gap
1084 for (i = 1; i <= C_PSI_AVG_SIZE_D ; i++)
1085 psi_avg[i] = psi_avg[0];
1086 }
1087
1088 // Estimation 1st order
1089 // Use biggest window to reduce noise effects signal in psi values
1090 // NOTE: Due to performance issues division by MSIZE is in predictor
1091 if (l1_config.params.rgap_algo >= 1) {
1092 quant_avg = (WORD16) (psi_avg[0] - psi_avg[C_PSI_AVG_SIZE_D]);
1093 }
1094
1095 for (i = C_PSI_AVG_SIZE_D - 1; i >= 0 ; i--)
1096 psi_avg[i+1] = psi_avg[i];
1097 psi_avg[0] = 0;
1098 M_Count = 0;
1099 good_snr = 0;
1100 }
1101
1102 } else {
1103 // No estmation when in Idle mode (DEEP or BIG SLEEP) => Reset!
1104 first_avg = 1;
1105 M_Count = 0;
1106 good_snr = 0;
1107 psi_avg[0] = 0;
1108 }
1109
1110 /********************/
1111 /* Filter algorithm */
1112 /********************/
1113
1114 /* Covariance error is increased of C_Q */
1115 P=P+(*frame_count)*C_Q;
1116
1117 /* Clipping of P */
1118 if (P>C_thr_P) P=C_thr_P;
1119
1120 if (snr>=C_thr_snr)
1121 {
1122 /* Clipping of error angle */
1123 if (angle>C_thr_phi)
1124 angle=C_thr_phi;
1125 if (angle<-C_thr_phi)
1126 angle=-C_thr_phi;
1127
1128 /* Kalman gain */
1129 /*K=P*(1/(P+C_a0_kalman+(C_g_kalman*RNS))) */
1130 /*C_a0_kalman=0.01 */
1131 /*C_g_kalman =0.05 */
1132 num=(C_g_kalman/snr)+P+C_a0_kalman;
1133 /* (F2.30 / F6.10) = F 12.20 */
1134
1135 /* denom = P << 19 = F 1.39 */
1136 /* extension of denom=P to a 40 bits variable */
1137 /* denom (F12.20) << 16 = F 4.36 */
1138 guard1=(WORD16)((WORD32)P>>16);
1139 /* denom = P<<16 = (F4.36) << 3 = F 1.39 */
1140 denomH=(UWORD16)P;
1141 /* Low part of denom is equal to 0, because P has been 16 */
1142 /* bits left shifted previously. */
1143 denomH_3msb=(denomH>>13)&0x0007;
1144 guard1=(guard1<<3)|denomH_3msb;
1145 denomH<<=3;
1146 denom=denomH<<16; //(UWORD32) removed typecast omaps00090550
1147 /* num + guard1 are a 40 bits representation of P */
1148 /* In order to compute P(F1.39)/num, we sample P in guard1 */
1149 /* (scaled to a 32 bits number) and num (32 bits number) */
1150 /* K = ((guard1<<24)/num)<<8 + (denom/num) */
1151 var1=(WORD32)guard1<<24;
1152 var1=var1/num;
1153 var1=(WORD32)var1<<8;
1154 /* var2 is an unsigned variable, var1 contains signed guard*/
1155 /* bits. */
1156 var2= ((WORD32)(denom)/(num)); //omaps00090550
1157 K = (var1+var2)<<1; /* F1.39 / F12.20 = F13.19 */
1158 /* F13.19 << 1 = F12.20 */
1159
1160 /* Clipping of the Kalman gain */
1161 if (K>=C_thr_K)
1162 K=C_thr_K;
1163
1164 /*******************************************************/
1165 /* P=(1-K)*P = 0.8 * 0.5 at maximum */
1166 /*******************************************************/
1167 /* Perform a positive variable F12.20 multiplication by*/
1168 /* positive variable F12.20 */
1169 var_16=(WORD16)(1048576L-K); /* acclow(1-K) = F12.20 */
1170 guard1=0; /* positive variable */
1171 var1=UMult_40b(P,var_16,&guard1);
1172 var_16=(WORD16)((1048576L-K)>>16);
1173 /* acchigh(1-K) = F12.20 */
1174 var2=P*var_16; /* var2 = 0x80000 * 0xc */
1175 /* at maximum, so result */
1176 /* is 32 bits WORD32 and */
1177 /* equal 0x600000 */
1178 /* extension of var2 to a 40 bits variable : var2<<16 */
1179 guard2=(WORD16)((WORD32)var2>>16);
1180 guard1guard2=((WORD32)guard1<<16) |((WORD32) guard2&0x0000FFFFL);
1181 var2=var2<<16;
1182 var_32=Add_40b(guard1guard2,var1,var2,&guardout);
1183 /* var_32 (F8.40) >> 16 = F8.24 */
1184 LGuard=(WORD32)guardout<<16;
1185 var1=(UWORD32)var_32>>16;
1186 /* var_32 >> 4 = F12.20 */
1187 P=(var1+LGuard)>>4;
1188
1189 Phi_32=Mult_40b(l1_config.params.psi_st_32,Psi_quant[0],&guardout);
1190 /* F0.32 * F13.3 = F5.35 */
1191 LGuard=(WORD32)guardout<<16; /* var_32 (F5.35) >> 16 */
1192 /* F13.19 */
1193 var1=(UWORD32)Phi_32>>16;
1194 Phi_32=Psi-(LGuard+var1); /* F13.19 */
1195
1196 /*Phi=angle-Phi_32*/
1197 Phi_32=((WORD32)angle<<4)-Phi_32;
1198 /* F1.15 * 4 = F13.19 */
1199 Phi=(WORD16)(Phi_32>>4); /* F17.15 */
1200 /*var1=K*Phi F12.20 * F1.15 = 13.35 */
1201 guard1=0;
1202 var1=Mult_40b(K,Phi,&guard1);
1203 /* var1 (F13.35) >> 16 */
1204 /* F13.19 */
1205 LGuard=(WORD32)guard1<<16;
1206 var1=(UWORD32)var1>>16;
1207 Psi+=var1+LGuard;
1208 } else {
1209 /************************************/
1210 /* Prediction */
1211 /************************************/
1212
1213 // Only predict in dedicated mode
1214 // NO prediction in idle mode
1215 // l1a_l1s_com.dedic_set.SignalCode = NULL
1216 if ( (l1_config.params.rgap_algo != 0) &&
1217 ((l1_mode==CON_EST_MODE2)||(l1_mode==DEDIC_MODE)
1218 #if L1_GPRS
1219 || l1_mode==PACKET_TRANSFER_MODE
1220 #endif
1221 ))
1222 {
1223
1224 /* Prediction of psi during reception gaps */
1225 B_Count+= *frame_count;
1226
1227 /* Predict psi ONLY when we have sufficient measurements available */
1228 /* If we don't have enough measurements we don't do anything (= 0th order estimation)*/
1229
1230 // Was the consecutive bad SNRs threshold value exceeded?
1231 if (B_Count>= l1_config.params.rgap_bad_snr_count_B) {
1232
1233 // Predict with 0th order estimation is the default
1234
1235 // Predict with 1st order estimation
1236 if (l1_config.params.rgap_algo >= 1)
1237 Psi += ((quant_avg * (l1_config.params.rgap_bad_snr_count_B))/(C_MSIZE));
1238
1239 B_Count= B_Count - l1_config.params.rgap_bad_snr_count_B;
1240
1241 // Indicate by raising first_avg flag that a reception gap has occurred
1242 // I.e. the psi_avg table must be reinitialised after leaving reception gap
1243 first_avg = 1;
1244
1245 // Counters in estimation part must also be reset
1246 M_Count = 0;
1247 good_snr = 0;
1248 psi_avg[0] = 0;
1249 }
1250 }
1251 }
1252
1253 /* Quantize psi value */
1254
1255 var_32=Mult_40b(Psi,l1_config.params.psi_st_inv,&guardout);
1256 /* F13.19 * C = F13.19 */
1257
1258 #if(RF_FAM == 61)
1259 /* In order to implement the NINT function for a F13.3, we check */
1260 /* if var_32 + 0.5*2**18 is a multiple of 2**18 */
1261 quotient=(WORD16)((WORD32)(((WORD32)(var_32+(1<<17)))/(1<<18)));
1262 var_16=quotient*4;
1263 #else
1264 /* In order to implement the NINT function for a F13.3, we check */
1265 /* if var_32 + 0.5*2**19 is a multiple of 2**19 */
1266 quotient=(WORD16)((WORD32)(((WORD32)(var_32+(1<<18)))/(1<<19)));
1267 var_16=quotient*8;
1268 #endif
1269 if (var_16>C_max_step)
1270 Psi_quant[C_N_del]=C_max_step;
1271 else
1272 if(var_16<C_min_step)
1273 Psi_quant[C_N_del]=C_min_step;
1274 else Psi_quant[C_N_del]=var_16; /* F13.3 */
1275
1276
1277 }/*end AFC_CLOSE_LOOP*/
1278 } /* end else AFC_INIT*/
1279
1280 *frame_count = 0;
1281 //Locosto
1282 // return(Psi_quant[C_N_del]>>3); /* F16.0 */
1283 return(((CONVERT_PSI_QUANT(Psi_quant[C_N_del]))&0x3FFF)); /* F16.0 to 14.2 or 13.3 */
1284 } /* end case algo 3 */
1285 #endif
1286
1287 #if (VCXO_ALGO == 1)
1288 default:
1289 return 0;
1290 //omaps00090550 break;
1291 } // end of Switch
1292 #endif
1293
1294 } /* end l1ctl_afc */
1295
1296
1297 /************************************/
1298 /* Automatic timing control (TOA) */
1299 /************************************/
1300
1301 #if (TOA_ALGO == 2)
1302
1303 #define TOA_DEBUG_ENABLE 0
1304
1305
1306 #if (TOA_DEBUG_ENABLE == 1)
1307
1308 #define TOA_MAKE_ZERO 0
1309
1310 #define TOA_LOG_BUFFER_LENGTH 4096
1311
1312 typedef struct
1313 {
1314 UWORD16 SNR_val;
1315 UWORD16 TOA_val;
1316 UWORD16 l1_mode;
1317 UWORD16 toa_frames_counter;
1318 UWORD16 fn_mod42432;
1319 }T_TOA_log_debug;
1320
1321
1322 T_TOA_log_debug toa_log_debug[TOA_LOG_BUFFER_LENGTH];
1323 UWORD32 toa_log_index;
1324
1325 UWORD32 toa_make_zero_f;
1326
1327 #endif
1328
1329 /*-------------------------------------------------------*/
1330 /* l1ctl_toa() */
1331 /*-------------------------------------------------------*/
1332 /* Parameters : */
1333 /* Return : */
1334 /* Functionality : */
1335 /*-------------------------------------------------------*/
1336
1337 WORD16 l1ctl_toa (UWORD8 phase, UWORD32 l1_mode, UWORD16 SNR_val, UWORD16 TOA_val)
1338 {
1339 WORD16 TOA_period_len = TOA_PERIOD_LEN [l1_mode];
1340 WORD16 TOA_SHIFT=ISH_INVALID;
1341 UWORD16 cumul_abs;
1342 WORD16 cumul_sign;
1343 WORD32 prod_tmp, div_tmp,prod_sign;
1344 WORD32 toa_update_flag=0;
1345 WORD16 cumul;
1346 UWORD16 cumul_counter;
1347 #if (NEW_TOA_ALGO == 1)
1348 UWORD16 Trans_active;
1349 static WORD16 cumul_noTrans =0;
1350 static UWORD16 period_counter_noTrans =0;
1351
1352 if ((l1_mode==CON_EST_MODE2)||(l1_mode==DEDIC_MODE)
1353 #if L1_GPRS
1354 || l1_mode==PACKET_TRANSFER_MODE
1355 #endif
1356 )
1357 Trans_active=TRUE;
1358 else Trans_active=FALSE;
1359 #endif
1360 if (phase==TOA_INIT)
1361 {
1362 #if (NEW_TOA_ALGO == 1)
1363 cumul_noTrans =0;
1364 period_counter_noTrans =0;
1365 #endif
1366
1367 l1s.toa_var.toa_frames_counter=0;
1368 l1s.toa_var.toa_accumul_counter=0;
1369 l1s.toa_var.toa_accumul_value=0;
1370 #if (TOA_DEBUG_ENABLE == 1)
1371 toa_log_index = 0;
1372 #if (TOA_MAKE_ZERO == 1)
1373 toa_make_zero_f = 1;
1374 #else
1375 toa_make_zero_f = 0;
1376 #endif
1377 #endif
1378
1379 return (TOA_SHIFT);
1380 }
1381
1382 cumul = l1s.toa_var.toa_accumul_value;
1383 cumul_counter = l1s.toa_var.toa_accumul_counter;
1384
1385 #if (TOA_DEBUG_ENABLE == 1)
1386 toa_log_debug[toa_log_index].SNR_val = SNR_val;
1387 toa_log_debug[toa_log_index].TOA_val = TOA_val;
1388 toa_log_debug[toa_log_index].l1_mode = l1_mode;
1389 toa_log_debug[toa_log_index].toa_frames_counter = l1s.toa_var.toa_frames_counter;
1390 toa_log_debug[toa_log_index].fn_mod42432 = l1s.actual_time.fn_mod42432;
1391
1392 toa_log_index++;
1393 if(toa_log_index == TOA_LOG_BUFFER_LENGTH)
1394 {
1395 toa_log_index = 0;
1396 }
1397 #endif /* #if (TOA_DEBUG_ENABLE == 1) */
1398
1399 #if (TRACE_TYPE == 5)
1400 trace_toa_sim_ctrl(SNR_val, TOA_val, l1_mode, l1s.toa_var.toa_frames_counter,
1401 l1s.toa_var.toa_accumul_counter, l1s.toa_var.toa_accumul_value);
1402 #endif
1403
1404 l1s.toa_var.toa_frames_counter++;
1405
1406 {
1407 /* Fix for TOA */
1408 #define DSP_CALC_NO_TABS_HO 0x3CA4
1409
1410 UWORD16 *toa_ho_fix;
1411 toa_ho_fix=(UWORD16 *)API_address_dsp2mcu(DSP_CALC_NO_TABS_HO);
1412
1413 if ((TOA_val >= 22) || (TOA_val <= 6)) {
1414 *toa_ho_fix = 1;
1415 }
1416
1417 if (*toa_ho_fix == 1) {
1418 if((TOA_val <= 18) && (TOA_val >= 10)) {
1419 *toa_ho_fix = 0;
1420 }
1421 } else {
1422 *toa_ho_fix = 0;
1423 }
1424 }
1425
1426
1427 #if (NEW_TOA_ALGO == 1)
1428 if (Trans_active)
1429 {
1430 #endif
1431 if (SNR_val>= L1_TOA_SNR_THRESHOLD)
1432 {
1433 cumul_counter++;
1434
1435 prod_tmp = L1_TOA_LAMBDA * cumul;
1436 prod_tmp = prod_tmp + ((0x00004000)); // basically for rounding
1437 div_tmp = ((prod_tmp >> 15) & (0x0000FFFF));
1438 cumul = div_tmp;
1439
1440 // implemented below is
1441 // cumul = cumul + (L1_TOA_ONE_MINUS_LAMBDA * signum(TOA_Val - L1_TOA_EXPECTED_TOA))
1442 if(TOA_val > L1_TOA_EXPECTED_TOA) {
1443 cumul = cumul + L1_TOA_ONE_MINUS_LAMBDA;
1444 }
1445 else if (TOA_val < L1_TOA_EXPECTED_TOA) {
1446 cumul = cumul - L1_TOA_ONE_MINUS_LAMBDA;
1447 }
1448 } // End if SNR_val
1449
1450 if(l1s.toa_var.toa_update_flag == TRUE)
1451 {
1452 toa_update_flag = 1;
1453 }
1454
1455 if (toa_update_flag)
1456 {
1457 cumul_sign = (cumul>0)? 1: -1;
1458 cumul_abs = cumul_sign*cumul;
1459 if(cumul_counter <= 5)
1460 {
1461 TOA_SHIFT = (cumul_abs<=L1_TOA_THRESHOLD_15)? 0: cumul_sign;
1462 }
1463 else if(cumul_counter == 6)
1464 {
1465 TOA_SHIFT = (cumul_abs<=L1_TOA_THRESHOLD_20)? 0: cumul_sign;
1466 }
1467 else if(cumul_counter == 7)
1468 {
1469 TOA_SHIFT = (cumul_abs<=L1_TOA_THRESHOLD_25)? 0: cumul_sign;
1470 }
1471 else if(cumul_counter >= 8)
1472 {
1473 TOA_SHIFT = (cumul_abs<=L1_TOA_THRESHOLD_30)? 0: cumul_sign;
1474 }
1475 #if (TRACE_TYPE==1) || (TRACE_TYPE==4)
1476 trace_info.toa_trace_var.toa_accumul_value = cumul;
1477 trace_info.toa_trace_var.toa_accumul_counter = cumul_counter;
1478 trace_info.toa_trace_var.toa_frames_counter = l1s.toa_var.toa_frames_counter;
1479 #endif
1480
1481 cumul = 0;
1482 cumul_counter = 0;
1483 l1s.toa_var.toa_frames_counter = 0;
1484 l1s.toa_var.toa_update_flag = FALSE;
1485
1486 #if (TOA_DEBUG_ENABLE == 1)
1487 #if (TOA_MAKE_ZERO == 1)
1488 if (toa_make_zero_f == 1)
1489 {
1490 TOA_SHIFT=0;
1491 }
1492 #endif /*#if (TOA_DEBUG_ENABLE == 1)*/
1493 #endif /*#if (TOA_MAKE_ZERO == 1)*/
1494
1495 } // end of if toa_update_flag
1496 #if (NEW_TOA_ALGO == 1)
1497
1498 }
1499
1500 else
1501 {
1502 period_counter_noTrans++;
1503
1504 if (SNR_val>= L1_TOA_SNR_THRESHOLD)
1505 {
1506 cumul_noTrans = cumul_noTrans + TOA_val - L1_TOA_EXPECTED_TOA;
1507
1508 } // End if SNR_val
1509
1510 if (l1s.toa_var.toa_update_flag == TRUE)
1511 {
1512 switch (period_counter_noTrans)
1513 {
1514 case 2:
1515 if (cumul_noTrans>=0)
1516 TOA_SHIFT = (cumul_noTrans+1) >>1 ;
1517 else
1518 TOA_SHIFT = (cumul_noTrans) >>1 ;
1519 break;
1520 case 3: /* Not fully accurate rounding*/
1521 if (cumul_noTrans>=0)
1522 TOA_SHIFT = (cumul_noTrans+2)/3 ;
1523 else
1524 TOA_SHIFT = (cumul_noTrans-2)/3 ;
1525 break;
1526 case 4:
1527 if (cumul_noTrans>=0)
1528 TOA_SHIFT = (cumul_noTrans+2) >>2 ;
1529 else
1530 TOA_SHIFT = (cumul_noTrans+1) >>2 ;
1531 break;
1532 default:
1533 TOA_SHIFT = cumul_noTrans;
1534 break;
1535 } /* end switch*/
1536
1537 if (TOA_SHIFT>8)
1538 TOA_SHIFT =8;
1539 if (TOA_SHIFT<-8)
1540 TOA_SHIFT =-8;
1541
1542 #if (TRACE_TYPE==1) || (TRACE_TYPE==4)
1543 trace_info.toa_trace_var.toa_accumul_value = cumul_noTrans;
1544 trace_info.toa_trace_var.toa_accumul_counter = period_counter_noTrans;
1545 trace_info.toa_trace_var.toa_frames_counter = period_counter_noTrans;
1546 #endif
1547
1548 cumul_noTrans = 0;
1549 period_counter_noTrans = 0;
1550 l1s.toa_var.toa_update_flag = FALSE;
1551 #if (TOA_DEBUG_ENABLE == 1)
1552 #if (TOA_MAKE_ZERO == 1)
1553 if (toa_make_zero_f == 1)
1554 {
1555 TOA_SHIFT=0;
1556 }
1557 #endif /*#if (TOA_DEBUG_ENABLE == 1)*/
1558 #endif /*#if (TOA_MAKE_ZERO == 1)*/
1559
1560 } // end if update_flag
1561 }
1562 #endif
1563 // error a TOA is waiting to be updated in the TPU and will be erased
1564 #if (TRACE_TYPE==1) || (TRACE_TYPE==4)
1565 if (l1s.toa_var.toa_shift != ISH_INVALID)
1566 {
1567 l1_trace_toa_not_updated (); // should not occur!!
1568 }
1569 #endif
1570
1571 if (TOA_SHIFT != ISH_INVALID) // new TOA => set the mask frames
1572 {
1573 // Set mask counter to 2 (2 frames masked).
1574 l1s.toa_var.toa_snr_mask = 2;
1575 }
1576
1577 l1s.toa_var.toa_accumul_value = cumul;
1578 l1s.toa_var.toa_accumul_counter = cumul_counter;
1579
1580 return(TOA_SHIFT);
1581
1582 } // l1ctl_toa
1583
1584
1585 #else
1586 /*-------------------------------------------------------*/
1587 /* l1ctl_toa_update() */
1588 /*-------------------------------------------------------*/
1589 /* Parameters : */
1590 /* Return : */
1591 /* Functionality : */
1592 /*-------------------------------------------------------*/
1593 WORD16 l1ctl_toa_update(UWORD32 *TOASP, UWORD32 l1_mode)
1594 {
1595 static UWORD16 Old_TOA_estimated=12; //unit is Qbit
1596 UWORD32 TOAMAX;
1597 WORD16 IZW,ISH,i;
1598 UWORD32 TOA_estimated=0; //unit is Qbit
1599 UWORD16 Trans_active;
1600
1601 if ((l1_mode==CON_EST_MODE2)||(l1_mode==DEDIC_MODE)
1602 #if L1_GPRS
1603 || l1_mode==PACKET_TRANSFER_MODE
1604 #endif
1605 )
1606 Trans_active=TRUE;
1607 else Trans_active=FALSE;
1608
1609 /* TOA offset computation and clock adjustement */
1610 TOAMAX=0;
1611 for (i=1;i<TOA_HISTO_LEN;i++)
1612 {
1613 if (TOASP[i]>TOAMAX)
1614 TOAMAX=TOASP[i];
1615 }
1616 TOAMAX >>= C_RED;
1617 i=1;IZW=0;
1618 while (i<TOA_HISTO_LEN && IZW==0)
1619 {
1620 if (TOASP[i]>=TOAMAX)
1621 IZW=i;
1622 i++;
1623 }
1624
1625 /* Estimated TOA calculation */
1626 if (TOASP[IZW-1]<(2*TOAMAX/3))
1627 {
1628 TOA_estimated=IZW;
1629 TOA_estimated *= 4; // unit in QBit
1630 }
1631 else
1632 {
1633 UWORD32 TOA_divisor = 0;
1634 TOA_estimated=(TOASP[IZW]*IZW)+(TOASP[IZW-1]*(IZW-1)>>C_GEW);
1635 TOA_estimated *= 8; //F13.3 in order to have qBit precision
1636 TOA_divisor = TOASP[IZW]+(TOASP[IZW-1] >> C_GEW);
1637 if (TOA_divisor!=0)
1638 {
1639 TOA_estimated/= TOASP[IZW]+(TOASP[IZW-1] >> C_GEW);
1640 TOA_estimated /= 2; // unit in QBit ("/8" then "*4" = "/2")
1641 }
1642 else
1643 {
1644 TOA_estimated = 0;
1645 }
1646 }
1647
1648 if (Trans_active)
1649 TOA_estimated=(TOA_estimated+(Old_TOA_estimated+4)) / 2;
1650
1651 /* Offset calculation*/
1652 if (TOA_estimated>=17 || TOA_estimated<=15)
1653 ISH=TOA_estimated - 16;
1654 else
1655 ISH=0;
1656
1657 if (Trans_active)
1658 {
1659 if (ISH>1) ISH=1;
1660 if (ISH<-1) ISH=-1;
1661 }
1662 else
1663 {
1664 if (ISH>8) ISH=8;
1665 if (ISH<-8) ISH=-8;
1666 }
1667
1668 Old_TOA_estimated = TOA_estimated - ISH - 4;
1669
1670
1671 return (ISH);
1672 }
1673
1674 /*-------------------------------------------------------*/
1675 /* l1ctl_toa() */
1676 /*-------------------------------------------------------*/
1677 /* Parameters : */
1678 /* Return : */
1679 /* Functionality : generate an histogram of TOA weighted */
1680 /* with SNR */
1681 /*-------------------------------------------------------*/
1682 WORD16 l1ctl_toa(UWORD8 phase, UWORD32 l1_mode, UWORD16 SNR_val, UWORD16 TOA_val, BOOL *toa_update, UWORD16 *toa_period_count
1683 #if (FF_L1_FAST_DECODING == 1)
1684 , UWORD8 skipped_values
1685 #endif
1686 )
1687 {
1688 // xSignalHeaderRec *msg;
1689 UWORD16 i;
1690 WORD16 TOA_period_len = TOA_PERIOD_LEN[l1_mode];
1691 static UWORD32 histo[TOA_HISTO_LEN];
1692 static WORD16 period_counter=0;
1693 UWORD32 SNR_ZW;
1694 WORD16 ISH=ISH_INVALID;
1695
1696 UWORD8 histo_center;
1697
1698 #if 0
1699 if ((l1_mode==CON_EST_MODE2)||(l1_mode==DEDIC_MODE))
1700 histo_center=4;
1701 else
1702 histo_center=5;
1703 #else
1704 histo_center=4;
1705 #endif
1706
1707
1708 if (phase==TOA_INIT)
1709 {
1710 period_counter=0;
1711
1712 for (i=0;i<TOA_HISTO_LEN;i++)
1713 histo[i]=0;
1714 histo[histo_center]=128; //F6.10
1715
1716 return(ISH);
1717 }
1718 #if (FF_L1_FAST_DECODING == 1)
1719 /* Manage any missing bursts due to fast decoding */
1720 period_counter += skipped_values;
1721 #endif
1722
1723 period_counter++;
1724 /* Filter update */
1725 if (SNR_val>=C_SNRGR)
1726 {
1727 if (SNR_val>C_SNR_THR)
1728 SNR_ZW=C_SNR_THR;
1729 else
1730 SNR_ZW=SNR_val;
1731 histo[TOA_val+1]+=SNR_ZW; /* if TOA=0 histo[1]++ */
1732 /* if TOA=1 histo[2]++ */
1733 /* ... */
1734 /* if TOA=9 histo[10]++ */
1735 /* histo[0] is reserved for computation */
1736 }
1737
1738 #if L1_GPRS
1739 if (l1_mode==PACKET_TRANSFER_MODE)
1740 {
1741 if (*toa_update)
1742 {
1743 // Get ISH.
1744 ISH = l1ctl_toa_update(histo, l1_mode);
1745
1746 //reset TOA period length counter
1747 period_counter=0;
1748
1749 //reset histogram
1750 for (i=0;i<TOA_HISTO_LEN;i++)
1751 histo[i]=0;
1752 histo[histo_center]=128; //F6.10
1753
1754 *toa_update = FALSE; // reset TOA update flag
1755 *toa_period_count = 0; // reset TOA period counter
1756 }
1757 }
1758 else
1759 #endif
1760 if (period_counter>=TOA_period_len)
1761 // It is time to compute a new ISH and to reset the histogram.
1762 // Rem: ">=" is very important since a "l1 mode" change can give
1763 // a "TOA_period_len" smaller than the previous one an
1764 // therefore a "period_counter" may be already higher than
1765 // the new "TOA_period_len".
1766 {
1767 // Get ISH.
1768 ISH = l1ctl_toa_update(histo, l1_mode);
1769
1770 //reset TOA period length counter
1771 period_counter=0;
1772
1773 //reset histogram
1774 for (i=0;i<TOA_HISTO_LEN;i++)
1775 histo[i]=0;
1776 histo[histo_center]=128; //F6.10
1777 }
1778
1779 // error a TOA is waiting to be updated in the TPU and will be erased
1780 #if (TRACE_TYPE==1) || (TRACE_TYPE==4)
1781 if (l1s.toa_shift != ISH_INVALID)
1782 {
1783 l1_trace_toa_not_updated(); // should not occur !!
1784 }
1785 #endif
1786
1787 if (ISH != ISH_INVALID) // new TOA => set the mask frames
1788 {
1789 // Set mask counter to 2 (2 frames masked).
1790 l1s.toa_snr_mask = 2;
1791 }
1792
1793 return(ISH);
1794 }
1795 #endif
1796
1797 /*-------------------------------------------------------*/
1798 /* l1ctl_txpwr() */
1799 /*-------------------------------------------------------*/
1800 /* Parameters : */
1801 /* Return : */
1802 /* Functionality : */
1803 /*-------------------------------------------------------*/
1804 UWORD8 l1ctl_txpwr(UWORD8 target_txpwr, UWORD8 current_txpwr)
1805 {
1806 if(target_txpwr > current_txpwr)
1807 {
1808 current_txpwr ++; // Increase TX power by 2 dB.
1809 }
1810 else
1811 if(target_txpwr < current_txpwr)
1812 {
1813 current_txpwr --; // Decrease TX power by 2 dB.
1814 }
1815
1816 return(current_txpwr);
1817 }
1818
1819
1820 /************************************/
1821 /* Automatic Gain Control */
1822 /************************************/
1823 /*-------------------------------------------------------*/
1824 /* l1ctl_encode_delta1() */
1825 /*-------------------------------------------------------*/
1826 /* Parameters : */
1827 /* Return : */
1828 /* Functionality : */
1829 /*-------------------------------------------------------*/
1830 #if(L1_FF_MULTIBAND == 0)
1831 WORD8 l1ctl_encode_delta1(UWORD16 radio_freq)
1832 {
1833 switch(l1_config.std.id)
1834 {
1835 case GSM:
1836 case GSM_E:
1837 case DCS1800:
1838 case PCS1900:
1839 case GSM850:
1840 return(l1_config.std.cal_freq1_band1);
1841 case DUAL:
1842 case DUALEXT:
1843 case DUAL_US:
1844 if(radio_freq >= l1_config.std.first_radio_freq_band2)
1845 return(l1_config.std.cal_freq1_band2);
1846 else
1847 return(l1_config.std.cal_freq1_band1);
1848 }
1849 return 0;//omaps00090550
1850
1851 }
1852 #endif
1853 /*-------------------------------------------------------*/
1854 /* l1ctl_encode_lna() */
1855 /*-------------------------------------------------------*/
1856 /* Parameters : */
1857 /* Return : */
1858 /* Functionality : */
1859 /*-------------------------------------------------------*/
1860 #if (L1_FF_MULTIBAND == 0)
1861 void l1ctl_encode_lna( UWORD8 input_level,
1862 UWORD8 *lna_state,
1863 UWORD16 radio_freq)
1864 {
1865
1866 /*** LNA Hysteresis is implemented as following :
1867
1868 |
1869 On|---<>----+-------+
1870 | | |
1871 LNA | | |
1872 | ^ v
1873 | | |
1874 | | |
1875 Off| +-------+----<>-----
1876 +--------------------------------
1877 50 40 30 20 input_level /-dBm
1878 THR_HIGH THR_LOW ***/
1879
1880
1881
1882
1883
1884 if(((l1_config.std.id == DUAL) || (l1_config.std.id == DUALEXT) ||(l1_config.std.id == DUAL_US)) &&
1885 (radio_freq >= l1_config.std.first_radio_freq_band2))
1886 {
1887 if ( input_level > l1_config.std.lna_switch_thr_high_band2 ) // < -40dBm ?
1888 {
1889 *lna_state = LNA_ON; // lna_off = FALSE
1890 }
1891 else if ( input_level < l1_config.std.lna_switch_thr_low_band2 ) // > -30dBm ?
1892 {
1893 *lna_state = LNA_OFF; // lna off = TRUE
1894 }
1895 }
1896 else
1897 {
1898 if ( input_level > l1_config.std.lna_switch_thr_high_band1 ) // < -40dBm ?
1899 {
1900 *lna_state = LNA_ON; // lna_off = FALSE
1901 }
1902 else if ( input_level < l1_config.std.lna_switch_thr_low_band1 ) // > -30dBm ?
1903 {
1904 *lna_state = LNA_OFF; // lna off = TRUE
1905 }
1906 }
1907
1908 }
1909
1910 #endif
1911
1912 /*-------------------------------------------------------*/
1913 /* l1ctl_csgc() */
1914 /*-------------------------------------------------------*/
1915 /* Description: */
1916 /* ============ */
1917 /* If we are running the first pass of a measurement */
1918 /* session, we use the HIGH_AGC default agc setting to */
1919 /* compute the input level from the measured power from */
1920 /* the DSP. If this input level is saturated we set a */
1921 /* saturation flag, otherwise we validate the measure and*/
1922 /* store, for the considered carrier, the input level. */
1923 /* When all the carriers have been scanned and some have */
1924 /* been flagged "saturated", we measure them with the */
1925 /* LOW_AGC agc setting, then store, for the considered */
1926 /* carrier, the input level. */
1927 /*-------------------------------------------------------*/
1928 UWORD8 l1ctl_csgc(UWORD8 pm, UWORD16 radio_freq)
1929 {
1930 WORD16 current_IL, current_calibrated_IL =0; //omaps00090550
1931 WORD8 delta1_freq, delta2_freq;
1932 WORD16 delta_drp_gain=0;
1933 UWORD32 index;
1934 UWORD16 g_magic;
1935 UWORD16 arfcn;
1936 UWORD16 dco_algo_ctl_pw_temp = 0;
1937 UWORD8 if_ctl = 0;
1938 #if (RF_RAM == 61) && (CODE_VERSION != SIMULATION)
1939 UWORD8 if_threshold = C_IF_ZERO_LOW_THRESHOLD_GSM;
1940 #endif
1941
1942 #if (L1_FF_MULTIBAND == 0)
1943
1944 // initialize index
1945 index = radio_freq - l1_config.std.radio_freq_index_offset;
1946
1947 #else
1948
1949 index =
1950 l1_multiband_radio_freq_convert_into_operative_radio_freq(radio_freq);
1951
1952 #endif /*if(L1_FF_MULTIBAND == 0)*/
1953
1954 delta1_freq = l1ctl_encode_delta1(radio_freq);
1955 delta2_freq = l1ctl_encode_delta2(radio_freq);
1956
1957 g_magic = l1ctl_get_g_magic(radio_freq);
1958 #if (L1_FF_MULTIBAND == 0)
1959 arfcn = Convert_l1_radio_freq(radio_freq);
1960 #endif
1961
1962 if (l1a_l1s_com.full_list.meas_1st_pass_read)
1963 {
1964 // We validate or not power measure (pm) for the considered carrier
1965 // with measurement achieved with HIGH_AGC setting. We are working
1966 // with non calibrated IL to avoid saturation
1967 #if(RF_FAM == 61)
1968 #if (CODE_VERSION != SIMULATION)
1969
1970 #if (PWMEAS_IF_MODE_FORCE == 0)
1971 cust_get_if_dco_ctl_algo(&dco_algo_ctl_pw_temp, &if_ctl, (UWORD8) L1_IL_INVALID ,
1972 0,
1973 radio_freq,if_threshold);
1974 #else
1975 if_ctl = IF_120KHZ_DSP;
1976 dco_algo_ctl_pw_temp = DCO_IF_0KHZ;
1977 #endif
1978
1979 #if (L1_FF_MULTIBAND == 0)
1980 delta_drp_gain = drp_gain_correction(arfcn, LNA_ON, (l1_config.params.high_agc << 1)); // F7.1 format
1981 #else
1982 delta_drp_gain = drp_gain_correction(radio_freq, LNA_ON, (l1_config.params.high_agc << 1)); // F7.1 format
1983 #endif // MULTIBAND == 0 else
1984
1985 if(if_ctl == IF_100KHZ_DSP){
1986 delta_drp_gain += SCF_ATTENUATION_LIF_100KHZ;
1987 }
1988 else{ /* i.e. if_ctl = IF_120KHZ_DSP*/
1989 delta_drp_gain += SCF_ATTENUATION_LIF_120KHZ;
1990 }
1991
1992 #endif
1993 #endif
1994 if (0==pm) // Check and filter illegal pm value by using last valid IL
1995 current_IL = (WORD16)(l1a_l1s_com.last_input_level[index].input_level);
1996 else
1997 {
1998 #if TESTMODE
1999 if (!l1_config.agc_enable)
2000 current_IL = (WORD16)(-(pm - ( (l1_config.tmode.rx_params.agc << 1) - delta_drp_gain ) - g_magic));
2001 else
2002 #endif
2003 current_IL = (WORD16)(-(pm - ( (l1_config.params.high_agc <<1) - delta_drp_gain) - g_magic));
2004 // for array index purpose, we work with positive IL
2005
2006 }
2007
2008 // NOTE: lna_value do not appear in this formula because lna is ALWAYS ON for
2009 // ---- this algorithm, so lna_value=lna_off*l1_config.params.lna_att_gsm=0
2010
2011 if ((current_IL<l1_config.params.high_agc_sat_thr) // Warning : we are working with positive IL
2012 // for IL_2_AGC_xx index purpose.
2013 #if TESTMODE
2014 && (l1_config.agc_enable)
2015 #endif
2016 )
2017 {
2018 // pm is saturated so measure is not valid
2019 l1a_l1s_com.full_list.nbr_sat_carrier_ctrl++;
2020 l1a_l1s_com.full_list.nbr_sat_carrier_read++;
2021 l1a_l1s_com.full_list.sat_flag[l1a_l1s_com.full_list.next_to_read] = 1;
2022 }
2023 else
2024 {
2025 current_calibrated_IL = current_IL - delta1_freq - delta2_freq;
2026
2027 #if TESTMODE
2028 // When running with fixed AGC setting saturated carriers may occur:
2029 // protect against negative IL;
2030 if ((!l1_config.agc_enable) && (current_calibrated_IL < 0))
2031 {
2032 current_calibrated_IL=0;
2033 current_IL=0;
2034 }
2035 #endif
2036
2037 // Protect IL stores against overflow
2038 if (current_calibrated_IL>INDEX_MAX)
2039 current_calibrated_IL=INDEX_MAX;
2040 if (current_IL>INDEX_MAX)
2041 current_IL=INDEX_MAX;
2042
2043 // we validate the measure and save input_level and lna_off fields.
2044 l1ctl_encode_lna((UWORD8)(current_calibrated_IL>>1),
2045 &(l1a_l1s_com.last_input_level[index].lna_off),
2046 radio_freq);
2047
2048 l1a_l1s_com.last_input_level[index].input_level = (UWORD8)current_IL;
2049 l1a_l1s_com.full_list.sat_flag[l1a_l1s_com.full_list.next_to_read] = 0;
2050 }
2051 }
2052 else // 2nd pass if any.
2053 {
2054 // we validate the measure and save input_level and lna_off(always 0)
2055 // fields.
2056 #if(RF_FAM == 61)
2057 #if (CODE_VERSION != SIMULATION)
2058 cust_get_if_dco_ctl_algo(&dco_algo_ctl_pw_temp, &if_ctl, (UWORD8) L1_IL_INVALID,
2059 0,radio_freq,if_threshold);
2060 #if (L1_FF_MULTIBAND == 0)
2061 delta_drp_gain = drp_gain_correction(arfcn, LNA_ON, (l1_config.params.low_agc << 1)); // F7.1 format
2062 #else
2063 delta_drp_gain = drp_gain_correction(radio_freq, LNA_ON, (l1_config.params.low_agc << 1)); // F7.1 format
2064 #endif
2065 if(if_ctl == IF_100KHZ_DSP){
2066 delta_drp_gain += SCF_ATTENUATION_LIF_100KHZ;
2067 }
2068 else{ /* i.e. if_ctl = IF_120KHZ_DSP*/
2069 delta_drp_gain += SCF_ATTENUATION_LIF_120KHZ;
2070 }
2071 #endif
2072 #endif
2073
2074
2075 if (0==pm) // Check and filter illegal pm value by using last valid IL
2076 current_IL = (WORD16)(l1a_l1s_com.last_input_level[index].input_level);
2077 else
2078 current_IL = (WORD16)(-(pm - ( (l1_config.params.low_agc << 1) - delta_drp_gain ) - g_magic));
2079
2080 current_calibrated_IL = current_IL - delta1_freq - delta2_freq;
2081
2082 // Protect IL stores against overflow
2083 if (current_calibrated_IL>INDEX_MAX)
2084 current_calibrated_IL=INDEX_MAX;
2085 if (current_IL>INDEX_MAX)
2086 current_IL=INDEX_MAX;
2087
2088 l1ctl_encode_lna((UWORD8)(current_calibrated_IL>>1),
2089 &(l1a_l1s_com.last_input_level[index].lna_off),
2090 radio_freq);
2091
2092 l1a_l1s_com.last_input_level[index].input_level = (UWORD8)current_IL;
2093
2094 l1a_l1s_com.full_list.sat_flag[l1a_l1s_com.full_list.next_to_read] = 0;
2095 }
2096
2097 return((UWORD8)current_calibrated_IL);
2098 }
2099
2100 /*-------------------------------------------------------*/
2101 /* l1ctl_pgc() */
2102 /*-------------------------------------------------------*/
2103 /* Description : For a given radio_freq, last_known_agc is */
2104 /* ============ based on a prior knowledge (the last */
2105 /* stored input_level for the considered */
2106 /* carrier). From the power measurement on */
2107 /* this carrier (pm), we update the */
2108 /* input_level for this carrier, for the */
2109 /* next task to control. */
2110 /*-------------------------------------------------------*/
2111 UWORD8 l1ctl_pgc(UWORD8 pm, UWORD8 last_known_il,
2112 UWORD8 lna_off, UWORD16 radio_freq)
2113 {
2114 WORD32 last_known_agc;
2115 WORD32 current_IL, current_calibrated_IL;
2116 WORD8 delta1_freq, delta2_freq;
2117 WORD16 delta_drp_gain=0;
2118 WORD32 index, lna_value;
2119 UWORD16 arfcn;
2120 UWORD16 dco_algo_ctl_pw_temp = 0;
2121 UWORD8 if_ctl = 0;
2122 #if (RF_RAM == 61) && (CODE_VERSION != SIMULATION)
2123 UWORD8 if_threshold = C_IF_ZERO_LOW_THRESHOLD_GSM;
2124 #endif
2125
2126 #if (L1_FF_MULTIBAND == 0)
2127
2128 // initialize index
2129 index = radio_freq - l1_config.std.radio_freq_index_offset;
2130
2131 #else
2132
2133 index = l1_multiband_radio_freq_convert_into_operative_radio_freq(radio_freq);
2134
2135 #endif // #if (L1_FF_MULTIBAND == 0) else
2136
2137 delta1_freq = l1ctl_encode_delta1(radio_freq);
2138 delta2_freq = l1ctl_encode_delta2(radio_freq);
2139
2140 lna_value = lna_off * l1ctl_get_lna_att(radio_freq);
2141
2142 last_known_agc = (Cust_get_agc_from_IL(radio_freq, last_known_il >> 1, PWR_ID, lna_off)) << 1;
2143 // F7.1 in order to be compatible with
2144 // pm and IL formats [-20,+140 in F7.1]
2145 // contain the input_level value we use
2146 // in the associated CTL task to build
2147 // the agc used in this CTL.
2148 #if (L1_FF_MULTIBAND == 0)
2149 arfcn = Convert_l1_radio_freq(radio_freq);
2150 #else
2151 arfcn=radio_freq;
2152 #endif
2153
2154 #if(RF_FAM == 61)
2155 #if (CODE_VERSION != SIMULATION)
2156
2157 #if (PWMEAS_IF_MODE_FORCE == 0)
2158 cust_get_if_dco_ctl_algo(&dco_algo_ctl_pw_temp, &if_ctl, (UWORD8) L1_IL_VALID ,
2159 last_known_il,
2160 radio_freq,if_threshold);
2161 #else
2162 if_ctl = IF_120KHZ_DSP;
2163 dco_algo_ctl_pw_temp = DCO_IF_0KHZ;
2164 #endif
2165
2166 delta_drp_gain = drp_gain_correction(arfcn, lna_off, last_known_agc); // F7.1 format
2167 if(if_ctl == IF_100KHZ_DSP){
2168 delta_drp_gain += SCF_ATTENUATION_LIF_100KHZ;
2169 }
2170 else{ /* i.e. if_ctl = IF_120KHZ_DSP*/
2171 delta_drp_gain += SCF_ATTENUATION_LIF_120KHZ;
2172 }
2173
2174 #endif
2175 #endif
2176
2177 if (0==pm) // Check and filter illegal pm value by using last valid IL
2178 current_IL = l1a_l1s_com.last_input_level[index].input_level ;
2179 else
2180 current_IL = -(pm - (last_known_agc - delta_drp_gain) + lna_value - l1ctl_get_g_magic(radio_freq));
2181
2182 current_calibrated_IL = current_IL - delta1_freq - delta2_freq;
2183
2184 // Protect IL stores against overflow
2185 if (current_calibrated_IL>INDEX_MAX)
2186 current_calibrated_IL=INDEX_MAX;
2187 if (current_IL>INDEX_MAX)
2188 current_IL=INDEX_MAX;
2189
2190 // we validate the measure and save input_level and lna_off fields
2191 l1ctl_encode_lna((UWORD8)(current_calibrated_IL>>1),
2192 &(l1a_l1s_com.last_input_level[index].lna_off),
2193 radio_freq);
2194
2195 l1a_l1s_com.last_input_level[index].input_level = (UWORD8)current_IL;
2196
2197 return((UWORD8)current_calibrated_IL);
2198 }
2199
2200
2201 /*-------------------------------------------------------*/
2202 /* l1ctl_pgc2() */
2203 /*-------------------------------------------------------*/
2204 /* Description : */
2205 /* ============= */
2206 /* from power measurement pm_high_agc, */
2207 /* achieve with an HIGH_AGC setting, and pm_low_agc */
2208 /* achieve with a LOW_AGC seeting, we deduce the new */
2209 /* AGC to apply in the next CTL task. */
2210 /*-------------------------------------------------------*/
2211 void l1ctl_pgc2(UWORD8 pm_high_agc, UWORD8 pm_low_agc, UWORD16 radio_freq)
2212 {
2213 UWORD8 pm;
2214 WORD32 IL_high_agc, IL_low_agc, new_IL, current_calibrated_IL;
2215 WORD8 delta1_freq, delta2_freq;
2216 WORD16 delta_high_drp_gain=0;
2217 WORD16 delta_low_drp_gain=0;
2218 WORD32 index;
2219 UWORD16 g_magic;
2220 UWORD16 arfcn;
2221 UWORD16 dco_algo_ctl_pw_temp = 0;
2222 UWORD8 if_ctl = 0;
2223 #if (RF_RAM == 61) && (CODE_VERSION != SIMULATION)
2224 UWORD8 if_threshold = C_IF_ZERO_LOW_THRESHOLD_GSM;
2225 #endif
2226
2227 #if (L1_FF_MULTIBAND == 0)
2228
2229 // initialize index
2230 index = radio_freq - l1_config.std.radio_freq_index_offset;
2231
2232 #else
2233
2234 index =
2235 l1_multiband_radio_freq_convert_into_operative_radio_freq(radio_freq);
2236
2237 #endif // #if (L1_FF_MULTIBAND == 0) else
2238
2239 delta1_freq = l1ctl_encode_delta1(radio_freq);
2240 delta2_freq = l1ctl_encode_delta2(radio_freq);
2241
2242 g_magic = l1ctl_get_g_magic(radio_freq);
2243
2244 // lna_off was set to 0 during CTRL, so lna_value = 0 do not appear in the following
2245 // formula.
2246
2247 #if (L1_FF_MULTIBAND == 0)
2248 arfcn = Convert_l1_radio_freq(radio_freq);
2249 #else
2250 arfcn=radio_freq;
2251 #endif
2252
2253 if ((0==pm_high_agc) || (0==pm_low_agc)) // Check and filter illegal pm value(s) by using last valid IL
2254 new_IL = l1a_l1s_com.last_input_level[index].input_level;
2255 else
2256 {
2257
2258 #if(RF_FAM == 61)
2259 #if (CODE_VERSION != SIMULATION)
2260
2261 #if (PWMEAS_IF_MODE_FORCE == 0)
2262 cust_get_if_dco_ctl_algo(&dco_algo_ctl_pw_temp, &if_ctl, (UWORD8) L1_IL_INVALID ,
2263 0,
2264 radio_freq,if_threshold);
2265 #else
2266 if_ctl = IF_120KHZ_DSP;
2267 dco_algo_ctl_pw_temp = DCO_IF_0KHZ;
2268 #endif
2269
2270
2271 delta_high_drp_gain = drp_gain_correction(arfcn, LNA_ON, (l1_config.params.high_agc << 1)); // F7.1 format
2272 delta_low_drp_gain = drp_gain_correction(arfcn, LNA_ON, (l1_config.params.low_agc << 1)); // F7.1 format
2273 if(if_ctl == IF_100KHZ_DSP){
2274 delta_high_drp_gain += SCF_ATTENUATION_LIF_100KHZ;
2275 delta_low_drp_gain += SCF_ATTENUATION_LIF_100KHZ;
2276 }
2277 else{ /* i.e. if_ctl = IF_120KHZ_DSP*/
2278 delta_high_drp_gain += SCF_ATTENUATION_LIF_120KHZ;
2279 delta_low_drp_gain += SCF_ATTENUATION_LIF_120KHZ;
2280 }
2281 #endif
2282 #endif
2283
2284 IL_high_agc = -(pm_high_agc - ((l1_config.params.high_agc << 1) - delta_high_drp_gain) - g_magic);
2285 IL_low_agc = -(pm_low_agc - ((l1_config.params.low_agc << 1) - delta_low_drp_gain) - g_magic);
2286
2287 // HIGH_AGC and LOW_AGC are formatted to F7.1 in order to be compatible with
2288 // pm and IL formats
2289
2290 if (IL_low_agc>=l1_config.params.low_agc_noise_thr)
2291 // pm_low_agc was on the noise floor, so not valid
2292 {
2293 // whatever the value of pm_high_agc, we consider it
2294 // as the right setting
2295 new_IL = IL_high_agc;
2296 pm = pm_high_agc;
2297 }
2298 else
2299 {
2300 // pm_low_agc is valid.
2301 if (IL_high_agc<=l1_config.params.high_agc_sat_thr)
2302 {
2303 // pm_high_agc is not valid, it's saturated.
2304 new_IL = IL_low_agc;
2305 pm = pm_low_agc;
2306 }
2307 else
2308 {
2309 // both pm_low_agc and pm_high_agc are valid, so we test the one that
2310 // gives the maximum input level and consider it as the right setting.
2311 if (IL_high_agc<=IL_low_agc)
2312 {
2313 new_IL = IL_high_agc;
2314 pm = pm_high_agc;
2315 }
2316 else
2317 {
2318 new_IL = IL_low_agc;
2319 pm = pm_low_agc;
2320 }
2321 }
2322 }
2323 }
2324
2325 #if (TRACE_TYPE == 1) || (TRACE_TYPE == 4)
2326 RTTL1_FILL_MON_MEAS(pm_high_agc, IL_high_agc - delta1_freq - delta2_freq, MS_AGC_ID, radio_freq)
2327 RTTL1_FILL_MON_MEAS(pm_low_agc, IL_low_agc - delta1_freq - delta2_freq, MS_AGC_ID, radio_freq)
2328 #endif
2329
2330 current_calibrated_IL = new_IL - delta1_freq - delta2_freq;
2331
2332 // Protect IL stores against overflow
2333 if (current_calibrated_IL>INDEX_MAX)
2334 current_calibrated_IL=INDEX_MAX;
2335 if (new_IL>INDEX_MAX)
2336 new_IL=INDEX_MAX;
2337
2338 // Updating of input_level and lna_off fields in order to correctly
2339 // setting the AGC for the next task.
2340 l1ctl_encode_lna((UWORD8)(current_calibrated_IL>>1),
2341 &(l1a_l1s_com.last_input_level[index].lna_off),
2342 radio_freq);
2343
2344 l1a_l1s_com.last_input_level[index].input_level = (UWORD8)new_IL;
2345 }
2346
2347
2348 /*-------------------------------------------------------*/
2349 /* l1ctl_find_max() */
2350 /*-------------------------------------------------------*/
2351 /* Parameters : */
2352 /* Return : */
2353 /* Functionality : */
2354 /*-------------------------------------------------------*/
2355 UWORD8 l1ctl_find_max(UWORD8 *buff, UWORD8 buffer_len)
2356 {
2357
2358 // WARNING: for array index purpose we work with POSITIVE input level
2359 // so maximum search for negative numbers is equivalent to
2360 // minimum search for positive numbers!!!!!!
2361 // (-30 > -120 but 30 < 120)
2362
2363 UWORD8 maximum = 240;
2364 UWORD8 i;
2365
2366 for (i=0; i<buffer_len; i++)
2367 {
2368 if (buff[i]<maximum)
2369 maximum=buff[i];
2370 }
2371
2372 return(maximum);
2373 }
2374
2375 /*-------------------------------------------------------*/
2376 /* l1ctl_pagc() */
2377 /*-------------------------------------------------------*/
2378 /* Description : */
2379 /* =========== */
2380 /* We deduce the last_known_agc from the last stored */
2381 /* input_level for the considered carrier. We use this */
2382 /* agc value to "build" the input level linked to the pm */
2383 /* we have just read. */
2384 /* This input level is used to feed a fifo of 4 elements */
2385 /* and then compute an input_level maximum. This value is*/
2386 /* used to update the input_level for this carrier. This */
2387 /* input_level will be used for the next task to control.*/
2388 /*-------------------------------------------------------*/
2389 UWORD8 l1ctl_pagc(UWORD8 pm, UWORD16 radio_freq, T_INPUT_LEVEL *IL_info_ptr)
2390 {
2391 WORD8 delta1_freq, delta2_freq;
2392 WORD16 delta_drp_gain=0;
2393 WORD32 last_known_agc;
2394 UWORD8 IL_max;
2395 WORD32 current_IL, current_calibrated_IL;
2396 UWORD8 i;
2397 WORD32 lna_value;
2398 UWORD16 arfcn;
2399 UWORD8 lna_off;
2400 UWORD16 dco_algo_ctl_pw_temp = 0;
2401 UWORD8 if_ctl = 0;
2402 #if (RF_RAM == 61) && (CODE_VERSION != SIMULATION)
2403 UWORD8 if_threshold = C_IF_ZERO_LOW_THRESHOLD_GSM;
2404 #endif
2405
2406 delta1_freq = l1ctl_encode_delta1(radio_freq);
2407 delta2_freq = l1ctl_encode_delta2(radio_freq);
2408
2409 // Update fifo
2410 for (i=3;i>0;i--)
2411 l1a_l1s_com.Scell_info.buff_beacon[i]=l1a_l1s_com.Scell_info.buff_beacon[i-1];
2412
2413 // from the lna state (ON/OFF) we compute the attenuation
2414 // that was applied to signal when performing the power
2415 // measure.
2416 lna_value = l1a_l1s_com.Scell_used_IL_dd.lna_off * l1ctl_get_lna_att(radio_freq);
2417
2418 // Compute applied agc for this pm
2419 last_known_agc = (Cust_get_agc_from_IL(radio_freq, l1a_l1s_com.Scell_used_IL_dd.input_level >> 1, MAX_ID,l1a_l1s_com.Scell_used_IL_dd.lna_off )) << 1;
2420 // F7.1 in order to be compatible
2421 // with pm and IL formats
2422 // contain the input_level value we use
2423 // in the associated CTL task to build
2424 // the agc used in this CTL.
2425
2426 #if (L1_FF_MULTIBAND == 0)
2427 arfcn = Convert_l1_radio_freq(radio_freq);
2428 #else
2429 arfcn=radio_freq;
2430 #endif
2431
2432 #if(RF_FAM == 61)
2433 #if (CODE_VERSION != SIMULATION)
2434
2435 cust_get_if_dco_ctl_algo(&dco_algo_ctl_pw_temp, &if_ctl, (UWORD8) L1_IL_VALID ,
2436 l1a_l1s_com.Scell_used_IL_dd.input_level,
2437 radio_freq,if_threshold);
2438 lna_off = l1a_l1s_com.Scell_used_IL_dd.lna_off;
2439 delta_drp_gain = drp_gain_correction(arfcn, lna_off, last_known_agc); // F7.1 format
2440 if(if_ctl == IF_100KHZ_DSP){
2441 delta_drp_gain += SCF_ATTENUATION_LIF_100KHZ;
2442 }
2443 else{ /* i.e. if_ctl = IF_120KHZ_DSP*/
2444 delta_drp_gain += SCF_ATTENUATION_LIF_120KHZ;
2445 }
2446
2447 #endif
2448 #endif
2449
2450 if (0==pm) // Check and filter illegal pm value by using last valid IL
2451 current_IL = IL_info_ptr->input_level;
2452 else
2453 current_IL = -(pm - (last_known_agc - delta_drp_gain) + lna_value - l1ctl_get_g_magic(radio_freq));
2454
2455 current_calibrated_IL = current_IL - delta1_freq - delta2_freq;
2456
2457 // Protect IL stores against overflow
2458 if (current_calibrated_IL>INDEX_MAX)
2459 current_calibrated_IL=INDEX_MAX;
2460 if (current_IL>INDEX_MAX)
2461 current_IL=INDEX_MAX;
2462
2463 l1a_l1s_com.Scell_info.buff_beacon[0] = (UWORD8)current_IL;
2464
2465 IL_max = l1ctl_find_max(&(l1a_l1s_com.Scell_info.buff_beacon[0]),4);
2466
2467 //input levels are always stored with lna_on
2468 l1ctl_encode_lna( (UWORD8)(current_calibrated_IL>>1),
2469 &(IL_info_ptr->lna_off),
2470 radio_freq );
2471
2472 IL_info_ptr->input_level = IL_max;
2473
2474 #if L2_L3_SIMUL
2475 #if (DEBUG_TRACE==BUFFER_TRACE_PAGC)
2476 buffer_trace(4,IL_info_ptr->input_level,last_known_agc,
2477 l1a_l1s_com.Scell_used_IL_dd.input_level,Cust_get_agc_from_IL(radio_freq, IL_max >> 1, MAX_ID, l1a_l1s_com.Scell_used_IL_dd.lna_off));
2478 #endif
2479 #endif
2480
2481 return((UWORD8)current_calibrated_IL);
2482 }
2483
2484 /*-------------------------------------------------------*/
2485 /* l1ctl_dpagc() */
2486 /*-------------------------------------------------------*/
2487 /* Description : */
2488 /* =========== */
2489 /* Based on the same principle as the one used for PAGC */
2490 /* algorithm except that we feed 3 different fifo: */
2491 /* 1) one is dedicated to BCCH carrier */
2492 /* 2) another one is dedicated to all the other type of */
2493 /* bursts */
2494 /* 3) the last one is dedicated to non DTX influenced */
2495 /* bursts */
2496 /*-------------------------------------------------------*/
2497 UWORD8 l1ctl_dpagc(BOOL dtx_on, BOOL beacon, UWORD8 pm, UWORD16 radio_freq, T_INPUT_LEVEL *IL_info_ptr)
2498 {
2499 UWORD8 av_G_all, av_G_DTX;
2500 UWORD8 max_G_all, max_G_DTX;
2501 WORD32 last_known_agc, new_IL, current_calibrated_IL;
2502 WORD8 delta1_freq, delta2_freq;
2503 WORD16 delta_drp_gain=0;
2504 UWORD8 i;
2505 UWORD8 *tab_ptr;
2506 T_DEDIC_SET *aset;
2507 WORD32 lna_value;
2508 UWORD16 arfcn;
2509 UWORD8 lna_off;
2510 UWORD16 dco_algo_ctl_pw_temp = 0;
2511 UWORD8 if_ctl = 0;
2512 #if (RF_RAM == 61) && (CODE_VERSION != SIMULATION)
2513 UWORD8 if_threshold = C_IF_ZERO_LOW_THRESHOLD_GSM;
2514 #endif
2515
2516 delta1_freq = l1ctl_encode_delta1(radio_freq);
2517 delta2_freq = l1ctl_encode_delta2(radio_freq);
2518
2519 aset = l1a_l1s_com.dedic_set.aset;
2520
2521 if (beacon)
2522 tab_ptr = l1a_l1s_com.Scell_info.buff_beacon;
2523 else
2524 tab_ptr = aset->G_all;
2525
2526 // Update fifo
2527 for (i=DPAGC_FIFO_LEN-1;i>0;i--)
2528 tab_ptr[i]=tab_ptr[i-1];
2529
2530 #if TESTMODE
2531 if (!l1_config.agc_enable)
2532 {
2533 // AGC gain can only be controlled in 2dB steps as the bottom bit (bit zero)
2534 // corresponds to the lna_off bit
2535 last_known_agc = (l1_config.tmode.rx_params.agc) << 1;
2536 lna_value = (l1_config.tmode.rx_params.lna_off) * l1ctl_get_lna_att(radio_freq);
2537 }
2538 else
2539 #endif
2540 {
2541 #if DPAGC_MAX_FLAG
2542 last_known_agc = (Cust_get_agc_from_IL(radio_freq, l1a_l1s_com.Scell_used_IL_dd.input_level >> 1, MAX_ID,l1a_l1s_com.Scell_used_IL_dd.lna_off)) << 1;
2543 // F7.1 in order to be compatible with pm and IL formats
2544 #else
2545 last_known_agc = (Cust_get_agc_from_IL(radio_freq, l1a_l1s_com.Scell_used_IL_dd.input_level >> 1, AV_ID,l1a_l1s_com.Scell_used_IL_dd.lna_off)) << 1;
2546 // F7.1 in order to be compatible with pm and IL formats
2547 #endif
2548 // input_level_dd : contain the input_level value we use
2549 // in the associated CTL task to build the agc used in this CTL.
2550
2551 lna_value = l1a_l1s_com.Scell_used_IL_dd.lna_off * l1ctl_get_lna_att(radio_freq);
2552 }
2553
2554 #if (L1_FF_MULTIBAND == 0)
2555 arfcn = Convert_l1_radio_freq(radio_freq);
2556 #else
2557 arfcn=radio_freq;
2558 #endif
2559
2560 #if(RF_FAM == 61)
2561 #if (CODE_VERSION != SIMULATION)
2562
2563 cust_get_if_dco_ctl_algo(&dco_algo_ctl_pw_temp, &if_ctl, (UWORD8) L1_IL_VALID ,
2564 l1a_l1s_com.Scell_used_IL_dd.input_level,
2565 radio_freq,if_threshold);
2566 lna_off = l1a_l1s_com.Scell_used_IL_dd.lna_off;
2567 delta_drp_gain = drp_gain_correction(arfcn, lna_off, last_known_agc); // F7.1 format
2568 if(if_ctl == IF_100KHZ_DSP){
2569 delta_drp_gain += SCF_ATTENUATION_LIF_100KHZ;
2570 }
2571 else{ /* i.e. if_ctl = IF_120KHZ_DSP*/
2572 delta_drp_gain += SCF_ATTENUATION_LIF_120KHZ;
2573 }
2574
2575 #endif
2576 #endif
2577
2578 if (0==pm) // Check and filter illegal pm value by using last valid IL
2579 new_IL = IL_info_ptr->input_level;
2580 else
2581 new_IL = -(pm - (last_known_agc - delta_drp_gain) + lna_value - l1ctl_get_g_magic(radio_freq));
2582
2583 current_calibrated_IL = new_IL - delta1_freq - delta2_freq;
2584
2585 // Protect IL stores against overflow
2586 if (current_calibrated_IL>INDEX_MAX)
2587 current_calibrated_IL=INDEX_MAX;
2588
2589 #if TESTMODE
2590 if (l1tm.tmode_state.dedicated_active) // Implies l1_config.TestMode = 1
2591 {
2592 // Update l1tm.tmode_stats.rssi_fifo (delay line from index 3 to 0)
2593 for (i=(sizeof(l1tm.tmode_stats.rssi_fifo)/sizeof(l1tm.tmode_stats.rssi_fifo[0]))-1; i>0; i--)
2594 {
2595 l1tm.tmode_stats.rssi_fifo[i] = l1tm.tmode_stats.rssi_fifo[i-1];
2596 }
2597 l1tm.tmode_stats.rssi_fifo[0] = current_calibrated_IL; // rssi value is F7.1
2598 l1tm.tmode_stats.rssi_recent = current_calibrated_IL; // rssi value is F7.1
2599 }
2600 #endif
2601
2602 if (new_IL>INDEX_MAX)
2603 new_IL=INDEX_MAX;
2604
2605 tab_ptr[0] = (UWORD8)new_IL;
2606
2607 if (dtx_on && !beacon)
2608 {
2609 // Update DTX fifo
2610 for (i=DPAGC_FIFO_LEN-1;i>0;i--)
2611 aset->G_DTX[i]=aset->G_DTX[i-1];
2612
2613 aset->G_DTX[0]=tab_ptr[0];
2614 }
2615
2616 /* Computation of MAX{G_all[i],G_DTX[j]} i,j=0..3 */
2617 #if DPAGC_MAX_FLAG
2618 max_G_all = l1ctl_find_max(&(tab_ptr[0]),DPAGC_FIFO_LEN);
2619
2620 if (!beacon)
2621 {
2622 max_G_DTX = l1ctl_find_max(&(aset->G_DTX[0]),DPAGC_FIFO_LEN);
2623
2624 // WARNING: for array index purpose we work with POSITIVE input level
2625 // so maximum search for negative numbers is equivalent to
2626 // minimum search for positive numbers!!!!!!
2627 // (-30 > -120 but 30 < 120)
2628 if (max_G_all <= max_G_DTX)
2629 new_IL = max_G_all;
2630 else
2631 new_IL = max_G_DTX;
2632 }
2633 else
2634 new_IL = max_G_all;
2635 #else
2636 av_G_all=av_G_DTX=0;
2637
2638 for (i=0;i<DPAGC_FIFO_LEN;i++)
2639 av_G_all += tab_ptr[i];
2640
2641 av_G_all /= DPAGC_FIFO_LEN;
2642
2643 if (!beacon)
2644 {
2645 for (i=0;i<DPAGC_FIFO_LEN;i++)
2646 av_G_DTX += aset->G_DTX[i];
2647
2648 av_G_DTX /= DPAGC_FIFO_LEN;
2649
2650 if (av_G_all >= av_G_DTX)
2651 new_IL = av_G_all;
2652 else
2653 new_IL = av_G_DTX;
2654 }
2655 else
2656 new_IL = av_G_all;
2657 #endif
2658
2659 // Updating of input_level and lna_off fields in order to correctly
2660 // setting the AGC for the next task.
2661 // input_level is always store with lna_on
2662 l1ctl_encode_lna( (UWORD8)(current_calibrated_IL>>1),
2663 &(IL_info_ptr->lna_off),
2664 radio_freq );
2665
2666 IL_info_ptr->input_level = (UWORD8)new_IL ;
2667
2668 #if L2_L3_SIMUL
2669 #if (DEBUG_TRACE==BUFFER_TRACE_DPAGC)
2670 buffer_trace(4,IL_info_ptr->input_level,last_known_agc,
2671 l1a_l1s_com.Scell_used_IL_dd.input_level,Cust_get_agc_from_IL(radio_freq, new_IL >> 1, MAX_ID,l1a_l1s_com.Scell_used_IL_dd.lna_off));
2672 #endif
2673 #endif
2674
2675 return((UWORD8)current_calibrated_IL);
2676 }
2677
2678 #if (AMR == 1)
2679 /*-------------------------------------------------------*/
2680 /* l1ctl_dpagc_amr() */
2681 /*-------------------------------------------------------*/
2682 /* Description : */
2683 /* =========== */
2684 /* Based on the same principle as the one used for DPAGC */
2685 /* algorithm except that the way to feed the G_dtx is */
2686 /* different */
2687 /*-------------------------------------------------------*/
2688 UWORD8 l1ctl_dpagc_amr(BOOL dtx_on, BOOL beacon, UWORD8 pm, UWORD16 radio_freq, T_INPUT_LEVEL *IL_info_ptr)
2689 {
2690 UWORD8 av_G_all, av_G_DTX;
2691 UWORD8 max_G_all, max_G_DTX, max_il;
2692 WORD32 last_known_agc, new_IL, current_calibrated_IL;
2693 WORD8 delta1_freq, delta2_freq;
2694 WORD16 delta_drp_gain=0;
2695 UWORD8 i;
2696 UWORD8 *tab_ptr, *tab_amr_ptr;
2697 T_DEDIC_SET *aset;
2698 WORD32 lna_value;
2699 UWORD16 arfcn;
2700 UWORD8 lna_off;
2701 UWORD16 dco_algo_ctl_pw_temp = 0;
2702 UWORD8 if_ctl = 0;
2703 #if (RF_RAM == 61) && (CODE_VERSION != SIMULATION)
2704 UWORD8 if_threshold = C_IF_ZERO_LOW_THRESHOLD_GSM;
2705 #endif
2706
2707 delta1_freq = l1ctl_encode_delta1(radio_freq);
2708 delta2_freq = l1ctl_encode_delta2(radio_freq);
2709
2710 aset = l1a_l1s_com.dedic_set.aset;
2711
2712 if (beacon)
2713 tab_ptr = l1a_l1s_com.Scell_info.buff_beacon;
2714 else
2715 tab_ptr = aset->G_all;
2716
2717 // Update fifo
2718 for (i=DPAGC_FIFO_LEN-1;i>0;i--)
2719 tab_ptr[i]=tab_ptr[i-1];
2720
2721 tab_amr_ptr = aset->G_amr;
2722 for (i=DPAGC_AMR_FIFO_LEN-1;i>0;i--)
2723 tab_amr_ptr[i]=tab_amr_ptr[i-1];
2724
2725 #if TESTMODE
2726 if (!l1_config.agc_enable)
2727 {
2728 // AGC gain can only be controlled in 2dB steps as the bottom bit (bit zero)
2729 // corresponds to the lna_off bit
2730 last_known_agc = (l1_config.tmode.rx_params.agc) << 1;
2731 lna_value = (l1_config.tmode.rx_params.lna_off) * l1ctl_get_lna_att(radio_freq);
2732 }
2733 else
2734 #endif
2735 {
2736 #if DPAGC_MAX_FLAG
2737 last_known_agc = (Cust_get_agc_from_IL(radio_freq, l1a_l1s_com.Scell_used_IL_dd.input_level >> 1, MAX_ID,l1a_l1s_com.Scell_used_IL_dd.lna_off)) << 1;
2738 // F7.1 in order to be compatible with pm and IL formats
2739 #else
2740 last_known_agc = (Cust_get_agc_from_IL(radio_freq, l1a_l1s_com.Scell_used_IL_dd.input_level >> 1, AV_ID,l1a_l1s_com.Scell_used_IL_dd.lna_off)) << 1;
2741 // F7.1 in order to be compatible with pm and IL formats
2742 #endif
2743 // input_level_dd : contain the input_level value we use
2744 // in the associated CTL task to build the agc used in this CTL.
2745
2746 lna_value = l1a_l1s_com.Scell_used_IL_dd.lna_off * l1ctl_get_lna_att(radio_freq);
2747 }
2748
2749 #if (L1_FF_MULTIBAND == 0)
2750 arfcn = Convert_l1_radio_freq(radio_freq);
2751 #else
2752 arfcn=radio_freq;
2753 #endif
2754
2755 #if(RF_FAM == 61)
2756 #if (CODE_VERSION != SIMULATION)
2757 cust_get_if_dco_ctl_algo(&dco_algo_ctl_pw_temp, &if_ctl, (UWORD8) L1_IL_VALID ,
2758 l1a_l1s_com.Scell_used_IL_dd.input_level,
2759 radio_freq,if_threshold);
2760 lna_off = l1a_l1s_com.Scell_used_IL_dd.lna_off;
2761 delta_drp_gain = drp_gain_correction(arfcn, lna_off, last_known_agc); // F7.1 format
2762 if(if_ctl == IF_100KHZ_DSP){
2763 delta_drp_gain += SCF_ATTENUATION_LIF_100KHZ;
2764 }
2765 else{ /* i.e. if_ctl = IF_120KHZ_DSP*/
2766 delta_drp_gain += SCF_ATTENUATION_LIF_120KHZ;
2767 }
2768 #endif
2769 #endif
2770
2771 if (0==pm) // Check and filter illegal pm value by using last valid IL
2772 new_IL = IL_info_ptr->input_level;
2773 else
2774 new_IL = -(pm - (last_known_agc - delta_drp_gain) + lna_value - l1ctl_get_g_magic(radio_freq));
2775
2776 current_calibrated_IL = new_IL - delta1_freq - delta2_freq;
2777
2778 // Protect IL stores against overflow
2779 if (current_calibrated_IL>INDEX_MAX)
2780 current_calibrated_IL=INDEX_MAX;
2781
2782 #if TESTMODE
2783 if (l1tm.tmode_state.dedicated_active) // Implies l1_config.TestMode = 1
2784 {
2785 // Update l1tm.tmode_stats.rssi_fifo (delay line from index 3 to 0)
2786 for (i=(sizeof(l1tm.tmode_stats.rssi_fifo)/sizeof(l1tm.tmode_stats.rssi_fifo[0]))-1; i>0; i--)
2787 {
2788 l1tm.tmode_stats.rssi_fifo[i] = l1tm.tmode_stats.rssi_fifo[i-1];
2789 }
2790 l1tm.tmode_stats.rssi_fifo[0] = current_calibrated_IL; // rssi value is F7.1
2791 l1tm.tmode_stats.rssi_recent = current_calibrated_IL; // rssi value is F7.1
2792 }
2793 #endif
2794
2795 if (new_IL>INDEX_MAX)
2796 new_IL=INDEX_MAX;
2797
2798 tab_ptr[0] = (UWORD8)new_IL;
2799 tab_amr_ptr[0] = (UWORD8)new_IL;
2800
2801 if (dtx_on && !beacon)
2802 {
2803 // a new AMR block is received, feed the G_dtx with the max_il of the block
2804 for (i=DPAGC_FIFO_LEN-1;i>0;i--)
2805 aset->G_DTX[i]=aset->G_DTX[i-1];
2806
2807 if (l1a_l1s_com.dedic_set.aset->achan_ptr->mode == TCH_AHS_MODE)
2808 {
2809 // Keep the max_il between the last 2 bursts
2810 if (aset->G_amr[0] > aset->G_amr[1])
2811 max_il = aset->G_amr[0];
2812 else
2813 max_il = aset->G_amr[1];
2814 }
2815 else
2816 {
2817 // Keep the max_il between the last 4 bursts
2818 max_il = l1ctl_find_max(&aset->G_amr[0], DPAGC_AMR_FIFO_LEN);
2819 }
2820
2821 aset->G_DTX[0]= max_il;
2822 }
2823
2824 /* Computation of MAX{G_all[i],G_DTX[j]} i,j=0..3 */
2825 #if DPAGC_MAX_FLAG
2826 max_G_all = l1ctl_find_max(&(tab_ptr[0]),DPAGC_FIFO_LEN);
2827
2828 if (!beacon)
2829 {
2830 max_G_DTX = l1ctl_find_max(&(aset->G_DTX[0]),DPAGC_FIFO_LEN);
2831
2832 // WARNING: for array index purpose we work with POSITIVE input level
2833 // so maximum search for negative numbers is equivalent to
2834 // minimum search for positive numbers!!!!!!
2835 // (-30 > -120 but 30 < 120)
2836 if (max_G_all <= max_G_DTX)
2837 new_IL = max_G_all;
2838 else
2839 new_IL = max_G_DTX;
2840 }
2841 else
2842 new_IL = max_G_all;
2843 #else
2844 av_G_all=av_G_DTX=0;
2845
2846 for (i=0;i<DPAGC_FIFO_LEN;i++)
2847 av_G_all += tab_ptr[i];
2848
2849 av_G_all /= DPAGC_FIFO_LEN;
2850
2851 if (!beacon)
2852 {
2853 for (i=0;i<DPAGC_FIFO_LEN;i++)
2854 av_G_DTX += aset->G_DTX[i];
2855
2856 av_G_DTX /= DPAGC_FIFO_LEN;
2857
2858 if (av_G_all >= av_G_DTX)
2859 new_IL = av_G_all;
2860 else
2861 new_IL = av_G_DTX;
2862 }
2863 else
2864 new_IL = av_G_all;
2865 #endif
2866
2867 // Updating of input_level and lna_off fields in order to correctly
2868 // setting the AGC for the next task.
2869 // input_level is always store with lna_on
2870
2871 l1ctl_encode_lna( (UWORD8)(current_calibrated_IL>>1),
2872 &(IL_info_ptr->lna_off),
2873 radio_freq );
2874 IL_info_ptr->input_level = (UWORD8)new_IL ;
2875
2876 #if L2_L3_SIMUL
2877 #if (DEBUG_TRACE==BUFFER_TRACE_DPAGC)
2878 buffer_trace(4,IL_info_ptr->input_level,last_known_agc,
2879 l1a_l1s_com.Scell_used_IL_dd.input_level,Cust_get_agc_from_IL(radio_freq, new_IL >> 1, MAX_ID,l1a_l1s_com.Scell_used_IL_dd.lna_off));
2880 #endif
2881 #endif
2882
2883 return((UWORD8)current_calibrated_IL);
2884 }
2885 #endif // AMR == 1
2886
2887 /*-------------------------------------------------------*/
2888 /* l1ctl_get_g_magic() */
2889 /*-------------------------------------------------------*/
2890 /* Parameters : */
2891 /* Return : */
2892 /* Functionality : */
2893 /*-------------------------------------------------------*/
2894 #if (L1_FF_MULTIBAND == 0)
2895 UWORD16 l1ctl_get_g_magic(UWORD16 radio_freq)
2896 {
2897
2898
2899 if ((l1_config.std.id == DUAL) || (l1_config.std.id == DUALEXT) || (l1_config.std.id == DUAL_US))
2900 {
2901 if (radio_freq >= l1_config.std.first_radio_freq_band2)
2902 return(l1_config.std.g_magic_band2);
2903 else
2904 return(l1_config.std.g_magic_band1);
2905 }
2906 else
2907 return(l1_config.std.g_magic_band1);
2908
2909
2910 }
2911 #endif
2912
2913 /*-------------------------------------------------------*/
2914 /* l1ctl_get_lna_att() */
2915 /*-------------------------------------------------------*/
2916 /* Parameters : */
2917 /* Return : */
2918 /* Functionality : */
2919 /*-------------------------------------------------------*/
2920 #if (L1_FF_MULTIBAND == 0)
2921 UWORD16 l1ctl_get_lna_att(UWORD16 radio_freq)
2922 {
2923
2924
2925 if ((l1_config.std.id == DUAL) || (l1_config.std.id == DUALEXT) || (l1_config.std.id == DUAL_US))
2926 {
2927 if (radio_freq >= l1_config.std.first_radio_freq_band2)
2928 return(l1_config.std.lna_att_band2);
2929 else
2930 return(l1_config.std.lna_att_band1);
2931 }
2932 else
2933 return(l1_config.std.lna_att_band1);
2934
2935
2936 }
2937 #endif
2938 /*-------------------------------------------------------*/
2939 /* l1ctl_update_TPU_with_toa() */
2940 /*-------------------------------------------------------*/
2941 /* Parameters : */
2942 /* Return : */
2943 /* Functionality : */
2944 /*-------------------------------------------------------*/
2945 UWORD16 l1ctl_update_TPU_with_toa(void)
2946 {
2947 #if (TOA_ALGO != 0)
2948 WORD16 toa_shift;
2949
2950 #if (TOA_ALGO == 2)
2951 toa_shift = l1s.toa_var.toa_shift;
2952 #else
2953 toa_shift = l1s.toa_shift;
2954 #endif
2955
2956 if (toa_shift != ISH_INVALID)
2957 // New ISH (TOA shift) has been stored in "l1s.toa_shift".
2958 {
2959 // NEW !!! For EOTD measurements in IDLE mode, cut AFC updates...
2960 #if (L1_EOTD==1)
2961 #if (L1_GPRS)
2962 if ( (l1a_l1s_com.nsync.eotd_meas_session == FALSE) ||
2963 (l1a_l1s_com.mode == DEDIC_MODE)||
2964 (l1a_l1s_com.l1s_en_task[PDTCH] == TASK_ENABLED))
2965 #else
2966 if ( (l1a_l1s_com.nsync.eotd_meas_session == FALSE) ||
2967 (l1a_l1s_com.mode == DEDIC_MODE))
2968 #endif
2969 {
2970 // In dedicated or transfer modes we need to track an TOA
2971 // updates to post correct th results, else E-OTD implementation
2972 // has qb errors...
2973
2974 if( (l1a_l1s_com.nsync.eotd_meas_session == TRUE)
2975 && (l1a_l1s_com.nsync.eotd_toa_phase == 1) )
2976 {
2977 l1a_l1s_com.nsync.eotd_toa_tracking += toa_shift;
2978 }
2979 #endif
2980 // Update tpu offset.
2981 l1s.tpu_offset = (l1s.tpu_offset + TPU_CLOCK_RANGE + toa_shift) % TPU_CLOCK_RANGE;
2982
2983 #if (TRACE_TYPE==1) || (TRACE_TYPE==4)
2984 #if (GSM_IDLE_RAM == 0)
2985 l1_trace_new_toa();
2986 #else
2987 l1_trace_new_toa_intram();
2988 #endif
2989 #endif
2990
2991 #if (L1_EOTD==1)
2992 }
2993 #endif
2994
2995 #if (TRACE_TYPE == 5)
2996 #if (TOA_ALGO == 2)
2997 trace_toa_sim_update (toa_shift,l1s.tpu_offset);
2998 #endif
2999 #endif
3000
3001 // Reset ISH.
3002 #if (TOA_ALGO == 2)
3003 l1s.toa_var.toa_shift = ISH_INVALID; // Reset the ISH.
3004 #else
3005 l1s.toa_shift = ISH_INVALID; // Reset the ISH.
3006 #endif
3007 }
3008 #endif
3009 return 0; //omaps00090550
3010 }
3011
3012
3013 /*-------------------------------------------------------*/
3014 /* l1ctl_saic() */
3015 /*-------------------------------------------------------*/
3016 /* Parameters : */
3017 /* Return : */
3018 /* Functionality : */
3019 /*-------------------------------------------------------*/
3020
3021 #if (L1_SAIC != 0)
3022 #define SWH_CHANTAP_INIT 0xFFD068CE
3023 #if (NEW_SNR_THRESHOLD == 1)
3024 UWORD8 l1ctl_saic (UWORD8 IL_for_rxlev, UWORD32 l1_mode, UWORD8 task, UWORD8 * saic_flag)
3025 #else
3026 UWORD8 l1ctl_saic (UWORD8 IL_for_rxlev, UWORD32 l1_mode)
3027 #endif /* NEW_SNR_THRESHOLD */
3028 {
3029 UWORD16 SWH_flag = 0;
3030 UWORD8 CSF_Filter_choice = L1_SAIC_HARDWARE_FILTER;
3031 #if (NEW_SNR_THRESHOLD == 0)
3032 volatile UWORD16 *ptr;
3033 UWORD8 saic_flag;
3034 #endif /* NEW_SNR_THRESHOLD */
3035 #if (NEW_SNR_THRESHOLD == 0)
3036 ptr = (volatile UWORD16 * ) (SWH_CHANTAP_INIT);
3037 *ptr = 0;
3038 saic_flag=1;
3039 #else
3040 *saic_flag=0;
3041 #endif
3042
3043 switch (l1_mode)
3044 {
3045 case DEDIC_MODE: // GSM DEDICATED MODE
3046 {
3047 #if (NEW_SNR_THRESHOLD == 1)
3048 *saic_flag=1;
3049 #endif
3050 if(IL_for_rxlev < L1_SAIC_GENIE_GSM_DEDIC_THRESHOLD)
3051 {
3052 SWH_flag=1;
3053 }
3054
3055 break;
3056 }
3057 #if L1_GPRS
3058 case PACKET_TRANSFER_MODE: // PACKET TRANSFER MODE
3059 {
3060 #if (NEW_SNR_THRESHOLD == 0)
3061 #if (L1_SAIC == 1)
3062 if(IL_for_rxlev < L1_SAIC_GENIE_GPRS_PCKT_TRAN_THRESHOLD)
3063 {
3064 *ptr = 4;
3065 }
3066 #endif /*#if (L1_SAIC == 3)*/
3067 #endif
3068
3069 #if (L1_SAIC == 3)
3070 if(IL_for_rxlev < L1_SAIC_GENIE_GPRS_PCKT_TRAN_THRESHOLD)
3071 {
3072 SWH_flag = 1;
3073 }
3074 #endif /*#if (L1_SAIC == 3)*/
3075 break;
3076 }
3077 #endif /*#if L1_GPRS*/
3078 default: /* GSM OR GPRS IDLE MODES */
3079 {
3080 #if ((L1_SAIC == 2)||(L1_SAIC == 3))
3081 if(IL_for_rxlev < L1_SAIC_GENIE_GSM_GPRS_IDLE_THRESHOLD)
3082 {
3083 SWH_flag=1;
3084 }
3085 #endif
3086 break;
3087 }
3088 }
3089
3090 l1ddsp_load_swh_flag (SWH_flag ,
3091 #if (NEW_SNR_THRESHOLD == 0)
3092 saic_flag
3093 #else
3094 *saic_flag
3095 #endif
3096 );
3097
3098 if(SWH_flag == 1)
3099 {
3100 CSF_Filter_choice = L1_SAIC_PROGRAMMABLE_FILTER;
3101 }
3102
3103
3104 #if (TRACE_TYPE == 1) || (TRACE_TYPE == 4)
3105 l1_trace_saic(SWH_flag,
3106 #if (NEW_SNR_THRESHOLD == 0)
3107 saic_flag
3108 #else
3109 *saic_flag
3110 #endif
3111 );
3112 #endif
3113 #if (TRACE_TYPE == 5)
3114 trace_saic_sim(IL_for_rxlev, l1_mode, SWH_flag);
3115 #endif
3116
3117 return(CSF_Filter_choice);
3118 }
3119 #endif
3120
3121 #if (FF_L1_FAST_DECODING == 1)
3122 /*-----------------------------------------------------------------*/
3123 /* l1ctl_pagc_missing_bursts */
3124 /*-----------------------------------------------------------------*/
3125 /* */
3126 /* Description: */
3127 /* ------------ */
3128 /* When fast decoding is active, fewer bursts are decoded. As a */
3129 /* result, fewer gain values are available. The PAGC algo must */
3130 /* be updated with the missed values. */
3131 /* */
3132 /* Input parameters: */
3133 /* ----------------- */
3134 /* UWORD8 skipped_values: the number of skipped bursts due to fast */
3135 /* decoding. */
3136 /* */
3137 /* Input parameters from globals: */
3138 /* ------------------------------ */
3139 /* l1a_l1s_com.Scell_info.buff_beacon: Input Level (IL) FIFO */
3140 /* l1_config.params.il_min: minimum level */
3141 /* */
3142 /* Output parameters: */
3143 /* ------------------ */
3144 /* none */
3145 /* */
3146 /* Modified parameters from globals: */
3147 /* --------------------------------- */
3148 /* l1a_l1s_com.Scell_info.buff_beacon: Input Level (IL) FIFO */
3149 /* */
3150 /*-----------------------------------------------------------------*/
3151
3152 void l1ctl_pagc_missing_bursts (UWORD8 skipped_values)
3153 {
3154 UWORD8 i = 0;
3155
3156 /* skipped_values cannot be greater than 3, otherwise this is an error
3157 * and the PAGC algorithm mustn't be updated. */
3158 if (skipped_values > 3)
3159 {
3160 return;
3161 }
3162
3163 /* Update fifo by removing skipped_values of samples */
3164 for (i = 3; i > (skipped_values - 1); i--)
3165 {
3166 l1a_l1s_com.Scell_info.buff_beacon[i] = l1a_l1s_com.Scell_info.buff_beacon[i-skipped_values];
3167 }
3168
3169 /* Insert minimum IL level as many times a burst has been skipped */
3170 for (i = 0; i < skipped_values; i++)
3171 {
3172 l1a_l1s_com.Scell_info.buff_beacon[i] = l1_config.params.il_min;
3173 }
3174 }
3175 #endif /* #if (FF_L1_FAST_DECODING == 1) */