target: rtt: include rtt.h
[openocd.git] / src / rtt / tcl.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2
3 /*
4 * Copyright (C) 2019-2020 by Marc Schink <dev@zapb.de>
5 */
6
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
10
11 #include <helper/log.h>
12 #include <target/rtt.h>
13
14 #include "rtt.h"
15
16 #define CHANNEL_NAME_SIZE 128
17
18 COMMAND_HANDLER(handle_rtt_setup_command)
19 {
20 struct rtt_source source;
21
22 if (CMD_ARGC != 3)
23 return ERROR_COMMAND_SYNTAX_ERROR;
24
25 source.find_cb = &target_rtt_find_control_block;
26 source.read_cb = &target_rtt_read_control_block;
27 source.start = &target_rtt_start;
28 source.stop = &target_rtt_stop;
29 source.read = &target_rtt_read_callback;
30 source.write = &target_rtt_write_callback;
31 source.read_channel_info = &target_rtt_read_channel_info;
32
33 target_addr_t address;
34 uint32_t size;
35
36 COMMAND_PARSE_NUMBER(target_addr, CMD_ARGV[0], address);
37 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], size);
38
39 rtt_register_source(source, get_current_target(CMD_CTX));
40
41 if (rtt_setup(address, size, CMD_ARGV[2]) != ERROR_OK)
42 return ERROR_FAIL;
43
44 return ERROR_OK;
45 }
46
47 COMMAND_HANDLER(handle_rtt_start_command)
48 {
49 if (CMD_ARGC > 0)
50 return ERROR_COMMAND_SYNTAX_ERROR;
51
52 if (!rtt_configured()) {
53 command_print(CMD, "RTT is not configured");
54 return ERROR_FAIL;
55 }
56
57 return rtt_start();
58 }
59
60 COMMAND_HANDLER(handle_rtt_stop_command)
61 {
62 if (CMD_ARGC > 0)
63 return ERROR_COMMAND_SYNTAX_ERROR;
64
65 return rtt_stop();
66 }
67
68 COMMAND_HANDLER(handle_rtt_polling_interval_command)
69 {
70 if (CMD_ARGC == 0) {
71 int ret;
72 unsigned int interval;
73
74 ret = rtt_get_polling_interval(&interval);
75
76 if (ret != ERROR_OK) {
77 command_print(CMD, "Failed to get polling interval");
78 return ret;
79 }
80
81 command_print(CMD, "%u ms", interval);
82 } else if (CMD_ARGC == 1) {
83 int ret;
84 unsigned int interval;
85
86 COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], interval);
87 ret = rtt_set_polling_interval(interval);
88
89 if (ret != ERROR_OK) {
90 command_print(CMD, "Failed to set polling interval");
91 return ret;
92 }
93 } else {
94 return ERROR_COMMAND_SYNTAX_ERROR;
95 }
96
97 return ERROR_OK;
98 }
99
100 COMMAND_HANDLER(handle_rtt_channels_command)
101 {
102 int ret;
103 char channel_name[CHANNEL_NAME_SIZE];
104 const struct rtt_control *ctrl;
105 struct rtt_channel_info info;
106
107 if (!rtt_found_cb()) {
108 command_print(CMD, "rtt: Control block not available");
109 return ERROR_FAIL;
110 }
111
112 ctrl = rtt_get_control();
113
114 command_print(CMD, "Channels: up=%u, down=%u", ctrl->num_up_channels,
115 ctrl->num_down_channels);
116
117 command_print(CMD, "Up-channels:");
118
119 info.name = channel_name;
120 info.name_length = sizeof(channel_name);
121
122 for (unsigned int i = 0; i < ctrl->num_up_channels; i++) {
123 ret = rtt_read_channel_info(i, RTT_CHANNEL_TYPE_UP, &info);
124
125 if (ret != ERROR_OK)
126 return ret;
127
128 if (!info.size)
129 continue;
130
131 command_print(CMD, "%u: %s %u %u", i, info.name, info.size,
132 info.flags);
133 }
134
135 command_print(CMD, "Down-channels:");
136
137 for (unsigned int i = 0; i < ctrl->num_down_channels; i++) {
138 ret = rtt_read_channel_info(i, RTT_CHANNEL_TYPE_DOWN, &info);
139
140 if (ret != ERROR_OK)
141 return ret;
142
143 if (!info.size)
144 continue;
145
146 command_print(CMD, "%u: %s %u %u", i, info.name, info.size,
147 info.flags);
148 }
149
150 return ERROR_OK;
151 }
152
153 COMMAND_HANDLER(handle_channel_list)
154 {
155 char channel_name[CHANNEL_NAME_SIZE];
156 const struct rtt_control *ctrl;
157 struct rtt_channel_info info;
158
159 if (CMD_ARGC != 0)
160 return ERROR_COMMAND_SYNTAX_ERROR;
161
162 if (!rtt_found_cb()) {
163 command_print(CMD, "rtt: Control block not available");
164 return ERROR_FAIL;
165 }
166
167 ctrl = rtt_get_control();
168
169 info.name = channel_name;
170 info.name_length = sizeof(channel_name);
171
172 command_print(CMD, "{");
173
174 for (unsigned int i = 0; i < ctrl->num_up_channels; i++) {
175 int ret = rtt_read_channel_info(i, RTT_CHANNEL_TYPE_UP, &info);
176 if (ret != ERROR_OK)
177 return ret;
178
179 if (!info.size)
180 continue;
181
182 command_print(CMD,
183 " {\n"
184 " name %s\n"
185 " size 0x%" PRIx32 "\n"
186 " flags 0x%" PRIx32 "\n"
187 " }",
188 info.name, info.size, info.flags);
189 }
190
191 command_print(CMD, "}\n{");
192
193 for (unsigned int i = 0; i < ctrl->num_down_channels; i++) {
194 int ret = rtt_read_channel_info(i, RTT_CHANNEL_TYPE_DOWN, &info);
195 if (ret != ERROR_OK)
196 return ret;
197
198 if (!info.size)
199 continue;
200
201 command_print(CMD,
202 " {\n"
203 " name %s\n"
204 " size 0x%" PRIx32 "\n"
205 " flags 0x%" PRIx32 "\n"
206 " }",
207 info.name, info.size, info.flags);
208 }
209
210 command_print(CMD, "}");
211
212 return ERROR_OK;
213 }
214
215 static const struct command_registration rtt_subcommand_handlers[] = {
216 {
217 .name = "setup",
218 .handler = handle_rtt_setup_command,
219 .mode = COMMAND_ANY,
220 .help = "setup RTT",
221 .usage = "<address> <size> <ID>"
222 },
223 {
224 .name = "start",
225 .handler = handle_rtt_start_command,
226 .mode = COMMAND_EXEC,
227 .help = "start RTT",
228 .usage = ""
229 },
230 {
231 .name = "stop",
232 .handler = handle_rtt_stop_command,
233 .mode = COMMAND_EXEC,
234 .help = "stop RTT",
235 .usage = ""
236 },
237 {
238 .name = "polling_interval",
239 .handler = handle_rtt_polling_interval_command,
240 .mode = COMMAND_EXEC,
241 .help = "show or set polling interval in ms",
242 .usage = "[interval]"
243 },
244 {
245 .name = "channels",
246 .handler = handle_rtt_channels_command,
247 .mode = COMMAND_EXEC,
248 .help = "list available channels",
249 .usage = ""
250 },
251 {
252 .name = "channellist",
253 .handler = handle_channel_list,
254 .mode = COMMAND_EXEC,
255 .help = "list available channels",
256 .usage = ""
257 },
258 COMMAND_REGISTRATION_DONE
259 };
260
261 const struct command_registration rtt_target_command_handlers[] = {
262 {
263 .name = "rtt",
264 .mode = COMMAND_EXEC,
265 .help = "RTT target commands",
266 .usage = "",
267 .chain = rtt_subcommand_handlers
268 },
269 COMMAND_REGISTRATION_DONE
270 };

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)