Appearance
UART
UART Serial API.
API functions for bidirectional Asynchronous serial communications
Sysprops
sysprop | description |
---|---|
gpio_tx | RX GPIO |
gpio_rx | TX GPIO |
gpio_rts | RTS GPIO |
gpio_cts | CTS GPIO |
Functions Overview
Name | |
---|---|
CW_DRIVER_FUNC | uart_config(int hDev, uint32_t baudrate, uint8_t bits, uint8_t stop, uint8_t parity) configure baudrate and hardware protocol for the UART. |
CW_DRIVER_FUNC | uart_write(int hDev, char * buf, size_t buflen, uint32_t timeout_ms) write a character sequence over the UART |
CW_DRIVER_FUNC | uart_read(int hDev, char * buf, size_t buflen, uint32_t timeout_ms) read a character sequence from the UART |
Defines
Name | |
---|---|
UART_IOCTL_SEND_BREAK |
Function Details
function uart_config
cpp
CW_DRIVER_FUNC uart_config(
int hDev,
uint32_t baudrate,
uint8_t bits,
uint8_t stop,
uint8_t parity
)
configure baudrate and hardware protocol for the UART.
Parameters:
- hDev device handle as returned by open(const char*)
- baudrate desired baudrate. the peripheral driver documentation should be consulted for supported baudrates
- bits databits in the UART protocol, ususally 8
- stop number of stop-bits in the UART protocol. since 1.5 stop bits is no longer used in modern devices, it is not supported here.
- parity 0 for no parity, 1 for odd and 2 for even parity
function uart_write
cpp
CW_DRIVER_FUNC uart_write(
int hDev,
char * buf,
size_t buflen,
uint32_t timeout_ms
)
write a character sequence over the UART
Parameters:
- hDev device handle as returned by open(const char*)
- buf pointer to a char buffer. the buffer is not copied in the function, so it needs to be valid until the function returns.
- buflen length of the passed buffer.
- timeout_ms timeout in milliseconds to wait for the buffer to be transmitted
Return: 0 on successful write.
the function acts as blocking during a write to simplify the application architecture.
function uart_read
cpp
CW_DRIVER_FUNC uart_read(
int hDev,
char * buf,
size_t buflen,
uint32_t timeout_ms
)
read a character sequence from the UART
Parameters:
- hDev device handle as returned by open(const char*)
- buf buffer to hold the received characters.
- buflen length of the provided buffer
- timeout_ms timeout in milliseconds to wait for buflen characters to be returned
Return: number of characters read
the function will return after
- the timeout has passed.
- n > 0 characters have been received, followed by a timeout of at least 2 character-times.
- the passed buffer is full.
Macros Documentation
define UART_IOCTL_SEND_BREAK
cpp
#define UART_IOCTL_SEND_BREAK (0x0F01)