Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 88 additions & 18 deletions include/zephyr/drivers/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <zephyr/sys/__assert.h>
#include <zephyr/sys/slist.h>
#include <zephyr/tracing/tracing.h>

#include <zephyr/types.h>
#include <stddef.h>
Expand Down Expand Up @@ -550,7 +551,7 @@ struct gpio_dt_spec {
* .ngpios = 32,
* .gpios_reserved = 0xdeadbeef,
* // 0b1101 1110 1010 1101 1011 1110 1110 1111
*
* };
* static const struct some_config dev_cfg_b = {
* .ngpios = 18,
* .gpios_reserved = 0xfffc0418,
Expand Down Expand Up @@ -875,8 +876,12 @@ static inline int z_impl_gpio_pin_interrupt_configure(const struct device *port,
(const struct gpio_driver_data *)port->data;
enum gpio_int_trig trig;
enum gpio_int_mode mode;
int ret;

SYS_PORT_TRACING_FUNC_ENTER(gpio_pin, interrupt_configure, port, pin, flags);

if (api->pin_interrupt_configure == NULL) {
SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, interrupt_configure, port, pin, -ENOSYS);
return -ENOSYS;
}

Expand Down Expand Up @@ -921,7 +926,9 @@ static inline int z_impl_gpio_pin_interrupt_configure(const struct device *port,
mode = (enum gpio_int_mode)(flags & (GPIO_INT_EDGE | GPIO_INT_DISABLE | GPIO_INT_ENABLE));
#endif /* CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT */

return api->pin_interrupt_configure(port, pin, mode, trig);
ret = api->pin_interrupt_configure(port, pin, mode, trig);
SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, interrupt_configure, port, pin, ret);
return ret;
}

/**
Expand Down Expand Up @@ -972,6 +979,9 @@ static inline int z_impl_gpio_pin_configure(const struct device *port,
(const struct gpio_driver_config *)port->config;
struct gpio_driver_data *data =
(struct gpio_driver_data *)port->data;
int ret;

SYS_PORT_TRACING_FUNC_ENTER(gpio_pin, configure, port, pin, flags);

__ASSERT((flags & GPIO_INT_MASK) == 0,
"Interrupt flags are not supported");
Expand Down Expand Up @@ -1011,7 +1021,9 @@ static inline int z_impl_gpio_pin_configure(const struct device *port,
data->invert &= ~(gpio_port_pins_t)BIT(pin);
}

return api->pin_configure(port, pin, flags);
ret = api->pin_configure(port, pin, flags);
SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, configure, port, pin, ret);
return ret;
}

/**
Expand Down Expand Up @@ -1060,12 +1072,18 @@ static inline int z_impl_gpio_port_get_direction(const struct device *port, gpio
gpio_port_pins_t *outputs)
{
const struct gpio_driver_api *api = (const struct gpio_driver_api *)port->api;
int ret;

SYS_PORT_TRACING_FUNC_ENTER(gpio_port, get_direction, port, map, inputs, outputs);

if (api->port_get_direction == NULL) {
SYS_PORT_TRACING_FUNC_EXIT(gpio_port, get_direction, port, -ENOSYS);
return -ENOSYS;
}

return api->port_get_direction(port, map, inputs, outputs);
ret = api->port_get_direction(port, map, inputs, outputs);
SYS_PORT_TRACING_FUNC_EXIT(gpio_port, get_direction, port, ret);
return ret;
}
#endif /* CONFIG_GPIO_GET_DIRECTION */

Expand Down Expand Up @@ -1184,11 +1202,18 @@ static inline int z_impl_gpio_pin_get_config(const struct device *port,
{
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->api;
int ret;

SYS_PORT_TRACING_FUNC_ENTER(gpio_pin, get_config, port, pin, *flags);

if (api->pin_get_config == NULL)
if (api->pin_get_config == NULL) {
SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, get_config, port, pin, -ENOSYS);
return -ENOSYS;
}

return api->pin_get_config(port, pin, flags);
ret = api->pin_get_config(port, pin, flags);
SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, get_config, port, pin, ret);
return ret;
}
#endif

