13#ifndef ZEPHYR_INCLUDE_DRIVERS_UART_UART_INTERNAL_H_
14#define ZEPHYR_INCLUDE_DRIVERS_UART_UART_INTERNAL_H_
36typedef void (*uart_irq_config_func_t)(
const struct device *dev);
39__subsystem
struct uart_driver_api {
41#ifdef CONFIG_UART_ASYNC_API
46 int (*tx_abort)(
const struct device *dev);
49 int (*rx_buf_rsp)(
const struct device *dev,
uint8_t *buf,
size_t len);
50 int (*rx_disable)(
const struct device *dev);
52#ifdef CONFIG_UART_WIDE_DATA
55 int (*rx_buf_rsp_u16)(
const struct device *dev,
uint16_t *buf,
size_t len);
61 int (*poll_in)(
const struct device *dev,
unsigned char *p_char);
62 void (*poll_out)(
const struct device *dev,
unsigned char out_char);
64#ifdef CONFIG_UART_WIDE_DATA
70 int (*err_check)(
const struct device *dev);
72#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
78#ifdef CONFIG_UART_INTERRUPT_DRIVEN
81 int (*fifo_fill)(
const struct device *dev,
const uint8_t *tx_data,
int len);
83#ifdef CONFIG_UART_WIDE_DATA
84 int (*fifo_fill_u16)(
const struct device *dev,
const uint16_t *tx_data,
int len);
88 int (*fifo_read)(
const struct device *dev,
uint8_t *rx_data,
const int size);
90#ifdef CONFIG_UART_WIDE_DATA
91 int (*fifo_read_u16)(
const struct device *dev,
uint16_t *rx_data,
const int size);
95 void (*irq_tx_enable)(
const struct device *dev);
98 void (*irq_tx_disable)(
const struct device *dev);
101 int (*irq_tx_ready)(
const struct device *dev);
104 void (*irq_rx_enable)(
const struct device *dev);
107 void (*irq_rx_disable)(
const struct device *dev);
110 int (*irq_tx_complete)(
const struct device *dev);
113 int (*irq_rx_ready)(
const struct device *dev);
116 void (*irq_err_enable)(
const struct device *dev);
119 void (*irq_err_disable)(
const struct device *dev);
122 int (*irq_is_pending)(
const struct device *dev);
125 int (*irq_update)(
const struct device *dev);
133#ifdef CONFIG_UART_LINE_CTRL
138#ifdef CONFIG_UART_DRV_CMD
143static inline int z_impl_uart_err_check(
const struct device *dev)
145 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
147 if (api->err_check == NULL) {
151 return api->err_check(dev);
154static inline int z_impl_uart_poll_in(
const struct device *dev,
unsigned char *p_char)
156 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
158 if (api->poll_in == NULL) {
162 return api->poll_in(dev, p_char);
165static inline int z_impl_uart_poll_in_u16(
const struct device *dev,
uint16_t *p_u16)
167#ifdef CONFIG_UART_WIDE_DATA
168 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
170 if (api->poll_in_u16 == NULL) {
174 return api->poll_in_u16(dev, p_u16);
182static inline void z_impl_uart_poll_out(
const struct device *dev,
unsigned char out_char)
184 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
186 api->poll_out(dev, out_char);
189static inline void z_impl_uart_poll_out_u16(
const struct device *dev,
uint16_t out_u16)
191#ifdef CONFIG_UART_WIDE_DATA
192 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
194 api->poll_out_u16(dev, out_u16);
201static inline int z_impl_uart_configure(
const struct device *dev,
const struct uart_config *cfg)
203#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
204 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
206 if (api->configure == NULL) {
209 return api->configure(dev, cfg);
217static inline int z_impl_uart_config_get(
const struct device *dev,
struct uart_config *cfg)
219#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
220 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
222 if (api->config_get == NULL) {
226 return api->config_get(dev, cfg);
236#ifdef CONFIG_UART_INTERRUPT_DRIVEN
237 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
239 if (api->fifo_fill == NULL) {
243 return api->fifo_fill(dev, tx_data, size);
254#if defined(CONFIG_UART_INTERRUPT_DRIVEN) && defined(CONFIG_UART_WIDE_DATA)
255 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
257 if (api->fifo_fill_u16 == NULL) {
261 return api->fifo_fill_u16(dev, tx_data, size);
272#ifdef CONFIG_UART_INTERRUPT_DRIVEN
273 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
275 if (api->fifo_read == NULL) {
279 return api->fifo_read(dev, rx_data, size);
290#if defined(CONFIG_UART_INTERRUPT_DRIVEN) && defined(CONFIG_UART_WIDE_DATA)
291 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
293 if (api->fifo_read_u16 == NULL) {
297 return api->fifo_read_u16(dev, rx_data, size);
306static inline void z_impl_uart_irq_tx_enable(
const struct device *dev)
308#ifdef CONFIG_UART_INTERRUPT_DRIVEN
309 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
311 if (api->irq_tx_enable != NULL) {
312 api->irq_tx_enable(dev);
319static inline void z_impl_uart_irq_tx_disable(
const struct device *dev)
321#ifdef CONFIG_UART_INTERRUPT_DRIVEN
322 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
324 if (api->irq_tx_disable != NULL) {
325 api->irq_tx_disable(dev);
334#ifdef CONFIG_UART_INTERRUPT_DRIVEN
335 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
337 if (api->irq_tx_ready == NULL) {
341 return api->irq_tx_ready(dev);
348static inline void z_impl_uart_irq_rx_enable(
const struct device *dev)
350#ifdef CONFIG_UART_INTERRUPT_DRIVEN
351 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
353 if (api->irq_rx_enable != NULL) {
354 api->irq_rx_enable(dev);
361static inline void z_impl_uart_irq_rx_disable(
const struct device *dev)
363#ifdef CONFIG_UART_INTERRUPT_DRIVEN
364 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
366 if (api->irq_rx_disable != NULL) {
367 api->irq_rx_disable(dev);
376#ifdef CONFIG_UART_INTERRUPT_DRIVEN
377 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
379 if (api->irq_tx_complete == NULL) {
382 return api->irq_tx_complete(dev);
391#ifdef CONFIG_UART_INTERRUPT_DRIVEN
392 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
394 if (api->irq_rx_ready == NULL) {
397 return api->irq_rx_ready(dev);
404static inline void z_impl_uart_irq_err_enable(
const struct device *dev)
406#ifdef CONFIG_UART_INTERRUPT_DRIVEN
407 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
409 if (api->irq_err_enable) {
410 api->irq_err_enable(dev);
417static inline void z_impl_uart_irq_err_disable(
const struct device *dev)
419#ifdef CONFIG_UART_INTERRUPT_DRIVEN
420 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
422 if (api->irq_err_disable) {
423 api->irq_err_disable(dev);
430static inline int z_impl_uart_irq_is_pending(
const struct device *dev)
432#ifdef CONFIG_UART_INTERRUPT_DRIVEN
433 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
435 if (api->irq_is_pending == NULL) {
438 return api->irq_is_pending(dev);
445static inline int z_impl_uart_irq_update(
const struct device *dev)
447#ifdef CONFIG_UART_INTERRUPT_DRIVEN
448 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
450 if (api->irq_update == NULL) {
453 return api->irq_update(dev);
463#ifdef CONFIG_UART_INTERRUPT_DRIVEN
464 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
466 if ((api != NULL) && (api->irq_callback_set != NULL)) {
467 api->irq_callback_set(dev, cb, user_data);
475 ARG_UNUSED(user_data);
488#ifdef CONFIG_UART_ASYNC_API
489 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
491 if (api->callback_set == NULL) {
495 return api->callback_set(dev, callback, user_data);
498 ARG_UNUSED(callback);
499 ARG_UNUSED(user_data);
504static inline int z_impl_uart_tx(
const struct device *dev,
const uint8_t *buf,
size_t len,
508#ifdef CONFIG_UART_ASYNC_API
509 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
511 return api->tx(dev, buf, len, timeout);
521static inline int z_impl_uart_tx_u16(
const struct device *dev,
const uint16_t *buf,
size_t len,
525#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
526 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
528 return api->tx_u16(dev, buf, len, timeout);
538static inline int z_impl_uart_tx_abort(
const struct device *dev)
540#ifdef CONFIG_UART_ASYNC_API
541 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
543 return api->tx_abort(dev);
550static inline int z_impl_uart_rx_enable(
const struct device *dev,
uint8_t *buf,
size_t len,
553#ifdef CONFIG_UART_ASYNC_API
554 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
556 return api->rx_enable(dev, buf, len, timeout);
566static inline int z_impl_uart_rx_enable_u16(
const struct device *dev,
uint16_t *buf,
size_t len,
569#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
570 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
572 return api->rx_enable_u16(dev, buf, len, timeout);
584#ifdef CONFIG_UART_ASYNC_API
585 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
587 return api->rx_buf_rsp(dev, buf, len);
598#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
599 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
601 return api->rx_buf_rsp_u16(dev, buf, len);
610static inline int z_impl_uart_rx_disable(
const struct device *dev)
612#ifdef CONFIG_UART_ASYNC_API
613 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
615 return api->rx_disable(dev);
624#ifdef CONFIG_UART_LINE_CTRL
625 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
627 if (api->line_ctrl_set == NULL) {
630 return api->line_ctrl_set(dev, ctrl, val);
641#ifdef CONFIG_UART_LINE_CTRL
642 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
644 if (api->line_ctrl_get == NULL) {
647 return api->line_ctrl_get(dev, ctrl, val);
658#ifdef CONFIG_UART_DRV_CMD
659 const struct uart_driver_api *api = (
const struct uart_driver_api *)dev->
api;
661 if (api->drv_cmd == NULL) {
664 return api->drv_cmd(dev,
cmd, p);
static void cmd(uint32_t command)
Execute a display list command by co-processor engine.
Definition ft8xx_reference_api.h:153
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define ENOTSUP
Unsupported value.
Definition errno.h:114
void(* uart_callback_t)(const struct device *dev, struct uart_event *evt, void *user_data)
Define the application callback function signature for uart_callback_set() function.
Definition uart.h:316
static int uart_rx_buf_rsp(const struct device *dev, uint8_t *buf, size_t len)
Provide receive buffer in response to UART_RX_BUF_REQUEST event.
static int uart_rx_buf_rsp_u16(const struct device *dev, uint16_t *buf, size_t len)
Provide wide data receive buffer in response to UART_RX_BUF_REQUEST event.
static int uart_callback_set(const struct device *dev, uart_callback_t callback, void *user_data)
Set event handler function.
static int uart_fifo_read_u16(const struct device *dev, uint16_t *rx_data, const int size)
Read wide data from FIFO.
static int uart_irq_tx_ready(const struct device *dev)
Check if UART TX buffer can accept bytes.
static int uart_irq_callback_set(const struct device *dev, uart_irq_callback_user_data_t cb)
Set the IRQ callback function pointer (legacy).
static int uart_irq_tx_complete(const struct device *dev)
Check if UART TX block finished transmission.
static int uart_fifo_fill_u16(const struct device *dev, const uint16_t *tx_data, int size)
Fill FIFO with wide data.
static int uart_fifo_read(const struct device *dev, uint8_t *rx_data, const int size)
Read data from FIFO.
static int uart_irq_rx_ready(const struct device *dev)
Check if UART RX buffer has a received char.
void(* uart_irq_callback_user_data_t)(const struct device *dev, void *user_data)
Define the application callback function signature for uart_irq_callback_user_data_set() function.
Definition uart.h:140
static int uart_irq_callback_user_data_set(const struct device *dev, uart_irq_callback_user_data_t cb, void *user_data)
Set the IRQ callback function pointer.
static int uart_fifo_fill(const struct device *dev, const uint8_t *tx_data, int size)
Fill FIFO with data.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:412
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:418
UART controller configuration structure.
Definition uart.h:120