FreeCalypso > hg > fc-selenite
comparison src/cs/layer1/dyn_dwl_cfile/l1_dyn_dwl_func.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 * 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_memcpy_16bit() */ | |
135 /*--------------------------------------------------------*/ | |
136 /* */ | |
137 /* Description: */ | |
138 /* ------------ */ | |
139 /* This function is equivalemt of memcopy. Thid function */ | |
140 /* does only 8/16 bit accessed to both source and */ | |
141 /* destination */ | |
142 /* */ | |
143 /* Input parameter: */ | |
144 /* --------------- */ | |
145 /* "src" - input pointer */ | |
146 /* "len" - number of bytes to copy */ | |
147 /* */ | |
148 /* Output parameter: */ | |
149 /* ---------------- */ | |
150 /* "dst" - output pointer */ | |
151 /* */ | |
152 /*--------------------------------------------------------*/ | |
153 void l1_memcpy_16bit(void *dst,void* src,unsigned int len) | |
154 { | |
155 unsigned int i; | |
156 unsigned int tempLen; | |
157 unsigned char *cdst,*csrc; | |
158 unsigned short *ssrc,*sdst; | |
159 | |
160 cdst=dst; | |
161 csrc=src; | |
162 sdst=dst; | |
163 ssrc=src; | |
164 | |
165 if(((unsigned int)src&0x01) || ((unsigned int)dst&0x01)){ | |
166 // if either source or destination is not 16-bit aligned do the entire memcopy | |
167 // in 8-bit | |
168 for(i=0;i<len;i++){ | |
169 *cdst++=*csrc++; | |
170 } | |
171 } | |
172 else{ | |
173 // if both the source and destination are 16-bit aligned do the memcopy | |
174 // in 16-bits | |
175 tempLen = len>>1; | |
176 for(i=0;i<tempLen;i++){ | |
177 *sdst++ = *ssrc++; | |
178 } | |
179 if(len & 0x1){ | |
180 // if the caller wanted to copy odd number of bytes do a last 8-bit copy | |
181 cdst=(unsigned char*)sdst; | |
182 csrc=(unsigned char*)ssrc; | |
183 *cdst++ = *csrc++; | |
184 } | |
185 } | |
186 return; | |
187 } | |
188 | |
189 /*---------------------------------------------------------------------------- */ | |
190 /* l1_copy_till_the_end_of_the_patch_and_update_write_pointer */ | |
191 /*---------------------------------------------------------------------------- */ | |
192 /* */ | |
193 /* Parameters : size of the patch, source and destination pointer */ | |
194 /* */ | |
195 /* Return : none */ | |
196 /* */ | |
197 /* Description : Copy until the end of the patch is reached */ | |
198 /* */ | |
199 /* */ | |
200 /*---------------------------------------------------------------------------- */ | |
201 | |
202 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) | |
203 { | |
204 while (tmp_patch_size > NUM_WORDS_COPY_API) | |
205 { | |
206 l1_memcpy_16bit(p_dest_mcu,p_src_mcu, NUM_WORDS_COPY_API*sizeof(UWORD16)); | |
207 p_dest_mcu += NUM_WORDS_COPY_API; | |
208 p_src_mcu += NUM_WORDS_COPY_API; | |
209 tmp_patch_size -= NUM_WORDS_COPY_API; | |
210 dyn_dwl_ndb->d_api_dwl_write_pointer += NUM_WORDS_COPY_API; | |
211 } | |
212 if (tmp_patch_size != 0) | |
213 { | |
214 l1_memcpy_16bit(p_dest_mcu,p_src_mcu, tmp_patch_size*sizeof(UWORD16)); | |
215 dyn_dwl_ndb->d_api_dwl_write_pointer += tmp_patch_size; | |
216 } | |
217 } | |
218 | |
219 /*---------------------------------------------------------------------------- */ | |
220 /* l1_copy_till_end_of_dwnld_area_and_update_write_pointer */ | |
221 /*---------------------------------------------------------------------------- */ | |
222 /* */ | |
223 /* Parameters : address of size of the patch, size of download area, */ | |
224 /* addresses of source pointer, destination pointer */ | |
225 /* */ | |
226 /* Return : source pointer and size modified by reference */ | |
227 /* */ | |
228 /* Description : Copy until the end of download area is reached */ | |
229 /* */ | |
230 /* */ | |
231 /*---------------------------------------------------------------------------- */ | |
232 | |
233 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) | |
234 { | |
235 UWORD16 tmp_patch_size = *p_tmp_patch_size; | |
236 UWORD16 *p_src_mcu = (UWORD16 *)*pp_src_mcu; | |
237 | |
238 while (tmp_dwnld_area_size > NUM_WORDS_COPY_API) | |
239 { | |
240 l1_memcpy_16bit(p_dest_mcu,p_src_mcu, NUM_WORDS_COPY_API*sizeof(UWORD16)); | |
241 p_dest_mcu += NUM_WORDS_COPY_API; | |
242 p_src_mcu += NUM_WORDS_COPY_API; | |
243 tmp_patch_size -= NUM_WORDS_COPY_API; | |
244 tmp_dwnld_area_size -= NUM_WORDS_COPY_API; | |
245 dyn_dwl_ndb->d_api_dwl_write_pointer += NUM_WORDS_COPY_API; | |
246 } | |
247 | |
248 if (tmp_dwnld_area_size > 0) | |
249 { | |
250 l1_memcpy_16bit(p_dest_mcu,p_src_mcu, tmp_dwnld_area_size*sizeof(UWORD16)); | |
251 p_src_mcu += tmp_dwnld_area_size; | |
252 tmp_patch_size -= tmp_dwnld_area_size; | |
253 dyn_dwl_ndb->d_api_dwl_write_pointer += tmp_dwnld_area_size; | |
254 } | |
255 *pp_src_mcu = (UWORD16 *) p_src_mcu; | |
256 *p_tmp_patch_size = tmp_patch_size; | |
257 } | |
258 | |
259 /*---------------------------------------------------------------------------- */ | |
260 /* l1_copy_first_N_words */ | |
261 /*---------------------------------------------------------------------------- */ | |
262 /* */ | |
263 /* Parameters : address of size of the patch, address of size of download area,*/ | |
264 /* addresses of source pointer, address of destination pointer */ | |
265 /* */ | |
266 /* Return : source and destination pointer modified by reference */ | |
267 /* size of download area and patch area modified by reference */ | |
268 /* */ | |
269 /* Description : Copy the min(N, remaining size of the patch) at the beginning */ | |
270 /* download area */ | |
271 /* */ | |
272 /* */ | |
273 /*---------------------------------------------------------------------------- */ | |
274 | |
275 BOOL l1_copy_first_N_words (UWORD16 *dwnld_area_size_p, UWORD16 *patch_area_size_p, UWORD16 **pp_dest_mcu, UWORD16 **pp_src_mcu) | |
276 { | |
277 BOOL return_flag; | |
278 UWORD16 num_words_interrupt; | |
279 UWORD16 tmp_patch_size = *patch_area_size_p; | |
280 UWORD16 tmp_dwnld_area_size = *dwnld_area_size_p; | |
281 UWORD16 *p_dest_mcu =(UWORD16 *)*pp_dest_mcu; | |
282 UWORD16 *p_src_mcu = (UWORD16 *)*pp_src_mcu; | |
283 | |
284 /* Copy first N words and generate API interrupt*/ | |
285 if (tmp_patch_size > NUM_WORDS_COPY_API) | |
286 { | |
287 num_words_interrupt = NUM_WORDS_COPY_API; | |
288 return_flag = TRUE; | |
289 } | |
290 else | |
291 { | |
292 num_words_interrupt = tmp_patch_size; | |
293 return_flag = FALSE; | |
294 } | |
295 | |
296 l1_memcpy_16bit(p_dest_mcu,p_src_mcu, num_words_interrupt*sizeof(UWORD16)); | |
297 | |
298 p_dest_mcu += num_words_interrupt; | |
299 p_src_mcu += num_words_interrupt; | |
300 | |
301 tmp_patch_size -= num_words_interrupt; | |
302 tmp_dwnld_area_size -= num_words_interrupt; | |
303 | |
304 dyn_dwl_ndb->d_api_dwl_write_pointer+=num_words_interrupt; | |
305 | |
306 *patch_area_size_p = tmp_patch_size; | |
307 *dwnld_area_size_p = tmp_dwnld_area_size; | |
308 *pp_dest_mcu = (UWORD16 *)p_dest_mcu; | |
309 *pp_src_mcu = (UWORD16 *)p_src_mcu ; | |
310 | |
311 return return_flag; | |
312 } | |
313 | |
314 /*---------------------------------------------------------------------------- */ | |
315 /* l1_initialize_download_area_parameters */ | |
316 /*---------------------------------------------------------------------------- */ | |
317 /* */ | |
318 /* Parameters : none */ | |
319 /* */ | |
320 /* */ | |
321 /* Return : download area size */ | |
322 /* */ | |
323 /* Description : Initialize download area: all the parameters */ | |
324 /* */ | |
325 /* */ | |
326 /*---------------------------------------------------------------------------- */ | |
327 | |
328 UWORD16 l1_initialize_download_area_parameters(void) | |
329 { | |
330 UWORD16 dwnld_area_size = 0; | |
331 | |
332 /* Set download address and size in API-DSP com */ | |
333 dyn_dwl_ndb->d_api_dwl_function_address[0] = l1a_apihisr_com.dyn_dwnld.copy_parameters.start_of_dwnld_area; | |
334 dyn_dwl_ndb->d_api_dwl_function_address[1] = 0x0; | |
335 | |
336 #if (CODE_VERSION == SIMULATION) | |
337 dyn_dwl_ndb->d_api_dwl_size = SIZE_DWNLD_AREA_SIMU; | |
338 #else | |
339 dyn_dwl_ndb->d_api_dwl_size = l1a_apihisr_com.dyn_dwnld.copy_parameters.size_of_dwnld_area; | |
340 #endif // CODE_VERSION == SIMULATION | |
341 | |
342 dwnld_area_size = l1a_apihisr_com.dyn_dwnld.copy_parameters.size_of_dwnld_area; | |
343 return dwnld_area_size; | |
344 } | |
345 | |
346 /*---------------------------------------------------------------------------- */ | |
347 /* l1_init_pointers_and_copy_first_block_of_data */ | |
348 /*---------------------------------------------------------------------------- */ | |
349 /* */ | |
350 /* Parameters : address of size of the patch, address of size of download area,*/ | |
351 /* addresses of source pointer, address of destination pointer */ | |
352 /* new patch flag */ | |
353 /* Return : TRUE if N< size of patch, FALSE otherwise */ | |
354 /* source and destination pointer modified by reference */ | |
355 /* size of download area and patch area modified by reference, */ | |
356 /* */ | |
357 /* Description : Initialize pointers and starts the copy. */ | |
358 /* */ | |
359 /* */ | |
360 /* */ | |
361 /*---------------------------------------------------------------------------- */ | |
362 | |
363 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) | |
364 { | |
365 BOOL return_flag; | |
366 | |
367 /* Initialize download area*/ | |
368 *dwnld_area_size_p = l1_initialize_download_area_parameters(); | |
369 | |
370 /* In case this is a new patch, initialize patch parameters*/ | |
371 if (new_patch == TRUE) | |
372 *patch_size_p = l1_initialize_patch_parameters(); | |
373 | |
374 /* Initialize pointers for the copy*/ | |
375 l1_initialize_pointers_for_copy(pp_dest_mcu, pp_src_mcu); | |
376 | |
377 /* If this is a new patch, the header of the patch must be taken off from the copy*/ | |
378 if (new_patch == TRUE) | |
379 { | |
380 /* Take the initial header off */ | |
381 *pp_src_mcu= (*pp_src_mcu)+HEADER_PATCH_SIZE; | |
382 *patch_size_p= (*patch_size_p)-HEADER_PATCH_SIZE; | |
383 } | |
384 | |
385 /* Copy first N words; if remaining size of the patch is smaller than N copy until the end of the patch */ | |
386 /* In this case, return FALSE as there are no more words to be copied*/ | |
387 return_flag = l1_copy_first_N_words (dwnld_area_size_p, patch_size_p, pp_dest_mcu, pp_src_mcu); | |
388 | |
389 return return_flag; | |
390 } | |
391 | |
392 | |
393 /*---------------------------------------------------------------------------- */ | |
394 /* l1_set_dyn_dwnld_install_vect */ | |
395 /*---------------------------------------------------------------------------- */ | |
396 /* */ | |
397 /* Parameters : size vector, destination address vector, crc vector */ | |
398 /* patch code vector, identifier i of the patch */ | |
399 /* new patch flag */ | |
400 /* Return : TRUE operation is successful, FALSE otherwise */ | |
401 /* */ | |
402 /* Description : Compute address, size and crc of i-th patch */ | |
403 /* */ | |
404 /*---------------------------------------------------------------------------- */ | |
405 | |
406 BOOL l1_set_dyn_dwnld_install_vect(UWORD16* size_p, UWORD32* dest_addr, UWORD16* crc_vect, const UWORD8 *patch_array_code, UWORD16 i) | |
407 { | |
408 UWORD16 full_size_32_bit, size, size_ext, dsp_addr, dsp_addr_ext, crc_value; | |
409 UWORD16 *codePtr; | |
410 UWORD16 size_total = 0; | |
411 BOOL status_flag = FALSE; | |
412 codePtr = (UWORD16 *) patch_array_code; | |
413 | |
414 if ( (0 == *codePtr++) && (0 == *codePtr++)) | |
415 { // NULL TAG detection | |
416 if ( (3 == *codePtr++) && (0 == *codePtr++)) | |
417 { // coff2c version number detection | |
418 size = *codePtr++; | |
419 size_ext = *codePtr++; | |
420 | |
421 // first header:4 | |
422 size_total+=HEADER_PATCH_SIZE; | |
423 while(size != 0 || size_ext != 0) | |
424 { | |
425 full_size_32_bit = (size_ext << 16) + size; | |
426 // reconstruction of the total 32-bit size of the section | |
427 size_total+=HEADER_PATCH_SIZE+full_size_32_bit+1; | |
428 // Header + size_block + cntrl_word(0xDEAD):1 | |
429 codePtr+=full_size_32_bit+2+1; | |
430 // Two words for address and one for the cntrl word 0xDEAD | |
431 size = *codePtr++; | |
432 size_ext = *codePtr++; | |
433 } | |
434 size_total+=HEADER_PATCH_SIZE; | |
435 // Last header to consider | |
436 | |
437 dsp_addr = *codePtr++; | |
438 dsp_addr_ext = *codePtr++; | |
439 crc_value = *codePtr++; | |
440 dest_addr[i] = (dsp_addr_ext << 16)+dsp_addr; | |
441 crc_vect[i] = crc_value; | |
442 size_p[i] = size_total; | |
443 status_flag = TRUE; | |
444 } | |
445 } | |
446 return status_flag; | |
447 } | |
448 #endif //L1_DYN_DSP_DWNLD == 1 |