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