Tizen Native API  5.5
UART

The UART API provides functions to control UART peripherals connected to the IoT device.

Required Header

#include <peripheral_io.h>

Overview

This UART API provides functions to control UART peripherals connected to the IoT device.

Realted Features

This API is related with the following feature:

It is recommended to use features in your application for reliability.

You can check if a IoT device supports the related features for this API
by using System Information, and control your application's actions accordingly.

To ensure your application is only running on the IoT device with specific features,
please define the features in your manifest file using the manifest editor in the SDK.

More details on featuring your application can be found from Feature Element.

Functions

int peripheral_uart_open (int port, peripheral_uart_h *uart)
 Opens the UART slave device.
int peripheral_uart_close (peripheral_uart_h uart)
 Closes the UART slave device.
int peripheral_uart_set_baud_rate (peripheral_uart_h uart, peripheral_uart_baud_rate_e baud)
 Sets baud rate of the UART slave device.
int peripheral_uart_set_byte_size (peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size)
 Sets byte size of the UART slave device.
int peripheral_uart_set_parity (peripheral_uart_h uart, peripheral_uart_parity_e parity)
 Sets parity bit of the UART slave device.
int peripheral_uart_set_stop_bits (peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits)
 Sets stop bits of the UART slave device.
int peripheral_uart_set_flow_control (peripheral_uart_h uart, peripheral_uart_software_flow_control_e sw_flow_control, peripheral_uart_hardware_flow_control_e hw_flow_control)
 Sets flow control of the UART slave device.
int peripheral_uart_read (peripheral_uart_h uart, uint8_t *data, uint32_t length)
 Reads data from the UART slave device.
int peripheral_uart_write (peripheral_uart_h uart, uint8_t *data, uint32_t length)
 Writes data to the UART slave device.

Typedefs

typedef struct _peripheral_uart_s * peripheral_uart_h
 The handle to the UART peripherals.

Typedef Documentation

typedef struct _peripheral_uart_s* peripheral_uart_h

The handle to the UART peripherals.

Since :
4.0

Enumeration Type Documentation

Enumeration for baud rate.

Since :
4.0
Enumerator:
PERIPHERAL_UART_BAUD_RATE_0 

The number of signal in one second is 0

PERIPHERAL_UART_BAUD_RATE_50 

The number of signal in one second is 50

PERIPHERAL_UART_BAUD_RATE_75 

The number of signal in one second is 75

PERIPHERAL_UART_BAUD_RATE_110 

The number of signal in one second is 110

PERIPHERAL_UART_BAUD_RATE_134 

The number of signal in one second is 134

PERIPHERAL_UART_BAUD_RATE_150 

The number of signal in one second is 150

PERIPHERAL_UART_BAUD_RATE_200 

The number of signal in one second is 200

PERIPHERAL_UART_BAUD_RATE_300 

The number of signal in one second is 300

PERIPHERAL_UART_BAUD_RATE_600 

The number of signal in one second is 600

PERIPHERAL_UART_BAUD_RATE_1200 

The number of signal in one second is 1200

PERIPHERAL_UART_BAUD_RATE_1800 

The number of signal in one second is 1800

PERIPHERAL_UART_BAUD_RATE_2400 

The number of signal in one second is 2400

PERIPHERAL_UART_BAUD_RATE_4800 

The number of signal in one second is 4800

PERIPHERAL_UART_BAUD_RATE_9600 

The number of signal in one second is 9600

PERIPHERAL_UART_BAUD_RATE_19200 

The number of signal in one second is 19200

PERIPHERAL_UART_BAUD_RATE_38400 

The number of signal in one second is 38400

PERIPHERAL_UART_BAUD_RATE_57600 

The number of signal in one second is 57600

PERIPHERAL_UART_BAUD_RATE_115200 

The number of signal in one second is 115200

PERIPHERAL_UART_BAUD_RATE_230400 

The number of signal in one second is 230400

Enumeration for byte size.

Since :
4.0
Enumerator:
PERIPHERAL_UART_BYTE_SIZE_5BIT 

5 data bits

PERIPHERAL_UART_BYTE_SIZE_6BIT 

