comparison L1/cust1/l1_cust.c @ 0:75a11d740a02

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