diff --git a/samples/subsys/tracing/CMakeLists.txt b/samples/subsys/tracing/CMakeLists.txt index b42587f68a1..518530b6713 100644 --- a/samples/subsys/tracing/CMakeLists.txt +++ b/samples/subsys/tracing/CMakeLists.txt @@ -10,4 +10,5 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(tracing_tests) target_sources(app PRIVATE src/main.c) +target_sources_ifdef(CONFIG_TRACING_GPIO app PRIVATE src/gpio_main.c) target_sources_ifdef(CONFIG_TRACING_USER app PRIVATE src/tracing_user.c) diff --git a/samples/subsys/tracing/README.rst b/samples/subsys/tracing/README.rst index 702eabb784f..7a3ce8425d3 100644 --- a/samples/subsys/tracing/README.rst +++ b/samples/subsys/tracing/README.rst @@ -127,3 +127,17 @@ Build a SystemView-tracing image with the :ref:`snippet-rtt-tracing`: :compact: After the application has run for a while, check the trace output file. + +Usage for GPIO Tracing Backend +******************************* + +Build a GPIO-tracing image with: + +.. zephyr-app-commands:: + :zephyr-app: samples/subsys/tracing + :board: native_sim + :conf: "prj_gpio.conf" + :goals: build + :compact: + +After the application has run for a while, check the trace output file. diff --git a/samples/subsys/tracing/gpio.overlay b/samples/subsys/tracing/gpio.overlay new file mode 100644 index 00000000000..2879430bab4 --- /dev/null +++ b/samples/subsys/tracing/gpio.overlay @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2024 Tenstorrent AI ULC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + gpio_emul: gpio_emul { + status = "okay"; + compatible = "zephyr,gpio-emul"; + rising-edge; + falling-edge; + high-level; + low-level; + gpio-controller; + #gpio-cells = < 0x2 >; + phandle = < 0x1 >; + }; +}; diff --git a/samples/subsys/tracing/prj_gpio.conf b/samples/subsys/tracing/prj_gpio.conf new file mode 100644 index 00000000000..b6ea42a804b --- /dev/null +++ b/samples/subsys/tracing/prj_gpio.conf @@ -0,0 +1,10 @@ +CONFIG_GPIO=y +CONFIG_GPIO_GET_CONFIG=y +CONFIG_TRACING=y +CONFIG_TRACING_GPIO=y +CONFIG_TRACING_THREAD=n +CONFIG_GPIO_EMUL=y +CONFIG_TRACING_USER=y +CONFIG_TRACING_TEST=n +CONFIG_TRACING_CTF=n +CONFIG_SEGGER_SYSTEMVIEW=n diff --git a/samples/subsys/tracing/sample.yaml b/samples/subsys/tracing/sample.yaml index e7104292b2d..c6fb90b0160 100644 --- a/samples/subsys/tracing/sample.yaml +++ b/samples/subsys/tracing/sample.yaml @@ -76,3 +76,13 @@ tests: extra_args: CONF_FILE="prj_percepio.conf" modules: - percepio + sample.tracing.gpio: + depends_on: gpio + harness: ztest + harness_config: + fixture: gpio_loopback + extra_args: + - CONF_FILE="prj_gpio.conf" + - EXTRA_DTC_OVERLAY_FILE="gpio.overlay" + integration_platforms: + - native_sim diff --git a/samples/subsys/tracing/src/gpio_main.c b/samples/subsys/tracing/src/gpio_main.c new file mode 100644 index 00000000000..f38943c0c4e --- /dev/null +++ b/samples/subsys/tracing/src/gpio_main.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2024 Tenstorrent AI ULC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +/* size of stack area used by each thread */ +#define STACKSIZE (2048) + +/* scheduling priority used by each thread */ +#define PRIORITY 7 + +void test_handler(const struct device *port, struct gpio_callback *cb, gpio_port_pins_t pins) +{ + printk("Interrupt detected!\n"); +} + +void gpio_sample(void) +{ + const struct device *dev = DEVICE_DT_GET(DT_NODELABEL(gpio_emul)); + + if (!device_is_ready(dev)) { + printk("%s: device not ready.\n", dev->name); + return; + } + + /* Configure pin 0 as output and toggle */ + gpio_pin_configure(dev, 0, GPIO_OUTPUT); + gpio_pin_set(dev, 0, 1); + gpio_pin_set(dev, 0, 0); + + /* Configure pin 1 as input */ + gpio_pin_configure(dev, 1, GPIO_INPUT); + + /* Read pin 1 */ + gpio_emul_input_set(dev, 1, 1); + gpio_pin_get(dev, 1); + gpio_emul_input_set(dev, 1, 0); + gpio_pin_get(dev, 1); + + /* Setup pin 1 for interrupt */ + gpio_pin_interrupt_configure(dev, 1, GPIO_INT_EDGE_RISING); + static struct gpio_callback gpio_cb; + + gpio_init_callback(&gpio_cb, test_handler, BIT(1)); + gpio_add_callback(dev, &gpio_cb); + + /* Trigger interrupt */ + gpio_emul_input_set(dev, 1, 1); + + /* Remove interrupt */ + gpio_remove_callback(dev, &gpio_cb); +} + +static void gpio_thread(void *dummy1, void *dummy2, void *dummy3) +{ + ARG_UNUSED(dummy1); + ARG_UNUSED(dummy2); + ARG_UNUSED(dummy3); + + gpio_sample(); +} + +K_THREAD_DEFINE(thread_gpio, STACKSIZE, gpio_thread, NULL, NULL, NULL, PRIORITY, 0, 0); diff --git a/samples/subsys/tracing/src/tracing_user.c b/samples/subsys/tracing/src/tracing_user.c index 7f9370c5d2a..37c27be5948 100644 --- a/samples/subsys/tracing/src/tracing_user.c +++ b/samples/subsys/tracing/src/tracing_user.c @@ -5,6 +5,8 @@ */ #include +#include +#include static int nested_interrupts[CONFIG_MP_MAX_NUM_CPUS]; @@ -56,3 +58,46 @@ void sys_trace_idle_user(void) { printk("%s\n", __func__); } + +void sys_trace_gpio_pin_configure_enter_user(const struct device *port, gpio_pin_t pin, + gpio_flags_t flags) +{ + printk("port: %s, pin: %d flags: %d\n", port->name, pin, flags); +} + +void sys_trace_gpio_pin_configure_exit_user(const struct device *port, gpio_pin_t pin, int ret) +{ + printk("port: %s, pin: %d ret: %d\n", port->name, pin, ret); +} + +void sys_trace_gpio_port_set_bits_raw_enter_user(const struct device *port, gpio_port_pins_t pins) +{ + printk("port: %s, pins: %d\n", port->name, pins); +} + +void sys_trace_gpio_port_set_bits_raw_exit_user(const struct device *port, int ret) +{ + printk("port: %s, ret: %d\n", port->name, ret); +} + +void sys_trace_gpio_port_clear_bits_raw_enter_user(const struct device *port, gpio_port_pins_t pins) +{ + printk("port: %s, pins: %d\n", port->name, pins); +} + +void sys_trace_gpio_port_clear_bits_raw_exit_user(const struct device *port, int ret) +{ + printk("port: %s, pins: %d\n", port->name, ret); +} + +void sys_trace_gpio_pin_interrupt_configure_enter_user(const struct device *port, gpio_pin_t pin, + gpio_flags_t flags) +{ + printk("port: %s, pin: %d flags: %d\n", port->name, pin, flags); +} + +void sys_trace_gpio_pin_interrupt_configure_exit_user(const struct device *port, gpio_pin_t pin, + int ret) +{ + printk("port: %s, pin: %d ret: %d\n", port->name, pin, ret); +} diff --git a/subsys/tracing/Kconfig b/subsys/tracing/Kconfig index 401a33aeef4..30be8d5955b 100644 --- a/subsys/tracing/Kconfig +++ b/subsys/tracing/Kconfig @@ -351,7 +351,7 @@ config TRACING_NET_CORE config TRACING_GPIO bool "Tracing GPIO" - default y if GPIO + default n help Enable tracing GPIO.