comparison gsm-fw/L1/dyn_dwl_cfile/l1_dyn_dwl_func.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_FUNC.C
4 *
5 * Filename l1_dyn_dwl_func.c
6 * Copyright 2004 (C) Texas Instruments
7 *
8 ************* Revision Controle System Header *************/
9
10 #include <stdio.h>
11 #include <string.h>
12 #include "l1_confg.h"
13 #include "l1_types.h"
14 #include "l1_const.h"
15 #include "l1_signa.h"
16 #include "sys_types.h"
17
18 #if(L1_DYN_DSP_DWNLD == 1)
19 #include "l1_dyn_dwl_const.h"
20 #include "l1_dyn_dwl_proto.h"
21 #include "l1_dyn_dwl_defty.h"
22 #endif
23 #if TESTMODE
24 #include "l1tm_defty.h"
25 #endif
26 #if (AUDIO_TASK == 1)
27 #include "l1audio_const.h"
28 #include "l1audio_cust.h"
29 #include "l1audio_defty.h"
30 #endif
31 #if (L1_GTT == 1)
32 #include "l1gtt_const.h"
33 #include "l1gtt_defty.h"
34 #endif
35 #if (L1_MP3 == 1)
36 #include "l1mp3_defty.h"
37 #endif //L1_MP3
38 #if (L1_MIDI == 1)
39 #include "l1midi_defty.h"
40 #endif
41
42 #include "l1_defty.h"
43 #include "l1_varex.h"
44 #include "l1_macro.h"
45
46 #if (L1_DYN_DSP_DWNLD == 1)
47 #ifndef NULL
48 #define NULL 0
49 #endif
50
51 extern T_DYN_DWNLD_MCU_DSP *dyn_dwl_ndb;
52 #if (CODE_VERSION == SIMULATION)
53 extern T_DYN_DWNLD_MCU_DSP dyn_dwl_ndb_sim;
54 extern UWORD16 dwnld_area_array[SIZE_DWNLD_AREA_SIMU];
55 #endif // CODE_VERSION == SIMULATION
56
57
58 /*---------------------------------------------------------------------------- */
59 /* l1_initialize_patch_parameters */
60 /*------------------------------------------------------------------------- */
61 /* */
62 /* Parameters : */
63 /* */
64 /* Return : size of the patch */
65 /* */
66 /* Description : Initialize patch parameters and returns the size of the patch*/
67 /* */
68 /* */
69 /*---------------------------------------------------------------------------- */
70
71 UWORD16 l1_initialize_patch_parameters(void)
72 {
73 UWORD16 patch_size = 0;
74
75 /* Initialize download patch parameters */
76 l1_apihisr.dyn_dwnld.running_source_pointer = l1a_apihisr_com.dyn_dwnld.copy_parameters.start_MCU_copy_address[l1a_apihisr_com.dyn_dwnld.copy_parameters.num_of_elem-l1_apihisr.dyn_dwnld.patch_ids_counter];
77 patch_size = l1a_apihisr_com.dyn_dwnld.copy_parameters.size_array[l1a_apihisr_com.dyn_dwnld.copy_parameters.num_of_elem-l1_apihisr.dyn_dwnld.patch_ids_counter];
78 dyn_dwl_ndb->d_api_dwl_crc = 0x0;
79 return patch_size;
80 }
81
82 /*---------------------------------------------------------------------------- */
83 /* l1_set_uninstall_parameters */
84 /*------------------------------------------------------------------------- */
85 /* */
86 /* Parameters : void */
87 /* */
88 /* Return : void */
89 /* */
90 /* Description : Set uninstall parameters */
91 /* */
92 /* */
93 /*---------------------------------------------------------------------------- */
94
95 void l1_set_uninstall_parameters(void)
96 {
97 /* Set next uninstall adress (pointer incremented) */
98 dyn_dwl_ndb->d_api_dwl_function_address[0] = (API) (l1a_apihisr_com.dyn_dwnld.uninstall_parameters.address[l1a_apihisr_com.dyn_dwnld.uninstall_parameters.num_of_elem - l1_apihisr.dyn_dwnld.uninstall_counter] & 0x0000FFFF);
99 dyn_dwl_ndb->d_api_dwl_function_address[1] = (API) ((l1a_apihisr_com.dyn_dwnld.uninstall_parameters.address[l1a_apihisr_com.dyn_dwnld.uninstall_parameters.num_of_elem - l1_apihisr.dyn_dwnld.uninstall_counter] >> 16) & 0x0000FFFF);
100
101 /* Set uninstall command */
102 dyn_dwl_ndb->d_api_dwl_download_ctrl = (API) C_DWL_DOWNLOAD_CTRL_UNINSTALL;
103 }
104
105 /*---------------------------------------------------------------------------- */
106 /* l1_initialize_pointers_for_copy */
107 /*------------------------------------------------------------------------- */
108 /* */
109 /* Parameters : address of source and destination pointer */
110 /* */
111 /* Return : source and destination address modified by reference */
112 /* */
113 /* Description : Initialize the pointers for the copy */
114 /* */
115 /* */
116 /*---------------------------------------------------------------------------- */
117
118 void l1_initialize_pointers_for_copy(UWORD16 **pp_dest_mcu, UWORD16 **pp_src_mcu)
119 {
120 /* BEGIN: Initialize download area parameters at start download area */
121 dyn_dwl_ndb->d_api_dwl_write_pointer = l1a_apihisr_com.dyn_dwnld.copy_parameters.start_of_dwnld_area - 1; // correction
122
123 /* Initialize pointers */
124 #if (CODE_VERSION == SIMULATION)
125 *pp_dest_mcu = (UWORD16 *) dwnld_area_array;
126 #else
127 *pp_dest_mcu = (UWORD16 *) API_address_dsp2mcu(l1a_apihisr_com.dyn_dwnld.copy_parameters.start_of_dwnld_area);
128 #endif // CODE_VERSION == SIMULATION
129
130 *pp_src_mcu = (UWORD16 *) l1_apihisr.dyn_dwnld.running_source_pointer;
131 }
132
133 /*---------------------------------------------------------------------------- */
134 /* l1_copy_till_the_end_of_the_patch_and_update_write_pointer */
135 /*---------------------------------------------------------------------------- */
136 /* */
137 /* Parameters : size of the patch, source and destination pointer */
138 /* */
139 /* Return : none */
140 /* */
141 /* Description : Copy until the end of the patch is reached */
142 /* */
143 /* */
144 /*---------------------------------------------------------------------------- */
145
146 void l1_copy_till_the_end_of_the_patch_and_update_write_pointer(UWORD16 tmp_patch_size, UWORD16* p_dest_mcu, UWORD16* p_src_mcu)
147 {
148 while (tmp_patch_size > NUM_WORDS_COPY_API)
149 {
150 l1_memcpy_16bit(p_dest_mcu,p_src_mcu, NUM_WORDS_COPY_API*sizeof(UWORD16));
151 p_dest_mcu += NUM_WORDS_COPY_API;
152 p_src_mcu += NUM_WORDS_COPY_API;
153 tmp_patch_size -= NUM_WORDS_COPY_API;
154 dyn_dwl_ndb->d_api_dwl_write_pointer += NUM_WORDS_COPY_API;
155 }
156 if (tmp_patch_size != 0)
157 {
158 l1_memcpy_16bit(p_dest_mcu,p_src_mcu, tmp_patch_size*sizeof(UWORD16));
159 dyn_dwl_ndb->d_api_dwl_write_pointer += tmp_patch_size;
160 }
161 }
162
163 /*---------------------------------------------------------------------------- */
164 /* l1_copy_till_end_of_dwnld_area_and_update_write_pointer */
165 /*---------------------------------------------------------------------------- */
166 /* */
167 /* Parameters : address of size of the patch, size of download area, */
168 /* addresses of source pointer, destination pointer */
169 /* */
170 /* Return : source pointer and size modified by reference */
171 /* */
172 /* Description : Copy until the end of download area is reached */
173 /* */
174 /* */
175 /*---------------------------------------------------------------------------- */
176
177 void l1_copy_till_end_of_dwnld_area_and_update_write_pointer(UWORD16 tmp_dwnld_area_size,UWORD16 *p_dest_mcu, UWORD16 *p_tmp_patch_size, UWORD16 **pp_src_mcu)
178 {
179 UWORD16 tmp_patch_size = *p_tmp_patch_size;
180 UWORD16 *p_src_mcu = (UWORD16 *)*pp_src_mcu;
181
182 while (tmp_dwnld_area_size > NUM_WORDS_COPY_API)
183 {
184 l1_memcpy_16bit(p_dest_mcu,p_src_mcu, NUM_WORDS_COPY_API*sizeof(UWORD16));
185 p_dest_mcu += NUM_WORDS_COPY_API;
186 p_src_mcu += NUM_WORDS_COPY_API;
187 tmp_patch_size -= NUM_WORDS_COPY_API;
188 tmp_dwnld_area_size -= NUM_WORDS_COPY_API;
189 dyn_dwl_ndb->d_api_dwl_write_pointer += NUM_WORDS_COPY_API;
190 }
191
192 if (tmp_dwnld_area_size > 0)
193 {
194 l1_memcpy_16bit(p_dest_mcu,p_src_mcu, tmp_dwnld_area_size*sizeof(UWORD16));
195 p_src_mcu += tmp_dwnld_area_size;
196 tmp_patch_size -= tmp_dwnld_area_size;
197 dyn_dwl_ndb->d_api_dwl_write_pointer += tmp_dwnld_area_size;
198 }
199 *pp_src_mcu = (UWORD16 *) p_src_mcu;
200 *p_tmp_patch_size = tmp_patch_size;
201 }
202
203 /*---------------------------------------------------------------------------- */
204 /* l1_copy_first_N_words */
205 /*---------------------------------------------------------------------------- */
206 /* */
207 /* Parameters : address of size of the patch, address of size of download area,*/
208 /* addresses of source pointer, address of destination pointer */
209 /* */
210 /* Return : source and destination pointer modified by reference */
211 /* size of download area and patch area modified by reference */
212 /* */
213 /* Description : Copy the min(N, remaining size of the patch) at the beginning */
214 /* download area */
215 /* */
216 /* */
217 /*---------------------------------------------------------------------------- */
218
219 BOOL l1_copy_first_N_words (UWORD16 *dwnld_area_size_p, UWORD16 *patch_area_size_p, UWORD16 **pp_dest_mcu, UWORD16 **pp_src_mcu)
220 {
221 BOOL return_flag;
222 UWORD16 num_words_interrupt;
223 UWORD16 tmp_patch_size = *patch_area_size_p;
224 UWORD16 tmp_dwnld_area_size = *dwnld_area_size_p;
225 UWORD16 *p_dest_mcu =(UWORD16 *)*pp_dest_mcu;
226 UWORD16 *p_src_mcu = (UWORD16 *)*pp_src_mcu;
227
228 /* Copy first N words and generate API interrupt*/
229 if (tmp_patch_size > NUM_WORDS_COPY_API)
230 {
231 num_words_interrupt = NUM_WORDS_COPY_API;
232 return_flag = TRUE;
233 }
234 else
235 {
236 num_words_interrupt = tmp_patch_size;
237 return_flag = FALSE;
238 }
239
240 l1_memcpy_16bit(p_dest_mcu,p_src_mcu, num_words_interrupt*sizeof(UWORD16));
241
242 p_dest_mcu += num_words_interrupt;
243 p_src_mcu += num_words_interrupt;
244
245 tmp_patch_size -= num_words_interrupt;
246 tmp_dwnld_area_size -= num_words_interrupt;
247
248 dyn_dwl_ndb->d_api_dwl_write_pointer+=num_words_interrupt;
249
250 *patch_area_size_p = tmp_patch_size;
251 *dwnld_area_size_p = tmp_dwnld_area_size;
252 *pp_dest_mcu = (UWORD16 *)p_dest_mcu;
253 *pp_src_mcu = (UWORD16 *)p_src_mcu ;
254
255 return return_flag;
256 }
257
258 /*---------------------------------------------------------------------------- */
259 /* l1_initialize_download_area_parameters */
260 /*---------------------------------------------------------------------------- */
261 /* */
262 /* Parameters : none */
263 /* */
264 /* */
265 /* Return : download area size */
266 /* */
267 /* Description : Initialize download area: all the parameters */
268 /* */
269 /* */
270 /*---------------------------------------------------------------------------- */
271
272 UWORD16 l1_initialize_download_area_parameters(void)
273 {
274 UWORD16 dwnld_area_size = 0;
275
276 /* Set download address and size in API-DSP com */
277 dyn_dwl_ndb->d_api_dwl_function_address[0] = l1a_apihisr_com.dyn_dwnld.copy_parameters.start_of_dwnld_area;
278 dyn_dwl_ndb->d_api_dwl_function_address[1] = 0x0;
279
280 #if (CODE_VERSION == SIMULATION)
281 dyn_dwl_ndb->d_api_dwl_size = SIZE_DWNLD_AREA_SIMU;
282 #else
283 dyn_dwl_ndb->d_api_dwl_size = l1a_apihisr_com.dyn_dwnld.copy_parameters.size_of_dwnld_area;
284 #endif // CODE_VERSION == SIMULATION
285
286 dwnld_area_size = l1a_apihisr_com.dyn_dwnld.copy_parameters.size_of_dwnld_area;
287 return dwnld_area_size;
288 }
289
290 /*---------------------------------------------------------------------------- */
291 /* l1_init_pointers_and_copy_first_block_of_data */
292 /*---------------------------------------------------------------------------- */
293 /* */
294 /* Parameters : address of size of the patch, address of size of download area,*/
295 /* addresses of source pointer, address of destination pointer */
296 /* new patch flag */
297 /* Return : TRUE if N< size of patch, FALSE otherwise */
298 /* source and destination pointer modified by reference */
299 /* size of download area and patch area modified by reference, */
300 /* */
301 /* Description : Initialize pointers and starts the copy. */
302 /* */
303 /* */
304 /* */
305 /*---------------------------------------------------------------------------- */
306
307 BOOL l1_init_pointers_and_copy_first_block_of_data(UWORD16 *dwnld_area_size_p, UWORD16 *patch_size_p, UWORD16 **pp_dest_mcu, UWORD16 **pp_src_mcu, BOOL new_patch)
308 {
309 BOOL return_flag;
310
311 /* Initialize download area*/
312 *dwnld_area_size_p = l1_initialize_download_area_parameters();
313
314 /* In case this is a new patch, initialize patch parameters*/
315 if (new_patch == TRUE)
316 *patch_size_p = l1_initialize_patch_parameters();
317
318 /* Initialize pointers for the copy*/
319 l1_initialize_pointers_for_copy(pp_dest_mcu, pp_src_mcu);
320
321 /* If this is a new patch, the header of the patch must be taken off from the copy*/
322 if (new_patch == TRUE)
323 {
324 /* Take the initial header off */
325 *pp_src_mcu= (*pp_src_mcu)+HEADER_PATCH_SIZE;
326 *patch_size_p= (*patch_size_p)-HEADER_PATCH_SIZE;
327 }
328
329 /* Copy first N words; if remaining size of the patch is smaller than N copy until the end of the patch */
330 /* In this case, return FALSE as there are no more words to be copied*/
331 return_flag = l1_copy_first_N_words (dwnld_area_size_p, patch_size_p, pp_dest_mcu, pp_src_mcu);
332
333 return return_flag;
334 }
335
336
337 /*---------------------------------------------------------------------------- */
338 /* l1_set_dyn_dwnld_install_vect */
339 /*---------------------------------------------------------------------------- */
340 /* */
341 /* Parameters : size vector, destination address vector, crc vector */
342 /* patch code vector, identifier i of the patch */
343 /* new patch flag */
344 /* Return : TRUE operation is successful, FALSE otherwise */
345 /* */
346 /* Description : Compute address, size and crc of i-th patch */
347 /* */
348 /*---------------------------------------------------------------------------- */
349
350 BOOL l1_set_dyn_dwnld_install_vect(UWORD16* size_p, UWORD32* dest_addr, UWORD16* crc_vect, const UWORD8 *patch_array_code, UWORD16 i)
351 {
352 UWORD16 full_size_32_bit, size, size_ext, dsp_addr, dsp_addr_ext, crc_value;
353 UWORD16 *codePtr;
354 UWORD16 size_total = 0;
355 BOOL status_flag = FALSE;
356 codePtr = (UWORD16 *) patch_array_code;
357
358 if ( (0 == *codePtr++) && (0 == *codePtr++))
359 { // NULL TAG detection
360 if ( (3 == *codePtr++) && (0 == *codePtr++))
361 { // coff2c version number detection
362 size = *codePtr++;
363 size_ext = *codePtr++;
364
365 // first header:4
366 size_total+=HEADER_PATCH_SIZE;
367 while(size != 0 || size_ext != 0)
368 {
369 full_size_32_bit = (size_ext << 16) + size;
370 // reconstruction of the total 32-bit size of the section
371 size_total+=HEADER_PATCH_SIZE+full_size_32_bit+1;
372 // Header + size_block + cntrl_word(0xDEAD):1
373 codePtr+=full_size_32_bit+2+1;
374 // Two words for address and one for the cntrl word 0xDEAD
375 size = *codePtr++;
376 size_ext = *codePtr++;
377 }
378 size_total+=HEADER_PATCH_SIZE;
379 // Last header to consider
380
381 dsp_addr = *codePtr++;
382 dsp_addr_ext = *codePtr++;
383 crc_value = *codePtr++;
384 dest_addr[i] = (dsp_addr_ext << 16)+dsp_addr;
385 crc_vect[i] = crc_value;
386 size_p[i] = size_total;
387 status_flag = TRUE;
388 }
389 }
390 return status_flag;
391 }
392 #endif //L1_DYN_DSP_DWNLD == 1