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

2  * SPDX-License-Identifier: Apache-2.0
10 #include <zephyr/drivers/uart.h>
22 UART_T *uart; member
30 void (*irq_config_func)(const struct device *dev);
44 static int uart_numaker_poll_in(const struct device *dev, unsigned char *c) in uart_numaker_poll_in() argument
46 const struct uart_numaker_config *config = dev->config; in uart_numaker_poll_in()
49 count = UART_Read(config->uart, c, 1); in uart_numaker_poll_in()
51 return -1; in uart_numaker_poll_in()
57 static void uart_numaker_poll_out(const struct device *dev, unsigned char c) in uart_numaker_poll_out() argument
59 const struct uart_numaker_config *config = dev->config; in uart_numaker_poll_out()
61 UART_Write(config->uart, &c, 1); in uart_numaker_poll_out()
64 static int uart_numaker_err_check(const struct device *dev) in uart_numaker_err_check() argument
66 const struct uart_numaker_config *config = dev->config; in uart_numaker_err_check()
67 UART_T *uart = config->uart; in uart_numaker_err_check() local
68 uint32_t flags = uart->FIFOSTS; in uart_numaker_err_check()
89 uart->FIFOSTS = (UART_FIFOSTS_BIF_Msk | UART_FIFOSTS_FEF_Msk | in uart_numaker_err_check()
105 return -ENOTSUP; in uart_numaker_convert_stopbit()
121 return -ENOTSUP; in uart_numaker_convert_datalen()
143 static int uart_numaker_configure(const struct device *dev, const struct uart_config *cfg) in uart_numaker_configure() argument
145 const struct uart_numaker_config *config = dev->config; in uart_numaker_configure()
146 struct uart_numaker_data *pData = dev->data; in uart_numaker_configure()
150 databits = uart_numaker_convert_datalen(cfg->data_bits); in uart_numaker_configure()
155 stopbits = uart_numaker_convert_stopbit(cfg->stop_bits); in uart_numaker_configure()
160 if (cfg->flow_ctrl == UART_CFG_FLOW_CTRL_NONE) { in uart_numaker_configure()
161 UART_DisableFlowCtrl(config->uart); in uart_numaker_configure()
162 } else if (cfg->flow_ctrl == UART_CFG_FLOW_CTRL_RTS_CTS) { in uart_numaker_configure()
163 UART_EnableFlowCtrl(config->uart); in uart_numaker_configure()
165 return -ENOTSUP; in uart_numaker_configure()
168 parity = uart_numaker_convert_parity(cfg->parity); in uart_numaker_configure()
170 UART_SetLineConfig(config->uart, cfg->baudrate, databits, parity, stopbits); in uart_numaker_configure()
172 memcpy(&pData->ucfg, cfg, sizeof(*cfg)); in uart_numaker_configure()
177 static int uart_numaker_config_get(const struct device *dev, struct uart_config *cfg) in uart_numaker_config_get() argument
179 struct uart_numaker_data *pData = dev->data; in uart_numaker_config_get()
181 memcpy(cfg, &pData->ucfg, sizeof(*cfg)); in uart_numaker_config_get()
187 static int uart_numaker_init(const struct device *dev) in uart_numaker_init() argument
189 const struct uart_numaker_config *config = dev->config; in uart_numaker_init()
190 struct uart_numaker_data *pData = dev->data; in uart_numaker_init()
199 scc_subsys.pcc.clk_modidx = config->clk_modidx; in uart_numaker_init()
200 scc_subsys.pcc.clk_src = config->clk_src; in uart_numaker_init()
201 scc_subsys.pcc.clk_div = config->clk_div; in uart_numaker_init()
204 err = clock_control_on(config->clk_dev, (clock_control_subsys_t)&scc_subsys); in uart_numaker_init()
209 err = clock_control_configure(config->clk_dev, (clock_control_subsys_t)&scc_subsys, NULL); in uart_numaker_init()
216 * Set multi-function pins for UART0 RXD and TXD in uart_numaker_init()
218 err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); in uart_numaker_init()
224 if (!device_is_ready(config->reset.dev)) { in uart_numaker_init()
226 return -ENODEV; in uart_numaker_init()
229 /* Reset UART to default state */ in uart_numaker_init()
230 reset_line_toggle_dt(&config->reset); in uart_numaker_init()
232 UART_Open(config->uart, pData->ucfg.baudrate); in uart_numaker_init()
235 config->irq_config_func(dev); in uart_numaker_init()
244 static int uart_numaker_fifo_fill(const struct device *dev, const uint8_t *tx_data, int size) in uart_numaker_fifo_fill() argument
246 const struct uart_numaker_config *config = dev->config; in uart_numaker_fifo_fill()
247 UART_T *uart = config->uart; in uart_numaker_fifo_fill() local
251 while (((size - tx_bytes) > 0) && (!(uart->FIFOSTS & UART_FIFOSTS_TXFULL_Msk))) { in uart_numaker_fifo_fill()
253 uart->DAT = tx_data[tx_bytes++]; in uart_numaker_fifo_fill()
259 static int uart_numaker_fifo_read(const struct device *dev, uint8_t *rx_data, const int size) in uart_numaker_fifo_read() argument
261 const struct uart_numaker_config *config = dev->config; in uart_numaker_fifo_read()
262 UART_T *uart = config->uart; in uart_numaker_fifo_read() local
266 while (((size - rx_bytes) > 0) && (!(uart->FIFOSTS & UART_FIFOSTS_RXEMPTY_Msk))) { in uart_numaker_fifo_read()
267 /* Read one byte from UART RX FIFO */ in uart_numaker_fifo_read()
268 rx_data[rx_bytes++] = (uint8_t)uart->DAT; in uart_numaker_fifo_read()
274 static void uart_numaker_irq_tx_enable(const struct device *dev) in uart_numaker_irq_tx_enable() argument
276 const struct uart_numaker_config *config = dev->config; in uart_numaker_irq_tx_enable()
277 UART_T *uart = config->uart; in uart_numaker_irq_tx_enable() local
279 UART_EnableInt(uart, UART_INTEN_THREIEN_Msk); in uart_numaker_irq_tx_enable()
282 static void uart_numaker_irq_tx_disable(const struct device *dev) in uart_numaker_irq_tx_disable() argument
284 const struct uart_numaker_config *config = dev->config; in uart_numaker_irq_tx_disable()
285 UART_T *uart = config->uart; in uart_numaker_irq_tx_disable() local
287 UART_DisableInt(uart, UART_INTEN_THREIEN_Msk); in uart_numaker_irq_tx_disable()
290 static int uart_numaker_irq_tx_ready(const struct device *dev) in uart_numaker_irq_tx_ready() argument
292 const struct uart_numaker_config *config = dev->config; in uart_numaker_irq_tx_ready()
293 UART_T *uart = config->uart; in uart_numaker_irq_tx_ready() local
295 return ((!UART_IS_TX_FULL(uart)) && (uart->INTEN & UART_INTEN_THREIEN_Msk)); in uart_numaker_irq_tx_ready()
298 static int uart_numaker_irq_tx_complete(const struct device *dev) in uart_numaker_irq_tx_complete() argument
300 const struct uart_numaker_config *config = dev->config; in uart_numaker_irq_tx_complete()
301 UART_T *uart = config->uart; in uart_numaker_irq_tx_complete() local
303 return (uart->INTSTS & UART_INTSTS_THREINT_Msk); in uart_numaker_irq_tx_complete()
306 static void uart_numaker_irq_rx_enable(const struct device *dev) in uart_numaker_irq_rx_enable() argument
308 const struct uart_numaker_config *config = dev->config; in uart_numaker_irq_rx_enable()
309 UART_T *uart = config->uart; in uart_numaker_irq_rx_enable() local
311 UART_EnableInt(uart, UART_INTEN_RDAIEN_Msk); in uart_numaker_irq_rx_enable()
314 static void uart_numaker_irq_rx_disable(const struct device *dev) in uart_numaker_irq_rx_disable() argument
316 const struct uart_numaker_config *config = dev->config; in uart_numaker_irq_rx_disable()
317 UART_T *uart = config->uart; in uart_numaker_irq_rx_disable() local
319 UART_DisableInt(uart, UART_INTEN_RDAIEN_Msk); in uart_numaker_irq_rx_disable()
322 static int uart_numaker_irq_rx_ready(const struct device *dev) in uart_numaker_irq_rx_ready() argument
324 const struct uart_numaker_config *config = dev->config; in uart_numaker_irq_rx_ready()
325 UART_T *uart = config->uart; in uart_numaker_irq_rx_ready() local
327 return ((!UART_GET_RX_EMPTY(uart)) && (uart->INTEN & UART_INTEN_RDAIEN_Msk)); in uart_numaker_irq_rx_ready()
330 static void uart_numaker_irq_err_enable(const struct device *dev) in uart_numaker_irq_err_enable() argument
332 const struct uart_numaker_config *config = dev->config; in uart_numaker_irq_err_enable()
333 UART_T *uart = config->uart; in uart_numaker_irq_err_enable() local
335 UART_EnableInt(uart, UART_INTEN_BUFERRIEN_Msk | UART_INTEN_SWBEIEN_Msk); in uart_numaker_irq_err_enable()
338 static void uart_numaker_irq_err_disable(const struct device *dev) in uart_numaker_irq_err_disable() argument
340 const struct uart_numaker_config *config = dev->config; in uart_numaker_irq_err_disable()
341 UART_T *uart = config->uart; in uart_numaker_irq_err_disable() local
343 UART_DisableInt(uart, UART_INTEN_BUFERRIEN_Msk | UART_INTEN_SWBEIEN_Msk); in uart_numaker_irq_err_disable()
346 static int uart_numaker_irq_is_pending(const struct device *dev) in uart_numaker_irq_is_pending() argument
349 return (uart_numaker_irq_tx_ready(dev) || (uart_numaker_irq_rx_ready(dev))); in uart_numaker_irq_is_pending()
352 static int uart_numaker_irq_update(const struct device *dev) in uart_numaker_irq_update() argument
354 ARG_UNUSED(dev); in uart_numaker_irq_update()
360 static void uart_numaker_irq_callback_set(const struct device *dev, in uart_numaker_irq_callback_set() argument
363 struct uart_numaker_data *pData = dev->data; in uart_numaker_irq_callback_set()
365 pData->user_cb = cb; in uart_numaker_irq_callback_set()
366 pData->user_data = cb_data; in uart_numaker_irq_callback_set()
369 static void uart_numaker_isr(const struct device *dev) in uart_numaker_isr() argument
371 struct uart_numaker_data *pData = dev->data; in uart_numaker_isr()
373 if (pData->user_cb) { in uart_numaker_isr()
374 pData->user_cb(dev, pData->user_data); in uart_numaker_isr()
380 static DEVICE_API(uart, uart_numaker_driver_api) = {
413 static void uart_numaker_irq_config_##n(const struct device *dev) \
430 .uart = (UART_T *)DT_INST_REG_ADDR(inst), \