comparison chipsetsw/services/etm/etm_trace.c @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /********************************************************************************
2 * Enhanced TestMode (ETM)
3 * @file etm_trace.c
4 *
5 * @author Kim T. Peteren (ktp@ti.com) and Mads Meisner-Jensen, mmj@ti.com
6 * @version 0.1
7 *
8
9 *
10 * History:
11 *
12 * Date Modification
13 * ------------------------------------
14 * 16/06/2003 Creation
15 *
16 * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
17 *********************************************************************************/
18
19
20 #include "etm/etm_trace.h"
21 #include "etm/etm_env.h"
22
23 #include "rvf/rvf_api.h"
24 #include "rvm/rvm_use_id_list.h"
25
26 #include <string.h>
27 #include <stdio.h>
28 #include <stdarg.h>
29
30
31 /******************************************************************************
32 * Prototypes
33 *****************************************************************************/
34
35 void trstr(unsigned int mask, char *string);
36
37
38 /******************************************************************************
39 * Target Tracing
40 *****************************************************************************/
41
42 static unsigned int ttr_mask = TgTrFatal; //TgTrFatal; //TgTrAll;
43
44 void tr_etm_init(unsigned int mask)
45 {
46 ttr_mask = mask;
47 }
48
49
50 void tr_etm(unsigned int mask, char *format, ...)
51 {
52 va_list args;
53 static char buf[256];
54
55 if (ttr_mask & mask) {
56 // build string ala tr() then call str()
57 va_start(args, format);
58 vsprintf(buf, format, args);
59 trstr(mask, buf);
60 va_end(args);
61 }
62 }
63
64
65 void trstr(unsigned int mask, char *string)
66 {
67 if (ttr_mask & mask) {
68 rvf_send_trace(string, strlen(string), NULL_PARAM,
69 RV_TRACE_LEVEL_WARNING, ETM_USE_ID);
70 rvf_delay(10);
71 }
72 }
73
74
75 void tr_etm_hexdump(unsigned int mask, const void *p, int size)
76 {
77 unsigned int type, module;
78
79 if (!(ttr_mask & mask))
80 return;
81
82 hexdump_buf((char*) p, size);
83 }
84
85
86 /******************************************************************************
87 * Hexdumping Functions
88 *****************************************************************************/
89
90 void etm_trace(char *string, int level)
91 {
92 rvf_send_trace(string, strlen(string), NULL_PARAM, level, ETM_USE_ID);
93 rvf_delay(20);
94 }
95
96
97 int sprint_int_as_hex(char *buf, unsigned int n, int width, char padding)
98 {
99 unsigned int m = n; // MUST be unsigned because it will be right shifted
100 int size = 0;
101 int i;
102 char digit;
103 char *buf_start = buf;
104
105 // Count number of digits in <n>
106 do {
107 size++;
108 } while (m >>= 4);
109
110 // Shift significant part of <n> into the top-most bits
111 n <<= 4 * (8 - size);
112
113 // Pad output buffer with <padding>
114 if (0 < width && width <= 8) {
115 width = (width > size ? width - size : 0);
116 while (width--)
117 *buf++ = padding;
118 }
119
120 // Convert <n>, outputting the hex digits
121 for (i = 0; i < size; i++) {
122 digit = (n >> 28) & 0xF;
123 digit += (digit < 10 ? '0' : 'A' - 10);
124 *buf++ = digit;
125 n <<= 4;
126 }
127
128 // Null terminate
129 *buf = 0;
130
131 return buf - buf_start;
132 }
133
134 int printf_int_as_hex(unsigned int n, int width, char padding)
135 {
136 char string[8+1];
137 int length;
138
139 length = sprint_int_as_hex(string, n, width, padding);
140 etm_trace(string, RV_TRACE_LEVEL_DEBUG_LOW);
141
142 return length;
143 }
144
145
146 int print_int_as_hex(unsigned int n)
147 {
148 return printf_int_as_hex(n, 0, 0);
149 }
150
151
152 void hexdump_buf(char *buf, int size)
153 {
154 int n, i, multiline;
155 char string[(8+1) + (16+1) + (3*16) + 1];
156 char *s;
157
158 multiline = (size > 16);
159
160 while (size > 0)
161 {
162 s = string;
163 n = (size > 16 ? 16 : size);
164
165 // Print address
166 if (multiline) {
167 s += sprint_int_as_hex(s, (unsigned int) buf, 8, ' ');
168 *s++ = ' ';
169 }
170
171 // Print the textual representation
172 for (i = 0; i < n; i++)
173 *s++ = (buf[i] >= ' ' && buf[i] < 127 ? buf[i] : '.');
174
175 // Pad textual representation with spaces
176 if (multiline)
177 for (i = 0; i < 16 - n; i++)
178 *s++ = ' ';
179
180 // Print hexedecimal bytes
181 for (i = 0; i < n; i++) {
182 *s++ = ' ';
183 s += sprint_int_as_hex(s, (unsigned int) buf[i] & 0xFF, 2, '0');
184 }
185
186 *s = 0;
187
188 etm_trace(string, RV_TRACE_LEVEL_DEBUG_LOW);
189
190 buf += 16;
191 size -= 16;
192 }
193 }