View on Github

UART

UART driver support for hardware abstraction layer.

Minimalist code

char buff[20];
rt_dev_t uart4;
ssize_t byteRead;

// init
uart4 = uart(4);
uart_open(uart4);
uart_setBaudSpeed(uart4, 115200);
uart_setBitConfig(uart4, 8, UART_BIT_PARITY_NONE, 1);
uart_enable(uart4);

// send and receive data
uart_write(uart4, "test\n", 5);

byteRead = uart_read(uart4, buff, 20); // reads up to 20 chars from uart 4 to buff and returns read byte count.

API

Device assignation

uart_getFreeDevice

rt_dev_t uart_getFreeDevice();

Gives a free uart device number and opens it

uart_open

int uart_open(rt_dev_t device);

Opens an uart

uart_close

int uart_close(rt_dev_t device);

Closes an uart

Device enable/disable

uart_enable

int uart_enable(rt_dev_t device);

Enables the specified uart device

uart_disable

int uart_disable(rt_dev_t device);

Disables the specified uart device

Device settings

uart_setBaudSpeed

int uart_setBaudSpeed(rt_dev_t device, uint32_t baudSpeed);

Sets the speed of receive and transmit

uart_baudSpeed

uint32_t uart_baudSpeed(rt_dev_t device);

Gets the true baud speed

uart_effectiveBaudSpeed

uint32_t uart_effectiveBaudSpeed(rt_dev_t device);

Gets the effective baud speed

uart_setBitConfig

int uart_setBitConfig(rt_dev_t device, uint8_t bitLength, uint8_t bitParity, uint8_t bitStop);

Sets the configuration bit (bit length, stop bits, parity)

uart_bitLength

uint8_t uart_bitLength(rt_dev_t device);

Gets the bit length of the device

uart_bitParity

uint8_t uart_bitParity(rt_dev_t device);

Gets the uart parity mode

uart_bitStop

uint8_t uart_bitStop(rt_dev_t device);

Gets number of stop bit

Device read / write

uart_write

ssize_t uart_write(rt_dev_t device, const char *data, size_t size);

Writes data to uart device

uart_read

ssize_t uart_read(rt_dev_t device, char *data, size_t size_max);

Reads size_max data received by uart device

uart_datardy

size_t uart_datardy(rt_dev_t device);

Gets number of data that could be read (in sw buffer)

Development status

Device assignation, configuration, send and read data fully functional

TODO

Supported architectures

Header file : uart.h