Lines Matching +full:uart +full:- +full:dev
4 * SPDX-License-Identifier: Apache-2.0
10 * @brief Driver for UART on NXP IMX family processor.
21 #include <zephyr/drivers/uart.h>
26 #define UART_STRUCT(dev) \ argument
27 ((UART_Type *)((const struct imx_uart_config *const)(dev)->config)->base)
35 void (*irq_config_func)(const struct device *dev);
47 * @brief Initialize UART channel
50 * It is assumed that this function is called only once per UART.
52 * @param dev UART device struct
56 static int uart_imx_init(const struct device *dev) in uart_imx_init() argument
58 UART_Type *uart = UART_STRUCT(dev); in uart_imx_init() local
59 const struct imx_uart_config *config = dev->config; in uart_imx_init()
66 /* Setup UART init structure */ in uart_imx_init()
68 .baudRate = config->baud_rate, in uart_imx_init()
75 err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); in uart_imx_init()
81 initConfig.clockRate = get_uart_clock_freq(uart); in uart_imx_init()
83 UART_Init(uart, &initConfig); in uart_imx_init()
85 /* Set UART built-in hardware FIFO Watermark. */ in uart_imx_init()
86 UART_SetTxFifoWatermark(uart, 2); in uart_imx_init()
87 UART_SetRxFifoWatermark(uart, 1); in uart_imx_init()
93 config->irq_config_func(dev); in uart_imx_init()
96 /* Set UART modem mode */ in uart_imx_init()
97 UART_SetModemMode(uart, config->modem_mode); in uart_imx_init()
99 /* Finally, enable the UART module */ in uart_imx_init()
100 UART_Enable(uart); in uart_imx_init()
105 static void uart_imx_poll_out(const struct device *dev, unsigned char c) in uart_imx_poll_out() argument
107 UART_Type *uart = UART_STRUCT(dev); in uart_imx_poll_out() local
109 while (!UART_GetStatusFlag(uart, uartStatusTxReady)) { in uart_imx_poll_out()
111 UART_Putchar(uart, c); in uart_imx_poll_out()
114 static int uart_imx_poll_in(const struct device *dev, unsigned char *c) in uart_imx_poll_in() argument
116 UART_Type *uart = UART_STRUCT(dev); in uart_imx_poll_in() local
117 int ret = -1; in uart_imx_poll_in()
119 if (UART_GetStatusFlag(uart, uartStatusRxDataReady)) { in uart_imx_poll_in()
120 *c = UART_Getchar(uart); in uart_imx_poll_in()
122 if (UART_GetStatusFlag(uart, uartStatusRxOverrun)) { in uart_imx_poll_in()
123 UART_ClearStatusFlag(uart, uartStatusRxOverrun); in uart_imx_poll_in()
133 static int uart_imx_fifo_fill(const struct device *dev, in uart_imx_fifo_fill() argument
137 UART_Type *uart = UART_STRUCT(dev); in uart_imx_fifo_fill() local
140 while (((size - num_tx) > 0) && in uart_imx_fifo_fill()
141 UART_GetStatusFlag(uart, uartStatusTxReady)) { in uart_imx_fifo_fill()
143 UART_Putchar(uart, tx_data[num_tx]); in uart_imx_fifo_fill()
150 static int uart_imx_fifo_read(const struct device *dev, uint8_t *rx_data, in uart_imx_fifo_read() argument
153 UART_Type *uart = UART_STRUCT(dev); in uart_imx_fifo_read() local
156 while (((size - num_rx) > 0) && in uart_imx_fifo_read()
157 UART_GetStatusFlag(uart, uartStatusRxReady)) { in uart_imx_fifo_read()
159 rx_data[num_rx++] = UART_Getchar(uart); in uart_imx_fifo_read()
162 if (UART_GetStatusFlag(uart, uartStatusRxOverrun)) { in uart_imx_fifo_read()
163 UART_ClearStatusFlag(uart, uartStatusRxOverrun); in uart_imx_fifo_read()
169 static void uart_imx_irq_tx_enable(const struct device *dev) in uart_imx_irq_tx_enable() argument
171 UART_Type *uart = UART_STRUCT(dev); in uart_imx_irq_tx_enable() local
173 UART_SetIntCmd(uart, uartIntTxReady, true); in uart_imx_irq_tx_enable()
176 static void uart_imx_irq_tx_disable(const struct device *dev) in uart_imx_irq_tx_disable() argument
178 UART_Type *uart = UART_STRUCT(dev); in uart_imx_irq_tx_disable() local
180 UART_SetIntCmd(uart, uartIntTxReady, false); in uart_imx_irq_tx_disable()
183 static int uart_imx_irq_tx_ready(const struct device *dev) in uart_imx_irq_tx_ready() argument
185 UART_Type *uart = UART_STRUCT(dev); in uart_imx_irq_tx_ready() local
187 return UART_GetStatusFlag(uart, uartStatusTxReady); in uart_imx_irq_tx_ready()
190 static void uart_imx_irq_rx_enable(const struct device *dev) in uart_imx_irq_rx_enable() argument
192 UART_Type *uart = UART_STRUCT(dev); in uart_imx_irq_rx_enable() local
194 UART_SetIntCmd(uart, uartIntRxReady, true); in uart_imx_irq_rx_enable()
197 static void uart_imx_irq_rx_disable(const struct device *dev) in uart_imx_irq_rx_disable() argument
199 UART_Type *uart = UART_STRUCT(dev); in uart_imx_irq_rx_disable() local
201 UART_SetIntCmd(uart, uartIntRxReady, false); in uart_imx_irq_rx_disable()
204 static int uart_imx_irq_rx_ready(const struct device *dev) in uart_imx_irq_rx_ready() argument
206 UART_Type *uart = UART_STRUCT(dev); in uart_imx_irq_rx_ready() local
208 return UART_GetStatusFlag(uart, uartStatusRxReady); in uart_imx_irq_rx_ready()
211 static void uart_imx_irq_err_enable(const struct device *dev) in uart_imx_irq_err_enable() argument
213 UART_Type *uart = UART_STRUCT(dev); in uart_imx_irq_err_enable() local
215 UART_SetIntCmd(uart, uartIntParityError, true); in uart_imx_irq_err_enable()
216 UART_SetIntCmd(uart, uartIntFrameError, true); in uart_imx_irq_err_enable()
219 static void uart_imx_irq_err_disable(const struct device *dev) in uart_imx_irq_err_disable() argument
221 UART_Type *uart = UART_STRUCT(dev); in uart_imx_irq_err_disable() local
223 UART_SetIntCmd(uart, uartIntParityError, false); in uart_imx_irq_err_disable()
224 UART_SetIntCmd(uart, uartIntFrameError, false); in uart_imx_irq_err_disable()
227 static int uart_imx_irq_is_pending(const struct device *dev) in uart_imx_irq_is_pending() argument
229 UART_Type *uart = UART_STRUCT(dev); in uart_imx_irq_is_pending() local
231 return UART_GetStatusFlag(uart, uartStatusRxReady) || in uart_imx_irq_is_pending()
232 UART_GetStatusFlag(uart, uartStatusTxReady); in uart_imx_irq_is_pending()
235 static int uart_imx_irq_update(const struct device *dev) in uart_imx_irq_update() argument
240 static void uart_imx_irq_callback_set(const struct device *dev, in uart_imx_irq_callback_set() argument
244 struct imx_uart_data *data = dev->data; in uart_imx_irq_callback_set()
246 data->callback = cb; in uart_imx_irq_callback_set()
247 data->cb_data = cb_data; in uart_imx_irq_callback_set()
255 * Note: imx UART Tx interrupts when ready to send; Rx interrupts when char
260 void uart_imx_isr(const struct device *dev) in uart_imx_isr() argument
262 struct imx_uart_data *data = dev->data; in uart_imx_isr()
264 if (data->callback) { in uart_imx_isr()
265 data->callback(dev, data->cb_data); in uart_imx_isr()
270 static DEVICE_API(uart, uart_imx_driver_api) = {
303 static void irq_config_func_##n(const struct device *dev) \