Lines Matching +full:uart +full:- +full:dev
4 * SPDX-License-Identifier: Apache-2.0
10 * @brief Driver for UART on ARM CMSDK APB UART.
12 * UART has two wires for RX and TX, and does not provide CTS or RTS.
20 #include <zephyr/drivers/uart.h>
24 /* UART registers struct */
42 /* UART Bits */
65 volatile struct uart_cmsdk_apb *uart; member
79 /* UART Clock control in Active State */
81 /* UART Clock control in Sleep State */
83 /* UART Clock control in Deep Sleep State */
87 static DEVICE_API(uart, uart_cmsdk_apb_driver_api);
89 static void uart_cmsdk_apb_isr(const struct device *dev);
95 * This routine set the given baud rate for the UART.
97 * @param dev UART device struct
99 static void baudrate_set(const struct device *dev) in baudrate_set() argument
101 const struct uart_cmsdk_apb_config * const dev_cfg = dev->config; in baudrate_set()
102 struct uart_cmsdk_apb_dev_data *const dev_data = dev->data; in baudrate_set()
108 if ((dev_data->baud_rate != 0U) && (dev_cfg->sys_clk_freq != 0U)) { in baudrate_set()
110 dev_cfg->uart->bauddiv = (dev_cfg->sys_clk_freq / dev_data->baud_rate); in baudrate_set()
115 * @brief Initialize UART channel
118 * It is assumed that this function is called only once per UART.
120 * @param dev UART device struct
124 static int uart_cmsdk_apb_init(const struct device *dev) in uart_cmsdk_apb_init() argument
126 const struct uart_cmsdk_apb_config * const dev_cfg = dev->config; in uart_cmsdk_apb_init()
131 struct uart_cmsdk_apb_dev_data * const data = dev->data; in uart_cmsdk_apb_init()
134 return -ENODEV; in uart_cmsdk_apb_init()
138 clock_control_on(clk, (clock_control_subsys_t) &data->uart_cc_as); in uart_cmsdk_apb_init()
139 clock_control_on(clk, (clock_control_subsys_t) &data->uart_cc_ss); in uart_cmsdk_apb_init()
140 clock_control_on(clk, (clock_control_subsys_t) &data->uart_cc_dss); in uart_cmsdk_apb_init()
145 baudrate_set(dev); in uart_cmsdk_apb_init()
148 dev_cfg->uart->ctrl = UART_RX_EN | UART_TX_EN; in uart_cmsdk_apb_init()
151 dev_cfg->irq_config_func(dev); in uart_cmsdk_apb_init()
160 * @param dev UART device struct
163 * @return 0 if a character arrived, -1 if the input buffer if empty.
166 static int uart_cmsdk_apb_poll_in(const struct device *dev, unsigned char *c) in uart_cmsdk_apb_poll_in() argument
168 const struct uart_cmsdk_apb_config *dev_cfg = dev->config; in uart_cmsdk_apb_poll_in()
170 /* If the receiver is not ready returns -1 */ in uart_cmsdk_apb_poll_in()
171 if (!(dev_cfg->uart->state & UART_RX_BF)) { in uart_cmsdk_apb_poll_in()
172 return -1; in uart_cmsdk_apb_poll_in()
176 *c = (unsigned char)dev_cfg->uart->data; in uart_cmsdk_apb_poll_in()
187 * @param dev UART device struct
190 static void uart_cmsdk_apb_poll_out(const struct device *dev, in uart_cmsdk_apb_poll_out() argument
193 const struct uart_cmsdk_apb_config *dev_cfg = dev->config; in uart_cmsdk_apb_poll_out()
196 while (dev_cfg->uart->state & UART_TX_BF) { in uart_cmsdk_apb_poll_out()
201 dev_cfg->uart->data = (uint32_t)c; in uart_cmsdk_apb_poll_out()
208 * @param dev UART device struct
214 static int uart_cmsdk_apb_fifo_fill(const struct device *dev, in uart_cmsdk_apb_fifo_fill() argument
217 const struct uart_cmsdk_apb_config *dev_cfg = dev->config; in uart_cmsdk_apb_fifo_fill()
223 if (len && !(dev_cfg->uart->state & UART_TX_BF)) { in uart_cmsdk_apb_fifo_fill()
227 * again automatically by the UART hardware machinery once in uart_cmsdk_apb_fifo_fill()
230 dev_cfg->uart->intclear = UART_TX_IN; in uart_cmsdk_apb_fifo_fill()
231 dev_cfg->uart->data = *tx_data; in uart_cmsdk_apb_fifo_fill()
241 * @param dev UART device struct
247 static int uart_cmsdk_apb_fifo_read(const struct device *dev, in uart_cmsdk_apb_fifo_read() argument
250 const struct uart_cmsdk_apb_config *dev_cfg = dev->config; in uart_cmsdk_apb_fifo_read()
256 if (size && dev_cfg->uart->state & UART_RX_BF) { in uart_cmsdk_apb_fifo_read()
260 * again automatically by the UART hardware machinery once in uart_cmsdk_apb_fifo_read()
263 dev_cfg->uart->intclear = UART_RX_IN; in uart_cmsdk_apb_fifo_read()
264 *rx_data = (unsigned char)dev_cfg->uart->data; in uart_cmsdk_apb_fifo_read()
274 * @param dev UART device struct
276 static void uart_cmsdk_apb_irq_tx_enable(const struct device *dev) in uart_cmsdk_apb_irq_tx_enable() argument
278 const struct uart_cmsdk_apb_config *dev_cfg = dev->config; in uart_cmsdk_apb_irq_tx_enable()
281 dev_cfg->uart->ctrl |= UART_TX_IN_EN; in uart_cmsdk_apb_irq_tx_enable()
283 * long as TX buffer is empty. But in CMSDK UART it's an edge in uart_cmsdk_apb_irq_tx_enable()
291 uart_cmsdk_apb_isr(dev); in uart_cmsdk_apb_irq_tx_enable()
298 * @param dev UART device struct
300 static void uart_cmsdk_apb_irq_tx_disable(const struct device *dev) in uart_cmsdk_apb_irq_tx_disable() argument
302 const struct uart_cmsdk_apb_config *dev_cfg = dev->config; in uart_cmsdk_apb_irq_tx_disable()
304 dev_cfg->uart->ctrl &= ~UART_TX_IN_EN; in uart_cmsdk_apb_irq_tx_disable()
306 dev_cfg->uart->intclear = UART_TX_IN; in uart_cmsdk_apb_irq_tx_disable()
312 * @param dev UART device struct
316 static int uart_cmsdk_apb_irq_tx_ready(const struct device *dev) in uart_cmsdk_apb_irq_tx_ready() argument
318 const struct uart_cmsdk_apb_config *dev_cfg = dev->config; in uart_cmsdk_apb_irq_tx_ready()
320 return !(dev_cfg->uart->state & UART_TX_BF); in uart_cmsdk_apb_irq_tx_ready()
326 * @param dev UART device struct
328 static void uart_cmsdk_apb_irq_rx_enable(const struct device *dev) in uart_cmsdk_apb_irq_rx_enable() argument
330 const struct uart_cmsdk_apb_config *dev_cfg = dev->config; in uart_cmsdk_apb_irq_rx_enable()
332 dev_cfg->uart->ctrl |= UART_RX_IN_EN; in uart_cmsdk_apb_irq_rx_enable()
338 * @param dev UART device struct
340 static void uart_cmsdk_apb_irq_rx_disable(const struct device *dev) in uart_cmsdk_apb_irq_rx_disable() argument
342 const struct uart_cmsdk_apb_config *dev_cfg = dev->config; in uart_cmsdk_apb_irq_rx_disable()
344 dev_cfg->uart->ctrl &= ~UART_RX_IN_EN; in uart_cmsdk_apb_irq_rx_disable()
346 dev_cfg->uart->intclear = UART_RX_IN; in uart_cmsdk_apb_irq_rx_disable()
352 * @param dev UART device struct
356 static int uart_cmsdk_apb_irq_tx_complete(const struct device *dev) in uart_cmsdk_apb_irq_tx_complete() argument
358 return uart_cmsdk_apb_irq_tx_ready(dev); in uart_cmsdk_apb_irq_tx_complete()
364 * @param dev UART device struct
368 static int uart_cmsdk_apb_irq_rx_ready(const struct device *dev) in uart_cmsdk_apb_irq_rx_ready() argument
370 const struct uart_cmsdk_apb_config *dev_cfg = dev->config; in uart_cmsdk_apb_irq_rx_ready()
372 return (dev_cfg->uart->state & UART_RX_BF) == UART_RX_BF; in uart_cmsdk_apb_irq_rx_ready()
378 * @param dev UART device struct
380 static void uart_cmsdk_apb_irq_err_enable(const struct device *dev) in uart_cmsdk_apb_irq_err_enable() argument
382 ARG_UNUSED(dev); in uart_cmsdk_apb_irq_err_enable()
388 * @param dev UART device struct
390 static void uart_cmsdk_apb_irq_err_disable(const struct device *dev) in uart_cmsdk_apb_irq_err_disable() argument
392 ARG_UNUSED(dev); in uart_cmsdk_apb_irq_err_disable()
398 * @param dev UART device struct
402 static int uart_cmsdk_apb_irq_is_pending(const struct device *dev) in uart_cmsdk_apb_irq_is_pending() argument
404 const struct uart_cmsdk_apb_config *dev_cfg = dev->config; in uart_cmsdk_apb_irq_is_pending()
406 return (dev_cfg->uart->intstatus & (UART_RX_IN | UART_TX_IN)); in uart_cmsdk_apb_irq_is_pending()
412 * @param dev UART device struct
416 static int uart_cmsdk_apb_irq_update(const struct device *dev) in uart_cmsdk_apb_irq_update() argument
424 * @param dev UART device structure
427 static void uart_cmsdk_apb_irq_callback_set(const struct device *dev, in uart_cmsdk_apb_irq_callback_set() argument
431 struct uart_cmsdk_apb_dev_data *data = dev->data; in uart_cmsdk_apb_irq_callback_set()
433 data->irq_cb = cb; in uart_cmsdk_apb_irq_callback_set()
434 data->irq_cb_data = cb_data; in uart_cmsdk_apb_irq_callback_set()
444 void uart_cmsdk_apb_isr(const struct device *dev) in uart_cmsdk_apb_isr() argument
446 struct uart_cmsdk_apb_dev_data *data = dev->data; in uart_cmsdk_apb_isr()
449 if (data->irq_cb) { in uart_cmsdk_apb_isr()
450 data->irq_cb(dev, data->irq_cb_data); in uart_cmsdk_apb_isr()
457 static DEVICE_API(uart, uart_cmsdk_apb_driver_api) = {
481 static void uart_cmsdk_apb_irq_config_func_0(const struct device *dev);
485 .uart = (volatile struct uart_cmsdk_apb *)DT_INST_REG_ADDR(0),
512 static void uart_cmsdk_apb_irq_config_func_0(const struct device *dev) in uart_cmsdk_apb_irq_config_func_0() argument
522 static void uart_cmsdk_apb_irq_config_func_0(const struct device *dev) in uart_cmsdk_apb_irq_config_func_0() argument
546 static void uart_cmsdk_apb_irq_config_func_1(const struct device *dev);
550 .uart = (volatile struct uart_cmsdk_apb *)DT_INST_REG_ADDR(1),
577 static void uart_cmsdk_apb_irq_config_func_1(const struct device *dev) in uart_cmsdk_apb_irq_config_func_1() argument
587 static void uart_cmsdk_apb_irq_config_func_1(const struct device *dev) in uart_cmsdk_apb_irq_config_func_1() argument
611 static void uart_cmsdk_apb_irq_config_func_2(const struct device *dev);
615 .uart = (volatile struct uart_cmsdk_apb *)DT_INST_REG_ADDR(2),
642 static void uart_cmsdk_apb_irq_config_func_2(const struct device *dev) in uart_cmsdk_apb_irq_config_func_2() argument
652 static void uart_cmsdk_apb_irq_config_func_2(const struct device *dev) in uart_cmsdk_apb_irq_config_func_2() argument
676 static void uart_cmsdk_apb_irq_config_func_3(const struct device *dev);
680 .uart = (volatile struct uart_cmsdk_apb *)DT_INST_REG_ADDR(3),
707 static void uart_cmsdk_apb_irq_config_func_3(const struct device *dev) in uart_cmsdk_apb_irq_config_func_3() argument
717 static void uart_cmsdk_apb_irq_config_func_3(const struct device *dev) in uart_cmsdk_apb_irq_config_func_3() argument
741 static void uart_cmsdk_apb_irq_config_func_4(const struct device *dev);
745 .uart = (volatile struct uart_cmsdk_apb *)DT_INST_REG_ADDR(4),
772 static void uart_cmsdk_apb_irq_config_func_4(const struct device *dev) in uart_cmsdk_apb_irq_config_func_4() argument
782 static void uart_cmsdk_apb_irq_config_func_4(const struct device *dev) in uart_cmsdk_apb_irq_config_func_4() argument