1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup USB 18 * @{ 19 * 20 * @brief Declares USB-related APIs, including the custom data types and functions used to obtain descriptors, 21 * interface objects, and request objects, and to submit requests. 22 * 23 * @since 1.0 24 * @version 1.0 25 */ 26 27 /** 28 * @file usb_object.h 29 * 30 * @brief Defines USB common data types, including the enumerated values returned by 31 * functions and definitions of other common data structures. 32 * 33 * @since 1.0 34 * @version 1.0 35 */ 36 #ifndef USB_OBJECT_H 37 #define USB_OBJECT_H 38 39 #include <stdint.h> 40 #include <stdatomic.h> 41 #include <pthread.h> 42 #include <sys/time.h> 43 #include "securec.h" 44 #include "hdf_base.h" 45 #include "hdf_slist.h" 46 #include "hdf_dlist.h" 47 #include "hdf_log.h" 48 #include "osal_mem.h" 49 #include "osal_mutex.h" 50 #include "osal_sem.h" 51 #include "osal_thread.h" 52 #include "osal_time.h" 53 #include "osal_atomic.h" 54 55 /** 56 * @brief Defines the maximum object ID. 57 */ 58 #define MAX_OBJECT_ID (0x7FFFFFFF) 59 60 /** 61 * @brief Defines the USB request status type. 62 * 63 * You can use this function to check the request execution status. 64 */ 65 typedef enum { 66 /** Request completed */ 67 USB_REQUEST_COMPLETED, 68 /** Request completed beforehand */ 69 USB_REQUEST_COMPLETED_SHORT, 70 /** Request error */ 71 USB_REQUEST_ERROR, 72 /** Request timeout */ 73 USB_REQUEST_TIMEOUT, 74 /** Request canceled */ 75 USB_REQUEST_CANCELLED, 76 /** Request stopped */ 77 USB_REQUEST_STALL, 78 /** Device disconnected */ 79 USB_REQUEST_NO_DEVICE, 80 /** Overflow error. The amount of sent data is more than requested. */ 81 USB_REQUEST_OVERFLOW, 82 } UsbRequestStatus; 83 84 /** 85 * @brief Defines the USB pipe direction. 86 */ 87 typedef enum { 88 /** Output direction (from the host to the device) */ 89 USB_PIPE_DIRECTION_OUT = 0x00, 90 /** Input direction (from the device to the host) */ 91 USB_PIPE_DIRECTION_IN = 0x80, 92 } UsbPipeDirection; 93 94 /** 95 * @brief Defines the USB pipe type. 96 */ 97 typedef enum { 98 /** Control transfer */ 99 USB_PIPE_TYPE_CONTROL = 0U, 100 /** 101 * Isochronous transfer is mainly used for transmitting time-dependent information, such as 102 * audio and video data,at a constant rate. Each isochronous transfer involves one or multiple 103 * isochronous transactions, each containing token packets and data packets but no handshake packets. 104 * This transfer mode ensures the timeliness of transfer but does not guarantee the correctness 105 * of data due to the absence of handshake. 106 * Different from bulk transfer, isochronous transfer allows a certain bit error rate (BER) 107 * under certain conditions, so as to ensure that 108 * audio and video data are transmitted on a real-time basis. 109 */ 110 USB_PIPE_TYPE_ISOCHRONOUS = 1U, 111 /** Bulk transfer */ 112 USB_PIPE_TYPE_BULK = 2U, 113 /** Interrupt transfer */ 114 USB_PIPE_TYPE_INTERRUPT = 3U, 115 } UsbPipeType; 116 117 /** 118 * @brief Defines the USB interface status. 119 */ 120 typedef enum { 121 /** Normal */ 122 USB_INTERFACE_STATUS_NORMAL, 123 /** Interface addition */ 124 USB_INTERFACE_STATUS_ADD, 125 /** Interface removal */ 126 USB_INTERFACE_STATUS_REMOVE, 127 /** Other status */ 128 USB_INTERFACE_STATUS_OTHER, 129 } UsbInterfaceStatus; 130 131 /** 132 * @brief Defines the USB basic object, which is contained in the data structure provided for users. 133 * It is used to mark an external object and create an object linked list. 134 */ 135 struct UsbObject { 136 /** Basic object ID */ 137 int32_t objectId; 138 /** Bidirectional linked list header */ 139 struct DListHead entry; 140 }; 141 142 #endif /* USB_OBJECT_H */ 143 /** @} */