comparison rvinterf/tmsh/tmcore.c @ 260:c146f38d2b5f

rvinterf subdir structure made a little more sensible
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 05 Feb 2014 04:02:13 +0000
parents rvinterf/etm/tmcore.c@2f285f20d617
children
comparison
equal deleted inserted replaced
259:35113b1964d3 260:c146f38d2b5f
1 /*
2 * In this module we are going to implement commands which send requests
3 * to ETM_CORE and the handling of responses from that target module.
4 */
5
6 #include <sys/types.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <strings.h>
10 #include <stdlib.h>
11 #include "pktmux.h"
12 #include "limits.h"
13 #include "localtypes.h"
14 #include "etm.h"
15
16 extern u_char rvi_msg[];
17 extern int rvi_msg_len;
18
19 static void
20 rw8_response()
21 {
22 char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
23 int num, i;
24
25 if (rvi_msg[3]) {
26 print_etm_pkt_raw("rw8 error");
27 return;
28 }
29 num = rvi_msg_len - 7;
30 if (!num) {
31 async_msg_output("w8 OK");
32 return;
33 }
34 strcpy(buf, "r8:");
35 dp = buf + 3;
36 for (i = 0; i < num; i++) {
37 sprintf(dp, " %02X", rvi_msg[i+6]);
38 dp += 3;
39 }
40 async_msg_output(buf);
41 }
42
43 static void
44 rw16_response()
45 {
46 char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
47 int num, i, d, off;
48
49 if (rvi_msg[3]) {
50 print_etm_pkt_raw("rw16 error");
51 return;
52 }
53 num = rvi_msg_len - 7;
54 if (!num) {
55 async_msg_output("w16 OK");
56 return;
57 }
58 if (num & 1) {
59 print_etm_pkt_raw("rw16 malformed resp");
60 return;
61 }
62 num >>= 1;
63 strcpy(buf, "r16:");
64 dp = buf + 4;
65 off = 6;
66 for (i = 0; i < num; i++) {
67 d = rvi_msg[off] | rvi_msg[off+1] << 8;
68 off += 2;
69 sprintf(dp, " %04X", d);
70 dp += 5;
71 }
72 async_msg_output(buf);
73 }
74
75 static void
76 rw32_response()
77 {
78 char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
79 int num, i, d, off;
80
81 if (rvi_msg[3]) {
82 print_etm_pkt_raw("rw32 error");
83 return;
84 }
85 num = rvi_msg_len - 7;
86 if (!num) {
87 async_msg_output("w32 OK");
88 return;
89 }
90 if (num & 3) {
91 print_etm_pkt_raw("rw32 malformed resp");
92 return;
93 }
94 num >>= 2;
95 strcpy(buf, "r32:");
96 dp = buf + 4;
97 off = 6;
98 for (i = 0; i < num; i++) {
99 d = rvi_msg[off] | rvi_msg[off+1] << 8 | rvi_msg[off+2] << 16
100 | rvi_msg[off+3] << 24;
101 off += 4;
102 sprintf(dp, " %08X", d);
103 dp += 9;
104 }
105 async_msg_output(buf);
106 }
107
108 static void
109 dieid_response()
110 {
111 char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
112 int num, i;
113
114 if (rvi_msg[3]) {
115 print_etm_pkt_raw("dieid error");
116 return;
117 }
118 num = rvi_msg_len - 6;
119 strcpy(buf, "dieid resp:");
120 dp = buf + 11;
121 for (i = 0; i < num; i++) {
122 sprintf(dp, " %02X", rvi_msg[i+5]);
123 dp += 3;
124 }
125 async_msg_output(buf);
126 }
127
128 static void
129 echo_response()
130 {
131 if (rvi_msg[3])
132 print_etm_pkt_raw("echo error");
133 else
134 print_etm_pkt_raw("echo resp");
135 }
136
137 static void
138 version_response()
139 {
140 char buf[80];
141
142 if (rvi_msg[3]) {
143 print_etm_pkt_raw("version error");
144 return;
145 }
146 if (rvi_msg_len != 10) {
147 print_etm_pkt_raw("version malformed resp");
148 return;
149 }
150 sprintf(buf, "version resp: %02X%02X%02X%02X", rvi_msg[8], rvi_msg[7],
151 rvi_msg[6], rvi_msg[5]);
152 async_msg_output(buf);
153 }
154
155 void
156 tmcore_msg_rx()
157 {
158 switch (rvi_msg[4]) {
159 case TMCORE_OPC_MEM:
160 if (rvi_msg_len < 7)
161 goto unknown;
162 switch (rvi_msg[5]) {
163 case 0x00:
164 case 0x04:
165 rw32_response();
166 return;
167 case 0x01:
168 rw8_response();
169 return;
170 case 0x02:
171 rw16_response();
172 return;
173 default:
174 goto unknown;
175 }
176 case TMCORE_OPC_ECHO:
177 echo_response();
178 return;
179 case TMCORE_OPC_VERSION:
180 version_response();
181 return;
182 case TMCORE_OPC_CODEC_RD:
183 abbr_response();
184 return;
185 case TMCORE_OPC_CODEC_WR:
186 abbw_response();
187 return;
188 case TMCORE_OPC_DIEID:
189 dieid_response();
190 return;
191 default:
192 unknown:
193 print_etm_pkt_raw("ETM_CORE resp");
194 }
195 }
196
197 void
198 cmd_r8(argc, argv)
199 char **argv;
200 {
201 u32 addr;
202 int count;
203 u_char cmdpkt[10];
204
205 addr = strtoul(argv[1], 0, 16);
206 if (argv[2])
207 count = strtoul(argv[2], 0, 0);
208 else
209 count = 1;
210 if (count < 1 || count > 253) {
211 printf("error: count argument outside valid range\n");
212 return;
213 }
214 cmdpkt[1] = ETM_CORE;
215 cmdpkt[2] = TMCORE_OPC_MEM;
216 cmdpkt[3] = 0x01;
217 cmdpkt[4] = count;
218 cmdpkt[5] = addr;
219 cmdpkt[6] = addr >> 8;
220 cmdpkt[7] = addr >> 16;
221 cmdpkt[8] = addr >> 24;
222 send_etm_cmd(cmdpkt, 8);
223 }
224
225 void
226 cmd_r16(argc, argv)
227 char **argv;
228 {
229 u32 addr;
230 int count;
231 u_char cmdpkt[10];
232
233 addr = strtoul(argv[1], 0, 16);
234 if (argv[2])
235 count = strtoul(argv[2], 0, 0);
236 else
237 count = 1;
238 if (addr & 1) {
239 printf("error: address not aligned\n");
240 return;
241 }
242 if (count < 1 || count > 126) {
243 printf("error: count argument outside valid range\n");
244 return;
245 }
246 cmdpkt[1] = ETM_CORE;
247 cmdpkt[2] = TMCORE_OPC_MEM;
248 cmdpkt[3] = 0x02;
249 cmdpkt[4] = count;
250 cmdpkt[5] = addr;
251 cmdpkt[6] = addr >> 8;
252 cmdpkt[7] = addr >> 16;
253 cmdpkt[8] = addr >> 24;
254 send_etm_cmd(cmdpkt, 8);
255 }
256
257 void
258 cmd_r32(argc, argv)
259 char **argv;
260 {
261 u32 addr;
262 int count;
263 u_char cmdpkt[10];
264
265 addr = strtoul(argv[1], 0, 16);
266 if (argv[2])
267 count = strtoul(argv[2], 0, 0);
268 else
269 count = 1;
270 if (addr & 3) {
271 printf("error: address not aligned\n");
272 return;
273 }
274 if (count < 1 || count > 63) {
275 printf("error: count argument outside valid range\n");
276 return;
277 }
278 cmdpkt[1] = ETM_CORE;
279 cmdpkt[2] = TMCORE_OPC_MEM;
280 cmdpkt[3] = 0x04;
281 cmdpkt[4] = count;
282 cmdpkt[5] = addr;
283 cmdpkt[6] = addr >> 8;
284 cmdpkt[7] = addr >> 16;
285 cmdpkt[8] = addr >> 24;
286 send_etm_cmd(cmdpkt, 8);
287 }
288
289 void
290 cmd_w8(argc, argv)
291 char **argv;
292 {
293 u32 addr, v;
294 u_char cmdpkt[MAX_PKT_TO_TARGET];
295 int di;
296 char **ap;
297
298 addr = strtoul(argv[1], 0, 16);
299 cmdpkt[1] = ETM_CORE;
300 cmdpkt[2] = TMCORE_OPC_MEM;
301 cmdpkt[3] = 0x11;
302 cmdpkt[4] = argc - 2;
303 cmdpkt[5] = addr;
304 cmdpkt[6] = addr >> 8;
305 cmdpkt[7] = addr >> 16;
306 cmdpkt[8] = addr >> 24;
307 di = 9;
308 for (ap = argv + 2; *ap; ap++) {
309 v = strtoul(*ap, 0, 16);
310 cmdpkt[di++] = v;
311 }
312 send_etm_cmd(cmdpkt, di - 1);
313 }
314
315 void
316 cmd_w16(argc, argv)
317 char **argv;
318 {
319 u32 addr, v;
320 u_char cmdpkt[MAX_PKT_TO_TARGET];
321 int di;
322 char **ap;
323
324 addr = strtoul(argv[1], 0, 16);
325 if (addr & 1) {
326 printf("error: address not aligned\n");
327 return;
328 }
329 cmdpkt[1] = ETM_CORE;
330 cmdpkt[2] = TMCORE_OPC_MEM;
331 cmdpkt[3] = 0x12;
332 cmdpkt[4] = argc - 2;
333 cmdpkt[5] = addr;
334 cmdpkt[6] = addr >> 8;
335 cmdpkt[7] = addr >> 16;
336 cmdpkt[8] = addr >> 24;
337 di = 9;
338 for (ap = argv + 2; *ap; ap++) {
339 v = strtoul(*ap, 0, 16);
340 cmdpkt[di++] = v;
341 cmdpkt[di++] = v >> 8;
342 }
343 send_etm_cmd(cmdpkt, di - 1);
344 }
345
346 void
347 cmd_w32(argc, argv)
348 char **argv;
349 {
350 u32 addr, v;
351 u_char cmdpkt[MAX_PKT_TO_TARGET];
352 int di;
353 char **ap;
354
355 addr = strtoul(argv[1], 0, 16);
356 if (addr & 3) {
357 printf("error: address not aligned\n");
358 return;
359 }
360 cmdpkt[1] = ETM_CORE;
361 cmdpkt[2] = TMCORE_OPC_MEM;
362 cmdpkt[3] = 0x14;
363 cmdpkt[4] = argc - 2;
364 cmdpkt[5] = addr;
365 cmdpkt[6] = addr >> 8;
366 cmdpkt[7] = addr >> 16;
367 cmdpkt[8] = addr >> 24;
368 di = 9;
369 for (ap = argv + 2; *ap; ap++) {
370 v = strtoul(*ap, 0, 16);
371 cmdpkt[di++] = v;
372 cmdpkt[di++] = v >> 8;
373 cmdpkt[di++] = v >> 16;
374 cmdpkt[di++] = v >> 24;
375 }
376 send_etm_cmd(cmdpkt, di - 1);
377 }
378
379 void
380 cmd_dieid(argc, argv)
381 char **argv;
382 {
383 u_char cmdpkt[4];
384
385 cmdpkt[1] = ETM_CORE;
386 cmdpkt[2] = TMCORE_OPC_DIEID;
387 send_etm_cmd(cmdpkt, 2);
388 }
389
390 void
391 cmd_ping(argc, argv)
392 char **argv;
393 {
394 int delay, size;
395 u_char cmdpkt[8];
396
397 if (argc > 1) {
398 delay = strtoul(argv[1], 0, 0);
399 if (delay > 65535) {
400 printf("error: ping delay argument too big\n");
401 return;
402 }
403 } else
404 delay = 0;
405 if (argc > 2) {
406 size = strtoul(argv[2], 0, 0);
407 if (size > 240) {
408 printf("error: ping size argument too big\n");
409 return;
410 }
411 } else
412 size = 1;
413 cmdpkt[1] = ETM_CORE;
414 cmdpkt[2] = TMCORE_OPC_ECHO;
415 cmdpkt[3] = delay;
416 cmdpkt[4] = delay >> 8;
417 cmdpkt[5] = size;
418 cmdpkt[6] = size >> 8;
419 send_etm_cmd(cmdpkt, 6);
420 }
421
422 void
423 cmd_tgtreset(argc, argv)
424 char **argv;
425 {
426 u_char cmdpkt[4];
427
428 cmdpkt[1] = ETM_CORE;
429 cmdpkt[2] = TMCORE_OPC_RESET;
430 send_etm_cmd(cmdpkt, 2);
431 }
432
433 void
434 cmd_version(argc, argv)
435 char **argv;
436 {
437 u32 arg;
438 u_char cmdpkt[8];
439
440 arg = strtoul(argv[1], 0, 16);
441 cmdpkt[1] = ETM_CORE;
442 cmdpkt[2] = TMCORE_OPC_VERSION;
443 cmdpkt[3] = arg;
444 cmdpkt[4] = arg >> 8;
445 cmdpkt[5] = arg >> 16;
446 cmdpkt[6] = arg >> 24;
447 send_etm_cmd(cmdpkt, 6);
448 }