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