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