comparison gsm-fw/L1/cust0/l1_cust.c @ 523:b92febec14aa

started FC version of l1_cust.c
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 14 Jul 2014 05:16:14 +0000
parents gsm-fw/L1/cust1/l1_cust.c@eafadfee35b2
children 1affe428bf72
comparison
equal deleted inserted replaced
522:2c9c2b95ddec 523:b92febec14aa
1 /*
2 * This FreeCalypso version of l1_cust.c is based on the LoCosto version;
3 * see ../cust1/l1_cust.c for the original.
4 */
5
6 #include <string.h>
7 #include "../../include/config.h"
8
9 #include "../include/l1_confg.h"
10 #include "../include/l1_const.h"
11 #include "../../bsp/ulpd.h"
12 #include "../../nucleus/nucleus.h"
13 #include "../../nucleus/tm_defs.h"
14 #include "../include/l1_types.h"
15 #include "../include/l1_time.h"
16 #include "../include/l1_trace.h"
17 #include "../../include/sys_types.h"
18 #include "../include/l1_macro.h"
19 #include "../../serial/serialswitch.h"
20 #include "../../bsp/abb+spi/abb.h"
21
22 #if(OP_L1_STANDALONE == 0)
23 #include "buzzer/buzzer.h" // for BZ_KeyBeep_OFF function
24 #include "sim/sim.h"
25 #endif
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
42 #if (L1_MP3 == 1)
43 #include "l1mp3_defty.h"
44 #endif
45
46 #if (L1_MIDI == 1)
47 #include "l1midi_defty.h"
48 #endif
49
50 #include "l1_defty.h"
51 #include "l1_msgty.h"
52 #include "l1_tabs.h"
53 #include "l1_varex.h"
54 #include "l1_proto.h"
55 #if (VCXO_ALGO == 1)
56 #include "l1_ctl.h"
57 #endif
58
59
60 #if (RF_FAM == 61)
61 #include "drp_drive.h"
62 #include "tpudrv61.h"
63 #include "l1_rf61.h"
64 #include "l1_rf61.c"
65 #endif
66
67
68 #if (RF_FAM == 60 )
69 #include "drp_drive.h"
70 #include "tpudrv60.h"
71 #include "l1_rf60.h"
72 #include "l1_rf60.c"
73 //#include "rf60.h"
74 #endif
75
76 #if (RF_FAM == 43)
77 #include "tpudrv43.h"
78 #include "l1_rf43.h"
79 #include "l1_rf43.c"
80 #endif
81
82 #if (RF_FAM == 35)
83 #include "tpudrv35.h"
84 #include "l1_rf35.h"
85 #include "l1_rf35.c"
86 #endif
87
88 #if (RF_FAM == 12)
89 #include "tpudrv12.h"
90 #include "l1_rf12.h"
91 #include "l1_rf12.c"
92 #endif
93
94 #if (RF_FAM == 10)
95 #include "tpudrv10.h"
96 #include "l1_rf10.h"
97 #include "l1_rf10.c"
98 #endif
99
100 #if (RF_FAM == 8)
101 #include "tpudrv8.h"
102 #include "l1_rf8.h"
103 #include "l1_rf8.c"
104 #endif
105
106 #if (RF_FAM == 2)
107 #include "l1_rf2.h"
108 #include "l1_rf2.c"
109 #endif
110
111 #if (DRP_FW_EXT == 1)
112 #include "l1_drp_inc.h"
113 #include "l1_ver.h"
114 #endif
115
116
117 // Nucleus functions
118 extern INT TMD_Timer_State;
119 extern UWORD32 TMD_Timer; // for big sleep
120 extern UWORD32 TCD_Priority_Groups;
121 extern VOID *TCD_Current_Thread;
122 extern TC_HCB *TCD_Active_HISR_Heads[TC_HISR_PRIORITIES];
123 extern TC_HCB *TCD_Active_HISR_Tails[TC_HISR_PRIORITIES];
124 extern TC_PROTECT TCD_System_Protect;
125
126 #if (L2_L3_SIMUL == 0)
127 #define FFS_WORKAROUND 0
128 #else
129 #define FFS_WORKAROUND 0
130 #endif
131 #if (FFS_WORKAROUND == 1)
132 #include "ffs/ffs.h"
133 #else
134 /* typedef signed int int32;
135 typedef signed char effs_t;*/
136 typedef signed int filesize_t;
137 effs_t ffs_fwrite(const char *name, void *addr, filesize_t size);
138 #if (DRP_FW_EXT == 0)
139 effs_t ffs_fread(const char *name, void *addr, filesize_t size);
140 #endif
141 #endif
142
143 // Import band configuration from Flash module (need to replace by an access function)
144 //extern UWORD8 std;
145 extern T_L1_CONFIG l1_config;
146 extern T_L1S_GLOBAL l1s;
147
148 #if(OP_L1_STANDALONE == 0)
149 extern SYS_BOOL cama_sleep_status(void);
150 #endif
151
152 #if (CODE_VERSION != SIMULATION)
153 // Import serial switch configuration
154 #if (CHIPSET == 12)
155 extern char ser_cfg_info[3];
156 #else
157 extern char ser_cfg_info[2];
158 #endif
159 #endif
160
161 #if(REL99 && FF_PRF)
162 T_TX_LEVEL *Cust_get_uplink_apc_power_reduction(UWORD8 band,
163 UWORD8 number_uplink_timeslot,
164 T_TX_LEVEL *p_tx_level);
165 #endif
166
167
168 void get_cal_from_nvmem (UWORD8 *ptr, UWORD16 len, UWORD8 id);
169 UWORD8 save_cal_in_nvmem (UWORD8 *ptr, UWORD16 len, UWORD8 id);
170 void config_rf_rw_band(char type, UWORD8 read);
171 void config_rf_read(char type);
172 void config_rf_write(char type);
173
174 #if (RF_FAM == 61)
175 #include "drp_api.h"
176
177
178 extern T_DRP_SW_DATA drp_sw_data_init;
179 extern T_DRP_SW_DATA drp_sw_data_calib;
180 extern T_DRP_SW_DATA drp_sw_data_calib_saved;
181 #endif
182
183 enum {
184 RF_ID = 0,
185 ADC_ID = 1
186 };
187
188 #if (L1_FF_MULTIBAND == 0)
189 /*-------------------------------------------------------*/
190 /* Parameters: none */
191 /* Return: none */
192 /* Functionality: Defines the location of rf-struct */
193 /* for each std. */
194 /*-------------------------------------------------------*/
195 //omaps00090550 #83 warinng removal
196 static const T_BAND_CONFIG band_config[] =
197 { /*ffs name, default addr, max carrier, min tx pwr */
198 {"",(T_RF_BAND *) 0,0,0},//undefined
199 {"900", (T_RF_BAND *)&rf_900, 174, 19 },//EGSM
200 {"1800",(T_RF_BAND *)&rf_1800, 374, 15 },//DCS
201 {"1900",(T_RF_BAND *)&rf_1900, 299, 15 },//PCS
202 {"850", (T_RF_BAND *)&rf_850, 124, 19 },//GSM850
203 #if (RF_FAM == 10)
204 {"1900_us",(T_RF_BAND *)&rf_1900, 299, 15 },//usdual 1900 rf tables are the same as 3band 1900 rf tables at the moment
205 #endif
206 {"900", (T_RF_BAND *)&rf_900, 124, 19 } //GSM, this should be last entry
207 };
208
209 /*-------------------------------------------------------*/
210 /* Parameters: none */
211 /* Return: none */
212 /* Functionality: Defines the indices into band_config */
213 /* for each std. */
214 /*-------------------------------------------------------*/
215 const T_STD_CONFIG std_config[] =
216 {
217 /* band1 index, band2 index, txpwr turning point, first arfcn*/
218 { 0, 0, 0, 0 }, // std = 0 not used
219 { BAND_GSM900, BAND_NONE, 0, 1 }, // std = 1 GSM
220 { BAND_EGSM900, BAND_NONE, 0, 1 }, // std = 2 EGSM
221 { BAND_PCS1900, BAND_NONE, 21, 512 }, // std = 3 PCS
222 { BAND_DCS1800, BAND_NONE, 28, 512 }, // std = 4 DCS
223 { BAND_GSM900, BAND_DCS1800, 28, 1 }, // std = 5 DUAL
224 { BAND_EGSM900, BAND_DCS1800, 28, 1 }, // std = 6 DUALEXT
225 { BAND_GSM850, BAND_NONE, 0, 128 }, // std = 7 850
226 #if (RF_FAM == 10)
227 { BAND_GSM850, BAND_PCS1900_US, 21, 1 } // std = 8 850/1900
228 #else
229 { BAND_GSM850, BAND_PCS1900, 21, 1 } // std = 8 850/1900
230 #endif
231 };
232 #endif //if (L1_FF_MULTIBAND == 0)
233
234 /*-------------------------------------------------------*/
235 /* Prototypes of external functions used in this file. */
236 /*-------------------------------------------------------*/
237 void l1_initialize(T_MMI_L1_CONFIG *mmi_l1_config);
238 #if (L1_FF_MULTIBAND == 0)
239 WORD16 Convert_l1_radio_freq (UWORD16 radio_freq);
240 #endif
241 /*-------------------------------------------------------*/
242 /* Cust_recover_Os() */
243 /*-------------------------------------------------------*/
244 /* */
245 /* Description: adjust OS from sleep duration */
246 /* ------------ */
247 /* This function fix the : */
248 /* - system clock */
249 /* - Nucleus timers */
250 /* - xxxxxx (customer dependant) */
251 /*-------------------------------------------------------*/
252
253 UWORD8 Cust_recover_Os(void)
254 {
255 #if (CODE_VERSION != SIMULATION)
256 if (l1_config.pwr_mngt == PWR_MNGT)
257 {
258 UWORD32 current_system_clock;
259
260 /***************************************************/
261 // Fix System clock and Nucleus Timers if any.... */
262 /***************************************************/
263 // Fix System clock ....
264 current_system_clock = NU_Retrieve_Clock();
265 current_system_clock += l1s.pw_mgr.sleep_duration;
266 NU_Set_Clock(current_system_clock);
267
268 // Fix Nucleus timer (if needed) ....
269 if (TMD_Timer_State == TM_ACTIVE)
270 {
271 TMD_Timer -= l1s.pw_mgr.sleep_duration;
272 if (!TMD_Timer) TMD_Timer_State = TM_EXPIRED;
273 }
274
275 /***************************************************/
276 // Cust dependant part ... */
277 /***************************************************/
278 //.............
279 //.............
280 //..............
281 return(TRUE);
282
283 }
284 #endif
285 return(TRUE); //omaps00090550
286 }
287
288
289
290 /*-------------------------------------------------------*/
291 /* Cust_check_system() */
292 /*-------------------------------------------------------*/
293 /* */
294 /* Description: */
295 /* ------------ */
296 /* GSM 1.5 : */
297 /* - authorize UWIRE clock to be stopped */
298 /* and write value in l1s.pw_mgr.modules_status. */
299 /* - authorize ARMIO clock to be stopped if the light is */
300 /* off and write value in l1s.pw_mgr.modules_status. */
301 /* - check if SIM clock have been stopped */
302 /* before allowing DEEP SLEEP. */
303 /* - check if UARTs are ready to enter deep sleep */
304 /* - choose the sleep mode */
305 /* */
306 /* Return: */
307 /* ------- */
308 /* DO_NOT_SLEEP, FRAME_STOP or CLOCK_STOP */
309 /*-------------------------------------------------------*/
310 UWORD8 Cust_check_system(void)
311 {
312
313 #if (CODE_VERSION != SIMULATION)
314 if (l1_config.pwr_mngt == PWR_MNGT)
315 {
316
317 #if (L2_L3_SIMUL == 0)
318 // Forbid deep sleep if the light is on
319 if(LT_Status())
320 {
321 //cut ARMIO and UWIRE clocks in big sleep
322 l1s.pw_mgr.modules_status = ARMIO_CLK_CUT | UWIRE_CLK_CUT ;
323 l1s.pw_mgr.why_big_sleep = BIG_SLEEP_DUE_TO_LIGHT_ON;
324 return(FRAME_STOP); // BIG sleep
325 }
326
327 #if (OP_L1_STANDALONE == 0)
328 // Forbid deep sleep if the camera is working
329 if(!cama_sleep_status())
330 {
331 l1s.pw_mgr.why_big_sleep = BIG_SLEEP_DUE_TO_CAMERA;
332 return(FRAME_STOP); // BIG sleep
333 }
334
335 // Forbid deep sleep if the SIM and UARTs not ready
336 #if (REQUIRED_FOR_ESAMPLE_LOCOSTO)
337 // Forbid deep sleep if the SIM and UARTs not ready
338 if(SIM_SleepStatus())
339 #endif
340 {
341 #endif
342 #endif
343 if(SER_UartSleepStatus())
344 {
345 return(CLOCK_STOP); // DEEP sleep
346 }
347 else l1s.pw_mgr.why_big_sleep = BIG_SLEEP_DUE_TO_UART;
348 #if (L2_L3_SIMUL == 0)
349 #if (OP_L1_STANDALONE == 0)
350 }
351 // Forbid deep sleep if the SIM and UARTs not ready
352 #if (REQUIRED_FOR_ESAMPLE_LOCOSTO)
353 else l1s.pw_mgr.why_big_sleep = BIG_SLEEP_DUE_TO_SIM;
354 #endif
355 #endif
356 #endif
357 // cut ARMIO and UWIRE clocks in big sleep
358 l1s.pw_mgr.modules_status = ARMIO_CLK_CUT | UWIRE_CLK_CUT ;
359 return(FRAME_STOP); // BIG sleep
360 }
361 #else // Simulation part
362 return(CLOCK_STOP); // DEEP sleep
363 #endif
364 return(CLOCK_STOP); // omaps00090550
365 }
366
367
368 /*-------------------------------------------------------*/
369 /* Parameters: none */
370 /* Return: none */
371 /* Functionality: Read the RF configuration, tables etc. */
372 /* from FFS files. */
373 /*-------------------------------------------------------*/
374 //omaps00090550 #83-d warnimg removal
375 static const T_CONFIG_FILE config_files_common[] =
376 {
377 #if (CODE_VERSION != SIMULATION)
378
379 // The first char is NOT part of the filename. It is used for
380 // categorizing the ffs file contents:
381 // f=rf-cal, F=rf-config,
382 // t=tx-cal, T=tx-config,
383 // r=rx-cal, R=rx-config,
384 // s=sys-cal, S=sys-config,
385 "f/gsm/rf/afcdac", &rf.afc.eeprom_afc, sizeof(rf.afc.eeprom_afc),
386 "F/gsm/rf/stdmap", &rf.radio_band_support, sizeof(rf.radio_band_support),
387 #if (VCXO_ALGO == 1)
388 "F/gsm/rf/afcparams", &rf.afc.psi_sta_inv, 4 * sizeof(UWORD32) + 4 * sizeof(WORD16),
389 #else
390 "F/gsm/rf/afcparams", &rf.afc.psi_sta_inv, 4 * sizeof(UWORD32),
391 #endif
392
393 "R/gsm/rf/rx/agcglobals", &rf.rx.agc, 4 * sizeof(UWORD16),
394 "R/gsm/rf/rx/il2agc", &rf.rx.agc.il2agc_pwr[0], 3 * sizeof(rf.rx.agc.il2agc_pwr),
395 "R/gsm/rf/rx/agcwords", &AGC_TABLE, sizeof(AGC_TABLE),
396
397 "s/sys/adccal", &adc_cal, sizeof(adc_cal),
398
399 "S/sys/abb", &abb, sizeof(abb),
400 "S/sys/uartswitch", &ser_cfg_info, sizeof(ser_cfg_info),
401
402 #if (RF_FAM ==61)
403 "S/sys/drp_wrapper", & drp_wrapper, sizeof(drp_wrapper),
404 #if (DRP_FW_EXT == 0)
405 "S/sys/drp_calibration", & drp_sw_data_calib, sizeof(drp_sw_data_calib),
406 #endif
407 #endif
408
409 #endif
410 NULL, 0, 0 // terminator
411 };
412
413 /*-------------------------------------------------------*/
414 /* Parameters: none */
415 /* Return: none */
416 /* Functionality: Read the RF configurations for */
417 /* each band from FFS files. These files */
418 /* are defined for one band, and and used */
419 /* for all bands. */
420 /*-------------------------------------------------------*/
421 //omaps00090550 #83 warning removal
422 static const T_CONFIG_FILE config_files_band[] =
423 {
424 // The first char is NOT part of the filename. It is used for
425 // categorizing the ffs file contents:
426 // f=rf-cal, F=rf-config,
427 // t=tx-cal, T=tx-config,
428 // r=rx-cal, R=rx-config,
429 // s=sys-cal, S=sys-config,
430
431 // generic for all bands
432 // band[0] is used as template for all bands.
433 "t/gsm/rf/tx/ramps", &rf_band[0].tx.ramp_tables, sizeof(rf_band[0].tx.ramp_tables),
434 "t/gsm/rf/tx/levels", &rf_band[0].tx.levels, sizeof(rf_band[0].tx.levels),
435 "t/gsm/rf/tx/calchan", &rf_band[0].tx.chan_cal_table, sizeof(rf_band[0].tx.chan_cal_table),
436 "T/gsm/rf/tx/caltemp", &rf_band[0].tx.temp, sizeof(rf_band[0].tx.temp),
437
438 "r/gsm/rf/rx/calchan", &rf_band[0].rx.agc_bands, sizeof(rf_band[0].rx.agc_bands),
439 "R/gsm/rf/rx/caltemp", &rf_band[0].rx.temp, sizeof(rf_band[0].rx.temp),
440 "r/gsm/rf/rx/agcparams", &rf_band[0].rx.rx_cal_params, sizeof(rf_band[0].rx.rx_cal_params),
441 NULL, 0, 0 // terminator
442 };
443
444 void config_ffs_read(char type)
445 {
446 config_rf_read(type);
447 config_rf_rw_band(type, 1);
448 }
449
450 void config_ffs_write(char type)
451 {
452 config_rf_write(type);
453 config_rf_rw_band(type, 0);
454 }
455
456 void config_rf_read(char type)
457 {
458 const T_CONFIG_FILE *file = config_files_common;
459
460 while (file->name != NULL)
461 {
462 if (type == '*' || type == file->name[0]) {
463 ffs_fread(&file->name[1], file->addr, file->size);
464 }
465 file++;
466 }
467 }
468
469 void config_rf_write(char type)
470 {
471 const T_CONFIG_FILE *file = config_files_common;
472
473 while (file->name != NULL)
474 {
475 if (type == '*' || type == file->name[0]) {
476 ffs_fwrite(&file->name[1], file->addr, file->size);
477 }
478 file++;
479 }
480 }
481
482 void config_rf_rw_band(char type, UWORD8 read)
483 {
484 const T_CONFIG_FILE *f1 = config_files_band;
485 UWORD8 i;
486 WORD32 offset;
487 char name[64];
488 char *p;
489 #if (L1_FF_MULTIBAND == 0)
490 UWORD8 std = l1_config.std.id;
491 #endif
492
493 #if FFS_WORKAROUND == 1
494 struct stat_s stat;
495 UWORD16 time;
496 #endif
497 #if (L1_FF_MULTIBAND == 0)
498 for (i=0; i< GSM_BANDS; i++)
499 {
500 if(std_config[std].band[i] !=0 )
501 {
502 #else
503 for (i = 0; i < RF_NB_SUPPORTED_BANDS; i++)
504 {
505 #endif /*if (L1_FF_MULTIBAND == 0) */
506 f1 = &config_files_band[0];
507 while (f1->name != NULL)
508 {
509 offset = (WORD32) f1->addr - (WORD32) &rf_band[0]; //offset in bytes
510 p = ((char *) &rf_band[i]) + offset;
511 if (type == '*' || type == f1->name[0])
512 {
513 strcpy(name, &f1->name[1]);
514 strcat(name, ".");
515 #if (L1_FF_MULTIBAND == 0)
516 strcat(name, band_config[std_config[std].band[i]].name);
517 #else
518 strcat(name, multiband_rf[i].name);
519 #endif /*if (L1_FF_MULTIBAND == 0)*/
520
521 if (read == 1)
522 ffs_fread(name, p, f1->size);
523 else //write == 0
524 {
525 ffs_fwrite(name, p, f1->size);
526
527 // wait until ffs write has finished
528 #if FFS_WORKAROUND == 1
529 stat.inode = 0;
530 time = 0;
531
532 do {
533 rvf_delay(10); // in milliseconds
534 time += 10;
535 ffs_stat(name, &stat);
536 } while (stat.inode == 0 && time < 500);
537 #endif
538 }
539 }
540 f1++;
541 }
542 }
543 #if (L1_FF_MULTIBAND == 0)
544 }
545 #endif
546 }
547
548
549 /*-------------------------------------------------------*/
550 /* Cust_init_std() */
551 /*-------------------------------------------------------*/
552 /* Parameters : */
553 /* Return : */
554 /* Functionality : Init Standard variable configuration */
555 /*-------------------------------------------------------*/
556 void Cust_init_std(void)
557 #if (L1_FF_MULTIBAND == 0)
558 {
559 UWORD8 std = l1_config.std.id;
560 UWORD8 band1, band2;
561 T_RF_BAND *pt1, *pt2;
562
563 band1 = std_config[std].band[0];
564 band2 = std_config[std].band[1];
565
566 //get these from std
567 pt1 = band_config[band1].addr;
568 pt2 = band_config[band2].addr;
569
570 // copy rf-struct from default flash to ram
571 memcpy(&rf_band[0], pt1, sizeof(T_RF_BAND));
572
573 if(std_config[std].band[1] != BAND_NONE )
574 memcpy(&rf_band[1], pt2, sizeof(T_RF_BAND));
575
576 // Read all RF and system configuration from FFS *before* we copy any of
577 // the rf structure variables to other places, like L1.
578
579 config_ffs_read('*');
580
581 l1_config.std.first_radio_freq = std_config[std].first_arfcn;
582
583 if(band2!=0)
584 l1_config.std.first_radio_freq_band2 = band_config[band1].max_carrier + 1;
585 else
586 l1_config.std.first_radio_freq_band2 = 0; //band1 carrier + 1 else 0
587
588 // if band2 is not used it is initialised with zeros
589 l1_config.std.nbmax_carrier = band_config[band1].max_carrier;
590 if(band2!=0)
591 l1_config.std.nbmax_carrier += band_config[band2].max_carrier;
592
593 l1_config.std.max_txpwr_band1 = band_config[band1].max_txpwr;
594 l1_config.std.max_txpwr_band2 = band_config[band2].max_txpwr;
595 l1_config.std.txpwr_turning_point = std_config[std].txpwr_tp;
596 l1_config.std.cal_freq1_band1 = 0;
597 l1_config.std.cal_freq1_band2 = 0;
598
599 l1_config.std.g_magic_band1 = rf_band[MULTI_BAND1].rx.rx_cal_params.g_magic;
600 l1_config.std.lna_att_band1 = rf_band[MULTI_BAND1].rx.rx_cal_params.lna_att;
601 l1_config.std.lna_switch_thr_low_band1 = rf_band[MULTI_BAND1].rx.rx_cal_params.lna_switch_thr_low;
602 l1_config.std.lna_switch_thr_high_band1 = rf_band[MULTI_BAND1].rx.rx_cal_params.lna_switch_thr_high;
603 l1_config.std.swap_iq_band1 = rf_band[MULTI_BAND1].swap_iq;
604
605 l1_config.std.g_magic_band2 = rf_band[MULTI_BAND2].rx.rx_cal_params.g_magic;
606 l1_config.std.lna_att_band2 = rf_band[MULTI_BAND2].rx.rx_cal_params.lna_att;
607 l1_config.std.lna_switch_thr_low_band2 = rf_band[MULTI_BAND2].rx.rx_cal_params.lna_switch_thr_low;
608 l1_config.std.lna_switch_thr_high_band2 = rf_band[MULTI_BAND2].rx.rx_cal_params.lna_switch_thr_high;
609 l1_config.std.swap_iq_band2 = rf_band[MULTI_BAND2].swap_iq;
610
611 l1_config.std.radio_freq_index_offset = l1_config.std.first_radio_freq-1;
612
613 // init variable indicating which radio bands are supported by the chosen RF
614 l1_config.std.radio_band_support = rf.radio_band_support;
615
616 //TBD: DRP Calib: Currently the Calib Data are only used for the routines, TBD add to l1_config. from saved Calibration
617 // on a need basis ?
618 }
619 #else
620 {
621 UWORD8 i;
622
623 for (i = 0; i < RF_NB_SUPPORTED_BANDS; i++)
624 {
625 switch(multiband_rf[i].gsm_band_identifier)
626 {
627 case RF_GSM900:
628 rf_band[i]=rf_900;
629 break;
630 case RF_GSM850:
631 rf_band[i]=rf_850;
632 break;
633 case RF_DCS1800:
634 rf_band[i]=rf_1800;
635 break;
636 case RF_PCS1900:
637 rf_band[i]=rf_1900;
638 break;
639 default:
640 break;
641 }
642 }
643 config_ffs_read('*');
644 }
645 #endif // if (L1_FF_MULTIBAND == 0)
646
647
648 /*-------------------------------------------------------*/
649 /* Cust_init_params() */
650 /*-------------------------------------------------------*/
651 /* Parameters : */
652 /* Return : */
653 /* Functionality : Init RF dependent paramters (AGC, TX) */
654 /*-------------------------------------------------------*/
655 void Cust_init_params(void)
656 {
657
658 #if (CODE_VERSION==SIMULATION)
659 extern UWORD16 simu_RX_SYNTH_SETUP_TIME; // set in xxx.txt l3 scenario file
660 extern UWORD16 simu_TX_SYNTH_SETUP_TIME; // set in xxx.txt l3 scenario file
661
662 l1_config.params.rx_synth_setup_time = simu_RX_SYNTH_SETUP_TIME;
663 l1_config.params.tx_synth_setup_time = simu_TX_SYNTH_SETUP_TIME;
664 #else
665 l1_config.params.rx_synth_setup_time = RX_SYNTH_SETUP_TIME;
666 l1_config.params.tx_synth_setup_time = TX_SYNTH_SETUP_TIME;
667 #endif
668
669
670 // Convert SYNTH_SETUP_TIME into SPLIT.
671 // We have kept a margin of 20qbit (EPSILON_MEAS) to cover offset change and Scenario closing time + margin.
672 l1_config.params.rx_synth_load_split = 1L + (l1_config.params.rx_synth_setup_time + EPSILON_MEAS) / (BP_DURATION/BP_SPLIT);
673 l1_config.params.tx_synth_load_split = 1L + (l1_config.params.tx_synth_setup_time + EPSILON_MEAS) / (BP_DURATION/BP_SPLIT);
674
675 l1_config.params.rx_synth_start_time = TPU_CLOCK_RANGE + PROVISION_TIME - l1_config.params.rx_synth_setup_time;
676 l1_config.params.tx_synth_start_time = TPU_CLOCK_RANGE - l1_config.params.tx_synth_setup_time;
677
678 l1_config.params.rx_change_synchro_time = l1_config.params.rx_synth_start_time - EPSILON_SYNC;
679 l1_config.params.rx_change_offset_time = l1_config.params.rx_synth_start_time - EPSILON_OFFS;
680
681 l1_config.params.tx_change_offset_time = TIME_OFFSET_TX -
682 TA_MAX -
683 l1_config.params.tx_synth_setup_time -
684 EPSILON_OFFS;
685
686 // TX duration = ramp up time + burst duration (data + tail bits)
687 l1_config.params.tx_nb_duration = UL_ABB_DELAY + rf.tx.guard_bits*4 + NB_BURST_DURATION_UL;
688 l1_config.params.tx_ra_duration = UL_ABB_DELAY + rf.tx.guard_bits*4 + RA_BURST_DURATION;
689
690 l1_config.params.tx_nb_load_split = 1L + (l1_config.params.tx_nb_duration - rf.tx.prg_tx - NB_MARGIN) / (BP_DURATION/BP_SPLIT);
691 l1_config.params.tx_ra_load_split = 1L + (l1_config.params.tx_ra_duration - rf.tx.prg_tx - NB_MARGIN) / (BP_DURATION/BP_SPLIT);
692
693 // time for the end of RX and TX TPU scenarios
694 l1_config.params.rx_tpu_scenario_ending = RX_TPU_SCENARIO_ENDING;
695 l1_config.params.tx_tpu_scenario_ending = TX_TPU_SCENARIO_ENDING;
696
697 // FB26 anchoring time is computed backward to leave only 6 qbit margin between
698 // FB26 window and next activity (RX time tracking).
699 // This margin is used as follow:
700 // Serving offset restore: 1 qbit (SERV_OFFS_REST_LOAD)
701 // Tpu Sleep: 2 qbit (TPU_SLEEP_LOAD)
702 // ---------
703 // Total: 3 qbit
704
705 l1_config.params.fb26_anchoring_time = (l1_config.params.rx_synth_start_time -
706 #if (CODE_VERSION == SIMULATION)
707 // simulator: end of scenario not included in window (no serialization)
708 1 -
709 #else
710 // RF dependent end of RX TPU scenario
711 l1_config.params.rx_tpu_scenario_ending -
712 #endif
713 EPSILON_SYNC -
714 TPU_SLEEP_LOAD -
715 SERV_OFFS_REST_LOAD -
716 FB26_ACQUIS_DURATION -
717 PROVISION_TIME +
718 TPU_CLOCK_RANGE) % TPU_CLOCK_RANGE;
719
720 l1_config.params.fb26_change_offset_time = l1_config.params.fb26_anchoring_time +
721 PROVISION_TIME -
722 l1_config.params.rx_synth_setup_time -
723 EPSILON_OFFS;
724
725 l1_config.params.guard_bits = rf.tx.guard_bits;
726
727 l1_config.params.prg_tx_gsm = rf.tx.prg_tx;
728 l1_config.params.prg_tx_dcs = rf.tx.prg_tx; //delay for dual band not implemented yet
729
730 l1_config.params.low_agc_noise_thr = rf.rx.agc.low_agc_noise_thr;
731 l1_config.params.high_agc_sat_thr = rf.rx.agc.high_agc_sat_thr;
732 l1_config.params.low_agc = rf.rx.agc.low_agc;
733 l1_config.params.high_agc = rf.rx.agc.high_agc;
734 l1_config.params.il_min = IL_MIN;
735
736 l1_config.params.fixed_txpwr = FIXED_TXPWR;
737 l1_config.params.eeprom_afc = rf.afc.eeprom_afc;
738 l1_config.params.setup_afc_and_rf = SETUP_AFC_AND_RF;
739 l1_config.params.rf_wakeup_tpu_scenario_duration = l1_config.params.setup_afc_and_rf + 1; //directly dependent of l1dmacro_RF_wakeup implementation
740
741 l1_config.params.psi_sta_inv = rf.afc.psi_sta_inv;
742 l1_config.params.psi_st = rf.afc.psi_st;
743 l1_config.params.psi_st_32 = rf.afc.psi_st_32;
744 l1_config.params.psi_st_inv = rf.afc.psi_st_inv;
745
746 #if (CODE_VERSION == SIMULATION)
747 #if (VCXO_ALGO == 1)
748 l1_config.params.afc_algo = ALGO_AFC_LQG_PREDICTOR; // VCXO|VCTCXO - Choosing AFC algorithm
749 #endif
750 #else
751 #if (VCXO_ALGO == 1)
752 l1_config.params.afc_dac_center = rf.afc.dac_center; // VCXO - assuming DAC linearity
753 l1_config.params.afc_dac_min = rf.afc.dac_min; // VCXO - assuming DAC linearity
754 l1_config.params.afc_dac_max = rf.afc.dac_max; // VCXO - assuming DAC linearity
755 #if (NEW_SNR_THRESHOLD == 0)
756 l1_config.params.afc_snr_thr = rf.afc.snr_thr; // VCXO - SNR threshold
757 #else
758 l1_config.params.afc_snr_thr = L1_TOA_SNR_THRESHOLD;
759 #endif /* NEW_SNR_THRESHOLD */
760 l1_config.params.afc_algo = ALGO_AFC_LQG_PREDICTOR; // VCXO|VCTCXO - Choosing AFC algorithm
761 l1_config.params.afc_win_avg_size_M = C_WIN_AVG_SIZE_M; // VCXO - Average psi values with this value
762 l1_config.params.rgap_algo = ALGO_AFC_RXGAP; // VCXO - Choosing Reception Gap algorithm
763 l1_config.params.rgap_bad_snr_count_B = C_RGAP_BAD_SNR_COUNT_B; // VCXO - Prediction SNR count
764 #endif
765 #endif
766
767 #if DCO_ALGO
768 #if (RF_FAM == 10)
769 // Enable DCO algorithm for direct conversion RFs
770 l1_config.params.dco_enabled = TRUE;
771 #else
772 l1_config.params.dco_enabled = FALSE;
773 #endif
774 #endif
775
776 #if (ANLG_FAM == 1)
777 l1_config.params.debug1 = C_DEBUG1; // Enable f_tx delay of 400000 cyc DEBUG
778 l1_config.params.afcctladd = abb[ABB_AFCCTLADD]; // Value at reset
779 l1_config.params.vbuctrl = abb[ABB_VBUCTRL]; // Uplink gain amp 0dB, Sidetone gain to mute
780 l1_config.params.vbdctrl = abb[ABB_VBDCTRL]; // Downlink gain amp 0dB, Volume control 0 dB
781 l1_config.params.bbctrl = abb[ABB_BBCTRL]; // value at reset
782 l1_config.params.apcoff = abb[ABB_APCOFF]; // value at reset
783 l1_config.params.bulioff = abb[ABB_BULIOFF]; // value at reset
784 l1_config.params.bulqoff = abb[ABB_BULQOFF]; // value at reset
785 l1_config.params.dai_onoff = abb[ABB_DAI_ON_OFF]; // value at reset
786 l1_config.params.auxdac = abb[ABB_AUXDAC]; // value at reset
787 l1_config.params.vbctrl = abb[ABB_VBCTRL]; // VULSWITCH=0, VDLAUX=1, VDLEAR=1
788 l1_config.params.apcdel1 = abb[ABB_APCDEL1]; // value at reset
789 #endif
790 #if (ANLG_FAM == 2)
791 l1_config.params.debug1 = C_DEBUG1; // Enable f_tx delay of 400000 cyc DEBUG
792 l1_config.params.afcctladd = abb[ABB_AFCCTLADD]; // Value at reset
793 l1_config.params.vbuctrl = abb[ABB_VBUCTRL]; // Uplink gain amp 0dB, Sidetone gain to mute
794 l1_config.params.vbdctrl = abb[ABB_VBDCTRL]; // Downlink gain amp 0dB, Volume control 0 dB
795 l1_config.params.bbctrl = abb[ABB_BBCTRL]; // value at reset
796 l1_config.params.bulgcal = abb[ABB_BULGCAL]; // value at reset
797 l1_config.params.apcoff = abb[ABB_APCOFF]; // value at reset
798 l1_config.params.bulioff = abb[ABB_BULIOFF]; // value at reset
799 l1_config.params.bulqoff = abb[ABB_BULQOFF]; // value at reset
800 l1_config.params.dai_onoff = abb[ABB_DAI_ON_OFF]; // value at reset
801 l1_config.params.auxdac = abb[ABB_AUXDAC]; // value at reset
802 l1_config.params.vbctrl1 = abb[ABB_VBCTRL1]; // VULSWITCH=0, VDLAUX=1, VDLEAR=1
803 l1_config.params.vbctrl2 = abb[ABB_VBCTRL2]; // MICBIASEL=0, VDLHSO=0, MICAUX=0
804 l1_config.params.apcdel1 = abb[ABB_APCDEL1]; // value at reset
805 l1_config.params.apcdel2 = abb[ABB_APCDEL2]; // value at reset
806 #endif
807 #if (ANLG_FAM == 3)
808 l1_config.params.debug1 = C_DEBUG1; // Enable f_tx delay of 400000 cyc DEBUG
809 l1_config.params.afcctladd = abb[ABB_AFCCTLADD]; // Value at reset
810 l1_config.params.vbuctrl = abb[ABB_VBUCTRL]; // Uplink gain amp 0dB, Sidetone gain to mute
811 l1_config.params.vbdctrl = abb[ABB_VBDCTRL]; // Downlink gain amp 0dB, Volume control 0 dB
812 l1_config.params.bbctrl = abb[ABB_BBCTRL]; // value at reset
813 l1_config.params.bulgcal = abb[ABB_BULGCAL]; // value at reset
814 l1_config.params.apcoff = abb[ABB_APCOFF]; // X2 Slope 128 and APCSWP disabled
815 l1_config.params.bulioff = abb[ABB_BULIOFF]; // value at reset
816 l1_config.params.bulqoff = abb[ABB_BULQOFF]; // value at reset
817 l1_config.params.dai_onoff = abb[ABB_DAI_ON_OFF]; // value at reset
818 l1_config.params.auxdac = abb[ABB_AUXDAC]; // value at reset
819 l1_config.params.vbctrl1 = abb[ABB_VBCTRL1]; // VULSWITCH=0
820 l1_config.params.vbctrl2 = abb[ABB_VBCTRL2]; // MICBIASEL=0, VDLHSO=0, MICAUX=0
821 l1_config.params.apcdel1 = abb[ABB_APCDEL1]; // value at reset
822 l1_config.params.apcdel2 = abb[ABB_APCDEL2]; // value at reset
823 l1_config.params.vbpop = abb[ABB_VBPOP]; // HSOAUTO enabled
824 l1_config.params.vau_delay_init = abb[ABB_VAUDINITD]; // 2 TDMA Frames between VDL "ON" and VDLHSO "ON"
825 l1_config.params.vaud_cfg = abb[ABB_VAUDCTRL]; // value at reset
826 l1_config.params.vauo_onoff = abb[ABB_VAUOCTRL]; // speech on AUX and EAR
827 l1_config.params.vaus_vol = abb[ABB_VAUSCTRL]; // value at reset
828 l1_config.params.vaud_pll = abb[ABB_VAUDPLL]; // value at reset
829 #endif
830
831 #if (RF_FAM == 61)
832 l1_config.params.apcctrl2 = drp_wrapper[DRP_WRAPPER_APCCTRL2];
833 l1_config.params.apcdel1 = drp_wrapper[DRP_WRAPPER_APCDEL1];
834 l1_config.params.apcdel2 = drp_wrapper[DRP_WRAPPER_APCDEL2];
835 #endif
836 #if (ANLG_FAM == 11)
837 l1_config.params.vulgain = abb[ABB_VULGAIN];
838 l1_config.params.vdlgain = abb[ABB_VDLGAIN];
839 l1_config.params.sidetone = abb[ABB_SIDETONE];
840 l1_config.params.ctrl1 = abb[ABB_CTRL1];
841 l1_config.params.ctrl2 = abb[ABB_CTRL2];
842 l1_config.params.ctrl3 = abb[ABB_CTRL3];
843 l1_config.params.ctrl4 = abb[ABB_CTRL4];
844 l1_config.params.ctrl5 = abb[ABB_CTRL5];
845 l1_config.params.ctrl6 = abb[ABB_CTRL6];
846 l1_config.params.popauto = abb[ABB_POPAUTO];
847 l1_config.params.outen1 = abb[ABB_OUTEN1];
848 l1_config.params.outen2 = abb[ABB_OUTEN2];
849 l1_config.params.outen3 = abb[ABB_OUTEN3];
850 l1_config.params.aulga = abb[ABB_AULGA];
851 l1_config.params.aurga = abb[ABB_AURGA];
852 #endif
853 }
854
855
856 /************************************/
857 /* Automatic Gain Control */
858 /************************************/
859
860 /*-------------------------------------------------------*/
861 /* Cust_get_agc_from_IL() */
862 /*-------------------------------------------------------*/
863 /* Parameters : */
864 /* Return : */
865 /* Functionality : returns agc value */
866 /*-------------------------------------------------------*/
867 WORD8 Cust_get_agc_from_IL(UWORD16 radio_freq, UWORD16 agc_index, UWORD8 table_id,UWORD8 lna_off_val)
868 {
869
870 UWORD16 agc_index_temp;
871
872 // radio_freq currently not used
873 // this parameter is passed in order to allow band dependent tables for specific RFs
874 // (e.g. dual band RF with separate AGC H/W blocks for GSM and DCS)
875
876 agc_index_temp = (agc_index<<1) + (lna_off_val * l1ctl_get_lna_att(radio_freq));
877 agc_index= agc_index_temp>>1;
878 if (agc_index > 120)
879 agc_index = 120; // Clip agc_index
880
881 switch (table_id)
882 {
883 case MAX_ID: return(rf.rx.agc.il2agc_max[agc_index]);
884 case AV_ID: return(rf.rx.agc.il2agc_av[agc_index]);
885 case PWR_ID: return(rf.rx.agc.il2agc_pwr[agc_index]);
886 }
887 return (0);//omaps00090550
888 }
889
890 /*-------------------------------------------------------*/
891 /* Cust_get_agc_band */
892 /*-------------------------------------------------------*/
893 /* Parameters : radio_freq */
894 /* Return : band number */
895 /* Functionality : Computes the band for RF calibration */
896 /*-------------------------------------------------------*/
897 /*---------------------------------------------*/
898
899 UWORD8 band_number;
900 #if (CODE_VERSION == SIMULATION)
901 UWORD16 Cust_get_agc_band(UWORD16 arfcn, UWORD8 gsm_band)
902 #else
903 UWORD16 inline Cust_get_agc_band(UWORD16 arfcn, UWORD8 gsm_band)
904 #endif
905 {
906 // WORD32 i =0 ; //omaps00090550
907
908 for (band_number=0;band_number<RF_RX_CAL_CHAN_SIZE;band_number++)
909 {
910 if (arfcn <= rf_band[gsm_band].rx.agc_bands[band_number].upper_bound)
911 return(band_number);
912 }
913 // Should never happen!
914 return(0);
915 }
916
917 #if (L1_FF_MULTIBAND == 0)
918 /*-------------------------------------------------------*/
919 /* Cust_is_band_high */
920 /*-------------------------------------------------------*/
921 /* Parameters : arfcn */
922 /* Return : 0 if low band */
923 /* 1 if high band */
924 /* Functionality : Generic function which return 1 if */
925 /* arfcn is in the high band */
926 /*-------------------------------------------------------*/
927
928 UWORD8 Cust_is_band_high(UWORD16 radio_freq)
929 {
930 UWORD16 max_carrier;
931 UWORD8 std = l1_config.std.id;
932
933 max_carrier = band_config[std_config[std].band[0]].max_carrier;
934
935 return(((radio_freq >= l1_config.std.first_radio_freq) &&
936 (radio_freq < (l1_config.std.first_radio_freq + max_carrier))) ? MULTI_BAND1 : MULTI_BAND2);
937 }
938 #endif
939
940 /*-------------------------------------------------------*/
941 /* l1ctl_encode_delta2() */
942 /*-------------------------------------------------------*/
943 /* Parameters : */
944 /* Return : */
945 /* Functionality : */
946 /*-------------------------------------------------------*/
947 WORD8 l1ctl_encode_delta2(UWORD16 radio_freq)
948 {
949 WORD8 delta2_freq;
950 UWORD16 i;
951 UWORD16 arfcn;
952 #if (L1_FF_MULTIBAND == 0)
953 UWORD8 band;
954
955 band = Cust_is_band_high(radio_freq);
956 arfcn = Convert_l1_radio_freq(radio_freq);
957 #else
958 WORD8 band;
959 // Corrected for input being rf_freq and not l1_freq
960 arfcn = rf_convert_l1freq_to_arfcn_rfband(rf_convert_rffreq_to_l1freq(radio_freq), &band);
961 #endif
962
963 i = Cust_get_agc_band(arfcn,band); //
964 delta2_freq = rf_band[band].rx.agc_bands[i].agc_calib;
965
966 //temperature compensation
967 for (i=0;i<RF_RX_CAL_TEMP_SIZE;i++)
968 {
969 if ((WORD16)adc.converted[ADC_RFTEMP] <= rf_band[band].rx.temp[i].temperature)
970 {
971 delta2_freq += rf_band[band].rx.temp[i].agc_calib;
972 break;
973 }
974 }
975
976 return(delta2_freq);
977 }
978
979 #if (L1_FF_MULTIBAND == 0)
980 #else
981 /*-------------------------------------------------------*/
982 /* l1ctl_get_g_magic() */
983 /*-------------------------------------------------------*/
984 /* Parameters : */
985 /* Return : */
986 /* Functionality : */
987 /*-------------------------------------------------------*/
988 UWORD16 l1ctl_get_g_magic(UWORD16 radio_freq)
989 {
990 // Corrected for input being rf_freq and not l1_freq
991 return (rf_band[rf_subband2band[rf_convert_rffreq_to_l1subband(radio_freq)]].rx.rx_cal_params.g_magic);
992 }
993
994
995 /*-------------------------------------------------------*/
996 /* l1ctl_get_lna_att() */
997 /*-------------------------------------------------------*/
998 /* Parameters : */
999 /* Return : */
1000 /* Functionality : */
1001 /*-------------------------------------------------------*/
1002 UWORD16 l1ctl_get_lna_att(UWORD16 radio_freq)
1003 {
1004 // The function is provided with rf_freq as input so
1005 // convert rf_freq to l1_subband then convert l1_subband to rf_band and index into rf_band
1006 return( rf_band[rf_subband2band[rf_convert_rffreq_to_l1subband(radio_freq)]].rx.rx_cal_params.lna_att);
1007 // return (rf_band[rf_convert_l1freq_to_rf_band_idx(radio_freq)].rx.rx_cal_params.lna_att);
1008 }
1009 /*-------------------------------------------------------*/
1010 /* l1ctl_encode_delta1() */
1011 /*-------------------------------------------------------*/
1012 /* Parameters : */
1013 /* Return : */
1014 /* Functionality : */
1015 /*-------------------------------------------------------*/
1016 WORD8 l1ctl_encode_delta1(UWORD16 radio_freq)
1017 {
1018 return 0;
1019 }
1020 /*-------------------------------------------------------*/
1021 /* l1ctl_encode_lna() */
1022 /*-------------------------------------------------------*/
1023 /* Parameters : */
1024 /* Return : */
1025 /* Functionality : */
1026 /*-------------------------------------------------------*/
1027 void l1ctl_encode_lna( UWORD8 input_level,
1028 UWORD8 *lna_state,
1029 UWORD16 radio_freq)
1030 {
1031
1032 /*** LNA Hysteresis is implemented as following :
1033
1034 |
1035 On|---<>----+-------+
1036 | | |
1037 LNA | | |
1038 | ^ v
1039 | | |
1040 | | |
1041 Off| +-------+----<>-----
1042 +--------------------------------
1043 50 40 30 20 input_level /-dBm
1044 THR_HIGH THR_LOW ***/
1045 WORD8 band;
1046 // Corrected for input to be rf_freq and not l1_freq
1047 band = rf_subband2band[rf_convert_rffreq_to_l1subband(radio_freq)];
1048 if ( input_level > rf_band[band].rx.rx_cal_params.lna_switch_thr_high) // < -44dBm ?
1049 {
1050 *lna_state = LNA_ON; // lna_off = FALSE
1051 }
1052 else if ( input_level < rf_band[band].rx.rx_cal_params.lna_switch_thr_low) // > -40dBm ?
1053 {
1054 *lna_state = LNA_OFF; // lna off = TRUE
1055 }
1056 }
1057
1058 UWORD8 l1ctl_get_iqswap(UWORD16 rf_freq)
1059 {
1060 return(rf_band[rf_subband2band[rf_convert_rffreq_to_l1subband(rf_freq)]].swap_iq);
1061 }
1062
1063 #endif //if L1_FF_MULTIBAND == 0)
1064
1065 /************************************/
1066 /* TX Management */
1067 /************************************/
1068 /*-------------------------------------------------------*/
1069 /* Cust_get_ramp_tab */
1070 /*-------------------------------------------------------*/
1071 /* Parameters : */
1072 /* Return : */
1073 /* Functionality :
1074 Notes:
1075 Cal+
1076 APCRAM : Dwn(15:11)Up(10:6)Forced(0)
1077 Locosto:
1078 APCRAM: Dwn(15:8)Up(7:0)
1079
1080 */
1081 /*-------------------------------------------------------*/
1082
1083 void Cust_get_ramp_tab(API *a_ramp, UWORD8 txpwr_ramp_up, UWORD8 txpwr_ramp_down, UWORD16 radio_freq)
1084 {
1085 UWORD16 index_up, index_down,j, arfcn;
1086 #if (L1_FF_MULTIBAND == 0)
1087 UWORD8 band;
1088
1089 band = Cust_is_band_high(radio_freq);
1090 arfcn = Convert_l1_radio_freq(radio_freq);
1091 #else
1092 WORD8 band;
1093 // Corrected for input being rf_freq and not l1_freq
1094 arfcn = rf_convert_l1freq_to_arfcn_rfband(rf_convert_rffreq_to_l1freq(radio_freq), &band);
1095 #endif //if( L1_FF_MULTIBAND == 0)
1096
1097 index_up = rf_band[band].tx.levels[txpwr_ramp_up].ramp_index;
1098 index_down = rf_band[band].tx.levels[txpwr_ramp_down].ramp_index;
1099
1100 #if ((ANLG_FAM == 1) || (ANLG_FAM == 2) || (ANLG_FAM == 3))
1101 for (j=0; j<16; j++)
1102 {
1103 a_ramp[j]=((rf_band[band].tx.ramp_tables[index_down].ramp_down[j])<<11) |
1104 ((rf_band[band].tx.ramp_tables[index_up].ramp_up[j]) << 6) |
1105 0x14;
1106 }
1107 #endif
1108
1109 #if (RF_FAM == 61)
1110 // 20 Coeff each 8 (RampDown) + 8 (RampUp)
1111 for (j=0; j<20; j++)
1112 {
1113 a_ramp[j]=( (255 - (rf_band[band].tx.ramp_tables[index_down].ramp_down[j]) ) <<8) |
1114 ((rf_band[band].tx.ramp_tables[index_up].ramp_up[j])) ;
1115 }
1116 #endif
1117 }
1118
1119 /*-------------------------------------------------------*/
1120 /* get_pwr_data */
1121 /*-------------------------------------------------------*/
1122 /* Parameters : */
1123 /* Return : */
1124 /* Functionality : */
1125 /*-------------------------------------------------------*/
1126
1127 #if ((ANLG_FAM == 1) || (ANLG_FAM == 2) || (ANLG_FAM == 3) || (RF_FAM == 61))
1128 UWORD16 Cust_get_pwr_data(UWORD8 txpwr, UWORD16 radio_freq
1129 #if (REL99 && FF_PRF)
1130 , UWORD8 number_uplink_timeslot
1131 #endif
1132 )
1133 {
1134
1135 UWORD16 i,j;
1136 UWORD16 arfcn;
1137
1138 T_TX_LEVEL *a_tx_levels;
1139
1140 #if (APC_VBAT_COMP == 1)
1141 static UWORD16 apc_max_value = APC_MAX_VALUE;
1142 #endif
1143
1144 #if(ORDER2_TX_TEMP_CAL==1)
1145 WORD16 pwr_data;
1146 #else
1147 UWORD16 pwr_data;
1148 #endif
1149
1150 #if (L1_FF_MULTIBAND == 0)
1151 UWORD8 band;
1152 band = Cust_is_band_high(radio_freq);
1153 arfcn = Convert_l1_radio_freq(radio_freq);
1154 #else
1155 WORD8 band;
1156 // Corrected for input being rf_freq and not l1_freq
1157 arfcn = rf_convert_l1freq_to_arfcn_rfband(rf_convert_rffreq_to_l1freq(radio_freq), &band);
1158 #endif //if( L1_FF_MULTIBAND == 0)
1159
1160 // band = Cust_is_band_high(radio_freq);
1161 // arfcn = Convert_l1_radio_freq(radio_freq);
1162
1163 a_tx_levels = &(rf_band[band].tx.levels[txpwr]); // get pointer to rf tx structure
1164
1165 #if REL99
1166 #if FF_PRF
1167 // uplink power reduction feature which decrease power level in case of uplink multislot
1168 a_tx_levels = Cust_get_uplink_apc_power_reduction(band, number_uplink_timeslot, a_tx_levels);
1169 #endif
1170 #endif
1171
1172 // get uncalibrated apc
1173 pwr_data = a_tx_levels->apc;
1174
1175 i = a_tx_levels->chan_cal_index; // get index for channel compensation
1176 j=0;
1177
1178 while (arfcn > rf_band[band].tx.chan_cal_table[i][j].arfcn_limit)
1179 j++;
1180
1181 // channel calibrate apc
1182 pwr_data = ((UWORD32) (pwr_data * rf_band[band].tx.chan_cal_table[i][j].chan_cal))/128;
1183
1184 // temperature compensate apc
1185 {
1186 T_TX_TEMP_CAL *pt;
1187
1188 pt = rf_band[band].tx.temp;
1189 while (((WORD16)adc.converted[ADC_RFTEMP] > pt->temperature) && ((pt-rf_band[band].tx.temp) < (RF_TX_CAL_TEMP_SIZE-1)))
1190 pt++;
1191 #if(ORDER2_TX_TEMP_CAL==1)
1192 pwr_data += (txpwr*(pt->a*txpwr + pt->b) + pt->c) / 64; //delta apc = ax^2+bx+c
1193 if(pwr_data < 0) pwr_data = 0;
1194 #else
1195 pwr_data += pt->apc_calib;
1196 #endif
1197 }
1198
1199 // Vbat compensate apc
1200 #if (APC_VBAT_COMP == 1)
1201
1202 if (adc.converted[ADC_VBAT] < VBAT_LOW_THRESHOLD)
1203 apc_max_value = APC_MAX_VALUE_LOW_BAT;
1204
1205 else if (adc.converted[ADC_VBAT] > VBAT_HIGH_THRESHOLD)
1206 apc_max_value = APC_MAX_VALUE;
1207
1208 // else do nothing as Vbat is staying between VBAT_LOW_THRESHOLD and
1209 // VBAT_HIGH_THRESHOLD -> max APC value is still the same than previous one
1210
1211 if (pwr_data > apc_max_value)
1212 pwr_data = apc_max_value;
1213 #endif // APC_VBAT_COMP == 1
1214
1215 return(pwr_data);
1216 }
1217 #endif
1218
1219
1220 #if(REL99 && FF_PRF)
1221
1222 /*-------------------------------------------------------*/
1223 /* Cust_get_uplink_apc_power_reduction */
1224 /*-------------------------------------------------------*/
1225 /* Parameters : */
1226 /* - frenquency band */
1227 /* - modulation type */
1228 /* - number of uplink timeslot */
1229 /* - pointer to radio power control structure */
1230 /* Return : */
1231 /* - pointer to radio power control structure */
1232 /* */
1233 /* Functionality : This function returns a pointer to */
1234 /* the radio power control structure after power */
1235 /* reduction processing. */
1236 /* Depending of the number of uplink timeslot, the */
1237 /* analogue power control (apc) value can be reduced */
1238 /* in order to limit effect of terminal heat */
1239 /* dissipation due to power amplifier. */
1240 /*-------------------------------------------------------*/
1241
1242 T_TX_LEVEL *Cust_get_uplink_apc_power_reduction(UWORD8 band,
1243 UWORD8 number_uplink_timeslot,
1244 T_TX_LEVEL *p_tx_level)
1245 {
1246 T_TX_LEVEL *p_power_reduction_tx_level;
1247
1248 #if TESTMODE
1249 if ((l1_config.TestMode == TRUE) && (l1_config.tmode.tx_params.power_reduction_enable == FALSE))
1250 return p_tx_level ; // return without any power reduction
1251 #endif
1252
1253 if ((number_uplink_timeslot >= 1) && (number_uplink_timeslot <= MAX_UPLINK_TIME_SLOT))
1254 {
1255 number_uplink_timeslot--; // index start from 0
1256 }
1257 else
1258 {
1259 return p_tx_level; // abnormal case we do not apply any power reduction
1260 }
1261
1262 p_power_reduction_tx_level = &(rf_band[band].tx.levels_power_reduction[number_uplink_timeslot]);
1263
1264 // We select the lowest power level in order to apply power reduction
1265 #if (CODE_VERSION != SIMULATION)
1266 if (p_tx_level->apc > p_power_reduction_tx_level->apc) // higher apc value means higher transmit power
1267 #else
1268 if (p_tx_level->apc < p_power_reduction_tx_level->apc) // ! for simulation rf apc tables are inverted so comparaison is the reverse
1269 #endif
1270 return p_power_reduction_tx_level;
1271 else
1272 return p_tx_level;
1273 }
1274
1275 #endif
1276
1277 /*-------------------------------------------------------*/
1278 /* Cust_Init_Layer1 */
1279 /*-------------------------------------------------------*/
1280 /* Parameters : */
1281 /* Return : */
1282 /* Functionality : Load and boot the DSP */
1283 /* Initialize shared memory and L1 data structures */
1284 /*-------------------------------------------------------*/
1285
1286 void Cust_Init_Layer1(void)
1287 {
1288 T_MMI_L1_CONFIG cfg;
1289
1290 // Get the current band configuration from the flash
1291 #if (OP_WCP==1) && (OP_L1_STANDALONE!=1)
1292 extern unsigned char ffs_GetBand();
1293 cfg.std = ffs_GetBand();
1294 #else // NO OP_WCP
1295 // cfg.std = std;
1296 cfg.std = STD;
1297 #endif // OP_WCP
1298
1299 cfg.tx_pwr_code = 1;
1300
1301 // sleep management configuration
1302
1303 #if(L1_POWER_MGT == 0)
1304 cfg.pwr_mngt = 0;
1305 cfg.pwr_mngt_mode_authorized = NO_SLEEP; //Sleep mode
1306 cfg.pwr_mngt_clocks = 0x5ff; // list of clocks cut in Big Sleep
1307 #endif
1308 #if(L1_POWER_MGT == 1)
1309 cfg.pwr_mngt = 1;
1310 cfg.pwr_mngt_mode_authorized = ALL_SLEEP; //Sleep mode
1311 cfg.pwr_mngt_clocks = 0x5ff; // list of clocks cut in Big Sleep
1312 #endif
1313
1314
1315
1316
1317
1318 #if (CODE_VERSION != SIMULATION)
1319 cfg.dwnld = DWNLD; //external define from makefile
1320 #endif
1321
1322 l1_initialize(&cfg);
1323
1324 //add below line for CSR 174476
1325 trace_info.current_config->l1_dyn_trace = 0; //disable L1 trace after L1 init
1326
1327 get_cal_from_nvmem((UWORD8 *)&rf, sizeof(rf), RF_ID);
1328 get_cal_from_nvmem((UWORD8 *)&adc_cal, sizeof(adc_cal), ADC_ID);
1329
1330 }
1331
1332
1333 /*****************************************************************************************/
1334 /*************************** TESTMODE functions **********************************/
1335 /*****************************************************************************************/
1336
1337
1338
1339 /*------------------------------------------------------*/
1340 /* madc_hex_2_physical */
1341 /*------------------------------------------------------*/
1342 /* Parameters : */
1343 /* Return : */
1344 /* Functionality : Function to convert MAD hexadecimal */
1345 /* values into physical values */
1346 /*------------------------------------------------------*/
1347
1348 void madc_hex_2_physical (UWORD16 *adc_hex, T_ADC *adc_phy)
1349 {
1350 WORD16 i;
1351 UWORD16 y;
1352 WORD16 Smin = 0, Smax = TEMP_TABLE_SIZE-1;
1353 WORD16 index = (TEMP_TABLE_SIZE-1)/2; /* y is the adc code after compensation of ADC slope error introduced by VREF error */
1354
1355 //store raw ADC values
1356 memcpy(&adc.raw[0], adc_hex, sizeof(adc.raw));
1357
1358 // Convert Vbat [mV] : direct equation with slope and offset compensation
1359 for (i = ADC_VBAT; i<ADC_RFTEMP; i++)
1360 adc.converted[i] = (((UWORD32)(adc_cal.a[i] * adc.raw[i])) >>10) + adc_cal.b[i];
1361
1362 /*Convert RF Temperature [Celsius]: binsearch into a table*/
1363 y = ((UWORD32)(adc_cal.a[ADC_RFTEMP] * adc.raw[ADC_RFTEMP]))>>8; /* rf.tempcal is the calibration of VREF*/
1364 while((Smax-Smin) > 1 )
1365 {
1366 if(y < temperature[index].adc)
1367 Smax=index;
1368 else
1369 Smin=index;
1370
1371 index = (Smax+Smin)/2;
1372 }
1373 adc.converted[ADC_RFTEMP] = temperature[index].temp;
1374
1375 for (i = ADC_RFTEMP+1; i<ADC_INDEX_END; i++)
1376 adc.converted[i] = (((UWORD32)(adc_cal.a[i] * adc.raw[i])) >>10) + adc_cal.b[i];
1377
1378 //store converted ADC values
1379 memcpy(adc_phy, &adc.converted[0], sizeof(adc.raw));
1380 }
1381
1382
1383 /*------------------------------------------------------*/
1384 /* get_cal_from_nvmem */
1385 /*------------------------------------------------------*/
1386 /* Parameters : */
1387 /* Return : */
1388 /* Functionality : Copy calibrated parameter to */
1389 /* calibration structure in RAM */
1390 /*------------------------------------------------------*/
1391
1392 void get_cal_from_nvmem (UWORD8 *ptr, UWORD16 len, UWORD8 id)
1393 {
1394
1395 }
1396
1397 /*------------------------------------------------------*/
1398 /* save_cal_from_nvmem */
1399 /*------------------------------------------------------*/
1400 /* Parameters : */
1401 /* Return : */
1402 /* Functionality : Copy calibrated structure from RAM */
1403 /* into NV memory */
1404 /*------------------------------------------------------*/
1405
1406 UWORD8 save_cal_in_nvmem (UWORD8 *ptr, UWORD16 len, UWORD8 id)
1407 {
1408 return (0);
1409 }
1410
1411 #if (TRACE_TYPE == 4)
1412
1413 /*------------------------------------------------------*/
1414 /* l1_cst_l1_parameters */
1415 /*------------------------------------------------------*/
1416 /* Parameters : s: pointer on configuration string */
1417 /* Return : nothing: global var are set */
1418 /* Functionality : Set global L1 vars for dynamic trace */
1419 /* and configuration */
1420 /* */
1421 /* This function is called when a CST message is sent */
1422 /* from the Condat Panel. */
1423 /*------------------------------------------------------*/
1424 void l1_cst_l1_parameters(char *s)
1425 {
1426 /*
1427 a sample command string can be:
1428 L1_PARAMS=<1,2,3,4,5> or
1429 L1_PARAMS=<1,23,3E32,4,5>
1430 with n parameters (here: 5 params); n>=1
1431 parameters are decoded as hexadecimal unsigned integers (UWORD16)
1432 */
1433
1434 UWORD8 uNParams = 0; /* Number of parameters */
1435 UWORD32 aParam[10]; /* Parameters array */
1436 UWORD8 uIndex = 0;
1437
1438 /* *** retrieve all parameters *** */
1439 while (s[uIndex] != '<') uIndex++;
1440 uIndex++;
1441 aParam[0] = 0;
1442
1443 /* uIndex points on 1st parameter */
1444
1445 while (s[uIndex] != '>')
1446 {
1447 if (s[uIndex] == ',')
1448 {
1449 uNParams++;
1450 aParam[uNParams] = 0;
1451 }
1452 else
1453 {
1454 /* uIndex points on a parameter char */
1455 UWORD8 uChar = s[uIndex];
1456 aParam[uNParams] = aParam[uNParams] << 4; /* shift 4 bits left */
1457 if ((uChar>='0') && (uChar<='9'))
1458 aParam[uNParams] += (uChar - '0'); /* retrieve value */
1459 else if ((uChar>='A') && (uChar<='F'))
1460 aParam[uNParams] += (10 + uChar - 'A'); /* retrieve value */
1461 else if ((uChar>='a') && (uChar<='f'))
1462 aParam[uNParams] += (10 + uChar - 'a'); /* retrieve value */
1463 }
1464
1465 uIndex++; /* go to next char */
1466 }
1467
1468 /* increment number of params */
1469 uNParams++;
1470
1471 /* *** handle parameters *** */
1472 /*
1473 1st param: command type
1474 2nd param: argument for command type
1475 */
1476 switch (aParam[0])
1477 {
1478 case 0: /* Trace setting */
1479 /* The 2nd parameter contains the trace bitmap*/
1480 if (uNParams >=2)
1481 trace_info.current_config->l1_dyn_trace = aParam[1];
1482 else
1483 trace_info.current_config->l1_dyn_trace = 0; /* error case: disable all trace */
1484 Trace_dyn_trace_change();
1485 break;
1486 default: /* ignore it */
1487 break;
1488 } // switch
1489 }
1490
1491 #endif
1492
1493 #if ((CHIPSET == 2) || (CHIPSET == 3) || (CHIPSET == 4) || \
1494 (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || \
1495 (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || \
1496 (CHIPSET == 11) || (CHIPSET == 12))
1497 /*-------------------------------------------------------*/
1498 /* power_down_config() : temporary implementation !!! */
1499 /*-------------------------------------------------------*/
1500 /* Parameters : sleep_mode (NO, SMALL, BIG, DEEP or ALL) */
1501 /* clocks to be cut in BIG sleep */
1502 /* Return : */
1503 /* Functionality : set the l1s variables */
1504 /* l1s.pw_mgr.mode_authorized and l1s.pw_mgr.clocks */
1505 /* according to the desired mode. */
1506 /*-------------------------------------------------------*/
1507 void power_down_config(UWORD8 sleep_mode, UWORD16 clocks)
1508 {
1509 #if (OP_L1_STANDALONE == 1)
1510 if(sleep_mode != NO_SLEEP)
1511 #endif
1512 {
1513 l1_config.pwr_mngt = PWR_MNGT;
1514 l1s.pw_mgr.mode_authorized = sleep_mode;
1515 l1s.pw_mgr.clocks = clocks;
1516 }
1517
1518 #if (OP_L1_STANDALONE == 0)
1519 l1s.pw_mgr.enough_gaug = FALSE;
1520 #endif
1521 }
1522 #endif
1523 //added for L1 standalone DRP calibration- this will overwrite the previous data
1524 #if (OP_L1_STANDALONE == 1)
1525 #pragma DATA_SECTION(drp_l1_standalone_calib_data, ".drp_l1_standalone_calib_data");
1526 T_DRP_SW_DATA drp_l1_standalone_calib_data;
1527 #pragma DATA_SECTION(valid_dro_standalone_calib_data_flag , ".valid_dro_standalone_calib_data_flag");
1528 UWORD32 valid_dro_standalone_calib_data_flag;
1529 //const T_DRP_SW_DATA drp_sw_data_init = { (UINT16) sizeof(T_DRP_CALIB), } -this needs to be filled by CCS
1530 //added for L1 standalone DRP calibration- ends
1531 #endif
1532 // for DRP Calibration
1533 /*-------------------------------------------------------*/
1534 /* Cust_init_params_drp() */
1535 /*-------------------------------------------------------*/
1536 /* Parameters : none */
1537 /* Return : none */
1538 /* Functionality : Intialization of DRP calibration. */
1539 /*-------------------------------------------------------*/
1540 #if (L1_DRP == 1)
1541 void Cust_init_params_drp(void)
1542 {
1543 #if (DRP_FW_EXT==1)
1544 l1s.boot_result=drp_sw_data_calib_upload_from_ffs(&drp_sw_data_calib);
1545 drp_copy_sw_data_to_drpsrm(&drp_sw_data_calib);
1546 #else // DRP_FW_EXT==0
1547 volatile UINT16 indx, strsize;
1548 volatile UINT8 *ptrsrc, *ptrdst;
1549
1550 #if (OP_L1_STANDALONE == 0)
1551 if(drp_sw_data_calib.length != drp_sw_data_init.length)
1552 {
1553 #endif
1554
1555 // For the 1st time FFS might have garbage, if so use the above as check to ensure
1556 //and copy from the .drp_sw_data_init structure.
1557
1558 // Copy drp_sw_data_init into drp_sw_data_calib
1559 strsize = sizeof(T_DRP_SW_DATA);
1560 ptrsrc = (UINT8 *)(&drp_sw_data_init);
1561 ptrdst = (UINT8 *)(&drp_sw_data_calib);
1562
1563 for(indx=0;indx < strsize;indx++)
1564 *ptrdst++ = *ptrsrc++;
1565
1566 #if (OP_L1_STANDALONE == 0)
1567 }
1568 #endif
1569
1570 drp_copy_sw_data_to_drpsrm(&drp_sw_data_calib);
1571
1572 //added for L1 standalone DRP calibration- this will overwrite the previous data
1573 #if (OP_L1_STANDALONE == 1)
1574 if(valid_dro_standalone_calib_data_flag == 0xDEADBEAF ) //indicates down the data via CCS
1575 drp_copy_sw_data_to_drpsrm(&drp_l1_standalone_calib_data);
1576 #endif
1577 //added for L1 standalone DRP calibration- ends
1578 #endif // DRP_FW_EXT
1579 }
1580 #endif
1581
1582
1583 #if (DRP_FW_EXT==1)
1584 void l1_get_boot_result_and_version(T_L1_BOOT_VERSION_CODE * p_version)
1585 {
1586 if(! p_version)
1587 {
1588 return;
1589 }
1590 p_version->dsp_code_version = l1s_dsp_com.dsp_ndb_ptr->d_version_number1;
1591 p_version->dsp_patch_version = l1s_dsp_com.dsp_ndb_ptr->d_version_number2;
1592 p_version->mcu_tcs_program_release = PROGRAM_RELEASE_VERSION;
1593 p_version->mcu_tcs_internal = INTERNAL_VERSION;
1594 p_version->mcu_tcs_official = OFFICIAL_VERSION;
1595
1596 p_version->drp_maj_ver = drp_ref_sw_ver;
1597 p_version->drp_min_ver = drp_ref_sw_tag;
1598
1599 p_version->boot_result = l1s.boot_result;
1600 }
1601 #endif /* DRP_FW_EXT */
1602
1603
1604
1605