Skip to content

Commit

Permalink
drivers: uart: Add return value to FIFO API callback set
Browse files Browse the repository at this point in the history
If the interrupt-driven aka FIFO API is not enabled or not supported by
a given UART, have the functions for setting the irq callback return an
error code.  They previously returned void.

This is the same way the analogous functions in the async UART API work.

This way it is possible to detect API support when a UART consumer
initializes.

Issue #53155

Signed-off-by: Trent Piepho <tpiepho@gmail.com>
  • Loading branch information
xyzzy42 authored and carlescufi committed Dec 31, 2022
1 parent d320100 commit 9ee1e64
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions include/zephyr/drivers/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -1160,22 +1160,30 @@ static inline int z_impl_uart_irq_update(const struct device *dev)
* @param dev UART device instance.
* @param cb Pointer to the callback function.
* @param user_data Data to pass to callback function.
*
* @retval 0 On success.
* @retval -ENOSYS If this function is not implemented.
* @retval -ENOTSUP If API is not enabled.
*/
static inline void uart_irq_callback_user_data_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *user_data)
static inline int uart_irq_callback_user_data_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *user_data)
{
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
const struct uart_driver_api *api =
(const struct uart_driver_api *)dev->api;

if ((api != NULL) && (api->irq_callback_set != NULL)) {
api->irq_callback_set(dev, cb, user_data);
return 0;
} else {
return -ENOSYS;
}
#else
ARG_UNUSED(dev);
ARG_UNUSED(cb);
ARG_UNUSED(user_data);
return -ENOTSUP;
#endif
}

Expand All @@ -1187,11 +1195,15 @@ static inline void uart_irq_callback_user_data_set(const struct device *dev,
*
* @param dev UART device instance.
* @param cb Pointer to the callback function.
*
* @retval 0 On success.
* @retval -ENOSYS If this function is not implemented.
* @retval -ENOTSUP If API is not enabled.
*/
static inline void uart_irq_callback_set(const struct device *dev,
static inline int uart_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb)
{
uart_irq_callback_user_data_set(dev, cb, NULL);
return uart_irq_callback_user_data_set(dev, cb, NULL);
}

/**
Expand Down

0 comments on commit 9ee1e64

Please sign in to comment.