diff options
author | Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl> | 2018-02-20 15:52:49 +0100 |
---|---|---|
committer | Szymon Janc <szymon.janc@codecoup.pl> | 2019-10-14 12:12:32 +0200 |
commit | 4f5a1df1c4ddfbfea9fd46b43ca4ad3f67fd3858 (patch) | |
tree | e6ee4fec32d6eb19231a94aec08ec7d4ca925e4e /monitor/control.c | |
parent | 7ce36e236c1bdb1941242b00e1d5c7812749a2de (diff) | |
download | bluez-4f5a1df1c4ddfbfea9fd46b43ca4ad3f67fd3858.tar.gz |
monitor: Add support for reading over J-Link RTT
This patch adds support for reading data over J-Link RTT. It can be
used as replacement for TTY when reading from embedded devices since
it's much faster and does block a UART. Data format is the same as
for TTY. At the moment monitor over RTT is only supported by Apache
Mynewt project.
Reading data is done by polling RTT every 1 msec since there is no
blocking API to read something from RTT buffer.
To enable reading from RTT, J-Link configuration needs to be passed via
command line (all parameters except <device> can be skipped to use
default value):
-J <device>,<serialno=0>,<interface=swd>,<speed=1000>
-J nrf52,683649029
In some cases J-Link cannot locate RTT buffer in RAM. In such case
RAM area and buffer name should be provided via command line:
-R <address=0x0>,<area=0x1000>,<buffer=monitor>
-R 0x20000000,0x10000
Diffstat (limited to 'monitor/control.c')
-rw-r--r-- | monitor/control.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/monitor/control.c b/monitor/control.c index 4022e7644..1e9054db3 100644 --- a/monitor/control.c +++ b/monitor/control.c @@ -57,6 +57,7 @@ #include "ellisys.h" #include "tty.h" #include "control.h" +#include "jlink.h" static struct btsnoop *btsnoop_file = NULL; static bool hcidump_fallback = false; @@ -1416,6 +1417,55 @@ int control_tty(const char *path, unsigned int speed) return 0; } +static void rtt_callback(int id, void *user_data) +{ + struct control_data *data = user_data; + ssize_t len; + + do { + len = jlink_rtt_read(data->buf + data->offset, + sizeof(data->buf) - data->offset); + data->offset += len; + process_data(data); + } while (len > 0); + + if (mainloop_modify_timeout(id, 1) < 0) + mainloop_exit_failure(); +} + +int control_rtt(char *jlink, char *rtt) +{ + struct control_data *data; + + if (jlink_init() < 0) { + fprintf(stderr, "Failed to initialize J-Link library\n"); + return -EIO; + } + + if (jlink_connect(jlink) < 0) { + fprintf(stderr, "Failed to connect to target device\n"); + return -ENODEV; + } + + if (jlink_start_rtt(rtt) < 0) { + fprintf(stderr, "Failed to initialize RTT\n"); + return -ENODEV; + } + + printf("--- RTT opened ---\n"); + + data = new0(struct control_data, 1); + data->channel = HCI_CHANNEL_MONITOR; + data->fd = -1; + + if (mainloop_add_timeout(1, rtt_callback, data, free_data) < 0) { + free(data); + return -EIO; + } + + return 0; +} + bool control_writer(const char *path) { btsnoop_file = btsnoop_create(path, 0, 0, BTSNOOP_FORMAT_MONITOR); |