Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Typedefs | Enumerations | Functions
UART

UART (Universal Asynchronous Receiver/Transmitter) API for Soletta. More...

Data Structures

struct  sol_uart_config
 A configuration struct used to set the UART paramenters. More...
 

Typedefs

typedef struct sol_uart sol_uart
 A handle to a UART device. More...
 
typedef struct sol_uart_config sol_uart_config
 A configuration struct used to set the UART paramenters. More...
 

Enumerations

enum  sol_uart_baud_rate {
  SOL_UART_BAUD_RATE_9600 = 0, SOL_UART_BAUD_RATE_19200, SOL_UART_BAUD_RATE_38400, SOL_UART_BAUD_RATE_57600,
  SOL_UART_BAUD_RATE_115200
}
 Baud rate is the number of times the signal can switch states in one second. More...
 
enum  sol_uart_data_bits { SOL_UART_DATA_BITS_8 = 0, SOL_UART_DATA_BITS_7, SOL_UART_DATA_BITS_6, SOL_UART_DATA_BITS_5 }
 Amount of data bits. More...
 
enum  sol_uart_parity { SOL_UART_PARITY_NONE = 0, SOL_UART_PARITY_EVEN, SOL_UART_PARITY_ODD }
 The parity characteristic can be even, odd, or none and it influences last trasmitted bit. More...
 
enum  sol_uart_stop_bits { SOL_UART_STOP_BITS_ONE = 0, SOL_UART_STOP_BITS_TWO }
 Amount of stop bits. More...
 

Functions

enum sol_uart_baud_rate sol_uart_baud_rate_from_str (const char *baud_rate)
 Converts a string UART baudRate to sol_uart_baud_rate. More...
 
const char * sol_uart_baud_rate_to_str (enum sol_uart_baud_rate baud_rate)
 Converts sol_uart_baud_rate to a string name. More...
 
void sol_uart_close (struct sol_uart *uart)
 Close an UART bus. More...
 
enum sol_uart_data_bits sol_uart_data_bits_from_str (const char *data_bits)
 Converts a string UART dataBits to sol_uart_data_bits. More...
 
const char * sol_uart_data_bits_to_str (enum sol_uart_data_bits data_bits)
 Converts sol_uart_data_bits to a string name. More...
 
int sol_uart_feed (struct sol_uart *uart, struct sol_blob *blob)
 Perform an UART asynchronous transmission. More...
 
struct sol_uartsol_uart_open (const char *port_name, const struct sol_uart_config *config)
 Open an UART bus. More...
 
enum sol_uart_parity sol_uart_parity_from_str (const char *parity)
 Converts a string UART parity to sol_uart_parity. More...
 
const char * sol_uart_parity_to_str (enum sol_uart_parity parity)
 Converts sol_uart_parity to a string name. More...
 
enum sol_uart_stop_bits sol_uart_stop_bits_from_str (const char *stop_bits)
 Converts a string UART stopBits to sol_uart_stop_bits. More...
 
const char * sol_uart_stop_bits_to_str (enum sol_uart_stop_bits stop_bits)
 Converts sol_uart_stop_bits to a string name. More...
 

Detailed Description

UART (Universal Asynchronous Receiver/Transmitter) API for Soletta.

Typedef Documentation

A handle to a UART device.

See Also
sol_uart_open()
sol_uart_close()
sol_uart_feed()

A configuration struct used to set the UART paramenters.

See Also
sol_uart_open()
Note
UART follows the Soletta stream design pattern, which can be found here: IO Streams

Enumeration Type Documentation

Baud rate is the number of times the signal can switch states in one second.

Need to be defined to set uart config.

Enumerator
SOL_UART_BAUD_RATE_9600 
SOL_UART_BAUD_RATE_19200 
SOL_UART_BAUD_RATE_38400 
SOL_UART_BAUD_RATE_57600 
SOL_UART_BAUD_RATE_115200 

Amount of data bits.

Enumerator
SOL_UART_DATA_BITS_8 

Use 8 data bits.

SOL_UART_DATA_BITS_7 

Use 7 data bits.

SOL_UART_DATA_BITS_6 

Use 6 data bits.

SOL_UART_DATA_BITS_5 

Use 5 data bits.

The parity characteristic can be even, odd, or none and it influences last trasmitted bit.

Enumerator
SOL_UART_PARITY_NONE 

no parity is used.

SOL_UART_PARITY_EVEN 

the last data bit transmitted will be a logical 1 if the data transmitted had an even amount of 0 bits.

SOL_UART_PARITY_ODD 

the last data bit transmitted will be a logical 1 if the data transmitted had an odd amount of 0 bits.

Amount of stop bits.

Enumerator
SOL_UART_STOP_BITS_ONE 

Use one stop bit.

SOL_UART_STOP_BITS_TWO 

Use two stop bits.

Function Documentation

