FreeCalypso > hg > freecalypso-citrine
comparison L1/cust0/mv100/l1_cust.c_traceversion @ 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 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:75a11d740a02 |
|---|---|
| 1 /************* Revision Controle System Header ************* | |
| 2 * GSM Layer 1 software | |
| 3 * L1_CUST.C | |
| 4 * | |
| 5 * Filename l1_cust.c | |
| 6 * Version 3.66 | |
| 7 * Date 03/21/03 | |
| 8 * | |
| 9 ************* Revision Controle System Header *************/ | |
| 10 | |
| 11 //#define GLOBAL | |
| 12 | |
| 13 #include "string.h" | |
| 14 | |
| 15 #include "l1_confg.h" | |
| 16 #include "l1_const.h" | |
| 17 #include "ulpd.h" | |
| 18 #include "tm_defs.h" | |
| 19 #include "l1_types.h" | |
| 20 #include "l1_time.h" | |
| 21 #include "l1_trace.h" | |
| 22 #include "sys_types.h" | |
| 23 #include "sim.h" | |
| 24 #include "buzzer.h" | |
| 25 #include "serialswitch.h" | |
| 26 | |
| 27 #if TESTMODE | |
| 28 #include "l1tm_defty.h" | |
| 29 #endif | |
| 30 | |
| 31 #if (AUDIO_TASK == 1) | |
| 32 #include "l1audio_const.h" | |
| 33 #include "l1audio_cust.h" | |
| 34 #include "l1audio_defty.h" | |
| 35 #endif | |
| 36 | |
| 37 #if (L1_GTT == 1) | |
| 38 #include "l1gtt_const.h" | |
| 39 #include "l1gtt_defty.h" | |
| 40 #endif | |
| 41 #include "l1_defty.h" | |
| 42 #include "l1_msgty.h" | |
| 43 #include "l1_tabs.h" | |
| 44 #include "l1_varex.h" | |
| 45 | |
| 46 #if (VCXO_ALGO == 1) | |
| 47 #include "l1_ctl.h" | |
| 48 #endif | |
| 49 | |
| 50 #if ((ANALOG == 1) || (ANALOG == 2) || (ANALOG == 3)) | |
| 51 #include "spi_drv.h" | |
| 52 #endif | |
| 53 | |
| 54 #if (RF==35) | |
| 55 #include "tpudrv35.h" | |
| 56 #include "l1_rf35.h" | |
| 57 #include "l1_rf35.c" | |
| 58 #endif | |
| 59 | |
| 60 #if (RF==12) | |
| 61 #include "tpudrv12.h" | |
| 62 #include "l1_rf12.h" | |
| 63 #include "l1_rf12.c" | |
| 64 #endif | |
| 65 | |
| 66 #if (RF==10) | |
| 67 #include "tpudrv10.h" | |
| 68 #include "l1_rf10.h" | |
| 69 #include "l1_rf10.c" | |
| 70 #endif | |
| 71 | |
| 72 #if (RF==8) | |
| 73 #include "tpudrv8.h" | |
| 74 #include "l1_rf8.h" | |
| 75 #include "l1_rf8.c" | |
| 76 #endif | |
| 77 | |
| 78 #if (RF==2) | |
| 79 #include "l1_rf2.h" | |
| 80 #include "l1_rf2.c" | |
| 81 #endif | |
| 82 | |
| 83 // Nucleus functions | |
| 84 extern INT TMD_Timer_State; | |
| 85 extern UWORD32 TMD_Timer; // for big sleep | |
| 86 extern UWORD32 TCD_Priority_Groups; | |
| 87 extern VOID *TCD_Current_Thread; | |
| 88 extern TC_HCB *TCD_Active_HISR_Heads[TC_HISR_PRIORITIES]; | |
| 89 extern TC_HCB *TCD_Active_HISR_Tails[TC_HISR_PRIORITIES]; | |
| 90 extern TC_PROTECT TCD_System_Protect; | |
| 91 | |
| 92 #if (L2_L3_SIMUL == 0) | |
| 93 #define FFS_WORKAROUND 1 | |
| 94 #else | |
| 95 #define FFS_WORKAROUND 0 | |
| 96 #endif | |
| 97 #if (FFS_WORKAROUND == 1) | |
| 98 #include "ffs.h" | |
| 99 #else | |
| 100 typedef signed int int32; | |
| 101 typedef signed char effs_t; | |
| 102 typedef int32 filesize_t; | |
| 103 effs_t ffs_fwrite(const char *name, void *addr, filesize_t size); | |
| 104 effs_t ffs_fread(const char *name, void *addr, filesize_t size); | |
| 105 #endif | |
| 106 | |
| 107 // Import band configuration from Flash module (need to replace by an access function) | |
| 108 //extern UWORD8 std; | |
| 109 extern T_L1_CONFIG l1_config; | |
| 110 extern T_L1S_GLOBAL l1s; | |
| 111 | |
| 112 #if (CODE_VERSION != SIMULATION) | |
| 113 // Import serial switch configuration | |
| 114 extern char ser_cfg_info[2]; | |
| 115 #endif | |
| 116 | |
| 117 void get_cal_from_nvmem (UWORD8 *ptr, UWORD16 len, UWORD8 id); | |
| 118 UWORD8 save_cal_in_nvmem (UWORD8 *ptr, UWORD16 len, UWORD8 id); | |
| 119 void config_rf_rw_band(char type, UWORD8 read); | |
| 120 void config_rf_read(char type); | |
| 121 void config_rf_write(char type); | |
| 122 | |
| 123 enum { | |
| 124 RF_ID = 0, | |
| 125 ADC_ID = 1 | |
| 126 }; | |
| 127 | |
| 128 /*-------------------------------------------------------*/ | |
| 129 /* Parameters: none */ | |
| 130 /* Return: none */ | |
| 131 /* Functionality: Defines the location of rf-struct */ | |
| 132 /* for each std. */ | |
| 133 /*-------------------------------------------------------*/ | |
| 134 | |
| 135 const static T_BAND_CONFIG band_config[] = | |
| 136 { /*ffs name, default addr, max carrier, min tx pwr */ | |
| 137 {"",(T_RF_BAND *) 0,0,0},//undefined | |
| 138 {"900", (T_RF_BAND *)&rf_900, 174, 19 },//EGSM | |
| 139 {"1800",(T_RF_BAND *)&rf_1800, 374, 15 },//DCS | |
| 140 {"1900",(T_RF_BAND *)&rf_1900, 299, 15 },//PCS | |
| 141 {"850", (T_RF_BAND *)&rf_850, 124, 19 },//GSM850 | |
| 142 #if (RF == 10) | |
| 143 {"1900_us",(T_RF_BAND *)&rf_1900, 299, 15 },//usdual 1900 rf tables are the same as 3band 1900 rf tables at the moment | |
| 144 #endif | |
| 145 {"900", (T_RF_BAND *)&rf_900, 124, 19 } //GSM, this should be last entry | |
| 146 }; | |
| 147 | |
| 148 /*-------------------------------------------------------*/ | |
| 149 /* Parameters: none */ | |
| 150 /* Return: none */ | |
| 151 /* Functionality: Defines the indices into band_config */ | |
| 152 /* for each std. */ | |
| 153 /*-------------------------------------------------------*/ | |
| 154 const T_STD_CONFIG std_config[] = | |
| 155 { | |
| 156 /* band1 index, band2 index, txpwr turning point, first arfcn*/ | |
| 157 { 0, 0, 0, 0 }, // std = 0 not used | |
| 158 { BAND_GSM900, BAND_NONE, 0, 1 }, // std = 1 GSM | |
| 159 { BAND_EGSM900, BAND_NONE, 0, 1 }, // std = 2 EGSM | |
| 160 { BAND_PCS1900, BAND_NONE, 21, 512 }, // std = 3 PCS | |
| 161 { BAND_DCS1800, BAND_NONE, 28, 512 }, // std = 4 DCS | |
| 162 { BAND_GSM900, BAND_DCS1800, 28, 1 }, // std = 5 DUAL | |
| 163 { BAND_EGSM900, BAND_DCS1800, 28, 1 }, // std = 6 DUALEXT | |
| 164 { BAND_GSM850, BAND_NONE, 0, 128 }, // std = 7 850 | |
| 165 #if (RF == 10) | |
| 166 { BAND_GSM850, BAND_PCS1900_US, 21, 1 } // std = 8 850/1900 | |
| 167 #else | |
| 168 { BAND_GSM850, BAND_PCS1900, 21, 1 } // std = 8 850/1900 | |
| 169 #endif | |
| 170 }; | |
| 171 | |
| 172 /*-------------------------------------------------------*/ | |
| 173 /* Prototypes of external functions used in this file. */ | |
| 174 /*-------------------------------------------------------*/ | |
| 175 void l1_initialize(T_MMI_L1_CONFIG *mmi_l1_config); | |
| 176 WORD16 Convert_l1_radio_freq (UWORD16 radio_freq); | |
| 177 | |
| 178 /*-------------------------------------------------------*/ | |
| 179 /* Cust_recover_Os() */ | |
| 180 /*-------------------------------------------------------*/ | |
| 181 /* */ | |
| 182 /* Description: adjust OS from sleep duration */ | |
| 183 /* ------------ */ | |
| 184 /* This function fix the : */ | |
| 185 /* - system clock */ | |
| 186 /* - Nucleus timers */ | |
| 187 /* - xxxxxx (customer dependant) */ | |
| 188 /*-------------------------------------------------------*/ | |
| 189 | |
| 190 UWORD8 Cust_recover_Os(void) | |
| 191 { | |
| 192 #if (CODE_VERSION != SIMULATION) | |
| 193 if (l1_config.pwr_mngt == PWR_MNGT) | |
| 194 { | |
| 195 UWORD32 current_system_clock; | |
| 196 | |
| 197 /***************************************************/ | |
| 198 // Fix System clock and Nucleus Timers if any.... */ | |
| 199 /***************************************************/ | |
| 200 // Fix System clock .... | |
| 201 current_system_clock = NU_Retrieve_Clock(); | |
| 202 current_system_clock += l1s.pw_mgr.sleep_duration; | |
| 203 NU_Set_Clock(current_system_clock); | |
| 204 | |
| 205 // Fix Nucleus timer (if needed) .... | |
| 206 if (TMD_Timer_State == TM_ACTIVE) | |
| 207 { | |
| 208 TMD_Timer -= l1s.pw_mgr.sleep_duration; | |
| 209 if (!TMD_Timer) TMD_Timer_State = TM_EXPIRED; | |
| 210 } | |
| 211 | |
| 212 /***************************************************/ | |
| 213 // Cust dependant part ... */ | |
| 214 /***************************************************/ | |
| 215 //............. | |
| 216 //............. | |
| 217 //.............. | |
| 218 return(TRUE); | |
| 219 | |
| 220 } | |
| 221 #endif | |
| 222 } | |
| 223 | |
| 224 | |
| 225 | |
| 226 /*-------------------------------------------------------*/ | |
| 227 /* Cust_check_system() */ | |
| 228 /*-------------------------------------------------------*/ | |
| 229 /* */ | |
| 230 /* Description: */ | |
| 231 /* ------------ */ | |
| 232 /* GSM 1.5 : */ | |
| 233 /* - authorize UWIRE clock to be stopped */ | |
| 234 /* and write value in l1s.pw_mgr.modules_status. */ | |
| 235 /* - authorize ARMIO clock to be stopped if the light is */ | |
| 236 /* off and write value in l1s.pw_mgr.modules_status. */ | |
| 237 /* - check if SIM clock have been stopped */ | |
| 238 /* before allowing DEEP SLEEP. */ | |
| 239 /* - check if UARTs are ready to enter deep sleep */ | |
| 240 /* - choose the sleep mode */ | |
| 241 /* */ | |
| 242 /* Return: */ | |
| 243 /* ------- */ | |
| 244 /* DO_NOT_SLEEP, FRAME_STOP or CLOCK_STOP */ | |
| 245 /*-------------------------------------------------------*/ | |
| 246 UWORD8 Cust_check_system(void) | |
| 247 { | |
| 248 extern UWORD8 why_big_sleep; | |
| 249 #if (CODE_VERSION != SIMULATION) | |
| 250 if (l1_config.pwr_mngt == PWR_MNGT) | |
| 251 { | |
| 252 | |
| 253 #if (L2_L3_SIMUL == 0) | |
| 254 // Forbid deep sleep if the light is on | |
| 255 if(LT_Status()) | |
| 256 { | |
| 257 //cut ARMIO and UWIRE clocks in big sleep | |
| 258 l1s.pw_mgr.modules_status = ARMIO_CLK_CUT | UWIRE_CLK_CUT ; | |
| 259 why_big_sleep = BIG_SLEEP_DUE_TO_LIGHT_ON; | |
| 260 return(FRAME_STOP); // BIG sleep | |
| 261 } | |
| 262 | |
| 263 // Forbid deep sleep if the SIM and UARTs not ready | |
| 264 if(SIM_SleepStatus()) | |
| 265 { | |
| 266 #endif | |
| 267 if(SER_UartSleepStatus()) | |
| 268 { | |
| 269 return(CLOCK_STOP); // DEEP sleep | |
| 270 } | |
| 271 else why_big_sleep = BIG_SLEEP_DUE_TO_UART; | |
| 272 #if (L2_L3_SIMUL == 0) | |
| 273 } | |
| 274 else why_big_sleep = BIG_SLEEP_DUE_TO_SIM; | |
| 275 #endif | |
| 276 // cut ARMIO and UWIRE clocks in big sleep | |
| 277 l1s.pw_mgr.modules_status = ARMIO_CLK_CUT | UWIRE_CLK_CUT ; | |
| 278 return(FRAME_STOP); // BIG sleep | |
| 279 } | |
| 280 #else // Simulation part | |
| 281 return(CLOCK_STOP); // DEEP sleep | |
| 282 #endif | |
| 283 } | |
| 284 | |
| 285 | |
| 286 /*-------------------------------------------------------*/ | |
| 287 /* Parameters: none */ | |
| 288 /* Return: none */ | |
| 289 /* Functionality: Read the RF configuration, tables etc. */ | |
| 290 /* from FFS files. */ | |
| 291 /*-------------------------------------------------------*/ | |
| 292 const static T_CONFIG_FILE config_files_common[] = | |
| 293 { | |
| 294 #if (CODE_VERSION != SIMULATION) | |
| 295 | |
| 296 // The first char is NOT part of the filename. It is used for | |
| 297 // categorizing the ffs file contents: | |
| 298 // f=rf-cal, F=rf-config, | |
| 299 // t=tx-cal, T=tx-config, | |
| 300 // r=rx-cal, R=rx-config, | |
| 301 // s=sys-cal, S=sys-config, | |
| 302 "f/gsm/rf/afcdac", &rf.afc.eeprom_afc, sizeof(rf.afc.eeprom_afc), | |
| 303 "F/gsm/rf/stdmap", &rf.radio_band_support, sizeof(rf.radio_band_support), | |
| 304 #if (VCXO_ALGO == 1) | |
| 305 "F/gsm/rf/afcparams", &rf.afc.psi_sta_inv, 4 * sizeof(UWORD32) + 4 * sizeof(WORD16), | |
| 306 #else | |
| 307 "F/gsm/rf/afcparams", &rf.afc.psi_sta_inv, 4 * sizeof(UWORD32), | |
| 308 #endif | |
| 309 | |
| 310 "R/gsm/rf/rx/agcglobals", &rf.rx.agc, 5 * sizeof(UWORD16), | |
| 311 "R/gsm/rf/rx/il2agc", &rf.rx.agc.il2agc_pwr[0], 3 * sizeof(rf.rx.agc.il2agc_pwr), | |
| 312 "R/gsm/rf/rx/agcwords", &AGC_TABLE, sizeof(AGC_TABLE), | |
| 313 | |
| 314 "s/sys/adccal", &adc_cal, sizeof(adc_cal), | |
| 315 | |
| 316 "S/sys/abb", &abb, sizeof(abb), | |
| 317 "S/sys/uartswitch", &ser_cfg_info, sizeof(ser_cfg_info), | |
| 318 | |
| 319 #endif | |
| 320 NULL, 0, 0 // terminator | |
| 321 }; | |
| 322 | |
| 323 /*-------------------------------------------------------*/ | |
| 324 /* Parameters: none */ | |
| 325 /* Return: none */ | |
| 326 /* Functionality: Read the RF configurations for */ | |
| 327 /* each band from FFS files. These files */ | |
| 328 /* are defined for one band, and and used */ | |
| 329 /* for all bands. */ | |
| 330 /*-------------------------------------------------------*/ | |
| 331 const static T_CONFIG_FILE config_files_band[] = | |
| 332 { | |
| 333 // The first char is NOT part of the filename. It is used for | |
| 334 // categorizing the ffs file contents: | |
| 335 // f=rf-cal, F=rf-config, | |
| 336 // t=tx-cal, T=tx-config, | |
| 337 // r=rx-cal, R=rx-config, | |
| 338 // s=sys-cal, S=sys-config, | |
| 339 | |
| 340 // generic for all bands | |
| 341 // band[0] is used as template for all bands. | |
| 342 "t/gsm/rf/tx/ramps", &rf_band[0].tx.ramp_tables, sizeof(rf_band[0].tx.ramp_tables), | |
| 343 "t/gsm/rf/tx/levels", &rf_band[0].tx.levels, sizeof(rf_band[0].tx.levels), | |
| 344 "t/gsm/rf/tx/calchan", &rf_band[0].tx.chan_cal_table, sizeof(rf_band[0].tx.chan_cal_table), | |
| 345 "T/gsm/rf/tx/caltemp", &rf_band[0].tx.temp, sizeof(rf_band[0].tx.temp), | |
| 346 | |
| 347 "r/gsm/rf/rx/calchan", &rf_band[0].rx.agc_bands, sizeof(rf_band[0].rx.agc_bands), | |
| 348 "R/gsm/rf/rx/caltemp", &rf_band[0].rx.temp, sizeof(rf_band[0].rx.temp), | |
| 349 "r/gsm/rf/rx/agcparams", &rf_band[0].rx.rx_cal_params, sizeof(rf_band[0].rx.rx_cal_params), | |
| 350 NULL, 0, 0 // terminator | |
| 351 }; | |
| 352 | |
| 353 void config_ffs_read(char type) | |
| 354 { | |
| 355 config_rf_read(type); | |
| 356 config_rf_rw_band(type, 1); | |
| 357 } | |
| 358 | |
| 359 void config_ffs_write(char type) | |
| 360 { | |
| 361 config_rf_write(type); | |
| 362 config_rf_rw_band(type, 0); | |
| 363 } | |
| 364 | |
| 365 void config_rf_read(char type) | |
| 366 { | |
| 367 const T_CONFIG_FILE *file = config_files_common; | |
| 368 | |
| 369 while (file->name != NULL) | |
| 370 { | |
| 371 if (type == '*' || type == file->name[0]) { | |
| 372 ffs_fread(&file->name[1], file->addr, file->size); | |
| 373 } | |
| 374 file++; | |
| 375 } | |
| 376 } | |
| 377 | |
| 378 void config_rf_write(char type) | |
| 379 { | |
| 380 const T_CONFIG_FILE *file = config_files_common; | |
| 381 | |
| 382 while (file->name != NULL) | |
| 383 { | |
| 384 if (type == '*' || type == file->name[0]) { | |
| 385 ffs_fwrite(&file->name[1], file->addr, file->size); | |
| 386 } | |
| 387 file++; | |
| 388 } | |
| 389 } | |
| 390 | |
| 391 void config_rf_rw_band(char type, UWORD8 read) | |
| 392 { | |
| 393 const T_CONFIG_FILE *f1 = config_files_band; | |
| 394 UWORD8 i; | |
| 395 WORD32 offset; | |
| 396 char name[64]; | |
| 397 char *p; | |
| 398 UWORD8 std = l1_config.std.id; | |
| 399 | |
| 400 #if FFS_WORKAROUND == 1 | |
| 401 struct stat_s stat; | |
| 402 UWORD16 time; | |
| 403 #endif | |
| 404 for (i=0; i< GSM_BANDS; i++) | |
| 405 { | |
| 406 if(std_config[std].band[i] !=0 ) | |
| 407 { | |
| 408 f1 = &config_files_band[0]; | |
| 409 while (f1->name != NULL) | |
| 410 { | |
| 411 offset = (WORD32) f1->addr - (WORD32) &rf_band[0]; //offset in bytes | |
| 412 p = ((char *) &rf_band[i]) + offset; | |
| 413 if (type == '*' || type == f1->name[0]) | |
| 414 { | |
| 415 strcpy(name, &f1->name[1]); | |
| 416 strcat(name, "."); | |
| 417 strcat(name, band_config[std_config[std].band[i]].name); | |
| 418 | |
| 419 if (read == 1) | |
| 420 ffs_fread(name, p, f1->size); | |
| 421 else //write == 0 | |
| 422 { | |
| 423 ffs_fwrite(name, p, f1->size); | |
| 424 | |
| 425 // wait until ffs write has finished | |
| 426 #if FFS_WORKAROUND == 1 | |
| 427 stat.inode = 0; | |
| 428 time = 0; | |
| 429 | |
| 430 do { | |
| 431 rvf_delay(10); // in milliseconds | |
| 432 time += 10; | |
| 433 ffs_stat(name, &stat); | |
| 434 } while (stat.inode == 0 && time < 500); | |
| 435 #endif | |
| 436 } | |
| 437 } | |
| 438 f1++; | |
| 439 } | |
| 440 } | |
| 441 } | |
| 442 } | |
| 443 | |
| 444 /*-------------------------------------------------------*/ | |
| 445 /* Cust_init_std() */ | |
| 446 /*-------------------------------------------------------*/ | |
| 447 /* Parameters : */ | |
| 448 /* Return : */ | |
| 449 /* Functionality : Init Standard variable configuration */ | |
| 450 /*-------------------------------------------------------*/ | |
| 451 void Cust_init_std(void) | |
| 452 { | |
| 453 UWORD8 std = l1_config.std.id; | |
| 454 UWORD8 band1, band2; | |
| 455 T_RF_BAND *pt1, *pt2; | |
| 456 | |
| 457 band1 = std_config[std].band[0]; | |
| 458 band2 = std_config[std].band[1]; | |
| 459 | |
| 460 //get these from std | |
| 461 pt1 = band_config[band1].addr; | |
| 462 pt2 = band_config[band2].addr; | |
| 463 | |
| 464 // copy rf-struct from default flash to ram | |
| 465 memcpy(&rf_band[0], pt1, sizeof(T_RF_BAND)); | |
| 466 | |
| 467 if(std_config[std].band[1] != BAND_NONE ) | |
| 468 memcpy(&rf_band[1], pt2, sizeof(T_RF_BAND)); | |
| 469 | |
| 470 // Read all RF and system configuration from FFS *before* we copy any of | |
| 471 // the rf structure variables to other places, like L1. | |
| 472 | |
| 473 config_ffs_read('*'); | |
| 474 | |
| 475 l1_config.std.first_radio_freq = std_config[std].first_arfcn; | |
| 476 | |
| 477 if(band2!=0) | |
| 478 l1_config.std.first_radio_freq_band2 = band_config[band1].max_carrier + 1; | |
| 479 else | |
| 480 l1_config.std.first_radio_freq_band2 = 0; //band1 carrier + 1 else 0 | |
| 481 | |
| 482 // if band2 is not used it is initialised with zeros | |
| 483 l1_config.std.nbmax_carrier = band_config[band1].max_carrier; | |
| 484 if(band2!=0) | |
| 485 l1_config.std.nbmax_carrier += band_config[band2].max_carrier; | |
| 486 | |
| 487 l1_config.std.max_txpwr_band1 = band_config[band1].max_txpwr; | |
| 488 l1_config.std.max_txpwr_band2 = band_config[band2].max_txpwr; | |
| 489 l1_config.std.txpwr_turning_point = std_config[std].txpwr_tp; | |
| 490 l1_config.std.cal_freq1_band1 = 0; | |
| 491 l1_config.std.cal_freq1_band2 = 0; | |
| 492 | |
| 493 l1_config.std.g_magic_band1 = rf_band[MULTI_BAND1].rx.rx_cal_params.g_magic; | |
| 494 l1_config.std.lna_att_band1 = rf_band[MULTI_BAND1].rx.rx_cal_params.lna_att; | |
| 495 l1_config.std.lna_switch_thr_low_band1 = rf_band[MULTI_BAND1].rx.rx_cal_params.lna_switch_thr_low; | |
| 496 l1_config.std.lna_switch_thr_high_band1 = rf_band[MULTI_BAND1].rx.rx_cal_params.lna_switch_thr_high; | |
| 497 l1_config.std.swap_iq_band1 = rf_band[MULTI_BAND1].swap_iq; | |
| 498 | |
| 499 l1_config.std.g_magic_band2 = rf_band[MULTI_BAND2].rx.rx_cal_params.g_magic; | |
| 500 l1_config.std.lna_att_band2 = rf_band[MULTI_BAND2].rx.rx_cal_params.lna_att; | |
| 501 l1_config.std.lna_switch_thr_low_band2 = rf_band[MULTI_BAND2].rx.rx_cal_params.lna_switch_thr_low; | |
| 502 l1_config.std.lna_switch_thr_high_band2 = rf_band[MULTI_BAND2].rx.rx_cal_params.lna_switch_thr_high; | |
| 503 l1_config.std.swap_iq_band2 = rf_band[MULTI_BAND2].swap_iq; | |
| 504 | |
| 505 l1_config.std.radio_freq_index_offset = l1_config.std.first_radio_freq-1; | |
| 506 | |
| 507 // init variable indicating which radio bands are supported by the chosen RF | |
| 508 l1_config.std.radio_band_support = rf.radio_band_support; | |
| 509 } | |
| 510 | |
| 511 | |
| 512 /*-------------------------------------------------------*/ | |
| 513 /* Cust_init_params() */ | |
| 514 /*-------------------------------------------------------*/ | |
| 515 /* Parameters : */ | |
| 516 /* Return : */ | |
| 517 /* Functionality : Init RF dependent paramters (AGC, TX) */ | |
| 518 /*-------------------------------------------------------*/ | |
| 519 void Cust_init_params(void) | |
| 520 { | |
| 521 | |
| 522 #if (CODE_VERSION==SIMULATION) | |
| 523 extern UWORD16 simu_RX_SYNTH_SETUP_TIME; // set in xxx.txt l3 scenario file | |
| 524 extern UWORD16 simu_TX_SYNTH_SETUP_TIME; // set in xxx.txt l3 scenario file | |
| 525 | |
| 526 l1_config.params.rx_synth_setup_time = simu_RX_SYNTH_SETUP_TIME; | |
| 527 l1_config.params.tx_synth_setup_time = simu_TX_SYNTH_SETUP_TIME; | |
| 528 #else | |
| 529 l1_config.params.rx_synth_setup_time = RX_SYNTH_SETUP_TIME; | |
| 530 l1_config.params.tx_synth_setup_time = TX_SYNTH_SETUP_TIME; | |
| 531 #endif | |
| 532 | |
| 533 | |
| 534 // Convert SYNTH_SETUP_TIME into SPLIT. | |
| 535 // We have kept a margin of 20qbit (EPSILON_MEAS) to cover offset change and Scenario closing time + margin. | |
| 536 l1_config.params.rx_synth_load_split = 1L + (l1_config.params.rx_synth_setup_time + EPSILON_MEAS) / (BP_DURATION/BP_SPLIT); | |
| 537 l1_config.params.tx_synth_load_split = 1L + (l1_config.params.tx_synth_setup_time + EPSILON_MEAS) / (BP_DURATION/BP_SPLIT); | |
| 538 | |
| 539 l1_config.params.rx_synth_start_time = TPU_CLOCK_RANGE + PROVISION_TIME - l1_config.params.rx_synth_setup_time; | |
| 540 l1_config.params.tx_synth_start_time = TPU_CLOCK_RANGE - l1_config.params.tx_synth_setup_time; | |
| 541 | |
| 542 l1_config.params.rx_change_synchro_time = l1_config.params.rx_synth_start_time - EPSILON_SYNC; | |
| 543 l1_config.params.rx_change_offset_time = l1_config.params.rx_synth_start_time - EPSILON_OFFS; | |
| 544 | |
| 545 l1_config.params.tx_change_offset_time = TIME_OFFSET_TX - | |
| 546 TA_MAX - | |
| 547 l1_config.params.tx_synth_setup_time - | |
| 548 EPSILON_OFFS; | |
| 549 | |
| 550 // TX duration = ramp up time + burst duration (data + tail bits) | |
| 551 l1_config.params.tx_nb_duration = UL_ABB_DELAY + rf.tx.guard_bits*4 + NB_BURST_DURATION_UL; | |
| 552 l1_config.params.tx_ra_duration = UL_ABB_DELAY + rf.tx.guard_bits*4 + RA_BURST_DURATION; | |
| 553 | |
| 554 l1_config.params.tx_nb_load_split = 1L + (l1_config.params.tx_nb_duration - rf.tx.prg_tx - NB_MARGIN) / (BP_DURATION/BP_SPLIT); | |
| 555 l1_config.params.tx_ra_load_split = 1L + (l1_config.params.tx_ra_duration - rf.tx.prg_tx - NB_MARGIN) / (BP_DURATION/BP_SPLIT); | |
| 556 | |
| 557 // time for the end of RX and TX TPU scenarios | |
| 558 l1_config.params.rx_tpu_scenario_ending = RX_TPU_SCENARIO_ENDING; | |
| 559 l1_config.params.tx_tpu_scenario_ending = TX_TPU_SCENARIO_ENDING; | |
| 560 | |
| 561 // FB26 anchoring time is computed backward to leave only 6 qbit margin between | |
| 562 // FB26 window and next activity (RX time tracking). | |
| 563 // This margin is used as follow: | |
| 564 // Serving offset restore: 1 qbit (SERV_OFFS_REST_LOAD) | |
| 565 // Tpu Sleep: 2 qbit (TPU_SLEEP_LOAD) | |
| 566 // --------- | |
| 567 // Total: 3 qbit | |
| 568 | |
| 569 l1_config.params.fb26_anchoring_time = (l1_config.params.rx_synth_start_time - | |
| 570 #if (CODE_VERSION == SIMULATION) | |
| 571 // simulator: end of scenario not included in window (no serialization) | |
| 572 1 - | |
| 573 #else | |
| 574 // RF dependent end of RX TPU scenario | |
| 575 l1_config.params.rx_tpu_scenario_ending - | |
| 576 #endif | |
| 577 EPSILON_SYNC - | |
| 578 TPU_SLEEP_LOAD - | |
| 579 SERV_OFFS_REST_LOAD - | |
| 580 FB26_ACQUIS_DURATION - | |
| 581 PROVISION_TIME + | |
| 582 TPU_CLOCK_RANGE) % TPU_CLOCK_RANGE; | |
| 583 | |
| 584 l1_config.params.fb26_change_offset_time = l1_config.params.fb26_anchoring_time + | |
| 585 PROVISION_TIME - | |
| 586 l1_config.params.rx_synth_setup_time - | |
| 587 EPSILON_OFFS; | |
| 588 | |
| 589 l1_config.params.guard_bits = rf.tx.guard_bits; | |
| 590 | |
| 591 l1_config.params.prg_tx_gsm = rf.tx.prg_tx; | |
| 592 l1_config.params.prg_tx_dcs = rf.tx.prg_tx; //delay for dual band not implemented yet | |
| 593 | |
| 594 l1_config.params.low_agc_noise_thr = rf.rx.agc.low_agc_noise_thr; | |
| 595 l1_config.params.high_agc_sat_thr = rf.rx.agc.high_agc_sat_thr; | |
| 596 l1_config.params.low_agc = rf.rx.agc.low_agc; | |
| 597 l1_config.params.high_agc = rf.rx.agc.high_agc; | |
| 598 l1_config.params.il_min = IL_MIN; | |
| 599 | |
| 600 l1_config.params.fixed_txpwr = FIXED_TXPWR; | |
| 601 l1_config.params.eeprom_afc = rf.afc.eeprom_afc; | |
| 602 l1_config.params.setup_afc_and_rf = SETUP_AFC_AND_RF; | |
| 603 | |
| 604 l1_config.params.psi_sta_inv = rf.afc.psi_sta_inv; | |
| 605 l1_config.params.psi_st = rf.afc.psi_st; | |
| 606 l1_config.params.psi_st_32 = rf.afc.psi_st_32; | |
| 607 l1_config.params.psi_st_inv = rf.afc.psi_st_inv; | |
| 608 | |
| 609 #if (CODE_VERSION == SIMULATION) | |
| 610 #if (VCXO_ALGO == 1) | |
| 611 l1_config.params.afc_algo = ALGO_AFC_LQG_PREDICTOR; // VCXO|VCTCXO - Choosing AFC algorithm | |
| 612 #endif | |
| 613 #else | |
| 614 #if (VCXO_ALGO == 1) | |
| 615 l1_config.params.afc_dac_center = rf.afc.dac_center; // VCXO - assuming DAC linearity | |
| 616 l1_config.params.afc_dac_min = rf.afc.dac_min; // VCXO - assuming DAC linearity | |
| 617 l1_config.params.afc_dac_max = rf.afc.dac_max; // VCXO - assuming DAC linearity | |
| 618 l1_config.params.afc_snr_thr = rf.afc.snr_thr; // VCXO - SNR threshold | |
| 619 l1_config.params.afc_algo = ALGO_AFC_LQG_PREDICTOR; // VCXO|VCTCXO - Choosing AFC algorithm | |
| 620 l1_config.params.afc_win_avg_size_M = C_WIN_AVG_SIZE_M; // VCXO - Average psi values with this value | |
| 621 l1_config.params.rgap_algo = ALGO_AFC_RXGAP; // VCXO - Choosing Reception Gap algorithm | |
| 622 l1_config.params.rgap_bad_snr_count_B = C_RGAP_BAD_SNR_COUNT_B; // VCXO - Prediction SNR count | |
| 623 #endif | |
| 624 #endif | |
| 625 | |
| 626 #if DCO_ALGO | |
| 627 #if (RF == 10) | |
| 628 // Enable DCO algorithm for direct conversion RFs | |
| 629 l1_config.params.dco_enabled = TRUE; | |
| 630 #else | |
| 631 l1_config.params.dco_enabled = FALSE; | |
| 632 #endif | |
| 633 #endif | |
| 634 | |
| 635 #if (ANALOG == 1) | |
| 636 l1_config.params.debug1 = C_DEBUG1; // Enable f_tx delay of 400000 cyc DEBUG | |
| 637 l1_config.params.afcctladd = abb[ABB_AFCCTLADD]; // Value at reset | |
| 638 l1_config.params.vbur = abb[ABB_VBUR]; // Uplink gain amp 0dB, Sidetone gain to mute | |
| 639 l1_config.params.vbdr = abb[ABB_VBDR]; // Downlink gain amp 0dB, Volume control 0 dB | |
| 640 l1_config.params.bbctl = abb[ABB_BBCTL]; // value at reset | |
| 641 l1_config.params.apcoff = abb[ABB_APCOFF]; // value at reset | |
| 642 l1_config.params.bulioff = abb[ABB_BULIOFF]; // value at reset | |
| 643 l1_config.params.bulqoff = abb[ABB_BULQOFF]; // value at reset | |
| 644 l1_config.params.dai_onoff = abb[ABB_DAI_ON_OFF]; // value at reset | |
| 645 l1_config.params.auxdac = abb[ABB_AUXDAC]; // value at reset | |
| 646 l1_config.params.vbcr = abb[ABB_VBCR]; // VULSWITCH=0, VDLAUX=1, VDLEAR=1 | |
| 647 l1_config.params.apcdel = abb[ABB_APCDEL]; // value at reset | |
| 648 #endif | |
| 649 #if (ANALOG == 2) | |
| 650 l1_config.params.debug1 = C_DEBUG1; // Enable f_tx delay of 400000 cyc DEBUG | |
| 651 l1_config.params.afcctladd = abb[ABB_AFCCTLADD]; // Value at reset | |
| 652 l1_config.params.vbur = abb[ABB_VBUR]; // Uplink gain amp 0dB, Sidetone gain to mute | |
| 653 l1_config.params.vbdr = abb[ABB_VBDR]; // Downlink gain amp 0dB, Volume control 0 dB | |
| 654 l1_config.params.bbctl = abb[ABB_BBCTL]; // value at reset | |
| 655 l1_config.params.bulgcal = abb[ABB_BULGCAL]; // value at reset | |
| 656 l1_config.params.apcoff = abb[ABB_APCOFF]; // value at reset | |
| 657 l1_config.params.bulioff = abb[ABB_BULIOFF]; // value at reset | |
| 658 l1_config.params.bulqoff = abb[ABB_BULQOFF]; // value at reset | |
| 659 l1_config.params.dai_onoff = abb[ABB_DAI_ON_OFF]; // value at reset | |
| 660 l1_config.params.auxdac = abb[ABB_AUXDAC]; // value at reset | |
| 661 l1_config.params.vbcr = abb[ABB_VBCR]; // VULSWITCH=0, VDLAUX=1, VDLEAR=1 | |
| 662 l1_config.params.vbcr2 = abb[ABB_VBCR2]; // MICBIASEL=0, VDLHSO=0, MICAUX=0 | |
| 663 l1_config.params.apcdel = abb[ABB_APCDEL]; // value at reset | |
| 664 l1_config.params.apcdel2 = abb[ABB_APCDEL2]; // value at reset | |
| 665 #endif | |
| 666 #if (ANALOG == 3) | |
| 667 l1_config.params.debug1 = C_DEBUG1; // Enable f_tx delay of 400000 cyc DEBUG | |
| 668 l1_config.params.afcctladd = abb[ABB_AFCCTLADD]; // Value at reset | |
| 669 l1_config.params.vbur = abb[ABB_VBUR]; // Uplink gain amp 0dB, Sidetone gain to mute | |
| 670 l1_config.params.vbdr = abb[ABB_VBDR]; // Downlink gain amp 0dB, Volume control 0 dB | |
| 671 l1_config.params.bbctl = abb[ABB_BBCTL]; // value at reset | |
| 672 l1_config.params.bulgcal = abb[ABB_BULGCAL]; // value at reset | |
| 673 l1_config.params.apcoff = abb[ABB_APCOFF]; // X2 Slope 128 and APCSWP disabled | |
| 674 l1_config.params.bulioff = abb[ABB_BULIOFF]; // value at reset | |
| 675 l1_config.params.bulqoff = abb[ABB_BULQOFF]; // value at reset | |
| 676 l1_config.params.dai_onoff = abb[ABB_DAI_ON_OFF]; // value at reset | |
| 677 l1_config.params.auxdac = abb[ABB_AUXDAC]; // value at reset | |
| 678 l1_config.params.vbcr = abb[ABB_VBCR]; // VULSWITCH=0 | |
| 679 l1_config.params.vbcr2 = abb[ABB_VBCR2]; // MICBIASEL=0, VDLHSO=0, MICAUX=0 | |
| 680 l1_config.params.apcdel = abb[ABB_APCDEL]; // value at reset | |
| 681 l1_config.params.apcdel2 = abb[ABB_APCDEL2]; // value at reset | |
| 682 l1_config.params.vbpop = abb[ABB_VBPOP]; // HSOAUTO enabled | |
| 683 l1_config.params.vau_delay_init = abb[ABB_VAUDINITD]; // 2 TDMA Frames between VDL "ON" and VDLHSO "ON" | |
| 684 l1_config.params.vaud_cfg = abb[ABB_VAUDCR]; // value at reset | |
| 685 l1_config.params.vauo_onoff = abb[ABB_VAUOCR]; // speech on AUX and EAR | |
| 686 l1_config.params.vaus_vol = abb[ABB_VAUSCR]; // value at reset | |
| 687 l1_config.params.vaud_pll = abb[ABB_VAUDPLL]; // value at reset | |
| 688 #endif | |
| 689 | |
| 690 // global variable for access to deep sleep time | |
| 691 l1_config.params.sleep_time = 0; | |
| 692 } | |
| 693 | |
| 694 | |
| 695 /************************************/ | |
| 696 /* Automatic Gain Control */ | |
| 697 /************************************/ | |
| 698 | |
| 699 /*-------------------------------------------------------*/ | |
| 700 /* Cust_get_agc_from_IL() */ | |
| 701 /*-------------------------------------------------------*/ | |
| 702 /* Parameters : */ | |
| 703 /* Return : */ | |
| 704 /* Functionality : returns agc value */ | |
| 705 /*-------------------------------------------------------*/ | |
| 706 WORD8 Cust_get_agc_from_IL(UWORD16 radio_freq, UWORD16 agc_index, UWORD8 table_id) | |
| 707 { | |
| 708 // radio_freq currently not used | |
| 709 // this parameter is passed in order to allow band dependent tables for specific RFs | |
| 710 // (e.g. dual band RF with separate AGC H/W blocks for GSM and DCS) | |
| 711 | |
| 712 if (agc_index > 120) | |
| 713 agc_index = 120; // Clip agc_index | |
| 714 | |
| 715 switch (table_id) | |
| 716 { | |
| 717 case MAX_ID: return(rf.rx.agc.il2agc_max[agc_index]); | |
| 718 case AV_ID: return(rf.rx.agc.il2agc_av[agc_index]); | |
| 719 case PWR_ID: return(rf.rx.agc.il2agc_pwr[agc_index]); | |
| 720 } | |
| 721 } | |
| 722 | |
| 723 /*-------------------------------------------------------*/ | |
| 724 /* Cust_get_agc_band */ | |
| 725 /*-------------------------------------------------------*/ | |
| 726 /* Parameters : radio_freq */ | |
| 727 /* Return : band number */ | |
| 728 /* Functionality : Computes the band for RF calibration */ | |
| 729 /*-------------------------------------------------------*/ | |
| 730 /*---------------------------------------------*/ | |
| 731 | |
| 732 | |
| 733 #if (CODE_VERSION == SIMULATION) | |
| 734 UWORD16 Cust_get_agc_band(UWORD16 arfcn, UWORD8 gsm_band) | |
| 735 #else | |
| 736 UWORD16 inline Cust_get_agc_band(UWORD16 arfcn, UWORD8 gsm_band) | |
| 737 #endif | |
| 738 { | |
| 739 WORD32 i ; | |
| 740 | |
| 741 for (i=0;i<RF_RX_CAL_CHAN_SIZE;i++) | |
| 742 { | |
| 743 if (arfcn <= rf_band[gsm_band].rx.agc_bands[i].upper_bound) | |
| 744 return(i); | |
| 745 } | |
| 746 // Should never happen! | |
| 747 return(0); | |
| 748 } | |
| 749 | |
| 750 /*-------------------------------------------------------*/ | |
| 751 /* Cust_is_band_high */ | |
| 752 /*-------------------------------------------------------*/ | |
| 753 /* Parameters : arfcn */ | |
| 754 /* Return : 0 if low band */ | |
| 755 /* 1 if high band */ | |
| 756 /* Functionality : Generic function which return 1 if */ | |
| 757 /* arfcn is in the high band */ | |
| 758 /*-------------------------------------------------------*/ | |
| 759 | |
| 760 UWORD8 Cust_is_band_high(UWORD16 radio_freq) | |
| 761 { | |
| 762 UWORD16 max_carrier; | |
| 763 UWORD8 std = l1_config.std.id; | |
| 764 | |
| 765 max_carrier = band_config[std_config[std].band[0]].max_carrier; | |
| 766 | |
| 767 return(((radio_freq >= l1_config.std.first_radio_freq) && | |
| 768 (radio_freq < (l1_config.std.first_radio_freq + max_carrier))) ? MULTI_BAND1 : MULTI_BAND2); | |
| 769 } | |
| 770 | |
| 771 /*-------------------------------------------------------*/ | |
| 772 /* l1ctl_encode_delta2() */ | |
| 773 /*-------------------------------------------------------*/ | |
| 774 /* Parameters : */ | |
| 775 /* Return : */ | |
| 776 /* Functionality : */ | |
| 777 /*-------------------------------------------------------*/ | |
| 778 WORD8 l1ctl_encode_delta2(UWORD16 radio_freq) | |
| 779 { | |
| 780 WORD8 delta2_freq; | |
| 781 UWORD16 i; | |
| 782 UWORD16 arfcn; | |
| 783 UWORD8 band; | |
| 784 | |
| 785 band = Cust_is_band_high(radio_freq); | |
| 786 arfcn = Convert_l1_radio_freq(radio_freq); | |
| 787 | |
| 788 i = Cust_get_agc_band(arfcn,band); // | |
| 789 delta2_freq = rf_band[band].rx.agc_bands[i].agc_calib; | |
| 790 | |
| 791 //temperature compensation | |
| 792 for (i=0;i<RF_RX_CAL_TEMP_SIZE;i++) | |
| 793 { | |
| 794 if ((WORD16)adc.converted[ADC_RFTEMP] <= rf_band[band].rx.temp[i].temperature) | |
| 795 { | |
| 796 delta2_freq += rf_band[band].rx.temp[i].agc_calib; | |
| 797 break; | |
| 798 } | |
| 799 } | |
| 800 | |
| 801 return(delta2_freq); | |
| 802 } | |
| 803 | |
| 804 /************************************/ | |
| 805 /* TX Management */ | |
| 806 /************************************/ | |
| 807 /*-------------------------------------------------------*/ | |
| 808 /* Cust_get_ramp_tab */ | |
| 809 /*-------------------------------------------------------*/ | |
| 810 /* Parameters : */ | |
| 811 /* Return : */ | |
| 812 /* Functionality : */ | |
| 813 /*-------------------------------------------------------*/ | |
| 814 | |
| 815 void Cust_get_ramp_tab(API *a_ramp, UWORD8 txpwr_ramp_up, UWORD8 txpwr_ramp_down, UWORD16 radio_freq) | |
| 816 { | |
| 817 UWORD16 index_up, index_down,j, arfcn; | |
| 818 UWORD8 band; | |
| 819 | |
| 820 band = Cust_is_band_high(radio_freq); | |
| 821 arfcn = Convert_l1_radio_freq(radio_freq); | |
| 822 | |
| 823 index_up = rf_band[band].tx.levels[txpwr_ramp_up].ramp_index; | |
| 824 index_down = rf_band[band].tx.levels[txpwr_ramp_down].ramp_index; | |
| 825 | |
| 826 #if ((ANALOG == 1) || (ANALOG == 2) || (ANALOG == 3)) | |
| 827 for (j=0; j<16; j++) | |
| 828 { | |
| 829 a_ramp[j]=((rf_band[band].tx.ramp_tables[index_down].ramp_down[j])<<11) | | |
| 830 ((rf_band[band].tx.ramp_tables[index_up].ramp_up[j]) << 6) | | |
| 831 0x14; | |
| 832 } | |
| 833 #endif | |
| 834 } | |
| 835 | |
| 836 /*-------------------------------------------------------*/ | |
| 837 /* get_pwr_data */ | |
| 838 /*-------------------------------------------------------*/ | |
| 839 /* Parameters : */ | |
| 840 /* Return : */ | |
| 841 /* Functionality : */ | |
| 842 /*-------------------------------------------------------*/ | |
| 843 | |
| 844 #if ((ANALOG == 1) || (ANALOG == 2) || (ANALOG == 3)) | |
| 845 UWORD16 Cust_get_pwr_data(UWORD8 txpwr, UWORD16 radio_freq) | |
| 846 { | |
| 847 | |
| 848 UWORD16 i,j; | |
| 849 UWORD16 arfcn; | |
| 850 UWORD8 band; | |
| 851 | |
| 852 #if(ORDER2_TX_TEMP_CAL==1) | |
| 853 WORD16 pwr_data; | |
| 854 #else | |
| 855 UWORD16 pwr_data; | |
| 856 #endif | |
| 857 | |
| 858 band = Cust_is_band_high(radio_freq); | |
| 859 arfcn = Convert_l1_radio_freq(radio_freq); | |
| 860 | |
| 861 i = rf_band[band].tx.levels[txpwr].chan_cal_index; | |
| 862 j=0; | |
| 863 // get uncalibrated apc | |
| 864 pwr_data = rf_band[band].tx.levels[txpwr].apc; | |
| 865 | |
| 866 while (arfcn > rf_band[band].tx.chan_cal_table[i][j].arfcn_limit) | |
| 867 j++; | |
| 868 | |
| 869 // channel calibrate apc | |
| 870 pwr_data = ((UWORD32) (pwr_data * rf_band[band].tx.chan_cal_table[i][j].chan_cal))/128; | |
| 871 | |
| 872 // temperature compensate apc | |
| 873 { | |
| 874 T_TX_TEMP_CAL *pt; | |
| 875 | |
| 876 pt = rf_band[band].tx.temp; | |
| 877 while ((WORD16)adc.converted[ADC_RFTEMP] > pt->temperature) | |
| 878 pt++; | |
| 879 #if(ORDER2_TX_TEMP_CAL==1) | |
| 880 pwr_data += (txpwr*(pt->a*txpwr + pt->b) + pt->c) / 64; //delta apc = ax^2+bx+c | |
| 881 if(pwr_data < 0) pwr_data = 0; | |
| 882 #else | |
| 883 pwr_data += pt->apc_calib; | |
| 884 #endif | |
| 885 } | |
| 886 return(pwr_data); | |
| 887 } | |
| 888 #endif | |
| 889 /*-------------------------------------------------------*/ | |
| 890 /* Cust_Init_Layer1 */ | |
| 891 /*-------------------------------------------------------*/ | |
| 892 /* Parameters : */ | |
| 893 /* Return : */ | |
| 894 /* Functionality : Load and boot the DSP */ | |
| 895 /* Initialize shared memory and L1 data structures */ | |
| 896 /*-------------------------------------------------------*/ | |
| 897 | |
| 898 void Cust_Init_Layer1(void) | |
| 899 { | |
| 900 T_MMI_L1_CONFIG cfg; | |
| 901 | |
| 902 // Get the current band configuration from the flash | |
| 903 #if (OP_WCP==1) | |
| 904 extern unsigned char ffs_GetBand(); | |
| 905 cfg.std = ffs_GetBand(); | |
| 906 #else // NO OP_WCP | |
| 907 // cfg.std = std; | |
| 908 cfg.std = STD; | |
| 909 #endif // OP_WCP | |
| 910 | |
| 911 cfg.tx_pwr_code = 1; | |
| 912 | |
| 913 // sleep management configuration | |
| 914 cfg.pwr_mngt = 0; | |
| 915 cfg.pwr_mngt_mode_authorized = NO_SLEEP; //Sleep mode | |
| 916 cfg.pwr_mngt_clocks = 0x5ff; // list of clocks cut in Big Sleep | |
| 917 | |
| 918 | |
| 919 | |
| 920 #if (CODE_VERSION != SIMULATION) | |
| 921 cfg.dwnld = DWNLD; //external define from makefile | |
| 922 #endif | |
| 923 | |
| 924 l1_initialize(&cfg); | |
| 925 | |
| 926 get_cal_from_nvmem((UWORD8 *)&rf, sizeof(rf), RF_ID); | |
| 927 get_cal_from_nvmem((UWORD8 *)&adc_cal, sizeof(adc_cal), ADC_ID); | |
| 928 | |
| 929 } | |
| 930 | |
| 931 | |
| 932 /*****************************************************************************************/ | |
| 933 /*************************** TESTMODE functions **********************************/ | |
| 934 /*****************************************************************************************/ | |
| 935 | |
| 936 | |
| 937 | |
| 938 /*------------------------------------------------------*/ | |
| 939 /* madc_hex_2_physical */ | |
| 940 /*------------------------------------------------------*/ | |
| 941 /* Parameters : */ | |
| 942 /* Return : */ | |
| 943 /* Functionality : Function to convert MAD hexadecimal */ | |
| 944 /* values into physical values */ | |
| 945 /*------------------------------------------------------*/ | |
| 946 | |
| 947 void madc_hex_2_physical (UWORD16 *adc_hex, T_ADC *adc_phy) | |
| 948 { | |
| 949 WORD16 i; | |
| 950 UWORD16 y; | |
| 951 WORD16 Smin = 0, Smax = TEMP_TABLE_SIZE-1; | |
| 952 WORD16 index = (TEMP_TABLE_SIZE-1)/2; /* y is the adc code after compensation of ADC slope error introduced by VREF error */ | |
| 953 | |
| 954 //store raw ADC values | |
| 955 memcpy(&adc.raw[0], adc_hex, sizeof(adc.raw)); | |
| 956 | |
| 957 // Convert Vbat [mV] : direct equation with slope and offset compensation | |
| 958 for (i = ADC_VBAT; i<ADC_RFTEMP; i++) | |
| 959 adc.converted[i] = (((UWORD32)(adc_cal.a[i] * adc.raw[i])) >>10) + adc_cal.b[i]; | |
| 960 | |
| 961 /*Convert RF Temperature [Celsius]: binsearch into a table*/ | |
| 962 y = ((UWORD32)(adc_cal.a[ADC_RFTEMP] * adc.raw[ADC_RFTEMP]))>>8; /* rf.tempcal is the calibration of VREF*/ | |
| 963 while((Smax-Smin) > 1 ) | |
| 964 { | |
| 965 if(y < temperature[index].adc) | |
| 966 Smax=index; | |
| 967 else | |
| 968 Smin=index; | |
| 969 | |
| 970 index = (Smax+Smin)/2; | |
| 971 } | |
| 972 adc.converted[ADC_RFTEMP] = temperature[index].temp; | |
| 973 | |
| 974 for (i = ADC_RFTEMP+1; i<ADC_INDEX_END; i++) | |
| 975 adc.converted[i] = (((UWORD32)(adc_cal.a[i] * adc.raw[i])) >>10) + adc_cal.b[i]; | |
| 976 | |
| 977 //store converted ADC values | |
| 978 memcpy(adc_phy, &adc.converted[0], sizeof(adc.raw)); | |
| 979 } | |
| 980 | |
| 981 | |
| 982 /*------------------------------------------------------*/ | |
| 983 /* get_cal_from_nvmem */ | |
| 984 /*------------------------------------------------------*/ | |
| 985 /* Parameters : */ | |
| 986 /* Return : */ | |
| 987 /* Functionality : Copy calibrated parameter to */ | |
| 988 /* calibration structure in RAM */ | |
| 989 /*------------------------------------------------------*/ | |
| 990 | |
| 991 void get_cal_from_nvmem (UWORD8 *ptr, UWORD16 len, UWORD8 id) | |
| 992 { | |
| 993 | |
| 994 } | |
| 995 | |
| 996 /*------------------------------------------------------*/ | |
| 997 /* save_cal_from_nvmem */ | |
| 998 /*------------------------------------------------------*/ | |
| 999 /* Parameters : */ | |
| 1000 /* Return : */ | |
| 1001 /* Functionality : Copy calibrated structure from RAM */ | |
| 1002 /* into NV memory */ | |
| 1003 /*------------------------------------------------------*/ | |
| 1004 | |
| 1005 UWORD8 save_cal_in_nvmem (UWORD8 *ptr, UWORD16 len, UWORD8 id) | |
| 1006 { | |
| 1007 #if (OP_WCP == 1) | |
| 1008 // FFS backup implementation an Avenger 2 | |
| 1009 // Request MPU-S to backup the FFS | |
| 1010 // after full calibration of device | |
| 1011 extern void ffs_backup(void); | |
| 1012 ffs_backup(); | |
| 1013 #endif | |
| 1014 return (0); | |
| 1015 } | |
| 1016 | |
| 1017 #if (TRACE_TYPE == 4) | |
| 1018 | |
| 1019 /*------------------------------------------------------*/ | |
| 1020 /* l1_cst_l1_parameters */ | |
| 1021 /*------------------------------------------------------*/ | |
| 1022 /* Parameters : s: pointer on configuration string */ | |
| 1023 /* Return : nothing: global var are set */ | |
| 1024 /* Functionality : Set global L1 vars for dynamic trace */ | |
| 1025 /* and configuration */ | |
| 1026 /* */ | |
| 1027 /* This function is called when a CST message is sent */ | |
| 1028 /* from the Condat Panel. */ | |
| 1029 /*------------------------------------------------------*/ | |
| 1030 void l1_cst_l1_parameters(char *s) | |
| 1031 { | |
| 1032 /* | |
| 1033 a sample command string can be: | |
| 1034 L1_PARAMS=<1,2,3,4,5> or | |
| 1035 L1_PARAMS=<1,23,3E32,4,5> | |
| 1036 with n parameters (here: 5 params); n>=1 | |
| 1037 parameters are decoded as hexadecimal unsigned integers (UWORD16) | |
| 1038 */ | |
| 1039 | |
| 1040 UWORD8 uNParams = 0; /* Number of parameters */ | |
| 1041 UWORD32 aParam[10]; /* Parameters array */ | |
| 1042 UWORD8 uIndex = 0; | |
| 1043 | |
| 1044 /* *** retrieve all parameters *** */ | |
| 1045 while (s[uIndex] != '<') uIndex++; | |
| 1046 uIndex++; | |
| 1047 aParam[0] = 0; | |
| 1048 | |
| 1049 /* uIndex points on 1st parameter */ | |
| 1050 | |
| 1051 while (s[uIndex] != '>') | |
| 1052 { | |
| 1053 if (s[uIndex] == ',') | |
| 1054 { | |
| 1055 uNParams++; | |
| 1056 aParam[uNParams] = 0; | |
| 1057 } | |
| 1058 else | |
| 1059 { | |
| 1060 /* uIndex points on a parameter char */ | |
| 1061 UWORD8 uChar = s[uIndex]; | |
| 1062 aParam[uNParams] = aParam[uNParams] << 4; /* shift 4 bits left */ | |
| 1063 if ((uChar>='0') && (uChar<='9')) | |
| 1064 aParam[uNParams] += (uChar - '0'); /* retrieve value */ | |
| 1065 else if ((uChar>='A') && (uChar<='F')) | |
| 1066 aParam[uNParams] += (10 + uChar - 'A'); /* retrieve value */ | |
| 1067 else if ((uChar>='a') && (uChar<='f')) | |
| 1068 aParam[uNParams] += (10 + uChar - 'a'); /* retrieve value */ | |
| 1069 } | |
| 1070 | |
| 1071 uIndex++; /* go to next char */ | |
| 1072 } | |
| 1073 | |
| 1074 /* increment number of params */ | |
| 1075 uNParams++; | |
| 1076 | |
| 1077 /* *** handle parameters *** */ | |
| 1078 /* | |
| 1079 1st param: command type | |
| 1080 2nd param: argument for command type | |
| 1081 */ | |
| 1082 switch (aParam[0]) | |
| 1083 { | |
| 1084 case 0: /* Trace setting */ | |
| 1085 /* The 2nd parameter contains the trace bitmap*/ | |
| 1086 if (uNParams >=2) | |
| 1087 trace_info.current_config->l1_dyn_trace = aParam[1]; | |
| 1088 else | |
| 1089 trace_info.current_config->l1_dyn_trace = 0; /* error case: disable all trace */ | |
| 1090 Trace_dyn_trace_change(); | |
| 1091 break; | |
| 1092 default: /* ignore it */ | |
| 1093 break; | |
| 1094 } // switch | |
| 1095 } | |
| 1096 | |
| 1097 #endif | |
| 1098 | |
| 1099 #if ((CHIPSET == 2) || (CHIPSET == 3) || (CHIPSET == 4) || \ | |
| 1100 (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || \ | |
| 1101 (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || \ | |
| 1102 (CHIPSET == 11) || (CHIPSET == 12)) | |
| 1103 /*-------------------------------------------------------*/ | |
| 1104 /* power_down_config() : temporary implementation !!! */ | |
| 1105 /*-------------------------------------------------------*/ | |
| 1106 /* Parameters : sleep_mode (NO, SMALL, BIG, DEEP or ALL) */ | |
| 1107 /* clocks to be cut in BIG sleep */ | |
| 1108 /* Return : */ | |
| 1109 /* Functionality : set the l1s variables */ | |
| 1110 /* l1s.pw_mgr.mode_authorized and l1s.pw_mgr.clocks */ | |
| 1111 /* according to the desired mode. */ | |
| 1112 /*-------------------------------------------------------*/ | |
| 1113 void power_down_config(UWORD8 sleep_mode, UWORD16 clocks) | |
| 1114 { | |
| 1115 #if (OP_L1_STANDALONE == 1) | |
| 1116 if(sleep_mode != NO_SLEEP) | |
| 1117 #endif | |
| 1118 { | |
| 1119 l1_config.pwr_mngt = PWR_MNGT; | |
| 1120 l1s.pw_mgr.mode_authorized = sleep_mode; | |
| 1121 l1s.pw_mgr.clocks = clocks; | |
| 1122 } | |
| 1123 | |
| 1124 #if (OP_L1_STANDALONE == 0) | |
| 1125 l1s.pw_mgr.enough_gaug = FALSE; | |
| 1126 #endif | |
| 1127 } | |
| 1128 #endif | |
| 1129 | |
| 1130 /* glowing,2004-06-16, import from M188 */ | |
| 1131 void layer1_em_get_rxlevqual(WORD32 *l1_rxlev_scell,WORD32 *l1_rxlev_dedic_sub, | |
| 1132 WORD32 *l1_rxqual_dedic,WORD32 *l1_rxqual_dedic_sub) | |
| 1133 { | |
| 1134 /* | |
| 1135 xmzhou_trace_string_value("values***********",(UINT32)(l1a_l1s_com.Scell_info.meas.acc)); | |
| 1136 xmzhou_trace_string_value("values***********",(UINT32)(l1a_l1s_com.Scell_info.meas.nbr_meas)); | |
| 1137 xmzhou_trace_string_value("values***********",(UINT32)(l1a_l1s_com.Smeas_dedic.acc_sub)); | |
| 1138 xmzhou_trace_string_value("values***********",(UINT32)(l1a_l1s_com.Smeas_dedic.nbr_meas_sub)); | |
| 1139 xmzhou_trace_string_value("values***********",(UINT32)(l1a_l1s_com.Smeas_dedic.qual_acc_full)); | |
| 1140 xmzhou_trace_string_value("values***********",(UINT32)(l1a_l1s_com.Smeas_dedic.qual_nbr_meas_full)); | |
| 1141 xmzhou_trace_string_value("values***********",(UINT32)(l1a_l1s_com.Smeas_dedic.qual_acc_sub)); | |
| 1142 xmzhou_trace_string_value("values***********",(UINT32)(l1a_l1s_com.Smeas_dedic.qual_nbr_meas_sub)); | |
| 1143 */ | |
| 1144 if(l1a_l1s_com.Scell_info.meas.nbr_meas != 0){ | |
| 1145 *l1_rxlev_scell=(WORD32)(l1a_l1s_com.Scell_info.meas.acc)/(WORD32)(l1a_l1s_com.Scell_info.meas.nbr_meas); | |
| 1146 }else{ | |
| 1147 *l1_rxlev_scell=(WORD32)(l1a_l1s_com.Scell_info.meas.acc)/(WORD32)(4); | |
| 1148 } | |
| 1149 // xmzhou_trace_string_value("l1_rxlev_scell",(UINT32)(*l1_rxlev_scell)); | |
| 1150 | |
| 1151 if(l1a_l1s_com.Smeas_dedic.nbr_meas_sub !=0){ | |
| 1152 *l1_rxlev_dedic_sub=(WORD32)(l1a_l1s_com.Smeas_dedic.acc_sub)/(WORD32)(l1a_l1s_com.Smeas_dedic.nbr_meas_sub); | |
| 1153 }else{ | |
| 1154 *l1_rxlev_dedic_sub=0; | |
| 1155 } | |
| 1156 // xmzhou_trace_string_value("l1_rxlev_dedic_sub",(UINT32)(*l1_rxlev_dedic_sub)); | |
| 1157 | |
| 1158 if(l1a_l1s_com.Smeas_dedic.qual_nbr_meas_full !=0){ | |
| 1159 *l1_rxqual_dedic=(WORD32)(l1a_l1s_com.Smeas_dedic.qual_acc_full)/(WORD32)(l1a_l1s_com.Smeas_dedic.qual_nbr_meas_full); | |
| 1160 }else{ | |
| 1161 *l1_rxqual_dedic=0; | |
| 1162 } | |
| 1163 // xmzhou_trace_string_value("l1_rxqual_dedic",(UINT32)(*l1_rxqual_dedic)); | |
| 1164 | |
| 1165 if(l1a_l1s_com.Smeas_dedic.qual_nbr_meas_sub){ | |
| 1166 *l1_rxqual_dedic_sub=(WORD32)(l1a_l1s_com.Smeas_dedic.qual_acc_sub)/(WORD32)(l1a_l1s_com.Smeas_dedic.qual_nbr_meas_sub); | |
| 1167 }else{ | |
| 1168 *l1_rxqual_dedic_sub=0; | |
| 1169 } | |
| 1170 // xmzhou_trace_string_value("l1_rxqual_dedic_sub",(UINT32)(*l1_rxqual_dedic_sub)); | |
| 1171 } | |
| 1172 | |
| 1173 void layer1_em_get_mode(WORD32 *l1_mode) | |
| 1174 { | |
| 1175 *l1_mode=l1a_l1s_com.mode; | |
| 1176 } | |
| 1177 | |
| 1178 /*glowing,2004-06-16, end of import */ | |
| 1179 |
