Lines Matching +full:uart +full:- +full:dev

1 /* stellarisUartDrv.c - Stellaris UART driver */
6 * Copyright (c) 2013-2015 Wind River Systems, Inc.
8 * SPDX-License-Identifier: Apache-2.0
12 * @brief Driver for Stellaris UART
14 * Driver for Stellaris UART found namely on TI LM3S6965 board. It is similar to
15 * an 16550 in functionality, but is not register-compatible.
16 * It is also register-compatible with the UART found on TI CC2650 SoC,
19 * There is only support for poll-mode, so it can only be used with the printk
28 #include <zephyr/drivers/uart.h>
34 /* Stellaris UART module */
72 volatile struct _uart *uart; member
115 static DEVICE_API(uart, uart_stellaris_driver_api);
120 * This routine set the given baud rate for the UART.
122 * @param dev UART device struct
126 static void baudrate_set(const struct device *dev, in baudrate_set() argument
129 const struct uart_stellaris_config *config = dev->config; in baudrate_set()
147 * those registers are 32-bit, but the reserved bits should be in baudrate_set()
150 config->uart->ibrd = (uint16_t)(brdi & 0xffff); /* 16 bits */ in baudrate_set()
151 config->uart->fbrd = (uint8_t)(brdf & 0x3f); /* 6 bits */ in baudrate_set()
155 * @brief Enable the UART
157 * This routine enables the given UART.
159 * @param dev UART device struct
161 static inline void enable(const struct device *dev) in enable() argument
163 const struct uart_stellaris_config *config = dev->config; in enable()
165 config->uart->ctl |= UARTCTL_UARTEN; in enable()
169 * @brief Disable the UART
171 * This routine disables the given UART.
173 * @param dev UART device struct
175 static inline void disable(const struct device *dev) in disable() argument
177 const struct uart_stellaris_config *config = dev->config; in disable()
179 config->uart->ctl &= ~UARTCTL_UARTEN; in disable()
182 while (config->uart->fr & UARTFR_BUSY) { in disable()
186 config->uart->lcrh &= ~UARTLCRH_FEN; in disable()
191 * 8-bit frame
200 * @brief Set the default UART line controls
202 * This routine sets the given UART's line controls to their default settings.
204 * @param dev UART device struct
206 static inline void line_control_defaults_set(const struct device *dev) in line_control_defaults_set() argument
208 const struct uart_stellaris_config *config = dev->config; in line_control_defaults_set()
210 config->uart->lcrh = LINE_CONTROL_DEFAULTS; in line_control_defaults_set()
214 * @brief Initialize UART channel
217 * It is assumed that this function is called only once per UART.
219 * @param dev UART device struct
223 static int uart_stellaris_init(const struct device *dev) in uart_stellaris_init() argument
225 struct uart_stellaris_dev_data_t *data = dev->data; in uart_stellaris_init()
226 const struct uart_stellaris_config *config = dev->config; in uart_stellaris_init()
227 disable(dev); in uart_stellaris_init()
228 baudrate_set(dev, data->baud_rate, in uart_stellaris_init()
229 config->sys_clk_freq); in uart_stellaris_init()
230 line_control_defaults_set(dev); in uart_stellaris_init()
231 enable(dev); in uart_stellaris_init()
234 config->irq_config_func(dev); in uart_stellaris_init()
241 * @brief Get the UART transmit ready status
243 * This routine returns the given UART's transmit ready status.
245 * @param dev UART device struct
249 static int poll_tx_ready(const struct device *dev) in poll_tx_ready() argument
251 const struct uart_stellaris_config *config = dev->config; in poll_tx_ready()
253 return (config->uart->fr & UARTFR_TXFE); in poll_tx_ready()
259 * @param dev UART device struct
262 * @return 0 if a character arrived, -1 if the input buffer if empty.
265 static int uart_stellaris_poll_in(const struct device *dev, unsigned char *c) in uart_stellaris_poll_in() argument
267 const struct uart_stellaris_config *config = dev->config; in uart_stellaris_poll_in()
269 if (config->uart->fr & UARTFR_RXFE) { in uart_stellaris_poll_in()
270 return (-1); in uart_stellaris_poll_in()
274 *c = (unsigned char)config->uart->dr; in uart_stellaris_poll_in()
285 * @param dev UART device struct
288 static void uart_stellaris_poll_out(const struct device *dev, in uart_stellaris_poll_out() argument
291 const struct uart_stellaris_config *config = dev->config; in uart_stellaris_poll_out()
293 while (!poll_tx_ready(dev)) { in uart_stellaris_poll_out()
297 config->uart->dr = (uint32_t)c; in uart_stellaris_poll_out()
305 * @param dev UART device struct
311 static int uart_stellaris_fifo_fill(const struct device *dev, in uart_stellaris_fifo_fill() argument
315 const struct uart_stellaris_config *config = dev->config; in uart_stellaris_fifo_fill()
318 while ((len - num_tx > 0) && ((config->uart->fr & UARTFR_TXFF) == 0U)) { in uart_stellaris_fifo_fill()
319 config->uart->dr = (uint32_t)tx_data[num_tx++]; in uart_stellaris_fifo_fill()
328 * @param dev UART device struct
334 static int uart_stellaris_fifo_read(const struct device *dev, in uart_stellaris_fifo_read() argument
338 const struct uart_stellaris_config *config = dev->config; in uart_stellaris_fifo_read()
341 while ((size - num_rx > 0) && ((config->uart->fr & UARTFR_RXFE) == 0U)) { in uart_stellaris_fifo_read()
342 rx_data[num_rx++] = (uint8_t)config->uart->dr; in uart_stellaris_fifo_read()
351 * @param dev UART device struct
353 static void uart_stellaris_irq_tx_enable(const struct device *dev) in uart_stellaris_irq_tx_enable() argument
361 const struct uart_stellaris_config *config = dev->config; in uart_stellaris_irq_tx_enable()
374 saved_ctl = config->uart->ctl; in uart_stellaris_irq_tx_enable()
375 saved_ibrd = config->uart->ibrd; in uart_stellaris_irq_tx_enable()
376 saved_fbrd = config->uart->fbrd; in uart_stellaris_irq_tx_enable()
379 disable(dev); in uart_stellaris_irq_tx_enable()
380 config->uart->fbrd = 0U; in uart_stellaris_irq_tx_enable()
381 config->uart->ibrd = 1U; in uart_stellaris_irq_tx_enable()
382 config->uart->lcrh = 0U; in uart_stellaris_irq_tx_enable()
383 config->uart->ctl = (UARTCTL_UARTEN | UARTCTL_TXEN | UARTCTL_LBE); in uart_stellaris_irq_tx_enable()
384 config->uart->dr = 0U; in uart_stellaris_irq_tx_enable()
386 while (config->uart->fr & UARTFR_BUSY) { in uart_stellaris_irq_tx_enable()
390 disable(dev); in uart_stellaris_irq_tx_enable()
391 config->uart->ibrd = saved_ibrd; in uart_stellaris_irq_tx_enable()
392 config->uart->fbrd = saved_fbrd; in uart_stellaris_irq_tx_enable()
393 line_control_defaults_set(dev); in uart_stellaris_irq_tx_enable()
394 config->uart->ctl = saved_ctl; in uart_stellaris_irq_tx_enable()
397 config->uart->im |= UARTTIM_TXIM; in uart_stellaris_irq_tx_enable()
403 * @param dev UART device struct
405 static void uart_stellaris_irq_tx_disable(const struct device *dev) in uart_stellaris_irq_tx_disable() argument
407 const struct uart_stellaris_config *config = dev->config; in uart_stellaris_irq_tx_disable()
409 config->uart->im &= ~UARTTIM_TXIM; in uart_stellaris_irq_tx_disable()
415 * @param dev UART device struct
419 static int uart_stellaris_irq_tx_ready(const struct device *dev) in uart_stellaris_irq_tx_ready() argument
421 const struct uart_stellaris_config *config = dev->config; in uart_stellaris_irq_tx_ready()
423 return ((config->uart->mis & UARTMIS_TXMIS) == UARTMIS_TXMIS); in uart_stellaris_irq_tx_ready()
429 * @param dev UART device struct
431 static void uart_stellaris_irq_rx_enable(const struct device *dev) in uart_stellaris_irq_rx_enable() argument
433 const struct uart_stellaris_config *config = dev->config; in uart_stellaris_irq_rx_enable()
435 config->uart->im |= UARTTIM_RXIM; in uart_stellaris_irq_rx_enable()
441 * @param dev UART device struct
443 static void uart_stellaris_irq_rx_disable(const struct device *dev) in uart_stellaris_irq_rx_disable() argument
445 const struct uart_stellaris_config *config = dev->config; in uart_stellaris_irq_rx_disable()
447 config->uart->im &= ~UARTTIM_RXIM; in uart_stellaris_irq_rx_disable()
453 * @param dev UART device struct
457 static int uart_stellaris_irq_rx_ready(const struct device *dev) in uart_stellaris_irq_rx_ready() argument
459 const struct uart_stellaris_config *config = dev->config; in uart_stellaris_irq_rx_ready()
461 return ((config->uart->mis & UARTMIS_RXMIS) == UARTMIS_RXMIS); in uart_stellaris_irq_rx_ready()
467 * @param dev UART device struct
469 static void uart_stellaris_irq_err_enable(const struct device *dev) in uart_stellaris_irq_err_enable() argument
471 const struct uart_stellaris_config *config = dev->config; in uart_stellaris_irq_err_enable()
473 config->uart->im |= (UARTTIM_RTIM | UARTTIM_FEIM | UARTTIM_PEIM | in uart_stellaris_irq_err_enable()
480 * @param dev UART device struct
482 static void uart_stellaris_irq_err_disable(const struct device *dev) in uart_stellaris_irq_err_disable() argument
484 const struct uart_stellaris_config *config = dev->config; in uart_stellaris_irq_err_disable()
486 config->uart->im &= ~(UARTTIM_RTIM | UARTTIM_FEIM | UARTTIM_PEIM | in uart_stellaris_irq_err_disable()
493 * @param dev UART device struct
497 static int uart_stellaris_irq_is_pending(const struct device *dev) in uart_stellaris_irq_is_pending() argument
499 const struct uart_stellaris_config *config = dev->config; in uart_stellaris_irq_is_pending()
502 return ((config->uart->mis & (UARTMIS_RXMIS | UARTMIS_TXMIS)) ? 1 : 0); in uart_stellaris_irq_is_pending()
508 * @param dev UART device struct
512 static int uart_stellaris_irq_update(const struct device *dev) in uart_stellaris_irq_update() argument
520 * @param dev UART device struct
523 static void uart_stellaris_irq_callback_set(const struct device *dev, in uart_stellaris_irq_callback_set() argument
527 struct uart_stellaris_dev_data_t * const dev_data = dev->data; in uart_stellaris_irq_callback_set()
529 dev_data->cb = cb; in uart_stellaris_irq_callback_set()
530 dev_data->cb_data = cb_data; in uart_stellaris_irq_callback_set()
540 static void uart_stellaris_isr(const struct device *dev) in uart_stellaris_isr() argument
542 struct uart_stellaris_dev_data_t * const dev_data = dev->data; in uart_stellaris_isr()
544 if (dev_data->cb) { in uart_stellaris_isr()
545 dev_data->cb(dev, dev_data->cb_data); in uart_stellaris_isr()
552 static DEVICE_API(uart, uart_stellaris_driver_api) = {
583 .uart = (volatile struct _uart *)DT_INST_REG_ADDR(0),
603 static void irq_config_func_0(const struct device *dev) in irq_config_func_0() argument
622 .uart = (volatile struct _uart *)DT_INST_REG_ADDR(1),
642 static void irq_config_func_1(const struct device *dev) in irq_config_func_1() argument
661 .uart = (volatile struct _uart *)DT_INST_REG_ADDR(2),
681 static void irq_config_func_2(const struct device *dev) in irq_config_func_2() argument