Expand Down Expand Up @@ -1230,13 +1255,16 @@ static inline int gpio_pin_get_config_dt(const struct gpio_dt_spec *spec,
__syscall int gpio_port_get_raw(const struct device *port,
gpio_port_value_t *value);

static inline int z_impl_gpio_port_get_raw(const struct device *port,
gpio_port_value_t *value)
static inline int z_impl_gpio_port_get_raw(const struct device *port, gpio_port_value_t *value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

such formatting changes should be in a separate commit

{
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->api;
const struct gpio_driver_api *api = (const struct gpio_driver_api *)port->api;
int ret;

SYS_PORT_TRACING_FUNC_ENTER(gpio_port, get_raw, port, value);

return api->port_get_raw(port, value);
ret = api->port_get_raw(port, value);
SYS_PORT_TRACING_FUNC_EXIT(gpio_port, get_raw, port, ret);
return ret;
}

/**
Expand Down Expand Up @@ -1299,8 +1327,13 @@ static inline int z_impl_gpio_port_set_masked_raw(const struct device *port,
{
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->api;
int ret;

return api->port_set_masked_raw(port, mask, value);
SYS_PORT_TRACING_FUNC_ENTER(gpio_port, set_masked_raw, port, mask, value);

ret = api->port_set_masked_raw(port, mask, value);
SYS_PORT_TRACING_FUNC_EXIT(gpio_port, set_masked_raw, port, ret);
return ret;
}

/**
Expand Down Expand Up @@ -1353,8 +1386,13 @@ static inline int z_impl_gpio_port_set_bits_raw(const struct device *port,
{
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->api;
int ret;

return api->port_set_bits_raw(port, pins);
SYS_PORT_TRACING_FUNC_ENTER(gpio_port, set_bits_raw, port, pins);

ret = api->port_set_bits_raw(port, pins);
SYS_PORT_TRACING_FUNC_EXIT(gpio_port, set_bits_raw, port, ret);
return ret;
}

/**
Expand Down Expand Up @@ -1391,8 +1429,13 @@ static inline int z_impl_gpio_port_clear_bits_raw(const struct device *port,
{
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->api;
int ret;

return api->port_clear_bits_raw(port, pins);
SYS_PORT_TRACING_FUNC_ENTER(gpio_port, clear_bits_raw, port, pins);

ret = api->port_clear_bits_raw(port, pins);
SYS_PORT_TRACING_FUNC_EXIT(gpio_port, clear_bits_raw, port, ret);
return ret;
}

/**
Expand Down Expand Up @@ -1429,8 +1472,13 @@ static inline int z_impl_gpio_port_toggle_bits(const struct device *port,
{
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->api;
int ret;

return api->port_toggle_bits(port, pins);
SYS_PORT_TRACING_FUNC_ENTER(gpio_port, toggle_bits, port, pins);

ret = api->port_toggle_bits(port, pins);
SYS_PORT_TRACING_FUNC_EXIT(gpio_port, toggle_bits, port, ret);
return ret;
}

/**
Expand Down Expand Up @@ -1693,11 +1741,15 @@ static inline void gpio_init_callback(struct gpio_callback *callback,
gpio_callback_handler_t handler,
gpio_port_pins_t pin_mask)
{
SYS_PORT_TRACING_FUNC_ENTER(gpio, init_callback, callback, handler, pin_mask);

__ASSERT(callback, "Callback pointer should not be NULL");
__ASSERT(handler, "Callback handler pointer should not be NULL");

callback->handler = handler;
callback->pin_mask = pin_mask;

SYS_PORT_TRACING_FUNC_EXIT(gpio, init_callback, callback);
}

/**
Expand All @@ -1719,12 +1771,18 @@ static inline int gpio_add_callback(const struct device *port,
{
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->api;
int ret;

SYS_PORT_TRACING_FUNC_ENTER(gpio, add_callback, port, callback);

if (api->manage_callback == NULL) {
SYS_PORT_TRACING_FUNC_EXIT(gpio, add_callback, port, -ENOSYS);
return -ENOSYS;
}

return api->manage_callback(port, callback, true);
ret = api->manage_callback(port, callback, true);
SYS_PORT_TRACING_FUNC_EXIT(gpio, add_callback, port, ret);
return ret;
}

/**
Expand Down Expand Up @@ -1767,12 +1825,18 @@ static inline int gpio_remove_callback(const struct device *port,
{
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->api;
int ret;

SYS_PORT_TRACING_FUNC_ENTER(gpio, remove_callback, port, callback);

if (api->manage_callback == NULL) {
SYS_PORT_TRACING_FUNC_EXIT(gpio, remove_callback, port, -ENOSYS);
return -ENOSYS;
}

return api->manage_callback(port, callback, false);
ret = api->manage_callback(port, callback, false);
SYS_PORT_TRACING_FUNC_EXIT(gpio, remove_callback, port, ret);
return ret;
}

/**
Expand Down Expand Up @@ -1812,12 +1876,18 @@ static inline int z_impl_gpio_get_pending_int(const struct device *dev)
{
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)dev->api;
int ret;

SYS_PORT_TRACING_FUNC_ENTER(gpio, get_pending_int, dev);

if (api->get_pending_int == NULL) {
SYS_PORT_TRACING_FUNC_EXIT(gpio, get_pending_int, dev, -ENOSYS);
return -ENOSYS;
}

return api->get_pending_int(dev);
ret = api->get_pending_int(dev);
SYS_PORT_TRACING_FUNC_EXIT(gpio, get_pending_int, dev, ret);
return ret;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions include/zephyr/drivers/gpio/gpio_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <zephyr/drivers/gpio.h>
#include <zephyr/sys/__assert.h>
#include <zephyr/sys/slist.h>
#include <zephyr/tracing/tracing.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -92,10 +93,14 @@ static inline void gpio_fire_callbacks(sys_slist_t *list,
{
struct gpio_callback *cb, *tmp;

sys_port_trace_gpio_fire_callbacks_enter(list, port, pins);

SYS_SLIST_FOR_EACH_CONTAINER_SAFE(list, cb, tmp, node) {
if (cb->pin_mask & pins) {
__ASSERT(cb->handler, "No callback handler!");

cb->handler(port, cb, cb->pin_mask & pins);
sys_port_trace_gpio_fire_callback(port, cb);
}
}
}
Expand Down
Loading
Loading