comparison src/cs/layer1/tm_cfile/l1tm_async.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
comparison
equal deleted inserted replaced
-1:000000000000 0:b6a5e36de839
1 /************* Revision Controle System Header *************
2 * GSM Layer 1 software
3 * L1TM_ASYNC.C
4 *
5 * Filename l1tm_async.c
6 * Copyright 2003 (C) Texas Instruments
7 *
8 ************* Revision Controle System Header *************/
9
10 #include "l1_macro.h"
11 #include "l1_confg.h"
12
13 #if TESTMODE
14 #define L1TM_ASYNC_C
15
16 #include <string.h>
17 #include <stdlib.h>
18 #include "l1_types.h"
19 #include "sys_types.h"
20 #include "l1_const.h"
21 #include "l1_time.h"
22 #include "l1_signa.h"
23 #include "cust_os.h"
24
25 #include "l1tm_defty.h"
26
27 #if (AUDIO_TASK == 1)
28 #include "l1audio_const.h"
29 #include "l1audio_cust.h"
30 #include "l1audio_defty.h"
31 #include "l1audio_signa.h"
32 #include "l1audio_proto.h"
33 #endif
34
35 #if (L1_GTT == 1)
36 #include "l1gtt_const.h"
37 #include "l1gtt_defty.h"
38 #endif
39
40 #if (L1_MP3 == 1)
41 #include "l1mp3_defty.h"
42 #endif
43
44 #if (L1_MIDI == 1)
45 #include "l1midi_defty.h"
46 #endif
47
48 #include "l1_defty.h"
49 #include "l1_msgty.h"
50 #include "l1_varex.h"
51 #include "l1_proto.h"
52
53 #include "l1tm_msgty.h"
54 #include "l1tm_signa.h"
55 #include "l1tm_varex.h"
56
57 #if (L1_STEREOPATH == 1)
58 #include "sys_dma.h"
59 #include "l1audio_stereo.h"
60 #endif
61
62 #if L1_GPRS
63 #include "l1p_cons.h"
64 #include "l1p_msgt.h"
65 #include "l1p_deft.h"
66 #include "l1p_vare.h"
67 #include "l1p_sign.h"
68 #endif
69
70 /* FreeCalypso TCS211 reconstruction */
71 #define ETM_PROTOCOL 0
72 #define ETM_MODE 0
73
74 //------------------------------------
75 // Prototypes from external functions
76 //------------------------------------
77 #if (OP_L1_STANDALONE == 1)
78 void etm_core(xSignalHeaderRec *msg);
79 #endif
80
81 void Cust_tm_init(void);
82
83 void l1tm_stats_fb_confirm (T_TMODE_FB_CON *prim, WORD32 test);
84 void l1tm_stats_sb_confirm (T_TMODE_NCELL_SYNC_IND *prim, WORD32 test);
85 void l1tm_stats_bcch_confirm (T_TMODE_BCCHS_CON *prim);
86 void l1tm_stats_tch_confirm (T_TMODE_TCH_INFO *prim);
87 void l1tm_stats_mon_confirm (T_TMODE_FB_CON *prim);
88 void l1tm_stats_full_list_meas_confirm(T_TMODE_RXLEV_REQ *prim);
89 BOOL l1tm_is_rx_counter_done (void);
90 void l1tm_reset_rx_state (void);
91
92 void l1tm_rf_param_write (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
93 void l1tm_rf_param_read (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
94 void l1tm_rf_table_write (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
95 void l1tm_rf_table_read (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
96 void l1tm_rx_param_write (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
97 void l1tm_rx_param_read (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
98 void l1tm_tx_param_write (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
99 void l1tm_tx_param_read (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
100 void l1tm_tx_template_write (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
101 void l1tm_tx_template_read (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
102
103 void l1tm_special_param_write (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
104 void l1tm_special_param_read (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
105 void l1tm_special_table_write (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
106 void l1tm_special_table_read (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
107 void l1tm_special_enable (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
108 void l1tm_rf_enable (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
109 void l1tm_stats_config_write (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
110 void l1tm_stats_config_read (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
111 void l1tm_statistics (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
112 void l1tm_stats_read (T_TM_RETURN *tm_return, WORD16 type, UWORD16 bitmask);
113 #if (L1_DRP == 1)
114 void l1tm_drp_sw_write(T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
115 #endif
116
117
118 void l1a_tmode_send_ul_msg (T_TM_RETURN *tm_ret);
119 UWORD16 l1tm_convert_arfcn2l1ch(UWORD16 arfcn, UWORD8 *error_flag);
120 void l1tm_fill_burst (UWORD16 pattern, UWORD16 *TM_ul_data);
121 void l1tm_initialize_var (void);
122 UWORD16 Convert_l1_radio_freq (SYS_UWORD16 radio_freq);
123
124 void tm_transmit(T_TM_RETURN *tm_ret);
125
126 #if (CODE_VERSION != SIMULATION)
127 void l1tm_tpu_table_write (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
128 void l1tm_tpu_table_read (T_TESTMODE_PRIM *prim, T_TM_RETURN *tm_return);
129 #endif
130
131 #if L1_GPRS
132 T_TRANSFER_SET *l1pa_get_free_transfer_set (UWORD8 new_tbf);
133 T_CRES_LIST_PARAM *l1pa_get_free_cres_list_set(void);
134 void l1tm_stats_pdtch_confirm (T_TMODE_PDTCH_INFO *prim);
135 #endif
136
137
138 #if (L1_TPU_DEV == 1)
139 void l1tm_flexi_tpu_table_read(T_TESTMODE_PRIM * prim, T_TM_RETURN * tm_return);
140 void l1tm_flexi_tpu_table_write(T_TESTMODE_PRIM * prim, T_TM_RETURN * tm_return);
141
142 //Flexi ABB Delay
143 void l1tm_flexi_abb_read(T_TESTMODE_PRIM * prim, T_TM_RETURN * tm_return);
144 void l1tm_flexi_abb_write(T_TESTMODE_PRIM * prim, T_TM_RETURN * tm_return);
145 #endif
146
147 // DRP Calibration
148 void l1tm_drp_calib_read(T_TESTMODE_PRIM * prim, T_TM_RETURN * tm_return);
149 void l1tm_drp_calib_write(T_TESTMODE_PRIM * prim, T_TM_RETURN * tm_return);
150
151 // Prototypes from internal functions
152 //------------------------------------
153 void l1a_tmode_fb0_process(xSignalHeaderRec *msg);
154 void l1a_tmode_fb1_process(xSignalHeaderRec *msg);
155 void l1a_tmode_sb_process(xSignalHeaderRec *msg);
156 void l1a_tmode_bcch_reading_process(xSignalHeaderRec *msg);
157 void l1a_tmode_dedicated_process(xSignalHeaderRec *msg);
158 void l1a_tmode_access_process(xSignalHeaderRec *msg);
159 void l1a_tmode_full_list_meas_process(xSignalHeaderRec *msg);
160
161 #if L1_GPRS
162 void l1a_tmode_transfer_process(xSignalHeaderRec *msg);
163 #endif
164 #if ((L1_STEREOPATH == 1) && (OP_L1_STANDALONE == 1))
165 void l1a_tmode_audio_stereopath_process(xSignalHeaderRec *msg);
166 extern void l1tm_stereopath_DMA_handler(SYS_UWORD16 dma_status);
167 extern void l1tm_stereopath_fill_buffer(void* buffer_address);
168 extern UWORD16 l1tm_stereopath_get_pattern(UWORD16 sampling_freq, UWORD16 sin_freq_left,UWORD16 sin_freq_right, UWORD8 data_type);
169 extern void l1a_audio_send_confirmation(UWORD32 SignalCode);
170 extern void l1_trigger_api_interrupt(void);
171 #if ( ANLG_FAM == 11)
172 //Add the two new sampling frequencies in the test mode for Locosto - 12khz and 24 khz
173 const UWORD16 l1tm_stereopath_sampling_freqs[9] = {8000,11025,12000,16000,22050,24000,32000,44100,48000};
174 #else
175 const UWORD16 l1tm_stereopath_sampling_freqs[8] = {48000,0,44100,32000,22050,16000,11025,8000};
176 #endif
177 const UWORD16 l1tm_stereopath_sin_freqs[4][2] = {{0,0},
178 {100,1000},
179 {1000,10000},
180 {1000,1000}}; // 4 different pattern of two freqs
181 const UWORD16 l1tm_stereopath_buffer[(480+1)*2];
182
183 T_STP_DRV_MCU_DSP *stp_drv_ndb = (T_STP_DRV_MCU_DSP *)API_address_dsp2mcu(C_STP_DRV_API_BASE_ADDRESS);
184
185 #if (CODE_VERSION == NOT_SIMULATION)
186 #pragma DATA_SECTION(TM_stereo_buf,".TM_stereo_buf");
187 #endif
188
189 #if (CHIPSET == 15)
190 #pragma DATA_SECTION(TM_stereo_buf_ext_mem, ".TM_stereo_buf_ext_mem");
191 #endif
192 volatile WORD16 TM_stereo_buf[STEREOPATH_MAX_NB_OF_FRAMES*2];
193 #if (CHIPSET == 15)
194 volatile WORD16 TM_stereo_buf_ext_mem[STEREOPATH_MAX_NB_OF_FRAMES*2];
195 #endif
196 #endif // ((L1_STEREOPATH == 1) && (OP_L1_STANDALONE == 1))
197
198 /***********************************************************************/
199 /* TESTMODE 3.X */
200 /***********************************************************************/
201
202 // omaps00090550 static UWORD8 tx_param_band=0; // used in tx_param_write/read; default is GSM900
203 /*-----------------------------------------------------------*/
204 /* l1a_tmode() */
205 /*-----------------------------------------------------------*/
206 /* Description : State machine controls TestMode processes */
207 /* */
208 /* Starting messages: TMODE_BCCH_REQ */
209 /* TMODE_PM_REQ */
210 /* TMODE_FB0_REQ */
211 /* TMODE_FB1_REQ */
212 /* TMODE_SB_REQ */
213 /* */
214 /* */
215 /* Result messages (input): L1_TMODE_MEAS_REPORT */
216 /* L1_SB_INFO */
217 /* L1_BCCHS_INFO */
218 /* */
219 /* Result messages (output): TMODE_PM_CON */
220 /* MPH5_NCELL_SB_IND */
221 /* */
222 /* Reset messages (input): MPH5_STOP_BCCH_READING */
223 /* */
224 /*-----------------------------------------------------------*/
225 void l1a_tmode(xSignalHeaderRec *msg)
226 {
227 T_TESTMODE_PRIM *prim;
228 T_TM_RETURN tm_ret;
229
230 int SignalCode = msg->SignalCode;
231
232 #if (OP_WCP==1) && (OP_L1_STANDALONE!=1)
233 // Security check for Operating System platforms (open platforms)
234 // We forbid TESTMODE if the phone is running with an OS
235 // so users can not invoke TESTMODE for malicious goals
236 extern unsigned long GC_RunningWithOs();
237
238 if(GC_RunningWithOs())
239 return;
240 #endif
241
242 if (SignalCode == TESTMODE_PRIM)
243 {
244 // use CID to decide what to do
245 prim = (T_TESTMODE_PRIM *)(msg->SigP);
246
247 // fill in the cid also named fid in the ETM protocol
248 tm_ret.cid = prim->cid;
249
250 switch (prim->cid)
251 {
252 case TM_INIT:
253 l1tm_initialize(&tm_ret);
254 break;
255 case TM_MODE_SET:
256 l1tm_mode_set(prim, &tm_ret);
257 break;
258 case VERSION_GET:
259 l1tm_version_get(prim, &tm_ret);
260 break;
261 case RF_ENABLE:
262 l1tm_rf_enable(prim, &tm_ret);
263 break;
264 case STATS_READ:
265 l1tm_statistics(prim, &tm_ret);
266 break;
267 case STATS_CONFIG_WRITE:
268 l1tm_stats_config_write(prim, &tm_ret);
269 break;
270 case STATS_CONFIG_READ:
271 l1tm_stats_config_read(prim, &tm_ret);
272 break;
273 case RF_PARAM_WRITE:
274 l1tm_rf_param_write(prim, &tm_ret);
275 break;
276 case RF_PARAM_READ:
277 l1tm_rf_param_read(prim, &tm_ret);
278 break;
279 case RF_TABLE_WRITE:
280 l1tm_rf_table_write(prim, &tm_ret);
281 break;
282 case RF_TABLE_READ:
283 l1tm_rf_table_read(prim, &tm_ret);
284 break;
285 case RX_PARAM_WRITE:
286 l1tm_rx_param_write(prim, &tm_ret);
287 break;
288 case RX_PARAM_READ:
289 l1tm_rx_param_read(prim, &tm_ret);
290 break;
291 case TX_PARAM_WRITE:
292 l1tm_tx_param_write(prim, &tm_ret);
293 break;
294 case TX_PARAM_READ:
295 l1tm_tx_param_read(prim, &tm_ret);
296 break;
297 case TX_TEMPLATE_WRITE:
298 l1tm_tx_template_write(prim, &tm_ret);
299 break;
300 case TX_TEMPLATE_READ:
301 l1tm_tx_template_read(prim, &tm_ret);
302 break;
303 case MEM_WRITE:
304 l1tm_mem_write(prim, &tm_ret);
305 break;
306 case MEM_READ:
307 l1tm_mem_read(prim, &tm_ret);
308 break;
309 case CODEC_WRITE:
310 l1tm_codec_write(prim, &tm_ret);
311 break;
312 case CODEC_READ:
313 l1tm_codec_read(prim, &tm_ret);
314 break;
315 case MISC_PARAM_WRITE:
316 l1tm_misc_param_write(prim, &tm_ret);
317 break;
318 case MISC_PARAM_READ:
319 l1tm_misc_param_read(prim, &tm_ret);
320 break;
321 case MISC_ENABLE:
322 l1tm_misc_enable(prim, &tm_ret);
323 break;
324 case SPECIAL_PARAM_WRITE:
325 l1tm_special_param_write(prim, &tm_ret);
326 break;
327 case SPECIAL_PARAM_READ:
328 l1tm_special_param_read(prim, &tm_ret);
329 break;
330 case SPECIAL_TABLE_WRITE:
331 l1tm_special_table_write(prim, &tm_ret);
332 break;
333 case SPECIAL_TABLE_READ:
334 l1tm_special_table_read(prim, &tm_ret);
335 break;
336 case SPECIAL_ENABLE:
337 l1tm_special_enable(prim, &tm_ret);
338 break;
339 #if (L1_DRP == 1)
340 case DRP_SW_WRITE:
341 l1tm_drp_sw_write(prim, &tm_ret);
342 break;
343 #endif
344 #if (CODE_VERSION != SIMULATION)
345 case TPU_TABLE_WRITE:
346 l1tm_tpu_table_write(prim, &tm_ret);
347 break;
348 case TPU_TABLE_READ:
349 l1tm_tpu_table_read(prim, &tm_ret);
350 break;
351 #endif
352 case TM_FFS:
353 l1tm_ffs(prim, &tm_ret);
354 break;
355 #if(L1_TPU_DEV == 1)
356 case FLEXI_TPU_TABLE_WRITE:
357 l1tm_flexi_tpu_table_write(prim, &tm_ret);
358 break;
359 case FLEXI_TPU_TABLE_READ:
360 l1tm_flexi_tpu_table_read(prim, &tm_ret);
361 break;
362 case FLEXI_ABB_WRITE:
363 l1tm_flexi_abb_write(prim, &tm_ret);
364 break;
365 case FLEXI_ABB_READ:
366 l1tm_flexi_abb_read(prim, &tm_ret);
367 break;
368 #endif
369 #if 0 //(CODE_VERSION != SIMULATION) // FreeCalypso TCS211 reconstruction
370 case DRP_CALIB_WRITE:
371 l1tm_drp_calib_write(prim, &tm_ret);
372 break;
373 case DRP_CALIB_READ:
374 l1tm_drp_calib_read(prim, &tm_ret);
375 break; // TBD for Future Use
376 #endif // CODE_VERSION
377 default:
378 #if (OP_L1_STANDALONE == 1)
379 etm_core(msg);
380 return;
381 #else
382 tm_ret.size = 0;
383 #if (ETM_PROTOCOL == 1)
384 tm_ret.status = -ETM_BADOP;
385 #else
386 tm_ret.status = E_BADCID;
387 #endif
388 #endif // OP_L1_STANDALONE
389 break;
390 } // end of switch
391 tm_transmit(&tm_ret);
392 } //end of TESTMODE_PRIM
393 #if L1_GPRS
394 else if ( ((SignalCode <= TMODE_PDTCH_INFO) && (SignalCode >= TMODE_RXLEV_REQ)) || (l1tm.tm_msg_received == TRUE) )
395 #else
396 else if ( ((SignalCode <= TMODE_TCH_INFO) && (SignalCode >= TMODE_RXLEV_REQ)) || (l1tm.tm_msg_received == TRUE) )
397 #endif
398 {
399 #if (CODE_VERSION == SIMULATION)
400 static BOOL tm_init = FALSE;
401
402 if (! tm_init)
403 {
404 Cust_tm_init();
405 l1tm_initialize_var();
406 l1_config.TestMode = 1;
407 tm_init=TRUE;
408 }
409 #endif
410 l1a_tmode_fb0_process(msg);
411 l1a_tmode_fb1_process(msg);
412 l1a_tmode_sb_process(msg);
413 l1a_tmode_bcch_reading_process(msg);
414 l1a_tmode_dedicated_process(msg);
415 l1a_tmode_access_process(msg);
416 l1a_tmode_full_list_meas_process(msg);
417 #if L1_GPRS
418 l1a_tmode_transfer_process(msg);
419 #endif
420 #if ((L1_STEREOPATH == 1) && (OP_L1_STANDALONE == 1))
421 l1a_tmode_audio_stereopath_process(msg);
422 #endif
423 } //end of not TESTMODE_PRIM
424 } // end of procedure.
425
426
427 /*-------------------------------------------------------*/
428 /* l1a_tmode_fb0_process() */
429 /*-------------------------------------------------------*/
430 /* Description : This state machine handles the 1st */
431 /* synchronization with the network in Test Mode. */
432 /* */
433 /* Starting messages: TMODE_FB0_REQ */
434 /* */
435 /* Result messages (input): L1C_FB_INFO */
436 /* */
437 /*-------------------------------------------------------*/
438 void l1a_tmode_fb0_process(xSignalHeaderRec *msg)
439 {
440 enum states
441 {
442 RESET = 0, // Reset state.
443 WAIT_INIT = 1, // Initial state.
444 SET_FS_FB_MODE0 = 2, // First Synchro, Setting of 1st FB mode 0.
445 WAIT_FS_FB_MODE0 = 3 // First Synchro, 1st FB mode 0 state.
446 };
447
448 UWORD8 *state = &l1a.state[TMODE_FB0];
449 UWORD32 SignalCode = msg->SignalCode;
450 BOOL done = 0;
451
452 #if (VCXO_ALGO == 1)
453 #define FS_FB_MODE0_CENTER 1
454 #define FS_FB_MODE0_MAX 2
455 #define FS_FB_MODE0_MIN 3
456
457 static WORD16 state_vcxo;
458 static WORD16 static_attempt_counter;
459 #endif
460
461 BOOL end_process = 0;
462
463 while(!end_process)
464 {
465 switch(*state)
466 {
467 case RESET:
468 {
469 // Step in state machine.
470 *state = WAIT_INIT;
471
472 #if (VCXO_ALGO == 1)
473 if(l1_config.params.eeprom_afc == 0) {
474 // Go to the initial VCXO AFC_INIT algorithm state
475 state_vcxo = FS_FB_MODE0_CENTER;
476 static_attempt_counter = 0;
477 }
478 #endif
479
480 // Reset tasks used in the process.
481 l1a_l1s_com.l1s_en_task[FBNEW] = TASK_DISABLED; // in tmode, not ALR
482 l1a_l1s_com.l1s_en_task[NSYNC] = TASK_DISABLED;
483
484 // Disable neighbour sync 0.
485 l1a_l1s_com.nsync.list[0].status = NSYNC_FREE;
486
487 }
488 break;
489
490 case WAIT_INIT:
491 {
492 if (SignalCode == TMODE_FB0_REQ)
493 {
494 #if (CODE_VERSION == SIMULATION)
495 l1tm_reset_rx_state();
496 #endif
497
498 // Flag msg received
499 l1tm.tm_msg_received = TRUE;
500
501 // Set task semaphores.
502 l1a_l1s_com.task_param[FBNEW] = SEMAPHORE_SET; // Set "parameter synchro semaphore for FB task.
503 l1a_l1s_com.task_param[NSYNC] = SEMAPHORE_SET; // Set "parameter synchro semaphore for FB task.
504
505 l1a_l1s_com.nsync.current_list_size = 0;
506
507 // Downlink stuff timeslot is 0 (default in CS)
508 l1a_l1s_com.dl_tn = 0;
509
510 // Set arfcn
511 l1a_l1s_com.nsync.list[0].radio_freq =l1_config.tmode.rf_params.bcch_arfcn;
512
513 //Set timing validity for FB no a priori info
514 l1a_l1s_com.nsync.list[0].timing_validity = 0;
515
516 // Reset offset and time alignment
517 l1a_l1s_com.nsync.list[0].fn_offset = 0;
518 l1a_l1s_com.nsync.list[0].time_alignmt = 0;
519
520 // Set functional mode.
521 l1a_l1s_com.mode = CS_MODE; //Needs to be set for l1ddsp_load_monit_task()
522
523 // Wideband search for FB detection.
524 l1a_l1s_com.fb_mode = FB_MODE_0;
525
526 // Enable SYNCHRO task to cleanup the MFTAB.
527 l1a_l1s_com.l1s_en_task[SYNCHRO] = TASK_ENABLED;
528
529 // Initialize AFC control function.
530 #if AFC_ALGO
531 if (l1_config.afc_enable) { // l1_config.TestMode MUST == 1
532 #if (VCXO_ALGO == 1)
533 // The TM rfpw 10 parameter has a different meaning when using
534 // a VCXO. Instead of containing the AFC used for the FB0, which
535 // is stored in the rftw 9 table now, it tells the TM which "state" must
536 // be used for the VCXO algorithm
537 //
538 switch(l1_config.params.eeprom_afc) {
539 case 0: // Full VCXO algo
540 // The AFC_INIT state is controlled by the state machine
541 // Reset attempt counter
542 static_attempt_counter = 0;
543 state_vcxo = FS_FB_MODE0_CENTER;
544 break;
545 case FS_FB_MODE0_CENTER * 8:
546 state_vcxo = FS_FB_MODE0_CENTER;
547 break;
548 case FS_FB_MODE0_MIN * 8:
549 state_vcxo = FS_FB_MODE0_MIN;
550 break;
551 case FS_FB_MODE0_MAX * 8:
552 state_vcxo = FS_FB_MODE0_MAX;
553 break;
554 default:
555 state_vcxo = FS_FB_MODE0_CENTER;
556 }
557 #endif
558 }
559 #endif
560
561 // Step in state machine
562 *state = SET_FS_FB_MODE0;
563 }
564 else
565 {
566 // End of process.
567 return;
568 }
569 }
570 break;
571
572 case SET_FS_FB_MODE0:
573 {
574 // Step in state machine.
575 *state = WAIT_FS_FB_MODE0;
576
577 // Enable neighbour sync 0.
578 l1a_l1s_com.nsync.list[0].status = NSYNC_PENDING; //Used by l1s_schedule_tasks in l1_sync
579
580 // Enable NSYNC task for FB detection mode 0.
581 l1a_l1s_com.l1s_en_task[NSYNC] = TASK_ENABLED;
582 if (l1_config.afc_enable) {// l1_config.TestMode MUST == 1
583 #if (VCXO_ALGO == 1)
584 switch(state_vcxo) {
585 case FS_FB_MODE0_CENTER:
586 l1s.afc = l1ctl_afc(AFC_INIT_CENTER, &l1s.afc_frame_count, NULL, 0, l1a_l1s_com.nsync.list[0].radio_freq,l1a_l1s_com.mode);
587 break;
588 case FS_FB_MODE0_MIN:
589 l1s.afc = l1ctl_afc(AFC_INIT_MIN, &l1s.afc_frame_count, NULL, 0, l1a_l1s_com.nsync.list[0].radio_freq,l1a_l1s_com.mode);
590 break;
591 case FS_FB_MODE0_MAX:
592 l1s.afc = l1ctl_afc(AFC_INIT_MAX, &l1s.afc_frame_count, NULL, 0, l1a_l1s_com.nsync.list[0].radio_freq,l1a_l1s_com.mode);
593 break;
594 default:
595 l1s.afc = l1ctl_afc(AFC_INIT_CENTER, &l1s.afc_frame_count, NULL, 0, l1a_l1s_com.nsync.list[0].radio_freq,l1a_l1s_com.mode);
596 }
597 #else
598 l1s.afc = l1ctl_afc(AFC_INIT, &l1s.afc_frame_count, l1_config.params.eeprom_afc, 0, l1a_l1s_com.nsync.list[0].radio_freq);
599 #endif
600 } // (l1_config.afc_enable) is TRUE
601
602 // End of process.
603 end_process = 1;
604 }
605 break;
606
607 case WAIT_FS_FB_MODE0:
608 {
609 if(SignalCode == L1C_FB_INFO)
610 // Frequency Burst acquisition result.
611 //------------------------------------
612 {
613 BOOL fb_found = ((T_L1C_FB_INFO *) (msg->SigP))->fb_flag;
614
615 if (fb_found)
616 {
617 // We consider the result of this successfull FB search attempt
618 // as a good a-priori information for next attempt.
619 // "fn_offset" is reversed to satisfy its definition,
620 // fn_offset = Fn_neigh - Fn_serving.
621 l1a_l1s_com.nsync.list[0].timing_validity = 1;
622 l1a_l1s_com.nsync.list[0].fn_offset = 51 - l1a_l1s_com.nsync.list[0].fn_offset;
623 }
624 #if (VCXO_ALGO == 1)
625 else
626 {
627 if(l1_config.params.eeprom_afc == 0)
628 {
629 //- Full VCXO algo
630
631 // Increment "static_attempt_counter".
632 static_attempt_counter++;
633 if(static_attempt_counter < 4)
634 {
635 // Max number of attemps not reached yet...
636 // try again with the same VCXO state
637 *state = SET_FS_FB_MODE0;
638 // Do not accumulate the statistics yet, just try again
639 break;
640 }
641 else
642 {
643 // Max number of attempt is reached... go back to 1st FB mode 0.
644 // Step in state machine.
645 static_attempt_counter = 0;
646
647 // Go to the next FS_FB_MODE0_CENTER state (CENTER -> MAX -> MIN)
648 // After MIN go to CENTER again, which means that the attempt failed
649 switch(state_vcxo)
650 {
651 case FS_FB_MODE0_CENTER:
652 state_vcxo = FS_FB_MODE0_MAX;
653 break;
654 case FS_FB_MODE0_MAX:
655 state_vcxo = FS_FB_MODE0_MIN;
656 break;
657 default: // i.e. case FS_FB_MODE0_MAX:
658 // The algorithm tried all the AFC_INIT values (CENTER, MAX & MIN)
659 // but did not detect an FB in any of the attemps for these values:
660 // The current attempt FAILED => Continue and accumulate the statistics
661 state_vcxo = FS_FB_MODE0_CENTER;
662 break;
663 }
664
665 if (state_vcxo != FS_FB_MODE0_CENTER)
666 {
667 *state = SET_FS_FB_MODE0;
668 // Do not accumulate the statistics yet, just try again with the new
669 // selected state_vcxo
670 break; // This breaks from the switch(*state), and thus re-loops thanks to the while(!end_process)
671 } // (state_vcxo != FS_FB_MODE0_CENTER)
672 } // (static_attempt_counter >= 4)
673 } // (l1_config.params.eeprom_afc != 0)
674 } // (fb_found) is FALSE
675 #endif
676
677 #if (VCXO_ALGO == 1)
678 if(l1_config.params.eeprom_afc == 0)
679 {
680 // If we got this far, the attempt ended (with a fail or a success)
681 // So we can go back to the initial state
682 state_vcxo = FS_FB_MODE0_CENTER;
683 }
684 #endif
685
686 //accumulate FB stats
687 l1tm_stats_fb_confirm( (T_TMODE_FB_CON*) ((T_L1C_FB_INFO *) (msg->SigP)), 0);
688
689 done = l1tm_is_rx_counter_done();
690 if (done == 1)
691 {
692 // Loop counter expired, stop the test
693 *state = RESET;
694
695 // Reset TM msg flag
696 // No new L1S result messages may be received before a new TM command
697 l1tm.tm_msg_received = FALSE;
698 break; // break out of switch
699 }
700 *state = SET_FS_FB_MODE0;
701 }
702 else if (SignalCode == TMODE_STOP_RX_TX)
703 // Stop SYNC mode message.
704 //--------------------------------
705 {
706 // Reset TM msg flag
707 // No new L1S result messages may be received before a new TM command
708 l1tm.tm_msg_received = FALSE;
709
710 // Step in state machine.
711 *state = RESET;
712
713 return;
714 }
715 else
716 {
717 // End of process.
718 return;
719 }
720 }
721 break;
722 }
723 }
724 }
725
726
727 /*-------------------------------------------------------*/
728 /* l1a_tmode_fb1_process() */
729 /*-------------------------------------------------------*/
730 /* Description : This state machine handles the 1st */
731 /* synchronization with the network in Test Mode. */
732 /* */
733 /* Starting messages: TMODE_FB1_REQ */
734 /* */
735 /* Result messages (input): L1C_FB_INFO */
736 /* */
737 /*-------------------------------------------------------*/
738 void l1a_tmode_fb1_process(xSignalHeaderRec *msg)
739 {
740 enum states
741 {
742 RESET = 0, // Reset state.
743 WAIT_INIT = 1, // Initial state.
744 SET_FS_FB_MODE1 = 2, // First Synchro, Setting of 1st FB mode 1.
745 WAIT_FS_FB_MODE1 = 3 // First Synchro, FB mode 1 state.
746 };
747
748 UWORD8 *state = &l1a.state[TMODE_FB1];
749 UWORD32 SignalCode = msg->SignalCode;
750 BOOL done = 0;
751
752 BOOL end_process = 0;
753
754 while(!end_process)
755 {
756 switch(*state)
757 {
758 case RESET:
759 {
760 // Step in state machine.
761 *state = WAIT_INIT;
762
763 // Reset of tasks used in this process is carried out in WAIT_FS_FBMODE1 state
764 // Otherwise we would possibly reset the task set by l1a_tmode_fb0_process()
765 }
766 break;
767
768 case WAIT_INIT:
769 {
770 if (SignalCode == TMODE_FB1_REQ)
771 {
772 #if (CODE_VERSION == SIMULATION)
773 l1tm_reset_rx_state();
774 #endif
775
776 // Flag msg received
777 l1tm.tm_msg_received = TRUE;
778
779 // Set task semaphores.
780 l1a_l1s_com.task_param[FBNEW] = SEMAPHORE_SET; // Set "parameter synchro semaphore for FB task.
781 l1a_l1s_com.task_param[NSYNC] = SEMAPHORE_SET; // Set "parameter synchro semaphore for FB task.
782
783 // Downlink stuff timeslot is 0 (default in CS)
784 l1a_l1s_com.dl_tn = 0;
785
786 // Set arfcn
787 l1a_l1s_com.nsync.list[0].radio_freq =l1_config.tmode.rf_params.bcch_arfcn;
788
789 // Set functional mode.
790 l1a_l1s_com.mode = CS_MODE; //Needs to be set for l1ddsp_load_monit_task()
791
792 // Set FB detection mode.
793 l1a_l1s_com.fb_mode = FB_MODE_1;
794
795 // Step in state machine
796 *state = SET_FS_FB_MODE1;
797 }
798 else
799 {
800 // End of process.
801 return;
802 }
803 }
804 break;
805
806 case SET_FS_FB_MODE1:
807 {
808 // Step in state machine.
809 *state = WAIT_FS_FB_MODE1;
810
811 // Enable neighbour sync 0.
812 l1a_l1s_com.nsync.list[0].status = NSYNC_PENDING;
813
814 // Enable NSYNC task for FB detection mode 1.
815 l1a_l1s_com.l1s_en_task[NSYNC] = TASK_ENABLED;
816
817 // End of process.
818 end_process = 1;
819 }
820 break;
821
822 case WAIT_FS_FB_MODE1:
823 {
824 // Use incoming message.
825 //----------------------
826 if(SignalCode == L1C_FB_INFO)
827 {
828 //accumulate FB stats
829 l1tm_stats_fb_confirm( (T_TMODE_FB_CON*) ((T_L1C_FB_INFO *) (msg->SigP)), 0);
830
831 // increment counter
832 done = l1tm_is_rx_counter_done();
833
834 if (done == 1)
835 {
836 // Loop counter expired, stop the test
837 *state = RESET;
838
839 // Reset TM msg flag
840 // No new L1S result messages may be received before a new TM command
841 l1tm.tm_msg_received = FALSE;
842
843 // Reset tasks used in the process.
844 l1a_l1s_com.l1s_en_task[FBNEW] = TASK_DISABLED; // in tmode, not ALR
845 l1a_l1s_com.l1s_en_task[NSYNC] = TASK_DISABLED;
846
847 // Disable neighbour sync 0.
848 l1a_l1s_com.nsync.list[0].status = NSYNC_FREE;
849
850 break; // break out of switch
851 }
852
853 *state = SET_FS_FB_MODE1;
854 } // end if L1C_FB_INFO
855 else if (SignalCode == TMODE_STOP_RX_TX)
856 // Stop SYNC mode message.
857 //--------------------------------
858 {
859 // Reset TM msg flag
860 // No new L1S result messages may be received before a new TM command
861 l1tm.tm_msg_received = FALSE;
862
863 // Step in state machine.
864 *state = RESET;
865
866 return;
867 }
868 else
869 // No action in this machine for other messages.
870 //----------------------------------------------
871 {
872 // End of process.
873 return;
874 }
875 }
876 break;
877 }
878 }
879 }
880
881
882 /*-------------------------------------------------------*/
883 /* l1a_tmode_sb_process() */
884 /*-------------------------------------------------------*/
885 /* Description : This state machine handles the 1st */
886 /* synchronization with the network in Test Mode. */
887 /* */
888 /* Starting messages: TMODE_SB_REQ */
889 /* */
890 /* Result messages (input): L1C_SB_INFO */
891 /* */
892 /*-------------------------------------------------------*/
893 void l1a_tmode_sb_process(xSignalHeaderRec *msg)
894 {
895 enum states
896 {
897 RESET = 0, // Reset state.
898 WAIT_INIT = 1, // Initial state.
899 SET_FS_SB = 2, // Set SB
900 WAIT_FS_SB = 3, // Wait for SB result
901 NEW_SYNCHRO = 4 // Camp on cell
902 };
903
904 UWORD8 *state = &l1a.state[TMODE_SB];
905 UWORD32 SignalCode = msg->SignalCode;
906 BOOL done = 0;
907
908 static UWORD8 static_bsic;
909 static UWORD32 static_fn_offset;
910 static UWORD32 static_time_alignmt;
911
912 BOOL end_process = 0;
913 while(!end_process)
914 {
915 switch(*state)
916 {
917 case RESET:
918 {
919 // Step in state machine.
920 *state = WAIT_INIT;
921
922 // Reset of tasks used in this process is carried out in WAIT_FS_SB state
923 // Otherwise we would possibly reset the NSYNC task set by l1a_tmode_fb0_process()
924 // or l1a_tmode_fb1_process
925 }
926 break;
927
928 case WAIT_INIT:
929 {
930 if (SignalCode == TMODE_SB_REQ)
931 {
932 #if (CODE_VERSION == SIMULATION)
933 l1tm_reset_rx_state();
934 #endif
935
936 // Flag msg received
937 l1tm.tm_msg_received = TRUE;
938
939 // Set arfcn
940 l1a_l1s_com.nsync.list[0].radio_freq =l1_config.tmode.rf_params.bcch_arfcn;
941
942 // Enable NSYNC task for SB detection (SB2).
943 #if ((REL99 == 1) && ((FF_BHO == 1) || (FF_RTD == 1)))
944 l1a_l1s_com.nsync.list[0].timing_validity = SB_ACQUISITION_PHASE ;
945 #else
946 l1a_l1s_com.nsync.list[0].timing_validity = 3;
947 #endif
948
949 // Step in state machine
950 *state = SET_FS_SB;
951 }
952 else
953 {
954 // End of process.
955 return;
956 }
957 }
958 break;
959
960 case SET_FS_SB:
961 {
962 // Step in state machine.
963 *state = WAIT_FS_SB;
964
965 // Enable neighbour sync 0.
966 l1a_l1s_com.nsync.list[0].status = NSYNC_PENDING;
967
968 // Enable NSYNC task for SB detection.
969 l1a_l1s_com.l1s_en_task[NSYNC] = TASK_ENABLED;
970
971 // End of process.
972 end_process = 1;
973 }
974 break;
975
976 case WAIT_FS_SB:
977 {
978 // Use incoming message.
979 //----------------------
980 if(SignalCode == L1C_SB_INFO)
981 {
982 UWORD8 sb_found = ((T_MPHC_NCELL_SYNC_IND *)(msg->SigP))->sb_flag;
983 UWORD8 bsic = ((T_MPHC_NCELL_SYNC_IND *)(msg->SigP))->bsic;
984
985 if(sb_found == TRUE)
986 // SB detection is a success...
987 //-----------------------------
988 {
989 // Save Results.
990 static_bsic = ((T_MPHC_NCELL_SYNC_IND *)(msg->SigP))->bsic;
991 static_fn_offset = ((T_MPHC_NCELL_SYNC_IND *)(msg->SigP))->fn_offset;
992 static_time_alignmt = ((T_MPHC_NCELL_SYNC_IND *)(msg->SigP))->time_alignmt;
993 }
994
995 l1tm_stats_sb_confirm( (T_TMODE_NCELL_SYNC_IND*) ((T_MPHC_NCELL_SYNC_IND*)(msg->SigP)), 0);
996
997 // if just an SB test, increment counter
998 // if not done, just stay in this state, schedule a new attempt
999 done = l1tm_is_rx_counter_done();
1000
1001 if (done == 1)
1002 {
1003 // step in state machine
1004 *state = NEW_SYNCHRO;
1005
1006 // Reset NSYNC task and SB2 task enable flags.
1007 l1a_l1s_com.l1s_en_task[SB2] = TASK_DISABLED; // in tmode, not ALR
1008 l1a_l1s_com.l1s_en_task[NSYNC] = TASK_DISABLED;
1009
1010 // Disable neighbour sync 0.
1011 l1a_l1s_com.nsync.list[0].status = NSYNC_FREE;
1012
1013 // Save results.
1014 l1a_l1s_com.nsync.list[0].fn_offset = static_fn_offset;
1015 l1a_l1s_com.nsync.list[0].time_alignmt = static_time_alignmt;
1016
1017 // Correct "ntdma" and "time_alignment" to shift 20 bit to the
1018 // future for Normal Burst reading tasks.
1019 l1a_add_time_for_nb(&l1a_l1s_com.nsync.list[0].time_alignmt,
1020 &l1a_l1s_com.nsync.list[0].fn_offset);
1021
1022 break; // break out of switch
1023 }
1024 else
1025 // Make a new SB attempt
1026 {
1027 l1a_l1s_com.nsync.list[0].status = NSYNC_PENDING;
1028
1029 // End of process.
1030 end_process = 1;
1031 }
1032 }
1033 else if (SignalCode == TMODE_STOP_RX_TX)
1034 // Stop SYNC mode message.
1035 //--------------------------------
1036 {
1037 // Reset TM msg flag
1038 // No new L1S result messages may be received before a new TM command
1039 l1tm.tm_msg_received = FALSE;
1040
1041 // Step in state machine.
1042 *state = RESET;
1043
1044 end_process = 1;
1045 }
1046 else
1047 // No action in this machine for other messages.
1048 //----------------------------------------------
1049 {
1050 // End of process.
1051 end_process = 1;
1052 }
1053 }//End Case WAIT_FS_SB
1054 break;
1055
1056 case NEW_SYNCHRO:
1057 {
1058 // Reset the Neighbor Cell information structure.
1059 l1a_reset_cell_info(&(l1a_l1s_com.Scell_info));
1060
1061 // STILL SAVING TSC WITHIN BSIC !!!!!!!!!!!!!!!!
1062
1063 // Download ARFCN, timing information and bitmap from the command message.
1064 l1a_l1s_com.Scell_info.radio_freq = l1_config.tmode.rf_params.bcch_arfcn;
1065 l1a_l1s_com.Scell_info.bsic = static_bsic;
1066 l1a_l1s_com.Scell_info.time_alignmt = l1a_l1s_com.nsync.list[0].time_alignmt;
1067 l1a_l1s_com.Scell_info.fn_offset = l1a_l1s_com.nsync.list[0].fn_offset;
1068
1069 // tn_difference -> loaded with the number of timeslot to shift.
1070 // dl_tn -> loaded with the new timeslot.
1071 l1a_l1s_com.tn_difference = 0 - l1a_l1s_com.dl_tn;
1072 l1a_l1s_com.dl_tn = 0; // Camping on timeslot 0.
1073
1074 // Layer 1 internal mode is set to IDLE MODE.
1075 l1a_l1s_com.mode = I_MODE;
1076
1077 // Set flag for toa init.
1078 #if (TOA_ALGO != 0)
1079 l1a_l1s_com.toa_reset = TRUE;
1080 #endif
1081
1082 // Enable SYNCHRO tasks.
1083 l1a_l1s_com.l1s_en_task[SYNCHRO] = TASK_ENABLED;
1084
1085 // Step in state machine.
1086 *state = RESET;
1087
1088 // Reset TM msg flag
1089 // No new L1S result messages may be received before a new TM command
1090 l1tm.tm_msg_received = FALSE;
1091 }
1092 break; // break out of switch
1093 // omaps00090550 break;
1094 }
1095 }
1096 }
1097
1098 /*-------------------------------------------------------*/
1099 /* l1a_tmode_bcch_reading_process() */
1100 /*-------------------------------------------------------*/
1101 /* Description : This state machine handles serving cell */
1102 /* BCCH reading in Test Mode. */
1103 /* */
1104 /* This process happens for a TestMode BCCH test, after */
1105 /* completing FB's and SB's in */
1106 /* l1a_tmode_initial_network_sync_process, */
1107 /* and then passing through l1a_tmode_cres_process, */
1108 /* */
1109 /* OR */
1110 /* */
1111 /* it can also happen for a TestMode TCH with synch */
1112 /* test where, FB's and SB's have already been detected, */
1113 /* and 4 BCCH's will be received before moving to the */
1114 /* TCH and dedicated mode. */
1115 /* */
1116 /* */
1117 /* Starting messages: TMODE_SCELL_NBCCH_REQ */
1118 /* ------------------ */
1119 /* */
1120 /* */
1121 /* Result messages (input): L1C_BCCHS_INFO */
1122 /* ------------------------ */
1123 /* System information data block from L1S. */
1124 /* */
1125 /* */
1126 /* Reset messages (input): TMODE_STOP_SCELL_BCCH_REQ */
1127 /* ----------------------- */
1128 /* */
1129 /*-------------------------------------------------------*/
1130 void l1a_tmode_bcch_reading_process(xSignalHeaderRec *msg)
1131 {
1132 enum states
1133 {
1134 RESET = 0,
1135 WAIT_INIT = 1,
1136 NBCCHS_CONFIG = 2,
1137 WAIT_BCCHS_RESULT = 3
1138 };
1139
1140 UWORD8 *state = &l1a.state[TMODE_BCCH];
1141 UWORD32 SignalCode = msg->SignalCode;
1142 BOOL done = 0;
1143
1144 BOOL end_process = 0;
1145 while(!end_process)
1146 {
1147 switch(*state)
1148 {
1149 case RESET:
1150 {
1151 // Step in state machine.
1152 *state = WAIT_INIT;
1153
1154 // Reset CS_MEAS process.
1155 l1a_l1s_com.l1s_en_task[NBCCHS] = TASK_DISABLED; // Clear NBCCHS task enable flag.
1156 //l1a_l1s_com.l1s_en_task[EBCCHS] = TASK_DISABLED; // Clear EBCCHS task enable flag.
1157 }
1158 break;
1159
1160 case WAIT_INIT:
1161 {
1162 if(SignalCode == TMODE_SCELL_NBCCH_REQ)
1163 {
1164
1165 #if (CODE_VERSION == SIMULATION)
1166 l1tm_reset_rx_state();
1167 #endif
1168
1169 // Flag msg received
1170 l1tm.tm_msg_received = TRUE;
1171
1172 // Request to read Normal BCCH from serving cell.
1173 l1a_l1s_com.Scell_info.radio_freq = l1_config.tmode.rf_params.bcch_arfcn;
1174
1175 // Step in state machine.
1176 *state = NBCCHS_CONFIG;
1177 }
1178
1179 else
1180 // No action in this machine for other messages.
1181 //----------------------------------------------
1182 {
1183 // End of process.
1184 return;
1185 }
1186 }
1187 break;
1188
1189 case NBCCHS_CONFIG:
1190 {
1191 UWORD8 i;
1192
1193 // Set semaphores for Normal Serving BCCH reading task.
1194 l1a_l1s_com.task_param[NBCCHS] = SEMAPHORE_SET;
1195
1196 // Download message content.
1197 //--------------------------
1198 l1a_l1s_com.nbcchs.schedule_array_size = 1;
1199
1200 for(i=0;i<l1a_l1s_com.nbcchs.schedule_array_size;i++)
1201 {
1202 l1a_l1s_com.nbcchs.schedule_array[i].modulus = 1;
1203 l1a_l1s_com.nbcchs.schedule_array[i].relative_position = 0;
1204 }
1205
1206 // Enable NBCCHS task.
1207 l1a_l1s_com.l1s_en_task[NBCCHS] = TASK_ENABLED;
1208
1209 // Step in state machine.
1210 *state = WAIT_BCCHS_RESULT;
1211
1212 // End of process.
1213 end_process = 1;
1214 }
1215 break;
1216
1217 case WAIT_BCCHS_RESULT:
1218 {
1219 if(SignalCode == L1C_BCCHS_INFO)
1220 // Serving cell BCCH reading result.
1221 //----------------------------------
1222 {
1223 // this function takes care of loops management
1224 l1tm_stats_bcch_confirm( (T_TMODE_BCCHS_CON*) ((T_MPHC_DATA_IND *)(msg->SigP)) );
1225
1226 done = l1tm_is_rx_counter_done();
1227
1228 if (done == 1)
1229 {
1230 // Reset TM msg flag
1231 // No new L1S result messages may be received before a new TM command
1232 l1tm.tm_msg_received = FALSE;
1233
1234 // This process must be reset.
1235 *state = RESET;
1236
1237 break;
1238 }
1239 else
1240 {
1241 // End of process.
1242 end_process = 1;
1243 }
1244 }
1245 else if (SignalCode == TMODE_STOP_RX_TX)
1246 // Stop BCCH mode message.
1247 //--------------------------------
1248 {
1249 // Reset TM msg flag
1250 // No new L1S result messages may be received before a new TM command
1251 l1tm.tm_msg_received = FALSE;
1252
1253 // Step in state machine.
1254 *state = RESET;
1255
1256 end_process = 1;
1257 }
1258 else
1259 // No action in this machine for other messages.
1260 //----------------------------------------------
1261 {
1262 // End of process.
1263 end_process = 1;
1264 }
1265 }
1266 break;
1267 } // end of "switch".
1268 } // end of "while"
1269 } // end of procedure.
1270
1271 /*-------------------------------------------------------*/
1272 /* l1a_tmode_dedicated_process() */
1273 /*-------------------------------------------------------*/
1274 /* Description : This state machine handles the dedicated*/
1275 /* mode setup in Test Mode (L1A side). */
1276 /* */
1277 /* Starting messages: TMODE_IMMED_ASSIGN_REQ */
1278 /* */
1279 /* Subsequent messages: */
1280 /* */
1281 /* Result messages (input): L1C_DEDIC_DONE */
1282 /* */
1283 /* Result messages (output): */
1284 /* */
1285 /* Reset messages (input): TMODE_STOP_RX_TX */
1286 /* */
1287 /*-------------------------------------------------------*/
1288 void l1a_tmode_dedicated_process(xSignalHeaderRec *msg)
1289 {
1290 enum states
1291 {
1292 RESET = 0,
1293 WAIT_INIT = 1,
1294 WAIT_MSG = 2
1295 };
1296
1297 T_DEDIC_SET *free_set;
1298 UWORD8 *state = &l1a.state[TMODE_DEDICATED];
1299 UWORD32 SignalCode = msg->SignalCode;
1300
1301 BOOL end_process = 0;
1302 while(!end_process)
1303 {
1304 switch(*state)
1305 {
1306 case RESET:
1307 {
1308 // Step in state machine.
1309 *state = WAIT_INIT;
1310
1311 l1a_l1s_com.l1s_en_task[FB26] = TASK_DISABLED; // Reset FB26 task enable flag.
1312
1313 // Reset D_NMEAS process.
1314 l1a_l1s_com.l1s_en_meas &= D_BAMS_MEAS_MASK; // Reset D_BAMS Measurement enable flag.
1315 l1a.l1a_en_meas[D_NMEAS] &= D_BAMS_MEAS_MASK;
1316
1317 // Reset L1S dedicated mode manager trigger.
1318 l1a_l1s_com.dedic_set.SignalCode = NULL;
1319 }
1320 break;
1321
1322 case WAIT_INIT:
1323 {
1324 switch(SignalCode)
1325 // switch on input message.
1326 //-------------------------------
1327 {
1328 case TMODE_IMMED_ASSIGN_REQ:
1329 // Immediate assignement message.
1330 //-------------------------------
1331 {
1332 UWORD8 maio_bef_sti;
1333 #if(L1_FF_MULTIBAND == 1)
1334 UWORD8 operative_radio_freq;
1335 #endif
1336
1337 // Flag msg received
1338 l1tm.tm_msg_received = TRUE;
1339
1340 #if (CODE_VERSION == SIMULATION)
1341 l1_config.tmode.rf_params.down_up = ((T_TMODE_IMMED_ASSIGN_REQ*)(msg->SigP))->ul_dl;
1342 l1tm_reset_rx_state();
1343 l1_config.tmode.stats_config.num_loops = 26; // 0 actually means infinite
1344 #endif
1345
1346 // save this info for later
1347 if (l1_config.tmode.rf_params.down_up == (TMODE_DOWNLINK|TMODE_UPLINK) &&
1348 l1_config.tmode.rf_params.mon_tasks == 1)
1349 {
1350 l1a_l1s_com.nsync.list[0].radio_freq = l1_config.tmode.rf_params.mon_arfcn;
1351 }
1352
1353 // Get Ptr to the free dedicated parameter set.
1354 // All important fields are initialised.
1355 free_set = l1a_get_free_dedic_set();
1356
1357 // Save given dedicated channel parameters from MPHC_IMMED_ASSIGN_REQ msg.
1358
1359 //========================================================================
1360
1361 free_set->chan1.desc.chan_sel.h = 0; // no hopping
1362
1363 free_set->chan1.desc.chan_sel.rf_channel.single_rf.radio_freq = l1_config.tmode.rf_params.tch_arfcn;
1364 //DON'T: union with radio_freq
1365 //free_set->chan1.desc.chan_sel.rf_channel.hopping_rf.maio=0;
1366 //free_set->chan1.desc.chan_sel.rf_channel.hopping_rf.hsn=0;
1367
1368 free_set->chan1.desc.channel_type = l1_config.tmode.rf_params.channel_type;
1369 free_set->chan1.desc.subchannel = l1_config.tmode.rf_params.subchannel;
1370 free_set->chan1.desc.timeslot_no = l1_config.tmode.rx_params.slot_num;
1371 free_set->chan1.desc.tsc = l1_config.tmode.tx_params.tsc;
1372
1373 //Set the loopback mode
1374 // 0: No loopback, 1: Loop A ... 6: Loop F
1375 if(l1_config.tmode.tx_params.burst_data >= 5 && l1_config.tmode.tx_params.burst_data <= 10 &&
1376 l1_config.tmode.rf_params.down_up == (TMODE_DOWNLINK | TMODE_UPLINK))
1377 {
1378 free_set->chan1.tch_loop = l1_config.tmode.tx_params.burst_data - 4;
1379
1380 // For loop back the channel mode needs to be set to TCH/FS
1381 free_set->chan1.mode = TCH_FS_MODE;
1382 }
1383 else
1384 {
1385 free_set->chan1.tch_loop = 0; // no loopback
1386
1387 // Rem1: Mode is forced to Signalling Only.
1388 if (l1_config.tmode.rf_params.channel_type == TCH_F)
1389 free_set->chan1.mode = TCH_FS_MODE;
1390 else
1391 free_set->chan1.mode = SIG_ONLY_MODE;
1392
1393 }
1394 /*
1395 ;--------------------------------------------------------------------------
1396 ; channel_desc_1 :
1397 ; chan_sel : ( h=FALSE, arfcn=5a )
1398 ; channel_type = 1 (TCHFS)
1399 ; subchannel = 0
1400 ; timeslot_no = 0
1401 ; tsc = 5
1402 ; timing_advance = 0
1403 ; frequency_list :
1404 ; rf_chan_cnt = 0000
1405 ; rf_chan_no : (0000, 0000, ...(total of 64)... 0000)
1406 ; starting_time =
1407 ; start_time_present = FALSE
1408 ; start_time :
1409 ; n32 =
1410 ; n51 =
1411 ; n26 =
1412 ; frequency_list_bef_sti
1413 ; rf_chan_cnt = 0000
1414 ; rf_chan_no : (0000, 0000, ...(total of 64)... 0000)
1415 ; maio_bef_sti = 0
1416 ; dtx_allowed = FALSE
1417 ; bcch_allocation = 0 carriers (...) UNUSED
1418 ; ba_id = 0 UNUSED
1419 ; pwrc = 5
1420 ;--------------------------------------------------------------------------
1421 */
1422 free_set->ma.freq_list.rf_chan_cnt = 0;
1423 free_set->ma.freq_list.rf_chan_no.A[0] = 0;
1424 free_set->ma.freq_list_bef_sti.rf_chan_cnt = 0;
1425 free_set->ma.freq_list_bef_sti.rf_chan_no.A[0] = 0; //DedicNew
1426
1427 maio_bef_sti = 0;
1428
1429 free_set->new_timing_advance = l1_config.tmode.tx_params.timing_advance;
1430 free_set->dtx_allowed = 0;
1431 // New Timing Advance value must be applied on 1st frame of dedic. channel.
1432 free_set->timing_advance = free_set->new_timing_advance;
1433
1434 l1a_l1s_com.dedic_set.pwrc = l1_config.tmode.tx_params.txpwr;
1435 // l1a_l1s_com.dedic_set.pwrc = 5; // change from TM2!
1436
1437 // TXPWR command was given in Idle, save it in dedicated mode structure.
1438 free_set->new_target_txpwr = l1s.applied_txpwr = l1_config.tmode.tx_params.txpwr;
1439
1440 // Serving Cell stays the same.
1441 free_set->cell_desc = l1a_l1s_com.Scell_info;
1442
1443 #if(L1_FF_MULTIBAND == 0)
1444
1445 free_set->cell_desc.traffic_meas_beacon
1446 = l1a_l1s_com.last_input_level[l1a_l1s_com.Scell_info.radio_freq - l1_config.std.radio_freq_index_offset];
1447 free_set->cell_desc.traffic_meas = l1a_l1s_com.last_input_level[l1a_l1s_com.Scell_info.radio_freq - l1_config.std.radio_freq_index_offset];
1448
1449 #else // L1_FF_MULTIBAND = 1 below
1450
1451 operative_radio_freq =
1452 l1_multiband_radio_freq_convert_into_operative_radio_freq(l1a_l1s_com.Scell_info.radio_freq);
1453
1454 free_set->cell_desc.traffic_meas_beacon
1455 = l1a_l1s_com.last_input_level[operative_radio_freq];
1456 free_set->cell_desc.traffic_meas = l1a_l1s_com.last_input_level[operative_radio_freq];
1457
1458 #endif // #if(L1_FF_MULTIBAND == 0) else
1459
1460
1461 // Decode the "starting time field", since staying on the same serving
1462 // the same STI fn is saved in both "neig_sti_fn" and "serv_sti_fn".
1463 free_set->neig_sti_fn = -1; //l1a_decode_starting_time(((T_MPHC_IMMED_ASSIGN_REQ *)(msg->SigP))->starting_time);
1464 free_set->serv_sti_fn = free_set->neig_sti_fn;
1465
1466 // Check/Fill "before starting time" fields.
1467 //l1a_fill_bef_sti_param(free_set, ((T_MPHC_IMMED_ASSIGN_REQ *)(msg->SigP))->starting_time.start_time_present);
1468
1469 //No hopping channel
1470
1471 // Save the "timeslot difference" between new and old configuration
1472 // in "tn_difference".
1473 // tn_difference -> loaded with the number of timeslot to shift.
1474 // dl_tn -> loaded with the new timeslot.
1475 l1a_l1s_com.tn_difference = free_set->chan1.desc.timeslot_no - l1a_l1s_com.dl_tn;
1476 l1a_l1s_com.dl_tn = free_set->chan1.desc.timeslot_no; // Save new TN id.
1477
1478 // Set "fset" pointer to the new parameter set.
1479 l1a_l1s_com.dedic_set.fset = free_set;
1480
1481 // Give new msg code to L1S. //TestMode: use existing L1S primitive name
1482 l1a_l1s_com.dedic_set.SignalCode = MPHC_IMMED_ASSIGN_REQ;
1483
1484 // step in state machine.
1485 *state = WAIT_MSG;
1486 }
1487 break;
1488
1489 } // end of "switch(SignalCode)".
1490 // end of process.
1491 end_process = 1;
1492 }
1493 break;
1494
1495 case WAIT_MSG:
1496 {
1497 switch(SignalCode)
1498 // switch on input message.
1499 //-------------------------------
1500 {
1501 case L1C_DEDIC_DONE:
1502 // Dedicated channel activated.
1503 //-----------------------------
1504 {
1505 // if MON tasks are enabled, set up FB26 and D_BAMS_MEAS tasks now as well
1506 if (l1_config.tmode.rf_params.down_up == (TMODE_DOWNLINK|TMODE_UPLINK) &&
1507 l1_config.tmode.rf_params.mon_tasks == 1)
1508 {
1509 l1a_l1s_com.task_param[FB26] = SEMAPHORE_SET;
1510 l1a_l1s_com.l1s_en_task[FB26] = TASK_ENABLED;
1511 #if (L1_12NEIGH ==1)
1512 //Set timing validity for FB no a priori info
1513 l1a_l1s_com.nsync.list[0].timing_validity = 0;
1514
1515 // Enable neighbour sync 0.
1516 l1a_l1s_com.nsync.list[0].status = NSYNC_PENDING; //Used by l1s_schedule_tasks in l1_sync
1517 l1a_l1s_com.l1s_en_task[NSYNC] = TASK_ENABLED;
1518 #endif
1519 }
1520
1521 if (l1_config.tmode.rx_params.pm_enable)
1522 {
1523 // Reset the BA list structure
1524 l1a_reset_ba_list();
1525
1526 // Next measurement report must indicate INVALID.
1527 //meas_valid = FALSE;
1528
1529 l1a_l1s_com.ba_list.nbr_carrier = 1;
1530
1531 // l1a_l1s_com.nsync.list[0].radio_freq was set to mon_arfcn above
1532 l1a_l1s_com.ba_list.A[0].radio_freq = l1a_l1s_com.nsync.list[0].radio_freq;
1533
1534 // Set parameter synchro semaphore for D_BAMS task.
1535 // Enable Dedicated mode BA list measurement task.
1536 l1a_l1s_com.meas_param |= D_BAMS_MEAS;
1537 l1a.l1a_en_meas[D_NMEAS] |= D_BAMS_MEAS;
1538 }
1539
1540 // keep track of dedicated mode state.
1541 l1tm.tmode_state.dedicated_active = 1;
1542
1543 // End of process.
1544 end_process = 1;
1545 }
1546 break;
1547
1548 case TMODE_TCH_INFO:
1549 // TCH result messages.
1550 //-----------------------
1551 {
1552 // Check if RX stats done in TCH
1553 if (l1_config.tmode.rf_params.mon_report == 0)
1554 {
1555 BOOL done;
1556
1557 // loop and stats management done within this function
1558 l1tm_stats_tch_confirm((T_TMODE_TCH_INFO *) (msg->SigP));
1559
1560 done = l1tm_is_rx_counter_done();
1561
1562 if (done == 1)
1563 // if done, send stop message
1564 {
1565 l1tm.tmode_state.dedicated_active = 0;
1566
1567 // Give new msg code to L1S.
1568 l1a_l1s_com.dedic_set.SignalCode = MPHC_STOP_DEDICATED_REQ;
1569
1570 // Reset TM msg flag
1571 // No new L1S result messages may be received before a new TM command
1572 l1tm.tm_msg_received = FALSE;
1573
1574 #if (L1_12NEIGH ==1)
1575 l1a_l1s_com.l1s_en_task[NSYNC] = TASK_DISABLED;
1576 // Disable neighbour sync 0.
1577 l1a_l1s_com.nsync.list[0].status = NSYNC_FREE; //Used by l1s_schedule_tasks in l1_sync
1578 #endif
1579
1580 // Step in state machine.
1581 *state = RESET;
1582 }
1583 }
1584
1585 // end of process
1586 end_process = 1;
1587 }
1588 break;
1589
1590 case L1C_FB_INFO:
1591 // MON result messages.
1592 //-----------------------
1593 {
1594 // Check if RX stats done in Monitor channel
1595 if (l1_config.tmode.rf_params.mon_report == 1)
1596 {
1597 BOOL done;
1598
1599 // loop and stats management done within this function
1600 l1tm_stats_mon_confirm( (T_TMODE_FB_CON*) ((T_L1C_FB_INFO *) (msg->SigP)));
1601
1602 done = l1tm_is_rx_counter_done();
1603
1604 if (done == 1)
1605 // if done, send stop message
1606 {
1607 l1tm.tmode_state.dedicated_active = 0;
1608
1609 // Give new msg code to L1S.
1610 l1a_l1s_com.dedic_set.SignalCode = MPHC_STOP_DEDICATED_REQ;
1611
1612 // Reset TM msg flag
1613 // No new L1S result messages may be received before a new TM command
1614 l1tm.tm_msg_received = FALSE;
1615
1616 #if (L1_12NEIGH ==1)
1617 l1a_l1s_com.l1s_en_task[NSYNC] = TASK_DISABLED;
1618 // Disable neighbour sync 0.
1619 l1a_l1s_com.nsync.list[0].status = NSYNC_FREE; //Used by l1s_schedule_tasks in l1_sync
1620 #endif
1621
1622 // Step in state machine.
1623 *state = RESET;
1624 }
1625 }
1626
1627 // end of process
1628 end_process = 1;
1629 }
1630 break;
1631
1632 case TMODE_STOP_RX_TX:
1633 // Release dedicated mode message.
1634 //--------------------------------
1635 {
1636 l1tm.tmode_state.dedicated_active = 0;
1637
1638 // Give new msg code to L1S.
1639 l1a_l1s_com.dedic_set.SignalCode = MPHC_STOP_DEDICATED_REQ;
1640
1641 // Reset TM msg flag
1642 // No new L1S result messages may be received before a new TM command
1643 l1tm.tm_msg_received = FALSE;
1644
1645 #if (L1_12NEIGH ==1)
1646 l1a_l1s_com.l1s_en_task[NSYNC] = TASK_DISABLED;
1647 // Disable neighbour sync 0.
1648 l1a_l1s_com.nsync.list[0].status = NSYNC_FREE; //Used by l1s_schedule_tasks in l1_sync
1649 #endif
1650 // Step in state machine.
1651 *state = RESET;
1652
1653 end_process = 1;
1654 }
1655 break;
1656
1657 default:
1658 // End of process.
1659 //----------------
1660 {
1661 end_process = 1;
1662 }
1663 } // end of "switch(SignalCode)".
1664 }
1665 break;
1666
1667 } // end of "switch".
1668 } // end of "while"
1669 } // end of procedure.
1670
1671 /*-------------------------------------------------------*/
1672 /* l1a_tmode_ra_process() */
1673 /*-------------------------------------------------------*/
1674 /* Description : This state machine handles the TestMode */
1675 /* access to the network (IDLE mode). */
1676 /* */
1677 /* Starting messages: TMODE_RA_START */
1678 /* */
1679 /* Result messages (input): L1C_RA_DONE */
1680 /* */
1681 /* Result messages (output): TMODE_RA_DONE */
1682 /* */
1683 /* Stop messages (input): TMODE_STOP_RX_TX */
1684 /* */
1685 /*-------------------------------------------------------*/
1686 void l1a_tmode_access_process(xSignalHeaderRec *msg)
1687 {
1688 enum states
1689 {
1690 RESET = 0,
1691 WAIT_INIT = 1,
1692 WAIT_RESULT = 2
1693 };
1694
1695 UWORD8 *state = &l1a.state[TMODE_RA];
1696 UWORD32 SignalCode = msg->SignalCode;
1697 BOOL done = 0;
1698
1699 while(1)
1700 {
1701 switch(*state)
1702 {
1703 case RESET:
1704 {
1705 // Step in state machine.
1706 *state = WAIT_INIT;
1707
1708 // Reset RAACC process.
1709 l1a_l1s_com.l1s_en_task[RAACC] = TASK_DISABLED; // Clear RAACC task enable flag.
1710 }
1711 break;
1712
1713 case WAIT_INIT:
1714 {
1715 if(SignalCode == TMODE_RA_START)
1716 // Configuration message for Access Link.
1717 //---------------------------------------
1718 {
1719 // Flag msg received
1720 l1tm.tm_msg_received = TRUE;
1721
1722 l1s.applied_txpwr = l1_config.tmode.tx_params.txpwr;
1723 l1a_l1s_com.ra_info.channel_request = 2; //l1_config.tm_params.channel_request;
1724
1725 // Initialize rand counter for RAACC process.
1726 l1a_l1s_com.ra_info.rand = 1;
1727
1728 // rand is random number of frames to wait between each AB transmission.
1729 // In actual L1 code this changes with each burst.
1730 // It is set to 1 here so the test runs fast.
1731
1732 // also, channel_request is constant in TestMode for all bursts.
1733 // Actual L1 changes channel_request message each time with a different
1734 // random reference. [channel_request = 3 bits for establishment cause
1735 // and 5 bits of random reference]
1736
1737 // Use 2 multiframes (0.5 seconds) in reading all serving normal bursts
1738 // (like paging reorganization) to refine TOA since we must have the quarter
1739 // bit accuracy for RACH transmission.
1740
1741 // Delay the start of RACH transmission (by incrementing rand
1742 // counter), only at the start of the test.
1743
1744 if(l1a_l1s_com.bcch_combined)
1745 {
1746 l1a_l1s_com.ra_info.rand += 54; // Combined: 2 multiframes = 54 slots.
1747 }
1748 else
1749 {
1750 l1a_l1s_com.ra_info.rand += 102; // Not combined: 2 multiframes = 102 slots.
1751 }
1752
1753 // step in state machine.
1754 *state = WAIT_RESULT;
1755
1756 // TestMode does not set up full BCCH reading
1757
1758 // Activate RAACC task (no semaphore for UL tasks).
1759 // TestMode does not enable Paging Reorg and Normal paging tasks.
1760 l1a_l1s_com.l1s_en_task[RAACC] = TASK_ENABLED;
1761
1762 // Change mode to connection establishment part 1.
1763 l1a_l1s_com.mode = CON_EST_MODE1; // used for toa calc.
1764 }
1765
1766 else
1767 // No action in this machine for other messages.
1768 //----------------------------------------------
1769 {
1770 // End of process.
1771 return;
1772 }
1773 }
1774 break;
1775
1776 case WAIT_RESULT:
1777 {
1778 if(SignalCode == L1C_RA_DONE)
1779 // Random access acknowledge message.
1780 //-----------------------------------
1781 {
1782 // Change mode to connection establishment part 2.
1783 l1a_l1s_com.mode = CON_EST_MODE2; // used for toa calc.
1784
1785 //change power level and arfcn on the fly
1786 l1s.applied_txpwr = l1_config.tmode.tx_params.txpwr;
1787 // l1a_l1s_com.Scell_info.radio_freq = l1_config.tmode.rf_params.tch_arfcn;
1788
1789 done = l1tm_is_rx_counter_done();
1790
1791 if (done)
1792 {
1793 // Reset TM msg flag
1794 // No new L1S result messages may be received before a new TM command
1795 l1tm.tm_msg_received = FALSE;
1796
1797 // No stats, just report end
1798 //tmstats_ra_confirm( (T_TMODE_RA_DONE*) ((T_MPHC_RA_CON *)(msg->SigP)) );
1799
1800 *state = RESET;
1801 }
1802 else // there are more loops to do...
1803 {
1804 l1a_l1s_com.ra_info.rand += 10; // 1 chosen/set for quicker test
1805 // Activate RAACC task (no semaphore for UL tasks).
1806 l1a_l1s_com.l1s_en_task[RAACC] = TASK_ENABLED;
1807 // end of process
1808 return;
1809 }
1810 }
1811
1812 else if(SignalCode == TMODE_STOP_RX_TX)
1813 {
1814 // Reset TM msg flag
1815 // No new L1S result messages may be received before a new TM command
1816 l1tm.tm_msg_received = FALSE;
1817
1818 // No stats, just report end
1819 //tmstats_ra_confirm( (T_TMODE_RA_DONE*) ((T_MPHC_RA_CON *)(msg->SigP)) );
1820 *state = RESET;
1821 return;
1822 }
1823
1824 else
1825 // No action in this machine for other messages.
1826 //----------------------------------------------
1827 {
1828 // End of process.
1829 return;
1830 }
1831 }
1832 break;
1833 } // end of "switch".
1834 } // end of "while"
1835 } // end of procedure.
1836
1837 /*-------------------------------------------------------*/
1838 /* l1a_tmode_full_list_meas_process() */
1839 /*-------------------------------------------------------*/
1840 /* */
1841 /* Description: */
1842 /* ------------ */
1843 /* This function is a state machine which handles the */
1844 /* Cell Selection Full List Power Measurement L1/L3 */
1845 /* interface and it handles the neigbour cell */
1846 /* measurement process in IDLE mode with FULL list. */
1847 /* When a message MPHC_RXLEV_REQ is received */
1848 /* the L1S task FSMS_MEAS is enabled. When this task */
1849 /* is completed a reporting message L1C_VALID_MEAS_INFO */
1850 /* is received and forwarded to L3. */
1851 /* */
1852 /* Starting messages: MPHC_RXLEV_REQ. */
1853 /* */
1854 /* Result messages (input): L1C_VALID_MEAS_INFO */
1855 /* */
1856 /* Result messages (output): MPHC_RXLEV_IND */
1857 /* */
1858 /* Reset messages (input): none */
1859 /* */
1860 /* Stop message (input): MPHC_STOP_RXLEV_REQ */
1861 /* */
1862 /* Stop message (output): MPHC_STOP_RXLEV_CON */
1863 /* */
1864 /* Rem: */
1865 /* ---- */
1866 /* L3 is in charge of the number of pass to follow the */
1867 /* GSM recommendation. */
1868 /* */
1869 /*-------------------------------------------------------*/
1870 void l1a_tmode_full_list_meas_process(xSignalHeaderRec *msg)
1871 {
1872 enum states
1873 {
1874 RESET = 0,
1875 WAIT_INIT = 1,
1876 WAIT_RESULT = 2
1877 };
1878
1879 UWORD8 *state = &l1a.state[TMODE_FULL_MEAS];
1880 UWORD32 SignalCode = msg->SignalCode;
1881
1882 BOOL end_process = 0;
1883
1884 while(!end_process)
1885 {
1886 switch(*state)
1887 {
1888 case RESET:
1889 {
1890 // Step in state machine.
1891 *state = WAIT_INIT;
1892
1893 // Reset FULL_MEAS process.
1894 l1a_l1s_com.l1s_en_meas &= FSMS_MEAS_MASK; // Clear Cell Selection Measurement enable flag.
1895 }
1896 break;
1897
1898 case WAIT_INIT:
1899 {
1900 if(SignalCode == TMODE_RXLEV_REQ)
1901 // Request to enter the Cell Selection measurements.
1902 //--------------------------------------------------
1903 {
1904 UWORD16 i;
1905
1906 // Flag msg received
1907 l1tm.tm_msg_received = TRUE;
1908
1909 // Do NOT download info from message
1910 // In TestMode always a full scanning is done, therefore primitive does not send the list
1911 l1a_l1s_com.full_list_ptr=(T_FULL_LIST_MEAS *)((T_TMODE_RXLEV_REQ *)(msg->SigP));
1912
1913 // Single power measurement carried out on monitor channel
1914 l1a_l1s_com.full_list_ptr->power_array_size = 1;
1915 l1a_l1s_com.full_list_ptr->power_array[0].radio_freq = l1_config.tmode.rf_params.mon_arfcn;
1916
1917 // Set "parameter synchro semaphores"
1918 l1a_l1s_com.meas_param |= FSMS_MEAS;
1919
1920 // Reset the full list structure.
1921 l1a_reset_full_list();
1922
1923 // Reset the Input Level (IL) memory table.
1924 #if (L1_FF_MULTIBAND == 1)
1925 for(i=0; i<= NBMAX_CARRIER; i++)
1926 #else
1927 for(i=0; i<=l1_config.std.nbmax_carrier; i++)
1928 #endif
1929 {
1930 l1a_l1s_com.last_input_level[i].input_level = l1_config.params.il_min;
1931 l1a_l1s_com.last_input_level[i].lna_off = 0;
1932 }
1933
1934 // Enable Cell Selection Full list measurement task.
1935 l1a.l1a_en_meas[TMODE_FULL_MEAS] |= FSMS_MEAS;
1936
1937 // Step in state machine.
1938 *state = WAIT_RESULT;
1939 }
1940
1941 // End of process.
1942 end_process = 1;
1943 }
1944 break;
1945
1946 case WAIT_RESULT:
1947 {
1948 if(SignalCode == L1C_VALID_MEAS_INFO)
1949 // One valid measurement pass has been completed over the full list of carriers.
1950 //------------------------------------------------------------------------------
1951 {
1952 BOOL done = FALSE;
1953
1954 //--------------------------------------------------------
1955 // WE COULD PUT HERE THE CODE TO TRANSLATE IL -> RXLEV !!!
1956 //--------------------------------------------------------
1957
1958 l1tm_stats_full_list_meas_confirm((T_TMODE_RXLEV_REQ *)(msg->SigP));
1959
1960 done = l1tm_is_rx_counter_done();
1961
1962 if (done)
1963 {
1964 // Reset TM msg flag
1965 // No new L1S result messages may be received before a new TM command
1966 l1tm.tm_msg_received = FALSE;
1967
1968 // Reset the machine.
1969 *state = RESET;
1970 }
1971 else
1972 {
1973 // Reset the full list structure.
1974 l1a_reset_full_list();
1975
1976 // Enable Cell Selection Full list measurement task.
1977 l1a.l1a_en_meas[TMODE_FULL_MEAS] |= FSMS_MEAS;
1978
1979 // End of process
1980 end_process = 1;
1981 }
1982 }
1983
1984 else if (SignalCode == TMODE_STOP_RX_TX)
1985 {
1986 // Reset TM msg flag
1987 // No new L1S result messages may be received before a new TM command
1988 l1tm.tm_msg_received = FALSE;
1989
1990 // Forward result message to L3.
1991 l1a_send_confirmation(TMODE_STOP_RXLEV_CON,RRM1_QUEUE);
1992 // Reset the machine.
1993 *state = RESET;
1994 end_process = 1;
1995 }
1996 else
1997 // No action in this machine for other messages.
1998 //----------------------------------------------
1999 {
2000 // End of process.
2001 end_process = 1;
2002 }
2003 }
2004 break;
2005 } // end of "switch".
2006 } // end of "while"
2007 } // end of procedure.
2008
2009
2010 #if L1_GPRS
2011 /*-------------------------------------------------------*/
2012 /* l1pa_tmode_transfer_process() */
2013 /*-------------------------------------------------------*/
2014 /* Description: */
2015 /* ------------ */
2016 /* */
2017 /* Starting messages: */
2018 /* ------------------ */
2019 /* */
2020 /* Subsequent messages: */
2021 /* -------------------- */
2022 /* */
2023 /* Result messages (input): */
2024 /* ------------------------ */
2025 /* */
2026 /* Result messages (output): */
2027 /* ------------------------- */
2028 /* */
2029 /* Reset messages (input): */
2030 /* ----------------------- */
2031 /* */
2032 /*-------------------------------------------------------*/
2033 void l1a_tmode_transfer_process(xSignalHeaderRec *msg)
2034 {
2035 enum states
2036 {
2037 RESET = 0,
2038 WAIT_INIT = 1,
2039 WAIT_MSG = 2
2040 };
2041
2042 UWORD8 *state = &l1a.state[TMODE_TRANSFER];
2043 UWORD32 SignalCode = msg->SignalCode;
2044
2045 static UWORD8 stat_gprs_slots;
2046
2047 BOOL end_process = 0;
2048
2049 while(!end_process)
2050 {
2051 switch(*state)
2052 {
2053 case RESET:
2054 {
2055 // Step in state machine.
2056 *state = WAIT_INIT;
2057
2058 // Reset FB26 task enable flag.
2059 l1a_l1s_com.l1s_en_task[FB26] = TASK_DISABLED;
2060
2061 // Reset TCR_MEAS process.
2062 l1pa_l1ps_com.l1ps_en_meas &= P_TCRMS_MEAS_MASK; // Disable Neighbour Measurement task.
2063 l1pa.l1pa_en_meas[TCR_MEAS] &= P_TCRMS_MEAS_MASK; // Reset Neighbour Measurement task.
2064
2065 // Rise transfert parameter semaphore.
2066 l1pa_l1ps_com.transfer.semaphore = TRUE;
2067 }
2068 break;
2069
2070 case WAIT_INIT:
2071 {
2072 switch(SignalCode)
2073 // switch on input message.
2074 //-------------------------
2075 {
2076 case TMODE_PDTCH_ASSIGN_REQ:
2077 // Assignement message.
2078 //---------------------
2079 {
2080 static UWORD32 count =0;
2081
2082 T_TRANSFER_SET *free_set;
2083 UWORD8 assignment_command;
2084 UWORD8 timeslot_alloc;
2085 UWORD8 timeslot;
2086 UWORD32 i;
2087
2088 count++ ;
2089
2090 #if (CODE_VERSION == SIMULATION)
2091 l1tm_reset_rx_state();
2092 #endif
2093
2094 // Flag msg received
2095 l1tm.tm_msg_received = TRUE;
2096
2097 // Rise transfert parameter semaphore to prevent L1S to use partial configuration.
2098 l1pa_l1ps_com.transfer.semaphore = TRUE;
2099
2100 assignment_command = BOTH_TBF;
2101
2102 // Get Ptr to the free dedicated parameter set.
2103 // All important fields are initialised.
2104 free_set = l1pa_get_free_transfer_set(assignment_command);
2105
2106 // Download message containt.
2107 free_set->assignment_id = 1;
2108 free_set->assignment_command = assignment_command;
2109 #if (CODE_VERSION == SIMULATION)
2110 free_set->multislot_class = ((T_TMODE_PDTCH_ASSIGN_REQ *)(msg->SigP))->multislot_class;
2111 #else
2112 free_set->multislot_class = l1_config.tmode.rf_params.multislot_class;
2113 #endif
2114 free_set->dl_pwr_ctl.p0 = 255; // no power control
2115 free_set->packet_ta.ta = 0;
2116 free_set->packet_ta.ta_index = 255;
2117 free_set->packet_ta.ta_tn = 255;
2118 free_set->tsc = l1_config.tmode.tx_params.tsc;
2119 free_set->freq_param.chan_sel.h = FALSE; // no hopping
2120 free_set->freq_param.chan_sel.rf_channel.single_rf.radio_freq = l1_config.tmode.rf_params.pdtch_arfcn;
2121 free_set->mac_mode = FIX_ALLOC_NO_HALF; // fixed allocation
2122 free_set->tbf_sti.present = TRUE; // STI present
2123 // FreeCalypso TCS211 reconstruction: LoCosto change backed out
2124 #if 0 //(CODE_VERSION == NOT_SIMULATION)
2125 // In order to reduce the latency for the ETM command "rfe 4", make absolute_fn as
2126 // next_time.fn+1. This was originally +100 because of which we had to wait for some
2127 // time before L1 actually starts the TBF.
2128 free_set->tbf_sti.absolute_fn= l1s.next_time.fn + 1;
2129 #else
2130 // In PC simulation, keep the old +100 to keep output logs same as reference
2131 free_set->tbf_sti.absolute_fn= l1s.next_time.fn + 100; // force to current FN+100
2132 #endif
2133
2134 free_set->interf_meas_enable = FALSE; // Interference measurements disabled
2135 free_set->pc_meas_chan = TRUE; // No measurement on the beacon (6 per MF52)
2136
2137 // Allocation of both UL and DL time slots
2138 free_set->dl_tbf_alloc.tfi = 1; // DL TFI ID
2139 free_set->ul_tbf_alloc->tfi = 2; // UL TFI ID
2140 #if (CODE_VERSION == SIMULATION)
2141 free_set->dl_tbf_alloc.timeslot_alloc = ((T_TMODE_PDTCH_ASSIGN_REQ *)(msg->SigP))->dl_ts_alloc;
2142 free_set->ul_tbf_alloc->timeslot_alloc = ((T_TMODE_PDTCH_ASSIGN_REQ *)(msg->SigP))->ul_ts_alloc;
2143 l1_config.tmode.stats_config.num_loops = ((T_TMODE_PDTCH_ASSIGN_REQ *)(msg->SigP))->ul_alloc_length;
2144 l1_config.tmode.rf_params.mon_tasks = ((T_TMODE_PDTCH_ASSIGN_REQ *)(msg->SigP))->mon_enable;
2145 l1_config.tmode.rf_params.mon_report = ((T_TMODE_PDTCH_ASSIGN_REQ *)(msg->SigP))->mon_enable;
2146 l1_config.tmode.rx_params.pm_enable = ((T_TMODE_PDTCH_ASSIGN_REQ *)(msg->SigP))->pm_enable;
2147 #else
2148 free_set->dl_tbf_alloc.timeslot_alloc = l1_config.tmode.rx_params.timeslot_alloc;
2149 free_set->ul_tbf_alloc->timeslot_alloc = l1_config.tmode.tx_params.timeslot_alloc;
2150 #endif
2151 // free_set->ul_tbf_alloc->fixed_alloc.bitmap_length = l1_config.tmode.stats_config.num_loops;
2152 // force to 127
2153 free_set->ul_tbf_alloc->fixed_alloc.bitmap_length = 127;
2154
2155 // Init fixed allocation bitmap
2156 for (i=0;i<free_set->ul_tbf_alloc->fixed_alloc.bitmap_length;i++)
2157 free_set->ul_tbf_alloc->fixed_alloc.bitmap[i] = free_set->ul_tbf_alloc->timeslot_alloc;
2158
2159 free_set->allocated_tbf = BOTH_TBF;
2160
2161 // Process the downlink TBF first allocated timeslot
2162 timeslot_alloc = free_set->dl_tbf_alloc.timeslot_alloc;
2163 timeslot = 0;
2164
2165 while((timeslot<7) && !(timeslot_alloc & (0x80>>timeslot)))
2166 {
2167 timeslot++;
2168 }
2169
2170 free_set->dl_tbf_synchro_timeslot = timeslot;
2171
2172 // Fill "synchro_timeslot" which will be the frame synchro slot.
2173 free_set->transfer_synchro_timeslot = timeslot;
2174
2175 // save stats bitmap
2176 stat_gprs_slots = l1_config.tmode.stats_config.stat_gprs_slots;
2177 // Adjust stats bit map
2178 l1_config.tmode.stats_config.stat_gprs_slots <<= timeslot;
2179
2180 // Process the uplink TBF first allocated timeslot
2181 // Fixed mode: the 1st allocated timeslot is the downlink control
2182 // timeslot allocated by the network, which is a timeslot allocated
2183 // in uplink
2184 timeslot_alloc = free_set->ul_tbf_alloc->timeslot_alloc;
2185
2186 timeslot = 0;
2187 while((timeslot<7) && !(timeslot_alloc & (0x80>>timeslot)))
2188 {
2189 timeslot++;
2190 }
2191 // if UL synchro TS > DL synchro TS, then fixed alloc ctrl TS is the UL sync TS
2192 // else fixed alloc ctrl TS is the DL sync TS
2193 if (timeslot > free_set->dl_tbf_synchro_timeslot)
2194 free_set->ul_tbf_alloc->fixed_alloc.ctrl_timeslot = timeslot;
2195 else
2196 free_set->ul_tbf_alloc->fixed_alloc.ctrl_timeslot = free_set->dl_tbf_synchro_timeslot;
2197
2198 free_set->ul_tbf_synchro_timeslot = free_set->ul_tbf_alloc->fixed_alloc.ctrl_timeslot;
2199
2200 // Init txpwr levels for multi slot TX
2201 // txpwr[index] is calculated according to TX allocation given by MACS
2202 // timeslot contains the first allocated TS in UL
2203 for(i = timeslot; i < 8; i++)
2204 {
2205 l1pa_l1ps_com.transfer.dl_pwr_ctrl.txpwr[i]
2206 = l1_config.tmode.tx_params.txpwr_gprs[i];
2207 }
2208
2209 // Step in state machine.
2210 *state = WAIT_MSG;
2211
2212 // Store signalcode.
2213 free_set->SignalCode = MPHP_ASSIGNMENT_REQ;
2214
2215 // Clear transfer parameter semaphore to let L1S use the new parameters.
2216 l1pa_l1ps_com.transfer.semaphore = FALSE;
2217
2218 // end of process.
2219 end_process = 1;
2220 }
2221 break;
2222
2223 default:
2224 // End of process.
2225 //----------------
2226 {
2227 return;
2228 }
2229 } // end switch(SignalCode)
2230 } // end case WAIT_INIT
2231 case WAIT_MSG:
2232 {
2233 switch(SignalCode)
2234 // switch on input message.
2235 //-------------------------
2236 {
2237 case L1P_TRANSFER_DONE:
2238 // Switch to TRANSFER mode has been done.
2239 {
2240 T_CRES_LIST_PARAM *free_list;
2241
2242 // Set up TCR_MEAS task, if MON tasks are enabled set up FB26
2243 if (l1_config.tmode.rf_params.mon_tasks == 1)
2244 {
2245 // Set FB26 task semaphore
2246 l1a_l1s_com.task_param[FB26] = SEMAPHORE_SET;
2247
2248 // This process always use the first element of "nsync" structure.
2249 l1a_l1s_com.nsync.current_list_size = 0;
2250 // l1a_l1s_com.nsync.list[0].radio_freq was set to mon_arfcn above
2251 l1a_l1s_com.nsync.list[0].radio_freq = l1_config.tmode.rf_params.mon_arfcn;
2252
2253 // Enable FB detection during packet transfer
2254 l1a_l1s_com.l1s_en_task[FB26] = TASK_ENABLED;
2255 #if (L1_12NEIGH ==1)
2256 //Set timing validity for FB no a priori info
2257 l1a_l1s_com.nsync.list[0].timing_validity = 0;
2258 // Enable neighbour sync 0.
2259 l1a_l1s_com.nsync.list[0].status = NSYNC_PENDING; //Used by l1s_schedule_tasks in l1_sync
2260 l1a_l1s_com.l1s_en_task[NSYNC] = TASK_ENABLED;
2261 #endif
2262 }
2263
2264 if (l1_config.tmode.rx_params.pm_enable)
2265 {
2266 // Set parameter synchro semaphore for P_TCRMS_MEAS task.
2267 l1pa_l1ps_com.meas_param |= P_TCRMS_MEAS;
2268
2269 // Reset Neighbour Cell measurement parameters.
2270 l1pa_l1ps_com.tcr_freq_list.tcr_next_to_ctrl = 0;
2271 l1pa_l1ps_com.tcr_freq_list.tcr_next_to_read = 0;
2272
2273 // Get Ptr to the free Neighbour meas list.
2274 // The number of carriers in the list and the list
2275 // identification are initialized.
2276 free_list = l1pa_get_free_cres_list_set();
2277
2278 // Download new list within T_CRES_LIST_PARAM structure.
2279 free_list->nb_carrier = 1;
2280 free_list->freq_list[0] = l1_config.tmode.rf_params.mon_arfcn;
2281
2282 free_list->list_id = 0;
2283
2284 // Set "flist" with Circuit Swithed BA frequency list parameters
2285 l1pa_l1ps_com.cres_freq_list.alist = free_list;
2286
2287 // Reset flags.
2288 l1pa_l1ps_com.tcr_freq_list.ms_ctrl = 0;
2289 l1pa_l1ps_com.tcr_freq_list.ms_ctrl_d = 0;
2290 l1pa_l1ps_com.tcr_freq_list.ms_ctrl_dd = 0;
2291
2292 // Reset measures made on beacon frequency.
2293 l1pa_l1ps_com.tcr_freq_list.beacon_meas = 0;
2294
2295 // Enable Packet Transfer Neighbour Measurement task.
2296 l1pa.l1pa_en_meas[TCR_MEAS] |= P_TCRMS_MEAS;
2297 }
2298
2299 // Flag packet transfer mode active
2300 l1tm.tmode_state.packet_transfer_active = TRUE;
2301
2302 // End of process.
2303 end_process = 1;
2304 }
2305 break;
2306
2307 case TMODE_PDTCH_INFO:
2308 // TCH result messages.
2309 //-----------------------
2310 {
2311 // Check if RX stats done in PDTCH
2312 if (l1_config.tmode.rf_params.mon_report == 0)
2313 {
2314 BOOL done;
2315
2316 // loop and stats management done within this function
2317 l1tm_stats_pdtch_confirm((T_TMODE_PDTCH_INFO *) (msg->SigP));
2318
2319 done = l1tm_is_rx_counter_done();
2320
2321 if (done == 1)
2322 // if done, send stop TBFs
2323 {
2324 // Rise transfer parameter semaphore to prevent L1S to use partial configuration.
2325 l1pa_l1ps_com.transfer.semaphore = TRUE;
2326
2327 // Enables the TBF release processing in L1S.
2328 l1pa_l1ps_com.transfer.tbf_release_param.tbf_release_cmd = TRUE;
2329
2330 // Download msg info into L1PA_L1PS_COM.
2331 l1pa_l1ps_com.transfer.tbf_release_param.released_tbf = BOTH_TBF;
2332
2333 // Clear transfer parameter semaphore to let L1S use the new parameters.
2334 l1pa_l1ps_com.transfer.semaphore = FALSE;
2335 }
2336 }
2337
2338 // end of process
2339 end_process = 1;
2340 }
2341 break;
2342
2343 case L1C_FB_INFO:
2344 // MON result messages.
2345 //-----------------------
2346 {
2347 // Check if RX stats done in Monitor channel
2348 if (l1_config.tmode.rf_params.mon_report == 1)
2349 {
2350 BOOL done;
2351
2352 // loop and stats management done within this function
2353 l1tm_stats_mon_confirm( (T_TMODE_FB_CON*) ((T_L1C_FB_INFO *) (msg->SigP)));
2354
2355 done = l1tm_is_rx_counter_done();
2356
2357 if (done == 1)
2358 // if done, send stop TBFs
2359 {
2360 // Rise transfer parameter semaphore to prevent L1S to use partial configuration.
2361 l1pa_l1ps_com.transfer.semaphore = TRUE;
2362
2363 // Enables the TBF release processing in L1S.
2364 l1pa_l1ps_com.transfer.tbf_release_param.tbf_release_cmd = TRUE;
2365
2366 // Download msg info into L1PA_L1PS_COM.
2367 l1pa_l1ps_com.transfer.tbf_release_param.released_tbf = BOTH_TBF;
2368
2369 // Clear transfer parameter semaphore to let L1S use the new parameters.
2370 l1pa_l1ps_com.transfer.semaphore = FALSE;
2371 }
2372 }
2373
2374 // end of process
2375 end_process = 1;
2376 }
2377 break;
2378
2379 case TMODE_STOP_RX_TX:
2380 // TBF Release.
2381 //-------------
2382 {
2383 // Rise transfer parameter semaphore to prevent L1S to use partial configuration.
2384 l1pa_l1ps_com.transfer.semaphore = TRUE;
2385
2386 // Enables the TBF release processing in L1S.
2387 l1pa_l1ps_com.transfer.tbf_release_param.tbf_release_cmd = TRUE;
2388
2389 // Download msg info into L1PA_L1PS_COM.
2390 l1pa_l1ps_com.transfer.tbf_release_param.released_tbf = BOTH_TBF;
2391
2392 // Clear transfer parameter semaphore to let L1S use the new parameters.
2393 l1pa_l1ps_com.transfer.semaphore = FALSE;
2394
2395 // end of process.
2396 end_process = 1;
2397 }
2398 break;
2399
2400 case L1P_TBF_RELEASED:
2401 // TBF has been release by L1S.
2402 {
2403 // Reset TM msg flag
2404 // No new L1S result messages may be received before a new TM command
2405 l1tm.tm_msg_received = FALSE;
2406
2407 // Reset transfer active state
2408 l1tm.tmode_state.packet_transfer_active = FALSE;
2409
2410 // Restore stats bitmap
2411 l1_config.tmode.stats_config.stat_gprs_slots = stat_gprs_slots;
2412
2413 #if (L1_12NEIGH ==1)
2414 l1a_l1s_com.l1s_en_task[NSYNC] = TASK_DISABLED;
2415 // Disable neighbour sync 0.
2416 l1a_l1s_com.nsync.list[0].status = NSYNC_FREE; //Used by l1s_schedule_tasks in l1_sync
2417 #endif
2418
2419 // Step in state machine.
2420 *state = RESET;
2421
2422 // End of process.
2423 end_process = 1;
2424 }
2425 break;
2426
2427 default:
2428 // End of process.
2429 //----------------
2430 {
2431 end_process = 1;
2432 }
2433 } // end of switch(SignalCode)
2434 } // end of case WAIT_MSG.
2435 } // end of "switch".
2436 } // end of "while"
2437 } // end of procedure.
2438 #endif
2439
2440 #if ((L1_STEREOPATH == 1) && (OP_L1_STANDALONE == 1))
2441 /*----------------------------------------------------------------*/
2442 /* l1a_tmode_audio_stereopath_process() */
2443 /*----------------------------------------------------------------*/
2444 /* */
2445 /* Description: */
2446 /* ------------ */
2447 /* This function is a state machine which handles the */
2448 /* stereopath feature. */
2449 /* */
2450 /* Starting messages: TMODE_AUDIO_STEREOPATH_DRV_START_REQ */
2451 /* */
2452 /* Result messages (input): L1_STEREOPATH_DRV_START_CON */
2453 /* */
2454 /* Result messages (output): TMODE_AUDIO_STEREOPATH_DRV_START_CON */
2455 /* */
2456 /* Reset messages (input): none */
2457 /* */
2458 /* Stop message (input): TMODE_AUDIO_STEREOPATH_DRV_STOP_REQ */
2459 /* L1_STEREOPATH_DRV_STOP_CON */
2460 /* */
2461 /* Stop message (output): TMODE_AUDIO_STEREOPATH_DRV_STOP_CON */
2462 /* */
2463 /* Rem: */
2464 /* ---- */
2465 /* */
2466 /*----------------------------------------------------------------*/
2467 void l1a_tmode_audio_stereopath_process(xSignalHeaderRec *msg)
2468 {
2469 #if (CODE_VERSION == NOT_SIMULATION)
2470 enum states
2471 {
2472 RESET = 0,
2473 WAIT_START_REQ = 1,
2474 WAIT_START_CON = 2,
2475 WAIT_STOP = 3,
2476 WAIT_DSP_STOP = 4
2477
2478 };
2479
2480 UWORD8 *state = &l1a.state[TMODE_AUDIO_STEREOPATH_DRV_STATE];
2481 UWORD32 SignalCode = msg->SignalCode;
2482
2483 static UWORD8 previous_config = 0;
2484
2485 BOOL end_process = 0;
2486
2487 while(!end_process)
2488 {
2489 switch(*state)
2490 {
2491 case RESET:
2492 {
2493 // initialize global variable
2494 l1tm.stereopath.stereopath_source_timeout = 0;
2495 l1tm.stereopath.stereopath_dest_timeout = 0;
2496 l1tm.stereopath.stereopath_drop = 0;
2497 l1tm.stereopath.stereopath_frame = 0;
2498 l1tm.stereopath.stereopath_block = 0;
2499 l1tm.stereopath.stereopath_half_block = 0;
2500 l1tm.stereopath.stereopath_current_sample = 0;
2501 l1tm.stereopath.stereopath_buffer_number = 0;
2502
2503 // initialize ndb
2504 stp_drv_ndb->d_cport_api_dma_install = 0;
2505 stp_drv_ndb->d_cport_api_dma_channel = 0;
2506 stp_drv_ndb->d_cport_api_dma_rootcause = 0;
2507
2508 // Init DSP background
2509 l1s_dsp_com.dsp_ndb_ptr->a_background_tasks[C_BGD_STP_DRV] = (API)((C_BGD_STP_DRV<<11) | 1);
2510 if (l1s_dsp_com.dsp_ndb_ptr->d_max_background<(C_BGD_STP_DRV+1))
2511 l1s_dsp_com.dsp_ndb_ptr->d_max_background=(API)(C_BGD_STP_DRV+1);
2512
2513
2514 *state = WAIT_START_REQ;
2515 }
2516 break;
2517
2518 case WAIT_START_REQ:
2519 {
2520 if (SignalCode == TMODE_AUDIO_STEREOPATH_START_REQ)
2521 {
2522 // receive a request to start stereopath
2523 T_TMODE_AUDIO_STEREOPATH_START_REQ* tmode_audio_sp_conf_ptr;
2524
2525 // Flag msg received
2526 l1tm.tm_msg_received = TRUE;
2527
2528 /******************************************************************/
2529 /**************** GET STEREOPATH PARAMETERS ***********************/
2530 /******************************************************************/
2531
2532 if (((T_TMODE_AUDIO_STEREOPATH_START_REQ *)(msg->SigP))->configuration == AUDIO_SP_SELF_CONF)
2533 {
2534 // no use of a predefined configuration, we have to get parameters from the message
2535 tmode_audio_sp_conf_ptr = ((T_TMODE_AUDIO_STEREOPATH_START_REQ *)(msg->SigP));
2536 }
2537 else
2538 {
2539 UWORD8 conf_index = 0;
2540
2541 // use of a predefined configuration, we have to get parameters from the constant config
2542 tmode_audio_sp_conf_ptr = (T_TMODE_AUDIO_STEREOPATH_START_REQ *) tmode_audio_sp_conf[conf_index];
2543
2544 while ((tmode_audio_sp_conf_ptr != NULL) && (conf_index < NB_MAX_STEREOPATH_CONFIG))
2545 {
2546 if (tmode_audio_sp_conf_ptr->configuration == ((T_TMODE_AUDIO_STEREOPATH_START_REQ *)(msg->SigP))->configuration)
2547 break;
2548
2549 tmode_audio_sp_conf_ptr = (T_TMODE_AUDIO_STEREOPATH_START_REQ *) tmode_audio_sp_conf[++conf_index];
2550 }
2551 }
2552
2553 if (tmode_audio_sp_conf_ptr == NULL)
2554 {
2555 // unknow configuration identifier --> use message parameters
2556 tmode_audio_sp_conf_ptr = ((T_TMODE_AUDIO_STEREOPATH_START_REQ *)(msg->SigP));
2557 }
2558
2559 // Download the stereopath description in the l1a_l1s structure.
2560 l1a_l1s_com.stereopath_drv_task.parameters.sampling_frequency = tmode_audio_sp_conf_ptr->sampling_frequency;
2561 l1a_l1s_com.stereopath_drv_task.parameters.DMA_allocation = tmode_audio_sp_conf_ptr->DMA_allocation;
2562 l1a_l1s_com.stereopath_drv_task.parameters.DMA_channel_number = tmode_audio_sp_conf_ptr->DMA_channel_number;
2563 l1a_l1s_com.stereopath_drv_task.parameters.data_type = tmode_audio_sp_conf_ptr->data_type;
2564 l1a_l1s_com.stereopath_drv_task.parameters.source_port = tmode_audio_sp_conf_ptr->source_port;
2565 l1a_l1s_com.stereopath_drv_task.parameters.element_number = tmode_audio_sp_conf_ptr->element_number;
2566 l1a_l1s_com.stereopath_drv_task.parameters.frame_number = tmode_audio_sp_conf_ptr->frame_number;
2567 l1a_l1s_com.stereopath_drv_task.parameters.mono_stereo = tmode_audio_sp_conf_ptr->mono_stereo;
2568 l1a_l1s_com.stereopath_drv_task.parameters.feature_identifier = AUDIO_SP_TESTS_ID;
2569
2570 /******************************************************************/
2571 /**************** CHECK ALLOCATION DSP/MCU ************************/
2572 /******************************************************************/
2573
2574 if (tmode_audio_sp_conf_ptr->DMA_allocation == AUDIO_SP_DMA_ALLOC_MCU)
2575 {
2576 l1a_l1s_com.stereopath_drv_task.parameters.DMA_int_callback_fct = l1tm_stereopath_DMA_handler;
2577 }
2578 else // DMA_allocation == AUDIO_SP_DMA_ALLOC_DSP
2579 {
2580 // Update ndb
2581 stp_drv_ndb->d_cport_api_dma_install = 1;
2582 stp_drv_ndb->d_cport_api_dma_channel = l1a_l1s_com.stereopath_drv_task.parameters.DMA_channel_number;
2583 stp_drv_ndb->d_cport_api_dma_rootcause = 0;
2584
2585 // start background task
2586 l1s_dsp_com.dsp_ndb_ptr->d_background_enable|=(API)(1<<C_BGD_STP_DRV);
2587 l1_trigger_api_interrupt();
2588
2589 l1a_l1s_com.stereopath_drv_task.parameters.DMA_int_callback_fct = f_dma_default_call_back_it;
2590 }
2591
2592 /******************************************************************/
2593 /**************** GENERATION OF THE PATTERN ***********************/
2594 /******************************************************************/
2595
2596 // Reservation and generation of the pattern used to fill the buffer
2597 if (tmode_audio_sp_conf_ptr->pattern_identifier != AUDIO_SP_SILENCE_PATTERN)
2598 {
2599 l1tm.stereopath.stereopath_pattern = (WORD8 *)l1tm_stereopath_buffer;
2600
2601 // if pattern has already been build with the same config (mp3,midi or ext audio) in the current scenario,
2602 // we don't do it again. This is to avoid to have a CPU overload during critical operation such as access or packet transfer
2603 if ((tmode_audio_sp_conf_ptr->configuration == 0) || (tmode_audio_sp_conf_ptr->configuration != previous_config))
2604 {
2605 previous_config = tmode_audio_sp_conf_ptr->configuration;
2606 l1tm.stereopath.stereopath_nb_samples = l1tm_stereopath_get_pattern(l1tm_stereopath_sampling_freqs[tmode_audio_sp_conf_ptr->sampling_frequency],
2607 l1tm_stereopath_sin_freqs[tmode_audio_sp_conf_ptr->pattern_identifier][0],
2608 l1tm_stereopath_sin_freqs[tmode_audio_sp_conf_ptr->pattern_identifier][1],
2609 tmode_audio_sp_conf_ptr->data_type);
2610 }
2611 }
2612 else
2613 {
2614 // Silence pattern, consider just 2 samples at the value 0
2615 l1tm.stereopath.stereopath_nb_samples = 2;
2616
2617 l1tm.stereopath.stereopath_pattern = (WORD8 *)l1tm_stereopath_buffer;
2618 l1tm.stereopath.stereopath_pattern[0] = l1tm.stereopath.stereopath_pattern[1] =
2619 l1tm.stereopath.stereopath_pattern[2] = l1tm.stereopath.stereopath_pattern[3] = 0x0000;
2620 }
2621
2622 /******************************************************************/
2623 /**************** GET ADDRESS OF THE BUFFER ***********************/
2624 /******************************************************************/
2625 #if (CHIPSET == 15)
2626 if (tmode_audio_sp_conf_ptr->source_port == AUDIO_SP_SOURCE_EMIF)
2627 {
2628 // get an address in internal RAM
2629 l1a_l1s_com.stereopath_drv_task.parameters.source_buffer_address = (WORD8*) TM_stereo_buf_ext_mem;
2630 }
2631
2632
2633 if (tmode_audio_sp_conf_ptr->source_port == AUDIO_SP_SOURCE_IMIF)
2634 {
2635 // get an address in internal RAM
2636 l1a_l1s_com.stereopath_drv_task.parameters.source_buffer_address = (WORD8*) TM_stereo_buf;
2637 }
2638
2639 if (tmode_audio_sp_conf_ptr->source_port == AUDIO_SP_SOURCE_API)
2640 {
2641 // Disable DSP trace
2642 l1s_dsp_com.dsp_ndb_ptr->d_debug_trace_type &= 0xfff0;
2643 l1s_dsp_com.dsp_ndb_ptr->d_debug_trace_type |= 0x8000;
2644
2645 l1a_l1s_com.stereopath_drv_task.parameters.source_buffer_address = (WORD8*)API_address_dsp2mcu(C_STP_DRV_BUF_API_BASE_ADDRESS);
2646 }
2647 #else
2648 if (tmode_audio_sp_conf_ptr->source_port == AUDIO_SP_SOURCE_IMIF)
2649 {
2650 // get an address in internal RAM
2651 l1a_l1s_com.stereopath_drv_task.parameters.source_buffer_address = (WORD8*) TM_stereo_buf;
2652 }
2653 else // source_port == AUDIO_SP_SOURCE_API
2654 {
2655 // Disable DSP trace
2656 l1s_dsp_com.dsp_ndb_ptr->d_debug_trace_type &= 0xfff0;
2657 l1s_dsp_com.dsp_ndb_ptr->d_debug_trace_type |= 0x8000;
2658
2659 l1a_l1s_com.stereopath_drv_task.parameters.source_buffer_address = (WORD8*)API_address_dsp2mcu(C_STP_DRV_BUF_API_BASE_ADDRESS);
2660 }
2661 #endif
2662
2663 /******************************************************************/
2664 /**************** FILL THE 2 FIRST BUFFERS ************************/
2665 /******************************************************************/
2666
2667 l1tm_stereopath_fill_buffer((void*) l1a_l1s_com.stereopath_drv_task.parameters.source_buffer_address);
2668 l1tm_stereopath_fill_buffer((void*) l1a_l1s_com.stereopath_drv_task.parameters.source_buffer_address);
2669
2670 // Start the L1S stereopath task
2671 l1a_l1s_com.stereopath_drv_task.command.start = TRUE;
2672
2673 *state = WAIT_START_CON;
2674 }
2675
2676 // End process
2677 end_process = 1;
2678 }
2679 break;
2680
2681 case WAIT_START_CON:
2682 {
2683 if (SignalCode == L1_STEREOPATH_DRV_START_CON)
2684 {
2685 // Send the start confirmation message
2686 l1a_audio_send_confirmation(TMODE_AUDIO_STEREOPATH_START_CON);
2687
2688 *state = WAIT_STOP;
2689 }
2690
2691 // End process
2692 end_process = 1;
2693 }
2694 break;
2695
2696 case WAIT_STOP:
2697 {
2698 if (SignalCode == TMODE_AUDIO_STEREOPATH_STOP_REQ)
2699 {
2700 if (l1a_l1s_com.stereopath_drv_task.parameters.DMA_allocation == AUDIO_SP_DMA_ALLOC_DSP)
2701 {
2702 // we first need to stop the DSP background task
2703 stp_drv_ndb->d_cport_api_dma_install = 0xFFFF;
2704 l1_trigger_api_interrupt();
2705
2706 *state = WAIT_DSP_STOP;
2707 }
2708 else
2709 {
2710 // Stop the L1S stereopath task
2711 l1a_l1s_com.stereopath_drv_task.command.stop = TRUE;
2712
2713 // End process
2714 end_process = 1;
2715 }
2716 }
2717 else
2718 if (SignalCode == L1_STEREOPATH_DRV_STOP_CON)
2719 {
2720 // Reset TM msg flag
2721 // No new L1S result messages may be received before a new TM command
2722 l1tm.tm_msg_received = FALSE;
2723
2724 free(l1tm.stereopath.stereopath_pattern);
2725
2726 // Send the stop confirmation message
2727 l1a_audio_send_confirmation(TMODE_AUDIO_STEREOPATH_STOP_CON);
2728
2729 *state = RESET;
2730 }
2731 else
2732 {
2733 // End process
2734 end_process = 1;
2735 }
2736 }
2737 break;
2738
2739 case WAIT_DSP_STOP:
2740 {
2741 if (stp_drv_ndb->d_cport_api_dma_install == 0)
2742 {
2743 // stop the DSP background task
2744 l1s_dsp_com.dsp_ndb_ptr->d_background_enable&=(API)(~(1<<C_BGD_STP_DRV));
2745 l1_trigger_api_interrupt();
2746
2747 // Stop the L1S stereopath task
2748 l1a_l1s_com.stereopath_drv_task.command.stop = TRUE;
2749
2750 *state = WAIT_STOP;
2751
2752 end_process = 1;
2753 }
2754 }
2755 break;
2756 } // switch
2757 } // while(!end_process)
2758 #endif // CODE_VERSION == NOT_SIMULATION
2759 }
2760 #endif // #if ((L1_STEREOPATH == 1) && (OP_L1_STANDALONE == 1))
2761 #endif