mraa  2.0.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
Functions | Typedefs
uart.h File Reference

API Description

UART is the Universal asynchronous receiver/transmitter interface to libmraa. It allows the exposure of UART pins on supported boards. With functionality to expand at a later date.

/* initialize UART */
uart = mraa_uart_init(UART);
if (uart == NULL) {
fprintf(stderr, "Failed to initialize UART\n");
goto err_exit;
}
while (flag) {
/* send data through UART */
mraa_uart_write(uart, buffer, sizeof(buffer));
sleep(1);
}
/* stop UART */

Go to the source code of this file.

Functions

mraa_uart_context mraa_uart_init (int uart)
 
mraa_uart_context mraa_uart_init_raw (const char *path)
 
mraa_result_t mraa_uart_flush (mraa_uart_context dev)
 
mraa_result_t mraa_uart_sendbreak (mraa_uart_context dev, int duration)
 
mraa_result_t mraa_uart_set_baudrate (mraa_uart_context dev, unsigned int baud)
 
mraa_result_t mraa_uart_set_mode (mraa_uart_context dev, int bytesize, mraa_uart_parity_t parity, int stopbits)
 
mraa_result_t mraa_uart_set_flowcontrol (mraa_uart_context dev, mraa_boolean_t xonxoff, mraa_boolean_t rtscts)
 
mraa_result_t mraa_uart_set_timeout (mraa_uart_context dev, int read, int write, int interchar)
 
mraa_result_t mraa_uart_set_non_blocking (mraa_uart_context dev, mraa_boolean_t nonblock)
 
const char * mraa_uart_get_dev_path (mraa_uart_context dev)
 
mraa_result_t mraa_uart_settings (int index, const char **devpath, const char **name, int *baudrate, int *databits, int *stopbits, mraa_uart_parity_t *parity, unsigned int *rtscts, unsigned int *xonxoff)
 
mraa_result_t mraa_uart_stop (mraa_uart_context dev)
 
int mraa_uart_read (mraa_uart_context dev, char *buf, size_t length)
 
int mraa_uart_write (mraa_uart_context dev, const char *buf, size_t length)
 
mraa_boolean_t mraa_uart_data_available (mraa_uart_context dev, unsigned int millis)
 

Typedefs

typedef struct _uart * mraa_uart_context
 

Function Documentation

mraa_uart_context mraa_uart_init ( int  uart)

Initialise uart_context, uses board mapping

Parameters
uartthe index of the uart set to use
Returns
uart context or NULL

Here is the caller graph for this function:

mraa_uart_context mraa_uart_init_raw ( const char *  path)

Initialise a raw uart_context. No board setup.

Parameters
pathfor example "/dev/ttyS0"
Returns
uart context or NULL

Here is the caller graph for this function:

mraa_result_t mraa_uart_flush ( mraa_uart_context  dev)

Flush the outbound data. Blocks until complete.

Parameters
devThe UART context
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_uart_sendbreak ( mraa_uart_context  dev,
int  duration 
)

Send a break to the device. Blocks until complete.

Parameters
devThe UART context
durationWhen 0, send a break lasting at least 250 milliseconds, and not more than 500 milliseconds. When non zero, the break duration is implementation specific.
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_uart_set_baudrate ( mraa_uart_context  dev,
unsigned int  baud 
)

Set the baudrate. Takes an int and will attempt to decide what baudrate is to be used on the UART hardware.

Parameters
devThe UART context
baudunsigned int of baudrate i.e. 9600
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_uart_set_mode ( mraa_uart_context  dev,
int  bytesize,
mraa_uart_parity_t  parity,
int  stopbits 
)

Set the transfer mode For example setting the mode to 8N1 would be "mraa_uart_set_mode(dev, 8,MRAA_UART_PARITY_NONE , 1)"

Parameters
devThe UART context
bytesizedata bits
parityParity bit setting
stopbitsstop bits
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_uart_set_flowcontrol ( mraa_uart_context  dev,
mraa_boolean_t  xonxoff,
mraa_boolean_t  rtscts 
)

Set the flowcontrol

Parameters
devThe UART context
xonxoffXON/XOFF Software flow control.
rtsctsRTS/CTS out of band hardware flow control
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_uart_set_timeout ( mraa_uart_context  dev,
int  read,
int  write,
int  interchar 
)

Set the timeout for read and write operations <= 0 will disable that timeout

Parameters
devThe UART context
readread timeout
writewrite timeout
intercharinbetween char timeout
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_uart_set_non_blocking ( mraa_uart_context  dev,
mraa_boolean_t  nonblock 
)

Set the blocking state for write operations

Parameters
devThe UART context
nonblocknew nonblocking state
Returns
Result of operation

Here is the caller graph for this function:

const char* mraa_uart_get_dev_path ( mraa_uart_context  dev)

Get Char pointer with tty device path within Linux For example. Could point to "/dev/ttyS0"

Parameters
devuart context
Returns
char pointer of device path

Here is the caller graph for this function:

mraa_result_t mraa_uart_settings ( int  index,
const char **  devpath,
const char **  name,
int *  baudrate,
int *  databits,
int *  stopbits,
mraa_uart_parity_t parity,
unsigned int *  rtscts,
unsigned int *  xonxoff 
)

Get the current settings of an UART. This is an unintrusive function. Meaning it intends not to change anything, only read the values without disturbing.

All but the first index parameter are "outparameters". That means they can contain values on return. If any parameter is not interesting, a null pointer can be sent instead as a placeholder. The devpath parameter can be either in or out parameter. In case of a negative index, the UART is identified using *devpath instead. This functionality is intended for and needed by for instance USB serial adapters.

In case of a non-success return value, the outparameters are undefined.

Parameters
indexuart index to look up, if negative, *devpath will be used instead
devpathpoints to the device path of the UART, eg: /dev/ttyS0
nameoutparameter that on return will point to the name of the UART
baudratepointer to an integer to contain the current baudrate (0–4M)
databitspointer to an integer to contain the number databits (5–8)
stopbitspointer to an integer to contain the number stopbits (1–2)
paritywill contain the current parity mode
rtsctswill point to non-zero if CTS/RTS flow control is enabled, zero otherwise
xonxoffwill point to a non-zero value if xon/xoff flow control is enabled
Returns
result
mraa_result_t mraa_uart_stop ( mraa_uart_context  dev)

Destroy a mraa_uart_context

Parameters
devuart context
Returns
mraa_result_t

Here is the caller graph for this function:

int mraa_uart_read ( mraa_uart_context  dev,
char *  buf,
size_t  length 
)

Read bytes from the device into a buffer

Parameters
devuart context
bufbuffer pointer
lengthmaximum size of buffer
Returns
the number of bytes read, or -1 if an error occurred

Here is the caller graph for this function:

int mraa_uart_write ( mraa_uart_context  dev,
const char *  buf,
size_t  length 
)

Write bytes in buffer to a device

Parameters
devuart context
bufbuffer pointer
lengthmaximum size of buffer
Returns
the number of bytes written, or -1 if an error occurred

Here is the caller graph for this function:

mraa_boolean_t mraa_uart_data_available ( mraa_uart_context  dev,
unsigned int  millis 
)

Check to see if data is available on the device for reading

Parameters
devuart context
millisnumber of milliseconds to wait, or 0 to return immediately
Returns
1 if there is data available to read, 0 otherwise

Here is the caller graph for this function:

Typedef Documentation

typedef struct _uart* mraa_uart_context

Mraa Uart Context

Include dependency graph for uart.h: