annotate rvinterf/tmsh/bsimresp.c @ 936:f4e6f6b6548e

rvinterf TM log: decode ETM_CORE commands
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 24 May 2023 04:00:18 +0000
parents 9706832b740b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
817
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Handling of ETM_BSIM responses (FreeCalypso addition to fw)
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include "bsim_etm_cmd.h"
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 extern u_char rvi_msg[];
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 extern int rvi_msg_len;
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 static char *cmd_names[] = {
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 "query", "disch", "start", "ci2cv", "complete", "ichg", "start-enable"
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 };
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 static void
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 handle_bsim_error()
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 char *errstr;
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 char msg[80];
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (rvi_msg_len != 6) {
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 print_etm_pkt_raw("ETM_BSIM long error packet");
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 return;
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 }
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 switch (rvi_msg[3]) {
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 case BSIM_ERR_BAD_CMD:
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 errstr = "bad command opcode";
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 break;
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 case BSIM_ERR_WRONG_STATE:
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 errstr = "wrong state";
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 break;
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 case BSIM_ERR_INV_PERCENT:
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 errstr = "invalid percent";
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 break;
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 case BSIM_ERR_INV_DISCHARGE:
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 errstr = "invalid discharge";
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 break;
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 default:
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 errstr = "unknown";
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 }
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 sprintf(msg, "bsim %s error 0x%02X (%s)", cmd_names[rvi_msg[4]],
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 rvi_msg[3], errstr);
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 async_msg_output(msg);
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 void
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 handle_bsim_response()
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 {
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 char msg[80];
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (rvi_msg_len == 5 && rvi_msg[3] == 0x3C) {
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 async_msg_output("bsim: ETM_NOSYS response");
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 return;
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (rvi_msg_len < 6) {
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 print_etm_pkt_raw("ETM_BSIM response too short");
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 return;
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (rvi_msg[4] > BSIM_CMD_START_ENABLE) {
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 print_etm_pkt_raw("ETM_BSIM unknown opcode");
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 return;
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (rvi_msg[3]) {
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 handle_bsim_error();
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 return;
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (rvi_msg_len == 6) {
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 sprintf(msg, "bsim %s OK", cmd_names[rvi_msg[4]]);
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 async_msg_output(msg);
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 return;
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 }
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 if (rvi_msg[4] == BSIM_CMD_QUERY && rvi_msg_len == 9) {
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 sprintf(msg, "bsim: state=%u percent=%u start_enable=%u",
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 rvi_msg[5], rvi_msg[6], rvi_msg[7]);
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 async_msg_output(msg);
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 return;
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 print_etm_pkt_raw("ETM_BSIM response wrong length");
9706832b740b fc-tmsh: ETM_BSIM response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 }