UART

Overview

Defines standard APIs of universal asynchronous receiver/transmitter (UART) capabilities.

You can use this module to access the UART and enable the driver to operate a UART-compliant device. The functions in this module help you to obtain and release the UART device handle, read and write data, obtain and set the baud rate and device attributes.

Since:

1.0

Summary

Files

File Name

Description

uart_if.h

Declares standard UART APIs.

Data Structures

Data Structure Name

Description

UartAttribute

Defines basic attributes of the UART port.

Enumerations

Enumeration Name

Description

UartTransMode {   UART_MODE_RD_BLOCK = 0, UART_MODE_RD_NONBLOCK, UART_MODE_DMA_RX_EN, UART_MODE_DMA_RX_DIS,   UART_MODE_DMA_TX_EN, UART_MODE_DMA_TX_DIS }

Enumerates UART transmission modes.

Functions

Function Name

Description

UartOpen (uint32_t port)

struct DevHandle 

Obtains the UART device handle.

UartClose (struct DevHandle handle)

void 

Releases the UART device handle.

UartRead (struct DevHandlehandle, uint8_t data, uint32_t size)

int32_t 

Reads data of a specified size from a UART device.

UartWrite (struct DevHandlehandle, uint8_t data, uint32_t size)

int32_t 

Writes data of a specified size into a UART device.

UartGetBaud (struct DevHandlehandle, uint32_t baudRate)

int32_t 

Obtains the baud rate of the UART device.

UartSetBaud (struct DevHandlehandle, uint32_t baudRate)

int32_t 

Sets the baud rate for the UART device.

UartGetAttribute (struct DevHandle handle, struct UartAttributeattribute)

int32_t 

Obtains the UART attribute.

UartSetAttribute (struct DevHandle handle, struct UartAttributeattribute)

int32_t 

Sets the UART attribute.

UartSetTransMode (struct DevHandle handle, enum UartTransMode mode)

int32_t 

Sets the UART transmission mode.

Details

Enumeration Type Documentation

UartTransMode

  1. enum[UartTransMode]($api-api-SmartVision-Devices-UART.md#gab9e041a0802a7e24da22215b458bf7db)

Description:

Enumerates UART transmission modes.

Attention:

The UART controller determines whether an enumerated transmission mode is supported.

Enumerator

Description

UART_MODE_RD_BLOCK 

Blocking mode

UART_MODE_RD_NONBLOCK 

Non-blocking mode

UART_MODE_DMA_RX_EN 

DMA enabled for data receiving

UART_MODE_DMA_RX_DIS 

DMA disabled for data receiving

UART_MODE_DMA_TX_EN 

DMA enabled for data transmitting

UART_MODE_DMA_TX_DIS 

DMA disabled for data transmitting

Function Documentation

UartClose()

  1. voidUartClose(struct[DevHandle]($api-api-SmartVision-Devices-DevHandle.md)* handle)

Description:

Releases the UART device handle.

If you no longer need to access the UART device, you should call this function to close its handle so as to release unused memory resources.

Parameters:

Name

Description

handleIndicates the pointer to the UART device handle, which is obtained via UartOpen.

UartGetAttribute()

  1. int32_tUartGetAttribute(struct[DevHandle]($api-api-SmartVision-Devices-DevHandle.md)* handle,struct[UartAttribute]($api-api-SmartVision-Devices-UartAttribute.md)* attribute )

Description:

Obtains the UART attribute.

UART attributes include data bits, stop bits, parity bit, CTS, RTS, and receiving and transmitting FIFO.

Parameters:

Name

Description

handleIndicates the pointer to the UART device handle, which is obtained via UartOpen.
attributeIndicates the pointer to the obtained UART attribute.

Returns:

Returns 0 if the UART attribute is obtained; returns a negative number otherwise.

UartGetBaud()

  1. int32_tUartGetBaud(struct[DevHandle]($api-api-SmartVision-Devices-DevHandle.md)* handle,uint32_t* baudRate )

Description:

Obtains the baud rate of the UART device.

Parameters:

Name

Description

handleIndicates the pointer to the UART device handle, which is obtained via UartOpen.
baudRateIndicates the pointer to the obtained baud rate.

Returns:

Returns 0 if the baud rate is obtained; returns a negative number otherwise.

UartOpen()

  1. struct[DevHandle]($api-api-SmartVision-Devices-DevHandle.md)*UartOpen(uint32_t port)

Description:

Obtains the UART device handle.

Before accessing the UART device, you must call this function to obtain the UART device handle.

Parameters:

Name

Description

portIndicates the UART port.

Returns:

Returns the pointer to the UART device handle if the handle is obtained; returns NULL otherwise.

UartRead()

  1. int32_tUartRead(struct[DevHandle]($api-api-SmartVision-Devices-DevHandle.md)* handle,uint8_t* data,uint32_t size )

Description:

Reads data of a specified size from a UART device.

Parameters:

Name

Description

handleIndicates the pointer to the UART device handle, which is obtained via UartOpen.
dataIndicates the pointer to the buffer for receiving the data.
sizeIndicates the size of the data to read.

Returns:

Returns the size of the data that is successfully read; returns a negative number if the reading fails.

UartSetAttribute()

  1. int32_tUartSetAttribute(struct[DevHandle]($api-api-SmartVision-Devices-DevHandle.md)* handle,struct[UartAttribute]($api-api-SmartVision-Devices-UartAttribute.md)* attribute )

Description:

Sets the UART attribute.

UART attributes include data bits, stop bits, parity bit, CTS, RTS, and receiving and transmitting FIFO.

Parameters:

Name

Description

handleIndicates the pointer to the UART device handle, which is obtained via UartOpen.
attributeIndicates the pointer to the UART attribute to set.

Returns:

Returns 0 if the setting is successful; returns a negative number otherwise.

UartSetBaud()

  1. int32_tUartSetBaud(struct[DevHandle]($api-api-SmartVision-Devices-DevHandle.md)* handle,uint32_t baudRate )

Description:

Sets the baud rate for the UART device.

Parameters:

Name

Description

handleIndicates the pointer to the UART device handle, which is obtained via UartOpen.
baudRateIndicates the baud rate to set.

Returns:

Returns 0 if the setting is successful; returns a negative number otherwise.

UartSetTransMode()

  1. int32_tUartSetTransMode(struct[DevHandle]($api-api-SmartVision-Devices-DevHandle.md)* handle,enum[UartTransMode]($api-api-SmartVision-Devices-UART.md#gab9e041a0802a7e24da22215b458bf7db) mode )

Description:

Sets the UART transmission mode.

Parameters:

Name

Description

handleIndicates the pointer to the UART device handle, which is obtained via UartOpen.
modeIndicates a transmission mode enumerated in {@linkUartTransMode}.

Returns:

Returns 0 if the setting is successful; returns a negative number otherwise.

UartWrite()

  1. int32_tUartWrite(struct[DevHandle]($api-api-SmartVision-Devices-DevHandle.md)* handle,uint8_t* data,uint32_t size )

Description:

Writes data of a specified size into a UART device.

Parameters:

Name

Description

handleIndicates the pointer to the UART device handle, which is obtained via UartOpen.
dataIndicates the pointer to the data to write.
sizeIndicates the size of the data to write.

Returns:

Returns 0 if the data is successfully written; returns a negative number otherwise.