HAL  v0.6.1
Hardware Abstraction Layer
Loading...
Searching...
No Matches
UART

Universal Asynchronous Receiver & Transmitter. More...

Collaboration diagram for UART:

Data Structures

struct  uart_bus_status_t
 
struct  uart_channel_attr_t
 
struct  uart_handle_t
 

Enumerations

enum  uart_result_t {
  UART_RESULT_OK ,
  UART_RESULT_INVALID ,
  UART_RESULT_UNSUPPORTED ,
  UART_RESULT_OVERRUN_ERROR ,
  UART_RESULT_UNDERRUN_ERROR ,
  UART_RESULT_FRAMING_ERROR ,
  UART_RESULT_PARITY_ERROR ,
  UART_RESULT_TIMEOUT ,
  UART_RESULT_IDLE ,
  UART_RESULT_BUSY ,
  UART_RESULT_ERR ,
  TOTAL_UART_RESULT
}
 
enum  uart_status_t {
  UART_STATUS_UNKNOWN ,
  UART_STATUS_OK ,
  UART_STATUS_BUSY ,
  UART_STATUS_STOP ,
  UART_STATUS_SENDING ,
  UART_STATUS_RECEIVING ,
  UART_STATUS_ERR ,
  TOTAL_UART_STATUS
}
 
enum  uart_mode_t {
  UART_MODE_ASYNCHRONOUS ,
  UART_MODE_SYNCHRONOUS ,
  TOTAL_UART_MODE
}
 
enum  uart_baudrate_t {
  UART_BAUDRATE_9600 = 9600U ,
  UART_BAUDRATE_19200 = 19200U ,
  UART_BAUDRATE_38400 = 38400U ,
  UART_BAUDRATE_57600 = 57600U ,
  UART_BAUDRATE_115200 = 115200U ,
  UART_BAUDRATE_576000 = 576000U ,
  UART_BAUDRATE_921600 = 921600U ,
  TOTAL_UART_BAUDRATE
}
 
enum  uart_baudrate_type_t {
  UART_BAUDRATE_TYPE_MANUAL ,
  UART_BAUDRATE_TYPE_AUTO ,
  TOTAL_UART_BAUDRATE_TYPE
}
 
enum  uart_data_bits_t {
  UART_DATA_BITS_8 ,
  UART_DATA_BITS_9 ,
  TOTAL_UART_DATA_BITS
}
 
enum  uart_stop_bits_t {
  UART_STOP_BITS_1 ,
  UART_STOP_BITS_2 ,
  TOTAL_UART_STOP_BITS
}
 
enum  uart_parity_t {
  UART_PARITY_EVEN ,
  UART_PARITY_ODD ,
  UART_PARITY_NONE ,
  TOTAL_UART_PARITY
}
 

Functions

uart_result_t hal_uart_init (uart_handle_t *handle, const uart_channel_attr_t attr)
 Configure UART channel with specific attributes.
 
uart_result_t hal_uart_write (uart_handle_t *handle, const uint8_t *tx_buffer, const size_t len)
 Write data to UART channel.
 
uart_result_t hal_uart_read (uart_handle_t *handle, uint8_t *rx_buffer, const size_t len)
 Read data from UART channel.
 
uart_result_t hal_uart_stop (uart_handle_t *handle)
 Stop UART operation.
 
uart_bus_status_t hal_uart_get_status (uart_handle_t *handle)
 Get UART bus status.
 
uart_result_t hal_uart_mutex_take (const uint8_t channel, const uint32_t timeout_ms)
 Try acquire RTOS mutex for specified channel.
 
uart_result_t hal_uart_mutex_give (const uint8_t channel)
 Release RTOS mutex for specified channel.
 

Detailed Description

Universal Asynchronous Receiver & Transmitter.

Enumeration Type Documentation

◆ uart_baudrate_t

#include <uart/public_inc/hal_uart.h>

Enumerator
UART_BAUDRATE_9600 
UART_BAUDRATE_19200 
UART_BAUDRATE_38400 
UART_BAUDRATE_57600 
UART_BAUDRATE_115200 
UART_BAUDRATE_576000 
UART_BAUDRATE_921600 
TOTAL_UART_BAUDRATE 

◆ uart_baudrate_type_t

#include <uart/public_inc/hal_uart.h>

