samples: tracing: update sample app for gpio tracing

Implement a sample app to perform basic GPIO tracing.

Signed-off-by: Alexander Lay <alexanderlay@tenstorrent.com>
Signed-off-by: Yang Xu <yangxu@tenstorrent.com>
This commit is contained in:
Alexander Lay 2024-06-12 20:45:07 -04:00 committed by Anas Nashif
parent 8f2dd90088
commit d356403664
8 changed files with 170 additions and 1 deletions

View file

@ -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)

View file

@ -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.

View file

@ -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 >;
};
};

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,70 @@
/*
* Copyright (c) 2024 Tenstorrent AI ULC
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>
#include <zephyr/logging/log.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/gpio/gpio_emul.h>
/* 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);

View file

@ -5,6 +5,8 @@
*/
#include <tracing_user.h>
#include <zephyr/kernel.h>
#include <zephyr/device.h>
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);
}

View file

@ -351,7 +351,7 @@ config TRACING_NET_CORE
config TRACING_GPIO
bool "Tracing GPIO"
default y if GPIO
default n
help
Enable tracing GPIO.