13#ifndef ZEPHYR_INCLUDE_DRIVERS_UART_H_
14#define ZEPHYR_INCLUDE_DRIVERS_UART_H_
338__subsystem
struct uart_driver_api {
340#ifdef CONFIG_UART_ASYNC_API
342 int (*callback_set)(
const struct device *dev,
346 int (*tx)(
const struct device *dev,
const uint8_t *buf,
size_t len,
348 int (*tx_abort)(
const struct device *dev);
350 int (*rx_enable)(
const struct device *dev,
uint8_t *buf,
size_t len,
352 int (*rx_buf_rsp)(
const struct device *dev,
uint8_t *buf,
size_t len);
353 int (*rx_disable)(
const struct device *dev);
355#ifdef CONFIG_UART_WIDE_DATA
367 int (*poll_in)(
const struct device *dev,
unsigned char *p_char);
368 void (*poll_out)(
const struct device *dev,
unsigned char out_char);
370#ifdef CONFIG_UART_WIDE_DATA
376 int (*err_check)(
const struct device *dev);
378#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
380 int (*configure)(
const struct device *dev,
385#ifdef CONFIG_UART_INTERRUPT_DRIVEN
388 int (*fifo_fill)(
const struct device *dev,
const uint8_t *tx_data,
391#ifdef CONFIG_UART_WIDE_DATA
392 int (*fifo_fill_u16)(
const struct device *dev,
const uint16_t *tx_data,
400#ifdef CONFIG_UART_WIDE_DATA
406 void (*irq_tx_enable)(
const struct device *dev);
409 void (*irq_tx_disable)(
const struct device *dev);
412 int (*irq_tx_ready)(
const struct device *dev);
415 void (*irq_rx_enable)(
const struct device *dev);
418 void (*irq_rx_disable)(
const struct device *dev);
421 int (*irq_tx_complete)(
const struct device *dev);
424 int (*irq_rx_ready)(
const struct device *dev);
427 void (*irq_err_enable)(
const struct device *dev);
430 void (*irq_err_disable)(
const struct device *dev);
433 int (*irq_is_pending)(
const struct device *dev);
436 int (*irq_update)(
const struct device *dev);
439 void (*irq_callback_set)(
const struct device *dev,
445#ifdef CONFIG_UART_LINE_CTRL
452#ifdef CONFIG_UART_DRV_CMD
471static inline int z_impl_uart_err_check(
const struct device *dev)
473 const struct uart_driver_api *api =
474 (
const struct uart_driver_api *)dev->
api;
476 if (api->err_check == NULL) {
480 return api->err_check(dev);
508static inline int z_impl_uart_poll_in(
const struct device *dev,
509 unsigned char *p_char)
511 const struct uart_driver_api *api =
512 (
const struct uart_driver_api *)dev->
api;
514 if (api->poll_in == NULL) {
518 return api->poll_in(dev, p_char);
542static inline int z_impl_uart_poll_in_u16(
const struct device *dev,
545#ifdef CONFIG_UART_WIDE_DATA
546 const struct uart_driver_api *api =
547 (
const struct uart_driver_api *)dev->
api;
549 if (api->poll_in_u16 == NULL) {
553 return api->poll_in_u16(dev, p_u16);
576 unsigned char out_char);
578static inline void z_impl_uart_poll_out(
const struct device *dev,
579 unsigned char out_char)
581 const struct uart_driver_api *api =
582 (
const struct uart_driver_api *)dev->
api;
584 api->poll_out(dev, out_char);
603static inline void z_impl_uart_poll_out_u16(
const struct device *dev,
606#ifdef CONFIG_UART_WIDE_DATA
607 const struct uart_driver_api *api =
608 (
const struct uart_driver_api *)dev->
api;
610 api->poll_out_u16(dev, out_u16);
638static inline int z_impl_uart_configure(
const struct device *dev,
641#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
642 const struct uart_driver_api *api =
643 (
const struct uart_driver_api *)dev->
api;
645 if (api->configure == NULL) {
648 return api->configure(dev, cfg);
673static inline int z_impl_uart_config_get(
const struct device *dev,
676#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
677 const struct uart_driver_api *api =
678 (
const struct uart_driver_api *)dev->
api;
680 if (api->config_get == NULL) {
684 return api->config_get(dev, cfg);
721#ifdef CONFIG_UART_INTERRUPT_DRIVEN
722 const struct uart_driver_api *api =
723 (
const struct uart_driver_api *)dev->
api;
725 if (api->fifo_fill == NULL) {
729 return api->fifo_fill(dev, tx_data, size);
762#if defined(CONFIG_UART_INTERRUPT_DRIVEN) && defined(CONFIG_UART_WIDE_DATA)
763 const struct uart_driver_api *api =
764 (
const struct uart_driver_api *)dev->
api;
766 if (api->fifo_fill_u16 == NULL) {
770 return api->fifo_fill_u16(dev, tx_data, size);
803#ifdef CONFIG_UART_INTERRUPT_DRIVEN
804 const struct uart_driver_api *api =
805 (
const struct uart_driver_api *)dev->
api;
807 if (api->fifo_read == NULL) {
811 return api->fifo_read(dev, rx_data, size);
845#if defined(CONFIG_UART_INTERRUPT_DRIVEN) && defined(CONFIG_UART_WIDE_DATA)
846 const struct uart_driver_api *api =
847 (
const struct uart_driver_api *)dev->
api;
849 if (api->fifo_read_u16 == NULL) {
853 return api->fifo_read_u16(dev, rx_data, size);
869static inline void z_impl_uart_irq_tx_enable(
const struct device *dev)
871#ifdef CONFIG_UART_INTERRUPT_DRIVEN
872 const struct uart_driver_api *api =
873 (
const struct uart_driver_api *)dev->
api;
875 if (api->irq_tx_enable != NULL) {
876 api->irq_tx_enable(dev);
890static inline void z_impl_uart_irq_tx_disable(
const struct device *dev)
892#ifdef CONFIG_UART_INTERRUPT_DRIVEN
893 const struct uart_driver_api *api =
894 (
const struct uart_driver_api *)dev->
api;
896 if (api->irq_tx_disable != NULL) {
897 api->irq_tx_disable(dev);
926#ifdef CONFIG_UART_INTERRUPT_DRIVEN
927 const struct uart_driver_api *api =
928 (
const struct uart_driver_api *)dev->
api;
930 if (api->irq_tx_ready == NULL) {
934 return api->irq_tx_ready(dev);
948static inline void z_impl_uart_irq_rx_enable(
const struct device *dev)
950#ifdef CONFIG_UART_INTERRUPT_DRIVEN
951 const struct uart_driver_api *api =
952 (
const struct uart_driver_api *)dev->
api;
954 if (api->irq_rx_enable != NULL) {
955 api->irq_rx_enable(dev);
969static inline void z_impl_uart_irq_rx_disable(
const struct device *dev)
971#ifdef CONFIG_UART_INTERRUPT_DRIVEN
972 const struct uart_driver_api *api =
973 (
const struct uart_driver_api *)dev->
api;
975 if (api->irq_rx_disable != NULL) {
976 api->irq_rx_disable(dev);
1004#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1005 const struct uart_driver_api *api =
1006 (
const struct uart_driver_api *)dev->
api;
1008 if (api->irq_tx_complete == NULL) {
1011 return api->irq_tx_complete(dev);
1040#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1041 const struct uart_driver_api *api =
1042 (
const struct uart_driver_api *)dev->
api;
1044 if (api->irq_rx_ready == NULL) {
1047 return api->irq_rx_ready(dev);
1060static inline void z_impl_uart_irq_err_enable(
const struct device *dev)
1062#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1063 const struct uart_driver_api *api =
1064 (
const struct uart_driver_api *)dev->
api;
1066 if (api->irq_err_enable) {
1067 api->irq_err_enable(dev);
1081static inline void z_impl_uart_irq_err_disable(
const struct device *dev)
1083#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1084 const struct uart_driver_api *api =
1085 (
const struct uart_driver_api *)dev->
api;
1087 if (api->irq_err_disable) {
1088 api->irq_err_disable(dev);
1107static inline int z_impl_uart_irq_is_pending(
const struct device *dev)
1109#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1110 const struct uart_driver_api *api =
1111 (
const struct uart_driver_api *)dev->
api;
1113 if (api->irq_is_pending == NULL) {
1116 return api->irq_is_pending(dev);
1150static inline int z_impl_uart_irq_update(
const struct device *dev)
1152#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1153 const struct uart_driver_api *api =
1154 (
const struct uart_driver_api *)dev->
api;
1156 if (api->irq_update == NULL) {
1159 return api->irq_update(dev);
1185#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1186 const struct uart_driver_api *api =
1187 (
const struct uart_driver_api *)dev->
api;
1189 if ((api != NULL) && (api->irq_callback_set != NULL)) {
1190 api->irq_callback_set(dev, cb, user_data);
1198 ARG_UNUSED(user_data);
1250#ifdef CONFIG_UART_ASYNC_API
1251 const struct uart_driver_api *api =
1252 (
const struct uart_driver_api *)dev->
api;
1254 if (api->callback_set == NULL) {
1258 return api->callback_set(dev, callback, user_data);
1261 ARG_UNUSED(callback);
1262 ARG_UNUSED(user_data);
1288static inline int z_impl_uart_tx(
const struct device *dev,
const uint8_t *buf,
1292#ifdef CONFIG_UART_ASYNC_API
1293 const struct uart_driver_api *api =
1294 (
const struct uart_driver_api *)dev->
api;
1296 return api->tx(dev, buf, len, timeout);
1301 ARG_UNUSED(timeout);
1326static inline int z_impl_uart_tx_u16(
const struct device *dev,
1331#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
1332 const struct uart_driver_api *api =
1333 (
const struct uart_driver_api *)dev->
api;
1335 return api->tx_u16(dev, buf, len, timeout);
1340 ARG_UNUSED(timeout);
1359static inline int z_impl_uart_tx_abort(
const struct device *dev)
1361#ifdef CONFIG_UART_ASYNC_API
1362 const struct uart_driver_api *api =
1363 (
const struct uart_driver_api *)dev->
api;
1365 return api->tx_abort(dev);
1397static inline int z_impl_uart_rx_enable(
const struct device *dev,
1401#ifdef CONFIG_UART_ASYNC_API
1402 const struct uart_driver_api *api =
1403 (
const struct uart_driver_api *)dev->
api;
1405 return api->rx_enable(dev, buf, len, timeout);
1410 ARG_UNUSED(timeout);
1439static inline int z_impl_uart_rx_enable_u16(
const struct device *dev,
1443#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
1444 const struct uart_driver_api *api =
1445 (
const struct uart_driver_api *)dev->
api;
1447 return api->rx_enable_u16(dev, buf, len, timeout);
1452 ARG_UNUSED(timeout);
1480#ifdef CONFIG_UART_ASYNC_API
1481 const struct uart_driver_api *api =
1482 (
const struct uart_driver_api *)dev->
api;
1484 return api->rx_buf_rsp(dev, buf, len);
1517#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_WIDE_DATA)
1518 const struct uart_driver_api *api =
1519 (
const struct uart_driver_api *)dev->
api;
1521 return api->rx_buf_rsp_u16(dev, buf, len);
1547static inline int z_impl_uart_rx_disable(
const struct device *dev)
1549#ifdef CONFIG_UART_ASYNC_API
1550 const struct uart_driver_api *api =
1551 (
const struct uart_driver_api *)dev->
api;
1553 return api->rx_disable(dev);
1579static inline int z_impl_uart_line_ctrl_set(
const struct device *dev,
1582#ifdef CONFIG_UART_LINE_CTRL
1583 const struct uart_driver_api *api =
1584 (
const struct uart_driver_api *)dev->
api;
1586 if (api->line_ctrl_set == NULL) {
1589 return api->line_ctrl_set(dev, ctrl, val);
1613static inline int z_impl_uart_line_ctrl_get(
const struct device *dev,
1616#ifdef CONFIG_UART_LINE_CTRL
1617 const struct uart_driver_api *api =
1618 (
const struct uart_driver_api *)dev->
api;
1620 if (api->line_ctrl_get == NULL) {
1623 return api->line_ctrl_get(dev, ctrl, val);
1652#ifdef CONFIG_UART_DRV_CMD
1653 const struct uart_driver_api *api =
1654 (
const struct uart_driver_api *)dev->
api;
1656 if (api->drv_cmd == NULL) {
1659 return api->drv_cmd(dev,
cmd, p);
1676#include <zephyr/syscalls/uart.h>
static void cmd(uint32_t command)
Execute a display list command by co-processor engine.
Definition ft8xx_reference_api.h:153
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#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:324
int uart_rx_enable_u16(const struct device *dev, uint16_t *buf, size_t len, int32_t timeout)
Start receiving wide data through UART.
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.
Definition uart.h:1477
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.
Definition uart.h:1514
int uart_rx_enable(const struct device *dev, uint8_t *buf, size_t len, int32_t timeout)
Start receiving data through UART.
int uart_tx_abort(const struct device *dev)
Abort current TX transmission.
int uart_tx_u16(const struct device *dev, const uint16_t *buf, size_t len, int32_t timeout)
Send given number of datum from buffer through UART.
static int uart_callback_set(const struct device *dev, uart_callback_t callback, void *user_data)
Set event handler function.
Definition uart.h:1246
uart_event_type
Types of events passed to callback in UART_ASYNC_API.
Definition uart.h:207
int uart_tx(const struct device *dev, const uint8_t *buf, size_t len, int32_t timeout)
Send given number of bytes from buffer through UART.
int uart_rx_disable(const struct device *dev)
Disable RX.
@ UART_RX_STOPPED
RX has stopped due to external event.
Definition uart.h:258
@ UART_TX_ABORTED
Transmitting aborted due to timeout or uart_tx_abort call.
Definition uart.h:217
@ UART_RX_BUF_REQUEST
Driver requests next buffer for continuous reception.
Definition uart.h:240
@ UART_TX_DONE
Whole TX buffer was transmitted.
Definition uart.h:209
@ UART_RX_RDY
Received data is ready for processing.
Definition uart.h:228
@ UART_RX_DISABLED
RX has been disabled and can be reenabled.
Definition uart.h:252
@ UART_RX_BUF_RELEASED
Buffer is no longer used by UART driver.
Definition uart.h:244
uart_line_ctrl
Line control signals.
Definition uart.h:35
int uart_err_check(const struct device *dev)
Check whether an error was detected.
int uart_config_get(const struct device *dev, struct uart_config *cfg)
Get UART configuration.
uart_config_flow_control
Hardware flow control options.
Definition uart.h:111
int uart_configure(const struct device *dev, const struct uart_config *cfg)
Set UART configuration.
int uart_drv_cmd(const struct device *dev, uint32_t cmd, uint32_t p)
Send extra command to driver.
int uart_line_ctrl_set(const struct device *dev, uint32_t ctrl, uint32_t val)
Manipulate line control for UART.
uart_config_parity
Parity modes.
Definition uart.h:79
uart_config_data_bits
Number of data bits.
Definition uart.h:96
uart_rx_stop_reason
Reception stop reasons.
Definition uart.h:49
uart_config_stop_bits
Number of stop bits.
Definition uart.h:88
int uart_line_ctrl_get(const struct device *dev, uint32_t ctrl, uint32_t *val)
Retrieve line control for UART.
@ UART_LINE_CTRL_DTR
Data Terminal Ready (DTR)
Definition uart.h:38
@ UART_LINE_CTRL_RTS
Request To Send (RTS)
Definition uart.h:37
@ UART_LINE_CTRL_BAUD_RATE
Baud rate.
Definition uart.h:36
@ UART_LINE_CTRL_DCD
Data Carrier Detect (DCD)
Definition uart.h:39
@ UART_LINE_CTRL_DSR
Data Set Ready (DSR)
Definition uart.h:40
@ UART_CFG_FLOW_CTRL_DTR_DSR
DTR/DSR flow control.
Definition uart.h:114
@ UART_CFG_FLOW_CTRL_NONE
No flow control.
Definition uart.h:112
@ UART_CFG_FLOW_CTRL_RS485
RS485 flow control.
Definition uart.h:115
@ UART_CFG_FLOW_CTRL_RTS_CTS
RTS/CTS flow control.
Definition uart.h:113
@ UART_CFG_PARITY_MARK
Mark parity.
Definition uart.h:83
@ UART_CFG_PARITY_NONE
No parity.
Definition uart.h:80
@ UART_CFG_PARITY_ODD
Odd parity.
Definition uart.h:81
@ UART_CFG_PARITY_SPACE
Space parity.
Definition uart.h:84
@ UART_CFG_PARITY_EVEN
Even parity.
Definition uart.h:82
@ UART_CFG_DATA_BITS_5
5 data bits
Definition uart.h:97
@ UART_CFG_DATA_BITS_8
8 data bits
Definition uart.h:100
@ UART_CFG_DATA_BITS_7
7 data bits
Definition uart.h:99
@ UART_CFG_DATA_BITS_6
6 data bits
Definition uart.h:98
@ UART_CFG_DATA_BITS_9
9 data bits
Definition uart.h:101
@ UART_ERROR_NOISE
Noise error.
Definition uart.h:75
@ UART_ERROR_OVERRUN
Overrun error.
Definition uart.h:51
@ UART_BREAK
Break interrupt.
Definition uart.h:63
@ UART_ERROR_PARITY
Parity error.
Definition uart.h:53
@ UART_ERROR_COLLISION
Collision error.
Definition uart.h:73
@ UART_ERROR_FRAMING
Framing error.
Definition uart.h:55
@ UART_CFG_STOP_BITS_1_5
1.5 stop bits
Definition uart.h:91
@ UART_CFG_STOP_BITS_0_5
0.5 stop bit
Definition uart.h:89
@ UART_CFG_STOP_BITS_1
1 stop bit
Definition uart.h:90
@ UART_CFG_STOP_BITS_2
2 stop bits
Definition uart.h:92
int uart_irq_is_pending(const struct device *dev)
Check if any IRQs is pending.
static int uart_fifo_read_u16(const struct device *dev, uint16_t *rx_data, const int size)
Read wide data from FIFO.
Definition uart.h:841
void uart_irq_rx_enable(const struct device *dev)
Enable RX interrupt.
static int uart_irq_tx_ready(const struct device *dev)
Check if UART TX buffer can accept bytes.
Definition uart.h:924
static int uart_irq_callback_set(const struct device *dev, uart_irq_callback_user_data_t cb)
Set the IRQ callback function pointer (legacy).
Definition uart.h:1216
void(* uart_irq_config_func_t)(const struct device *dev)
For configuring IRQ on each individual UART device.
Definition uart.h:149
void uart_irq_err_enable(const struct device *dev)
Enable error interrupt.
static int uart_irq_tx_complete(const struct device *dev)
Check if UART TX block finished transmission.
Definition uart.h:1002
void uart_irq_tx_enable(const struct device *dev)
Enable TX interrupt in IER.
void uart_irq_rx_disable(const struct device *dev)
Disable RX interrupt.
static int uart_fifo_fill_u16(const struct device *dev, const uint16_t *tx_data, int size)
Fill FIFO with wide data.
Definition uart.h:758
void uart_irq_err_disable(const struct device *dev)
Disable error interrupt.
static int uart_fifo_read(const struct device *dev, uint8_t *rx_data, const int size)
Read data from FIFO.
Definition uart.h:800
int uart_irq_update(const struct device *dev)
Start processing interrupts in ISR.
static int uart_irq_rx_ready(const struct device *dev)
Check if UART RX buffer has a received char.
Definition uart.h:1038
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:141
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.
Definition uart.h:1181
void uart_irq_tx_disable(const struct device *dev)
Disable TX interrupt in IER.
static int uart_fifo_fill(const struct device *dev, const uint8_t *tx_data, int size)
Fill FIFO with data.
Definition uart.h:717
void uart_poll_out(const struct device *dev, unsigned char out_char)
Write a character to the device for output.
void uart_poll_out_u16(const struct device *dev, uint16_t out_u16)
Write a 16-bit datum to the device for output.
int uart_poll_in_u16(const struct device *dev, uint16_t *p_u16)
Read a 16-bit datum from the device for input.
int uart_poll_in(const struct device *dev, unsigned char *p_char)
Read a character from the device for input.
__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:121
uint8_t stop_bits
Stop bits, use uart_config_stop_bits.
Definition uart.h:124
uint8_t parity
Parity bit, use uart_config_parity.
Definition uart.h:123
uint8_t data_bits
Data bits, use uart_config_data_bits.
Definition uart.h:125
uint32_t baudrate
Baudrate setting in bps.
Definition uart.h:122
uint8_t flow_ctrl
Flow control setting, use uart_config_flow_control.
Definition uart.h:126
UART RX buffer released event data.
Definition uart.h:285
uint8_t * buf
Pointer to buffer that is no longer in use.
Definition uart.h:287
UART RX stopped data.
Definition uart.h:291
struct uart_event_rx data
Last received data.
Definition uart.h:295
enum uart_rx_stop_reason reason
Reason why receiving stopped.
Definition uart.h:293
UART RX event data.
Definition uart.h:275
uint8_t * buf
Pointer to current buffer.
Definition uart.h:277
size_t len
Number of new bytes received.
Definition uart.h:281
size_t offset
Currently received data offset in bytes.
Definition uart.h:279
UART TX event data.
Definition uart.h:262
const uint8_t * buf
Pointer to current buffer.
Definition uart.h:264
size_t len
Number of bytes sent.
Definition uart.h:266
Structure containing information about current event.
Definition uart.h:299
union uart_event::uart_event_data data
enum uart_event_type type
Type of event.
Definition uart.h:301
Event data.
Definition uart.h:303
struct uart_event_tx tx
UART_TX_DONE and UART_TX_ABORTED events data.
Definition uart.h:305
struct uart_event_rx_stop rx_stop
UART_RX_STOPPED event data.
Definition uart.h:311
struct uart_event_rx_buf rx_buf
UART_RX_BUF_RELEASED event data.
Definition uart.h:309
struct uart_event_rx rx
UART_RX_RDY event data.
Definition uart.h:307