1# ddk_api.h 2<!--Kit: Driver Development Kit--> 3<!--Subsystem: Driver--> 4<!--Owner: @lixinsheng2--> 5<!--Designer: @w00373942--> 6<!--Tester: @dong-dongzhen--> 7<!--Adviser: @w_Machine_cc--> 8 9## Overview 10 11Declares the BASE DDK APIs used by the USB host to access USB devices. 12 13**File to include**: <ddk/ddk_api.h> 14 15**Library**: libddk_base.z.so 16 17**System capability**: SystemCapability.Driver.DDK.Extension 18 19**Since**: 12 20 21**Related module**: [BaseDdk](capi-baseddk.md) 22 23## Summary 24 25### Function 26 27| Name| Description| 28| -- | -- | 29| [DDK_RetCode OH_DDK_CreateAshmem(const uint8_t *name, uint32_t size, DDK_Ashmem **ashmem)](#oh_ddk_createashmem) | Creates an **Ashmem** object. To prevent resource leakage, call **OH_DDK_DestroyAshmem** to destroy the **Ashmem** object when it is no longer needed.| 30| [DDK_RetCode OH_DDK_MapAshmem(DDK_Ashmem *ashmem, const uint8_t ashmemMapType)](#oh_ddk_mapashmem) | Maps the created **Ashmem** object to the user space. Call **OH_DDK_UnmapAshmem** to unmap the **Ashmem** object when it is no longer needed.| 31| [DDK_RetCode OH_DDK_UnmapAshmem(DDK_Ashmem *ashmem)](#oh_ddk_unmapashmem) | Unmaps an **Ashmem** object.| 32| [DDK_RetCode OH_DDK_DestroyAshmem(DDK_Ashmem *ashmem)](#oh_ddk_destroyashmem) | Destroys an **Ashmem** object.| 33 34## Function Description 35 36### OH_DDK_CreateAshmem() 37 38``` 39DDK_RetCode OH_DDK_CreateAshmem(const uint8_t *name, uint32_t size, DDK_Ashmem **ashmem) 40``` 41 42**Description** 43 44Creates an **Ashmem** object. To prevent resource leakage, call **OH_DDK_DestroyAshmem** to destroy the **Ashmem** object when it is no longer needed. 45 46**Since**: 12 47 48 49**Parameters** 50 51| Name | Description| 52|---------------------------------------------------| -- | 53| const uint8_t *name | Pointer to the name of the **Ashmem** object.| 54| uint32_t size | Buffer size of the **Ashmem** object.| 55| [DDK_Ashmem](capi-baseddk-ddk-ashmem.md) **ashmem | Pointer to the **Ashmem** object.| 56 57**Returns** 58 59| Type| Description| 60| -- | -- | 61| [DDK_RetCode](capi-ddk-types-h.md#ddk_retcode) | [DDK_SUCCESS](capi-ddk-types-h.md#ddk_retcode): The API call is successful.<br> [DDK_INVALID_PARAMETER](capi-ddk-types-h.md#ddk_retcode): The input **name** is a null pointer, the value of **size** is 0, or the input **ashmem** is a null pointer.<br> [DDK_FAILURE](capi-ddk-types-h.md#ddk_retcode): The attempt to create an **Ashmem** object or the DDK_Ashmem structure fails.| 62 63### OH_DDK_MapAshmem() 64 65``` 66DDK_RetCode OH_DDK_MapAshmem(DDK_Ashmem *ashmem, const uint8_t ashmemMapType) 67``` 68 69**Description** 70 71Maps the created **Ashmem** object to the user space. Call **OH_DDK_UnmapAshmem** to unmap the **Ashmem** object when it is no longer needed. 72 73**Since**: 12 74 75 76**Parameters** 77 78| Name | Description| 79|--------------------------------------------------| -- | 80| [DDK_Ashmem](capi-baseddk-ddk-ashmem.md) *ashmem | Pointer to the **Ashmem** object.| 81| const uint8_t ashmemMapType | Mapping type for the **Ashmem** object.| 82 83**Returns** 84 85| Type| Description| 86| -- | -- | 87| [DDK_RetCode](capi-ddk-types-h.md#ddk_retcode) | [DDK_SUCCESS](capi-ddk-types-h.md#ddk_retcode): The API call is successful.<br> [DDK_NULL_PTR](capi-ddk-types-h.md#ddk_retcode): The input **ashmem** is a null pointer.<br> [DDK_FAILURE](capi-ddk-types-h.md#ddk_retcode): The file descriptor of the **Ashmem** object is invalid.<br> [DDK_INVALID_OPERATION] (capi-ddk-types-h.md#ddk_retcode): The attempt to call MapAshmem fails.| 88 89### OH_DDK_UnmapAshmem() 90 91``` 92DDK_RetCode OH_DDK_UnmapAshmem(DDK_Ashmem *ashmem) 93``` 94 95**Description** 96 97Unmaps an **Ashmem** object. 98 99**Since**: 12 100 101 102**Parameters** 103 104| Name | Description| 105|--------------------------------------------------| -- | 106| [DDK_Ashmem](capi-baseddk-ddk-ashmem.md) *ashmem | Pointer to the **Ashmem** object.| 107 108**Returns** 109 110| Type| Description| 111| -- | -- | 112| [DDK_RetCode](capi-ddk-types-h.md#ddk_retcode) | [DDK_SUCCESS](capi-ddk-types-h.md#ddk_retcode): The API call is successful.<br> [DDK_NULL_PTR](capi-ddk-types-h.md#ddk_retcode): The input **ashmem** is a null pointer.<br> [DDK_FAILURE](capi-ddk-types-h.md#ddk_retcode): The file descriptor of the **Ashmem** object is invalid.| 113 114### OH_DDK_DestroyAshmem() 115 116``` 117DDK_RetCode OH_DDK_DestroyAshmem(DDK_Ashmem *ashmem) 118``` 119 120**Description** 121 122Destroys an **Ashmem** object. 123 124**Since**: 12 125 126 127**Parameters** 128 129| Name | Description| 130|--------------------------------------------------| -- | 131| [DDK_Ashmem](capi-baseddk-ddk-ashmem.md) *ashmem | Pointer to the **Ashmem** object.| 132 133**Returns** 134 135| Type| Description| 136| -- | -- | 137| [DDK_RetCode](capi-ddk-types-h.md#ddk_retcode) | [DDK_SUCCESS](capi-ddk-types-h.md#ddk_retcode): The API call is successful.<br> [DDK_NULL_PTR](capi-ddk-types-h.md#ddk_retcode): The input **ashmem** is a null pointer.<br> [DDK_FAILURE](capi-ddk-types-h.md#ddk_retcode): The file descriptor of the **Ashmem** object is invalid.| 138