Enumerator
UART_BAUDRATE_TYPE_MANUAL 
UART_BAUDRATE_TYPE_AUTO 
TOTAL_UART_BAUDRATE_TYPE 

◆ uart_data_bits_t

#include <uart/public_inc/hal_uart.h>

Enumerator
UART_DATA_BITS_8 
UART_DATA_BITS_9 
TOTAL_UART_DATA_BITS 

◆ uart_mode_t

#include <uart/public_inc/hal_uart.h>

Enumerator
UART_MODE_ASYNCHRONOUS 
UART_MODE_SYNCHRONOUS 
TOTAL_UART_MODE 

◆ uart_parity_t

#include <uart/public_inc/hal_uart.h>

Enumerator
UART_PARITY_EVEN 
UART_PARITY_ODD 
UART_PARITY_NONE 
TOTAL_UART_PARITY 

◆ uart_result_t

#include <uart/public_inc/hal_uart.h>

Enumerator
UART_RESULT_OK 

No error.

UART_RESULT_INVALID 

Operation invalid.

UART_RESULT_UNSUPPORTED 

Operation not supported.

UART_RESULT_OVERRUN_ERROR 

Overrun occurred.

UART_RESULT_UNDERRUN_ERROR 

Underrun occured.

UART_RESULT_FRAMING_ERROR 

Message framing error.

UART_RESULT_PARITY_ERROR 

Message paritiy error.

UART_RESULT_TIMEOUT 

Operation timeout.

UART_RESULT_IDLE 

Bus idle.

UART_RESULT_BUSY 

Bus busy.

UART_RESULT_ERR 

Error occurred.

TOTAL_UART_RESULT 

◆ uart_status_t

#include <uart/public_inc/hal_uart.h>

Enumerator
UART_STATUS_UNKNOWN 

Unknown bus status.

UART_STATUS_OK 

No error.

UART_STATUS_BUSY 

Bus busy.

UART_STATUS_STOP 

Channel stopped.

UART_STATUS_SENDING 

Channel sending.

UART_STATUS_RECEIVING 

Channel receiving.

UART_STATUS_ERR 

Error occurred.

TOTAL_UART_STATUS 

◆ uart_stop_bits_t

#include <uart/public_inc/hal_uart.h>

Enumerator
UART_STOP_BITS_1 
UART_STOP_BITS_2 
TOTAL_UART_STOP_BITS 

Function Documentation

◆ hal_uart_get_status()

uart_bus_status_t hal_uart_get_status ( uart_handle_t * handle)

#include <uart/public_inc/hal_uart.h>

Get UART bus status.

uart_bus_status_t hal_uart_get_status(uart_handle_t *handle)
Get UART bus status.
Definition hal_uart.h:123
Parameters
[in,out]handleUART handler
Returns
UART channel bus status

◆ hal_uart_init()

uart_result_t hal_uart_init ( uart_handle_t * handle,
const uart_channel_attr_t attr )

#include <uart/public_inc/hal_uart.h>

Configure UART channel with specific attributes.

uart_handle_t handle = { .channel = BSP_UART_CHANNEL_1 };
.rx_pin = 10U,
.tx_pin = 11U,
.cts_pin = 12U,
.rts_pin = 13U,
.baudrate = 115200U,
.baudrate_type = UART_BAUDRATE_TYPE_MANUAL,
.stop_bits = UART_STOP_BITS_1,
.parity = UART_PARITY_NONE,
.low_power_enable = false,
.flow_control_enable = true
};
uart_result_t result = hal_uart_init( &handle, attr );
uart_result_t hal_uart_init(uart_handle_t *handle, const uart_channel_attr_t attr)
Configure UART channel with specific attributes.
uart_result_t
Definition hal_uart.h:39
@ UART_BAUDRATE_TYPE_MANUAL
Definition hal_uart.h:91
@ UART_PARITY_NONE
Definition hal_uart.h:117
@ UART_STOP_BITS_1
Definition hal_uart.h:107
@ UART_MODE_ASYNCHRONOUS
Definition hal_uart.h:70
Definition hal_uart.h:130
gpio_pin_t rx_pin
Definition hal_uart.h:131
Definition hal_uart.h:147
uint8_t channel
UART channel.
Definition hal_uart.h:148
Parameters
[in,out]handleUART handler
[in]attrUART channel attribute
Return values
UART_RESULT_OKSuccess configure UART channel
UART_RESULT_INVALIDConfiguration attributes invalid
UART_RESULT_UNSUPPORTEDOperation not supported
UART_RESULT_ERRFailed configure UART channel

