FreeCalypso > hg > freecalypso-citrine
comparison L1/dyn_dwl_cfile/l1_dyn_dwl_apihisr.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_APIHISR.C | |
4 * | |
5 * Filename l1_dyn_dwl_apihisr.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 "sys_types.h" | |
15 #include "../../riviera/rv/rv_general.h" | |
16 #include "../../nucleus/nucleus.h" | |
17 #include "l1_types.h" | |
18 #include "l1audio_cust.h" | |
19 #include "l1audio_defty.h" | |
20 #include "l1audio_const.h" | |
21 #include "l1_const.h" | |
22 #include "l1tm_defty.h" | |
23 | |
24 #if (L1_GTT == 1) | |
25 #include "l1gtt_const.h" | |
26 #include "l1gtt_defty.h" | |
27 #endif | |
28 | |
29 #if (L1_DYN_DSP_DWNLD == 1) | |
30 #include "l1_dyn_dwl_const.h" | |
31 #include "l1_dyn_dwl_signa.h" | |
32 #include "l1_dyn_dwl_defty.h" | |
33 #include "l1_dyn_dwl_msgty.h" | |
34 #include "l1_dyn_dwl_error.h" | |
35 #include "l1_dyn_dwl_proto.h" | |
36 #include "l1_api_hisr.h" | |
37 #endif | |
38 #if (L1_MP3 == 1) | |
39 #include "l1mp3_defty.h" | |
40 #endif //L1_MP3 | |
41 #if (L1_MIDI == 1) | |
42 #include "l1midi_defty.h" | |
43 #endif | |
44 | |
45 #include "l1_defty.h" | |
46 #include "../../gpf/inc/cust_os.h" | |
47 /* #include "nu_main.h" */ | |
48 #include "l1audio_signa.h" | |
49 #include "l1audio_cust.h" | |
50 #include "l1_varex.h" | |
51 #include "l1_macro.h" | |
52 #include "l1_api_hisr.h" | |
53 #include "l1_trace.h" | |
54 | |
55 #if (L1_DYN_DSP_DWNLD == 1) | |
56 | |
57 /* Dynamic Download NDB API */ | |
58 T_DYN_DWNLD_MCU_DSP *dyn_dwl_ndb; | |
59 | |
60 #if (CODE_VERSION == SIMULATION) | |
61 T_DYN_DWNLD_MCU_DSP dyn_dwl_ndb_sim; | |
62 UWORD16 dwnld_area_array[SIZE_DWNLD_AREA_SIMU]; | |
63 #endif | |
64 | |
65 enum states | |
66 { | |
67 RESET = 0, | |
68 WAIT_UNINSTALL = 1, | |
69 WAIT_DSP_END_BUFFER = 2, | |
70 WAIT_CRC = 3, | |
71 WAIT_INSTALL = 4 | |
72 }; | |
73 /*------------------------------------------------------------------------------------------------------------- */ | |
74 /* l1_dyn_dwnld_copy_patch_process() */ | |
75 /*------------------------------------------------------------------------------------------------------------- */ | |
76 /* */ | |
77 /* Parameters : BOOL new_patch: TRUE if the patch is copied from scratch, FALSE if it has been started so far */ | |
78 /* */ | |
79 /* Return : state in which must be stepped into */ | |
80 /* */ | |
81 /* Description : Performs the copy of the patch and computes next state of corresponding APIHISR state machine */ | |
82 /* */ | |
83 /*------------------------------------------------------------------------------------------------------------- */ | |
84 | |
85 UWORD8 l1_dyn_dwnld_copy_patch_process (BOOL new_patch) | |
86 { | |
87 BOOL still_words_to_be_copied; | |
88 UWORD16 tmp_dwnld_area_size; | |
89 UWORD8 return_state; | |
90 UWORD16 *p_src_mcu = NULL; | |
91 UWORD16 *p_dest_mcu = NULL; | |
92 UWORD16 *tmp_pointer = NULL; | |
93 | |
94 UWORD16 tmp_patch_size = l1_apihisr.dyn_dwnld.tmp_patch_size; | |
95 | |
96 /* Copy first N block of data */ | |
97 still_words_to_be_copied = l1_init_pointers_and_copy_first_block_of_data(&(tmp_dwnld_area_size), &(tmp_patch_size), &(p_dest_mcu), &(p_src_mcu),new_patch); | |
98 | |
99 /* Set download command */ | |
100 dyn_dwl_ndb->d_api_dwl_download_ctrl = (API) C_DWL_DOWNLOAD_CTRL_DOWNLOAD; | |
101 | |
102 #if (CODE_VERSION == SIMULATION) | |
103 l1_trigger_api_interrupt(); | |
104 #endif | |
105 | |
106 /* Check if there are still words to be copied after first API interrupt generation: if not */ | |
107 /* the patch has been completely downloaded and MCU waits for CRC*/ | |
108 if(still_words_to_be_copied == FALSE) | |
109 { | |
110 return_state = WAIT_CRC; | |
111 } | |
112 | |
113 /* If not copy the patch: if download area is bigger than patch size copy until the end of the patch */ | |
114 /* Else copy till the end of buffer download area and wait for DSP interrupt */ | |
115 else | |
116 { | |
117 if (tmp_dwnld_area_size >= tmp_patch_size) | |
118 { | |
119 l1_copy_till_the_end_of_the_patch_and_update_write_pointer(tmp_patch_size,p_dest_mcu,p_src_mcu); | |
120 return_state = WAIT_CRC; | |
121 } | |
122 else | |
123 { | |
124 l1_copy_till_end_of_dwnld_area_and_update_write_pointer(tmp_dwnld_area_size,p_dest_mcu,&tmp_patch_size,&p_src_mcu); | |
125 | |
126 /* Save source patch file pointerand temporary patch size*/ | |
127 l1_apihisr.dyn_dwnld.running_source_pointer = (UWORD32) p_src_mcu; | |
128 l1_apihisr.dyn_dwnld.tmp_patch_size = tmp_patch_size; | |
129 | |
130 /* Change state*/ | |
131 return_state = WAIT_DSP_END_BUFFER; | |
132 } | |
133 } | |
134 return return_state; | |
135 } | |
136 /*-------------------------------------------------------------*/ | |
137 /* l1_dyn_dwnld_apihisr() */ | |
138 /*-------------------------------------------------------------*/ | |
139 /* */ | |
140 /* Parameters : none */ | |
141 /* */ | |
142 /* Return : n/a */ | |
143 /* */ | |
144 /* Description : implements Dynamic Download API HISR */ | |
145 /* */ | |
146 /*-------------------------------------------------------------*/ | |
147 | |
148 void l1_dyn_dwnld_apihisr() | |
149 { | |
150 | |
151 UWORD8 *state = &l1_apihisr.dyn_dwnld.state; | |
152 | |
153 | |
154 /* Variables for copy process */ | |
155 | |
156 xSignalHeaderRec *conf_msg; | |
157 BOOL flag_error; | |
158 | |
159 /* Dynamic Download error handler : check if critical error occured */ | |
160 if( l1_dyn_dwnld_apihisr_error_handler() == TRUE ) | |
161 { | |
162 /* Send notification to L1A */ | |
163 conf_msg = os_alloc_sig(sizeof(T_API_L1_DYN_DWNLD_STOP)); | |
164 DEBUGMSG(status,NU_ALLOC_ERR) | |
165 conf_msg->SignalCode = API_L1_DYN_DWNLD_STOP; | |
166 ((T_API_L1_DYN_DWNLD_STOP *) (conf_msg->SigP))->error = dyn_dwl_ndb->d_api_dwl_error_code; | |
167 dyn_dwl_ndb->d_api_dwl_error_code = C_DWL_ERR_RESET; | |
168 os_send_sig(conf_msg,L1C1_QUEUE); | |
169 DEBUGMSG(status,NU_SEND_QUEUE_ERR) | |
170 | |
171 /* Branch state */ | |
172 *state = RESET; | |
173 flag_error = TRUE; | |
174 return; | |
175 } | |
176 else | |
177 { | |
178 flag_error = FALSE; | |
179 } | |
180 | |
181 /****************/ | |
182 /*STATE MACHINE */ | |
183 /****************/ | |
184 | |
185 while (1){ | |
186 switch(*state) | |
187 { | |
188 /*********/ | |
189 /* RESET */ | |
190 /*********/ | |
191 case RESET: | |
192 { | |
193 /* Check reset init command (if reset by DSP) / Restart in case dynamic download delayed */ | |
194 if ( dyn_dwl_ndb->d_api_dwl_download_ctrl == (API) C_DWL_DOWNLOAD_CTRL_DSP_ACK || | |
195 l1a_apihisr_com.dyn_dwnld.command.restart == TRUE) | |
196 { | |
197 if (flag_error == FALSE) | |
198 { | |
199 | |
200 /* Send confirmation to L1A */ | |
201 conf_msg = os_alloc_sig(0); | |
202 DEBUGMSG(status,NU_ALLOC_ERR) | |
203 conf_msg->SignalCode = API_L1_DYN_DWNLD_START_CON; | |
204 os_send_sig(conf_msg,L1C1_QUEUE); | |
205 DEBUGMSG(status,NU_SEND_QUEUE_ERR) | |
206 | |
207 /* Store patch IDs to install counter in global API */ | |
208 l1_apihisr.dyn_dwnld.patch_ids_counter = l1a_apihisr_com.dyn_dwnld.copy_parameters.num_of_elem; | |
209 | |
210 /* Reset command */ | |
211 l1a_apihisr_com.dyn_dwnld.command.restart = FALSE; | |
212 | |
213 /* Test if number of uninstall elements is greater than zero */ | |
214 if ( l1a_apihisr_com.dyn_dwnld.uninstall_parameters.num_of_elem > 0 ) | |
215 { | |
216 /* Copy num of elem L1A-API variable counter into global uninstall counter */ | |
217 l1_apihisr.dyn_dwnld.uninstall_counter = l1a_apihisr_com.dyn_dwnld.uninstall_parameters.num_of_elem; | |
218 | |
219 l1_set_uninstall_parameters(); | |
220 | |
221 #if (CODE_VERSION == SIMULATION) | |
222 l1_trigger_api_interrupt(); | |
223 #endif | |
224 | |
225 /* Change state */ | |
226 *state = WAIT_UNINSTALL; | |
227 } | |
228 else /* No elements to uninstall*/ | |
229 { | |
230 /* Reset patch size */ | |
231 l1_apihisr.dyn_dwnld.tmp_patch_size = 0; | |
232 | |
233 /* Copy the patch and update current state*/ | |
234 *state = l1_dyn_dwnld_copy_patch_process(TRUE); | |
235 | |
236 } | |
237 } | |
238 } | |
239 return; | |
240 } /* end case RESET */ | |
241 //omaps00090550 break; | |
242 | |
243 /******************/ | |
244 /* WAIT_UNINSTALL */ | |
245 /******************/ | |
246 case WAIT_UNINSTALL: | |
247 { | |
248 /* Check uninstall command (if reset by DSP) */ | |
249 if ( dyn_dwl_ndb->d_api_dwl_download_ctrl == (API) C_DWL_DOWNLOAD_CTRL_DSP_ACK ) | |
250 { | |
251 /* Decrement uninstall counter */ | |
252 l1_apihisr.dyn_dwnld.uninstall_counter--; | |
253 | |
254 /* Check uninstall counter: if it is 0 no more uninstall to perform*/ | |
255 if ( l1_apihisr.dyn_dwnld.uninstall_counter == 0 ) | |
256 { | |
257 /* Send confirmation to L1A */ | |
258 conf_msg = os_alloc_sig(0); | |
259 DEBUGMSG(status,NU_ALLOC_ERR) | |
260 conf_msg->SignalCode = API_L1_DYN_DWNLD_UNINST_OK; | |
261 os_send_sig(conf_msg,L1C1_QUEUE); | |
262 DEBUGMSG(status,NU_SEND_QUEUE_ERR) | |
263 | |
264 /* Reset patch size */ | |
265 l1_apihisr.dyn_dwnld.tmp_patch_size = 0; | |
266 | |
267 /* Copy the patch and update current state*/ | |
268 *state = l1_dyn_dwnld_copy_patch_process(TRUE); | |
269 } | |
270 else /* there are some uninstall to perform */ | |
271 { | |
272 l1_set_uninstall_parameters(); | |
273 | |
274 #if (CODE_VERSION == SIMULATION) | |
275 l1_trigger_api_interrupt(); | |
276 #endif | |
277 } | |
278 } | |
279 return; | |
280 } /* end case WAIT_UNINSTALL */ | |
281 //omaps00090550 break; | |
282 | |
283 /***********************/ | |
284 /* WAIT_DSP_END_BUFFER */ | |
285 /***********************/ | |
286 case WAIT_DSP_END_BUFFER: | |
287 { | |
288 if ( dyn_dwl_ndb->d_api_dwl_download_ctrl == (API) C_DWL_DOWNLOAD_CTRL_DSP_ACK ) | |
289 { | |
290 /* Copy the patch and update current state*/ | |
291 *state = l1_dyn_dwnld_copy_patch_process(FALSE); | |
292 } | |
293 return; | |
294 } /* end case WAIT_DSP_END_BUFFER */ | |
295 //omaps00090550 break; | |
296 | |
297 /************/ | |
298 /* WAIT_CRC */ | |
299 /************/ | |
300 case WAIT_CRC: | |
301 { | |
302 /* Check if DSP install command is reset */ | |
303 if (dyn_dwl_ndb->d_api_dwl_download_ctrl == (API) C_DWL_DOWNLOAD_CTRL_DSP_ACK ) | |
304 { | |
305 /* Test if CRC is OK */ | |
306 if ( dyn_dwl_ndb->d_api_dwl_crc != l1a_apihisr_com.dyn_dwnld.copy_parameters.crc[l1a_apihisr_com.dyn_dwnld.copy_parameters.num_of_elem-l1_apihisr.dyn_dwnld.patch_ids_counter]) /* CRC not OK */ | |
307 { | |
308 /* Send notification to L1A */ | |
309 conf_msg = os_alloc_sig(sizeof(T_API_L1_CRC_NOT_OK)); | |
310 DEBUGMSG(status,NU_ALLOC_ERR) | |
311 conf_msg->SignalCode = API_L1_CRC_NOT_OK; | |
312 ((T_API_L1_CRC_NOT_OK *) (conf_msg->SigP))->patch_id = dyn_dwl_ndb->d_api_dwl_crc; | |
313 os_send_sig(conf_msg,L1C1_QUEUE); | |
314 DEBUGMSG(status,NU_SEND_QUEUE_ERR) | |
315 | |
316 /* Change state */ | |
317 *state = RESET; | |
318 } | |
319 else /* CRC OK */ | |
320 { | |
321 conf_msg = os_alloc_sig(sizeof(T_API_L1_CRC_NOT_OK)); | |
322 DEBUGMSG(status,NU_ALLOC_ERR) | |
323 conf_msg->SignalCode = API_L1_CRC_OK; | |
324 ((T_API_L1_CRC_NOT_OK *) (conf_msg->SigP))->patch_id = l1a_apihisr_com.dyn_dwnld.copy_parameters.crc[l1a_apihisr_com.dyn_dwnld.copy_parameters.num_of_elem-l1_apihisr.dyn_dwnld.patch_ids_counter]; | |
325 os_send_sig(conf_msg,L1C1_QUEUE); | |
326 DEBUGMSG(status,NU_SEND_QUEUE_ERR) | |
327 *state = WAIT_INSTALL; | |
328 | |
329 /* Set install parameters */ | |
330 | |
331 dyn_dwl_ndb->d_api_dwl_function_address[0] = | |
332 (API) (l1a_apihisr_com.dyn_dwnld.copy_parameters.address_to_install[l1a_apihisr_com.dyn_dwnld.copy_parameters.num_of_elem-l1_apihisr.dyn_dwnld.patch_ids_counter] & 0x0000FFFF); | |
333 dyn_dwl_ndb->d_api_dwl_function_address[1] = | |
334 (API) ((l1a_apihisr_com.dyn_dwnld.copy_parameters.address_to_install[l1a_apihisr_com.dyn_dwnld.copy_parameters.num_of_elem-l1_apihisr.dyn_dwnld.patch_ids_counter] >> 16) & 0x0000FFFF); | |
335 | |
336 dyn_dwl_ndb->d_api_dwl_download_ctrl = (API) C_DWL_DOWNLOAD_CTRL_INSTALL; | |
337 | |
338 #if (CODE_VERSION == SIMULATION) | |
339 l1_trigger_api_interrupt(); | |
340 #endif | |
341 } | |
342 } | |
343 return; | |
344 } /* end case WAIT_CRC */ | |
345 //omaps00090550 break; | |
346 | |
347 /****************/ | |
348 /* WAIT_INSTALL */ | |
349 /****************/ | |
350 case WAIT_INSTALL: | |
351 { | |
352 /* Check if DSP install command is reset */ | |
353 if (dyn_dwl_ndb->d_api_dwl_download_ctrl == (API) C_DWL_DOWNLOAD_CTRL_DSP_ACK ) | |
354 { | |
355 /* Decrement patch counter */ | |
356 l1_apihisr.dyn_dwnld.patch_ids_counter--; | |
357 | |
358 /* Test if patch counter is null */ | |
359 if ( l1_apihisr.dyn_dwnld.patch_ids_counter == 0 ) | |
360 { | |
361 /* Send notification to L1A */ | |
362 conf_msg = os_alloc_sig(0); | |
363 DEBUGMSG(status,NU_ALLOC_ERR) | |
364 conf_msg->SignalCode = API_L1_DYN_DWNLD_FINISHED; | |
365 os_send_sig(conf_msg,L1C1_QUEUE); | |
366 DEBUGMSG(status,NU_SEND_QUEUE_ERR) | |
367 *state = RESET; | |
368 } | |
369 else | |
370 { | |
371 /* Reset patch size */ | |
372 l1_apihisr.dyn_dwnld.tmp_patch_size = 0; | |
373 | |
374 /* Copy the patch and update current state*/ | |
375 *state = l1_dyn_dwnld_copy_patch_process(TRUE); | |
376 } | |
377 } | |
378 return; | |
379 } /* end case WAIT_INSTALL */ | |
380 //omaps00090550 break; | |
381 } /* end switch */ | |
382 } /* end while */ | |
383 } | |
384 | |
385 /*-------------------------------------------------------------*/ | |
386 /* l1_dyn_dwnld_apihisr_error_handler() */ | |
387 /*-------------------------------------------------------------*/ | |
388 /* */ | |
389 /* Parameters : error_code (OUT) error_code received from DSP */ | |
390 /* */ | |
391 /* Return : TRUE if errors signaled by DSP */ | |
392 /* */ | |
393 /*-------------------------------------------------------------*/ | |
394 BOOL l1_dyn_dwnld_apihisr_error_handler() | |
395 { | |
396 BOOL critical; | |
397 | |
398 /* Initialisation */ | |
399 critical = FALSE; | |
400 | |
401 if(dyn_dwl_ndb->d_api_dwl_error_code != 0) | |
402 { | |
403 critical = TRUE; | |
404 } | |
405 | |
406 return critical; | |
407 } | |
408 | |
409 | |
410 #endif /* L1_DYN_DSP_DWNLD */ | |
411 |