1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
/*
* Copyright (C) 2019-2020 by Marc Schink <dev@zapb.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <helper/log.h>
#include <target/rtt.h>
#include "rtt.h"
#define CHANNEL_NAME_SIZE 128
COMMAND_HANDLER(handle_rtt_setup_command)
{
struct rtt_source source;
if (CMD_ARGC != 3)
return ERROR_COMMAND_SYNTAX_ERROR;
source.find_cb = &target_rtt_find_control_block;
source.read_cb = &target_rtt_read_control_block;
source.start = &target_rtt_start;
source.stop = &target_rtt_stop;
source.read = &target_rtt_read_callback;
source.write = &target_rtt_write_callback;
source.read_channel_info = &target_rtt_read_channel_info;
target_addr_t address;
uint32_t size;
COMMAND_PARSE_NUMBER(target_addr, CMD_ARGV[0], address);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], size);
rtt_register_source(source, get_current_target(CMD_CTX));
if (rtt_setup(address, size, CMD_ARGV[2]) != ERROR_OK)
return ERROR_FAIL;
return ERROR_OK;
}
COMMAND_HANDLER(handle_rtt_start_command)
{
if (CMD_ARGC > 0)
return ERROR_COMMAND_SYNTAX_ERROR;
if (!rtt_configured()) {
command_print(CMD, "RTT is not configured");
return ERROR_FAIL;
}
return rtt_start();
}
COMMAND_HANDLER(handle_rtt_stop_command)
{
if (CMD_ARGC > 0)
return ERROR_COMMAND_SYNTAX_ERROR;
return rtt_stop();
}
COMMAND_HANDLER(handle_rtt_polling_interval_command)
{
if (CMD_ARGC == 0) {
int ret;
unsigned int interval;
ret = rtt_get_polling_interval(&interval);
if (ret != ERROR_OK) {
command_print(CMD, "Failed to get polling interval");
return ret;
}
command_print(CMD, "%u ms", interval);
} else if (CMD_ARGC == 1) {
int ret;
unsigned int interval;
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], interval);
ret = rtt_set_polling_interval(interval);
if (ret != ERROR_OK) {
command_print(CMD, "Failed to set polling interval");
return ret;
}
} else {
return ERROR_COMMAND_SYNTAX_ERROR;
}
return ERROR_OK;
}
COMMAND_HANDLER(handle_rtt_channels_command)
{
int ret;
char channel_name[CHANNEL_NAME_SIZE];
const struct rtt_control *ctrl;
struct rtt_channel_info info;
if (!rtt_found_cb()) {
command_print(CMD, "rtt: Control block not available");
return ERROR_FAIL;
}
ctrl = rtt_get_control();
command_print(CMD, "Channels: up=%u, down=%u", ctrl->num_up_channels,
ctrl->num_down_channels);
command_print(CMD, "Up-channels:");
info.name = channel_name;
info.name_length = sizeof(channel_name);
for (unsigned int i = 0; i < ctrl->num_up_channels; i++) {
ret = rtt_read_channel_info(i, RTT_CHANNEL_TYPE_UP, &info);
if (ret != ERROR_OK)
return ret;
if (!info.size)
continue;
command_print(CMD, "%u: %s %u %u", i, info.name, info.size,
info.flags);
}
command_print(CMD, "Down-channels:");
for (unsigned int i = 0; i < ctrl->num_down_channels; i++) {
ret = rtt_read_channel_info(i, RTT_CHANNEL_TYPE_DOWN, &info);
if (ret != ERROR_OK)
return ret;
if (!info.size)
continue;
command_print(CMD, "%u: %s %u %u", i, info.name, info.size,
info.flags);
}
return ERROR_OK;
}
static int jim_channel_list(Jim_Interp *interp, int argc,
Jim_Obj * const *argv)
{
Jim_Obj *list;
Jim_Obj *channel_list;
char channel_name[CHANNEL_NAME_SIZE];
const struct rtt_control *ctrl;
struct rtt_channel_info info;
if (!rtt_found_cb()) {
Jim_SetResultFormatted(interp, "rtt: Control block not available");
return ERROR_FAIL;
}
ctrl = rtt_get_control();
info.name = channel_name;
info.name_length = sizeof(channel_name);
list = Jim_NewListObj(interp, NULL, 0);
channel_list = Jim_NewListObj(interp, NULL, 0);
for (unsigned int i = 0; i < ctrl->num_up_channels; i++) {
int ret;
Jim_Obj *tmp;
ret = rtt_read_channel_info(i, RTT_CHANNEL_TYPE_UP, &info);
if (ret != ERROR_OK)
return ret;
if (!info.size)
continue;
tmp = Jim_NewListObj(interp, NULL, 0);
Jim_ListAppendElement(interp, tmp, Jim_NewStringObj(interp,
"name", -1));
Jim_ListAppendElement(interp, tmp, Jim_NewStringObj(interp,
info.name, -1));
Jim_ListAppendElement(interp, tmp, Jim_NewStringObj(interp,
"size", -1));
Jim_ListAppendElement(interp, tmp, Jim_NewIntObj(interp,
info.size));
Jim_ListAppendElement(interp, tmp, Jim_NewStringObj(interp,
"flags", -1));
Jim_ListAppendElement(interp, tmp, Jim_NewIntObj(interp,
info.flags));
Jim_ListAppendElement(interp, channel_list, tmp);
}
Jim_ListAppendElement(interp, list, channel_list);
channel_list = Jim_NewListObj(interp, NULL, 0);
for (unsigned int i = 0; i < ctrl->num_down_channels; i++) {
int ret;
Jim_Obj *tmp;
ret = rtt_read_channel_info(i, RTT_CHANNEL_TYPE_DOWN, &info);
if (ret != ERROR_OK)
return ret;
if (!info.size)
continue;
tmp = Jim_NewListObj(interp, NULL, 0);
Jim_ListAppendElement(interp, tmp, Jim_NewStringObj(interp,
"name", -1));
Jim_ListAppendElement(interp, tmp, Jim_NewStringObj(interp,
info.name, -1));
Jim_ListAppendElement(interp, tmp, Jim_NewStringObj(interp,
"size", -1));
Jim_ListAppendElement(interp, tmp, Jim_NewIntObj(interp,
info.size));
Jim_ListAppendElement(interp, tmp, Jim_NewStringObj(interp,
"flags", -1));
Jim_ListAppendElement(interp, tmp, Jim_NewIntObj(interp,
info.flags));
Jim_ListAppendElement(interp, channel_list, tmp);
}
Jim_ListAppendElement(interp, list, channel_list);
Jim_SetResult(interp, list);
return JIM_OK;
}
static const struct command_registration rtt_subcommand_handlers[] = {
{
.name = "setup",
.handler = handle_rtt_setup_command,
.mode = COMMAND_ANY,
.help = "setup RTT",
.usage = "<address> <size> <ID>"
},
{
.name = "start",
.handler = handle_rtt_start_command,
.mode = COMMAND_EXEC,
.help = "start RTT",
.usage = ""
},
{
.name = "stop",
.handler = handle_rtt_stop_command,
.mode = COMMAND_EXEC,
.help = "stop RTT",
.usage = ""
},
{
.name = "polling_interval",
.handler = handle_rtt_polling_interval_command,
.mode = COMMAND_EXEC,
.help = "show or set polling interval in ms",
.usage = "[interval]"
},
{
.name = "channels",
.handler = handle_rtt_channels_command,
.mode = COMMAND_EXEC,
.help = "list available channels",
.usage = ""
},
{
.name = "channellist",
.jim_handler = jim_channel_list,
.mode = COMMAND_EXEC,
.help = "list available channels",
.usage = ""
},
COMMAND_REGISTRATION_DONE
};
const struct command_registration rtt_target_command_handlers[] = {
{
.name = "rtt",
.mode = COMMAND_EXEC,
.help = "RTT target commands",
.usage = "",
.chain = rtt_subcommand_handlers
},
COMMAND_REGISTRATION_DONE
};
|