• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2022 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 <pthread.h>
41 #include <sys/time.h>
42 #include "securec.h"
43 #include "hdf_base.h"
44 #include "hdf_slist.h"
45 #include "hdf_dlist.h"
46 #include "hdf_log.h"
47 #include "osal_mem.h"
48 #include "osal_mutex.h"
49 #include "osal_sem.h"
50 #include "osal_thread.h"
51 #include "osal_time.h"
52 #include "osal_atomic.h"
53 
54 /**
55  * @brief Defines the maximum object ID.
56  */
57 #define MAX_OBJECT_ID       (0x7FFFFFFF)
58 
59 /**
60  * @brief Defines the USB request status type.
61  *
62  * You can use this function to check the request execution status.
63  */
64 typedef enum {
65     /** Request completed */
66     USB_REQUEST_COMPLETED,
67     /** Request completed beforehand */
68     USB_REQUEST_COMPLETED_SHORT,
69     /** Request error */
70     USB_REQUEST_ERROR,
71     /** Request timeout */
72     USB_REQUEST_TIMEOUT,
73     /** Request canceled */
74     USB_REQUEST_CANCELLED,
75     /** Request stopped */
76     USB_REQUEST_STALL,
77     /** Device disconnected */
78     USB_REQUEST_NO_DEVICE,
79     /** Overflow error. The amount of sent data is more than requested. */
80     USB_REQUEST_OVERFLOW,
81 } UsbRequestStatus;
82 
83 /**
84  * @brief Defines the USB pipe direction.
85  */
86 typedef enum {
87     /** Output direction (from the host to the device) */
88     USB_PIPE_DIRECTION_OUT = 0x00,
89     /** Input direction (from the device to the host) */
90     USB_PIPE_DIRECTION_IN = 0x80,
91 } UsbPipeDirection;
92 
93 /**
94  * @brief Defines the USB pipe type.
95  */
96 typedef enum {
97     /** Control transfer */
98     USB_PIPE_TYPE_CONTROL = 0U,
99     /**
100      * Isochronous transfer is mainly used for transmitting time-dependent information, such as
101      * audio and video data,at a constant rate. Each isochronous transfer involves one or multiple
102      * isochronous transactions, each containing token packets and data packets but no handshake packets.
103      * This transfer mode ensures the timeliness of transfer but does not guarantee the correctness
104      * of data due to the absence of handshake.
105      * Different from bulk transfer, isochronous transfer allows a certain bit error rate (BER)
106      * under certain conditions, so as to ensure that
107      *  audio and video data are transmitted on a real-time basis.
108      */
109     USB_PIPE_TYPE_ISOCHRONOUS = 1U,
110     /** Bulk transfer */
111     USB_PIPE_TYPE_BULK = 2U,
112     /** Interrupt transfer */
113     USB_PIPE_TYPE_INTERRUPT = 3U,
114 } UsbPipeType;
115 
116 /**
117  * @brief Defines the USB interface status.
118  */
119 typedef enum {
120     /** Normal */
121     USB_INTERFACE_STATUS_NORMAL,
122     /** Interface addition */
123     USB_INTERFACE_STATUS_ADD,
124     /** Interface removal */
125     USB_INTERFACE_STATUS_REMOVE,
126     /** Other status */
127     USB_INTERFACE_STATUS_OTHER,
128 } UsbInterfaceStatus;
129 
130 /**
131  * @brief Defines the USB basic object, which is contained in the data structure provided for users.
132  * It is used to mark an external object and create an object linked list.
133  */
134 struct UsbObject {
135     /** Basic object ID */
136     int32_t objectId;
137     /** Bidirectional linked list header */
138     struct DListHead entry;
139 };
140 
141 #endif /* USB_OBJECT_H */
142 /** @} */