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
43 int (*callback_set)(
const struct device *dev,
uart_callback_t callback,
void *user_data);
45 int (*tx)(
const struct device *dev,
const uint8_t *buf,
size_t len,
int32_t timeout);
46 int (*tx_abort)(
const struct device *dev);
48 int (*rx_enable)(
const struct device *dev,
uint8_t *buf,
size_t len,
int32_t timeout);
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
53 int (*tx_u16)(
const struct device *dev,
const uint16_t *buf,
size_t len,
int32_t timeout);
54 int (*rx_enable_u16)(
const struct device *dev,
uint16_t *buf,
size_t len,
int32_t timeout);
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
65 int (*poll_in_u16)(
const struct device *dev,
uint16_t *p_u16);
66 void (*poll_out_u16)(
const struct device *dev,
uint16_t out_u16);
70 int (*err_check)(
const struct device *dev);
72#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
74 int (*configure)(
const struct device *dev,
const struct uart_config *cfg);
75 int (*config_get)(
const struct device *dev,
struct uart_config *cfg);
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
134 int (*line_ctrl_set)(
const struct device *dev,
uint32_t ctrl,
uint32_t val);
135 int (*line_ctrl_get)(
const struct device *dev,
uint32_t ctrl,
uint32_t *val);
138#ifdef CONFIG_UART_DRV_CMD
143static inline int z_impl_uart_err_check(
const struct device *dev)
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)
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
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)
187static inline void z_impl_uart_poll_out_u16(
const struct device *dev,
uint16_t out_u16)
189#ifdef CONFIG_UART_WIDE_DATA
197static inline int z_impl_uart_configure(
const struct device *dev,
const struct uart_config *cfg)
199#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
202 if (api->configure ==
NULL) {
205 return api->configure(dev, cfg);
213static inline int z_impl_uart_config_get(
const struct device *dev,
struct uart_config *cfg)
215#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
218 if (api->config_get ==
NULL) {
222 return api->config_get(dev, cfg);
232#ifdef CONFIG_UART_INTERRUPT_DRIVEN
235 if (api->fifo_fill ==
NULL) {
239 return api->fifo_fill(dev, tx_data, size);
250#if defined(CONFIG_UART_INTERRUPT_DRIVEN) && defined(CONFIG_UART_WIDE_DATA)
253 if (api->fifo_fill_u16 ==
NULL) {
257 return api->fifo_fill_u16(dev, tx_data, size);
268#ifdef CONFIG_UART_INTERRUPT_DRIVEN
271 if (api->fifo_read ==
NULL) {
275 return api->fifo_read(dev, rx_data, size);
286#if defined(CONFIG_UART_INTERRUPT_DRIVEN) && defined(CONFIG_UART_WIDE_DATA)
289 if (api->fifo_read_u16 ==
NULL) {
293 return api->fifo_read_u16(dev, rx_data, size);
302static inline void z_impl_uart_irq_tx_enable(
const struct device *dev)
304#ifdef CONFIG_UART_INTERRUPT_DRIVEN
307 if (api->irq_tx_enable !=
NULL) {
308 api->irq_tx_enable(dev);
315static inline void z_impl_uart_irq_tx_disable(
const struct device *dev)
317#ifdef CONFIG_UART_INTERRUPT_DRIVEN
320 if (api->irq_tx_disable !=
NULL) {
321 api->irq_tx_disable(dev);
330#ifdef CONFIG_UART_INTERRUPT_DRIVEN
333 if (api->irq_tx_ready ==
NULL) {
337 return api->irq_tx_ready(dev);
344static inline void z_impl_uart_irq_rx_enable(
const struct device *dev)
346#ifdef CONFIG_UART_INTERRUPT_DRIVEN
349 if (api->irq_rx_enable !=
NULL) {
350 api->irq_rx_enable(dev);
357static inline void z_impl_uart_irq_rx_disable(
const struct device *dev)
359#ifdef CONFIG_UART_INTERRUPT_DRIVEN
362 if (api->irq_rx_disable !=
NULL) {
363 api->irq_rx_disable(dev);
372#ifdef CONFIG_UART_INTERRUPT_DRIVEN
375 if (api->irq_tx_complete ==
NULL) {
378 return api->irq_tx_complete(dev);
387#ifdef CONFIG_UART_INTERRUPT_DRIVEN
390 if (api->irq_rx_ready ==
NULL) {
393 return api->irq_rx_ready(dev);
400static inline void z_impl_uart_irq_err_enable(
const struct device *dev)
402#ifdef CONFIG_UART_INTERRUPT_DRIVEN
405 if (api->irq_err_enable) {
406 api->irq_err_enable(dev);
413static inline void z_impl_uart_irq_err_disable(
const struct device *dev)
415#ifdef CONFIG_UART_INTERRUPT_DRIVEN
418 if (api->irq_err_disable) {
419 api->irq_err_disable(dev);
426static inline int z_impl_uart_irq_is_pending(
const struct device *dev)
428#ifdef CONFIG_UART_INTERRUPT_DRIVEN
431 if (api->irq_is_pending ==
NULL) {
434 return api->irq_is_pending(dev);
441static inline int z_impl_uart_irq_update(
const struct device *dev)
443#ifdef CONFIG_UART_INTERRUPT_DRIVEN
446 if (api->irq_update ==
NULL) {
449 return api->irq_update(dev);
459#ifdef CONFIG_UART_INTERRUPT_DRIVEN
462 if ((api !=
NULL) && (api->irq_callback_set !=
NULL)) {
463 api->irq_callback_set(dev, cb, user_data);
471 ARG_UNUSED(user_data);
484#ifdef CONFIG_UART_ASYNC_API
487 if (api->callback_set ==
NULL) {
491 return api->callback_set(dev, callback, user_data);
494 ARG_UNUSED(callback);
495 ARG_UNUSED(user_data);
500static inline int z_impl_uart_tx(
const struct device *dev,
const uint8_t *buf,
size_t len,
504#ifdef CONFIG_UART_ASYNC_API
515static inline int z_impl_uart_tx_u16(
const struct device *dev,
const uint16_t *buf,
size_t len,
519#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
530static inline int z_impl_uart_tx_abort(
const struct device *dev)
532#ifdef CONFIG_UART_ASYNC_API
540static inline int z_impl_uart_rx_enable(
const struct device *dev,
uint8_t *buf,
size_t len,
543#ifdef CONFIG_UART_ASYNC_API
544 return DEVICE_API_GET(uart, dev)->rx_enable(dev, buf, len, timeout);
554static inline int z_impl_uart_rx_enable_u16(
const struct device *dev,
uint16_t *buf,
size_t len,
557#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
558 return DEVICE_API_GET(uart, dev)->rx_enable_u16(dev, buf, len, timeout);
570#ifdef CONFIG_UART_ASYNC_API
582#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
592static inline int z_impl_uart_rx_disable(
const struct device *dev)
594#ifdef CONFIG_UART_ASYNC_API
604#ifdef CONFIG_UART_LINE_CTRL
607 if (api->line_ctrl_set ==
NULL) {
610 return api->line_ctrl_set(dev, ctrl, val);
621#ifdef CONFIG_UART_LINE_CTRL
624 if (api->line_ctrl_get ==
NULL) {
627 return api->line_ctrl_get(dev, ctrl, val);
638#ifdef CONFIG_UART_DRV_CMD
641 if (api->drv_cmd ==
NULL) {
644 return api->drv_cmd(dev,
cmd, p);
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1375
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:318
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:142
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.
#define NULL
Definition iar_missing_defs.h:20
__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:513
UART controller configuration structure.
Definition uart.h:122