FreeCalypso > hg > freecalypso-tools
comparison rvinterf/tmsh/etmbasic.c @ 0:e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 11 Jun 2016 00:13:35 +0000 |
parents | |
children | 585f63e5bca6 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7502631a0f9 |
---|---|
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 #include "tm3.h" | |
14 | |
15 extern u_char rvi_msg[]; | |
16 extern int rvi_msg_len; | |
17 | |
18 void | |
19 print_etm_pkt_raw(err) | |
20 char *err; | |
21 { | |
22 char buf[MAX_PKT_FROM_TARGET*3+80], *dp; | |
23 int i; | |
24 | |
25 sprintf(buf, "%s:", err); | |
26 dp = index(buf, '\0'); | |
27 for (i = 2; i < rvi_msg_len; i++) { | |
28 sprintf(dp, " %02X", rvi_msg[i]); | |
29 dp += 3; | |
30 } | |
31 async_msg_output(buf); | |
32 } | |
33 | |
34 void | |
35 etm_packet_rx() | |
36 { | |
37 int i, c; | |
38 | |
39 if (rvi_msg_len < 4) { | |
40 runt: print_etm_pkt_raw("TM runt"); | |
41 return; | |
42 } | |
43 c = 0; | |
44 for (i = 2; i < rvi_msg_len; i++) | |
45 c ^= rvi_msg[i]; | |
46 if (c) { | |
47 print_etm_pkt_raw("BAD CKSUM"); | |
48 return; | |
49 } | |
50 switch (rvi_msg[2]) { | |
51 case ETM_CORE: | |
52 if (rvi_msg_len < 6) | |
53 goto runt; | |
54 tmcore_msg_rx(); | |
55 return; | |
56 case ETM_FFS1: | |
57 print_etm_pkt_raw("FFS1"); | |
58 return; | |
59 case ETM_FFS2: | |
60 if (rvi_msg_len < 5) | |
61 goto runt; | |
62 handle_ffs2_response(); | |
63 return; | |
64 /* TM3 */ | |
65 case MEM_READ: | |
66 if (rvi_msg_len < 5) | |
67 goto runt; | |
68 handle_omr_response(); | |
69 return; | |
70 default: | |
71 print_etm_pkt_raw("TM unknown"); | |
72 } | |
73 } | |
74 | |
75 void | |
76 cmd_etmpkt(argc, argv) | |
77 char **argv; | |
78 { | |
79 u_char pkt[MAX_PKT_TO_TARGET]; | |
80 int di, c, b; | |
81 char **ap; | |
82 | |
83 pkt[0] = RVT_TM_HEADER; | |
84 di = 1; | |
85 c = 0; | |
86 for (ap = argv + 1; *ap; ap++) { | |
87 b = strtoul(*ap, 0, 16); | |
88 pkt[di++] = b; | |
89 c ^= b; | |
90 } | |
91 pkt[di++] = c; | |
92 send_pkt_to_target(pkt, di); | |
93 } | |
94 | |
95 void | |
96 send_etm_cmd(buf, len) | |
97 u_char *buf; | |
98 { | |
99 int i, c; | |
100 | |
101 buf[0] = RVT_TM_HEADER; | |
102 c = 0; | |
103 for (i = 1; i <= len; i++) | |
104 c ^= buf[i]; | |
105 buf[i] = c; | |
106 send_pkt_to_target(buf, len + 2); | |
107 } |