drivers: serial: async_to_irq: Fix initialization
Callback was set in uart_async_to_irq_rx_enable() which is only called when RX is enabled. Callback shall be called in the init function. uart_async_to_irq_init() signature changed to take device as the input argument instead of data and config for the adaptation layer (which can be retrieved from the device). Device is needed when setting a callback during the initialization. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
5ce801fa2b
commit
e48053fdb5
3 changed files with 13 additions and 14 deletions
|
@ -336,15 +336,8 @@ void z_uart_async_to_irq_irq_callback_set(const struct device *dev,
|
||||||
int uart_async_to_irq_rx_enable(const struct device *dev)
|
int uart_async_to_irq_rx_enable(const struct device *dev)
|
||||||
{
|
{
|
||||||
struct uart_async_to_irq_data *data = get_data(dev);
|
struct uart_async_to_irq_data *data = get_data(dev);
|
||||||
const struct uart_async_to_irq_config *config = get_config(dev);
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = config->api->callback_set(dev, uart_async_to_irq_callback, data);
|
|
||||||
if (err < 0) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
err = try_rx_enable(dev, data);
|
err = try_rx_enable(dev, data);
|
||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
atomic_or(&data->flags, A2I_RX_ENABLE);
|
atomic_or(&data->flags, A2I_RX_ENABLE);
|
||||||
|
@ -381,13 +374,21 @@ void uart_async_to_irq_trampoline_cb(const struct device *dev)
|
||||||
} while (atomic_dec(&data->irq_req) > 1);
|
} while (atomic_dec(&data->irq_req) > 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int uart_async_to_irq_init(struct uart_async_to_irq_data *data,
|
int uart_async_to_irq_init(const struct device *dev)
|
||||||
const struct uart_async_to_irq_config *config)
|
|
||||||
{
|
{
|
||||||
|
struct uart_async_to_irq_data *data = get_data(dev);
|
||||||
|
const struct uart_async_to_irq_config *config = get_config(dev);
|
||||||
|
int err;
|
||||||
|
|
||||||
data->tx.buf = config->tx_buf;
|
data->tx.buf = config->tx_buf;
|
||||||
data->tx.len = config->tx_len;
|
data->tx.len = config->tx_len;
|
||||||
|
|
||||||
k_sem_init(&data->rx.sem, 0, 1);
|
k_sem_init(&data->rx.sem, 0, 1);
|
||||||
|
|
||||||
|
err = config->api->callback_set(dev, uart_async_to_irq_callback, data);
|
||||||
|
if (err < 0) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
return uart_async_rx_init(&data->rx.async_rx, &config->async_rx);
|
return uart_async_rx_init(&data->rx.async_rx, &config->async_rx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -857,7 +857,7 @@ static int uarte_nrfx_init(const struct device *dev)
|
||||||
|
|
||||||
if (UARTE_ANY_INTERRUPT_DRIVEN) {
|
if (UARTE_ANY_INTERRUPT_DRIVEN) {
|
||||||
if (cfg->a2i_config) {
|
if (cfg->a2i_config) {
|
||||||
err = uart_async_to_irq_init(data->a2i_data, cfg->a2i_config);
|
err = uart_async_to_irq_init(dev);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,13 +109,11 @@ void uart_async_to_irq_trampoline_cb(const struct device *dev);
|
||||||
|
|
||||||
/** @brief Initialize the adaptation layer.
|
/** @brief Initialize the adaptation layer.
|
||||||
*
|
*
|
||||||
* @param data Data associated with the given adaptation layer instance.
|
* @param dev UART device. Device must support asynchronous API.
|
||||||
* @param config Configuration structure. Must be persistent.
|
|
||||||
*
|
*
|
||||||
* @retval 0 On successful initialization.
|
* @retval 0 On successful initialization.
|
||||||
*/
|
*/
|
||||||
int uart_async_to_irq_init(struct uart_async_to_irq_data *data,
|
int uart_async_to_irq_init(const struct device *dev);
|
||||||
const struct uart_async_to_irq_config *config);
|
|
||||||
|
|
||||||
/* @brief Enable RX for interrupt driven API.
|
/* @brief Enable RX for interrupt driven API.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue