| hiTraceMeter.startTrace(name: string, taskId: number) | void | Marks the start of a trace task. If multiple trace tasks with the same name need to be performed at the same time or a trace task needs to be performed multiple times concurrently, different task IDs must be specified in **startTrace**. If the trace tasks with the same name are not performed at the same time, the same task ID can be used.|
| hiTraceMeter.finishTrace(name: string, taskId: number) | void | Marks the end of a trace task. The values of **name** and **taskId** must be the same as those of **hiTraceMeter.startTrace**.|
| hiTraceMeter.traceByValue(name: string, value: number) | void | Marks the value changes of a numeric variable in a trace task.|
| hiTraceMeter.startTrace(name: string, taskId: number) | void | Marks the start of a trace task. If multiple trace tasks with the same name need to be performed at the same time or a trace task needs to be performed multiple times concurrently, different task IDs must be specified in **startTrace**. If the trace tasks with the same name are not performed at the same time, the same task ID can be used.|
| hiTraceMeter.finishTrace(name: string, taskId: number) | void | Marks the end of a trace task. The values of **name** and **taskId** must be the same as those of **hiTraceMeter.startTrace**. |
| hiTraceMeter.traceByValue(name: string, value: number) | void | Marks the value changes of a numeric variable in a trace task. |
hiTraceMeter provides APIs for system performance tracing. You can call the APIs provided by the hiTraceMeter module in your own service logic to effectively track service processes and check the system performance.
> **NOTE**
> - This development guide is applicable only when you use Native APIs for application development. For details about APIs, see [API Reference](../reference/native-apis/_hitrace.md).
> - For details about how to use ArkTS APIs for application development, see [Development Guidelines](hitracemeter-guidelines.md) and [API Reference](../reference/apis/js-apis-hitracemeter.md).
## Available APIs
| API| Description|
| -------- | -------- |
| void OH_HiTrace_StartTrace(const char* name) | Starts a synchronous time slice trace.|
| void OH_HiTrace_FinishTrace() | Ends a synchronous time slice trace.|
| void OH_HiTrace_StartAsyncTrace(const char* name, int32_t taskId) | Starts an asynchronous time slice trace.|
| void OH_HiTrace_FinishAsyncTrace(const char* name, int32_t taskId) | Ends an asynchronous time slice trace.|
| taskId | number | No | ID used to indicate the association of APIs in a trace. If multiple traces with the same name need to be performed at the same time or a trace needs to be performed multiple times concurrently, different task IDs must be specified in **startTrace**.|
| count | number | No | Value of the variable. |
## Development Example
1. Add the link of **libhitrace_ndk.z.so** to **CMakeLists.txt**.
```
target_link_libraries(entry PUBLIC libhitrace_ndk.z.so)
```
2. Reference the **hitrace** header file in the source file.
```c++
#include "hitrace/trace.h"
```
3. Open the hdc shell and run the **hitrace --trace_begin app** command to enable the trace function.
```shell
capturing trace...
```
4. Perform a performance trace. The following uses asynchronous trace as an example.
```c++
OH_HiTrace_StartAsyncTrace("hitraceTest",123);
OH_HiTrace_FinishAsyncTrace("hitraceTest",123);
```
5. Run the **hitrace --trace_dump | grep hitraceTest** command to view the trace result.
The **mindSporeLite** module provides APIs for the MindSpore Lite inference engine to implment model inference.
MindSpore Lite is an AI engine that implements AI model inference for different hardware devices. It has been used in a wide range of fields, such as image classification, target recognition, facial recognition, and character recognition.
The **mindSporeLite** module provides APIs for the MindSpore Lite inference engine to implment model inference.
Unregisters the observer for account information change events of the SIM card. This API uses an asynchronous callback to return the result.
>**NOTE**
>
>You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks.
| isImmediate<sup>10+</sup> | boolean | No | Whether to hibernate a device immediately. If this parameter is not specified, the default value **false** is used. The system automatically determines when to enter the hibernation state.<br>**NOTE**: This parameter is supported since API version 10.|
**Error codes**
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
| businessId | string | Yes | Unique service ID registered on the multimodal side. It corresponds to **businessId** in the **ability_launch_config.json** file.|
| businessKey| string | Yes | Unique service ID registered on the multimodal side. It corresponds to **businessId** in the **ability_launch_config.json** file.|
| delay | number | Yes | Delay for starting an ability using the shortcut key, in ms.|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. |
| businessId | string | Yes | Unique service ID registered on the multimodal side. It corresponds to **businessId** in the **ability_launch_config.json** file.|
| businessKey| string | Yes | Unique service ID registered on the multimodal side. It corresponds to **businessId** in the **ability_launch_config.json** file.|
| delay | number | Yes | Delay for starting an ability using the shortcut key, in ms.|
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** indicates that the SIM card in the specified slot is installed, and the value **false** indicates the opposite. |
| callback | AsyncCallback<number> | Yes | Callback used to return the result.<br>The return value is bound to the SIM card and increases from 1.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| callback | AsyncCallback<number> | Yes | Callback used to return the result.<br>The return value is bound to the SIM card and increases from 1.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
The cellular data module provides basic mobile data management functions. You can obtain and set the default slot of the SIM card used for mobile data, and obtain the uplink and downlink connection status of cellular data services and connection status of the packet switched (PS) domain. Besides, you can check whether cellular data services and data roaming are enabled.
The **data** module provides basic mobile data management functions. You can obtain and set the default slot of the SIM card used for mobile data, and obtain the uplink and downlink connection status of cellular data services and connection status of the packet switched (PS) domain. Besides, you can check whether cellular data services and data roaming are enabled.
>**NOTE**
>
...
...
@@ -24,7 +24,7 @@ Obtains the default slot of the SIM card used for mobile data. This API uses an
| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.<br>**true**: Roaming is enabled for the cellular data service.<br>**false**: Roaming is disabled for the cellular data service.|
**Error codes**
...
...
@@ -394,7 +394,7 @@ Checks whether roaming is enabled for the cellular data service. This API uses a
hiTraceMeter provides APIs for system performance tracing.
You can call the APIs provided by hiTraceMeter in your own service logic to effectively track service processes and check the system performance.
\@syscap SystemCapability.HiviewDFX.HiTrace
**Since**
10
## Summary
### File
| Name| Description|
| -------- | -------- |
| [trace.h](trace_8h.md) | Defines APIs of the HiTraceMeter module for performance trace.<br>**File to include**: <hitrace/trace.h><br>**Library**: libhitrace_ndk.z.so|
### Functions
| Name| Description|
| -------- | -------- |
| [OH_HiTrace_StartTrace](#oh_hitrace_starttrace)(const char \*name) | Marks the start of a synchronous trace.|
| [OH_HiTrace_FinishTrace](#oh_hitrace_finishtrace)(void) | Marks the end of a synchronous trace.|
| [OH_HiTrace_StartAsyncTrace](#oh_hitrace_startasynctrace)(const char \*name, int32_t taskId) | Marks the start of an asynchronous trace.|
| [OH_HiTrace_FinishAsyncTrace](#oh_hitrace_finishasynctrace)(const char \*name, int32_t taskId) | Marks the end of an asynchronous trace.|
| [OH_HiTrace_CountTrace](#oh_hitrace_counttrace)(const char \*name, int64_t count) | Traces the value change of an integer variable based on its name.|
This API is called in the callback function after an asynchronous trace is complete. It is used with **OH_HiTrace_StartAsyncTrace** in pairs. Its name and task ID must be the same as those of **OH_HiTrace_StartAsyncTrace**.
**Parameters**
| Name| Description|
| -------- | -------- |
| name | Name of the asynchronous trace.|
| taskId | ID of the asynchronous trace. The start and end of an asynchronous trace task do not occur in sequence. Therefore, the start and end of an asynchronous trace need to be matched based on the task name and the unique task ID together.|
**Since**
10
### OH_HiTrace_FinishTrace()
```
void OH_HiTrace_FinishTrace (void )
```
**Description**
Marks the end of a synchronous trace.
This API must be used with **OH_HiTrace_StartTrace** in pairs. During trace data parsing, the system matches it with the **OH_HiTrace_StartTrace** API recently invoked in the service process.
This API is called to implement performance trace in asynchronous manner. The start and end of an asynchronous trace task do not occur in sequence. Therefore, a unique **taskId** is required to ensure proper data parsing. It is passed as an input parameter for the asynchronous API. This API is used with **OH_HiTrace_FinishAsyncTrace** in pairs. The two APIs that have the same name and task ID together form an asynchronous trace. If multiple trace tasks with the same name need to be performed at the same time or a trace task needs to be performed multiple times concurrently, different task IDs must be specified in **OH_HiTrace_StartTrace**. If the trace tasks with the same name are not performed at the same time, the same taskId can be used.
**Parameters**
| Name| Description|
| -------- | -------- |
| name | Name of an asynchronous trace.|
| taskId | ID of the asynchronous trace. The start and end of an asynchronous trace task do not occur in sequence. Therefore, the start and end of an asynchronous trace need to be matched based on the task name and the unique task ID together.|
**Since**
10
### OH_HiTrace_StartTrace()
```
void OH_HiTrace_StartTrace (const char * name)
```
**Description**
Marks the start of a synchronous trace.
This API is used with **OH_HiTrace_FinishTrace** in pairs. The two APIs can be used in nested mode. The stack data structure is used for matching during trace data parsing.
| [wTotalLength](#wtotallength) | Total length of the configuration descriptor, including the configuration, interface, endpoint, and class- or vendor-specific descriptors.|
| [bNumInterfaces](#bnuminterfaces) | Number of interfaces supported by the configuration.|
| [bConfigurationValue](#bconfigurationvalue) | Configuration index, which is used to select the configuration.|
| [iConfiguration](#iconfiguration) | Index of the string descriptor that describes the configuration.|
| [bmAttributes](#bmattributes) | Configuration attributes, including the power mode and remote wakeup.|
| [bMaxPower](#bmaxpower) | Maximum power consumption of the bus-powered USB device, in 2 mA.|
## Member Variable Description
### bConfigurationValue
```
uint8_t UsbConfigDescriptor::bConfigurationValue
```
**Description**
Configuration index, which is used to select the configuration.
### bDescriptorType
```
uint8_t UsbConfigDescriptor::bDescriptorType
```
**Description**
Descriptor type.
### bLength
```
uint8_t UsbConfigDescriptor::bLength
```
**Description**
Size of the descriptor, in bytes.
### bmAttributes
```
uint8_t UsbConfigDescriptor::bmAttributes
```
**Description**
Configuration attributes, including the power mode and remote wakeup.
### bMaxPower
```
uint8_t UsbConfigDescriptor::bMaxPower
```
**Description**
Maximum power consumption of the bus-powered USB device, in 2 mA.
### bNumInterfaces
```
uint8_t UsbConfigDescriptor::bNumInterfaces
```
**Description**
Number of interfaces supported by the configuration.
### iConfiguration
```
uint8_t UsbConfigDescriptor::iConfiguration
```
**Description**
Index of the string descriptor that describes the configuration.
### wTotalLength
```
uint16_t UsbConfigDescriptor::wTotalLength
```
**Description**
Total length of the configuration descriptor, including the configuration, interface, endpoint, and class- or vendor-specific descriptors.
| [wValue](#wvalue) | Value corresponding to **wValue** in the USB protocol. Its meaning varies according to the request.|
| [wIndex](#windex) | Index corresponding to **wIndex** in the USB protocol. It is usually used to transfer the index or offset. Its meaning varies according to the request. |
| [wLength](#wlength) | Data length corresponding to **wLength** in the USB protocol. If data is transferred, this field indicates the number of transferred bytes.|
## Member Variable Description
### wIndex
```
uint16_t UsbControlRequestSetup::wIndex
```
**Description**
Index corresponding to **wIndex** in the USB protocol. It is usually used to transfer the index or offset. Its meaning varies according to the request.
### wLength
```
uint16_t UsbControlRequestSetup::wLength
```
**Description**
Data length corresponding to **wLength** in the USB protocol. If data is transferred, this field indicates the number of transferred bytes.
### bRequest
```
uint8_t UsbControlRequestSetup::bRequest
```
**Description**
Specific request.
### bmRequestType
```
uint8_t UsbControlRequestSetup::bmRequestType
```
**Description**
Request type.
### wValue
```
uint16_t UsbControlRequestSetup::wValue
```
**Description**
Value corresponding to **wValue** in the USB protocol. Its meaning varies according to the request.
Provides USB DDK APIs to open and close USB interfaces, perform non-isochronous and isochronous data transfer over USB pipes, and implement control transfer and interrupt transfer, etc.
\@syscap SystemCapability.Driver.USB.Extension
**Since**
10
## Summary
### File
| Name| Description|
| -------- | -------- |
| [usb_ddk_api.h](usb__ddk__api_8h.md) | Declares the USB DDK APIs used by the USB host to access USB devices.<br>File to include: <usb/usb_ddk_api.h>|
| [usb_ddk_types.h](usb__ddk__types_8h.md) | Provides the enumerated variables, structures, and macros used in USB DDK APIs.<br>File to include: <usb/usb_ddk_types.h> |
### Structs
| Name| Description|
| -------- | -------- |
| [UsbControlRequestSetup](_usb_control_request_setup.md) | Setup data for control transfer. It corresponds to **Setup Data** in the USB protocol.|
| [UsbDeviceDescriptor](_usb_device_descriptor.md) | Standard device descriptor, corresponding to **Standard Device Descriptor** in the USB protocol.|
| [UsbConfigDescriptor](_usb_config_descriptor.md) | Standard configuration descriptor, corresponding to **Standard Configuration Descriptor** in the USB protocol.|
| [UsbInterfaceDescriptor](_usb_interface_descriptor.md) | Standard interface descriptor, corresponding to **Standard Interface Descriptor** in the USB protocol.|
| [UsbEndpointDescriptor](_usb_endpoint_descriptor.md) | Standard endpoint descriptor, corresponding to **Standard Endpoint Descriptor** in the USB protocol.|
| [UsbDeviceMemMap](_usb_device_mem_map.md) | Device memory map created by calling [OH_Usb_CreateDeviceMemMap()](#oh_usb_createdevicememmap). A buffer using the device memory map can provide better performance.|
| [UsbDeviceMemMap](#usbdevicememmap) | Device memory map created by calling [OH_Usb_CreateDeviceMemMap()](#oh_usb_createdevicememmap). A buffer using the device memory map can provide better performance.|
| [OH_Usb_Init](#oh_usb_init)(void) | Initializes the DDK.|
| [OH_Usb_Release](#oh_usb_release)(void) | Releases the DDK.|
| [OH_Usb_GetDeviceDescriptor](#oh_usb_getdevicedescriptor)(uint64_t deviceId, struct [UsbDeviceDescriptor](_usb_device_descriptor.md)\*desc) | Obtains the device descriptor.|
| [OH_Usb_GetConfigDescriptor](#oh_usb_getconfigdescriptor)(uint64_t deviceId, uint8_t configIndex, struct [UsbDdkConfigDescriptor](_usb_ddk_config_descriptor.md)\*\*const config) | Obtains the configuration descriptor. To avoid memory leakage, use **OH_Usb_FreeConfigDescriptor** to release a descriptor after use.|
| [OH_Usb_FreeConfigDescriptor](#oh_usb_freeconfigdescriptor)(const struct [UsbDdkConfigDescriptor](_usb_ddk_config_descriptor.md)\*const config) | Releases the configuration descriptor. To avoid memory leakage, release a descriptor after use.|
| [OH_Usb_ClaimInterface](#oh_usb_claiminterface)(uint64_t deviceId, uint8_t interfaceIndex, uint64_t \*[interfaceHandle](usb__ddk__types_8h.md#interfacehandle)) | Declares a USB interface.|
| [OH_Usb_ReleaseInterface](#oh_usb_releaseinterface)(uint64_t[interfaceHandle](usb__ddk__types_8h.md#interfacehandle)) | Releases a USB interface.|
| [OH_Usb_SelectInterfaceSetting](#oh_usb_selectinterfacesetting)(uint64_t[interfaceHandle](usb__ddk__types_8h.md#interfacehandle), uint8_t settingIndex) | Activates the alternate setting of a USB interface.|
| [OH_Usb_GetCurrentInterfaceSetting](#oh_usb_getcurrentinterfacesetting)(uint64_t[interfaceHandle](usb__ddk__types_8h.md#interfacehandle), uint8_t \*settingIndex) | Obtains the activated alternate setting of a USB interface.|
| [OH_Usb_SendControlReadRequest](#oh_usb_sendcontrolreadrequest)(uint64_t[interfaceHandle](usb__ddk__types_8h.md#interfacehandle), const struct [UsbControlRequestSetup](_usb_control_request_setup.md)\*setup, uint32_t [timeout](usb__ddk__types_8h.md#timeout), uint8_t \*data, uint32_t \*dataLen) | Sends a control read transfer request. This API works in a synchronous manner.|
| [OH_Usb_SendControlWriteRequest](#oh_usb_sendcontrolwriterequest)(uint64_t[interfaceHandle](usb__ddk__types_8h.md#interfacehandle), const struct [UsbControlRequestSetup](_usb_control_request_setup.md)\*setup, uint32_t [timeout](usb__ddk__types_8h.md#timeout), const uint8_t \*data, uint32_t dataLen) | Sends a control write transfer request. This API works in a synchronous manner.|
| [OH_Usb_SendPipeRequest](#oh_usb_sendpiperequest)(const struct [UsbRequestPipe](_usb_request_pipe.md)\*pipe, [UsbDeviceMemMap](_usb_device_mem_map.md)\*devMmap) | Sends a pipe request. This API works in a synchronous manner. It applies to interrupt transfer and bulk transfer.|
| [OH_Usb_CreateDeviceMemMap](#oh_usb_createdevicememmap)(uint64_t deviceId, size_t size, [UsbDeviceMemMap](_usb_device_mem_map.md)\*\*devMmap) | Creates a buffer. To avoid memory leakage, use [OH_Usb_DestroyDeviceMemMap()](#oh_usb_destroydevicememmap) to destroy a buffer after use.|
| [OH_Usb_DestroyDeviceMemMap](#oh_usb_destroydevicememmap)([UsbDeviceMemMap](_usb_device_mem_map.md)\*devMmap) | Destroys a buffer. To avoid resource leakage, destroy a buffer in time after use.|
Device memory map created by calling [OH_Usb_CreateDeviceMemMap()](#oh_usb_createdevicememmap). A buffer using the device memory map can provide better performance.
## Enum Description
### UsbDdkErrCode
```
enum UsbDdkErrCode
```
**Description**
USB DDK error code definitions.
| Value| Description|
| -------- | -------- |
| USB_DDK_SUCCESS | Operation successful.|
| USB_DDK_FAILED | Operation failed.|
| USB_DDK_INVALID_PARAMETER | Invalid parameter.|
| USB_DDK_MEMORY_ERROR | Memory-related error, for example, insufficient memory, memory data copy failure, or memory application failure.|
Obtains the configuration descriptor. To avoid memory leakage, use **OH_Usb_FreeConfigDescriptor** to release a descriptor after use.
**Parameters**
| Name| Description|
| -------- | -------- |
| deviceId | Device ID.|
| configIndex | Configuration ID, which corresponds to [bConfigurationValue](_usb_config_descriptor.md#bconfigurationvalue) in the USB protocol.|
| config | Configuration descriptor, which includes the standard configuration descriptor defined in the USB protocol and the associated interface descriptor and endpoint descriptor.|
**Returns**
**0** if the operation is successful; a negative value otherwise.
Obtains the activated alternate setting of a USB interface.
**Parameters**
| Name| Description|
| -------- | -------- |
| interfaceHandle | Interface operation handle.|
| settingIndex | Index of the alternate setting, which corresponds to [bAlternateSetting](_usb_interface_descriptor.md#balternatesetting) in the USB protocol.|
**Returns**
**0** if the operation is successful; a negative value otherwise.
Activates the alternate setting of a USB interface.
**Parameters**
| Name| Description|
| -------- | -------- |
| interfaceHandle | Interface operation handle.|
| settingIndex | Index of the alternate setting, which corresponds to [bAlternateSetting](_usb_interface_descriptor.md#balternatesetting) in the USB protocol.|
**Returns**
**0** if the operation is successful; a negative value otherwise.
| [bcdUSB](#bcdusb) | USB protocol release number.|
| [bDeviceClass](#bdeviceclass) | Interface class code allocated by the USB-IF.|
| [bDeviceSubClass](#bdevicesubclass) | Device subclass code allocated by USB-IF. The value is limited by that of bDeviceClass.|
| [bDeviceProtocol](#bdeviceprotocol) | Protocol code allocated by USB-IF. The value is limited by that of [bDeviceClass](#bdeviceclass) and [bDeviceSubClass](#bdevicesubclass).|
| [bMaxPacketSize0](#bmaxpacketsize0) | Maximum packet size of endpoint 0. Only values 8, 16, 32, and 64 are valid.|
| [idVendor](#idvendor) | Vendor ID allocated by USB-IF.|
| [idProduct](#idproduct) | Product ID allocated by the vendor.|
Device memory map created by calling [OH_Usb_CreateDeviceMemMap()](_usb_ddk.md#oh_usb_createdevicememmap). A buffer using the device memory map can provide better performance.
**Since**
10
**Related Modules**
[UsbDdk](_usb_ddk.md)
## Summary
### Member Variables
| Name| Description|
| -------- | -------- |
| [address](#address) | Buffer address.|
| [size](#size) | Buffer size.|
| [offset](#offset) | Offset of the used buffer. The default value is 0, indicating that there is no offset and the buffer starts from the specified address.|
| [bufferLength](#bufferlength) | Length of the used buffer. By default, the value is equal to the size, indicating that the entire buffer is used.|
| [transferedLength](#transferedlength) | Length of the transferred data.|
## Member Variable Description
### address
```
uint8_t* const UsbDeviceMemMap::address
```
**Description**
Buffer address.
### bufferLength
```
uint32_t UsbDeviceMemMap::bufferLength
```
**Description**
Length of the used buffer. By default, the value is equal to the size, indicating that the entire buffer is used.
### offset
```
uint32_t UsbDeviceMemMap::offset
```
**Description**
Offset of the used buffer. The default value is 0, indicating that there is no offset and the buffer starts from the specified address.
| [bAlternateSetting](#balternatesetting) | Value used to select the alternate setting of the interface.|
| [bNumEndpoints](#bnumendpoints) | Number of endpoints (excluding endpoint 0) used by the interface.|
| [bInterfaceClass](#binterfaceclass) | Interface class code allocated by the USB-IF.|
| [bInterfaceSubClass](#binterfacesubclass) | Device subclass code allocated by USB-IF. The value is limited by that of [bInterfaceClass](#binterfaceclass).|
| [bInterfaceProtocol](#binterfaceprotocol) | Protocol code allocated by USB-IF. The value is limited by that of [bInterfaceClass](#binterfaceclass) and [bInterfaceSubClass](#binterfacesubclass).|
| [iInterface](#iinterface) | Index of the string descriptor that describes the interface.|
## Member Variable Description
### bAlternateSetting
```
uint8_t UsbInterfaceDescriptor::bAlternateSetting
```
**Description**
Value used to select the alternate setting of the interface.
| [OH_HiTrace_StartTrace](_hitrace.md#oh_hitrace_starttrace)(const char \*name) | Marks the start of a synchronous trace.|
| [OH_HiTrace_FinishTrace](_hitrace.md#oh_hitrace_finishtrace)(void) | Marks the end of a synchronous trace.|
| [OH_HiTrace_StartAsyncTrace](_hitrace.md#oh_hitrace_startasynctrace)(const char \*name, int32_t taskId) | Marks the start of an asynchronous trace.|
| [OH_HiTrace_FinishAsyncTrace](_hitrace.md#oh_hitrace_finishasynctrace)(const char \*name, int32_t taskId) | Marks the end of an asynchronous trace.|
| [OH_HiTrace_CountTrace](_hitrace.md#oh_hitrace_counttrace)(const char \*name, int64_t count) | Traces the value change of an integer variable based on its name.|
Declares the USB DDK APIs used by the USB host to access USB devices.
**Since**
10
**Related Modules**
[UsbDdk](_usb_ddk.md)
## Summary
### Functions
| Name| Description|
| -------- | -------- |
| [OH_Usb_Init](_usb_ddk.md#oh_usb_init) (void) | Initializes the DDK.|
| [OH_Usb_Release](_usb_ddk.md#oh_usb_release) (void) | Releases the DDK.|
| [OH_Usb_GetDeviceDescriptor](_usb_ddk.md#oh_usb_getdevicedescriptor) (uint64_t deviceId, struct [UsbDeviceDescriptor](_usb_device_descriptor.md) \*desc) | Obtains the device descriptor.|
| [OH_Usb_GetConfigDescriptor](_usb_ddk.md#oh_usb_getconfigdescriptor) (uint64_t deviceId, uint8_t configIndex, struct [UsbDdkConfigDescriptor](_usb_ddk_config_descriptor.md) \*\*const config) | Obtains the configuration descriptor. To avoid memory leakage, use [OH_Usb_FreeConfigDescriptor()](_usb_ddk.md#oh_usb_freeconfigdescriptor) to release a descriptor after use.|
| [OH_Usb_FreeConfigDescriptor](_usb_ddk.md#oh_usb_freeconfigdescriptor) (const struct [UsbDdkConfigDescriptor](_usb_ddk_config_descriptor.md) \*const config) | Releases the configuration descriptor. To avoid memory leakage, release a descriptor after use.|
| [OH_Usb_ClaimInterface](_usb_ddk.md#oh_usb_claiminterface) (uint64_t deviceId, uint8_t interfaceIndex, uint64_t \*[interfaceHandle](usb__ddk__types_8h.md#interfacehandle)) | Declares a USB interface.|
| [OH_Usb_ReleaseInterface](_usb_ddk.md#oh_usb_releaseinterface) (uint64_t [interfaceHandle](usb__ddk__types_8h.md#interfacehandle)) | Releases a USB interface.|
| [OH_Usb_SelectInterfaceSetting](_usb_ddk.md#oh_usb_selectinterfacesetting) (uint64_t [interfaceHandle](usb__ddk__types_8h.md#interfacehandle), uint8_t settingIndex) | Activates the alternate setting of a USB interface.|
| [OH_Usb_GetCurrentInterfaceSetting](_usb_ddk.md#oh_usb_getcurrentinterfacesetting) (uint64_t [interfaceHandle](usb__ddk__types_8h.md#interfacehandle), uint8_t \*settingIndex) | Obtains the activated alternate setting of a USB interface.|
| [OH_Usb_SendControlReadRequest](_usb_ddk.md#oh_usb_sendcontrolreadrequest) (uint64_t [interfaceHandle](usb__ddk__types_8h.md#interfacehandle), const struct [UsbControlRequestSetup](_usb_control_request_setup.md) \*setup, uint32_t [timeout](usb__ddk__types_8h.md#timeout), uint8_t \*data, uint32_t \*dataLen) | Sends a control read transfer request. This API works in a synchronous manner.|
| [OH_Usb_SendControlWriteRequest](_usb_ddk.md#oh_usb_sendcontrolwriterequest) (uint64_t [interfaceHandle](usb__ddk__types_8h.md#interfacehandle), const struct [UsbControlRequestSetup](_usb_control_request_setup.md) \*setup, uint32_t [timeout](usb__ddk__types_8h.md#timeout), const uint8_t \*data, uint32_t dataLen) | Sends a control write transfer request. This API works in a synchronous manner.|
| [OH_Usb_SendPipeRequest](_usb_ddk.md#oh_usb_sendpiperequest) (const struct [UsbRequestPipe](_usb_request_pipe.md) \*pipe, [UsbDeviceMemMap](_usb_device_mem_map.md) \*devMmap) | Sends a pipe request. This API works in a synchronous manner. It applies to interrupt transfer and bulk transfer.|
| [OH_Usb_CreateDeviceMemMap](_usb_ddk.md#oh_usb_createdevicememmap) (uint64_t deviceId, size_t size, [UsbDeviceMemMap](_usb_device_mem_map.md) \*\*devMmap) | Creates a buffer. To avoid memory leakage, use [OH_Usb_DestroyDeviceMemMap()](_usb_ddk.md#oh_usb_destroydevicememmap) to destroy a buffer after use.|
| [OH_Usb_DestroyDeviceMemMap](_usb_ddk.md#oh_usb_destroydevicememmap) ([UsbDeviceMemMap](_usb_device_mem_map.md) \*devMmap) | Destroys a buffer. To avoid resource leakage, destroy a buffer in time after use.|
Provides the enumerated variables, structures, and macros used in USB DDK APIs.
**Since**
10
**Related Modules**
[UsbDdk](_usb_ddk.md)
## Summary
### Structs
| Name| Description|
| -------- | -------- |
| [UsbControlRequestSetup](_usb_control_request_setup.md) | Setup data for control transfer, corresponding to **Setup Data** in the USB protocol.|
| [UsbDeviceDescriptor](_usb_device_descriptor.md) | Standard device descriptor, corresponding to **Standard Device Descriptor** in the USB protocol.|
| [UsbConfigDescriptor](_usb_config_descriptor.md) | Standard configuration descriptor, corresponding to **Standard Configuration Descriptor** in the USB protocol.|
| [UsbInterfaceDescriptor](_usb_interface_descriptor.md) | Standard interface descriptor, corresponding to **Standard Interface Descriptor** in the USB protocol.|
| [UsbEndpointDescriptor](_usb_endpoint_descriptor.md) | Standard endpoint descriptor, corresponding to **Standard Endpoint Descriptor** in the USB protocol.|
| [UsbDeviceMemMap](_usb_device_mem_map.md) | Device memory map created by calling [OH_Usb_CreateDeviceMemMap()](_usb_ddk.md#oh_usb_createdevicememmap). A buffer using the device memory map can provide better performance.|
| [UsbDeviceMemMap](_usb_ddk.md#usbdevicememmap) | Device memory map created by calling [OH_Usb_CreateDeviceMemMap()](_usb_ddk.md#oh_usb_createdevicememmap). A buffer using the device memory map can provide better performance.|
### Enums
| Name| Description|
| -------- | -------- |
| [UsbDdkErrCode](_usb_ddk.md#usbddkerrcode) {<br>USB_DDK_SUCCESS = 0, USB_DDK_FAILED = -1, USB_DDK_INVALID_PARAMETER = -2, USB_DDK_MEMORY_ERROR = -3,<br>USB_DDK_INVALID_OPERATION = -4, USB_DDK_NULL_PTR = -5, USB_DDK_DEVICE_BUSY = -6, USB_DDK_TIMEOUT = -7<br>} | USB DDK error code definition.|
| [wValue](#wvalue) | Value corresponding to **wValue** in the USB protocol. Its meaning varies according to the request.|
| [wIndex](#windex) | Index corresponding to **wIndex** in the USB protocol. It is usually used to transfer the index or offset. Its meaning varies according to the request. |
| [wLength](#wlength) | Data length corresponding to **wLength** in the USB protocol. If data is transferred, this field indicates the number of transferred bytes.|
| [bLength](#blength) | Size of the descriptor, in bytes.|
| [bcdUSB](#bcdusb) | USB protocol release number.|
| [bDeviceClass](#bdeviceclass) | Interface class code allocated by the USB-IF.|
| [bDeviceSubClass](#bdevicesubclass) | Device subclass code allocated by USB-IF. The value is limited by that of bDeviceClass.|
| [bDeviceProtocol](#bdeviceprotocol) | Protocol code allocated by USB-IF. The value is limited by that of [bDeviceClass](#bdeviceclass) and [bDeviceSubClass](#bdevicesubclass).|
| [bMaxPacketSize0](#bmaxpacketsize0) | Maximum packet size of endpoint 0. Only values 8, 16, 32, and 64 are valid.|
| [idVendor](#idvendor) | Vendor ID allocated by USB-IF.|
| [idProduct](#idproduct) | Product ID allocated by the vendor.|
| [wTotalLength](#wtotallength) | Total length of the configuration descriptor, including the configuration, interface, endpoint, and class- or vendor-specific descriptors.|
| [bNumInterfaces](#bnuminterfaces) | Number of interfaces supported by the configuration.|
| [bConfigurationValue](#bconfigurationvalue) | Configuration index, which is used to select the configuration.|
| [iConfiguration](#iconfiguration) | Index of the string descriptor that describes the configuration.|
| [bmAttributes](#bmattributes) | Configuration attributes, including the power mode and remote wakeup.|
| [bMaxPower](#bmaxpower) | Maximum power consumption of the bus-powered USB device, in 2 mA.|
| [bAlternateSetting](#balternatesetting) | Value used to select the alternate setting of the interface.|
| [bNumEndpoints](#bnumendpoints) | Number of endpoints (excluding endpoint 0) used by the interface.|
| [bInterfaceClass](#binterfaceclass) | Interface class code allocated by the USB-IF.|
| [bInterfaceSubClass](#binterfacesubclass) | Device subclass code allocated by USB-IF. The value is limited by that of [bInterfaceClass](#binterfaceclass).|
| [bInterfaceProtocol](#binterfaceprotocol) | Protocol code allocated by USB-IF. The value is limited by that of [bInterfaceClass](#binterfaceclass) and [bInterfaceSubClass](#binterfacesubclass).|
| [iInterface](#iinterface) | Index of the string descriptor that describes the interface.|
| [bEndpointAddress](#bendpointaddress) | Endpoint address, including the endpoint number and endpoint direction.|
| [bmAttributes](#bmattributes) | Endpoint attributes, including the transfer type, synchronization type, and usage type.|
| [wMaxPacketSize](#wmaxpacketsize) | Maximum packet size supported by an endpoint.|
| [bInterval](#binterval) | Interval for polling endpoints for data transfer.|
| [bRefresh](#brefresh) | Refresh rate for audio devices.|
| [bSynchAddress](#bsynchaddress) | Endpoint synchronization address for audio devices.|
| [timeout](#timeout) | Timeout duration, in milliseconds.|
## Variable Description
### bAlternateSetting
```
uint8_t bAlternateSetting
```
**Description**
Value used to select the alternate setting of the interface.
### bcdDevice
```
uint16_t bcdDevice
```
**Description**
Device release number.
### bcdUSB
```
uint16_t bcdUSB
```
**Description**
USB protocol release number.
### bConfigurationValue
```
uint8_t bConfigurationValue
```
**Description**
Configuration index, which is used to select the configuration.
### bDescriptorType
```
uint8_t bDescriptorType
```
**Description**
Descriptor type.
### bDeviceClass
```
uint8_t bDeviceClass
```
**Description**
Interface class code allocated by the USB-IF.
### bDeviceProtocol
```
uint8_t bDeviceProtocol
```
**Description**
Protocol code allocated by USB-IF. The value is limited by that of [bDeviceClass](#bdeviceclass) and [bDeviceSubClass](#bdevicesubclass).
### bDeviceSubClass
```
uint8_t bDeviceSubClass
```
**Description**
Device subclass code allocated by USB-IF. The value is limited by that of bDeviceClass.
### bEndpointAddress
```
uint8_t bEndpointAddress
```
**Description**
Endpoint address, including the endpoint number and endpoint direction.
### bmAttributes
```
uint8_t bmAttributes
```
**Description**
Endpoint attributes, including the transfer type, synchronization type, and usage type.
### bInterfaceClass
```
uint8_t bInterfaceClass
```
**Description**
Interface class code allocated by the USB-IF.
### bInterfaceNumber
```
uint8_t bInterfaceNumber
```
**Description**
Interface ID.
### bInterfaceProtocol
```
uint8_t bInterfaceProtocol
```
**Description**
Protocol code allocated by USB-IF. The value is limited by that of [bInterfaceClass](#binterfaceclass) and [bInterfaceSubClass](#binterfacesubclass).
### bInterfaceSubClass
```
uint8_t bInterfaceSubClass
```
**Description**
Device subclass code allocated by USB-IF. The value is limited by that of [bInterfaceClass](#binterfaceclass).
### bInterval
```
uint8_t bInterval
```
**Description**
Interval for polling endpoints for data transfer.
### bLength
```
uint8_t bLength
```
**Description**
Size of the descriptor, in bytes.
### bmAttributes
```
uint8_t bmAttributes
```
**Description**
Configuration attributes, including the power mode and remote wakeup.
### bMaxPacketSize0
```
uint8_t bMaxPacketSize0
```
**Description**
Maximum packet size of endpoint 0. Only values 8, 16, 32, and 64 are valid.
### bMaxPower
```
uint8_t bMaxPower
```
**Description**
Maximum power consumption of the bus-powered USB device, in 2 mA.
### bNumConfigurations
```
uint8_t bNumConfigurations
```
**Description**
Configuration quantity.
### bNumEndpoints
```
uint8_t bNumEndpoints
```
**Description**
Number of endpoints (excluding endpoint 0) used by the interface.
### bNumInterfaces
```
uint8_t bNumInterfaces
```
**Description**
Number of interfaces supported by the configuration.
### bRefresh
```
uint8_t bRefresh
```
**Description**
Refresh rate for audio devices.
### bSynchAddress
```
uint8_t bSynchAddress
```
**Description**
Endpoint synchronization address for audio devices.
### endpoint
```
uint8_t endpoint
```
**Description**
Endpoint address.
### iConfiguration
```
uint8_t iConfiguration
```
**Description**
Index of the string descriptor that describes the configuration.
### idProduct
```
uint16_t idProduct
```
**Description**
Product ID allocated by the vendor.
### idVendor
```
uint16_t idVendor
```
**Description**
Vendor ID allocated by USB-IF.
### iInterface
```
uint8_t iInterface
```
**Description**
Index of the string descriptor that describes the interface.
### iManufacturer
```
uint8_t iManufacturer
```
**Description**
Index of the string descriptor that describes the vendor.
### wIndex
```
uint16_t wIndex
```
**Description**
Index corresponding to **wIndex** in the USB protocol. It is usually used to transfer the index or offset. Its meaning varies according to the request.
### interfaceHandle
```
uint64_t interfaceHandle
```
**Description**
Interface operation handle.
### iProduct
```
uint8_t iProduct
```
**Description**
Index of the string descriptor that describes the product.
### iSerialNumber
```
uint8_t iSerialNumber
```
**Description**
Index of the string descriptor that describes the device SN.
### wLength
```
uint16_t wLength
```
**Description**
Data length corresponding to **wLength** in the USB protocol. If data is transferred, this field indicates the number of transferred bytes.
### bRequest
```
uint8_t bRequest
```
**Description**
Specific request.
### bmRequestType
```
uint8_t bmRequestType
```
**Description**
Request type.
### timeout
```
uint32_t timeout
```
**Description**
Timeout duration, in milliseconds.
### wValue
```
uint16_t wValue
```
**Description**
Value corresponding to **wValue** in the USB protocol. Its meaning varies according to the request.
### wMaxPacketSize
```
uint16_t wMaxPacketSize
```
**Description**
Maximum packet size supported by an endpoint.
### wTotalLength
```
uint16_t wTotalLength
```
**Description**
Total length of the configuration descriptor, including the configuration, interface, endpoint, and class- or vendor-specific descriptors.