comparison src/gpf/frame/vsi_trc.c @ 5:1ea54a97e831

src/gpf: import of Magnetite src/gpf3
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 08:11:07 +0000
parents
children
comparison
equal deleted inserted replaced
4:6e457872f745 5:1ea54a97e831
1 /*
2 +------------------------------------------------------------------------------
3 | File: vsi_trc.c
4 +------------------------------------------------------------------------------
5 | Copyright 2002 Texas Instruments Berlin, AG
6 | All rights reserved.
7 |
8 | This file is confidential and a trade secret of Texas
9 | Instruments Berlin, AG
10 | The receipt of or possession of this file does not convey
11 | any rights to reproduce or disclose its contents or to
12 | manufacture, use, or sell anything it may describe, in
13 | whole, or in part, without the specific written consent of
14 | Texas Instruments Berlin, AG.
15 +-----------------------------------------------------------------------------
16 | Purpose : This Module defines the virtual system interface part
17 | for the tracing functionality.
18 +-----------------------------------------------------------------------------
19 */
20
21 #ifndef __VSI_TRC_C__
22 #define __VSI_TRC_C__
23 #endif
24
25 #undef TEST_EXT_TRACE
26
27 /*==== LINT =======================================================*/
28
29 /*lint -emacro(506,va_start) Constant value Boolean */
30 /*lint -emacro(506,va_arg) Constant value Boolean */
31 /*lint -emacro(718,va_start) Symbol 'Symbol' undeclared, assumed to return int */
32 /*lint -emacro(522,va_arg) Warning -- Expected void type, assignment, increment or decrement */
33 /*lint -emacro(10,va_arg) Error -- Expecting '(' */
34 /*lint -emacro(516,va_arg) Warning -- 'Symbol _va_argref()' has arg. type conflict (arg. no. 1 -- basic) */
35 /*lint -e661 */
36 /*lint -e662 */
37
38 /*==== INCLUDES ===================================================*/
39
40 #ifndef _VXWORKS_
41 #include <stdarg.h>
42 #endif
43 #include <stdio.h>
44 #include <string.h>
45 #include "typedefs.h"
46
47 #include "vsi.h"
48 #include "os.h"
49 #include "tools.h"
50 #include "frame.h"
51 #include "frm_defs.h"
52 #include "frm_types.h"
53 #include "frm_glob.h"
54 #include "p_frame.h"
55 #ifndef _TOOLS_
56 #include "tstdriver.h"
57 #endif
58
59 /*==== TYPES ======================================================*/
60
61 typedef struct
62 {
63 unsigned int magic_nr;
64 void (*trace_error)(const char * const format, va_list varpars);
65 void (*trace_assert)(const char * const format, va_list varpars);
66 } T_EXT_TRACE;
67
68 /*==== CONSTANTS ==================================================*/
69
70 #define EXT_TRACE_INITIALIZED 0xaffedead
71
72 /*==== EXTERNALS ==================================================*/
73
74 /* -------------- S H A R E D - BEGIN ---------------- */
75 #ifdef _TOOLS_
76 #pragma data_seg("FRAME_SHARED")
77 #endif
78
79 /*
80 * contains the correspnding flags for each task
81 */
82 extern T_HANDLE TestGroupHandle;
83 extern UBYTE FrameEnv;
84 extern char TaskName[];
85 extern char FRM_TST_NAME[];
86
87 #ifdef _TOOLS_
88 extern char FRM_SYST_NAME[];
89 #else
90 extern OS_HANDLE TST_Handle;
91 extern OS_HANDLE RCV_Handle;
92 extern int time_is_tdma_frame;
93 extern char error_ind_dst[];
94 extern T_FRM_ERROR_IND *frm_error_ind;
95 #endif
96
97 /*==== VARIABLES ==================================================*/
98
99 /*
100 this file may be compiled twice for FLASH and RAM, make sure we
101 get the variable declarations exactly once
102 */
103
104 #ifndef RUN_INT_RAM
105 /* must be seen only from FLASH */
106 GLOBAL char TraceBuffer [ TRACE_TEXT_SIZE ]={0};
107
108 /* must be seen from RAM and FLASH */
109 GLOBAL OS_HANDLE trc_hCommTrace=VSI_ERROR;
110 GLOBAL BOOL trc_LittleEndian = FALSE;
111 /* used by the entities */
112 GLOBAL char EntityNameBuf[RESOURCE_NAMELEN];
113 GLOBAL USHORT emergeny_trace;
114 #else
115 /* must be seen from RAM and FLASH */
116 extern OS_HANDLE trc_hCommTrace;
117 extern BOOL trc_LittleEndian;
118 extern USHORT emergeny_trace;
119 #endif
120
121 #ifndef RUN_INT_RAM
122 T_EXT_TRACE ext_trace_func;
123 #else
124 extern T_EXT_TRACE ext_trace_func;
125 #endif
126
127 #ifdef TEST_EXT_TRACE
128
129 void trace_error ( const char * const format, va_list varpars );
130 void trace_assert ( const char * const format, va_list varpars );
131
132 #ifndef RUN_INT_RAM
133 T_EXT_TRACE_FUNC ext_trace_functions =
134 {
135 trace_error,
136 trace_assert
137 };
138 #else
139 extern T_EXT_TRACE_FUNC ext_trace_functions;
140 #endif
141
142 #endif /* TEST_EXT_TRACE */
143
144 /*==== VARIABLES ==================================================*/
145
146 #ifdef _TOOLS_
147 #pragma data_seg()
148 #endif
149 /* -------------- S H A R E D - END ---------------- */
150
151 /*==== PROTOTYPES ==================================================*/
152
153 void ext_trace_init ( void );
154 int int_vsi_o_ttrace ( T_HANDLE Caller, ULONG TraceClass, const char * const format, va_list varpars );
155 int int_vsi_o_itrace ( T_HANDLE Caller, ULONG TraceClass, ULONG index, const char * const format, va_list varpars );
156 int vsi_o_datasend ( T_HANDLE caller, T_HANDLE dst, char *ext_dst, T_PRIM_HEADER *prim FILE_LINE_TYPE );
157 U32 int_vsi_tc2trace_opc(ULONG trace_class);
158
159 #ifdef _TARGET_
160 SHORT tst_pei_primitive (void *primitive);
161 #endif
162
163 /*==== FUNCTIONS ==================================================*/
164
165 #ifndef RUN_FLASH
166 U32 int_vsi_tc2trace_opc(ULONG trace_class)
167 {
168 switch (trace_class)
169 {
170 case TC_FUNC:
171 return FUNC_TRACE_OPC;
172 case TC_EVENT:
173 return EVENT_TRACE_OPC;
174 case TC_PRIM:
175 return PRIM_TRACE_OPC;
176 case TC_STATE:
177 return STATE_TRACE_OPC;
178 case TC_SYSTEM:
179 return SYSTEM_TRACE_OPC;
180 case TC_ISIG:
181 return ISIG_TRACE_OPC;
182 case TC_ERROR:
183 return ERROR_TRACE_OPC;
184 case TC_CCD:
185 return CCD_TRACE_OPC;
186 case TC_TIMER:
187 return TIMER_TRACE_OPC;
188 case TC_PROFILER:
189 return PROFILER_TRACE_OPC;
190
191 case TC_USER1:
192 return USER1_TRACE_OPC;
193 case TC_USER2:
194 return USER2_TRACE_OPC;
195 case TC_USER3:
196 return USER3_TRACE_OPC;
197 case TC_USER4:
198 return USER4_TRACE_OPC;
199 case TC_USER5:
200 return USER5_TRACE_OPC;
201 case TC_USER6:
202 return USER6_TRACE_OPC;
203 case TC_USER7:
204 return USER7_TRACE_OPC;
205 case TC_USER8:
206 return USER8_TRACE_OPC;
207
208 default:
209 return TRACE_OPC;
210 }
211 }
212 #endif /* RUN_FLASH */
213
214 #ifdef _TOOLS_
215 /*
216 +------------------------------------------------------------------------------
217 | Function : vsi_o_set_htrace
218 +------------------------------------------------------------------------------
219 | Description : This function sets the module variable trc_hCommTrace
220 |
221 | Parameters : comhandle - the new value
222 |
223 | Return : none
224 +------------------------------------------------------------------------------
225 */
226 void vsi_o_set_htrace (T_HANDLE comhandle)
227 {
228 trc_hCommTrace = (OS_HANDLE) comhandle;
229 }
230 #endif /* _TOOLS_ */
231
232 #ifndef RUN_FLASH
233 /*
234 +--------------------------------------------------------------------+
235 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
236 | STATE : code ROUTINE : vsi_o_trace |
237 +--------------------------------------------------------------------+
238
239 PURPOSE : traces a dynamic string
240
241 */
242 LOCAL int vsi_o_trace ( T_HANDLE Caller, T_PRIM_HEADER *prim, ULONG suspend )
243 {
244 T_S_HEADER *s_hdr;
245 LONG Status;
246 OS_QDATA QMsg;
247 BOOL AlarmTrace = FALSE;
248
249 s_hdr = (T_S_HEADER*)((ULONG*)prim + prim->sh_offset);
250 if ( TracesAborted[Caller] )
251 {
252 #ifdef _TOOLS_
253 /*
254 * Only needed for _TOOLS_ because Nucleus provides at least 52 Bytes in the partition
255 */
256 os_DeallocatePartition ( Caller, (T_VOID_STRUCT*)prim );
257 Status = os_AllocatePartition ( Caller, (T_VOID_STRUCT**)&prim, 80, suspend, TestGroupHandle );
258 #endif
259 sprintf ((char*)P2D(prim),"Trc Abort: %d !",TracesAborted[Caller]+1 );
260 prim->len = strlen ((char*)P2D(prim)) + sizeof(T_PRIM_HEADER);
261 prim->sh_offset = S_HDR_OFFSET(prim->len);
262 s_hdr = (T_S_HEADER*)((ULONG*)prim + prim->sh_offset);
263 AlarmTrace = TRUE;
264 }
265
266 s_hdr->snd[0] = (char)Caller;
267 if ( Caller )
268 s_hdr->snd[0] |= (char)HANDLE_BIT;
269
270 s_hdr->org_rcv[0] = 0;
271
272 #ifdef _TOOLS_
273 get_local_time (&s_hdr->time);
274 #else
275 if ( time_is_tdma_frame == 1 )
276 {
277 os_GetTime(Caller,&s_hdr->time);
278 s_hdr->time |= TIME_IS_TDMA;
279 }
280 else
281 {
282 os_GetTime(Caller,&s_hdr->time);
283 s_hdr->time &= ~TIME_IS_TDMA;
284 }
285 #endif
286
287 QMsg.flags = 0;
288 QMsg.data16 = MSG_PRIMITIVE;
289 QMsg.data32 = 0;
290 QMsg.ptr = (T_VOID_STRUCT*)prim;
291 #ifdef _TOOLS_
292 QMsg.len = ALIGN(prim->len) + sizeof(T_S_HEADER);
293 #endif
294 os_GetTime ( 0, &QMsg.time );
295
296 #ifndef _TOOLS_
297 if ( trc_hCommTrace == VSI_ERROR )
298 if ( (trc_hCommTrace = vsi_c_open ( TST_Handle, FRM_TST_NAME ) ) == OS_ERROR )
299 {
300 os_DeallocatePartition ( Caller, (T_VOID_STRUCT*)prim );
301 return VSI_ERROR;
302 }
303 #else
304 if ( trc_hCommTrace == VSI_ERROR )
305 {
306 if ( FrameEnv == ENV_TOOLS )
307 {
308 os_DeallocatePartition ( Caller, (T_VOID_STRUCT*)prim );
309 return VSI_ERROR;
310 }
311 else
312 {
313 if ( os_OpenQueue ( NO_TASK, FRM_TST_NAME, &trc_hCommTrace ) == OS_ERROR )
314 {
315 os_DeallocatePartition ( Caller, (T_VOID_STRUCT*)prim );
316 return VSI_ERROR;
317 }
318 }
319 }
320 if ( FrameEnv == ENV_TOOLS )
321 {
322 s_hdr->snd[0] = '~';
323 if ( os_GetTaskName ( Caller, Caller, &s_hdr->snd[1] ) == OS_ERROR )
324 {
325 char Sender[RESOURCE_NAMELEN];
326 char *ptr = (char*)P2D(prim);
327 unsigned int NameLen;
328
329 if ( *ptr == '~')
330 {
331 NameLen = GetNextToken ((char*)(ptr), Sender,"~");
332 InsertString(Sender, &s_hdr->snd[1], 4);
333 prim->len -= 2+NameLen;
334 memcpy ( ptr, ptr+2+NameLen, prim->len-sizeof(T_PRIM_HEADER) );
335 QMsg.len = ALIGN(prim->len) + sizeof(T_S_HEADER);
336 }
337 else
338 InsertString(FRM_SYST_NAME, &s_hdr->snd[1], 4);
339 }
340 }
341 #endif /* _TOOLS_ */
342
343 QMsg.e_id = trc_hCommTrace;
344
345 #ifndef _TOOLS_
346 if ( Caller == TST_Handle || Caller == RCV_Handle )
347 {
348 tst_drv_write ( Caller, 0, NULL, (char*)P2D(prim) );
349 os_DeallocatePartition ( Caller, (T_VOID_STRUCT*)prim );
350 return VSI_OK;
351 }
352 #ifndef _TARGET_
353 else
354 /*
355 * for the PC Simulation SuspendTrace[0] is != 0. To avoid that the system traces
356 * sent with caller NO_TASK block the system if the caller was TST, the Caller
357 * is set to the real caller here. This has no consequence on the caller name
358 * displayed in PCO because this is already formated into the header.
359 */
360 {
361 if ( Caller == NO_TASK )
362 {
363 Caller = e_running[os_MyHandle()];
364 }
365 }
366 #endif
367 #endif
368
369 QMsg.e_id = trc_hCommTrace;
370 #ifdef _TOOLS_
371 Status = os_SendToQueue ( NO_TASK, trc_hCommTrace, MSG_TRACE_PRIO, suspend, &QMsg );
372 #else
373 Status = os_SendToQueue ( NO_TASK, pf_TaskTable[trc_hCommTrace].QueueHandle, MSG_TRACE_PRIO, suspend, &QMsg );
374 #endif
375 if ( Status == OS_OK || Status == OS_WAITED )
376 {
377 TracesAborted[Caller] = 0;
378 if ( AlarmTrace )
379 return VSI_ERROR;
380 else
381 return VSI_OK;
382 }
383 else
384 {
385 /*
386 * No queue space available -> free partition
387 */
388 os_DeallocatePartition ( Caller, (T_VOID_STRUCT*)prim );
389 TracesAborted[Caller]++;
390 }
391 return VSI_ERROR;
392 }
393 #endif
394
395 #ifndef RUN_FLASH
396 /*
397 +--------------------------------------------------------------------+
398 | PROJECT : GSM-Frame (8415) MODULE : VSI_COM |
399 | STATE : code ROUTINE : vsi_o_primsend |
400 +--------------------------------------------------------------------+
401
402 PURPOSE : traces a data segment as a primitive
403
404 */
405 int vsi_o_primsend ( T_HANDLE caller, unsigned int mask, T_HANDLE dst, char *ext_dst, unsigned int opc, void *ptr, unsigned int len FILE_LINE_TYPE )
406 {
407 int alloc_size;
408 T_PRIM_HEADER *prim;
409 T_HANDLE e_handle;
410
411 if ( caller != 0 )
412 e_handle = caller;
413 else
414 e_handle = e_running[os_MyHandle()];
415
416 if ( (e_handle >= 0) && (TraceMask[e_handle] & mask) )
417 {
418 if ( opc != 0 )
419 {
420 alloc_size = len + sizeof(T_PRIM_HEADER);
421 if ( alloc_size < (int)MaxPrimPartSize )
422 {
423 prim = (T_PRIM_HEADER*)vsi_c_new ( 0, alloc_size, opc FILE_LINE );
424 memcpy((char*)P2D(prim), ptr, len);
425 /* if primitive is FRM_WARNING_IND -> free */
426 if ( opc == FRM_WARNING_IND )
427 {
428 PFREE(ptr);
429 }
430 }
431 else
432 {
433 vsi_o_ttrace ( caller, TC_SYSTEM, "SYSTEM WARNING: Binary trace too long -> discarded in %s(%d)" FILE_LINE );
434 return VSI_ERROR;
435 }
436 }
437 else
438 {
439 prim = D2P(ptr);
440 }
441 if ( vsi_o_datasend ( e_handle, dst, ext_dst, prim FILE_LINE ) == VSI_ERROR )
442 {
443 vsi_c_free ( 0, (T_VOID_STRUCT**)&prim FILE_LINE );
444 }
445 }
446 return VSI_OK;
447 }
448 #endif
449
450 #ifndef RUN_FLASH
451 /*
452 +--------------------------------------------------------------------+
453 | PROJECT : GSM-Frame (8415) MODULE : VSI_COM |
454 | STATE : code ROUTINE : vsi_o_sdusend |
455 +--------------------------------------------------------------------+
456
457 PURPOSE : traces an SDU as a primitive
458
459 */
460 int vsi_o_sdusend ( T_HANDLE caller, T_HANDLE dst, char *ext_dst, int opc, char ent, char dir, char type, void *ptr, unsigned int len FILE_LINE_TYPE )
461 {
462 T_PRIM_HEADER *prim;
463 T_HANDLE e_handle;
464 int alloc_size;
465
466 if ( caller != 0 )
467 e_handle = caller;
468 else
469 e_handle = e_running[os_MyHandle()];
470
471 if ( (e_handle >= 0) && (TraceMask[e_handle] & TC_SDU) )
472 {
473 if ( opc != 0 )
474 {
475 alloc_size = len + sizeof(T_PRIM_HEADER) + sizeof(T_SDU_TRACE);
476 if ( alloc_size < (int)MaxPrimPartSize )
477 {
478 prim = (T_PRIM_HEADER*)vsi_c_new ( 0, alloc_size, opc FILE_LINE );
479 ((T_SDU_TRACE*)(P2D(prim)))->entity = ent;
480 ((T_SDU_TRACE*)(P2D(prim)))->dir = dir;
481 ((T_SDU_TRACE*)(P2D(prim)))->type = type;
482 ((T_SDU_TRACE*)(P2D(prim)))->align1 = 0;
483 memcpy(((char*)P2D(prim))+sizeof(T_SDU_TRACE), ptr, len);
484 if ( vsi_o_datasend ( e_handle, dst, ext_dst, prim FILE_LINE ) == VSI_ERROR )
485 {
486 vsi_c_free ( 0, (T_VOID_STRUCT**)&prim FILE_LINE );
487 }
488 }
489 else
490 {
491 vsi_o_ttrace ( caller, TC_SYSTEM, "SYSTEM WARNING: Binary trace too long -> discarded in %s(%d)" FILE_LINE );
492 }
493 }
494 }
495 return VSI_OK;
496 }
497 #endif
498
499 #ifndef RUN_FLASH
500 /*
501 +--------------------------------------------------------------------+
502 | PROJECT : GSM-Frame (8415) MODULE : VSI_COM |
503 | STATE : code ROUTINE : vsi_o_datasend |
504 +--------------------------------------------------------------------+
505
506 PURPOSE : traces an already allocated primitive
507
508 */
509 int vsi_o_datasend ( T_HANDLE caller, T_HANDLE dst, char *ext_dst, T_PRIM_HEADER *prim FILE_LINE_TYPE )
510 {
511 int alloc_size;
512 T_PRIM_HEADER *carrier;
513 T_S_HEADER *s_hdr;
514 LONG status;
515 OS_QDATA DMsg;
516 unsigned int i;
517 ULONG suspend;
518
519 suspend = get_suspend_state(caller,CHECK_TRC_SUSPEND);
520
521 /* allocate carrier */
522 alloc_size = S_ALLOC_SIZE(4 + 1);
523 status = os_AllocatePartition ( caller, (T_VOID_STRUCT**)&carrier, alloc_size, suspend, TestGroupHandle );
524 if ( status == OS_OK || status == OS_WAITED || status == OS_ALLOCATED_BIGGER )
525 {
526 DMsg.data16 = MSG_PRIMITIVE;
527 DMsg.data32 = prim->opc;
528 #ifdef _TOOLS_
529 DMsg.len = alloc_size;
530 #endif
531 DMsg.ptr = (T_VOID_STRUCT*)carrier;
532
533 carrier->opc = prim->opc;
534 carrier->len = alloc_size;
535 carrier->sh_offset = S_HDR_OFFSET(alloc_size - sizeof(T_S_HEADER));
536 s_hdr = (T_S_HEADER*)((ULONG*)carrier + carrier->sh_offset);
537 if ( dst != 0 )
538 {
539 if ( vsi_e_name ( caller, dst, TaskName ) == VSI_OK )
540 {
541 /* set org_rcv */
542 for (i = 0; TaskName[i] && i < sizeof (s_hdr->rcv); i++)
543 s_hdr->org_rcv[i] = TaskName[i];
544 if (i < sizeof s_hdr->rcv)
545 s_hdr->org_rcv[i] = 0;
546 }
547 else
548 {
549 s_hdr->org_rcv[0] = 0;
550 }
551 }
552 else
553 {
554 s_hdr->org_rcv[0] = 0;
555 }
556 strncpy (s_hdr->rcv, ext_dst, RESOURCE_NAMELEN);
557 s_hdr->rcv[RESOURCE_NAMELEN-1] = 0;
558 if ( caller != 0 )
559 {
560 if ( vsi_e_name ( caller, caller, TaskName ) == VSI_OK )
561 {
562 /* set snd */
563 for (i = 0; TaskName[i] && i < sizeof (s_hdr->snd); i++)
564 s_hdr->snd[i] = TaskName[i];
565 if (i < sizeof s_hdr->snd)
566 s_hdr->snd[i] = 0;
567 }
568 }
569 else
570 {
571 if ( pf_TaskTable[caller].Name[0] != 0 )
572 {
573 s_hdr->snd[0] = (char)(caller | HANDLE_BIT);
574 }
575 else
576 {
577 s_hdr->rcv[0] = 0;
578 }
579 }
580 os_GetTime(0,&s_hdr->time);
581
582 ((T_PRIM_X*)(carrier))->prim_ptr = prim;
583 DMsg.e_id = trc_hCommTrace;
584 }
585 else
586 {
587 TracesAborted[caller]++;
588 return VSI_ERROR;
589 }
590
591 #ifdef MEMORY_SUPERVISION
592 vsi_ppm_send ( caller, pf_TaskTable[trc_hCommTrace].QueueHandle, prim FILE_LINE_MACRO );
593 #endif /* MEMORY_SUPERVISION */
594 if ( os_SendToQueue ( caller, pf_TaskTable[trc_hCommTrace].QueueHandle, OS_NORMAL, suspend, &DMsg ) == OS_TIMEOUT )
595 {
596 os_DeallocatePartition ( caller, (T_VOID_STRUCT*)carrier );
597 TracesAborted[caller]++;
598 return VSI_ERROR;
599 }
600 return VSI_OK;
601 }
602 #endif
603
604 #ifndef RUN_FLASH
605 /*
606 +--------------------------------------------------------------------+
607 | PROJECT : GSM-Frame (8415) MODULE : VSI_COM |
608 | STATE : code ROUTINE : vsi_o_memtrace |
609 +--------------------------------------------------------------------+
610
611 PURPOSE : check if PS already started
612
613 */
614 int vsi_o_memtrace ( T_HANDLE caller, void *ptr, unsigned int len )
615 {
616 T_PRIM_HEADER *prim;
617 T_HANDLE e_handle;
618 LONG status;
619 unsigned int i;
620 ULONG suspend;
621
622 if ( caller != 0 )
623 e_handle = caller;
624 else
625 e_handle = e_running[os_MyHandle()];
626
627 if ( (e_handle >= 0) && (TraceMask[e_handle] & TC_DATA) )
628 {
629 suspend = get_suspend_state(e_handle,CHECK_TRC_SUSPEND);
630 status = os_AllocatePartition ( e_handle, (T_VOID_STRUCT**)&prim, S_ALLOC_SIZE(len)*3, suspend, TestGroupHandle );
631 if ( status == OS_OK || status == OS_WAITED || status == OS_ALLOCATED_BIGGER )
632 {
633 unsigned char *dst_ptr = (unsigned char*)P2D(prim);
634 unsigned char *src_ptr = (unsigned char*)ptr;
635 for ( i = 0; i < len; i++, src_ptr++ )
636 {
637 if (*src_ptr>>4 > 9)
638 *dst_ptr++ = (*src_ptr>>4) + ('A'-10);
639 else
640 *dst_ptr++ = (*src_ptr>>4) +'0';
641 if ((*src_ptr&0xf) > 9)
642 *dst_ptr++ = (*src_ptr&0xf) + ('A'-10);
643 else
644 *dst_ptr++ = (*src_ptr&0xf) +'0';
645 *dst_ptr++ = 0x20;
646 }
647
648 prim->opc = int_vsi_tc2trace_opc(TC_DATA);
649 prim->len = 3*len + sizeof(T_PRIM_HEADER);
650 prim->sh_offset = S_HDR_OFFSET(prim->len);
651
652 return ( vsi_o_trace ( e_handle, prim, suspend ) );
653 }
654 TracesAborted[e_handle]++;
655 return VSI_ERROR;
656
657 }
658 return VSI_OK;
659 }
660 #endif
661
662 #ifndef RUN_FLASH
663 /*
664 +--------------------------------------------------------------------+
665 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
666 | STATE : code ROUTINE : vsi_o_func_ttrace |
667 +--------------------------------------------------------------------+
668
669 PURPOSE : traces a function name
670
671 */
672 int vsi_o_func_ttrace ( const char * const format, ... )
673 {
674 va_list varpars;
675 T_HANDLE Caller;
676
677 Caller = e_running[os_MyHandle()];
678
679 if ( (Caller >= 0) && (TraceMask[Caller] & TC_FUNC) )
680 {
681 va_start (varpars, format);
682 return int_vsi_o_ttrace ( Caller, TC_FUNC, format, varpars );
683 }
684 return VSI_ERROR;
685 }
686 #endif
687
688 #ifndef RUN_FLASH
689 /*
690 +--------------------------------------------------------------------+
691 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
692 | STATE : code ROUTINE : vsi_o_event_ttrace |
693 +--------------------------------------------------------------------+
694
695 PURPOSE : traces an event
696
697 */
698 int vsi_o_event_ttrace ( const char * const format, ... )
699 {
700 va_list varpars;
701 T_HANDLE Caller;
702
703 Caller = e_running[os_MyHandle()];
704
705 if ( (Caller >= 0) && (TraceMask[Caller] & TC_EVENT) )
706 {
707 va_start (varpars, format);
708 return int_vsi_o_ttrace ( Caller, TC_EVENT, format, varpars );
709 }
710 return VSI_ERROR;
711 }
712 #endif
713
714 #ifndef RUN_FLASH
715 /*
716 +--------------------------------------------------------------------+
717 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
718 | STATE : code ROUTINE : vsi_o_error_ttrace |
719 +--------------------------------------------------------------------+
720
721 PURPOSE : traces an error
722
723 */
724 int vsi_o_error_ttrace ( const char * const format, ... )
725 {
726 va_list varpars;
727 T_HANDLE Caller;
728
729 Caller = e_running[os_MyHandle()];
730
731 if ( (Caller >= 0) && (TraceMask[Caller] & TC_ERROR) )
732 {
733 va_start (varpars, format);
734 int_vsi_o_ttrace ( Caller, TC_ERROR, format, varpars );
735 vsi_o_ttrace ( NO_TASK, TC_ERROR, "TRACE ERROR in %s", pf_TaskTable[Caller].Name );
736 if ( ext_trace_func.trace_error != NULL )
737 {
738 ext_trace_func.trace_error ( format, varpars );
739 }
740 return VSI_OK;
741 }
742 return VSI_ERROR;
743 }
744 #endif
745
746 #ifndef RUN_FLASH
747 /*
748 +--------------------------------------------------------------------+
749 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
750 | STATE : code ROUTINE : vsi_o_state_ttrace |
751 +--------------------------------------------------------------------+
752
753 PURPOSE : traces a dynamic string
754
755 */
756 int vsi_o_state_ttrace ( const char * const format, ... )
757 {
758 va_list varpars;
759 T_HANDLE Caller;
760
761 Caller = e_running[os_MyHandle()];
762
763 if ( (Caller >= 0) && (TraceMask[Caller] & TC_STATE) )
764 {
765 va_start (varpars, format);
766 return int_vsi_o_ttrace ( Caller, TC_STATE, format, varpars );
767 }
768 return VSI_ERROR;
769 }
770 #endif
771
772 #ifndef RUN_FLASH
773 /*
774 +--------------------------------------------------------------------+
775 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
776 | STATE : code ROUTINE : vsi_o_class_ttrace |
777 +--------------------------------------------------------------------+
778
779 PURPOSE : traces a dynamic string
780
781 */
782 int vsi_o_class_ttrace ( ULONG trace_class, const char * const format, ... )
783 {
784 va_list varpars;
785 T_HANDLE Caller;
786
787 Caller = e_running[os_MyHandle()];
788
789 if ( (Caller >= 0) && (TraceMask[Caller] & trace_class) )
790 {
791 va_start (varpars, format);
792 return int_vsi_o_ttrace ( Caller, trace_class, format, varpars );
793 }
794 return VSI_ERROR;
795 }
796 #endif
797
798 #ifndef RUN_FLASH
799 /*
800 +--------------------------------------------------------------------+
801 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
802 | STATE : code ROUTINE : vsi_o_ttrace |
803 +--------------------------------------------------------------------+
804
805 PURPOSE : traces a dynamic string
806
807 */
808 int vsi_o_ttrace ( T_HANDLE Caller, ULONG TraceClass, const char * const format, ... )
809 {
810 va_list varpars;
811
812 if ( (Caller >= 0) && (TraceMask[Caller] & TraceClass) )
813 {
814 va_start (varpars, format);
815 return int_vsi_o_ttrace ( Caller, TraceClass, format, varpars );
816 }
817 return VSI_ERROR;
818 }
819 #endif
820
821 #ifndef RUN_FLASH
822 /*
823 +--------------------------------------------------------------------+
824 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
825 | STATE : code ROUTINE : int_vsi_o_ttrace |
826 +--------------------------------------------------------------------+
827
828 PURPOSE : traces a dynamic string
829
830 */
831 int int_vsi_o_ttrace ( T_HANDLE Caller, ULONG TraceClass, const char * const format, va_list varpars )
832 {
833 T_PRIM_HEADER *prim;
834 LONG Status;
835 ULONG suspend;
836 unsigned int offset = 0;
837 unsigned int num;
838
839 suspend = get_suspend_state(Caller,CHECK_TRC_SUSPEND);
840 Status = os_AllocatePartition ( Caller, (T_VOID_STRUCT**)&prim, TextTracePartitionSize, suspend, TestGroupHandle );
841 if ( Status == OS_OK || Status == OS_WAITED || Status == OS_ALLOCATED_BIGGER )
842 {
843 #if 0
844 /* be activated when PCO can handle this */
845 if ( TraceClass == TC_ERROR )
846 {
847 *((char*)(P2D(prim))) = '#';
848 offset = 1;
849 }
850 #endif
851 #ifdef _TOOLS_
852 int trc_length = TextTracePartitionSize - sizeof(T_S_HEADER) - sizeof(T_PRIM_HEADER) - 1;
853 trc_length &= ~0x03;
854 num = offset + (unsigned int)_vsnprintf ((char*)(P2D(prim)) + offset, trc_length, format, varpars) + 1; /* + 1 for terminating 0 */
855 #else
856 num = offset + (unsigned int)vsprintf ((char*)(P2D(prim)) + offset, format, varpars) + 1; /* + 1 for terminating 0 */
857 #endif
858 va_end (varpars);
859 if ( num + sizeof(T_S_HEADER) + sizeof(T_PRIM_HEADER) >= TextTracePartitionSize )
860 {
861 sprintf ( (char*)(P2D(prim))+60, "... %s trace too long", pf_TaskTable[Caller].Name );
862 vsi_o_assert ( NO_TASK, OS_SYST_ERR_STR_TOO_LONG, __FILE__, __LINE__,(char*)(P2D(prim)));
863 }
864 prim->opc = int_vsi_tc2trace_opc(TraceClass);
865 prim->len = strlen((char*)P2D(prim)) + sizeof(T_PRIM_HEADER);
866 prim->sh_offset = S_HDR_OFFSET(prim->len);
867
868 return ( vsi_o_trace ( Caller, prim, suspend ) );
869 }
870 if ( FrameEnv == ENV_STACK )
871 {
872 TracesAborted[Caller]++;
873 }
874 return VSI_ERROR;
875 }
876 #endif
877
878 #ifndef RUN_FLASH
879 /*
880 +--------------------------------------------------------------------+
881 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
882 | STATE : code ROUTINE : vsi_o_func_itrace |
883 +--------------------------------------------------------------------+
884
885 PURPOSE : traces a function name
886
887 */
888 int vsi_o_func_itrace ( ULONG index, const char * const format, ... )
889 {
890 va_list varpars;
891 T_HANDLE Caller;
892
893 Caller = e_running[os_MyHandle()];
894
895 if ( (Caller >= 0) && (TraceMask[Caller] & TC_FUNC) )
896 {
897 va_start (varpars, format);
898 return int_vsi_o_itrace ( Caller, TC_FUNC, index, format, varpars );
899 }
900 return VSI_ERROR;
901 }
902 #endif
903
904 #ifndef RUN_FLASH
905 /*
906 +--------------------------------------------------------------------+
907 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
908 | STATE : code ROUTINE : vsi_o_event_itrace |
909 +--------------------------------------------------------------------+
910
911 PURPOSE : traces an event
912
913 */
914 int vsi_o_event_itrace ( ULONG index, const char * const format, ... )
915 {
916 va_list varpars;
917 T_HANDLE Caller;
918
919 Caller = e_running[os_MyHandle()];
920
921 if ( (Caller >= 0) && (TraceMask[Caller] & TC_EVENT) )
922 {
923 va_start (varpars, format);
924 return int_vsi_o_itrace ( Caller, TC_EVENT, index, format, varpars );
925 }
926 return VSI_ERROR;
927 }
928 #endif
929
930 #ifndef RUN_FLASH
931 /*
932 +--------------------------------------------------------------------+
933 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
934 | STATE : code ROUTINE : vsi_o_error_itrace |
935 +--------------------------------------------------------------------+
936
937 PURPOSE : traces an error
938
939 */
940 int vsi_o_error_itrace ( ULONG index, const char * const format, ... )
941 {
942 va_list varpars;
943 T_HANDLE Caller;
944
945 Caller = e_running[os_MyHandle()];
946
947 if ( (Caller >= 0) && (TraceMask[Caller] & TC_ERROR) )
948 {
949 va_start (varpars, format);
950 int_vsi_o_itrace ( Caller, TC_ERROR, index, format, varpars );
951 os_GetTaskName ( Caller, Caller, TaskName );
952 vsi_o_ttrace ( NO_TASK, TC_ERROR, "TRACE ERROR in %s", pf_TaskTable[Caller].Name );
953 return VSI_OK;
954 }
955 return VSI_ERROR;
956 }
957 #endif
958
959 #ifndef RUN_FLASH
960 /*
961 +--------------------------------------------------------------------+
962 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
963 | STATE : code ROUTINE : vsi_o_state_itrace |
964 +--------------------------------------------------------------------+
965
966 PURPOSE : traces a dynamic string
967
968 */
969 int vsi_o_state_itrace ( ULONG index, const char * const format, ... )
970 {
971 va_list varpars;
972 T_HANDLE Caller;
973
974 Caller = e_running[os_MyHandle()];
975
976 if ( (Caller >= 0) && (TraceMask[Caller] & TC_STATE) )
977 {
978 va_start (varpars, format);
979 return int_vsi_o_itrace ( Caller, TC_STATE, index, format, varpars );
980 }
981 return VSI_ERROR;
982 }
983 #endif
984
985 #ifndef RUN_FLASH
986 /*
987 +--------------------------------------------------------------------+
988 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
989 | STATE : code ROUTINE : vsi_o_class_itrace |
990 +--------------------------------------------------------------------+
991
992 PURPOSE : traces a dynamic string
993
994 */
995 int vsi_o_class_itrace ( ULONG trace_class, ULONG Index, const char * const format, ... )
996 {
997 va_list varpars;
998 T_HANDLE Caller;
999
1000 Caller = e_running[os_MyHandle()];
1001
1002 if ( (Caller >= 0) && (TraceMask[Caller] & trace_class) )
1003 {
1004 va_start (varpars, format);
1005 return int_vsi_o_itrace ( Caller, trace_class, Index, format, varpars );
1006 }
1007 return VSI_ERROR;
1008 }
1009 #endif
1010
1011 #ifndef RUN_FLASH
1012 /*
1013 +--------------------------------------------------------------------+
1014 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
1015 | STATE : code ROUTINE : vsi_o_ttrace |
1016 +--------------------------------------------------------------------+
1017
1018 PURPOSE : traces a dynamic string
1019
1020 */
1021 int vsi_o_itrace ( T_HANDLE Caller, ULONG TraceClass, ULONG Index, const char * const format, ... )
1022 {
1023 va_list varpars;
1024
1025 if ( (Caller >= 0) && (TraceMask[Caller] & TraceClass) )
1026 {
1027 va_start (varpars, format);
1028 return int_vsi_o_itrace ( Caller, TraceClass, Index, format, varpars );
1029 }
1030 return VSI_ERROR;
1031 }
1032 #endif
1033
1034 #ifndef RUN_FLASH
1035 /*
1036 +--------------------------------------------------------------------+
1037 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
1038 | STATE : code ROUTINE : int_vsi_o_itrace |
1039 +--------------------------------------------------------------------+
1040
1041 PURPOSE : traces a dynamic string
1042
1043 */
1044 int int_vsi_o_itrace ( T_HANDLE Caller, ULONG TraceClass, ULONG index, const char * const format,
1045 va_list varpars )
1046 {
1047 T_PRIM_HEADER *prim;
1048 LONG Status;
1049 ULONG suspend;
1050 unsigned int offset = 0;
1051 unsigned int paramCount;
1052 unsigned int i;
1053
1054 /*
1055 * the offset is calculated prior to the actual write operation
1056 * to avoid writing beyond the allocated size
1057 *
1058 * all write operation are addressed relatively to the precalculated
1059 * offset e.g. *(&Prim->Data + offset - 5)
1060 */
1061 if ( (Caller >= 0) && (TraceMask[Caller] & TraceClass) )
1062 {
1063 suspend = get_suspend_state(Caller,CHECK_TRC_SUSPEND);
1064 Status = os_AllocatePartition ( Caller, (T_VOID_STRUCT**)&prim, (ULONG)TextTracePartitionSize, suspend, TestGroupHandle );
1065 if ( Status == OS_OK || Status == OS_WAITED || Status == OS_ALLOCATED_BIGGER )
1066 {
1067
1068 /*
1069 * the index preceded by %
1070 */
1071 #if 0
1072 /* be activated when PCO can handle this */
1073 if ( TraceClass == TC_ERROR )
1074 {
1075 *((char*)(P2D(prim))) = '#';
1076 offset = 1;
1077 }
1078 #endif
1079 offset += 5;
1080 if(offset <= TextTracePartitionSize - sizeof(T_S_HEADER) - sizeof(T_PRIM_HEADER))
1081 {
1082 *((char*)(P2D(prim)) + offset - 5) = '%';
1083 if(trc_LittleEndian)
1084 {
1085 *((char*)(P2D(prim)) + offset - 4) = *((char *)&index);
1086 *((char*)(P2D(prim)) + offset - 3) = *(((char *)&index)+1);
1087 *((char*)(P2D(prim)) + offset - 2) = *(((char *)&index)+2);
1088 *((char*)(P2D(prim)) + offset - 1) = *(((char *)&index)+3);
1089 }
1090 else
1091 {
1092 *((char*)(P2D(prim)) + offset - 4) = *(((char *)&index)+3);
1093 *((char*)(P2D(prim)) + offset - 3) = *(((char *)&index)+2);
1094 *((char*)(P2D(prim)) + offset - 2) = *(((char *)&index)+1);
1095 *((char*)(P2D(prim)) + offset - 1) = *((char *)&index);
1096 }
1097 }
1098 /*
1099 * parse the format string
1100 */
1101 paramCount = strlen(format);
1102
1103 for (i=0; i<paramCount; i++)
1104 {
1105 switch(*(format+i))
1106 {
1107 case 'c': /* one byte */
1108 offset+=1;
1109 if(offset <= TextTracePartitionSize - sizeof(T_S_HEADER) - sizeof(T_PRIM_HEADER))
1110 *((char*)(P2D(prim)) + offset - 1) = *((char *)varpars);
1111
1112 va_arg(varpars, char);
1113 break;
1114 case 'i': /* four bytes */
1115 case 'p':
1116 case '*':
1117 offset+=4;
1118 if(offset <= TextTracePartitionSize - sizeof(T_S_HEADER) - sizeof(T_PRIM_HEADER))
1119 {
1120 if(trc_LittleEndian)
1121 {
1122 *((char*)(P2D(prim)) + offset - 4) = *((char *)varpars);
1123 *((char*)(P2D(prim)) + offset - 3) = *(((char *)varpars)+1);
1124 *((char*)(P2D(prim)) + offset - 2) = *(((char *)varpars)+2);
1125 *((char*)(P2D(prim)) + offset - 1) = *(((char *)varpars)+3);
1126 }
1127 else
1128 {
1129 *((char*)(P2D(prim)) + offset - 4) = *(((char *)varpars)+3);
1130 *((char*)(P2D(prim)) + offset - 3) = *(((char *)varpars)+2);
1131 *((char*)(P2D(prim)) + offset - 2) = *(((char *)varpars)+1);
1132 *((char*)(P2D(prim)) + offset - 1) = *((char *)varpars);
1133 }
1134 }
1135 va_arg(varpars, int);
1136 break;
1137 case 'd': /* eigth bytes */
1138 offset += 8;
1139
1140 /*
1141 * TI and Microsoft represent double values differently
1142 *
1143 Double Host representation (address incressing from byte 1 to 8)
1144 layout Microsoft TMS470x
1145
1146 SEEEEEEE byte 8 byte 4
1147 EEMMMMMM byte 7 byte 3
1148 MMMMMMMM byte 6 byte 2
1149 MMMMMMMM byte 5 byte 1
1150 MMMMMMMM byte 4 byte 8
1151 MMMMMMMM byte 3 byte 7
1152 MMMMMMMM byte 2 byte 6
1153 MMMMMMMM byte 1 byte 5
1154
1155 S - sign bit
1156 E - exponent bits
1157 M - mantissa bits
1158
1159 *
1160 * double
1161 */
1162
1163
1164 if(offset <= TextTracePartitionSize - sizeof(T_S_HEADER) - sizeof(T_PRIM_HEADER))
1165 {
1166 #ifdef _TARGET_
1167 /* TI TMS470 Compiler */
1168 *((char*)(P2D(prim)) + offset - 4) = *((char *)varpars);
1169 *((char*)(P2D(prim)) + offset - 3) = *(((char *)varpars)+1);
1170 *((char*)(P2D(prim)) + offset - 2) = *(((char *)varpars)+2);
1171 *((char*)(P2D(prim)) + offset - 1) = *(((char *)varpars)+3);
1172 *((char*)(P2D(prim)) + offset - 8) = *(((char *)varpars)+4);
1173 *((char*)(P2D(prim)) + offset - 7) = *(((char *)varpars)+5);
1174 *((char*)(P2D(prim)) + offset - 6) = *(((char *)varpars)+6);
1175 *((char*)(P2D(prim)) + offset - 5) = *(((char *)varpars)+7);
1176 #else
1177 /*
1178 * This should work as well, since no reordering is done.
1179 * Don't believe the VC5/6 manual which states a complete
1180 * different byte order :(
1181 *
1182 */
1183 /* PC- Simulation */
1184 *((char*)(P2D(prim)) + offset - 8) = *((char *)varpars);
1185 *((char*)(P2D(prim)) + offset - 7) = *(((char *)varpars)+1);
1186 *((char*)(P2D(prim)) + offset - 6) = *(((char *)varpars)+2);
1187 *((char*)(P2D(prim)) + offset - 5) = *(((char *)varpars)+3);
1188 *((char*)(P2D(prim)) + offset - 4) = *(((char *)varpars)+4);
1189 *((char*)(P2D(prim)) + offset - 3) = *(((char *)varpars)+5);
1190 *((char*)(P2D(prim)) + offset - 2) = *(((char *)varpars)+6);
1191 *((char*)(P2D(prim)) + offset - 1) = *(((char *)varpars)+7);
1192 #endif /* _TARGET_ */
1193 }
1194
1195 va_arg(varpars, double);
1196 break;
1197 case 's': /* a string of bytes */
1198 {
1199 /*
1200 * copy the string including the terminating NULL
1201 */
1202 unsigned int len = strlen(*((char **)varpars)) + 1;
1203
1204 offset += len;
1205 if(offset <= TextTracePartitionSize - sizeof(T_S_HEADER) - sizeof(T_PRIM_HEADER))
1206 {
1207 memcpy((char*)(P2D(prim)) + offset - len, *((char **)varpars), len);
1208 }
1209 va_arg(varpars, char **);
1210 }
1211 break;
1212 default: /* unknown type */
1213 vsi_o_assert ( NO_TASK, OS_SYST_ERR_STR_TOO_LONG, __FILE__, __LINE__,
1214 "Unknown Trace Format" );
1215 break;
1216 }
1217 }
1218
1219 va_end (varpars);
1220 /*
1221 * if the amount of trace data was bigger than the allocated
1222 * size - discard the trace and send an error trace instead
1223 */
1224 if (offset > TextTracePartitionSize - sizeof(T_S_HEADER) - sizeof(T_PRIM_HEADER))
1225 {
1226 unsigned int n = (unsigned int)sprintf ((char*)P2D(prim),"ERROR: Compressed trace (index %d) too long (%d bytes). Trace discarded !!!",index, offset);
1227 prim->len = n + sizeof(T_PRIM_HEADER);
1228 }
1229 else
1230 {
1231 prim->len = offset + sizeof(T_PRIM_HEADER);
1232 }
1233
1234 prim->opc = int_vsi_tc2trace_opc(TraceClass);
1235 prim->sh_offset = S_HDR_OFFSET(prim->len);
1236
1237 return ( vsi_o_trace ( Caller, prim, suspend ) );
1238 }
1239 if ( FrameEnv == ENV_STACK )
1240 {
1241 TracesAborted[Caller]++;
1242 }
1243 }
1244 return VSI_ERROR;
1245 }
1246 #endif
1247
1248 #ifndef RUN_FLASH
1249 /*
1250 +--------------------------------------------------------------------+
1251 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
1252 | STATE : code ROUTINE : vsi_o_ptrace |
1253 +--------------------------------------------------------------------+
1254
1255 PURPOSE : traces a primitive opc and direction
1256
1257 */
1258 int vsi_o_ptrace ( T_HANDLE Caller, ULONG opc, UBYTE dir )
1259 {
1260 T_PRIM_HEADER *prim;
1261 ULONG suspend;
1262 LONG Status;
1263 ULONG size;
1264 int opc_len;
1265
1266 if ( (Caller >= 0) && (TraceMask[Caller] & TC_PRIM)
1267 #ifdef _TOOLS_
1268 && (SAP_NR(opc)!=TRACE_SAP) && (opc!=TRACE_OPC)
1269 #endif
1270 )
1271 {
1272 suspend = get_suspend_state(Caller,CHECK_TRC_SUSPEND);
1273 size = S_ALLOC_SIZE(PTRACE_LEN_OPC32);
1274 Status = os_AllocatePartition ( Caller, (T_VOID_STRUCT**)&prim, size, suspend, TestGroupHandle );
1275 if ( Status == OS_OK || Status == OS_WAITED || Status == OS_ALLOCATED_BIGGER )
1276 {
1277 prim->opc = int_vsi_tc2trace_opc(TC_PRIM);
1278
1279 if ( dir )
1280 strcpy ( (char*)P2D(prim),"$---OUT:$p0x123456789" );
1281 else
1282 strcpy ( (char*)P2D(prim),"$--- IN:$p0x123456789" );
1283
1284 if ( OPC32BIT(opc) )
1285 {
1286 opc_len = CHARS_FOR_32BIT;
1287 prim->len = PTRACE_LEN_OPC32;
1288 }
1289 else
1290 {
1291 opc_len = CHARS_FOR_16BIT;
1292 prim->len = PTRACE_LEN_OPC16;
1293 }
1294 prim->len = prim->len + sizeof(T_PRIM_HEADER);
1295 HexToASCII ( opc, (char*)P2D(prim) + 12, opc_len );
1296 strcpy (((char*)P2D(prim) + 12 + opc_len), "$" );
1297
1298 prim->sh_offset = S_HDR_OFFSET(prim->len);
1299 return ( vsi_o_trace ( Caller, prim, suspend ) );
1300 }
1301 TracesAborted[Caller]++;
1302 }
1303 return VSI_ERROR;
1304 }
1305 #endif
1306
1307 #ifndef RUN_FLASH
1308 /*
1309 +--------------------------------------------------------------------+
1310 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
1311 | STATE : code ROUTINE : vsi_o_strace |
1312 +--------------------------------------------------------------------+
1313
1314 PURPOSE : traces a state and state transition
1315
1316 */
1317 int vsi_o_strace (T_HANDLE Caller, const char *const machine,
1318 const char *const curstate,
1319 const char *const newstate)
1320 {
1321 T_PRIM_HEADER *prim;
1322 LONG Status;
1323 ULONG size;
1324 ULONG suspend;
1325
1326 if ( (Caller >= 0) && (TraceMask[Caller] & TC_STATE) )
1327 {
1328 suspend = get_suspend_state(Caller,CHECK_TRC_SUSPEND);
1329 size = S_ALLOC_SIZE(STRACE_LEN);
1330 Status = os_AllocatePartition ( Caller, (T_VOID_STRUCT**)&prim, size, suspend, TestGroupHandle );
1331 if ( Status == OS_OK || Status == OS_WAITED || Status == OS_ALLOCATED_BIGGER )
1332 {
1333 strcpy ( (char *)P2D(prim), machine );
1334 strcat ( (char *)P2D(prim), ":" );
1335 strcat ( (char *)P2D(prim), curstate );
1336 if ( newstate != NULL )
1337 {
1338 strcat ( (char *)P2D(prim), " -> " );
1339 strcat ( (char *)P2D(prim), newstate );
1340 }
1341
1342 prim->opc = int_vsi_tc2trace_opc(TC_STATE);
1343 prim->len = strlen((char*)P2D(prim)) + sizeof(T_PRIM_HEADER);
1344 prim->sh_offset = S_HDR_OFFSET(prim->len);
1345
1346 return ( vsi_o_trace ( Caller, prim, suspend ) );
1347 }
1348 TracesAborted[Caller]++;
1349 }
1350 return VSI_ERROR;
1351 }
1352 #endif
1353
1354 #ifndef RUN_INT_RAM
1355 /*
1356 +--------------------------------------------------------------------+
1357 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
1358 | STATE : code ROUTINE : vsi_o_assert |
1359 +--------------------------------------------------------------------+
1360
1361 PURPOSE : assert
1362
1363 */
1364 /*lint -esym(715,cause) suppress Info -- Symbol 'cause' not referenced */
1365 int vsi_o_assert (T_HANDLE Caller, USHORT cause, const char *file, int line, const char * const format,...)
1366 {
1367 va_list varpars;
1368 #ifdef _TARGET_
1369 OS_QDATA Msg;
1370
1371 while ( os_ReceiveFromQueue( Caller, pf_TaskTable[trc_hCommTrace].QueueHandle, &Msg, OS_NO_SUSPEND ) == OS_OK )
1372 {
1373 tst_pei_primitive (Msg.ptr);
1374 }
1375 #endif
1376 strcpy ( TraceBuffer, "SYSTEM ERROR: " );
1377 va_start (varpars, format);
1378 vsprintf (TraceBuffer+strlen("SYSTEM ERROR: "), format, varpars);
1379 va_end (varpars);
1380 sprintf (TraceBuffer+strlen(TraceBuffer), ", %s(%d)", file, line );
1381 #ifdef _TOOLS_
1382 vsi_o_ttrace ( NO_TASK, TC_SYSTEM, TraceBuffer );
1383 #else
1384 if ( cause & OS_SYST_ERR )
1385 emergeny_trace = 1;
1386 tst_drv_write ( NO_TASK, 0, NULL, TraceBuffer );
1387
1388 if ( error_ind_dst[0] != 0 )
1389 {
1390 frm_error_ind->error_code = cause;
1391 strncpy ((char*)frm_error_ind->error_string, TraceBuffer, FRM_PRIM_STR_SIZE);
1392 frm_error_ind->error_string[FRM_PRIM_STR_SIZE-1] = 0;
1393 tst_drv_write ( NO_TASK, FRM_ERROR_IND, error_ind_dst, (char*)frm_error_ind );
1394 }
1395 #endif
1396 #if defined _NUCLEUS_ && !defined _TARGET_
1397 printf ("%s\n",TraceBuffer);
1398 printf ( "Task %s suspended\n", pf_TaskTable[Caller].Name );
1399 #endif
1400 if ( ext_trace_func.trace_assert != NULL )
1401 {
1402 /* in case of OS_SYST_ERR_QUEUE_FULL we should not to send the trace to ACI,
1403 because ACI will probably no longer be scheduled.
1404 in case of OS_SYST_ERR_NO_PARTITION the PALLOC in ACI fails and will
1405 probably hide the root cause of the problem.
1406 */
1407 if ( cause != OS_SYST_ERR_QUEUE_FULL && cause != OS_SYST_ERR_NO_PARTITION )
1408 {
1409 ext_trace_func.trace_assert ( format, varpars );
1410 os_SuspendTask ( Caller, 1000 );
1411 }
1412 }
1413 #ifdef _NUCLEUS_
1414 os_SystemError ( os_MyHandle(), cause, TraceBuffer );
1415 #endif
1416 return VSI_OK;
1417 }
1418 #endif
1419
1420 #ifndef RUN_INT_RAM
1421 /*
1422 +--------------------------------------------------------------------+
1423 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
1424 | STATE : code ROUTINE : vsi_settracemask |
1425 +--------------------------------------------------------------------+
1426
1427 PURPOSE : set trace mask
1428
1429 */
1430
1431 int vsi_settracemask ( T_HANDLE Caller, T_HANDLE Handle, ULONG Mask )
1432 {
1433
1434 if ( Handle == 0 || pf_TaskTable[Handle].Name[0] != 0 )
1435 {
1436 TraceMask[Handle] = Mask;
1437 TraceMask[0] |= TC_SYSTEM;
1438 return VSI_OK;
1439 }
1440 else
1441 return VSI_ERROR;
1442 }
1443 #endif
1444
1445 #ifndef RUN_INT_RAM
1446 /*
1447 +--------------------------------------------------------------------+
1448 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
1449 | STATE : code ROUTINE : vsi_gettracemask |
1450 +--------------------------------------------------------------------+
1451
1452 PURPOSE : get trace mask
1453
1454 */
1455
1456 int vsi_gettracemask ( T_HANDLE Caller, T_HANDLE Handle, ULONG *Mask )
1457 {
1458 if ( Handle == 0 || pf_TaskTable[Handle].Name[0] != 0 )
1459 {
1460 *Mask = TraceMask[Handle];
1461 return VSI_OK;
1462 }
1463 else
1464 return VSI_ERROR;
1465 }
1466 #endif
1467
1468 #ifndef RUN_INT_RAM
1469 /*
1470 +--------------------------------------------------------------------+
1471 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
1472 | STATE : code ROUTINE : vsi_trcsuspend |
1473 +--------------------------------------------------------------------+
1474
1475 PURPOSE : set suspend for traces
1476
1477 */
1478
1479 int vsi_trcsuspend ( T_HANDLE Caller, T_HANDLE Handle, ULONG Suspend )
1480 {
1481 /* SuspendTrace[Handle] = Suspend; */
1482 return VSI_OK;
1483 }
1484 #endif
1485
1486 #ifndef RUN_FLASH
1487 /*
1488 +--------------------------------------------------------------------+
1489 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
1490 | STATE : code ROUTINE : vsi_trc_free |
1491 +--------------------------------------------------------------------+
1492
1493 PURPOSE : monitor test interface partition allocation
1494 */
1495
1496 int vsi_trc_free ( T_HANDLE Caller, T_VOID_STRUCT **Prim )
1497 {
1498 if ( os_DeallocatePartition ( Caller, *Prim ) != OS_ERROR )
1499 {
1500 *Prim = NULL;
1501 return VSI_OK;
1502 }
1503 return VSI_ERROR;
1504 }
1505 #endif
1506
1507 #ifndef RUN_INT_RAM
1508 /*
1509 +--------------------------------------------------------------------+
1510 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
1511 | STATE : code ROUTINE : InitializeTestpools |
1512 +--------------------------------------------------------------------+
1513
1514 PURPOSE : initialize supervision, write index to each partition.
1515
1516 */
1517 void InitializeTrace ( void )
1518 {
1519 USHORT i;
1520 ULONG ByteOrder;
1521
1522 /*
1523 * test the byte order
1524 */
1525 ByteOrder = 0x11223344;
1526
1527 if(*((char *) &ByteOrder) == 0x44)
1528 trc_LittleEndian = TRUE;
1529 else if (*((char *) &ByteOrder) == 0x11)
1530 trc_LittleEndian = FALSE;
1531 else
1532 vsi_o_assert ( NO_TASK, OS_SYST_ERR_STR_TOO_LONG, __FILE__, __LINE__,
1533 "Unknown Byte Order" );
1534 emergeny_trace = 0;
1535 trc_hCommTrace = VSI_ERROR;;
1536 for ( i = 0; i <= MaxEntities; i++ )
1537 {
1538 TracesAborted[i] = 0;
1539 #ifdef _TARGET_
1540 TraceMask[i] = TC_SYSTEM|TC_ERROR;
1541 #else /* _TARGET_ */
1542 TraceMask[i] = 0xffffffff & ~TC_CCD;
1543 #endif /* _TARGET_ */
1544 }
1545 #ifdef _TARGET_
1546 #endif
1547 ext_trace_func.magic_nr = 0;
1548 ext_trace_init();
1549 }
1550 #endif
1551
1552 #ifndef RUN_FLASH
1553 /*
1554 +--------------------------------------------------------------------+
1555 | PROJECT : GSM-Frame (8415) MODULE : VSI_TRC |
1556 | STATE : code ROUTINE : get_suspend_state |
1557 +--------------------------------------------------------------------+
1558
1559 PURPOSE : check if suspend is allowed.
1560
1561 */
1562 ULONG get_suspend_state ( T_HANDLE caller, int type )
1563 {
1564
1565 if ( caller != 0 )
1566 {
1567 #ifdef _TARGET_
1568 if ( type == CHECK_TRC_SUSPEND )
1569 {
1570 if ( pf_TaskTable[caller].Flags & TRC_NO_SUSPEND )
1571 {
1572 return OS_NO_SUSPEND;
1573 }
1574 else
1575 {
1576 return OS_SUSPEND;
1577 }
1578 }
1579 else if ( type == CHECK_PRIM_SUSPEND )
1580 {
1581 if ( pf_TaskTable[caller].Flags & PRIM_NO_SUSPEND )
1582 {
1583 return OS_NO_SUSPEND;
1584 }
1585 else
1586 {
1587 return OS_SUSPEND;
1588 }
1589 }
1590 else
1591 {
1592 return OS_NO_SUSPEND;
1593 }
1594 #else
1595 /*
1596 It is checked if the caller is a SYSTEM_PROCESS to ensure that
1597 TST and RCV do not block while tracing to avoid a deadlock.
1598 */
1599 if ( pf_TaskTable[caller].Flags & SYSTEM_PROCESS )
1600 return OS_NO_SUSPEND;
1601 else
1602 return OS_SUSPEND;
1603 #endif
1604 }
1605 else
1606 {
1607 #ifdef _TARGET_
1608 return OS_NO_SUSPEND;
1609 #else
1610 return OS_SUSPEND;
1611 #endif
1612 }
1613 }
1614 #endif
1615
1616
1617 /* -------------------------------------------------------------------------
1618 External Trace functions
1619 ----------------------------------------------------------------------------*/
1620
1621 #ifdef TEST_EXT_TRACE
1622
1623 #ifndef RUN_INT_RAM
1624 void trace_error ( const char * const format, va_list varpars )
1625 {
1626 #ifndef _TARGET_
1627 char buf[99];
1628
1629 vsprintf (buf, format, varpars);
1630 printf ("%s\n",buf);
1631 #endif
1632 }
1633 #endif
1634
1635 #ifndef RUN_INT_RAM
1636 void trace_assert ( const char * const format, va_list varpars )
1637 {
1638 #ifndef _TARGET_
1639 char buf[99];
1640
1641 vsprintf (buf, format, varpars);
1642 printf ("%s\n",buf);
1643 #endif
1644 }
1645 #endif
1646
1647 #endif /* TEST_EXT_TRACE */
1648
1649 #ifndef RUN_INT_RAM
1650 /*
1651 +------------------------------------------------------------------------------
1652 | Function : ext_trace_register
1653 +------------------------------------------------------------------------------
1654 | Description : register the external trace functions.
1655 |
1656 | Parameters : func - pointer to API function pointer table
1657 |
1658 | Return : void
1659 +------------------------------------------------------------------------------
1660 */
1661 void vsi_ext_trace_register ( T_EXT_TRACE_FUNC * func )
1662 {
1663 ext_trace_func.trace_error = func->trace_error;
1664 ext_trace_func.trace_assert = func->trace_assert;
1665 ext_trace_func.magic_nr = EXT_TRACE_INITIALIZED;
1666 }
1667 #endif
1668
1669 #ifndef RUN_INT_RAM
1670 /*
1671 +------------------------------------------------------------------------------
1672 | Function : ext_trace_init
1673 +------------------------------------------------------------------------------
1674 | Description : initialize external trace function pointer table.
1675 |
1676 | Parameters : void
1677 |
1678 | Return : void
1679 +------------------------------------------------------------------------------
1680 */
1681 void ext_trace_init ( void )
1682 {
1683 #ifdef TEST_EXT_TRACE
1684 vsi_ext_trace_register ( &ext_trace_functions );
1685 #endif
1686 if ( ext_trace_func.magic_nr != EXT_TRACE_INITIALIZED )
1687 {
1688 ext_trace_func.trace_error = NULL;
1689 ext_trace_func.trace_assert = NULL;
1690 }
1691 }
1692 #endif
1693
1694
1695
1696