drivers: serial: Fix uart_callback_t usage in relevant drivers
Now providing the device pointer that calls the callback. Fixes #26923 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
parent
4644d4a40c
commit
915608b80a
3 changed files with 43 additions and 39 deletions
|
@ -52,6 +52,8 @@ BUILD_ASSERT((PROP(hw_flow_control) && HW_FLOW_CONTROL_AVAILABLE) ||
|
|||
|
||||
static NRF_UART_Type *const uart0_addr = (NRF_UART_Type *)DT_INST_REG_ADDR(0);
|
||||
|
||||
DEVICE_DECLARE(uart_nrfx_uart0);
|
||||
|
||||
/* Device data structure */
|
||||
struct uart_nrfx_data {
|
||||
struct uart_config uart_config;
|
||||
|
@ -394,10 +396,10 @@ static int uart_nrfx_config_get(struct device *dev, struct uart_config *cfg)
|
|||
|
||||
#ifdef CONFIG_UART_0_ASYNC
|
||||
|
||||
static void user_callback(struct uart_event *event)
|
||||
static void user_callback(struct device *dev, struct uart_event *event)
|
||||
{
|
||||
if (uart0_cb.callback) {
|
||||
uart0_cb.callback(event, uart0_cb.user_data);
|
||||
uart0_cb.callback(dev, event, uart0_cb.user_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -455,7 +457,7 @@ static int uart_nrfx_tx_abort(struct device *dev)
|
|||
uart0_cb.tx_buffer_length = 0;
|
||||
uart0_cb.tx_counter = 0;
|
||||
|
||||
user_callback(&evt);
|
||||
user_callback(dev, &evt);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -519,7 +521,7 @@ static int uart_nrfx_rx_disable(struct device *dev)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void rx_rdy_evt(void)
|
||||
static void rx_rdy_evt(struct device *dev)
|
||||
{
|
||||
struct uart_event event;
|
||||
size_t rx_cnt = uart0_cb.rx_counter;
|
||||
|
@ -531,24 +533,24 @@ static void rx_rdy_evt(void)
|
|||
|
||||
uart0_cb.rx_offset = rx_cnt;
|
||||
|
||||
user_callback(&event);
|
||||
user_callback(dev, &event);
|
||||
}
|
||||
|
||||
static void buf_released_evt(void)
|
||||
static void buf_released_evt(struct device *dev)
|
||||
{
|
||||
struct uart_event event = {
|
||||
.type = UART_RX_BUF_RELEASED,
|
||||
.data.rx_buf.buf = uart0_cb.rx_buffer
|
||||
};
|
||||
user_callback(&event);
|
||||
user_callback(dev, &event);
|
||||
}
|
||||
|
||||
static void rx_disabled_evt(void)
|
||||
static void rx_disabled_evt(struct device *dev)
|
||||
{
|
||||
struct uart_event event = {
|
||||
.type = UART_RX_DISABLED
|
||||
};
|
||||
user_callback(&event);
|
||||
user_callback(dev, &event);
|
||||
}
|
||||
|
||||
static void rx_reset_state(void)
|
||||
|
@ -576,13 +578,13 @@ static void rx_isr(struct device *dev)
|
|||
} else {
|
||||
if (uart0_cb.rx_counter == 0) {
|
||||
event.type = UART_RX_BUF_REQUEST;
|
||||
user_callback(&event);
|
||||
user_callback(dev, &event);
|
||||
}
|
||||
uart0_cb.rx_buffer[uart0_cb.rx_counter] =
|
||||
nrf_uart_rxd_get(uart0_addr);
|
||||
uart0_cb.rx_counter++;
|
||||
if (uart0_cb.rx_timeout == 0) {
|
||||
rx_rdy_evt();
|
||||
rx_rdy_evt(dev);
|
||||
} else if (uart0_cb.rx_timeout != SYS_FOREVER_MS) {
|
||||
k_delayed_work_submit(&uart0_cb.rx_timeout_work,
|
||||
K_MSEC(uart0_cb.rx_timeout));
|
||||
|
@ -593,10 +595,10 @@ static void rx_isr(struct device *dev)
|
|||
if (uart0_cb.rx_timeout != SYS_FOREVER_MS) {
|
||||
k_delayed_work_cancel(&uart0_cb.rx_timeout_work);
|
||||
}
|
||||
rx_rdy_evt();
|
||||
rx_rdy_evt(dev);
|
||||
|
||||
if (uart0_cb.rx_secondary_buffer_length) {
|
||||
buf_released_evt();
|
||||
buf_released_evt(dev);
|
||||
/* Switch to secondary buffer. */
|
||||
uart0_cb.rx_buffer_length =
|
||||
uart0_cb.rx_secondary_buffer_length;
|
||||
|
@ -606,14 +608,14 @@ static void rx_isr(struct device *dev)
|
|||
uart0_cb.rx_offset = 0;
|
||||
|
||||
event.type = UART_RX_BUF_REQUEST;
|
||||
user_callback(&event);
|
||||
user_callback(dev, &event);
|
||||
} else {
|
||||
uart_nrfx_rx_disable(dev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void tx_isr(void)
|
||||
static void tx_isr(struct device *dev)
|
||||
{
|
||||
uart0_cb.tx_counter++;
|
||||
if (uart0_cb.tx_counter < uart0_cb.tx_buffer_length &&
|
||||
|
@ -648,7 +650,7 @@ static void tx_isr(void)
|
|||
uart0_cb.tx_buffer = NULL;
|
||||
|
||||
nrf_uart_int_disable(uart0_addr, NRF_UART_INT_MASK_TXDRDY);
|
||||
user_callback(&event);
|
||||
user_callback(dev, &event);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -680,7 +682,7 @@ static void error_isr(struct device *dev)
|
|||
.data.rx_stop.data.buf = uart0_cb.rx_buffer
|
||||
};
|
||||
|
||||
user_callback(&event);
|
||||
user_callback(dev, &event);
|
||||
/* Abort transfer. */
|
||||
uart_nrfx_rx_disable(dev);
|
||||
}
|
||||
|
@ -690,23 +692,23 @@ static void error_isr(struct device *dev)
|
|||
* it is used as a sign that peripheral has finished its operation and is
|
||||
* disabled.
|
||||
*/
|
||||
static void rxto_isr(void)
|
||||
static void rxto_isr(struct device *dev)
|
||||
{
|
||||
nrf_uart_event_clear(uart0_addr, NRF_UART_EVENT_RXTO);
|
||||
|
||||
/* Send rxrdy if there is any data pending. */
|
||||
if (uart0_cb.rx_counter - uart0_cb.rx_offset) {
|
||||
rx_rdy_evt();
|
||||
rx_rdy_evt(dev);
|
||||
}
|
||||
|
||||
buf_released_evt();
|
||||
buf_released_evt(dev);
|
||||
if (uart0_cb.rx_secondary_buffer_length) {
|
||||
uart0_cb.rx_buffer = uart0_cb.rx_secondary_buffer;
|
||||
buf_released_evt();
|
||||
buf_released_evt(dev);
|
||||
}
|
||||
|
||||
rx_reset_state();
|
||||
rx_disabled_evt();
|
||||
rx_disabled_evt(dev);
|
||||
}
|
||||
|
||||
void uart_nrfx_isr(void *arg)
|
||||
|
@ -725,17 +727,17 @@ void uart_nrfx_isr(void *arg)
|
|||
if (nrf_uart_event_check(uart0_addr, NRF_UART_EVENT_TXDRDY)
|
||||
&& nrf_uart_int_enable_check(uart0_addr,
|
||||
NRF_UART_INT_MASK_TXDRDY)) {
|
||||
tx_isr();
|
||||
tx_isr(uart);
|
||||
}
|
||||
|
||||
if (nrf_uart_event_check(uart0_addr, NRF_UART_EVENT_RXTO)) {
|
||||
rxto_isr();
|
||||
rxto_isr(uart);
|
||||
}
|
||||
}
|
||||
|
||||
static void rx_timeout(struct k_work *work)
|
||||
{
|
||||
rx_rdy_evt();
|
||||
rx_rdy_evt(DEVICE_GET(uart_nrfx_uart0));
|
||||
}
|
||||
|
||||
#if HW_FLOW_CONTROL_AVAILABLE
|
||||
|
@ -752,7 +754,7 @@ static void tx_timeout(struct k_work *work)
|
|||
evt.data.tx.len = uart0_cb.tx_buffer_length;
|
||||
uart0_cb.tx_buffer_length = 0;
|
||||
uart0_cb.tx_counter = 0;
|
||||
user_callback(&evt);
|
||||
user_callback(DEVICE_GET(uart_nrfx_uart0), &evt);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
@ -953,8 +955,6 @@ static void uart_nrfx_isr(void *arg)
|
|||
}
|
||||
#endif /* CONFIG_UART_0_INTERRUPT_DRIVEN */
|
||||
|
||||
DEVICE_DECLARE(uart_nrfx_uart0);
|
||||
|
||||
/**
|
||||
* @brief Initialize UART channel
|
||||
*
|
||||
|
|
|
@ -622,7 +622,7 @@ static void user_callback(struct device *dev, struct uart_event *evt)
|
|||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
|
||||
if (data->async->user_callback) {
|
||||
data->async->user_callback(evt, data->async->user_data);
|
||||
data->async->user_callback(dev, evt, data->async->user_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ struct uart_sam0_dev_data {
|
|||
void *cb_data;
|
||||
#endif
|
||||
#if CONFIG_UART_ASYNC_API
|
||||
struct device *dev;
|
||||
const struct uart_sam0_dev_cfg *cfg;
|
||||
struct device *dma;
|
||||
|
||||
|
@ -143,7 +144,7 @@ static void uart_sam0_dma_tx_done(void *arg, uint32_t id, int error_code)
|
|||
dev_data->tx_len = 0U;
|
||||
|
||||
if (evt.data.tx.len != 0U && dev_data->async_cb) {
|
||||
dev_data->async_cb(&evt, dev_data->async_cb_data);
|
||||
dev_data->async_cb(dev, &evt, dev_data->async_cb_data);
|
||||
}
|
||||
|
||||
irq_unlock(key);
|
||||
|
@ -177,7 +178,8 @@ static int uart_sam0_tx_halt(struct uart_sam0_dev_data *dev_data)
|
|||
|
||||
if (tx_active) {
|
||||
if (dev_data->async_cb) {
|
||||
dev_data->async_cb(&evt, dev_data->async_cb_data);
|
||||
dev_data->async_cb(dev_data->dev,
|
||||
&evt, dev_data->async_cb_data);
|
||||
}
|
||||
} else {
|
||||
return -EINVAL;
|
||||
|
@ -216,7 +218,8 @@ static void uart_sam0_notify_rx_processed(struct uart_sam0_dev_data *dev_data,
|
|||
|
||||
dev_data->rx_processed_len = processed;
|
||||
|
||||
dev_data->async_cb(&evt, dev_data->async_cb_data);
|
||||
dev_data->async_cb(dev_data->dev,
|
||||
&evt, dev_data->async_cb_data);
|
||||
}
|
||||
|
||||
static void uart_sam0_dma_rx_done(void *arg, uint32_t id, int error_code)
|
||||
|
@ -245,7 +248,7 @@ static void uart_sam0_dma_rx_done(void *arg, uint32_t id, int error_code)
|
|||
},
|
||||
};
|
||||
|
||||
dev_data->async_cb(&evt, dev_data->async_cb_data);
|
||||
dev_data->async_cb(dev, &evt, dev_data->async_cb_data);
|
||||
}
|
||||
|
||||
/* No next buffer, so end the transfer */
|
||||
|
@ -258,7 +261,7 @@ static void uart_sam0_dma_rx_done(void *arg, uint32_t id, int error_code)
|
|||
.type = UART_RX_DISABLED,
|
||||
};
|
||||
|
||||
dev_data->async_cb(&evt, dev_data->async_cb_data);
|
||||
dev_data->async_cb(dev, &evt, dev_data->async_cb_data);
|
||||
}
|
||||
|
||||
irq_unlock(key);
|
||||
|
@ -295,7 +298,7 @@ static void uart_sam0_dma_rx_done(void *arg, uint32_t id, int error_code)
|
|||
.type = UART_RX_BUF_REQUEST,
|
||||
};
|
||||
|
||||
dev_data->async_cb(&evt, dev_data->async_cb_data);
|
||||
dev_data->async_cb(dev, &evt, dev_data->async_cb_data);
|
||||
|
||||
irq_unlock(key);
|
||||
}
|
||||
|
@ -556,6 +559,7 @@ static int uart_sam0_init(struct device *dev)
|
|||
#endif
|
||||
|
||||
#ifdef CONFIG_UART_ASYNC_API
|
||||
dev_data->dev = dev;
|
||||
dev_data->cfg = cfg;
|
||||
dev_data->dma = device_get_binding(cfg->dma_dev);
|
||||
|
||||
|
@ -677,7 +681,7 @@ static void uart_sam0_isr(void *arg)
|
|||
.type = UART_RX_BUF_REQUEST,
|
||||
};
|
||||
|
||||
dev_data->async_cb(&evt, dev_data->async_cb_data);
|
||||
dev_data->async_cb(dev, &evt, dev_data->async_cb_data);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -989,7 +993,7 @@ static int uart_sam0_rx_disable(struct device *dev)
|
|||
dev_data->rx_len = 0U;
|
||||
|
||||
if (dev_data->async_cb) {
|
||||
dev_data->async_cb(&evt, dev_data->async_cb_data);
|
||||
dev_data->async_cb(dev, &evt, dev_data->async_cb_data);
|
||||
}
|
||||
|
||||
if (dev_data->rx_next_len) {
|
||||
|
@ -1004,13 +1008,13 @@ static int uart_sam0_rx_disable(struct device *dev)
|
|||
dev_data->rx_next_len = 0U;
|
||||
|
||||
if (dev_data->async_cb) {
|
||||
dev_data->async_cb(&evt, dev_data->async_cb_data);
|
||||
dev_data->async_cb(dev, &evt, dev_data->async_cb_data);
|
||||
}
|
||||
}
|
||||
|
||||
evt.type = UART_RX_DISABLED;
|
||||
if (dev_data->async_cb) {
|
||||
dev_data->async_cb(&evt, dev_data->async_cb_data);
|
||||
dev_data->async_cb(dev, &evt, dev_data->async_cb_data);
|
||||
}
|
||||
|
||||
irq_unlock(key);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue