Tizen Native API  9.0

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

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 and returns a handle representing it.
int peripheral_uart_open_flags (int port, peripheral_open_flags_e flags, peripheral_uart_h *uart)
 Opens the UART slave device using specified open flags, and returns a handle representing it.
int peripheral_uart_close (peripheral_uart_h uart)
 Closes the UART slave device and frees resources associated with the handle.
int peripheral_uart_set_baud_rate (peripheral_uart_h uart, peripheral_uart_baud_rate_e baud)
 Sets the baud rate for the given UART slave device.
int peripheral_uart_set_byte_size (peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size)
 Sets data byte size for the given UART slave device.
int peripheral_uart_set_parity (peripheral_uart_h uart, peripheral_uart_parity_e parity)
 Sets the parity bit for the given UART slave device.
int peripheral_uart_set_stop_bits (peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits)
 Sets the number of stop bits for 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 hardware and software 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 into a local buffer.
int peripheral_uart_flush (peripheral_uart_h uart)
 Discards data queued for writing to UART slave device, but not yet transmitted.
int peripheral_uart_drain (peripheral_uart_h uart)
 Waits for all data queued for UART to be transmitted.
int peripheral_uart_write (peripheral_uart_h uart, uint8_t *data, uint32_t length)
 Writes data from a buffer to the UART slave device.

Typedefs

typedef struct _peripheral_uart_s * peripheral_uart_h
 An opaque handle representing a UART peripherals device.

Typedef Documentation

typedef struct _peripheral_uart_s* peripheral_uart_h

An opaque handle representing a UART peripherals device.

A handle to a single UART slave device, for use with most UART peripherals interfaces

Since :
4.0

Enumeration Type Documentation

Enumeration for signal baud rate for UART slave devices.

Controls the baud rate, i.e. signals per second on a UART device

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 data byte size for UART slave devices.

Controls how many bits per byte are there for data, on UART slave devices.

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 for UART slave devices.

Controls details of the hardware flow control on UART devices

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 for UART slave devices.

Controls whether parity is even, odd, or none for UART devices

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 for UART slave devices.

Controls details of the software flow control on UART devices

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 the number of stop bits for UART slave devices.

Controls whether there is one or two stop bits for UART devices

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 and frees resources associated with the handle.

Warning:
This is not for use by third-party applications.

This function should be called at the end of the object's lifetime to avoid a memleak.

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_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
Precondition:
peripheral_uart_open()

Waits for all data queued for UART to be transmitted.

Warning:
This is not for use by third-party applications.

Waits for all data queued for UART to be transmitted.

Since :
8.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]uartThe UART handle
Returns:
PERIPHERAL_ERROR_NONE on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_TRY_AGAINTry again
PERIPHERAL_ERROR_UNKNOWNUnknown internal error

Discards data queued for writing to UART slave device, but not yet transmitted.

Warning:
This is not for use by third-party applications.

Discards data queued for writing to UART slave device, but not yet transmitted.

Since :
8.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]uartThe UART handle
Returns:
PERIPHERAL_ERROR_NONE on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_TRY_AGAINTry again
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
int peripheral_uart_open ( int  port,
peripheral_uart_h uart 
)

Opens the UART slave device and returns a handle representing it.

Warning:
This is not for use by third-party applications.

Starts the lifetime of the handle and allocates its needed resources.

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_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
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_RESOURCE_BUSYDevice is in use
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
Postcondition:
peripheral_uart_close()
int peripheral_uart_open_flags ( int  port,
peripheral_open_flags_e  flags,
peripheral_uart_h uart 
)

Opens the UART slave device using specified open flags, and returns a handle representing it.

Warning:
This is not for use by third-party applications.

Starts the lifetime of the handle and allocates its needed resources.

Since :
6.5
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
[in]flagsThe flags to open call
[out]uartThe UART handle is created on success
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
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_RESOURCE_BUSYDevice is in use
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 into a local buffer.

Warning:
This is not for use by third-party applications.

Reads data from the UART slave device into a local buffer.

Since :
4.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]uartThe UART handle
[out]dataThe buffer to read
[in]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_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_TRY_AGAINTry again
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_uart_write()

Sets the baud rate for the given UART slave device.

Warning:
This is not for use by third-party applications.

Sets the baud rate for the given UART slave device.

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_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_NO_DEVICEDevice does not exist or is removed
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_uart_baud_rate_e

Sets data byte size for the given UART slave device.

Warning:
This is not for use by third-party applications.

Sets data byte size for the given UART slave device.

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_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_NO_DEVICEDevice does not exist or is removed
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_uart_byte_size_e

Sets hardware and software flow control of the UART slave device.

Warning:
This is not for use by third-party applications.

Sets hardware and software flow control of the UART slave device.

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_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_NO_DEVICEDevice does not exist or is removed
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_uart_software_flow_control_e
peripheral_uart_hardware_flow_control_e

Sets the parity bit for the given UART slave device.

Warning:
This is not for use by third-party applications.

Sets the parity bit for the given UART slave device.

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_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_NO_DEVICEDevice does not exist or is removed
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_uart_parity_e

Sets the number of stop bits for the UART slave device.

Warning:
This is not for use by third-party applications.

Sets the number of stop bits for the UART slave device.

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_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_NO_DEVICEDevice does not exist or is removed
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 from a buffer to the UART slave device.

Warning:
This is not for use by third-party applications.

Writes data from a buffer to the UART slave device.

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_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_TRY_AGAINTry again
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_uart_read()