2020-02-06 04:59:54 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Intel corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2021-10-13 19:16:39 +02:00
|
|
|
/* Disable syscall tracing for all calls from this compilation unit to avoid
|
|
|
|
* undefined symbols as the macros are not expanded recursively
|
|
|
|
*/
|
|
|
|
#define DISABLE_SYSCALL_TRACING
|
|
|
|
|
2020-02-06 04:59:54 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <ctype.h>
|
2022-05-06 11:12:04 +02:00
|
|
|
#include <zephyr/kernel.h>
|
|
|
|
#include <zephyr/device.h>
|
|
|
|
#include <zephyr/drivers/uart.h>
|
|
|
|
#include <zephyr/sys/__assert.h>
|
2020-02-06 04:59:54 +01:00
|
|
|
#include <tracing_core.h>
|
|
|
|
#include <tracing_buffer.h>
|
|
|
|
#include <tracing_backend.h>
|
|
|
|
|
2021-10-13 19:16:39 +02:00
|
|
|
|
2022-08-17 15:31:42 +02:00
|
|
|
static const struct device *const tracing_uart_dev =
|
|
|
|
DEVICE_DT_GET(DT_CHOSEN(zephyr_tracing_uart));
|
2020-02-06 04:59:54 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_TRACING_HANDLE_HOST_CMD
|
2020-04-30 20:33:38 +02:00
|
|
|
static void uart_isr(const struct device *dev, void *user_data)
|
2020-02-06 04:59:54 +01:00
|
|
|
{
|
|
|
|
int rx;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t byte;
|
|
|
|
static uint8_t *cmd;
|
|
|
|
static uint32_t length, cur;
|
2020-02-06 04:59:54 +01:00
|
|
|
|
2020-06-24 19:06:44 +02:00
|
|
|
ARG_UNUSED(user_data);
|
|
|
|
|
2020-02-06 04:59:54 +01:00
|
|
|
while (uart_irq_update(dev) && uart_irq_is_pending(dev)) {
|
|
|
|
if (!uart_irq_rx_ready(dev)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
rx = uart_fifo_read(dev, &byte, 1);
|
|
|
|
if (rx < 0) {
|
|
|
|
uart_irq_rx_disable(dev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cmd) {
|
|
|
|
length = tracing_cmd_buffer_alloc(&cmd);
|
|
|
|
}
|
|
|
|
|
2023-03-16 00:58:29 +01:00
|
|
|
if (isprint(byte) == 0) {
|
2020-02-06 04:59:54 +01:00
|
|
|
if (byte == '\r') {
|
|
|
|
cmd[cur] = '\0';
|
|
|
|
tracing_cmd_handle(cmd, cur);
|
|
|
|
cmd = NULL;
|
|
|
|
cur = 0U;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur < length - 1) {
|
|
|
|
cmd[cur++] = byte;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void tracing_backend_uart_output(
|
2021-10-13 19:16:39 +02:00
|
|
|
const struct tracing_backend *backend,
|
|
|
|
uint8_t *data, uint32_t length)
|
2020-02-06 04:59:54 +01:00
|
|
|
{
|
2020-05-27 18:26:57 +02:00
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
2020-07-23 23:36:30 +02:00
|
|
|
uart_poll_out(tracing_uart_dev, data[i]);
|
2020-02-06 04:59:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tracing_backend_uart_init(void)
|
|
|
|
{
|
2022-07-19 17:44:56 +02:00
|
|
|
__ASSERT(device_is_ready(tracing_uart_dev), "uart backend is not ready");
|
2020-02-06 04:59:54 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_TRACING_HANDLE_HOST_CMD
|
2020-07-23 23:36:30 +02:00
|
|
|
uart_irq_rx_disable(tracing_uart_dev);
|
|
|
|
uart_irq_tx_disable(tracing_uart_dev);
|
2020-02-06 04:59:54 +01:00
|
|
|
|
2020-07-23 23:36:30 +02:00
|
|
|
uart_irq_callback_set(tracing_uart_dev, uart_isr);
|
2020-02-06 04:59:54 +01:00
|
|
|
|
2020-07-23 23:36:30 +02:00
|
|
|
while (uart_irq_rx_ready(tracing_uart_dev)) {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t c;
|
2020-02-06 04:59:54 +01:00
|
|
|
|
2020-07-23 23:36:30 +02:00
|
|
|
uart_fifo_read(tracing_uart_dev, &c, 1);
|
2020-02-06 04:59:54 +01:00
|
|
|
}
|
|
|
|
|
2020-07-23 23:36:30 +02:00
|
|
|
uart_irq_rx_enable(tracing_uart_dev);
|
2020-02-06 04:59:54 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct tracing_backend_api tracing_backend_uart_api = {
|
|
|
|
.init = tracing_backend_uart_init,
|
2021-10-13 19:16:39 +02:00
|
|
|
.output = tracing_backend_uart_output
|
2020-02-06 04:59:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TRACING_BACKEND_DEFINE(tracing_backend_uart, tracing_backend_uart_api);
|