FreeCalypso > hg > freecalypso-sw
comparison rvinterf/tmsh/etmbasic.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/etmbasic.c@c413e791595a |
children | 577291a2ad76 |
comparison
equal
deleted
inserted
replaced
259:35113b1964d3 | 260:c146f38d2b5f |
---|---|
1 /* | |
2 * Basic ETM interaction | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include <string.h> | |
8 #include <strings.h> | |
9 #include <stdlib.h> | |
10 #include "pktmux.h" | |
11 #include "limits.h" | |
12 #include "etm.h" | |
13 | |
14 extern u_char rvi_msg[]; | |
15 extern int rvi_msg_len; | |
16 | |
17 void | |
18 print_etm_pkt_raw(err) | |
19 char *err; | |
20 { | |
21 char buf[MAX_PKT_FROM_TARGET*3+80], *dp; | |
22 int i; | |
23 | |
24 sprintf(buf, "%s:", err); | |
25 dp = index(buf, '\0'); | |
26 for (i = 2; i < rvi_msg_len; i++) { | |
27 sprintf(dp, " %02X", rvi_msg[i]); | |
28 dp += 3; | |
29 } | |
30 async_msg_output(buf); | |
31 } | |
32 | |
33 void | |
34 etm_packet_rx() | |
35 { | |
36 int i, c; | |
37 | |
38 if (rvi_msg_len < 4) { | |
39 runt: print_etm_pkt_raw("ETM Runt"); | |
40 return; | |
41 } | |
42 c = 0; | |
43 for (i = 2; i < rvi_msg_len; i++) | |
44 c ^= rvi_msg[i]; | |
45 if (c) { | |
46 print_etm_pkt_raw("BAD CKSUM"); | |
47 return; | |
48 } | |
49 switch (rvi_msg[2]) { | |
50 case ETM_CORE: | |
51 if (rvi_msg_len < 6) | |
52 goto runt; | |
53 tmcore_msg_rx(); | |
54 return; | |
55 case ETM_FFS1: | |
56 print_etm_pkt_raw("FFS1"); | |
57 return; | |
58 case ETM_FFS2: | |
59 print_etm_pkt_raw("FFS2"); | |
60 return; | |
61 default: | |
62 print_etm_pkt_raw("ETM Unknown"); | |
63 } | |
64 } | |
65 | |
66 void | |
67 cmd_etmpkt(argc, argv) | |
68 char **argv; | |
69 { | |
70 u_char pkt[MAX_PKT_TO_TARGET]; | |
71 int di, c, b; | |
72 char **ap; | |
73 | |
74 pkt[0] = RVT_TM_HEADER; | |
75 di = 1; | |
76 c = 0; | |
77 for (ap = argv + 1; *ap; ap++) { | |
78 b = strtoul(*ap, 0, 16); | |
79 pkt[di++] = b; | |
80 c ^= b; | |
81 } | |
82 pkt[di++] = c; | |
83 send_pkt_to_target(pkt, di); | |
84 } | |
85 | |
86 void | |
87 send_etm_cmd(buf, len) | |
88 u_char *buf; | |
89 { | |
90 int i, c; | |
91 | |
92 buf[0] = RVT_TM_HEADER; | |
93 c = 0; | |
94 for (i = 1; i <= len; i++) | |
95 c ^= buf[i]; | |
96 buf[i] = c; | |
97 send_pkt_to_target(buf, len + 2); | |
98 } |