6 data bits

PERIPHERAL_UART_BYTE_SIZE_7BIT 

7 data bits

PERIPHERAL_UART_BYTE_SIZE_8BIT 

8 data bits

Enumeration for hardware flow control.

Since :
4.0
Enumerator:
PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE 

No hardware flow control

PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS 

Automatic RTS/CTS hardware flow control

Enumeration for parity bit.

Since :
4.0
Enumerator:
PERIPHERAL_UART_PARITY_NONE 

No parity is used

PERIPHERAL_UART_PARITY_EVEN 

Even parity is used

PERIPHERAL_UART_PARITY_ODD 

ODD parity is used

Enumeration for software flow control.

Since :
4.0
Enumerator:
PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE 

No software flow control

PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF 

XON/XOFF software flow control

Enumeration for stop bits.

Since :
4.0
Enumerator:
PERIPHERAL_UART_STOP_BITS_1BIT 

One stop bit

PERIPHERAL_UART_STOP_BITS_2BIT 

Two stop bits


Function Documentation

Closes the UART slave device.

Warning:
This is not for use by third-party applications.
Since :
4.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]uartThe UART handle
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
Precondition:
peripheral_uart_open()
int peripheral_uart_open ( int  port,
peripheral_uart_h uart 
)

Opens the UART slave device.

Warning:
This is not for use by third-party applications.
Since :
4.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Remarks:
uart should be released with peripheral_uart_close()
Parameters:
[in]portThe UART port number that the slave device is connected
[out]uartThe UART handle is created on success
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_NO_DEVICEDevice does not exist or is removed
PERIPHERAL_ERROR_OUT_OF_MEMORYMemory allocation failed
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_RESOURCE_BUSYDevice is in use
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
Postcondition:
peripheral_uart_close()
int peripheral_uart_read ( peripheral_uart_h  uart,
uint8_t *  data,
uint32_t  length 
)

Reads data from the UART slave device.

Warning:
This is not for use by third-party applications.
Since :
4.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]uartThe UART handle
[out]dataThe buffer to read
[out]lengthThe size of buffer (in bytes)
Returns:
the number of bytes read on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_TRY_AGAINTry again
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_uart_write()

Sets baud rate of the UART slave device.

Warning:
This is not for use by third-party applications.
Since :
4.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]uartThe UART handle
[in]baudBaud rate of the UART slave device
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_NO_DEVICEDevice does not exist or is removed
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_uart_baud_rate_e

Sets byte size of the UART slave device.

Warning:
This is not for use by third-party applications.
Since :
4.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]uartThe UART handle
[in]byte_sizeByte size of the UART slave device
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_NO_DEVICEDevice does not exist or is removed
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_uart_byte_size_e

Sets flow control of the UART slave device.

Warning:
This is not for use by third-party applications.
Since :
4.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]uartThe UART handle
[in]sw_flow_controlSoftware flow control (Turns a transmitter on or off)
[in]hw_flow_controlHardware flow control (Turns "Request to Send/Clear to Send" on or off)
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_NO_DEVICEDevice does not exist or is removed
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_uart_software_flow_control_e
peripheral_uart_hardware_flow_control_e

Sets parity bit of the UART slave device.

Warning:
This is not for use by third-party applications.
Since :
4.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]uartThe UART handle
[in]parityParity bit of the UART slave device
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_NO_DEVICEDevice does not exist or is removed
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_uart_parity_e

Sets stop bits of the UART slave device.

Warning:
This is not for use by third-party applications.
Since :
4.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]uartThe UART handle
[in]stop_bitsStop bits of the UART slave device
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_NO_DEVICEDevice does not exist or is removed
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_uart_stop_bits_e
int peripheral_uart_write ( peripheral_uart_h  uart,
uint8_t *  data,
uint32_t  length 
)

Writes data to the UART slave device.

Warning:
This is not for use by third-party applications.
Since :
4.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]uartThe UART handle
[in]dataThe buffer to write
[in]lengthThe size of buffer (in bytes)
Returns:
the number of bytes write on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_TRY_AGAINTry again
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_uart_read()