comparison gsm-fw/L1/dyn_dwl_cfile/l1_dyn_dwl_afunc.c @ 925:c56ba3363aa3

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