target/cortex_m: drop useless target_halt() call
[openocd.git] / src / rtt / rtt.h
bloba5630a951592635a9ad5811606381ef84b8a5c04
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 /*
4 * Copyright (C) 2016-2020 by Marc Schink <dev@zapb.de>
5 */
7 #ifndef OPENOCD_RTT_RTT_H
8 #define OPENOCD_RTT_RTT_H
10 #include <stdint.h>
11 #include <stdbool.h>
13 #include <helper/command.h>
14 #include <target/target.h>
16 /**
17 * Control block ID length in bytes, including the trailing null-terminator.
19 #define RTT_CB_MAX_ID_LENGTH 16
21 /* Control block size in bytes. */
22 #define RTT_CB_SIZE (RTT_CB_MAX_ID_LENGTH + 2 * sizeof(uint32_t))
24 /* Channel structure size in bytes. */
25 #define RTT_CHANNEL_SIZE 24
27 /* Minimal channel buffer size in bytes. */
28 #define RTT_CHANNEL_BUFFER_MIN_SIZE 2
30 /** RTT control block. */
31 struct rtt_control {
32 /** Control block address on the target. */
33 target_addr_t address;
34 /** Control block identifier, including trailing null-terminator. */
35 char id[RTT_CB_MAX_ID_LENGTH];
36 /** Maximum number of up-channels. */
37 uint32_t num_up_channels;
38 /** Maximum number of down-channels. */
39 uint32_t num_down_channels;
42 /** RTT channel. */
43 struct rtt_channel {
44 /** Channel structure address on the target. */
45 target_addr_t address;
46 /** Channel name address on the target. */
47 uint32_t name_addr;
48 /** Buffer address on the target. */
49 uint32_t buffer_addr;
50 /** Channel buffer size in bytes. */
51 uint32_t size;
52 /** Write position within the buffer in bytes. */
53 uint32_t write_pos;
54 /** Read position within the buffer in bytes. */
55 uint32_t read_pos;
56 /**
57 * Buffer flags.
59 * @note: Not used at the moment.
61 uint32_t flags;
64 /** RTT channel information. */
65 struct rtt_channel_info {
66 /** Channel name. */
67 char *name;
68 /** Length of the name in bytes, including the trailing null-terminator. */
69 size_t name_length;
70 /** Buffer size in bytes. */
71 uint32_t size;
72 /**
73 * Buffer flags.
75 * @note: Not used at the moment.
77 uint32_t flags;
80 typedef int (*rtt_sink_read)(unsigned int channel, const uint8_t *buffer,
81 size_t length, void *user_data);
83 struct rtt_sink_list {
84 rtt_sink_read read;
85 void *user_data;
87 struct rtt_sink_list *next;
90 /** Channel type. */
91 enum rtt_channel_type {
92 /** Up channel (target to host). */
93 RTT_CHANNEL_TYPE_UP,
94 /** Down channel (host to target). */
95 RTT_CHANNEL_TYPE_DOWN
98 typedef int (*rtt_source_find_ctrl_block)(struct target *target,
99 target_addr_t *address, size_t size, const char *id, bool *found,
100 void *user_data);
101 typedef int (*rtt_source_read_ctrl_block)(struct target *target,
102 target_addr_t address, struct rtt_control *ctrl_block,
103 void *user_data);
104 typedef int (*rtt_source_read_channel_info)(struct target *target,
105 const struct rtt_control *ctrl, unsigned int channel,
106 enum rtt_channel_type type, struct rtt_channel_info *info,
107 void *user_data);
108 typedef int (*rtt_source_start)(struct target *target,
109 const struct rtt_control *ctrl, void *user_data);
110 typedef int (*rtt_source_stop)(struct target *target, void *user_data);
111 typedef int (*rtt_source_read)(struct target *target,
112 const struct rtt_control *ctrl, struct rtt_sink_list **sinks,
113 size_t num_channels, void *user_data);
114 typedef int (*rtt_source_write)(struct target *target,
115 struct rtt_control *ctrl, unsigned int channel,
116 const uint8_t *buffer, size_t *length, void *user_data);
118 /** RTT source. */
119 struct rtt_source {
120 rtt_source_find_ctrl_block find_cb;
121 rtt_source_read_ctrl_block read_cb;
122 rtt_source_read_channel_info read_channel_info;
123 rtt_source_start start;
124 rtt_source_stop stop;
125 rtt_source_read read;
126 rtt_source_write write;
130 * Initialize Real-Time Transfer (RTT).
132 * @returns ERROR_OK on success, an error code on failure.
134 int rtt_init(void);
137 * Shutdown Real-Time Transfer (RTT).
139 * @returns ERROR_OK on success, an error code on failure.
141 int rtt_exit(void);
144 * Register an RTT source for a target.
146 * @param[in] source RTT source.
147 * @param[in,out] target Target.
149 * @returns ERROR_OK on success, an error code on failure.
151 int rtt_register_source(const struct rtt_source source,
152 struct target *target);
155 * Setup RTT.
157 * @param[in] address Start address to search for the control block.
158 * @param[in] size Size of the control block search area.
159 * @param[in] id Identifier of the control block. Must be null-terminated.
161 * @returns ERROR_OK on success, an error code on failure.
163 int rtt_setup(target_addr_t address, size_t size, const char *id);
166 * Start Real-Time Transfer (RTT).
168 * @returns ERROR_OK on success, an error code on failure.
170 int rtt_start(void);
173 * Stop Real-Time Transfer (RTT).
175 * @returns ERROR_OK on success, an error code on failure.
177 int rtt_stop(void);
180 * Get the polling interval.
182 * @param[out] interval Polling interval in milliseconds.
184 * @returns ERROR_OK on success, an error code on failure.
186 int rtt_get_polling_interval(unsigned int *interval);
189 * Set the polling interval.
191 * @param[in] interval Polling interval in milliseconds.
193 * @returns ERROR_OK on success, an error code on failure.
195 int rtt_set_polling_interval(unsigned int interval);
198 * Get whether RTT is started.
200 * @returns Whether RTT is started.
202 bool rtt_started(void);
205 * Get whether RTT is configured.
207 * @returns Whether RTT is configured.
209 bool rtt_configured(void);
212 * Get whether RTT control block was found.
214 * @returns Whether RTT was found.
216 bool rtt_found_cb(void);
219 * Get the RTT control block.
221 * @returns The RTT control block.
223 const struct rtt_control *rtt_get_control(void);
226 * Read channel information.
228 * @param[in] channel_index Channel index.
229 * @param[in] type Channel type.
230 * @param[out] info Channel information.
232 * @returns ERROR_OK on success, an error code on failure.
234 int rtt_read_channel_info(unsigned int channel_index,
235 enum rtt_channel_type type, struct rtt_channel_info *info);
238 * Register an RTT sink.
240 * @param[in] channel_index Channel index.
241 * @param[in] read Read callback function.
242 * @param[in,out] user_data User data to be passed to the callback function.
244 * @returns ERROR_OK on success, an error code on failure.
246 int rtt_register_sink(unsigned int channel_index, rtt_sink_read read,
247 void *user_data);
250 * Unregister an RTT sink.
252 * @param[in] channel_index Channel index.
253 * @param[in] read Read callback function.
254 * @param[in,out] user_data User data to be passed to the callback function.
256 * @returns ERROR_OK on success, an error code on failure.
258 int rtt_unregister_sink(unsigned int channel_index, rtt_sink_read read,
259 void *user_data);
262 * Write to an RTT channel.
264 * @param[in] channel_index Channel index.
265 * @param[in] buffer Buffer with data that should be written to the channel.
266 * @param[in,out] length Number of bytes to write. On success, the argument gets
267 * updated with the actual number of written bytes.
269 * @returns ERROR_OK on success, an error code on failure.
271 int rtt_write_channel(unsigned int channel_index, const uint8_t *buffer,
272 size_t *length);
274 extern const struct command_registration rtt_target_command_handlers[];
276 #endif /* OPENOCD_RTT_RTT_H */