Lines Matching +full:uart +full:- +full:dev
2 * Copyright (c) 2018 - 2019 Antmicro <www.antmicro.com>
4 * SPDX-License-Identifier: Apache-2.0
14 #include <zephyr/drivers/uart.h>
33 void (*config_func)(const struct device *dev);
50 * @param dev UART device struct
53 static void uart_litex_poll_out(const struct device *dev, unsigned char c) in uart_litex_poll_out() argument
55 const struct uart_litex_device_config *config = dev->config; in uart_litex_poll_out()
57 while (litex_read8(config->txfull_addr)) { in uart_litex_poll_out()
60 litex_write8(c, config->rxtx_addr); in uart_litex_poll_out()
66 * @param dev UART device struct
69 * @return 0 if a character arrived, -1 if the input buffer if empty.
71 static int uart_litex_poll_in(const struct device *dev, unsigned char *c) in uart_litex_poll_in() argument
73 const struct uart_litex_device_config *config = dev->config; in uart_litex_poll_in()
75 if (!litex_read8(config->rxempty_addr)) { in uart_litex_poll_in()
76 *c = litex_read8(config->rxtx_addr); in uart_litex_poll_in()
81 litex_write8(UART_EV_RX, config->ev_pending_addr); in uart_litex_poll_in()
84 return -1; in uart_litex_poll_in()
92 * @param dev UART device struct
94 static void uart_litex_irq_tx_enable(const struct device *dev) in uart_litex_irq_tx_enable() argument
96 const struct uart_litex_device_config *config = dev->config; in uart_litex_irq_tx_enable()
97 struct uart_litex_data *data = dev->data; in uart_litex_irq_tx_enable()
99 uint8_t enable = litex_read8(config->ev_enable_addr); in uart_litex_irq_tx_enable()
101 litex_write8(enable | UART_EV_TX, config->ev_enable_addr); in uart_litex_irq_tx_enable()
103 if (!litex_read8(config->txfull_addr)) { in uart_litex_irq_tx_enable()
109 k_timer_start(&data->timer, K_NO_WAIT, K_NO_WAIT); in uart_litex_irq_tx_enable()
116 * @param dev UART device struct
118 static void uart_litex_irq_tx_disable(const struct device *dev) in uart_litex_irq_tx_disable() argument
120 const struct uart_litex_device_config *config = dev->config; in uart_litex_irq_tx_disable()
122 uint8_t enable = litex_read8(config->ev_enable_addr); in uart_litex_irq_tx_disable()
124 litex_write8(enable & ~(UART_EV_TX), config->ev_enable_addr); in uart_litex_irq_tx_disable()
130 * @param dev UART device struct
132 static void uart_litex_irq_rx_enable(const struct device *dev) in uart_litex_irq_rx_enable() argument
134 const struct uart_litex_device_config *config = dev->config; in uart_litex_irq_rx_enable()
136 uint8_t enable = litex_read8(config->ev_enable_addr); in uart_litex_irq_rx_enable()
138 litex_write8(enable | UART_EV_RX, config->ev_enable_addr); in uart_litex_irq_rx_enable()
144 * @param dev UART device struct
146 static void uart_litex_irq_rx_disable(const struct device *dev) in uart_litex_irq_rx_disable() argument
148 const struct uart_litex_device_config *config = dev->config; in uart_litex_irq_rx_disable()
150 uint8_t enable = litex_read8(config->ev_enable_addr); in uart_litex_irq_rx_disable()
152 litex_write8(enable & ~(UART_EV_RX), config->ev_enable_addr); in uart_litex_irq_rx_disable()
156 * @brief Check if Tx IRQ has been raised and UART is ready to accept new data
158 * @param dev UART device struct
162 static int uart_litex_irq_tx_ready(const struct device *dev) in uart_litex_irq_tx_ready() argument
164 const struct uart_litex_device_config *config = dev->config; in uart_litex_irq_tx_ready()
166 uint8_t val = litex_read8(config->txfull_addr); in uart_litex_irq_tx_ready()
172 * @brief Check if Rx IRQ has been raised and there's data to be read from UART
174 * @param dev UART device struct
178 static int uart_litex_irq_rx_ready(const struct device *dev) in uart_litex_irq_rx_ready() argument
180 const struct uart_litex_device_config *config = dev->config; in uart_litex_irq_rx_ready()
183 pending = litex_read8(config->ev_pending_addr); in uart_litex_irq_rx_ready()
195 * @param dev UART device struct
201 static int uart_litex_fifo_fill(const struct device *dev, in uart_litex_fifo_fill() argument
204 const struct uart_litex_device_config *config = dev->config; in uart_litex_fifo_fill()
207 for (i = 0; i < size && !litex_read8(config->txfull_addr); i++) { in uart_litex_fifo_fill()
208 litex_write8(tx_data[i], config->rxtx_addr); in uart_litex_fifo_fill()
217 * @param dev UART device struct
223 static int uart_litex_fifo_read(const struct device *dev, in uart_litex_fifo_read() argument
226 const struct uart_litex_device_config *config = dev->config; in uart_litex_fifo_read()
229 for (i = 0; i < size && !litex_read8(config->rxempty_addr); i++) { in uart_litex_fifo_read()
230 rx_data[i] = litex_read8(config->rxtx_addr); in uart_litex_fifo_read()
235 litex_write8(UART_EV_RX, config->ev_pending_addr); in uart_litex_fifo_read()
241 static void uart_litex_irq_err(const struct device *dev) in uart_litex_irq_err() argument
243 ARG_UNUSED(dev); in uart_litex_irq_err()
249 * @param dev UART device struct
253 static int uart_litex_irq_is_pending(const struct device *dev) in uart_litex_irq_is_pending() argument
255 return (uart_litex_irq_tx_ready(dev) || uart_litex_irq_rx_ready(dev)); in uart_litex_irq_is_pending()
258 static int uart_litex_irq_update(const struct device *dev) in uart_litex_irq_update() argument
266 * @param dev UART device struct
269 static void uart_litex_irq_callback_set(const struct device *dev, in uart_litex_irq_callback_set() argument
275 data = dev->data; in uart_litex_irq_callback_set()
276 data->callback = cb; in uart_litex_irq_callback_set()
277 data->cb_data = cb_data; in uart_litex_irq_callback_set()
280 static void uart_litex_irq_handler(const struct device *dev) in uart_litex_irq_handler() argument
282 const struct uart_litex_device_config *config = dev->config; in uart_litex_irq_handler()
283 struct uart_litex_data *data = dev->data; in uart_litex_irq_handler()
286 if (data->callback) { in uart_litex_irq_handler()
287 data->callback(dev, data->cb_data); in uart_litex_irq_handler()
291 litex_write8(UART_EV_RX, config->ev_pending_addr); in uart_litex_irq_handler()
298 const struct device *dev = k_timer_user_data_get(timer); in uart_litex_tx_soft_isr() local
300 uart_litex_irq_handler(dev); in uart_litex_tx_soft_isr()
304 static DEVICE_API(uart, uart_litex_driver_api) = {
325 static int uart_litex_init(const struct device *dev) in uart_litex_init() argument
327 const struct uart_litex_device_config *config = dev->config; in uart_litex_init()
329 litex_write8(UART_EV_TX | UART_EV_RX, config->ev_pending_addr); in uart_litex_init()
332 struct uart_litex_data *data = dev->data; in uart_litex_init()
334 k_timer_init(&data->timer, &uart_litex_tx_soft_isr, NULL); in uart_litex_init()
335 k_timer_user_data_set(&data->timer, (void *)dev); in uart_litex_init()
337 config->config_func(dev); in uart_litex_init()
344 static void uart_irq_config##n(const struct device *dev) \