◆ hal_uart_mutex_give()

uart_result_t hal_uart_mutex_give ( const uint8_t channel)

#include <uart/public_inc/hal_uart.h>

Release RTOS mutex for specified channel.

uart_result_t result = hal_uart_mutex_give( BSP_UART_CHANNEL_1 );
uart_result_t hal_uart_mutex_give(const uint8_t channel)
Release RTOS mutex for specified channel.
Parameters
[in]channelUART channel's mutex to be released
Return values
UART_RESULT_OKSuccess release mutex
UART_RESULT_INVALIDInvalid channel
UART_RESULT_UNSUPPORTEDOperation not supported
UART_RESULT_ERRFailed release mutex

◆ hal_uart_mutex_take()

uart_result_t hal_uart_mutex_take ( const uint8_t channel,
const uint32_t timeout_ms )

#include <uart/public_inc/hal_uart.h>

Try acquire RTOS mutex for specified channel.

uart_result_t result = hal_uart_mutex_take( BSP_UART_CHANNEL_1, 10U );
uart_result_t hal_uart_mutex_take(const uint8_t channel, const uint32_t timeout_ms)
Try acquire RTOS mutex for specified channel.
Parameters
[in]channelUART channel's mutex to be locked
[in]timeout_msMutex acquiring timeout in milliseconds
Return values
UART_RESULT_OKSuccess acquire mutex
UART_RESULT_INVALIDInvalid channel
UART_RESULT_UNSUPPORTEDOperation not supported
UART_RESULT_ERRFailed acquire mutex

◆ hal_uart_read()

uart_result_t hal_uart_read ( uart_handle_t * handle,
uint8_t * rx_buffer,
const size_t len )

#include <uart/public_inc/hal_uart.h>

Read data from UART channel.

uint8_t rx_buffer[3] = {0U};
uart_result_t result = hal_uart_read( &handle,
rx_buffer,
sizeof( rx_buffer ) );
uart_result_t hal_uart_read(uart_handle_t *handle, uint8_t *rx_buffer, const size_t len)
Read data from UART channel.
Parameters
[in,out]handleUART handler
[in]rx_bufferReceiving buffer
[in]lenBuffer size
Return values
UART_RESULT_OKSuccess read UART data
UART_RESULT_OVERRUN_ERRORUART overrun
UART_RESULT_FRAMING_ERRORUART frame error
UART_RESULT_PARITY_ERRORUART parity error
UART_RESULT_ERRFailed read UART data

◆ hal_uart_stop()

uart_result_t hal_uart_stop ( uart_handle_t * handle)

#include <uart/public_inc/hal_uart.h>

Stop UART operation.

uart_result_t result = hal_uart_stop( &handle );
uart_result_t hal_uart_stop(uart_handle_t *handle)
Stop UART operation.
Parameters
[in,out]handleUART handler
Return values
UART_RESULT_OKSuccess stop UART operation
UART_RESULT_UNSUPPORTEDOperation not supported
UART_RESULT_ERRFailed stop UART operation

◆ hal_uart_write()

uart_result_t hal_uart_write ( uart_handle_t * handle,
const uint8_t * tx_buffer,
const size_t len )

#include <uart/public_inc/hal_uart.h>

Write data to UART channel.

uint8_t tx_buffer[] = { 10U, 20U, 30U };
uart_result_t result = hal_uart_write( &handle,
tx_buffer,
sizeof( tx_buffer ) );
uart_result_t hal_uart_write(uart_handle_t *handle, const uint8_t *tx_buffer, const size_t len)
Write data to UART channel.
Parameters
[in,out]handleUART handler
[in]tx_bufferBuffer to be transmitted
[in]lenBuffer size
Return values
UART_RESULT_OKSuccess write UART data
UART_RESULT_UNDERRUN_ERRORUART underrun
UART_RESULT_FRAMING_ERRORUART frame error
UART_RESULT_PARITY_ERRORUART parity error
UART_RESULT_ERRFailed write UART data