Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
uart.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018-2019 Nordic Semiconductor ASA
3 * Copyright (c) 2015 Wind River Systems, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
13#ifndef ZEPHYR_INCLUDE_DRIVERS_UART_H_
14#define ZEPHYR_INCLUDE_DRIVERS_UART_H_
15
25#include <stddef.h>
26
27#include <zephyr/device.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
41
76
85
93
102
116
127
140typedef void (*uart_irq_callback_user_data_t)(const struct device *dev,
141 void *user_data);
142
252
256 const uint8_t *buf;
258 size_t len;
259};
260
271 size_t offset;
273 size_t len;
274};
275
281
289
306
316typedef void (*uart_callback_t)(const struct device *dev,
317 struct uart_event *evt, void *user_data);
318
332__syscall int uart_err_check(const struct device *dev);
333
357__syscall int uart_poll_in(const struct device *dev, unsigned char *p_char);
358
378__syscall int uart_poll_in_u16(const struct device *dev, uint16_t *p_u16);
379
395__syscall void uart_poll_out(const struct device *dev,
396 unsigned char out_char);
397
412__syscall void uart_poll_out_u16(const struct device *dev, uint16_t out_u16);
413
432__syscall int uart_configure(const struct device *dev,
433 const struct uart_config *cfg);
434
449__syscall int uart_config_get(const struct device *dev,
450 struct uart_config *cfg);
451
477static inline int uart_fifo_fill(const struct device *dev, const uint8_t *tx_data, int size);
478
499static inline int uart_fifo_fill_u16(const struct device *dev, const uint16_t *tx_data, int size);
500
522static inline int uart_fifo_read(const struct device *dev, uint8_t *rx_data, const int size);
523
545static inline int uart_fifo_read_u16(const struct device *dev, uint16_t *rx_data, const int size);
546
552__syscall void uart_irq_tx_enable(const struct device *dev);
553
559__syscall void uart_irq_tx_disable(const struct device *dev);
560
581static inline int uart_irq_tx_ready(const struct device *dev);
582
588__syscall void uart_irq_rx_enable(const struct device *dev);
589
595__syscall void uart_irq_rx_disable(const struct device *dev);
596
616static inline int uart_irq_tx_complete(const struct device *dev);
617
638static inline int uart_irq_rx_ready(const struct device *dev);
639
645__syscall void uart_irq_err_enable(const struct device *dev);
646
652__syscall void uart_irq_err_disable(const struct device *dev);
653
664__syscall int uart_irq_is_pending(const struct device *dev);
665
691__syscall int uart_irq_update(const struct device *dev);
692
708static inline int uart_irq_callback_user_data_set(const struct device *dev,
710 void *user_data);
711
725static inline int uart_irq_callback_set(const struct device *dev,
727
752static inline int uart_callback_set(const struct device *dev,
753 uart_callback_t callback,
754 void *user_data);
755
773__syscall int uart_tx(const struct device *dev, const uint8_t *buf,
774 size_t len,
775 int32_t timeout);
776
794__syscall int uart_tx_u16(const struct device *dev, const uint16_t *buf,
795 size_t len, int32_t timeout);
796
809__syscall int uart_tx_abort(const struct device *dev);
810
832__syscall int uart_rx_enable(const struct device *dev, uint8_t *buf,
833 size_t len,
834 int32_t timeout);
835
857__syscall int uart_rx_enable_u16(const struct device *dev, uint16_t *buf,
858 size_t len, int32_t timeout);
859
880static inline int uart_rx_buf_rsp(const struct device *dev, uint8_t *buf,
881 size_t len);
882
904static inline int uart_rx_buf_rsp_u16(const struct device *dev, uint16_t *buf,
905 size_t len);
906
922__syscall int uart_rx_disable(const struct device *dev);
923
940__syscall int uart_line_ctrl_set(const struct device *dev,
941 uint32_t ctrl, uint32_t val);
942
955__syscall int uart_line_ctrl_get(const struct device *dev, uint32_t ctrl,
956 uint32_t *val);
957
973__syscall int uart_drv_cmd(const struct device *dev, uint32_t cmd, uint32_t p);
974
975#ifdef __cplusplus
976}
977#endif
978
984#include <zephyr/syscalls/uart.h>
985
986#endif /* ZEPHYR_INCLUDE_DRIVERS_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
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
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.
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.
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.
uart_event_type
Types of events passed to callback in UART_ASYNC_API.
Definition uart.h:199
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:250
@ UART_TX_ABORTED
Transmitting aborted due to timeout or uart_tx_abort call.
Definition uart.h:209
@ UART_RX_BUF_REQUEST
Driver requests next buffer for continuous reception.
Definition uart.h:232
@ UART_TX_DONE
Whole TX buffer was transmitted.
Definition uart.h:201
@ UART_RX_RDY
Received data is ready for processing.
Definition uart.h:220
@ UART_RX_DISABLED
RX has been disabled and can be reenabled.
Definition uart.h:244
@ UART_RX_BUF_RELEASED
Buffer is no longer used by UART driver.
Definition uart.h:236
uart_line_ctrl
Line control signals.
Definition uart.h:34
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:110
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:78
uart_config_data_bits
Number of data bits.
Definition uart.h:95
uart_rx_stop_reason
Reception stop reasons.
Definition uart.h:48
uart_config_stop_bits
Number of stop bits.
Definition uart.h:87
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:37
@ UART_LINE_CTRL_RTS
Request To Send (RTS)
Definition uart.h:36
@ UART_LINE_CTRL_BAUD_RATE
Baud rate.
Definition uart.h:35
@ UART_LINE_CTRL_DCD
Data Carrier Detect (DCD)
Definition uart.h:38
@ UART_LINE_CTRL_DSR
Data Set Ready (DSR)
Definition uart.h:39
@ UART_CFG_FLOW_CTRL_DTR_DSR
DTR/DSR flow control.
Definition uart.h:113
@ UART_CFG_FLOW_CTRL_NONE
No flow control.
Definition uart.h:111
@ UART_CFG_FLOW_CTRL_RS485
RS485 flow control.
Definition uart.h:114
@ UART_CFG_FLOW_CTRL_RTS_CTS
RTS/CTS flow control.
Definition uart.h:112
@ UART_CFG_PARITY_MARK
Mark parity.
Definition uart.h:82
@ UART_CFG_PARITY_NONE
No parity.
Definition uart.h:79
@ UART_CFG_PARITY_ODD
Odd parity.
Definition uart.h:80
@ UART_CFG_PARITY_SPACE
Space parity.
Definition uart.h:83
@ UART_CFG_PARITY_EVEN
Even parity.
Definition uart.h:81
@ UART_CFG_DATA_BITS_5
5 data bits
Definition uart.h:96
@ UART_CFG_DATA_BITS_8
8 data bits
Definition uart.h:99
@ UART_CFG_DATA_BITS_7
7 data bits
Definition uart.h:98
@ UART_CFG_DATA_BITS_6
6 data bits
Definition uart.h:97
@ UART_CFG_DATA_BITS_9
9 data bits
Definition uart.h:100
@ UART_ERROR_NOISE
Noise error.
Definition uart.h:74
@ UART_ERROR_OVERRUN
Overrun error.
Definition uart.h:50
@ UART_BREAK
Break interrupt.
Definition uart.h:62
@ UART_ERROR_PARITY
Parity error.
Definition uart.h:52
@ UART_ERROR_COLLISION
Collision error.
Definition uart.h:72
@ UART_ERROR_FRAMING
Framing error.
Definition uart.h:54
@ UART_CFG_STOP_BITS_1_5
1.5 stop bits
Definition uart.h:90
@ UART_CFG_STOP_BITS_0_5
0.5 stop bit
Definition uart.h:88
@ UART_CFG_STOP_BITS_1
1 stop bit
Definition uart.h:89
@ UART_CFG_STOP_BITS_2
2 stop bits
Definition uart.h:91
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.
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.
static int uart_irq_callback_set(const struct device *dev, uart_irq_callback_user_data_t cb)
Set the IRQ callback function pointer (legacy).
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.
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.
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.
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.
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.
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.
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
UART controller configuration structure.
Definition uart.h:120
uint8_t stop_bits
Stop bits, use uart_config_stop_bits.
Definition uart.h:123
uint8_t parity
Parity bit, use uart_config_parity.
Definition uart.h:122
uint8_t data_bits
Data bits, use uart_config_data_bits.
Definition uart.h:124
uint32_t baudrate
Baudrate setting in bps.
Definition uart.h:121
uint8_t flow_ctrl
Flow control setting, use uart_config_flow_control.
Definition uart.h:125
UART RX buffer released event data.
Definition uart.h:277
uint8_t * buf
Pointer to buffer that is no longer in use.
Definition uart.h:279
UART RX stopped data.
Definition uart.h:283
struct uart_event_rx data
Last received data.
Definition uart.h:287
enum uart_rx_stop_reason reason
Reason why receiving stopped.
Definition uart.h:285
UART RX event data.
Definition uart.h:267
uint8_t * buf
Pointer to current buffer.
Definition uart.h:269
size_t len
Number of new bytes received.
Definition uart.h:273
size_t offset
Currently received data offset in bytes.
Definition uart.h:271
UART TX event data.
Definition uart.h:254
const uint8_t * buf
Pointer to current buffer.
Definition uart.h:256
size_t len
Number of bytes sent.
Definition uart.h:258
Structure containing information about current event.
Definition uart.h:291
union uart_event::uart_event_data data
enum uart_event_type type
Type of event.
Definition uart.h:293
Internal APIs for UART drivers.
Event data.
Definition uart.h:295
struct uart_event_tx tx
UART_TX_DONE and UART_TX_ABORTED events data.
Definition uart.h:297
struct uart_event_rx_stop rx_stop
UART_RX_STOPPED event data.
Definition uart.h:303
struct uart_event_rx_buf rx_buf
UART_RX_BUF_RELEASED event data.
Definition uart.h:301
struct uart_event_rx rx
UART_RX_RDY event data.
Definition uart.h:299