annotate rvinterf/libasync/interf.c @ 992:a7b0b426f9ca

target-utils: boot ROM UART autodetection revamped The new implementation should work with both the familiar Calypso C035 boot ROM version found in our regular targets as well as the older Calypso F741979B version found on the vintage D-Sample board.
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Wed, 30 Dec 2015 21:28:41 +0000
parents 40b8557b9d04
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
182
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module implements the link to rvinterf.
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdlib.h>
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <unistd.h>
260
c146f38d2b5f rvinterf subdir structure made a little more sensible
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 256
diff changeset
9 #include "localsock.h"
182
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 extern int sock;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 u_char rvi_msg[LOCALSOCK_MAX_MSG];
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 int rvi_msg_len;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 static int rx_state, rx_left;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 static u_char *rx_ptr;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 void
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 localsock_prep_for_length_rx()
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 rx_state = 0;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 rx_ptr = rvi_msg;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 rx_left = 2;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 }
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 static void
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 prep_for_message_rx()
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 rx_state = 1;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 rx_ptr = rvi_msg;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 rx_left = rvi_msg_len;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 }
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 void
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 process_msg_from_rvinterf()
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 {
183
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
38 switch (rvi_msg[0]) {
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
39 case RVI2CLI_PKT_FROM_TARGET:
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
40 process_pkt_from_target();
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
41 return;
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
42 case RVI2CLI_LOCAL_CMD_RESP:
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
43 if (rvi_msg_len < 2)
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
44 goto bad;
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
45 if (rvi_msg[1] == '+')
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
46 return;
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
47 tty_cleanup();
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
48 fprintf(stderr, "Error from rvinterf: %.*s\n", rvi_msg_len - 1,
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
49 rvi_msg + 1);
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
50 exit(1);
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
51 default:
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
52 bad:
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
53 tty_cleanup();
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
54 fprintf(stderr,
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
55 "Error: unexpected message type %02X from rvinterf\n",
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
56 rvi_msg[0]);
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
57 exit(1);
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
58 }
182
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 }
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 void
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 handle_rvinterf_input()
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 int cc;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 cc = read(sock, rx_ptr, rx_left);
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 if (cc <= 0) {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 tty_cleanup();
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 perror("read from rvinterf socket");
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 exit(1);
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 }
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 rx_ptr += cc;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 rx_left -= cc;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 if (rx_left)
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 return;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 /* got the thing, process it */
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 if (rx_state) {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 process_msg_from_rvinterf();
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 localsock_prep_for_length_rx();
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 } else {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 rvi_msg_len = rvi_msg[0] << 8 | rvi_msg[1];
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 if (rvi_msg_len < 1 || rvi_msg_len > LOCALSOCK_MAX_MSG) {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 tty_cleanup();
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 fprintf(stderr,
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 "Invalid length from rvinterf: %02X%02X\n",
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 rvi_msg[0], rvi_msg[1]);
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 exit(1);
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 }
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 prep_for_message_rx();
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 }
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 }
184
4714fdfca39c fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 183
diff changeset
92
4714fdfca39c fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 183
diff changeset
93 void
4714fdfca39c fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 183
diff changeset
94 send_pkt_to_target(pkt, pktlen)
4714fdfca39c fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 183
diff changeset
95 u_char *pkt;
4714fdfca39c fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 183
diff changeset
96 {
4714fdfca39c fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 183
diff changeset
97 u_char hdrbuf[3];
4714fdfca39c fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 183
diff changeset
98 int len1;
4714fdfca39c fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 183
diff changeset
99
4714fdfca39c fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 183
diff changeset
100 len1 = pktlen + 1;
4714fdfca39c fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 183
diff changeset
101 hdrbuf[0] = len1 >> 8;
4714fdfca39c fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 183
diff changeset
102 hdrbuf[1] = len1 & 0xFF;
4714fdfca39c fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 183
diff changeset
103 hdrbuf[2] = CLI2RVI_PKT_TO_TARGET;
4714fdfca39c fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 183
diff changeset
104 write(sock, hdrbuf, 3);
4714fdfca39c fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 183
diff changeset
105 write(sock, pkt, pktlen);
4714fdfca39c fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 183
diff changeset
106 }