comparison L1/dyn_dwl_cfile/l1_dyn_dwl_afunc.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children dfc7b0bc468a
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
1 /************* Revision Controle System Header *************
2 * GSM Layer 1 software
3 * L1_DYN_DWL_AFUNC.C
4 *
5 * Filename l1_dyn_dwl_afunc.c
6 * Copyright 2004 (C) Texas Instruments
7 *
8 ************* Revision Controle System Header *************/
9
10 #include "config.h"
11 #include "l1_confg.h"
12 #include "l1_types.h"
13 #include "sys_types.h"
14 #include "../../gpf/inc/cust_os.h"
15 #include "l1_macro.h"
16 #include "l1_const.h"
17 #if TESTMODE
18 #include "l1tm_defty.h"
19 #endif
20 #if (AUDIO_TASK == 1)
21 #include "l1audio_const.h"
22 #include "l1audio_cust.h"
23 #include "l1audio_defty.h"
24 #include "l1audio_signa.h"
25 #endif
26 #if (L1_GTT == 1)
27 #include "l1gtt_const.h"
28 #include "l1gtt_defty.h"
29 #include "l1gtt_signa.h"
30 #endif
31 #if (L1_DYN_DSP_DWNLD == 1)
32 #include "l1_dyn_dwl_msgty.h"
33 #include "l1_dyn_dwl_defty.h"
34 #include "l1_dyn_dwl_proto.h"
35 #include "l1_dyn_dwl_const.h"
36 #endif //L1_DYN_DSP_DWNLD
37 #if (L1_MP3 == 1)
38 #include "l1mp3_signa.h"
39 #include "l1mp3_defty.h"
40 #endif //L1_MP3
41 #if (L1_MIDI == 1)
42 #include "l1midi_defty.h"
43 #endif
44 #if (L1_AAC == 1)
45 #include "l1aac_signa.h"
46 #include "l1aac_defty.h"
47 #endif //L1_AAC
48 #include "l1_defty.h"
49 #include "l1_varex.h"
50 #include "l1_msgty.h"
51 #include "l1_proto.h"
52 #include "l1_signa.h"
53 #include <string.h>
54 #include <stdio.h>
55
56
57 #if (TRACE_TYPE == 1) ||(TRACE_TYPE == 4) || (TRACE_TYPE == 7) || (TESTMODE)
58 #include "l1_trace.h"
59 #endif
60
61 #if (L1_DYN_DSP_DWNLD == 1)
62
63 extern const BOOL primitives_to_patch_matrix[][MAX_NUM_OF_PATCH_IDS];
64 extern const BOOL incompatibility_matrix[][MAX_NUM_OF_PATCH_IDS];
65 extern const BOOL semaphore_matrix[][MAX_NUM_OF_SEMAPHORES];
66
67 /* table reconstructed from disassembly of TCS211 binary object */
68 const T_SIGNAL_PATCH signal_patch_array[NUM_OF_DYN_DWNLD_PRIMITIVES] =
69 {
70 {L1C_STOP_DEDICATED_DONE, 0},
71 #if (L1_GTT == 1)
72 {MMI_GTT_START_REQ, 1},
73 #endif
74 {MPHC_IMMED_ASSIGN_REQ, 2},
75 #if (MELODY_E2 == 1)
76 {MMI_MELODY0_E2_START_REQ, 3},
77 {MMI_MELODY1_E2_START_REQ, 4},
78 {L1_BACK_MELODY_E2_UNLOAD_INSTRUMENT_CON, 5},
79 #endif
80 };
81
82
83 /*
84 * LoCosto version of L1 has a function called l1_check_flag_for_download_area()
85 * here. TCS211 binary object has l1_handle_particular_cases_for_TCS211()
86 * instead. We are going to reconstruct the TCS211 function based on
87 * disassembly, using the LoCosto version as our starting point.
88 */
89
90 void l1_handle_particular_cases_for_TCS211(UWORD32 msg_code, BOOL *return_flag)
91 {
92 switch(msg_code)
93 {
94 /* from disassembly */
95 case MPHC_IMMED_ASSIGN_REQ: /* 0x0033 */
96 /* code at 0x8e */
97 l1a.dyn_dwnld.dedicated_stop_flag = FALSE;
98 return;
99 case L1C_STOP_DEDICATED_DONE: /* 0x0081 */
100 /* code at 0x86 */
101 l1a.dyn_dwnld.dedicated_stop_flag = TRUE;
102 return;
103 #if (MELODY_E2 == 1)
104 case MMI_MELODY0_E2_START_REQ: /* 0x182E */
105 /* code at 0x6c */
106 l1a.dyn_dwnld.melody0_E2_flag_activated = TRUE;
107 if (l1a.dyn_dwnld.melody1_E2_flag_activated == TRUE) {
108 /* code at 0x80 */
109 *return_flag = FALSE;
110 return;
111 }
112 return;
113 case MMI_MELODY1_E2_START_REQ: /* 0x1832 */
114 /* code at 0x56 */
115 l1a.dyn_dwnld.melody1_E2_flag_activated = TRUE;
116 if (l1a.dyn_dwnld.melody0_E2_flag_activated == TRUE) {
117 /* code at 0x80 */
118 *return_flag = FALSE;
119 return;
120 }
121 return;
122 case L1_BACK_MELODY_E2_UNLOAD_INSTRUMENT_CON: /* 0x1866 */
123 /* code at 0x3e */
124 if (l1a.dyn_dwnld.melody0_E2_flag_activated == TRUE ||
125 l1a.dyn_dwnld.melody1_E2_flag_activated == TRUE) {
126 /* code at 0x80 */
127 *return_flag = FALSE;
128 return;
129 }
130 return;
131 case L1_MELODY0_E2_STOP_CON: /* 0x1867 */
132 /* code at 0x36 */
133 l1a.dyn_dwnld.melody0_E2_flag_activated = FALSE;
134 return;
135 case L1_MELODY1_E2_STOP_CON: /* 0x1868 */
136 /* code at 0x2e */
137 l1a.dyn_dwnld.melody1_E2_flag_activated = FALSE;
138 return;
139 #endif
140 default:
141 return;
142 }
143
144 }
145 /*------------------------------------------------------------------------------------------------------------------- */
146 /* l1_does_the_incoming_primitive_trigger_dynamic_dwnld */
147 /*------------------------------------------------------------------------------------------------------------------- */
148 /* */
149 /* Parameters : Signal Code of the message, delay flag */
150 /* */
151 /* Return : TRUE if the primitive triggers a dynamic download, FALSE in the other case */
152 /* */
153 /* Description : Check if the primitive triggers a dynamic download; if yes it return TRUE, otherwise FALSE */
154 /* */
155 /* */
156 /*------------------------------------------------------------------------------------------------------------------- */
157
158 BOOL l1_does_the_incoming_primitive_trigger_dynamic_dwnld(UWORD32 msg_code, BOOL delay_flag)
159 {
160 BOOL return_flag = FALSE;
161 UWORD16 i;
162 for (i=0;i<l1a.dyn_dwnld.num_of_primitives;i++)
163 {
164 if(msg_code == signal_patch_array[i].primitive)
165 return_flag = TRUE;
166
167 }
168
169 l1_handle_particular_cases_for_TCS211(msg_code, &return_flag);
170
171 return return_flag;
172 }
173
174 /*---------------------------------------------------------------------------------------- */
175 /* l1_lookup_primitive_patch_matrix */
176 /*---------------------------------------------------------------------------------------- */
177 /* */
178 /* Parameters : Signal Code of the message, patch_id vector */
179 /* */
180 /* Return : number of patches to download, patch ids vectore (by reference) */
181 /* */
182 /* Description : Retrieves the patch ids to be downloaded and number of patches to download */
183 /* Patch ID is retrieved via look-up in primitives to patch ID matrix */
184 /* */
185 /*---------------------------------------------------------------------------------------- */
186
187 UWORD16 l1_lookup_primitive_patch_matrix(UWORD32 msg_code, UWORD16* patch_id_p)
188 {
189 UWORD16 j;
190 UWORD16 counter=0;
191 UWORD16 msg_code_id=0 ;//omaps00090550
192
193 // Check if one of the messages belongs to the set of primitves which triggers a dynamic download and saves its index
194
195 #if 0 // LoCosto-ism not present in TCS211
196 if (!((l1a.state[L1A_GTT_STATE] == 0) || (l1a.state[L1A_GTT_STATE] == 1))) // TTY ON
197 {
198 if(msg_code == MMI_TCH_VOCODER_CFG_REQ) // AND Current_message == VOCODER
199 {
200 // Dont do anything
201 return 0;
202 }
203 }
204 #endif
205
206 for (j=0;j<NUM_OF_DYN_DWNLD_PRIMITIVES;j++)
207 {
208 if (msg_code == signal_patch_array[j].primitive)
209 msg_code_id = signal_patch_array[j].msg_id;
210 }
211
212
213 // Compute the number of elements to be downloaded and their ids
214 for (j=0; j<MAX_NUM_OF_PATCH_IDS; j++)
215 {
216 patch_id_p[j]=0xFFFF; //omaps00090550 ;
217 if(primitives_to_patch_matrix[msg_code_id][j] == 1)
218 {
219 patch_id_p[counter++]=j;
220 }
221 }
222 return counter;
223 }
224
225 /*------------------------------------------------------------------------- */
226 /* l1_is_patch_already_installed */
227 /*------------------------------------------------------------------------- */
228 /* */
229 /* Parameters : patch id */
230 /* */
231 /* Return : TRUE patch is already installed, FALSE otherwise */
232 /* */
233 /* Description : Check if the selected patch id is already installed or not*/
234 /* */
235 /* */
236 /*------------------------------------------------------------------------- */
237
238 BOOL l1_is_patch_already_installed (UWORD16 patch_id)
239 {
240 UWORD16 i=0;
241 while(i<l1a.dyn_dwnld.num_patches_installed)
242 {
243 if(l1a.dyn_dwnld.patch_id[i]==patch_id)
244 break;
245 else
246 i++;
247 }
248 if(i<l1a.dyn_dwnld.num_patches_installed)
249 return TRUE;
250 else
251 return FALSE;
252 }
253
254 /*----------------------------------------------------------------------------- */
255 /* l1_is_patch_id_in_uninstall_set */
256 /*----------------------------------------------------------------------------- */
257 /* */
258 /* Parameters : patch id, uninstall address vector, num of uninstall elements */
259 /* */
260 /* Return : TRUE patch is in the set, FALSE otherwise */
261 /* */
262 /* Description : Check if the selected patch id is in the uninstall set or not */
263 /* */
264 /* */
265 /*----------------------------------------------------------------------------- */
266
267 BOOL l1_is_patch_id_in_uninstall_set (UWORD16 patch_id, UWORD16 *uninstall_patch_vect, UWORD16 num_of_uninstall_elem)
268 {
269 UWORD16 i;
270 for (i=0;i<num_of_uninstall_elem;i++)
271 {
272 if(patch_id==uninstall_patch_vect[i])
273 return TRUE;
274 }
275 return FALSE;
276 }
277
278 /*--------------------------------------------------------------------------------------------------------------------------------------- */
279 /* l1_manage_patch_incompatibilty */
280 /*--------------------------------------------------------------------------------------------------------------------------------------- */
281 /* */
282 /* Parameters : num of patch to download, num of uninstalled elements (pointer), uninstall vect */
283 /* Return : TRUE if there is some patch to uninstall, FALSE otherwise. By reference, num of patches to uninstall and their IDs */
284 /* */
285 /* Description : Check if some patch must be uninstalled: in case, retrieves the number of patch to uninstall and their IDs */
286 /* */
287 /*--------------------------------------------------------------------------------------------------------------------------------------- */
288
289 BOOL l1_manage_patch_incompatibilty(UWORD16 num_of_patch_id_to_dwnld, UWORD16 *num_of_uninstall_elem, UWORD16 *uninstall_patch_id_vect)
290 {
291 UWORD16 i,j;
292 UWORD16 patch_id;
293
294 // Reset values passed by reference
295 *num_of_uninstall_elem=0;
296 for(j=0;j<MAX_NUM_OF_PATCH_IDS;j++)
297 uninstall_patch_id_vect[j]=0xFFFF; //omaps00090550 ;
298
299 // First cycle: for all the patches that must be downloaded
300 for(i=0;i<num_of_patch_id_to_dwnld;i++)
301 {
302 patch_id=l1a.dyn_dwnld.next_patch_id[i];
303 // Check all incompatibilities
304 for(j=0;j<MAX_NUM_OF_PATCH_IDS;j++)
305 {
306 // If patch ID j is incompatible with selected patch id that must be downloaded
307 if(incompatibility_matrix[patch_id][j]==1)
308 {
309 // If patch j is already installed and not yet in the uninstall set
310 if((l1_is_patch_already_installed(j) == TRUE) && (l1_is_patch_id_in_uninstall_set(j,uninstall_patch_id_vect,(*num_of_uninstall_elem))==FALSE))
311 {
312 // Add patch j in the uninstall set and increase number of uninstall elements
313 uninstall_patch_id_vect[*num_of_uninstall_elem]=j;
314 (*num_of_uninstall_elem)++;
315 }
316 }
317 }
318 }
319 if(*num_of_uninstall_elem==0)
320 return TRUE;
321 else
322 return FALSE;
323 }
324
325 /*----------------------------------------------------------------- */
326 /* l1_set_semaphores_for_all_state_machines_involved */
327 /*----------------------------------------------------------------- */
328 /* */
329 /* Parameters : num of patches to download, */
330 /* Return : none */
331 /* */
332 /* Description : Set semaphores for the state machines impacted */
333 /* */
334 /* */
335 /*----------------------------------------------------------------- */
336
337 void l1_set_semaphores_for_all_state_machines_involved(UWORD16 num_of_patch_id_to_dwnld, UWORD16* next_patch_id)
338 {
339 UWORD16 i,j, patch_id;
340 for (i=0;i<num_of_patch_id_to_dwnld;i++)
341 {
342 patch_id = next_patch_id[i];
343 for(j=0;j<MAX_NUM_OF_SEMAPHORES;j++)
344 {
345 if(semaphore_matrix[patch_id][j]==1)
346 {
347 l1a.dyn_dwnld.semaphore_vect[j]=RED;
348 }
349 }
350 }
351 }
352
353 /*----------------------------------------------------------------- */
354 /* l1_update_semaphores_for_all_state_machines */
355 /*----------------------------------------------------------------- */
356 /* */
357 /* Parameters : num of patches to download, */
358 /* Return : none */
359 /* */
360 /* Description : Update semaphores for the state machines impacted */
361 /* (DELAY case) */
362 /* */
363 /*----------------------------------------------------------------- */
364
365 void l1_update_semaphores_for_all_state_machines(UWORD16 num_of_patch_id_to_dwnld)
366 {
367 /* In case of delay the patch which is DELAYED may have been be already installed*/
368 /* The semaphores that have been raised during the previous dynamic download */
369 /* for that patch must be updated */
370
371 UWORD16 i,j, patch_id;
372 for(j=0;j<MAX_NUM_OF_SEMAPHORES;j++)
373 l1a.dyn_dwnld.semaphore_vect[j] = GREEN;
374 for (i=0;i<num_of_patch_id_to_dwnld;i++)
375 {
376 patch_id = l1a.dyn_dwnld.next_patch_id[i];
377 for(j=0;j<MAX_NUM_OF_SEMAPHORES;j++)
378 {
379 if(semaphore_matrix[patch_id][j]==1)
380 {
381 l1a.dyn_dwnld.semaphore_vect[j]=RED;
382 }
383 }
384 }
385 }
386
387 /*-------------------------------------------------------*/
388 /* l1_reset_semaphores */
389 /*-------------------------------------------------------*/
390 /* */
391 /* Parameters : none */
392 /* Return : */
393 /* */
394 /* Description : Reset semaphores only for the state machines related to the currently downloaded patches */
395 /* In fact, because of delay, some semaphores can be set for patch that will be downloaded in the follwoing step */
396 /* */
397 /*-------------------------------------------------------*/
398 void l1_reset_semaphores()
399 {
400 UWORD16 i,j, patch_id;
401 for (i=0;i<l1a.dyn_dwnld.num_of_elem_to_copy;i++)
402 {
403 patch_id = l1a.dyn_dwnld.next_patch_id[i];
404 for(j=0;j<MAX_NUM_OF_SEMAPHORES;j++)
405 {
406 if(semaphore_matrix[patch_id][j]==1)
407 {
408 l1a.dyn_dwnld.semaphore_vect[j]=GREEN;
409 }
410 }
411 }
412 }
413
414
415 /*---------------------------------------------------------- */
416 /* l1_push_Primitive */
417 /*---------------------------------------------------------- */
418 /* */
419 /* Parameters : primitive ID */
420 /* Return : TRUE if push is successful, FALSE otherwise */
421 /* */
422 /* Description : Push primitive ID into DELAY FIFO */
423 /* */
424 /* */
425 /*---------------------------------------------------------- */
426
427 BOOL l1_push_Primitive(UWORD32 primitive_id)
428 {
429 UWORD32 num_elem = l1a.dyn_dwnld.waiting_patch_fifo.num_of_elem;
430 BOOL return_flag = TRUE;
431
432 if(num_elem >= MAX_NUM_OF_PATCH_IDS)
433 {
434 return_flag = FALSE;
435 }
436 else
437 {
438 l1a.dyn_dwnld.waiting_patch_fifo.signal_code_vect[num_elem++] = primitive_id;
439 l1a.dyn_dwnld.waiting_patch_fifo.num_of_elem = num_elem;
440 }
441 return return_flag;
442 }
443
444 /*---------------------------------------------------------- */
445 /* l1_pop_Primitive */
446 /*---------------------------------------------------------- */
447 /* */
448 /* Parameters : primitive ID (pointer) */
449 /* Return : TRUE if pop is successful, FALSE otherwise */
450 /* */
451 /* Description : Pop primitive from DELAY FIFO */
452 /* */
453 /* */
454 /*---------------------------------------------------------- */
455
456 BOOL l1_pop_Primitive(UWORD32 *p_primitive)
457 {
458 UWORD32 primitive_id;
459 UWORD8 ind;
460 UWORD32 num_elem = l1a.dyn_dwnld.waiting_patch_fifo.num_of_elem;
461 BOOL return_flag = TRUE;
462
463 if(num_elem <= 0)
464 {
465 return_flag = FALSE;
466 }
467 else
468 {
469 primitive_id = l1a.dyn_dwnld.waiting_patch_fifo.signal_code_vect[0];
470 for (ind = 0;ind<num_elem-1;ind++)
471 l1a.dyn_dwnld.waiting_patch_fifo.signal_code_vect[ind] = l1a.dyn_dwnld.waiting_patch_fifo.signal_code_vect[ind+1];
472 l1a.dyn_dwnld.waiting_patch_fifo.signal_code_vect[num_elem-1] = 0;
473 l1a.dyn_dwnld.waiting_patch_fifo.num_of_elem = num_elem-1;
474 *p_primitive = primitive_id;
475 }
476 return return_flag;
477 }
478 /*---------------------------------------------------------- */
479 /* l1_check_Fifo_Primitive */
480 /*---------------------------------------------------------- */
481 /* */
482 /* Parameters : none */
483 /* Return : Number of elements in the FIFO */
484 /* */
485 /* Description : Return number of elements in the FIFO */
486 /* */
487 /* */
488 /*---------------------------------------------------------- */
489
490 UWORD32 l1_check_Fifo_Primitive()
491 {
492 return l1a.dyn_dwnld.waiting_patch_fifo.num_of_elem;
493 }
494 #endif // L1_DYN_DSP_DWNLD == 1