enum sol_uart_baud_rate sol_uart_baud_rate_from_str ( const char *  baud_rate)

Converts a string UART baudRate to sol_uart_baud_rate.

This function converts a string UART baudRate to enumeration sol_uart_baud_rate.

See Also
sol_uart_baud_rate_to_str().
Parameters
baud_rateValid values are "baud-9600", "baud-19200", "baud-38400", "baud-57600", "baud-115200".
Returns
enumeration sol_uart_baud_rate
const char* sol_uart_baud_rate_to_str ( enum sol_uart_baud_rate  baud_rate)

Converts sol_uart_baud_rate to a string name.

This function converts sol_uart_baud_rate enumeration to a string UART baudRate.

See Also
sol_uart_baud_rate_from_str().
Parameters
baud_ratesol_uart_baud_rate
Returns
String representation of the sol_uart_baud_rate
void sol_uart_close ( struct sol_uart uart)

Close an UART bus.

It's important to note that after this functions is called pending blobs blobs will not be written and the sol_uart_config::on_feed_done() will be called with status set to -ECANCELED. The callback sol_uart_config::on_data() will also be called if the rx buffer has data in it.

Parameters
uartThe UART bus handle
Examples:
/src/samples/common/uart.c.

Referenced by consumer_read_available(), and shutdown().

enum sol_uart_data_bits sol_uart_data_bits_from_str ( const char *  data_bits)

Converts a string UART dataBits to sol_uart_data_bits.

This function converts a string UART dataBits to enumeration sol_uart_data_bits.

See Also
sol_uart_data_bits_to_str().
Parameters
data_bitsValid values are "databits-5", "databits-6", "databits-7", "databits-8".
Returns
enumeration sol_uart_data_bits
const char* sol_uart_data_bits_to_str ( enum sol_uart_data_bits  data_bits)

Converts sol_uart_data_bits to a string name.

This function converts sol_uart_data_bits enumeration to a string UART dataBits.

See Also
sol_uart_data_bits_from_str().
Parameters
data_bitssol_uart_data_bits
Returns
String representation of the sol_uart_data_bits
int sol_uart_feed ( struct sol_uart uart,
struct sol_blob blob 
)

Perform an UART asynchronous transmission.

This function will queue a feed operation on the UART bus. It calls sol_blob_ref(), thus it's safe to call sol_blob_unref() right after this function returns. After a blob is completely written the callback sol_uart_config::on_feed_done() is called, if provided. On errors callback sol_uart_config::on_feed_done() is called with negative status.

Parameters
uartThe UART bus handle
blobThe blob to be written
Returns
0 on success, -ENOSPC if sol_uart_config::feed_size is not zero and there's no more space left or negative errno on error
See Also
sol_uart_config::on_feed_done()
Note
UART follows the Soletta stream design pattern, which can be found here: IO Streams
Examples:
/src/samples/common/uart.c.

Referenced by send_blob().

struct sol_uart* sol_uart_open ( const char *  port_name,
const struct sol_uart_config config 
)

Open an UART bus.

Parameters
port_namethe name of UART port, on Linux it should be ttyUSB0 or ttyACM0 in small OSes it should be a id number.
configThe UART bus configuration
Returns
A new UART bus handle
Note
For now it only supports one user of each port at time, 2 or more users on the same port will cause several concurrency errors.
Examples:
/src/samples/common/uart.c.

Referenced by startup().

enum sol_uart_parity sol_uart_parity_from_str ( const char *  parity)

Converts a string UART parity to sol_uart_parity.

This function converts a string UART parity to enumeration sol_uart_parity.

See Also
sol_uart_parity_to_str().
Parameters
parityValid values are "none", "even", "odd".
Returns
enumeration sol_uart_parity
const char* sol_uart_parity_to_str ( enum sol_uart_parity  parity)

Converts sol_uart_parity to a string name.

This function converts sol_uart_parity enumeration to a string UART parity.

See Also
sol_uart_parity_from_str().
Parameters
paritysol_uart_parity
Returns
String representation of the sol_uart_parity
enum sol_uart_stop_bits sol_uart_stop_bits_from_str ( const char *  stop_bits)

Converts a string UART stopBits to sol_uart_stop_bits.

This function converts a string UART stopBits to enumeration sol_uart_stop_bits.

See Also
sol_uart_stop_bits_to_str().
Parameters
stop_bitsValid values are "stopbits-1", "stopbits-2".
Returns
enumeration sol_uart_stop_bits
const char* sol_uart_stop_bits_to_str ( enum sol_uart_stop_bits  stop_bits)

Converts sol_uart_stop_bits to a string name.

This function converts sol_uart_stop_bits enumeration to a string UART stopBits.

See Also
sol_uart_stop_bits_from_str().
Parameters
stop_bitssol_uart_stop_bits
Returns
String representation of the sol_uart_stop_bits