OpenOCD
rtt/rtt.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /*
4  * Copyright (C) 2016-2020 by Marc Schink <dev@zapb.de>
5  */
6 
7 #ifndef OPENOCD_RTT_RTT_H
8 #define OPENOCD_RTT_RTT_H
9 
10 #include <stdint.h>
11 #include <stdbool.h>
12 
13 #include <helper/command.h>
14 #include <target/target.h>
15 
19 #define RTT_CB_MAX_ID_LENGTH 16
20 
21 /* Control block size in bytes. */
22 #define RTT_CB_SIZE (RTT_CB_MAX_ID_LENGTH + 2 * sizeof(uint32_t))
23 
24 /* Channel structure size in bytes. */
25 #define RTT_CHANNEL_SIZE 24
26 
27 /* Minimal channel buffer size in bytes. */
28 #define RTT_CHANNEL_BUFFER_MIN_SIZE 2
29 
31 struct rtt_control {
37  uint32_t num_up_channels;
40 };
41 
43 struct rtt_channel {
47  uint32_t name_addr;
49  uint32_t buffer_addr;
51  uint32_t size;
53  uint32_t write_pos;
55  uint32_t read_pos;
61  uint32_t flags;
62 };
63 
67  char *name;
69  size_t name_length;
71  uint32_t size;
77  uint32_t flags;
78 };
79 
80 typedef int (*rtt_sink_read)(unsigned int channel, const uint8_t *buffer,
81  size_t length, void *user_data);
82 
83 struct rtt_sink_list {
85  void *user_data;
86 
88 };
89 
96 };
97 
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);
105  const struct rtt_control *ctrl, unsigned int channel,
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);
117 
119 struct rtt_source {
127 };
128 
134 int rtt_init(void);
135 
141 int rtt_exit(void);
142 
151 int rtt_register_source(const struct rtt_source source,
152  struct target *target);
153 
163 int rtt_setup(target_addr_t address, size_t size, const char *id);
164 
170 int rtt_start(void);
171 
177 int rtt_stop(void);
178 
186 int rtt_get_polling_interval(unsigned int *interval);
187 
195 int rtt_set_polling_interval(unsigned int interval);
196 
202 bool rtt_started(void);
203 
209 bool rtt_configured(void);
210 
216 bool rtt_found_cb(void);
217 
223 const struct rtt_control *rtt_get_control(void);
224 
234 int rtt_read_channel_info(unsigned int channel_index,
236 
246 int rtt_register_sink(unsigned int channel_index, rtt_sink_read read,
247  void *user_data);
248 
258 int rtt_unregister_sink(unsigned int channel_index, rtt_sink_read read,
259  void *user_data);
260 
271 int rtt_write_channel(unsigned int channel_index, const uint8_t *buffer,
272  size_t *length);
273 
275 
276 #endif /* OPENOCD_RTT_RTT_H */
uint8_t type
Definition: esp_usb_jtag.c:0
uint8_t length
Definition: esp_usb_jtag.c:1
struct target * target
Definition: rtt/rtt.c:26
struct rtt_control ctrl
Control block.
Definition: rtt/rtt.c:25
size_t size
Size of the control block search area.
Definition: rtt/rtt.c:30
struct rtt_source source
Definition: rtt/rtt.c:23
char id[RTT_CB_MAX_ID_LENGTH]
Control block identifier.
Definition: rtt/rtt.c:32
int rtt_stop(void)
Stop Real-Time Transfer (RTT).
Definition: rtt/rtt.c:165
#define RTT_CB_MAX_ID_LENGTH
Control block ID length in bytes, including the trailing null-terminator.
Definition: rtt/rtt.h:19
int rtt_start(void)
Start Real-Time Transfer (RTT).
Definition: rtt/rtt.c:124
int(* rtt_source_read)(struct target *target, const struct rtt_control *ctrl, struct rtt_sink_list **sinks, size_t num_channels, void *user_data)
Definition: rtt/rtt.h:111
int rtt_register_sink(unsigned int channel_index, rtt_sink_read read, void *user_data)
Register an RTT sink.
Definition: rtt/rtt.c:206
int(* rtt_source_start)(struct target *target, const struct rtt_control *ctrl, void *user_data)
Definition: rtt/rtt.h:108
bool rtt_configured(void)
Get whether RTT is configured.
Definition: rtt/rtt.c:305
int(* rtt_source_read_ctrl_block)(struct target *target, target_addr_t address, struct rtt_control *ctrl_block, void *user_data)
Definition: rtt/rtt.h:101
bool rtt_found_cb(void)
Get whether RTT control block was found.
Definition: rtt/rtt.c:310
int(* rtt_source_find_ctrl_block)(struct target *target, target_addr_t *address, size_t size, const char *id, bool *found, void *user_data)
Definition: rtt/rtt.h:98
int rtt_set_polling_interval(unsigned int interval)
Set the polling interval.
Definition: rtt/rtt.c:272
int(* rtt_source_write)(struct target *target, struct rtt_control *ctrl, unsigned int channel, const uint8_t *buffer, size_t *length, void *user_data)
Definition: rtt/rtt.h:114
int rtt_unregister_sink(unsigned int channel_index, rtt_sink_read read, void *user_data)
Unregister an RTT sink.
Definition: rtt/rtt.c:232
int(* rtt_sink_read)(unsigned int channel, const uint8_t *buffer, size_t length, void *user_data)
Definition: rtt/rtt.h:80
int(* rtt_source_read_channel_info)(struct target *target, const struct rtt_control *ctrl, unsigned int channel, enum rtt_channel_type type, struct rtt_channel_info *info, void *user_data)
Definition: rtt/rtt.h:104
int rtt_init(void)
Initialize Real-Time Transfer (RTT).
Definition: rtt/rtt.c:48
bool rtt_started(void)
Get whether RTT is started.
Definition: rtt/rtt.c:300
int rtt_register_source(const struct rtt_source source, struct target *target)
Register an RTT source for a target.
Definition: rtt/rtt.c:106
int rtt_exit(void)
Shutdown Real-Time Transfer (RTT).
Definition: rtt/rtt.c:65
const struct rtt_control * rtt_get_control(void)
Get the RTT control block.
Definition: rtt/rtt.c:315
int rtt_get_polling_interval(unsigned int *interval)
Get the polling interval.
Definition: rtt/rtt.c:262
int rtt_setup(target_addr_t address, size_t size, const char *id)
Setup RTT.
Definition: rtt/rtt.c:88
const struct command_registration rtt_target_command_handlers[]
Definition: rtt/tcl.c:267
int rtt_read_channel_info(unsigned int channel_index, enum rtt_channel_type type, struct rtt_channel_info *info)
Read channel information.
Definition: rtt/rtt.c:320
rtt_channel_type
Channel type.
Definition: rtt/rtt.h:91
@ RTT_CHANNEL_TYPE_UP
Up channel (target to host).
Definition: rtt/rtt.h:93
@ RTT_CHANNEL_TYPE_DOWN
Down channel (host to target).
Definition: rtt/rtt.h:95
int(* rtt_source_stop)(struct target *target, void *user_data)
Definition: rtt/rtt.h:110
int rtt_write_channel(unsigned int channel_index, const uint8_t *buffer, size_t *length)
Write to an RTT channel.
Definition: rtt/rtt.c:288
RTT channel information.
Definition: rtt/rtt.h:65
char * name
Channel name.
Definition: rtt/rtt.h:67
uint32_t size
Buffer size in bytes.
Definition: rtt/rtt.h:71
size_t name_length
Length of the name in bytes, including the trailing null-terminator.
Definition: rtt/rtt.h:69
uint32_t flags
Buffer flags.
Definition: rtt/rtt.h:77
RTT channel.
Definition: rtt/rtt.h:43
uint32_t read_pos
Read position within the buffer in bytes.
Definition: rtt/rtt.h:55
uint32_t name_addr
Channel name address on the target.
Definition: rtt/rtt.h:47
target_addr_t address
Channel structure address on the target.
Definition: rtt/rtt.h:45
uint32_t write_pos
Write position within the buffer in bytes.
Definition: rtt/rtt.h:53
uint32_t size
Channel buffer size in bytes.
Definition: rtt/rtt.h:51
uint32_t flags
Buffer flags.
Definition: rtt/rtt.h:61
uint32_t buffer_addr
Buffer address on the target.
Definition: rtt/rtt.h:49
RTT control block.
Definition: rtt/rtt.h:31
target_addr_t address
Control block address on the target.
Definition: rtt/rtt.h:33
uint32_t num_up_channels
Maximum number of up-channels.
Definition: rtt/rtt.h:37
uint32_t num_down_channels
Maximum number of down-channels.
Definition: rtt/rtt.h:39
struct rtt_sink_list * next
Definition: rtt/rtt.h:87
rtt_sink_read read
Definition: rtt/rtt.h:84
void * user_data
Definition: rtt/rtt.h:85
RTT source.
Definition: rtt/rtt.h:119
rtt_source_find_ctrl_block find_cb
Definition: rtt/rtt.h:120
rtt_source_start start
Definition: rtt/rtt.h:123
rtt_source_stop stop
Definition: rtt/rtt.h:124
rtt_source_write write
Definition: rtt/rtt.h:126
rtt_source_read_ctrl_block read_cb
Definition: rtt/rtt.h:121
rtt_source_read_channel_info read_channel_info
Definition: rtt/rtt.h:122
rtt_source_read read
Definition: rtt/rtt.h:125
Definition: target.h:116
uint64_t target_addr_t
Definition: types.h:335
static struct ublast_lowlevel_priv info