FreeCalypso > hg > tcs211-l1-reconst
comparison chipsetsw/layer1/cfile/l1_ctl.c @ 84:1cda9bc89011
l1_ctl.c: l1ctl_afc() reconstructed
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Sat, 02 Apr 2016 07:56:24 +0000 |
parents | 43dd68d8d891 |
children | eca8d5f642fd |
comparison
equal
deleted
inserted
replaced
83:43dd68d8d891 | 84:1cda9bc89011 |
---|---|
337 static WORD16 psi_quant; /* F13.3 */ | 337 static WORD16 psi_quant; /* F13.3 */ |
338 static WORD16 quant_avg; | 338 static WORD16 quant_avg; |
339 static UWORD32 M_Count; | 339 static UWORD32 M_Count; |
340 static WORD32 psi_avg[C_PSI_AVG_SIZE_D+1]; // Data history array | 340 static WORD32 psi_avg[C_PSI_AVG_SIZE_D+1]; // Data history array |
341 static WORD16 B_Count; // Counter for consecutive SNR below C_thr_snr | 341 static WORD16 B_Count; // Counter for consecutive SNR below C_thr_snr |
342 UWORD16 L = 10433; // Gain algo2 | 342 #if 0 /* LoCosto added var */ |
343 UWORD16 L = 10433; // Gain algo2 | |
344 #endif | |
343 static UWORD16 first_avg; | 345 static UWORD16 first_avg; |
344 static UWORD16 good_snr; | 346 static UWORD16 good_snr; |
345 | 347 |
346 /* to be able to keep in memory the old AFC variables in case of spurious | 348 /* to be able to keep in memory the old AFC variables in case of spurious |
347 FB detection */ | 349 FB detection */ |
351 #endif | 353 #endif |
352 #if (L1_FF_MULTIBAND == 1) | 354 #if (L1_FF_MULTIBAND == 1) |
353 UWORD8 physical_band_id; | 355 UWORD8 physical_band_id; |
354 #endif | 356 #endif |
355 | 357 |
356 | 358 #if 0 /* LoCosto added var init */ |
357 //Set AFC close loop gain for ALGO_AFC_LQG_PREDICTOR. | 359 //Set AFC close loop gain for ALGO_AFC_LQG_PREDICTOR. |
358 if(l1_mode==I_MODE)//MS is in Idle mode | 360 if(l1_mode==I_MODE)//MS is in Idle mode |
359 L = 41732; //F0.20 L=41732/2^20 = 0.04 | 361 L = 41732; //F0.20 L=41732/2^20 = 0.04 |
360 else //All other modes than Idle | 362 else //All other modes than Idle |
361 L = 10433; //F0.20 L=10433/2^20 = 0.01 | 363 L = 10433; //F0.20 L=10433/2^20 = 0.01 |
362 | 364 #endif |
363 | 365 |
364 #if (L1_FF_MULTIBAND == 0) | 366 #if (L1_FF_MULTIBAND == 0) |
365 | 367 |
366 if (((l1_config.std.id == DUAL) || (l1_config.std.id == DUALEXT) || (l1_config.std.id == DUAL_US)) && | 368 if (((l1_config.std.id == DUAL) || (l1_config.std.id == DUALEXT) || (l1_config.std.id == DUAL_US)) && |
367 #if (VCXO_ALGO == 1) | 369 #if (VCXO_ALGO == 1) |
618 case AFC_INIT_CENTER : | 620 case AFC_INIT_CENTER : |
619 case AFC_INIT_MAX : | 621 case AFC_INIT_MAX : |
620 case AFC_INIT_MIN : | 622 case AFC_INIT_MIN : |
621 quant_avg = 0; | 623 quant_avg = 0; |
622 M_Count = 0; | 624 M_Count = 0; |
623 for (i = 0; i <= C_PSI_AVG_SIZE_D ; i++) //omaps00090550 | 625 #if 0 /* present in LoCosto but not in TCS211 */ |
624 psi_avg[i] = 0; | 626 for (i = 0; i <= C_PSI_AVG_SIZE_D ; i++) //omaps00090550 |
625 first_avg = 1; | 627 psi_avg[i] = 0; |
626 good_snr = 0; | 628 #endif |
629 first_avg = 1; | |
630 good_snr = 0; | |
627 | 631 |
628 // DAC search algorithm is as follows - up to 12 attempts are made | 632 // DAC search algorithm is as follows - up to 12 attempts are made |
629 // DAC search algorithm uses three values : DAC_center -> DAC_max -> DAC_min -> | 633 // DAC search algorithm uses three values : DAC_center -> DAC_max -> DAC_min -> |
630 // The first four attempts are made on DAC_center | 634 // The first four attempts are made on DAC_center |
631 // The next four attempts are made on DAC_max | 635 // The next four attempts are made on DAC_max |
692 /*we check if var_32 + 0.5*2**19 is a multiple of 2**19 */ | 696 /*we check if var_32 + 0.5*2**19 is a multiple of 2**19 */ |
693 var_16 = (WORD16) | 697 var_16 = (WORD16) |
694 ((WORD32) (((WORD32)(var_32 + (1<<18))) / (1<<19))); | 698 ((WORD32) (((WORD32)(var_32 + (1<<18))) / (1<<19))); |
695 var_16 = var_16 * 8; | 699 var_16 = var_16 * 8; |
696 #endif | 700 #endif |
701 | |
702 #if 0 /* LoCosto code with saturation */ | |
697 if (var_16 > C_max_step) | 703 if (var_16 > C_max_step) |
698 psi_quant = Add_Sat_sign_16b(psi_quant,C_max_step); | 704 psi_quant = Add_Sat_sign_16b(psi_quant,C_max_step); |
699 else if (var_16 < C_min_step) | 705 else if (var_16 < C_min_step) |
700 psi_quant = Add_Sat_sign_16b(psi_quant,C_min_step); | 706 psi_quant = Add_Sat_sign_16b(psi_quant,C_min_step); |
701 else psi_quant = Add_Sat_sign_16b(psi_quant,var_16); /* F13.3 */ | 707 else psi_quant = Add_Sat_sign_16b(psi_quant,var_16); /* F13.3 */ |
708 #else /* matching TCS211 */ | |
709 if (var_16 > C_max_step) | |
710 psi_quant += C_max_step; | |
711 else if (var_16 < C_min_step) | |
712 psi_quant += C_min_step; | |
713 else psi_quant += var_16; /* F13.3 */ | |
714 #endif | |
715 | |
702 /* F0.32 * F13.3 = F5.35 */ | 716 /* F0.32 * F13.3 = F5.35 */ |
703 psi_past[C_N_del]=Mult_40b(l1_config.params.psi_st_32,psi_quant, &guardout); | 717 psi_past[C_N_del]=Mult_40b(l1_config.params.psi_st_32,psi_quant, &guardout); |
704 /* (F13.3<<16 )+(F5.35>>16) = F13.19 */ | 718 /* (F13.3<<16 )+(F5.35>>16) = F13.19 */ |
705 psi_past[C_N_del]=((WORD32)guardout<<16)+((UWORD32)psi_past[C_N_del]>>16); | 719 psi_past[C_N_del]=((WORD32)guardout<<16)+((UWORD32)psi_past[C_N_del]>>16); |
706 | 720 |
786 | 800 |
787 Phi_32 = psi_past[C_N_del] - psi_past[0]; /* F13.19 */ | 801 Phi_32 = psi_past[C_N_del] - psi_past[0]; /* F13.19 */ |
788 /* Phi = angle - Phi_32*/ | 802 /* Phi = angle - Phi_32*/ |
789 Phi_32 = ((WORD32) angle << 4) - Phi_32; | 803 Phi_32 = ((WORD32) angle << 4) - Phi_32; |
790 /* F1.15 * 4 = F13.19 */ | 804 /* F1.15 * 4 = F13.19 */ |
791 Phi = (WORD16)((WORD32)((WORD32)(Phi_32 + (1<<3)))/ (1<<4)); /* F17.15 */ | 805 #if 0 /* LoCosto code */ |
806 Phi = (WORD16)((WORD32)((WORD32)(Phi_32 + (1<<3)))/ (1<<4)); /* F17.15 */ | |
807 #else /* TCS211 reconstruction */ | |
808 Phi = Phi_32 >> 4; | |
809 #endif | |
792 /* (F0.20 * F1.15) >> 16 = F13.19 */ | 810 /* (F0.20 * F1.15) >> 16 = F13.19 */ |
793 var_32 = (L * Phi + (1<<15)) >> 16; | 811 #if 0 /* LoCosto code with saturation and L */ |
794 psi_past[C_N_del] = Add_Sat_sign_32b(psi_past[C_N_del],var_32); | 812 var_32 = (L * Phi + (1<<15)) >> 16; |
795 | 813 psi_past[C_N_del] = Add_Sat_sign_32b(psi_past[C_N_del],var_32); |
814 #else /* matching TCS211 */ | |
815 psi_past[C_N_del] += (10433 * Phi) >> 16; | |
816 #endif | |
796 | 817 |
797 } | 818 } |
798 else | 819 else |
799 { | 820 { |
800 /************************************/ | 821 /************************************/ |
824 // Predict with 0th order estimation is the default | 845 // Predict with 0th order estimation is the default |
825 | 846 |
826 // Predict with 1st order estimation | 847 // Predict with 1st order estimation |
827 if (l1_config.params.rgap_algo >= 1) | 848 if (l1_config.params.rgap_algo >= 1) |
828 { | 849 { |
850 #if 0 /* LoCosto code with saturation */ | |
829 psi_past[C_N_del] = Add_Sat_sign_32b(psi_past[C_N_del], | 851 psi_past[C_N_del] = Add_Sat_sign_32b(psi_past[C_N_del], |
830 ((quant_avg * (l1_config.params.rgap_bad_snr_count_B))/(C_MSIZE)) | 852 ((quant_avg * (l1_config.params.rgap_bad_snr_count_B))/(C_MSIZE)) |
831 ); | 853 ); |
854 #else /* matching TCS211 */ | |
855 psi_past[C_N_del] += | |
856 ((quant_avg * (l1_config.params.rgap_bad_snr_count_B))/(C_MSIZE)); | |
857 #endif | |
832 } | 858 } |
833 | 859 |
834 B_Count= B_Count - l1_config.params.rgap_bad_snr_count_B; | 860 B_Count= B_Count - l1_config.params.rgap_bad_snr_count_B; |
835 | 861 |
836 // Indicate by raising first_avg flag that a reception gap has occurred | 862 // Indicate by raising first_avg flag that a reception gap has occurred |
846 } | 872 } |
847 | 873 |
848 /* Quantize psi value */ | 874 /* Quantize psi value */ |
849 | 875 |
850 /* F0.19 * 16.0 = F16.19 */ | 876 /* F0.19 * 16.0 = F16.19 */ |
851 var_32 = Sat_Mult_20sign_16unsign(psi_past[C_N_del],l1_config.params.psi_st_inv); | 877 #if 0 /* LoCosto code */ |
878 var_32 = Sat_Mult_20sign_16unsign(psi_past[C_N_del],l1_config.params.psi_st_inv); | |
879 #else /* TCS211 reconstruction */ | |
880 var_32 = psi_past[C_N_del] * l1_config.params.psi_st_inv; | |
881 #endif | |
852 | 882 |
853 #if(RF_FAM == 61) | 883 #if(RF_FAM == 61) |
854 /* In order to implement the NINT function for a F13.3,*/ | 884 /* In order to implement the NINT function for a F13.3,*/ |
855 /*we check if var_32 + 0.5*2**18 is a multiple of 2**18 */ | 885 /*we check if var_32 + 0.5*2**18 is a multiple of 2**18 */ |
856 var_16 = (WORD16) | 886 var_16 = (WORD16) |
887 // directly loaded from EEPROM, and "snr" variable is not meaningful. | 917 // directly loaded from EEPROM, and "snr" variable is not meaningful. |
888 /* Static variables initialisation */ | 918 /* Static variables initialisation */ |
889 | 919 |
890 quant_avg = 0; | 920 quant_avg = 0; |
891 M_Count = 0; | 921 M_Count = 0; |
892 for (i = 0; i <=C_PSI_AVG_SIZE_D ; i++) //omaps00090550 | 922 #if 0 /* present in LoCosto but not in TCS211 */ |
893 psi_avg[i] = 0; | 923 for (i = 0; i <=C_PSI_AVG_SIZE_D ; i++) //omaps00090550 |
894 first_avg = 1; | 924 psi_avg[i] = 0; |
895 good_snr = 0; | 925 #endif |
926 first_avg = 1; | |
927 good_snr = 0; | |
896 | 928 |
897 // DAC search algorithm is as follows - up to 12 attempts are made | 929 // DAC search algorithm is as follows - up to 12 attempts are made |
898 // DAC search algorithm uses three values : DAC_center -> DAC_max -> DAC_min -> | 930 // DAC search algorithm uses three values : DAC_center -> DAC_max -> DAC_min -> |
899 // The first four attempts are made on DAC_center | 931 // The first four attempts are made on DAC_center |
900 // The next four attempts are made on DAC_max | 932 // The next four attempts are made on DAC_max |
965 /* In order to implement the NINT function for a F16.0, we check */ | 997 /* In order to implement the NINT function for a F16.0, we check */ |
966 /* if var_32 + 0.5*2**19 is a multiple of 2**19 */ | 998 /* if var_32 + 0.5*2**19 is a multiple of 2**19 */ |
967 quotient=(WORD16)((WORD32)(((WORD32)(var_32+(1<<18)))/(1<<19))); | 999 quotient=(WORD16)((WORD32)(((WORD32)(var_32+(1<<18)))/(1<<19))); |
968 var_16=quotient*8; | 1000 var_16=quotient*8; |
969 #endif | 1001 #endif |
1002 | |
1003 #if 0 /* LoCosto code with saturation */ | |
970 if (var_16>C_max_step) | 1004 if (var_16>C_max_step) |
971 Psi_quant[C_N_del]=Add_Sat_sign_16b(Psi_quant[C_N_del],C_max_step); | 1005 Psi_quant[C_N_del]=Add_Sat_sign_16b(Psi_quant[C_N_del],C_max_step); |
972 else | 1006 else if (var_16<C_min_step) |
973 if(var_16<C_min_step) | 1007 Psi_quant[C_N_del]=Add_Sat_sign_16b(Psi_quant[C_N_del],C_min_step); |
974 Psi_quant[C_N_del]=Add_Sat_sign_16b(Psi_quant[C_N_del],C_min_step); | 1008 else Psi_quant[C_N_del]=Add_Sat_sign_16b(Psi_quant[C_N_del],var_16); /* F13.3 */ |
975 else Psi_quant[C_N_del]=Add_Sat_sign_16b(Psi_quant[C_N_del],var_16); /* F13.3 */ | 1009 #else /* matching TCS211 */ |
976 | 1010 if (var_16>C_max_step) |
977 | 1011 Psi_quant[C_N_del] += C_max_step; |
1012 else if (var_16<C_min_step) | |
1013 Psi_quant[C_N_del] += C_min_step; | |
1014 else Psi_quant[C_N_del] += var_16; /* F13.3 */ | |
1015 #endif | |
978 | 1016 |
979 /* F0.32 * F13.3 = F5.35 */ | 1017 /* F0.32 * F13.3 = F5.35 */ |
980 Psi=Mult_40b(l1_config.params.psi_st_32,Psi_quant[C_N_del], &guardout); | 1018 Psi=Mult_40b(l1_config.params.psi_st_32,Psi_quant[C_N_del], &guardout); |
981 /* (F13.3<<16 )+(F5.35>>16) = F13.19 */ | 1019 /* (F13.3<<16 )+(F5.35>>16) = F13.19 */ |
982 Psi=((WORD32)guardout<<16)+((UWORD32)Psi>>16); | 1020 Psi=((WORD32)guardout<<16)+((UWORD32)Psi>>16); |
1091 var1=(WORD32)guard1<<24; | 1129 var1=(WORD32)guard1<<24; |
1092 var1=var1/num; | 1130 var1=var1/num; |
1093 var1=(WORD32)var1<<8; | 1131 var1=(WORD32)var1<<8; |
1094 /* var2 is an unsigned variable, var1 contains signed guard*/ | 1132 /* var2 is an unsigned variable, var1 contains signed guard*/ |
1095 /* bits. */ | 1133 /* bits. */ |
1096 var2= ((WORD32)(denom)/(num)); //omaps00090550 | 1134 #if 0 /* fixed LoCosto code */ |
1135 var2= ((WORD32)(denom)/(num)); //omaps00090550 | |
1136 #else /* matching TCS211 */ | |
1137 var2= denom / num; | |
1138 #endif | |
1097 K = (var1+var2)<<1; /* F1.39 / F12.20 = F13.19 */ | 1139 K = (var1+var2)<<1; /* F1.39 / F12.20 = F13.19 */ |
1098 /* F13.19 << 1 = F12.20 */ | 1140 /* F13.19 << 1 = F12.20 */ |
1099 | 1141 |
1100 /* Clipping of the Kalman gain */ | 1142 /* Clipping of the Kalman gain */ |
1101 if (K>=C_thr_K) | 1143 if (K>=C_thr_K) |