annotate rvinterf/tmsh/bsimcmd.c @ 857:7fc16168c3d2

CHANGES: document l1trace-filter
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 09 Nov 2021 23:25:52 +0000
parents b3724fe6c581
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
816
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we are going to implement FreeCalypso BSIM
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * (battery simulation mode) commands.
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <string.h>
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <strings.h>
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "limits.h"
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "localtypes.h"
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "etm.h"
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "bsim_etm_cmd.h"
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "exitcodes.h"
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 cmd_bsim_query(argc, argv)
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 char **argv;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 {
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 u_char cmdpkt[4];
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 cmdpkt[1] = ETM_BSIM;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 cmdpkt[2] = BSIM_CMD_QUERY;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 send_etm_cmd(cmdpkt, 2);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 return(0);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 }
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 cmd_bsim_disch(argc, argv)
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 char **argv;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 {
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 u_char cmdpkt[5];
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 cmdpkt[1] = ETM_BSIM;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 cmdpkt[2] = BSIM_CMD_DISCHARGE;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 cmdpkt[3] = strtoul(argv[1], 0, 0);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 send_etm_cmd(cmdpkt, 3);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 return(0);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 cmd_bsim_start(argc, argv)
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 char **argv;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 {
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 u_char cmdpkt[4];
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 cmdpkt[1] = ETM_BSIM;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 cmdpkt[2] = BSIM_CMD_CHG_START;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 send_etm_cmd(cmdpkt, 2);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 return(0);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 cmd_bsim_start_enable(argc, argv)
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 char **argv;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 {
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 u_char cmdpkt[5];
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 cmdpkt[1] = ETM_BSIM;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 cmdpkt[2] = BSIM_CMD_START_ENABLE;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 cmdpkt[3] = strtoul(argv[1], 0, 0);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 send_etm_cmd(cmdpkt, 3);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return(0);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 cmd_bsim_ci2cv(argc, argv)
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 char **argv;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 {
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 u_char cmdpkt[4];
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 cmdpkt[1] = ETM_BSIM;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 cmdpkt[2] = BSIM_CMD_CHG_CI2CV;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 send_etm_cmd(cmdpkt, 2);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 return(0);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 }
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 cmd_bsim_complete(argc, argv)
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 char **argv;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 {
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 u_char cmdpkt[4];
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 cmdpkt[1] = ETM_BSIM;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 cmdpkt[2] = BSIM_CMD_CHG_COMPLETE;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 send_etm_cmd(cmdpkt, 2);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 return(0);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 }
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 cmd_bsim_ichg(argc, argv)
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 char **argv;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 {
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 u_char cmdpkt[6];
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 unsigned ichg;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 ichg = strtoul(argv[1], 0, 0);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 cmdpkt[1] = ETM_BSIM;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 cmdpkt[2] = BSIM_CMD_SET_ICHG;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 cmdpkt[3] = ichg;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 cmdpkt[4] = ichg >> 8;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 send_etm_cmd(cmdpkt, 4);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 return(0);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 }
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 static struct cmdtab {
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 char *cmd;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 int minargs;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 int maxargs;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 int (*func)();
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 } bsim_cmds[] = {
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 {"ci2cv", 0, 0, cmd_bsim_ci2cv},
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 {"complete", 0, 0, cmd_bsim_complete},
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 {"disch", 1, 1, cmd_bsim_disch},
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 {"ichg", 1, 1, cmd_bsim_ichg},
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 {"query", 0, 0, cmd_bsim_query},
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 {"start", 0, 0, cmd_bsim_start},
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 {"start-enable", 1, 1, cmd_bsim_start_enable},
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 {0, 0, 0, 0}
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 };
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 cmd_bsim(argc, argv)
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 char **argv;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 {
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 struct cmdtab *tp;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 int extargs;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 for (tp = bsim_cmds; tp->cmd; tp++)
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 if (!strcmp(tp->cmd, argv[1]))
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 break;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 if (!tp->func) {
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 printf("error: no such bsim command\n");
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 return(ERROR_USAGE);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 }
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 extargs = argc - 2;
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 if (extargs > tp->maxargs) {
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 printf("error: too many arguments\n");
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 return(ERROR_USAGE);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 }
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 if (extargs < tp->minargs) {
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 printf("error: too few arguments\n");
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 return(ERROR_USAGE);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 }
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 return tp->func(argc - 1, argv + 1);
b3724fe6c581 fc-tmsh bsim commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 }