FreeCalypso > hg > freecalypso-sw
comparison rvinterf/etm/tmcore.c @ 188:9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Mon, 25 Nov 2013 02:11:47 +0000 |
parents | |
children | a95d253ef952 |
comparison
equal
deleted
inserted
replaced
187:f5f8776f7c66 | 188:9f4f331ac24d |
---|---|
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 "etm.h" | |
14 | |
15 extern u_char rvi_msg[]; | |
16 extern int rvi_msg_len; | |
17 | |
18 static void | |
19 r8_response() | |
20 { | |
21 char buf[MAX_PKT_FROM_TARGET*3+80], *dp; | |
22 int num, i; | |
23 | |
24 if (rvi_msg[3]) { | |
25 print_etm_pkt_raw("r8 error"); | |
26 return; | |
27 } | |
28 num = rvi_msg_len - 7; | |
29 strcpy(buf, "r8:"); | |
30 dp = buf + 3; | |
31 for (i = 0; i < num; i++) { | |
32 sprintf(dp, " %02X", rvi_msg[i+6]); | |
33 dp += 3; | |
34 } | |
35 async_msg_output(buf); | |
36 } | |
37 | |
38 static void | |
39 r16_response() | |
40 { | |
41 char buf[MAX_PKT_FROM_TARGET*3+80], *dp; | |
42 int num, i, d, off; | |
43 | |
44 if (rvi_msg[3]) { | |
45 print_etm_pkt_raw("r16 error"); | |
46 return; | |
47 } | |
48 num = rvi_msg_len - 7; | |
49 if (num & 1) { | |
50 print_etm_pkt_raw("r16 malformed resp"); | |
51 return; | |
52 } | |
53 num >>= 1; | |
54 strcpy(buf, "r16:"); | |
55 dp = buf + 4; | |
56 off = 6; | |
57 for (i = 0; i < num; i++) { | |
58 d = rvi_msg[off] | rvi_msg[off+1] << 8; | |
59 off += 2; | |
60 sprintf(dp, " %04X", d); | |
61 dp += 5; | |
62 } | |
63 async_msg_output(buf); | |
64 } | |
65 | |
66 static void | |
67 r32_response() | |
68 { | |
69 char buf[MAX_PKT_FROM_TARGET*3+80], *dp; | |
70 int num, i, d, off; | |
71 | |
72 if (rvi_msg[3]) { | |
73 print_etm_pkt_raw("r32 error"); | |
74 return; | |
75 } | |
76 num = rvi_msg_len - 7; | |
77 if (num & 3) { | |
78 print_etm_pkt_raw("r32 malformed resp"); | |
79 return; | |
80 } | |
81 num >>= 2; | |
82 strcpy(buf, "r32:"); | |
83 dp = buf + 4; | |
84 off = 6; | |
85 for (i = 0; i < num; i++) { | |
86 d = rvi_msg[off] | rvi_msg[off+1] << 8 | rvi_msg[off+2] << 16 | |
87 | rvi_msg[off+3]; | |
88 off += 4; | |
89 sprintf(dp, " %08X", d); | |
90 dp += 9; | |
91 } | |
92 async_msg_output(buf); | |
93 } | |
94 | |
95 static void | |
96 dieid_response() | |
97 { | |
98 char buf[MAX_PKT_FROM_TARGET*3+80], *dp; | |
99 int num, i; | |
100 | |
101 if (rvi_msg[3]) { | |
102 print_etm_pkt_raw("dieid error"); | |
103 return; | |
104 } | |
105 num = rvi_msg_len - 6; | |
106 strcpy(buf, "dieid resp:"); | |
107 dp = buf + 3; | |
108 for (i = 0; i < num; i++) { | |
109 sprintf(dp, " %02X", rvi_msg[i+5]); | |
110 dp += 3; | |
111 } | |
112 async_msg_output(buf); | |
113 } | |
114 | |
115 static void | |
116 echo_response() | |
117 { | |
118 if (rvi_msg[3]) | |
119 print_etm_pkt_raw("echo error"); | |
120 else | |
121 print_etm_pkt_raw("echo resp"); | |
122 } | |
123 | |
124 static void | |
125 version_response() | |
126 { | |
127 char buf[80]; | |
128 | |
129 if (rvi_msg[3]) { | |
130 print_etm_pkt_raw("version error"); | |
131 return; | |
132 } | |
133 if (rvi_msg_len != 10) { | |
134 print_etm_pkt_raw("version malformed resp"); | |
135 return; | |
136 } | |
137 sprintf(buf, "version resp: %02X%02X%02X%02X", rvi_msg[8], rvi_msg[7], | |
138 rvi_msg[6], rvi_msg[5]); | |
139 async_msg_output(buf); | |
140 } | |
141 | |
142 void | |
143 tmcore_msg_rx() | |
144 { | |
145 switch (rvi_msg[4]) { | |
146 case TMCORE_OPC_MEM: | |
147 if (rvi_msg_len < 7) | |
148 goto unknown; | |
149 switch (rvi_msg[5]) { | |
150 case 0x00: | |
151 case 0x04: | |
152 r32_response(); | |
153 return; | |
154 case 0x01: | |
155 r8_response(); | |
156 return; | |
157 case 0x02: | |
158 r16_response(); | |
159 return; | |
160 default: | |
161 goto unknown; | |
162 } | |
163 case TMCORE_OPC_ECHO: | |
164 echo_response(); | |
165 return; | |
166 case TMCORE_OPC_VERSION: | |
167 version_response(); | |
168 return; | |
169 case TMCORE_OPC_CODEC_RD: | |
170 case TMCORE_OPC_CODEC_WR: | |
171 /* not yet implemented */ | |
172 goto unknown; | |
173 case TMCORE_OPC_DIEID: | |
174 dieid_response(); | |
175 return; | |
176 default: | |
177 unknown: | |
178 print_etm_pkt_raw("ETM_CORE resp"); | |
179 } | |
180 } |