FreeCalypso > hg > freecalypso-hwlab
annotate lcdtest/interf.c @ 106:66f04193a906
fc-simtool: pb-dump: forgot newline at the end of record
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 25 Jan 2021 06:03:58 +0000 |
parents | de3d3cfcbb35 |
children |
rev | line source |
---|---|
28
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we implement our synchronous interface to the target |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * via rvinterf. |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <unistd.h> |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <rvinterf/limits.h> |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <rvinterf/localsock.h> |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <rvinterf/pktmux.h> |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "exitcodes.h" |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 extern int sock; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 int rx_enable_state; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 u_char rvi_msg[LOCALSOCK_MAX_MSG]; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 int rvi_msg_len; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 static void |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 collect_bytes_from_rvi(buf, nbytes) |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 u_char *buf; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 int cc; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 while (nbytes) { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 cc = read(sock, buf, nbytes); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (cc <= 0) { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 perror("read from rvinterf socket"); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 exit(ERROR_RVINTERF); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 buf += cc; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 nbytes -= cc; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 collect_rvi_msg() |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 u_char lenbuf[2]; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 collect_bytes_from_rvi(lenbuf, 2); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 rvi_msg_len = lenbuf[0] << 8 | lenbuf[1]; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (rvi_msg_len < 1 || rvi_msg_len > LOCALSOCK_MAX_MSG) { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 fprintf(stderr, "Invalid length from rvinterf: %02X%02X\n", |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 lenbuf[0], lenbuf[1]); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 exit(ERROR_RVINTERF); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 collect_bytes_from_rvi(rvi_msg, rvi_msg_len); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 return(0); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 send_rvimisc_command(cmdpkt, cmdlen) |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 u_char *cmdpkt; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 u_char lenbuf[2]; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 lenbuf[0] = 0; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 lenbuf[1] = cmdlen; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 write(sock, lenbuf, 2); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 write(sock, cmdpkt, cmdlen); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 rx_control(enable) |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 u_char cmdpkt[2]; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 int cmdlen; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 /* are we already in the desired state? */ |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (rx_enable_state == enable) |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 return(0); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 /* no, do the work */ |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 if (enable) { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 cmdpkt[0] = CLI2RVI_WANT_MUXPROTO; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 cmdpkt[1] = RVT_TM_HEADER; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 cmdlen = 2; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 } else { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 cmdpkt[0] = CLI2RVI_RESET_PACKET_RX; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 cmdlen = 1; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 send_rvimisc_command(cmdpkt, cmdlen); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 collect_rvi_msg(); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 if (rvi_msg[0] != RVI2CLI_LOCAL_CMD_RESP || rvi_msg_len < 2) { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 fprintf(stderr, |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 "error: unexpected response to rvinterf local command\n"); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 exit(ERROR_RVINTERF); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 if (rvi_msg[1] != '+') { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 fprintf(stderr, "Error from rvinterf: %.*s\n", rvi_msg_len - 1, |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 rvi_msg + 1); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 exit(ERROR_RVINTERF); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 rx_enable_state = enable; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 return(0); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 send_pkt_to_target(pkt, pktlen) |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 u_char *pkt; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 u_char hdrbuf[3]; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 int len1; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 len1 = pktlen + 1; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 hdrbuf[0] = len1 >> 8; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 hdrbuf[1] = len1 & 0xFF; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 hdrbuf[2] = CLI2RVI_PKT_TO_TARGET; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 write(sock, hdrbuf, 3); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 write(sock, pkt, pktlen); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 target_pkt_exch(outpkt, outpktlen) |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 u_char *outpkt; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 rx_control(1); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 send_pkt_to_target(outpkt, outpktlen); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 collect_rvi_msg(); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 if (rvi_msg[0] != RVI2CLI_PKT_FROM_TARGET) { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 fprintf(stderr, |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 "error: unexpected response type from rvinterf\n"); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 exit(ERROR_RVINTERF); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 return(0); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 etm_pkt_exch(outbuf, outlen) |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 u_char *outbuf; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 int i, c; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 outbuf[0] = RVT_TM_HEADER; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 c = 0; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 for (i = 1; i <= outlen; i++) |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 c ^= outbuf[i]; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 outbuf[i] = c; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 target_pkt_exch(outbuf, outlen + 2); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 if (rvi_msg[1] != RVT_TM_HEADER) { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 printf("error: packet from target is not ETM!\n"); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 return(ERROR_TARGET); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 if (rvi_msg_len < 5) { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 printf("error: ETM response packet is too short\n"); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 return(ERROR_TARGET); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 c = 0; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 for (i = 2; i < rvi_msg_len; i++) |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 c ^= rvi_msg[i]; |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 if (c) { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 printf("ETM response checksum error!\n"); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 return(ERROR_TARGET); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 if (rvi_msg[2] != outbuf[1]) { |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 printf("error: target response is from wrong ETM component\n"); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 return(ERROR_TARGET); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 } |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 return(0); |
de3d3cfcbb35
lcdtest: lcdphone program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 } |