Tizen Native API  6.5
Synchronous IO

This API is used to perform synchronous operations.

Overview

A transfer is performed by single function call which returns after transfer was finished. Before transferring, you must select proper endpoint. Then you can perform transfer operations on it:

 int transferred;
 usb_host_config_h cfg;
 usb_host_interface_h iface;
 usb_host_endpoint_h ep;

 usb_host_device_get_config(dev, cfg_index, &cfg);
 usb_host_config_get_interface(cfg, interface_number, &iface);
 usb_host_interface_get_endpoint(iface, ep_number, &ep);

 ret = usb_host_transfer(ep, data, length, &transfered, 0);
 if (ret < 0)
     error();

In this example data buffer contains data received from device. Value of transfered is set to the number of received bytes.

Related Features

This API is related with the following features:

  • http://tizen.org/feature/usb.host

It is recommended to design feature related codes in your application for reliability.

You can check if a device supports the related features for this API by using System Information, thereby controlling the procedure of your application.

To ensure your application is only running on the 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 usb_host_control_transfer (usb_host_device_h dev, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, unsigned char *data, uint16_t w_length, unsigned int timeout, int *transferred)
 Performs USB control transfer.
int usb_host_transfer (usb_host_endpoint_h ep, unsigned char *data, int length, int *transferred, unsigned int timeout)
 Performs transfer on given endpoint.

Function Documentation

int usb_host_control_transfer ( usb_host_device_h  dev,
uint8_t  bm_request_type,
uint8_t  b_request,
uint16_t  w_value,
uint16_t  w_index,
unsigned char *  data,
uint16_t  w_length,
unsigned int  timeout,
int *  transferred 
)

Performs USB control transfer.

For more explanation about the values please refer to USB protocol specification

Since :
3.0
Remarks:
The wValue, wIndex and wLength fields values should be given in host-endian byte order.
Parameters:
[in]devDevice handle
[in]bm_request_typebmRequestType type field for the setup packet
[in]b_requestbRequest field for the setup packet
[in]w_valuewValue field for the setup packet
[in]w_indexwIndex field for the setup packet
[in]dataSuitably-sized data buffer for either input or output (depending on direction bits within bmRequestType)
[in]w_lengthwLength field for the setup packet. The data buffer should be at least this size
[in]timeoutTimeout (in milliseconds) that this function should wait before giving up due to no response being received. For an unlimited
[out]transferredNumber of transferred bytes timeout, 0 value should be used.
Returns:
0 on success, negative error code otherwise
Return values:
USB_HOST_ERROR_NONESuccessful
USB_HOST_ERROR_TIMED_OUTTransfer timed out
USB_HOST_ERROR_BROKEN_PIPEControl request was not supported by the device
USB_HOST_ERROR_NO_SUCH_DEVICEThe device has been disconnected
USB_HOST_ERROR_INVALID_PARAMETERInvalid parameter was passed
USB_HOST_ERROR_NOT_SUPPORTEDNot supported
USB_HOST_ERROR_DEVICE_NOT_OPENEDThe device was not opened
USB_HOST_ERROR_OVERFLOWDevice offered more data
Precondition:
dev must point to device opened by usb_host_device_open() or usb_host_device_open_with_vid_pid()
int usb_host_transfer ( usb_host_endpoint_h  ep,
unsigned char *  data,
int  length,
int *  transferred,
unsigned int  timeout 
)

Performs transfer on given endpoint.

Performs a USB transfer on given endpoint. Direction of transfer is determined by the endpoint.

Since :
3.0
Parameters:
[in]epEndpoint handle
[in]dataSuitably-sized data buffer for either input or output (depending on endpoint)
[in]lengthFor writes, the number of bytes from data to be sent, for reads the maximum number of bytes to receive into the data buffer
[out]transferrednumber of bytes actually transferred
[in]timeoutTimeout (in milliseconds) that this function should wait before giving up due to no response being received (for an unlimited timeout 0 value should be used)
Returns:
0 on success (and populates transferred), negative error code on error
Return values:
USB_HOST_ERROR_NONESuccessful
USB_HOST_ERROR_TIMED_OUTTransfer timed out
USB_HOST_ERROR_BROKEN_PIPEEndpoint halted
USB_HOST_ERROR_OVERFLOWDevice offered more data
USB_HOST_ERROR_NO_SUCH_DEVICEDevice has been disconnected
USB_HOST_ERROR_INVALID_PARAMETERInvalid parameter was passed
USB_HOST_ERROR_NOT_SUPPORTEDNot supported
USB_HOST_ERROR_DEVICE_NOT_OPENEDThe device was not opened
Precondition:
ep must be a valid endpoint received from usb_host_interface_get_endpoint().
ep must be an endpoint of device opened by usb_host_device_open() or usb_host_device_open_with_vid_pid().