8. UART operation guide¶
8.1. The Operation Preparation of UART Is as Follows¶
Use the kernel released by SDK。
8.2. Module Compilation¶
The source path is drivers/uart. When users need to access UART devices, they first need to specify the UART source path and header file path in the compilation script. After successful compilation, a library file named libuart.a is generated in the out directory. The library file needs to be specified with the -luart parameter when linking
8.3. Operation Example¶
Step 1:
Call the following interface in the initialization function to implement UART driver registration:
uart_dev_init();
If dma is enabled to receive data, dmac initialization is performed and called in the initialization function:
cvi_dmac_init();
Step 2:
Open the specified UART by calling open from the /dev/ttySN node
Step 3:
After opening UART, ioctl configuration read can be called to read data, write can send data, read can be blocked by select
Step 4:
When UART is not used, close is called to close, after which UART controller no longer receives data from the serial port.
8.4. Action Sample UART API Reference¶
uart_dev_init: UART Device Initialization
uart_suspend: UART Device Suspend
uart_resume: UART Device Wake Up
8.4.1. uart_dev_init¶
【Description】
UART Device Initialization
【Syntax】
int uart_dev_init(void);
【参数】
Parameters |
Description |
Input / Output |
---|---|---|
None |
None |
None |
8.4.2. uart_suspend¶
【Description】
UART Device Suspend
【Syntax】
int uart_suspend(void);
【参数】
Parameters |
Description |
Input / Output |
---|---|---|
Data |
Reserved, passed in NULL |
None |
【Return Value】
Return Value |
Description |
---|---|
0 |
Success |
Others |
Failure |
8.4.3. uart_resume¶
【Description】
UART Initial wake-up of device。
【Syntax】
int uart_resume(void);
【参数】
Parameters |
Description |
Input / Output |
---|---|---|
Data |
Not used, passing in NULL |
None |
【Return Value】
Return Value |
Description |
---|---|
0 |
Success |
Others |
Failure |
8.5. ioctl Configuration Instructions¶
【Description】
After turning on UART, configure UART baud rate, dma reception, blocking reads, wired control, etc. through ioctl.For example, configure baud rate:ret = ioctl(fd, CFG_BAUDRATE, 9600);
【Configuration Instructions】
Command Number |
Command Code |
Parameters |
Description |
---|---|---|---|
UART_CFG_BAUDRATE |
0x101 |
baud rate |
Configure baud rate, UART0 default baud rate 115200; UART1, UART2, UART3 are 9600 Supports a maximum baud rate of 921600 |
UART_CFG_DMA_RX |
0x102 |
0 or 1 |
0: Configured as interrupt receiving mode; 1: Configured DMA reception defaults to interrupt type |
UART_CFG_DMA_TX |
0x103 |
0 or 1 |
0: Configured as interrupt receiving mode; 1: Configured DMA reception defaults to interrupt type |
UART_CFG_RD_BLOCK |
0x104 |
0 or 1 |
0: Configure read as non-blocking mode; 1: Configure event blocking read The default is blocking mode; |
UART_CFG_ATTR |
0x105 |
0 or 1 |
Configure check bits, data bits, stop bits, FIFO, CTS/RTS, etc The default is: no check bit, 8 bits of data bit, 1 bit Stop bit, no CTS/RTS. Refer to the header file struct uart_attr |
UART_CFG_PRIV |
0x110 |
Custo mization |
Drive custom commands |