FreeCalypso > hg > freecalypso-citrine
comparison services/dar/dar_emergency.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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:75a11d740a02 |
---|---|
1 /****************************************************************************/ | |
2 /* */ | |
3 /* File Name: dar_emergency.c */ | |
4 /* */ | |
5 /* Purpose: This function is called when the DAR entity has detected */ | |
6 /* an emergency ( Error or exception) */ | |
7 /* */ | |
8 /* */ | |
9 /* Version 0.1 */ | |
10 /* */ | |
11 /* Date Modification */ | |
12 /* ------------------------------------ */ | |
13 /* 17 October 2001 Create */ | |
14 /* */ | |
15 /* Author Stephanie Gerthoux */ | |
16 /* */ | |
17 /* (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved*/ | |
18 /****************************************************************************/ | |
19 | |
20 #include "../../riviera/rv/rv_defined_swe.h" | |
21 #ifdef RVM_DAR_SWE | |
22 /* ************************************************ */ | |
23 /* THE DAR ENTITY IS ENABLED */ | |
24 /* ************************************************ */ | |
25 | |
26 #include <string.h> | |
27 #include "../../riviera/rvm/rvm_gen.h" | |
28 #include "dar_api.h" | |
29 #include "dar_macro_i.h" | |
30 #include "dar_messages_i.h" | |
31 #include "dar_const_i.h" | |
32 #include "dar_diagnose_i.h" | |
33 #include "dar_msg_ft.h" | |
34 | |
35 #ifndef _WINDOWS | |
36 #include "../../bsp/timer.h" | |
37 #endif | |
38 | |
39 /**** Global variable ****/ | |
40 /* index used in the circular buffer*/ | |
41 extern UINT16 dar_current_index; | |
42 | |
43 /* Write buffer*/ | |
44 extern char dar_write_buffer[DAR_MAX_BUFFER_SIZE]; | |
45 | |
46 /* Get the dar current status */ | |
47 extern T_DAR_RECOVERY_STATUS dar_current_status; | |
48 | |
49 /* Get the dar exception status */ | |
50 extern UINT8 dar_exception_status; | |
51 | |
52 /* Define a pointer to the Global Environment Control block */ | |
53 extern T_DAR_ENV_CTRL_BLK *dar_gbl_var_p; | |
54 | |
55 /* Define the recovery buffer */ | |
56 extern UINT8 dar_recovery_buffer[DAR_RECOVERY_DATA_MAX_BUFFER_SIZE]; | |
57 | |
58 /* Ram buffer that contains the Debug Unit register */ | |
59 extern UINT32 debug_RAM[DEBUG_UNIT_WORD_SIZE]; | |
60 | |
61 | |
62 /**** Extern functions ****/ | |
63 extern void * dar_read_mbox (UINT8 mbox); | |
64 | |
65 | |
66 /***************************************************************************/ | |
67 /* */ | |
68 /* Function Name: dar_process_emergency */ | |
69 /* */ | |
70 /* Purpose: This function is called to process emergency data and to */ | |
71 /* store them in RAM buffer when an emergency has been */ | |
72 /* detected. */ | |
73 /* */ | |
74 /* Input Parameters: */ | |
75 /* Pointer to the message to store */ | |
76 /* Data Format, ( the Binary format is not supported) */ | |
77 /* Data Use Id, */ | |
78 /* Flags */ | |
79 /* */ | |
80 /* Output Parameters: */ | |
81 /* Validation of the diagnose execution. */ | |
82 /* */ | |
83 /* */ | |
84 /* */ | |
85 /* Revision History: */ | |
86 /* None. */ | |
87 /* */ | |
88 /***************************************************************************/ | |
89 T_RV_RET dar_process_emergency( T_DAR_INFO *buffer_p, | |
90 T_DAR_FORMAT format, | |
91 T_RVM_USE_ID dar_use_id, | |
92 UINT32 flags) | |
93 { | |
94 /* Declare local variables */ | |
95 UINT32 i = 0; | |
96 UINT32 length = 0; | |
97 T_RV_HDR *msg_p = ( T_RV_HDR*) dar_read_mbox(DAR_MBOX); | |
98 | |
99 /**** Update the DAR recovery status ****/ | |
100 dar_current_status = DAR_EMERGENCY_SCUTTLING; | |
101 | |
102 /**** Empty the mail box before the reset of the system ****/ | |
103 while(msg_p != NULL) | |
104 { | |
105 /* If it's a Write message, store it in the RAM */ | |
106 /* ( it is not interesting to store filter message ) */ | |
107 if ((msg_p->msg_id) == DAR_WRITE_REQ) | |
108 { | |
109 /* store the message in the RAM*/ | |
110 dar_write_data_in_buffer((T_DAR_WRITE_START *)msg_p); | |
111 } | |
112 | |
113 /* free the Header of the message */ | |
114 rvf_free_buf((T_RVF_BUFFER *) msg_p); | |
115 | |
116 /* Read the next message */ | |
117 msg_p = ( T_RV_HDR*) dar_read_mbox(DAR_MBOX); | |
118 | |
119 } /* while (msg_p != NULL) */ | |
120 | |
121 /**** Store emergency data in RAM buffer ****/ | |
122 /* Diagnose string length */ | |
123 length = (UINT16) strlen(buffer_p); | |
124 | |
125 /**** Check if the DAR entity is started ****/ | |
126 if (dar_gbl_var_p != NULL ) | |
127 { | |
128 /* Data format */ | |
129 dar_gbl_var_p->format = format; | |
130 } | |
131 | |
132 if ( flags & DAR_NEW_ENTRY ) | |
133 { | |
134 /** Circular buffer to store data **/ | |
135 /* Add 0xFF to separate 2 strings */ | |
136 dar_write_buffer[dar_current_index] = 0xF; | |
137 DAR_PLUS_PLUS(dar_current_index); /* increment with wraparound */ | |
138 dar_write_buffer[dar_current_index] = 0xF; | |
139 DAR_PLUS_PLUS(dar_current_index); /* increment with wraparound */ | |
140 | |
141 /* The group_nb is 16 bit length, and the buffer is an UINT8 length */ | |
142 /* So the group_nb must be stocked by dividing it in 2 parts */ | |
143 dar_write_buffer[dar_current_index] = ((dar_use_id>>16)& 0x7FFF)>>8; | |
144 /*add the 8 first bits of the Use id group*/ | |
145 DAR_PLUS_PLUS(dar_current_index); | |
146 dar_write_buffer[dar_current_index] = (dar_use_id>>16)& 0x7FFF; | |
147 /*add the 8 last bits of the Use id group*/ | |
148 DAR_PLUS_PLUS(dar_current_index); | |
149 | |
150 /* The mask is 16 bit length, and the buffer is an UINT8 length */ | |
151 /* So the mask must be stocked by dividing it in 2 parts */ | |
152 dar_write_buffer[dar_current_index] = ((dar_use_id)&0xFFFF)>>8; | |
153 /* add the 8 first bits of the Use id mask */ | |
154 DAR_PLUS_PLUS(dar_current_index); | |
155 dar_write_buffer[dar_current_index] = (dar_use_id)&0xFFFF; | |
156 /* add the 8 last bits of the Use id mask */ | |
157 DAR_PLUS_PLUS(dar_current_index); | |
158 | |
159 /* Add the dar_level data */ | |
160 dar_write_buffer[dar_current_index] = DAR_ERROR; | |
161 DAR_PLUS_PLUS(dar_current_index); | |
162 } | |
163 | |
164 /* circular buffer to store diagnose data in RAM buffer */ | |
165 for (i=0; i < length; i++ ) | |
166 { | |
167 /* copy string in the RAM char by char*/ | |
168 dar_write_buffer[dar_current_index]=buffer_p[i]; | |
169 | |
170 /* detection of the end of the buffer */ | |
171 /* When current = DAR_MAX_BUFFER_SIZE , current = 0 */ | |
172 DAR_PLUS_PLUS(dar_current_index); | |
173 } | |
174 | |
175 /* DAR information is redirected to standard trace */ | |
176 //DAR_SEND_TRACE("Circular buffer :",RV_TRACE_LEVEL_ERROR); | |
177 //rvf_send_trace(buffer_p, length, NULL_PARAM, RV_TRACE_LEVEL_ERROR, DAR_USE_ID); | |
178 | |
179 /* Trace the buffer (used for debug) */ | |
180 rvf_delay(RVF_MS_TO_TICKS(1000)); | |
181 | |
182 | |
183 /**** Check if the DAR entity is started ****/ | |
184 if (dar_gbl_var_p != NULL ) | |
185 { | |
186 if (dar_gbl_var_p->entity_dar_callback != NULL ) | |
187 { | |
188 /* Call the MMI callback function to save some parameters before | |
189 reset */ | |
190 dar_gbl_var_p->entity_dar_callback(dar_recovery_buffer, | |
191 DAR_RECOVERY_DATA_MAX_BUFFER_SIZE); | |
192 } | |
193 } | |
194 | |
195 /* The system is reset if requested */ | |
196 if ( flags & DAR_EMERGENCY_RESET ) | |
197 { | |
198 dar_reset(); | |
199 } | |
200 return(RV_OK); | |
201 | |
202 } /* dar_process_emergency */ | |
203 | |
204 | |
205 /***************************************************************************/ | |
206 /* */ | |
207 /* Function Name: dar_exception_arm_undefined */ | |
208 /* */ | |
209 /* Purpose: This function is called to process ARM undefined */ | |
210 /* instruction exception and to store this exception in the */ | |
211 /* RAM buffer. */ | |
212 /* */ | |
213 /* Input Parameters: */ | |
214 /* None */ | |
215 /* */ | |
216 /* Output Parameters: */ | |
217 /* Validation of the diagnose execution. */ | |
218 /* */ | |
219 /* */ | |
220 /* */ | |
221 /* Revision History: */ | |
222 /* None. */ | |
223 /* */ | |
224 /***************************************************************************/ | |
225 void dar_exception_arm_undefined(void) | |
226 { | |
227 /* Declare local variables */ | |
228 T_DAR_INFO *buffer_p= " DAR Emergency exception : ARM undefined ";/*exception data to store*/ | |
229 | |
230 /* Update the DAR recovery status */ | |
231 dar_current_status = DAR_EMERGENCY_SCUTTLING; | |
232 | |
233 /* Update the DAR exception status */ | |
234 dar_exception_status = DAR_EXCEPTION_UNDEFINED; | |
235 | |
236 /* Empty the mail box and store data in RAM buffer */ | |
237 dar_empty_mb_and_save_data(buffer_p); | |
238 | |
239 /* Check if the DAR entity is started */ | |
240 if (dar_gbl_var_p != NULL ) | |
241 { | |
242 if (dar_gbl_var_p->entity_dar_callback != NULL) | |
243 { | |
244 /* Call the MMI callback function to save some parameters before | |
245 reset */ | |
246 dar_gbl_var_p->entity_dar_callback(dar_recovery_buffer, | |
247 DAR_RECOVERY_DATA_MAX_BUFFER_SIZE); | |
248 } | |
249 } | |
250 | |
251 dar_reset(); | |
252 | |
253 } /* dar_exception_arm_undefined */ | |
254 | |
255 /***************************************************************************/ | |
256 /* */ | |
257 /* Function Name: dar_exception_arm_swi */ | |
258 /* */ | |
259 /* Purpose: This function is called to process ARM SW Interrupt */ | |
260 /* exception and to store this exception in the RAM buffer. */ | |
261 /* */ | |
262 /* Input Parameters: */ | |
263 /* None */ | |
264 /* */ | |
265 /* Output Parameters: */ | |
266 /* Validation of the diagnose execution. */ | |
267 /* */ | |
268 /* */ | |
269 /* */ | |
270 /* Revision History: */ | |
271 /* None. */ | |
272 /* */ | |
273 /***************************************************************************/ | |
274 void dar_exception_arm_swi(void) | |
275 { | |
276 /* Declare local variables */ | |
277 T_DAR_INFO *buffer_p= " DAR Emergency exception : ARM SWI ";/*exception data to store*/ | |
278 | |
279 /* Update the DAR recovery status */ | |
280 dar_current_status = DAR_EMERGENCY_SCUTTLING; | |
281 | |
282 /* Update the DAR exception status */ | |
283 dar_exception_status = DAR_EXCEPTION_SWI; | |
284 | |
285 /* Empty the mail box and store data in RAM buffer */ | |
286 dar_empty_mb_and_save_data(buffer_p); | |
287 | |
288 /* Check if the DAR entity is started */ | |
289 if (dar_gbl_var_p != NULL ) | |
290 { | |
291 if ( dar_gbl_var_p->entity_dar_callback != NULL) | |
292 { | |
293 /* Call the MMI callback function to save some parameters before | |
294 reset */ | |
295 dar_gbl_var_p->entity_dar_callback(dar_recovery_buffer, | |
296 DAR_RECOVERY_DATA_MAX_BUFFER_SIZE); | |
297 } | |
298 } | |
299 | |
300 dar_reset(); | |
301 | |
302 } /* dar_exception_arm_swi */ | |
303 | |
304 /***************************************************************************/ | |
305 /* */ | |
306 /* Function Name: dar_exception_arm_abort_prefetch */ | |
307 /* */ | |
308 /* Purpose: This function is called to process ARM abort prefetch */ | |
309 /* exception and to store this exception in the RAM buffer. */ | |
310 /* */ | |
311 /* Input Parameters: */ | |
312 /* None */ | |
313 /* */ | |
314 /* Output Parameters: */ | |
315 /* Validation of the diagnose execution. */ | |
316 /* */ | |
317 /* */ | |
318 /* */ | |
319 /* Revision History: */ | |
320 /* None. */ | |
321 /* */ | |
322 /***************************************************************************/ | |
323 void dar_exception_arm_abort_prefetch(void) | |
324 { | |
325 #ifndef _WINDOWS | |
326 /* Local variable */ | |
327 UINT8 i; | |
328 #endif | |
329 | |
330 #if ((CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 10) || \ | |
331 (CHIPSET == 11) || (CHIPSET == 12)) | |
332 /* Debug unit pointer */ | |
333 volatile UINT32 *debug_register_p; | |
334 #endif | |
335 | |
336 /* Declare local variables */ | |
337 T_DAR_INFO *buffer_p = " DAR Emergency exception : ARM abort prefetch";/*exception data to store*/ | |
338 | |
339 /* Update the DAR recovery status */ | |
340 dar_current_status = DAR_EMERGENCY_SCUTTLING; | |
341 | |
342 /* Update the DAR exception status */ | |
343 dar_exception_status = DAR_EXCEPTION_PREFETCH_ABORT; | |
344 | |
345 /* Empty the mail box and store data in RAM buffer */ | |
346 dar_empty_mb_and_save_data(buffer_p); | |
347 | |
348 /* Check if the DAR entity is started */ | |
349 if (dar_gbl_var_p != NULL ) | |
350 { | |
351 if (dar_gbl_var_p->entity_dar_callback != NULL) | |
352 { | |
353 /* Call the MMI callback function to save some parameters before | |
354 reset */ | |
355 dar_gbl_var_p->entity_dar_callback(dar_recovery_buffer, | |
356 DAR_RECOVERY_DATA_MAX_BUFFER_SIZE); | |
357 } | |
358 } | |
359 | |
360 #if ((CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 10) || \ | |
361 (CHIPSET == 11) || (CHIPSET == 12)) | |
362 /* Initialize the adress of the Debug Unit pointer */ | |
363 debug_register_p = (volatile UINT32*) DAR_DEBUG_UNIT_REGISTER; | |
364 #endif | |
365 | |
366 #ifndef _WINDOWS | |
367 #if ((CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 10) || \ | |
368 (CHIPSET == 11) || (CHIPSET == 12)) | |
369 /* Save the Debug Unit into the RAM */ | |
370 for (i=0; i<DEBUG_UNIT_WORD_SIZE; i++ ) | |
371 { | |
372 debug_RAM[i] = *debug_register_p; | |
373 debug_register_p++; | |
374 } | |
375 #endif | |
376 | |
377 dar_reset(); | |
378 #endif | |
379 | |
380 } /* dar_exception_arm_abort_prefetch */ | |
381 | |
382 /***************************************************************************/ | |
383 /* */ | |
384 /* Function Name: dar_exception_arm_abort_data */ | |
385 /* */ | |
386 /* Purpose: This function is called to process ARM abort data exception*/ | |
387 /* and to store this exception in the RAM buffer */ | |
388 /* */ | |
389 /* Input Parameters: */ | |
390 /* None */ | |
391 /* */ | |
392 /* Output Parameters: */ | |
393 /* Validation of the diagnose execution. */ | |
394 /* */ | |
395 /* */ | |
396 /* */ | |
397 /* Revision History: */ | |
398 /* None. */ | |
399 /* */ | |
400 /***************************************************************************/ | |
401 void dar_exception_arm_abort_data(void) | |
402 { | |
403 #ifndef _WINDOWS | |
404 /* Local variable */ | |
405 UINT8 i; | |
406 #endif | |
407 | |
408 #if ((CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 10) || \ | |
409 (CHIPSET == 11) || (CHIPSET == 12)) | |
410 /* Debug unit pointer */ | |
411 volatile UINT32 *debug_register_p; | |
412 #endif | |
413 | |
414 /* Declare local variables */ | |
415 T_DAR_INFO *buffer_p= " DAR Emergency exception : ARM abort data";/*exception data to store*/ | |
416 | |
417 /* Update the DAR recovery status */ | |
418 dar_current_status = DAR_EMERGENCY_SCUTTLING; | |
419 | |
420 /* Update the DAR exception status */ | |
421 dar_exception_status = DAR_EXCEPTION_DATA_ABORT; | |
422 | |
423 /* Empty the mail box and store data in RAM buffer */ | |
424 dar_empty_mb_and_save_data(buffer_p); | |
425 | |
426 /* Check if the DAR entity is started */ | |
427 if (dar_gbl_var_p != NULL ) | |
428 { | |
429 if (dar_gbl_var_p->entity_dar_callback != NULL) | |
430 { | |
431 | |
432 /* Call the MMI callback function to save some parameters before | |
433 reset */ | |
434 dar_gbl_var_p->entity_dar_callback(dar_recovery_buffer, | |
435 DAR_RECOVERY_DATA_MAX_BUFFER_SIZE); | |
436 } | |
437 } | |
438 | |
439 #if ((CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 10) || \ | |
440 (CHIPSET == 11) || (CHIPSET == 12)) | |
441 /* Initialize the adress of the Debug Unit pointer */ | |
442 debug_register_p = (volatile UINT32*) DAR_DEBUG_UNIT_REGISTER; | |
443 #endif | |
444 | |
445 #ifndef _WINDOWS | |
446 #if ((CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 10) || \ | |
447 (CHIPSET == 11) || (CHIPSET == 12)) | |
448 /* Save the Debug Unit into the RAM */ | |
449 for (i=0; i<DEBUG_UNIT_WORD_SIZE; i++ ) | |
450 { | |
451 debug_RAM[i] = *debug_register_p; | |
452 debug_register_p++; | |
453 } | |
454 #endif | |
455 | |
456 dar_reset(); | |
457 #endif | |
458 | |
459 } /* dar_exception_arm_abort_data */ | |
460 | |
461 /***************************************************************************/ | |
462 /* */ | |
463 /* Function Name: dar_exception_arm_reserved */ | |
464 /* */ | |
465 /* Purpose: This function is called to process ARM exception */ | |
466 /* and to store this exception in the RAM buffer */ | |
467 /* */ | |
468 /* Input Parameters: */ | |
469 /* None */ | |
470 /* */ | |
471 /* Output Parameters: */ | |
472 /* Validation of the diagnose execution. */ | |
473 /* */ | |
474 /* */ | |
475 /* */ | |
476 /* Revision History: */ | |
477 /* None. */ | |
478 /* */ | |
479 /***************************************************************************/ | |
480 void dar_exception_arm_reserved(void) | |
481 { | |
482 /* Declare local variables */ | |
483 T_DAR_INFO *buffer_p= " DAR Emergency exception : ARM reserved";/*exception data to store*/ | |
484 | |
485 /* Update the DAR recovery status */ | |
486 dar_current_status = DAR_EMERGENCY_SCUTTLING; | |
487 | |
488 /* Update the DAR exception status */ | |
489 dar_exception_status = DAR_EXCEPTION_RESERVED; | |
490 | |
491 /* Empty the mail box and store data in RAM buffer */ | |
492 dar_empty_mb_and_save_data(buffer_p); | |
493 | |
494 /* Check if the DAR entity is started */ | |
495 if (dar_gbl_var_p != NULL ) | |
496 { | |
497 if (dar_gbl_var_p->entity_dar_callback != NULL) | |
498 { | |
499 /* Call the MMI callback function to save some parameters before | |
500 reset */ | |
501 dar_gbl_var_p->entity_dar_callback(dar_recovery_buffer, | |
502 DAR_RECOVERY_DATA_MAX_BUFFER_SIZE); | |
503 } | |
504 } | |
505 | |
506 dar_reset(); | |
507 | |
508 } /* dar_exception_arm_reserved */ | |
509 | |
510 /****************************************************************************/ | |
511 /* */ | |
512 /* Function Name: dar_exception */ | |
513 /* */ | |
514 /* Purpose: This function is called to vector exceptions to the correct */ | |
515 /* handler */ | |
516 /* */ | |
517 /* Input Parameters: */ | |
518 /* abort type which come from int.s ( -> magic number) */ | |
519 /* */ | |
520 /* Output Parameters: */ | |
521 /* Validation of the diagnose execution. */ | |
522 /* */ | |
523 /* */ | |
524 /* */ | |
525 /* Revision History: */ | |
526 /* None. */ | |
527 /* */ | |
528 /****************************************************************************/ | |
529 void dar_exception(int abort_type) | |
530 { | |
531 switch (abort_type) | |
532 { | |
533 /* magic numbers come from int.s There is no way to make compiler | |
534 * derived constants out of them | |
535 */ | |
536 case 1: | |
537 dar_exception_arm_undefined(); | |
538 break; | |
539 case 2: | |
540 dar_exception_arm_swi(); | |
541 break; | |
542 case 3: | |
543 dar_exception_arm_abort_prefetch(); | |
544 break; | |
545 case 4: | |
546 dar_exception_arm_abort_data(); | |
547 break; | |
548 case 5: | |
549 dar_exception_arm_reserved(); | |
550 break; | |
551 } | |
552 } /* dar_exception */ | |
553 | |
554 #else | |
555 /* ************************************************ */ | |
556 /* THE DAR ENTITY IS DISABLED */ | |
557 /* ************************************************ */ | |
558 | |
559 void dar_exception(int abort_type) | |
560 { | |
561 static char msg[] = "*ARM EXCEPTION #?"; | |
562 | |
563 if (abort_type >= 0 && abort_type <= 9) | |
564 msg[16] = abort_type + '0'; | |
565 freecalypso_raw_dbgout(msg); | |
566 while (1) | |
567 ; | |
568 } /* dar_exception */ | |
569 | |
570 #endif /* #ifdef RVM_DAR_SWE */ |